SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
everdrive.h
Go to the documentation of this file.
1
9
10#ifndef _EVERDRIVE
11#define _EVERDRIVE
12
13#if (MODULE_EVERDRIVE != 0)
14
15//config register bits
16#define _SS 0
17#define _FULL_SPEED 1
18#define _SPI16 2
19#define _GAME_MODE 3
20#define _SMS_MODE 4
21#define _HARD_RESET 5
22#define _RAM_MODE_1 6
23#define _RAM_ON 7
24#define _VBL_CATCH 8
25#define _MEGAKEY_ON 9
26#define _MEGAKEY_REGION_1 10
27#define _SSF_MODE_ON 11
28#define _RAM_FS 12
29#define _CART 13
30
31//state register bits
32#define _SPI_READY 0
33#define _RY 1
34#define _SMS_KEY 2
35#define _SD_CART 3
36
37//everdrive hardware registers
38#define SPI_PORT *((volatile u16*) (0xA13000))
39#define CFG_PORT *((volatile u16*) (0xA13002))
40#define VBL_PORT *((volatile u16*) (0xA13004))
41#define SRAM_BANK_PORT *((volatile u16*) (0xA13006))
42#define VER_PORT *((volatile u16*) (0xA13008))
43#define ROM_MAP_PORT *((volatile u16*) (0xA1300a))
44
45
46#define CFGC(bit)(cfg &= ~(1 << bit), CFG_PORT = cfg)
47#define CFGS(bit)(cfg |= (1 << bit), CFG_PORT = cfg)
48
49#define IS_RY (CFG_PORT & (1 << _RY))
50#define IS_SPI_READY (CFG_PORT & (1 << _SPI_READY))
51#define IS_SMS_KEY_PRESSED (CFG_PORT & (1 << _SMS_KEY))
52#define IS_SD_SLOT_EMPTY (CFG_PORT & (1 << _SD_CART))
53
54#define SPI_HI_SPEED_ON CFGS(_FULL_SPEED)
55#define SPI_HI_SPEED_OFF CFGC(_FULL_SPEED)
56
57#define SPI16_ON CFGS(_SPI16);
58#define SPI16_OFF CFGC(_SPI16);
59
60#define SS_ON CFGC(_SS)
61#define SS_OFF CFGS(_SS)
62
63#define CART_ON CFGC(_CART)
64#define CART_OFF CFGS(_CART)
65
66#define RAM_ON CFGS(_RAM_ON);
67#define RAM_OFF CFGC(_RAM_ON);
68
69#define VBL_CATCH_ON CFGS(_VBL_CATCH);
70#define VBL_CATCH_OFF CFGC(_VBL_CATCH);
71
72#define SPI_BUSY while(!IS_SPI_READY)
73#define EPR_BUSY while(!IS_RY)
74
75
76
77extern u16 cfg;
78
79
80//SD/MMC card initialization. should be run just one times, aer this cart will be ready for work
81//will return 0 success
82u8 evd_mmcInit();
83
84
85//read block (512b) from SD/MMC card. mmc_addr should be multiple to 512
86//will return 0 success
87u8 evd_mmcRdBlock(u32 mmc_addr, u8 *stor);
88
89
90//write block (512b) to SD/MMC card. mmc_addr should be multiple to 512
91//will return 0 success
92u8 evd_mmcWrBlock(u32 mmc_addr, u8 *data_ptr);
93
94
95//erase flash memry sector(64kb). rom_addr should be multiple to 64k.
96//code of this function should be placed in ram because rom memory inaccessible while erase process
97//WARNING! this function may damage cart bios if sectors in range 0 - 0x40000 will be erased
98void evd_eprEraseBlock(u32 rom_addr);
99
100
101//write data to flash memory. len should be multiple to 4.
102//each byte of flah memory should be erased before writeing by evd_eprEraseBlock
103//code of this function should be placed in ram because rom memory inaccessible while writeing process
104//WARNING! this function may damage cart bios if memory will be writen in area 0 - 0x40000
105void evd_eprProgBlock(u16 *data, u32 rom_addr, u32 len);
106
107
108//everdrive initialization.
109//def_rom_bank = 0 if app placed in 0-0x400000 area, 1 if in 0x400000-0x800000 arae
110//_is_ram_app = 0 if app assembled for work in rom, 1 if app assembleed for work in ram
111void evd_init(u16 def_rom_bank, u8 _is_ram_app);
112
113
114#endif // MODULE_EVERDRIVE
115
116#endif
unsigned long u32
Definition types.h:105
unsigned short u16
Definition types.h:100
unsigned char u8
Definition types.h:95