summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/c64/cbm_crt.c
blob: 54b127c5af52b1c91d32adb8b66c9a8c27d50da1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/*********************************************************************

    cbm_crt.c

    Commodore C64 cartridge images

*********************************************************************/

#include "cbm_crt.h"



//**************************************************************************
//  MACROS/CONSTANTS
//**************************************************************************

#define LOG 0


// slot names for the C64 cartridge types
static const char * CRT_C64_SLOT_NAMES[_CRT_C64_COUNT] =
{
	"standard",
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	"simons_basic",
	"ocean",
	UNSUPPORTED,
	"fun_play",
	"super_games",
	UNSUPPORTED,
	"epyxfastload",
	"westermann",
	"rex",
	UNSUPPORTED,
	"magic_formel",
	"system3",
	"warp_speed",
	"dinamic",
	"zaxxon",
	"magic_desk",
	UNSUPPORTED,
	"comal80",
	"struct_basic",
	"ross",
	"ep64",
	"ep7x8",
	"dela_ep256",
	"rex_ep256",
	"mikroasm",
	UNSUPPORTED,
	UNSUPPORTED,
	"stardos",
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	"ieee488",
	UNSUPPORTED,
	UNSUPPORTED,
	"exos",
	UNSUPPORTED,
	UNSUPPORTED,
	UNSUPPORTED,
	"super_explode",
	UNSUPPORTED,
	UNSUPPORTED,
	"mach5",
	UNSUPPORTED,
	"pagefox",
	UNSUPPORTED,
	"silverrock"
};



//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

//-------------------------------------------------
//  cbm_crt_get_card - get slot interface card
//-------------------------------------------------

const char * cbm_crt_get_card(core_file *file)
{
	// read the header
	cbm_crt_header header;
	core_fread(file, &header, CRT_HEADER_LENGTH);

	if (memcmp(header.signature, CRT_SIGNATURE, 16) == 0)
	{
		UINT16 hardware = pick_integer_be(header.hardware, 0, 2);

		return CRT_C64_SLOT_NAMES[hardware];
	}

	return NULL;
}


//-------------------------------------------------
//  cbm_crt_read_header - read cartridge header
//-------------------------------------------------

bool cbm_crt_read_header(core_file* file, size_t *roml_size, size_t *romh_size, int *exrom, int *game)
{
	// read the header
	cbm_crt_header header;
	core_fread(file, &header, CRT_HEADER_LENGTH);

	if (memcmp(header.signature, CRT_SIGNATURE, 16) != 0)
		return false;

	UINT16 hardware = pick_integer_be(header.hardware, 0, 2);
	*exrom = header.exrom;
	*game = header.game;

	if (LOG)
	{
		logerror("Name: %s\n", header.name);
		logerror("Hardware: %04x\n", hardware);
		logerror("Slot device: %s\n", CRT_C64_SLOT_NAMES[hardware]);
		logerror("EXROM: %u\n", header.exrom);
		logerror("GAME: %u\n", header.game);
	}

	// determine ROM region lengths
	while (!core_feof(file))
	{
		cbm_crt_chip chip;
		core_fread(file, &chip, CRT_CHIP_LENGTH);

		UINT16 address = pick_integer_be(chip.start_address, 0, 2);
		UINT16 size = pick_integer_be(chip.image_size, 0, 2);
		UINT16 type = pick_integer_be(chip.chip_type, 0, 2);

		if (LOG)
		{
			logerror("CHIP Address: %04x\n", address);
			logerror("CHIP Size: %04x\n", size);
			logerror("CHIP Type: %04x\n", type);
		}

		switch (address)
		{
		case 0x8000: *roml_size += size; break;
		case 0xa000: *romh_size += size; break;
		case 0xe000: *romh_size += size; break;
		default: logerror("Invalid CHIP loading address!\n"); break;
		}

		core_fseek(file, size, SEEK_CUR);
	}

	return true;
}


//-------------------------------------------------
//  cbm_crt_read_data - read cartridge data
//-------------------------------------------------

bool cbm_crt_read_data(core_file* file, UINT8 *roml, UINT8 *romh)
{
	offs_t roml_offset = 0;
	offs_t romh_offset = 0;

	core_fseek(file, CRT_HEADER_LENGTH, SEEK_SET);

	while (!core_feof(file))
	{
		cbm_crt_chip chip;
		core_fread(file, &chip, CRT_CHIP_LENGTH);

		UINT16 address = pick_integer_be(chip.start_address, 0, 2);
		UINT16 size = pick_integer_be(chip.image_size, 0, 2);

		switch (address)
		{
		case 0x8000: core_fread(file, roml + roml_offset, size); roml_offset += size; break;
		case 0xa000: core_fread(file, romh + romh_offset, size); romh_offset += size; break;
		case 0xe000: core_fread(file, romh + romh_offset, size); romh_offset += size; break;
		}
	}

	return true;
}