diff --git a/Code/automata.asm b/Code/automata.asm index 9c011a3..cbd8180 100644 --- a/Code/automata.asm +++ b/Code/automata.asm @@ -15,6 +15,7 @@ EXPORT Buffer1 SECTION "Automata buffer 1", WRAM0, ALIGN[9] Buffer1: ds 20 * 18 +EXPORT Old SECTION "Automata data", HRAM New: ds 1 ; high byte of pointer to bufferX Old: ds 1 ; high byte of pointer to bufferX @@ -261,6 +262,12 @@ UpdateAutomata: .bottomright ConwayGroup -19, -359, -340, -341, -1, -21, -20, -39 + ; move buffer address back to beginning + ld hl, Old + dec [hl] + xor a + ldh [Progress], a + ret EXPORT SwapBuffers, InitAutomata diff --git a/Code/edit.asm b/Code/edit.asm new file mode 100644 index 0000000..5a67eed --- /dev/null +++ b/Code/edit.asm @@ -0,0 +1,93 @@ +INCLUDE "hardware.inc" + +Section "Joypad memory", HRAM +; Bits 0..7 are A, B, Select, Start, Right, Left, Up, Down +JoypadDown: ds 1 +JoypadPressed: ds 1 + +SECTION "Update joypad", ROM0 +UpdateJoypad: + ; read directions + ld a, P1F_5 + ldh [rP1], a + ldh a, [rP1] + ldh a, [rP1] + ldh a, [rP1] + ldh a, [rP1] + and a, $0F + swap a ; move into high nibble + ld b, a + + ; read buttons + ld a, P1F_4 + ldh [rP1], a + ldh a, [rP1] + ldh a, [rP1] + ldh a, [rP1] + ldh a, [rP1] + and a, $0F + + ; merge directions and buttons + ; complement so that active buttons read as 1 + or a, b + cpl + + ; backup all buttons in B + ld b, a + + ; store just pressed buttons + ldh a, [JoypadPressed] + cpl + and a, b + ldh [JoypadDown], a + + ; store currently pressed buttons + ld a, b + ldh [JoypadPressed], a + + ; reset joypad + ld a, $30 + ldh [rP1], a + ret + +Section "Edit memory", HRAM +SelectX: ds 1 +SelectY: ds 1 + +EXPORT InitEdit +SECTION "Init edit", ROM0 +InitEdit: + ld a, 20 + ldh [SelectX], a + ld a, 18 + ldh [SelectY], a + xor a + ldh [JoypadDown], a + ldh [JoypadPressed], a + ret + + +EXPORT EditOldBuffer +SECTION "Edit old buffer", ROM0 +EditOldBuffer: + call UpdateJoypad + + ldh a, [JoypadDown] + and a, %1000 + ret z + +.loop + halt + xor a + ldh a, [rIF] + + call UpdateJoypad + ldh a, [JoypadDown] + and a, %1000 + ret nz + + jr .loop + + + + \ No newline at end of file diff --git a/Code/main.asm b/Code/main.asm index 3857ff7..a1ec0da 100644 --- a/Code/main.asm +++ b/Code/main.asm @@ -69,6 +69,7 @@ Start: call MemoryCopy call InitAutomata + call InitEdit ; enable h-blank interrupt in lcd stat ld a, STATF_MODE00 @@ -82,5 +83,6 @@ Start: call StartRender call UpdateAutomata call WaitRender + call EditOldBuffer call SwapBuffers jp .mainloop diff --git a/build.bat b/build.bat index 325b424..e5f3fc6 100644 --- a/build.bat +++ b/build.bat @@ -4,5 +4,6 @@ ..\..\Assembler\rgbasm -i ..\..\Include\ -i Graphics\ -i Code\ -o Build\render.o Code\render.asm ..\..\Assembler\rgbasm -i ..\..\Include\ -i Graphics\ -i Code\ -o Build\utils.o Code\utils.asm ..\..\Assembler\rgbasm -i ..\..\Include\ -i Graphics\ -i Code\ -o Build\nintendo-out.o Code\nintendo-out.asm -..\..\Assembler\rgblink -n rom.sym -w -t -o rom.gb -d Build/main.o Build/data.o Build/automata.o Build/render.o Build/utils.o Build/nintendo-out.o +..\..\Assembler\rgbasm -i ..\..\Include\ -i Graphics\ -i Code\ -o Build\edit.o Code\edit.asm +..\..\Assembler\rgblink -n rom.sym -w -t -o rom.gb -d Build/main.o Build/data.o Build/automata.o Build/render.o Build/utils.o Build/nintendo-out.o Build/edit.o ..\..\Assembler\rgbfix -t "Game of Life" -v -p 0 rom.gb \ No newline at end of file