== Writing the Header ==

Before writing your actual program's code, you need a header to describe WLA
the SNES' memorymap. This is basically just a file you will include into your
source. It contains all of the basic information about your ROM. The following
is a basic header file for a 2 Mbit ROM. Look at the comments beside each line
for a brief explanation of that line. I will provide a better explanation
after revealing the code.

If you do not know how the memory in the SNES is organized, just sit tight.
Right now you just need to know that there are a couple different ways game
cartridges organize the memory. We'll be making a LoRom program, where our
game ROM will be from $8000-$FFFF in banks $00-$07 (2 Mbit size). You can form
up to 24-bit addresses in the SNES, and the bank number is the first 8 bits.
Hope you got that. Email me if you need help. The first steps into the SNES
are bumpy.

;------------------------------ Header File ---------------------------------
;   This is basically a combo of MarctheMER's and Neviksti's header files
; Perhaps reading their's will also help your understanding of the header,
; but I believe this will be the simplest method of defining your header,
; as Marc's doesn't provide a full explanation, and Neviksti's can be
; a bit more difficult for beginners (using the WLA directives is easier).
;----------------------------------------------------------------------------

;==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                  ; Define's Slot 0's starting address.
.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 "SNES Program Name    "  ; Program Title - can't be over 21 bytes,
  ;    "123456789012345678901"  ; use spaces for unused bytes of the name.

  SLOWROM
  LOROM

  CARTRIDGETYPE $00             ; $00 = ROM only, see WLA documentation for others
  ROMSIZE $08                   ; $08 = 2 Mbits,  see WLA doc for more..
  SRAMSIZE $00                  ; No SRAM         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 EmptyHandler
  IRQ EmptyHandler
.ENDNATIVEVECTOR

.SNESEMUVECTOR                  ; Define Emulation Mode interrupt vector table
  COP Emptyhandler
  ABORT EmptyHandler
  NMI EmptyHandler
  RESET Start
  IRQBRK EmptyHandler
.ENDEMUVECTOR

.BANK 0 SLOT 0                  ; Defines the ROM bank and the slot it is inserted in memory.
.ORG 0                          ; .ORG 0 is really $8000, because the slot starts at $8000
.SECTION "EmptyVectors" SEMIFREE

EmptyHandler:
        rti

.ENDS

.EMPTYFILL $00
;---------------------------------- END -------------------------------------

What we basically just did was write a file which told the assembler about
the SNES' memory organization. We also provided some information about our
program, such as the ROM size. Now I will walk through the code. Skip over
anything you already understand.

.MEMORYMAP

SLOTSIZE $8000 DEFAULTSLOT 0 SLOT 0 $8000 .ENDME - Ends the .MEMORYMAP directive.

.ROMBANKSIZE $8000 - comment says it all.
.ROMBANKS 8 - comment says it all.

.SNESHEADER

.ENDSNES - End the .SNESHEADER header definition.

.SNESNATIVEVECTOR

.ENDNATIVEVECTOR

.SNESEMUVECTOR

.BANK 0 SLOT 0 .ORG 0 .SECTION "EmptyVectors" SEMIFREE .EMPTYFILL $00 Well that is your basic LoRom header file!!! I really described the whole file
to make sure you are understanding it. Try writing it out yourself, and then
save it as header.inc or something.inc. This will gave you some basic practice
and memorization. The next tutorial will focus on an ACTUAL SNES PROGRAM!

back