edit automata while paused

This commit is contained in:
2019-01-06 19:22:22 +01:00
parent 75e2589091
commit 103965a135
9 changed files with 204 additions and 14 deletions

View File

@@ -15,7 +15,7 @@ EXPORT Buffer1
SECTION "Automata buffer 1", WRAM0, ALIGN[9]
Buffer1: ds 20 * 18
EXPORT Old
EXPORT New, Old, Progress
SECTION "Automata data", HRAM
New: ds 1 ; high byte of pointer to bufferX
Old: ds 1 ; high byte of pointer to bufferX

View File

@@ -1,8 +1,13 @@
INCLUDE "hardware.inc"
INCLUDE "utils.inc"
SPRITE_ANIM_DELAY EQU 12
Section "Edit memory", HRAM
SelectX: ds 1
SelectY: ds 1
SpriteAnimation: ds 1
SpriteDelay: ds 1
EXPORT InitEdit
SECTION "Init edit", ROM0
@@ -16,22 +21,185 @@ InitEdit:
EXPORT EditOldBuffer
SECTION "Edit old buffer", ROM0
EditOldBuffer:
; check start has been pressed
ldh a, [JoypadDown]
and a, %1000
and a, JOYPAD_START
ret z
.loop
; wait v-blank
halt
; show sprites
ldh a, [rLCDC]
or a, LCDCF_OBJON
ldh [rLCDC], a
; init sprite animation
xor a
ldh a, [rIF]
ldh [SpriteAnimation], a
ld a, SPRITE_ANIM_DELAY
ldh [SpriteDelay], a
.loop
; clear interrupts
xor a
ldh [rIF], a
; compute cursor X position
ldh a, [SelectX]
sla a
sla a
add a, 8
ld b, a
; compute cursor Y position
ldh a, [SelectY]
sla a
sla a
add a, 16
ld c, a
; update and load sprite animation
ldh a, [SpriteDelay]
dec a
ldh [SpriteDelay], a
jr nz, .same
ldh a, [SpriteAnimation]
inc a
and a, 3
ldh [SpriteAnimation], a
ld a, SPRITE_ANIM_DELAY
ldh [SpriteDelay], a
.same
ldh a, [SpriteAnimation]
ld d, a
; update sprite in OAM
SetSprite 0, b, c, d, 0
call UpdateJoypad
; check A button has been pressed
ldh a, [JoypadDown]
and a, %1000
ret nz
and a, JOYPAD_A
call nz, ToggleCell
jr .loop
; check start has been pressed
ldh a, [JoypadDown]
and a, JOYPAD_START
jr nz, .exit
; check left direction
ldh a, [JoypadDown]
and a, JOYPAD_LEFT
jr z, .endLeft
ldh a, [SelectX]
and a
jr z, .endLeft
dec a
ldh [SelectX], a
.endLeft
; check up direction
ldh a, [JoypadDown]
and a, JOYPAD_UP
jr z, .endUp
ldh a, [SelectY]
and a
jr z, .endUp
dec a
ldh [SelectY], a
.endUp
; check right direction
ldh a, [JoypadDown]
and a, JOYPAD_RIGHT
jr z, .endRight
ldh a, [SelectX]
cp a, 39
jr nc, .endRight
inc a
ldh [SelectX], a
.endRight
; check down direction
ldh a, [JoypadDown]
and a, JOYPAD_DOWN
jr z, .endDown
ldh a, [SelectY]
cp a, 35
jr nc, .endDown
inc a
ldh [SelectY], a
.endDown
; wait v-blank
halt
jp .loop
.exit
; hide sprites
ldh a, [rLCDC]
and a, ~LCDCF_OBJON
ldh [rLCDC], a
ret
Section "Value to flag", ROM0, ALIGN[8]
Flag: db 1, 2, 4, 8
; \1: horizontal stride
ToggleInTargetBuffer: MACRO
; move pointer to 2x2 cell group
ldh a, [SelectY]
sra a
jr z, .addX\@
ld c, a
ld de, \1
.mul\@
add hl, de
dec c
jr nz, .mul\@
.addX\@
xor a
ld d, a
ldh a, [SelectX]
sra a
ld e, a
add hl, de
; compute cell number in 2x2 cell group
ldh a, [SelectX]
and a, 1
ld b, a
ldh a, [SelectY]
and a, 1
sla a
or a, b
; transform cell number to bit offset in 2x2 cell
ld d, HIGH(Flag)
ld e, a
ld a, [de]
ld b, a
ld a, [hl]
xor a, b
ld [hl], a
ENDM
ToggleCell:
ldh a, [Video]
ld l, a
ldh a, [Video + 1]
xor a, %100 ; change to displayed video buffer
ld h, a
ToggleInTargetBuffer 32
ldh a, [Progress]
ld l, a
ldh a, [Old]
ld h, a
ToggleInTargetBuffer 20
ret

View File

@@ -1,4 +1,5 @@
INCLUDE "hardware.inc"
INCLUDE "utils.inc"
EMPTY_BG_TILE EQU 17
_VRAM_BG_TILES EQU $9000
@@ -82,11 +83,12 @@ ENDC
ld a, LCDCF_ON
ld [rLCDC], a
ClearAndEnableInterrupts
.mainloop
call StartRender
call UpdateAutomata
call WaitRender
call SwapBuffers
call UpdateJoypad
call EditOldBuffer
call SwapBuffers
jp .mainloop

View File

@@ -132,7 +132,6 @@ ELSE
ld a, IEF_VBLANK
ENDC
ld [rIE], a
ClearAndEnableInterrupts
ret
@@ -141,11 +140,11 @@ SECTION "WaitRender", ROM0
WaitRender:
ldh a, [LinesLeft]
or a
ret z
jr z, .exit
halt
jr WaitRender
di
.exit
IF RENDER_IN_HBL != 0
; enable only v-blank interrupt and wait for vbl
ld a, IEF_VBLANK
@@ -155,4 +154,16 @@ IF RENDER_IN_HBL != 0
halt
ENDC
; move video pointer back to beginning
ld hl, Video
ld a, [hl+]
ld h, [hl]
ld l, a
ld de, -(32*18)
add hl, de
ld a, l
ldh [Video], a
ld a, h
ldh [Video + 1], a
ret

View File

@@ -1,10 +1,19 @@
INCLUDE "hardware.inc"
JOYPAD_A EQU $01
JOYPAD_B EQU $02
JOYPAD_SELECT EQU $04
JOYPAD_START EQU $08
JOYPAD_RIGHT EQU $10
JOYPAD_LEFT EQU $20
JOYPAD_UP EQU $40
JOYPAD_DOWN EQU $80
; destroys A
ClearAndEnableInterrupts: MACRO
xor a
ei ; will take effect AFTER next instruction
ldh a, [rIF]
ldh [rIF], a
ENDM
; \1: sprite ID

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
rom.gb

Binary file not shown.