;=============
vec_vblank:
push_all
-
+ call vblank
pop_all
reti
pop bc
pop af
#endmacro
+
+; relative jump: jr <label> RELB
+#define REL - $ - 2 & 0xFF
#include "hw.inc"
#include "macros.inc"
+#include "oam.s"
+#include "wram.s"
.org 0x0
#include "jmp.inc"
#include "header.inc"
entry:
+ call disableinterrutpts
+
+ call mem_init
+
call lcd_off
call copy_tiles
call lcd_on
+ call enableinterrupts
+
main:
@forever:
jp @forever
#include "tiles.inc"
#include "video.s"
#include "mem.s"
+#include "strings.s"
+#include "sys.s"
; fill bank
.fill 0, 0x7FFF - $
+mem_init:
+ ; clear wram
+ ld a, 0
+ ld hl, WRAM
+ ld bc, WRAMLEN
+ call memset
+
+ ; copy shadow oam dma function
+ ld de, shadow_oam_to_oam
+ ld hl, OAMDMAFN
+ ld bc, shadow_oam_to_oam_end - shadow_oam_to_oam
+ call memcpy
+ ret
+
; copies memory from one location to another
; inputs:
; de: source
; hl: destination
; bc: length
memcpy:
- @loop:
+@loop:
ld a, [de]
ld [hl+], a
jp nz, @loop
ret
+
+ ; sets a memory location to a specific value
+ ; inputs:
+ ; hl: destination
+ ; bc: length
+ ; d: value
+memset:
+@loop:
+ ld a, d
+ ld [hl+], a
+
+ dec bc
+ ld a, b
+ or a, c
+ jp nz, @loop
+ ret
+
+
+; dma shadow oam to oam
+; registers:
+; hl, af, bc, de
+shadow_oam_to_oam:
+ ld a, shadow_oam >> 8
+ ldh [DMA], a
+ ld a, 40 ; 160-cycle wait
+@wait:
+ dec a
+ jr nz, @wait REL
+ ret
+shadow_oam_to_oam_end:
--- /dev/null
+; oam memory layout
+.se 0
+.de oamy, 1
+.de oamx, 1
+.de oamchr, 1
+.de oamflag, 1
+.de oamsize, 0
--- /dev/null
+; map ascii values to the actual tileset here
+.rep i, 10, 1, .scc i + '0' = i
+.rep i, 26, 1, .scc i + 'a' = i + 10
+.rep i, 26, 1, .scc i + 'A' = i + 10
+
+; map space to empty tile
+.scc 0x20 = 0x30
+
+STR_TITLE:
+.str "game"
+.db 0
--- /dev/null
+nohandler:
+ ret
+
+panic:
+ ret
+
+enableinterrupts:
+ ; enable interrupts
+ ld a, IVBLANK
+ ld [IE], a
+ ei
+ ret
+
+disableinterrutpts:
+ ld a, 0
+ ld [IE], a
+ di
+ ret
+; vblank handler
+vblank:
+ call OAMDMAFN
+
+ ret
+
vblank_wait:
ld a, [RLY]
cp a, 144
ret
lcd_on:
- ld a, LCDCF_ON | LCDCF_BGON
+ ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON
ld [RLCD], a
ret
+ ; copies tilest0 and tileset1 to
+ ; vram
copy_tiles:
ld de, tileset0
ld hl, VRAM
--- /dev/null
+#define WRAM 0xC000
+#define WRAMLEN 0xFFF
+.org WRAM
+
+.def int OAMDMAFN = 0xFF80
+
+shadow_oam: .adv OBJSMAX * oamsize