118 lines
2.0 KiB
C
118 lines
2.0 KiB
C
#include "test.h"
|
|
#include "string.h"
|
|
#include "graph.h"
|
|
#include "platform.h"
|
|
#include "fxlib.h"
|
|
#include "event.h"
|
|
|
|
// general debug data
|
|
int line=0;
|
|
char buf[32];
|
|
|
|
// useful macros
|
|
#define print(s) Print((unsigned char*)(s))
|
|
#define text(x, y, s) do {locate((x)+1, (y)+1); print((s));} while(0)
|
|
#define disp Graph_printVram
|
|
#define clear() Graph_fill(COLOR_WHITE)
|
|
#define debug(s, l) do {for(int i=0; i<21; i++) text(i, line, " "); text(0, line, (s)); line+=(l); if(line>=8||line<0) line=0; disp();} while(0)
|
|
|
|
// debug functions
|
|
void debugC(char c, int lf) {
|
|
buf[0]=c;
|
|
buf[1]='\0';
|
|
debug(buf, lf);
|
|
}
|
|
void debugD(int i, int lf) {
|
|
debug(itodec(i), lf);
|
|
}
|
|
void debugH(int i, int lf) {
|
|
debug(itohex(i, 8), lf);
|
|
}
|
|
void debugS(char* s, int lf) {
|
|
debug(s, lf);
|
|
}
|
|
void debugClr() {
|
|
line=0;
|
|
clear();
|
|
disp();
|
|
}
|
|
void debugLine(int l) {
|
|
if(l<0) l=0;
|
|
if(l>=8) l=8;
|
|
line=l;
|
|
}
|
|
|
|
void halt() {
|
|
unsigned int i;
|
|
while(1) GetKey(&i);
|
|
}
|
|
void pause() {
|
|
unsigned int i=0;
|
|
while(i!=KEY_CTRL_EXE) GetKey(&i);
|
|
}
|
|
|
|
// file test
|
|
int testFile() {
|
|
Platform_init();
|
|
|
|
// test file opening
|
|
debugClr();
|
|
debugS("Open", 1);
|
|
int fd=File_open("test.bin", FILE_OPEN_read|FILE_OPEN_write);
|
|
debugS("OK", 1);
|
|
debugD(fd, 1);
|
|
pause();
|
|
if(fd<0) return 1;
|
|
|
|
// test file read
|
|
debugClr();
|
|
debugS("Read", 1);
|
|
char buf[64];
|
|
int len=File_read(fd, 0, &buf, 64);
|
|
debugS("OK", 1);
|
|
debugD(len, 1);
|
|
pause();
|
|
if(len!=64) {
|
|
File_close(fd);
|
|
return 2;
|
|
}
|
|
|
|
debugClr();
|
|
debugS("Quit", 1);
|
|
Platform_quit();
|
|
debugS("OK", 1);
|
|
pause();
|
|
|
|
return 0;
|
|
}
|
|
|
|
// event test
|
|
int testEvt() {
|
|
Platform_init();
|
|
|
|
Graph_fill(COLOR_WHITE);
|
|
disp();
|
|
|
|
Event_clean();
|
|
event_t evt;
|
|
int count=0;
|
|
while(1) {
|
|
if(!Event_wait(&evt)) break;
|
|
debugClr();
|
|
debugD(count++, 1);
|
|
debugD(evt.type, 1);
|
|
debugD(evt.subtype, 1);
|
|
if(evt.type==EVENT_TYPE_KEYBOARD) {
|
|
debugD(evt.keyevent.repeat, 1);
|
|
debugD(evt.keyevent.code, 1);
|
|
} else if(evt.type==EVENT_TYPE_TIMER) {
|
|
debugD(evt.timerevent.code, 1);
|
|
}
|
|
}
|
|
debugClr();
|
|
debugS("Aborted", 1);
|
|
pause();
|
|
|
|
Platform_quit();
|
|
}
|