From a7bbae82e0e8aed9298f833708436a49dfb8526e Mon Sep 17 00:00:00 2001 From: Thomas Cherryhomes Date: Thu, 31 Jan 2019 11:16:20 -0600 Subject: [PATCH] fix key mapping. Work on exit code. Implement beep. Ensure that character size not accidentally reset after initial sizing. --- io.c | 21 +++++++++++++++---- key.h | 2 +- keyboard.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- main.c | 1 + screen.c | 5 ++++- terminal.c | 2 +- 6 files changed, 81 insertions(+), 9 deletions(-) diff --git a/io.c b/io.c index 98b19c6..7497e74 100755 --- a/io.c +++ b/io.c @@ -1,5 +1,6 @@ #include #include +#include #include "io.h" #include "protocol.h" #include "terminal.h" @@ -16,6 +17,7 @@ short driverIn; short driverOut; SerShk handshake; Ptr serial_buffer; +CntrlParam paramBlock; void io_init(void) { @@ -25,7 +27,7 @@ void io_init(void) done(); handshake.fXOn=0; - handshake.fCTS=0; + handshake.fCTS=1; handshake.errs=0; handshake.evts=0; handshake.fInX=0; @@ -34,10 +36,15 @@ void io_init(void) SerReset(driverOut,baud57600+stop10+noParity+data8); serial_buffer=NewPtr(SERIAL_BUFFER_SIZE); - if (serial_buffer!=noErr) - done(); + /* if (serial_buffer!=noErr) */ + /* done(); */ - SerSetBuf(driverIn,serial_buffer,SERIAL_BUFFER_SIZE); + SerSetBuf(driverIn,serial_buffer,SERIAL_BUFFER_SIZE); + paramBlock.ioCRefNum=driverIn; + paramBlock.csCode=kSERDHandshakeRS232; + PBControl((ParmBlkPtr)¶mBlock,false); + paramBlock.csCode=kSERDAssertDTR; + PBControl((ParmBlkPtr)¶mBlock,false); } void io_send_byte(unsigned char b) @@ -81,6 +88,11 @@ void io_set_baud(int baud) */ void io_hang_up(void) { + paramBlock.csCode=kSERDNegateDTR; + PBControl((ParmBlkPtr)¶mBlock,false); + Delay(100,NULL); + paramBlock.csCode=kSERDAssertDTR; + PBControl((ParmBlkPtr)¶mBlock,false); } /** @@ -108,6 +120,7 @@ void io_done() { if (serial_buffer!=NULL) { + io_hang_up(); SerSetBuf(driverIn,NULL,0); DisposePtr(serial_buffer); serial_buffer=NULL; diff --git a/key.h b/key.h index 8cfb99a..c540624 100644 --- a/key.h +++ b/key.h @@ -14,7 +14,7 @@ int key_to_pkey[]={ PKEY_NOKEY, /* 0x05 CTRL-E */ PKEY_NOKEY, /* 0x06 CTRL-F */ PKEY_NOKEY, /* 0x07 CTRL-G */ - PKEY_NOKEY, /* 0x08 CTRL-H */ + PKEY_ERASE, /* 0x08 CTRL-H */ PKEY_TAB, /* 0x09 CTRL-I */ PKEY_NOKEY, /* 0x0a CTRL-J */ PKEY_NOKEY, /* 0x0b CTRL-K */ diff --git a/keyboard.c b/keyboard.c index cb4ca1f..6a5e0f8 100755 --- a/keyboard.c +++ b/keyboard.c @@ -4,6 +4,7 @@ #include "io.h" #include "screen.h" #include "trace.h" +#include "terminal.h" #define true 1 #define false 0 @@ -32,19 +33,73 @@ void keyboard_out(int platoKey) void keyboard_main(EventRecord* e) { unsigned char key; + unsigned char code; key=e->message&0x7F; + code=((e->message)>>8)&0x7F; if (TTY) { - keyboard_out_tty(key); + if (e->modifiers & cmdKey) + { + if (key=='h') + { + TTY=padT; + io_hang_up(); + } + else if (key=='t') + { + terminal_set_tty(); + } + else if (key=='p') + { + terminal_set_plato(); + } + } + else + keyboard_out_tty(key); } else { - if (e->modifiers & 4096) /* CTRL key*/ + if (e->modifiers & cmdKey) + { + if (key=='h') + { + terminal_set_tty(); + io_hang_up(); + } + else if (key=='t') + { + terminal_set_tty(); + } + else if (key=='p') + { + terminal_set_plato(); + } + } + else if (e->modifiers & 4096) /* CTRL key*/ { if (e->modifiers & 512) key|=0x80; keyboard_out(ctrl_key_to_pkey[key]); } + else if ((e->modifiers & 512) && key==0x0d) + { + keyboard_out(PKEY_NEXT1); + } + else if ((e->modifiers & 512) && key==0x08) + { + keyboard_out(PKEY_ERASE1); + } + else if ((e->modifiers & 4096) && code==0x04) + { + if (e->modifiers & 512) + keyboard_out(PKEY_HELP1); + else + keyboard_out(PKEY_HELP); + } + else if ((e->modifiers & 4096) && code==0x2E) + { + keyboard_out(PKEY_MICRO); + } else keyboard_out(key_to_pkey[key]); } diff --git a/main.c b/main.c index bb7505c..d5567ab 100755 --- a/main.c +++ b/main.c @@ -36,5 +36,6 @@ void main(void) screen_main(); /* keyboard_main() and touch_main() are called in here. */ io_main(); } + done(); } diff --git a/screen.c b/screen.c index 1516ef8..b4ca397 100644 --- a/screen.c +++ b/screen.c @@ -43,6 +43,7 @@ int windowHeight; static AEEventHandlerUPP oappUPP, odocUPP, pdocUPP, quitUPP; extern unsigned char running; static long sysv; +extern void done(void); /* Apple Event Handler callbacks */ @@ -189,7 +190,7 @@ void screen_menu_command(long menu_command) { case 1: - ExitToShell(); + done(); break; } } @@ -273,6 +274,7 @@ void screen_wait(void) */ void screen_beep(void) { + SysBeep(5); } /** @@ -650,4 +652,5 @@ void screen_paint(padPt* Coord) */ void screen_done(void) { + ExitToShell(); } diff --git a/terminal.c b/terminal.c index 8d66198..f4b0234 100755 --- a/terminal.c +++ b/terminal.c @@ -87,7 +87,7 @@ void terminal_set_tty(void) CurMem=M0; CurMode=ModeRewrite; CharWide=8; - CharHigh=16; + /* CharHigh=16; */ TTYLoc.x = 0; TTYLoc.y = 495; }