Skip to content

Commit

Permalink
Added eggs
Browse files Browse the repository at this point in the history
Added egg generation, drawing and eating, improved snake turning
  • Loading branch information
LeonarthCG committed Aug 13, 2018
1 parent 82a0249 commit d22fb95
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

*.db
Event Assembler/
*.sav
9 changes: 9 additions & 0 deletions ASM/Egg/Assemble ARM ELF.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off

SET startDir=C:\devkitPro\devkitARM\bin\

@rem Assemble into an elf
SET as="%startDir%arm-none-eabi-as"
%as% -g -mcpu=arm7tdmi -mthumb-interwork %1 -o "%~n1.elf"

pause
Binary file added ASM/Egg/drawEgg.elf
Binary file not shown.
20 changes: 20 additions & 0 deletions ASM/Egg/drawEgg.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.thumb

push {lr}

ldr r3,=drawTile
mov lr,r3
ldr r3,=#0x02000000
ldrh r2,[r3,#6]
cmp r2,#0
beq End
ldrb r2,[r3,#6] @x
ldrb r3,[r3,#7] @y
mov r0,#0
ldr r1,=#0x02000000
ldrb r1,[r1,#0x14]
.short 0xF800

End:
pop {r0}
bx r0
Binary file added ASM/Egg/eatEgg.elf
Binary file not shown.
19 changes: 19 additions & 0 deletions ASM/Egg/eatEgg.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.thumb

ldr r0,=#0x02000000
ldrh r1,[r0,#0x6] @egg coords
ldrh r2,[r0] @size
lsl r2,#1
add r2,#0x20
sub r2,#2
ldrh r2,[r0,r2] @head coords
cmp r1,r2
bne End
mov r3,#0
strh r3,[r0,#0x6] @destroy egg
ldrh r3,[r0,#0xE]
add r3,#1 @add size
strh r3,[r0,#0xE]

End:
bx lr
Binary file added ASM/Egg/makeEgg.elf
Binary file not shown.
75 changes: 75 additions & 0 deletions ASM/Egg/makeEgg.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.thumb

push {lr}

ldr r0,=#0x02000000
ldrh r0,[r0,#6] @egg coords
cmp r0,#0
bne End @if egg already exists, do nothing

@generate egg color and save it
ldr r0,=rng
mov lr,r0
.short 0xF800
mov r1,#1
and r0,r1
ldr r1,=#0x02000000
add r0,#20
str r0,[r1,#0x14]

@make a list of all tiles that are available
mov r0,#0
mov r1,#2
mov r2,#0 @ammount of tiles in the list*2
b loopnoadd
loop:
add r0,#1
loopnoadd:
cmp r0,#0x1E
bne dontincreasey
mov r0,#0
add r1,#1
dontincreasey:
cmp r1,#0x14
beq endloop
@check if the coords conflict with the body, if they do, do not add them to the list
push {r0-r2}
ldr r2,=bonkSnake
mov lr,r2
.short 0xF800
mov r3,r0
pop {r0-r2}
cmp r3,#1
beq loop
ldr r3,=#0x02005000
strb r0,[r3,r2]
add r2,#1
strb r1,[r3,r2]
add r2,#1
b loop
endloop:

ldr r0,=#0x02000000
strh r2,[r0,#0x16] @save length

@choose a tile from the list
ldr r0,=rng
mov lr,r0
.short 0xF800

ldr r3,=#0x02000000
ldrh r1,[r3,#0x16]
lsr r1,#1
add r1,#1
swi #6 @divide random number by length/2 +1
lsl r1,#1
ldr r3,=#0x02005000
ldrh r0,[r3,r1]

@store coords
ldr r3,=#0x02000000
strh r0,[r3,#6]

End:
pop {r0}
bx r0
Binary file added ASM/Snake/bonkSnake.elf
Binary file not shown.
31 changes: 31 additions & 0 deletions ASM/Snake/bonkSnake.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.thumb

@r0 = x, r1 = y

lsl r1,#8
add r0,r1 @xy

ldr r2,=#0x02000000
ldrh r3,[r2]
add r2,#0x20
lsl r3,#1
add r3,r2

loop:
cmp r2,r3
beq nobonk
ldrh r1,[r2]
cmp r1,r0
beq bonk
add r2,#2
b loop

bonk:
mov r0,#1
b End

nobonk:
mov r0,#0

End:
bx lr
Binary file modified ASM/Snake/moveSnake.elf
Binary file not shown.
53 changes: 48 additions & 5 deletions ASM/Snake/moveSnake.s
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
.thumb

push {lr}
push {r4,r5}

ldr r4,=#0x02000000
ldrb r0,[r4,#0xD]
cmp r0,#0xF0
bhi EndTrampolin
mov r5,r4
ldrh r0,[r5]
cmp r0,#0
beq gameOver
beq gameOverTrampolin
ldr r3,=#540
cmp r0,r3
beq gameOver
beq gameOverWinTrampolin

b skipTrampolin
EndTrampolin:
b End
gameOverTrampolin:
b gameOver
gameOverWinTrampolin:
b gameOverWin
skipTrampolin:

mov r3,r5
add r3,#0x20
Expand Down Expand Up @@ -110,6 +123,15 @@ b End

domove:
@check if the snake is going to hit herself
push {r0-r3}
mov r0,r1
mov r1,r2
ldr r3,=bonkSnake
mov lr,r3
.short 0xF800
cmp r0,#1
beq gameOverBonk
pop {r0-r3}
strb r1,[r4]
strb r2,[r4,#1]
b End
Expand Down Expand Up @@ -163,15 +185,36 @@ ldrh r3,[r4]
add r3,#1
strh r3,[r4]
@check if the snake is going to hit herself
push {r0-r3}
mov r0,r1
mov r1,r2
ldr r3,=bonkSnake
mov lr,r3
.short 0xF800
cmp r0,#1
beq gameOverBonk
pop {r0-r3}
strb r1,[r4,r0]
add r0,#1
strb r2,[r4,r0]
b End

End:
pop {r4,r5}
bx lr
pop {r0}
bx r0

gameOverBonk:
pop {r0-r3}

gameOver:
pop {r4,r5}
bx lr
ldr r0,=#0x02000000
mov r1,#0xFF
strb r1,[r0,#0xD]
b End

gameOverWin:
ldr r0,=#0x02000000
mov r1,#0xFE
strb r1,[r0,#0xD]
b End
Binary file modified ASM/Snake/turnSnake.elf
Binary file not shown.
83 changes: 81 additions & 2 deletions ASM/Snake/turnSnake.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
.thumb

push {lr}
ldr r1,=#0x02000000

@check game over
ldrb r0,[r1,#0xD]
cmp r0,#0xF0
bhi End

@get button presses
ldrb r0,[r1,#5]
lsl r0,#4
Expand Down Expand Up @@ -42,7 +48,7 @@ b End
store:
@one final check, check if the snake is going to be turning towards the screen
ldr r2,=#0x02000000
ldrb r1,[r2]
ldrh r1,[r2]
lsl r1,#1
add r1,#0x20
sub r1,#2
Expand All @@ -53,21 +59,89 @@ cmp r0,#0x10
bne notright
cmp r1,#0x1D
beq End
@check if bonk
push {r0-r3}
ldr r3,=bonkSnake
mov lr,r3
ldr r2,=#0x02000000
ldrh r3,[r2]
lsl r3,#1
add r3,#0x20
sub r3,#2
add r2,r3
ldrb r0,[r2]
ldrb r1,[r2,#1]
add r0,#1
.short 0xF800
cmp r0,#1
beq turnBonk
pop {r0-r3}
notright:
cmp r0,#0x20
bne notleft
cmp r1,#0
beq End
@check if bonk
push {r0-r3}
ldr r3,=bonkSnake
mov lr,r3
ldr r2,=#0x02000000
ldrh r3,[r2]
lsl r3,#1
add r3,#0x20
sub r3,#2
add r2,r3
ldrb r0,[r2]
ldrb r1,[r2,#1]
sub r0,#1
.short 0xF800
cmp r0,#1
beq turnBonk
pop {r0-r3}
notleft:
cmp r0,#0x40
bne notup
cmp r2,#2
beq End
@check if bonk
push {r0-r3}
ldr r3,=bonkSnake
mov lr,r3
ldr r2,=#0x02000000
ldrh r3,[r2]
lsl r3,#1
add r3,#0x20
sub r3,#2
add r2,r3
ldrb r0,[r2]
ldrb r1,[r2,#1]
sub r1,#1
.short 0xF800
cmp r0,#1
beq turnBonk
pop {r0-r3}
notup:
cmp r0,#0x80
bne notdown
cmp r2,#0x13
beq End
@check if bonk
push {r0-r3}
ldr r3,=bonkSnake
mov lr,r3
ldr r2,=#0x02000000
ldrh r3,[r2]
lsl r3,#1
add r3,#0x20
sub r3,#2
add r2,r3
ldrb r0,[r2]
ldrb r1,[r2,#1]
add r1,#1
.short 0xF800
cmp r0,#1
beq turnBonk
pop {r0-r3}
notdown:
ldr r1,=#0x02000000
strb r3,[r1,#2]
Expand All @@ -76,4 +150,9 @@ End:
ldr r0,=#0x02000000 @clear button presses
mov r1,#0 @this is to stop the infinite zig-zag the snake does if you hold up/down and left/right and release
strb r1,[r0,#5] @zig-zag can still be performed by holding down both keys, if you really really want to do that
bx lr
pop {r0}
bx r0

turnBonk:
pop {r0-r3}
b End
Binary file modified ASM/mainLoop.elf
Binary file not shown.
Loading

0 comments on commit d22fb95

Please sign in to comment.