Cartridge bigger than 32Mbits ?

Ask anything your want about the 32X Mushroom programming.

Moderator: BigEvilCorporation

User avatar
TmEE co.(TM)
Very interested
Posts: 2296
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Mon Nov 17, 2008 3:12 pm

I forgot about the lack of A0....
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

ammianus
Very interested
Posts: 123
Joined: Sun Jan 29, 2012 2:10 pm
Location: North America
Contact:

Post by ammianus » Sat Feb 04, 2012 9:00 pm

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.
This is probably a really noob question, but which document are you referring to exactly?
Last edited by ammianus on Sun Feb 05, 2012 11:48 am, edited 1 time in total.

Chilly Willy
Very interested
Posts: 2550
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat Feb 04, 2012 11:03 pm

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 code

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
SH2 code

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 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.

ammianus
Very interested
Posts: 123
Joined: Sun Jan 29, 2012 2:10 pm
Location: North America
Contact:

Post by ammianus » Sun Feb 05, 2012 12:57 pm

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 code

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
SH2 code

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 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.
That is great info, thanks.

In your SH2 example, what is the type and value of "bank"? just an integer to represent an area?

So there are banking "areas", is this right?

0 - can't change
1 - 5 areas that could be changed, but not w/ neo myth cart?
6 - 7 areas can be changed w/ neo myth
8 - 9 other areas you can switch into 6 -7?
[10 - N] possible areas not supported by carts?

Does each of the 0-8 areas have a fixed address? e.g. area 6 = 0x600000 ?

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

ammianus
Very interested
Posts: 123
Joined: Sun Jan 29, 2012 2:10 pm
Location: North America
Contact:

Post by ammianus » Sun Feb 05, 2012 1:07 pm

Also, reading through Devster's 32X guide, is this true?
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.
and he explained using the bankswitch as always switiching 1 MB to 0x900000 (or is that a typo):
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

Chilly Willy
Very interested
Posts: 2550
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Feb 05, 2012 8:19 pm

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?
Bank is an int between 0 and 9 (ten banks to make 5MB of rom).

So there are banking "areas", is this right?
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.
Does each of the 0-8 areas have a fixed address? e.g. area 6 = 0x600000 ?
Regions
0 = 0x000000 - 0x07FFFF
1 = 0x080000 - 0x0FFFFF
2 = 0x100000 - 0x17FFFF
3 = 0x180000 - 0x1FFFFF
4 = 0x200000 - 0x27FFFF
5 = 0x280000 - 0x2FFFFF
6 = 0x300000 - 0x37FFFF
7 = 0x380000 - 0x3FFFFF

The SEGA mapper allows regions 1 to 7 to be changed. The NeoMyth only allows you to change regions 6 and 7. I don't know which regions the Everdrive allows, but to be compatible, it cannot change 0 and must also allow changes to 6 and 7.
Also, reading through Devster's 32X guide, is this true?
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.
and he explained using the bankswitch as always switiching 1 MB to 0x900000 (or is that a typo):
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
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 while RV is not set, the 68000 can reach the rest of the rom space by using a single bank at 0x900000 to 0x9FFFFF. That bank can be set to any 1MB offset inside the rom space as shown by the bankswitching table above. That is to reach the ROM SPACE - once you reach that rom space, the actual rom location is determined by the mapper as explained at the very top. So there are TWO bank switching mechanisms you need to deal with on the 32X - the bank for the 68000 while RV is not set, and the banks handled by the mapper in the cart itself.

maxwell_ln
Newbie
Posts: 3
Joined: Tue Jan 16, 2018 9:10 pm

Re: Cartridge bigger than 32Mbits ?

Post by maxwell_ln » Tue Jan 16, 2018 9:36 pm

ok i guess Im somewhat late to the party but here goes

Im trying to create a 5MB 32x-ROM that will work on my Everdrive (OS10-unstable, mapper:OS)

I have updated the ROM header to have SSF and placed a byte at the 3 and 4MB mark

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  |................|
the init code on the MD (runs from RAM area)

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
---
part of the not working code ( returns 1 instead of 2)

Code: Select all

         lea	 0x900000, a0	| switchable ROM area
 	 move.w (a0), d0
so basicly it just did nothing and returned the byte from page6 instead of page8

as a second test tried to read at 0x22300000 from the SH2 and also got page6 there.

anyone a hint on what is missing?

User avatar
TmEE co.(TM)
Very interested
Posts: 2296
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Cartridge bigger than 32Mbits ?

Post by TmEE co.(TM) » Tue Jan 16, 2018 10:18 pm

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.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Chilly Willy
Very interested
Posts: 2550
Joined: Fri Aug 17, 2007 9:33 pm

Re: Cartridge bigger than 32Mbits ?

Post by Chilly Willy » Wed Jan 17, 2018 3:41 am

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.

maxwell_ln
Newbie
Posts: 3
Joined: Tue Jan 16, 2018 9:10 pm

Re: Cartridge bigger than 32Mbits ?

Post by maxwell_ln » Wed Jan 17, 2018 4:58 pm

wow these are some fast replies :)
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.
The misleading thing might be the odd/even addressing used.

Code: Select all

move.w #0x0002, 0xA130F4
should do the same thing as:

Code: Select all

move.b #0, #0xA130F4
move.b #2, #0xA130F5
Used the word-writes here because thats how the everdrive ssf-ex-sample does it.

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;
}
i also tried byte-writes on odd addresses similar to chillywilly`s (Neo Myth?) example.

Code: Select all

    add.w   d0,d0
    lea     0xA130F1,a0         /* bank control */
    move.b  d1,0(a0,d0.w)       /* set area to cart bank
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.
the unset is also there but its hidden (code section has a scrollbar)

I also tried putting some interrupt code around it but that does not do much here i guess

Code: Select all

move.w  #0x2700, sr
...
move.w  #0x2000, sr

not sure what to try next

Chilly Willy
Very interested
Posts: 2550
Joined: Fri Aug 17, 2007 9:33 pm

Re: Cartridge bigger than 32Mbits ?

Post by Chilly Willy » Wed Jan 17, 2018 9:19 pm

You shouldn't be writing to 0xA130E6 unless you're trying to use the SD or USB. Also, how are you determining what is being read? Maybe it's working, but you're not displaying the value correctly to see it's working.

maxwell_ln
Newbie
Posts: 3
Joined: Tue Jan 16, 2018 9:10 pm

Re: Cartridge bigger than 32Mbits ?

Post by maxwell_ln » Thu Jan 18, 2018 6:21 pm

ok solved it! This is somewhat embarrassing but i thought i should share it anyway.

when updating to the new MEGAOS.bin (v10) i should also have updated to the new mega-usb.exe for some reason.

I was trying to deploy with version 1.1 and that does somehow not work with bigger roms. When deploying with v2.0 (linky) the code works fine.

Chilly Willy
Very interested
Posts: 2550
Joined: Fri Aug 17, 2007 9:33 pm

Re: Cartridge bigger than 32Mbits ?

Post by Chilly Willy » Thu Jan 18, 2018 7:08 pm

A quick look at the source shows v1.x doesn't look for "SSF" in the rom header when setting the options. v2 does. Thanks for posting about it. It may help someone else later, and let's us know we weren't crazy as your code looked fine. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest