Skip to content

Commit

Permalink
Added background buffers, updated routines to use them
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarthCG committed Aug 12, 2018
1 parent 81ec666 commit 82a0249
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 12 deletions.
Binary file modified ASM/Snake/cleanSnake.elf
Binary file not shown.
6 changes: 4 additions & 2 deletions ASM/Snake/cleanSnake.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.thumb

ldr r0,=#0x0600F800
ldr r1,=#0x0600FD00
ldr r0,=bgTilemapsBuffer
ldr r0,[r0]
ldr r1,=#0x500
add r1,r0
mov r2,#0

loop:
Expand Down
Binary file added ASM/copyBuffers.elf
Binary file not shown.
39 changes: 39 additions & 0 deletions ASM/copyBuffers.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.thumb

push {r4-r7}
mov r7,#0
ldr r4,=bgTilemapsBuffer
ldr r5,=bgTilemaps

loop1:
mov r6,r7
lsl r6,#2
mov r2,#0
ldr r3,=#0x5000
ldr r0,=#0x02000000
add r0,#0x10
ldrb r0,[r0,r7]
cmp r0,#0
beq next
ldr r0,[r4,r6]
cmp r0,#0
beq next
ldr r1,[r5,r6]
cmp r1,#0
beq next
loop2:
ldr r6,[r0,r2]
str r6,[r1,r2]
cmp r2,r3
beq next
add r2,#4
b loop2
next:
add r7,#1
cmp r7,#4
beq End
b loop1

End:
pop {r4-r7}
bx lr
Binary file modified ASM/drawTile.elf
Binary file not shown.
19 changes: 9 additions & 10 deletions ASM/drawTile.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

push {lr}

@r0 = tile attribute (palette,tile id, flipping?
@r1 = bg layer
@r0 = bg layer
@r1 = tile attribute (palette,tile id, flipping?
@r2 = x
@r3 = y

push {r4,r5}
mov r4,r2
mov r5,r3

@set starting size of snake
lsl r1,#2
ldr r2,=bgTilemaps
add r1,r2
ldr r1,[r1] @bg layer map offset
lsl r0,#2
ldr r2,=bgTilemapsBuffer
add r0,r2
ldr r0,[r0] @bg layer map offset
lsl r4,#1 @x*2 (*2 since each tile is a short)
add r1,r4
add r0,r4
lsl r5,#6 @y*32*2 (32 being the ammount of tiles in a row)
add r1,r5 @final offset = bg layer map offset + x*2 + y*32*2
strh r0,[r1]
add r0,r5 @final offset = bg layer map offset + x*2 + y*32*2
strh r1,[r0]

End:
pop {r4,r5}
Expand Down
Binary file modified ASM/mainLoop.elf
Binary file not shown.
14 changes: 14 additions & 0 deletions ASM/mainLoop.s
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ noButtons:

swi #5 @wait for vblank

ldr r0,=copyBuffers
mov lr,r0
.short 0xF800

ldr r0,=#0x02000000
add r0,#0x10
mov r1,#0
strb r1,[r0] @set bg 0 to not be updated

ldrb r0,=#0x02000000
ldrb r1,[r0,#3] @speed
ldrb r2,[r0,#4] @counter
Expand All @@ -49,6 +58,11 @@ blo skipSnake @if counter is lower than speed, skip game logic and wait another
mov r3,#0
strb r3,[r0,#4] @counter

ldr r0,=#0x02000000
add r0,#0x10
mov r1,#1
strb r1,[r0] @set bg 0 to be updated

ldr r0,=turnSnake
mov lr,r0
.short 0xF800
Expand Down
16 changes: 16 additions & 0 deletions RAM map.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$02000000 SHORT Snake current size
$02000002 BYTE Snake facing direction
$02000003 BYTE Game speed
$02000004 BYTE Counter
$02000005 BYTE Buttons being pressed
$02000006 SHORT Egg coordinates
$02000008 WORD RNG seed
$0200000C BYTE This byte is set after the first time RNG is used
$0200000D BYTE Game state
$0200000E SHORT Snake new size
$02000010 BYTE Update background map 0 flag
$02000011 BYTE Update background map 1 flag
$02000012 BYTE Update background map 2 flag
$02000013 BYTE Update background map 3 flag
...
$02000020 LIST Snake body piece coordinates
10 changes: 10 additions & 0 deletions ROM Buildfile.event
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ rng:
drawTile:
#inctext lyn "ASM\drawTile.elf" //draw tile at given coords and background layer

copyBuffers:
#inctext lyn "ASM\copyBuffers.elf" //copy the tilemap buffers over to their destination

makeTileAttribute:
#inctext lyn "ASM\makeTileAttribute.elf" //piece together the short for the tile based on the attributes

Expand Down Expand Up @@ -79,6 +82,13 @@ facing directions of the snake:

//the snake's longest possible length is 540, so I'm going to limit it to that and cause a game over if it's reched

ALIGN 4
bgTilemapsBuffer:
WORD $03000000
WORD $0
WORD $0
WORD $0

ALIGN 4
bgTilemaps:
WORD $0600F800
Expand Down
Binary file modified rom.gba
Binary file not shown.

0 comments on commit 82a0249

Please sign in to comment.