input: added basci controller input subsystem
authorLukas Krickl <lukas@krickl.dev>
Tue, 1 Oct 2024 15:23:52 +0000 (17:23 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 1 Oct 2024 15:23:52 +0000 (17:23 +0200)
src/input.s [new file with mode: 0644]
src/main.s
src/video.s
src/wram.s

diff --git a/src/input.s b/src/input.s
new file mode 100644 (file)
index 0000000..b14edfd
--- /dev/null
@@ -0,0 +1,48 @@
+  ; poll inputs
+  ; returns:
+  ;   new inputs in [curr_inputs]
+  ;   previous inputs in [prev_inputs]
+poll_inputs:
+  ld a, [curr_inputs]
+  ld [prev_inputs], a
+
+  ld a, P1FDPAD
+  call poll_p1
+  swap a
+  ld b, a
+  
+  ld a, P1FBTN 
+  call poll_p1 
+  or a, b
+   
+  
+  ld [curr_inputs], a
+  ld a, b
+
+  ret 
+
+
+  ; poll p1 
+  ; inputs:
+  ;   a: P1 key matrix flag 
+  ; returns
+  ;   a: A0-3 -> inputs
+poll_p1:
+  ld [RP1], a
+  ; wait for values to become stable 
+  ldh a, [RP1]
+  ldh a, [RP1]
+  ldh a, [RP1]
+  ldh a, [RP1]
+  ldh a, [RP1]
+  ldh a, [RP1] ; last read counts
+  xor a, 0x0F
+  and a, 0x0F
+
+  ld d, a
+  ; reset P1F
+  ld a, P1FNONE 
+  ldh [RP1], a
+  ld a, d
+
+  ret 
index 5661aeda0cf4e718fad983c027b6d68bbefc195b..9d751ff05b645dde72a3c77b9f1ad5d70acf2c86 100644 (file)
@@ -30,6 +30,7 @@ main:
 #include "mem.s"
 #include "strings.s"
 #include "sys.s"
+#include "input.s"
 
 ; fill bank
 .fill 0, 0x7FFF - $
index d7b97dd20c92ba0e5d4704a37842b714c60e392e..b61bac05b13a89d6d98530315a4dedf6997b69b0 100644 (file)
@@ -2,19 +2,24 @@
 vblank:
   call OAMDMAFN
   
+  call poll_inputs
+
   ; test puts 
   ld hl, STR_TITLE
   ld de, SCRN0
   call puts
 
+
   ret
 
+  ; wait for next vblank
 vblank_wait:
   ld a, [RLY] 
   cp a, 144
   jp c, vblank_wait
   ret
 
+  ; turns off the lcd
 lcd_off:
   ; *never* turn off LCD without waiting 
   ; for vblank!
@@ -25,12 +30,14 @@ lcd_off:
 
   ret
 
+  ; turns on the lcd 
 lcd_on:
   ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON 
   ld [RLCD], a
 
   ret
 
+  ; init video system
 video_init:
   call copy_tiles
 
index 9bf26c9c40c824868661fc54c64be91f46888be3..c206cc6a04a8a3d4736f5360e1517bab18717694 100644 (file)
@@ -8,6 +8,11 @@ shadow_oam: .adv OBJSMAX * oamsize
 
 #define ACTORS_MAX 16
 
+  ; current frame's inputs 
+curr_inputs: .adv 1
+  ; previous frame's inputs
+prev_inputs: .adv 1
+
 ; actor type enum
 .se 1
 .de ACTOR_TYPE_PLAYER, 1