RGBGrafx>Functions

back to the front page


Table Of Contents
General Functions
RGBG_ScreenOff
Tile Functions
RGBG_LoadTiles
RGBG_RotateTileRight
RGBG_RotateTileLeft
Palette Functions
RGBG_ConvertColor15to24
RGBG_ConvertColor24to15
RGBG_SetDefPals
RGBG_SetGBCPals
RGBG_FillGBCPals
RGBG_InvertGBCPals
RGBG_GrayscaleGBCPals
Map Functions
RGBG_SetTileMap
RGBG_FillTileMap
RGBG_SetTile
RGBG_XYToTileMap
Sprite Functions
RGBG_SetSpriteTile
RGBG_SetSpriteProp
RGBG_SetSpritePos
RGBG_GetSpriteTile
RGBG_GetSpriteProp
RGBG_GetSpritePos
RGBG_MoveSprite
RGBG_CopyDMARoutine
RGBG_DoDMA
RGBG_ZeroOAM
Fade Functions
RGBG_MakeDarker
RGBG_MakeLighter
RGBG_SimpleFadeOut
RGBG_InitComplexFadeBkg
RGBG_RunComplexFadeStepBkg
RGBG_DecodeComplexFadePalsBkg
RGBG_UpdateComplexFadePalsBkg
RGBG_InitComplexFadeObj
RGBG_RunComplexFadeStepObj
RGBG_DecodeComplexFadePalsObj
RGBG_UpdateComplexFadePalsObj
RGBG_RunComplexFadeBkg
RGBG_RunComplexFadeObj

General Functions
RGBG_ScreenOff

RGBG_ScreenOff

Waits for the beginning of vblank and turns of the screen. This functions complies with Nintendo's guidlines, and should pass lot check.

Input

none

no input


Tile Functions
RGBG_LoadTiles, RGBG_RotateTileRight, RGBG_RotateTileLeft

RGBG_LoadTiles

Loads tiles from memory into video RAM

Input

BC

Pointer to the Source tileset

D

Number of tile to copy

E

First destination tile

[RGBG_tileset]

High byte of tileset to write to ($88 or $88)


RGBG_RotateTileRight

Rotates one tile to the right. Usefull creating paralax backgrounds.

Input

A

Tile to rotate

[RGBG_tileset]

High byte of tileset that contains the tile ($88 or $88)


RGBG_RotateTileLeft

See RGBG_RotateTileRight


Palette Functions
RGBG_ConvertColor15to24, RGBG_ConvertColor24to15, RGBG_SetDefPals, RGBG_SetGBCPals, RGBG_FillGBCPals, RGBG_InvertGBCPals, RGBG_GrayscaleGBCPals

RGBG_ConvertColor15to24

Converts a color from the GBC's 15-bit standard (xbbbbbgggggrrrrr) to a 24-bit color, with one byte per component.

Input

D

High byte of color

E

Low byte of color

Outuut

H

Blue component

L

Green component

A

Red component


RGBG_ConvertColor24to15

Converts a color from 24-bit color, byte per component format to the GBC's 15-bit standard (xbbbbbgggggrrrrr).

Input

H

Blue component

L

Green component

A

Red component

Output

D

High byte of color

E

Low byte of color


RGBG_SetDefPals

Sets all of the the Gameboy Color and Monochrome Gameboy palettes to a plain grayscale

Input

none

no input


RGBG_SetGBCPals

Sets a range of colors in the GameBoy Color palettes based on colors stored in memory. Uses colors stored in 15-bit Gameboy Color format.

Input

A

0 (or RGBG_BKG_PALS) for bakground palettes
1 (or RGBG_SPR_PALS) for sprite palettes

B

First color (first palette*4 + first color in that palette)

C

Number of colors to set

HL

Pointer to source colors


RGBG_FillGBCPals

Fills all of the GameBoy Color palettes with a single color. Uses a color stored in 15-bit Gameboy Color format.

Input

HL

Color to fill the paletts with


RGBG_InvertGBCPals

Inverts colors stored in memory, and stores the new colors into memory. Uses a color stored in 15-bit Gameboy Color format.

Input

B

Number of colors to invert

DE

Pointer to input colors.

HL

Pointer to output colors. (may be the same as DE)


RGBG_GrayscaleGBCPals

Grayscales colors stored in memory, and stores the new colors into memory. Uses a color stored in 15-bit Gameboy Color format.

Input

B

Number of colors to invert

DE

Pointer to input colors.

HL

Pointer to output colors. (may be the same as DE)


Map Functions
RGBG_SetTileMap, RGBG_FillTileMap, RGBG_SetTile, RGBG_XYToTileMap

RGBG_SetTileMap

Sets an area of a tilemap in VRAM based on a map in memory.

Input

BC

Pointer to source tilemap

H

Y-coordinate of upper left corner of the area to set in VRAM

L

X-coordinate of upper left corner of the area to set in VRAM

D

Height of area in VRAM to set

E

Width of area in VRAM to set

[RGBG_tilemap]

High byte of the destination tilemap ($98 or $9C)

[RGBG_map_offset]

Added to each byte of the source tilemap before it is copied to VRAM


RGBG_FillTileMap

Fills an area of a tilemap in VRAM with a given value.

Input

B

Tile to fill the area of the map with.

H

Y-coordinate of upper left corner of the area to set in VRAM

L

X-coordinate of upper left corner of the area to set in VRAM

D

Height of area in VRAM to set

E

Width of area in VRAM to set

[RGBG_tilemap]

High byte of the destination tilemap ($98 or $9C)


RGBG_SetTile

Set a single location in a tilemap in VRAM to a given value.

Input

A

Value to set the location in VRAM to

H

Y-coordinate of the location in VRAM

L

X-coordinate of the location in VRAM

[RGBG_tilemap]

High byte of the destination tilemap ($98 or $9C)


RGBG_XYToTileMap

Creates a pointer to a given location in a tilemap in VRAM.

Input

H

Y-coordinate of the location in VRAM

L

X-coordinate of the location in VRAM

[RGBG_tilemap]

High byte of the destination tilemap ($98 or $9C)

Output

HL

Points to the location in VRAM


Sprite Functions
RGBG_SetSpriteTile, RGBG_SetSpriteProp, RGBG_SetSpritePos, RGBG_GetSpriteTile, RGBG_GetSpriteProp, RGBG_GetSpritePos, RGBG_MoveSprite, RGBG_CopyDMARoutine, RGBG_DoDMA, RGBG_ZeroOAM

RGBG_SetSpriteTile

Sets which tile is used for a given sprite in RGBG's echo OAM.

Input

A

Which sprite to affect

B

New tile number for the sprite

Output

[RGBG_update_sprites]

TRUE (non-zero number)


RGBG_SetSpriteProp

Set the property byte for a given sprite in RGBG's echo OAM.

Input

A

Which sprite to affect

B

New property byte for the sprite

Output

[RGBG_update_sprites]

TRUE (non-zero number)


RGBG_SetSpritePos

Set the postition of a given sprite in RGBG's echo OAM.

Input

A

Which sprite to affect

B

New X-coordinate for the sprite

C

New Y-coordinate for the sprite

Output

[RGBG_update_sprites]

TRUE (non-zero number)


RGBG_GetSpriteTile

Returns the tile number used by a given sprite in RGBG's echo OAM.

Input

A

Which sprite to obtain tile number from

Output

A

Tile number used by the sprite


RGBG_GetSpriteProp

Returns the property byte for a given sprite in RGBG's echo OAM.

Input

A

Which sprite to obtain the property byte from

Output

A

Property byte used by the sprite


RGBG_GetSpritePos

Retutrns the postition of a given sprite in RGBG's echo OAM.

Input

A

Which sprite to affect

Output

B

X-coordinate of the sprite

C

Y-coordinate of the sprite


RGBG_MoveSprite

Moves a sprite in RGBDS's echjo OAM based on a signed X and Y delta.

Input

A

Which sprite to affect

B

X-Delta

C

Y-Delta


RGBG_CopyDMARoutine

Copies RGBG's sprite DMA routine into a reserved space (16 bytes) in high RAM.

Input

none

no input


RGBG_DoDMA

Copies the data from RGBG's OAM echo into the real OAM. If this functions is called before RGBG_CopyDMARoutine, your ROM will almost certainly crash. Interupts must be disabled when you call this function. It is recomended you call this function from the vertical blank interupt

Input

none

no input

Output

[RGBG_update_sprites]

FALSE (0)


Example Code

SECTION "VBL_INT", HOME[$0040]
vbl_int::
	push AF

;update our sprites if need be
	ld A,[RGBG_update_sprites]
	and A
	jp z, .bail
	call RGBG_DoDMA
	
.bail	pop AF
	reti

RGBG_ZeroOAM

Fill's RGBG's echo OAM with 0's.

Input

none

no input


Fade Functions
RGBG_MakeDarker, RGBG_MakeLighter, RGBG_SimpleFadeOut, RGBG_InitComplexFadeBkg, RGBG_RunComplexFadeStepBkg, RGBG_DecodeComplexFadePalsBkg, RGBG_UpdateComplexFadePalsBkg, RGBG_InitComplexFadeObj, RGBG_RunComplexFadeStepObj, RGBG_DecodeComplexFadePalsObj, RGBG_UpdateComplexFadePalsObj, RGBG_RunComplexFadeBkg, RGBG_RunComplexFadeObj

RGBG_MakeDarker

Darkens (decrements) three color components (R,G,B), but does not allow any component to go below 0. Usefull for custom fade routines.

Input

H

Component #1

L

Component #2

A

Component #3

Output

H

Darkened component #1

L

Darkened component #2

A

Darkened component #3


RGBG_MakeLighter

Lightens (increments) three color components (R,G,B), but does not allow any component to go over 31. Usefull for custom fade routines.

Input

H

Component #1

L

Component #2

A

Component #3

Output

H

Lightened component #1

L

Lightened component #2

A

Lightened component #3


RGBG_SimpleFadeOut

Fades every palette (both background and sprite) to either white or black over a period of about half of a second

Input

[RGBG_fade_to_color]

RGBG_WHITE (1) to fade to white
RGBG_BLACK (0) to fade to black


RGBG_InitComplexFadeBkg

Sets up a complex fade that involves a range of Background palettes. Complex fades will fade from a range of the current palettes to a range of palettes stored in memory. Complex fades can be run in the background, while you run other tasks in the foreground. The palettes are faded over 128 steps.

Input

HL

Pointer to the palettes to fade to. Palettes ared stored in the Gameboy Color's 15-bit standard

[RGBG_first_pal_to_fade_bkg]

First palette to fade

[RGBG_pals_to_fade_bkg]

Number of palettes to fade

Output

[RGBG_fade_steps_left_bkg]

128 (it takes 128 steps to complete a complex fade)


Example Code

	ld A,0
	;start fading from the first (0th) palette
	ld [RGBG_first_pal_to_fade_bkg],A
	
	;fade 4 palettes
	ld A,4					
	ld [RGBG_pals_to_fade_bkg],A	
	
	;fade to the palettes stored at BkgFader 
	ld HL, BkgFader	
	
	;set up the fade
	call RGBG_InitComplexFadeBkg
	
.loop
.waitnvbl
	ldh a,[$41] 
	and 3
	cp 1
	jr z, .waitnvbl
	
	;we're not it VBL now, so do non-video dependant stuff

	;we can call this fuction as many times as we want
	;at a time (has no effect if the fade is done)
	call RGBG_RunComplexFadeStepBkg
	call RGBG_RunComplexFadeStepBkg
	call RGBG_RunComplexFadeStepBkg
	
	
	;we only need to call this once fore every
	;RGBG_Upgade ComplexFadePals we plan to do
	;(we may want to skip this if [RGBG_fade_steps_left_bkg]=0)
	call RGBG_DecodeComplexFadePals
	
	;other code can be run here!
	;huzzah!
	
.waitvbl
	ldh a,[$41] 
	and 3
	cp 1
	jr nz, .waitvbl
	
	;now we're in VBL, so do video dependant stuff
	
	;(we may want to skip this if [RGBG_fade_steps_left]=0)
	call RGBG_UpdateComplexFadePalsBkg
	
	jp .loop

RGBG_RunComplexFadeStepBkg

Runs a step in the complex fade. If [RGBG_fade_steps_left_bkg] is 0, the function will bail (returns without effecting the (finished) fade). Running a fade step does not actually update the palettes, it simply updates the fade work RAM, so it can be run when VRAM is not accesable.

See code example for RGBG_InitComplexFadeBkg

Input

[RGBG_first_pal_to_fade_bkg]

First palette that's being faded

[RGBG_pals_to_fade_bkg]

Number of palettes that are being faded

Output

[RGBG_fade_steps_left_bkg]

The number of fade steps that still must be run before the fade is complete.


RGBG_DecodeComplexFadePalsBkg

Decodes the complex fade's work RAM, and translates it into a set of GameBoy Color standard 15-bit palettes. This functions does not require VRAM, and can be run when VRAM is not accesable..

See code example for RGBG_InitComplexFadeBkg

Input

[RGBG_first_pal_to_fade_bkg]

First palette that's being faded

[RGBG_pals_to_fade_bkg]

Number of palettes that are being faded


RGBG_UpdateComplexFadePalsBkg

Sets the GameBoy Color's palettes in VRAM based on the palettes decoded by RGBG_DecodeComplexFadePalsBkg. This function requires acess to VRAM, and should be run during the vertical blank period.

See code example for RGBG_InitComplexFadeBkg

Input

[RGBG_first_pal_to_fade_bkg]

First palette that's being faded

[RGBG_pals_to_fade_bkg]

Number of palettes that are being faded


RGBG_RunComplexFadeBkg

Self contained function to run a complex fade from start to finish. As this function runs 'in the foreground', the the rest of program will be paused while it is running (you may still use interupts, but I won't guarantee stability!).

Input

HL

Pointer to the palettes to fade to. Palettes ared stored in the Gameboy Color's 15-bit standard

B & C

Thus function will run 'C' many steps every 'B' vblanks (to control timing).

[RGBG_first_pal_to_fade_bkg]

First palette that's being faded

[RGBG_pals_to_fade_bkg]

Number of palettes that are being faded


Object Palette Complex Fade Functions

Each object (sprite) pallete complex fade function (complex fade functions with an 'Obj' suffix) is functionally equivalent to it background palette complex fade function (complex fade functions with an 'Bkg' suffix). The object palette fades use a seperate area in RAM, so both background and object palette fades can be run simutaneously.

See: RGBG_InitComplexFadeBkg, RGBG_RunComplexFadeStepBkg, RGBG_DecodeComplexFadePalsBkg, RGBG_UpdateComplexFadePalsBkg