SNES Hi/Fast ROM Header Problems

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
User avatar
LycanLambda
Posts: 3
Joined: Tue Aug 06, 2013 6:04 pm
Location: City 17

Re: SNES Hi/Fast ROM Header Problems

Post by LycanLambda »

Whoa, quite alot to digest. I understood a good bit, but most of it is still over my head to some degree, I'll bookmark this entire thread for future use :mrgreen:

Also, Bazz, I was quite the knucklehead in thinking "Oh Yeah It'll Be One Overclocked SNES With Fast/HiROM, Can't Wait!"...And now I realize the elegance and simplicity of LoRom. I've been reading through your tutorials along with the other's recommendations and cobbled together a standardized LoRom header for all my projects.

I think I'm still understanding the WLA DX's system of dividing memory up, but from what I garner, it works like this:


-Bank
_____-Slot
_________-Section

(With ORG defining the 16 bit address, and the sections stack ontop of each other if they are defined in the same slot/bank)

I've included in the zip of my test LoRom header with a PNG/XLS of my interpretation of the lorom memory map (Oh god I feel like a elementary school kid showing his teacher a macaroni sculpture :lol: ), so rip that apart if I got anything wrong (Along with the header)

Thanks an awful lot guys
Attachments
LoROM_Test_Header.zip
(13.13 KiB) Downloaded 65 times
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: SNES Hi/Fast ROM Header Problems

Post by bazz »

LycanLambda wrote:Whoa, quite alot to digest. I understood a good bit, but most of it is still over my head to some degree, I'll bookmark this entire thread for future use :mrgreen:

Also, Bazz, I was quite the knucklehead in thinking "Oh Yeah It'll Be One Overclocked SNES With Fast/HiROM, Can't Wait!"...And now I realize the elegance and simplicity of LoRom. I've been reading through your tutorials along with the other's recommendations and cobbled together a standardized LoRom header for all my projects.

I think I'm still understanding the WLA DX's system of dividing memory up, but from what I garner, it works like this:


-Bank
_____-Slot
_________-Section

(With ORG defining the 16 bit address, and the sections stack ontop of each other if they are defined in the same slot/bank)

I've included in the zip of my test LoRom header with a PNG/XLS of my interpretation of the lorom memory map (Oh god I feel like a elementary school kid showing his teacher a macaroni sculpture :lol: ), so rip that apart if I got anything wrong (Along with the header)

Thanks an awful lot guys
Yes, I was also allured by HiRom at the beginning,
You may Read up on WLA DX readme for information on .section
User avatar
Ramsis
Posts: 341
Joined: Sun Jul 01, 2012 6:44 am
Location: Lion's den :3
Contact:

Re: SNES Hi/Fast ROM Header Problems

Post by Ramsis »

LycanLambda wrote:Whoa, quite alot to digest. I understood a good bit, but most of it is still over my head to some degree, I'll bookmark this entire thread for future use :mrgreen:
Don't you give up on HiROM just yet! :P Once you understand the basic concept, along with its main difference as compared to LoROM, it's in fact not rocket science.

After fiddling around with my PowerPak code for some time, I managed to completely convert the project to HiROM. Works great! :)

Image

Some things you have to take care of when doing HiROM are dummy jumps (see the dev. manual, can't remember the page right now, but it's mentioned somewhere in there), like the one at the beginning of Vblank, as well as setting up the data bank register correctly.

You probably won't notice from the screenshot, but reworking the text engine has actually been the hardest part. It was definitely worth it, though. Thanks to a rewritten data bank access, my new text routine is able to process strings from anywhere within the ROM. :D

I'm not releasing the project as of now, but here's the ROM structure code in case you want to try again. Note the START_OFFSET define, which is crucial -- I'm not really sure why, but the ROM won't work at all if you set START_OFFSET to anything below $8000. Also, you need to change the DBR to $00 just before your initialization routine, and the latter should include a lda #$01 : sta $420D, which sets Memory-2 area to 3.58 MHz (FastROM).

Code: Select all

; ****************************** Defines *******************************

.BASE $C0

.DEFINE START_OFFSET    $F000

.EMPTYFILL              $FF


; ********************** ROM makeup, SNES header ***********************

.MEMORYMAP
        DEFAULTSLOT     0
        SLOTSIZE        $10000
        SLOT 0          $0000
.ENDME



.ROMBANKMAP
        BANKSTOTAL      8
        BANKSIZE        $10000                  ; ROM banks are 64 KBytes in size
        BANKS           8                       ; 8 ROM banks = 4Mbit
.ENDRO



.SNESHEADER                                     ; this also calculates ROM checksum & complement
        ID              "SNES"
        NAME            "RAMSIS' HIROM DEMO   "
        HIROM
        FASTROM
        CARTRIDGETYPE   $00
        ROMSIZE         $09
        SRAMSIZE        $00
        COUNTRY         $01
        LICENSEECODE    $33
        VERSION         $00
.ENDSNES



.BANK 0 SLOT 0
.ORG START_OFFSET + $FB0

        .DB             "00"                    ; new licensee code



; *************************** Vector tables ****************************

.SNESNATIVEVECTOR
        COP             EmptyHandler
        BRK             EmptyHandler
        ABORT           EmptyHandler
        NMI             VBlank
        UNUSED          $0000
        IRQ             EmptyHandler
.ENDNATIVEVECTOR



.SNESEMUVECTOR
        COP              EmptyHandler
        UNUSED           $0000
        ABORT            EmptyHandler
        NMI              EmptyHandler
        RESET            Startup
        IRQBRK           EmptyHandler
.ENDEMUVECTOR



.BANK 0 SLOT 0
.ORG START_OFFSET

.SECTION "EmptyVectors" SEMIFREE

EmptyHandler:
        rti

.ENDS



; ************************** Global variables **************************

        .INCLUDE "global_variables.asm"



; ********************** Library routines, macros **********************

.BANK 0 SLOT 0
.ORG 0

.SECTION "InitSNESCode" FORCE

        .INCLUDE "hirom_initsnes.inc.asm"

.ENDS



.SECTION "Joypads" SEMIFREE

        .INCLUDE "hirom_joypads.inc.asm"

.ENDS



.BANK 0 SLOT 0
.ORG START_OFFSET

.SECTION "ScreenSetup" SEMIFREE

        .INCLUDE "hirom_setup.inc.asm"          ; screen setup, Vblank, etc.

.ENDS



.SECTION "SpriteInit"

        .INCLUDE "hirom_sprites.inc.asm"

.ENDS



; **************************** Main program ****************************

.BANK 0 SLOT 0
.ORG START_OFFSET + $FA0

.SECTION "begin" FORCE

Startup:
        sei                                     ; disable interrupts
        clc
        xce                                     ; switch to native mode

        jml Main

.ENDS


.BANK 0 SLOT 0
.ORG 0

.SECTION "MainCode" SEMIFREE

        .INCLUDE "hirom_maincode.inc.asm"

        .INCLUDE "hirom_text.inc.asm"

.ENDS



; *************************** Graphics data ****************************

.BANK 1 SLOT 0
.ORG 0

.SECTION "CharacterData"

        .INCLUDE "hirom_gfxdata.inc"            ; sprites, fonts, palettes

.ENDS



; ****************************** Strings *******************************

.BANK 2 SLOT 0
.ORG 0

.SECTION "TextStrings"

        .INCLUDE "hirom_textstrings.inc"        ; raw text

.ENDS
Good luck, and have fun! :)
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: SNES Hi/Fast ROM Header Problems

Post by bazz »

Ramsis wrote:
LycanLambda wrote:but the ROM won't work at all if you set START_OFFSET to anything below $8000.
My guess is-in HiRom, ROM chunks are 64K, only the upper 32K chunks are mirrored into system banks 00-3f. Anything in 0000-7FFF must be coded differently to correctly operate.
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: SNES Hi/Fast ROM Header Problems

Post by koitsu »

What bazz said is correct.

It's not that hard to understand once you see the actual memory map layout for mode 21 ("hirom") and read the notes:

download/file.php?id=732&mode=view

You really don't have to "design" anything uniquely with mode 21 either, you just have to make sure that you choose to run your code out of banks $c0-ff if you want this. These banks also work for high speed mode.

Alternately you have the choice of running code in the $8000-ffff region out of banks $80-bf, which will allow you to use high speed mode in addition to being able to access registers without 24-bit addressing (i.e. sta $2100 while in bank $80 will do what you expect, while if in bank $c0 would require you to do sta $002100 (slower and operand length is longer)). But there is also a "clever trick" to accomplish this which Square and Enix both would regularly do: setting Direct Page (which is always in bank $00) to $2100 (ex. rep #$20 / lda #$2100 / tcd, allowing you to do things like sta $00 to tinker with register $2100, regardless of what bank you're in.

The part that's important to remember is that all the 65816 vectors are technically in bank $00 (that's where the 65816 looks for them in during power-up), which is why bank $c08000-c0ffff is mirrored as $008000-00ffff. You have to make sure the upper 32KByte of the first 64KByte of your image is also treated as "in bank $00 for the vectors". I can rephrase this a couple other ways if needed.

And don't forget what I said earlier in this thread about the need in your vector routines (ex. NMI, IRQ, RESET, etc.) to properly set the K register (a.k.a. "PCB" (PC Bank)) to the correct bank your NMI/IRQ/RESET code is in. It's your call though and entirely possible to design your vector routines to use long addressing exclusively or change the bank around as they need. Just saying, don't forget about this. :-)
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: SNES Hi/Fast ROM Header Problems

Post by koitsu »

Ramsis wrote:Note the START_OFFSET define, which is crucial -- I'm not really sure why, but the ROM won't work at all if you set START_OFFSET to anything below $8000.
The reason should become obvious once you read my previous post. :-)
User avatar
Ramsis
Posts: 341
Joined: Sun Jul 01, 2012 6:44 am
Location: Lion's den :3
Contact:

Re: SNES Hi/Fast ROM Header Problems

Post by Ramsis »

koitsu wrote:The reason should become obvious once you read my previous post. :-)
Indeed. :idea: Just had a look at dev. manual page 2-21-4 (i.e., the image you linked), and that says it all. Thanks a lot, koitsu! :D
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Post Reply