/******************************************************************** * * * HCS_C HOST Program * * Version 1.09 * 3/31/2008 Removed Modem support * 8/13/2008 Increased size, added HCSNET support, added term ctl to console * ********************************************************************* * * 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.03 -- Nov 9, 2007 -- Added diagnostic dump command * 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 NUM_WINDOWS 30 #define SERIAL_PORT_TIMEOUT 20000 #define Tics 30 /* 2 seconds */ // Windows 10 and above are static and get their own foreground #define WINDOW_TIME 10 #define WINDOW_DIGIN 11 #define WINDOW_DIGOUT 12 #define WINDOW_CMB0 13 #define WINDOW_CMB1 14 #define WINDOW_CMB2 15 #define WINDOW_CMB3 16 #define WINDOW_MIN0 17 #define WINDOW_MIN1 18 #define WINDOW_MIN2 19 #define WINDOW_MIN3 20 #define WINDOW_TERM0 21 #define WINDOW_TERM1 22 #define WINDOW_TERM2 23 #define WINDOW_TERM3 24 #define WINDOW_DIO0 25 #define WINDOW_DIO1 26 #define WINDOW_DIO2 27 #define WINDOW_DIO3 28 #define WINDOW_MSG 29 // 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 #define HCSSTAT_CHECKSUM_FAIL 0x1 // high byte of status // 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 RET_CHAR '\x0d' #define esc '\x1b' #define CLEAR_CHAR '\x01' #define POS_X_CHAR '\x03' #define POS_Y_CHAR '\x04' #define POS_CHAR '\x05' #define HOME_CHAR '\x06' #define NEWLINE_CHAR '\x07' #define RIGHT_CHAR '\x08' #define LEFT_CHAR '\x09' #define DOWN_CHAR '\x0a' #define UP_CHAR '\x0b' #define alert '!' #define ack '^' #define CONSOLE_ACTION '$' #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 setx10 '\x12' #define setin '\x15' #define setout '\x18' #define CONSOLE_STORE_EVENTS '\x1c' #define CONSOLE_LOAD_EVENTS '\x1d' #define CONSOLE_ERASE_EVENTS '\x1e' #define CONSOLE_DUMP_MEM '\x1f' #define CONSOLE_WRITE_MEM '\x20' #define setadc '\x1b' #define setdac '\x1e' #define setbit '\x23' #define netstr '\x30' #define vstr '\x31' #define HCS_CON_SENDTIME '\x80' #define HCS_CON_SENDSTAT '\x81' #define HCS_CON_SENDLOG '\x82' #define HCS_CON_SENDMSG '\x83' #define HCS_CON_SENDIMG '\x91' #define HCS_CON_SENDCMB '\x92' #define HCS_CON_SENDMIN '\x93' #define HCS_CON_SENDTERM '\x94' #define HCS_CON_SENDDIO '\x95' #define HCS_CON_SENDVDO '\x96' // ID for each type #define ID_END 0 #define ID_HCSNET_IMG 1 #define ID_HCSNET_CMB 2 #define ID_HCSNET_MIN 3 #define ID_HCSNET_TERM 4 #define ID_HCSNET_DIO 5 #define ID_HCSNET_VDO 6 // Offsets into the token array for each set of device pointers to rcv_rs485_0_array #define HCSNET_IMG_OFFSET 2 #define HCSNET_CMB_OFFSET 0x22 #define HCSNET_MIN_OFFSET 0x42 #define HCSNET_TERM_OFFSET 0x62 #define HCSNET_DIO_OFFSET 0x82 #define HCSNET_TERMSIZE_OFFSET 0xa2 #define HCSNET_DIOSIZE_OFFSET 0xb2 // uhhhh... #define HCSNET_ARRAY_CMB_IN 35 // number of receive bytes (note that CMB and MIN send 22 and 5 words #define HCSNET_IMG_SIZE 10 #define HCSNET_CMB_SIZE 22 #define HCSNET_MIN_SIZE 5 #define HCSNET_TERM_SIZE 1 #define HCSNET_DIO_SIZE 1 // 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 void do_window_labels(); extern void do_CMB_window_labels(char); extern void do_MIN_window_labels(char); extern void do_TERM_window_labels(char); extern void do_DIO_window_labels(char); extern void vs_putlabel(char,char*,int,int); 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 display_hcs_default(void); extern void display_hcs_img(void); extern void display_hcs_cmb(void); extern void display_hcs_min(void); extern void display_hcs_term(void); extern void display_hcs_dio(void); extern void SaveStoreStat(void); extern void DisplayMessage(void); extern void DisplayDebugMessage(char); extern void DisplayCmd(char); extern void DisplayMsgMismatch(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 DisplayMemData(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 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 delay(); extern void sound(); extern void nosound(void); extern void show_bin_byte(char,char); extern void show_bin_byte_changed(char,char,char); extern void show_bin_nibble(char,char); extern void show_bin_nibble_changed(char,char,char); extern void show_analog(char,char,char []); extern void do_flybox(char,char,char); // 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 = 109; /* Low two digits must be minor version number */ short hcs_store_id; short hcs_store_stat; char hcs_store_name[100]; unsigned int win[NUM_WINDOWS]; time_t t1_start, t2_start; int time1=false, time2=false, Port=0, mousepresent; int fore[NUM_WINDOWS] = { black, yellow, black, white, black, black, black, black, black, black, yellow, lightgreen, lightgreen, white, white, yellow, yellow, yellow, yellow, white, white, white, white, white, white, white, white, white, white, white }; int back[NUM_WINDOWS] = { lightgray, magenta, magenta, black, lightgray, lightgray, lightgray, lightgray, lightgray, lightgray, blue, red, red, cyan, cyan, magenta, magenta, magenta, magenta, black, black, black, black, black, black, black, black, black, black, black }; unsigned char modinit[40] = "AT&FLT&K3&Q5"; /* Array contains physical_x, physical_y, port_rows, port_columns, and hide for windows 10-32. Seems to only really use physical_x,y? */ // WINDOW_TIME 10 // WINDOW_DIGIN 11 // WINDOW_DIGOUT 12 // WINDOW_CMB0 13 // WINDOW_CMB1 14 // WINDOW_CMB2 15 // WINDOW_CMB3 16 // WINDOW_MIN0 17 // WINDOW_MIN1 18 // WINDOW_MIN2 19 // WINDOW_MIN3 20 // WINDOW_TERM0 21 // WINDOW_TERM1 22 // WINDOW_TERM2 23 // WINDOW_TERM3 24 // WINDOW_DIO0 25 // WINDOW_DIO1 26 // WINDOW_DIO2 27 // WINDOW_DIO3 28 // WINDOW_MSG 29 unsigned int scrn[20][5] = { {45, 2, 5, 34, FALSE}, // 0: Time screen (10) {40, 9, 4, 40, FALSE}, // 1: hcs inputs {40, 15, 4, 40, FALSE}, // 2: hcs outputs {1, 20, 8, 36, FALSE}, // 3: combo 0 screen {1, 30, 8, 36, FALSE}, // 4: combo 1 screen {1, 30, 8, 36, FALSE}, // 5: combo 2 screen {1, 30, 8, 36, FALSE}, // 6: combo 3 screen {40, 21, 8, 22, FALSE}, // 7: min0 screen {40, 28, 8, 22, FALSE}, // 8: min1 screen {40, 35, 8, 22, FALSE}, // 9: min2 screen {40, 42, 8, 22, FALSE}, // 10: min3 screen {1, 40, 2, 40, FALSE}, // 11: term0 screen {1, 44, 2, 40, FALSE}, // 12: term1 screen {1, 44, 2, 40, FALSE}, // 13: term2 screen {1, 44, 2, 40, FALSE}, // 14: term3 screen {1, 48, 3, 32, FALSE}, // 15: dio0 screen {1, 48, 3, 32, FALSE}, // 16: dio1 screen {1, 48, 3, 32, FALSE}, // 17: dio2 screen {1, 48, 3, 32, FALSE}, // 18: dio3 screen {1, 2, 5, 36, FALSE} // 19: msg screen }; unsigned char box5[13] = { '\x0f','»','Ù','È','Í','º','Í','Í', 'Ä','Ä','Ä','Ç','¶' }; 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; return 0; if ((fp=fopen("host.cfg", "wb")) == NULL) return 1; for (i=10; iphysical_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; for (i = 10;i < NUM_WINDOWS;i++) { vs_locatecur(win[i],0,1,1); vs_clrtoend(win[i],0,fore[i],back[i]); } do_window_labels(); } 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); wn_openw(win[0]); /* scroll_bars_on = BOTH_BARS; */ thumbwheels_on = BOTH_BARS; default_box = box5; /////////////// Digital IN window ///////////////////////////////////////// win[WINDOW_DIGIN]= wn_createw(4,40,scrn[WINDOW_DIGIN-10][0], scrn[WINDOW_DIGIN-10][1],1,1,4,40, FALSE,HEAD_ON," Digital In ",NULL); do_flybox(WINDOW_DIGIN,28,40); /////////////// Digital OUT window ///////////////////////////////////////// win[WINDOW_DIGOUT]= wn_createw(4,40, scrn[WINDOW_DIGOUT-10][0],scrn[WINDOW_DIGOUT-10][1],1,1,4,40, FALSE,HEAD_ON," Digital Out ",NULL); do_flybox(WINDOW_DIGOUT,28,40); /////////////// HCS COMBO MODULE window ///////////////////////////////////////// win[WINDOW_CMB0]= wn_createw(8,36, scrn[WINDOW_CMB0-10][0],scrn[WINDOW_CMB0-10][1],1,10,8,36, FALSE,HEAD_ON," HCS COMBO 0 ",NULL); do_flybox(WINDOW_CMB0,29,36); win[WINDOW_CMB1]= wn_createw(8,36, scrn[WINDOW_CMB1-10][0],scrn[WINDOW_CMB1-10][1],1,1,8,36, FALSE,HEAD_ON," HCS COMBO 1 ",NULL); do_flybox(WINDOW_CMB1,29,36); win[WINDOW_CMB2]= wn_createw(8,36, scrn[WINDOW_CMB2-10][0],scrn[WINDOW_CMB2-10][1],1,1,8,36, FALSE,HEAD_ON," HCS COMBO 2 ",NULL); do_flybox(WINDOW_CMB2,29,36); win[WINDOW_CMB3]= wn_createw(8,36, scrn[WINDOW_CMB3-10][0],scrn[WINDOW_CMB3-10][1],1,1,8,36, FALSE,HEAD_ON," HCS COMBO 3 ",NULL); do_flybox(WINDOW_CMB3,29,36); /////////////// TERM MODULE window ///////////////////////////////////////// win[WINDOW_TERM0]= wn_createw(2,36, scrn[WINDOW_TERM0-10][0],scrn[WINDOW_TERM0-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET TERM 0 ",NULL); vs_clrvs(win[WINDOW_TERM0],0,fore[WINDOW_TERM0],back[WINDOW_TERM0]); if (!scrn[WINDOW_TERM0-10][4]) wn_openw(win[WINDOW_TERM0]); win[WINDOW_TERM1]= wn_createw(2,36, scrn[WINDOW_TERM1-10][0],scrn[WINDOW_TERM1-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET TERM 1 ",NULL); vs_clrvs(win[WINDOW_TERM1],0,fore[WINDOW_TERM1],back[WINDOW_TERM1]); if (!scrn[WINDOW_TERM1-10][4]) wn_openw(win[WINDOW_TERM1]); win[WINDOW_TERM2]= wn_createw(2,36, scrn[WINDOW_TERM2-10][0],scrn[WINDOW_TERM2-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET TERM 2 ",NULL); vs_clrvs(win[WINDOW_TERM2],0,fore[WINDOW_TERM2],back[WINDOW_TERM2]); if (!scrn[WINDOW_TERM2-10][4]) wn_openw(win[WINDOW_TERM2]); win[WINDOW_TERM3]= wn_createw(2,36, scrn[WINDOW_TERM3-10][0],scrn[WINDOW_TERM3-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET TERM 3 ",NULL); vs_clrvs(win[WINDOW_TERM3],0,fore[WINDOW_TERM3],back[WINDOW_TERM3]); if (!scrn[WINDOW_TERM3-10][4]) wn_openw(win[WINDOW_TERM3]); /////////////// DIO MODULE window ///////////////////////////////////////// win[WINDOW_DIO0]= wn_createw(2,36, scrn[WINDOW_DIO0-10][0],scrn[WINDOW_DIO0-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET DIO 0 ",NULL); vs_clrvs(win[WINDOW_DIO0],0,fore[WINDOW_DIO0],back[WINDOW_DIO0]); if (!scrn[WINDOW_DIO0-10][4]) wn_openw(win[WINDOW_DIO0]); win[WINDOW_DIO1]= wn_createw(2,36, scrn[WINDOW_DIO1-10][0],scrn[WINDOW_DIO1-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET DIO 1 ",NULL); vs_clrvs(win[WINDOW_DIO1],0,fore[WINDOW_DIO1],back[WINDOW_DIO1]); if (!scrn[WINDOW_DIO1-10][4]) wn_openw(win[WINDOW_DIO1]); win[WINDOW_DIO2]= wn_createw(2,36, scrn[WINDOW_DIO2-10][0],scrn[WINDOW_DIO2-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET DIO 2 ",NULL); vs_clrvs(win[WINDOW_DIO2],0,fore[WINDOW_DIO2],back[WINDOW_DIO2]); if (!scrn[WINDOW_DIO2-10][4]) wn_openw(win[WINDOW_DIO2]); win[WINDOW_DIO3]= wn_createw(2,36, scrn[WINDOW_DIO3-10][0],scrn[WINDOW_DIO3-10][1],1,1,2,36, FALSE,HEAD_ON," HCSNET DIO 3 ",NULL); vs_clrvs(win[WINDOW_DIO3],0,fore[WINDOW_DIO3],back[WINDOW_DIO3]); if (!scrn[WINDOW_DIO3-10][4]) wn_openw(win[WINDOW_DIO3]); /////////////// HCSNet Mini window ///////////////////////////////////////// win[WINDOW_MIN0]= wn_createw(5,40, scrn[WINDOW_MIN0-10][0],scrn[WINDOW_MIN0-10][1],1,1,5,40, FALSE,HEAD_ON," HCS Mini Combo 0 ",NULL); do_flybox(WINDOW_MIN0,28,40); win[WINDOW_MIN1]= wn_createw(5,40, scrn[WINDOW_MIN1-10][0],scrn[WINDOW_MIN1-10][1],1,1,5,40, FALSE,HEAD_ON," HCS Mini Combo 1",NULL); do_flybox(WINDOW_MIN1,1,1); win[WINDOW_MIN2]= wn_createw(5,40, scrn[WINDOW_MIN2-10][0],scrn[WINDOW_MIN2-10][1],1,1,5,40, FALSE,HEAD_ON," HCS Mini Combo 2",NULL); do_flybox(WINDOW_MIN2,28,40); win[WINDOW_MIN3]= wn_createw(5,40, scrn[WINDOW_MIN3-10][0],scrn[WINDOW_MIN3-10][1],1,1,5,40, FALSE,HEAD_ON," HCS Mini Combo 3 ",NULL); do_flybox(WINDOW_MIN3,28,40); //////////////////////// MESSAGE window //////////////////////////////////// // win[WINDOW_MSG]= wn_createw(12,20,scrn[8][0],scrn[8][1],1,1,scrn[8][2],scrn[8][3], win[WINDOW_MSG]= wn_createw(16,36,scrn[WINDOW_MSG-10][0],scrn[WINDOW_MSG-10] [1],1,1,16,36,FALSE,HEAD_ON," Message ",NULL); do_flybox(WINDOW_MSG,28,40); scroll_bars_on = NO_BARS; thumbwheels_on = NO_BARS; default_box = box0; //////////////////////// Time window //////////////////////////////////// win[WINDOW_TIME]= wn_createw(5,34,scrn[WINDOW_TIME-10][0],scrn[WINDOW_TIME-10][1],1,1, scrn[WINDOW_TIME-10][2],scrn[WINDOW_TIME-10][3], FALSE,HEAD_ON,NULL,NULL); do_flybox(WINDOW_TIME,28,40); 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; //////////////////////// Top menu line/////////////////////////////////// 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(7,10,7,2,1,1,7,9,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"); vs_putcods(win[5],0,2,6,6,fore[5],back[5],red,back[5],"~Dump"); vs_putcods(win[5],0,2,7,6,fore[5],back[5],red,back[5],"~Write"); 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(21,14,25,2,1,1,21,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],"HCSNET CMB0"); vs_putcods(win[8],0,2,5,12,fore[8],back[8],red,back[8],"HCSNET CMB1"); vs_putcods(win[8],0,2,6,12,fore[8],back[8],red,back[8],"HCSNET CMB2"); vs_putcods(win[8],0,2,7,12,fore[8],back[8],red,back[8],"HCSNET CMB3"); vs_putcods(win[8],0,2,8,12,fore[8],back[8],red,back[8],"HCSNET MIN0"); vs_putcods(win[8],0,2,9,12,fore[8],back[8],red,back[8],"HCSNET MIN1"); vs_putcods(win[8],0,2,10,12,fore[8],back[8],red,back[8],"HCSNET MIN2"); vs_putcods(win[8],0,2,11,12,fore[8],back[8],red,back[8],"HCSNET MIN3"); vs_putcods(win[8],0,2,12,12,fore[8],back[8],red,back[8],"HCSNET TERM0"); vs_putcods(win[8],0,2,13,12,fore[8],back[8],red,back[8],"HCSNET TERM1"); vs_putcods(win[8],0,2,14,12,fore[8],back[8],red,back[8],"HCSNET TERM2"); vs_putcods(win[8],0,2,15,12,fore[8],back[8],red,back[8],"HCSNET TERM3"); vs_putcods(win[8],0,2,16,12,fore[8],back[8],red,back[8],"HCSNET DIO0"); vs_putcods(win[8],0,2,17,12,fore[8],back[8],red,back[8],"HCSNET DIO1"); vs_putcods(win[8],0,2,18,12,fore[8],back[8],red,back[8],"HCSNET DIO2"); vs_putcods(win[8],0,2,19,12,fore[8],back[8],red,back[8],"HCSNET DIO3"); vs_putcods(win[8],0,2,20,12,fore[8],back[8],red,back[8],"~Message"); win[9] = wn_createw(3,40,27,12,1,1,3,40,FALSE,HEAD_ON,"ALERTS",NULL); vs_clrvs(win[9],0,fore[9],back[9]); vs_putscenter(win[9],0,"WARNING: HCS ALERT",fore[9], back[9],1); do_window_labels(); default_box = box0; win[1] = wn_createw(7,40,20,10,1,1,7,40,FALSE,HEAD_ON,NULL,NULL); vs_clrvs(win[1],0,fore[1],back[1]); 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); 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)2008 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; } void do_window_labels() { vs_clrvs(win[0],0,white,black); vs_putcods(win[0],0,1,1,80,black,lightgray,red,lightgray, " ~! ~File ~Command ~Log ~Window HCS_C HOST Version 1.09"); vs_putscenter(win[WINDOW_DIGIN],0, "33222222 22221111 111111 ",fore[WINDOW_DIGIN],back[WINDOW_DIGIN],1); vs_putscenter(win[WINDOW_DIGIN],0, "10987654 32109876 54321098 76543210",fore[WINDOW_DIGIN],back[WINDOW_DIGIN],2); vs_putscenter(win[WINDOW_DIGOUT],0, "33222222 22221111 111111 ",fore[WINDOW_DIGOUT],back[WINDOW_DIGOUT],1); vs_putscenter(win[WINDOW_DIGOUT],0, "10987654 32109876 54321098 76543210",fore[WINDOW_DIGOUT],back[WINDOW_DIGOUT],2); do_CMB_window_labels(WINDOW_CMB0); do_CMB_window_labels(WINDOW_CMB1); do_CMB_window_labels(WINDOW_CMB2); do_CMB_window_labels(WINDOW_CMB3); do_MIN_window_labels(WINDOW_MIN0); do_MIN_window_labels(WINDOW_MIN1); do_MIN_window_labels(WINDOW_MIN2); do_MIN_window_labels(WINDOW_MIN3); do_TERM_window_labels(WINDOW_TERM0); do_TERM_window_labels(WINDOW_TERM1); do_TERM_window_labels(WINDOW_TERM2); do_TERM_window_labels(WINDOW_TERM3); do_DIO_window_labels(WINDOW_DIO0); do_DIO_window_labels(WINDOW_DIO1); do_DIO_window_labels(WINDOW_DIO2); do_DIO_window_labels(WINDOW_DIO3); } void do_CMB_window_labels(char window) { vs_putlabel(window, "Status",2,1); vs_putlabel(window, "IO",2,2); vs_putlabel(window, "IO dir (1=out)",2,3); vs_putlabel(window, "Relay Opto",2,4); vs_putlabel(window, "Keybd",2,5); vs_putlabel(window, "Analog in",2,6); vs_putlabel(window, "Analog min",2,7); vs_putlabel(window, "Analog max",2,8); } void do_MIN_window_labels(char window) { vs_putlabel(window, "Status",2,1); vs_putlabel(window, "IO",2,2); vs_putlabel(window, "IO dir (1=out)",2,3); vs_putlabel(window, "Relay Opto",2,4); vs_putlabel(window, "Keybd",2,5); } void do_TERM_window_labels(char window) { vs_locatecur(win[window],0,1,1); vs_printf(win[window],0,fore[window],back[window], "TERM%d RCV: ",window - WINDOW_TERM0); } void do_DIO_window_labels(char window) { vs_locatecur(win[window],0,1,1); vs_printf(win[window],0,fore[window],back[window], "DIO%d RCV: ",window - WINDOW_DIO0); } void vs_putlabel(char window,char *label,int x,int y) { vs_locatecur(win[window],0,x,y); vs_printf(win[window],0,fore[window],back[window],label); } void do_flybox(char winsel,char x,char y) { vs_clrvs(win[winsel],0,fore[winsel],back[winsel]); if (!scrn[winsel-10][4]) { wn_flybox(wdw[win[winsel]]->physical_x+ wdw[win[winsel]]->port_columns/2, wdw[win[winsel]]->physical_y+ wdw[win[winsel]]->port_rows/2, 1,1, wdw[win[winsel]]->physical_x, wdw[win[winsel]]->physical_y, wdw[win[winsel]]->port_rows, wdw[win[winsel]]->port_columns, x,y,box1,white,black); wn_openw(win[winsel]); } } 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 > NUM_WINDOWS) return; next = current + 1; if ((next < 10) || (next >= NUM_WINDOWS)) next = 10; // while (wdw[win[next]]->hide && next!=current) { next++; if (next >= NUM_WINDOWS) 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]); } 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); } } // Here is the first of the HCS_C packet display routines that are run every // second. This is the most basic one, showing date and time, system status, // various alerts, and the HCS_C inputs and outputs. It is always run every // second. void display_hcs_default(void) { int i; char hcs_info_array[28]; int input_data; int get_ptr; char rtc_sec,rtc_min,rtc_hour,rtc_dow,rtc_dom,rtc_month,rtc_year; // 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 display_hcs_c 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. // // Version 1.09 now uses a data format that will be compatible with // new hosts (such as the darkbasic 3D host). As usual, there is a an alert // (0x24 '$') to start, a command, and then the expected data in binary // format. By the time any of the Display calls are made, such as this one, the // alert and the command bytes have been removed. // // First, get the standard display info, it is 18 bytes in the following // format--NOTE!! THESE NUMBERS ARE OFFSET -1 FROM WHAT IS SENT BY HCS_C FW // // 0 : rtc_sec // 1-2 : rtc_minute (0x3f), rtc_hour (0xfc0), rtc_dow (0x7000), lsb rtc_dom (0x8000) // 3-4 : msbt rtc_dom (0xf), rtc_month (0xf0), rtc_year (0xff00) // 5-6 : HCS_C inputs port 0 low 16 bits // 7-8: HCS_C inputs port 0 high 16 bits // 9-10: HCS_C outputs port 0 low 16 bits // 11-12: HCS_C outputs port 0 high 16 bits // 13-14: HCS_C status 16 bits // 15-16 HCS_C alerts 16 bits // 17 RET_CHAR get_ptr = 0; for (i=0; i<24; i++) hcs_info_array[i] = '.'; // for (i=0; i<18; i++) // This is an exact count for (i=0; i<18; i++) { hcs_info_array[get_ptr] = SioGetc(Port, Tics); get_ptr += 1; } // Check that whole packet received correctly, if not, abort if (hcs_info_array[17] != RET_CHAR) return; // Now format the various status words rtc_sec = hcs_info_array[0]; rtc_min = hcs_info_array[1] & 0x3f; rtc_hour = (hcs_info_array[1] & 0xc0) >> 6; rtc_hour += ((hcs_info_array[2] & 0xf) << 2); rtc_dow = (hcs_info_array[2] & 0x70) >> 4; rtc_dom = (hcs_info_array[2] & 0x80) >> 7; rtc_dom = rtc_dom + ((hcs_info_array[3] & 0xf) << 1); rtc_month = (hcs_info_array[3] & 0xf0) >> 4; rtc_year = hcs_info_array[4]; // Devices will get their own display command, not done here anymore. // // 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++) // { // input_data = SioGetc(Port, Tics); // hcs_info_array[device_array_ptr] = input_data; // device_array_ptr += 1; // } // } // hcs_info_array[device_array_ptr] = 0; // indicate no more devices vs_locatecur(win[WINDOW_TIME],0,3,1); vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"%02d:%02d:%02d ", rtc_hour, rtc_min, rtc_sec); switch (rtc_dow) { case 1: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Sun, "); break; case 2: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Mon, "); break; case 3: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Tue, "); break; case 4: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Wed, "); break; case 5: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Thu, "); break; case 6: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Fri, "); break; case 7: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Sat, "); break; } switch (rtc_month) { case 1 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Jan "); break; case 2 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Feb "); break; case 3 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Mar "); break; case 4 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Apr "); break; case 5 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"May "); break; case 6 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Jun "); break; case 7 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Jul "); break; case 8 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Aug "); break; case 9 : vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Sep "); break; case 16: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Oct "); break; case 17: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Nov "); break; case 18: vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"Dec "); break; } // ONLY WORKS FOR YEARS AFTER 2000! vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"%02d, 20%02d", rtc_dom, rtc_year & 0xff); // if ((hcs_info_array[16] & 1) != 0) // { // First, clear ID and name fields for (i = 2; i <= 5; i++) { vs_locatecur(win[WINDOW_TIME],0,1,i); vs_printf(win[WINDOW_TIME],0,fore[10],back[10], " "); } vs_locatecur(win[WINDOW_TIME],0,1,3); if ((hcs_info_array[13] & HCSSTAT_LOADVERSION_FAIL) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "EVENTS WRONG VERSION, NO LOAD"); else if ((hcs_info_array[14] & HCSSTAT_CHECKSUM_FAIL) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "EVENTS CHECKSUM FAILURE "); else if ((hcs_info_array[13] & HCSSTAT_STORE_FAIL) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "EVENTS FAILED TO STORE "); else if ((hcs_info_array[13] & HCSSTAT_ERASE_FAIL) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "FLASH FAILED TO ERASE "); else if ((hcs_info_array[13] & HCSSTAT_RS485_FAIL) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "HCSNET TRANSMISSION ERROR "); else if ((hcs_info_array[13] & HCSSTAT_NEWEVENTS) != 0) { vs_printf(win[WINDOW_TIME],0,fore[10],back[10], " New events file loaded. "); vs_locatecur(win[WINDOW_TIME],0,1,4); vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "Events file (ID=new): "); vs_locatecur(win[WINDOW_TIME],0,1,5); vs_printf(win[WINDOW_TIME],0,fore[10],back[10], " "); } else if ((hcs_info_array[13] & HCSSTAT_POWERUP) == 0) { if ((hcs_info_array[13] & HCSSTAT_NO_EVENTS_FILE) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "No Flash events file found. "); else vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "Flash events file loaded. "); vs_locatecur(win[WINDOW_TIME],0,1,4); vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "Events file (ID=%d): ", hcs_store_id); vs_locatecur(win[WINDOW_TIME],0,1,5); vs_printf(win[WINDOW_TIME],0,fore[10],back[10],"%s ",hcs_store_name); } else { vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "HCS_C connected, powerup OK. "); vs_locatecur(win[WINDOW_TIME],0,1,4); if ((hcs_info_array[13] & HCSSTAT_NO_EVENTS_FILE) != 0) vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "No powerup events file found."); else vs_printf(win[WINDOW_TIME],0,fore[10],back[10], "Powerup events file loaded. "); vs_locatecur(win[WINDOW_TIME],0,1,5); vs_printf(win[WINDOW_TIME],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[WINDOW_DIGIN],0,3,3); // Always dump all four bytes line 3 input_data = hcs_info_array[8]; show_bin_byte(input_data,WINDOW_DIGIN); vs_printf(win[WINDOW_DIGIN],0,fore[WINDOW_DIGIN],back[WINDOW_DIGIN]," "); input_data = hcs_info_array[7]; show_bin_byte(input_data,WINDOW_DIGIN); vs_printf(win[WINDOW_DIGIN],0,fore[WINDOW_DIGIN],back[WINDOW_DIGIN]," "); input_data = hcs_info_array[6]; show_bin_byte(input_data,WINDOW_DIGIN); vs_printf(win[WINDOW_DIGIN],0,fore[WINDOW_DIGIN],back[WINDOW_DIGIN]," "); input_data = hcs_info_array[5]; show_bin_byte(input_data,WINDOW_DIGIN); // Outputs: vs_locatecur(win[WINDOW_DIGOUT],0,3,3); // Always dump all four bytes line 3 input_data = hcs_info_array[12]; show_bin_byte(input_data,WINDOW_DIGOUT); vs_printf(win[WINDOW_DIGOUT],0,fore[WINDOW_DIGOUT],back[WINDOW_DIGOUT]," "); input_data = hcs_info_array[11]; show_bin_byte(input_data,WINDOW_DIGOUT); vs_printf(win[WINDOW_DIGOUT],0,fore[WINDOW_DIGOUT],back[WINDOW_DIGOUT]," "); input_data = hcs_info_array[10]; show_bin_byte(input_data,WINDOW_DIGOUT); vs_printf(win[WINDOW_DIGOUT],0,fore[WINDOW_DIGOUT],back[WINDOW_DIGOUT]," "); input_data = hcs_info_array[9]; show_bin_byte(input_data,WINDOW_DIGOUT); input_data = (hcs_info_array[16] << 8) | hcs_info_array[15]; if (input_data != 0) { wn_openw(win[9]); vs_locatecur(win[9],0,11,3); vs_printf(win[9],0,red,white,"HCS ALERT CODE %x",input_data); } else wn_closew(win[9]); // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG], "ALERT %x ",input_data); // debug termination // input_data = (hcs_info_array[WINDOW_MSG] << 8) | hcs_info_array[17]; // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG], "after %x,",input_data); // input_data = (hcs_info_array[20] << 8) | hcs_info_array[19]; // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG], " %x ",input_data); } // These are the remote device display routines. void display_hcs_img(void) { int i; char hcs_info_array[28]; int get_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). // // Version 1.09 now uses a data format that will be compatible with // new hosts (such as the darkbasic 3D host). As usual, there is a an alert // (0x24 '$') to start, a command, and then the expected data in binary // format. By the time any of the Display calls are made, such as this one, the // alert and the command bytes have been removed. // // First, get the standard display info, it is 18 bytes in the following // format--NOTE!! THESE NUMBERS ARE OFFSET -1 FROM WHAT IS SENT BY HCS_C FW // // 0 : rtc_sec // 1-2 : rtc_minute (0x3f), rtc_hour (0xfc0), rtc_dow (0x7000), lsb rtc_dom (0x8000) // 3-4 : msbt rtc_dom (0xf), rtc_month (0xf0), rtc_year (0xff00) // 5-6 : HCS_C inputs port 0 low 16 bits // 7-8: HCS_C inputs port 0 high 16 bits // 9-10: HCS_C outputs port 0 low 16 bits // 11-12: HCS_C outputs port 0 high 16 bits // 13-14: HCS_C status 16 bits // 15-16 HCS_C alerts 16 bits // 17 RET_CHAR get_ptr = 0; for (i=0; i<18; i++) { hcs_info_array[get_ptr] = SioGetc(Port, Tics); get_ptr += 1; } // Now format the various status words } // These are the remote device display routines. void display_hcs_cmb(void) { int i; char hcs_info_array[50]; int input_data; int changed_data; int get_ptr; char window; // 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). // // Version 1.09 now uses a data format that will be compatible with // new hosts (such as the darkbasic 3D host). As usual, there is a an alert // (0x24 '$') to start, a command, and then the expected data in binary // format. By the time any of the Display calls are made, such as this one, the // alert and the command bytes have been removed. // // First, get the standard display info, it is 18 bytes in the following // format--NOTE!! THESE NUMBERS ARE OFFSET -1 FROM WHAT IS SENT BY HCS_C FW // // 0 : rtc_sec // 1-2 : rtc_minute (0x3f), rtc_hour (0xfc0), rtc_dow (0x7000), lsb rtc_dom (0x8000) // 3-4 : msbt rtc_dom (0xf), rtc_month (0xf0), rtc_year (0xff00) // 5-6 : HCS_C inputs port 0 low 16 bits // 7-8: HCS_C inputs port 0 high 16 bits // 9-10: HCS_C outputs port 0 low 16 bits // 11-12: HCS_C outputs port 0 high 16 bits // 13-14: HCS_C status 16 bits // 15-16 HCS_C alerts 16 bits // 17 RET_CHAR // // First, fetch the CMB device address number (0-15). It selects which window to update // NOTE this requires that the number codes for remote devices are in ascending order window = WINDOW_CMB1 + (SioGetc(Port, Tics) & 0xf) - 1; get_ptr = 0; for (i=0; i= 0x20)) hcs_store_name[i] = c; else hcs_store_name[i] = ' '; hcs_store_name[27] = 0; } } void DisplayMessage(void) { int ch; int x,y; ch = ' '; wn_openw(win[WINDOW_MSG]); // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"!",(char)ch); // when needed for diagnostic display of the testing var // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"%x",testing); // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],":",(char)ch); // vs_locatecur(win[WINDOW_DIGIN],0,1,3); // vs_clrtoend(win[WINDOW_DIGIN],0,fore[11],back[11]); while ((ch=SioGetc(Port, Tics)) != 0) { if (ch < 0) return; switch (ch) { case RET_CHAR: return; break; case NEWLINE_CHAR: vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"\n"); break; case POS_X_CHAR: x = SioGetc(Port, Tics); vs_locatecur(win[WINDOW_MSG],0,x,y); break; case POS_Y_CHAR: y = SioGetc(Port, Tics); vs_locatecur(win[WINDOW_MSG],0,x,y); break; case POS_CHAR: x = SioGetc(Port, Tics); y = SioGetc(Port, Tics); vs_locatecur(win[WINDOW_MSG],0,x,y); break; case CLEAR_CHAR: vs_locatecur(win[WINDOW_MSG],0,1,1); vs_clrtoend(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG]); break; case HOME_CHAR: vs_locatecur(win[WINDOW_MSG],0,1,1); break; case RIGHT_CHAR: x = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_x; y = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_y; if (x < wdw[win[WINDOW_MSG]]->tiles[0]->vs_columns) x += 1; vs_locatecur(win[WINDOW_MSG],0,x,y); break; case LEFT_CHAR: x = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_x; y = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_y; if (x > 1) x -= 1; vs_locatecur(win[WINDOW_MSG],0,x,y); break; case DOWN_CHAR: x = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_x; y = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_y; if (y < wdw[win[WINDOW_MSG]]->tiles[0]->vs_rows) y += 1; vs_locatecur(win[WINDOW_MSG],0,x,y); break; case UP_CHAR: x = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_x; y = wdw[win[WINDOW_MSG]]->tiles[0]->cursor_y; if (y > 1) y -= 1; vs_locatecur(win[WINDOW_MSG],0,x,y); break; default: vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"%1c",(char)ch); break; } } } void DisplayCmd(char ch) { wn_openw(win[WINDOW_MSG]); vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"%02x",ch); } void DisplayMemData(void) { int ch; ch = ' '; wn_openw(win[WINDOW_MSG]); vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"%",(char)ch); // when needed for diagnostic display of the testing var // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"%x",testing); // vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],":",(char)ch); vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"Dump:",(char)ch); while ((ch=SioGetc(Port, Tics)) != 0) { if (ch < 0) return; if (ch == RET_CHAR) return; vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"%1c",(char)ch); } } void DisplayDeviceMessage(int device_num) { wn_openw(win[WINDOW_MSG]); switch (device_num) { case 0: vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"Device Done."); break; case 1: vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"Device CMB."); break; case 2: vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"Device TERM."); break; } } void DisplayDebugMessage(char c) { char ch; int ch_count; ch = ' '; ch_count = 0; wn_openw(win[WINDOW_MSG]); vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"Comm error: %x ",c); } void DisplayMsgMismatch(char c) { char ch; int ch_count; ch = ' '; ch_count = 0; wn_openw(win[WINDOW_MSG]); vs_printf(win[WINDOW_MSG],0,fore[WINDOW_MSG],back[WINDOW_MSG],"Message error: %x ",c); } 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, CONSOLE_STORE_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, CONSOLE_LOAD_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, CONSOLE_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 DumpDiag(void) { unsigned char old_inactive; char buffer[8]; char int_buffer[50]; long innum; int abort = false; int i,j; 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 memory address: "); vs_gets(win[3],0,true,buffer,fore[3],back[3],8); sscanf(buffer,"%lx",&innum); if (!abort) { SioPutc(Port, alert); SioPutc(Port, CONSOLE_DUMP_MEM); for (i = 0;i < 8;i++) // send memory address, least sign nibble first { j = 0x40 + (innum & 0xf); // pass nibble at a time, quicky code SioPutc(Port,j); innum = innum >> 4; } SioPutc(Port, 0); } wn_hidecur(); wn_closew(win[3]); } void WriteDiag(void) { unsigned char old_inactive; char buffer[8]; char int_buffer[50]; long writeaddr; long writedata; int abort = false; int i,j; 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 memory address: "); vs_gets(win[3],0,true,buffer,fore[3],back[3],8); sscanf(buffer,"%lx",&writeaddr); vs_printf(win[3],0,fore[3],back[3],"Enter memory data to write: "); vs_gets(win[3],0,true,buffer,fore[3],back[3],8); sscanf(buffer,"%lx",&writedata); if (!abort) { SioPutc(Port, alert); SioPutc(Port, CONSOLE_WRITE_MEM); for (i = 0;i < 8;i++) // send memory address, least sign nibble first { j = 0x40 + (writeaddr & 0xf); // pass nibble at a time, quicky code SioPutc(Port,j); writeaddr = writeaddr >> 4; } for (i = 0;i < 4;i++) // send memory data to write, least sign nibble first { j = 0x40 + (writedata & 0xf); // pass nibble at a time, quicky code SioPutc(Port,j); writedata = writedata >> 4; } SioPutc(Port, 0); } 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 == CONSOLE_ACTION) 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 == CONSOLE_ACTION) 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 == CONSOLE_ACTION) 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; int housemod; 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) ((map_x10_code(toupper(house - 'A'))) + (map_x10_code(module-1) << 4))); // SioPutc(Port, (char) (func-1)); switch(func) { case 1: SioPutc(Port, (char) (0x10)); break; case 2: SioPutc(Port, (char) (0x18)); break; case 3: SioPutc(Port, (char) (0x14)); break; case 4: SioPutc(Port, (char) (0x1c)); break; case 5: SioPutc(Port, (char) (0x12)); break; case 6: SioPutc(Port, (char) (0x1a)); break; default: SioPutc(Port, (char) (0x10)); break; } SioPutc(Port, (char) count); } wn_hidecur(); wn_closew(win[3]); } int map_x10_code(int incode) { switch(incode & 0xf) { case 0x0: return(0x6); case 0x1: return(0x7); case 0x2: return(0x4); case 0x3: return(0x5); case 0x4: return(0x8); case 0x5: return(0x9); case 0x6: return(0xa); case 0x7: return(0xb); case 0x8: return(0xe); case 0x9: return(0xf); case 0xa: return(0xc); case 0xb: return(0xd); case 0xc: return(0x0); case 0xd: return(0x1); case 0xe: return(0x2); case 0xf: return(0x3); default: return(0x0); } } 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 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; else if ((y==8) && (x>7) && (x<12)) DumpDiag(); else if ((y==9) && (x>7) && (x<12)) WriteDiag(); 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; case 0x20: DumpDiag(); /* D */ break; case 0x11: WriteDiag(); /* W */ 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[WINDOW_TIME]); else if ((y==4) && (x>26) && (x<39)) wn_openw(win[WINDOW_DIGIN]); else if ((y==5) && (x>26) && (x<39)) wn_openw(win[WINDOW_DIGOUT]); else if ((y==6) && (x>26) && (x<39)) wn_openw(win[WINDOW_CMB0]); else if ((y==7) && (x>26) && (x<39)) wn_openw(win[WINDOW_CMB1]); else if ((y==8) && (x>26) && (x<39)) wn_openw(win[WINDOW_CMB2]); else if ((y==9) && (x>26) && (x<39)) wn_openw(win[WINDOW_CMB3]); else if ((y==10) && (x>26) && (x<39)) wn_openw(win[WINDOW_MIN0]); else if ((y==11) && (x>26) && (x<39)) wn_openw(win[WINDOW_MIN1]); else if ((y==12) && (x>26) && (x<39)) wn_openw(win[WINDOW_MIN2]); else if ((y==13) && (x>26) && (x<39)) wn_openw(win[WINDOW_MIN3]); else if ((y==14) && (x>26) && (x<39)) wn_openw(win[WINDOW_TERM0]); else if ((y==15) && (x>26) && (x<39)) wn_openw(win[WINDOW_TERM1]); else if ((y==16) && (x>26) && (x<39)) wn_openw(win[WINDOW_TERM2]); else if ((y==17) && (x>26) && (x<39)) wn_openw(win[WINDOW_TERM3]); else if ((y==18) && (x>26) && (x<39)) wn_openw(win[WINDOW_DIO0]); else if ((y==19) && (x>26) && (x<39)) wn_openw(win[WINDOW_DIO1]); else if ((y==20) && (x>26) && (x<39)) wn_openw(win[WINDOW_DIO2]); else if ((y==21) && (x>26) && (x<39)) wn_openw(win[WINDOW_DIO3]); else if ((y==22) && (x>26) && (x<39)) wn_openw(win[WINDOW_MSG]); done = true; } } if (kbhit()) { chx = kb_getxc(); switch (chx >> 8) { case 0x14: wn_openw(win[WINDOW_TIME]); /* T */ break; case 0x20: wn_openw(win[WINDOW_DIGIN]); /* D */ break; case 0x18: wn_openw(win[WINDOW_DIGOUT]); /* O */ break; case 0x31: wn_openw(win[WINDOW_CMB1]); /* N */ break; case 0x2d: wn_openw(win[WINDOW_MIN1]); /* X */ break; case 0x1e: wn_openw(win[WINDOW_TERM1]); /* A */ break; case 0x22: wn_openw(win[WINDOW_MIN1]); /* G */ break; case 0x30: wn_openw(win[17]); /* B */ break; case 0x32: wn_openw(win[WINDOW_MSG]); /* 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); } 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(); physical_rows = 50; 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, RET_CHAR); 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 == CONSOLE_ACTION) { if ((c=SioGetc(Port, Tics)) >= 0) { switch ((char) c) { case HCS_CON_SENDTIME: display_hcs_default(); break; case HCS_CON_SENDIMG: display_hcs_img(); break; case HCS_CON_SENDCMB: display_hcs_cmb(); break; case HCS_CON_SENDMIN: display_hcs_min(); break; case HCS_CON_SENDTERM: display_hcs_term(); break; case HCS_CON_SENDDIO: display_hcs_dio(); break; case HCS_CON_SENDMSG: // this is the console message token DisplayMessage(); break; case HCS_CON_SENDLOG: // HCS_C Says logfile coming storelog(); break; case HCS_CON_SENDSTAT: SaveStoreStat(); break; default: DisplayCmd(c); // error condition, display break; } } } // else // error condition, send message // DisplayCmd(c); } ////////////////////////////// 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 (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 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; }