aboutsummaryrefslogtreecommitdiff
path: root/entity/utils.gbasm
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-09-19 18:56:32 +0900
committerAstatin <astatin@redacted>2024-09-19 18:56:32 +0900
commitec1f79b44203735f581c7f85b6c23216aaf587a6 (patch)
tree0ae669440b2dce7f2e23cfadebb3dc0ab42efcba /entity/utils.gbasm
parentfa37dcacf1ff0de66f5c4eed7b89be6006d6d77b (diff)
Read action buttons and set it in the entity direction highest nibble
Diffstat (limited to 'entity/utils.gbasm')
-rw-r--r--entity/utils.gbasm48
1 files changed, 48 insertions, 0 deletions
diff --git a/entity/utils.gbasm b/entity/utils.gbasm
new file mode 100644
index 0000000..23abb3a
--- /dev/null
+++ b/entity/utils.gbasm
@@ -0,0 +1,48 @@
+Get_Position_After_Move: ; entity (whatever alignement) in HL, direction to test in A, X Result in C, Y result in B
+ PUSH HL
+ PUSH AF
+
+ LD A, L
+ AND $f8
+ LD L, A
+
+ INC HL
+
+ LD A, (HL+)
+ LD C, A
+ LD A, (HL+)
+ LD B, A
+
+ POP AF
+ BIT 3, A
+ JR Z, =Get_Position_After_Move.direction_end
+
+ PUSH BC
+
+ DEC A
+ LD B, A
+
+ SLA A
+ AND $02
+ DEC A
+
+ BIT 1, B
+ JR NZ, =Get_Position_After_Move.vertical
+
+ Get_Position_After_Move.horizontal:
+ POP BC
+ ADD C
+ LD C, A
+ JR =Get_Position_After_Move.direction_end
+
+ Get_Position_After_Move.vertical:
+ POP BC
+ ADD B
+ LD B, A
+
+ Get_Position_After_Move.direction_end:
+
+ POP HL
+ RET
+
+