unit: moved tile to screen to a macro
authorLukas Krickl <lukas@krickl.dev>
Sat, 9 Aug 2025 03:44:38 +0000 (05:44 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 9 Aug 2025 03:44:38 +0000 (05:44 +0200)
src/objanim.s
src/unit.s

index ae697f3dcb9267ed6808b38aaa736967a6132d08..076666bc5b3895bdaef24a83702505502e577241 100644 (file)
@@ -68,15 +68,11 @@ objanim_door_open_fn:
        inc de ; skip flags
        ld a, [de] ; a = y position
        inc de ; de = x postion
-       mul16 a
-       add a, OBJ_OFF_Y
-       sub a, b
+       tile_to_scrn OBJ_OFF_Y, b
        ld [hl+], a
 
        ld a, [de] ; a = x position
-       mul16 a
-       add a, OBJ_OFF_X
-       sub a, c
+       tile_to_scrn OBJ_OFF_X, b
        ld [hl+], a
        
        ld a, 0x80 
index 3836ed7580931b2122c774517af2bd85bedea1dc..9a5933c4f8e2d3dfd4caa326547ced825c44f5f8 100644 (file)
@@ -185,6 +185,17 @@ unit_generic_draw_adjust_subtile:
 @done:
 
   ret
+       
+       ; translates tile to screen
+       ; inputs:
+       ;               $1: Y/X offset
+       ;               $2: register containing scroll
+       ;                a: tile position
+#macro tile_to_scrn
+  mul16 a
+  add a, $1 
+  sub a, $2 
+#endmacro
 
   ; draws any unit
   ; inputs:
@@ -215,17 +226,13 @@ unit_generic_draw:
   
   ; set y pos
   ld a, [de]
-  mul16 a
-  add a, OBJ_OFF_Y
-  sub a, b
+       tile_to_scrn OBJ_OFF_Y, b
   ld [hl+], a
 
   ; set x pos
   inc de
   ld a, [de]
-  mul16 a
-  add a, OBJ_OFF_X
-  sub a, c
+       tile_to_scrn OBJ_OFF_X, c 
   ld c, a 
   ld a, [TMP_X_OFFSET]
   add a, c