PDA

View Full Version : Useful G/S/C ASM routines


IIMarckus
November 28th, 2007, 08:37 PM
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: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: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: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: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: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: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: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: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.

Blazichu
December 5th, 2007, 03:53 AM
This is very useful. I will find it helpful when hacking GS, well done on the Tutorial ;)

Binary
December 5th, 2007, 06:33 AM
Very useful, now i have learnt more about G/S/C Hacking.
Thanks alot.

~Celebi

Coolboyman
December 5th, 2007, 09:29 PM
Hey marckus, this was a great idea to help people out who are interested in ASM. Good job.

The dude
February 29th, 2008, 04:41 PM
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
February 29th, 2008, 06:12 PM
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.