aboutsummaryrefslogtreecommitdiff
path: root/cart.h
blob: f2b10a4a9321aeba3500af215e0210d234dc7cae (plain)
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

/* CART header support for cart2xex

	Format of CART header (from atari800 cart.txt):

 first 4 bytes containing 'C' 'A' 'R' 'T'.
 next 4 bytes containing cartridge type in MSB format (see the table below).
 next 4 bytes containing cartridge checksum in MSB format (ROM only).
 next 4 bytes are currently unused (zero).
 followed immediately with the ROM data: 4, 8, 16, 32, 40, 64, 128, 256, 512
 or 1024 kilobytes.

 See cart.c for the list of cart types.
*/

#ifndef CART_H
#define CART_H

#define CART_SIGNATURE "CART"

#define CART_SIGNATURE_OFFSET 0
#define CART_TYPE_OFFSET 4
#define CART_CHECKSUM_OFFSET 8
#define CART_UNUSED_OFFSET 12

typedef enum {
	M_INVALID,
	M_ATARI8,
	M_5200
} machine_t;

typedef struct {
	int machine;
	int size;
	char *name;
} cart_t;

extern cart_t cart_types[];
extern const int MAX_CART_TYPE;

int has_cart_signature(unsigned char *cart);
void cart_dump_header(unsigned char *cart, int calc_cksum);
unsigned int get_cart_type(unsigned char *cart);
unsigned int get_cart_size(unsigned char *cart);
unsigned int get_cart_checksum(unsigned char *cart);
machine_t get_cart_machine(unsigned char *cart);
unsigned int calc_rom_checksum(unsigned char *rom, int bytes);
unsigned int cart_checksum_ok(unsigned char *cart);
int create_cart_header(
		unsigned char *buffer, unsigned char *rom, unsigned int type);
void set_cart_checksum(unsigned char *cart, unsigned int sum);
void set_cart_type(unsigned char *cart, unsigned int type);
void set_cart_unused(unsigned char *cart, unsigned int data);

#endif