Wiki

Clone wiki

pokered-hg / ScriptingNotes

Scripting Notes

PLAY_CRY $13d0

  1. select Mon ID:
    1. ld a,xx
  2. call $13d0

PRINT_BCD_NUMBER $15cd

  1. select flags (bit 765) and length of number (low nybble):
    1. ld c,xx
  2. select location of number:
    1. ld de,ddee
  3. select location on the screen ($C3A0-c507):
    1. ld hl,hhll
  4. call $15cd
765zero interpr.P money
0000 = zero
0010 = zeroYES
0100 = zero
0110 = zeroYES
1000 = space
1010 = spaceYES
1100 = nothing
1110 = nothingYES

COPY_GFX_1BPP $1886

  1. set source:
    1. ld a,aa ;bank
    2. ld de,ddee ;pointer
  2. set destination:
    1. ld hl,hhll
  3. set tile number:
    1. ld c,cc
  4. call $1886

CLEAN_SCREEN_PART $18c4 (or DRAW_BOX?)

  1. set height(b) and width(c) of area (unit is tile):
    1. ld bc,hhww
  2. set starting tile on screen (screen begins at c3a0):
    1. ld hl,$c???
  3. call $18c4

STOP music

  1. select stop_marker:
    1. ld a,$ff
  2. call $23b1

(read also APPENDIX $23b1)

LOAD music

  1. select music_bank
    1. ld c,xx
  2. select music_specifics(???)
    1. ld a,yy
  3. call $23a1

SCRIPT_TEXT $2920

Check Text Pointer Structure for in‐depth examination

  1. select text_ID
    1. ld a,xx
    2. ld [ff00+8c],a
  2. call $2920
valtext
$00menu
$d3“PA: your safari game is over!”
$d0“\n fainted”
$d1black‐out sentence
$d2“REPEL’s effect wore off”
$f5vending machine
$f6Cable Club
$f7slot machines
$fcturn on PC
$fd“switch on!” (Mon Storage Sys)
$femart buy/sell menu
$ffpokecenter heal speech

COPY_DATA_[cf7b]_FF $2a5a

Writes data from hl into [cf7b]. FF-terminated.

  1. select source:
    1. ld hl,hhll
  2. call $2a5a

COUNT_SET_BITS $2b7f

Value is stored always in $d11e.

  1. select starting byte:
    1. ld hl,hhll
  2. select number of bytes (i.e number of bits/8)
    1. ld b,bb
  3. call $2a5a

ADD_ITEM_LIST $2bcf

This is probably a sub-routine of GIVE_ITEM.

  1. select list’s starting byte:
    1. ld hl,hhll
  2. select type and quantity of items:
    1. ld a,xx ;type
    2. ld [$cf91],a
    3. ld a,yy
    4. ld [$cf96],a ;quantity
  3. call $2bcf

GET_MON_NAME_[cd6d] $2f9e

Write the Pokémon name (real name, not nickname), at cd6d. Used mainly for texts (that use command[01] to write text from RAM).

  1. select monID:
    1. ld a,xx
    2. ld [$d11e],a
  2. call $2f9e

LOAD_LEVEL $3071

Loads map specified in $d35e and all related to it?

  1. call $3071

[load mapID in [$D35E]; maybe event displacement coul be necessary too.]


TOSS_ITEM $30c4

  1. load starting address:
    1. ld hl,$d31d
  2. call $30c4

[add more info]


CC57_SCRIPTS $310e

IF (bit 0,[$d736])
  {
    ld b,6
    ld hl,$63e0
    jp Bankswitch
  }

$CC57 must be ≠ 0 for this function to be activated.

  1. set subScript ptr:
    1. ld a,xx ;subScriptID
  2. call $310e ???

TRAINER_IN_MAP $3160

Handles both level script and trainer events:

  1. Select data:
    1. ld hl,ScriptPtrTable
    2. ld de,TrainerHeaders
  2. call correctly:
    1. ld a,[ScriptFlag]
    2. call $3160
    3. ld [ScriptFlag],a
    4. ret
ScriptFlag ex
Viridian Gym = [$D5FB]

STORE_2_STRINGS $317f

Stores 2 strings in RAM:

  • [$CF5F] $11 bytes max
  • [$CF70] $0B bytes max
  1. load ptrs:
    1. ld hl,string1
    2. ld de,string2
  2. call $317f
  • string1: [char][char]…[$50]
  • string2: [char][char]…[$50]

SET_BATTLE $31cc

This is a map-script (not text-script)

  1. set Battle Specs ptr:
    1. ld hl,TrainerHeaders
  2. set ptr to battle ptrs:
    1. ld de,ddee
  3. call $31cc

TrainerHeaders:

  • [flagbit (and textscriptID)]
  • [trainer’s view range x 0x10]
  • [flag-byte ptr]
  • [ptr to text before battle]
  • [ptr to text later on]
  • [ptr to text ending battle]
  • [ptr to text (same as previous)]
  • [0xFF]

[check Appendix:Trainer scripts]


HEX_DEC_CONVERT $323d

  1. select mode:
    1. ld b,xyz000vw
x = write zeros
y = don’t
z = P?
v = 2B
w = 1B
vw = 3B
  1. select RAM location:
    1. ld de,ddee
  2. call $323d

SAVE_OAM_POS? $32ef

  1. select Object_ID:
    1. ld a,xx
    2. ld [$cf13],a
  2. call $32ef

[not sure]


STORE_WINLOSE_TEXT $3354

  1. select win_text and lose_text:
    1. ld hl,hhll
    2. ld de,ddee
  2. call $3354

HANDLE_SPINNERS $3442

  1. Set spinners’ table:
    1. ld hl,.Spinners
  2. call $3442

Spinners:

  • [Y][X][Mov1.Ptr]
  • [Y][X][Mov2.Ptr]
  • [Y][X][MovN.Ptr]
  • [$FF]

Mov.Ptr:

  • [Direction][n. of steps]
  • [$FF]

{sound_A7, outside, is spin sound}


FORCE_PLAYER_MOVE $3486

  1. load path in $ccd3 (check $350c)
  2. set length_of_path:
    1. ld a,xx
    2. ld [$cd38]
  3. call $3486

[$cd38] > 0 until path_move is over.


CHECK_ITEM $3493

  1. select Item_ID:
    1. ld b,xx
  2. call $3493

FACE_OBJECT $34a6

  1. select person’s ID:
    1. ld a,xx
    2. ld [$ff8c],a
  2. select direction:
    1. ld a,yy
    2. ld [$ff8d],a
  3. call $34a6

CHECK_COORDS $34bf

Sets carry if finds a match.

CoordsTable = [Y][X]…[FF]

  1. select CoordsTable pointer:
    1. ld hl,hhll
  2. call $34bf

(example: Seafoam holes)


COPY_RLE_DATA $350c

Note: ‘de’ is source, ‘hl’ is dest

  1. select source (run-length encoded)
    1. ld de,ddee
    2. ld [$ff00+8c],a
  2. select destination (in RAM area): preferably $CCD3
    1. ld hl,hhll
  3. call $350c
  • [OUT: ccd2 = data decompressed length]
  • [OUT: a = [ccd2] + 1]

CALL_ANOTHER_BANK $35d6

  1. select Bank:
    1. ld b,xx
  2. select Address
    1. ld hl,aabb
  3. call $35d6

YES_NO_CHOICE $35ec

  1. call $35ec
  2. check choice (0 = Yes, 1 = No)
    1. ld a,[$cc26]
    2. and a
  3. Highly customizable (ret nz; jr z,xx; etc..)

APPLY_PATH $363a

  1. select people_ID
    1. ld a,xx
    2. ld [$ff00+8c],a
  2. path_structure pointer
    1. ld de,yyzz
  3. call $363a

[bit 0,[$d730] ≠ 0 until path_move is over.]


LOAD_FONT_GFX $3680

Simple as that:

  1. call $3680

LOAD_TEXTBOX_GFX $36a0

Simple as that (loads fullCaps chars,apices,jpn chars and textboxes’ borders):

  1. call $36a0

LOAD_HEALTHBAR_GFX $36c0

Simple as that (loads healthbar, textbox borders, monMenu gfx):

  1. call $36c0

BACKUP_SCREEN_BUFF $36f4

Saves area $C3A0-$C507 to $CD81-$CEE8

  1. call $36f4

RESTORE_SCREEN_BUFF $3701

Loads area $CD81-$CEE8 to $C3A0-$C507 and print it to screen.

  1. call $3701

REFRESH_SCREEN $3739

  1. select how many times to refresh:
    1. ld c,xx
  2. call $3739

WAIT_END_CRY $3748

Usually used right after “$13d0”

  1. call $3748

GET_KEY_PRESS $3831

  1. call $3831
  2. Read what key is pressed:
    1. ld a,[$ffb5]
      [ffb7 = keyDown] ;XXX
      [ffb5 = keyPress] ;XXX

MULTIPLY $38ac

RESULT is stored in [$ff96]-[$ff98], obviously in little-endian.

  1. clean result’s MSB [$ff96]:
    1. xor a
    2. ld [$ff96],a
  2. load factors:
    1. ;1st factor [16 bit]
    2. ld a,hh
    3. ld [$ff97],a
    4. ld a,ll
    5. ld [$ff98],a
    6. ;2nd factor [8 bit]
    7. ld a,ii
    8. ld [$ff99],a
  3. call $38ac
  • [1st factor is 16 bit]
  • [2nd factor is 8 bit]

DIVIDE $38b9

Formats are Big-Endian (!). Result is 16 bit.

  1. load dividend in area [$ff93 + {reg.b}] through [$ff95 + {reg.b}].
  2. load divisor:
    1. ld a,dd
    2. ld [$ff99],a
  3. Load HRAM-used shift:
    1. ld b,bb ;2 ≤ bb ≤ 4
  4. call $38b9

[result is rounded down (int)]}


ADD_MON_ASK_NICK $3927 ;??? needs fix

Actually adds monster to the party and asks for nickname:

  1. Don’t know why:
    1. or a
    2. d [$cc49],a
  2. select level and specie:
    1. ld a,lv
    2. ld [$d127],a
    3. ld a,xx
    4. ld a,[$cf91]
    5. ld a,[$d11e]
  3. call $3927

MULTIPLY_$3a87

hl = (a x bc) + hl

  1. Load values (a, bc, hl)
  2. call $3a87

PRINT_TEXT $3c49

  1. select {Pointer_offset - 1} (must point to a byte=$17):
    1. ld hl,xxyy
  2. call $3c49

pointed structure:

  • $17
  • pointer
  • bank
  • $50

SELECT_CODE_POINTER $3d97

  1. select pointer_ID:
    1. ld a,xx
    2. ld a,(vvww)
  2. select pointertable’s pointer:
    1. ld hl,yyzz
  3. call $3d97

[for more info check APPENDIX($3d97)]


GIVE_ITEM 0x3e2e

  1. select item ID(b) and quantity(c):
    1. ld bc,xxyy

Double choice:

  1. call $3e2e
  1. ld a,$1e
    1. call $3e6d

GIVE_PKMN $3e48

  1. select pkmn(b) & level(c):
    1. ld bc,xxyy
  2. call $3e48
  3. check carry

GET_RND_NUM $3e5c

  1. call $3e5c

a = 1st random value [$FFD3] = 1st random value [$FFD4] = 2nd random value


GENERAL SCRIPT $3e6d

How to use

  1. [OPTIONAL] value needed in the subroutine
    1. ld a,xx
    2. ld [$cc4d],a
  2. subroutine ID
    1. ld a,yy
  3. call subroutine selection
    1. call $3e6d

[for more info check APPENDIX($3e6d)]


RESTORE_REGS_PREDEF $3e94

This routine is used by routines called by Predef (routine at $3e6d) and restores registers that were saved in the following RAM locations:

  • cc4f: h
  • cc50: l
  • cc51: d
  • cc52: e
  • cc53: b
  • cc54: c
  1. call $3e94

[skip this]

APPLY_DOUBLE_PATH 06:64

  1. select pkmn(b) & level(c):
    1. ld bc,xxyy
  2. call $3e48
  3. check carry

[/end skip]

TEXT ZONE (pointer table pointed by TextPointer [MapHeader])

APPENDIX ($23b1)

97 = poisoned pokemon sound (while walking in overworld)


APPENDIX TRAINER SCRIPTS

Text-script part:
{
	db $08
	ld hl,MyTrainerHeader1
	call $31cc
	jp $24d7
MyTrainerHeaders:
MyTrainerHeader1:
	;(…)
	;(…)
MyTrainerHeaderN:
	;(…)
	db $FF
}
Map-script part:
{
	ld hl,MyTrainerHeaders
	ld de,TrainerScriptPtrs
	ld a,[MapFlag]
	call $3160
	ld [MapFlag],a
	ret
TrainerScriptPtrs:
	dw $3219
	dw $324c
	dw $3275
}
3219:
{
Reads trainerHeader (first of all checks flag, if set skip to next trainerHeader, until FF-endByte)
}
324c:
{
}
3275:
{
}

APPENDIX ($3d97)

example Pallet town:

…
ROM6:4E6A 21 73 4E         ld hl,4e73	;pointer to pointers’table
ROM6:4E6D FA F1 D5         ld a,(d5f1)	;PalletRAM for code_ID

;jp xxyy with yy = (hl + ax2), xx = (hl + 1 + ax2)

ROM6:4E70 C3 97 3D         jp 3d97
…

APPENDIX ($3e6d)

RAM used:

  • cc4e: subroutine_ID
  • cf12: old bank number
  • d0b7: new bank number
  • cc4f: h
  • cc50: l
  • cc51: d
  • cc52: e
  • cc53: b
  • cc54: c
  • + lot of other RAMs, depending on which subr is called.

To recover registers’ values ‘call $3e94’

note1: various “clone” pointers[$09=$0a=$0d=$0e], why?

note2: pointers that point to bank0 (ID=$1d,$1e)load bank3, is it just padding?

note3: following pointers are little-endian (actually middle-endian: |bank|little-endian ptr|).

IDPointerPurpose
000F 604D
010F C670
020F 7370
030B 407E
040F 0371magnify backpics
051E BA5A
0603 3271
0703 A576restore mon’s health (es.: 1st rival battle)
081E 5E4Danimations maybe??
0903 1E77
0a03 1E77
0b03 1D78
0c03 3678subtract coins (BCD operation (decimal adjust))
0d03 1E77
0e03 1E77
0f03 5078
1003 6676RAMtbls:D737/9A/ED..setBit,resByte(\{bit}),b={0,1,2}c=[aaaaabbb]
1103 D771make an object visible (flags: d5a6-d5c6) [opposite of ID=15]
1203 A671check shown/hidden objects (flags starting at $d5a6)
1303 9C46
140F 834A
1503 C871make an object invisible (flags: d5a6-) [opposite of ID=11]
1603 C871
1703 9E6E
1803 5078initialize flags (and things like itemsack, etc.)
1903 5447load tileset header
1a0E 5B6FGetLevUpAtks_
1b01 436E
1c03 A578check item in bag
1d03 B53E
1e03 2E3Egive item (b = item_ID, c = item_num)
1f12 EB40blink screen for 4 frames [example: poisoned pokemon]
2003 BA78somehow related to apply_movement
2112 FF40
2203 2979somehow related to apply_movement
2303 A079
2412 2541
2503 1D7A
2603 DC79
2701 B05A
280F 026D
2910 0040
2a0E 1C6DGetEvos’ subset (label: Predef_2a_)
2b1C 8C77
2c0F 186F
2d01 5F5A
2e03 036ABio screen, gym-leaders/badges arrangement
2f10 F350
301C 6D49
311E DA5D
3210 8256load intro(copyrights,Gamefreak,NidoVSJigg)
331E 6958
341C 5D4B
3503 8645
3604 5369
3704 576B
3810 E250
3915 0F69
3a10 1050convert Mon_ID Chaotic-to-Dex
3b01 A162decompr sprite(hl=ptr,b=bank)& arrange[used in BioMenu & not only]
3c03 546F
3d10 D142load DexPage (INPUT:[$d11e]=DexMonID)
3e0E B86FGetWildMonAtks_
3f1C 0A77SAVE GAME
401C 2B60send SGB-packs at beginning (MLT_REQ,DATA_SND,PCT_TRN,…)
4103 1371
4217 5E5B
4304 3E77
4404 6377
451C DF5Dload SGB packages (PAL_SET)
4617 DC40load dex screen (es:lab when choosing starter)
4703 E572
4803 1D7A
490F EC4D
4a1C 604FTownMap (in Dex only?)
4b09 6B7D
4c05 477Cballoon over head (cd4f:personID, cd50:([!][?][^_^])
4d01 AF5A
4e01 EB64
4f0D A17C
501C 0F78save dex & party infos to SRAM1
511C BD76load dex & party infos from SRAM1
521C E875load SAV from SRAM1
531C E277save current bank’s stored mons to SRAM1
541C D95A
551D 5C40
5611 6941
571E BA45
581E 1045
5903 BE45
5a03 0B46
5b03 994D
5c01 E14Dcheck H/S obj (RAM_Table D5CE, FF-term.) ???
5d09 987D
5e03 7374related to AttacksData
5f04 EF68
6004 F668
6107 C649
6216 3550

Updated