Initial setup for engine
authorLukas Krickl <lukas@krickl.dev>
Tue, 1 Oct 2024 08:05:20 +0000 (10:05 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 1 Oct 2024 08:05:20 +0000 (10:05 +0200)
src/jmp.inc
src/macros.inc
src/main.s
src/mem.s
src/oam.s [new file with mode: 0644]
src/strings.s [new file with mode: 0644]
src/sys.s [new file with mode: 0644]
src/video.s
src/wram.s [new file with mode: 0644]

index 2a8501d1acc8cccceee4cf1c9fd480498cf0ae21..f6f0d18c45d564081b5af4726214c1d60039e302 100644 (file)
@@ -15,7 +15,7 @@ rst_panic:
 ;=============
 vec_vblank:
   push_all 
-  
+  call vblank  
   pop_all
 
   reti
index b4e7f0ce9a0e68b4f2ef6ca33cbea467d531bb2a..e7686387e32e0bf1efb470682c818d354344b3b0 100644 (file)
@@ -11,3 +11,6 @@
   pop bc
   pop af
 #endmacro
+
+; relative jump: jr <label> RELB 
+#define REL - $ - 2 & 0xFF 
index 870aafc767a35374a433573e6669e8a26a7277c2..604bbc4761192e2b088ac2c3683f2f974ca439b8 100644 (file)
@@ -1,5 +1,7 @@
 #include "hw.inc"
 #include "macros.inc"
+#include "oam.s"
+#include "wram.s"
 
 .org 0x0
 #include "jmp.inc"
@@ -7,10 +9,16 @@
 #include "header.inc"
  
 entry: 
+  call disableinterrutpts
+  
+  call mem_init 
+
   call lcd_off
   call copy_tiles
   call lcd_on
 
+  call enableinterrupts
+
 main:
 @forever:
   jp @forever 
@@ -18,6 +26,8 @@ main:
 #include "tiles.inc"
 #include "video.s"
 #include "mem.s"
+#include "strings.s"
+#include "sys.s"
 
 ; fill bank
 .fill 0, 0x7FFF - $
index 97315cc0bfee638a670b3bb814cd78c82f154f30..4a9dbdd4e7e8d6f83589fb2658556c5e7256a440 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -1,10 +1,24 @@
+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
 
@@ -15,3 +29,33 @@ memcpy:
   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:
diff --git a/src/oam.s b/src/oam.s
new file mode 100644 (file)
index 0000000..b71df91
--- /dev/null
+++ b/src/oam.s
@@ -0,0 +1,7 @@
+; oam memory layout 
+.se 0
+.de oamy, 1
+.de oamx, 1
+.de oamchr, 1
+.de oamflag, 1
+.de oamsize, 0
diff --git a/src/strings.s b/src/strings.s
new file mode 100644 (file)
index 0000000..eecbd24
--- /dev/null
@@ -0,0 +1,11 @@
+; 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
diff --git a/src/sys.s b/src/sys.s
new file mode 100644 (file)
index 0000000..f058b4b
--- /dev/null
+++ b/src/sys.s
@@ -0,0 +1,18 @@
+nohandler:
+  ret
+
+panic:
+  ret
+
+enableinterrupts:
+  ; enable interrupts 
+  ld a, IVBLANK
+  ld [IE], a
+  ei 
+  ret
+
+disableinterrutpts:
+  ld a, 0
+  ld [IE], a
+  di
+  ret
index 560114195e29ea24e2ba0a14a7dbb66726ec9247..7aa2bf9ee54b4b92b16e7b732f257644963216ab 100644 (file)
@@ -1,3 +1,9 @@
+; vblank handler
+vblank:
+  call OAMDMAFN
+
+  ret
+
 vblank_wait:
   ld a, [RLY] 
   cp a, 144
@@ -15,11 +21,13 @@ lcd_off:
   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 
diff --git a/src/wram.s b/src/wram.s
new file mode 100644 (file)
index 0000000..589dcfa
--- /dev/null
@@ -0,0 +1,7 @@
+#define WRAM 0xC000
+#define WRAMLEN 0xFFF
+.org WRAM
+
+.def int OAMDMAFN = 0xFF80 
+
+shadow_oam: .adv OBJSMAX * oamsize