diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 11 | ||||
-rw-r--r-- | RAM_Var_map | 3 | ||||
-rw-r--r-- | bunny.gbasm | 66 | ||||
-rw-r--r-- | buttons.gbasm | 37 | ||||
-rw-r--r-- | init.gbasm | 52 | ||||
-rw-r--r-- | main.gbasm | 20 | ||||
-rw-r--r-- | tiles.gbasm | 22 |
8 files changed, 212 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..34b242a --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +all: run + +build/%.rom: %.gbasm + mkdir -p build + gbasm $< $@ + +run: build/main.rom + gb $< + +clean: + rm -rf build diff --git a/RAM_Var_map b/RAM_Var_map new file mode 100644 index 0000000..ed1049b --- /dev/null +++ b/RAM_Var_map @@ -0,0 +1,3 @@ +FF80 = Bunny Y position (in px) +FF81 = Bunny X position (in px) +FF82 = Current Direction (Up = 1, Right = 2, Down = 3, Left = 4) diff --git a/bunny.gbasm b/bunny.gbasm new file mode 100644 index 0000000..b2e6ca3 --- /dev/null +++ b/bunny.gbasm @@ -0,0 +1,66 @@ +Initialize_Bunny: + LD A, $20 + LD ($80), A + LD A, $20 + LD ($81), A + RET + +Move_Bunny: + LD A, ($82) + CP $00 + JR Z, =Display_Bunny + + Move_Bunny.check_direction: + DEC A + LD B, $01 + BIT 0, A + JR NZ, =Move_Bunny.check_direction_end + LD B, $FF + + Move_Bunny.check_direction_end: + + BIT 1, A + JR NZ, =Move_Bunny.vertical_move + + Move_Bunny.horizontal_move: + LD A, ($81) + ADD B + LD ($81), A + JP =Move_Bunny.end + + Move_Bunny.vertical_move: + LD A, ($80) + ADD B + LD ($80), A + + Move_Bunny.end: + RET + +Display_Bunny: ; X position in B, Y position in C + LD A, ($81) + LD B, A + LD A, ($80) + LD C, A + + ; First OBJ (left) + LD HL, $FE00 + LD A, C + LD (HL+), A + LD A, B + LD (HL+), A + LD A, $01 + LD (HL+), A + INC HL + + ; Second OBJ + LD A, B + ADD $08 + LD B, A + + LD A, C + LD (HL+), A + LD A, B + LD (HL+), A + LD A, $03 + LD (HL+), A + RET diff --git a/buttons.gbasm b/buttons.gbasm new file mode 100644 index 0000000..b2015de --- /dev/null +++ b/buttons.gbasm @@ -0,0 +1,37 @@ +Pad_Button_Check: + PUSH AF + PUSH BC + + LD A, $20 + LD ($00), A + LD A, ($00) + LD C, A + LD A, $00 + + Pad_Button_Check.Right: + BIT 0, C + JR NZ =Pad_Button_Check.Left + LD A, $02 + + Pad_Button_Check.Left: + BIT 1, C + JR NZ =Pad_Button_Check.Up + LD A, $01 + + Pad_Button_Check.Up: + BIT 2, C + JR NZ =Pad_Button_Check.Down + LD A, $03 + + Pad_Button_Check.Down: + BIT 3, C + JR NZ =Pad_Button_Check.End + LD A, $04 + + Pad_Button_Check.End: + + LD ($82), A + + POP BC + POP AF + RET diff --git a/init.gbasm b/init.gbasm new file mode 100644 index 0000000..1245ce7 --- /dev/null +++ b/init.gbasm @@ -0,0 +1,52 @@ +.PADTO 0x0040 +VBlank: + CALL =VBLANK_Entrypoint + RETI + +.PADTO 0x0100 +Start: + JP =Empty_VRAM + +.PADTO 0x0104 +Nintendo_Logo: ; The Nintendo logo must be stored in bytes 0x104-133 + .DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D + .DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99 + .DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E + +.PADTO 0x0134 +Checksum: ; The bytes 0x134-0x14d need to add up to 0xe7 (= 0xff - 0x19) + .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 + .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 + +Empty_VRAM.loop: + XOR A + LD (HL+), a ; We set the memory pointed to by HL to 0 and increase HL + LD a, $a0 + CP h ; Until h has reached $a0 ($a0000 is the end of VRAM) + JR NZ, =Empty_VRAM.loop + + ; BG Palette + LD DE, $ff47 + LD A, $e4 + LD (DE), A + + ; OBJ0 Palette + LD DE, $ff48 + LD A, $e4 + LD (DE), A + + ; LCDC + LD DE, $ff40 + LD A, (DE) + OR $06 + LD (DE), A + + ; Interrupts + LD DE, $ffff + LD A, $01 + LD (DE), A + + JP =Entrypoint diff --git a/main.gbasm b/main.gbasm new file mode 100644 index 0000000..6b701c8 --- /dev/null +++ b/main.gbasm @@ -0,0 +1,20 @@ +.INCLUDE "init.gbasm" + +Entrypoint: + CALL =Load_Tile + CALL =Initialize_Bunny + + EI + Wait_for_VRAM.loop: + HALT + JP =Wait_for_VRAM.loop + +VBLANK_Entrypoint: + CALL =Pad_Button_Check + CALL =Move_Bunny + CALL =Display_Bunny + RET + +.INCLUDE "tiles.gbasm" +.INCLUDE "bunny.gbasm" +.INCLUDE "buttons.gbasm" diff --git a/tiles.gbasm b/tiles.gbasm new file mode 100644 index 0000000..f69a87d --- /dev/null +++ b/tiles.gbasm @@ -0,0 +1,22 @@ + +Tile_Image_Data: + .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 $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 + +Load_Tile: + LD HL, $8010 + LD DE, =Tile_Image_Data + LD B, $40 + Load_Tile.loop0: + LD A, (DE) + LD (HL+), A + INC DE + DEC B + XOR A + CP B + JR NZ =Load_Tile.loop0 + RET + + |