wla BACKGROUND and OVERWRITE directives with pvsneslib

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
hoit
Posts: 28
Joined: Sun Dec 24, 2017 10:16 am

wla BACKGROUND and OVERWRITE directives with pvsneslib

Post by hoit »

Hi,

I try to develop with PVSnesLib (C library) and to change few parameters in header.

The library is build with this header file :

Code: Select all

;==LoRom==      ; We'll get to HiRom some other time.

.MEMORYMAP                      ; Begin describing the system architecture.
  SLOTSIZE $8000                ; The slot is $8000 bytes in size. More details on slots later.
  DEFAULTSLOT 0                 ; There's only 1 slot in SNES, there are more in other consoles.
  SLOT 0 $8000                  ; Defines Slot 0's starting address.
  SLOT 1 $0 $2000
  SLOT 2 $2000 $E000
  SLOT 3 $0 $10000
.ENDME          ; End MemoryMap definition

.ROMBANKSIZE $8000              ; Every ROM bank is 32 KBytes in size
.ROMBANKS 8                     ; 2 Mbits - Tell WLA we want to use 8 ROM Banks

.SNESHEADER
  ID "SNES"                     ; 1-4 letter string, just leave it as "SNES"

  NAME "LIBSNES DEFAULT CART "  ; Program Title - can't be over 21 bytes,
  ;    "123456789012345678901"  ; use spaces for unused bytes of the name.

  SLOWROM
  LOROM

  CARTRIDGETYPE $00             ; $00 = ROM only $02 = ROM+SRAM, see WLA documentation for others
  ROMSIZE $08                   ; $08 = 2 Mbits,  see WLA doc for more..
  SRAMSIZE $00                  ; $00 = No Sram, $01 = 16 kbits, see WLA doc for more..
  COUNTRY $01                   ; $01 = U.S.  $00 = Japan, that's all I know
  LICENSEECODE $00              ; Just use $00
  VERSION $00                   ; $00 = 1.00, $01 = 1.01, etc.
.ENDSNES

.SNESNATIVEVECTOR               ; Define Native Mode interrupt vector table
  COP EmptyHandler
  BRK EmptyHandler
  ABORT EmptyHandler
  NMI VBlank
  IRQ EmptyHandler
.ENDNATIVEVECTOR

.SNESEMUVECTOR                  ; Define Emulation Mode interrupt vector table
  COP EmptyHandler
  ABORT EmptyHandler
  NMI EmptyHandler
  RESET tcc__start                   ; where execution starts
  IRQBRK EmptyHandler
.ENDEMUVECTOR
When you create a new project using PVSneslib and try to change values in header, it doesn't work because .obj files from the library are embedded with .obj files of project which contains its own header too...

For example this one :

Code: Select all

;==LoRom==      ; We'll get to HiRom some other time.

.MEMORYMAP                      ; Begin describing the system architecture.
  SLOTSIZE $8000                ; The slot is $8000 bytes in size. More details on slots later.
  DEFAULTSLOT 0                 ; There's only 1 slot in SNES, there are more in other consoles.
  SLOT 0 $8000                  ; Defines Slot 0's starting address.
  SLOT 1 $0 $2000
  SLOT 2 $2000 $E000
  SLOT 3 $0 $10000
.ENDME          ; End MemoryMap definition

.ROMBANKSIZE $8000              ; Every ROM bank is 32 KBytes in size
.ROMBANKS 8                     ; 2 Mbits - Tell WLA we want to use 8 ROM Banks

.SNESHEADER
  ID "SNES"                     ; 1-4 letter string, just leave it as "SNES"

  NAME "LIBSNES HELLO WORLD  "  ; Program Title - can't be over 21 bytes,
  ;    "123456789012345678901"  ; use spaces for unused bytes of the name.

  ;FASTROM
  SLOWROM
  LOROM

  CARTRIDGETYPE $00             ; $00 = ROM only $02 = ROM+SRAM, see WLA documentation for others
  ROMSIZE $08                   ; $08 = 2 Mbits,  see WLA doc for more..
  SRAMSIZE $00                  ; $00 = No Sram, $01 = 16 kbits, see WLA doc for more..
  COUNTRY $01                   ; $01 = U.S.  $00 = Japan, that's all I know
  LICENSEECODE $00              ; Just use $00
  VERSION $00                   ; $00 = 1.00, $01 = 1.01, etc.
.ENDSNES

.SNESNATIVEVECTOR               ; Define Native Mode interrupt vector table
  COP EmptyHandler
  BRK EmptyHandler
  ABORT EmptyHandler
  NMI VBlank
  IRQ EmptyHandler
.ENDNATIVEVECTOR

.SNESEMUVECTOR                  ; Define Emulation Mode interrupt vector table
  COP EmptyHandler
  ABORT EmptyHandler
  NMI EmptyHandler
  RESET tcc__start                   ; where execution starts
  IRQBRK EmptyHandler
.ENDEMUVECTOR

So when you build the game, title is "LIBSNES DEFAULT CART " and not "LIBSNES HELLO WORLD " but it don't produce errors.
When you try to change more important parameters like SRAMSIZE, you get this error : CHECK_HEADERS: The object files are from different projects.

PVSneslib developer created a tool to change parameters on .sfc (snestool) file like game title but i think it is possible to do it directly with wla.

To explain it, i took the most simple sample : change game title (but my final goal is to change rom CPU speed to fastrom)

I read in wla documentation that we can use .BACKGROUND directive to "patch" the rom :

"Currently WLA can also be used as a patch tool. Just include the original
ROM image into the project with .BACKGROUND and insert e.g., OVERWRITE .SECTIONs
to patch the desired areas. Output the data into a new ROM image and there
you have it. 100% readable (asm coded) patches are reality!"


My new header should become :

Code: Select all

.MEMORYMAP                      ; Begin describing the system architecture.
  SLOTSIZE $8000                ; The slot is $8000 bytes in size. More details on slots later.
  DEFAULTSLOT 0                 ; There's only 1 slot in SNES, there are more in other consoles.
  SLOT 0 $8000                  ; Defines Slot 0's starting address.
  SLOT 1 $0 $2000
  SLOT 2 $2000 $E000
  SLOT 3 $0 $10000
.ENDME          ; End MemoryMap definition

.ROMBANKSIZE $8000              ; Every ROM bank is 32 KBytes in size
.ROMBANKS 8      

.BACKGROUND "hello_world.sfc"

OVERWRITE .SNESHEADER
  ID "SNES"                     ; 1-4 letter string, just leave it as "SNES"

  NAME "TEST OVERWRITE PARAM "  ; Program Title - can't be over 21 bytes,
  ;    "123456789012345678901"  ; use spaces for unused bytes of the name.

  SLOWROM
  LOROM

  CARTRIDGETYPE $00             ; $00 = ROM only $02 = ROM+SRAM, see WLA documentation for others
  ROMSIZE $08                   ; $08 = 2 Mbits,  see WLA doc for more..
  SRAMSIZE $00                  ; $00 = No Sram, $01 = 16 kbits, see WLA doc for more..
  COUNTRY $01                   ; $01 = U.S.  $00 = Japan, that's all I know
  LICENSEECODE $00              ; Just use $00
  VERSION $00                   ; $00 = 1.00, $01 = 1.01, etc.
.ENDSNES

.SNESNATIVEVECTOR               ; Define Native Mode interrupt vector table
  COP EmptyHandler
  BRK EmptyHandler
  ABORT EmptyHandler
  NMI VBlank
  IRQ EmptyHandler
.ENDNATIVEVECTOR

.SNESEMUVECTOR                  ; Define Emulation Mode interrupt vector table
  COP EmptyHandler
  ABORT EmptyHandler
  NMI EmptyHandler
  RESET tcc__start                   ; where execution starts
  IRQBRK EmptyHandler
.ENDEMUVECTOR

I build the .sfc file, then i try to do a news one with wla :
- the new header
E:\devkitsnes\bin\wla-65816 -io newhdr.asm newhdr.obj

- the new .sfc file but using newhdr.obj :
E:\devkitsnes\bin\wlalink -dsnov hello_world.obj data.obj newhdr.obj E:\pvsneslib\lib\crt0_snes.obj E:\pvsneslib\lib\libc.obj E:\pvsneslib\lib\libm.obj E:\pvsneslib\lib\libtcc.obj E:\snes-examples\hello_world/hello_world1.sfc

but it gives me :

E:\pvsneslib\lib\crt0_snes.obj:crt0_snes.asm: INSERT_SECTIONS: No room for section "Snes_Init" (143 bytes) in ROM bank 0.banks[s->bank] 32768, s->address 0x2

*** edit : i removed wrong investigations ! ***
i tried to build crt0_snes.obj with the new header but error is still the same

Do you have a solution to do it with wla or some explanations ?
Any help will be appreciated :)

Thanks
hoit
Posts: 28
Joined: Sun Dec 24, 2017 10:16 am

Re: wla BACKGROUND and OVERWRITE directives with pvsneslib

Post by hoit »

I checked other directives in wla documentation ( https://buildmedia.readthedocs.org/medi ... wla-dx.pdf ) and i thought to workarounds to do it like :

- .UNDEFINE at the first step of header (of game project) then to keep the rest (i hoped it will change existing values)

- Append in header of the lib .IFNDEF PVSNESLIB_DEBUG and define PVSNESLIB_DEBUG in the game header but without successful result.

it is a very restrictive issue and the last way i guess to do it is to link directly PVSNESLIB (and remove .obj files generated with it) in each project and use only the main header.asm but i find it is heavy... (i will not works in all cases)

so if anybody has other ideas..
Post Reply