Voilà par exemple le
_main de la démo 1:
void _main(void) {
unsigned short key = 0;
unsigned char* bg_img = NULL;
short i,j;
unsigned short* dest;
TEXCONFIG textures[2];
unsigned short (*GetPossibleKeys)(void); // will hold key function of calctype
LCD_BUFFER lcd;
short oldfont = FontGetSys(); // used to restore previously set font
LCD_save(lcd);
FATCONFIG fc = {
MAP_WIDTH,
MAP_HEIGHT,
map,
textures,
0, // number of sprites
NULL, // the sprite array
96, // start pos_x
96, // start pos_y
0, // orientation
NULL, // destination plane0
NULL, // destination plane1
NULL, // background image
0 // frame counter
};
//-------------------------------------------------------------------------
// allocate space for a background image and fill the lower part of the
// light plane with 0xff to simulate a floor ...
//-------------------------------------------------------------------------
if (!(bg_img = (unsigned char*)malloc(1152*2))) {
ST_helpMsg("ERROR: out of mem")
return;
}
memset(bg_img,0x00,1152*2);
dest = (unsigned short*)bg_img;
for (i=0;i<6;i++) {
for (j=0;j<48;j++) *dest++ = 0x0000;
for (j=0;j<48;j++) *dest++ = 0xffff;
}
fc.background = (unsigned short*)bg_img;
InstallDummyHandlerForINTs();
//-------------------------------------------------------------------------
// initialize grayscales, clear both planes and set the destination plane
// addresses for the FAT-Engine
//-------------------------------------------------------------------------
if (!GrayMode(GRAY_ON)) {
free(bg_img);
RestoreHandlerForINTs();
ST_helpMsg("ERROR: out of mem")
return;
}
memset(GetPlane(0),0,LCD_SIZE);
memset(GetPlane(1),0,LCD_SIZE);
fc.dest_plane0 = GetPlane(0);
fc.dest_plane1 = GetPlane(1);
if (TI89) {
display_offsetx = 0;
display_offsety = 0;
GetPossibleKeys = GetPossibleKeys89;
}
else {
// TI92p or V200
display_offsetx = 40;
display_offsety = 14;
fc.dest_plane0 += (14*30+4)/2;
fc.dest_plane1 += (14*30+4)/2;
GetPossibleKeys = GetPossibleKeys92p;
}
//-------------------------------------------------------------------------
// initialize the FAT-Engine and output a simple title text
//-------------------------------------------------------------------------
if (FAT_LoadEngine() != FAT_LOADOKAY) {
GrayMode(GRAY_OFF);
free(bg_img);
RestoreHandlerForINTs();
LCD_restore(lcd);
ST_helpMsg("ERROR: cannot load engine")
return;
}
FontSetSys(F_4x6);
OutputTitle();
//-------------------------------------------------------------------------
// fill TEXCONFIG structures
//-------------------------------------------------------------------------
ConvertGRAYToTEXCONFIG(houses,textures);
ConvertGRAYToTEXCONFIG(houses+512,&textures[1]);
//-------------------------------------------------------------------------
// the main rendering loop ...
//-------------------------------------------------------------------------
do {
FAT_Render(&fc); // render image
frame_drawn(&fc); // handles frame counter drawing
if ((key = GetPossibleKeys())) {
if (key & KEYFLAGS_ESC) break;
if (key & KEYFLAGS_UP) PlayerMove(&fc,1);
if (key & KEYFLAGS_DOWN) PlayerMove(&fc,0);
if (key & KEYFLAGS_RIGHT) PlayerTurn(&fc,1);
if (key & KEYFLAGS_LEFT) PlayerTurn(&fc,0);
}
}
while(1);
//-------------------------------------------------------------------------
// some clean stuff ...
//-------------------------------------------------------------------------
FontSetSys(oldfont);
WaitTillAllKeysReleased();
GrayMode(GRAY_OFF);
free(bg_img);
LCD_restore(lcd);
ST_helpMsg(FAT_GetPoweredByString());
FAT_UnloadEngine();
RestoreHandlerForINTs();
OSqclear(kbd_queue());
}