• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Development: Useful G/S/C ASM routines

IIMarckus

J946@5488AA97464
402
Posts
16
Years
    • Seen Feb 21, 2024
    PRINT TEXT
    Writes a text box to screen.
    - load hl with the pointer to the starting textcode (usually 00h)
    - call $0F5E [G/S] or $1057 [C]

    Example:
    Code:
    21 3C 42  ld hl,$423C
    CD 5E 0F  call $0F5E

    COPY DATA
    Copies a set number of bytes from one location to another.
    - load hl with location of data to be copied
    - load de with location to copy to
    - load bc with the length of the data in bytes
    - call $311A [G/S] or $3026 [C]

    COPY TILES
    Writes tiles (including text variables) to screen. No length is given; it copies until reaching a 50h.
    - load hl with the tilemap location (G/S: $C3A0-$C507; Crystal: $C4A0-$C607)
    - load de with the pointer to the tiles
    - call $0F74 [G/S] or $1078 [C]

    Example:
    Code:
    21 E9 C4  ld hl,$C4E9
    11 00 40  ld de,$4000
    CD 74 0F  call $0F74

    PLAY MUSIC
    Starts playing background music.
    - load de with the song number
    - call $3D98 [G/S] or $3B97 [C]

    Example:
    Code:
    11 01 00  ld de,$0001
    CD 98 3D  call $3D98

    PLAY SOUND
    Plays a sound effect.
    - load de with the sound number
    - call $3E24 [G/S] or $3C23 [C]

    Example:
    Code:
    11 17 00  ld de,$0017
    CD 24 3E  call $3D98

    BANKSWITCH (HOME)
    Use this ONLY when PC is in the home ROM bank ($0000-$3FFF), or else you'll wind up in the middle of unrelated code! This changes the ROM bank currently in $4000-$7FFF, but not the location of the program counter.
    - load a with the bank number
    - rst $10 [G/S/C]

    Example:
    Code:
    3E 08     ld a,$08
    D7        rst $10

    BANKSWITCH
    Use this when PC is in the switchable ROM bank ($4000-$7FFF).
    - load a with the bank number
    - load hl with the location within the bank you want to switch to
    - rst $08 [G/S/C]

    Example:
    Code:
    3E 16     ld a,$16
    21 00 40  ld hl,$4000
    CF        rst $08

    USEFUL RAM LOCATIONS

    CURRENT ROM BANK
    If you ever need to know what ROM bank you're in, read the byte at $FF9F [G/S] or $FF9D [C].

    Example:
    Code:
    F0 9F     ld a,[$FF9F]

    TILEMAP
    Locations $C3A0-$C507 [G/S] and $C4A0-$C607 [C] each represent a background tile on the screen. $C3A0 [G/S] is the first tile of the first row, $C3B4 [G/S] is the second tile of the first row, and so on. Write a value to one of these bytes, and the corresponding background tile will appear in that location on the screen.

    Example:
    Code:
    3E 0A      ld a,$0A
    EA 4E C4   ld ($C44E),a



    If you've found some good in-game routines (or coded your own), feel free to post it here.
     
    Last edited:
    1,372
    Posts
    18
    Years
    • Seen Jan 18, 2021
    This is very useful. I will find it helpful when hacking GS, well done on the Tutorial ;)
     

    Binary

    え?
    3,977
    Posts
    16
    Years
    • Seen Apr 7, 2014
    Very useful, now i have learnt more about G/S/C Hacking.
    Thanks alot.

    ~Celebi
     

    The dude

    Metal is good
    87
    Posts
    19
    Years
    • Seen May 11, 2016
    What about Call 311a? The Most Important one in GS!!!
    Its a raw data copy thing

    ld hl,data
    ld de,copy to...
    ld bc, how many bytes
    Call 311a!!!!
     

    IIMarckus

    J946@5488AA97464
    402
    Posts
    16
    Years
    • Seen Feb 21, 2024
    Thanks, The dude! At first I confused yours with the tile copy routine, but this one lets you choose the number of bytes, rather than ending at $50.
     
    Back
    Top