Posted: Mon Nov 17, 2008 3:12 pm
I forgot about the lack of A0....
Sega Megadrive/Genesis development
http://gendev.spritesmind.net/forum/
This is probably a really noob question, but which document are you referring to exactly?Snake wrote: Yup, this is official sega banking hardware. It annoys me slightly that this stuff has become known as "SF2 banking" or "PS4 banking" when its clearly documented (and well enough that it didn't need to be redocumented) in sega manuals as standard hardware.
Code: Select all
set_cart_bank:
move.w #0x2700,sr /* disable ints */
andi.w #0x0007,d0 /* area */
add.w d0,d0
move.w 0xA15122,d1 /* COMM2 holds bank # */
andi.w #0x003F,d1
lea 0xA130F1,a0 /* bank control */
move.b #1,0xA15107 /* set RV */
move.b d1,0(a0,d0.w) /* set area to cart bank */
move.b #0,0xA15107 /* clear RV */
move.w #0,0xA15120 /* done */
move.w #0x2000,sr /* enable ints */
bra main_loop
Code: Select all
MARS_SYS_COMM2 = bank;
MARS_SYS_COMM0 = 0x0606; // set area 6 to bank N
while (MARS_SYS_COMM0) ;
MARS_SYS_COMM2 = bank + 1;
MARS_SYS_COMM0 = 0x0607; // set area 7 to bank N+1
while (MARS_SYS_COMM0) ;
That is great info, thanks.Chilly Willy wrote:The 32X devkit docs and examples. The 32X can also use the standard SEGA mapper, but you have to remember a couple things:
Only the 68000 can access the mapper, so if the SH2 needs a map register updated, you have to communicate with the 68000 to do that.
Like when accessing the sram, disable ints on the 68000, set the RV bit, set the mapper register, clear the RV bit, then enable ints. Make sure the code doing this is in ram to avoid any issues with the rom changing. I made an example of using the mapper with the SH2, playing 5 MB worth of PCM audio.
The main parts are:
68000 codeSH2 codeCode: Select all
set_cart_bank: move.w #0x2700,sr /* disable ints */ andi.w #0x0007,d0 /* area */ add.w d0,d0 move.w 0xA15122,d1 /* COMM2 holds bank # */ andi.w #0x003F,d1 lea 0xA130F1,a0 /* bank control */ move.b #1,0xA15107 /* set RV */ move.b d1,0(a0,d0.w) /* set area to cart bank */ move.b #0,0xA15107 /* clear RV */ move.w #0,0xA15120 /* done */ move.w #0x2000,sr /* enable ints */ bra main_loop
That shows the SH2 setting two different banks. As long as that code isn't in the bank area itself, you're okay. The first bank (512KB) can't be changed, so that shouldn't be a problem. You can only change banks 1 to 7, and the Neo Myth flash cart only supports changing banks 6 and 7, and only to a max of 10 banks (5MB). The Everdrive flash cart also only allows for 5MB, but I don't know which banks it allows you to change. The flash carts don't allow for the full range of what the SEGA mapper allows, only what is used by SSF2.Code: Select all
MARS_SYS_COMM2 = bank; MARS_SYS_COMM0 = 0x0606; // set area 6 to bank N while (MARS_SYS_COMM0) ; MARS_SYS_COMM2 = bank + 1; MARS_SYS_COMM0 = 0x0607; // set area 7 to bank N+1 while (MARS_SYS_COMM0) ;
Code: Select all
int bank = 8; // want to switch to area 8
MARS_SYS_COMM2 = bank;
MARS_SYS_COMM0 = 0x0606; // set area 6 to bank 8
while (MARS_SYS_COMM0) ;
// read image , data or sounds from the address for area 6
and he explained using the bankswitch as always switiching 1 MB to 0x900000 (or is that a typo):32X Cartridges...
When accessing the cartridge from the 68k and sh2, the sh2 gets to access it first. The
68k can only access cartridge rom from the bank areas. The 68k does not have full view
of the rom. The sh2 does not need any banking areas, and it has full view of the rom.
0x04.w Cartridge Bankswitching
-------------------------------
Write: Bits 0-1: Determines which 1 mb long cartridge ROM bank will appear at
0x900000-0x9FFFFF on the 68k. Each bank is one megabyte long.
Bankswitching Example Values (FOR THE 68k !!!)
0x0000: 0x900000-0x9FFFFF appears as 0x000000-0x0FFFFF ROM
0x0001: 0x900000-0x9FFFFF appears as 0x100000-0x1FFFFF ROM
0x0002: 0x900000-0x9FFFFF appears as 0x200000-0x2FFFFF ROM
0x0003: 0x900000-0x9FFFFF appears as 0x300000-0x3FFFFF ROM
Read: Reflects the bank that is set
Bank is an int between 0 and 9 (ten banks to make 5MB of rom).ammianus wrote: That is great info, thanks.
In your SH2 example, what is the type and value of "bank"? just an integer to represent an area?
As mentioned earlier, the rom space of 4MB is split into 8 512KB sections. The first section cannot be changed, while all the rest can be set to any value from 0 to (# banks - 1). While the SEGA mapper allows up to 63 (32MB), flash carts currently only allow up to 9 since the biggest game ever made was 5 MB. At some point someone may make a cart that allows for the full range.So there are banking "areas", is this right?
RegionsDoes each of the 0-8 areas have a fixed address? e.g. area 6 = 0x600000 ?
Yes, that's all correct... unless you set the RV bit. While RV is set, the rom appears to the 68000 at the "normal" location. When RV is not set, the first 512KB of the rom space actually appears at 0x880000 to 0x8FFFFF. That is fixed and cannot be changed. If you run 68000 code from the rom in a 32X game, it should probably be in that space.Also, reading through Devster's 32X guide, is this true?and he explained using the bankswitch as always switiching 1 MB to 0x900000 (or is that a typo):32X Cartridges...
When accessing the cartridge from the 68k and sh2, the sh2 gets to access it first. The
68k can only access cartridge rom from the bank areas. The 68k does not have full view
of the rom. The sh2 does not need any banking areas, and it has full view of the rom.0x04.w Cartridge Bankswitching
-------------------------------
Write: Bits 0-1: Determines which 1 mb long cartridge ROM bank will appear at
0x900000-0x9FFFFF on the 68k. Each bank is one megabyte long.
Bankswitching Example Values (FOR THE 68k !!!)
0x0000: 0x900000-0x9FFFFF appears as 0x000000-0x0FFFFF ROM
0x0001: 0x900000-0x9FFFFF appears as 0x100000-0x1FFFFF ROM
0x0002: 0x900000-0x9FFFFF appears as 0x200000-0x2FFFFF ROM
0x0003: 0x900000-0x9FFFFF appears as 0x300000-0x3FFFFF ROM
Read: Reflects the bank that is set
Code: Select all
00000100 53 45 47 41 20 53 53 46 20 20 20 20 20 20 20 20 |SEGA SSF |
..
00300000 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
..
00400000 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
Code: Select all
move.b #1, 0xA15107 | set RV
move.b #3, 0xA15105 | select MB3 => page6&7
move.w #0xc000, 0xA130F0 | Mapper control p+32x bit
move.w #1, 0xA130e6 | everdrive io control bit?
move.w #0x0001, 0xA130F2
move.w #0x0002, 0xA130F4
move.w #0x0003, 0xA130F6
move.w #0x0004, 0xA130F8
move.w #0x0005, 0xA130Fa
move.w #0x0008, 0xA130Fc | this should now be MB4
move.w #0x0007, 0xA130Fe
move.b #0, 0xA15107 | clear RV
Code: Select all
lea 0x900000, a0 | switchable ROM area
move.w (a0), d0
The misleading thing might be the odd/even addressing used.Your bank writes goes to high byte (D8....D15), you'll have to do MOVE.W #$bb00, ($A130xx) where bb is your bank number to get the number go to low byte (D0...D7) which the mapper responds to. Little-endian vs Big-Endian business.
Code: Select all
move.w #0x0002, 0xA130F4
Code: Select all
move.b #0, #0xA130F4
move.b #2, #0xA130F5
Code: Select all
#define SSF_REG16(reg) *((volatile u16 *)(0xA13000 + reg))
#define REG_SSF_CTRL 0xF0
void ssf_set_rom_bank(u8 bank, u8 val) {
SSF_REG16(REG_SSF_CTRL + bank * 2) = val;
}
Code: Select all
add.w d0,d0
lea 0xA130F1,a0 /* bank control */
move.b d1,0(a0,d0.w) /* set area to cart bank
the unset is also there but its hidden (code section has a scrollbar)You set RV, but do you unset it afterwards? You should also have ints disabled around setting these registers unless you can guarantee that it won't disturb any ints and/or won't be disturbed by ints.
Code: Select all
move.w #0x2700, sr
...
move.w #0x2000, sr