refactor: Removed legacy cursor code
authorLukas Krickl <lukas@krickl.dev>
Tue, 17 Jun 2025 03:26:55 +0000 (05:26 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 17 Jun 2025 03:26:55 +0000 (05:26 +0200)
This code was mostly deprecated.
This includes all old cursor code in player.s as well as the update
states and game modes related to cursors.

For testing purposes the base map with demo actors loads directly now.
The cursor code luckily was not used outside its own module anymore.

src/macros.inc
src/main.s
src/mem.s
src/player.s
src/state.s
src/unit.s
src/update.s
src/wram.s

index 9d2162dbda02f207d3341ee63afbd5e362ab024f..f06eed2465b88fdcecab8c643d54df0fba5abc25 100644 (file)
 #macro strt
   .str $1
   .db 0
-#endmacro
-
-  ; generic version of cursor get 
-  ; math
-  ; inputs:
-  ;   $1: stating address
-  ;   $1: row size in bytes
-  ;   $2: col size in bytes
-#macro cursor_get_at_generic 
-  ; find the cell the cursor has selected 
-  ld hl, $1
-
-  ; move y rows down
-  ld de, $2
-  ld a, [cursor_y]
-  div8 a 
-  cp a, 0
-  jr z, @not_y_loop REL
-@y_loop:
-    add hl, de
-    dec a
-    cp a, 0
-    jr nz, @y_loop REL
-@not_y_loop:
-
-  ; move x cells 
-  ld de, $3 
-  ld a, [cursor_x]
-  div8 a
-  cp a, 0
-  jr z, @not_x_loop REL
-@x_loop:
-    add hl, de
-    dec a
-    cp a, 0
-    jr nz, @x_loop REL
-@not_x_loop:
 #endmacro
   
   ; calls rst 0x08
index 2f86235eb260dee631500ece3949c9990e2ceb5e..8da98ad080fea81e9844153e1ea99a87b179fc1f 100644 (file)
@@ -27,8 +27,6 @@ entry:
 
   call lcd_on
   call vblank_wait
-  
-  call cursor_player_init
 
   call enableinterrupts
 
index ab644d44717ce6e6d517671a9ac2faca61d1fc6f..475fbaf67a5ab9f7f612e6bca87d8e2b0f0d821f 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -14,17 +14,13 @@ mem_init:
   call memcpy
 
   ; set up game mode 
-  call unit_placement_init 
+
+  call map_load_demo_actors
+  call game_init 
   call mbc1_init
   
   ret
 
-unit_placement_init:
-  ld de, st_update_unit_placement
-  ld hl, game_mode
-  ld bc, st_size
-  jp memcpy
-
 game_init:
   ld de, st_update_game 
   ld hl, game_mode
index b7e87a761dbe53d0112bf82affa61f5467f5b410..822a4a688aefc3a5591a73dceaa3c043a371f269 100644 (file)
@@ -1,212 +1,2 @@
 .def int CURSOR_TILE = 0x04
 
-#define CURSOR_MOVE_TIMER TILE_SIZE
-#define CURSOR_MOVE_SPEED 8
-
-  ; init the player 
-cursor_player_init:
-  ld de, st_cursor
-  ld hl, actor_player
-  ld bc, st_size
-  call memcpy
-
-  ret
-
-  ; update the player 
-  ; players do not behave like regular actors
-  ; and are not allocate to the regular 
-  ; actor table
-  ; inputs:
-  ;   hl: pointer to player memory
-cursor_player_update:
-  call cursor_handle_inputs
-  push bc
-  call cursor_player_draw_cursor
-  pop bc
-  ret
-
-  ; updates the cursor 
-  ; sprites
-cursor_player_draw_cursor:
-@draw_cursor:
-  ; draw cursor
-  call load_scroll
-
-  ; 8x8 small cursor
-  call load_unit_obj
-
-  ld a, [cursor_y]
-  add a, OBJ_OFF_Y
-  sub a, b
-  ld [hl+], a
-
-  ld a, [cursor_x]
-  add a, OBJ_OFF_X
-  sub a, c
-  ld [hl+], a
-
-  ld a, CURSOR_TILE
-  ld [hl+], a
-
-  xor a, a
-  ld [hl+], a
-  
-  ldnull bc
-  ret
-
-cursor_handle_inputs:
-  input_held BTNA
-  jr z, @not_a REL
-    ; TODO: remove demo actor load
-    ; and load real units
-    call map_load_demo_actors
-    call game_init 
-@not_a:
-
-  ; movement keys with cooldown
-
-  input_held BTNDOWN
-  jr z, @notdown REL
-
-    call cursor_try_abort_move_down
-    jp z, @done
-  
-    cursor_move_direction cursor_move_y, cursor_move_x, 1 
-    
-    ; adjust scroll
-    cursor_adjust_scroll add, scroll_move_y
-
-    call cursor_move
-    ld bc, st_cursor_delay
-    ret
-@notdown:
-  
-  input_held BTNUP
-  jr z, @notup REL
-
-    call cursor_try_abort_move_up
-    jp z, @done 
-
-    cursor_move_direction cursor_move_y, cursor_move_x, NEGATE
-
-    ; adjust scroll
-    cursor_adjust_scroll sub, scroll_move_y
-    
-    call cursor_move
-    ld bc, st_cursor_delay 
-    ret
-@notup:
-
-  input_held BTNLEFT
-  jr z, @notleft REL
-
-    call cursor_try_abort_move_left
-    jr z, @done REL
-
-    cursor_move_direction cursor_move_x, cursor_move_y, NEGATE
-
-    ; adjust scroll
-    cursor_adjust_scroll sub, scroll_move_x
-    
-    call cursor_move
-    ld bc, st_cursor_delay 
-    ret
-@notleft:
-
-  input_held BTNRIGHT 
-  jr z, @notright REL
-
-    call cursor_try_abort_move_right
-    jr z, @done REL
-
-    cursor_move_direction cursor_move_x, cursor_move_y, 1 
-
-    ; adjust scroll
-    cursor_adjust_scroll add, scroll_move_x
-    
-    call cursor_move
-    ld bc, st_cursor_delay 
-    ret
-@notright:
-
-  input_just BTNSELECT
-  jr z, @not_select REL
-    ; select goes to build menu
-    
-    ldnull bc
-    ret
-@not_select:
-@done:
-  ldnull bc
-  ret
-
-cursor_move:
-  ld a, [cursor_y]
-  ld b, a
-
-  ld a, [cursor_move_y]
-  add a, b
-  ld [cursor_y], a
-
-  ld a, [cursor_x]
-  ld b, a
-
-  ld a, [cursor_move_x]
-  add a, b
-  ld [cursor_x], a
-
-  call scroll_update
-  ret
-
-cursor_try_abort_move_left:
-  ld b, CURSOR_MIN_X
-  ld hl, cursor_x
-  jp try_abort_move_at
-
-cursor_try_abort_move_right:
-  ld b, CURSOR_MAX_X
-  ld hl, cursor_x
-  jp try_abort_move_at
-
-cursor_try_abort_move_up:
-  ld b, CURSOR_MIN_Y
-  ld hl, cursor_y
-  jp try_abort_move_at
-
-cursor_try_abort_move_down:
-  ld b, CURSOR_MAX_Y
-  ld hl, cursor_y
-  jp try_abort_move_at
-
-  ; aborts a move direciton  
-  ; inputs: 
-  ;   b: compare variable (e.g. min or max value)
-  ;  hl: position ptr
-  ; returns: z == 0 if move was aborted 
-try_abort_move_at:
-  ; do not abort if position is wrong
-  ld a, [hl]
-  cp a, b
-  ret
-
-  ; gets the current cell
-  ; the cursor is pointing at
-  ; at cursor_y/x
-  ; returns:
-  ;   hl: cell ptr
-cursor_get_cell:
-  cursor_get_at_generic state_cells, MAP_W * c_size, c_size
-
-  ret
-
-  ; gets the current tile in SCRN0 
-  ; based on cursor's location
-  ; cursor_y/x
-  ; retunrs:
-  ;   hl: tile position
-cursor_get_tile:
-  cursor_get_at_generic SCRN0, MAP_W, 1 
-
-  ret
-
-
index a4c47a21109fbe8704f683c83d33649007df52c3..3ddd966a7472c1ede8768e0d98c718cfb0c20490 100644 (file)
@@ -81,17 +81,8 @@ st_null_fn:
 st_null:
   st_def 0xFF, st_null_fn, st_null
 
-st_cursor:
-  st_def 0x00, cursor_player_update, st_cursor
-st_cursor_draw:
-  st_def 0x00, cursor_player_draw_cursor, st_cursor
-st_cursor_delay:
-  st_def CURSOR_MOVE_TIMER, st_null_fn, st_cursor
-
 st_update_game:
   st_def 0x00, update_game, st_update_game
-st_update_unit_placement:
-  st_def 0x00, update_unit_placement, st_update_unit_placement
 st_update_pause:
   st_def 0x00, update_pause, st_update_pause
 st_update_game_over:
index fabccbcf7c25a5423b952f89ea1d69886da4911e..9eb857cdf605f9d26785f0c1861eed7b4c4e372b 100644 (file)
@@ -836,7 +836,7 @@ st_unit_idle:
   st_def 0x00, unit_idle, st_unit_idle
 
 st_unit_delay_to_active:
-  st_def CURSOR_MOVE_TIMER, unit_delay_to_active, st_unit_switch_to_active
+  st_def 8, unit_delay_to_active, st_unit_switch_to_active
 
 st_unit_switch_to_active:
   st_def 0, unit_switch_to_active, st_unit_switch_to_active 
index 7e55201fb056e745d8b8df1e7ebac07d2f69941a..5d726dbd7d66d4a0afaefc327f41c061906f5446 100644 (file)
@@ -25,16 +25,6 @@ update_game:
   ldnull bc
   ret
 
-update_unit_placement:
-  ld de, actor_player 
-  call st_update
-  
-  ld hl, p0_units
-  call units_update
-
-  ldnull bc
-  ret
-
 update_pause:
   ldnull bc
   ret
index 23e0c54378e1cd132eb5be750408cb43e867cdc6..fdd33a17c17a0c30754b0b19e37eaa75005e3836 100644 (file)
@@ -33,13 +33,6 @@ unit_next_best_init: .adv 1
 unit_next_best_act_ptr: .adv 2
 unit_next_timer: .adv 1
 
-  ; actors 
-  ; actors are state machines
-  ; they get updated once a frame
-  ; actor player is a simple cursor 
-  ; that has deploymnet control
-actor_player: .adv act_size 
-
   ; offset into bg_update_queue 
 bg_update_index: .adv 2
 bg_update_queue: .adv bge_size * BGE_MAX 
@@ -72,12 +65,6 @@ srand: .adv 2
   ; last d16 result
 d16: .adv 1
 
-cursor:
-cursor_y: .adv 1
-cursor_x: .adv 1
-cursor_move_y: .adv 1
-cursor_move_x: .adv 1
-
   ; +/-1 for each time the cursor moves
   ; allows us to move scroll when needed 
 scroll_move_y: .adv 1