initial commit because i lost my git history and had to make a new repo :(

This commit is contained in:
2026-05-25 23:03:40 +02:00
commit 20faef4555
12 changed files with 2145 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
SRC=main
#EMU=mgba-qt
EMU=emulicious
all:
mkdir -p build
rgbasm src/$(SRC).asm -o build/$(SRC).o
rgblink build/$(SRC).o -o build/$(SRC).gbu -m build/$(SRC).map -n build/$(SRC).sym
rgbfix -v build/$(SRC).gbu -o build/$(SRC).gb
clean:
rm ./build -r
run: all
$(EMU) ./build/$(SRC).gb 1> /dev/null 2> /dev/null &
+7
View File
@@ -0,0 +1,7 @@
# Small z80 asm game
Featuring movement!
### How to:
assemble: `make all` [requires rgbds]
run : `make run` [requires mgba-qt]
+202
View File
@@ -0,0 +1,202 @@
SECTION "Ball Functions", ROM0
funcBallUpdate:
call funcBallApplyVelocity
call funcBallBounce
ret
; Add the ball's momentum to its position in OAM.
funcBallApplyVelocity:
ld a, [w_ball_velocity_x]
ld b, a
ld a, [STARTOF(OAM) + 5]
add a, b
ld [STARTOF(OAM) + 5], a
ld a, [w_ball_velocity_y]
ld b, a
ld a, [STARTOF(OAM) + 4]
add a, b
ld [STARTOF(OAM) + 4], a
ret
funcBallBounce:
.funcBounceOnTop
; Remember to offset the OAM position!
; (8, 16) in OAM coordinates is (0, 0) on the screen.
call funcGetRelativeBallPosition
; y--
dec c
call funcGetTileByPixel ; Returns tile address in hl
ld a, [hl]
call funcIsWallTile
jr nz, .funcBounceOnRight
; is wall
call funcRemoveBrick ; HL is still set
ld a, 1
ld [w_ball_velocity_y], a
.funcBounceOnRight
call funcGetRelativeBallPosition
inc b
call funcGetTileByPixel
ld a, [hl]
call funcIsWallTile
jr nz, .funcBounceOnLeft
call funcRemoveBrick ; HL is still set
ld a, -1
ld [w_ball_velocity_x], a
.funcBounceOnLeft
call funcGetRelativeBallPosition
dec b
call funcGetTileByPixel
ld a, [hl]
call funcIsWallTile
jr nz, .funcBounceOnBottom
call funcRemoveBrick ; HL is still set
ld a, 1
ld [w_ball_velocity_x], a
.funcBounceOnBottom
call funcGetRelativeBallPosition
inc c
call funcGetTileByPixel
ld a, [hl]
call funcIsWallTile
jr nz, .funcBounceOnPaddle
call funcRemoveBrick ; HL is still set
ld a, -1
ld [w_ball_velocity_y], a
.funcBounceOnPaddle
; load ball and paddle y position and compare
ld a, [STARTOF(OAM)] ; paddle
ld b, a
ld a, [STARTOF(OAM) + 4]
add 4
cp b
jp nz, .return ; Ball.y != Paddle.y
; same y so now check:
; no collision when
; (left edge) ball.x+8 < paddle.x
; or
; (right edge) ball.x-8 > paddle.x
ld a, [STARTOF(OAM)+1]
ld b, a ; Paddle.X
ld a, [STARTOF(OAM)+1 + 4]
; (left edge)
add 8 ; Ball.X + 8
cp b ; ball.x+8 < paddle.x
jp c, .return
; (right edge)
sub 16 ; Ball.X - 16
ld c, a
ld a, b ; Paddle.X
cp c
jp c, .return
; collision
ld a, -1
ld [w_ball_velocity_y], a
.return
ret
; load ball position from OAM and return relative to window
; @return C: Y
; @return B: X
funcGetRelativeBallPosition:
ld a, [STARTOF(OAM) + 4]; Y
ld c, a
ld a, [STARTOF(OAM) + 5]; X
ld b, a
; offset
ld a, c
sub 16
ld c, a
ld a, b
sub 8
ld b, a
ret
; @param a: tile ID
; @return z: set if a is a wall.
funcIsWallTile:
cp a, $00
ret z
cp a, $01
ret z
cp a, $02
ret z
cp a, $04
ret z
cp a, $05
ret z
cp a, $06
ret z
cp a, $07
ret
; Convert a pixel position to a tilemap address
; hl = $9800 + X + Y * 32
; @param b: X
; @param c: Y
; @return hl: tile address
funcGetTileByPixel:
; index = (Y / 8) * 32 + (X / 8)
; address = STARTOF(VRAM) + index
; 1. Calculate floor(Y to 8ths) / 8 * 32
; <=> floor(Y to 8ths) / 8 * 8 * 4 <=> floor(Y to 8 ths) * 4
; -> to round down to a multiple of 8 we discard the last 3 bit
; -> we then write into hl and multiply by adding with itself, this
; gives us the space of a 16 bit reg so we dont overflow
; store in hl
ld a, c
and %1111_1000 ; Discard 3 bits to round down to multiple of 8
ld l, a
xor a
ld h, a
add hl, hl
add hl, hl
; 2. Calculate (x/8)
; store in e
ld a, b
srl a ;../2
srl a ;../4
srl a ;../8
ld e, a
; 3. Add (1.) and (2.) together
; store in bc
xor a
ld d, a
add hl, de
; 4. Add to base addr
; store in hl
ld de, $9800
add hl, de
ret
+27
View File
@@ -0,0 +1,27 @@
DEF BRICK_LEFT EQU $05
DEF BRICK_RIGHT EQU $06
DEF BRICK_BLANK EQU $08
; Remove both tiles of a colided Brick
; @param hl: address of brick-tile
funcRemoveBrick:
.check_left
ld a, [hl]
cp BRICK_LEFT
jr nz, .check_right
; hit left tile of block
ld a, BRICK_BLANK
ld [hl+], a
ld [hl], a
.check_right
ld a, [hl]
cp BRICK_RIGHT
jr nz, .end
; hit right tile of block
ld a, BRICK_BLANK
ld [hl-], a
ld [hl], a
.end
ret
+397
View File
@@ -0,0 +1,397 @@
SECTION "Data", ROM0
Tiles:
dw `33333333
dw `33333333
dw `33333333
dw `33322222
dw `33322222
dw `33322222
dw `33322211
dw `33322211
dw `33333333
dw `33333333
dw `33333333
dw `22222222
dw `22222222
dw `22222222
dw `11111111
dw `11111111
dw `33333333
dw `33333333
dw `33333333
dw `22222333
dw `22222333
dw `22222333
dw `11222333
dw `11222333
dw `33333333
dw `33333333
dw `33333333
dw `33333333
dw `33333333
dw `33333333
dw `33333333
dw `33333333
dw `33322211
dw `33322211
dw `33322211
dw `33322211
dw `33322211
dw `33322211
dw `33322211
dw `33322211
dw `22222222
dw `20000000
dw `20111111
dw `20111111
dw `20111111
dw `20111111
dw `22222222
dw `33333333
dw `22222223
dw `00000023
dw `11111123
dw `11111123
dw `11111123
dw `11111123
dw `22222223
dw `33333333
dw `11222333
dw `11222333
dw `11222333
dw `11222333
dw `11222333
dw `11222333
dw `11222333
dw `11222333
dw `00000000
dw `00000000
dw `00000000
dw `00000000
dw `00000000
dw `00000000
dw `00000000
dw `00000000
dw `11001100
dw `11111111
dw `11111111
dw `21212121
dw `22222222
dw `22322232
dw `23232323
dw `33333333
; duck
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222211
dw `22222211
dw `22222211
dw `22222222
dw `22222222
dw `22222222
dw `11111111
dw `11111111
dw `11221111
dw `11221111
dw `11000011
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `11222222
dw `11222222
dw `11222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222211
dw `22222200
dw `22222200
dw `22000000
dw `22000000
dw `22222222
dw `22222222
dw `22222222
dw `11000011
dw `11111111
dw `11111111
dw `11111111
dw `11111111
dw `11111111
dw `11111111
dw `11000022
dw `11222222
dw `11222222
dw `11222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222200
dw `22222200
dw `22222211
dw `22222211
dw `22221111
dw `22221111
dw `22221111
dw `11000022
dw `00112222
dw `00112222
dw `11112200
dw `11112200
dw `11220000
dw `11220000
dw `11220000
dw `22222222
dw `22222222
dw `22222222
dw `22000000
dw `22000000
dw `00000000
dw `00000000
dw `00000000
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `22222222
dw `11110022
dw `11110022
dw `11110022
dw `22221111
dw `22221111
dw `22221111
dw `22221111
dw `22221111
dw `22222211
dw `22222211
dw `22222222
dw `11220000
dw `11110000
dw `11110000
dw `11111111
dw `11111111
dw `11111111
dw `11111111
dw `22222222
dw `00000000
dw `00111111
dw `00111111
dw `11111111
dw `11111111
dw `11111111
dw `11111111
dw `22222222
dw `11110022
dw `11000022
dw `11000022
dw `00002222
dw `00002222
dw `00222222
dw `00222222
dw `22222222
.end
Tilemap:
db $00, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $02, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $0A, $0B, $0C, $0D, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $0E, $0F, $10, $11, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $12, $13, $14, $15, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $16, $17, $18, $19, $03, 0,0,0,0,0,0,0,0,0,0,0,0
db $04, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
.end
TitleTileset:
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $00,$00, $00,$00, $00,$00, $01,$01, $03,$03, $07,$07, $06,$06, $0C,$0C
DB $00,$00, $00,$00, $C0,$C0, $C0,$C0, $81,$81, $03,$03, $03,$03, $07,$07
DB $00,$00, $00,$00, $00,$00, $C0,$C0, $C0,$C0, $81,$81, $01,$01, $03,$03
DB $00,$00, $00,$00, $00,$00, $60,$60, $E0,$E0, $E0,$E0, $C1,$C1, $C3,$C3
DB $00,$00, $00,$00, $60,$60, $63,$63, $CF,$CF, $8D,$8D, $81,$81, $03,$03
DB $00,$00, $00,$00, $7C,$7C, $FE,$FE, $C3,$C3, $C3,$C3, $83,$83, $06,$06
DB $00,$00, $00,$00, $01,$01, $07,$07, $07,$07, $02,$02, $02,$02, $04,$04
DB $00,$00, $FC,$FC, $FE,$FE, $87,$87, $03,$03, $03,$03, $03,$03, $06,$06
DB $00,$00, $00,$00, $00,$00, $01,$01, $01,$01, $03,$03, $06,$06, $06,$06
DB $00,$00, $00,$00, $00,$00, $81,$81, $83,$83, $06,$06, $0C,$0C, $18,$18
DB $00,$00, $00,$00, $70,$70, $C8,$C8, $08,$08, $08,$08, $18,$18, $30,$30
DB $00,$00, $00,$00, $04,$04, $0C,$0C, $0C,$0C, $18,$18, $18,$18, $31,$31
DB $00,$00, $00,$00, $00,$00, $00,$00, $06,$06, $3E,$3E, $F0,$F0, $C0,$C0
DB $00,$00, $00,$00, $00,$00, $07,$07, $0E,$0E, $18,$18, $10,$10, $30,$30
DB $00,$00, $00,$00, $FE,$FE, $FE,$FE, $01,$01, $03,$03, $07,$07, $01,$01
DB $00,$00, $00,$00, $00,$00, $7C,$7C, $FF,$FF, $C3,$C3, $C1,$C1, $81,$81
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $80,$80, $80,$80
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $01,$01
DB $18,$18, $38,$38, $30,$30, $60,$60, $60,$60, $C0,$C0, $C1,$C1, $81,$81
DB $0E,$0E, $1E,$1E, $3C,$3C, $3C,$3C, $78,$78, $F0,$F0, $F0,$F0, $70,$70
DB $07,$07, $0D,$0D, $09,$09, $19,$19, $11,$11, $31,$31, $61,$61, $63,$63
DB $C2,$C2, $86,$86, $84,$84, $8C,$8C, $88,$88, $98,$98, $10,$10, $30,$30
DB $07,$07, $06,$06, $0C,$0C, $0F,$0F, $1F,$1F, $10,$10, $20,$20, $60,$60
DB $0E,$0E, $38,$38, $F0,$F0, $80,$80, $C0,$C0, $60,$60, $30,$30, $30,$30
DB $04,$04, $08,$08, $08,$08, $30,$30, $3F,$3F, $3F,$3F, $70,$70, $70,$70
DB $0E,$0E, $1C,$1C, $38,$38, $F0,$F0, $E0,$E0, $00,$00, $00,$00, $00,$00
DB $0C,$0C, $18,$18, $18,$18, $30,$30, $60,$60, $60,$60, $C1,$C1, $C1,$C1
DB $18,$18, $30,$30, $61,$61, $61,$61, $C0,$C0, $80,$80, $80,$80, $00,$00
DB $30,$30, $E0,$E0, $C0,$C0, $80,$80, $01,$01, $01,$01, $03,$03, $06,$06
DB $37,$37, $7C,$7C, $F8,$F8, $F0,$F0, $B0,$B0, $B0,$B0, $30,$30, $60,$60
DB $00,$00, $00,$00, $00,$00, $00,$00, $01,$01, $01,$01, $03,$03, $03,$03
DB $60,$60, $60,$60, $CF,$CF, $FF,$FF, $E0,$E0, $80,$80, $00,$00, $00,$00
DB $03,$03, $03,$03, $86,$86, $86,$86, $0C,$0C, $0C,$0C, $18,$18, $18,$18
DB $01,$01, $01,$01, $01,$01, $03,$03, $03,$03, $07,$07, $06,$06, $0E,$0E
DB $80,$80, $80,$80, $80,$80, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $01,$01, $03,$03, $03,$03, $07,$07, $06,$06, $06,$06, $06,$06, $07,$07
DB $82,$82, $06,$06, $0C,$0C, $18,$18, $10,$10, $31,$31, $61,$61, $C1,$C1
DB $60,$60, $60,$60, $C1,$C1, $C1,$C1, $C3,$C3, $83,$83, $82,$82, $86,$86
DB $C3,$C3, $83,$83, $83,$83, $83,$83, $03,$03, $03,$03, $03,$03, $03,$03
DB $20,$20, $60,$60, $40,$40, $40,$40, $C1,$C1, $81,$81, $83,$83, $83,$83
DB $40,$40, $C0,$C0, $80,$80, $80,$80, $80,$80, $01,$01, $07,$07, $FF,$FF
DB $30,$30, $30,$30, $71,$71, $61,$61, $E3,$E3, $C2,$C2, $86,$86, $06,$06
DB $D8,$D8, $98,$98, $8C,$8C, $0C,$0C, $06,$06, $06,$06, $03,$03, $03,$03
DB $01,$01, $01,$01, $03,$03, $03,$03, $02,$02, $06,$06, $06,$06, $06,$06
DB $83,$83, $83,$83, $06,$06, $06,$06, $06,$06, $06,$06, $06,$06, $07,$07
DB $00,$00, $00,$00, $01,$01, $03,$03, $02,$02, $04,$04, $0C,$0C, $18,$18
DB $86,$86, $8C,$8C, $0C,$0C, $18,$18, $18,$18, $10,$10, $30,$30, $30,$30
DB $60,$60, $60,$60, $60,$60, $61,$61, $63,$63, $66,$66, $7C,$7C, $38,$38
DB $06,$06, $06,$06, $8C,$8C, $8C,$8C, $08,$08, $18,$18, $1F,$1F, $1F,$1F
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $F8,$F8, $F8,$F8, $00,$00
DB $38,$38, $30,$30, $30,$30, $60,$60, $60,$60, $41,$41, $C3,$C3, $CF,$CF
DB $0C,$0C, $18,$18, $38,$38, $70,$70, $E0,$E0, $C0,$C0, $80,$80, $00,$00
DB $03,$03, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $01,$01, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $86,$86, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $7C,$7C, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $FF,$FF, $80,$FF
DB $03,$03, $01,$01, $00,$00, $00,$00, $00,$00, $00,$00, $FF,$FF, $01,$FF
DB $F0,$F0, $C0,$C0, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $30,$30, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $18,$18, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $FC,$FC, $70,$70, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $80,$FF, $80,$FF, $80,$FF, $80,$FF, $80,$FF, $FF,$FF, $FF,$FF, $01,$FF
DB $01,$FF, $01,$FF, $01,$FF, $01,$FF, $01,$FF, $FF,$FF, $FF,$FF, $80,$FF
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $FF,$FF, $01,$FF
DB $80,$FF, $80,$FF, $80,$FF, $80,$FF, $80,$FF, $FF,$FF, $00,$00, $00,$00
DB $01,$FF, $01,$FF, $01,$FF, $01,$FF, $01,$FF, $FF,$FF, $00,$00, $00,$00
DB $00,$00, $00,$00, $00,$00, $00,$00, $03,$03, $03,$03, $03,$03, $03,$03
DB $00,$00, $00,$00, $00,$00, $00,$00, $F0,$F0, $18,$18, $0C,$0C, $0C,$0C
DB $00,$00, $00,$00, $00,$00, $00,$00, $03,$03, $06,$06, $0C,$0C, $0C,$0C
DB $00,$00, $00,$00, $00,$00, $00,$00, $C0,$C0, $20,$20, $03,$03, $03,$03
DB $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $06,$06, $06,$06
DB $03,$03, $03,$03, $03,$03, $03,$03, $03,$03, $03,$03, $03,$03, $03,$03
DB $0C,$0C, $0C,$0C, $18,$18, $F0,$F0, $00,$00, $00,$00, $00,$00, $00,$00
DB $D8,$D8, $E1,$E1, $C3,$C3, $C3,$C3, $C3,$C3, $C3,$C3, $C3,$C3, $C1,$C1
DB $F0,$F0, $98,$98, $0C,$0C, $0C,$0C, $FC,$FC, $00,$00, $00,$00, $84,$84
DB $78,$78, $C4,$C4, $C0,$C0, $E0,$E0, $78,$78, $1C,$1C, $0C,$0C, $8C,$8C
DB $0E,$0E, $07,$07, $03,$03, $00,$00, $00,$00, $00,$00, $00,$00, $08,$08
DB $0F,$0F, $03,$03, $C3,$C3, $E3,$E3, $33,$33, $33,$33, $33,$33, $63,$63
DB $C7,$C7, $08,$08, $00,$00, $00,$00, $07,$07, $0C,$0C, $0C,$0C, $0C,$0C
DB $C3,$C3, $63,$63, $63,$63, $63,$63, $E3,$E3, $63,$63, $63,$63, $E3,$E3
DB $7F,$7F, $86,$86, $06,$06, $06,$06, $06,$06, $06,$06, $06,$06, $06,$06
DB $80,$80, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $C0,$C0, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $F8,$F8, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $78,$78, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $07,$07, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $C1,$C1, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $C7,$C7, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
DB $E3,$E3, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00, $00,$00
.end
TitleTilemap:
DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $12, $13, $14, $15, $16, $17, $18, $19, $1A, $1B, $1C, $1D, $1E, $1F, $20, $21, $22, $23, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $24, $25, $26, $27, $28, $29, $2A, $2B, $2C, $2D, $2E, $2F, $30, $31, $32, $33, $34, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $35, $36, $37, $35, $35, $38, $00, $00, $39, $3A, $3B, $3C, $00, $3D, $00, $3E, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $00, $00, $00, $39, $3F, $40, $41, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $00, $00, $39, $3F, $40, $3F, $40, $41, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $00, $39, $3F, $40, $3F, $40, $3F, $40, $41, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $39, $3F, $40, $3F, $40, $3F, $40, $3F, $40, $41, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $39, $3F, $40, $3F, $40, $3F, $40, $3F, $40, $3F, $40, $41, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $39, $3F, $40, $3F, $40, $3F, $40, $3F, $40, $3F, $40, $3F, $40, $41, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $42, $43, $42, $43, $42, $43, $42, $43, $42, $43, $42, $43, $42, $43, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $44, $45, $00, $00, $00, $00, $46, $47, $00, $00, $48, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $49, $4A, $4B, $4C, $4D, $4D, $4E, $4F, $50, $51, $52, $53, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $35, $00, $54, $55, $56, $56, $57, $58, $59, $5A, $35, $53, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
DB $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0
.end
Paddle:
dw `13333331
dw `30000003
dw `13333331
dw `00000000
dw `00000000
dw `00000000
dw `00000000
dw `00000000
.end
Ball:
dw `00033000
dw `00322300
dw `03222230
dw `03222230
dw `00322300
dw `00033000
dw `00000000
dw `00000000
.end
+117
View File
@@ -0,0 +1,117 @@
SECTION "Functions", ROM0
; Read inputs and stores result in global vars
; @result w_current_input: The current state %CCCC BBBB
; @result w_new_input: What changed to 1 %CCCC BBBB
; B = BUTTONS, C = CONTROL PAD
funcUpdateInput:
ld a, JOYP_GET_BUTTONS
call .read_input_nipple
ld b, a
ld a, JOYP_GET_CTRL_PAD
call .read_input_nipple
; now combine a and b into one
swap a ; a is now %CCCC 1111
xor b ; b was %1111 BBBB
ld b, a ; result now %CCCC BBBB inverted -> active low to active high
; release input register
ld a, JOYP_GET_NONE
ld [rJOYP], a
; update variables with result in b
ld a, [w_current_input]
xor b ; what changed
and b ; what changed to 1
ld [w_new_input], a
ld a, b
ld [w_current_input], a
ret
.read_input_nipple
ldh [rJOYP], a ; set input mode to reading buttons
call .burn_cycles
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP] ; now the output should be safe
or $F0 ; mask of upper nibble
ret
.burn_cycles
ret
; Spins untill VBlank
funcWaitVBlankStart:
.loop
ld a, [rLY]
cp 144
jr c, .loop
ret
; Spins untill VBlank is done
funcWaitVBlankEnd:
.loop
ld a, [rLY]
cp 144
jr nc, .loop
ret
funcDelay1Second:
ld hl, 16191 ; ~1 second worth of iterations (see math below)
.loop:
dec hl ; 8 cycles
ld a, h ; 4 cycles
or l ; 4 cycles
jr nz, .loop ; 12 cycles taken / 8 not taken
ret
; Copy bytes from one area to another.
; @param de: Source
; @param hl: Destination
; @param bc: Length
funcMemCopy:
.loop
ld a, [de]
ld [hl+], a
inc de
dec bc
ld a, b
or c
jr nz, .loop
ret
; Fills a chunk of memory with a specified byte
; @param hl: Target
; @param bc: Length
; @param d: Byte
funcMemSet:
.loop
ld a, d
ld [hl+], a
dec bc
ld a, b
or c
jr nz, .loop
ret
; Fills a chunk of memory with zeroes
; @param hl: Target
; @param bc: Length
funcMemZero:
xor a
ld d, a
jp funcMemSet
+166
View File
@@ -0,0 +1,166 @@
SECTION "Game", ROM0
funcInitGame:
call funcWaitVBlankStart
call funcLoadGame
call funcInitGlobals
ret
funcLoadGame:
; turn off lcd
xor a
ld [rLCDC], a
; Populate VRAM
ld de, Tiles
ld hl, $9000
ld bc, Tiles.end - Tiles
call funcMemCopy
ld de, Tilemap
ld hl, $9800
ld bc, Tilemap.end - Tilemap
call funcMemCopy
ld de, Paddle
ld hl, STARTOF(VRAM)
ld bc, Paddle.end - Paddle
call funcMemCopy
ld de, Ball
ld hl, STARTOF(VRAM) + $10
ld bc, Ball.end - Ball
call funcMemCopy
ld hl, STARTOF(OAM)
ld bc, SIZEOF(OAM)
call funcMemZero
; Load OAM data for paddle
ld hl, STARTOF(OAM)
ld a, 128 + 16 ; Y
ld [hl+], a
ld a, 16 + 8 ; X
ld [hl+], a
xor a
ld [hl+], a ; TILEID
ld [hl+], a ; ATTRIB
ld a, 100 + 16 ; Y
ld [hli], a
ld a, 32 + 8 ; X
ld [hli], a
ld a, 1
ld [hli], a ; TILEID
xor a
ld [hli], a ; ATTRIB
; LCD
ld a, LCDC_ON | LCDC_BG_ON | LCDC_OBJ_ON
ld [rLCDC], a
; Palletes
ld a, %11_10_01_00
ld [rBGP], a
ld [rOBP0], a
ret
funcInitGlobals:
; Initialize global variables
ld hl, STARTOF("Globals")
ld bc, SIZEOF("Globals")
call funcMemZero
; globals default values
or 1
ld [w_ball_velocity_x], a
ld a, -1
ld [w_ball_velocity_y], a
ret
funcGameCheckGameWon:
; iterate over the tilemap and exit if brick is found
ld hl, $9800
ld bc, 563 ; checking 563 tiles (17 rows of tiles, ending at screen corner)
.loop
ld a, [hl]
cp BRICK_LEFT
jr z, .brick_found
cp BRICK_RIGHT
jr z, .brick_found
inc hl
dec bc
ld a, b
or c
jp nz, .loop
; no brick found - we won
jp funcGameOver
.brick_found
ret
funcGameCheckGameOver:
; get ball position
ld a, [STARTOF(OAM)+4]
cp 152
jp c, .done
jp funcGameOver
.done
ret
funcGameOver:
; flashing screen loop
ld b, 4
.loop
call funcWaitVBlankEnd
call funcDelay1Second
call funcWaitVBlankStart
; invert BGP
ld a, [rBGP]
cpl
ld [rBGP], a
dec b
jr nz, .loop
; second loop for delay
ld b, 8
.loop2
call funcDelay1Second
dec b
jr nz, .loop2
jp EntryPoint
funcGameLoop:
.loop:
call funcWaitVBlankEnd
call funcWaitVBlankStart
call funcBallUpdate
call funcUpdateInput
call funcPaddleUpdatePosition
call funcGameCheckGameOver
call funcGameCheckGameWon
jr .loop
ret
+5
View File
@@ -0,0 +1,5 @@
SECTION "Globals", WRAM0
w_current_input: db
w_new_input: db
w_ball_velocity_x: db
w_ball_velocity_y: db
+1110
View File
File diff suppressed because it is too large Load Diff
+30
View File
@@ -0,0 +1,30 @@
INCLUDE "src/hardware.inc"
INCLUDE "src/globals.asm"
INCLUDE "src/functions.asm"
INCLUDE "src/game.asm"
INCLUDE "src/paddle.asm"
INCLUDE "src/brick.asm"
INCLUDE "src/ball.asm"
INCLUDE "src/title.asm"
INCLUDE "src/data.asm"
SECTION "Header", ROM0[$100]
jp EntryPoint
; room for header
ds $150 - @, 0
EntryPoint:
; === TITLE ===
call funcLoadTitle
call funcTitleLoop
; === GAME ===
call funcInitGame
call funcGameLoop
+28
View File
@@ -0,0 +1,28 @@
SECTION "Paddle", ROM0
funcPaddleUpdatePosition:
.check_left
ld a, [w_current_input]
and a, PAD_LEFT
jr z, .check_right
.move_left
ld a, [STARTOF(OAM)+1] ; X POS
dec a
; clamp to >16
cp 16
jr c, .check_right
ld [STARTOF(OAM)+1], a
.check_right
ld a, [w_current_input]
and a, PAD_RIGHT
jr z, .movement_end
.move_right
ld a, [STARTOF(OAM)+1] ; X POS
inc a
cp 105
jp nc, .movement_end
ld [STARTOF(OAM)+1], a
.movement_end
ret
+40
View File
@@ -0,0 +1,40 @@
SECTION "TitleScreen", ROM0
; Make sure this is executed in VBLANK
; Loads Tileset and Tilemap for title
funcLoadTitle:
call funcWaitVBlankStart
; turn off lcd
xor a
ld [rLCDC], a
; load tilemap and tileset
ld de, TitleTileset
ld hl, $9000
ld bc, TitleTileset.end - TitleTileset
call funcMemCopy
ld de, TitleTilemap
ld hl, $9800
ld bc, TitleTilemap.end - TitleTilemap
call funcMemCopy
; turn on lcd
ld a, LCDC_ON | LCDC_BG_ON
ld [rLCDC], a
; load palette
ld a, %11100100
ld [rBGP], a
ret
funcTitleLoop:
call funcUpdateInput
ld a, [w_current_input]
and PAD_START
jr z, funcTitleLoop
ret