useful macros, jingle when toggling edit mode, sound effect when clearing

This commit is contained in:
2019-01-07 22:21:44 +01:00
parent ba57562bd8
commit ea776334b3
5 changed files with 119 additions and 47 deletions

View File

@@ -5,7 +5,7 @@ SPRITE_ANIM_DELAY EQU 12
REPEAT_START_DELAY EQU 16 REPEAT_START_DELAY EQU 16
REPEAT_DELAY EQU 3 REPEAT_DELAY EQU 3
Section "Edit memory", HRAM SECTION "Edit memory", HRAM
SelectX: ds 1 SelectX: ds 1
SelectY: ds 1 SelectY: ds 1
Down: ds 1 Down: ds 1
@@ -26,22 +26,64 @@ InitEdit:
ldh [RepeatDelay], a ldh [RepeatDelay], a
ret ret
SECTION "Jingle", ROM0
Jingle:
; load initial frequency into HL
FREQUENCY = 330
ld hl, PULSE_FREQUENCY
; load step to be added to frequency in DE
; based on if a != 0 or not
or a
jr z, .up
.down
ld de, 100
jr .do
.up
ld de, -100
.do
; load note count
ld b, 3
.loop
; play pulse channel 1 with frequency set in HL
xor a
ldh [rNR10], a ; sweep
ld a, (%01 << 6) + 30
ldh [rNR11], a ; pattern + sound length
ld a, $43
ldh [rNR12], a ; init volume + envelope sweep
ld a, l
ldh [rNR13], a
ld a, h
or a, SOUND_START
ldh [rNR14], a
; add DE to HL frequency
add hl, de
; wait ~166ms
ld c, 6
.delay
HaltAndClearInterrupts
dec c
jr nz, .delay
; repeat a few times
dec b
ret z
jr .loop
EXPORT EditOldBuffer EXPORT EditOldBuffer
SECTION "Edit old buffer", ROM0 SECTION "Edit old buffer", ROM0
EditOldBuffer: EditOldBuffer:
; check start has been pressed ; check start has been pressed
ldh a, [JoypadDown] ldh a, [JoypadDown]
and a, JOYPAD_START and a, PADF_START
ret z ret z
; wait v-blank
halt
; show sprites
ldh a, [rLCDC]
or a, LCDCF_OBJON
ldh [rLCDC], a
; sound ON ; sound ON
ld a, $80 ld a, $80
ldh [rNR52], a ldh [rNR52], a
@@ -50,6 +92,18 @@ EditOldBuffer:
ld a, $99 ld a, $99
ldh [rNR51], a ; channels 1 (pulse) and 4 (noise) on both speakers ldh [rNR51], a ; channels 1 (pulse) and 4 (noise) on both speakers
; play jingle with notes going down
xor a
call Jingle
; wait v-blank
halt
; show sprites
ldh a, [rLCDC]
or a, LCDCF_OBJON
ldh [rLCDC], a
; init sprite animation ; init sprite animation
xor a xor a
ldh [SpriteAnimation], a ldh [SpriteAnimation], a
@@ -61,11 +115,11 @@ EditOldBuffer:
xor a, %100 xor a, %100
ldh [Video + 1], a ldh [Video + 1], a
.loop
; clear interrupts ; clear interrupts
xor a xor a
ldh [rIF], a ldh [rIF], a
.loop
; compute cursor X position ; compute cursor X position
ldh a, [SelectX] ldh a, [SelectX]
sla a sla a
@@ -102,16 +156,16 @@ EditOldBuffer:
; check A button has been pressed ; check A button has been pressed
ldh a, [JoypadDown] ldh a, [JoypadDown]
and a, JOYPAD_A and a, PADF_A
call nz, ToggleCell call nz, ToggleCell
ldh a, [JoypadDown] ldh a, [JoypadDown]
and a, JOYPAD_SELECT and a, PADF_SELECT
call nz, Clear call nz, Clear
; check start has been pressed ; check start has been pressed
ldh a, [JoypadDown] ldh a, [JoypadDown]
and a, JOYPAD_START and a, PADF_START
jr nz, .exit jr nz, .exit
; reset input ; reset input
@@ -155,7 +209,7 @@ EditOldBuffer:
.do .do
; check left direction ; check left direction
ldh a, [Down] ldh a, [Down]
and a, JOYPAD_LEFT and a, PADF_LEFT
jr z, .endLeft jr z, .endLeft
ldh a, [SelectX] ldh a, [SelectX]
and a and a
@@ -166,7 +220,7 @@ EditOldBuffer:
; check up direction ; check up direction
ldh a, [Down] ldh a, [Down]
and a, JOYPAD_UP and a, PADF_UP
jr z, .endUp jr z, .endUp
ldh a, [SelectY] ldh a, [SelectY]
and a and a
@@ -177,7 +231,7 @@ EditOldBuffer:
; check right direction ; check right direction
ldh a, [Down] ldh a, [Down]
and a, JOYPAD_RIGHT and a, PADF_RIGHT
jr z, .endRight jr z, .endRight
ldh a, [SelectX] ldh a, [SelectX]
cp a, 39 cp a, 39
@@ -188,7 +242,7 @@ EditOldBuffer:
; check down direction ; check down direction
ldh a, [Down] ldh a, [Down]
and a, JOYPAD_DOWN and a, PADF_DOWN
jr z, .endDown jr z, .endDown
ldh a, [SelectY] ldh a, [SelectY]
cp a, 35 cp a, 35
@@ -199,12 +253,15 @@ EditOldBuffer:
; wait v-blank ; wait v-blank
.skip .skip
halt HaltAndClearInterrupts
jp .loop jp .loop
.exit .exit
ld a, 1
call Jingle
; hide sprites ; hide sprites
ldh a, [rLCDC] ldh a, [rLCDC]
and a, ~LCDCF_OBJON and a, ~LCDCF_OBJON
@@ -215,13 +272,20 @@ EditOldBuffer:
xor a, %100 xor a, %100
ldh [Video + 1], a ldh [Video + 1], a
; wait for sound to finish
ld b, 10
.waitSound
HaltAndClearInterrupts
dec b
jr nz, .waitSound
; sound OFF ; sound OFF
xor a xor a
ldh [rNR52], a ldh [rNR52], a
ret ret
Section "Value to flag", ROM0, ALIGN[8] SECTION "Value to flag", ROM0, ALIGN[8]
Flag: db 1, 2, 4, 8 Flag: db 1, 2, 4, 8
; \1: horizontal stride ; \1: horizontal stride
@@ -245,6 +309,7 @@ MoveToCell: MACRO
add hl, de add hl, de
ENDM ENDM
SECTION "Toggle cell", ROM0
ToggleCell: ToggleCell:
; compute cell number in 2x2 cell group ; compute cell number in 2x2 cell group
ldh a, [SelectX] ldh a, [SelectX]
@@ -309,14 +374,16 @@ ToggleCell:
ldh [rNR11], a ; pattern + sound length ldh [rNR11], a ; pattern + sound length
ld a, $43 ld a, $43
ldh [rNR12], a ; init volume + envelope sweep ldh [rNR12], a ; init volume + envelope sweep
ld a, $D7 FREQUENCY = 100
ldh [rNR13], a ; frequency low ($6D7 = 1751 => 440Hz) ld a, LOW(PULSE_FREQUENCY)
ld a, $83 ldh [rNR13], a
ldh [rNR14], a ; start + frequency high ld a, SOUND_START | HIGH(PULSE_FREQUENCY)
ldh [rNR14], a
.exit .exit
ret ret
SECTION "Clear buffers", ROM0
Clear: Clear:
; load old buffer address and store into rendered ; load old buffer address and store into rendered
ldh a, [Progress] ldh a, [Progress]
@@ -331,6 +398,16 @@ Clear:
ld d, 0 ld d, 0
call MemorySet call MemorySet
; play long noise
xor a
ldh [rNR41], a ; set sound duration
ld a, $F4
ldh [rNR42], a ; set volume with long sweep
ld a, $72
ldh [rNR43], a ; set frequency
ld a, $80
ldh [rNR44], a ; start
; render cleared buffer ; render cleared buffer
call StartRender call StartRender
call WaitRender call WaitRender

View File

@@ -1,16 +1,11 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
INCLUDE "utils.inc"
SECTION "Random", ROM0, ALIGN[4] SECTION "Random", ROM0, ALIGN[4]
Random: Random:
db -1, 1, 2, -1, 4, 3, -2, -1, -4, 3, -1, 5, 2 db -1, 1, 2, -1, 4, 3, -2, -1, -4, 3, -1, 5, 2
RandomEnd: RandomEnd:
HaltAndClearIF: MACRO
halt
xor a
ld [rIF], a
ENDM
EXPORT ScrollNintendoOut EXPORT ScrollNintendoOut
SECTION "Scroll Nintendo Out", ROM0 SECTION "Scroll Nintendo Out", ROM0
ScrollNintendoOut: ScrollNintendoOut:
@@ -18,7 +13,7 @@ ScrollNintendoOut:
; wait a moment ; wait a moment
ld b, 32 ld b, 32
.wait .wait
HaltAndClearIF HaltAndClearInterrupts
dec b dec b
jr nz, .wait jr nz, .wait
@@ -45,8 +40,8 @@ ScrollNintendoOut:
ld e, 0 ld e, 0
ld b, 42 ld b, 42
.noise .noise
HaltAndClearIF HaltAndClearInterrupts
HaltAndClearIF HaltAndClearInterrupts
ld a, [de] ld a, [de]
ldh [rSCY], a ldh [rSCY], a
@@ -85,7 +80,7 @@ ScrollNintendoOut:
; nintendo logo lift-off! ; nintendo logo lift-off!
.scrollup .scrollup
HaltAndClearIF HaltAndClearInterrupts
; scroll up ; scroll up
ldh a, [rSCY] ldh a, [rSCY]

View File

@@ -149,9 +149,7 @@ IF RENDER_IN_HBL != 0
; enable only v-blank interrupt and wait for vbl ; enable only v-blank interrupt and wait for vbl
ld a, IEF_VBLANK ld a, IEF_VBLANK
ld [rIE], a ld [rIE], a
xor a HaltAndClearInterrupts
ldh [rIF], a
halt
ENDC ENDC
ret ret

View File

@@ -1,14 +1,9 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
JOYPAD_A EQU $01 JOYPAD_DIRECTIONS EQU (PADF_UP | PADF_DOWN | PADF_LEFT | PADF_RIGHT)
JOYPAD_B EQU $02
JOYPAD_SELECT EQU $04 SOUND_START EQU $80
JOYPAD_START EQU $08 PULSE_FREQUENCY EQUS "(-131072 / (FREQUENCY) + 2048)"
JOYPAD_RIGHT EQU $10
JOYPAD_LEFT EQU $20
JOYPAD_UP EQU $40
JOYPAD_DOWN EQU $80
JOYPAD_DIRECTIONS EQU $F0
; destroys A ; destroys A
ClearAndEnableInterrupts: MACRO ClearAndEnableInterrupts: MACRO
@@ -17,6 +12,13 @@ ClearAndEnableInterrupts: MACRO
ldh [rIF], a ldh [rIF], a
ENDM ENDM
; destroys A
HaltAndClearInterrupts: MACRO
xor a
ldh [rIF], a
halt
ENDM
; \1: sprite ID ; \1: sprite ID
; \2: X position ; \2: X position
; \3: Y position ; \3: Y position

BIN
rom.gb

Binary file not shown.