You've already forked pokecrystal-board
mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-09-08 08:13:02 -07:00
Merge branch 'yenatch/split-predefs-specials-stds' into fix-split-predefs-specials-stds
https://github.com/kanzure/pokecrystal/pull/198
This commit is contained in:
31
common/double_speed.asm
Normal file
31
common/double_speed.asm
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
; The CGB hardware introduces Double Speed Mode.
|
||||||
|
; While active, the clock speed is doubled.
|
||||||
|
|
||||||
|
; The hardware can switch between normal speed
|
||||||
|
; and double speed at any time, but LCD output
|
||||||
|
; collapses during the switch.
|
||||||
|
|
||||||
|
DoubleSpeed: ; 2fef
|
||||||
|
ld hl, rKEY1
|
||||||
|
bit 7, [hl]
|
||||||
|
jr z, SwitchSpeed
|
||||||
|
ret
|
||||||
|
; 2ff7
|
||||||
|
|
||||||
|
NormalSpeed: ; 2ff7
|
||||||
|
ld hl, rKEY1
|
||||||
|
bit 7, [hl]
|
||||||
|
ret z
|
||||||
|
; 2ffd
|
||||||
|
|
||||||
|
SwitchSpeed: ; 2ffd
|
||||||
|
set 0, [hl]
|
||||||
|
xor a
|
||||||
|
ld [rIF], a
|
||||||
|
ld [rIE], a
|
||||||
|
ld a, $30
|
||||||
|
ld [rJOYP], a
|
||||||
|
stop ; rgbasm adds a nop after this instruction by default
|
||||||
|
ret
|
||||||
|
; 300b
|
||||||
|
|
38
common/handshake.asm
Normal file
38
common/handshake.asm
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
AskSerial: ; 2063
|
||||||
|
; send out a handshake while serial int is off
|
||||||
|
ld a, [$c2d4]
|
||||||
|
bit 0, a
|
||||||
|
ret z
|
||||||
|
|
||||||
|
ld a, [$c2d5]
|
||||||
|
and a
|
||||||
|
ret nz
|
||||||
|
|
||||||
|
; once every 6 frames
|
||||||
|
ld hl, $ca8a
|
||||||
|
inc [hl]
|
||||||
|
ld a, [hl]
|
||||||
|
cp 6
|
||||||
|
ret c
|
||||||
|
|
||||||
|
xor a
|
||||||
|
ld [hl], a
|
||||||
|
|
||||||
|
ld a, $c
|
||||||
|
ld [$c2d5], a
|
||||||
|
|
||||||
|
; handshake
|
||||||
|
ld a, $88
|
||||||
|
ld [rSB], a
|
||||||
|
|
||||||
|
; switch to internal clock
|
||||||
|
ld a, %00000001
|
||||||
|
ld [rSC], a
|
||||||
|
|
||||||
|
; start transfer
|
||||||
|
ld a, %10000001
|
||||||
|
ld [rSC], a
|
||||||
|
|
||||||
|
ret
|
||||||
|
; 208a
|
||||||
|
|
@@ -156,7 +156,7 @@ Init: ; 17d
|
|||||||
ld a, [hCGB]
|
ld a, [hCGB]
|
||||||
and a
|
and a
|
||||||
jr z, .asm_22b
|
jr z, .asm_22b
|
||||||
call Function2ff7
|
call NormalSpeed
|
||||||
.asm_22b
|
.asm_22b
|
||||||
|
|
||||||
xor a
|
xor a
|
||||||
|
76
common/item.asm
Normal file
76
common/item.asm
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
DoItemEffect: ; 2f3f
|
||||||
|
callba _DoItemEffect
|
||||||
|
ret
|
||||||
|
; 2f46
|
||||||
|
|
||||||
|
CheckTossableItem: ; 2f46
|
||||||
|
push hl
|
||||||
|
push de
|
||||||
|
push bc
|
||||||
|
callba _CheckTossableItem
|
||||||
|
pop bc
|
||||||
|
pop de
|
||||||
|
pop hl
|
||||||
|
ret
|
||||||
|
; 2f53
|
||||||
|
|
||||||
|
TossItem: ; 2f53
|
||||||
|
push hl
|
||||||
|
push de
|
||||||
|
push bc
|
||||||
|
ld a, [hROMBank]
|
||||||
|
push af
|
||||||
|
ld a, BANK(_TossItem)
|
||||||
|
rst Bankswitch
|
||||||
|
|
||||||
|
call _TossItem
|
||||||
|
|
||||||
|
pop bc
|
||||||
|
ld a, b
|
||||||
|
rst Bankswitch
|
||||||
|
pop bc
|
||||||
|
pop de
|
||||||
|
pop hl
|
||||||
|
ret
|
||||||
|
; 2f66
|
||||||
|
|
||||||
|
ReceiveItem: ; 2f66
|
||||||
|
push bc
|
||||||
|
ld a, [hROMBank]
|
||||||
|
push af
|
||||||
|
ld a, BANK(_ReceiveItem)
|
||||||
|
rst Bankswitch
|
||||||
|
push hl
|
||||||
|
push de
|
||||||
|
|
||||||
|
call _ReceiveItem
|
||||||
|
|
||||||
|
pop de
|
||||||
|
pop hl
|
||||||
|
pop bc
|
||||||
|
ld a, b
|
||||||
|
rst Bankswitch
|
||||||
|
pop bc
|
||||||
|
ret
|
||||||
|
; 2f79
|
||||||
|
|
||||||
|
CheckItem: ; 2f79
|
||||||
|
push hl
|
||||||
|
push de
|
||||||
|
push bc
|
||||||
|
ld a, [hROMBank]
|
||||||
|
push af
|
||||||
|
ld a, BANK(_CheckItem)
|
||||||
|
rst Bankswitch
|
||||||
|
|
||||||
|
call _CheckItem
|
||||||
|
|
||||||
|
pop bc
|
||||||
|
ld a, b
|
||||||
|
rst Bankswitch
|
||||||
|
pop bc
|
||||||
|
pop de
|
||||||
|
pop hl
|
||||||
|
ret
|
||||||
|
; 2f8c
|
||||||
|
|
54
common/predef.asm
Normal file
54
common/predef.asm
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
Predef: ; 2d83
|
||||||
|
; Call predefined function a.
|
||||||
|
; Preserves bc, de, hl and f.
|
||||||
|
|
||||||
|
ld [PredefID], a
|
||||||
|
ld a, [hROMBank]
|
||||||
|
push af
|
||||||
|
|
||||||
|
ld a, BANK(GetPredefPointer)
|
||||||
|
rst Bankswitch
|
||||||
|
call GetPredefPointer ; stores hl in PredefTemp
|
||||||
|
|
||||||
|
; Switch to the new function's bank
|
||||||
|
rst Bankswitch
|
||||||
|
|
||||||
|
; Instead of directly calling stuff,
|
||||||
|
; push it to the stack in reverse.
|
||||||
|
|
||||||
|
ld hl, .Return
|
||||||
|
push hl
|
||||||
|
|
||||||
|
; Call the Predef function
|
||||||
|
ld a, [PredefAddress]
|
||||||
|
ld h, a
|
||||||
|
ld a, [PredefAddress + 1]
|
||||||
|
ld l, a
|
||||||
|
push hl
|
||||||
|
|
||||||
|
; Get hl back
|
||||||
|
ld a, [PredefTemp]
|
||||||
|
ld h, a
|
||||||
|
ld a, [PredefTemp + 1]
|
||||||
|
ld l, a
|
||||||
|
ret
|
||||||
|
|
||||||
|
.Return
|
||||||
|
; Clean up after the Predef call
|
||||||
|
|
||||||
|
ld a, h
|
||||||
|
ld [PredefTemp], a
|
||||||
|
ld a, l
|
||||||
|
ld [PredefTemp+1], a
|
||||||
|
|
||||||
|
pop hl
|
||||||
|
ld a, h
|
||||||
|
rst Bankswitch
|
||||||
|
|
||||||
|
ld a, [PredefTemp]
|
||||||
|
ld h, a
|
||||||
|
ld a, [PredefTemp + 1]
|
||||||
|
ld l, a
|
||||||
|
ret
|
||||||
|
; 2dba
|
||||||
|
|
76
common/random.asm
Normal file
76
common/random.asm
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
Random: ; 2f8c
|
||||||
|
; A simple hardware-based random number generator (RNG).
|
||||||
|
|
||||||
|
; Two random numbers are generated by adding and subtracting
|
||||||
|
; the divider to the respective values every time it's called.
|
||||||
|
|
||||||
|
; The divider is a register that increments at a rate of 16384Hz.
|
||||||
|
; For comparison, the Game Boy operates at a clock speed of 4.2MHz.
|
||||||
|
|
||||||
|
; Additionally, an equivalent function is executed in VBlank.
|
||||||
|
|
||||||
|
; This leaves a with the value in hRandomSub.
|
||||||
|
|
||||||
|
push bc
|
||||||
|
|
||||||
|
ld a, [rDIV]
|
||||||
|
ld b, a
|
||||||
|
ld a, [hRandomAdd]
|
||||||
|
adc b
|
||||||
|
ld [hRandomAdd], a
|
||||||
|
|
||||||
|
ld a, [rDIV]
|
||||||
|
ld b, a
|
||||||
|
ld a, [hRandomSub]
|
||||||
|
sbc b
|
||||||
|
ld [hRandomSub], a
|
||||||
|
|
||||||
|
pop bc
|
||||||
|
ret
|
||||||
|
; 2f9f
|
||||||
|
|
||||||
|
BattleRandom: ; 2f9f
|
||||||
|
; _BattleRandom lives in another bank.
|
||||||
|
|
||||||
|
; It handles all RNG calls in the battle engine, allowing
|
||||||
|
; link battles to remain in sync using a shared PRNG.
|
||||||
|
|
||||||
|
ld a, [hROMBank]
|
||||||
|
push af
|
||||||
|
ld a, BANK(_BattleRandom)
|
||||||
|
rst Bankswitch
|
||||||
|
|
||||||
|
call _BattleRandom
|
||||||
|
|
||||||
|
ld [$cfb6], a
|
||||||
|
pop af
|
||||||
|
rst Bankswitch
|
||||||
|
ld a, [$cfb6]
|
||||||
|
ret
|
||||||
|
; 2fb1
|
||||||
|
|
||||||
|
|
||||||
|
Function2fb1: ; 2fb1
|
||||||
|
push bc
|
||||||
|
ld c, a
|
||||||
|
xor a
|
||||||
|
sub c
|
||||||
|
.asm_2fb5
|
||||||
|
sub c
|
||||||
|
jr nc, .asm_2fb5
|
||||||
|
add c
|
||||||
|
ld b, a
|
||||||
|
push bc
|
||||||
|
.asm_2fbb
|
||||||
|
call Random
|
||||||
|
ld a, [hRandomAdd]
|
||||||
|
ld c, a
|
||||||
|
add b
|
||||||
|
jr c, .asm_2fbb
|
||||||
|
ld a, c
|
||||||
|
pop bc
|
||||||
|
call SimpleDivide
|
||||||
|
pop bc
|
||||||
|
ret
|
||||||
|
; 2fcb
|
||||||
|
|
34
common/sram.asm
Normal file
34
common/sram.asm
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
GetSRAMBank: ; 2fcb
|
||||||
|
; load sram bank a
|
||||||
|
; if invalid bank, sram is disabled
|
||||||
|
cp NUM_SRAM_BANKS
|
||||||
|
jr c, OpenSRAM
|
||||||
|
jr CloseSRAM
|
||||||
|
; 2fd1
|
||||||
|
|
||||||
|
OpenSRAM: ; 2fd1
|
||||||
|
; switch to sram bank a
|
||||||
|
push af
|
||||||
|
; latch clock data
|
||||||
|
ld a, 1
|
||||||
|
ld [MBC3LatchClock], a
|
||||||
|
; enable sram/clock write
|
||||||
|
ld a, SRAM_ENABLE
|
||||||
|
ld [MBC3SRamEnable], a
|
||||||
|
; select sram bank
|
||||||
|
pop af
|
||||||
|
ld [MBC3SRamBank], a
|
||||||
|
ret
|
||||||
|
; 2fe1
|
||||||
|
|
||||||
|
CloseSRAM: ; 2fe1
|
||||||
|
push af
|
||||||
|
ld a, SRAM_DISABLE
|
||||||
|
; reset clock latch for next time
|
||||||
|
ld [MBC3LatchClock], a
|
||||||
|
; disable sram/clock write
|
||||||
|
ld [MBC3SRamEnable], a
|
||||||
|
pop af
|
||||||
|
ret
|
||||||
|
; 2fec
|
||||||
|
|
@@ -539,7 +539,7 @@ Script_verbosegiveitem2: ; 0x96f8e
|
|||||||
ld a, [de]
|
ld a, [de]
|
||||||
ld [$d10c], a
|
ld [$d10c], a
|
||||||
ld hl, $d892
|
ld hl, $d892
|
||||||
call Function2f66
|
call ReceiveItem
|
||||||
ld a, $1
|
ld a, $1
|
||||||
jr c, .asm_96fb0 ; 0x96fad $1
|
jr c, .asm_96fb0 ; 0x96fad $1
|
||||||
xor a
|
xor a
|
||||||
@@ -2320,7 +2320,7 @@ Script_giveitem: ; 0x977ca
|
|||||||
call GetScriptByte
|
call GetScriptByte
|
||||||
ld [$d10c], a
|
ld [$d10c], a
|
||||||
ld hl, $d892
|
ld hl, $d892
|
||||||
call Function2f66
|
call ReceiveItem
|
||||||
jr nc, .asm_977eb ; 0x977e3 $6
|
jr nc, .asm_977eb ; 0x977e3 $6
|
||||||
ld a, $1
|
ld a, $1
|
||||||
ld [$c2dd], a
|
ld [$c2dd], a
|
||||||
@@ -2346,7 +2346,7 @@ Script_takeitem: ; 0x977f0
|
|||||||
ld a, $ff
|
ld a, $ff
|
||||||
ld [$d107], a
|
ld [$d107], a
|
||||||
ld hl, $d892
|
ld hl, $d892
|
||||||
call Function2f53
|
call TossItem
|
||||||
ret nc
|
ret nc
|
||||||
ld a, $1
|
ld a, $1
|
||||||
ld [$c2dd], a
|
ld [$c2dd], a
|
||||||
@@ -2363,7 +2363,7 @@ Script_checkitem: ; 0x97812
|
|||||||
call GetScriptByte
|
call GetScriptByte
|
||||||
ld [$d106], a
|
ld [$d106], a
|
||||||
ld hl, $d892
|
ld hl, $d892
|
||||||
call PickUpItem
|
call CheckItem
|
||||||
ret nc
|
ret nc
|
||||||
ld a, $1
|
ld a, $1
|
||||||
ld [$c2dd], a
|
ld [$c2dd], a
|
||||||
|
@@ -45,7 +45,7 @@ GiveOddEgg: ; 1fb4b6
|
|||||||
ld a, $ff
|
ld a, $ff
|
||||||
ld [$d107], a
|
ld [$d107], a
|
||||||
ld hl, NumItems
|
ld hl, NumItems
|
||||||
call Function2f53
|
call TossItem
|
||||||
ld a, EGG
|
ld a, EGG
|
||||||
ld [$cd2a], a
|
ld [$cd2a], a
|
||||||
ld a, $29
|
ld a, $29
|
||||||
|
Reference in New Issue
Block a user