/* functions that perform all the screen updates */ /* <%Z%%M% %Q% sccs %I%> */ /**************************************************************************** screen.c: Date Written: 11/3/95 Written by: John LaBatt Project: COMDEMO.MAK Purpose: These functions setup and display the data on the screen. The function to process a keystroke is also in this module. ****************************************************************************/ #include #include #include #include #include #include "comdemo.h" #include "udrive.h" /* Include the universal driver functions */ /* Set the active window in which the user is editting */ void SetWindow(int type) { int xstart,xend; switch (type) { case DI_WINDOW: xstart = 1; xend = 8; break; case DO_WINDOW: xstart = 9; xend = 17; break; case AI_WINDOW: xstart = 18; xend = 31; break; case AO_WINDOW: xstart = 32; xend = 45; break; case FI_WINDOW: xstart = 46; xend = 63; break; case FO_WINDOW: xstart = 64; xend = 80; break; } _settextwindow(4,xstart,24,xend); _setbkcolor(BLACK); } /* Update the data that is being printed in the discrete window */ void UpdateDiscreteWindow(int type, unsigned char *data) { int j,loc,pow,offs; int maxview; char text[20]; _settextcolor(WHITE); /* Normal non-active color */ SetWindow(type); /* switch to appropriate window */ /* location and offset in array where data is */ offs = startaddr[type] % 8; loc = (startaddr[type] - offs) / 8; pow = 1 << offs; /* compute how many rows to print */ maxview = startaddr[type] + 20; if (maxview > maxaddr[type]) maxview = maxaddr[type]; for(j=startaddr[type];j 0) { /* has been editted but not written */ _settextcolor(RED); sprintf(text,"%3d =%2s",curraddr[type],editstr); } else /* has not been editted */ _settextcolor(BRT_WHITE); } } _outtext(text); pow = pow * 2; if (pow > 128) { loc++; pow = 1; } } } /* Update the data that is being printed in the analog window */ void UpdateAnalogWindow(int type, int *data) { int j; int maxview; char text[20]; _settextcolor(WHITE); /* Normal non-active color */ SetWindow(type); /* switch to appropriate window */ /* compute how many rows to print */ maxview = startaddr[type] + 20; if (maxview > maxaddr[type]) maxview = maxaddr[type]; for(j=startaddr[type];j 0) { /* has been editted but not written */ _settextcolor(RED); sprintf(text,"%3d =%6s",curraddr[type],editstr); } else { /* has not been editted */ _settextcolor(BRT_WHITE); sprintf(text,"%3d =%6d",curraddr[type],data[curraddr[type]]); } } } _outtext(text); } } /* Update the data that is being printed in the float window */ void UpdateFloatWindow(int type, float *data) { int j; int maxview; char text[20]; _settextcolor(WHITE); /* Normal non-active color */ SetWindow(type); /* switch to appropriate window */ /* compute how many rows to print */ maxview = startaddr[type] + 20; if (maxview > maxaddr[type]) maxview = maxaddr[type]; for(j=startaddr[type];j 0) { /* has been editted but not written */ _settextcolor(RED); sprintf(text,"%3d =%12s",curraddr[type],editstr); } else { /* has not been editted */ _settextcolor(BRT_WHITE); sprintf(text,"%3d =%12.1f",curraddr[type],data[curraddr[type]]); } } } _outtext(text); } } /* This function performs all of the screen initialization. */ void InitScreen() { int j; _clearscreen(_GWINDOW); /* Clear the screen */ _displaycursor(_GCURSOROFF); /* Turn cursor off */ /* Print generic information */ _settextwindow(1,1,3,80); _settextposition(1,6); _outtext( "DISCRETE ANALOG FLOATING POINT"); _settextposition(2,2); _outtext( "-------------- -------------------- ------------------------"); _settextposition(3,2); _outtext( "INPUT OUTPUT INPUT OUTPUT INPUT OUTPUT"); _settextwindow(25,60,25,80); _settextcolor(RED); _outtext("ALT-X to Exit"); activewindow = DI_WINDOW; /* Discrete in is default active window */ maxaddr[DI_WINDOW] = MAX_DISCRETE; maxaddr[DO_WINDOW] = MAX_DISCRETE; maxaddr[AI_WINDOW] = MAX_ANALOG; maxaddr[AO_WINDOW] = MAX_ANALOG; maxaddr[FI_WINDOW] = MAX_FLOAT; maxaddr[FO_WINDOW] = MAX_FLOAT; /* All windows start displaying from 0 and have 0 as the active address */ for(j=0;j<6;j++) { startaddr[j] = 0; curraddr[j] = 0; } } /* Clear the screen and turn the cursor back on */ void RestoreScreen() { _settextwindow(1,1,25,80); _settextcolor(WHITE); _clearscreen(_GWINDOW); _displaycursor(_GCURSORON); _settextposition(1,1); } /* This function will process the key that was pressed by the user */ void ProcessKey(UD_CONT *ct) { unsigned char key; key = (char)_getch(); /* get the pressed key */ if (key == 0x00) /* Two character code */ key = (char)(_getch() + 128); switch(key) { case UPARROW: if (editted) { WriteVal(ct); editted = FALSE; } if(curraddr[activewindow] > 0) { curraddr[activewindow]--; if (curraddr[activewindow] < startaddr[activewindow]) startaddr[activewindow]--; } break; case DOWNARROW: if (editted) { WriteVal(ct); editted = FALSE; } if(curraddr[activewindow] < (maxaddr[activewindow] - 1)) { curraddr[activewindow]++; if (curraddr[activewindow] > (startaddr[activewindow] + 19)) startaddr[activewindow]++; } break; case RIGHTARROW: if (editted) { WriteVal(ct); editted = FALSE; } activewindow = (activewindow + 1) % 6; break; case LEFTARROW: if (editted) { WriteVal(ct); editted = FALSE; } if (activewindow == 0) activewindow = 5; else activewindow--; break; case PAGEUP: if (editted) { WriteVal(ct); editted = FALSE; } startaddr[activewindow] = startaddr[activewindow] - 20; curraddr[activewindow] = curraddr[activewindow] - 20; if(startaddr[activewindow] < 0) { curraddr[activewindow] = 0; startaddr[activewindow] = 0; } break; case PAGEDOWN: if (editted) { WriteVal(ct); editted = FALSE; } startaddr[activewindow] = startaddr[activewindow] + 20; curraddr[activewindow] = curraddr[activewindow] + 20; if(startaddr[activewindow] > (maxaddr[activewindow] - 20)) { startaddr[activewindow] = maxaddr[activewindow] - 20; if (startaddr[activewindow] < 0) startaddr[activewindow] = 0; curraddr[activewindow] = maxaddr[activewindow] - 1; } break; case BACKSPACE: if(strlen(editstr) > 0) editstr[strlen(editstr) - 1] = '\0'; if(strlen(editstr) == 0) editted = FALSE; break; case RETURN: if (editted) { WriteVal(ct); editted = FALSE; } break; case TAB: if (editted) { WriteVal(ct); editted = FALSE; } activewindow = (activewindow + 1) % 6; break; case ALTX: quit = TRUE; break; default: /* valid chars depend on which window is active */ switch(activewindow) { case DO_WINDOW: if((key == '0') || (key == '1')) { editted = TRUE; sprintf(editstr,"%c",key); } break; case AO_WINDOW: if(((key >= '0') && (key <= '9')) || (key == '-')) { editted = TRUE; editstr[strlen(editstr) + 1] = '\0'; editstr[strlen(editstr)] = key; } break; case FO_WINDOW: if(((key >= '0') && (key <= '9')) || (key == '.') || (key == '-')) { editted = TRUE; editstr[strlen(editstr) + 1] = '\0'; editstr[strlen(editstr)] = key; } break; } break; } }