diff --git a/Makefile b/Makefile index e83d0e3..e30c8c6 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: CFRIDGE CFRIDGE: *.c *.h *.s - cl65 -C apple2.cfg -t apple2enh -o CFRIDGE *.c *.s + cl65 -C apple2-tgi.cfg -t apple2enh -o CFRIDGE *.c *.s clean: -rm *.o CFRIDGE diff --git a/a2e.hi.tgi b/a2e.hi.tgi new file mode 100644 index 0000000..eee1e64 Binary files /dev/null and b/a2e.hi.tgi differ diff --git a/apple2-tgi.cfg b/apple2-tgi.cfg new file mode 100644 index 0000000..68dfe4c --- /dev/null +++ b/apple2-tgi.cfg @@ -0,0 +1,39 @@ +FEATURES { + STARTADDRESS: default = $4000; +} +MEMORY { + ZP: start = $0080, size = $001A, define = yes; + HEADER: start = $0000, size = $0004, file = ""; + RAM: start = $4000, size = $7600, file = %O; +} +SEGMENTS { + EXEHDR: load = HEADER, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, optional = yes; + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = ro; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + HEAP: load = RAM, type = bss, optional = yes; # must sit just below stack + ZEROPAGE: load = ZP, type = zp; +} +FEATURES { + CONDES: segment = INIT, + type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__; + CONDES: segment = RODATA, + type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__; + CONDES: type = interruptor, + segment = RODATA, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__; +} +SYMBOLS { + __STACKSIZE__ = $800; # 2K stack +} + + diff --git a/main.c b/main.c index 51fbd28..1acba5b 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include "ow.h" #include "ow-temp.h" #include "ow-time.h" @@ -11,6 +14,7 @@ COMP_STATUS compressor_status; unsigned char* tempsensor=NULL; unsigned char* clockdev=NULL; +unsigned char tempsamples[280]; int main (void) { @@ -24,6 +28,17 @@ int main (void) time_t shutoff=0; unsigned char cmd; time_t gototime=0; + time_t lastupdate=0; + + for (i=0; i<280; i++) + tempsamples[i]=70; + + tgi_load(TGI_MODE_280_192_6); + if (tgi_geterror()!=TGI_ERR_OK) + { + printf("tgi_load() failed\n"); + exit(EXIT_FAILURE); + } devcount=ow_enumeratedevices(devs, 10); @@ -59,17 +74,24 @@ int main (void) clrscr(); } + tgi_init(); // turn on Hi-Res mode + POKE(-16301,0); // make it split-screen + drawgraph(70); + if (tgi_geterror()!=TGI_ERR_OK) + { + printf("tgi_init() failed\n"); + exit(EXIT_FAILURE); + } relayctrl(0); - gotoxy(25,0); + gotoxy(25,20); printf("off "); - gotoxy(0,2); do { do { t=ow_time_read(clockdev); currtemp=ow_temp_read(tempsensor, OW_TEMP_FAHRENHEIT); - gotoxy(0,0); + gotoxy(0,20); printf("curr=%i set=%i goto=%i \n", currtemp, setpoint, @@ -83,30 +105,35 @@ int main (void) intime.tm_min, intime.tm_sec); printf(" \n"); + if (t>lastupdate+60) + { + lastupdate=t; + drawgraph(currtemp); + } gotoy(wherey()-1); if (currtemp>=setpoint+2 && compressor_status==COMP_OFF) { if (t-shutoff>300) { relayctrl(1); - gotoxy(25,0); + gotoxy(25,20); printf("on "); - gotoxy(0,2); + gotoxy(0,22); } else { - gotoxy(25,0); + gotoxy(25,20); printf("wait"); - gotoxy(0,2); + gotoxy(0,22); } } if (currtemp<=setpoint-2 && compressor_status==COMP_ON) { relayctrl(0); shutoff=t; - gotoxy(25,0); + gotoxy(25,20); printf("off "); - gotoxy(0,2); + gotoxy(0,22); } if (t>=gototime && gotopoint!=setpoint) { @@ -244,3 +271,41 @@ void relayctrl(unsigned char on) compressor_status=(on)?COMP_ON:COMP_OFF; return; } + +void drawgraph(unsigned char newsample) +{ + unsigned int x, y; + char mkr[3]="00"; + + tgi_setcolor(0); + tgi_setpixel(0,yscale(tempsamples[0])); + tgi_gotoxy(0,yscale(tempsamples[0])); + for (x=1; x<280; x++) + { + tgi_lineto(x,yscale(tempsamples[x])); + tempsamples[x-1]=tempsamples[x]; + } + tempsamples[279]=newsample; + for (y=30; y<=90; y+=10) + { + tgi_setcolor(1); + tgi_line(14,yscale(y),279,yscale(y)); + tgi_setcolor(3); + mkr[0]=48+(y/10); + tgi_outtextxy(0,yscale(y)-4,mkr); + } + tgi_setpixel(0,yscale(tempsamples[0])); + tgi_gotoxy(0,yscale(tempsamples[0])); + for (x=1; x<280; x++) + tgi_lineto(x,yscale(tempsamples[x])); +} + +int yscale(int y) +{ + if (y>90) // clamp to within range + y=90; + if (y<30) + y=30; + return 5+(90-y)*5/2; +} + diff --git a/main.h b/main.h index ee93f45..e6239ee 100644 --- a/main.h +++ b/main.h @@ -8,5 +8,7 @@ int readYN(); int readnum(int defval, unsigned char timeout); void backup(); void relayctrl(unsigned char on); +void drawgraph(unsigned char newsample); +int yscale(int y); #endif // _MAIN_H