Attached in this post is a ZIP file that contains the source code, the makefile, and the test picture in RGB24 RAW format that this snipped uses.
Code:
Code: Select all
// Includes
#include <sys/types.h>
#include <memory.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)
#define CDBUFFLEN 8192 // CD data buffer length
// Setup the ordering tables
GsOT myOT[2];
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];
int ActiveOT;
// For the easy CD reading function
u_char CdBuff[CDBUFFLEN]; // Data buffer for easy CD loading
int CdBufferOffs; // Offset of the next byte to read within the buffer
int CdBytesRead; // The number of bytes read from the buffer
u_char RowBuff[7680]; // 640x4 24-bit chunk
// Bitmap header structure (failed)
/*
typedef struct
{
// Entry header
//char id[2];
short id;
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);
void CdEasyReadFile(char *filename, u_long *destptr, u_long NumBytes);
int main(void)
{
RECT RowRect = { 0, 0, 640*3/2, 4 };
u_char cdresult=0;
int vy;
// Init everything
Init();
// Read the first 4 rows of the bitmap
//CdReadFile("\\bm24test.raw;1", (u_long*)&CdBuff[0], 8192);
//CdReadSync(0, result);
CdEasyReadFile("\\bm24test.raw;1", (u_long*)&RowBuff[0], 7680);
for (vy=0; vy<479; vy=vy+4)
{
// Load the chunk into the framebuffer
RowRect.y = vy;
LoadImage(&RowRect, (u_long*)&RowBuff[0]);
DrawSync(0);
// Load more chunks
CdEasyReadFile(0, (u_long*)&RowBuff[0], 7680);
};
}
void Init(void)
{
DISPENV disp;
// Initialize the graphics
ResetGraph(0);
SetGraphDebug(0);
SetDefDispEnv(&disp, 0, 0, 640, 480);
disp.isrgb24 = 1;
PutDispEnv(&disp);
SetDispMask(1);
/*
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]);
}
void CdEasyReadFile(char *filename, u_long *destptr, u_long NumBytes)
{
int CdDestOffs=0;
int CdCopyBytes=0;
u_char CdResult=0;
/*
if (filename > 0)
{
CdBytesRead = 0;
CdBufferOffs = 0;
};
*/
while (1)
{
if (CdBytesRead <= 0)
{
CdReadFile(filename, (u_long*)&CdBuff[0], CDBUFFLEN);
CdReadSync(0, &CdResult);
CdBytesRead = CDBUFFLEN;
CdBufferOffs = 0;
};
CdCopyBytes = (NumBytes - CdDestOffs);
if ((CdDestOffs + CdCopyBytes) > CdBytesRead) CdCopyBytes = CdBytesRead;
if ((CdDestOffs + CdCopyBytes) > NumBytes) CdCopyBytes = NumBytes - CdDestOffs;
memcpy(destptr + CdDestOffs, &CdBuff[CdBufferOffs], CdCopyBytes);
CdBufferOffs = CdBufferOffs + CdCopyBytes;
CdDestOffs = CdDestOffs + CdCopyBytes;
CdBytesRead = CdBytesRead - CdCopyBytes;
if (CdDestOffs >= NumBytes) break;
};
}