|
|
1.1 ! root 1: /*----------------------------------------------------------------------------- ! 2: Talking BIOS device driver for the AT&T PC6300. ! 3: Copyright (C) Karl Dahlke 1987 ! 4: This software may be freely used and distributed ! 5: for any non-profit purpose. ! 6: *----------------------------------------------------------------------------- ! 7: */ ! 8: ! 9: /* cursup.c: cursor support; should really be statics */ ! 10: ! 11: #include "speech.h" ! 12: ! 13: #define NLINES 25 /* number of lines on the screen */ ! 14: ! 15: /* variables for screen memory reading, console only, need not be replicated */ ! 16: static short scrncur; /* screen memory cursor */ ! 17: static short temp_s; /* temp cursor into screen memory */ ! 18: static char *temp_b; /* temp cursor into internal buffer */ ! 19: int sdscreenmode; ! 20: static char far *screenmem = (char far *) 0xb8000000; ! 21: ! 22: /* get current character. ! 23: * assumes there is text in the circular buffer, ! 24: * hence the cursor actually points to a valid character. ! 25: * Grab the character from the circular buffer or from screen memory, ! 26: * depending on the value of the flag sdscreenmode. ! 27: * This and subsequent routines access the temp cursor. ! 28: * After a letter or word is read, the temp cursor ! 29: * is copied to the real cursor via cursor_set(). */ ! 30: getc() ! 31: { ! 32: if(sdscreenmode) { ! 33: if(temp_s & 1) return '\r'; ! 34: return screenmem[temp_s]; ! 35: } ! 36: return *(temp_b); ! 37: } /* getc */ ! 38: ! 39: /* increment cursor */ ! 40: incptr() ! 41: { ! 42: if(sdscreenmode) { ! 43: if(temp_s++ & 1) return temp_s == NLINES*80*2; ! 44: if(temp_s % (80*2) != 80*2-1) ++temp_s; ! 45: return 0; ! 46: } ! 47: if(++temp_b == sdc->buftop) temp_b = sdc->bufbot; ! 48: return temp_b == sdc->bufhead; ! 49: } /* incptr */ ! 50: ! 51: /* decrement cursor */ ! 52: decptr() ! 53: { ! 54: char *oldb; ! 55: if(sdscreenmode) { ! 56: if(temp_s-- & 1) return 0; ! 57: if(temp_s < 0) return 1; ! 58: if(temp_s % (80*2) != 80*2-1) --temp_s; ! 59: return 0; ! 60: } ! 61: oldb = temp_b; ! 62: if(oldb == sdc->bufbot) temp_b = sdc->buftop; ! 63: --temp_b; ! 64: return oldb == sdc->buftail; ! 65: } /* decptr */ ! 66: ! 67: cursor_copy() ! 68: { ! 69: if(sdscreenmode) temp_s = scrncur; ! 70: else temp_b = sdc->bufcur; ! 71: } /* cursor_copy */ ! 72: ! 73: cursor_set() ! 74: { ! 75: if(sdscreenmode) scrncur = temp_s; ! 76: else sdc->bufcur = temp_b; ! 77: } /* cursor_set */ ! 78: ! 79: /* is buffer empty? */ ! 80: bufempty() ! 81: { ! 82: return !sdscreenmode && sdc->bufhead == sdc->buftail; ! 83: } /* bufempty */ ! 84: ! 85: /* move cursor to the top of the buffer */ ! 86: buftop() ! 87: { ! 88: if(sdscreenmode) scrncur = 0; ! 89: else sdc->bufcur = sdc->buftail; ! 90: } /* buftop */ ! 91: ! 92: /* move cursor to the bottom of the buffer */ ! 93: bufbot() ! 94: { ! 95: if(sdscreenmode) scrncur = NLINES*80*2 - 1; ! 96: else { ! 97: temp_b = sdc->bufhead; ! 98: decptr(); ! 99: sdc->bufcur = temp_b; ! 100: } ! 101: } /* bufbot */ ! 102: ! 103: /* move temp cursor to the bottom of the buffer */ ! 104: bufbot_temp() ! 105: { ! 106: if(sdscreenmode) temp_s = NLINES*80*2 - 2; ! 107: else temp_b = sdc->bufhead; ! 108: } /* bufbot_temp */ ! 109: ! 110: /* clear the buffer; do not call if sdscreenmode is set */ ! 111: bufclear() ! 112: { ! 113: sdc->bufhead = sdc->bufcur = sdc->buftail; ! 114: } /* bufclear */ ! 115: ! 116: /* find cursor on screen; not yet used */ ! 117: static findcur() ! 118: { ! 119: register i; ! 120: for(i=0; i<NLINES*80*2; i+=2) ! 121: if(screenmem[i] == 0x20 && screenmem[i+1] == 15) { temp_s = i; return 0; } ! 122: return 1; ! 123: } /* findcur */ ! 124: ! 125: /* the previous routines manipulate a virtual reading cursor that lives within ! 126: * the circular buffer or screen memory, depending on the value of the flag ! 127: * sdscreenmode. The following routines exploit the previous routines ! 128: * to move the cursor to the next word, last line, etc. */ ! 129: ! 130: /* back up cursor until new line is reached */ ! 131: backnl() ! 132: { ! 133: short count = 0; ! 134: while(++count, !decptr()) ! 135: if(getc() == '\r') break; ! 136: incptr(); ! 137: return count; ! 138: } /* backnl */ ! 139: ! 140: /* advance cursor past newline */ ! 141: nextnl() ! 142: { ! 143: while(getc() != '\r') ! 144: if(incptr()) return 1; ! 145: return incptr(); ! 146: } /* nextnl */ ! 147: ! 148: /* back up cursor to the beginning of the current symbol */ ! 149: backsym() ! 150: { ! 151: if(!isalnum(getc())) return; ! 152: do ! 153: if(!isalnum(getc())) break; ! 154: while(!decptr()); ! 155: incptr(); ! 156: } /* backsym */ ! 157: ! 158: /* advance cursor to the end of the current symbol */ ! 159: nextsym() ! 160: { ! 161: if(!isalnum(getc())) return; ! 162: do ! 163: if(!isalnum(getc())) break; ! 164: while(!incptr()); ! 165: decptr(); ! 166: } /* nextsym */ ! 167: ! 168: /* search through the buffer for a string */ ! 169: bufsearch(updown, string) ! 170: char updown; /* direction of search */ ! 171: char *string; ! 172: { ! 173: char fail; ! 174: ! 175: if(sdc->oneline) { ! 176: if(updown) { ! 177: backnl(); ! 178: fail = decptr(); ! 179: } else fail = nextnl(); ! 180: } else fail = updown ? decptr() : incptr(); ! 181: if(fail) return 1; ! 182: ! 183: do { ! 184: if(getc() == *string) { ! 185: if(wordmatch(string)) return 0; /* success */ ! 186: } ! 187: fail = updown ? decptr() : incptr(); ! 188: } while(!fail); ! 189: return 1; ! 190: } /* bufsearch */ ! 191: ! 192: static wordmatch(s) ! 193: char *s; ! 194: { ! 195: short count = 0; ! 196: ! 197: if(!*++s) return 1; ! 198: ! 199: while(!incptr()) { ! 200: ++count; /* another advance */ ! 201: if(getc() != *s) break; ! 202: if(!*++s) return 1; ! 203: } /* while matches */ ! 204: ! 205: /* put the cursor back */ ! 206: while(count--) ! 207: if(decptr()) break; ! 208: return 0; ! 209: } /* wordmatch */ ! 210: ! 211: #ifdef MSDOS ! 212: strlen(s) ! 213: char *s; ! 214: { ! 215: int i = 0; ! 216: while(*s++) ++i; ! 217: return i; ! 218: } /* strlen */ ! 219: #endif ! 220:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.