diff --git a/.gitignore b/.gitignore index 3896f80..56d2b6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.db Event Assembler/ +*.sav diff --git a/ASM/Egg/Assemble ARM ELF.bat b/ASM/Egg/Assemble ARM ELF.bat new file mode 100644 index 0000000..0df75b4 --- /dev/null +++ b/ASM/Egg/Assemble ARM ELF.bat @@ -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 \ No newline at end of file diff --git a/ASM/Egg/drawEgg.elf b/ASM/Egg/drawEgg.elf new file mode 100644 index 0000000..2362451 Binary files /dev/null and b/ASM/Egg/drawEgg.elf differ diff --git a/ASM/Egg/drawEgg.s b/ASM/Egg/drawEgg.s new file mode 100644 index 0000000..db61131 --- /dev/null +++ b/ASM/Egg/drawEgg.s @@ -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 diff --git a/ASM/Egg/eatEgg.elf b/ASM/Egg/eatEgg.elf new file mode 100644 index 0000000..dc0706a Binary files /dev/null and b/ASM/Egg/eatEgg.elf differ diff --git a/ASM/Egg/eatEgg.s b/ASM/Egg/eatEgg.s new file mode 100644 index 0000000..8ee46e4 --- /dev/null +++ b/ASM/Egg/eatEgg.s @@ -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 diff --git a/ASM/Egg/makeEgg.elf b/ASM/Egg/makeEgg.elf new file mode 100644 index 0000000..0864668 Binary files /dev/null and b/ASM/Egg/makeEgg.elf differ diff --git a/ASM/Egg/makeEgg.s b/ASM/Egg/makeEgg.s new file mode 100644 index 0000000..88afea6 --- /dev/null +++ b/ASM/Egg/makeEgg.s @@ -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 diff --git a/ASM/Snake/bonkSnake.elf b/ASM/Snake/bonkSnake.elf new file mode 100644 index 0000000..18f3f17 Binary files /dev/null and b/ASM/Snake/bonkSnake.elf differ diff --git a/ASM/Snake/bonkSnake.s b/ASM/Snake/bonkSnake.s new file mode 100644 index 0000000..22c0f22 --- /dev/null +++ b/ASM/Snake/bonkSnake.s @@ -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 diff --git a/ASM/Snake/moveSnake.elf b/ASM/Snake/moveSnake.elf index b7b6753..7427eda 100644 Binary files a/ASM/Snake/moveSnake.elf and b/ASM/Snake/moveSnake.elf differ diff --git a/ASM/Snake/moveSnake.s b/ASM/Snake/moveSnake.s index 93b8399..d10db70 100644 --- a/ASM/Snake/moveSnake.s +++ b/ASM/Snake/moveSnake.s @@ -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 @@ -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 @@ -163,6 +185,15 @@ 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] @@ -170,8 +201,20 @@ 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 diff --git a/ASM/Snake/turnSnake.elf b/ASM/Snake/turnSnake.elf index 82b0bb1..5f63da8 100644 Binary files a/ASM/Snake/turnSnake.elf and b/ASM/Snake/turnSnake.elf differ diff --git a/ASM/Snake/turnSnake.s b/ASM/Snake/turnSnake.s index 138e280..f918374 100644 --- a/ASM/Snake/turnSnake.s +++ b/ASM/Snake/turnSnake.s @@ -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 @@ -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 @@ -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] @@ -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 diff --git a/ASM/mainLoop.elf b/ASM/mainLoop.elf index ece9111..3569975 100644 Binary files a/ASM/mainLoop.elf and b/ASM/mainLoop.elf differ diff --git a/ASM/mainLoop.s b/ASM/mainLoop.s index f7b932e..24da79e 100644 --- a/ASM/mainLoop.s +++ b/ASM/mainLoop.s @@ -63,6 +63,10 @@ add r0,#0x10 mov r1,#1 strb r1,[r0] @set bg 0 to be updated +ldr r0,=makeEgg +mov lr,r0 +.short 0xF800 + ldr r0,=turnSnake mov lr,r0 .short 0xF800 @@ -71,6 +75,19 @@ ldr r0,=moveSnake mov lr,r0 .short 0xF800 +ldr r0,=eatEgg +mov lr,r0 +.short 0xF800 + +ldr r0,=makeEgg +mov lr,r0 +.short 0xF800 + +ldr r0,=#0x02000000 +ldrb r0,[r0,#0xD] +cmp r0,#0xF0 +bhi nobg0draw + ldr r0,=cleanSnake mov lr,r0 .short 0xF800 @@ -79,6 +96,12 @@ ldr r0,=drawSnake mov lr,r0 .short 0xF800 +ldr r0,=drawEgg +mov lr,r0 +.short 0xF800 + +nobg0draw: + skipSnake: b main diff --git a/RAM map.txt b/RAM map.txt index 88f7e02..c7f2387 100644 --- a/RAM map.txt +++ b/RAM map.txt @@ -12,5 +12,9 @@ $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 +$02000014 BYTE Tile to use for egg +.. +$02000016 SHORT Length of list at $02005000 ... -$02000020 LIST Snake body piece coordinates \ No newline at end of file +$02000020 LIST Snake body piece coordinates +$02005000 LIST Buffer with available tiles for eggs diff --git a/ROM Buildfile.event b/ROM Buildfile.event index 8c13c70..45428c1 100644 --- a/ROM Buildfile.event +++ b/ROM Buildfile.event @@ -54,10 +54,14 @@ turnSnake: //button presses are saved each frame, even if the game logic isn't run each frame, and are cleared at the end of this routine //this allows the player to input a direction for the snake to turn to without having to hold the button down waiting for the game logic //the snake also can't turn towards the border of the screen if adjacent to it +//in addition, the snake can't turn if doing so is going to make her face her own body immediately moveSnake: #inctext lyn "ASM\Snake\moveSnake.elf" //check if the snake has grown and move all pieces of the body as needed +bonkSnake: +#inctext lyn "ASM\Snake\bonkSnake.elf" //check if the given coords are already occupied by snake, return 1 if it is + cleanSnake: #inctext lyn "ASM\Snake\cleanSnake.elf" //wipe the background layer to avoid leftover snake bits @@ -69,6 +73,15 @@ drawSnakeBody: //the checks got long enough for it to justify a routine //snake body shapes are the -, the |, the luigi, the waluigi, the mirror luigi and the mirror waluigi, of course +makeEgg: +#inctext lyn "ASM\Egg\makeEgg.elf" //spawn egg and write the coords and tile to ram for the drawEgg routine + +eatEgg: +#inctext lyn "ASM\Egg\eatEgg.elf" //check if head and egg are in the same coords, and if so remove egg and add size to snake + +drawEgg: +#inctext lyn "ASM\Egg\drawEgg.elf" //draw egg according to the coords and tile in ram + /* facing directions of the snake: 1 diff --git a/rom.gba b/rom.gba index e42d2af..d8062dd 100644 Binary files a/rom.gba and b/rom.gba differ