Add frontend helper
This commit is contained in:
parent
765c742f08
commit
716a3dda38
7 changed files with 105 additions and 173 deletions
|
@ -15,12 +15,10 @@
|
|||
#define LCR_SETTING_RESOLUTION_Y 240
|
||||
#define LCR_SETTING_MUSIC 0
|
||||
|
||||
#define DATA_FILE_NAME "data"
|
||||
|
||||
#include "game.h"
|
||||
#include "frontend_helper.h"
|
||||
|
||||
char framebuffer[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y * 4];
|
||||
FILE *dataFile = 0;
|
||||
uint8_t buttonStates[8];
|
||||
|
||||
void LCR_drawPixel(unsigned long index, uint16_t color)
|
||||
|
@ -34,44 +32,6 @@ void LCR_drawPixel(unsigned long index, uint16_t color)
|
|||
*p = (color >> 8) & 0xf8;
|
||||
}
|
||||
|
||||
char LCR_getNextDataFileChar(void)
|
||||
{
|
||||
if (!dataFile)
|
||||
return 0;
|
||||
|
||||
int c = fgetc(dataFile);
|
||||
|
||||
if (c == EOF)
|
||||
{
|
||||
rewind(dataFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void LCR_appendDataStr(const char *str)
|
||||
{
|
||||
if (!dataFile)
|
||||
return;
|
||||
|
||||
if (str == 0 || *str == 0)
|
||||
rewind(dataFile);
|
||||
else
|
||||
{
|
||||
fclose(dataFile);
|
||||
|
||||
dataFile = fopen(DATA_FILE_NAME,"a");
|
||||
|
||||
if (dataFile)
|
||||
{
|
||||
fprintf(dataFile,"%s",str);
|
||||
fclose(dataFile);
|
||||
dataFile = fopen(DATA_FILE_NAME,"r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t LCR_keyPressed(uint8_t key)
|
||||
{
|
||||
return buttonStates[key % 8];
|
||||
|
@ -82,11 +42,6 @@ void LCR_sleep(uint16_t timeMs)
|
|||
usleep(timeMs * 1000);
|
||||
}
|
||||
|
||||
void LCR_log(const char *str)
|
||||
{
|
||||
printf("LOG: %s\n",str);
|
||||
}
|
||||
|
||||
void printHelp(void)
|
||||
{
|
||||
printf(
|
||||
|
@ -113,10 +68,7 @@ int main(int argc, char **argv)
|
|||
Display *display = XOpenDisplay(0);
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
dataFile = fopen(DATA_FILE_NAME,"r");
|
||||
|
||||
if (!dataFile)
|
||||
LCR_log("couldn't open data file");
|
||||
openDataFile();
|
||||
|
||||
Window window = XCreateSimpleWindow(display,RootWindow(display,screen),10,10,
|
||||
LCR_SETTING_RESOLUTION_X,LCR_SETTING_RESOLUTION_Y,1,
|
||||
|
@ -189,10 +141,7 @@ int main(int argc, char **argv)
|
|||
|
||||
XDestroyImage(image);
|
||||
XCloseDisplay(display);
|
||||
|
||||
if (dataFile)
|
||||
fclose(dataFile);
|
||||
|
||||
closeDataFile();
|
||||
LCR_gameEnd();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue