From e050cc53f2b4b15bab9fb16d7cbdd11aa450c6f2 Mon Sep 17 00:00:00 2001 From: velllu <91963404+velllu@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:30:21 +0200 Subject: [PATCH] Added 2 sprites in a row in `sprite-scroll-x` --- README.md | 2 +- src/sprite-scroll-x.asm | 54 +++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3094cc1..56e4cd7 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/sprite-scroll-x.asm b/src/sprite-scroll-x.asm index 2a0afbe..9be63f1 100644 --- a/src/sprite-scroll-x.asm +++ b/src/sprite-scroll-x.asm @@ -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] @@ -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 @@ -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