The code:
Code: Select all
// Includes
#include <sys/types.h>
#include <libapi.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <libcd.h>
#include <stdio.h>
// Some defines
#define OT_LENGTH 8
#define PACKETMAX (2048)
#define PACKETMAX2 (PACKETMAX*24)
// Object tables
GsOT myOT[2];
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];
int ActiveOT;
// Bitmap header structure
typedef struct
{
// Entry header
char id[2];
int size;
short res1;
short res2;
int offset;
// Bitmap header
int hsize;
int width;
int height;
short planes;
short bpp;
int compression;
int imagebytes;
int xres;
int yres;
int numcolors;
int sigcolors;
} bmpheader_struct;
bmpheader_struct bmpheader;
// Prototypes
int main(void);
void Init(void);
void Display(void);
void PrepDisplay(void);
int main(void)
{
int handle;
u_char cdresult;
// Init everything
Init();
// Read some of the bitmap header
CdReadFile("cdrom:\\bm24test.bmp;1", (u_long*)&bmpheader, sizeof(bmpheader));
CdReadSync(0, &cdresult);
while (1)
{
PrepDisplay();
FntPrint("\nTest...\n");
FntPrint("cdresult=%d\n", cdresult);
FntPrint("\nHeader results:\n");
FntPrint("hchar=%d\n", bmpheader.id[0]);
FntPrint("width=%d\n", bmpheader.width);
FntPrint("height=%d\n", bmpheader.height);
Display();
}
}
void Init(void)
{
// Initialize the graphics
GsInitGraph(320, 240, GsNONINTER|GsOFSGPU, 1, 0);
GsDefDispBuff(0, 0, 0, 240);
myOT[0].length = OT_LENGTH;
myOT[1].length = OT_LENGTH;
myOT[0].org = myOT_TAG[0];
myOT[1].org = myOT_TAG[1];
GsClearOt(0, 0, &myOT[0]);
GsClearOt(0, 0, &myOT[1]);
ResetGraph(0);
SetVideoMode(MODE_NTSC);
SetGraphDebug(0);
// Clear the screens
GsSortClear(0, 0, 0, &myOT[0]);
GsSortClear(0, 0, 0, &myOT[1]);
// Initialize debug font
FntLoad(960, 256);
FntOpen(0, 0, 320, 240, 0, 512);
// Initialize the CD drive
CdInit();
}
void Display(void)
{
FntFlush(-1);
DrawSync(0);
VSync(0);
GsSwapDispBuff();
GsSortClear(0, 0, 0, &myOT[ActiveOT]);
GsDrawOt(&myOT[ActiveOT]);
}
void PrepDisplay(void)
{
ActiveOT = GsGetActiveBuff();
GsSetWorkBase((PACKET*)GPUPacketArea[ActiveOT]);
GsClearOt(0, 0, &myOT[ActiveOT]);
}