/******************************************************************** * * * HCS_C HOST Program * * Version 1.05 * * * Dec 23, 2006 * ********************************************************************* * * Copyright (c) 2005, Zeta Engineering * Copyright (c) 1999-2000, Creative Control Concepts * Copyright (c) 1992-1999, Circuit Cellar Inc. * Copyright (c) 2001, Circuit Cellar Incorporated (Steve@circuitcellar.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Copyright (C) 2001 * Circuit Cellar Incorporated * 4 Park St. * Vernon, CT 06066 * * steve@circuitcellar.com * * Version -- Date -- Changes (UID) *-------------------------------------------------------------------------- * 0.02 -- July 7, 2005 -- Changed window display for 32 IOs * 5.00 -- February 21, 2005 * -- Made a number of fixes for HCS_C * 4.60 -- January 5, 2005 * -- Changed speed to 115K for Bob's HCS_C W/XPRESS * requires that the users define HCS_C to use. * Otherwise it's still 9600. * 4.51 -- August 16, 2001 * -- Version Increment, first GPL release (wmaton) * -- Clean-ups around comments (wmaton) * -- Added URL for located newest source of this * program (wmaton) * -- Got rid of fixed version number and added variable * at the top of this file to definte it like in * compile (wmaton) * 4.00 -- January 20, 2000 * -- Updated version # & Splash Screen * 3.63 -- January 5, 2000 * -- Updated version # & Splash Screen * 3.62 -- February 4,1999 * -- Y2K (jeff bachiochi) * 3.60 -- March 6, 1998 * -- Fixed analog output display * 3.50 -- March 15, 1997 * -- Final Answer MAN release * 3.05 -- November 3, 1996 * -- Answer MAN support * 3.01 -- June 10, 1995 * -- Fix log data dump * -- Fix vs_fillchar error on multiple program load * 3.00 -- March 16, 1995 * -- Release version * 2.10 -- December 20, 1993 * -- Release version * 2.00 -- March 3, 1993 * -- Release version * 1.20 -- November 18, 1992 * -- Increase timeout values for fast machines * -- Added MCIR support * -- Patched vs_locatecur error bug * 1.00 -- March 1992 -- Release version * * *********************************************************************/ #include #include #include #include #include #include #include #include #include "pro.h" #include "xglobals.h" #include "vs.h" #include "colors.h" #include "mouse.h" #include "pcl4c.h" typedef unsigned int u_int; #define SERIAL_PORT_TIMEOUT 20000 #define Tics 30 /* 2 seconds */ // These IDs must match the IDs in the HCS_C firmware #define ID_HCS_COMBO 1 #define ID_HCS_TERM 2 // HCS status codes #define HCSSTAT_OK 0 #define HCSSTAT_LOADVERSION_FAIL 1 #define HCSSTAT_ERASE_FAIL 2 #define HCSSTAT_STORE_FAIL 4 #define HCSSTAT_NO_EVENTS_FILE 8 #define HCSSTAT_POWERUP 0x10 #define HCSSTAT_RS485_FAIL 0x20 #define HCSSTAT_NEWEVENTS 0x80 // status error range #define HCSSTAT_ERROR 0xf //#ifdef HCS_C //#define Tics 36 /* 2 seconds */ //#define Tics 360 /* Really just a guess */ //#else //#define Tics 36 /* 2 seconds */ //#endif #define true 1 #define false 0 #define bell '\x07' #define tab '\x09' #define cr '\x0d' #define esc '\x1b' #define alert '!' #define ack '^' #define reply '$' #define badver '#' #define toobig '@' #define clear '\x00' #define pause '\x01' #define update '\x02' #define newtime '\x05' #define newevnt '\x06' #define clrlog '\x07' #define logsize '\x08' #define dumplog '\x09' #define sendlog '\x0b' #define setx10 '\x12' #define setin '\x15' #define setout '\x18' #define cmd_save_events '\x1c' #define cmd_retrieve_events '\x1d' #define cmd_erase_events '\x1e' #define setadc '\x1b' #define setdac '\x1e' #define setbit '\x23' #define netstr '\x30' #define vstr '\x31' #define curtime '\x80' #define x10stat '\x81' #define inpstat '\x82' #define outstat '\x83' #define adcstat '\x84' #define dacstat '\x85' #define modstat '\x86' #define netstat '\x87' #define msgdisp '\x88' #define storestat '\x89' #define msgconsole '\x97' // Declarations extern int ErrorCheck(int Code); extern int AllocSeg(int Size); extern int bcd(int num); extern void reset_HCS(); extern int SaveScreen(void); extern void ReadScreen(void); extern void ClearWindows(void); extern int InitPort(void); extern void SetupScreen(void); extern int FindActive(void); extern void NextActive(void); extern void MoveActiveUp(void); extern void MoveActiveDown(void); extern void MoveActiveLeft(void); extern void MoveActiveRight(void); extern void SizeActiveUp(void); extern void SizeActiveDown(void); extern void SizeActiveLeft(void); extern void SizeActiveRight(void); extern void CloseActive(void); extern void DisplayInputs(void); extern void DisplayOutputs(void); extern void DisplayADCs(void); extern void DisplayDACs(void); extern void DisplayModule(void); extern void DisplayNetwork(void); extern void DisplayNetbits(void); extern void DisplayInfo(void); extern void SaveStoreStat(void); extern void DisplayMessage(void); extern void DisplayDebugMessage(char); extern void DisplayDeviceMessage(int); extern void Happy(void); extern void sound_alert(void); extern void NewEvents(void); extern void NewTime(void); extern void DumpLog(void); extern void ClearLog(void); extern void LogSize(void); extern void SetInput(void); extern void SetOutput(void); extern void SetADC(void); extern void SetDAC(void); extern void SetX10(void); extern void SetNetbit(void); extern void NetString(void); extern void VoiceString(void); extern void ModemOut(char str[]); extern void ModemIn(char str[],int timeout); extern void ModemInit(void); extern void Hangup(void); extern void Dial(void); extern void SpecialMenu(void); extern int FileMenu(void); extern void CommandMenu(void); extern void LogMenu(void); extern void WindowMenu(void); extern void ModemMenu(void); extern void delay(int); extern void sound(int); extern void nosound(void); // extern unsigned int kb_getxc(void); extern unsigned int kb_getshift(void); extern void v_gotoxy(u_int oldx, u_int oldy); extern void v_curshape(u_int oldb, u_int olde); int testing = 0; // //int oldx, oldy, oldb, olde; // in XGLOBALS.H // This version number doesnt matter, it is not checked: check is done // between HCS_C Rom and compiler version. int version = 105; /* Low two digits must be minor version number */ short hcs_store_id; short hcs_store_stat; char hcs_store_name[100]; unsigned int win[20]; time_t t1_start, t2_start; int time1=false, time2=false, Port=0, mousepresent; int fore[20] = { black, yellow, black, white, black, black, black, black, black, black, yellow, lightgreen, lightgreen, white, black, yellow, yellow, black, white}; int back[20] = { lightgray, magenta, magenta, black, lightgray, lightgray, lightgray, lightgray, lightgray, lightgray, blue, red, red, cyan, green, magenta, magenta, cyan, black}; unsigned char modinit[40] = "AT&FLT&K3&Q5"; /* Array contains physical_x, physical_y, port_rows, port_columns, and hide for windows 10-18 */ unsigned int scrn[10][5] = {{45, 2, 5, 34, FALSE}, {40, 9, 4, 40, FALSE}, {40, 15, 4, 40, FALSE}, {1, 2, 14, 36, FALSE}, {1, 4, 8, 22, TRUE}, {27, 12, 4, 16, TRUE}, {27, 19, 4, 16, TRUE}, {47, 21, 3, 32, TRUE}, {1, 20, 4, 36, FALSE}, {40, 15, 4, 40, FALSE}}; unsigned char box5[13] = { '\x0f','»','Ù','È','Í','º','Í','Í', 'Ä','Ä','Ä','Ç','¶' }; int network_mod[5] = {0,0,0,0,0}; int out_used[15] = {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; int in_used[15] = {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; int dac_used[15] = {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; int nb_used[15] = {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; int curr_state = 0; //debugging value char house_used[16] = " "; short time_dump_error = 0; //void my_delay() //{ //} //void my_sound() //{ //} void nosound() { } int ErrorCheck(int Code) { /* Trap PCL error codes */ if (Code < 0) { SioError(Code); SioDone(Port); exit(1); } return(0); } int AllocSeg(int Size) { int Seg; char far *Ptr; /* allocate far heap */ Ptr = (char far *) _fmalloc(Size+16); if (Ptr==NULL) return 0; /* SEG:0 points to buffer */ Seg = (FP_SEG(Ptr) + 1) + (FP_OFF(Ptr)>>4); return Seg; } int bcd(int num) { if (num>99) num = num - 100; return ((num / 10) * 16) + (num % 10); } void reset_HCS(void) { SioPutc(Port, alert); SioPutc(Port, clear); } int SaveScreen(void) { FILE *fp; int i; if ((fp=fopen("host.cfg", "wb")) == NULL) return 1; for (i=10; i<19; i++) { fputc(wdw[win[i]]->physical_x, fp); fputc(wdw[win[i]]->physical_y, fp); fputc(wdw[win[i]]->port_rows, fp); fputc(wdw[win[i]]->port_columns, fp); fputc(wdw[win[i]]->hide, fp); } fputs(modinit, fp); fclose(fp); return 0; } void ReadScreen(void) { FILE *fp; int i, j; if ((fp=fopen("host.cfg", "rb")) == NULL) return; for (i=0; i<9; i++) for (j=0; j<5; j++) scrn[i][j] = fgetc(fp); fgets(modinit, 50, fp); fclose(fp); } void ClearWindows(void) { int i; vs_locatecur(win[11],0,1,3); vs_clrtoend(win[11],0,fore[11],back[11]); vs_locatecur(win[12],0,1,3); vs_clrtoend(win[12],0,fore[12],back[12]); // vs_locatecur(win[13],0,1,2); // vs_clrtoend(win[13],0,fore[13],back[13]); vs_locatecur(win[14],0,1,3); vs_clrtoend(win[14],0,fore[14],back[14]); vs_locatecur(win[15],0,1,1); vs_clrtoend(win[15],0,fore[15],back[15]); vs_locatecur(win[16],0,1,1); vs_clrtoend(win[16],0,fore[16],back[16]); vs_locatecur(win[17],0,1,3); vs_clrtoend(win[17],0,fore[17],back[17]); vs_locatecur(win[18],0,1,1); vs_clrtoend(win[18],0,fore[18],back[18]); for (i=0; i<=4; i++) network_mod[i] = 0; for (i=0; i<=14; i++) { in_used[i] = 99; out_used[i] = 99; dac_used[i] = 99; nb_used[i] = 99; } strcpy(house_used, " "); } int InitPort(void) { int error; /* Set up transmit & receive buffer */ SioRxBuf(Port,AllocSeg(2048),Size2048); /* Set port parmameters */ SioParms(Port,NoParity,OneStopBit,WordLength8); /* Reset the port */ //ifdef HCS_C // error = SioReset(Port,Baud115200); //else error = SioReset(Port,Baud9600); //endif if (!error) { SioRTS(Port, 'S'); SioDTR(Port, 'S'); /* Turn off flow control */ SioFlow(Port, false); } return error; } void SetupScreen(void) { char str[256]; scroll_bars_on = NO_BARS; thumbwheels_on = NO_BARS; method = DMA; active_attr = white + (black << 4); inactive_attr = lightgray + (black << 4); wn_hidecur(); win[0] = wn_createw(physical_rows, physical_columns, 1,1,1,1, physical_rows-2, physical_columns-2, FALSE, NONE, NULL, NULL); vs_clrvs(win[0],0,white,black); vs_putcods(win[0],0,1,1,80,black,lightgray,red,lightgray, " ~! ~File ~Command ~Log ~Window ~Modem HCS_C Version 1.05"); wn_openw(win[0]); /* scroll_bars_on = BOTH_BARS; */ thumbwheels_on = BOTH_BARS; default_box = box5; /////////////// Digital IN window ///////////////////////////////////////// // win[11]= wn_createw(7,40,scrn[1][0],scrn[1][1],1,1,scrn[1][2],scrn[1][3], win[11]= wn_createw(4,40,scrn[1][0],scrn[1][1],1,1,4,40, FALSE,HEAD_ON," Digital In ",NULL); vs_clrvs(win[11],0,fore[11],back[11]); vs_putscenter(win[11],0, " 111111 11112222 22222233",fore[11],back[11],1); vs_putscenter(win[11],0, "01234567 89012345 67890123 45678901",fore[11],back[11],2); if (!scrn[1][4]) { wn_flybox(wdw[win[11]]->physical_x+ wdw[win[11]]->port_columns/2, wdw[win[11]]->physical_y+ wdw[win[11]]->port_rows/2, 1,1, wdw[win[11]]->physical_x, wdw[win[11]]->physical_y, wdw[win[11]]->port_rows, wdw[win[11]]->port_columns, 28,40,box1,white,black); wn_openw(win[11]); } /////////////// Digital OUT window ///////////////////////////////////////// win[12]= wn_createw(4,40,scrn[9][0],scrn[9][1],1,1,4,40, FALSE,HEAD_ON," Digital Out ",NULL); vs_clrvs(win[12],0,fore[12],back[12]); vs_putscenter(win[12],0, " 111111 11112222 22222233",fore[12],back[12],1); vs_putscenter(win[12],0, "01234567 89012345 67890123 45678901",fore[12],back[12],2); if (!scrn[9][4]) { wn_flybox(wdw[win[12]]->physical_x+ wdw[win[12]]->port_columns/2, wdw[win[12]]->physical_y+ wdw[win[12]]->port_rows/2, 1,1, wdw[win[12]]->physical_x, wdw[win[12]]->physical_y, wdw[win[12]]->port_rows, wdw[win[12]]->port_columns, 28,40,box1,white,black); wn_openw(win[12]); } /////////////// HCS COMBO MODULE window ///////////////////////////////////////// // win[13]= wn_createw(40,20,scrn[3][0],scrn[3][1],1,1,scrn[3][2],scrn[3][3], win[13]= wn_createw(19,36,scrn[3][0],scrn[3][1],1,1,14,36, FALSE,HEAD_ON," HCS COMBO 1 ",NULL); vs_clrvs(win[13],0,fore[13],back[13]); vs_putscenter(win[13],0, "Status ",fore[13],back[13],1); vs_putscenter(win[13],0, "IO ",fore[13],back[13],2); vs_putscenter(win[13],0, "IO occurred ",fore[13],back[13],3); vs_putscenter(win[13],0, "Relays ",fore[13],back[13],4); vs_putscenter(win[13],0, "Voice ",fore[13],back[13],5); vs_putscenter(win[13],0, "Touchscreen ",fore[13],back[13],6); vs_putscenter(win[13],0, "Opto ",fore[13],back[13],7); vs_putscenter(win[13],0, "Opto occurred ",fore[13],back[13],8); vs_putscenter(win[13],0, "IO dir ",fore[13],back[13],9); vs_putscenter(win[13],0, "Keyboard ",fore[13],back[13],10); vs_putscenter(win[13],0, "Analog in ",fore[13],back[13],11); vs_putscenter(win[13],0, "Analog min ",fore[13],back[13],12); vs_putscenter(win[13],0, "Analog max ",fore[13],back[13],13); if (!scrn[3][4]) { wn_flybox(wdw[win[13]]->physical_x+ wdw[win[13]]->port_columns/2, wdw[win[13]]->physical_y+ wdw[win[13]]->port_rows/2, 1,1, wdw[win[13]]->physical_x, wdw[win[13]]->physical_y, wdw[win[13]]->port_rows, wdw[win[13]]->port_columns, 29,36,box1,white,black); wn_openw(win[13]); } /////////////// X10 MODULE window ///////////////////////////////////////// win[14]= wn_createw(18,22,scrn[4][0],scrn[4][1],1,1,scrn[4][2],scrn[4][3], FALSE,HEAD_ON," X-10 Mods ",NULL); vs_clrvs(win[14],0,fore[14],back[14]); vs_putscenter(win[14],0," 1111111",fore[14],back[14],1); vs_putscenter(win[14],0,"1234567890123456",fore[14],back[14],2); if (!scrn[4][4]) { wn_flybox(wdw[win[14]]->physical_x+ wdw[win[14]]->port_columns/2, wdw[win[14]]->physical_y+ wdw[win[14]]->port_rows/2, 1,1, wdw[win[14]]->physical_x, wdw[win[14]]->physical_y, wdw[win[14]]->port_rows, wdw[win[14]]->port_columns, 28,40,box1,white,black); wn_openw(win[14]); } /////////////// TERM1 window ///////////////////////////////////////// // win[15]= wn_createw(30,16,scrn[5][0],scrn[5][1],1,1,scrn[5][2],scrn[5][3], win[15]= wn_createw(5,18,scrn[5][0],scrn[5][1],1,1,5,18, FALSE,HEAD_ON," HCSNET TERM ",NULL); vs_clrvs(win[15],0,fore[15],back[15]); if (!scrn[5][4]) { vs_putscenter(win[15],0, "TERM1 Status ",fore[15],back[15],1); wn_openw(win[15]); } /////////////// Analog OUT window ///////////////////////////////////////// win[16]= wn_createw(10,16,scrn[6][0],scrn[6][1],1,1,scrn[6][2],scrn[6][3], FALSE,HEAD_ON," Analog Out ",NULL); vs_clrvs(win[16],0,fore[16],back[16]); if (!scrn[6][4]) { wn_flybox(wdw[win[16]]->physical_x+ wdw[win[16]]->port_columns/2, wdw[win[16]]->physical_y+ wdw[win[16]]->port_rows/2, 1,1, wdw[win[16]]->physical_x, wdw[win[16]]->physical_y, wdw[win[16]]->port_rows, wdw[win[16]]->port_columns, 28,40,box1,white,black); wn_openw(win[16]); } /////////////// Netbit window ///////////////////////////////////////// win[17]= wn_createw(17,32,scrn[7][0],scrn[7][1],1,1,scrn[7][2],scrn[7][3], TRUE,HEAD_ON," Netbit ",NULL); vs_clrvs(win[17],0,fore[17],back[17]); vs_putscenter(win[17],0, " 111111 11112222",fore[17],back[17],1); vs_putscenter(win[17],0, " 01234567 89012345 67890123",fore[17],back[17],2); if (!scrn[7][4]) { wn_flybox(wdw[win[17]]->physical_x+ wdw[win[17]]->port_columns/2, wdw[win[17]]->physical_y+ wdw[win[17]]->port_rows/2, 1,1, wdw[win[17]]->physical_x, wdw[win[17]]->physical_y, wdw[win[17]]->port_rows, wdw[win[17]]->port_columns, 28,40,box1,white,black); wn_openw(win[17]); } //////////////////////// MESSAGE window //////////////////////////////////// // win[18]= wn_createw(12,20,scrn[8][0],scrn[8][1],1,1,scrn[8][2],scrn[8][3], win[18]= wn_createw(5,36,scrn[8][0],scrn[8][1],1,1,5,36, FALSE,HEAD_ON," Message ",NULL); vs_clrvs(win[18],0,fore[18],back[18]); if (!scrn[8][4]) { wn_flybox(wdw[win[18]]->physical_x+ wdw[win[18]]->port_columns/2, wdw[win[18]]->physical_y+ wdw[win[18]]->port_rows/2, 1,1, wdw[win[18]]->physical_x, wdw[win[18]]->physical_y, wdw[win[18]]->port_rows, wdw[win[18]]->port_columns, 28,40,box1,white,black); wn_openw(win[18]); } scroll_bars_on = NO_BARS; thumbwheels_on = NO_BARS; default_box = box0; //////////////////////// Time window //////////////////////////////////// win[10]= wn_createw(5,34,scrn[0][0],scrn[0][1],1,1,scrn[0][2],scrn[0][3], FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[10],0,fore[10],back[10]); if (!scrn[0][4]) { wn_flybox(wdw[win[10]]->physical_x+ wdw[win[10]]->port_columns/2, wdw[win[10]]->physical_y+ wdw[win[10]]->port_rows/2, 1,1, wdw[win[10]]->physical_x, wdw[win[10]]->physical_y, wdw[win[10]]->port_rows, wdw[win[10]]->port_columns, 28,40,box1,white,black); wn_openw(win[10]); } win[2] = wn_createw(6,40,20,6,1,1,6,40,FALSE,HEAD_ON,NULL,NULL); win[3] = wn_createw(6,40,20,12,1,1,6,40,FALSE,HEAD_ON,NULL,NULL); default_box = box1; win[4] = wn_createw(1,10,2,2,1,1,1,10,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[4],0,fore[4],back[4]); vs_putcods(win[4],0,2,1,8,fore[4],back[4],red,back[4],"~About..."); win[5] = wn_createw(5,8,5,2,1,1,5,8,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[5],0,fore[5],back[5]); vs_putcods(win[5],0,2,1,6,fore[5],back[5],red,back[5],"~Load"); vs_putcods(win[5],0,2,2,6,fore[5],back[5],red,back[5],"~Save"); vs_putcods(win[5],0,2,3,6,fore[5],back[5],red,back[5],"~Retrve"); vs_putcods(win[5],0,2,4,6,fore[5],back[5],red,back[5],"~Erase"); vs_putcods(win[5],0,2,5,6,fore[5],back[5],red,back[5],"~Quit"); win[6] = wn_createw(9,15,11,2,1,1,9,15,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[6],0,fore[6],back[6]); vs_putcods(win[6],0,2,1,13,fore[6],back[6],red,back[6],"Set ~Time"); vs_putcods(win[6],0,2,2,13,fore[6],back[6],red,back[6],"Set ~Input..."); vs_putcods(win[6],0,2,3,13,fore[6],back[6],red,back[6],"Set ~Output..."); vs_putcods(win[6],0,2,4,13,fore[6],back[6],red,back[6],"Set ~X-10..."); vs_putcods(win[6],0,2,5,13,fore[6],back[6],red,back[6],"Set ~ADC..."); vs_putcods(win[6],0,2,6,13,fore[6],back[6],red,back[6],"Set ~DAC..."); vs_putcods(win[6],0,2,7,13,fore[6],back[6],red,back[6],"Set Net~bit..."); vs_putcods(win[6],0,2,8,13,fore[6],back[6],red,back[6],"~Voice..."); vs_putcods(win[6],0,2,9,13,fore[6],back[6],red,back[6],"~Network..."); win[7] = wn_createw(3,7,20,2,1,1,3,7,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[7],0,fore[7],back[7]); vs_putcods(win[7],0,2,1,5,fore[7],back[7],red,back[7],"~Clear"); vs_putcods(win[7],0,2,2,5,fore[7],back[7],red,back[7],"~Size"); vs_putcods(win[7],0,2,3,5,fore[7],back[7],red,back[7],"~Dump"); win[8] = wn_createw(9,14,25,2,1,1,9,14,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[8],0,fore[8],back[8]); vs_putcods(win[8],0,2,1,12,fore[8],back[8],red,back[8],"~Time"); vs_putcods(win[8],0,2,2,12,fore[8],back[8],red,back[8],"~Digital In"); vs_putcods(win[8],0,2,3,12,fore[8],back[8],red,back[8],"Digital ~Out"); vs_putcods(win[8],0,2,4,12,fore[8],back[8],red,back[8],"~HCS Combo"); vs_putcods(win[8],0,2,5,12,fore[8],back[8],red,back[8],"~X-10 Mods"); vs_putcods(win[8],0,2,6,12,fore[8],back[8],red,back[8],"~Analog In"); vs_putcods(win[8],0,2,7,12,fore[8],back[8],red,back[8],"Analo~g Out"); vs_putcods(win[8],0,2,8,12,fore[8],back[8],red,back[8],"Net~bits"); vs_putcods(win[8],0,2,9,12,fore[8],back[8],red,back[8],"~Message"); win[9] = wn_createw(3,9,33,2,1,1,3,9,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[9],0,fore[9],back[9]); vs_putcods(win[9],0,2,1,7,fore[9],back[9],red,back[9],"~Init..."); vs_putcods(win[9],0,2,2,7,fore[9],back[9],red,back[9],"~Dial..."); vs_putcods(win[9],0,2,3,7,fore[9],back[9],red,back[9],"~Hangup"); default_box = box0; win[1] = wn_createw(7,40,20,10,1,1,7,40,FALSE,HEAD_ON,NULL,NULL); wn_flybox(wdw[win[1]]->physical_x+ wdw[win[1]]->port_columns/2, wdw[win[1]]->physical_y+ wdw[win[1]]->port_rows/2, 1,1, wdw[win[1]]->physical_x, wdw[win[1]]->physical_y, wdw[win[1]]->port_rows, wdw[win[1]]->port_columns, 28,40,box1,white,black); vs_clrvs(win[1],0,fore[1],back[1]); sprintf(str, "Version %1d.%02d", version/100, version%100); vs_putscenter(win[1],0,"Zeta Engineering",fore[1],back[1],1); vs_putscenter(win[1],0,"HCS_C Host Program",fore[1],back[1],2); vs_putscenter(win[1],0,str,fore[1],back[1],4); vs_putscenter(win[1],0,"(c)2005 Zeta Engineering",fore[1], back[1],5); vs_putscenter(win[1],0,"(c)2001-2005 Open Source HCS Project",fore[1], back[1],6); vs_putscenter(win[1],0,"(c)1999-2000 Creative Control Concepts",fore[1], back[1],7); vs_putscenter(win[1],0,"(c)1992-1999 Circuit Cellar, Inc.",fore[1], back[1],8); wn_openw(win[1]); t1_start = time(NULL); time1 = true; } int FindActive(void) { int current=1; while ((win[current] != active_wdw) && (current < 20)) current++; return current; } void NextActive(void) { int current=1, next; current = FindActive(); if (current >= 20) return; next = current + 1; if ((next < 10) || (next > 18)) next = 10; while (wdw[win[next]]->hide && next!=current) { next++; if (next > 18) next = 10; } wn_openw(win[next]); } void MoveActiveUp(void) { int current; current = FindActive(); wn_locatew(win[current], wdw[win[current]]->physical_x, wdw[win[current]]->physical_y - 1); } void MoveActiveDown(void) { int current; current = FindActive(); wn_locatew(win[current], wdw[win[current]]->physical_x, wdw[win[current]]->physical_y + 1); } void MoveActiveLeft(void) { int current; current = FindActive(); wn_locatew(win[current], wdw[win[current]]->physical_x - 1, wdw[win[current]]->physical_y); } void MoveActiveRight(void) { int current; current = FindActive(); wn_locatew(win[current], wdw[win[current]]->physical_x + 1, wdw[win[current]]->physical_y); } void SizeActiveUp(void) { int current; current = FindActive(); wn_sizet(win[current], wdw[win[current]]->last_tile, 0, -1); } void SizeActiveDown(void) { int current; current = FindActive(); wn_sizet(win[current], wdw[win[current]]->last_tile, 0, 1); } void SizeActiveLeft(void) { int current; current = FindActive(); wn_sizet(win[current], wdw[win[current]]->last_tile, -1, 0); } void SizeActiveRight(void) { int current; current = FindActive(); wn_sizet(win[current], wdw[win[current]]->last_tile, 1, 0); } void CloseActive(void) { int current; current = FindActive(); wn_closew(win[current]); } // Modified for HCS_C. If receive display inputs command, void DisplayInputs(void) { int i; int inputdata; // int s; // int icode,group,line,stat; // icode = SioGetc(Port, Tics); // if (icode < 0) return; // group = (icode + 1) / 3; // // stat = SioGetc(Port, Tics); // if (stat < 0) return; // // for (i=0; i<=8; i++) { // if (in_used[i] == group) // { // line = i + 3; // break; // } // if (in_used[i] == 99) // { // in_used[i] = group; // line = i + 3; // break; // } // } // vs_locatecur(win[11],0,1,line); // vs_printf(win[11],0,fore[11],back[11]," %03u:",group ? (group*24)-8:group); // if (icode>1) // vs_locatecur(win[11],0,(6+((icode+1)%3)*9),line); // else // vs_locatecur(win[11],0,(6+icode*9),line); vs_locatecur(win[11],0,6,3); // Always dump all four bytes line 3 inputdata = SioGetc(Port, Tics); for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); inputdata = SioGetc(Port, Tics); for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); inputdata = SioGetc(Port, Tics); for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); inputdata = SioGetc(Port, Tics); for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); } void DisplayOutputs(void) { int s,i; int ocode,group,line,stat; ocode = SioGetc(Port, Tics); if (ocode < 0) return; group = (ocode + 1) / 3; stat = SioGetc(Port, Tics); if (stat < 0) return; for (i=0; i<=8; i++) { if (out_used[i] == group) { line = i + 3; break; } if (out_used[i] == 99) { out_used[i] = group; line = i + 3; break; } } vs_locatecur(win[12],0,1,line); vs_printf(win[12],0,fore[12],back[12]," %03u:",group ? (group*24)-8:group); if (ocode>1) vs_locatecur(win[12],0,(6+((ocode+1)%3)*9),line); else vs_locatecur(win[12],0,(6+ocode*9),line); s = stat; for (i=1; i<=8; i++, s = s >> 1) vs_printf(win[12],0,fore[12],back[12],(s & 0x0001) ? "1":"0"); } void DisplayADCs(void) { int group,start,i,j; int stat[8]; group = SioGetc(Port, Tics); start = group * 8; for (i=0; i<=7; i++) { stat[i] = (SioGetc(Port, Tics) + (SioGetc(Port, Tics) * 256)) % 9999; if (stat[i] < 0) return; } for (i=0; i<=3; i++) { if (group==13) vs_locatecur(win[15],0,1,i+5); else vs_locatecur(win[15],0,1,i+1); j = i * 2; vs_printf(win[15],0,fore[15],back[15]," %03i: %04i %04i",j+start, stat[j],stat[j+1]); } } void DisplayDACs(void) { int group,start,i; int line,stat[4]; // group = SioGetc(Port, Tics); // start = group * 4; // // for (i=0; i<=1; i++) { // stat[i] = (SioGetc(Port, Tics) + (SioGetc(Port, Tics) * 256)) % 9999; // if (stat[i] < 0) return; // } // // for (i=0; i<=8; i++) { // if (dac_used[i] == group) { // line = i + 1; // break; // } // if (dac_used[i] == 99) { // dac_used[i] = group; // line = i + 1; // break; // } // } // vs_locatecur(win[16],0,1,line); // vs_printf(win[16],0,fore[16],back[16]," %03i: %04i %04i",start, // stat[0],stat[1]); } void DisplayModule(void) { char house; int s,i,line,ihouse,stat; ihouse = SioGetc(Port, Tics); if (ihouse < 0) return; house = (char) ihouse; stat = SioGetc(Port, Tics) + (SioGetc(Port, Tics) * 256); for (i=0; i<=15; i++) { if (house_used[i] == house) { line = i + 3; break; } if (house_used[i] == ' ') { house_used[i] = house; line = i + 3; break; } } vs_locatecur(win[14],0,2,line); vs_printf(win[14],0,fore[14],back[14],"%1c ",house); s = stat; for (i=1; i<=16; i++, s = s >> 1) vs_printf(win[14],0,fore[14],back[14],(s & 0x0001) ? "1":"0"); vs_printf(win[14],0,fore[14],back[14]," %1c",house); } void DisplayNetwork(void) { int netmod,i; netmod = SioGetc(Port, Tics); vs_locatecur(win[13],0,12,2); for (i=1; i<=8; i++, netmod = netmod >> 1) vs_printf(win[13],0,fore[13],back[13],(netmod & 0x0001) ? "1":"0"); vs_printf(win[13],0,fore[13],back[13]," "); netmod = SioGetc(Port, Tics); for (i=1; i<=8; i++, netmod = netmod >> 1) vs_printf(win[13],0,fore[13],back[13],(netmod & 0x0001) ? "1":"0"); vs_printf(win[13],0,fore[13],back[13]," "); // netmod = SioGetc(Port, Tics); // if (netmod < 0) return; // switch (netmod & 0xf0) { // case 0x00: // vs_printf(win[13],0,fore[13],back[13],"PL : "); // break; // case 0x10: // vs_printf(win[13],0,fore[13],back[13],"MC/IR: "); // break; // case 0x20: // vs_printf(win[13],0,fore[13],back[13],"LCD : "); // break; // case 0x30: // vs_printf(win[13],0,fore[13],back[13],"DIO : "); // break; // case 0x40: // vs_printf(win[13],0,fore[13],back[13],"AMAN : "); // break; // case 0x50: // vs_printf(win[13],0,fore[13],back[13],"DIO+ : "); // break; // } // vs_locatecur(win[13],0,(netmod & 0x0f) + 9,line); // // if (stat == 1) // vs_printf(win[13],0,fore[13],back[13],"*"); // else if (stat == 2) // vs_printf(win[13],0,fore[13],back[13],"E"); // else // vs_printf(win[13],0,fore[13],back[13],"-"); } void DisplayNetbits(void) { int s,i; int ncode,group,line,stat; ncode = SioGetc(Port, Tics); if (ncode < 0) return; group = ncode / 3; stat = SioGetc(Port, Tics); if (stat < 0) return; for (i=0; i<=14; i++) { if (nb_used[i] == group) { line = i + 3; break; } if (nb_used[i] == 99) { nb_used[i] = group; line = i + 3; break; } } vs_locatecur(win[17],0,1,line); vs_printf(win[17],0,fore[17],back[17]," %03u:",group*24); vs_locatecur(win[17],0,(6+(ncode%3)*9),line); s = stat; for (i=1; i<=8; i++, s = s >> 1) vs_printf(win[17],0,fore[17],back[17],(s & 0x0001) ? "1":"0"); } int get_device_size(int device_val) { switch (device_val) { case ID_HCS_COMBO: return(46); case ID_HCS_TERM: return(1); default: return(1); } } void DisplayInfo(void) { int i; short hcs_info_array[300]; int inputdata; int device_type, device_addr, device_size; int device_array_ptr; // NOTE: The number of bytes MUST exactly equal the number of transmitted // bytes including the last one (CHAR_EOL). Note that the hcs_xpress_int_utils // curr_dump_string number is one greater than this number i. (secs is at // 1 here, but is 2 there). But since you must add one for the status byte, the // numbers are equal). // // The DisplayInfo routine also displays the HCS_C inputs and outputs, and // displays any devices specified in the device list of an events program. // 18 is the size of the basic array with no devices. device_array_ptr = 0; for (i=0; i<17; i++) { hcs_info_array[device_array_ptr] = SioGetc(Port, Tics); device_array_ptr += 1; } while ((device_type = SioGetc(Port, Tics)) != 0) // look for a device ID { hcs_info_array[device_array_ptr] = device_type; device_array_ptr += 1; device_addr = SioGetc(Port, Tics); hcs_info_array[device_array_ptr] = device_addr; device_array_ptr += 1; device_size = get_device_size(device_type); for (i = 0;i < device_size;i++) { hcs_info_array[device_array_ptr] = SioGetc(Port, Tics); device_array_ptr += 1; } } hcs_info_array[device_array_ptr] = 0; // indicate no more devices vs_locatecur(win[10],0,3,1); vs_printf(win[10],0,fore[10],back[10],"%02X:%02X:%02X ", hcs_info_array[3], hcs_info_array[2], hcs_info_array[1]); switch (hcs_info_array[4] & 0x0f) { case 1: vs_printf(win[10],0,fore[10],back[10],"Sun, "); break; case 2: vs_printf(win[10],0,fore[10],back[10],"Mon, "); break; case 3: vs_printf(win[10],0,fore[10],back[10],"Tue, "); break; case 4: vs_printf(win[10],0,fore[10],back[10],"Wed, "); break; case 5: vs_printf(win[10],0,fore[10],back[10],"Thu, "); break; case 6: vs_printf(win[10],0,fore[10],back[10],"Fri, "); break; case 7: vs_printf(win[10],0,fore[10],back[10],"Sat, "); break; } switch (hcs_info_array[6]) { case 1 : vs_printf(win[10],0,fore[10],back[10],"Jan "); break; case 2 : vs_printf(win[10],0,fore[10],back[10],"Feb "); break; case 3 : vs_printf(win[10],0,fore[10],back[10],"Mar "); break; case 4 : vs_printf(win[10],0,fore[10],back[10],"Apr "); break; case 5 : vs_printf(win[10],0,fore[10],back[10],"May "); break; case 6 : vs_printf(win[10],0,fore[10],back[10],"Jun "); break; case 7 : vs_printf(win[10],0,fore[10],back[10],"Jul "); break; case 8 : vs_printf(win[10],0,fore[10],back[10],"Aug "); break; case 9 : vs_printf(win[10],0,fore[10],back[10],"Sep "); break; case 16: vs_printf(win[10],0,fore[10],back[10],"Oct "); break; case 17: vs_printf(win[10],0,fore[10],back[10],"Nov "); break; case 18: vs_printf(win[10],0,fore[10],back[10],"Dec "); break; } if ((hcs_info_array[7] & 0xff) > 98) vs_printf(win[10],0,fore[10],back[10],"%02X, 19%02X", hcs_info_array[5], hcs_info_array[7] & 0xff); else vs_printf(win[10],0,fore[10],back[10],"%02X, 20%02X", hcs_info_array[5], hcs_info_array[7] & 0xff); // if ((hcs_info_array[16] & 1) != 0) // { // First, clear ID and name fields for (i = 2; i <= 5; i++) { vs_locatecur(win[10],0,1,i); vs_printf(win[10],0,fore[10],back[10], " "); } vs_locatecur(win[10],0,1,3); if ((hcs_info_array[16] & HCSSTAT_LOADVERSION_FAIL) != 0) vs_printf(win[10],0,fore[10],back[10], "EVENTS WRONG VERSION, NO LOAD"); else if ((hcs_info_array[16] & HCSSTAT_STORE_FAIL) != 0) vs_printf(win[10],0,fore[10],back[10], "EVENTS FAILED TO STORE "); else if ((hcs_info_array[16] & HCSSTAT_ERASE_FAIL) != 0) vs_printf(win[10],0,fore[10],back[10], "FLASH FAILED TO ERASE "); else if ((hcs_info_array[16] & HCSSTAT_RS485_FAIL) != 0) vs_printf(win[10],0,fore[10],back[10], "HCSNET TRANSMISSION ERROR "); else if ((hcs_info_array[16] & HCSSTAT_NEWEVENTS) != 0) { vs_printf(win[10],0,fore[10],back[10], " New events file loaded. "); vs_locatecur(win[10],0,1,4); vs_printf(win[10],0,fore[10],back[10], "Events file (ID=new): "); vs_locatecur(win[10],0,1,5); vs_printf(win[10],0,fore[10],back[10], " "); } else if ((hcs_info_array[16] & HCSSTAT_POWERUP) == 0) { if ((hcs_info_array[16] & HCSSTAT_NO_EVENTS_FILE) != 0) vs_printf(win[10],0,fore[10],back[10], "No Flash events file found. "); else vs_printf(win[10],0,fore[10],back[10], "Flash events file loaded. "); vs_locatecur(win[10],0,1,4); vs_printf(win[10],0,fore[10],back[10], "Events file (ID=%d): ", hcs_store_id); vs_locatecur(win[10],0,1,5); vs_printf(win[10],0,fore[10],back[10],"%s ",hcs_store_name); } else { vs_printf(win[10],0,fore[10],back[10], "HCS_C connected, powerup OK. "); vs_locatecur(win[10],0,1,4); if ((hcs_info_array[16] & HCSSTAT_NO_EVENTS_FILE) != 0) vs_printf(win[10],0,fore[10],back[10], "No powerup events file found."); else vs_printf(win[10],0,fore[10],back[10], "Powerup events file loaded. "); vs_locatecur(win[10],0,1,5); vs_printf(win[10],0,fore[10],back[10], "No events file, use default. "); } // } // When displaying time, the IO data is tagged along afterwards, so dump it too // into the IO register windows. // Inputs: vs_locatecur(win[11],0,3,3); // Always dump all four bytes line 3 inputdata = hcs_info_array[8]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); inputdata = hcs_info_array[9]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); inputdata = hcs_info_array[10]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[11],0,fore[11],back[11]," "); inputdata = hcs_info_array[11]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[11],0,fore[11],back[11],(inputdata & 0x0001) ? "1":"0"); // Outputs: vs_locatecur(win[12],0,3,3); // Always dump all four bytes line 3 inputdata = hcs_info_array[12]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[12],0,fore[12],back[12],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[12],0,fore[12],back[12]," "); inputdata = hcs_info_array[13]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[12],0,fore[12],back[12],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[12],0,fore[12],back[12]," "); inputdata = hcs_info_array[14]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[12],0,fore[12],back[12],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[12],0,fore[12],back[12]," "); inputdata = hcs_info_array[15]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[12],0,fore[12],back[12],(inputdata & 0x0001) ? "1":"0"); // Now dump the HCS_COMOBO query data in bit form. This currently reads the data from // the last module queried. HCS_COMBO dumps 22 16 bit words, starting with pairs at // hcs_info_array[17] (note that this is one less than the corresponding int_array_ptr // in the firmware hcs_xpress_int_utils, because that has to also output an initial // special character 80h that is absorbed by the initial curtime character in // main (the main loop UART char command section). // // The format is dependent on the device ID, the first two bytes are the device // type and device address. The device type indicates how to display the data. device_array_ptr = 17; while ((device_type = hcs_info_array[device_array_ptr]) != 0) { // DisplayDeviceMessage(device_type); device_array_ptr += 2; switch (device_type) { case ID_HCS_COMBO: // status vs_locatecur(win[13],0,19,1); inputdata = hcs_info_array[device_array_ptr + 43]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 42]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // IO vs_locatecur(win[13],0,19,2); inputdata = hcs_info_array[device_array_ptr + 15]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 14]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // IO occurred vs_locatecur(win[13],0,19,3); inputdata = hcs_info_array[device_array_ptr + 17]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 16]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // Opto vs_locatecur(win[13],0,19,7); inputdata = hcs_info_array[device_array_ptr + 1]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 0]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // Opto occurred vs_locatecur(win[13],0,19,8); inputdata = hcs_info_array[device_array_ptr + 3]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 2]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // Relays vs_locatecur(win[13],0,19,4); inputdata = hcs_info_array[device_array_ptr + 5]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 4]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // Voice vs_locatecur(win[13],0,19,5); inputdata = hcs_info_array[device_array_ptr + 7]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 6]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // IO dir vs_locatecur(win[13],0,19,9); inputdata = hcs_info_array[device_array_ptr + 13]; for (i=1; i<=8; i++, inputdata = inputdata << 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); inputdata = hcs_info_array[device_array_ptr + 12]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) { if ((inputdata & 0x80) == 0) vs_printf(win[13],0,fore[13],back[13],"0"); else vs_printf(win[13],0,fore[13],back[13],"1"); } vs_printf(win[13],0,fore[13],back[13]," "); // Keyboard vs_locatecur(win[13],0,19,10); inputdata = hcs_info_array[device_array_ptr + 9]; vs_printf(win[13],0,fore[13],back[13]," %c (%x) stat %x ", hcs_info_array[device_array_ptr + 8], hcs_info_array[device_array_ptr + 8], hcs_info_array[device_array_ptr + 9]); // Output the analog values vs_locatecur(win[13],0,16,11); vs_printf(win[13],0,fore[13],back[13],"%1.2f %1.2f %1.2f %1.2f", (float)(((hcs_info_array[device_array_ptr + 19] & 3) << 8) | (hcs_info_array[device_array_ptr + 18] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 21] & 3) << 8) | (hcs_info_array[device_array_ptr + 20] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 23] & 3) << 8) | (hcs_info_array[device_array_ptr + 22] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 25] & 3) << 8) | (hcs_info_array[device_array_ptr + 24] & 0xff))/1024.0*5.0); vs_locatecur(win[13],0,16,12); vs_printf(win[13],0,fore[13],back[13],"%1.2f %1.2f %1.2f %1.2f", (float)(((hcs_info_array[device_array_ptr + 27] & 3) << 8) | (hcs_info_array[device_array_ptr + 26] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 29] & 3) << 8) | (hcs_info_array[device_array_ptr + 28] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 31] & 3) << 8) | (hcs_info_array[device_array_ptr + 30] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 33] & 3) << 8) | (hcs_info_array[device_array_ptr + 32] & 0xff))/1024.0*5.0); vs_locatecur(win[13],0,16,13); vs_printf(win[13],0,fore[13],back[13],"%1.2f %1.2f %1.2f %1.2f", (float)(((hcs_info_array[device_array_ptr + 35] & 3) << 8) | (hcs_info_array[device_array_ptr + 34] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 37] & 3) << 8) | (hcs_info_array[device_array_ptr + 36] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 39] & 3) << 8) | (hcs_info_array[device_array_ptr + 38] & 0xff))/1024.0*5.0, (float)(((hcs_info_array[device_array_ptr + 41] & 3) << 8) | (hcs_info_array[device_array_ptr + 40] & 0xff))/1024.0*5.0); break; case ID_HCS_TERM: inputdata = hcs_info_array[device_array_ptr + 2]; vs_locatecur(win[15],0,2,3); inputdata = hcs_info_array[8]; for (i=1; i<=8; i++, inputdata = inputdata >> 1) vs_printf(win[15],0,fore[15],back[15],(inputdata & 0x0001) ? "1":"0"); vs_printf(win[15],0,fore[15],back[15]," "); break; default: break; } } // inputdata = hcs_info_array[16]; // for (i=1; i<=8; i++, inputdata = inputdata >> 1) // vs_printf(win[13],0,fore[13],back[13],(inputdata & 0x0001) ? "1":"0"); // vs_printf(win[13],0,fore[13],back[13]," "); // debugging info // vs_printf(win[10],0,fore[10],back[10],"?%02X", // curr_state); } void SaveStoreStat(void) { int i; char c; // NOTE: The number of bytes MUST exactly equal the number of transmitted // bytes including the last one (CHAR_EOL). Note that the hcs_xpress_int_utils // curr_dump_string number is one greater than this number i. (secs is at // 1 here, but is 2 there). But since you must add one for the status byte, the // numbers are equal). // // The DisplayInfo routine also displays the HCS_C inputs and outputs, and // displays any devices specified in the device list of an events program. // 18 is the size of the basic array with no devices. hcs_store_stat = SioGetc(Port, Tics); hcs_store_id = SioGetc(Port, Tics); for (i=0; i<27; i++) { c = hcs_store_name[i] = SioGetc(Port, Tics); if ((c < 0x80) && (c >= 0x20)) hcs_store_name[i] = c; else hcs_store_name[i] = ' '; hcs_store_name[27] = 0; } } void DisplayMessage(void) { int ch; ch = ' '; wn_openw(win[18]); vs_printf(win[18],0,fore[18],back[18],"!",(char)ch); while ((ch=SioGetc(Port, Tics)) != 0) { if (ch < 0) return; if (ch == 0xd) return; vs_printf(win[18],0,fore[18],back[18],"%1c",(char)ch); } } void DisplayDeviceMessage(int device_num) { wn_openw(win[18]); switch (device_num) { case 0: vs_printf(win[18],0,fore[18],back[18],"Device Done."); break; case 1: vs_printf(win[18],0,fore[18],back[18],"Device CMB."); break; case 2: vs_printf(win[18],0,fore[18],back[18],"Device TERM."); break; } } void DisplayDebugMessage(char c) { char ch; ch = ' '; wn_openw(win[18]); vs_printf(win[18],0,fore[18],back[18],"Comm error: %x ",c); vs_printf(win[18],0,fore[18],back[18],"%02x-",ch & 0xff); while ((ch=SioGetc(Port, Tics)) != 0) { // if (ch < 0) // { // vs_printf(win[18],0,fore[18],back[18],"<->",ch & 0xff); // return; // } if (ch == 0xd) { vs_printf(win[18],0,fore[18],back[18],"",ch & 0xff); return; } vs_printf(win[18],0,fore[18],back[18],"%02x-",ch & 0xff); } } void Happy(void) { sound(600); delay(200); sound(800); delay(200); nosound(); } void sound_alert(void) { sound(600); delay(200); sound(400); delay(200); nosound(); } void NewEvents(void) { FILE *fp; unsigned char old_inactive; char ch; int count=0; // Put up a popup window telling user that a newevents // file is being loaded0G vs_clrvs(win[2],0,fore[2],back[2]); vs_locatecur(win[2],0,2,1); vs_format(win[2],0,fore[2],back[2], "Loading new event program..."); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[2]); inactive_attr = old_inactive; if ((fp=fopen("events.bin", "rb")) == NULL) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "EVENTS.BIN file not found!"); sound_alert(); t2_start = time(NULL); time2 = true; return; } SioPutc(Port, alert); SioPutc(Port, newevnt); // There is a UART messenging collision problem if acks // are used on console commands--the HCS_C may be in the // middle of a transmit command and cannot arbitrarily stop // to send a console command ack. So now console commands // are just sent. If data is to be received (such as an error // condition) the HCS_C will eventually send a message to the // console window. However, this Host code will no longer // expect an ack signal. // while ((char) (c=SioGetc(Port, Tics)) != ack) { // count++; // if ((c < 0) || (count > SERIAL_PORT_TIMEOUT)) // { // vs_format(win[2],0,fore[2],back[2], // "\n\n Download Timeout on HCS_C. Try again."); // sound_alert(); // t2_start = time(NULL); // time2 = true; // return; // } // } count = 0; while (!feof(fp)) { ch = getc(fp); SioPutc(Port, ch); count++; if (count>100) { vs_format(win[2],0,fore[2],back[2],"."); count = 0; } } fclose(fp); ClearWindows(); // c = SioGetc(Port, Tics); // if ((char)c == badver) { // vs_format(win[2],0,fore[2],back[2], // "\n Firmware and COMPILE versions\n don't match. Recompile your code."); // sound_alert(); // t2_start = time(NULL); // time2 = true; // return; // } // else if ((char)c == toobig) { // vs_format(win[2],0,fore[2],back[2], // "\n XPRESS program too big for\n available memory."); // sound_alert(); // t2_start = time(NULL); // time2 = true; // return; // } // else if (((char)c != ack) || (c < 0)) { // vs_format(win[2],0,fore[2],back[2], // "\n Error sending events. No ack."); // vs_printf(win[2],0,fore[2],back[2],"c %x",c); // sound_alert(); // t2_start = time(NULL); // time2 = true; // return; // } vs_format(win[2],0,fore[2],back[2], "\n New events loaded."); Happy(); t2_start = time(NULL); time2 = true; } void SaveEvents(void) { unsigned char old_inactive; char buffer[5]; char name_buffer[50]; int innum, abort = false; int i; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter events array number (0-255): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&innum); if ((innum<0) || (innum>255)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid input number.\n"); delay(1000); abort = true; } for (i = 0;i < 30;i++) // init string to all zeroes (string terminators) name_buffer[i] = 0; vs_printf(win[3],0,fore[3],back[3],"Enter events array name, up to 27 chars:"); vs_gets(win[3],0,true,name_buffer,fore[3],back[3],27); name_buffer[27] = 0; // no more than 27 chars total, force end of string if (!abort) { SioPutc(Port, alert); SioPutc(Port, cmd_save_events); SioPutc(Port, 0x12); // security code to make sure command is real SioPutc(Port, 0x34); SioPutc(Port, 0x01); // select 2nd Flash bank (where events arrays stored SioPutc(Port, 0x82); SioPutc(Port, innum); // send which events token array number to save to. for (i = 0;i < 30;i++) // send name of events file SioPutc(Port,name_buffer[i]); } wn_hidecur(); wn_closew(win[3]); } void RetrieveEvents(void) { unsigned char old_inactive; char buffer[5]; int innum, abort = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter retrieve events array number (0-255): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&innum); if ((innum<0) || (innum>255)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid input number.\n"); delay(1000); abort = true; } if (!abort) { SioPutc(Port, alert); SioPutc(Port, cmd_retrieve_events); SioPutc(Port, innum); // send which events token array number to save to. } wn_hidecur(); wn_closew(win[3]); } void ClearEvents(void) { unsigned char old_inactive; char buffer[5]; int areyousure; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"ARE YOU SURE? This will wipe out ALL stored events arrays: Y? "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%c",&areyousure); if ((areyousure & 0xff) != 'Y') { vs_printf(win[3],0,fore[3],back[3],"\nErase Aborted (%x).\n",areyousure); delay(1000); } else { vs_printf(win[3],0,fore[3],back[3],"\nErase IN PROCESS. Do not powercycle for 5 minutes!\n"); SioPutc(Port, alert); SioPutc(Port, cmd_erase_events); SioPutc(Port, 0x56); // security code to make sure command is real SioPutc(Port, 0x78); SioPutc(Port, 0x01); // select 2nd Flash bank (where events arrays stored SioPutc(Port, 0x82); delay(5000); } wn_hidecur(); wn_closew(win[3]); } void NewTime(void) { struct tm *systime; time_t t; unsigned char old_inactive; int c, done = false, charcnt = 0, replyst = false; vs_clrvs(win[2],0,fore[2],back[2]); vs_puts(win[2],0,2,1,35,fore[2],back[2], "Updating time..."); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[2]); inactive_attr = old_inactive; t = time(NULL); systime = localtime(&t); SioPutc(Port, alert); SioPutc(Port, newtime); SioPutc(Port, '\x00'); /* hundredths of sec */ SioPutc(Port, (char)bcd(systime->tm_sec)); SioPutc(Port, (char)bcd(systime->tm_min)); SioPutc(Port, (char)bcd(systime->tm_hour)); SioPutc(Port, (char)bcd(systime->tm_wday+1)); SioPutc(Port, (char)bcd(systime->tm_mday)); SioPutc(Port, (char)bcd(systime->tm_mon+1)); SioPutc(Port, (char)bcd(systime->tm_year)); while (!done) { c = SioGetc(Port, Tics); charcnt++; if ((c < 0) || (charcnt > 200)) { // vs_puts(win[2],0,2,3,35,fore[2],back[2], // "Time Set Timeout on HCS_C. Try again."); sound_alert(); t2_start = time(NULL); time2 = true; return; } if ((char)c == reply) replyst = true; else if (((char)c == newtime) && replyst) done = true; else replyst = false; } vs_puts(win[2],0,2,3,35,fore[2],back[2], "New time loaded."); Happy(); t2_start = time(NULL); time2 = true; } void DumpLog(void) { // unsigned char old_inactive; // vs_clrvs(win[2],0,fore[2],back[2]); // vs_locatecur(win[2],0,2,1); // vs_format(win[2],0,fore[2],back[2], // "Dumping logged data to disk:"); // old_inactive = inactive_attr; // inactive_attr = black + (lightgray << 4); // wn_openw(win[2]); // inactive_attr = old_inactive; // when setting up a log dump, just send the command. It is not // possible to sit and wait for an acknowledgement, so quit at that // point. When the HCS_C gets the command, it will set up the log // string and eventually send a console command CONSOLE_SENDDUMP // along with the dump data. SioPutc(Port, alert); SioPutc(Port, dumplog); // Happy(); // t2_start = time(NULL); // time2 = true; } // This is now asynchronous from the dumplog command since HCS_C // cannot predictably wait for the dumplog response (other console // strings may be in progress, so there may be substantial delays). void storelog(void) { int c,i; int last = 0; int done = false; int numfilechars = 0; int count = 0; unsigned char *dump; FILE *fp; unsigned char old_inactive; vs_clrvs(win[2],0,fore[2],back[2]); vs_locatecur(win[2],0,2,1); vs_format(win[2],0,fore[2],back[2], "Got to storelog routine."); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[2]); inactive_attr = old_inactive; if ((fp=fopen("logdata.bin", "wb")) == NULL) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Error opening LOGDATA.BIN file!"); sound_alert(); t2_start = time(NULL); time2 = true; return; } dump = malloc(32767); // HCS_C fix 32768 is too big if (!dump) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Error allocating memory!"); sound_alert(); t2_start = time(NULL); time2 = true; return; } i = 0; while (!done) { // start by transferring chars into a memory array. c = SioGetc(Port, Tics); vs_format(win[2],0,fore[2],back[2],">"); dump[i] = (char) c; numfilechars += 1; count++; if (count>255) { vs_format(win[2],0,fore[2],back[2],"."); count = 0; } // if there 0xff char left, assumes is done with the log file if (c==0xff) { last++; if (last>=3) done = true; } else last = 0; // If no more chars to send, output error, ended incorrectly. if (c < 0) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Dump Log failed to get termination. Try again."); sound_alert(); t2_start = time(NULL); time2 = true; return; } i += 1; } if (fwrite(dump, (numfilechars - 3), 1, fp) != 1) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Error writing LOGDATA.BIN file!"); sound_alert(); t2_start = time(NULL); time2 = true; return; } fclose(fp); free(dump); vs_puts(win[2],0,2,3,35,fore[2],back[2], "Logged data saved."); Happy(); t2_start = time(NULL); time2 = true; } void ClearLog(void) { unsigned char old_inactive; int c, done = false, charcnt = 0; int replyst = false; vs_clrvs(win[2],0,fore[2],back[2]); vs_puts(win[2],0,2,1,35,fore[2],back[2], "Clearing log..."); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[2]); inactive_attr = old_inactive; SioPutc(Port, alert); SioPutc(Port, clrlog); while (!done) { c = SioGetc(Port, Tics); charcnt++; if ((c < 0) || (charcnt > SERIAL_PORT_TIMEOUT)) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Clear Log Timeout on HCS_C. Try again."); sound_alert(); t2_start = time(NULL); time2 = true; return; } if ((char)c == reply) replyst = true; else if (((char)c == clrlog) && replyst) done = true; else replyst = false; } vs_puts(win[2],0,2,3,35,fore[2],back[2], "Log storage cleared."); Happy(); t2_start = time(NULL); time2 = true; } void LogSize(void) { unsigned char old_inactive; int c, i, replyst=false, done=false, charcnt=0, size=0; vs_clrvs(win[2],0,fore[2],back[2]); vs_locatecur(win[2],0,1,1); vs_printf(win[2],0,fore[2],back[2]," Getting log size..."); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[2]); inactive_attr = old_inactive; SioPutc(Port, alert); SioPutc(Port, logsize); while (!done) { c = SioGetc(Port, Tics); charcnt++; if ((c < 0) || (charcnt > SERIAL_PORT_TIMEOUT)) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Log Size Timeout on HCS_C. Try again."); sound_alert(); t2_start = time(NULL); time2 = true; return; } if ((char)c == reply) replyst = true; else if (((char)c == logsize) && replyst) done = true; else replyst = false; } for (i=0; i<2; i++) { c = SioGetc(Port, Tics); if (c < 0) { vs_puts(win[2],0,2,3,35,fore[2],back[2], "Log Size Timeout on HCS_C. Try again."); sound_alert(); t2_start = time(NULL); time2 = true; return; } size = size + (i ? c*256 : c); } if (size == 1) vs_printf(win[2],0,fore[2],back[2],"\n\n Log size = %i entry",size); else vs_printf(win[2],0,fore[2],back[2],"\n\n Log size = %i entries",size); t2_start = time(NULL); time2 = true; } void SetInput(void) { unsigned char old_inactive; char state, buffer[5]; int innum, abort = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter input number (0-255): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&innum); if ((innum<0) || (innum>255)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid input number.\n"); delay(1000); abort = true; } if (!abort) { vs_printf(win[3],0,fore[3],back[3],"\nEnter new state (0/1/T): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%c",&state); if ((state!='0') && (state!='1') && (toupper(state)!='T')) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid state.\n"); delay(1000); abort = true; } } if (!abort) { SioPutc(Port, alert); SioPutc(Port, setin); SioPutc(Port, (char) innum); switch (toupper(state)) { case '0': SioPutc(Port, '\x00'); break; case '1': SioPutc(Port, '\x01'); break; case 'T': SioPutc(Port, '\x02'); break; } } wn_hidecur(); wn_closew(win[3]); } void SetOutput(void) { unsigned char old_inactive; char buffer[5]; int outnum, state, abort = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter output number (0-255): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&outnum); if ((outnum<0) || (outnum>255)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid output number.\n"); delay(1000); abort = true; } if (!abort) { vs_printf(win[3],0,fore[3],back[3],"\nEnter new state (0/1): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&state); if ((state!=0) && (state!=1)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid state.\n"); delay(1000); abort = true; } } if (!abort) { SioPutc(Port, alert); SioPutc(Port, setout); SioPutc(Port, (char) outnum); SioPutc(Port, (char) state); } wn_hidecur(); wn_closew(win[3]); } void SetADC(void) { unsigned char old_inactive; char state, buffer[5]; int adcnum, value, abort = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter ADC number (0-135): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&adcnum); if ((adcnum<0) || (adcnum>135)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid ADC number.\n"); delay(1000); abort = true; } if (!abort) { vs_printf(win[3],0,fore[3],back[3],"\nEnter new value (0-4095/T): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%c",&state); if (toupper(state)!='T') { sscanf(buffer,"%i",&value); if ((value<0) || (value>4095)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid value.\n"); delay(1000); abort = true; } } else value = 4096; } if (!abort) { SioPutc(Port, alert); SioPutc(Port, setadc); SioPutc(Port, (char) adcnum); SioPutc(Port, (char) (value%256)); SioPutc(Port, (char) (value/256)); } wn_hidecur(); wn_closew(win[3]); } void SetDAC(void) { unsigned char old_inactive; char buffer[5]; int dacnum, value, abort = false; // SioPutc(Port, alert); // SioPutc(Port, pause); // old_inactive = inactive_attr; // inactive_attr = black + (lightgray << 4); // wn_openw(win[3]); // inactive_attr = old_inactive; // vs_clrvs(win[3],0,fore[3],back[3]); // vs_locatecur(win[3],0,1,1); // wn_showcur(); // vs_printf(win[3],0,fore[3],back[3],"Enter DAC number (0-31): "); // vs_gets(win[3],0,true,buffer,fore[3],back[3],5); // sscanf(buffer,"%i",&dacnum); // if ((dacnum<0) || (dacnum>31)) { // vs_printf(win[3],0,fore[3],back[3],"\nInvalid DAC number.\n"); // delay(1000); // abort = true; // } // if (!abort) { // vs_printf(win[3],0,fore[3],back[3],"\nEnter new value (0-4095): "); // vs_gets(win[3],0,true,buffer,fore[3],back[3],5); // sscanf(buffer,"%i",&value); // if ((value<0) || (value>4095)) { // vs_printf(win[3],0,fore[3],back[3],"\nInvalid value.\n"); // delay(1000); // abort = true; // } // } // if (!abort) { // SioPutc(Port, alert); // SioPutc(Port, setdac); // SioPutc(Port, (char) dacnum); // SioPutc(Port, (char) (value%256)); // SioPutc(Port, (char) (value/256)); // } // wn_hidecur(); // wn_closew(win[3]); } void SetX10(void) { unsigned char old_inactive; char buffer[5], house; int module, func, count = 2, abort = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter house code (A-P): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%c",&house); if ((toupper(house)<'A') || (toupper(house)>'P')) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid house code.\n"); delay(1000); abort = true; } if (!abort) { vs_printf(win[3],0,fore[3],back[3],"Enter module number (1-16): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&module); if ((module<1) || (module>16)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid number.\n"); delay(1000); abort = true; } } if (!abort) { vs_printf(win[3],0,fore[3],back[3],"1=AllUnitsOff, 2=AllLightsOn"); vs_printf(win[3],0,fore[3],back[3],"\n3=On, 4=Off, 5=Dim, 6=Bright"); vs_printf(win[3],0,fore[3],back[3],"\nEnter function code (1-6): "); wn_showcur(); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&func); if ((func<1) || (func>6)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid code.\n"); delay(1000); abort = true; } } if (!abort && func>=5) { vs_printf(win[3],0,fore[3],back[3],"Enter number of steps (1-31): "); wn_showcur(); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&count); if ((count<1) || (count>31)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid number.\n"); delay(1000); abort = true; } } if (!abort) { SioPutc(Port, alert); SioPutc(Port, setx10); SioPutc(Port, (char) (((toupper(house)-'A')<<4) + (module-1))); SioPutc(Port, (char) (func-1)); SioPutc(Port, (char) count); } wn_hidecur(); wn_closew(win[3]); } void SetNetbit(void) { unsigned char old_inactive; char buffer[5]; int bitnum, state, abort = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter netbit number (0-319): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&bitnum); if ((bitnum<0) || (bitnum>319)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid netbit number.\n"); delay(1000); abort = true; } if (!abort) { vs_printf(win[3],0,fore[3],back[3],"\nEnter new state (0/1): "); vs_gets(win[3],0,true,buffer,fore[3],back[3],5); sscanf(buffer,"%i",&state); if ((state!=0) && (state!=1)) { vs_printf(win[3],0,fore[3],back[3],"\nInvalid state.\n"); delay(1000); abort = true; } } if (!abort) { SioPutc(Port, alert); SioPutc(Port, setbit); SioPutc(Port, (char) (bitnum%256)); SioPutc(Port, (char) (bitnum/256)); SioPutc(Port, (char) state); } wn_hidecur(); wn_closew(win[3]); } void NetString(void) { unsigned char old_inactive; char buffer[80]; int i = 0, done = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; while (!done) { i = 0; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter a network command string:\n"); vs_gets(win[3],0,true,buffer,fore[3],back[3],80); wn_hidecur(); if (buffer[0]) { SioPutc(Port, alert); SioPutc(Port, netstr); while (buffer[i]) SioPutc(Port, buffer[i++]); SioPutc(Port, '\x00'); SioPutc(Port, alert); SioPutc(Port, pause); } else done = true; } wn_closew(win[3]); } void VoiceString(void) { unsigned char old_inactive; char buffer[80]; int i = 0, done = false; SioPutc(Port, alert); SioPutc(Port, pause); old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; while (!done) { i = 0; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter a voice string:\n"); vs_gets(win[3],0,true,buffer,fore[3],back[3],80); wn_hidecur(); if (buffer[0]) { SioPutc(Port, alert); SioPutc(Port, vstr); while (buffer[i]) SioPutc(Port, buffer[i++]); SioPutc(Port, '\x00'); SioPutc(Port, alert); SioPutc(Port, pause); } else done = true; } wn_closew(win[3]); } void ModemOut(char str[]) { int i=0; while (str[i]) { SioPutc(Port, str[i]); i++; } } void ModemIn(char str[],int timeout) { int i=0, c=0; char ch; do { ch = SioGetc(Port, timeout*18); str[i++] = ch; if (ch == '\n') c++; } while ((ch > 0) && (c < 2)); if (ch < 0) { i = 0; vs_printf(win[3],0,fore[3],back[3],"\nError communicating with modem.\n"); } str[i] = '0'; } void ModemInit(void) { unsigned char old_inactive; char buffer[30]; old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Current string = %s\n",modinit); vs_printf(win[3],0,fore[3],back[3],"\nEnter new init string: "); vs_gets(win[3],0,true,buffer,fore[3],back[3],30); wn_hidecur(); if (buffer[0]) strcpy(modinit, buffer); else { vs_printf(win[3],0,fore[3],back[3],"Init string unchanged\n"); delay(3000); } wn_closew(win[3]); } void Hangup(void) { SioDTR(Port, 'C'); delay(1000); SioDTR(Port, 'S'); } void Dial(void) { unsigned char old_inactive; char *buf, buffer[30], repbuf[50]; old_inactive = inactive_attr; inactive_attr = black + (lightgray << 4); wn_openw(win[3]); inactive_attr = old_inactive; vs_clrvs(win[3],0,fore[3],back[3]); vs_locatecur(win[3],0,1,1); wn_showcur(); vs_printf(win[3],0,fore[3],back[3],"Enter phone number: "); vs_gets(win[3],0,true,buffer,fore[3],back[3],30); wn_hidecur(); if (buffer[0]) { vs_printf(win[3],0,fore[3],back[3],"Resetting modem..."); SioDTR(Port, 'S'); ModemOut("ATZ\r"); ModemIn(repbuf,4); if (strstr(repbuf,"OK")) { ModemOut(modinit); ModemOut("\r"); ModemIn(repbuf,2); if (strstr(repbuf,"OK")) { vs_printf(win[3],0,fore[3],back[3],"\nDialing %s...",buffer); ModemOut("ATD"); ModemOut(buffer); ModemOut("\r"); ModemIn(repbuf,60); buf = strstr(repbuf,"\r"); vs_printf(win[3],0,fore[3],back[3],"%s",buf); if (strstr(repbuf,"CONNECT")) SioPutc(Port, cr); else Hangup(); } else Hangup(); } else Hangup(); } else vs_printf(win[3],0,fore[3],back[3],"Aborting dial\n"); delay(3000); wn_closew(win[3]); } void SpecialMenu(void) { unsigned char old_active; unsigned int chx; int button, pressed, x, y; int done = false; SioPutc(Port, alert); SioPutc(Port, pause); vs_putcods(win[0],0,2,1,3,black,green,red,green," ~! "); old_active = active_attr; active_attr = black + (lightgray << 4); wn_openw(win[4]); active_attr = old_active; while (!done) { if (mousepresent) { button = 1; kb_mousepressed(&button, &pressed, &x, &y); x = (x/8) + 1; y = (y/8) + 1; if (pressed) { if ((y==3) && (x>3) && (x<12)) { wn_closew(win[4]); wn_openw(win[1]); t1_start = time(NULL); time1 = true; } done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x1e: wn_closew(win[4]); /* A */ wn_openw(win[1]); t1_start = time(NULL); time1 = true; } done = true; } } wn_closew(win[4]); vs_putcods(win[0],0,2,1,3,black,lightgray,red,lightgray," ~! "); SioPutc(Port, alert); SioPutc(Port, update); } int FileMenu(void) { unsigned char old_active; unsigned int chx; int button, pressed, x, y; int done = false, quit = false; SioPutc(Port, alert); SioPutc(Port, pause); vs_putcods(win[0],0,5,1,6,black,green,red,green," ~File "); old_active = active_attr; active_attr = black + (lightgray << 4); wn_openw(win[5]); active_attr = old_active; while (!done) { if (mousepresent) { button = 1; kb_mousepressed(&button, &pressed, &x, &y); x = (x/8) + 1; y = (y/8) + 1; if (pressed) { if ((y==3) && (x>7) && (x<12)) NewEvents(); else if ((y==4) && (x>7) && (x<12)) SaveEvents(); else if ((y==5) && (x>7) && (x<12)) RetrieveEvents(); else if ((y==6) && (x>7) && (x<12)) ClearEvents(); else if ((y==7) && (x>7) && (x<12)) quit = true; done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x26: NewEvents(); /* L */ break; case 0x1f: SaveEvents(); /* S = save token events array */ break; case 0x13: RetrieveEvents(); /* R = retrieve token events array */ break; case 0x12: ClearEvents(); /* E = Clear all token events arrays */ break; case 0x2D: /* X */ case 0x10: quit = true; /* Q */ break; default: testing = chx >> 8; break; } done = true; } } wn_closew(win[5]); vs_putcods(win[0],0,5,1,6,black,lightgray,red,lightgray," ~File "); SioPutc(Port, alert); SioPutc(Port, update); return(quit); } void CommandMenu(void) { unsigned char old_active; unsigned int chx; int button, pressed, x, y; int done = false; SioPutc(Port, alert); SioPutc(Port, pause); vs_putcods(win[0],0,11,1,9,black,green,red,green," ~Command "); old_active = active_attr; active_attr = black + (lightgray << 4); wn_openw(win[6]); active_attr = old_active; while (!done) { if (mousepresent) { button = 1; kb_mousepressed(&button, &pressed, &x, &y); x = (x/8) + 1; y = (y/8) + 1; if (pressed) { if ((y==3) && (x>12) && (x<26)) NewTime(); else if ((y==4) && (x>12) && (x<26)) SetInput(); else if ((y==5) && (x>12) && (x<26)) SetOutput(); else if ((y==6) && (x>12) && (x<26)) SetX10(); else if ((y==7) && (x>12) && (x<26)) SetADC(); else if ((y==8) && (x>12) && (x<26)) SetDAC(); else if ((y==9) && (x>12) && (x<26)) SetNetbit(); else if ((y==10) && (x>12) && (x<26)) VoiceString(); else if ((y==11) && (x>12) && (x<26)) NetString(); done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x14: NewTime(); /* T */ break; case 0x17: SetInput(); /* I */ break; case 0x18: SetOutput(); /* O */ break; case 0x2d: SetX10(); /* X */ break; case 0x1e: SetADC(); /* A */ break; case 0x20: SetDAC(); /* D */ break; case 0x30: SetNetbit(); /* B */ break; case 0x2f: VoiceString(); /* V */ break; case 0x31: NetString(); /* N */ break; } done = true; } } wn_closew(win[6]); vs_putcods(win[0],0,11,1,9,black,lightgray,red,lightgray," ~Command "); SioPutc(Port, alert); SioPutc(Port, update); } void LogMenu(void) { unsigned char old_active; unsigned int chx; int button, pressed, x, y; int done = false; SioPutc(Port, alert); SioPutc(Port, pause); vs_putcods(win[0],0,20,1,5,black,green,red,green," ~Log "); old_active = active_attr; active_attr = black + (lightgray << 4); wn_openw(win[7]); active_attr = old_active; while (!done) { if (mousepresent) { button = 1; kb_mousepressed(&button, &pressed, &x, &y); x = (x/8) + 1; y = (y/8) + 1; if (pressed) { if ((y==3) && (x>21) && (x<27)) ClearLog(); else if ((y==4) && (x>21) && (x<27)) LogSize(); else if ((y==5) && (x>21) && (x<27)) DumpLog(); done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x2e: ClearLog(); /* C */ break; case 0x1f: LogSize(); /* S */ break; case 0x20: DumpLog(); /* D */ break; } done = true; } } wn_closew(win[7]); vs_putcods(win[0],0,20,1,5,black,lightgray,red,lightgray," ~Log "); SioPutc(Port, alert); SioPutc(Port, update); } void WindowMenu(void) { unsigned char old_active; unsigned int chx; int button, pressed, x, y; int done = false; SioPutc(Port, alert); SioPutc(Port, pause); vs_putcods(win[0],0,25,1,8,black,green,red,green," ~Window "); old_active = active_attr; active_attr = black + (lightgray << 4); wn_openw(win[8]); active_attr = old_active; while (!done) { if (mousepresent) { button = 1; kb_mousepressed(&button, &pressed, &x, &y); x = (x/8) + 1; y = (y/8) + 1; if (pressed) { if ((y==3) && (x>26) && (x<39)) wn_openw(win[10]); else if ((y==4) && (x>26) && (x<39)) wn_openw(win[11]); else if ((y==5) && (x>26) && (x<39)) wn_openw(win[12]); else if ((y==6) && (x>26) && (x<39)) wn_openw(win[13]); else if ((y==7) && (x>26) && (x<39)) wn_openw(win[14]); else if ((y==8) && (x>26) && (x<39)) wn_openw(win[15]); else if ((y==9) && (x>26) && (x<39)) wn_openw(win[16]); else if ((y==10) && (x>26) && (x<39)) wn_openw(win[17]); else if ((y==11) && (x>26) && (x<39)) wn_openw(win[18]); done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x14: wn_openw(win[10]); /* T */ break; case 0x20: wn_openw(win[11]); /* D */ break; case 0x18: wn_openw(win[12]); /* O */ break; case 0x31: wn_openw(win[13]); /* N */ break; case 0x2d: wn_openw(win[14]); /* X */ break; case 0x1e: wn_openw(win[15]); /* A */ break; case 0x22: wn_openw(win[16]); /* G */ break; case 0x30: wn_openw(win[17]); /* B */ break; case 0x32: wn_openw(win[18]); /* M */ break; } done = true; } } wn_closew(win[8]); vs_putcods(win[0],0,25,1,8,black,lightgray,red,lightgray," ~Window "); SioPutc(Port, alert); SioPutc(Port, update); } void ModemMenu(void) { unsigned char old_active; unsigned int chx; int button, pressed, x, y; int done = false; SioPutc(Port, alert); SioPutc(Port, pause); vs_putcods(win[0],0,33,1,7,black,green,red,green," ~Modem "); old_active = active_attr; active_attr = black + (lightgray << 4); wn_openw(win[9]); active_attr = old_active; while (!done) { if (mousepresent) { button = 1; kb_mousepressed(&button, &pressed, &x, &y); x = (x/8) + 1; y = (y/8) + 1; if (pressed) { if ((y==3) && (x>34) && (x<42)) ModemInit(); else if ((y==4) && (x>34) && (x<42)) Dial(); else if ((y==5) && (x>34) && (x<42)) Hangup(); done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x17: ModemInit(); /* I */ break; case 0x20: Dial(); /* D */ break; case 0x23: Hangup(); /* H */ break; } done = true; } } wn_closew(win[9]); vs_putcods(win[0],0,33,1,7,black,lightgray,red,lightgray," ~Modem "); SioPutc(Port, alert); SioPutc(Port, update); } main(int argc, char *argv[]) { int error, i, c, done = false, help; int button, pressed, xm, ym, m2, m3, m4; unsigned int rhandle, x, y, offset, chx, shift; wn_init(); curr_state = 0; mousepresent = kb_ismouse(); if (argc>1) { if (!stricmp(argv[1],"/COM1") || !stricmp(argv[2],"/COM1")) { Port = 0; help = false; } if (!stricmp(argv[1],"/COM2") || !stricmp(argv[2],"/COM2")) { Port = 1; help = false; } if (!stricmp(argv[1],"/COM3") || !stricmp(argv[2],"/COM3")) { Port = 2; help = false; } if (!stricmp(argv[1],"/COM4") || !stricmp(argv[2],"/COM4")) { Port = 3; help = false; } if (!stricmp(argv[1],"/M") || !stricmp(argv[2],"/M")) { for (i=0; i<16; i++) { ibm_fcolor_table[i] = 0; ibm_bcolor_table[i] = 7; } ibm_fcolor_table[15] = 15; ibm_fcolor_table[7] = 7; ibm_bcolor_table[0] = 0; help = false; } if (!stricmp(argv[1],"/S") || !stricmp(argv[2],"/S")) { // Speed? } if (help) { printf("\n HCS_C Host Program"); printf("\n Version %1d.%02d\n", version/100, version%100); printf("\n Newest version is at zetaengineering.com/"); printf("\nUsage: HOST {/COM1|/COM2|/COM3|/COM4} {/M}\n"); printf("\nwhere: COM1 = serial port 1"); printf("\n COM2 = serial port 2"); printf("\n COM3 = serial port 3"); printf("\n COM4 = serial port 4"); printf("\n M = monochrome display\n"); return 1; } } if (mousepresent) kb_showmouse(); clrscr(); hcs_store_stat = 0; hcs_store_id = 0xff; sprintf(hcs_store_name,"No events file, using default"); hcs_store_name[29] = 0; error = InitPort(); if (error) { printf("\nError initializing serial port!\n"); kb_hidemouse(); SioDone(Port); return 1; } ReadScreen(); SetupScreen(); SioPutc(Port, cr); SioPutc(Port, alert); SioPutc(Port, update); //////////////////////////////////////////////////////////////////////////////// // MAIN LOOP // //////////////////////////////////////////////////////////////////////////////// while (kbhit()) getch(); // Here is the main host execution loop while (!done) { while (!kbhit() && !done) { if (time1) if (difftime(time(NULL), t1_start) >= 8) { time1 = false; wn_closew(win[1]); } if (time2) if (difftime(time(NULL), t2_start) >= 4) { time2 = false; wn_closew(win[2]); } ////////////////////////////// UART control /////////////// // Check for characters from the console UART if ((c=SioGetc(Port, 0)) >= 0) { if ((char)c == reply) if ((c=SioGetc(Port, Tics)) >= 0) switch ((char) c) { case curtime: DisplayInfo(); break; case x10stat: DisplayModule(); break; case inpstat: DisplayInputs(); break; case outstat: DisplayOutputs(); break; case adcstat: DisplayADCs(); break; case dacstat: DisplayDACs(); break; case modstat: DisplayNetwork(); break; case netstat: DisplayNetbits(); break; case msgdisp: // ??? this is the lcd message token DisplayMessage(); // it should be 97 the console msg break; case msgconsole: // this is the console message token DisplayMessage(); break; case sendlog: // this is the console message token storelog(); break; case storestat: SaveStoreStat(); break; default: DisplayDebugMessage(c + 0xc0); // error condition, display break; } else // error condition, send message DisplayDebugMessage(c + 0x80); } ////////////////////////////// Mouse control /////////////// if (mousepresent) { /* Check for mouse click */ button = 1; kb_mousepressed(&button, &pressed, &xm, &ym); /* Convert to screen coordinates */ x = (xm/8) + 1; y = (ym/8) + 1; if (pressed && (wn_isonwdw(x, y, &rhandle)) && (rhandle == 0) && (y == 1)) { curr_state = 3; /* Do menu bar */ if (x<5) SpecialMenu(); else if ((x>4) && (x<11)) done = FileMenu(); else if ((x>10) && (x<20)) CommandMenu(); else if ((x>19) && (x<25)) LogMenu(); else if ((x>24) && (x<33)) WindowMenu(); else if ((x>32) && (x<40)) ModemMenu(); } else if (pressed && (wn_isonwdw(x, y, &rhandle)) && (rhandle > 0)) { /* Bring window clicked to front */ if (rhandle != last_wdw) { kb_hidemouse(); wn_openw(rhandle); kb_showmouse(); } /* If button pressed, check out where we are */ m2 = 1; kb_mousestatus(&m2, &m3, &m4); if (m2) { /* Do window move */ if (wn_isonubar(rhandle, x, y)) { m2 = 1; /* Flag button as pressed */ offset = x - wdw[rhandle]->physical_x; while (m2 == 1) { kb_mousestatus(&m2, &m3, &m4); x = (m3/8) + 1; y = (m4/8) + 1; if ((wdw[rhandle]->physical_x != (x-offset)) || (wdw[rhandle]->physical_y != y)) { kb_hidemouse(); wn_locatew(rhandle, (x-offset), y); kb_showmouse(); } } } /* Do window size */ else if (wn_isonlrc(rhandle, x, y)){ m2 = 1; /* Flag button as pressed */ while (m2 == 1) { kb_mousestatus(&m2, &m3, &m4); x = (m3/8) + 1; y = (m4/8) + 1; if (((wdw[rhandle]->physical_x + wdw[rhandle]->port_columns + 1) != x) || ((wdw[rhandle]->physical_y + wdw[rhandle]->port_rows + 1) != y)) { kb_hidemouse(); wn_sizet(rhandle, wdw[rhandle]->last_tile, x - wdw[rhandle]->physical_x - wdw[rhandle]->port_columns - 1, y - wdw[rhandle]->physical_y - wdw[rhandle]->port_rows - 1); kb_showmouse(); } } } else if (wn_isonulc(rhandle, x, y)) wn_closew(rhandle); /* Do the scroll bars in the same way */ else if (wn_isonsbd(rhandle, 0, x, y)) { m2 = 1; while (m2 == 1) { kb_mousestatus(&m2, &m3, &m4); kb_hidemouse(); wn_scrollvs(rhandle,0,0,1); kb_showmouse(); wn_sync_tw_to_vs(rhandle, 0); } } else if (wn_isonsbr(rhandle, 0, x, y)) { m2 = 1; while (m2 == 1) { kb_mousestatus(&m2, &m3, &m4); kb_hidemouse(); wn_scrollvs(rhandle,0,1,0); kb_showmouse(); wn_sync_tw_to_vs(rhandle, 0); } } else if (wn_isonsbl(rhandle, 0, x, y)) { m2 = 1; while (m2 == 1) { kb_mousestatus(&m2, &m3, &m4); kb_hidemouse(); wn_scrollvs(rhandle,0,-1,0); kb_showmouse(); wn_sync_tw_to_vs(rhandle, 0); } } else if (wn_isonsbu(rhandle, 0, x, y)) { m2 = 1; while (m2 == 1) { kb_mousestatus(&m2, &m3, &m4); kb_hidemouse(); wn_scrollvs(rhandle,0,0,-1); kb_showmouse(); wn_sync_tw_to_vs(rhandle, 0); } } else if (wn_isonvtw(rhandle, 0, x, y)) { kb_mousestatus(&m2, &m3, &m4); while (m2 == 1) { y = m4/(200/physical_rows) + 1; y = y - (wdw[rhandle]->physical_y + 2); kb_hidemouse(); wn_locatetwabs(rhandle, 0, -1, y); wn_sync_vs_to_tw(rhandle, 0); kb_showmouse(); kb_mousestatus(&m2, &m3, &m4); } } else if (wn_isonhtw(rhandle, 0, x, y)) { kb_mousestatus(&m2, &m3, &m4); while (m2 == 1) { x = m3/(640/physical_columns) + 1; kb_hidemouse(); x = x - (wdw[rhandle]->physical_x + 2); wn_locatetwabs(rhandle, 0, x, -1); wn_sync_vs_to_tw(rhandle, 0); kb_showmouse(); kb_mousestatus(&m2, &m3, &m4); } } else if (wn_isonvrbar(rhandle, 0, x, y)) { y = y - (wdw[rhandle]->physical_y + 2); wn_locatetwabs(rhandle, 0, -1, y); wn_sync_vs_to_tw(rhandle, 0); } else if (wn_isonhbar(rhandle, 0, x, y)) { x = x - (wdw[rhandle]->physical_x + 2); wn_locatetwabs(rhandle, 0, x, -1); wn_sync_vs_to_tw(rhandle, 0); } } /* If it is a single-click, we've got different choices */ else if (pressed) { /* If it is in a virtual screen move the screen's cursor */ if (wn_isonvs(rhandle,0,&x,&y)) vs_locatecur(rhandle,0,x,y); /* We handle single clicks on scroll bars in the same way */ else if (wn_isonsbu(rhandle, 0, x, y)) wn_scrollvs(rhandle,0,0,1); else if (wn_isonsbl(rhandle, 0, x, y)) wn_scrollvs(rhandle,0,1,0); else if (wn_isonsbr(rhandle, 0, x, y)) wn_scrollvs(rhandle,0,-1,0); else if (wn_isonsbd(rhandle, 0, x, y)) wn_scrollvs(rhandle,0,0,-1); else if (wn_isonvrbar(rhandle, 0, x, y)) { y = y - (wdw[rhandle]->physical_y + 2); wn_locatetwabs(rhandle, 0, -1, y); wn_sync_vs_to_tw(rhandle, 0); } else if (wn_isonhbar(rhandle, 0, x, y)) { x = x - (wdw[rhandle]->physical_x + 2); wn_locatetwabs(rhandle, 0, x, -1); wn_sync_vs_to_tw(rhandle, 0); } else if (wn_isonurc(rhandle, x, y)) { kb_hidemouse(); wn_zoomw(); kb_showmouse(); } else if (wn_isonulc(rhandle, x, y)) wn_closew(rhandle); } } } } ////////////////////////////// Keyboard control /////////////// if (kbhit() && !done) { curr_state = 2; chx = kb_getxc(); /* ** FEDC BA98 7654 3210 ** 1--- ---- --1- ---- ** -1-- ---- --1- ---- ** --1- ---- --1- ---- ** ---1 ---- --1- ---- ** ---- 1--- --1- ---- ** ---- -1-- --1- ---- ** ---- --1- --1- ---- ** ---- ---1 --1- -1-- ** ---- ---- 1-1- ---- ** ---- ---- -11- ---- ** ---- ---- --1- ---- ** ---- ---- --11 ---- ** ---- ---- --1- 1--- ** ---- ---- --1- -1-- CTRL (Right) ** ---- ---- --1- --1- Left Shift ** ---- ---- --1- ---1 Right Shift ** */ shift = kb_getshift(); if (!(shift & 0x0008)) { // Bug fix, the character shifted position for keystrokes is // incorrect // switch (chx >> 3) // original shift position switch (chx >> 8) { // Hotkey menu selection case 0x21: done = FileMenu(); /* F */ break; case 0x2e: CommandMenu(); /* C */ break; case 0x26: LogMenu(); /* L */ break; case 0x11: WindowMenu(); /* W */ break; case 0x32: ModemMenu(); /* M */ break; case 0x10: done = true; /* Q */ break; case 0x1c: SioPutc(Port, alert); /* Enter */ SioPutc(Port, update); break; case 0x0f: NextActive(); /* Tab */ break; case 0x53: CloseActive(); /* Delete */ break; case 0x48: MoveActiveUp(); /* Up */ break; case 0x50: MoveActiveDown(); /* Down */ break; case 0x4b: MoveActiveLeft(); /* Left */ break; case 0x4d: MoveActiveRight(); /* Right */ break; default: sound(1000); delay(100); nosound(); } } else { switch (chx >> 8) { case 0x02: SpecialMenu(); /* ! */ break; case 0x48: SizeActiveUp(); /* ShUp */ break; case 0x50: SizeActiveDown(); /* ShDown */ break; case 0x4b: SizeActiveLeft(); /* ShLeft */ break; case 0x4d: SizeActiveRight(); /* ShRight */ break; } } } } SaveScreen(); kb_hidemouse(); wn_restorescr(); v_gotoxy(oldx, oldy); v_curshape(oldb, olde); SioDone(Port); return 0; }