map: Added basic panic handler that is called when the map ptr is NULL
authorLukas Krickl <lukas@krickl.dev>
Tue, 31 Dec 2024 15:35:49 +0000 (16:35 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 31 Dec 2024 15:35:49 +0000 (16:35 +0100)
src/map.s
src/strings.s
src/sys.s

index 102469a5ee8b92d2e9ff5be40b59145810870f2d..2558ad2366007fd24a71e3dc2329d7e26e27b95c 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -186,7 +186,12 @@ room_goto:
   ld e, a
   ld a, [hl]
   ld d, a
+
+  ; check if de is NULL 
+  add a, e
+  cp a, 0
+  call z, panic 
+
   call room_load_from
 
   ; its player's turn again
index 4080d9de97dfcb10664eefc886b2c19042b1a705..6e019705a265694066d6220e816fe0f1bf1e7db4 100644 (file)
@@ -21,6 +21,10 @@ STR_MP:
 
 STR_GAME_OVER:
 .str "GAME OVER"
+.db 0
+
+STR_PANIC:
+.str "PANIC"
 .db 0
 
   ; print a string 0-terminated to the screen 
index 18314b059bd86536b6e711eab94e2608ad66355f..c30a158853bf923a61f4133a3f674c0c1c5ee3f2 100644 (file)
--- a/src/sys.s
+++ b/src/sys.s
@@ -1,8 +1,21 @@
 nohandler:
   ret
 
+  ; crashes the program 
+  ; and displays debug information on screen
 panic:
-  ret
+  ; no more interrupts
+  call disableinterrutpts
+
+  call next_vblank_wait
+
+  ; print panic message 
+  ld hl, STR_PANIC
+  ld de, SCRN0
+  call puts
+
+@loop:
+  jp @loop
 
 enableinterrupts:
   ; enable interrupts