|
|
1.1 ! root 1: /*************************************************************************** ! 2: * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE * ! 3: * is provided to you without charge, and with no warranty. You may give * ! 4: * away copies of JOVE, including sources, provided that this notice is * ! 5: * included in all the files. * ! 6: ***************************************************************************/ ! 7: ! 8: #include "jove.h" ! 9: ! 10: #ifdef IBMPC ! 11: ! 12: /* here come the actual emulation routines */ ! 13: ! 14: #include <dos.h> ! 15: #include <conio.h> ! 16: ! 17: #define BYTE unsigned char ! 18: #define WORD unsigned int ! 19: ! 20: #ifdef MAC ! 21: # undef private ! 22: # define private ! 23: #endif ! 24: ! 25: private BYTE near get_mode proto((void)); ! 26: ! 27: private WORD ! 28: near cur_page proto((void)), ! 29: near get_cur proto((void)); ! 30: ! 31: private void ! 32: near ch_out proto((BYTE, BYTE)), ! 33: near clr_eop proto((void)), ! 34: near cur_advance proto((void)), ! 35: near cur_down proto((void)), ! 36: near cur_left proto((void)), ! 37: near cur_right proto((void)), ! 38: near cur_up proto((void)), ! 39: near line_feed proto((void)), ! 40: near set_cur proto((WORD)), ! 41: near set_mode proto((BYTE)), ! 42: near wherexy proto((BYTE *, BYTE *)); ! 43: ! 44: void near normfun proto((char)), ! 45: near scr_win proto((int, BYTE, BYTE, BYTE, BYTE)), ! 46: near clr_page(), ! 47: near clr_eoln(); ! 48: ! 49: #ifdef MAC ! 50: # undef private ! 51: # define private static ! 52: #endif ! 53: ! 54: #define VIDEO 0x10 ! 55: ! 56: #define intr(n, r) int86((n), (r), (r)); ! 57: ! 58: BYTE CHPL=80, ! 59: LPP=25, ! 60: CUR_PAGE=0, ! 61: C_ATTR = 0x07, ! 62: C_X=0, ! 63: C_Y=0; ! 64: ! 65: int Fgcolor = 7, ! 66: Bgcolor = 0, ! 67: Mdcolor = 0; ! 68: ! 69: void setcolor(fg, bg) ! 70: BYTE fg, bg; ! 71: { ! 72: C_ATTR = ((bg&0xf)<<4)|(fg&0xf); ! 73: } ! 74: ! 75: private ! 76: WORD near cur_page() ! 77: { ! 78: union REGS vr; ! 79: ! 80: vr.h.ah = 0x0f; ! 81: intr(VIDEO, &vr); ! 82: return(vr.h.bh); ! 83: } ! 84: ! 85: private ! 86: void near set_cur(xy) ! 87: WORD xy; ! 88: { ! 89: union REGS vr; ! 90: ! 91: vr.h.bh = CUR_PAGE; ! 92: vr.h.ah = 0x02; ! 93: vr.x.dx = xy; ! 94: intr(VIDEO, &vr); ! 95: } ! 96: ! 97: private ! 98: WORD near get_cur() ! 99: { ! 100: union REGS vr; ! 101: ! 102: vr.h.bh = CUR_PAGE; ! 103: vr.h.ah = 0x03; ! 104: intr(VIDEO, &vr); ! 105: return (vr.x.dx); ! 106: } ! 107: ! 108: private ! 109: BYTE near get_mode() ! 110: { ! 111: union REGS vr; ! 112: ! 113: vr.h.ah = 0x0f; ! 114: intr(VIDEO, &vr); ! 115: return(vr.h.al); ! 116: } ! 117: ! 118: BYTE lpp() ! 119: { ! 120: int far *regen = (int far *) 0x44C; ! 121: int what; ! 122: BYTE chpl(); ! 123: ! 124: what = (*regen&0xff00)/2/chpl(); ! 125: return (what > 43 ? 25 : what); ! 126: } ! 127: ! 128: private ! 129: void near set_mode(n) ! 130: BYTE n; ! 131: { ! 132: union REGS vr; ! 133: ! 134: vr.h.ah = 0x00; ! 135: vr.h.al = n; ! 136: intr(VIDEO, &vr); ! 137: } ! 138: ! 139: #define gotoxy(x,y) set_cur((x)<<8|((y)&0xff)) ! 140: #define cur_mov(x,y) set_cur((C_X=(x))<<8|((C_Y=(y))&0xff)) ! 141: ! 142: private ! 143: void near wherexy( x, y) ! 144: BYTE *x, *y; ! 145: { ! 146: register WORD xy; ! 147: ! 148: xy = get_cur(); ! 149: *x = xy>>8; ! 150: *y = xy&0xff; ! 151: } ! 152: ! 153: #define wherex() C_X ! 154: #define wherey() C_Y ! 155: ! 156: void near scr_win(no, ulr, ulc, lrr, lrc) ! 157: int no; ! 158: BYTE ulr, ulc, lrr, lrc; ! 159: { ! 160: union REGS vr; ! 161: ! 162: if (no >= 0) ! 163: vr.h.ah = 0x06; ! 164: else { ! 165: vr.h.ah = 0x07; ! 166: no = - no; ! 167: } ! 168: vr.h.al = no; ! 169: vr.x.cx = ulr<<8 | ulc; ! 170: vr.x.dx = lrr<<8 | lrc; ! 171: vr.h.bh = C_ATTR; ! 172: intr(VIDEO, &vr); ! 173: } ! 174: ! 175: BYTE chpl() ! 176: { ! 177: union REGS vr; ! 178: ! 179: vr.h.ah = 0x0f; ! 180: intr(VIDEO, &vr); ! 181: return(vr.h.ah); ! 182: } ! 183: ! 184: void near ! 185: clr_page() ! 186: { ! 187: scr_win(0, 0, 0, LPP-1, CHPL-1); ! 188: gotoxy(C_X = 0, C_Y = 0); ! 189: } ! 190: ! 191: private ! 192: void near cur_right() ! 193: { ! 194: if (C_Y < CHPL-1) ! 195: C_Y++; ! 196: gotoxy(C_X, C_Y); ! 197: } ! 198: ! 199: private ! 200: void near cur_up() ! 201: { ! 202: if (C_X) ! 203: C_X--; ! 204: gotoxy(C_X, C_Y); ! 205: } ! 206: ! 207: private ! 208: void near cur_left() ! 209: { ! 210: if (C_Y) ! 211: C_Y--; ! 212: gotoxy(C_X, C_Y); ! 213: } ! 214: ! 215: private ! 216: void near cur_down() ! 217: { ! 218: if (C_X < LPP-1) ! 219: C_X++; ! 220: gotoxy(C_X, C_Y); ! 221: } ! 222: ! 223: private ! 224: void near ch_out(c, n) ! 225: BYTE c, n; ! 226: { ! 227: union REGS vr; ! 228: ! 229: vr.h.ah = 0x09; ! 230: vr.h.al = c; ! 231: vr.h.bl = C_ATTR; ! 232: vr.h.bh = CUR_PAGE; ! 233: vr.x.cx = n; ! 234: intr(VIDEO, &vr); ! 235: } ! 236: ! 237: #define wrch(c) ch_out((c), 1), cur_advance() ! 238: ! 239: #define home_cur() gotoxy(C_X = 0, C_Y = 0) ! 240: ! 241: void near ! 242: clr_eoln() ! 243: { ! 244: ch_out(' ', CHPL-wherey()); ! 245: } ! 246: ! 247: private ! 248: void near clr_eop() ! 249: { ! 250: clr_eoln(); ! 251: scr_win(LPP-1-wherex(), wherex()+1, 0, LPP-1, CHPL-1); ! 252: } ! 253: ! 254: void init_43() ! 255: { ! 256: BYTE far *info = (BYTE far *) 0x487; ! 257: WORD far *CRTC = (WORD far *) 0x463; ! 258: union REGS vr; ! 259: WORD cur; ! 260: ! 261: CUR_PAGE = cur_page(); ! 262: CHPL = chpl(); ! 263: LPP = lpp(); ! 264: ! 265: if (get_mode()!=3) ! 266: set_mode(3); ! 267: cur = get_cur(); ! 268: ! 269: vr.x.ax = 0x1112; ! 270: vr.h.bl = 0; ! 271: intr(VIDEO, &vr); ! 272: ! 273: *info |= 1; ! 274: vr.x.ax = 0x0100; ! 275: vr.h.bh = 0; ! 276: vr.x.cx = 0x0600; ! 277: intr(VIDEO, &vr); ! 278: ! 279: outp(*CRTC, 0x14); ! 280: outp(*CRTC+1, 0x07); ! 281: ! 282: vr.x.ax = 0x1200; ! 283: vr.h.bl = 0x20; ! 284: intr(VIDEO, &vr); ! 285: ! 286: LPP = lpp(); ! 287: ! 288: set_cur(cur); ! 289: wherexy(&C_X, &C_Y); ! 290: } ! 291: ! 292: void reset_43() ! 293: { ! 294: BYTE far *info = (BYTE far *) 0x487; ! 295: WORD far *CRTC = (WORD far *) 0x463; ! 296: union REGS vr; ! 297: ! 298: set_mode(3); ! 299: ! 300: *info &= 128; ! 301: vr.x.ax = 0x0100; ! 302: vr.h.bh = 0x0607; ! 303: vr.x.cx = 0x0607; ! 304: intr(VIDEO, &vr); ! 305: ! 306: outp(*CRTC, 0x14); ! 307: outp(*CRTC+1, 13); ! 308: ! 309: } ! 310: ! 311: #define scr_up() scr_win(1, 0, 0, LPP-1, CHPL-1) ! 312: #define back_space() cur_left() ! 313: ! 314: private ! 315: void near line_feed() ! 316: { ! 317: if (++C_X > LPP-1) { ! 318: C_X = LPP-1; ! 319: scr_up(); ! 320: } ! 321: gotoxy(C_X, C_Y); ! 322: } ! 323: ! 324: #define BELL_P 0x61 /* speaker */ ! 325: #define BELL_D 0x2dc /* 550 hz */ ! 326: #define TIME_P 0x40 /* timer */ ! 327: #define TINI 182 /* 10110110b timer initialization */ ! 328: ! 329: void dobell(x) ! 330: { ! 331: unsigned int n = 0x8888; ! 332: int orgval; ! 333: ! 334: outp(TIME_P+3, TINI); ! 335: outp(TIME_P+2, BELL_D&0xff); ! 336: outp(TIME_P+2, BELL_D>>8); ! 337: orgval = inp(BELL_P); ! 338: outp(BELL_P, orgval|3); /* turn speaker on */ ! 339: while (--n > 0) ! 340: ; ! 341: outp(BELL_P, orgval); ! 342: } ! 343: ! 344: #define carriage_return() gotoxy(wherex(), C_Y = 0) ! 345: ! 346: private ! 347: void near cur_advance() ! 348: { ! 349: if (++C_Y > CHPL-1) { ! 350: C_Y = 0; ! 351: if (++C_X > LPP-1) { ! 352: scr_up(); ! 353: C_X = LPP-1; ! 354: } ! 355: } ! 356: gotoxy(C_X, C_Y); ! 357: } ! 358: ! 359: void init_term() ! 360: { ! 361: if (lpp() == 43) ! 362: reset_43(); ! 363: CUR_PAGE = cur_page(); ! 364: CHPL = chpl(); ! 365: LPP = lpp(); ! 366: wherexy(&C_X, &C_Y); ! 367: } ! 368: ! 369: void near normfun(); ! 370: ! 371: void write_em(s) ! 372: char *s; ! 373: { ! 374: while (*s) ! 375: normfun(*s++); ! 376: } ! 377: ! 378: void write_emif(s) ! 379: char *s; ! 380: { ! 381: if (s) ! 382: write_em(s); ! 383: } ! 384: ! 385: void write_emc(s, n) ! 386: char *s; ! 387: int n; ! 388: { ! 389: while (n--) ! 390: normfun(*s++); ! 391: } ! 392: ! 393: void near normfun(c) ! 394: char c; ! 395: { ! 396: switch (c) { ! 397: case 10: line_feed(); break; ! 398: case 13: carriage_return(); break; ! 399: case 8: back_space(); break; ! 400: case 7: dobell(0); break; ! 401: case 0: break; ! 402: default: wrch(c); ! 403: } ! 404: } ! 405: ! 406: #endif /* IBMPC */ ! 407: ! 408: #ifdef IBMPC ! 409: ! 410: /* No cursor optimization on an IBMPC, this simplifies things a lot. ! 411: Think about it: it would be silly! ! 412: */ ! 413: ! 414: int phystab = 8; ! 415: ! 416: void ! 417: Placur(line, col) ! 418: { ! 419: cur_mov(line, col); ! 420: CapCol = col; ! 421: CapLine = line; ! 422: } ! 423: ! 424: void ! 425: SO_on() ! 426: { ! 427: if (Mdcolor) ! 428: setcolor(Mdcolor&0xf, Mdcolor>>4); ! 429: else ! 430: setcolor(Bgcolor, Fgcolor); ! 431: } ! 432: ! 433: void ! 434: SO_off() ! 435: { ! 436: setcolor(Fgcolor, Bgcolor); ! 437: } ! 438: ! 439: extern int EGA; ! 440: ! 441: void ! 442: ! 443: UnsetTerm(foo) ! 444: char *foo; ! 445: { ! 446: extern int ILI; ! 447: ! 448: Placur(ILI, 0); ! 449: clr_eoln(); ! 450: if (EGA) ! 451: reset_43(); ! 452: } ! 453: ! 454: ! 455: void ! 456: ResetTerm() ! 457: { ! 458: if (EGA) ! 459: init_43(); ! 460: else ! 461: init_term(); ! 462: ! 463: do_sgtty(); /* this is so if you change baudrate or stuff ! 464: like that, JOVE will notice. */ ! 465: ttyset(ON); ! 466: } ! 467: ! 468: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.