This sample program loads sprite from TIM image and displays it:
#include <psx.h> #include <stdio.h> #include <stdlib.h> unsigned int prim_list[0x4000]; unsigned short padbuf; volatile int display_is_old = 1; volatile int time_counter = 0; int dbuf=0, hx=0, hy=0; GsImage tim_image; GsSprite sprite; unsigned char data_buffer[0x40000]; // 256 kilobytes void prog_vblank_handler() { display_is_old = 1; time_counter++; } int main() { PSX_Init(); GsInit(); GsSetList(prim_list); GsClearMem(); GsSetVideoMode(320, 240, EXAMPLES_VMODE); SetVBlankHandler(prog_vblank_handler); FILE *f = fopen("cdrom:\\IMAGE.TIM;1", "rb"); fseek(f, 0, SEEK_END); int fsize = ftell(f); fseek(f, 0, SEEK_SET); fread(data_buffer, sizeof(char), fsize, f); fclose(f); GsImageFromTim(&tim_image, data_buffer); GsUploadImage(&tim_image); GsSpriteFromImage(&sprite, &tim_image, 1); sprite.x = 10; sprite.y = 10; sprite.w = 100; sprite.h = 100; sprite.r = 128; sprite.g = 128; sprite.b = 128; while(1) { if(display_is_old) { dbuf=!dbuf; GsSetDispEnvSimple(0, dbuf ? 0 : 256); GsSetDrawEnvSimple(0, dbuf ? 256 : 0, 320, 240); GsSortCls(0,0,0); GsSortSprite(&sprite); GsDrawList(); while(GsIsDrawing()); display_is_old=0; } } return 0; }
Need to say, you must have sprite image.bmp, which is just windows bitmap. And also you need to make changes into your Makefile, to produce TIM image form BMP and to place it into disc image.
Your Makefile should look like this(if your program placed in file sprite.c):
include ../Makefile.cfg all: mkdir -p cd_root psx-gcc -O3 $(CFLAGS) -DEXAMPLES_VMODE=$(EXAMPLES_VMODE) -o sprite.elf sprite.c elf2exe sprite.elf sprite.exe cp sprite.exe cd_root bmp2tim image.bmp cd_root/image.tim 16 -org=320,0 systemcnf sprite.exe > cd_root/system.cnf $(MKISOFS_COMMAND) -o sprite.hsf -V SPRITE -sysid PLAYSTATION cd_root mkpsxiso sprite.hsf sprite.bin $(CDLIC_FILE) rm -f sprite.hsf clean: rm -f sprite.bin sprite.cue sprite.exe sprite.elf rm -fr cd_root