Sun Sep 19 18:28:43 1993 Listing crtctrl.h Page: 1 1: /* 2: 3: crtctrl.h -- definitions about crt control sequence for PC-98series 4: 5: revision history 6: 0.0: Sep. 21, 1991 by Dai Ishijima 7: 8: */ 9: 10: #define TEXT_ON 1 11: #define TEXT_OFF 0 12: #define TEXT_GRAPH 3 13: #define TEXT_KANJI 0 14: 15: #define TEXT_DEFAULT 0 16: #define TEXT_HILIGHT 1 17: #define TEXT_VERLINE 2 18: #define TEXT_UNDLINE 4 19: #define TEXT_BLINK 5 20: #define TEXT_REVERSE 7 21: #define TEXT_BLACK 30 22: #define TEXT_BLUE 18 23: #define TEXT_RED 17 24: #define TEXT_MAZENDA 19 25: #define TEXT_GREEN 20 26: #define TEXT_CYAN 22 27: #define TEXT_YELLOW 21 28: #define TEXT_WHITE 23 29: 30: #define gotoxy(x, y) \ 31: fprintf(stderr, "\033[%d;%dH", (y) + 1, (x) + 1) 32: /* !! x: 0..79, y: 0..24 !! */ 33: #define sysline(s) \ 34: fprintf(stderr, "\033[>1%c", (s) ? 'l' : 'h') 35: #define cursor(s) \ 36: fprintf(stderr, "\033[>5%c", (s) ? 'l' : 'h') 37: #define textmode(m) \ 38: fprintf(stderr, "\033[)%c", ((m) == TEXT_GRAPH) ? '3' : '0') 39: #define clrscr() \ 40: fprintf(stderr, "\033[2J") 41: #define textlines(l) \ 42: fprintf(stderr, "\033[>3%c", ((l) == 20) ? 'h' : 'l') 43: #define textcolor(c) \ 44: fprintf(stderr, "\033[%dm", c) 45: Sun Sep 19 18:28:43 1993 Listing gl.h Page: 1 1: /* 2: 3: gl.h -- graphics lio header 4: 5: */ 6: 7: #define GDEFAULT 0xff 8: #define DIGIAL8 0 9: #define ANALOG8 1 10: #define ANALOG16 2 11: #define SIMPLELINE 0 12: #define SIMPLEBOX 1 13: #define FILLEDBOX 2 14: #define NOSTYLE 0 15: #define USESTYLE 1 16: #define USETILE 2 17: #define SOLIDLINE 0xffff 18: 19: /**/ 20: int ginit(void); 21: void gdcwait(void); 22: int gscreen(int mode, int sw, int active, int display); 23: int gview(int x1, int y1, int x2, int y2, 24: unsigned char background, unsigned char border); 25: int gcolor(int bg, int bd, int fg, int pm); 26: int gpalette(int p, int c); 27: int gcls(void); 28: int gpset(int x, int y, int c); 29: int gline(int x1, int y1, int x2, int y2, 30: unsigned int c, unsigned int code, unsigned int sw, unsigned int c2, 31: unsigned int style, unsigned int tlen, char *tile); 32: int gpoint(int x, int y); 33: /**/ 34: 35: #define setview(x1, y1, x2, y2) \ 36: gview(x1, y1, x2, y2, GDEFAULT, GDEFAULT) 37: #define line(x1, y1, x2, y2) \ 38: gline(x1, y1, x2, y2, \ 39: GDEFAULT, SIMPLELINE, NOSTYLE, 0, 0, 0, NULL) 40: #define styledline(x1, y1, x2, y2, style) \ 41: gline(x1, y1, x2, y2, \ 42: GDEFAULT, SIMPLELINE, USESTYLE, 0, style, 0, NULL) 43: #define styledcline(x1, y1, x2, y2, c, style) \ 44: gline(x1, y1, x2, y2, \ 45: c, SIMPLELINE, USESTYLE, 0, style, 0, NULL) 46: #define box(x1, y1, x2, y2) \ 47: gline(x1, y1, x2, y2, \ 48: GDEFAULT, SIMPLEBOX, NOSTYLE, 0, 0, 0, NULL) 49: #define filledbox(x1, y1, x2, y2) \ 50: gline(x1, y1, x2, y2, \ 51: GDEFAULT, FILLEDBOX, NOSTYLE, 0, 0, 0, NULL) 52: #define cfilledbox(x1, y1, x2, y2, c) \ 53: gline(x1, y1, x2, y2, \ 54: c, FILLEDBOX, NOSTYLE, 0, 0, 0, NULL) 55: #define styledbox(x1, y1, x2, y2, style) \ 56: gline(x1, y1, x2, y2, \ 57: GDEFAULT, SIMPLEBOX, USESTYLE, 0, style, 0, NULL) 58: #define setfcolord(fg) \ 59: gcolor(GDEFAULT, GDEFAULT, fg, DIGIAL8) 60: #define pset(x, y) \ 61: gpset(x, y, GDEFAULT) 62: 63: Sun Sep 19 18:28:43 1993 Listing gpib.h Page: 1 1: /* 2: * 3: */ 4: 5: /* 6: * constants for gpib bios 7: */ 8: 9: /* return codes */ 10: #define GPIB_OK 0x00 11: #define WITHEOI 0x01 12: #define EOIONLY 0x02 13: #define NOEOI 0x80 14: #define TIMEDOUT 0xfe 15: #define ILLEAGAL 0xff 16: #define GPIBERR 0xfc 17: #define FORCEIFC 0xf8 18: 19: /* about DELIMITER */ 20: #define NODELIM 0x00 21: #define DELIMCRLF 0x01 22: #define DELIMCR 0x02 23: #define DELIMLF 0x03 24: #define DELIMEOI 0x80 25: 26: /* about TIMEDOUT */ 27: #define NOTIMEOUT 0 28: 29: /* 30: * function prototypes 31: */ 32: void setstop(void); 33: void setvec(void); 34: int ib_init(void); 35: void ib_close(void); 36: int ib_setdelim(int d); 37: int ib_delim(void); 38: int ib_readsw(void); 39: int ib_readifc(void); 40: int ib_srqstb(void); 41: int ib_srqaddr(void); 42: int ib_srqnores(void); 43: int ib_setifc(int ticks); 44: int ib_setren(void); 45: int ib_resetren(void); 46: int ib_send(int cmdlen, void *cmd, int datlen, void *dat); 47: int ib_recieve(int cmdlen, void *cmd, int *datlen, void *dat); 48: int ib_poll(int n, void *talker); 49: int ib_setsrq(int stb, int eoi); 50: int ib_ppoll(int n, void *listenlist, int ppoll, int ppu); 51: int ib_setppr(int ppr); 52: int ib_timeout(int sec); 53: int ib_chkstb(int *stb, int *eoi); 54: int ib_puts(char *s, int la); 55: int ib_gets(char *s, int size, int ta); 56: 57: /* GPIB command */ 58: #define GTL 0x01 59: #define SDC 0x04 60: #define PPC 0x05 61: #define GET 0x08 62: #define LLO 0x11 63: #define DCL 0x14 64: #define PPU 0x15 Sun Sep 19 18:28:43 1993 Listing gpib.h Page: 2 65: #define SPE 0x18 66: #define SPD 0x19 67: #define LA 0x20 68: #define UNL 0x3F 69: #define TA 0x40 70: #define UNT 0x5F 71: 72: /* 73: * some other macros 74: */ 75: #define talka(a) (TA + (a)) 76: #define lisna(a) (LA + (a)) 77: #define myadr() (ib_readsw() & 0x1f) Sun Sep 19 18:28:43 1993 Listing daisy.h Page: 1 1: /* 2: * daisy.h -- data acquisition system header file 3: */ 4: 5: /* define constants */ 6: #define NTCL 2 /* トランジェントコンバータの台数 */ 7: #define TCLCH 6 /* トランジェントコンバータ1台のチャンネル数 */ 8: #define NDSO 3 /* ストレージオシロの台数 */ 9: #define DSOCH 2 /* ストレージオシロ1台のチャンネル数 */ 10: 11: #define TCLMAXWORDS 4096 12: #define DATABUFSIZ (sizeof(int) * TCLMAXWORDS) 13: #define DSOWORDS 1024 14: 15: #define TCL1 0 16: 17: #define tcladr(tcl) (tcl + 1) 18: #define dsoadr(dso) (dso + 3) 19: #define usetcl(tcl, ch) (1) 20: #define usedso(dso, ch) (1) 21: 22: #define TCLOFS 512 /* トランジェントコンバータのゼロレベル */ 23: #define TCLDIV 100 /* トランジェントコンバータの1div */ 24: #define DSOOFS 128 25: #define DSODIV 25 26: 27: /* データの表示場所 */ 28: #define dsopos(dso, ch) ((dso) * DSOCH + (ch)) 29: #define tclpos(tcl, ch) ((tcl) * TCLCH + (ch) + NDSO * DSOCH) 30: 31: #define QUIT 3 32: #define SAVE 0 33: 34: #define YMENU 20 35: 36: /* chkstat.c */ 37: void checkstatus(int status); 38: 39: /* display.c */ 40: void xyoffset(int n, int *xoff, int *yoff); 41: void drawgrid(int pos); 42: void clrdisp(int pos); 43: void dispdso(int dso, int ch, unsigned char *d); 44: void disptcl(int tcl, int ch, int tclwords, int *d); 45: 46: /* dmenu.c */ 47: void putmenu(int n, char *item[], int sel, int blink); 48: int selmenu(int n, char *item[], int *sel, char *retcond); 49: char *dsavedir(void); 50: char *sdate(void); 51: void putdfree(void); 52: void putcnt(int count); 53: void putsdir(char *s); 54: void putdate(void); 55: int selntcw(int *tcnw); 56: int seldsop(int *dsop); 57: int setsdir(char *sdir); 58: int optmenu(void); 59: void modeset(); 60: int quitmenu(void); 61: int waittrigger(int cnt); 62: 63: /* getdata.c */ 64: void dsopause(int dso); Sun Sep 19 18:28:43 1993 Listing daisy.h Page: 2 65: void dsopauseoff(int dso); 66: void getdso(int dso, int ch, char *d); 67: int tclstatus(int tcl); 68: void tclmode(int tcl, int mode); 69: void tclstart(int tcl, int mode, int ch); 70: void tclstandby(int tcl); 71: int triggered(int tcl); 72: void forcetrig(int tcl); 73: void gettcl(int tcl, int ch, int n, int *d); 74: void savedsobuf(int dso, int ch, char *d); 75: void loaddsobuf(int dso, int ch, char *d); 76: void savetclbuf(int tcl, int ch, char *d); 77: void loadtclbuf(int tcl, int ch, char *d); 78: void getdata(int tclwords); 79: void savedata(int count, char *path, int tclwords); 80: 81: /* getkey.c */ 82: int getkey(void); 83: int getchr(void); 84: 85: /* getline.c */ 86: void cursorpos(int *x, int *y); 87: void delchar(char *s, int pos); 88: void inschar(char *s, int pos, int ch); 89: int setch(int n, char *s, int pos, int ch); 90: int getline(int n, char *s, char *retcond); 91: 92: /* stty.c */ 93: int gtty(int handle); 94: void stty(int mode, int handle); 95: void rawmode(void); 96: void cookedmode(void); Sun Sep 19 18:28:43 1993 Listing daisy.c Page: 1 1: /* 2: * daisy -- data acquisition system 3: */ 4: 5: #include 6: #include 7: #include 8: #include 9: 10: #include "gpib.h" 11: #include "gl.h" 12: #include "crtctrl.h" 13: #include "daisy.h" 14: 15: char path[MAXPATH]; 16: int tclwords; 17: 18: void daisy() 19: { 20: int cnt; 21: int i; 22: int status; 23: 24: cnt = 0; 25: tclwords = 1024; 26: strcpy(path, "d:/"); 27: gscreen(3, 0, 0, 1); 28: gcls(); 29: gscreen(2, 0, 1, 3); 30: for (i = 0; i < (NDSO * DSOCH + NTCL * TCLCH); i++) { 31: drawgrid(i); 32: } 33: gscreen(2, 0, 0, 3); 34: showmenues(cnt, path); 35: cnt = 0; 36: for (i = 0; i < NTCL; i++) { 37: tclstandby(i); 38: } 39: waittrigger(cnt); 40: for (i = 1; i < NTCL; i++) { 41: forcetrig(i); 42: } 43: gotoxy(0, YMENU + 3); 44: fputs("*データ取り込み中* ", stderr); 45: getdata(tclwords); 46: gotoxy(0, YMENU + 3); 47: fputs("*仮保存中* ", stderr); 48: savedata(cnt, path, tclwords); 49: for (;;) { 50: for (i = 0; i < NTCL; i++) { 51: tclstandby(i); 52: } 53: status = waittrigger(cnt); 54: for (i = 1; i < NTCL; i++) { 55: forcetrig(i); 56: } 57: if (status == SAVE) { 58: ++cnt; 59: } 60: else if (status == QUIT) { 61: break; 62: } 63: gotoxy(0, YMENU + 3); 64: fputs("*データ取り込み中* ", stderr); Sun Sep 19 18:28:43 1993 Listing daisy.c Page: 2 65: getdata(tclwords); 66: gotoxy(0, YMENU + 3); 67: fputs("*仮保存中* ", stderr); 68: savedata(cnt, path, tclwords); 69: } 70: } 71: 72: 73: void resetcrt() 74: { 75: cursor(TEXT_ON); 76: sysline(TEXT_ON); 77: cookedmode(); 78: gcls(); 79: } 80: 81: 82: void main() 83: { 84: cursor(TEXT_OFF); 85: sysline(TEXT_OFF); 86: clrscr(); 87: rawmode(); 88: atexit(resetcrt); 89: ginit(); 90: ib_init(); 91: ib_setifc(1000); 92: ib_setren(); 93: sleep(1); 94: ib_setdelim(DELIMEOI); 95: ib_timeout(5); 96: atexit(ib_close); 97: daisy(); 98: ib_resetren(); 99: gscreen(3, 0, 0, 0); 100: gcls(); 101: exit(0); 102: } 103: 104: 105: 106: Sun Sep 19 18:28:43 1993 Listing getdata.c Page: 1 1: /* 2: * getdata.c -- control TCL-005DG and COM7xxx 3: * 4: * 0.0: Jan. 14, 1992 by Dai Ishijima 5: */ 6: 7: #include 8: #include 9: #include 10: #include "gpib.h" 11: #include "gl.h" 12: #include "daisy.h" 13: 14: /* transient converter control word */ 15: #define TOFAST 32 16: #define TOWRITE 96 17: #define TOFIX 160 18: #define TOSLOW 0 19: #define TOSLOWSTART 128 20: #define TOTRANSREADY 16 21: #define TOTRANSSTART 144 22: 23: /* transient converter status word */ 24: #define TCLISINIT 11 25: #define TCLISWRITE 15 26: #define TCLISFIX 14 27: #define TCLISFAST 14 28: #define TCLISSLOW 10 29: #define TCLISRECORD 8 30: 31: #define WAITFORREADY 200 /* [ms] */ 32: 33: static char *progid = "@(#)getdata.c 0.0 (Dai Ishijima) Mar. 7, 1993"; 34: 35: /* system does not have 16 colors board */ 36: #ifndef HAVE16C 37: static unsigned char dsobuf[NDSO][DSOCH][DSOWORDS]; 38: #endif 39: 40: 41: void dsopause(int dso) 42: { 43: ib_puts("PAUSE ON", dsoadr(dso)); 44: } 45: 46: 47: void dsopauseoff(int dso) 48: { 49: ib_puts("PAUSE OFF", dsoadr(dso)); 50: } 51: 52: 53: void getdso(int dso, int ch, char *d) 54: { 55: char cmd[16]; 56: int status, size; 57: 58: ib_puts("WAVE CODE BINARY", dsoadr(dso)); 59: sprintf(cmd, "WAVE OUT CH%d", ch + 1); 60: ib_puts(cmd, dsoadr(dso)); 61: ib_setdelim(DELIMEOI); 62: cmd[0] = UNL; 63: cmd[1] = lisna(myadr()); 64: cmd[2] = talka(dsoadr(dso)); Sun Sep 19 18:28:43 1993 Listing getdata.c Page: 2 65: size = DSOWORDS; 66: status = ib_recieve(3, cmd, &size, d); 67: if (status > NOEOI) { 68: checkstatus(status); 69: exit(1); 70: } 71: } 72: 73: 74: int tclstatus(int tcl) 75: { 76: char cmd[3]; 77: unsigned char status; 78: int size; 79: int retcode; 80: 81: cmd[0] = UNL; 82: cmd[1] = lisna(myadr()); 83: cmd[2] = talka(tcladr(tcl)); 84: size = 1; 85: retcode = ib_recieve(3, cmd, &size, &status); 86: if (retcode > NOEOI) { 87: checkstatus(retcode); 88: exit(1); 89: } 90: return(status); 91: } 92: 93: 94: void tclmode(int tcl, int mode) 95: { 96: char cmd[4]; 97: 98: cmd[0] = UNL; 99: cmd[1] = lisna(tcladr(tcl)); 100: cmd[2] = talka(myadr()); 101: cmd[3] = mode; 102: ib_send(3, cmd, 1, &cmd[3]); 103: } 104: 105: 106: void tclstart(int tcl, int mode, int ch) 107: { 108: char cmd[4]; 109: 110: cmd[0] = UNL; 111: cmd[1] = lisna(tcladr(tcl)); 112: cmd[2] = talka(myadr()); 113: cmd[3] = mode + ch; 114: ib_send(3, cmd, 1, &cmd[3]); 115: } 116: 117: 118: void tclstandby(int tcl) 119: { 120: tclmode(tcl, TOFAST); 121: while (tclstatus(tcl) != TCLISFAST) { 122: tclmode(tcl, TOFAST); 123: } 124: while (tclstatus(tcl) != TCLISWRITE) { 125: tclmode(tcl, TOWRITE); 126: } 127: } 128: Sun Sep 19 18:28:43 1993 Listing getdata.c Page: 3 129: 130: int triggered(tcl) 131: { 132: return(tclstatus(tcl) == TCLISFIX); 133: } 134: 135: 136: void forcetrig(tcl) 137: { 138: tclmode(tcl, TOFIX); 139: } 140: 141: 142: void gettcl(int tcl, int ch, int n, int *d) 143: { 144: char cmd[4]; 145: int size; 146: int status; 147: int i; 148: 149: do { 150: tclmode(tcl, TOTRANSREADY); 151: delay(WAITFORREADY); 152: tclstart(tcl, TOTRANSSTART, ch); 153: cmd[0] = UNL; 154: cmd[1] = lisna(myadr()); 155: cmd[2] = talka(tcladr(tcl)); 156: size = n * sizeof(d[0]); 157: status = ib_recieve(3, cmd, &size, d); 158: for (i = size / sizeof(d[0]); i < n; i++) { 159: d[i] = d[i - 1]; /* もし、指定したワード数を読めなかった時 */ 160: } 161: if (status > NOEOI) { 162: checkstatus(status); 163: } 164: if ((0 <= d[0]) && (d[0] <= 1023) && 165: (size / sizeof(d[0]) < TCLMAXWORDS - 1)) { 166: /* 1バイトだけ読み込む (TCLのバグかなぁ?) */ 167: size = 1; 168: status = ib_recieve(0, cmd, &size, &cmd[3]); 169: if (status > NOEOI) { 170: checkstatus(status); 171: } 172: } 173: if (d[0] < 0 || 1023 < d[0]) { 174: fputs("リトライ...", stderr); 175: } 176: } while (d[0] < 0 || 1023 < d[0]); 177: tclmode(tcl, TOFAST); 178: while (tclstatus(tcl) != TCLISFAST) { 179: tclmode(tcl, TOFAST); 180: } 181: } 182: 183: 184: #define PSELECT 0xa6 /* 描画画面選択レジスタ */ 185: #define PLANE0 0 /* 表GVRAM選択 */ 186: #define PLANE1 1 /* 裏GVRAM選択 */ 187: /* 取り込んだデータは、いったん裏GVRAMに保存しておく */ 188: #define TCLSAVE 0xa800 /* TCL は GVRAM0, 1, 2 */ 189: #define DSOSAVE 0xe000 /* DSO は GVRAM3 に保存する */ 190: 191: 192: #ifdef HAVE16C Sun Sep 19 18:28:43 1993 Listing getdata.c Page: 4 193: void savedsobuf(int dso, int ch, char *d) 194: { 195: int seg; 196: 197: seg = DSOSAVE + (dso * DSOCH + ch) * (DSOWORDS / 16); 198: outp(PSELECT, PLANE1); 199: movedata(FP_SEG((void far *)d), FP_OFF((void far *)d), seg, 0, DSOWORDS); 200: outp(PSELECT, PLANE0); 201: } 202: 203: 204: void loaddsobuf(int dso, int ch, char *d) 205: { 206: int seg; 207: 208: seg = DSOSAVE + (dso * DSOCH + ch) * (DSOWORDS / 16); 209: outp(PSELECT, PLANE1); 210: movedata(seg, 0, FP_SEG((void far *)d), FP_OFF((void far *)d), DSOWORDS); 211: outp(PSELECT, PLANE0); 212: } 213: #else 214: 215: 216: void savedsobuf(int dso, int ch, char *d) 217: { 218: movedata(FP_SEG((void far *)d), FP_OFF((void far *)d), 219: FP_SEG((void far *)dsobuf[dso][ch]), 220: FP_OFF((void far *)dsobuf[dso][ch]), 221: DSOWORDS); 222: } 223: 224: 225: void loaddsobuf(int dso, int ch, char *d) 226: { 227: movedata(FP_SEG((void far *)dsobuf[dso][ch]), 228: FP_OFF((void far *)dsobuf[dso][ch]), 229: FP_SEG((void far *)d), FP_OFF((void far *)d), 230: DSOWORDS); 231: } 232: #endif 233: 234: 235: void savetclbuf(int tcl, int ch, char *d) 236: { 237: int seg; 238: 239: seg = TCLSAVE + (tcl * TCLCH + ch) * (DATABUFSIZ / 16); 240: outp(PSELECT, PLANE1); 241: movedata(FP_SEG((void far *)d), FP_OFF((void far *)d), seg, 0, DATABUFSIZ); 242: outp(PSELECT, PLANE0); 243: } 244: 245: 246: void loadtclbuf(int tcl, int ch, char *d) 247: { 248: int seg; 249: 250: seg = TCLSAVE + (tcl * TCLCH + ch) * (DATABUFSIZ / 16); 251: outp(PSELECT, PLANE1); 252: movedata(seg, 0, FP_SEG((void far *)d), FP_OFF((void far *)d), DATABUFSIZ); 253: outp(PSELECT, PLANE0); 254: } 255: 256: Sun Sep 19 18:28:43 1993 Listing getdata.c Page: 5 257: void getdata(int tclwords) 258: { 259: int dso, tcl, ch; 260: char d[DATABUFSIZ]; 261: 262: ib_setdelim(DELIMCRLF); 263: for (dso = 0; dso < NDSO; dso++) { 264: if (usedso(dso, 0) || usedso(dso, 1)) { 265: dsopause(dso); 266: } 267: } 268: for (dso = 0; dso < NDSO; dso++) { 269: for (ch = 0; ch < DSOCH; ch++) { 270: if (usedso(dso, ch)) { 271: getdso(dso, ch, d); 272: clrdisp(dsopos(dso, ch)); 273: dispdso(dso, ch, d); 274: savedsobuf(dso, ch, d); 275: } 276: } 277: if (usedso(dso, 0) || usedso(dso, 1)) { 278: dsopauseoff(dso); 279: } 280: } 281: ib_setdelim(DELIMEOI); 282: for (tcl = 0; tcl < NTCL; tcl++) { 283: for (ch = 0; ch < TCLCH; ch++) { 284: if (usetcl(tcl, ch)) { 285: gettcl(tcl, ch, tclwords, (int *)d); 286: clrdisp(tclpos(tcl, ch)); 287: disptcl(tcl, ch, tclwords, (int *)d); 288: savetclbuf(tcl, ch, d); 289: } 290: } 291: } 292: } 293: 294: 295: void savedata(int count, char *path, int tclwords) 296: { 297: int dso, tcl; 298: int ch; 299: char fnam[MAXPATH]; 300: char d[DATABUFSIZ]; 301: FILE *fp; 302: 303: for (dso = 0; dso < NDSO; dso++) { 304: for (ch = 0; ch < DSOCH; ch++) { 305: if (usedso(dso, ch)) { 306: loaddsobuf(dso, ch, d); 307: sprintf(fnam, "%sdso%d%d.%03d", path, dso + 1, ch + 1, count); 308: if ((fp = fopen(fnam, "wb")) == NULL) { 309: fprintf(stderr, "can't open %s\n", fnam); 310: exit(1); 311: } 312: fwrite(d, sizeof(char), DSOWORDS, fp); 313: fclose(fp); 314: } 315: } 316: } 317: for (tcl = 0; tcl < NTCL; tcl++) { 318: for (ch = 0; ch < TCLCH; ch++) { 319: if (usetcl(tcl, ch)) { 320: loadtclbuf(tcl, ch, d); Sun Sep 19 18:28:43 1993 Listing getdata.c Page: 6 321: sprintf(fnam, "%stcl%d%d.%03d", path, tcl + 1, ch + 1, count); 322: if ((fp = fopen(fnam, "wb")) == NULL) { 323: fprintf(stderr, "can't open %s\n", fnam); 324: exit(1); 325: } 326: fwrite(d, sizeof(int), tclwords, fp); 327: fclose(fp); 328: } 329: } 330: } 331: } Sun Sep 19 18:28:43 1993 Listing display.c Page: 1 1: /* 2: * display.c -- display data on graphics screen 3: */ 4: 5: #include 6: 7: #include "gl.h" 8: #include "daisy.h" 9: 10: #define XDIV 10 11: #define YDIV 8 12: #define DIVSIZ 10 13: #define STYLE 0xaaaa 14: #define BLACK 0 15: 16: static char *progid = "@(#)display.c (Dai Ishijima) Jan. 14, 1993"; 17: 18: 19: void xyoffset(int n, int *xoff, int *yoff) 20: { 21: *xoff = 108 * (n % 6) - ((n % 6) > 2); 22: *yoff = 16 + 112 * (n / 6); 23: } 24: 25: 26: void drawgrid(int pos) 27: { 28: int x, y; 29: int xoff, yoff; 30: int style; 31: 32: style = STYLE; 33: xyoffset(pos, &xoff, &yoff); 34: for (x = 0; x <=XDIV; x++) { 35: styledline(x * DIVSIZ + xoff, yoff, 36: x * DIVSIZ + xoff, YDIV * DIVSIZ + yoff, 37: style); 38: } 39: for (y = 0; y <= YDIV; y++) { 40: styledline(xoff, y * DIVSIZ + yoff, 41: XDIV * DIVSIZ + xoff, y * DIVSIZ + yoff, 42: style); 43: } 44: } 45: 46: 47: void clrdisp(int pos) 48: { 49: int xoff, yoff; 50: 51: xyoffset(pos, &xoff, &yoff); 52: cfilledbox(xoff, yoff, xoff + XDIV * DIVSIZ, yoff + YDIV * DIVSIZ, BLACK); 53: } 54: 55: 56: void dispdso(int dso, int ch, unsigned char *d) 57: { 58: int x, p; 59: int ymin, ymax; 60: int xoff, yoff; 61: 62: xyoffset(dsopos(dso, ch), &xoff, &yoff); 63: p = 0; 64: for (x = 0; x <= XDIV * DIVSIZ; x++) { Sun Sep 19 18:28:43 1993 Listing display.c Page: 2 65: ymin = ymax = d[p]; 66: while (p < (long)x * DSOWORDS / (long)(XDIV * DIVSIZ)) { 67: if (ymin > d[p]) { 68: ymin = d[p]; 69: } 70: if (ymax < d[p]) { 71: ymax = d[p]; 72: } 73: ++p; 74: } 75: ymax = (((long)(ymax - DSOOFS)) * DIVSIZ) / (long)DSODIV; 76: ymin = (((long)(ymin - DSOOFS)) * DIVSIZ) / (long)DSODIV; 77: if (ymax > YDIV / 2 * DIVSIZ) { 78: ymax = YDIV / 2 * DIVSIZ; 79: } 80: if (ymin < -YDIV / 2 * DIVSIZ) { 81: ymin = -YDIV / 2 * DIVSIZ; 82: } 83: line(x + xoff, yoff + YDIV / 2 * DIVSIZ - ymax, 84: x + xoff, yoff + YDIV / 2 * DIVSIZ - ymin); 85: } 86: } 87: 88: 89: 90: void disptcl(int tcl, int ch, int tclwords, int *d) 91: { 92: int x, p; 93: int ymin, ymax; 94: int xoff, yoff; 95: 96: xyoffset(tclpos(tcl, ch), &xoff, &yoff); 97: p = 0; 98: for (x = 0; x <= XDIV * DIVSIZ; x++) { 99: ymin = ymax = d[p]; 100: while (p < (long)x * tclwords / (long)(XDIV * DIVSIZ)) { 101: if (ymin > d[p]) { 102: ymin = d[p]; 103: } 104: if (ymax < d[p]) { 105: ymax = d[p]; 106: } 107: ++p; 108: } 109: ymax = (((long)(ymax - TCLOFS)) * DIVSIZ) / (long)TCLDIV; 110: ymin = (((long)(ymin - TCLOFS)) * DIVSIZ) / (long)TCLDIV; 111: if (ymax > YDIV / 2 * DIVSIZ) { 112: ymax = YDIV / 2 * DIVSIZ; 113: } 114: if (ymin < -YDIV / 2 * DIVSIZ) { 115: ymin = -YDIV / 2 * DIVSIZ; 116: } 117: line(x + xoff, yoff + YDIV / 2 * DIVSIZ - ymax, 118: x + xoff, yoff + YDIV / 2 * DIVSIZ - ymin); 119: } 120: } 121: Sun Sep 19 18:28:43 1993 Listing chkstat.c Page: 1 1: #include 2: #include "gpib.h" 3: 4: void checkstatus(int status) 5: { 6: switch (status) { 7: #ifdef DEBUG 8: case GPIB_OK: 9: fputs("処理正常終了", stderr); 10: break; 11: case WITHEOI: 12: fputs("デリミタとEOI受信による終了", stderr); 13: break; 14: case EOIONLY: 15: fputs("EOI受信による終了", stderr); 16: break; 17: case NOEOI: 18: fputs("データ格納領域不足/デリミタ未受信", stderr); 19: break; 20: #endif 21: case FORCEIFC: 22: fputs("IFC受信による強制終了", stderr); 23: break; 24: case GPIBERR: 25: fputs("GPIB規定違反検出", stderr); 26: break; 27: case TIMEDOUT: 28: fputs("タイムアウトによる強制終了", stderr); 29: break; 30: case ILLEAGAL: 31: fputs("不正呼び出し", stderr); 32: break; 33: default: 34: fprintf(stderr, "終了コード: %02x ?", status); 35: exit(3); 36: break; 37: } 38: } Sun Sep 19 18:28:43 1993 Listing menu.c Page: 1 1: /* 2: * dmenu.c 3: * 4: * 0.0: Jan. 3, 93 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: 14: #include "crtctrl.h" 15: #include "daisy.h" 16: 17: #define YES 1 18: #define NO 0 19: 20: #define CRET 13 21: #define ESCAPE 27 22: #define SPACEBAR ' ' 23: #define LEFTARROW 0x08 24: #define RIGHTARROW 0x0c 25: #define UPARROW 0x0b 26: #define DOWNARROW 0x0a 27: #define EOS 0 28: 29: #define MENUDELIM '/' 30: 31: 32: void putmenu(int n, char *item[], int sel, int blink) 33: { 34: int i; 35: int x, y; 36: 37: cursorpos(&x, &y); 38: for (i = 0; i < n; i++) { 39: if (i == sel) { 40: textcolor(TEXT_UNDLINE); 41: if (blink) { 42: textcolor(TEXT_REVERSE); 43: } 44: } 45: fputs(item[i], stderr); 46: textcolor(TEXT_DEFAULT); 47: if (i < n - 1) { 48: putc(MENUDELIM, stderr); 49: } 50: } 51: gotoxy(x, y); 52: } 53: 54: 55: int selmenu(int n, char *item[], int *sel, char *retcond) 56: { 57: int ch; 58: int old; 59: 60: old = *sel; 61: putmenu(n, item, *sel, YES); 62: while (strchr(retcond, (ch = getchr())) == NULL) { 63: if (ch == LEFTARROW) { 64: *sel = (*sel + n - 1) % n; Sun Sep 19 18:28:43 1993 Listing menu.c Page: 2 65: } 66: else if (ch == RIGHTARROW) { 67: *sel = (*sel + n + 1) % n; 68: } 69: putmenu(n, item, *sel, YES); 70: } 71: if (ch == ESCAPE) { 72: *sel = old; 73: } 74: putmenu(n, item, *sel, NO); 75: return(ch); 76: } 77: 78: #define XTCNW 0 79: #define YTCNW YMENU 80: #define LTCNW "TCワード数: " 81: #define NTCNW 3 82: static char *itcnw[] = {"1024", "2048", "4096"}; 83: 84: #define XDSOP 30 85: #define YDSOP YMENU 86: #define LDSOP "DSOポーズ解除: " 87: #define NDSOP 3 88: static char *idsop[] = {"手動", "即時", "60秒後"}; 89: 90: #define XSAVE 16 91: #define YSAVE (YMENU + 2) 92: #define LSAVE "取り込んだデータの保存: " 93: #define NSAVE 2 94: static char *isave[] = {"する", "しない"}; 95: 96: #define XCNT 0 97: #define YCNT (YMENU + 2) 98: #define LCNT "カウント: " 99: 100: #define XDATE 56 101: #define YDATE (YMENU + 2) 102: 103: #define XDFREE 56 104: #define YDFREE (YMENU + 1) 105: #define LDFREE "空き容量: " 106: 107: #define XSDIR 0 108: #define YSDIR (YMENU + 1) 109: #define LSDIR "データ保存ディレクトリ: " 110: 111: #define XOPTM 66 112: #define YOPTM (YMENU) 113: #define LOPTM "" 114: #define NOPTM 1 115: static char *ioptm[] = {"その他"}; 116: 117: #define SAVEDIR "d:/tmp" 118: 119: static char *month[] = { 120: "jan", "feb", "mar", "apr", "may", "jun", 121: "jul", "aug", "sep", "oct", "nov", "dec" 122: }; 123: 124: 125: /* set default save directory */ 126: char *dsavedir(void) 127: { 128: static char s[MAXPATH + 1]; Sun Sep 19 18:28:43 1993 Listing menu.c Page: 3 129: time_t t; 130: struct tm *p; 131: 132: t = time(NULL); 133: p = localtime(&t); 134: sprintf(s, "%s/%s%02d/", SAVEDIR, month[p->tm_mon], p->tm_mday); 135: return(s); 136: } 137: 138: 139: /* MM/DD/YY hh:mm:ss */ 140: char *sdate(void) 141: { 142: static char s[16]; 143: time_t t; 144: struct tm *p; 145: 146: t = time(NULL); 147: p = localtime(&t); 148: sprintf(s, "%02d/%02d/%02d %02d:%02d:%02d", 149: p->tm_mon + 1, p->tm_mday, p->tm_year, 150: p->tm_hour, p->tm_min, p->tm_sec); 151: return(s); 152: } 153: 154: 155: void putdfree(void) 156: { 157: struct dfree x; 158: unsigned long df; 159: extern char path[]; 160: 161: getdfree(toupper(path[0]) - 'A' + 1, &x); 162: df = (unsigned long)x.df_avail * x.df_bsec * x.df_sclus / 1024; 163: gotoxy(XDFREE, YDFREE); 164: fputs(LDFREE, stderr); 165: fprintf(stderr, "%ldk", df); 166: } 167: 168: 169: void putcnt(int count) 170: { 171: gotoxy(XCNT, YCNT); 172: fputs(LCNT, stderr); 173: fprintf(stderr, "%03d", count); 174: } 175: 176: 177: void putsdir(char *s) 178: { 179: gotoxy(XSDIR, YSDIR); 180: fputs(LSDIR, stderr); 181: fputs(s, stderr); 182: } 183: 184: 185: void putdate(void) 186: { 187: gotoxy(XDATE, YDATE); 188: fputs(sdate(), stderr); 189: } 190: 191: #define XGUIDE 20 192: #define YGUIDE (YMENU + 3) Sun Sep 19 18:28:43 1993 Listing menu.c Page: 4 193: #define GTCNW "TCのワード数を選択して下さい " 194: #define GSDIR "データを保存するディレクトリを入力して下さい " 195: #define GDSOP "DSOのポーズ解除を選択して下さい " 196: #define GOPTM "オプションメニューを表示します " 197: #define XMODES 0 198: #define YMODES (YMENU + 3) 199: #define LMODES "*設定モード* " 200: 201: static char retcond[] = {CRET, ESCAPE, UPARROW, DOWNARROW, EOS}; 202: 203: int selntcw(int *tcnw) 204: { 205: int status; 206: 207: gotoxy(XGUIDE, YGUIDE); 208: fputs(GTCNW, stderr); 209: gotoxy(XTCNW, YTCNW); 210: fputs(LTCNW, stderr); 211: status = selmenu(NTCNW, itcnw, tcnw, retcond); 212: return(status); 213: } 214: 215: 216: int seldsop(int *dsop) 217: { 218: int status; 219: 220: gotoxy(XGUIDE, YGUIDE); 221: fputs(GDSOP, stderr); 222: gotoxy(XDSOP, YDSOP); 223: fputs(LDSOP, stderr); 224: status = selmenu(NDSOP, idsop, dsop, retcond); 225: return(status); 226: } 227: 228: 229: int setsdir(char *sdir) 230: { 231: int status; 232: char s[80]; 233: 234: strcpy(s, sdir); 235: gotoxy(XGUIDE, YGUIDE); 236: fputs(GSDIR, stderr); 237: gotoxy(XSDIR, YSDIR); 238: fputs(LSDIR, stderr); 239: cursor(TEXT_ON); 240: status = getline(20, sdir, retcond); 241: cursor(TEXT_OFF); 242: if ((status == ESCAPE) || (sdir[0] == EOS)) { 243: strcpy(sdir, s); 244: } 245: putsdir(sdir); 246: return(status); 247: } 248: 249: 250: int optmenu(void) 251: { 252: int status; 253: int optm = 0; 254: 255: gotoxy(XGUIDE, YGUIDE); 256: fputs(GOPTM, stderr); Sun Sep 19 18:28:43 1993 Listing menu.c Page: 5 257: gotoxy(XOPTM, YOPTM); 258: fputs(LOPTM, stderr); 259: status = selmenu(NOPTM, ioptm, &optm, retcond); 260: return(status); 261: } 262: 263: 264: #define NMODESET 4 265: void modeset() 266: { 267: int n; 268: int ntcw, dsop; 269: int status; 270: char sdir[80]; 271: 272: extern char path[]; 273: extern int tclwords; 274: 275: ntcw = dsop = 0; 276: gotoxy(XMODES, YMODES); 277: fputs(LMODES, stderr); 278: n = 0; 279: while (YES) { 280: putdate(); 281: if (n == 0) { 282: status = selntcw(&ntcw); 283: tclwords = 1024 << ntcw; 284: } 285: else if (n == 1) { 286: status = seldsop(&dsop); 287: } 288: else if (n == 2) { 289: status = setsdir(path); 290: putdfree(); 291: if (path[strlen(path) - 1] != '/') { 292: strcat(path, "/"); 293: } 294: } 295: else if (n == 3) { 296: status = optmenu(); 297: } 298: if ((status == ESCAPE) || (status == CRET)) { 299: break; 300: } 301: else if (status == UPARROW) { 302: n = (n + NMODESET - 1) % NMODESET; 303: } 304: else { 305: n = (n + NMODESET + 1) % NMODESET; 306: } 307: } 308: } 309: 310: 311: #define XQUIT 16 312: #define YQUIT (YMENU + 3) 313: #define LQUIT "終了しますか: " 314: #define NQUIT 2 315: /*static char *isave[] = {"する", "しない"};*/ 316: 317: int quitmenu(void) 318: { 319: int quit, status; 320: static char retcond[] = {CRET, ESCAPE, EOS}; Sun Sep 19 18:28:43 1993 Listing menu.c Page: 6 321: 322: quit = 1; 323: cursor(TEXT_OFF); 324: gotoxy(XQUIT, YQUIT); 325: fputs(LQUIT, stderr); 326: status = selmenu(NQUIT, isave, &quit, retcond); 327: return((quit == 0) && (status != ESCAPE)); 328: } 329: 330: 331: #define QUIT 3 332: 333: int waittrigger(int cnt) 334: { 335: static int lastsel = 0; 336: int selection; 337: int flag, ch; 338: 339: putdfree(); 340: putcnt(cnt); 341: putdate(); 342: flag = YES; 343: selection = lastsel; 344: gotoxy(0, YMENU + 3); 345: fputs("*トリガ待機中* ", stderr); 346: gotoxy(XSAVE, YSAVE); 347: fputs(LSAVE, stderr); 348: putmenu(NSAVE, isave, selection, flag); 349: while (!(triggered(TCL1))) { 350: if ((ch = getkey()) == QUIT) { 351: gotoxy(XSAVE, YSAVE); 352: fputs(LSAVE, stderr); 353: putmenu(NSAVE, isave, selection, NO); 354: if (quitmenu() == YES) { 355: selection = QUIT; 356: break; 357: } 358: else { 359: gotoxy(0, YMENU + 3); 360: fputs("*トリガ待機中* ", stderr); 361: fputs(" ", stderr); 362: fputs(" ", stderr); 363: fputs(" ", stderr); 364: gotoxy(XSAVE, YSAVE); 365: fputs(LSAVE, stderr); 366: putmenu(NSAVE, isave, selection, flag); 367: } 368: } 369: else if (ch != 0) { 370: switch (ch) { 371: case ESCAPE: 372: gotoxy(XSAVE, YSAVE); 373: fputs(LSAVE, stderr); 374: putmenu(NSAVE, isave, selection, NO); 375: modeset(); 376: gotoxy(0, YMENU + 3); 377: fputs("*トリガ待機中* ", stderr); 378: fputs(" ", stderr); 379: fputs(" ", stderr); 380: fputs(" ", stderr); 381: break; 382: case CRET: 383: flag = NO; 384: lastsel = selection; Sun Sep 19 18:28:43 1993 Listing menu.c Page: 7 385: break; 386: case LEFTARROW: 387: case RIGHTARROW: 388: case SPACEBAR: 389: selection = (selection + 1) % NSAVE; 390: break; 391: } 392: gotoxy(XSAVE, YSAVE); 393: fputs(LSAVE, stderr); 394: putmenu(NSAVE, isave, selection, flag); 395: } 396: putdate(); 397: } 398: return(selection); 399: } 400: 401: 402: void showmenues(int cnt, char *path) 403: { 404: gotoxy(XTCNW, YTCNW); 405: fputs(LTCNW, stderr); 406: putmenu(NTCNW, itcnw, 1, NO); 407: gotoxy(XDSOP, YDSOP); 408: fputs(LDSOP, stderr); 409: putmenu(NDSOP, idsop, 2, NO); 410: gotoxy(XSAVE, YSAVE); 411: fputs(LSAVE, stderr); 412: putmenu(NSAVE, isave, 0, NO); 413: putcnt(cnt); 414: putsdir(path); 415: putdfree(); 416: putdate(); 417: } Sun Sep 19 18:28:43 1993 Listing console.c Page: 1 1: /* 2: * console.c -- console i/o routines 3: * 4: * 0.0: Jan. 3, 93 by Dai Ishijima (getkey.c) 5: * 1.0: Feb. 28 6: */ 7: 8: #include 9: #include 10: #include 11: 12: #include "console.h" 13: 14: /* 15: * DOS functions 16: */ 17: /* direct console input */ 18: #define DIR_CONS_IO 0x06 19: #define CONS_INPUT 0xff 20: /* i/o control */ 21: #define IOCTRL 0x44 22: #define STTYGET 0 23: #define STTYSET 1 24: 25: #define RAWMODE 1 26: #define COOKED 0 27: 28: #define max(a, b) (((a) > (b)) ? (a) : (b)) 29: #define min(a, b) (((a) < (b)) ? (a) : (b)) 30: 31: #define EOS 0 32: #define CRET 13 33: #define ESCAPE 0x1b 34: 35: static char progid[] = "@(#) console.c 1.0 (daichan) 02/28/93"; 36: 37: 38: int getkey(void) 39: { 40: union REGS regs; 41: 42: regs.h.ah = DIR_CONS_IO; 43: regs.h.dl = CONS_INPUT; 44: intdos(®s, ®s); 45: return(regs.h.al); 46: } 47: 48: 49: int getchr(void) 50: { 51: int ch; 52: 53: while ((ch = getkey()) == 0) 54: ; 55: return(ch); 56: } 57: 58: 59: #define CURSORPOS "\033[6n" 60: 61: void cursorpos(int *x, int *y) 62: { 63: char s[16]; 64: int p; Sun Sep 19 18:28:43 1993 Listing console.c Page: 2 65: 66: fputs(CURSORPOS, stderr); 67: p = 0; 68: while ((s[p] = getkey()) != EOS) { 69: ++p; 70: } 71: sscanf(s, "%*2c %d ; %d R", y, x); 72: --*y; 73: --*x; 74: } 75: 76: 77: void delchar(char *s, int pos) 78: { 79: s += pos; 80: while (*s != EOS) { 81: *s = *(s + 1); 82: ++s; 83: } 84: } 85: 86: 87: void inschar(char *s, int pos, int ch) 88: { 89: char *t; 90: 91: t = s + pos; 92: while (*t != EOS) { 93: ++t; 94: } 95: while (s + pos <= t) { 96: *(t + 1) = *t; 97: --t; 98: } 99: *(s + pos) = ch; 100: } 101: 102: 103: #define BACKSP 0x08 104: #define DELETE 0x04 105: #define LEFT 0x02 106: #define RIGHT 0x06 107: 108: int setch(int n, char *s, int pos, int ch) 109: { 110: int len; 111: 112: switch (ch) { 113: case BACKSP: 114: if (0 < pos) { 115: --pos; 116: pos = max(0, pos); 117: delchar(s, pos); 118: } 119: break; 120: case DELETE: 121: delchar(s, pos); 122: break; 123: case LEFT: 124: --pos; 125: pos = max(0, pos); 126: break; 127: case RIGHT: 128: ++pos; Sun Sep 19 18:28:43 1993 Listing console.c Page: 3 129: len = strlen(s); 130: pos = min(len, pos); 131: break; 132: default: 133: if ((' ' <= ch) && (ch != DELETE) && (strlen(s) < n)) { 134: inschar(s, pos, ch); 135: ++pos; 136: len = strlen(s); 137: pos = min(pos, len); 138: } 139: } 140: return(pos); 141: } 142: 143: 144: int getline(int n, char *s, char *retcond) 145: { 146: int x, y; 147: int ch; 148: int pos; 149: 150: cursorpos(&x, &y); 151: for (pos = 0; pos < n; pos++) { 152: fputc(' ', stderr); 153: } 154: gotoxy(x, y); 155: *s = EOS; 156: pos = 0; 157: while (strchr(retcond, (ch = getchr())) == NULL) { 158: pos = setch(n, s, pos, ch); 159: gotoxy(x, y); 160: fputs(s, stderr); 161: putc(' ', stderr); 162: gotoxy(x + pos, y); 163: } 164: return(ch); 165: } 166: 167: 168: int gtty(handle) 169: int handle; 170: { 171: union REGS regs; 172: 173: regs.x.bx = handle; 174: regs.h.ah = IOCTRL; 175: regs.h.al = STTYGET; 176: intdos(®s, ®s); 177: return(regs.x.dx); 178: } 179: 180: 181: void stty(mode, handle) 182: int mode, handle; 183: { 184: union REGS regs; 185: regs.x.dx = gtty(handle); 186: regs.h.dh = 0; 187: if (mode == RAWMODE) { 188: regs.h.dl |= (1 << 5); 189: } 190: else { 191: regs.h.dl &= (~(1 << 5)); 192: } Sun Sep 19 18:28:43 1993 Listing console.c Page: 4 193: regs.x.bx = handle; 194: regs.h.ah = IOCTRL; 195: regs.h.al = STTYSET; 196: intdos(®s, ®s); 197: } 198: 199: 200: void rawmode(void) 201: { 202: stty(RAWMODE, fileno(stdin)); 203: stty(RAWMODE, fileno(stdout)); 204: stty(RAWMODE, fileno(stderr)); 205: } 206: 207: 208: void cookedmode(void) 209: { 210: stty(COOKED, fileno(stdin)); 211: stty(COOKED, fileno(stdout)); 212: stty(COOKED, fileno(stderr)); 213: } Sun Sep 19 18:28:43 1993 Listing gl.c Page: 1 1: /* 2: 3: graphics lio handlers for PC-9801 series personal computer 4: 5: Copyright (C) by Dai Ishijima 6: 7: You are allowed to redistribute this program with the above 8: copyright and this notice. 9: 10: revision history 11: 0.0: Sep. 8, 1991 by Dai Ishijima 12: 0.1: Oct. 3 13: 0.2: Nov. 28 14: 0.3: Dec. 21 15: 0.4: Jan. 13, 1993 16: 17: */ 18: 19: static char *progid = "@(#)gl.c 0.4 (Dai Ishijima) Jan. 13, 1993"; 20: 21: /* 22: C A U T I O N : 23: 24: This program overwrites the table of interrupt vectors (0xa0..0xaf, 25: 0xc5, 0xce). If the DOS or TSR programs used these interrupts, the 26: machine might be out of order. 27: 28: */ 29: 30: #include 31: #include 32: #include 33: 34: #include "gl.h" 35: 36: /* 37: local (static) constants 38: */ 39: /* about graphics logical input/output */ 40: #define SEGLIO 0xf990 /* segment of GLIO entry */ 41: #define SIZEOFWORK 0x1400 /* size of GLIO work area */ 42: #define MARGIN 16 /* for segment allignment */ 43: #define TOPOFPWORK 0x06a0 /* GPAINT work area start address */ 44: #define ENDOFPWORK 0x0fff /* GPAINT work area end address */ 45: /* This area (0x6a0..0xfff) is not used by GLIO */ 46: #define OFSOFINT 4 /* offset of interrupt number */ 47: #define OFSOFVEC 6 /* offset of interrupt vector */ 48: #define SIZEOFVEC 4 /* size of vector: 4 bytes (seg + ofs) */ 49: 50: /* interrupt numbers */ 51: #define GINIT 0xa0 52: #define GSCREEN 0xa1 53: #define GVIEW 0xa2 54: #define GCOLOR 0xa3 55: #define GPALETTE 0xa4 56: #define GCLS 0xa5 57: #define GPSET 0xa6 58: #define GLINE 0xa7 59: #define GCIRCLE 0xa8 60: #define GPAINT 0xa9 61: #define GTILE 0xaa 62: #define GGET 0xab 63: #define GPUT 0xac 64: #define GPRINT 0xad Sun Sep 19 18:28:43 1993 Listing gl.c Page: 2 65: #define GROLL 0xae 66: #define GPOINT 0xaf 67: #define GCOPY 0xce 68: #define INTFORSTOP 0xc5 /* interrupt No. for check STOP */ 69: 70: /* pset/preset flag in GPSET */ 71: #define PSETFLAG 1 72: #define PRESETFLAG 2 73: 74: /* about 80x86 */ 75: #define IRETCODE (unsigned char)0xcf 76: 77: /* about GDC (mPD7220) */ 78: #define GDCSTATUS 0xa0 /* GDC read status */ 79: #define ISEMPTY 4 80: #define ISDRAWING 8 81: 82: 83: /* GLIO work area */ 84: typedef union { 85: unsigned char dummy[SIZEOFWORK]; 86: 87: struct screen_args { 88: unsigned char mode; 89: unsigned char sw; 90: unsigned char active; 91: unsigned char display; 92: } screen; 93: 94: struct view_args { 95: int x1; 96: int y1; 97: int x2; 98: int y2; 99: unsigned char background; 100: unsigned char border; 101: } view; 102: 103: struct color_args { 104: unsigned char junk; 105: unsigned char background; 106: unsigned char border; 107: unsigned char foreground; 108: unsigned char palmode; 109: } color; 110: 111: struct palette_args { 112: unsigned char pal; 113: unsigned int col; 114: } palette; 115: 116: struct pset_args { 117: int x; 118: int y; 119: unsigned char pal; 120: } pset; 121: 122: struct line_args { 123: int x1; 124: int y1; 125: int x2; 126: int y2; 127: unsigned char pal; 128: unsigned char code; Sun Sep 19 18:28:43 1993 Listing gl.c Page: 3 129: unsigned char sw; 130: unsigned char pal2; 131: unsigned char stylehi; 132: unsigned char tile_len; 133: unsigned int tile_ofs; 134: unsigned int tile_seg; 135: } line; 136: 137: struct circle_args { 138: int cx; 139: int cy; 140: int rx; 141: int ry; 142: unsigned char pal; 143: unsigned char flag; 144: int sx; 145: int sy; 146: int ex; 147: int ey; 148: unsigned char pal2; 149: unsigned int tile_ofs; 150: unsigned int tile_seg; 151: } circle; 152: 153: struct paint_args { 154: int x; 155: int y; 156: unsigned char region; 157: unsigned char border; 158: unsigned int work_end; 159: unsigned int work_start; 160: } paint; 161: 162: struct tile_args { 163: int x; 164: int y; 165: unsigned char junk; 166: unsigned char len; 167: unsigned int offset; 168: unsigned int segment; 169: unsigned char border; 170: unsigned char junk2[5]; 171: unsigned int work_end; 172: unsigned int work_start; 173: } tile; 174: 175: struct get_args { 176: int x1; 177: int y1; 178: int x2; 179: int y2; 180: unsigned int offset; 181: unsigned int segment; 182: unsigned int len; 183: } get; 184: 185: struct put_args { 186: int x; 187: int y; 188: unsigned int offset; 189: unsigned int segment; 190: unsigned int len; 191: unsigned char mode; 192: unsigned char sw; Sun Sep 19 18:28:43 1993 Listing gl.c Page: 4 193: unsigned char foreground; 194: unsigned char background; 195: } put; 196: 197: struct print_args { 198: int x; 199: int y; 200: int code; 201: unsigned char mode; 202: unsigned char sw; 203: unsigned char foreground; 204: unsigned char background; 205: } print; 206: 207: struct roll_args { 208: int vertical; 209: int horizontal; 210: unsigned char flag; 211: } roll; 212: 213: struct point_args { 214: int x; 215: int y; 216: } point; 217: } arguments; 218: 219: /* define register array */ 220: typedef union { 221: struct byteregisters { 222: unsigned char al, ah, bl, bh, cl, ch, dl, dh; 223: unsigned int bp, si, di, ds, es, flag; 224: } h; 225: struct wordresisters { 226: unsigned int ax, bx, cx, dx; 227: unsigned int bp, si, di, ds, es, flag; 228: } x; 229: struct REGPACK p; 230: } registers; 231: 232: 233: /* variables */ 234: static registers regs; 235: static unsigned char workarea[SIZEOFWORK + MARGIN]; 236: static arguments *argp; 237: static char huge *ap; 238: 239: 240: /* set interrupt vector for check stop key */ 241: static void setstopvec(void) 242: { 243: unsigned int i; 244: void interrupt (*func)(); 245: 246: /* search IRET code in SYSTEM ROM area */ 247: for (i = 0; i < (unsigned)0xffff; i++) { 248: if ((unsigned char)peekb(SEGLIO, i) == IRETCODE) { 249: break; 250: } 251: } 252: if ((unsigned char)peekb(SEGLIO, i) != IRETCODE) { 253: fprintf(stderr, "GLIO: can't find IRET code\n"); 254: exit(1); 255: } 256: func = MK_FP(SEGLIO, i); Sun Sep 19 18:28:43 1993 Listing gl.c Page: 5 257: setvect(INTFORSTOP, func); 258: } 259: 260: 261: /* set interrupt vectors */ 262: static void setgvec(void) 263: { 264: int intno; 265: int vect; 266: int n; 267: int i; 268: void interrupt (*func)(); 269: 270: n = (unsigned char)peekb(SEGLIO, 0); 271: for (i = 0; i < n; i++) { 272: intno = (unsigned char)peekb(SEGLIO, i * SIZEOFVEC + OFSOFINT); 273: vect = peek(SEGLIO, i * SIZEOFVEC + OFSOFVEC); 274: func = MK_FP(SEGLIO, vect); 275: setvect(intno, func); 276: } 277: } 278: 279: 280: /* call graphics logical I/O */ 281: static int intglio(intno) 282: int intno; 283: { 284: regs.x.bx = FP_OFF(ap); 285: regs.x.ds = regs.x.es = FP_SEG(ap); 286: intr(intno, &(regs.p)); 287: return(regs.h.ah); 288: } 289: 290: 291: /* initialize graphics LIO */ 292: int ginit(void) 293: { 294: int i; 295: 296: ap = (char huge *)(&workarea[0]); 297: ++ap; 298: --ap; 299: if (FP_OFF(ap) > 15) { 300: fprintf(stderr, "GLIO: can't normalize huge pointer\n"); 301: } 302: for (i = 0; FP_OFF(ap) != 0; ap++, i++) { 303: ; 304: } 305: argp = (arguments *)(&workarea[i]); 306: setstopvec(); 307: setgvec(); 308: return(intglio(GINIT)); 309: } 310: 311: 312: /* wait until GDC buffer free */ 313: void gdcwait(void) 314: { 315: while (!(inp(GDCSTATUS) & ISEMPTY )) 316: ; /* wait until GDC FIFO is empty */ 317: argp->dummy[TOPOFPWORK] = argp->dummy[ENDOFPWORK]; 318: /* This code is NO effect */ 319: /* Does above statement cost 26 cpu clocks? */ 320: while ( (inp(GDCSTATUS) & ISDRAWING)) Sun Sep 19 18:28:43 1993 Listing gl.c Page: 6 321: ; /* wait until GDC is not drawing */ 322: } 323: 324: 325: /* set screen mode */ 326: int gscreen(int mode, int sw, int active, int display) 327: { 328: argp->screen.mode = mode; 329: argp->screen.sw = sw; 330: argp->screen.active = active; 331: argp->screen.display = display; 332: return(intglio(GSCREEN)); 333: } 334: 335: 336: /* set viewport */ 337: int gview(int x1, int y1, int x2, int y2, 338: unsigned char background, unsigned char border) 339: { 340: argp->view.x1 = x1; 341: argp->view.y1 = y1; 342: argp->view.x2 = x2; 343: argp->view.y2 = y2; 344: argp->view.background = background; 345: argp->view.border = border; 346: return(intglio(GVIEW)); 347: } 348: 349: 350: /* set forground, background, border color */ 351: int gcolor(int bg, int bd, int fg, int pm) 352: { 353: argp->color.junk = 0; 354: argp->color.background = bg; 355: argp->color.border = bd; 356: argp->color.foreground = fg; 357: argp->color.palmode = pm; 358: return(intglio(GCOLOR)); 359: } 360: 361: 362: /* set color palette */ 363: int gpalette(int p, int c) 364: { 365: argp->palette.pal = p; 366: argp->palette.col = c; 367: return(intglio(GPALETTE)); 368: } 369: 370: 371: /* clear graphics screen */ 372: int gcls(void) 373: { 374: return(intglio(GCLS)); 375: } 376: 377: 378: /* draw a dot */ 379: int gpset(int x, int y, int c) 380: { 381: argp->pset.x = x; 382: argp->pset.y = y; 383: argp->pset.pal = c; 384: regs.h.ah = PSETFLAG; Sun Sep 19 18:28:43 1993 Listing gl.c Page: 7 385: return(intglio(GPSET)); 386: } 387: 388: 389: /* draw a line */ 390: int gline(int x1, int y1, int x2, int y2, 391: unsigned int c, unsigned int code, unsigned int sw, unsigned int c2, 392: unsigned int style, unsigned int tlen, char *tile) 393: { 394: argp->line.x1 = x1; 395: argp->line.y1 = y1; 396: argp->line.x2 = x2; 397: argp->line.y2 = y2; 398: argp->line.pal = c; 399: argp->line.code = code; 400: argp->line.sw = sw; 401: if (code == FILLEDBOX) { 402: argp->line.pal2 = c2; 403: argp->line.stylehi = 0; 404: } 405: else { 406: argp->line.pal2 = style % 256; 407: argp->line.stylehi = style / 256; 408: } 409: argp->line.tile_len = tlen; 410: argp->line.tile_ofs = FP_OFF((void far *)tile); 411: argp->line.tile_seg = FP_SEG((void far *)tile); 412: return(intglio(GLINE)); 413: } 414: 415: 416: /* return palette code of (x, y) */ 417: int gpoint(int x, int y) 418: { 419: argp->point.x = x; 420: argp->point.y = y; 421: intglio(GPOINT); 422: return((unsigned char)regs.h.al); 423: } Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 1 1: /* 2: * gpib.c -- gpib ROM bios handler 3: * 4: * 0.0: Sep. 7, 1992 by Dai Ishijima 5: */ 6: 7: #include 8: #include 9: #include 10: 11: #include "gpib.h" 12: 13: #ifdef _MSC_VER 14: # include "poke.h" 15: #endif 16: 17: /* define register array */ 18: typedef union { 19: struct byteregisters { 20: unsigned char al, ah, bl, bh, cl, ch, dl, dh; 21: unsigned int bp, si, di, ds, es, flag; 22: } h; 23: struct wordresisters { 24: unsigned int ax, bx, cx, dx; 25: unsigned int bp, si, di, ds, es, flag; 26: } x; 27: struct REGPACK p; 28: } registers; 29: 30: typedef struct { 31: unsigned char mode; 32: unsigned char addstat; 33: unsigned char intstat1; 34: unsigned char intstat2; 35: unsigned char works[12]; 36: unsigned int ofs; 37: unsigned int seg; 38: } ctrl_t; 39: 40: typedef struct { 41: unsigned char addr; 42: unsigned char stb; 43: } talklist; 44: 45: typedef struct { 46: unsigned char addr; 47: unsigned char ppe; 48: } listenlist; 49: 50: 51: static registers regs; 52: 53: #define INITIALIZE 0x00 54: #define SETIFC 0x01 55: #define SETREN 0x02 56: #define RESETREN 0x03 57: #define SENDDATA 0x04 58: #define RECIEVEDATA 0x05 59: #define SPOLL 0x06 60: #define SETSRQ 0x07 61: #define PARAPOLL 0x08 62: #define SETPPR 0x09 63: #define SETTIMEOUT 0x0a 64: #define CHECKSTB 0x0b Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 2 65: 66: #define SEGGPIB 0xd540 67: #define INTGPIB 0xd1 68: #define IRETCODE 0xcf 69: #define INTFORSTOP 0xc5 70: #define SIZEOFVEC 4 71: #define READSW 0x99 72: #define READIFC 0x9b 73: 74: static int intno; /* GPIB interrupt number */ 75: static int delim = DELIMCRLF | DELIMEOI; /* delimiter */ 76: static int stb_of_srq, addr_of_srq, norespond; 77: static unsigned char works[sizeof(ctrl_t) + 16]; 78: static ctrl_t *ctrlinfo; 79: 80: /* set interrupt vector for check stop key */ 81: static void setstop(void) 82: { 83: unsigned int i; 84: void interrupt (*func)(); 85: 86: /* search IRET code in SYSTEM ROM area */ 87: for (i = 0; i < (unsigned)0xffff; i++) { 88: if ((unsigned char)peekb(SEGGPIB, i) == IRETCODE) { 89: break; 90: } 91: } 92: if ((unsigned char)peekb(SEGGPIB, i) != IRETCODE) { 93: fprintf(stderr, "GPIB: can't find IRET code\n"); 94: exit(1); 95: } 96: func = MK_FP(SEGGPIB, i); 97: setvect(INTFORSTOP, func); 98: } 99: 100: 101: static void setvec(void) 102: { 103: int vect; 104: void interrupt (*func)(); 105: 106: if (peekb(SEGGPIB, 0) != 1) { 107: fprintf(stderr, "GPIB: no PC-9801-29: Illeagal entry\n"); 108: exit(1); 109: } 110: if ((intno = (unsigned char)peekb(SEGGPIB, 4)) != INTGPIB) { 111: fprintf(stderr, "GPIB: no PC-9801-29: Illeagal vector no: "); 112: fprintf(stderr, "%x\n", intno); 113: exit(1); 114: } 115: vect = peek(SEGGPIB, 6); 116: func = MK_FP(SEGGPIB, vect); 117: setvect(intno, func); 118: } 119: 120: 121: int ib_init(void) 122: { 123: int i; 124: char huge *p; 125: 126: p = (char huge *)(&works[0]); 127: #ifdef DEBUG 128: fprintf(stderr, "%Fp\n", p); Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 3 129: #endif 130: ++p; 131: --p; 132: #ifdef DEBUG 133: fprintf(stderr, "%Fp\n", p); 134: #endif 135: if (FP_OFF(p) > 15) { 136: fprintf(stderr, "GPIB: can't normalize huge pointer\n"); 137: } 138: for (i = 0; FP_OFF(p) != 0; p++, i++) { 139: #ifdef DEBUG 140: fprintf(stderr, "%Fp\n", p); 141: #endif 142: } 143: ctrlinfo = (ctrl_t *)(&works[i]); 144: #ifdef DEBUG 145: fprintf(stderr, "%Fp, %Fp\n", (void far *)&works[i], p); 146: #endif 147: setvec(); 148: setstop(); 149: regs.x.es = FP_SEG(p); 150: regs.h.ah = INITIALIZE; 151: intr(intno, &(regs.p)); 152: return(regs.h.ah); 153: } 154: 155: 156: /* 157: * mPD8259A/71059 158: */ 159: /* port of interrupt mask register */ 160: #define IMRM 0x02 /* master */ 161: #define IMRS 0x0a /* slave */ 162: 163: #define READSW 0x99 164: 165: typedef union { 166: unsigned char bytes; 167: struct { 168: unsigned myaddr: 5; 169: unsigned m_or_s: 1; 170: unsigned gint: 2; 171: } bits; 172: } readsw_t; 173: 174: 175: void mask(int level) 176: { 177: int intmask; 178: int bitmask; 179: int port; 180: 181: port = IMRM; 182: if (level >= 8) { 183: port = IMRS; 184: level -= 8; 185: } 186: intmask = inp(port); 187: bitmask = (1 << level); 188: outp(port, intmask | bitmask); 189: } 190: 191: /* interrupt signal vs. interrupt level */ 192: #define IR31 3 Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 4 193: #define IR101 10 194: #define IR121 12 195: #define IR131 13 196: 197: #define GINT0 0 198: #define GINT4 1 199: #define GINT5 2 200: #define GINT6 3 201: 202: void maskgint(void) 203: { 204: readsw_t sw; 205: 206: sw.bytes = inp(READSW); 207: switch(sw.bits.gint) { 208: case GINT0: 209: mask(IR31); 210: break; 211: case GINT4: 212: mask(IR101); 213: break; 214: case GINT5: 215: mask(IR121); 216: break; 217: case GINT6: 218: mask(IR131); 219: break; 220: } 221: } 222: 223: 224: void ib_close(void) 225: { 226: ib_init(); 227: ib_setifc(10); 228: ib_resetren(); 229: maskgint(); 230: } 231: 232: 233: /* CMD DELIM */ 234: int ib_setdelim(int d) 235: { 236: return(delim = d); 237: } 238: 239: 240: /* IEEE(0) */ 241: int ib_delim(void) 242: { 243: return(delim); 244: } 245: 246: 247: /* IEEE(1) */ 248: int ib_readsw(void) 249: { 250: return(inp(READSW)); 251: } 252: 253: 254: int ib_readifc(void) 255: { 256: return(inp(READIFC)); Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 5 257: } 258: 259: 260: /* IEEE(4) */ 261: int ib_srqstb(void) 262: { 263: return(stb_of_srq); 264: } 265: 266: 267: /* IEEE(5) */ 268: int ib_srqaddr(void) 269: { 270: return(addr_of_srq); 271: } 272: 273: 274: /* IEEE(6) */ 275: int ib_srqnores(void) 276: { 277: return(norespond); 278: } 279: 280: 281: /* ISET IFC */ 282: int ib_setifc(int ticks) 283: { 284: regs.h.ah = SETIFC; 285: regs.h.bh = ticks; 286: intr(intno, &(regs.p)); 287: return(regs.h.ah); 288: } 289: 290: 291: /* ISET REN */ 292: int ib_setren(void) 293: { 294: regs.h.ah = SETREN; 295: intr(intno, &(regs.p)); 296: return(regs.h.ah); 297: } 298: 299: 300: /* IRESET REN */ 301: int ib_resetren(void) 302: { 303: regs.h.ah = RESETREN; 304: intr(intno, &(regs.p)); 305: return(regs.h.ah); 306: } 307: 308: 309: /* WBYTE, PRINT@ */ 310: int ib_send(int cmdlen, void *cmd, int datlen, void *dat) 311: { 312: regs.x.es = FP_SEG((void far *)cmd); 313: regs.x.si = FP_OFF((void far *)cmd); 314: regs.x.bx = cmdlen; 315: regs.x.di = FP_OFF((void far *)dat); 316: if (regs.x.es != FP_SEG((void far *)dat)) { 317: fprintf(stderr, "ib_send: different segment\n"); 318: exit(1); 319: } 320: regs.x.cx = datlen; Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 6 321: regs.h.al = delim; 322: regs.h.ah = SENDDATA; 323: intr(intno, &(regs.p)); 324: return(regs.h.ah); 325: } 326: 327: 328: /* RBYTE, INPUT@ */ 329: int ib_recieve(int cmdlen, void *cmd, int *datlen, void *dat) 330: { 331: regs.x.es = FP_SEG((void far *)cmd); 332: regs.x.si = FP_OFF((void far *)cmd); 333: regs.x.bx = cmdlen; 334: regs.x.di = FP_OFF((void far *)dat); 335: if (regs.x.es != FP_SEG((void far *)dat)) { 336: fprintf(stderr, "ib_send: different segment\n"); 337: exit(1); 338: } 339: regs.x.cx = *datlen; 340: regs.h.al = delim; 341: regs.h.ah = RECIEVEDATA; 342: intr(intno, &(regs.p)); 343: *datlen = regs.x.dx; 344: return(regs.h.ah); 345: } 346: 347: 348: /* POLL */ 349: int ib_poll(int n, void *talker) 350: { 351: regs.x.cx = n; 352: regs.x.es = FP_SEG((void far *)talker); 353: regs.x.di = FP_OFF((void far *)talker); 354: regs.h.ah = SPOLL; 355: intr(intno, &(regs.p)); 356: return(regs.h.ah); 357: } 358: 359: 360: /* ISET SRQ */ 361: int ib_setsrq(int stb, int eoi) 362: { 363: regs.h.bh = stb; 364: regs.h.bl = eoi; 365: regs.h.ah = SETSRQ; 366: intr(intno, &(regs.p)); 367: return(regs.h.ah); 368: } 369: 370: 371: /* PPOLL */ 372: int ib_ppoll(int n, void *listenlist, int ppoll, int ppu) 373: { 374: regs.x.cx = n; 375: regs.x.es = FP_SEG((void far *)listenlist); 376: regs.x.di = FP_OFF((void far *)listenlist); 377: regs.h.bh = ppoll; 378: regs.h.bl = ppu; 379: regs.h.ah = PARAPOLL; 380: intr(intno, &(regs.p)); 381: return(regs.h.ah); 382: } 383: 384: Sun Sep 19 18:28:43 1993 Listing gpib.c Page: 7 385: /* CMD PPR */ 386: int ib_setppr(int ppr) 387: { 388: regs.h.bh = ppr; 389: regs.h.ah = SETPPR; 390: intr(intno, &(regs.p)); 391: return(regs.h.ah); 392: } 393: 394: 395: /* CMD TIMEOUT */ 396: int ib_timeout(int sec) 397: { 398: regs.h.bh = sec; 399: regs.h.ah = SETTIMEOUT; 400: intr(intno, &(regs.p)); 401: return(regs.h.ah); 402: } 403: 404: 405: /* */ 406: int ib_chkstb(int *stb, int *eoi) 407: { 408: regs.h.ah = CHECKSTB; 409: intr(intno, &(regs.p)); 410: *stb = regs.h.dh; 411: *eoi = regs.h.dl; 412: return(regs.h.ah); 413: } 414: 415: 416: /* print@ */ 417: int ib_puts(char *s, int la) 418: { 419: char cmd[3]; 420: 421: cmd[0] = UNL; 422: cmd[1] = talka(myadr()); 423: cmd[2] = lisna(la); 424: return(ib_send(3, cmd, strlen(s), s)); 425: } 426: 427: 428: /* input@ */ 429: int ib_gets(char *s, int size, int ta) 430: { 431: char cmd[3]; 432: int status; 433: 434: cmd[0] = UNT; 435: cmd[1] = talka(ta); 436: cmd[2] = lisna(myadr()); 437: status = ib_recieve(3, cmd, &size, s); 438: s[size] = '\0'; 439: return(status); 440: }