added basic player movement
authorLukas Krickl <lukas@krickl.dev>
Wed, 2 Oct 2024 15:31:50 +0000 (17:31 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 2 Oct 2024 15:31:50 +0000 (17:31 +0200)
src/hw.inc
src/input.s
src/player.s
src/video.s
tiles/tileset0.inc

index 3942be3774d2d4459ff126f549a307f4695325c0..dc8ac7042ecd104148bdaff98b59752bcf9e8154 100644 (file)
@@ -14,6 +14,7 @@
 #define LCDCF_ON 0b10000000
 #define LCDCF_OBJON 0b00000010
 #define LCDF_WINDOWON 0b00100000
+#define LCDF_OBJ_SIZE 0b00000100
 
 #define RBGP 0xFF47
 #define ROBP0 0xFF48
 #define P1F4 0b00010000 ; get dpad
 
 ; buttons 
-#define BTNDOWN 0x80
-#define BTNUP 0x40
-#define BTNLEFT 0x20
-#define BTNRIGHT 0x10
-#define BTNSTART 0x08
-#define BTNSELECT 0x04
-#define BTNA 0x02
-#define BTNB 0x01
+.def int BTNDOWN = 0x80
+.def int BTNUP = 0x40
+.def int BTNLEFT = 0x20
+.def int BTNRIGHT = 0x10
+.def int BTNSTART = 0x08
+.def int BTNSELECT = 0x04
+.def int BTNA = 0x02
+.def int BTNB = 0x01
+
+; obj off-screen offsets
+#define OBJ_OFF_X 8
+#define OBJ_OFF_Y 16
 
 ; interrupts
 ; interrupt flag 
index b14edfd599f9129af9fe07719b41cdff8156048e..bc13f071a7d7ee9bcf68601ba60f9657911b308f 100644 (file)
@@ -1,3 +1,17 @@
+#macro input_just
+
+#endmacro 
+
+  ; checks for a button press
+  ; inputs: 
+  ;   $1 BUTTON
+  ; returns:
+  ;   a: button state
+#macro input_held
+  ld a, [curr_inputs] 
+  and a, $1
+#endmacro
+
   ; poll inputs
   ; returns:
   ;   new inputs in [curr_inputs]
index 43401ef92683eab9b97f9d5d198f90747397c4dc..ac4d0b9cb0610dfea2a1063e4fa5354b95acad40 100644 (file)
@@ -1,3 +1,9 @@
+; player gets 3 sprite slots in a row
+.def int PLAYER_SPRITE1 = shadow_oam + 0
+
+.def int PLAYER_TILE_IDLE1 = 0x04
+.def int PLAYER_TILE_IDLE2 = 0x14
+
   ; update the player 
   ; players do not behave like regular actors
   ; and are not allocate to the regular 
@@ -5,4 +11,63 @@
   ; inputs:
   ;   hl: pointer to player memory
 player_update:
+  ; update 
+
+  ; input handling
+  input_held BTNDOWN
+  jr z, @notdown REL
+  
+  ld de, player_y
+  add hl, de
+  ld a, [hl]
+  inc a
+  ld [hl], a
+@notdown:
+
+
+  ; drawing 
+  ; d: player_y
+  ; e: player_x
+
+  ld a, [hl+]
+  ld d, a
+  ld a, [hl+]
+  ld e, a
+
+  ; obj 1
+  ld hl, PLAYER_SPRITE1
+
+  ; set player position 
+  ld a, d ; y 
+  add a, OBJ_OFF_Y
+
+  ld [hl+], a
+  ld a, e ; x 
+  add a, OBJ_OFF_X
+  ld [hl+], a
+
+  ; idel tile 1
+  ld a, PLAYER_TILE_IDLE1 
+  ld [hl+], a
+
+  ; flags
+  xor a, a
+  ld [hl+], a
+
+  ; obj 2
+  ld a, d ; y 
+  add a, OBJ_OFF_Y
+  ld [hl+], a
+  ld a, e ; x 
+  add a, 8 + OBJ_OFF_X
+  ld [hl+], a
+  
+  ; idle tile 2
+  ld a, PLAYER_TILE_IDLE2 
+  ld [hl+], a
+  
+  ; flags
+  xor a, a
+  ld [hl+], a
+
   ret
index 4d4bf54d6f23ac396b72cbd8c63b00337f704b48..f08c3aebbb50ac45bb79799e536edfbb69767459 100644 (file)
@@ -35,7 +35,7 @@ lcd_off:
 
   ; turns on the lcd 
 lcd_on:
-  ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON 
+  ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDF_OBJ_SIZE 
   ld [RLCD], a
 
   ret
@@ -52,6 +52,13 @@ video_init:
   ; set up bgp
   ld a, 0b11100100
   ld [RBGP], a
+
+  ld a, 0b11100100 
+  ld [ROBP0], a
+
+  ld a, 0b11011000
+  ld [ROBP1], a
+
   ret
 
   ; copies tilest0 and tileset1 to
index 3d464daa2e0869226b29bb78c95daf74a8c87a61..f234e97663e6c9686475bd0935cadc78e65ffdf5 100644 (file)
 .chr 00000000
 ; tile 4
 .chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 00033333
+.chr 00322222
+.chr 03222222
+.chr 03222222
+.chr 03221222
+.chr 03221222
+.chr 03221222
 ; tile 5
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 03221222
+.chr 03221222
+.chr 03222222
+.chr 03222222
+.chr 03222222
+.chr 00322222
+.chr 00033333
 .chr 00000000
 ; tile 6
 .chr 00000000
 .chr 00000000
 ; tile 20
 .chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333000
+.chr 22222300
+.chr 22222230
+.chr 22222230
+.chr 21222230
+.chr 21222230
+.chr 21222230
 ; tile 21
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 21222230
+.chr 21222230
+.chr 22222230
+.chr 22222230
+.chr 22222230
+.chr 22222300
+.chr 33333000
 .chr 00000000
 ; tile 22
 .chr 00000000