aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bunny.gbasm94
-rw-r--r--buttons.gbasm14
-rw-r--r--definitions.gbasm24
-rw-r--r--init.gbasm16
-rw-r--r--main.gbasm4
-rw-r--r--map.gbasm26
-rw-r--r--tiles.gbasm53
7 files changed, 165 insertions, 66 deletions
diff --git a/bunny.gbasm b/bunny.gbasm
index 9e80bef..eb4e574 100644
--- a/bunny.gbasm
+++ b/bunny.gbasm
@@ -1,22 +1,22 @@
Initialize_Bunny:
LD A, $50
- LD ($80), A
+ LD $mem_bunny_x_px, A
LD A, $50
- LD ($81), A
+ LD $mem_bunny_y_px, A
RET
Move_Bunny:
- LD A, ($83)
+ LD A, $mem_moving_sprite_direction
CP $00
JR NZ, =Move_Bunny.check_direction
- LD A, ($82)
- LD ($83), A
+ LD A, $mem_button_direction
+ LD $mem_moving_sprite_direction, A
CP $00
JR Z, =Move_Bunny.end
Move_Bunny.check_direction:
- LD ($85), A
+ LD $mem_sprite_direction, A
DEC A
LD B, $01
@@ -30,77 +30,77 @@ Move_Bunny:
JR NZ, =Move_Bunny.vertical_px_move
Move_Bunny.horizontal_px_move:
- LD A, ($81)
+ LD A, $mem_bunny_x_px
ADD B
CP $30
JR C, =Move_Bunny.horizontal_px_move.scrolling_fallback
CP $71
JR NC, =Move_Bunny.horizontal_px_move.scrolling_fallback
- LD ($81), A
+ LD $mem_bunny_x_px, A
JP =Move_Bunny.check_end_of_movement
Move_Bunny.horizontal_px_move.scrolling_fallback:
- LD A, ($43)
+ LD A, $reg_viewport_x
ADD B
- LD ($43), A
+ LD $reg_viewport_x, A
JP =Move_Bunny.check_end_of_movement
Move_Bunny.vertical_px_move:
- LD A, ($80)
+ LD A, $mem_bunny_y_px
ADD B
CP $30
JR C, =Move_Bunny.vertical_px_move.scrolling_fallback
CP $71
JR NC, =Move_Bunny.vertical_px_move.scrolling_fallback
- LD ($80), A
+ LD $mem_bunny_y_px, A
JP =Move_Bunny.check_end_of_movement
Move_Bunny.vertical_px_move.scrolling_fallback:
- LD A, ($42)
+ LD A, $reg_viewport_y
ADD B
- LD ($42), A
+ LD $reg_viewport_y, A
JP =Move_Bunny.check_end_of_movement
Move_Bunny.check_end_of_movement:
- LD A, ($84)
+ LD A, $mem_moving_animation_step
INC A
AND $0f
- LD ($84), A
+ LD $mem_moving_animation_step, A
JR NZ, =Move_Bunny.end
- LD ($83), A
- LD A, ($85)
+ LD $mem_moving_sprite_direction, A
+ LD A, $mem_sprite_direction
DEC A
BIT 1, A
JR NZ, =Move_Bunny.vertical_tile_move
Move_Bunny.horizontal_tile_move:
- LD A, ($86)
+ LD A, $mem_bunny_x
ADD B
- LD ($86), A
+ LD $mem_bunny_x, A
JP =Move_Bunny.end
Move_Bunny.vertical_tile_move:
- LD A, ($87)
+ LD A, $mem_bunny_y
ADD B
- LD ($87), A
+ LD $mem_bunny_y, A
Move_Bunny.end:
RET
Display_Bunny: ; X position in $81, Y position in $80
- LD A, ($86)
- LD HL, $9800
+ LD A, $mem_bunny_x
+ LD HL, $9840
CALL =Print_8bit
- LD A, ($87)
- LD HL, $9820
+ LD A, $mem_bunny_y
+ LD HL, $9860
CALL =Print_8bit
- LD A, ($81)
+ LD A, $mem_bunny_x_px
LD B, A
- LD A, ($80)
+ LD A, $mem_bunny_y_px
LD C, A
- LD A, ($84)
+ LD A, $mem_moving_animation_step
SUB $08
BIT 7, A
@@ -120,14 +120,34 @@ Display_Bunny: ; X position in $81, Y position in $80
LD C, A
- ; X flip
- LD A, ($85)
- CP $02
- LD E, $01
- LD D, $00
- JR NZ, =Display_Bunny.Write_OBJ
- LD D, $20
- LD E, $03
+ LD A, $mem_sprite_direction
+ CP $enum_direction_left
+ JR Z, =Display_Bunny.Left_Direction_sprite
+ CP $enum_direction_right
+ JR Z, =Display_Bunny.Right_Direction_sprite
+ CP $enum_direction_up
+ JR Z, =Display_Bunny.Up_Direction_sprite
+ JP =Display_Bunny.Down_Direction_sprite
+
+ Display_Bunny.Left_Direction_sprite:
+ LD E, $01
+ LD D, $00
+ JP =Display_Bunny.Write_OBJ
+
+ Display_Bunny.Right_Direction_sprite:
+ LD E, $03
+ LD D, $20
+ JP =Display_Bunny.Write_OBJ
+
+ Display_Bunny.Up_Direction_sprite:
+ LD E, $05
+ LD D, $00
+ JP =Display_Bunny.Write_OBJ
+
+ Display_Bunny.Down_Direction_sprite:
+ LD E, $09
+ LD D, $00
+ JP =Display_Bunny.Write_OBJ
Display_Bunny.Write_OBJ:
; First OBJ (left)
diff --git a/buttons.gbasm b/buttons.gbasm
index b2015de..b5e94ff 100644
--- a/buttons.gbasm
+++ b/buttons.gbasm
@@ -3,34 +3,34 @@ Pad_Button_Check:
PUSH BC
LD A, $20
- LD ($00), A
- LD A, ($00)
+ LD $reg_joypad, A
+ LD A, $reg_joypad
LD C, A
LD A, $00
Pad_Button_Check.Right:
BIT 0, C
JR NZ =Pad_Button_Check.Left
- LD A, $02
+ LD A, $enum_direction_right
Pad_Button_Check.Left:
BIT 1, C
JR NZ =Pad_Button_Check.Up
- LD A, $01
+ LD A, $enum_direction_left
Pad_Button_Check.Up:
BIT 2, C
JR NZ =Pad_Button_Check.Down
- LD A, $03
+ LD A, $enum_direction_up
Pad_Button_Check.Down:
BIT 3, C
JR NZ =Pad_Button_Check.End
- LD A, $04
+ LD A, $enum_direction_down
Pad_Button_Check.End:
- LD ($82), A
+ LD $mem_button_direction, A
POP BC
POP AF
diff --git a/definitions.gbasm b/definitions.gbasm
new file mode 100644
index 0000000..035e5d9
--- /dev/null
+++ b/definitions.gbasm
@@ -0,0 +1,24 @@
+.DEFINE reg_joypad ($00)
+.DEFINE reg_lcd_controller ($40)
+.DEFINE reg_viewport_y ($42)
+.DEFINE reg_viewport_x ($43)
+.DEFINE reg_bg_palette ($47)
+.DEFINE reg_obj0_palette ($48)
+.DEFINE reg_interrupt_enable ($ff)
+
+.DEFINE VRAM_start $8000
+.DEFINE OAM_start $FE00
+
+.DEFINE mem_bunny_x_px ($80)
+.DEFINE mem_bunny_y_px ($81)
+.DEFINE mem_button_direction ($82)
+.DEFINE mem_moving_sprite_direction ($83)
+.DEFINE mem_moving_animation_step ($84)
+.DEFINE mem_sprite_direction ($85)
+.DEFINE mem_bunny_x ($86)
+.DEFINE mem_bunny_y ($87)
+
+.DEFINE enum_direction_left $01
+.DEFINE enum_direction_right $02
+.DEFINE enum_direction_up $03
+.DEFINE enum_direction_down $04
diff --git a/init.gbasm b/init.gbasm
index 1245ce7..20a5461 100644
--- a/init.gbasm
+++ b/init.gbasm
@@ -19,7 +19,7 @@ Checksum: ; The bytes 0x134-0x14d need to add up to 0xe7 (= 0xff - 0x19)
.DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$e7
Empty_VRAM: ; (Clear screen)
- LD hl, $8000 ; We set the HL register to the start of VRAM
+ LD hl, $VRAM_start ; We set the HL register to the start of VRAM
Empty_VRAM.loop:
XOR A
@@ -29,24 +29,20 @@ Empty_VRAM.loop:
JR NZ, =Empty_VRAM.loop
; BG Palette
- LD DE, $ff47
LD A, $e4
- LD (DE), A
+ LD $reg_bg_palette, A
; OBJ0 Palette
- LD DE, $ff48
LD A, $e4
- LD (DE), A
+ LD $reg_obj0_palette, A
; LCDC
- LD DE, $ff40
- LD A, (DE)
+ LD A, $reg_lcd_controller
OR $06
- LD (DE), A
+ LD $reg_lcd_controller, A
; Interrupts
- LD DE, $ffff
LD A, $01
- LD (DE), A
+ LD $reg_interrupt_enable, A
JP =Entrypoint
diff --git a/main.gbasm b/main.gbasm
index 6eb27f3..36993de 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -1,8 +1,9 @@
+.INCLUDE "definitions.gbasm"
.INCLUDE "init.gbasm"
Entrypoint:
CALL =Load_Tile
- CALL =Load_Number_Font
+ CALL =Load_Map
CALL =Initialize_Bunny
EI
@@ -18,5 +19,6 @@ VBLANK_Entrypoint:
.INCLUDE "tiles.gbasm"
.INCLUDE "print.gbasm"
+.INCLUDE "map.gbasm"
.INCLUDE "bunny.gbasm"
.INCLUDE "buttons.gbasm"
diff --git a/map.gbasm b/map.gbasm
new file mode 100644
index 0000000..1a145c5
--- /dev/null
+++ b/map.gbasm
@@ -0,0 +1,26 @@
+Load_Map:
+ LD DE, $9800
+ LD B, $40
+
+ Load_Map.loop:
+ LD A, E
+ AND $20
+ SRL A
+ SRL A
+ SRL A
+ SRL A
+ LD C, A
+ LD A, E
+ AND $01
+ OR C
+ OR $20
+
+ LD (DE), A
+
+ INC DE
+ DEC B
+ LD A, $00
+ CP B
+ JR NZ =Load_Map.loop
+
+ RET
diff --git a/tiles.gbasm b/tiles.gbasm
index cd37801..7db9168 100644
--- a/tiles.gbasm
+++ b/tiles.gbasm
@@ -1,9 +1,28 @@
+BG_Tile_Image_Data:
+ ; Leaf wall
+ .DB $ff, $b3, $4c, $ff, $28, $d7, $ba, $47, $e4, $ef, $41, $ff, $47, $b8, $cd, $3d
+ .DB $bd, $5a, $e7, $fd, $2a, $d7, $aa, $6d, $82, $fe, $83, $ff, $bc, $c7, $c3, $ee
+ .DB $70, $7f, $82, $ff, $2d, $d3, $58, $af, $6d, $1a, $fc, $bd, $e7, $e7, $00, $00
+ .DB $13, $ff, $76, $df, $35, $ba, $48, $fd, $69, $d7, $e7, $ef, $bc, $bc, $00, $00
-Tile_Image_Data:
+OBJ_Tile_Image_Data:
+ ; Bunny Side
.DB $00, $00, $44, $44, $aa, $ee, $aa, $ee, $fe, $b2, $fc, $b4, $fc, $94, $75, $4d
- .DB $7f, $42, $2f, $30, $1f, $10, $39, $26, $37, $2f, $48, $78, $50, $70, $60, $60
+ .DB $ff, $82, $6f, $70, $3f, $20, $3f, $20, $31, $2e, $4e, $7f, $51, $71, $60, $60
.DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $c0, $c0
- .DB $34, $f4, $ce, $3a, $fe, $0a, $fc, $04, $bc, $c4, $5c, $64, $88, $f8, $f0, $f0
+ .DB $34, $f4, $ce, $3a, $fe, $0a, $fc, $04, $bc, $44, $5c, $e4, $88, $f8, $f0, $f0
+
+ ; Bunny Back
+ .DB $00, $00, $00, $00, $00, $00, $1c, $1c, $2e, $32, $2f, $3b, $1f, $19, $0e, $0f
+ .DB $13, $1c, $27, $38, $2f, $30, $2f, $30, $2f, $30, $13, $1c, $15, $1b, $0e, $0e
+ .DB $00, $00, $40, $40, $a0, $e0, $a0, $e0, $e0, $a0, $e0, $20, $c0, $40, $e0, $e0
+ .DB $d0, $30, $d0, $30, $e8, $18, $f8, $08, $f0, $10, $90, $70, $70, $90, $e0, $e0
+
+ ; Bunny Front
+ .DB $00, $00, $04, $04, $0a, $0e, $0a, $0e, $0e, $0a, $0f, $09, $07, $05, $0f, $0e
+ .DB $17, $1c, $17, $1a, $2f, $30, $3f, $20, $1f, $10, $17, $1d, $0d, $0f, $06, $06
+ .DB $00, $00, $00, $00, $00, $00, $70, $70, $e8, $98, $e8, $b8, $f0, $30, $e0, $e0
+ .DB $d0, $70, $e8, $98, $e8, $18, $f8, $08, $f8, $08, $d0, $70, $60, $e0, $c0, $c0
Number_Font_Data:
.DB $00, $38, $4c, $c6, $c6, $64, $38, $00 ; 0
@@ -20,24 +39,36 @@ Number_Font_Data:
.DB $00, $7c, $46, $7c, $46, $46, $7c, $00 ; B
.DB $00, $3c, $62, $60, $60, $62, $3c, $00 ; C
.DB $00, $7c, $62, $62, $62, $62, $7c, $00 ; D
- .DB $00, $7e, $60, $7c, $60, $60, $7e, $00 ; D
- .DB $00, $7e, $60, $7c, $60, $60, $60, $00 ; D
+ .DB $00, $7e, $60, $7c, $60, $60, $7e, $00 ; E
+ .DB $00, $7e, $60, $7c, $60, $60, $60, $00 ; F
-Load_Tile:
- LD HL, $8010
- LD DE, =Tile_Image_Data
- LD B, $40
+memcpy: ; src = DE, dest = HL, n = BC
Load_Tile.loop0:
LD A, (DE)
LD (HL+), A
INC DE
- DEC B
+ DEC BC
XOR A
CP B
JR NZ =Load_Tile.loop0
+ CP C
+ JR NZ =Load_Tile.loop0
RET
-Load_Number_Font: ; Load number font into the tilemap at tiles 0x10-0x19
+Load_Tile:
+ LD HL, $8010
+ LD DE, =OBJ_Tile_Image_Data
+ LD BC, $00c0
+ CALL =memcpy
+ CALL =Load_Number_Font
+ LD HL, $8200
+ LD DE, =BG_Tile_Image_Data
+ LD BC, $0040
+ CALL =memcpy
+ RET
+
+
+Load_Number_Font: ; Load number font into the tilemap at tiles 0x10-0x1f
LD HL, $8100
LD DE, =Number_Font_Data
LD B, $80