Remove raster FX lib from boilerplate
It's not as needed and barebones as the rest of the boilerplate, and at least one person has been confused about it.
This commit is contained in:
@@ -6,6 +6,5 @@ INCLUDE "home/header.asm"
|
|||||||
|
|
||||||
INCLUDE "home/utils.asm"
|
INCLUDE "home/utils.asm"
|
||||||
INCLUDE "home/sgb.asm"
|
INCLUDE "home/sgb.asm"
|
||||||
INCLUDE "home/raster_fx.asm"
|
|
||||||
INCLUDE "home/unpb16.asm"
|
INCLUDE "home/unpb16.asm"
|
||||||
|
|
||||||
|
|||||||
@@ -77,18 +77,11 @@ Reset::
|
|||||||
dec b
|
dec b
|
||||||
jr nz, .copyOAMDMA
|
jr nz, .copyOAMDMA
|
||||||
|
|
||||||
ld a, LOW(hScanlineFXBuffer1)
|
|
||||||
ldh [hWhichScanlineBuffer], a
|
|
||||||
ld a, $FF
|
|
||||||
ldh [hScanlineFXBuffer1], a
|
|
||||||
ld a, STATF_LYC
|
|
||||||
ldh [rSTAT], a
|
|
||||||
|
|
||||||
ld a, LCDCF_ON | LCDCF_BGON
|
ld a, LCDCF_ON | LCDCF_BGON
|
||||||
ldh [hLCDC], a
|
ldh [hLCDC], a
|
||||||
ldh [rLCDC], a
|
ldh [rLCDC], a
|
||||||
|
|
||||||
ld a, IEF_VBLANK | IEF_LCDC
|
ld a, IEF_VBLANK
|
||||||
ldh [rIE], a
|
ldh [rIE], a
|
||||||
xor a
|
xor a
|
||||||
ei ; Delayed until the next instruction: perfectly safe!
|
ei ; Delayed until the next instruction: perfectly safe!
|
||||||
|
|||||||
@@ -1,221 +0,0 @@
|
|||||||
|
|
||||||
SECTION "Raster fx helper functions", ROM0
|
|
||||||
|
|
||||||
; Get a pointer to the currently free scanline buffer
|
|
||||||
; @return a The pointer
|
|
||||||
; @return c The pointer
|
|
||||||
; @destroys a c
|
|
||||||
GetFreeScanlineBuf::
|
|
||||||
ldh a, [hWhichScanlineBuffer]
|
|
||||||
xor LOW(hScanlineFXBuffer2) ^ LOW(hScanlineFXBuffer1)
|
|
||||||
ld c, a
|
|
||||||
ret
|
|
||||||
|
|
||||||
; Switches to the currently free scanline buffer
|
|
||||||
; @return c A pointer to the newly freed buffer
|
|
||||||
; @return b A pointer to the newly used buffer
|
|
||||||
; @destroys a c
|
|
||||||
SwitchScanlineBuf::
|
|
||||||
call GetFreeScanlineBuf
|
|
||||||
ldh [hWhichScanlineBuffer], a
|
|
||||||
ld b, a
|
|
||||||
xor LOW(hScanlineFXBuffer2) ^ LOW(hScanlineFXBuffer1)
|
|
||||||
ld c, a
|
|
||||||
ret
|
|
||||||
|
|
||||||
; Switches to the currently free scanline buffer, and copies it over to the other buffer
|
|
||||||
; @destroys a c hl
|
|
||||||
SwitchAndCopyScanlineBuf::
|
|
||||||
call SwitchScanlineBuf
|
|
||||||
ld l, b
|
|
||||||
ld h, HIGH(hScanlineFXBuffer1)
|
|
||||||
.loop
|
|
||||||
ld a, [hli]
|
|
||||||
ld [$ff00+c], a
|
|
||||||
inc c
|
|
||||||
inc a
|
|
||||||
jr nz, .loop
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
; Finds the effect applied to a given scanline
|
|
||||||
; @param b The scanline being looked for
|
|
||||||
; @return Zero Set if the lookup succeeded
|
|
||||||
; @return c A pointer to the effect's scanline, otherwise to the terminating $FF byte
|
|
||||||
; @destroys a c
|
|
||||||
GetFXByScanline::
|
|
||||||
call GetFreeScanlineBuf
|
|
||||||
.lookup
|
|
||||||
ld a, [$ff00+c]
|
|
||||||
cp b
|
|
||||||
ret nc ; Return if scanline was greater than or equal
|
|
||||||
inc c
|
|
||||||
inc c
|
|
||||||
inc c
|
|
||||||
jr .lookup
|
|
||||||
|
|
||||||
; Insert effect into the free buffer at the given scanline
|
|
||||||
; The effect's scanline will have been set, and the other two values will be zero'd
|
|
||||||
; @param b The scanline to insert the effect at
|
|
||||||
; @return c A pointer to the new effect's port address
|
|
||||||
; @return Zero Set if the scanline is already taken (in which case c still holds the correct value)
|
|
||||||
; @destroys a bc hl
|
|
||||||
InsertFX::
|
|
||||||
call GetFreeScanlineBuf
|
|
||||||
ld l, c
|
|
||||||
ld h, HIGH(hScanlineFXBuffer1)
|
|
||||||
scf ; Don't skip the check
|
|
||||||
.lookForEnd
|
|
||||||
ld a, [hli]
|
|
||||||
inc l
|
|
||||||
; C is inherited from previous `cp b`
|
|
||||||
jr nc, .skip ; If we're already greater then the scanline, skip this
|
|
||||||
cp b
|
|
||||||
ret z ; End now if the scanline is already taken, because two FX can't be on the same line
|
|
||||||
jr c, .skip ; Skip if we aren't the first greater than the scanline
|
|
||||||
ld c, l ; Make c point to the target's value
|
|
||||||
.skip
|
|
||||||
inc l
|
|
||||||
inc a
|
|
||||||
jr nz, .lookForEnd
|
|
||||||
; Write new terminator ($FF)
|
|
||||||
ld [hl], h ; Bet you didn't expect this opcode to ever be used, eh?
|
|
||||||
dec l
|
|
||||||
.copy
|
|
||||||
dec l
|
|
||||||
dec l
|
|
||||||
dec l
|
|
||||||
ld a, [hli]
|
|
||||||
inc l
|
|
||||||
inc l
|
|
||||||
ld [hld], a ; If we just copied the target scanline,
|
|
||||||
ld a, l ; this points to the value
|
|
||||||
cp c ; which we know the address of!
|
|
||||||
jr nz, .copy
|
|
||||||
; Move the pointer and init the new fx
|
|
||||||
xor a
|
|
||||||
ld [hld], a
|
|
||||||
ld [hld], a
|
|
||||||
ld [hl], b ; Write the desired scanline
|
|
||||||
inc a ; Don't have Z set
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
; Remove effect from the free buffer
|
|
||||||
; @param b The targeted effect's scanline
|
|
||||||
; @return Zero Set if the lookup succeeded
|
|
||||||
; @destroys a c hl
|
|
||||||
RemoveFX::
|
|
||||||
call GetFXByScanline
|
|
||||||
ret nz
|
|
||||||
ld l, c
|
|
||||||
ld h, HIGH(hScanlineFXBuffer1)
|
|
||||||
inc c
|
|
||||||
inc c
|
|
||||||
inc c
|
|
||||||
.copy
|
|
||||||
; Copy scanline
|
|
||||||
ld a, [$ff00+c]
|
|
||||||
ld [hli], a
|
|
||||||
inc a
|
|
||||||
ret z ; End if we copied the terminator
|
|
||||||
inc c
|
|
||||||
; Copy port address
|
|
||||||
ld a, [$ff00+c]
|
|
||||||
ld [hli], a
|
|
||||||
inc c
|
|
||||||
; Copy value
|
|
||||||
ld a, [$ff00+c]
|
|
||||||
ld [hli], a
|
|
||||||
inc c
|
|
||||||
jr .copy
|
|
||||||
|
|
||||||
|
|
||||||
; Add the textbox raster FX
|
|
||||||
; Caution: overwrites the currently free fx buffer with the active (+textbox)
|
|
||||||
; @param b The number of pixels of the textbox to display (0 closes it)
|
|
||||||
; @destroys a bc de hl
|
|
||||||
SetUpTextbox::
|
|
||||||
ld h, HIGH(hWhichScanlineBuffer)
|
|
||||||
|
|
||||||
; Check if backup operations should be performed
|
|
||||||
ldh a, [hIsTextboxActive]
|
|
||||||
and a
|
|
||||||
jr nz, .dontBackup
|
|
||||||
ld a, b
|
|
||||||
and a
|
|
||||||
ret z ; Do nothing if the textbox is closed while it is closed (lol)
|
|
||||||
ldh a, [hWhichScanlineBuffer]
|
|
||||||
ld c, a
|
|
||||||
ld l, LOW(hBackupScanlineFXBuffer)
|
|
||||||
.backup
|
|
||||||
ld a, [$ff00+c]
|
|
||||||
inc c
|
|
||||||
ld [hli], a
|
|
||||||
inc a
|
|
||||||
jr nz, .backup
|
|
||||||
inc a ; ld a, 1
|
|
||||||
ldh [hIsTextboxActive], a
|
|
||||||
; Fall through, but this won't get executed
|
|
||||||
.dontBackup
|
|
||||||
ld a, b
|
|
||||||
and a
|
|
||||||
jr z, .restoreAndQuit
|
|
||||||
|
|
||||||
; Get pointers to buffers
|
|
||||||
ldh a, [hWhichScanlineBuffer]
|
|
||||||
ld c, a
|
|
||||||
xor LOW(hScanlineFXBuffer2) ^ LOW(hScanlineFXBuffer1)
|
|
||||||
ld l, a
|
|
||||||
; Calculate scanline
|
|
||||||
ld a, SCRN_Y
|
|
||||||
sub b
|
|
||||||
ld b, a
|
|
||||||
|
|
||||||
scf
|
|
||||||
.copy
|
|
||||||
ld a, [$ff00+c] ; Get scanline
|
|
||||||
cp b
|
|
||||||
jr nc, .insertTextbox
|
|
||||||
inc c
|
|
||||||
ld [hl], a
|
|
||||||
ld a, [$ff00+c] ; Read port
|
|
||||||
inc c
|
|
||||||
inc c ; Skip value, jic
|
|
||||||
and a ; Are we copying a textbox FX?
|
|
||||||
jr z, .copy ; Abort
|
|
||||||
inc l
|
|
||||||
ld [hli], a
|
|
||||||
dec c
|
|
||||||
ld a, [$ff00+c] ; Read value
|
|
||||||
inc c
|
|
||||||
ld [hli], a
|
|
||||||
jr .copy
|
|
||||||
|
|
||||||
.restoreAndQuit
|
|
||||||
call GetFreeScanlineBuf
|
|
||||||
.restore
|
|
||||||
ld a, [hli]
|
|
||||||
ld [$ff00+c], a
|
|
||||||
inc c
|
|
||||||
inc a
|
|
||||||
jr nz, .restore
|
|
||||||
; a = 0
|
|
||||||
ldh [hIsTextboxActive], a
|
|
||||||
ret
|
|
||||||
|
|
||||||
.insertTextbox
|
|
||||||
; Place the textbox FX
|
|
||||||
ld [hl], b
|
|
||||||
inc l
|
|
||||||
ld [hl], 0
|
|
||||||
inc l
|
|
||||||
ld a, b
|
|
||||||
sub SCRN_Y
|
|
||||||
ld [hli], a
|
|
||||||
ld [hl], $FF ; Don't forget to terminate!
|
|
||||||
|
|
||||||
ldh a, [hWhichScanlineBuffer]
|
|
||||||
xor LOW(hScanlineFXBuffer2) ^ LOW(hScanlineFXBuffer1)
|
|
||||||
ldh [hWhichScanlineBuffer], a
|
|
||||||
ret
|
|
||||||
@@ -98,12 +98,8 @@ ENDM
|
|||||||
jp VBlankHandler
|
jp VBlankHandler
|
||||||
|
|
||||||
; LCD
|
; LCD
|
||||||
push af
|
reti
|
||||||
push bc
|
ds 7
|
||||||
ldh a, [hScanlineFXIndex]
|
|
||||||
ld c, a
|
|
||||||
ld a, [c] ; Get port ID
|
|
||||||
jr LCDHandler
|
|
||||||
|
|
||||||
; Timer
|
; Timer
|
||||||
reti
|
reti
|
||||||
@@ -125,70 +121,6 @@ CallDE::
|
|||||||
reti
|
reti
|
||||||
|
|
||||||
|
|
||||||
LCDHandler:
|
|
||||||
ld b, a ; Save port ID for later
|
|
||||||
inc c
|
|
||||||
inc c
|
|
||||||
ld a, [c] ; Get next effect's scanline
|
|
||||||
dec a ; Compensate for processing time
|
|
||||||
ldh [rLYC], a ; Get set up (hopefully this should reset the interrupt trigger line)
|
|
||||||
ld a, c ; Point to next effect's port ID
|
|
||||||
inc a
|
|
||||||
ldh [hScanlineFXIndex], a
|
|
||||||
dec c
|
|
||||||
; Wait a bit to write during HBlank, to avoid gfx artifacts
|
|
||||||
ld a, 4
|
|
||||||
.waitMode0
|
|
||||||
dec a
|
|
||||||
jr nz, .waitMode0
|
|
||||||
|
|
||||||
; Check if we're trying to write to P1 ($FF*00*)
|
|
||||||
ld a, b
|
|
||||||
and a ; Note: `and $7F` can be used instead to have control on bit 7 (if ever needed)
|
|
||||||
; Perform common ops
|
|
||||||
ld a, [c] ; Get value
|
|
||||||
; rP1 is hardwired to instead perform textbox ops
|
|
||||||
jr nz, .notTextbox
|
|
||||||
|
|
||||||
ldh [rSCY], a ; Store value, which is actually for SCY (dat plot twist, eh?)
|
|
||||||
xor a
|
|
||||||
ldh [rSCX], a
|
|
||||||
ld c, LOW(rLCDC)
|
|
||||||
ldh a, [hLCDC] ; Retrieve LCDC value
|
|
||||||
and ~(LCDCF_WINON | LCDCF_BG8000 | LCDCF_OBJON)
|
|
||||||
or LCDCF_BG9C00
|
|
||||||
; Note: this is scrapped support for sprites on the textbox
|
|
||||||
; It was initially planned for JP diacritics.
|
|
||||||
; If for whatever reason, you need to re-activate this feature...
|
|
||||||
; ...uncomment this, and remove "LCDCF_OBJON" from above.
|
|
||||||
;
|
|
||||||
; ld [c], a ; Apply LCDC modification
|
|
||||||
; ; Perform OAM DMA to get textbox's sprites
|
|
||||||
; ; Luckily, sprites are hidden during DMA
|
|
||||||
; ; Also no sprites should be present on the textbox 1st row, hiding our trickery >:P
|
|
||||||
; ld a, HIGH(wTextboxOAM)
|
|
||||||
; call hOAMDMA
|
|
||||||
; ; Reload OAM on next frame
|
|
||||||
; ldh a, [hCurrentOAMBuffer]
|
|
||||||
; ldh [hOAMBuffer], a
|
|
||||||
; jr .onlyOneEffect
|
|
||||||
|
|
||||||
.notTextbox
|
|
||||||
ld c, b ; Retrieve port
|
|
||||||
res 7, c
|
|
||||||
ld [c], a ; Apply FX
|
|
||||||
bit 7, b
|
|
||||||
jr z, .onlyOneEffect
|
|
||||||
ldh a, [hSecondFXAddr]
|
|
||||||
ld c, a
|
|
||||||
ldh a, [hSecondFXValue]
|
|
||||||
ld [$ff00+c], a
|
|
||||||
.onlyOneEffect
|
|
||||||
pop bc
|
|
||||||
pop af
|
|
||||||
reti
|
|
||||||
|
|
||||||
|
|
||||||
SECTION "VBlank handler", ROM0
|
SECTION "VBlank handler", ROM0
|
||||||
|
|
||||||
VBlankHandler:
|
VBlankHandler:
|
||||||
@@ -203,19 +135,6 @@ VBlankHandler:
|
|||||||
transfer_reg WX
|
transfer_reg WX
|
||||||
|
|
||||||
|
|
||||||
ldh a, [hWhichScanlineBuffer]
|
|
||||||
ld c, a
|
|
||||||
; Get first effect's scanline
|
|
||||||
ld a, [$ff00+c]
|
|
||||||
dec a ; Compensate for the processing time
|
|
||||||
; NOTE: this assumes no effect is scheduled on line 0
|
|
||||||
; This should never happen; instead, use the HRAM shadow regs (hSCY, etc.)
|
|
||||||
ldh [rLYC], a
|
|
||||||
inc c
|
|
||||||
ld a, c
|
|
||||||
ldh [hScanlineFXIndex], a
|
|
||||||
|
|
||||||
|
|
||||||
; Update OAM if needed
|
; Update OAM if needed
|
||||||
; Do this last so it will go through even without time
|
; Do this last so it will go through even without time
|
||||||
; This will simply cause sprites to not be displayed on the top few scanlines, but that's not as bad as palettes not loading at all, huh?
|
; This will simply cause sprites to not be displayed on the top few scanlines, but that's not as bad as palettes not loading at all, huh?
|
||||||
|
|||||||
@@ -45,34 +45,6 @@ hOBP1::
|
|||||||
db
|
db
|
||||||
|
|
||||||
|
|
||||||
; Low byte of the current scanline buffer
|
|
||||||
; Permits double-buffering
|
|
||||||
hWhichScanlineBuffer::
|
|
||||||
db
|
|
||||||
; Low byte of byte read by STAT handler
|
|
||||||
; NO TOUCHY
|
|
||||||
hScanlineFXIndex::
|
|
||||||
db
|
|
||||||
|
|
||||||
; Scanline FX buffers (scanline, addr, value)
|
|
||||||
; Double-buffering used to prevent ract conditions
|
|
||||||
hScanlineFXBuffer1::
|
|
||||||
ds 3 * 5 + 1
|
|
||||||
hScanlineFXBuffer2::
|
|
||||||
ds 3 * 5 + 1
|
|
||||||
|
|
||||||
; Addr/value pair to allow writing to 2 regs in the same scanline
|
|
||||||
hSecondFXAddr::
|
|
||||||
db
|
|
||||||
hSecondFXValue::
|
|
||||||
db
|
|
||||||
|
|
||||||
hIsTextboxActive::
|
|
||||||
db
|
|
||||||
hBackupScanlineFXBuffer::
|
|
||||||
ds 3 * 5 + 1
|
|
||||||
|
|
||||||
|
|
||||||
; Joypad regs
|
; Joypad regs
|
||||||
hHeldButtons::
|
hHeldButtons::
|
||||||
db
|
db
|
||||||
|
|||||||
Reference in New Issue
Block a user