Skip to content

Commit

Permalink
Added 2 sprites in a row in sprite-scroll-x
Browse files Browse the repository at this point in the history
  • Loading branch information
velllu committed Oct 4, 2024
1 parent 0bda1a8 commit e050cc5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ I have written these tests (just one as of now) for my [own gameboy emulator](ht
> I have written these to be used on an emulator, altough these should also work on hardware, I will not be responsible for the damage it might cause
# Tests
- `sprite-scroll-x`, this one puts a sprite in the middle of the screen, and after every vblank interrupt, moves the sprite by one pixel.
- `sprite-scroll-x`, this one put three sprites on the screen, all of them should scroll by one pixel after every frame (using vblank interrupts), they are divided in two rows, one by itself, and two in a row

# Building
To build a test run `./build.sh testname`, for example, `./build.sh sprite-scroll-x`. To clean generated files except the rom, run `./build.sh clean`.
Expand Down
54 changes: 36 additions & 18 deletions src/sprite-scroll-x.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DEF rLCDC EQU $FF40
DEF rOBP0 EQU $FF48
DEF rIE EQU $FFFF
DEF rIF EQU $FF0F
DEF rDMA EQU $FF46
DEF OAMRAM EQU $FE00

section "VBlank Interrupt", rom0[$40]
Expand Down Expand Up @@ -97,24 +98,11 @@ Main:
ld bc, TilesEnd
call LoadArea

; Now we load the sprite
ld hl, OAMRAM
; Y Position
ld a, 160 / 2
ld [hl+], a

; X Position
ld a, 8
ld [hl+], a

; Tile number
ld a, 1
ld [hl+], a

; Attributes
ld a, 0
ld [hl+], a
; We load sprites in OAM
ld hl, $FE00
ld de, SpriteData
ld bc, SpriteDataEnd
call LoadArea

; Set the palette
ld a, %11100100
Expand Down Expand Up @@ -145,8 +133,38 @@ VBlank:
add a, b
ld [hl], a

ld hl, OAMRAM + 5
ld a, [hl]
add a, b
ld [hl], a

ld hl, OAMRAM + 9
ld a, [hl]
add a, b
ld [hl], a

reti

SpriteData:
; Sprite 1
db 160 / 2 ; Y
db 0 ; X
db 1 ; Tile number
db 0 ; Attributes

; Sprite 2
db 160 / 2 + 16 ; Y
db 0 ; X
db 1 ; Tile number
db 0 ; Attributes

; Sprite 3, the one next to Sprite 2
db 160 / 2 + 16 ; Y
db 8 ; X
db 1 ; Tile number
db 0 ; Attributes
SpriteDataEnd:

section "Tile data", rom0
Tiles:
rept 16
Expand Down

0 comments on commit e050cc5

Please sign in to comment.