void gp_setCpuspeed ( int freq )
Set CPU speed in MHz
int freq Set CPU speed in MHz
[22,33,40,50,66,100,133,144,156,160,166]
RETURNS nothing
INFO:
Before you do anything else, first set the CPU speed.
short gp_initFramebuffer ( void *addr, u16 bitmode, u16 refreshrate )
Init the Screen with a Framebuffer.
For gp32(non light), gp32 FLU, old BLU
void *addr Framebuffer start
u16 bitmode [8]=256 Colors
[16]=True Color
u16 refreshrate [50-120], Refreshrate of TFT screen in Hz
RETURNS The real set Refreshrate.
INFO:
The gp32 offers a 240x320 LCD Display.
Cabable of 8 and 16Bit Color mode.
In 16Bit True Color the Screen is organized in 16 Bit.
This means every Point (X) on the Screen is 16Bit long (2 Byte)
In 8 Bit palette mode the Screen is organized in 8 Bit.
This means every Point (X) on the Screen is 8Bit long (1 Byte)
..0:XXXXXXXXXXXXXXXXXXXX..........XXX:239
240:XXXXXXXXXXXXXXXXXXXX..........XXX:479
480:XXXXXXXXXXXXXXXXXXXX..........XXX:719
and this 320 times
The 16 Bit represent the color of one point.
5Bit are Red, 5Bit are Green, 5Bit are Blue
1Bit is nothing ( Intensity in 8 Bit mode )
.BIT15.......BIT0
%RRRRRGGGGGBBBBB0
If you want to set the color Red, your color mask is:
%1111 1000 0000 0000 = 0xF800
short gp_initFramebufferBP ( void *addr, u16 bitmode, u16 refreshrate )
Init the Screen with a Framebuffer.
Use this function if you have a "faulty" BLU+, and suffer from strange
screen Problems.
void *addr Framebuffer start
u16 bitmode [8]=256 Colors
[16]=True
Color
u16 refreshrate [50-120], Refreshrate of TFT
screen in Hz
RETURNS The real set Refreshrate.
void gp_setPalette ( u8 pos, u16 color )
Set Palette in 8Bit Mode
u8 pos [0-255] Select Palette color to change
u16 color 16Bit color
RETURNS nothing
INFO:
Allows you to set the color palette. You can choose a palette register, and fill it with the color.
If you are using the 8 bit colormode, you need a palette first.
In 8 Bit colormode, every char is one point. This means that the framebuffer is now 240x320x8Bit = 76800 Bytes
The Palette format is : %RRRRRGGGGGBBBBBI (5551)
I : Intensity Bit 1=on 0=off ( always put it on )
C-EXAMPLE:
// One Pointer to the Screen.
u8 *framebuffer;
// Set pointer to the framebuffer
framebuffer = (u8*) FRAMEBUFFER; // 0x0C7B4000
// Init the screen in 8Bit mode
gp_setCpuspeed(50);
gp_initFramebuffer(framebuffer,8,120);
// Set palette color 0, Red
gp_setPalette(0,0xf800+1); // Red +1 is the intensity bit
// Set palette color 1, Green
gp_setPalette(1,(0xf800>>5)+1); // Green
// Fill the screen with the color Green
for (x=0 ;x<240*320;x++) framebuffer[x]=1; // Palette color 1
void gp_setFramebuffer ( void *addr, int vsync )
Allows you to set the virtual Start address of the Screen.
void *addr Framebuffer start
int vsync [1]: wait for vsync
[0]: do not wait
RETURNS nothing
INFO:
Allows you to set the virtual Start address of the Screen.
This is useful for Scrolling the screen, without copying any Byte of data.
void gp_drawPixel16 ( int x, int y, u16 color, u16 *framebuffer )
SetPixel TrueColor
int x x position on screen [0-319]
int y y position on screen [0-239]
u16 color color of the pixel. ( 16Bit )
u16 *framebuffer pointer to the screenbuffer we are painting to
RETURNS nothing
C-EXAMPLE:
// One Pointer to the Screen.
u16 *framebuffer1;
Set the Pointer to the Screen ( is defined at gp32.h )
framebuffer1 = (u16*) FRAMEBUFFER;
// Init the Screen in 16Bit mode.
gp_setCpuspeed(66);
gp_initFramebuffer(framebuffer1,16,85)
// Put one Pixel to the screen.
gp_drawPixel16( 100, 50, 0xF800, framebuffer1 );
// Remember: 0xF800 = RED
void gp_drawPixel8 ( int x, int y, u8 color, u8 *framebuffer )
SetPixel in 8Bit mode (256 Color mode)
int x x position on screen [0-319]
int y y position on screen [0-239]
u8 color Number of palette color [0-255]
u8 *framebuffer pointer to the framebuffer we are painting to
RETURNS nothing
C-EXAMPLE:
// One Pointer to the Screen.
u8 *framebuffer;
Set the Pointer to the Screen ( is defined at gp32.h )
framebuffer = (u8*) FRAMEBUFFER;
// Init the Screen in 8Bit mode (256 Colors).
gp_setCpuspeed(50);
gp_initFramebuffer(framebuffer,8,120);
// Set palette color 0 to RED
gp_setPalette(0,0xf800);
// Set palette color 1 to GREEN
gp_setPalette(1,0xf800>>5);
// Put one Pixel to the screen. ( RED )
gp_drawPixel8( 100, 50, 0, framebuffer );
// Put one Pixel to the screen. ( GREEN )
gp_drawPixel8 ( 100, 55, 1, framebuffer );
void gp_clearFramebuffer16 ( u16 *framebuffer, u16 color )
Fast screenclear in Truecolormode (16 Bit)
u16 *framebuffer pointer to the framebuffer we are painting to
u16 color color of the pixel. ( one short )
RETURNS nothing
INFO:
This Functions allows you, to clear the framebuffer with a given
color. This function is 100% assembler written, and very fast.
C-EXAMPLE:
// One Pointer to the Screen.
u16 *framebuffer1;
//Set the Pointer to the Screen ( is defined at gp32.h )
framebuffer1 = (u16*) FRAMEBUFFER;
// Init the Screen in 16Bit mode.
gp_setCpuspeed(40);
gp_initFramebuffer(framebuffer1,16,85);
// Clear the Screen with the color black
gp_clearFramebuffer16( framebuffer1, 0x0000 );
void gp_drawLine16 ( int x0, int y0, int x1, int y1, u16 color, u16 *framebuffer )
Drawing a line in Truecolormode (16 Bit)
int x0 x-point0 [0-319]
int y0 y-point0 [0-239]
int x1 x-point1 [0-319]
int y1 y-point1 [0-239]
u16 color color of the pixel. ( one short )
u16 *framebuffer pointer to the framebuffer we are painting to
RETURNS nothing
INFO:
This Functions allows you, to draw a Line from point 0 to point 1
given by x0,y0,x1,y1 coordinates.
C-EXAMPLE:
// One Pointer to the Screen.
u16 *framebuffer1;
//Set the Pointer to the Screen ( is defined at gp32.h )
framebuffer1 = (u16*) FRAMEBUFFER;
// Init the Screen in 16Bit mode.
gp_setCpuspeed(40);
gp_initFramebuffer(framebuffer1,16,85);
// draw a Line from 10,10 to 200,200 in the color 0xf800
gp_drawLine16(10, 10, 200, 200, 0xf800, framebuffer1);
u16 gp_getButton( )
Get the status of the 7 gp32 buttons
RETURNS u16 Bitmask of pressed Buttons
INFO:
There are 7 Buttons on your gp32, and every Press, results in a Bitmask.
The buttons are defined as followed:
BUTTON_LEFT.....KEYPAD LEFT
BUTTON_DOWN.....KEYPAD DOWN
BUTTON_RIGHT....KEYPAD RIGHT
BUTTON_UP.......KEYPAD UP
BUTTON_L........Button L
BUTTON_B........Button B
BUTTON_A........Button A
BUTTON_R........Button R
BUTTON_START....Button START
BUTTON_SELECT...Button SELECT
C-EXAMPLE:
// Init the Button sub-system
// gp_ButtonInit() -> obsolete
// Get the current status of the buttons
if ( gp_getButton() & BUTTON_RIGHT )..// Keypad right pressed
if ( gp_getButton() & BUTTON_LEFT )...// Keypad left pressed
if ( gp_getButton() & BUTTON_UP ).....// Keypad up pressed
if ( gp_getButton() & BUTTON_DOWN )...// Keypad down pressed
void gp_Reset()
RESET the gp32
RETURNS nothing
INFO:
Sets the CPU speed to 66Mhz, and RESET the gp32.
void gp_setMMU(u32 mempos_start,u32 mempos_end,int mode)
CPU/Memory control ( MMU setting )
u32 mempos_start start address of the memory region
you want the MMU changes to affect
u32 mempos_end end address of the memory region
you want the MMU changes to affect
u32 flags This value is ORed to the second level MMU page table descriptor
Only the low 12 bits are used
0xFF2 - to disable cache and writeback
0xFFA - to enable cache and disable writeback
0xFFE - to enable cache and writeback
RETURNS nothing
INFO:
This function allows you to Set the Memory mode for a region of memory
NOTE:
Keep in mind that the granularity of MMU pages is 4KB, which means
that the addresses you feed into the BIOS call must 4KB aligned addresses.
If you are using sound, the framebuffer must be (sometimes) in 0xFF2 mode
void gp_setDMA ( u32 source, u32 destination, u32 size, u8 channel )
void gp_waitDMA( u8 channel )
CPU/Memory control ( DMA copy )
u32 source source address
u32 destination destination address
u32 size number of shorts you want to copy
keep in mind, one short is 2 Bytes
u8 channel [0-3] is the DMA channel
if you use sound, you can only use 0 and 1
RETURNS nothing
INFO:
This is the DMA memory copy function. It allows you to copy one
memory region to another, without using the cpu.
gp_setDMA returns directly, and copys the memory in background.
( multitasking )
If you are using two gp_setDMA(0) in a row, the second gp_setDMA(0)
waits on the first to finish, then the second DMA starts.
gp_waitDMA(0) wait on the DMA0.
C-EXAMPLE:
short *mem1;
short *mem2;
mem1 = (u16*) malloc (1024);
mem2 = (u16*) malloc (1024);
// Copy 1024 shorts = 2048 Bytes from mem1 to mem2
gp_setDMA( mem1, mem2, 1024,0 )
void gp_drawString ( int x, int y, int len, char *buffer, u16 color, u16 *framebuffer )
Draw string with a 8x8 font
int x x pos on screen [0-319]
int y y pos on screen [0-239]
int len size of buffer in bytes
char *buffer buffer of asci-text
u16 color color of the drawn string
u16 *framebuffer pointer to framebuffer
RETURNS nothing
INFO:
You can display text on the gp32 screen, by using this function.
You can use this function in 16Bit and 8Bit Mode.
C-EXAMPLE:
// 16Bit mode direct color mode
// Display the word "TeST" to the screen, at position
// (x,y) 10,10, in the color RED
gp_drawString (10,10,5,"TeST ",0xF800,framebuffer);
// In 8Bit (256 Color mode) using palette color 0
gp_drawString(50,110,23,"Text in 8Bit mode.... ",0,framebuffer);
void gp_initRTC()
int gp_getRTC()
void gp_clearRTC()
Using the Realtimeclock
gp_initRTC() start the Realtimeclock, and set it 0
int gp_getRTC() RETURNS the Realtimeclock tickcount
gp_clearRTC() set the Realtimeclock tickcount to 0 (still counting)
INFO:
Allows you to Init a RTC timer. The timer is cpuclock independent
The RTC is running in 1/64 sec mode
This means, that every second the timer is called 64 times
C-EXAMPLE:
int timer;
gp_initRTC( );
timer = gp_getRTC( );
int gp_initChatboard()
Init the Chatboard
RETURNS "1" Chatboard found
"0" Chatboard not found
INFO:
Init the Chatboard
The Chatboard is a little hardware keyboard for your gp32
char gp_getChatboard()
Get one Key from Chatboard
RETURNS "0" No key pressed
else the ascii code of the pressed key
INFO:
Get one Key from Chatboard
The Chatboard is a little hardware keyboard for your gp32
C-EXAMPLE:
int init;
char c;
init = gp_initChatboard();
if (init) {
c=gp_getChatboard();
if (get >0) { } // key pressed
}
else // No chatboard found
int smc_dir ( char *dirname, DIR *dir_list )
#include "fileio.h"
Reading Directory, and store the Filenames and Filesize to the struct *DIR
char *dirname Name of the Directory
"dev0:\\gpmm\\" for \\gpmm
DIR *dir_list A pointer to the *dir_list structure
RETURNS The number of entrys in the Dir
0 = ERROR, >0 = OK
Remember: "." and ".." are 2 entrys
INFO:
Reading Directory, and store the Filenames and Filesize to the struct *DIR
INFO:
//DIR struct
typedef struct {
char name[128][16]; // 128 entrys,16 Bytes long
int size[128];
} DIR;
C-EXAMPLE:
// Include the smc header
#include "fileio.h"
// Create memory for the dir_struct
DIR dir_struct;
// Returns: How many Files are in the Directory ?
int dir_entrys;
// Reading Directory of \\gpmm
dir_entrys=smc_dir("dev0:\\gpmm\\",&dir_struct);
and the content is stored in:
char dir_struct.name[x]
and
int dir_struct.size[x]
int smc_read ( char *filename, void *dest, int offset, int size )
#include "fileio.h"
Open a File for reading, and store the content in dest memory
char *filename name of file to open
"dev0:\\GPMM\\SMCTEST.FXE"
void *dest memory buffer to store the content
int offset offset in file
0=beginning of file
int size size in bytes to read
RETURNS bytes read from file
INFO:
Open a File for reading, and store the content in dest memory
C-EXAMPLE:
// Loading something to memory
char *buffer; // pointer to free memory
int offset=0; // position in file, 0=beginning
int bytes=8192; // read bytes
int bytes_read; // Returns entrys
buffer = (char*) malloc(bytes);
bytes_read=smc_read("dev0:\\gpmm\\test.fxe",buffer,offset,bytes);
if (bytes_read == 0) { } // ERROR
if (bytes_read == 8192) { } // OK
}
int smc_write ( char *filename, void *dest, int size )
#include "fileio.h"
Create File and write size bytes to it
char *filename name of file to write to
"dev0:\\GPMM\\test.txt"
void *dest memory buffer with stored data
int size size in bytes to write
RETURNS nothing
INFO:
Allows you to create a File, and write size bytes to it.
If the File exists it will be overwritten.
C-EXAMPLE:
// Creating and writing to smc
char buffer[64]="DELETE ME iam a Test... ";
smc_write("dev0:\\delete.me",(char*)buffer,25);
int smc_createdir ( char *pathname )
#include "fileio.h"
Create a Directory
char *pathname name of the directory
"dev0:\\GPMM\\TESTDIR"
RETURNS "0" on error, "1" on success
INFO:
Allows you to create a empty Directory
SMC INFORMATION:
INFO:
Instead of the 3 smc functions, you can use the following stdio functions:
GPFILE *smc_fopen(const char *path, const char *mode); //supported mode "r" and "w"
size_t smc_fread(void *ptr, size_t size, size_t nmemb, GPFILE *stream);
size_t smc_fwrite(void *ptr, size_t size, size_t nmemb, GPFILE *stream);
int smc_fclose(GPFILE *stream);
int smc_fseek(GPFILE *stream, long offset, int whence);
long smc_ftell(GPFILE *stream);
void smc_rewind(GPFILE *stream);
int smc_filesize(GPFILE *stream);
C-EXAMPLE:
#include "fileio.h"
char buffer[255];
int err,size;
// create gpfile pointer
GPFILE *gpfile;
// open file "dev0:\\gpmm\\filetest.dat" for reading
gpfile = smc_fopen("dev0:\\gpmm\\filetest.dat","r");
// get filesize
size = smc_filesize(gpfile);
// read 12 bytes
err = smc_fread(buffer, 12, 1, gpfile);
// get current pos in stream ( should be 12 now )
err = smc_ftell(gpfile);
// seek to byte 20 in stream
smc_fseek(gpfile, 20,SEEK_SET);
// close stream
smc_fclose(gpfile);
int gp_zda_headersize(char *zdadata)
Get headersize of zda container
char *zdadata pointer to the first 12 Byte of zda container file
RETURNS complete size of zda header
INFO:
Get headersize of zda container
int gp_zda_csize(char *zdadata, char *filename)
Get compressed size of a file in zda container
char *zdadata pointer to the complete zda header
char *filename filename of file inside zda container
RETURNS compressed size of file
INFO:
Get compressed size of a file in zda container
int gp_zda_usize(char *zdadata, char *filename)
Get uncompressed size of a file in zda container
char *zdadata pointer to the complete zda header
char *filename filename of file inside zda container
RETURNS uncompressed size of file
INFO:
Get uncompressed size of a file in zda container
int gp_zda_offset(char *zdadata, char *filename)
Get offset of file in zda container
char *zdadata pointer to the complete zda header
char *filename filename of file inside zda container
RETURNS offset to compressed data
counting from file_start
INFO:
Get offset of file in zda container
The zda file container is a simple container to store files compressed
in one container file. You can simply create a zda container file with
./zcontainer file1 file2 file3 ...
It will create a zda file, with all files compressed in it. You dont need
to know anything about the structure of this file. The above gp_zda_
functions will handle this.
C-EXAMPLE:
char header_12bytes[12]; // The ZDA header is always 12 Bytes big
char *full_header; // The full headersize depend on content
char *compressed;
char *uncompressed;
int real_headersize;
int usize,csize,offset,err;
smc_read("dev0:\\GPMM\\datah.zda",header_12bytes,0,12); // read in the 12 bytes header.
real_headersize=gp_zda_headersize(header_12bytes); // calculate the real headersize
full_header = (char*) malloc(real_headersize); // malloc space for full header
smc_read("dev0:\\GPMM\\datah.zda",full_header,0,real_headersize); // read in the full header
csize = gp_zda_csize (full_header, "README.TXT"); // get compressed.. size of file README.TXT
usize = gp_zda_usize (full_header, "README.TXT"); // get uncompressed size of file README.TXT
offset= gp_zda_offset(full_header, "README.TXT"); // get the offset for file README.TXT, counting from file beginning
compressed = (char*) malloc(csize); // temp buffer for compressed file
uncompressed = (char*) malloc(usize); // buffer for uncompressed data
err=smc_read("dev0:\\GPMM\\datah.zda",compressed,offset,csize); // read in the compressed data
gp_drawString(10,100,26,"Uncompressing file ... ",0xF800,framebuffer1);
err = gp_uncompressZDA( (u8*)uncompressed, &usize, (u8*)compressed, csize ); // uncompress compressed data with size csize
if (err == 0) gp_drawString(10,110,20,uncompressed,0xF800,framebuffer1);
if (err == 1) gp_drawString(10,110, 6,"ERROR ",0xF800,framebuffer1);
// free all memory
free (full_header);
free (compressed);
free (uncompressed);
void gp_startSoundmixer( int finetuning )
Start the gp32 soundsystem / realtimemixer
int finetuning [0]: normal mode
[1]: faster mode (will not work on all Clockrates)
RETURNS nothing
INFO:
Starts the realtime mixer, this mixer can mix modfiles and samples
in realtime, and in background. Its not 100% finished. It will
later allow you: up and down sample samples in realtime.
So you can playback a 11025 Mono, and a 22050 Stereo sample
at the same time.
Current State:
The mixer/soundsystem is running in 22050Hz Stereo, and can mix
22050Hz Mono and
22050Hz Stereo Samples
void gp_stopSoundmixer()
Stop the realtimemixer (removes timer and irq)
RETURNS nothing
INFO:
Removes the realtimemixer, and stops sound output.
void gp_addSample( u16 *data, u16 freq, u16 stereo, u8 volume, u32 size )
Play a sample trough realtimemixer
u16 *data samplebuffer data
u16 freq samplefreq: [11025,22050,44100]
u16 stereo [0]: mono
[1]: stereo
u8 volume [0-16]: volume of sample
[0]: normal
[16]: quietly
u32 size size of sampledata in bytes
RETURNS nothing
INFO:
Playback a sample trough timer based mixer
C-EXAMPLE:
extern unsigned char sample1[]; // 202232 Bytes, Stereo, 22050Khz, 16Bit
gp_setCpuspeed(66); // Make shure you first set the cpu speed
gp_startSoundmixer(0); // and then init the sound.
gp_addSample( sample, 22050, 1, 0, 202232 );
Current State:
You can use 22050Hz,16Bit, Mono and Stereo samples, volume is not working yet.
void gp_startModfile( char *mod )
Start amiga modfile in background ( timer based )
char *mod modfile data
RETURNS nothing
INFO:
Playback of an Amiga modfile
C-EXAMPLE:
extern unsigned char modfile[];
gp_setCpuspeed(33); // works in all clockrates, clickfree
gp_startSoundmixer(0); // The modrenderer works at 22050 khz
gp_startModfile(modfile); // adds mod to mixer
void gp_pauseModfile()
void gp_resumeModfile()
Pause and resume a modfile
RETURNS nothing
INFO:
gp_pauseModfile() set a playing modfile to pause
gp_resumeModfile() resume modfile playback at the position you paused it
void gp_drawSprite ( u16 *sprite, short put_x, short put_y, u16 *framebuffer, u16 xsize, u16 ysize )
void gp_drawSpriteT( u16 *sprite, short put_x, short put_y, u16 *framebuffer, u16 trans, u16 xsize, u16 ysize )
Draw a sprite in normal or transparent mode
u16 *sprite sprite raw data 16bit
short put_x [0-319] x-pos on screen
short put_y [0-239] y-pos on screen
u16 *framebuffer pointer to the framebuffer we are painting to
u16 trans transparent color, 16bit
u16 xsize x-size of sprite in pixel
u16 ysize y-size of sprite in pixel
RETURNS nothing
INFO:
Draw a raw data sprite to the framebuffer
Transparent means, that this color of the sprite is not drawn to the screen.
So this color is transparent, and you can see the background at this point.
C-EXAMPLE:
Have a look to example.sprite
void gp_drawSpriteH ( u16 *sprite, short put_x, short put_y, u16 *framebuffer )
void gp_drawSpriteHT ( u16 *sprite, short put_x, short put_y, u16 *framebuffer, u16 trans )
void gp_drawSpriteHTB( u16 *sprite, short put_x, short put_y, u16 *framebuffer, u16 trans,u8 alpha )
Draw a sprite with header, alphablending, transparent
u16 *sprite sprite data created with: bmp2bin -x
always use the included bmp2bin
short put_x [0-319] x-pos on screen
short put_y [0-239] y-pos on screen
u16 *framebuffer pointer to the framebuffer we are painting to
u16 trans transparent color, 16bit
u8 alpha [0-31]: alphablending of sprite
[0]: sprite is not visible
[15]: 50% background,50% sprite
[31]: Sprite full visible
RETURNS nothing
INFO:
Draw sprites with headers, in the header is the x and y size stored.
You can create a sprite with heder, by using: bmp2raw -x
Transparent means, that this color of the sprite is not drawn to the screen.
So this color is transparent, and you can see the background at this point.
Alphablending means, that you can mix the background and the spritedate.
C-EXAMPLE:
Have a look to example.sprite
void gp_drawTiled16 (u16 *sprite_data, u16 trans, u16 x_len, u16 plot_number, s16 plot_x, s16 plot_y, u16 *framebuffer)
Draw one Element from a tiled sprite
u16 *sprite sprite data with header, 16bit, of your tiled grafik
u16 trans transparent color, not drawn
u16 x_len the x_size (in points) of one Element in youre tiled sprite
u16 plot_number display which tiled element ?
s16 plot_x [0-319] x pos on tft-screen
s16 plot_y [0-239] y pos on tft-screen
u16 *framebuffer framebuffer we are painting to
RETURNS nothing
INFO:
Draw one element from a tiled sprite with header, to screen
Transparent means, that this color of the sprite is not drawn to the screen.
So this color is transparent, and you can see the background at this point.
To understand the tiled sprite system, have a look to the example sprites.
C-EXAMPLE:
Have a look to example.tiled