; assembler: wla-dx v10.4 ; command: `wla-gb -o test.o gb-test.wladx.txt && echo -e '[objects]\ntest.o' > gb-test.wladx.link && wlalink -r gb-test.wladx.link gb-test.gb && rm -fv gb-test.wladx.link test.o` ; ----------- define ROM/RAM layout ----------- .memorymap slotsize $4000 ; sizeof banks slot 0 start 0 size $4000 name "home" ; home bank slot 1 start $4000 size $4000 name "romx" ; switchable banks slot 2 start $8000 size $4000 name "vram" slot 3 start $c000 size $4000 name "wram" slot 4 start $ff80 size $80 name "hram" defaultslot 0 ; use home as default .endme ; me too thanks .rombankmap bankstotal 3 banksize $4000 banks 3 .endro ; ----------- automatic headers ----------- .gbheader name "TEST ROM " cartridgetype $12 ramsize 0 .endgb .nintendologo ; ----------- constants ----------- .define ROMBANK $2000 ; ----------- macros ----------- .macro farcall ld a, bank(\1) ld hl, \1 rst $00 .endm ; ----------- ram allocations ----------- .struct TestStruct current_bank db ; 1 bytes long test_var dw ; 2 bytes long .endst .ramsection "stuff" slot "wram" .union WRAM ds $2000 .nextu ; defines the following: ; Work.current_bank ; Work.test_var ; _sizeof_Work ; _sizeof_Work.current_bank ; _sizeof_Work.test_var Work instanceof TestStruct .endu .union ; idk why I did it like this ECHO ds $2000 .endu .ends .ramsection "hram" slot "hram" buffer db ; 1 bytes long .ends ; ----------- interrupt and rst's ----------- .bank 0 slot "home" .org $0 .section "rst 0" size 8 force jp Bankswitch .ends .org $8 .section "rst 8" size 8 force reti .ends .org $10 .section "rst 10" size 8 force reti .ends .org $18 .section "rst 18" size 8 force reti .ends .org $20 .section "rst 20" size 8 force reti .ends .org $28 .section "rst 28" size 8 force reti .ends .org $30 .section "rst 30" size 8 force reti .ends .org $38 .section "rst 38" size 8 force reti .ends .org $40 .section "rst 40" size 8 force jp VBlank .ends .org $48 .section "rst 48" size 8 force reti .ends .org $50 .section "rst 50" size 8 force reti .ends .org $58 .section "rst 58" size 8 force reti .ends .org $60 .section "rst 60" size 8 force reti .ends .org $68 .section "hihome" force ; whatever you wanna put in high-home .ends ; ----------- entry point ----------- .org $100 .section "entry" force nop jp Init .ends .org $150 .section "main" force Init: ld a, 1 ld (Work.current_bank), a call Bank1Routine - halt nop jr - .ends .section "functions" VBlank: reti Bankswitch: ldh (buffer & $ff), a ld a, (Work.current_bank) push af ldh a, (buffer & $ff) ld (Work.current_bank), a ld (ROMBANK), a call + pop af ld (Work.current_bank), a ld (ROMBANK), a ret + jp hl .ends .bank 1 slot "romx" .section "bank1" Bank1Routine: farcall Bank2Routine ret .ends .bank 2 slot "romx" .section "bank2" Bank2Routine: ld a, 0 .rept 5 ld (Work.test_var), a inc a .endr ret .ends