From: Lukas Krickl Date: Tue, 17 Jun 2025 03:26:55 +0000 (+0200) Subject: refactor: Removed legacy cursor code X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=fab0705f09fd51541ad8420897cc043ab82cc2c3;p=gbrg%2F.git refactor: Removed legacy cursor code 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. --- diff --git a/src/macros.inc b/src/macros.inc index 9d2162d..f06eed2 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -269,43 +269,6 @@ #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 diff --git a/src/main.s b/src/main.s index 2f86235..8da98ad 100644 --- a/src/main.s +++ b/src/main.s @@ -27,8 +27,6 @@ entry: call lcd_on call vblank_wait - - call cursor_player_init call enableinterrupts diff --git a/src/mem.s b/src/mem.s index ab644d4..475fbaf 100644 --- 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 diff --git a/src/player.s b/src/player.s index b7e87a7..822a4a6 100644 --- a/src/player.s +++ b/src/player.s @@ -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 - - diff --git a/src/state.s b/src/state.s index a4c47a2..3ddd966 100644 --- a/src/state.s +++ b/src/state.s @@ -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: diff --git a/src/unit.s b/src/unit.s index fabccbc..9eb857c 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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 diff --git a/src/update.s b/src/update.s index 7e55201..5d726db 100644 --- a/src/update.s +++ b/src/update.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 23e0c54..fdd33a1 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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