; assembler: asmotor git+87a91af ; command: `motorz80 -mcg -v -ogb-test.o gb-test.asmotor.txt && xlink -cngb -fngb -ogb-test.gb gb-test.o && rm -vf gb-test.o` ; ----------- constants --------- ROMBANK equ $2000 ; ----------- variables --------- section "WRAM", BSS ; for gameboy, this starts at $c000 automatically wCurrentBank:: db wTestVar:: db ; HRAM section "HRAM", HRAM hBuffer:: db ; ----------- macros --------- farcall: macro ld a, bank(\1) ld hl, \1 rst _bankswitch endm ; ----------- ints and rsts --------- section "rst 0", HOME[$00] _bankswitch:: jp Bankswitch ; although `ds ??` can be used here, ; i decided against it because it's not "dynamic" ; unfortunately that would also mean that `-z00` ; effectively means nothing since it'll ; be filled with $FF anyway. section "rst 8", HOME[$08] rst_08:: reti section "rst 10", HOME[$10] rst_10:: reti section "rst 18", HOME[$18] rst_18:: reti section "rst 20", HOME[$20] rst_20:: reti section "rst 28", HOME[$28] rst_28:: reti section "rst 30", HOME[$30] rst_30:: reti section "rst 38", HOME[$38] rst_38:: reti section "vblank", HOME[$40] _vblank:: jp VBlank section "lcdc", HOME[$48] _lcdc:: reti section "timer", HOME[$50] _timer:: reti section "serial", HOME[$58] _serial:: reti section "hilo", HOME[$60] _hilo:: reti section "highhome", HOME[$68] ; high home here section "entry", HOME[$100] entry:: nop jp Init ; nintendo logo ; handled by linker ; gameboy header section "header", HOME[$134] db "TEST ROM " db $00 ; cgb enabled db "ZU" ; new licensee code db $00 ; sgb enable db $12 ; cart type db $00 ; rom size db $00 ; ram size db $01 ; international db $33 ; use new code db $00 ; rom version db 0 ; header chksum (use another tool?) dw 0 ; global chksum (use another tool?) ; entry point Init:: ld a, 1 ld [wCurrentBank], a ;call Bank1Routine .purgatory halt nop jr .purgatory VBlank: reti Bankswitch: ldh [hBuffer], a ld a, [wCurrentBank] push af ldh a, [hBuffer] ld [wCurrentBank], a ld [ROMBANK], a call .jphl pop af ld [wCurrentBank], a ld [ROMBANK], a ret .jphl jp [hl] ; the braces are required section "part1", CODE, BANK[1] Bank1Routine: farcall Bank2Routine ret section "part2", CODE, BANK[2] Bank2Routine: ld a, 0 rept 5 ld [wTestVar], a inc a endr ret