From adc1bb10d4580602cc11337557f462f0e7f78717 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 5 Aug 2025 12:09:39 +0200 Subject: [PATCH] unit: moved unit cpu code to new file for generic cpu scripts --- src/main.s | 1 + src/unit_cpu.s | 26 ++++++++++++++++++++++++++ src/unit_demo.s | 24 ------------------------ 3 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 src/unit_cpu.s diff --git a/src/main.s b/src/main.s index fb5c0dd..fda10b9 100644 --- a/src/main.s +++ b/src/main.s @@ -56,6 +56,7 @@ main: #include "sys.s" #include "input.s" #include "player.s" +#include "unit_cpu.s" #include "update.s" #include "ui.s" #include "audio.s" diff --git a/src/unit_cpu.s b/src/unit_cpu.s new file mode 100644 index 0000000..fda1b99 --- /dev/null +++ b/src/unit_cpu.s @@ -0,0 +1,26 @@ + +unit_handle_cpu_inputs: + +unit_cpu_random_move: + ; pick where to go + call roll_d16 + and a, 3 ; 0-3 + ; 0 == left + cp a, 0 + call z, unit_try_move_left + + ; 1 == right + cp a, 1 + call z, unit_try_move_right + + ; 2 == up + cp a, 2 + call z, unit_try_move_up + + ; 3 == down + cp a, 3 + call z, unit_try_move_down + + ld bc, st_unit_delay_to_active + ret + diff --git a/src/unit_demo.s b/src/unit_demo.s index 663bc7f..e203d7e 100644 --- a/src/unit_demo.s +++ b/src/unit_demo.s @@ -11,30 +11,6 @@ unit_demo_1_cpu_update: ret -unit_handle_cpu_inputs: - ; pick where to go - call roll_d16 - and a, 3 ; 0-3 - ; 0 == left - cp a, 0 - call z, unit_try_move_left - - ; 1 == right - cp a, 1 - call z, unit_try_move_right - - ; 2 == up - cp a, 2 - call z, unit_try_move_up - - ; 3 == down - cp a, 3 - call z, unit_try_move_down - - ld bc, st_unit_delay_to_active - ret - - unit_demo_1_cpu_update_idle: ldnull bc ret -- 2.30.2