Skip to content

Commit

Permalink
First mostly playable version
Browse files Browse the repository at this point in the history
Improved the snake drawing function, made the game go back to the titlescreen after a game over, added a background grid.
  • Loading branch information
LeonarthCG committed Aug 15, 2018
1 parent 56d489a commit 1e0da89
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 23 deletions.
Binary file modified ASM/Snake/drawSnake.elf
Binary file not shown.
45 changes: 42 additions & 3 deletions ASM/Snake/drawSnake.s
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
.thumb

push {lr}
push {r4-r6}
push {r4-r7}
ldr r4,=#0x02000000
@erase old tongue if it exists
ldr r0,=bgTilemapsBuffer
ldr r0,[r0]
ldr r1,=#0x500
add r1,r0
tongueloop:
cmp r0,r1
beq donetongue
ldrb r2,[r0]
cmp r2,#1
beq erasetongue
cmp r2,#6
beq erasetongue
add r0,#2
b tongueloop
erasetongue:
mov r2,#0
strh r2,[r0]
donetongue:
@erase old tail
ldrh r0,[r4,#0x1A]
cmp r0,#0
beq erasedtail
ldr r3,=drawTile
mov lr,r3
ldrb r2,[r4,#0x1A] @x
ldrb r3,[r4,#0x1B] @y
mov r1,#0 @attribute
mov r0,#0 @bg layer
.short 0xF800
erasedtail:
ldrh r5,[r4] @size
cmp r5,#0
beq End
bne dontEnd
b End
dontEnd:
sub r5,#1
lsl r5,#1
mov r7,r5
sub r7,#4

@get snake size
sneakLoop:
Expand All @@ -30,6 +64,11 @@ nextEntry:
cmp r5,#0
beq End
sub r5,#2
cmp r5,r7
beq skip
b sneakLoop
skip:
mov r7,r5
b sneakLoop

drawTail:
Expand Down Expand Up @@ -161,6 +200,6 @@ endtongue:
b nextEntry

End:
pop {r4-r6}
pop {r4-r7}
pop {r0}
bx r0
Binary file modified ASM/boot.elf
Binary file not shown.
5 changes: 2 additions & 3 deletions ASM/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ mov r1,#0x10
add r2,#4
strb r1,[r0,r2] @start with a black screen

mov r1,#3
strb r1,[r0,#1] @turn on bg layers 0 and 1

@enable timer 0, 1 and 2
ldr r1,=#0x100
ldr r2,=#0xEEDB
Expand All @@ -58,6 +55,8 @@ mov r1,#0x1F
strb r1,[r0,#9] @set the offset for the bg map 0
mov r1,#0x1E
strb r1,[r0,#11] @set the offset for the bg map 1
mov r1,#0x1D
strb r1,[r0,#13] @set the offset for the bg map 2

swi #5

Expand Down
Binary file modified ASM/mainLoop.elf
Binary file not shown.
47 changes: 33 additions & 14 deletions ASM/mainLoop.s
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ ldr r1,[r1,#4]
ldr r2,=#0x200
.short 0xF800

@make the bg2 background
ldr r0,=backgroundgridTSA
ldr r1,=bgTilemaps
ldr r1,[r1,#8]
ldr r3,=loadData
mov lr,r3
.short 0xF800

@temporary black border
ldr r0,=fillDest
mov lr,r0
Expand All @@ -30,10 +38,14 @@ ldr r0,=#0x04000000
mov r1,#1
strb r1,[r0,#8]

@disable bg 1 for now
mov r1,#1
@disable bg 1 for now, enable bg 2
mov r1,#5
strb r1,[r0,#1]

@lower bg 2 priority
mov r1,#3
strb r1,[r0,#0xC]

ldr r0,=snekIMG
ldr r1,=#0x06000000
ldr r3,=loadData
Expand All @@ -55,10 +67,12 @@ mov lr,r0
.short 0xF800

ldr r0,=#0x02000000
add r0,#0x10
mov r1,#0
strb r1,[r0,#2] @reset facing direction
strb r1,[r0,#0xD] @reset game state
mov r1,#1
strb r1,[r0] @set bg 0 and 1 to be updated
strb r1,[r0,#1]
strb r1,[r0,#0x10] @set bg 0 and 1 to be updated
strb r1,[r0,#0x11]

ldr r0,=drawSnake
mov lr,r0
Expand Down Expand Up @@ -140,6 +154,11 @@ b skipSnake @skip game logic
runSnake:
strh r3,[r0,#0x18] @update counter

@check for game over
ldrb r3,[r0,#0xD]
cmp r3,#0xFF
beq gameover

ldr r0,=#0x02000000
add r0,#0x10
mov r1,#1
Expand Down Expand Up @@ -170,15 +189,6 @@ ldrb r0,[r0,#0xD]
cmp r0,#0xF0
bhi nobg0draw

ldr r0,=fillDest
mov lr,r0
mov r0,#0
ldr r1,=bgTilemapsBuffer
ldr r1,[r1]
add r1,#0x80
ldr r2,=#0x120
.short 0xF800

ldr r0,=drawSnake
mov lr,r0
.short 0xF800
Expand All @@ -194,3 +204,12 @@ b main
skipSnake:
swi #5 @wait for vblank
b main

gameover:
@back to title screen
ldr r0,=fadeOut
mov lr,r0
.short 0xF800
ldr r0,=titlescreenLoop
mov lr,r0
.short 0xF800
Binary file modified ASM/titlescreenLoop.elf
Binary file not shown.
5 changes: 4 additions & 1 deletion ASM/titlescreenLoop.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.thumb

@set background 0 to 256 colors mode, and change priority
ldr r0,=#0x04000000
mov r1,#3
strb r1,[r0,#1] @turn on bg layers 0 and 1

@set background 0 to 256 colors mode, and change priority
mov r1,#0x81
strb r1,[r0,#8]

Expand Down
Binary file added Graphics/backgroundgrid.tsa.bin
Binary file not shown.
Binary file added Graphics/backgroundgrid.tsa.bin.bak
Binary file not shown.
Binary file modified Graphics/snek.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions ROM Buildfile.event
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ ALIGN 4
bgTilemapsBuffer:
WORD $03000000
WORD $03000800
WORD $0
WORD $03001000
WORD $0

ALIGN 4
bgTilemaps:
WORD $0600F800
WORD $0600F000
WORD $0
WORD $0600E800
WORD $0

ALIGN 4
Expand Down Expand Up @@ -181,3 +181,8 @@ presstartTSA:
SHORT 0 25
#incbin "Graphics\pressstart.tsa.bin"

ALIGN 4
backgroundgridTSA:
SHORT 0 320
#incbin "Graphics\backgroundgrid.tsa.bin"

Binary file modified rom.gba
Binary file not shown.

0 comments on commit 1e0da89

Please sign in to comment.