cells: wip cell update code
authorLukas Krickl <lukas@krickl.dev>
Tue, 8 Apr 2025 10:54:24 +0000 (12:54 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 8 Apr 2025 10:54:24 +0000 (12:54 +0200)
src/cells.s

index e3e4ae63b6f9a81faee5ca4ad502ac34c6b30f3e..13c0bf55384db4ebdf864a2716bfd3463c446b8c 100644 (file)
@@ -3,9 +3,40 @@
   ; does not call c_st_routine if c_head_offset != 0
   ; inputs:
   ;   de: cell ptr
-  ; returns:
-  ;   de: next cell ptr
 cell_update:
+  ld hl, c_head_offset
+  add hl, de ; hl = c_head_offset for current cell
+  ld a, [hl] ; a = head offset
+  cp a, 0
+  ; if not head cell return
+  ret nz
+
+  ; save cell ptr 
+  push de
+
+  ; otherwise call update routine 
+  ld hl, c_st_routine 
+  add hl, de ; hl = ptr to routine to call
+  
+  push hl
+  pop bc ; bc = ptr to rotuine to call
+  ld a, [bc]
+  ld l, a
+  inc bc
+  ld a, [bc]
+  ld h, a ; hl = update routine 
+
+  ; cell ptr has to be passed
+  ; to call 
+  pop de
+  call call_hl
+
+  ; restore cell ptr
+  pop de
+
+  ; TODO: write new s_st_routine 
+  ; if bc is not 0000
+
   ret
 
   ; default road update state