Organize the engine/ directory, take 3

Renamed `title` to `movies`.
Moved some functions from `engine/routines/` to their fitting
directories, and cleaned up the base `engine/` directory.
Moved `engine/pokemon/tmhm.asm` back to `engine/items/`.

Made a new subdirectory:
* engine/tilesets: Contains all map-related graphics routines.
This commit is contained in:
mid-kid
2018-03-25 16:18:33 +02:00
parent 60e21a8663
commit 0d9241889f
36 changed files with 648 additions and 648 deletions

View File

@@ -0,0 +1,20 @@
CheckSave:: ; 4cffe
ld a, BANK(sCheckValue1) ; BANK(sCheckValue2)
call GetSRAMBank
ld a, [sCheckValue1]
ld b, a
ld a, [sCheckValue2]
ld c, a
call CloseSRAM
ld a, b
cp SAVE_CHECK_VALUE_1
jr nz, .ok
ld a, c
cp SAVE_CHECK_VALUE_2
jr nz, .ok
ld c, $1
ret
.ok
ld c, $0
ret

View File

@@ -0,0 +1,19 @@
CheckTime:: ; c000
ld a, [wTimeOfDay]
ld hl, .TimeOfDayTable
ld de, 2
call IsInArray
inc hl
ld c, [hl]
ret c
xor a
ld c, a
ret
.TimeOfDayTable: ; c012
db MORN_F, MORN
db DAY_F, DAY
db NITE_F, NITE
db NITE_F, NITE
db -1

View File

@@ -0,0 +1,86 @@
EngineFlagAction:: ; 80430
; Do action b on engine flag de
;
; b = 0: reset flag
; = 1: set flag
; > 1: check flag, result in c
;
; Setting/resetting does not return a result.
; 16-bit flag ids are considered invalid, but it's nice
; to know that the infrastructure is there.
ld a, d
cp 0
jr z, .ceiling
jr c, .read ; cp 0 can't set carry!
jr .invalid
; There are only $a2 engine flags, so
; anything beyond that is invalid too.
.ceiling
ld a, e
cp NUM_ENGINE_FLAGS
jr c, .read
; Invalid flags are treated as flag 00.
.invalid
xor a
ld e, a
ld d, a
; Get this flag's location.
.read
ld hl, EngineFlags
; location
add hl, de
add hl, de
; bit
add hl, de
; location
ld e, [hl]
inc hl
ld d, [hl]
inc hl
; bit
ld c, [hl]
; What are we doing with this flag?
ld a, b
cp 1
jr c, .reset ; b = 0
jr z, .set ; b = 1
; Return the given flag in c.
.check
ld a, [de]
and c
ld c, a
ret
; Set the given flag.
.set
ld a, [de]
or c
ld [de], a
ret
; Reset the given flag.
.reset
ld a, c
cpl ; AND all bits except the one in question
ld c, a
ld a, [de]
and c
ld [de], a
ret
; 80462
INCLUDE "data/engine_flags.asm"

221
engine/events/money.asm Executable file
View File

@@ -0,0 +1,221 @@
GiveMoney:: ; 15fd7
ld a, 3
call AddMoney
ld bc, MaxMoney
ld a, 3
call CompareMoney
jr z, .not_maxed_out
jr c, .not_maxed_out
ld hl, MaxMoney
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
scf
ret
.not_maxed_out
and a
ret
; 15ff7
MaxMoney: ; 15ff7
dt MAX_MONEY
; 15ffa
TakeMoney:: ; 15ffa
ld a, 3
call SubtractMoney
jr nc, .okay
; leave with 0 money
xor a
ld [de], a
inc de
ld [de], a
inc de
ld [de], a
scf
ret
.okay
and a
ret
; 1600b
CompareMoney:: ; 1600b
ld a, 3
CompareFunds: ; 1600d
; a: number of bytes
; bc: start addr of amount (big-endian)
; de: start addr of account (big-endian)
push hl
push de
push bc
ld h, b
ld l, c
ld c, 0
ld b, a
.loop1
dec a
jr z, .done
inc de
inc hl
jr .loop1
.done
and a
.loop2
ld a, [de]
sbc [hl]
jr z, .okay
inc c
.okay
dec de
dec hl
dec b
jr nz, .loop2
jr c, .set_carry
ld a, c
and a
jr .skip_carry
.set_carry
ld a, 1
and a
scf
.skip_carry
pop bc
pop de
pop hl
ret
; 16035
SubtractMoney: ; 16035
ld a, 3
SubtractFunds: ; 16037
; a: number of bytes
; bc: start addr of amount (big-endian)
; de: start addr of account (big-endian)
push hl
push de
push bc
ld h, b
ld l, c
ld b, a
ld c, 0
.loop
dec a
jr z, .done
inc de
inc hl
jr .loop
.done
and a
.loop2
ld a, [de]
sbc [hl]
ld [de], a
dec de
dec hl
dec b
jr nz, .loop2
pop bc
pop de
pop hl
ret
; 16053
AddMoney: ; 16053
ld a, 3
AddFunds: ; 16055
; a: number of bytes
; bc: start addr of amount (big-endian)
; de: start addr of account (big-endian)
push hl
push de
push bc
ld h, b
ld l, c
ld b, a
.loop1
dec a
jr z, .done
inc de
inc hl
jr .loop1
.done
and a
.loop2
ld a, [de]
adc [hl]
ld [de], a
dec de
dec hl
dec b
jr nz, .loop2
pop bc
pop de
pop hl
ret
; 1606f
GiveCoins:: ; 1606f
ld a, 2
ld de, wCoins
call AddFunds
ld a, 2
ld bc, .maxcoins
call CompareFunds
jr c, .not_maxed
ld hl, .maxcoins
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
scf
ret
.not_maxed
and a
ret
; 1608d
.maxcoins ; 1608d
bigdw MAX_COINS
; 1608f
TakeCoins:: ; 1608f
ld a, 2
ld de, wCoins
call SubtractFunds
jr nc, .okay
; leave with 0 coins
xor a
ld [de], a
inc de
ld [de], a
scf
ret
.okay
and a
ret
; 160a1
CheckCoins:: ; 160a1
ld a, 2
ld de, wCoins
jp CompareFunds
; 160a9

View File

@@ -0,0 +1,31 @@
PlaySlowCry: ; fb841
ld a, [wScriptVar]
call LoadCry
jr c, .done
ld hl, wCryPitch
ld a, [hli]
ld h, [hl]
ld l, a
ld bc, -$140
add hl, bc
ld a, l
ld [wCryPitch], a
ld a, h
ld [wCryPitch + 1], a
ld hl, wCryLength
ld a, [hli]
ld h, [hl]
ld l, a
ld bc, $60
add hl, bc
ld a, l
ld [wCryLength], a
ld a, h
ld [wCryLength + 1], a
farcall _PlayCry
call WaitSFX
.done
ret
; fb877