diff --git a/io.c b/io.c index 67bc34c..a98fe68 100755 --- a/io.c +++ b/io.c @@ -1,3 +1,5 @@ +#include +#include #include "io.h" #include "protocol.h" #include "terminal.h" @@ -5,18 +7,58 @@ #define true 1 #define false 0 +#define SERIAL_BUFFER_SIZE 16000 + extern unsigned char trace_active; +extern void done(void); + +short driverIn; +short driverOut; +SerShk handshake; +Ptr serial_buffer; void io_init(void) { + if (OpenDriver("\p.AOut",&driverOut) != noErr) + done(); + if (OpenDriver("\p.AIn",&driverIn) != noErr) + done(); + + handshake.fXOn=0; + handshake.fCTS=0; + handshake.errs=0; + handshake.evts=0; + handshake.fInX=0; + + SerHShake(driverIn,&handshake); + SerReset(driverOut,baud1200+stop10+noParity+data8); + serial_buffer=NewPtr(SERIAL_BUFFER_SIZE); + + if (serial_buffer!=noErr) + done(); + + SerSetBuf(driverIn,serial_buffer,SERIAL_BUFFER_SIZE); } void io_send_byte(unsigned char b) { + long count=1; + if (NoEcho==padF) + return; + + FSWrite(driverOut,&count,&b); } void io_main(void) { + long count; + padByte inBuff[SERIAL_BUFFER_SIZE]; + SerGetBuf(driverIn,&count); + if (count>0) + { + FSRead(driverIn,&count,inBuff); + ShowPLATO(inBuff,(short)count); + } } /** @@ -64,4 +106,10 @@ void io_send_back_out(void) void io_done() { + if (serial_buffer!=NULL) + { + SerSetBuf(driverIn,NULL,0); + DisposePtr(serial_buffer); + serial_buffer=NULL; + } } diff --git a/keyboard.c b/keyboard.c index 998e524..4192455 100755 --- a/keyboard.c +++ b/keyboard.c @@ -14,13 +14,36 @@ extern char tmp[64]; void keyboard_out(int platoKey) { + if (platoKey==0xff) + { + return; + } + + if (platoKey>0x7F) + { + Key(ACCESS); + Key(ACCESS_KEYS[platoKey-0x80]); + return; + } + Key(platoKey); + return; } -void keyboard_main(void) +void keyboard_main(EventRecord* e) { + if (TTY) + { + keyboard_out_tty(e->message&0x7F); + } + else + { + + } } -void keyboard_out_tty(int ch) +void keyboard_out_tty(padByte ch) { + ShowPLATO(&ch,1); + io_send_byte(ch); } diff --git a/keyboard.h b/keyboard.h index 3c9b71b..c47aabb 100755 --- a/keyboard.h +++ b/keyboard.h @@ -10,6 +10,9 @@ #ifndef KEYBOARD_H #define KEYBOARD_H +#include +#include "protocol.h" + /** * keyboard_out - If platoKey < 0x7f, pass off to protocol * directly. Otherwise, platoKey is an access key, and the @@ -21,11 +24,11 @@ void keyboard_out(int platoKey); /** * keyboard_main - Handle the keyboard presses */ -void keyboard_main(void); +void keyboard_main(EventRecord* e); /** * keyboard_out_tty - keyboard output to serial I/O in TTY mode */ -void keyboard_out_tty(int ch); +void keyboard_out_tty(padByte ch); #endif diff --git a/main.c b/main.c index cfaafa3..bb7505c 100755 --- a/main.c +++ b/main.c @@ -13,27 +13,28 @@ unsigned char already_started=false; unsigned char running=false; -void main(void) +void done(void) { - screen_init(); - /* touch_init(); */ - /* help_init(); */ - /* NoEcho=padT; */ - ShowPLATO(splash,sizeof(splash)); - /* NoEcho=padF; */ - /* terminal_initial_position(); */ - /* io_init(); */ - running=true; - /* screen_show_dial(); */ - /* screen_greeting(); */ - while (running==true) - { - screen_main(); - keyboard_main(); - io_main(); - touch_main(); - } io_done(); touch_done(); screen_done(); } + +void main(void) +{ + screen_init(); + touch_init(); + help_init(); + NoEcho=padT; + ShowPLATO(splash,sizeof(splash)); + NoEcho=padF; + terminal_initial_position(); + io_init(); + running=true; + while (running==true) + { + screen_main(); /* keyboard_main() and touch_main() are called in here. */ + io_main(); + } +} + diff --git a/screen.c b/screen.c index 72df19a..8068bdd 100644 --- a/screen.c +++ b/screen.c @@ -13,6 +13,7 @@ #include "font.h" #include "protocol.h" #include "io.h" +#include "keyboard.h" #define true 1 #define false 0 @@ -177,7 +178,12 @@ void screen_main(void) SystemClick(&theEvent,currentWindow); break; } + case keyDown: + case autoKey: + keyboard_main(&theEvent); + break; case updateEvt: + /* To be implemented, somehow... */ break; } }