sgdk
everdrive.h
Go to the documentation of this file.
00001 
00010 #ifndef _EVERDRIVE
00011 #define _EVERDRIVE
00012 
00013 
00014 //config register bits
00015 #define _SS 0
00016 #define _FULL_SPEED 1
00017 #define _SPI16 2
00018 #define _GAME_MODE 3
00019 #define _SMS_MODE 4
00020 #define _HARD_RESET 5
00021 #define _RAM_MODE_1 6
00022 #define _RAM_ON 7
00023 #define _VBL_CATCH 8
00024 #define _MEGAKEY_ON 9
00025 #define _MEGAKEY_REGION_1 10
00026 #define _SSF_MODE_ON 11
00027 #define _RAM_FS 12
00028 #define _CART 13
00029 
00030 //state register bits
00031 #define _SPI_READY 0
00032 #define _RY 1
00033 #define _SMS_KEY 2
00034 #define _SD_CART 3
00035 
00036 //everdrive hardware registers
00037 #define SPI_PORT *((volatile u16*) (0xA13000))
00038 #define CFG_PORT *((volatile u16*) (0xA13002))
00039 #define VBL_PORT *((volatile u16*) (0xA13004))
00040 #define SRAM_BANK_PORT *((volatile u16*) (0xA13006))
00041 #define VER_PORT *((volatile u16*) (0xA13008))
00042 #define ROM_MAP_PORT *((volatile u16*) (0xA1300a))
00043 
00044 
00045 #define CFGC(bit)(cfg &= ~(1 << bit), CFG_PORT = cfg)
00046 #define CFGS(bit)(cfg |= (1 << bit), CFG_PORT = cfg)
00047 
00048 #define IS_RY (CFG_PORT & (1 << _RY))
00049 #define IS_SPI_READY (CFG_PORT & (1 << _SPI_READY))
00050 #define IS_SMS_KEY_PRESSED (CFG_PORT & (1 << _SMS_KEY))
00051 #define IS_SD_SLOT_EMPTY (CFG_PORT & (1 << _SD_CART))
00052 
00053 #define SPI_HI_SPEED_ON CFGS(_FULL_SPEED)
00054 #define SPI_HI_SPEED_OFF CFGC(_FULL_SPEED)
00055 
00056 #define SPI16_ON CFGS(_SPI16);
00057 #define SPI16_OFF CFGC(_SPI16);
00058 
00059 #define SS_ON CFGC(_SS)
00060 #define SS_OFF CFGS(_SS)
00061 
00062 #define CART_ON CFGC(_CART)
00063 #define CART_OFF CFGS(_CART)
00064 
00065 #define RAM_ON CFGS(_RAM_ON);
00066 #define RAM_OFF CFGC(_RAM_ON);
00067 
00068 #define VBL_CATCH_ON CFGS(_VBL_CATCH);
00069 #define VBL_CATCH_OFF CFGC(_VBL_CATCH);
00070 
00071 #define SPI_BUSY while(!IS_SPI_READY)
00072 #define EPR_BUSY while(!IS_RY)
00073 
00074 
00075 
00076 extern u16 cfg;
00077 
00078 
00079 //SD/MMC card initialization. should be run just one times, aer this cart will be ready for work
00080 //will return 0 success
00081 u8 evd_mmcInit();
00082 
00083 
00084 //read block (512b) from SD/MMC card. mmc_addr should be multiple to 512
00085 //will return 0 success
00086 u8 evd_mmcRdBlock(u32 mmc_addr, u8 *stor);
00087 
00088 
00089 //write block (512b) to SD/MMC card. mmc_addr should be multiple to 512
00090 //will return 0 success
00091 u8 evd_mmcWrBlock(u32 mmc_addr, u8 *data_ptr);
00092 
00093 
00094 //erase flash memry sector(64kb). rom_addr should be multiple to 64k.
00095 //code of this function should be placed in ram because rom memory inaccessible while erase process
00096 //WARNING! this function may damage cart bios if sectors in range 0 - 0x40000 will be erased
00097 void evd_eprEraseBlock(u32 rom_addr);
00098 
00099 
00100 //write data to flash memory. len should be multiple to 4.
00101 //each byte of flah memory should be erased before writeing by evd_eprEraseBlock
00102 //code of this function should be placed in ram because rom memory inaccessible while writeing process
00103 //WARNING! this function may damage cart bios if memory will be writen in area 0 - 0x40000
00104 void evd_eprProgBlock(u16 *data, u32 rom_addr, u32 len);
00105 
00106 
00107 //everdrive initialization.
00108 //def_rom_bank = 0 if app placed in 0-0x400000 area, 1 if in 0x400000-0x800000 arae
00109 //_is_ram_app = 0 if app assembled for work in rom, 1 if app assembleed for work in ram
00110 void evd_init(u16 def_rom_bank, u8 _is_ram_app);
00111 
00112 
00113 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines