Okay, now let's look at the flash cart. These follow the "standard" GBA flash cart rules - you have two spaces: a flash space, and an sram space. Without an ASIC, you can have up to 32MB of flash and 128KB of sram. Flash carts usually have an ASIC to allow you to have more flash or sram, and to add extra features. The ASIC is controlled by special accesses to flash space.
The Neo2 flash carts used with the Neo Myth follows the above description. The extras you get are RTCs, a 16 bit DMA channel, 8Kbit cache, a battery monitor, 16Mbit of "menu" flash, and 256 to 1024 Mbit of "game" flash. In addition, the Neo2-SD has only 256Mbit of game flash while adding 128 Mbit of "zip" ram and an SD card interface.
To control the Neo2 ASIC, you do an access to flash space where the address lines set an address and the data. Obviously, there must be a way to distinguish real flash accesses from ASIC commands. You do this by first doing a series of accesses which will never occur in the course of "real" flash accesses. This "unlocking" sequence then is followed by whatever command you need to do.
The unlocking sequence of the Neo2 is:
NEO2_ASIC_COMMAND( 0xff, 0xd200 );
NEO2_ASIC_COMMAND( 0x00, 0x1500 );
NEO2_ASIC_COMMAND( 0x01, 0xd200 );
NEO2_ASIC_COMMAND( 0x02, 0x1500 );
NEO2_ASIC_COMMAND( 0xfe, 0x1500 );
where the first value is the address, and the second is the data value. The Neo2 takes the data on A0 to A15 in the flash space, and the address on A16 to A23 in the flash space. This will be shifted up one on the MD space as the bus is a word wide. Also, the bank registers must be set for the upper bits since the space in the MD map is limited as discussed in the previous post. So the procedure to do an ASIC operation on the Neo Myth is to set GBAC_LIO to the msn of the address, and then read the rom address equal to the lsn of the address plus the data, shifted left one.
There are three control/status registers in the flash cart ASIC: CR, CR1, and IOSR.
CR = control register 0
b15 = 1 = set RTC via writes to sram space at offsets 0x000 to 0x700, set GTC via writes to sram space at offsets 0x800 to 0xC00.
b14 = ?
b13 = 1 = enable writing to flash
b12 = ?
b11 = 1 = CS delay enable
b10 = 1 = SD card interface enable (if present)
b9 = 1 = select game flash, 0 = select menu flash
b8 = ?
b7 = 1 = SD card interface enable (if present)
b6 = ?
b5 = ?
b4 = ?
b3 = ?
b2 = ?
b1 = ?
b0 = ?
Notes: b1-b0 usually set. b10 and b7 probably control different parts of the SD interface.
CR1 = control register 1
Not much is known other than the data value 0x0630 is written to CR1 to enable 1Gbit flash size.
IOSR = I/O status (and control) register
b3-b0 = direction control for bits b7-b4. 1 = output, 0 = input
b4 = SD Detect. This is an input which indicates if an SD card is present.
b5 = Menu flash IO. This is an input.
b6 = IR IO. This is an output.
b7 = Menu flash IO. This is an input.
b8 = PSRAM enable (if has zip ram)
b11-9 = 111 = enable game flash, 000 = enable menu flash
b12 = IR enable (if has IR port)
b13 = 1 = enable game flash if type 0 flash, 0 if type 1
b14 = ?
b15 = 1 = enable game flash, 0 = enable menu flash
All the bits associated with game flash and menu flash are not know precisely. For example, b11-9 probably all enable different things, we just know they all need to be set for game flash, and cleared for the menu flash. Likewise, the difference between type 0 and type 1 flash isn't known.
Commands:
NEO2_ASIC_COMMAND( 0x37, value ) = set CR
NEO2_ASIC_COMMAND( 0xEE, value ) = set CR1
NEO2_ASIC_COMMAND( 0xDA, value ) = set IOSR
NEO2_ASIC_COMMAND( 0xC4, bank ) = set game flash bank
NEO2_ASIC_COMMAND( 0xE0, bank ) = set sram bank
NEO2_ASIC_COMMAND( 0xE2, value ) = set flash sram/psram options
NEO2_ASIC_COMMAND( 0x90, value ) = set ID mode
ID mode is how you identify the Neo2 ASIC, and how you access the goodies inside it. When you set ID mode to a value of 0x3500, you allow reading the goodies through the sram space. Some (like the cache) can also be written. The goodies are at offsets:
#define NEO2_MAGIC_OFFS 0
#define NEO2_VOLTAGE_BYTE_OFFS 5
#define NEO2_CONSOLE_VOLTAGE_BYTE_OFFS 6
#define NEO2_RTC_1_SEC_4BIT_OFFS 0x4000
#define NEO2_RTC_10_SEC_3BIT_OFFS 0x4100
#define NEO2_RTC_1_MIN_4BIT_OFFS 0x4200
#define NEO2_RTC_10_MIN_3BIT_OFFS 0x4300
#define NEO2_RTC_HOUR_5BIT_OFFS 0x4400
#define NEO2_RTC_DAY_LO_4BIT_OFFS 0x4500
#define NEO2_RTC_DAY_MD_4BIT_OFFS 0x4600
#define NEO2_RTC_DAY_HI_4BIT_OFFS 0x4700
#define NEO2_GTC_1_MIN_4BIT_OFFS 0x4800
#define NEO2_GTC_10_MIN_3BIT_OFFS 0x4900
#define NEO2_GTC_HOUR_5BIT_OFFS 0x4a00
#define NEO2_GTC_DAY_LO_4BIT_OFFS 0x4b00
#define NEO2_GTC_DAY_HI_4BIT_OFFS 0x4c00
#define NEO2_CR1_16BIT_REG_OFFS 0x8040
#define NEO2_GAME_SRAM_DEV_ID_OFFS 0x8050
#define NEO2_CR_16BIT_REG_OFFS 0x8070
#define NEO2_IOSR_16BIT_REG_OFFS 0x8080
#define NEO2_GAME_FLASH_BANK_OFFS 0x8090
#define NEO2_GAME_SRAM_BANK_OFFS 0x80A0
#define NEO2_CACHE_OFFS 0xC000 // offset of NEO2 inner cache into SRAM
At offset 0 is the MAGIC value that tells you this is a Neo2 flash cart. It is 0x34, 0x16, 0x96, 0x24, and 0xF6.
At offset 5 is the current battery voltage for the flash cart. 0 is <= 0.8V, up to 63 which is 3.3V.
At offset 6 is the current voltage from the console. It is the same as the battery voltage.
At offset 0x4000 to 0x4700 is the main RTC.
At offset 0x4800 to 0x4C00 is a more limited RTC, probably meant for in-game time tracking.
Offsets 0x8070, 0x8040, and 0x8080 allow you to read the current contents of CR, CR1, and IOSR respectively. These are read one bit at a time from b0 of the offset given, to the offset + 15.
You can read the device ID of the SRAM in the flash cart through offset 0x8050 to 0x805F.
You can read the current flash and sram bank through offsets 0x8090 to 0x809F and 0x80A0 to 0x80AF.
There is an 8 Kbit (1 KB) cache in the ASIC that is at offset 0xC000 to 0xC3FF. You can read/write the cache directly a byte at a time. You don't have to do the bit-at-a-time like the registers above.
You disable ID mode by setting ID mode to value 0x4900.
The set flash sram/psram options take the following values:
0x1500 = psram write enable
0xD200 = psram write disable
0xDD00 = fat sram write enable
0x3900 = fat sram write disable
0x7E00 = fat sram read enable
0x9400 = fat sram read disable
I think "fat" sram read/write means it's a word wide instead of a byte wide.
You might wonder what the sram and flash bank registers are for - well, the GBA cart spec only allows for 16 address lines for sram space, and only 24 address lines for flash space. That limits the amount of flash or sram addressable as mention way back at the top of this post. Since flash carts tend to have more than that, you have to bank select the flash and sram to access it all. Considering the current Neo Flash menu doesn't bother, I think there will be problems trying to run games beyond the limits of the first bank of flash and sram.
EDIT: On further reflection, when CR1 is set to 0x0630, the comment is "SET 1G ROM". Further, EXTM_ON is then set to 0xFFFF with a comment on enabling A24 and A25. Even further, the high bank register holds A24 to A27. All that leads me to believe that the Neo2 flash cart has optional extra address lines for the flash space - enough for 1Gbit addressing. It must be enabled in the flash ASIC through CR1, and then the extra lines enabled through the Neo Myth ASIC by setting EXTM_IO. So I believe there's no problem addressing all the game flash in the menu. However, I don't see something similar for the sram. So maybe some of the sram issues people have been having in other threads are due to which bank the sram is set to in the menu entry. If it's within 128KB, it works, otherwise it fails.
EDIT: 2009/11/12 - Added more info about IOSR