move common asm from engine/ to common/

engine/ was getting really bloated and common asm wasnt what it was made for
This commit is contained in:
yenatch
2013-09-07 23:38:19 -04:00
parent 7a3a4f913b
commit 9f53825ce2
20 changed files with 19 additions and 19 deletions

View File

@@ -1,431 +0,0 @@
; Functions to copy data from ROM.
Functiondc9: ; dc9
ld a, [rLCDC]
bit 7, a
jp z, Copy2bpp
ld a, [hROMBank]
push af
ld a, BANK(Function104284)
rst Bankswitch
call Function104284
pop af
rst Bankswitch
ret
; ddc
Functionddc: ; ddc
ld a, [rLCDC]
bit 7, a
jp z, Copy1bpp
ld a, [hROMBank]
push af
ld a, BANK(Function1042b2)
rst Bankswitch
call Function1042b2
pop af
rst Bankswitch
ret
; def
Functiondef: ; def
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call FarCopyBytesDouble
pop af
rst Bankswitch
ret
; dfd
Functiondfd: ; dfd
dec c
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
.asm_e09
ld a, d
ld [rHDMA1], a
ld a, e
and $f0
ld [rHDMA2], a
ld a, h
and $1f
ld [rHDMA3], a
ld a, l
and $f0
ld [rHDMA4], a
ld a, c
cp $8
jr c, .asm_e3c
sub $8
ld c, a
ld a, $f
ld [hDMATransfer], a
call DelayFrame
ld a, l
add $0
ld l, a
ld a, h
adc $1
ld h, a
ld a, e
add $0
ld e, a
ld a, d
adc $1
ld d, a
jr .asm_e09
.asm_e3c
ld a, c
and $7f
ld [hDMATransfer], a
call DelayFrame
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
; e4a
Functione4a: ; e4a
ld a, $5
ld hl, $4135
rst FarCall
ret
; e51
Functione51: ; e51
ld a, $3e
ld hl, $7449
rst FarCall
ret
; e58
Functione58: ; e58
ld a, $3e
ld hl, $74be
rst FarCall
ret
; e5f
Functione5f: ; e5f
ld a, $3e
ld hl, $748a
rst FarCall
ld a, $3e
ld hl, $74b0
rst FarCall
ret
; e6c
Functione6c: ; e6c
ld a, $3e
ld hl, $74b0
rst FarCall
ret
; e73
Functione73: ; e73
push de
ld a, $0
call GetSRAMBank
push bc
ld de, $a000
ld a, b
call FarDecompress
pop bc
pop hl
ld de, $a000
call Request2bpp
call CloseSRAM
ret
; e8d
FarCopyBytes: ; e8d
; copy bc bytes from a:hl to de
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call CopyBytes
pop af
rst Bankswitch
ret
; 0xe9b
FarCopyBytesDouble: ; e9b
; Copy bc bytes from a:hl to bc*2 bytes at de,
; doubling each byte in the process.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
; switcheroo, de <> hl
ld a, h
ld h, d
ld d, a
ld a, l
ld l, e
ld e, a
inc b
inc c
jr .dec
.loop
ld a, [de]
inc de
ld [hli], a
ld [hli], a
.dec
dec c
jr nz, .loop
dec b
jr nz, .loop
pop af
rst Bankswitch
ret
; 0xeba
Request2bpp: ; eba
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, [$ffd3]
push af
ld a, $8
ld [$ffd3], a
ld a, [InLinkBattle]
cp $4
jr nz, .asm_edc
ld a, [$ffe9]
and a
jr nz, .asm_edc
ld a, $6
ld [$ffd3], a
.asm_edc
ld a, e
ld [Requested2bppSource], a
ld a, d
ld [Requested2bppSource + 1], a
ld a, l
ld [Requested2bppDest], a
ld a, h
ld [Requested2bppDest + 1], a
.asm_eec
ld a, c
ld hl, $ffd3
cp [hl]
jr nc, .asm_f08
ld [Requested2bpp], a
.wait
call DelayFrame
ld a, [Requested2bpp]
and a
jr nz, .wait
pop af
ld [$ffd3], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.asm_f08
ld a, [$ffd3]
ld [Requested2bpp], a
.asm_f0d
call DelayFrame
ld a, [Requested2bpp]
and a
jr nz, .asm_f0d
ld a, c
ld hl, $ffd3
sub [hl]
ld c, a
jr .asm_eec
; f1e
Request1bpp: ; f1e
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, [$ffd3]
push af
ld a, $8
ld [$ffd3], a
ld a, [InLinkBattle]
cp $4
jr nz, .asm_f40
ld a, [$ffe9]
and a
jr nz, .asm_f40
ld a, $6
ld [$ffd3], a
.asm_f40
ld a, e
ld [Requested1bppSource], a
ld a, d
ld [Requested1bppSource + 1], a
ld a, l
ld [Requested1bppDest], a
ld a, h
ld [Requested1bppDest + 1], a
.asm_f50
ld a, c
ld hl, $ffd3
cp [hl]
jr nc, .asm_f6c
ld [Requested1bpp], a
.wait
call DelayFrame
ld a, [Requested1bpp]
and a
jr nz, .wait
pop af
ld [$ffd3], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.asm_f6c
ld a, [$ffd3]
ld [Requested1bpp], a
.asm_f71
call DelayFrame
ld a, [Requested1bpp]
and a
jr nz, .asm_f71
ld a, c
ld hl, $ffd3
sub [hl]
ld c, a
jr .asm_f50
; f82
Get2bpp: ; f82
ld a, [rLCDC]
bit 7, a
jp nz, Request2bpp
Copy2bpp: ; f89
; copy c 2bpp tiles from b:de to hl
push hl
ld h, d
ld l, e
pop de
; bank
ld a, b
; bc = c * $10
push af
swap c
ld a, $f
and c
ld b, a
ld a, $f0
and c
ld c, a
pop af
jp FarCopyBytes
; f9d
Get1bpp: ; f9d
ld a, [rLCDC]
bit 7, a
jp nz, Request1bpp
Copy1bpp: ; fa4
; copy c 1bpp tiles from b:de to hl
push de
ld d, h
ld e, l
; bank
ld a, b
; bc = c * $10 / 2
push af
ld h, 0
ld l, c
add hl, hl
add hl, hl
add hl, hl
ld b, h
ld c, l
pop af
pop hl
jp FarCopyBytesDouble
; fb6

View File

@@ -1,367 +0,0 @@
FarDecompress: ; b40
; Decompress graphics data at a:hl to de
; put a away for a sec
ld [$c2c4], a
; save bank
ld a, [hROMBank]
push af
; bankswitch
ld a, [$c2c4]
rst Bankswitch
; what we came here for
call Decompress
; restore bank
pop af
rst Bankswitch
ret
; b50
Decompress: ; b50
; Pokemon Crystal uses an lz variant for compression.
; This is mainly used for graphics, but the intro's
; tilemaps also use this compression.
; This function decompresses lz-compressed data at hl to de.
; Basic rundown:
; A typical control command consists of:
; -the command (bits 5-7)
; -the count (bits 0-4)
; -and any additional params
; $ff is used as a terminator.
; Commands:
; 0: literal
; literal data for some number of bytes
; 1: iterate
; one byte repeated for some number of bytes
; 2: alternate
; two bytes alternated for some number of bytes
; 3: zero (whitespace)
; 0x00 repeated for some number of bytes
; Repeater control commands have a signed parameter used to determine the start point.
; Wraparound is simulated:
; Positive values are added to the start address of the decompressed data
; and negative values are subtracted from the current position.
; 4: repeat
; repeat some number of bytes from decompressed data
; 5: flipped
; repeat some number of flipped bytes from decompressed data
; ex: $ad = %10101101 -> %10110101 = $b5
; 6: reverse
; repeat some number of bytes in reverse from decompressed data
; If the value in the count needs to be larger than 5 bits,
; control code 7 can be used to expand the count to 10 bits.
; A new control command is read in bits 2-4.
; The new 10-bit count is split:
; bits 0-1 contain the top 2 bits
; another byte is added containing the latter 8
; So, the structure of the control command becomes:
; 111xxxyy yyyyyyyy
; | | | |
; | | our new count
; | the control command for this count
; 7 (this command)
; For more information, refer to the code below and in extras/gfx.py .
; save starting output address
ld a, e
ld [$c2c2], a
ld a, d
ld [$c2c3], a
.loop
; get next byte
ld a, [hl]
; done?
cp $ff ; end
ret z
; get control code
and %11100000
; 10-bit param?
cp $e0 ; LZ_HI
jr nz, .normal
; 10-bit param:
; get next 3 bits (%00011100)
ld a, [hl]
add a
add a ; << 3
add a
; this is our new control code
and %11100000
push af
; get param hi
ld a, [hli]
and %00000011
ld b, a
; get param lo
ld a, [hli]
ld c, a
; read at least 1 byte
inc bc
jr .readers
.normal
; push control code
push af
; get param
ld a, [hli]
and %00011111
ld c, a
ld b, $0
; read at least 1 byte
inc c
.readers
; let's get started
; inc loop counts since we bail as soon as they hit 0
inc b
inc c
; get control code
pop af
; command type
bit 7, a ; 80, a0, c0
jr nz, .repeatertype
; literals
cp $20 ; LZ_ITER
jr z, .iter
cp $40 ; LZ_ALT
jr z, .alt
cp $60 ; LZ_ZERO
jr z, .zero
; else $00
; 00 ; LZ_LIT
; literal data for bc bytes
.loop1
; done?
dec c
jr nz, .next1
dec b
jp z, .loop
.next1
ld a, [hli]
ld [de], a
inc de
jr .loop1
; 20 ; LZ_ITER
; write byte for bc bytes
.iter
ld a, [hli]
.iterloop
dec c
jr nz, .iternext
dec b
jp z, .loop
.iternext
ld [de], a
inc de
jr .iterloop
; 40 ; LZ_ALT
; alternate two bytes for bc bytes
; next pair
.alt
; done?
dec c
jr nz, .alt0
dec b
jp z, .altclose0
; alternate for bc
.alt0
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .alt1
; done?
dec b
jp z, .altclose1
.alt1
ld a, [hld]
ld [de], a
inc de
jr .alt
; skip past the bytes we were alternating
.altclose0
inc hl
.altclose1
inc hl
jr .loop
; 60 ; LZ_ZERO
; write 00 for bc bytes
.zero
xor a
.zeroloop
dec c
jr nz, .zeronext
dec b
jp z, .loop
.zeronext
ld [de], a
inc de
jr .zeroloop
; repeats
; 80, a0, c0
; repeat decompressed data from output
.repeatertype
push hl
push af
; get next byte
ld a, [hli]
; absolute?
bit 7, a
jr z, .absolute
; relative
; a = -a
and %01111111 ; forget the bit we just looked at
cpl
; add de (current output address)
add e
ld l, a
ld a, $ff ; -1
adc d
ld h, a
jr .repeaters
.absolute
; get next byte (lo)
ld l, [hl]
; last byte (hi)
ld h, a
; add starting output address
ld a, [$c2c2]
add l
ld l, a
ld a, [$c2c3]
adc h
ld h, a
.repeaters
pop af
cp $80 ; LZ_REPEAT
jr z, .repeat
cp $a0 ; LZ_FLIP
jr z, .flip
cp $c0 ; LZ_REVERSE
jr z, .reverse
; e0 -> 80
; 80 ; LZ_REPEAT
; repeat some decompressed data
.repeat
; done?
dec c
jr nz, .repeatnext
dec b
jr z, .cleanup
.repeatnext
ld a, [hli]
ld [de], a
inc de
jr .repeat
; a0 ; LZ_FLIP
; repeat some decompressed data w/ flipped bit order
.flip
dec c
jr nz, .flipnext
dec b
jp z, .cleanup
.flipnext
ld a, [hli]
push bc
ld bc, $0008
.fliploop
rra
rl b
dec c
jr nz, .fliploop
ld a, b
pop bc
ld [de], a
inc de
jr .flip
; c0 ; LZ_REVERSE
; repeat some decompressed data in reverse
.reverse
dec c
jr nz, .reversenext
dec b
jp z, .cleanup
.reversenext
ld a, [hld]
ld [de], a
inc de
jr .reverse
.cleanup
; get type of repeat we just used
pop hl
; was it relative or absolute?
bit 7, [hl]
jr nz, .next
; skip two bytes for absolute
inc hl
; skip one byte for relative
.next
inc hl
jp .loop
; c2f

View File

@@ -1,23 +0,0 @@
DelayFrame: ; 45a
; Wait for one frame
ld a, 1
ld [VBlankOccurred], a
; Wait for the next VBlank, halting to conserve battery
.halt
halt ; rgbasm adds a nop after this instruction by default
ld a, [VBlankOccurred]
and a
jr nz, .halt
ret
; 468
DelayFrames: ; 468
; Wait c frames
call DelayFrame
dec c
jr nz, DelayFrames
ret
; 46f

View File

@@ -1,134 +0,0 @@
; Functions to fade the screen in and out.
Function48c: ; 48c
ld a, [TimeOfDayPal]
ld b, a
ld hl, IncGradGBPalTable_11
ld a, l
sub b
ld l, a
jr nc, .asm_499
dec h
.asm_499
ld a, [hli]
ld [rBGP], a
ld a, [hli]
ld [rOBP0], a
ld a, [hli]
ld [rOBP1], a
ret
; 4a3
Function4a3: ; 4a3
ld a, [hCGB]
and a
jr z, .asm_4af
ld hl, IncGradGBPalTable_00
ld b, 4
jr FadeOut
.asm_4af
ld hl, IncGradGBPalTable_08
ld b, 4
jr FadeOut
; 4b6
Function4b6: ; 4b6
ld a, [hCGB]
and a
jr z, .asm_4c2
ld hl, IncGradGBPalTable_05
ld b, 3
jr FadeOut
.asm_4c2
ld hl, IncGradGBPalTable_13
ld b, 3
; 4c7
FadeOut: ; 4c7
push de
ld a, [hli]
call DmgToCgbBGPals
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
call DmgToCgbObjPals
ld c, 8
call DelayFrames
pop de
dec b
jr nz, FadeOut
ret
; 4dd
Function4dd: ; 4dd
ld a, [hCGB]
and a
jr z, .asm_4e9
ld hl, IncGradGBPalTable_04 - 1
ld b, 4
jr FadeIn
.asm_4e9
ld hl, IncGradGBPalTable_12 - 1
ld b, 4
jr FadeIn
; 4f0
Function4f0: ; 4f0
ld a, [hCGB]
and a
jr z, .asm_4fc
ld hl, IncGradGBPalTable_07 - 1
ld b, 3
jr FadeIn
.asm_4fc
ld hl, IncGradGBPalTable_15 - 1
ld b, 3
; fallthrough
; 501
FadeIn: ; 501
push de
ld a, [hld]
ld d, a
ld a, [hld]
ld e, a
call DmgToCgbObjPals
ld a, [hld]
call DmgToCgbBGPals
ld c, 8
call DelayFrames
pop de
dec b
jr nz, FadeIn
ret
; 517
; 517
IncGradGBPalTable_00: db %11111111, %11111111, %11111111
IncGradGBPalTable_01: db %11111110, %11111110, %11111110
IncGradGBPalTable_02: db %11111001, %11111001, %11111001
IncGradGBPalTable_03: db %11100100, %11100100, %11100100
IncGradGBPalTable_04: db %11100100, %11100100, %11100100
IncGradGBPalTable_05: db %10010000, %10010000, %10010000
IncGradGBPalTable_06: db %01000000, %01000000, %01000000
IncGradGBPalTable_07: db %00000000, %00000000, %00000000
; bgp obp1 obp2
IncGradGBPalTable_08: db %11111111, %11111111, %11111111
IncGradGBPalTable_09: db %11111110, %11111110, %11111000
IncGradGBPalTable_10: db %11111001, %11100100, %11100100
IncGradGBPalTable_11: db %11100100, %11010000, %11100000
IncGradGBPalTable_12: db %11100100, %11010000, %11100000
IncGradGBPalTable_13: db %10010000, %10000000, %10010000
IncGradGBPalTable_14: db %01000000, %01000000, %01000000
IncGradGBPalTable_15: db %00000000, %00000000, %00000000
; 547

View File

@@ -1,55 +0,0 @@
FarCall_de: ; 2d54
; Call a:de.
; Preserves other registers.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call .de
jr ReturnFarCall
.de
push de
ret
; 2d63
FarCall_hl: ; 2d63
; Call a:hl.
; Preserves other registers.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call Function2d82
; 2d6e
ReturnFarCall: ; 2d6e
; We want to retain the contents of f.
; To do this, we can pop to bc instead of af.
ld a, b
ld [$cfb9], a
ld a, c
ld [$cfba], a
; Restore the working bank.
pop bc
ld a, b
rst Bankswitch
ld a, [$cfb9]
ld b, a
ld a, [$cfba]
ld c, a
ret
; 2d82
Function2d82: ; 2d82
jp [hl]
; 2d83

View File

@@ -1,132 +0,0 @@
ResetGameTime: ; 208a
xor a
ld [GameTimeCap], a
ld [GameTimeHours], a
ld [GameTimeHours + 1], a
ld [GameTimeMinutes], a
ld [GameTimeSeconds], a
ld [GameTimeFrames], a
ret
; 209e
GameTimer: ; 209e
nop
ld a, [rSVBK]
push af
ld a, 1
ld [rSVBK], a
call UpdateGameTimer
pop af
ld [rSVBK], a
ret
; 20ad
UpdateGameTimer: ; 20ad
; Increment the game timer by one frame.
; The game timer is capped at 999:59:59.00.
; Don't update if game logic is paused.
ld a, [$c2cd]
and a
ret nz
; Is the timer paused?
ld hl, GameTimerPause
bit 0, [hl]
ret z
; Is the timer already capped?
ld hl, GameTimeCap
bit 0, [hl]
ret nz
; +1 frame
ld hl, GameTimeFrames
ld a, [hl]
inc a
cp 60 ; frames/second
jr nc, .second
ld [hl], a
ret
.second
xor a
ld [hl], a
; +1 second
ld hl, GameTimeSeconds
ld a, [hl]
inc a
cp 60 ; seconds/minute
jr nc, .minute
ld [hl], a
ret
.minute
xor a
ld [hl], a
; +1 minute
ld hl, GameTimeMinutes
ld a, [hl]
inc a
cp 60 ; minutes/hour
jr nc, .hour
ld [hl], a
ret
.hour
xor a
ld [hl], a
; +1 hour
ld a, [GameTimeHours]
ld h, a
ld a, [GameTimeHours + 1]
ld l, a
inc hl
; Cap the timer after 1000 hours.
ld a, h
cp 1000 / $100
jr c, .ok
ld a, l
cp 1000 % $100
jr c, .ok
ld hl, GameTimeCap
set 0, [hl]
ld a, 59 ; 999:59:59.00
ld [GameTimeMinutes], a
ld [GameTimeSeconds], a
ret
.ok
ld a, h
ld [GameTimeHours], a
ld a, l
ld [GameTimeHours + 1], a
ret
; 210f

View File

@@ -1,225 +0,0 @@
Reset: ; 150
di
call CleanSoundRestart
xor a
ld [$ffde], a
call ClearPalettes
xor a
ld [rIF], a
ld a, 1 ; VBlank int
ld [rIE], a
ei
ld hl, $cfbe
set 7, [hl]
ld c, 32
call DelayFrames
jr Init
; 16e
_Start: ; 16e
cp $11
jr z, .asm_175
xor a
jr .asm_177
.asm_175
ld a, $1
.asm_177
ld [hCGB], a
ld a, $1
ld [$ffea], a
; 17d
Init: ; 17d
di
xor a
ld [rIF], a
ld [rIE], a
ld [rRP], a
ld [rSCX], a
ld [rSCY], a
ld [rSB], a
ld [rSC], a
ld [rWX], a
ld [rWY], a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
ld [rTMA], a
ld [rTAC], a
ld [$d000], a
ld a, %100 ; Start timer at 4096Hz
ld [rTAC], a
.wait
ld a, [rLY]
cp 145
jr nz, .wait
xor a
ld [rLCDC], a
; Clear WRAM bank 0
ld hl, $c000
ld bc, $d000 - $c000
.asm_1b1
ld [hl], 0
inc hl
dec bc
ld a, b
or c
jr nz, .asm_1b1
ld sp, Stack
; Clear HRAM
ld a, [hCGB]
push af
ld a, [$ffea]
push af
xor a
ld hl, $ff80
ld bc, $ffff - $ff80
call ByteFill
pop af
ld [$ffea], a
pop af
ld [hCGB], a
call ClearWRAM
ld a, 1
ld [rSVBK], a
call ClearVRAM
call ClearSprites
call Function270
ld a, BANK(LoadPushOAM)
rst Bankswitch
call LoadPushOAM
xor a
ld [$ffde], a
ld [hSCX], a
ld [hSCY], a
ld [rJOYP], a
ld a, $8 ; HBlank int enable
ld [rSTAT], a
ld a, $90
ld [hWY], a
ld [rWY], a
ld a, 7
ld [hWX], a
ld [rWX], a
ld a, %11100011
; LCD on
; Win tilemap 1
; Win on
; BG/Win tiledata 0
; BG Tilemap 0
; OBJ 8x8
; OBJ on
; BG on
ld [rLCDC], a
ld a, $ff
ld [$ffcb], a
callba Function9890
ld a, $9c
ld [$ffd7], a
xor a
ld [hBGMapAddress], a
callba StartClock
xor a
ld [MBC3LatchClock], a
ld [MBC3SRamEnable], a
ld a, [hCGB]
and a
jr z, .asm_22b
call Function2ff7
.asm_22b
xor a
ld [rIF], a
ld a, %1111 ; VBlank, LCDStat, Timer, Serial interrupts
ld [rIE], a
ei
call DelayFrame
ld a, $30
call Predef
call CleanSoundRestart
xor a
ld [CurMusic], a
jp GameInit
; 245
ClearVRAM: ; 245
; Wipe VRAM banks 0 and 1
ld a, 1
ld [rVBK], a
call .clear
xor a
ld [rVBK], a
.clear
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ret
; 25a
ClearWRAM: ; 25a
; Wipe swappable WRAM banks (1-7)
ld a, 1
.asm_25c
push af
ld [rSVBK], a
xor a
ld hl, $d000
ld bc, $1000
call ByteFill
pop af
inc a
cp 8
jr nc, .asm_25c
ret
; 270
Function270: ; 270
ld a, $0
call GetSRAMBank
ld hl, $a000
ld bc, $0020
xor a
call ByteFill
call CloseSRAM
ret
; 283

View File

@@ -1,491 +0,0 @@
JoypadInt: ; 92e
; Replaced by Joypad, called from VBlank instead of the useless
; joypad interrupt.
; This is a placeholder in case the interrupt is somehow enabled.
reti
; 92f
ClearJoypadPublic: ; 92f
xor a
; Pressed this frame (delta)
ld [hJoyPressed], a
; Currently pressed
ld [hJoyDown], a
ret
; 935
Joypad: ; 935
; Read the joypad register and translate it to something more
; workable for use in-game. There are 8 buttons, so we can use
; one byte to contain all player input.
; Updates:
; hJoypadReleased: released this frame (delta)
; hJoypadPressed: pressed this frame (delta)
; hJoypadDown: currently pressed
; hJoypadSum: pressed so far
; Any of these three bits can be used to disable input.
ld a, [$cfbe]
and %11010000
ret nz
; If we're saving, input is disabled.
ld a, [$c2cd]
and a
ret nz
; We can only get four inputs at a time.
; We take d-pad first for no particular reason.
ld a, D_PAD
ld [rJOYP], a
; Read twice to give the request time to take.
ld a, [rJOYP]
ld a, [rJOYP]
; The Joypad register output is in the lo nybble (inversed).
; We make the hi nybble of our new container d-pad input.
cpl
and $f
swap a
; We'll keep this in b for now.
ld b, a
; Buttons make 8 total inputs (A, B, Select, Start).
; We can fit this into one byte.
ld a, BUTTONS
ld [rJOYP], a
; Wait for input to stabilize.
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
; Buttons take the lo nybble.
cpl
and $f
or b
ld b, a
; Reset the joypad register since we're done with it.
ld a, $30
ld [rJOYP], a
; To get the delta we xor the last frame's input with the new one.
ld a, [hJoypadDown] ; last frame
ld e, a
xor b
ld d, a
; Released this frame:
and e
ld [hJoypadReleased], a
; Pressed this frame:
ld a, d
and b
ld [hJoypadPressed], a
; Add any new presses to the list of collective presses:
ld c, a
ld a, [hJoypadSum]
or c
ld [hJoypadSum], a
; Currently pressed:
ld a, b
ld [hJoypadDown], a
; Now that we have the input, we can do stuff with it.
; For example, soft reset:
and BUTTON_A | BUTTON_B | SELECT | START
cp BUTTON_A | BUTTON_B | SELECT | START
jp z, Reset
ret
; 984
GetJoypadPublic: ; 984
; Update mirror joypad input from hJoypadDown (real input)
; hJoyReleased: released this frame (delta)
; hJoyPressed: pressed this frame (delta)
; hJoyDown: currently pressed
; bit 0 A
; 1 B
; 2 SELECT
; 3 START
; 4 RIGHT
; 5 LEFT
; 6 UP
; 7 DOWN
push af
push hl
push de
push bc
; The player input can be automated using an input stream.
; See more below.
ld a, [InputType]
cp a, AUTO_INPUT
jr z, .auto
; To get deltas, take this and last frame's input.
ld a, [hJoypadDown] ; real input
ld b, a
ld a, [hJoyDown] ; last frame mirror
ld e, a
; Released this frame:
xor b
ld d, a
and e
ld [hJoyReleased], a
; Pressed this frame:
ld a, d
and b
ld [hJoyPressed], a
; It looks like the collective presses got commented out here.
ld c, a
; Currently pressed:
ld a, b
ld [hJoyDown], a ; frame input
.quit
pop bc
pop de
pop hl
pop af
ret
.auto
; Use a predetermined input stream (used in the catching tutorial).
; Stream format: [input][duration]
; A value of $ff will immediately end the stream.
; Read from the input stream.
ld a, [hROMBank]
push af
ld a, [AutoInputBank]
rst Bankswitch
ld hl, AutoInputAddress
ld a, [hli]
ld h, [hl]
ld l, a
; We only update when the input duration has expired.
ld a, [AutoInputLength]
and a
jr z, .updateauto
; Until then, don't change anything.
dec a
ld [AutoInputLength], a
pop af
rst Bankswitch
jr .quit
.updateauto
; An input of $ff will end the stream.
ld a, [hli]
cp a, $ff
jr z, .stopauto
ld b, a
; A duration of $ff will end the stream indefinitely.
ld a, [hli]
ld [AutoInputLength], a
cp a, $ff
jr nz, .next
; The current input is overwritten.
dec hl
dec hl
ld b, NO_INPUT
jr .finishauto
.next
; On to the next input...
ld a, l
ld [AutoInputAddress], a
ld a, h
ld [AutoInputAddress+1], a
jr .finishauto
.stopauto
call StopAutoInput
ld b, NO_INPUT
.finishauto
pop af
rst Bankswitch
ld a, b
ld [hJoyPressed], a ; pressed
ld [hJoyDown], a ; input
jr .quit
; 9ee
StartAutoInput: ; 9ee
; Start reading automated input stream at a:hl.
ld [AutoInputBank], a
ld a, l
ld [AutoInputAddress], a
ld a, h
ld [AutoInputAddress+1], a
; Start reading the stream immediately.
xor a
ld [AutoInputLength], a
; Reset input mirrors.
xor a
ld [hJoyPressed], a ; pressed this frame
ld [hJoyReleased], a ; released this frame
ld [hJoyDown], a ; currently pressed
ld a, AUTO_INPUT
ld [InputType], a
ret
; a0a
StopAutoInput: ; a0a
; Clear variables related to automated input.
xor a
ld [AutoInputBank], a
ld [AutoInputAddress], a
ld [AutoInputAddress+1], a
ld [AutoInputLength], a
; Back to normal input.
ld [InputType], a
ret
; a1b
Functiona1b: ; a1b
call DelayFrame
push bc
call Functiona57
pop bc
ld a, [hJoyDown]
cp D_UP | SELECT | BUTTON_B
jr z, .asm_a34
ld a, [$ffa9]
and START | BUTTON_A
jr nz, .asm_a34
dec c
jr nz, Functiona1b
and a
ret
.asm_a34
scf
ret
; a36
Functiona36: ; a36
call DelayFrame
call GetJoypadPublic
ld a, [hJoyPressed]
and BUTTON_A | BUTTON_B
ret nz
call RTC
jr Functiona36
; a46
Functiona46: ; a46
ld a, [hOAMUpdate]
push af
ld a, 1
ld [hOAMUpdate], a
call WaitBGMap
call Functiona36
pop af
ld [hOAMUpdate], a
ret
; a57
Functiona57: ; a57
call GetJoypadPublic
ld a, [$ffaa]
and a
ld a, [hJoyPressed]
jr z, .asm_a63
ld a, [hJoyDown]
.asm_a63
ld [$ffa9], a
ld a, [hJoyPressed]
and a
jr z, .asm_a70
ld a, 15
ld [TextDelayFrames], a
ret
.asm_a70
ld a, [TextDelayFrames]
and a
jr z, .asm_a7a
xor a
ld [$ffa9], a
ret
.asm_a7a
ld a, 5
ld [TextDelayFrames], a
ret
; a80
Functiona80: ; a80
ld a, [$ffaf]
push af
ld a, [$ffb0]
push af
xor a
ld [$ffaf], a
ld a, $6
ld [$ffb0], a
.asm_a8d
push hl
ld hl, $c606
call Functionb06
pop hl
call Functiona57
ld a, [$ffa9]
and $3
jr z, .asm_a8d
pop af
ld [$ffb0], a
pop af
ld [$ffaf], a
ret
; aa5
Functionaa5: ; aa5
call Functiona57
ld a, [$ffa9]
and BUTTON_A | BUTTON_B
jr z, Functionaa5
ret
; aaf
Functionaaf: ; aaf
ld a, [InLinkBattle]
and a
jr nz, .asm_ac1
call Functionac6
push de
ld de, SFX_READ_TEXT_2
call StartSFX
pop de
ret
.asm_ac1
ld c, 65
jp DelayFrames
; ac6
Functionac6: ; ac6
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [InputType]
or a
jr z, .asm_ad9
callba Function1de28a
.asm_ad9
call Functionaf5
call Functiona57
ld a, [hJoyPressed]
and $3
jr nz, .asm_af1
call RTC
ld a, $1
ld [hBGMapMode], a
call DelayFrame
jr .asm_ad9
.asm_af1
pop af
ld [hOAMUpdate], a
ret
; af5
Functionaf5: ; af5
ld a, [$ff9b]
and $10
jr z, .asm_aff
ld a, $ee
jr .asm_b02
.asm_aff
ld a, [$c605]
.asm_b02
ld [$c606], a
ret
; b06
Functionb06: ; b06
push bc
ld a, [hl]
ld b, a
ld a, $ee
cp b
pop bc
jr nz, .asm_b27
ld a, [$ffaf]
dec a
ld [$ffaf], a
ret nz
ld a, [$ffb0]
dec a
ld [$ffb0], a
ret nz
ld a, $7a
ld [hl], a
ld a, $ff
ld [$ffaf], a
ld a, $6
ld [$ffb0], a
ret
.asm_b27
ld a, [$ffaf]
and a
ret z
dec a
ld [$ffaf], a
ret nz
dec a
ld [$ffaf], a
ld a, [$ffb0]
dec a
ld [$ffb0], a
ret nz
ld a, $6
ld [$ffb0], a
ld a, $ee
ld [hl], a
ret
; b40

View File

@@ -1,81 +0,0 @@
; LCD handling
Function547: ; 547
ld a, [hLCDStatCustom]
cp rSCX & $ff
ret nz
ld c, a
ld a, [LYOverrides]
ld [$ff00+c], a
ret
; 552
LCD: ; 552
push af
ld a, [hLCDStatCustom]
and a
jr z, .done
; At this point it's assumed we're in WRAM bank 5!
push bc
ld a, [rLY]
ld c, a
ld b, LYOverrides >> 8
ld a, [bc]
ld b, a
ld a, [hLCDStatCustom]
ld c, a
ld a, b
ld [$ff00+c], a
pop bc
.done
pop af
reti
; 568
DisableLCD: ; 568
; Turn the LCD off
; Don't need to do anything if the LCD is already off
ld a, [rLCDC]
bit 7, a ; lcd enable
ret z
xor a
ld [rIF], a
ld a, [rIE]
ld b, a
; Disable VBlank
res 0, a ; vblank
ld [rIE], a
.wait
; Wait until VBlank would normally happen
ld a, [rLY]
cp 145
jr nz, .wait
ld a, [rLCDC]
and %01111111 ; lcd enable off
ld [rLCDC], a
xor a
ld [rIF], a
ld a, b
ld [rIE], a
ret
; 58a
EnableLCD: ; 58a
ld a, [rLCDC]
set 7, a ; lcd enable
ld [rLCDC], a
ret
; 591

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,347 +0,0 @@
; Functions dealing with palettes.
UpdatePalsIfCGB: ; c2f
; update bgp data from BGPals
; update obp data from OBPals
; return carry if successful
; check cgb
ld a, [hCGB]
and a
ret z
UpdateCGBPals: ; c33
; return carry if successful
; any pals to update?
ld a, [hCGBPalUpdate]
and a
ret z
ForceUpdateCGBPals: ; c37
ld a, [rSVBK]
push af
ld a, 5 ; BANK(BGPals)
ld [rSVBK], a
ld hl, BGPals ; 5:d080
; copy 8 pals to bgpd
ld a, %10000000 ; auto increment, index 0
ld [rBGPI], a
ld c, rBGPD % $100
ld b, 4 ; NUM_PALS / 2
.bgp
rept $10
ld a, [hli]
ld [$ff00+c], a
endr
dec b
jr nz, .bgp
; hl is now 5:d0c0 OBPals
; copy 8 pals to obpd
ld a, %10000000 ; auto increment, index 0
ld [rOBPI], a
ld c, rOBPD - rJOYP
ld b, 4 ; NUM_PALS / 2
.obp
rept $10
ld a, [hli]
ld [$ff00+c], a
endr
dec b
jr nz, .obp
pop af
ld [rSVBK], a
; clear pal update queue
xor a
ld [hCGBPalUpdate], a
scf
ret
; c9f
DmgToCgbBGPals: ; c9f
; exists to forego reinserting cgb-converted image data
; input: a -> bgp
ld [rBGP], a
push af
ld a, [hCGB]
and a
jr z, .end
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
; copy & reorder bg pal buffer
ld hl, BGPals ; to
ld de, Unkn1Pals ; from
; order
ld a, [rBGP]
ld b, a
; all pals
ld c, 8
call CopyPals
; request pal update
ld a, 1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.end
pop af
ret
; ccb
DmgToCgbObjPals: ; ccb
; exists to forego reinserting cgb-converted image data
; input: d -> obp1
; e -> obp2
ld a, e
ld [rOBP0], a
ld a, d
ld [rOBP1], a
ld a, [hCGB]
and a
ret z
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
; copy & reorder obj pal buffer
ld hl, OBPals ; to
ld de, Unkn2Pals ; from
; order
ld a, [rOBP0]
ld b, a
; all pals
ld c, 8
call CopyPals
; request pal update
ld a, 1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
ret
; cf8
Functioncf8: ; cf8
ld [rOBP0], a
push af
ld a, [hCGB]
and a
jr z, .asm_d22
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, $d0c0
ld de, MartPointer
ld a, [rOBP0]
ld b, a
ld c, $1
call CopyPals
ld a, $1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.asm_d22
pop af
ret
; d24
Functiond24: ; d24
ld [rOBP1], a
push af
ld a, [hCGB]
and a
jr z, .asm_d4e
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, $d0c8
ld de, $d048
ld a, [rOBP1]
ld b, a
ld c, $1
call CopyPals
ld a, $1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.asm_d4e
pop af
ret
; d50
CopyPals: ; d50
; copy c palettes in order b from de to hl
push bc
ld c, 4 ; NUM_PAL_COLORS
.loop
push de
push hl
; get pal color
ld a, b
and %11 ; color
; 2 bytes per color
add a
ld l, a
ld h, 0
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
; dest
pop hl
; write color
ld [hl], e
inc hl
ld [hl], d
inc hl
; next pal color
srl b
srl b
; source
pop de
; done pal?
dec c
jr nz, .loop
; de += 8 (next pal)
ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal
add e
jr nc, .ok
inc d
.ok
ld e, a
; how many more pals?
pop bc
dec c
jr nz, CopyPals
ret
; d79
Functiond79: ; d79
ld a, [hCGB]
and a
ret z
ld a, 1
ld [rVBK], a
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ld a, 0
ld [rVBK], a
ret
; d90
Functiond90: ; d90
ret
; d91
Functiond91: ; d91
ld a, [hCGB]
and a
ret z
ld a, [rSVBK]
push af
ld a, 5 ; BANK(BGPals)
ld [rSVBK], a
ld hl, BGPals
ld bc, $40 + $10
xor a
call ByteFill
pop af
ld [rSVBK], a
ld a, 1
ld [hCGBPalUpdate], a
call DelayFrame
ret
; db1
Functiondb1: ; db1
ld a, [hROMBank]
push af
ld a, BANK(Function4c000)
rst Bankswitch
call Function4c000
pop af
rst Bankswitch
ret
; dbd
Functiondbd: ; dbd
ld a, [hROMBank]
push af
ld a, BANK(Function4c03f)
rst Bankswitch
call Function4c03f
pop af
rst Bankswitch
ret
; dc9

View File

@@ -1,25 +0,0 @@
RTC: ; 46f
; update time and time-sensitive palettes
; rtc enabled?
ld a, [$c2ce]
cp 0
ret z
call UpdateTime
; obj update on?
ld a, [VramState]
bit 0, a ; obj update
ret z
TimeOfDayPals: ; 47e
callab _TimeOfDayPals
ret
; 485
UpdateTimePals: ; 485
callab _UpdateTimePals
ret
; 48c

View File

@@ -1,408 +0,0 @@
Serial: ; 6ef
; The serial interrupt.
push af
push bc
push de
push hl
ld a, [$ffc9]
and a
jr nz, .asm_71c
ld a, [$c2d4]
bit 0, a
jr nz, .asm_721
ld a, [$ffcb]
inc a
jr z, .asm_726
ld a, [rSB]
ld [hSerialReceive], a
ld a, [hSerialSend]
ld [rSB], a
ld a, [$ffcb]
cp $2
jr z, .asm_752
ld a, 0 << rSC_ON
ld [rSC], a
ld a, 1 << rSC_ON
ld [rSC], a
jr .asm_752
.asm_71c
call Function3e80
jr .asm_75a
.asm_721
call Function2057
jr .asm_75a
.asm_726
ld a, [rSB]
cp $1
jr z, .asm_730
cp $2
jr nz, .asm_752
.asm_730
ld [hSerialReceive], a
ld [$ffcb], a
cp $2
jr z, .asm_74f
xor a
ld [rSB], a
ld a, $3
ld [rDIV], a
.asm_73f
ld a, [rDIV]
bit 7, a
jr nz, .asm_73f
ld a, 0 << rSC_ON
ld [rSC], a
ld a, 1 << rSC_ON
ld [rSC], a
jr .asm_752
.asm_74f
xor a
ld [rSB], a
.asm_752
ld a, $1
ld [$ffca], a
ld a, $fe
ld [hSerialSend], a
.asm_75a
pop hl
pop de
pop bc
pop af
reti
; 75f
Function75f: ; 75f
ld a, $1
ld [$ffcc], a
.asm_763
ld a, [hl]
ld [hSerialSend], a
call Function78a
push bc
ld b, a
inc hl
ld a, $30
.asm_76e
dec a
jr nz, .asm_76e
ld a, [$ffcc]
and a
ld a, b
pop bc
jr z, .asm_782
dec hl
cp $fd
jr nz, .asm_763
xor a
ld [$ffcc], a
jr .asm_763
.asm_782
ld [de], a
inc de
dec bc
ld a, b
or c
jr nz, .asm_763
ret
; 78a
Function78a: ; 78a
xor a
ld [$ffca], a
ld a, [$ffcb]
cp $2
jr nz, .asm_79b
ld a, $1
ld [rSC], a
ld a, $81
ld [rSC], a
.asm_79b
ld a, [$ffca]
and a
jr nz, .asm_7e5
ld a, [$ffcb]
cp $1
jr nz, .asm_7c0
call Function82b
jr z, .asm_7c0
call .asm_825
push hl
ld hl, $cf5c
inc [hl]
jr nz, .asm_7b7
dec hl
inc [hl]
.asm_7b7
pop hl
call Function82b
jr nz, .asm_79b
jp Function833
.asm_7c0
ld a, [rIE]
and $f
cp $8
jr nz, .asm_79b
ld a, [$cf5d]
dec a
ld [$cf5d], a
jr nz, .asm_79b
ld a, [$cf5e]
dec a
ld [$cf5e], a
jr nz, .asm_79b
ld a, [$ffcb]
cp $1
jr z, .asm_7e5
ld a, $ff
.asm_7e2
dec a
jr nz, .asm_7e2
.asm_7e5
xor a
ld [$ffca], a
ld a, [rIE]
and $f
sub $8
jr nz, .asm_7f8
ld [$cf5d], a
ld a, $50
ld [$cf5e], a
.asm_7f8
ld a, [hSerialReceive]
cp $fe
ret nz
call Function82b
jr z, .asm_813
push hl
ld hl, $cf5c
ld a, [hl]
dec a
ld [hld], a
inc a
jr nz, .asm_80d
dec [hl]
.asm_80d
pop hl
call Function82b
jr z, Function833
.asm_813
ld a, [rIE]
and $f
cp $8
ld a, $fe
ret z
ld a, [hl]
ld [hSerialSend], a
call DelayFrame
jp Function78a
.asm_825
ld a, $f
.asm_827
dec a
jr nz, .asm_827
ret
; 82b
Function82b: ; 82b
push hl
ld hl, $cf5b
ld a, [hli]
or [hl]
pop hl
ret
; 833
Function833: ; 833
dec a
ld [$cf5b], a
ld [$cf5c], a
ret
; 83b
Function83b: ; 83b
ld hl, $cf56
ld de, $cf51
ld c, $2
ld a, $1
ld [$ffcc], a
.asm_847
call DelayFrame
ld a, [hl]
ld [hSerialSend], a
call Function78a
ld b, a
inc hl
ld a, [$ffcc]
and a
ld a, $0
ld [$ffcc], a
jr nz, .asm_847
ld a, b
ld [de], a
inc de
dec c
jr nz, .asm_847
ret
; 862
Function862: ; 862
call Function309d
callab Function4000
call Function87d
jp Function30b4
; 871
Function871: ; 871
call Function309d
callab Function4000
jp Function87d
; 87d
Function87d: ; 87d
ld a, $ff
ld [$cf52], a
.asm_882
call Function8c1
call DelayFrame
call Function82b
jr z, .asm_89e
push hl
ld hl, $cf5c
dec [hl]
jr nz, .asm_89d
dec hl
dec [hl]
jr nz, .asm_89d
pop hl
xor a
jp Function833
.asm_89d
pop hl
.asm_89e
ld a, [$cf52]
inc a
jr z, .asm_882
ld b, $a
.asm_8a6
call DelayFrame
call Function8c1
dec b
jr nz, .asm_8a6
ld b, $a
.asm_8b1
call DelayFrame
call Function908
dec b
jr nz, .asm_8b1
ld a, [$cf52]
ld [$cf51], a
ret
; 8c1
Function8c1: ; 8c1
push bc
ld b, $60
ld a, [InLinkBattle]
cp $1
jr z, .asm_8d7
ld b, $60
jr c, .asm_8d7
cp $2
ld b, $70
jr z, .asm_8d7
ld b, $80
.asm_8d7
call Function8f3
ld a, [$cf56]
add b
ld [hSerialSend], a
ld a, [$ffcb]
cp $2
jr nz, .asm_8ee
ld a, $1
ld [rSC], a
ld a, $81
ld [rSC], a
.asm_8ee
call Function8f3
pop bc
ret
; 8f3
Function8f3: ; 8f3
ld a, [hSerialReceive]
ld [$cf51], a
and $f0
cp b
ret nz
xor a
ld [hSerialReceive], a
ld a, [$cf51]
and $f
ld [$cf52], a
ret
; 908
Function908: ; 908
xor a
ld [hSerialSend], a
ld a, [$ffcb]
cp $2
ret nz
ld a, $1
ld [rSC], a
ld a, $81
ld [rSC], a
ret
; 919
Function919: ; 919
ld a, [InLinkBattle]
and a
ret nz
ld a, $2
ld [rSB], a
xor a
ld [hSerialReceive], a
ld a, $0
ld [rSC], a
ld a, $80
ld [rSC], a
ret
; 92e

View File

@@ -1,22 +0,0 @@
Cosine: ; 1b0f
; Return d * cos(a) in hl
add $10 ; 90 degrees
Sine: ; 1b11
; Return d * sin(a) in hl
; a is a signed 6-bit value.
ld e, a
ld a, [hROMBank]
push af
ld a, BANK(_Sine)
rst Bankswitch
call _Sine
pop af
rst Bankswitch
ret
; 1b1e

File diff suppressed because it is too large Load Diff

View File

@@ -1,311 +0,0 @@
; Functions relating to the timer interrupt and the real-time-clock.
AskTimer: ; 591
push af
ld a, [$ffe9]
and a
jr z, .asm_59a
call Timer
.asm_59a
pop af
reti
; 59c
LatchClock: ; 59c
; latch clock counter data
ld a, 0
ld [MBC3LatchClock], a
ld a, 1
ld [MBC3LatchClock], a
ret
; 5a7
UpdateTime: ; 5a7
call GetClock
call FixDays
call FixTime
callba GetTimeOfDay
ret
; 5b7
GetClock: ; 5b7
; store clock data in hRTCDayHi-hRTCSeconds
; enable clock r/w
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
; clock data is 'backwards' in hram
call LatchClock
ld hl, MBC3SRamBank
ld de, MBC3RTC
ld [hl], RTC_S
ld a, [de]
and $3f
ld [hRTCSeconds], a
ld [hl], RTC_M
ld a, [de]
and $3f
ld [hRTCMinutes], a
ld [hl], RTC_H
ld a, [de]
and $1f
ld [hRTCHours], a
ld [hl], RTC_DL
ld a, [de]
ld [hRTCDayLo], a
ld [hl], RTC_DH
ld a, [de]
ld [hRTCDayHi], a
; unlatch clock / disable clock r/w
call CloseSRAM
ret
; 5e8
FixDays: ; 5e8
; fix day count
; mod by 140
; check if day count > 255 (bit 8 set)
ld a, [hRTCDayHi] ; DH
bit 0, a
jr z, .daylo
; reset dh (bit 8)
res 0, a
ld [hRTCDayHi], a ; DH
; mod 140
; mod twice since bit 8 (DH) was set
ld a, [hRTCDayLo] ; DL
.modh
sub 140
jr nc, .modh
.modl
sub 140
jr nc, .modl
add 140
; update dl
ld [hRTCDayLo], a ; DL
; unknown output
ld a, $40 ; %1000000
jr .set
.daylo
; quit if fewer than 140 days have passed
ld a, [hRTCDayLo] ; DL
cp 140
jr c, .quit
; mod 140
.mod
sub 140
jr nc, .mod
add 140
; update dl
ld [hRTCDayLo], a ; DL
; unknown output
ld a, $20 ; %100000
.set
; update clock with modded day value
push af
call SetClock
pop af
scf
ret
.quit
xor a
ret
; 61d
FixTime: ; 61d
; add ingame time (set at newgame) to current time
; day hr min sec
; store time in CurDay, hHours, hMinutes, hSeconds
; second
ld a, [hRTCSeconds] ; S
ld c, a
ld a, [StartSecond]
add c
sub 60
jr nc, .updatesec
add 60
.updatesec
ld [hSeconds], a
; minute
ccf ; carry is set, so turn it off
ld a, [hRTCMinutes] ; M
ld c, a
ld a, [StartMinute]
adc c
sub 60
jr nc, .updatemin
add 60
.updatemin
ld [hMinutes], a
; hour
ccf ; carry is set, so turn it off
ld a, [hRTCHours] ; H
ld c, a
ld a, [StartHour]
adc c
sub 24
jr nc, .updatehr
add 24
.updatehr
ld [hHours], a
; day
ccf ; carry is set, so turn it off
ld a, [hRTCDayLo] ; DL
ld c, a
ld a, [StartDay]
adc c
ld [CurDay], a
ret
; 658
Function658: ; 658
xor a
ld [StringBuffer2], a
ld a, $0
ld [$d089], a
jr .asm_677
call UpdateTime
ld a, [hHours]
ld [$d087], a
ld a, [hMinutes]
ld [$d088], a
ld a, [hSeconds]
ld [$d089], a
jr .asm_677
.asm_677
ld a, $5
ld hl, $40ed
rst FarCall
ret
; 67e
Function67e: ; 67e
call Function685
call SetClock
ret
; 685
Function685: ; 685
xor a
ld [hRTCSeconds], a
ld [hRTCMinutes], a
ld [hRTCHours], a
ld [hRTCDayLo], a
ld [hRTCDayHi], a
ret
; 691
SetClock: ; 691
; set clock data from hram
; enable clock r/w
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
; set clock data
; stored 'backwards' in hram
call LatchClock
ld hl, MBC3SRamBank
ld de, MBC3RTC
; seems to be a halt check that got partially commented out
; this block is totally pointless
ld [hl], RTC_DH
ld a, [de]
bit 6, a ; halt
ld [de], a
; seconds
ld [hl], RTC_S
ld a, [hRTCSeconds]
ld [de], a
; minutes
ld [hl], RTC_M
ld a, [hRTCMinutes]
ld [de], a
; hours
ld [hl], RTC_H
ld a, [hRTCHours]
ld [de], a
; day lo
ld [hl], RTC_DL
ld a, [hRTCDayLo]
ld [de], a
; day hi
ld [hl], RTC_DH
ld a, [hRTCDayHi]
res 6, a ; make sure timer is active
ld [de], a
; cleanup
call CloseSRAM ; unlatch clock, disable clock r/w
ret
; 6c4
Function6c4: ; 6c4
xor a
push af
ld a, $0
call GetSRAMBank
pop af
ld [$ac60], a
call CloseSRAM
ret
; 6d3
Function6d3: ; 6d3
ld hl, $ac60
push af
ld a, $0
call GetSRAMBank
pop af
or [hl]
ld [hl], a
call CloseSRAM
ret
; 6e3
Function6e3: ; 6e3
ld a, $0
call GetSRAMBank
ld a, [$ac60]
call CloseSRAM
ret
; 6ef

File diff suppressed because it is too large Load Diff

View File

@@ -1,487 +0,0 @@
; Functions dealing with VRAM.
DMATransfer: ; 15d8
; Return carry if the transfer is completed.
ld a, [hDMATransfer]
and a
ret z
; Start transfer
ld [rHDMA5], a
; Execution is halted until the transfer is complete.
xor a
ld [hDMATransfer], a
scf
ret
; 15e3
UpdateBGMapBuffer: ; 15e3
; Copy [$ffdc] 16x8 tiles from BGMapBuffer
; to bg map addresses in BGMapBufferPtrs.
; [$ffdc] must be even since this is done in pairs.
; Return carry on success.
ld a, [hBGMapUpdate]
and a
ret z
ld a, [rVBK]
push af
ld [hSPBuffer], sp
ld hl, BGMapBufferPtrs
ld sp, hl
; We can now pop the addresses of affected spots on the BG Map
ld hl, BGMapPalBuffer
ld de, BGMapBuffer
.next
; Copy a pair of 16x8 blocks (one 16x16 block)
rept 2
; Get our BG Map address
pop bc
; Palettes
ld a, 1
ld [rVBK], a
ld a, [hli]
ld [bc], a
inc c
ld a, [hli]
ld [bc], a
dec c
; Tiles
ld a, 0
ld [rVBK], a
ld a, [de]
inc de
ld [bc], a
inc c
ld a, [de]
inc de
ld [bc], a
endr
; We've done 2 16x8 blocks
ld a, [$ffdc]
dec a
dec a
ld [$ffdc], a
jr nz, .next
ld a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
ld h, a
ld sp, hl
pop af
ld [rVBK], a
xor a
ld [hBGMapUpdate], a
scf
ret
; 163a
WaitTop: ; 163a
; Wait until the top third of the BG Map is being updated.
ld a, [hBGMapMode]
and a
ret z
ld a, [hBGMapThird]
and a
jr z, .done
call DelayFrame
jr WaitTop
.done
xor a
ld [hBGMapMode], a
ret
; 164c
UpdateBGMap: ; 164c
; Update the BG Map, in thirds, from TileMap and AttrMap.
ld a, [hBGMapMode]
and a
ret z
; BG Map 0
dec a ; 1
jr z, .Tiles
dec a ; 2
jr z, .Attr
; BG Map 1
dec a
ld a, [hBGMapAddress]
ld l, a
ld a, [hBGMapAddress + 1]
ld h, a
push hl
xor a
ld [hBGMapAddress], a
ld a, VBGMap1 >> 8
ld [hBGMapAddress + 1], a
ld a, [hBGMapMode]
push af
cp 3
call z, .Tiles
pop af
cp 4
call z, .Attr
pop hl
ld a, l
ld [hBGMapAddress], a
ld a, h
ld [hBGMapAddress + 1], a
ret
.Attr
ld a, 1
ld [rVBK], a
ld hl, AttrMap
call .update
ld a, 0
ld [rVBK], a
ret
.Tiles
ld hl, TileMap
.update
ld [hSPBuffer], sp
; Which third?
ld a, [hBGMapThird]
and a ; 0
jr z, .top
dec a ; 1
jr z, .middle
; 2
THIRD_HEIGHT EQU SCREEN_HEIGHT / 3
.bottom
ld de, 2 * THIRD_HEIGHT * SCREEN_WIDTH
add hl, de
ld sp, hl
ld a, [hBGMapAddress + 1]
ld h, a
ld a, [hBGMapAddress]
ld l, a
ld de, 2 * THIRD_HEIGHT * BG_MAP_WIDTH
add hl, de
; Next time: top third
xor a
jr .start
.middle
ld de, THIRD_HEIGHT * SCREEN_WIDTH
add hl, de
ld sp, hl
ld a, [hBGMapAddress + 1]
ld h, a
ld a, [hBGMapAddress]
ld l, a
ld de, THIRD_HEIGHT * BG_MAP_WIDTH
add hl, de
; Next time: bottom third
ld a, 2
jr .start
.top
ld sp, hl
ld a, [hBGMapAddress + 1]
ld h, a
ld a, [hBGMapAddress]
ld l, a
; Next time: middle third
ld a, 1
.start
; Which third to update next time
ld [hBGMapThird], a
; Rows of tiles in a third
ld a, SCREEN_HEIGHT / 3
; Discrepancy between TileMap and BGMap
ld bc, BG_MAP_WIDTH - (SCREEN_WIDTH - 1)
.row
; Copy a row of 20 tiles
rept SCREEN_WIDTH / 2 - 1
pop de
ld [hl], e
inc l
ld [hl], d
inc l
endr
pop de
ld [hl], e
inc l
ld [hl], d
add hl, bc
dec a
jr nz, .row
ld a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret
; 170a
Serve1bppRequest: ; 170a
; Only call during the first fifth of VBlank
ld a, [Requested1bpp]
and a
ret z
; Back out if we're too far into VBlank
ld a, [rLY]
cp 144
ret c
cp 146
ret nc
; Copy [Requested1bpp] 1bpp tiles from [Requested1bppSource] to [Requested1bppDest]
ld [hSPBuffer], sp
; Source
ld hl, Requested1bppSource
ld a, [hli]
ld h, [hl]
ld l, a
ld sp, hl
; Destination
ld hl, Requested1bppDest
ld a, [hli]
ld h, [hl]
ld l, a
; # tiles to copy
ld a, [Requested1bpp]
ld b, a
xor a
ld [Requested1bpp], a
.next
rept 3
pop de
ld [hl], e
inc l
ld [hl], e
inc l
ld [hl], d
inc l
ld [hl], d
inc l
endr
pop de
ld [hl], e
inc l
ld [hl], e
inc l
ld [hl], d
inc l
ld [hl], d
inc hl
dec b
jr nz, .next
ld a, l
ld [Requested1bppDest], a
ld a, h
ld [Requested1bppDest + 1], a
ld [Requested1bppSource], sp
ld a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret
; 1769
Serve2bppRequest: ; 1769
; Only call during the first fifth of VBlank
ld a, [Requested2bpp]
and a
ret z
; Back out if we're too far into VBlank
ld a, [rLY]
cp 144
ret c
cp 146
ret nc
jr _Serve2bppRequest
Serve2bppRequest@VBlank: ; 1778
ld a, [Requested2bpp]
and a
ret z
_Serve2bppRequest: ; 177d
; Copy [Requested2bpp] 2bpp tiles from [Requested2bppSource] to [Requested2bppDest]
ld [hSPBuffer], sp
; Source
ld hl, Requested2bppSource
ld a, [hli]
ld h, [hl]
ld l, a
ld sp, hl
; Destination
ld hl, Requested2bppDest
ld a, [hli]
ld h, [hl]
ld l, a
; # tiles to copy
ld a, [Requested2bpp]
ld b, a
xor a
ld [Requested2bpp], a
.next
rept 7
pop de
ld [hl], e
inc l
ld [hl], d
inc l
endr
pop de
ld [hl], e
inc l
ld [hl], d
inc hl
dec b
jr nz, .next
ld a, l
ld [Requested2bppDest], a
ld a, h
ld [Requested2bppDest + 1], a
ld [Requested2bppSource], sp
ld a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret
; 17d3
AnimateTileset: ; 17d3
; Only call during the first fifth of VBlank
ld a, [$ffde]
and a
ret z
; Back out if we're too far into VBlank
ld a, [rLY]
cp 144
ret c
cp 151
ret nc
ld a, [hROMBank]
push af
ld a, BANK(_AnimateTileset)
rst Bankswitch
ld a, [rSVBK]
push af
ld a, 1
ld [rSVBK], a
ld a, [rVBK]
push af
ld a, 0
ld [rVBK], a
call _AnimateTileset
pop af
ld [rVBK], a
pop af
ld [rSVBK], a
pop af
rst Bankswitch
ret
; 17ff