Tue Nov 17 19:44:57 2020 Listing makefile Page: 1 1: CC=tcc 2: 3: # implicit rules 4: .c.obj: 5: $(CC) -m$(MEM) $(CFLAGS) -c $< 6: 7: # 8: PROG=go.exe 9: HDRS=gl.h ms.h bed.h crtctrl.h poke.h proto.h 10: OBJS=main.obj file.obj be.obj sb.obj misc.obj gl.obj ms.obj 11: SRCS=sb.c main.c file.c be.c misc.c gl.c ms.c 12: MAKEFILE=makefile 13: XBMS=test test2 test3 14: ETCS=xbmini.c xbmini.exe readme.doc 15: #CFLAGS= 16: 17: # HUGE model 18: MEM=h 19: 20: $(PROG): $(OBJS) 21: $(CC) -m$(MEM) $(CFLAGS) -e$(PROG) $(OBJS) 22: 23: $(OBJS): $(HDRS) $(MAKEFILE) 24: 25: clean: 26: rm -f $(OBJS) 27: 28: list: 29: olist $(MAKEFILE) $(HDRS) $(SRCS) > bed.lst 30: 31: archive: 32: lha u bed.lzh $(MAKEFILE) $(HDRS) $(SRCS) $(PROG) 33: lha u bed.lzh $(XBMS) $(ETCS) Tue Nov 17 19:44:57 2020 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 setstopvec(void); 21: int setgvec(void); 22: int intglio(int intno); 23: int ginit(void); 24: int gdcwait(void); 25: int gscreen(int mode, int sw, int active, int display); 26: int gview(int x1, int y1, int x2, int y2, 27: unsigned char background, unsigned char border); 28: int gcolor(int bg, int bd, int fg, int pm); 29: int gpalette(int p, int c); 30: int gcls(void); 31: int gpset(int x, int y, int c); 32: int gline(int x1, int y1, int x2, int y2, 33: unsigned int c, unsigned int code, unsigned int sw, unsigned int c2, 34: unsigned int style, unsigned int tlen, char *tile); 35: int gpoint(int x, int y); 36: /**/ 37: Tue Nov 17 19:44:57 2020 Listing gl.h Page: 2 38: #define setview(x1, y1, x2, y2) \ 39: gview(x1, y1, x2, y2, GDEFAULT, GDEFAULT) 40: #define line(x1, y1, x2, y2) \ 41: gline(x1, y1, x2, y2, \ 42: GDEFAULT, SIMPLELINE, NOSTYLE, 0, 0, 0, NULL) 43: #define styledline(x1, y1, x2, y2, style) \ 44: gline(x1, y1, x2, y2, \ 45: GDEFAULT, SIMPLELINE, USESTYLE, 0, style, 0, NULL) 46: #define styledcline(x1, y1, x2, y2, c, style) \ 47: gline(x1, y1, x2, y2, \ 48: c, SIMPLELINE, USESTYLE, 0, style, 0, NULL) 49: #define box(x1, y1, x2, y2) \ 50: gline(x1, y1, x2, y2, \ 51: GDEFAULT, SIMPLEBOX, NOSTYLE, 0, 0, 0, NULL) 52: #define filledbox(x1, y1, x2, y2) \ 53: gline(x1, y1, x2, y2, \ 54: GDEFAULT, FILLEDBOX, NOSTYLE, 0, 0, 0, NULL) 55: #define cfilledbox(x1, y1, x2, y2, c) \ 56: gline(x1, y1, x2, y2, \ 57: c, FILLEDBOX, NOSTYLE, 0, 0, 0, NULL) 58: #define styledbox(x1, y1, x2, y2, style) \ 59: gline(x1, y1, x2, y2, \ 60: GDEFAULT, SIMPLEBOX, USESTYLE, 0, style, 0, NULL) 61: #define setfcolord(fg) \ 62: gcolor(GDEFAULT, GDEFAULT, fg, DIGIAL8) 63: #define pset(x, y) \ 64: gpset(x, y, GDEFAULT) 65: 66: Tue Nov 17 19:44:57 2020 Listing ms.h Page: 1 1: /* 2: 3: ms.h -- mouse handler header 4: 5: 0.0: Sep. 8, 1991 by Dai Ishijima 6: 7: */ 8: 9: #define MCANTUSE 0 10: #define MPRESSED (-1) 11: #define MRELEASED 0 12: 13: /* frequency of interruption */ 14: #define MFPORT 0xbfdb /* system port */ 15: #define MFNORM 0 /* normal: 120Hz */ 16: #define MFHALF 1 /* 1/2: 60Hz */ 17: #define MFQUARTER 2 /* 1/4: 30Hz */ 18: #define MFOCT 3 /* 1/8: 15Hz */ 19: 20: /* set frequency */ 21: #define msetfreq(f) outp(MFPORT, f) 22: 23: int minit(); 24: mdisplay(); 25: mhide(); 26: mstatus(); 27: mwhere(); 28: msetxy(); 29: mleftpress(); 30: mrightpress(); 31: mleftrelease(); 32: mrightrelease(); 33: mcursor(); 34: mdistance(); 35: msensitive(); 36: mxregion(); 37: myregion(); 38: msetplane(); Tue Nov 17 19:44:57 2020 Listing bed.h Page: 1 1: #define DISPALL 1 2: #define SBAR 2 3: #define BUFS 3 4: #define EDIT 2 5: 6: #define WHITE 7 7: #define BLACK 0 8: 9: #define max(a,b) (((a) > (b)) ? (a) : (b)) 10: #define min(a,b) (((a) < (b)) ? (a) : (b)) 11: 12: #define YES 1 13: #define NO 0 14: 15: #define MAXSIZE 400 16: #define SBWIDTH 16 17: 18: extern char *progname; 19: #include "proto.h" Tue Nov 17 19:44:57 2020 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: Tue Nov 17 19:44:57 2020 Listing poke.h Page: 1 1: /* 2: 3: poke.h -- definitions to manipulate memories 4: 5: */ 6: 7: /* get segment of far pointer fp */ 8: #define FP_SEG(fp) ((unsigned int)( (unsigned long)fp >> 16 )) 9: 10: /* get offset of far pointer fp */ 11: #define FP_OFF(fp) ((unsigned int)( (unsigned long)fp )) 12: 13: /* make far pointer */ 14: #define MK_FP(seg, ofs) \ 15: ((void far *)( ((unsigned long)(seg) << 16) | (unsigned int)(ofs) )) 16: 17: /* write a word on a:b */ 18: #define poke(a, b, c) \ 19: (*((unsigned int far *)MK_FP(a, b)) = (unsigned int)(c)); 20: 21: /* write a byte on a:b */ 22: #define pokeb(a, b, c) \ 23: (*((unsigned char far *)MK_FP(a, b)) = (unsigned char)(c)); 24: 25: #define peek(a, b) (*((unsigned int far*)MK_FP(a, b))) 26: #define peekb(a, b) (*((unsigned char far*)MK_FP(a, b))) Tue Nov 17 19:44:57 2020 Listing proto.h Page: 1 1: int region(int x,int min,int max); 2: int x2h(int x,int width); 3: int h2x(int h,int width); 4: int y2v(int y,int height); 5: int v2y(int v,int height); 6: int getstep(int left,int right); 7: int checkarrow(int x,int y,int left,int right,int *horv,int *step); 8: int drawarrows(void); 9: int onvbar(int x,int y,int vofs,int vlen); 10: int onvarea(int x,int y); 11: int vwrite(int vofs,int vlen); 12: int vghost(int vofs,int vlen,int gofs); 13: int vmove(int x,int y,int left,int right,int y0,int *vofs,int vofs0,int vlen,int height); 14: int vbar(int height,int ysize,int *yofs); 15: int onhbar(int x,int y,int hofs,int hlen); 16: int onharea(int x,int y); 17: int hwrite(int hofs,int hlen); 18: int hghost(int hofs,int hlen,int gofs); 19: int hmove(int x,int y,int left,int right,int x0,int *hofs,int hofs0,int hlen,int width); 20: int hbar(int width,int xsize,int *xofs); 21: int sb(int width,int height,int xsize,int ysize,int *xofs,int *yofs); 22: int main(void); 23: int skipto(FILE *fp,char *s); 24: int getsize(FILE *fp,int *width,int *height); 25: int getbyte(FILE *fp); 26: unsigned int bitrev(unsigned int b); 27: int readbitmap(FILE *fp,int width,int height); 28: int writebitmap(int width, int height); 29: int makeline(unsigned char *work,int mag,int start,int n,int shiftbits); 30: int toboard(int mag,int xsize,int ysize,int xofs,int yofs); 31: int drawmesh(int xsize,int ysize,int mag); 32: int drawboard(int xsize,int ysize,int mag); 33: int printmagmenu(void); 34: int checkmag(int *mag); 35: int resetsize(int width,int height,int mag,int *xsize,int *ysize,int *use sb); 36: int newofs(int max,int size,int size0,int ofs0); 37: int sbscrn(int width,int height,int xsize,int ysize,int xofs,int yofs); 38: unsigned int getmask(int shift,int mag); 39: int onoff(int x,int y,int xofs,int yofs,int mag,int col); 40: int setreset(int x,int y,int left,int right,int xsize,int ysize,int mag, int xofs,int yofs); 41: int edit(int width,int height); 42: int initpalette(void); 43: int selscrn(int n); 44: int setstopvec(void); 45: int setgvec(void); 46: int intglio(int intno); 47: int ginit(void); 48: int gdcwait(void); 49: int gscreen(int mode,int sw,int active,int display); 50: int gview(int x1,int y1,int x2,int y2,unsigned char background,unsigned ch ar border); 51: int gcolor(int bg,int bd,int fg,int pm); 52: int gpalette(int p,int c); 53: int gcls(void); 54: int gpset(int x,int y,int c); 55: int gline(int x1,int y1,int x2,int y2,unsigned int c,unsigned int code,un Tue Nov 17 19:44:57 2020 Listing proto.h Page: 2 signed int sw,unsigned int c2,unsigned int style,unsigned int tlen,char *ti le); 56: int gpoint(int x,int y); 57: int mintr(int function); 58: int minit(void); 59: int mdisplay(void); 60: int mhide(void); 61: int mstatus(int *x,int *y,int *left,int *right); 62: int mwhere(int *x,int *y); 63: int msetxy(int x,int y); 64: int mleftpress(int *pressed,int *times,int *x,int *y); 65: int mrightpress(int *pressed,int *times,int *x,int *y); 66: int mleftrelease(int *released,int *times,int *x,int *y); 67: int mrightrelease(int *released,int *times,int *x,int *y); 68: int mcursor(int xhot,int yhot,char *pattern); 69: int mdistance(int *dx,int *dy); 70: int msensitive(int xs,int ys); 71: int mxregion(int x1,int x2); 72: int myregion(int y1,int y2); 73: int msetplane(int plane); Tue Nov 17 19:44:57 2020 Listing sb.c Page: 1 1: /* 2: 3: sb.c -- scroll bar 4: 5: */ 6: 7: static char *progid = "@(#)sb.c 0.1 (Dai Ishijima) Nov. 18, 1991"; 8: 9: #include 10: #include 11: #include "gl.h" 12: #include "ms.h" 13: #include "crtctrl.h" 14: #include "bed.h" 15: 16: 17: #define VBARX1 385 18: #define VBARY1 15 19: #define VBARX2 399 20: #define VBARY2 369 21: 22: #define HBARX1 15 23: #define HBARY1 385 24: #define HBARX2 369 25: #define HBARY2 399 26: 27: #define WHITE 7 28: #define BLACK 0 29: #define GHOSTLINE 0x3333 30: 31: #define ARROWBOXSIZE 15 32: 33: #define HORIZONTAL 1 34: #define VERTICAL 2 35: 36: #define XGEO 60 37: #define YGEO 2 38: #define XXOFS (XGEO + 8) 39: #define YXOFS YGEO 40: #define XYOFS (XXOFS + 4) 41: #define YYOFS YXOFS 42: 43: 44: int region(x, min, max) 45: int x, min, max; 46: { 47: if (x < min) { 48: return(min); 49: } 50: else if (max < x) { 51: return(max); 52: } 53: return(x); 54: } 55: 56: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 2 57: /* xofs -> hofs */ 58: int x2h(x, width) 59: int x, width; 60: { 61: return((double)x * (HBARX2 - HBARX1 - 3) / width + .5); 62: } 63: 64: 65: /* hofs -> xofs */ 66: int h2x(h, width) 67: int h, width; 68: { 69: return((double)h * width / (HBARX2 - HBARX1 - 3) + .5); 70: } 71: 72: 73: /* yofs -> vofs */ 74: int y2v(y, height) 75: int y, height; 76: { 77: return((double)y * (VBARY2 - VBARY1 - 3) / height + .5); 78: } 79: 80: 81: /* hofs -> xofs */ 82: int v2y(v, height) 83: int v, height; 84: { 85: return((double)v * height / (VBARY2 - VBARY1 - 3) + .5); 86: } 87: 88: 89: int getstep(left, right) 90: int left, right; 91: { 92: if (left) { 93: return(8); 94: } 95: else if (right) { 96: return(1); 97: } 98: else { 99: return(0); 100: } 101: } 102: 103: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 3 104: checkarrow(x, y, left, right, horv, step) 105: int x, y; 106: int left, right; 107: int *horv, *step; 108: { 109: *horv = *step = 0; 110: if ((VBARX1 <= x) && (x <= VBARX2)) { 111: if ((VBARY1 - ARROWBOXSIZE < y) && (y < VBARY1)) { 112: *horv = VERTICAL; 113: *step = -getstep(left, right); 114: } 115: else if ((VBARY2 < y) && (y <= VBARY2 + ARROWBOXSIZE)) { 116: *horv = VERTICAL; 117: *step = getstep(left, right); 118: } 119: } 120: else if ((HBARY1 <= y) && (y <= HBARY2)) { 121: if ((HBARX1 - ARROWBOXSIZE < x) && (x < HBARX1)) { 122: *horv = HORIZONTAL; 123: *step = -getstep(left, right); 124: } 125: else if ((HBARX2 < x) && (x < HBARX2 + ARROWBOXSIZE)) { 126: *horv = HORIZONTAL; 127: *step = getstep(left, right); 128: } 129: } 130: } 131: 132: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 4 133: #define ARROWPTS 8 134: drawarrows() 135: { 136: static char p[ARROWPTS][2] = { 137: {2,7}, {8, 1}, {8, 4}, {13, 4}, {13, 10}, {8, 10}, {8, 13}, {2, 7} 138: }; 139: int i; 140: 141: selscrn(SBAR); 142: setfcolord(BLACK); 143: filledbox(HBARX1 - ARROWBOXSIZE, HBARY1, HBARX1, HBARY2); 144: setfcolord(WHITE); 145: box(HBARX1 - ARROWBOXSIZE, HBARY1, HBARX1, HBARY2); 146: for (i = 1; i < ARROWPTS; i++) { 147: line(HBARX1 - ARROWBOXSIZE + p[i - 1][0], HBARY1 + p[i - 1][1], 148: HBARX1 - ARROWBOXSIZE + p[i][0], HBARY1 + p[i][1]); 149: } 150: setfcolord(BLACK); 151: filledbox(HBARX2, HBARY1, HBARX2 + ARROWBOXSIZE, HBARY2); 152: setfcolord(WHITE); 153: box(HBARX2, HBARY1, HBARX2 + ARROWBOXSIZE, HBARY2); 154: for (i = 1; i < ARROWPTS; i++) { 155: line(HBARX2 + ARROWBOXSIZE - p[i - 1][0], HBARY1 + p[i - 1][1], 156: HBARX2 + ARROWBOXSIZE - p[i][0], HBARY1 + p[i][1]); 157: } 158: setfcolord(BLACK); 159: filledbox(VBARX1, VBARY1 - ARROWBOXSIZE, VBARX2, VBARY1); 160: setfcolord(WHITE); 161: box(VBARX1, VBARY1 - ARROWBOXSIZE, VBARX2, VBARY1); 162: for (i = 1; i < ARROWPTS; i++) { 163: line(VBARX1 + p[i - 1][1], VBARY1 - ARROWBOXSIZE + p[i - 1][0], 164: VBARX1 + p[i][1], VBARY1 -ARROWBOXSIZE + p[i][0]); 165: } 166: setfcolord(BLACK); 167: filledbox(VBARX1, VBARY2, VBARX2, VBARY2 + ARROWBOXSIZE); 168: setfcolord(WHITE); 169: box(VBARX1, VBARY2, VBARX2, VBARY2 + ARROWBOXSIZE); 170: for (i = 1; i < ARROWPTS; i++) { 171: line(VBARX1 + p[i - 1][1], VBARY2 + ARROWBOXSIZE - p[i - 1][0], 172: VBARX1 + p[i][1], VBARY2 + ARROWBOXSIZE - p[i][0]); 173: } 174: filledbox(VBARX1, HBARY1, VBARX2, HBARY2); 175: setfcolord(BLACK); 176: box(VBARX1, HBARY1, VBARX2 - 1, HBARY2 - 1); 177: box(VBARX1 + 2, HBARY1 + 2, VBARX2 - 6, HBARY2 - 6); 178: box(VBARX1 + 5, HBARY1 + 5, VBARX2 - 3, HBARY2 - 3); 179: setfcolord(WHITE); 180: } 181: 182: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 5 183: onvbar(x, y, vofs, vlen) 184: int x, y; 185: int vofs, vlen; 186: { 187: return( 188: (VBARX1 + 2 <= x) && (x <= VBARX2 - 2) 189: && (VBARY1 + 2 + vofs <= y) && (y <= VBARY1 + 2 + vofs + vlen) 190: ); 191: } 192: 193: 194: onvarea(x, y) 195: int x, y; 196: { 197: return( 198: (VBARX1 + 2 <= x) && (x <= VBARX2 - 2) 199: && (VBARY1 + 2 <= y) && (y <= VBARY2 - 2) 200: ); 201: } 202: 203: 204: 205: vwrite(vofs, vlen) 206: int vofs; 207: int vlen; 208: { 209: vofs = region(vofs, 0, VBARY2 - VBARY1 - vlen - 4); 210: selscrn(SBAR); 211: setfcolord(WHITE); 212: box(VBARX1, VBARY1, VBARX2, VBARY2); 213: setfcolord(BLACK); 214: filledbox(VBARX1 + 1, VBARY1 + 1, VBARX2 - 1, VBARY2 - 1); 215: setfcolord(WHITE); 216: box(VBARX1 + 2, VBARY1 + 2 + vofs, VBARX2 - 2, VBARY1 + 2 + vofs + vlen); 217: } 218: 219: 220: vghost(vofs, vlen, gofs) 221: int vofs; 222: int vlen; 223: int gofs; 224: { 225: gofs = region(gofs, 0, VBARY2 - VBARY1 - vlen - 4); 226: selscrn(SBAR); 227: setfcolord(BLACK); 228: filledbox(VBARX1 + 1, VBARY1 + 1, VBARX2 - 1, VBARY2 - 1); 229: setfcolord(WHITE); 230: box(VBARX1 + 2, VBARY1 + 2 + vofs, VBARX2 - 2, VBARY1 + 2 + vofs + vlen); 231: styledbox(VBARX1 + 2, VBARY1 + 2 + gofs, 232: VBARX2 - 2, VBARY1 + 2 + gofs + vlen, GHOSTLINE); 233: } 234: 235: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 6 236: vmove(x, y, left, right, y0, vofs, vofs0, vlen, height) 237: int x, y, left, right, y0, *vofs, vofs0, vlen, height; 238: { 239: int lastofs = -1; 240: 241: while (left) { 242: *vofs = region(vofs0 + y - y0, 0, VBARY2 - VBARY1 - vlen - 4); 243: if (*vofs != lastofs) { 244: vghost(vofs0, vlen, *vofs); 245: lastofs = *vofs; 246: gotoxy(XYOFS, YYOFS); 247: fprintf(stderr, "%3d", v2y(*vofs, height)); 248: selscrn(DISPALL); 249: } 250: mstatus(&x, &y, &left, &right); 251: } 252: if (!onvarea(x, y)) { 253: *vofs = vofs0; 254: } 255: } 256: 257: 258: vbar(height, ysize, yofs) 259: int height; 260: int ysize; 261: int *yofs; 262: { 263: int x, y, left, right; 264: int vofs, vofs0, vlen; 265: int y0; 266: 267: vlen = y2v(ysize, height); 268: vofs = y2v(*yofs, height); 269: mstatus(&x, &y, &left, &right); 270: if (left && onvarea(x, y)) { 271: vofs0 = vofs; 272: if (onvbar(x, y, vofs, vlen)) { 273: y0 = y; 274: } 275: else { 276: y0 = VBARY1 + vofs0 + vlen / 2; 277: vofs = vofs0 + (y - y0); 278: } 279: vmove(x, y, left, right, y0, &vofs, vofs0, vlen, height); 280: vwrite(vofs, vlen); 281: *yofs = v2y(vofs, height); 282: gotoxy(XYOFS, YYOFS); 283: fprintf(stderr, "%3d", *yofs); 284: selscrn(DISPALL); 285: } 286: } 287: 288: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 7 289: onhbar(x, y, hofs, hlen) 290: int x, y; 291: int hofs, hlen; 292: { 293: return( 294: (HBARX1 + 2 + hofs <= x) && (x <= HBARX1 + 2 + hofs + hlen) 295: && (HBARY1 <= y) && (y <= HBARY2) 296: ); 297: } 298: 299: 300: onharea(x, y) 301: int x, y; 302: { 303: return( 304: (HBARX1 + 2 <= x) && (x <= HBARX2 - 2) 305: && (HBARY1 + 2 <= y) && (y <= HBARY2 - 2) 306: ); 307: } 308: 309: 310: hwrite(hofs, hlen) 311: int hofs; 312: int hlen; 313: { 314: hofs = region(hofs, 0, HBARX2 - HBARX1 - hlen - 4); 315: selscrn(SBAR); 316: setfcolord(WHITE); 317: box(HBARX1, HBARY1, HBARX2, HBARY2); 318: setfcolord(BLACK); 319: filledbox(HBARX1 + 1, HBARY1 + 1, HBARX2 - 1, HBARY2 - 1); 320: setfcolord(WHITE); 321: box(HBARX1 + 2 + hofs, HBARY1 + 2, HBARX1 + 2 + hofs + hlen, HBARY2 - 2); 322: } 323: 324: 325: hghost(hofs, hlen, gofs) 326: int hofs; 327: int hlen; 328: int gofs; 329: { 330: gofs = region(gofs, 0, HBARX2 - HBARX1 - hlen - 4); 331: selscrn(SBAR); 332: setfcolord(BLACK); 333: filledbox(HBARX1 + 1, HBARY1 + 1, HBARX2 - 1, HBARY2 - 1); 334: setfcolord(WHITE); 335: box(HBARX1 + 2 + hofs, HBARY1 + 2, HBARX1 + 2 + hofs + hlen, HBARY2 - 2); 336: styledbox(HBARX1 + 2 + gofs, HBARY1 + 2, 337: HBARX1 + 2 + gofs + hlen, HBARY2 - 2, GHOSTLINE); 338: } 339: 340: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 8 341: hmove(x, y, left, right, x0, hofs, hofs0, hlen, width) 342: int x, y, left, right, x0, *hofs, hofs0, hlen, width; 343: { 344: int lastofs = -1; 345: 346: while (left) { 347: *hofs = region(hofs0 + x - x0, 0, HBARX2 - HBARX1 - hlen - 4); 348: if (*hofs != lastofs) { 349: hghost(hofs0, hlen, *hofs); 350: lastofs = *hofs; 351: gotoxy(XXOFS, YXOFS); 352: fprintf(stderr, "%3d", h2x(*hofs, width)); 353: selscrn(DISPALL); 354: } 355: mstatus(&x, &y, &left, &right); 356: } 357: if (!onharea(x, y)) { 358: *hofs = hofs0; 359: } 360: } 361: 362: 363: hbar(width, xsize, xofs) 364: int width; 365: int xsize; 366: int *xofs; 367: { 368: int x, y, left, right; 369: int hofs, hofs0, hlen; 370: int x0; 371: 372: hlen = x2h(xsize, width); 373: hofs = x2h(*xofs, width); 374: mstatus(&x, &y, &left, &right); 375: if (left && onharea(x, y)) { 376: hofs0 = hofs; 377: if (onhbar(x, y, hofs, hlen)) { 378: x0 = x; 379: } 380: else { 381: x0 = HBARX1 + hofs0 + hlen / 2; 382: hofs = hofs0 + (x - x0); 383: } 384: hmove(x, y, left, right, x0, &hofs, hofs0, hlen, width); 385: hwrite(hofs, hlen); 386: *xofs = h2x(hofs, width); 387: gotoxy(XXOFS, YXOFS); 388: fprintf(stderr, "%3d", *xofs); 389: selscrn(DISPALL); 390: } 391: } 392: 393: Tue Nov 17 19:44:57 2020 Listing sb.c Page: 9 394: sb(width, height, xsize, ysize, xofs, yofs) 395: int width, height; 396: int xsize, ysize; 397: int *xofs, *yofs; 398: { 399: int x, y, left, right; 400: int horv, step; 401: 402: mstatus(&x, &y, &left, &right); 403: checkarrow(x, y, left, right, &horv, &step); 404: if (step != 0 && horv == HORIZONTAL) { 405: *xofs = region(*xofs + step, 0, width - xsize); 406: selscrn(SBAR); 407: hwrite(x2h(*xofs, width), x2h(xsize, width)); 408: selscrn(DISPALL); 409: } 410: else if (step != 0 && horv == VERTICAL) { 411: *yofs = region(*yofs + step, 0, height - ysize); 412: selscrn(SBAR); 413: vwrite(y2v(*yofs, height), y2v(ysize, height)); 414: selscrn(DISPALL); 415: } 416: else if (left && onharea(x, y)) { 417: hbar(width, xsize, xofs); 418: } 419: else if (left && onvarea(x, y)) { 420: vbar(height, ysize, yofs); 421: } 422: gotoxy(XGEO, YGEO); 423: fprintf(stderr, "%3dx%3d+%3d+%3d", xsize, ysize, *xofs, *yofs); 424: } Tue Nov 17 19:44:57 2020 Listing main.c Page: 1 1: /* 2: 3: */ 4: 5: static char *progid = "@(#)main.c 0.1 (Dai Ishijima) Nov. 25, 1991"; 6: 7: #include 8: #include 9: 10: #include "gl.h" 11: #include "ms.h" 12: #include "crtctrl.h" 13: #include "bed.h" 14: 15: char *progname; 16: 17: #ifdef MOUSEP 18: char mousep[] = { 19: 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 20: 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0xff, 0xff, 21: 0xff, 0xff, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 22: 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 23: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 26: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00 27: }; 28: #endif 29: 30: main() 31: { 32: int width, height; 33: 34: progname = "bed"; 35: 36: if (minit() == MCANTUSE) { 37: fprintf(stderr, "mouse driver is not installed\n"); 38: exit(1); 39: } 40: mhide(); 41: #ifdef MOUSEP 42: mcursor(7, 7, mousep); 43: #endif 44: ginit(); 45: gscreen(3, 0, 0, 1); 46: setview(0, 0, 639, 399); 47: setfcolord(WHITE); 48: initpalette(); 49: gcls(); 50: 51: sysline(TEXT_OFF); 52: cursor(TEXT_OFF); 53: clrscr(); 54: Tue Nov 17 19:44:57 2020 Listing main.c Page: 2 55: selscrn(BUFS); 56: getsize(stdin, &width, &height); 57: readbitmap(stdin, width, height); 58: drawboard(min(100, width), min(100, height), 4); 59: edit(width, height); 60: mhide(); 61: /* gcls(); */ 62: gscreen(3, 3, 0, 0); 63: writebitmap(width, height); 64: cursor(TEXT_ON); 65: sysline(TEXT_ON); 66: exit(0); 67: } Tue Nov 17 19:44:57 2020 Listing file.c Page: 1 1: /* 2: 3: file.c Nov. 18, 1991 4: Apr. 30, 1992 5: 6: */ 7: 8: static char *progid = "@(#)file.c 0.1 (Dai Ishijima) Nov. 18, 1991"; 9: 10: #include 11: #include 12: #include 13: 14: #include "gl.h" 15: #include "bed.h" 16: 17: #ifdef _MSC_VER 18: # include "poke.h" 19: #endif 20: 21: 22: /* skip to string *s */ 23: int skipto(fp, s) 24: FILE *fp; 25: char *s; 26: { 27: int ch; 28: char *t; 29: 30: t = s; 31: while (*t != '\0') { 32: if ((ch = getc(fp)) == EOF) { 33: return(ch); 34: } 35: if (ch == *t) { 36: ++t; 37: } 38: else { 39: t = s; 40: if (ch == *t) { 41: ++t; 42: } 43: } 44: } 45: return(ch); 46: } 47: 48: Tue Nov 17 19:44:57 2020 Listing file.c Page: 2 49: /* get width, height from bitmap file header */ 50: getsize(fp, width, height) 51: FILE *fp; 52: int *width; 53: int *height; 54: { 55: skipto(fp, "#define"); 56: skipto(fp, "_width"); 57: if (fscanf(fp, "%d", width) < 1) { 58: fprintf(fp, "%s: can't get width\n", progname); 59: exit(1); 60: } 61: skipto(fp, "#define"); 62: skipto(fp, "_height"); 63: if (fscanf(fp, "%d", height) < 1) { 64: fprintf(fp, "%s: can't get height\n", progname); 65: exit(1); 66: } 67: skipto(fp, "bits[]"); 68: skipto(fp, "{"); 69: } 70: 71: Tue Nov 17 19:44:57 2020 Listing file.c Page: 3 72: int getbyte(fp) 73: FILE *fp; 74: { 75: int ch; 76: int d; 77: 78: ch = getc(fp); 79: while (!(isxdigit(ch))) { 80: if (ch == EOF) { 81: return(EOF); 82: } 83: ch = getc(fp); 84: } 85: if (ch == '0') { 86: ch = getc(fp); 87: if (isxdigit(ch)) { 88: ungetc(ch, fp); 89: } 90: else if ((ch != 'x') && (ch != 'X')) { 91: return(0); 92: } 93: } 94: else { 95: ungetc(ch, fp); 96: } 97: if (fscanf(fp, "%x", &d) < 1) { 98: while ((ch = getc(fp)) != '\n') { 99: if (ch == EOF) 100: break; 101: putc(ch, stderr); 102: } 103: return(EOF); 104: } 105: else { 106: return(d); 107: } 108: } 109: 110: #define MASK8 0xff 111: 112: /* reverse bit order */ 113: unsigned int bitrev(b) 114: unsigned int b; 115: { 116: static unsigned char p[] = { 117: 0x00, 0x08, 0x04, 0x0c, 118: 0x02, 0x0a, 0x06, 0x0e, 119: 0x01, 0x09, 0x05, 0x0d, 120: 0x03, 0x0b, 0x07, 0x0f 121: }; 122: b &= MASK8; 123: return(p[b % 16] * 16 + p[b / 16]); 124: } 125: 126: Tue Nov 17 19:44:57 2020 Listing file.c Page: 4 127: #define WORKVRAM 0xb000 128: #define BYTESOFLINE 80 129: #define vramaddress(x, y) (y * BYTESOFLINE + x) 130: 131: /* store bitmap into video ram */ 132: readbitmap(fp, width, height) 133: FILE *fp; 134: int width, height; 135: { 136: int x, y; 137: int b; 138: 139: selscrn(BUFS); 140: gdcwait(); 141: for (y = 0; y < height; y++) { 142: for (x = 0; x < (width + 7) / 8; x++) { 143: if ((b = getbyte(fp)) == EOF) { 144: fprintf(stderr, "%s: unexpected EOF\n", progname); 145: fprintf(stderr, "%dx%d\n", width, height); 146: fprintf(stderr, "%d, %d", x, y); 147: exit(1); 148: } 149: pokeb(WORKVRAM, vramaddress(x, y), ~bitrev(b)); 150: } 151: } 152: } 153: 154: Tue Nov 17 19:44:57 2020 Listing file.c Page: 5 155: #define OUTFIL "bedout.xbm" 156: #define NFIELDS 12 157: 158: writebitmap(width, height) 159: int width; 160: int height; 161: { 162: FILE *fp; 163: int x, y, n; 164: 165: if ((fp = fopen(OUTFIL, "w")) == NULL) { 166: fprintf(stderr, "%s: can't open %s.\n", progname, OUTFIL); 167: exit(1); 168: } 169: fprintf(fp, "#define bed_width %d\n", width); 170: fprintf(fp, "#define bed_height %d\n", height); 171: fprintf(fp, "static char bed_bits[] = { \n"); 172: n = 0; 173: for (y = 0; y < height; y++) { 174: for (x = 0; x < (width + 7) / 8; x++) { 175: fprintf(fp, "0x"); 176: fprintf(fp, "%02x", 177: (~bitrev(peekb(WORKVRAM, vramaddress(x, y)))) & MASK8); 178: ++n; 179: if (n % NFIELDS == 0) { 180: fprintf(fp, ",\n "); 181: } 182: else if (n >= height * ((width + 7) / 8)) { 183: fprintf(fp, "};\n"); 184: } 185: else { 186: fprintf(fp, ", "); 187: } 188: } 189: } 190: fclose(fp); 191: } Tue Nov 17 19:44:57 2020 Listing be.c Page: 1 1: /* 2: 3: be.c 4: 5: */ 6: 7: static char *progid = "@(#)be.c 0.1 (Dai Ishijima) Nov. 25, 1991"; 8: 9: #include 10: #include 11: #include 12: #include "gl.h" 13: #include "bed.h" 14: #include "crtctrl.h" 15: 16: #ifdef _MSC_VER 17: # include "poke.h" 18: #endif 19: 20: 21: /* */ 22: #define seg(p) (FP_SEG((char far *)p)) 23: #define ofs(p) (FP_OFF((char far *)p)) 24: #define BUFSVRAM 0xb000 25: #define EDITVRAM 0xa800 26: #define BYTESOFLINE 80 27: #define DOTTED (0x5555U) 28: 29: static unsigned char x2[] = { 30: 0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, 31: 0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff 32: }; 33: 34: static unsigned char x6[16][3] = { 35: {0x00, 0x00, 0x00}, {0x00, 0x00, 0x3f}, 36: {0x00, 0x0f, 0xc0}, {0x00, 0x0f, 0xff}, 37: {0x03, 0xf0, 0x00}, {0x03, 0xf0, 0x3f}, 38: {0x03, 0xff, 0xc0}, {0x03, 0xff, 0xff}, 39: {0xfc, 0x00, 0x00}, {0xfc, 0x00, 0x3f}, 40: {0xfc, 0x0f, 0xc0}, {0xfc, 0x0f, 0xff}, 41: {0xff, 0xf0, 0x00}, {0xff, 0xf0, 0x3f}, 42: {0xff, 0xff, 0xc0}, {0xff, 0xff, 0xff} 43: }; 44: 45: Tue Nov 17 19:44:57 2020 Listing be.c Page: 2 46: makeline(work, mag, start, n, shiftbits) 47: unsigned char *work; 48: int mag, start, n, shiftbits; 49: { 50: int x; 51: unsigned char d, a, b; 52: 53: for (x = 0; x < n; x++) { 54: d = ((unsigned int)((unsigned char)peekb(BUFSVRAM, start + x) * 256 55: + (unsigned char)peekb(BUFSVRAM, start + x + 1)) << shiftbits) 56: / 256; 57: if (mag == 1) { 58: work[x] = d; 59: } 60: else if (mag == 2) { 61: work[x * mag] = x2[d / 16]; 62: work[x * mag + 1] = x2[d % 16]; 63: } 64: else if (mag == 4) { 65: a = x2[d / 16]; 66: b = x2[d % 16]; 67: work[x * mag] = x2[a / 16]; 68: work[x * mag + 1] = x2[a % 16]; 69: work[x * mag + 2] = x2[b / 16]; 70: work[x * mag + 3] = x2[b % 16]; 71: } 72: else if (mag == 6) { 73: for (a = 0; a < 3; a++) { 74: work[x * mag + a] = x6[d / 16][a]; 75: work[x * mag + a + 3] = x6[d % 16][a]; 76: } 77: } 78: else if (mag == 8) { 79: for (a = 128, b = x * mag; a > 0; a /= 2, b++) { 80: work[b] = (d & a) ? 0xff : 0; 81: } 82: } 83: else if (mag == 16) { 84: for (a = 128, b = x * mag; a > 0; a /= 2, b += 2) { 85: work[b] = work[b + 1] = (d & a) ? 0xff : 0; 86: } 87: } 88: } 89: } 90: 91: Tue Nov 17 19:44:57 2020 Listing be.c Page: 3 92: toboard(mag, xsize, ysize, xofs, yofs) 93: int mag; 94: int xsize, ysize; 95: int xofs, yofs; 96: { 97: int x, y; 98: int shiftbits, n, m, start; 99: unsigned char work[50]; 100: unsigned int destin = 0; 101: 102: n = (xsize + 7) / 8; 103: m = (xsize * mag + 7) / 8; 104: shiftbits = xofs % 8; 105: start = yofs * BYTESOFLINE + xofs / 8; 106: selscrn(BUFS); 107: gdcwait(); 108: for (y = 0; y < ysize; y++) { 109: makeline(work, mag, start, n, shiftbits); 110: start += BYTESOFLINE; 111: for (x = 0; x < mag; x++) { 112: movedata(seg(work), ofs(work), EDITVRAM, destin, m); 113: destin += BYTESOFLINE; 114: } 115: } 116: } 117: 118: 119: drawmesh(xsize, ysize, mag) 120: int xsize, ysize, mag; 121: { 122: int x, y, xmax, ymax; 123: 124: if (mag <= 2) 125: return; 126: xmax = min(xsize * mag, MAXSIZE - 1); 127: ymax = min(ysize * mag, MAXSIZE - 1); 128: selscrn(EDIT); 129: for (y = 0; y <= ymax; y += mag) { 130: styledcline(0, y, xmax, y, BLACK, DOTTED); 131: styledcline(0, y, xmax, y, WHITE, ~DOTTED); 132: } 133: for (x = 0; x <= xmax; x += mag) { 134: styledcline(x, 0, x, ymax, BLACK, DOTTED); 135: styledcline(x, 0, x, ymax, WHITE, ~DOTTED); 136: } 137: } 138: 139: Tue Nov 17 19:44:57 2020 Listing be.c Page: 4 140: drawboard(xsize, ysize, mag) 141: int xsize, ysize, mag; 142: { 143: int x, y, xmax, ymax; 144: 145: xmax = min(xsize * mag, MAXSIZE - 1); 146: ymax = min(ysize * mag, MAXSIZE - 1); 147: selscrn(EDIT); 148: setfcolord(WHITE); 149: filledbox(0, 0, xmax, ymax); 150: setfcolord(BLACK); 151: for (y = 0; y <= ymax; y += mag) { 152: styledline(0, y, xmax, y, DOTTED); 153: } 154: for (x = 0; x <= xmax; x += mag) { 155: styledline(x, 0, x, ymax, DOTTED); 156: } 157: setfcolord(WHITE); 158: } 159: 160: #define XMAG 60 161: #define YMAG 5 162: 163: printmagmenu() 164: { 165: gotoxy(XMAG, YMAG); 166: /* 012345678900123456789 */ 167: fprintf(stderr, "x1 x2 x4 x6 x8 x16"); 168: } 169: 170: Tue Nov 17 19:44:57 2020 Listing be.c Page: 5 171: checkmag(mag) 172: int *mag; 173: { 174: int x, y, left, right; 175: 176: mstatus(&x, &y, &left, &right); 177: x /= 8; 178: y /= 16; 179: if (y == YMAG && left) { 180: x -= XMAG; 181: if (0 <= x && x <= 1) { 182: *mag = 1; 183: } 184: else if (3 <= x && x <= 4) { 185: *mag = 2; 186: } 187: else if (6 <= x && x <= 7) { 188: *mag = 4; 189: } 190: else if (9 <= x && x <= 10) { 191: *mag = 6; 192: } 193: else if (12 <= x && x <= 13) { 194: *mag = 8; 195: } 196: else if (15 <= x && x <= 16) { 197: *mag = 16; 198: } 199: } 200: } 201: 202: 203: resetsize(width, height, mag, xsize, ysize, usesb) 204: int width, height; 205: int mag; 206: int *xsize, *ysize; 207: int *usesb; 208: { 209: int msize; 210: 211: msize = MAXSIZE / mag; 212: 213: *usesb = NO; 214: if (width > msize || height > msize) { 215: *usesb = YES; 216: msize = (MAXSIZE - SBWIDTH) / mag; 217: } 218: *xsize = min(width, msize); 219: *ysize = min(height, msize); 220: } 221: 222: Tue Nov 17 19:44:57 2020 Listing be.c Page: 6 223: int newofs(max, size, size0, ofs0) 224: int max, size, size0, ofs0; 225: { 226: if (ofs0 <= 0) { 227: return(0); 228: } 229: else if (ofs0 >= max - size0) { 230: return(max - size); 231: } 232: else { 233: return(region((int)(ofs0 + .5 * (size0 - size)), 0, max - size)); 234: } 235: } 236: 237: 238: sbscrn(width, height, xsize, ysize, xofs, yofs) 239: int width, height, xsize, ysize, xofs, yofs; 240: { 241: selscrn(SBAR); 242: drawarrows(); 243: hwrite(x2h(xofs, width), x2h(xsize, width)); 244: vwrite(y2v(yofs, height), y2v(ysize, height)); 245: } 246: 247: 248: unsigned int getmask(shift, mag) 249: int shift, mag; 250: { 251: if (mag == 1) { 252: return((unsigned)0x8000 >> shift); 253: } 254: else if (mag == 2) { 255: return((unsigned)0xc000 >> shift); 256: } 257: else if (mag == 4) { 258: return((unsigned)0x7000 >> shift); 259: } 260: else if (mag == 6) { 261: return((unsigned)0x7c00 >> shift); 262: } 263: else if (mag == 8) { 264: return(0x7f00); 265: } 266: else if (mag == 16) { 267: return(0x7fff); 268: } 269: } 270: 271: Tue Nov 17 19:44:57 2020 Listing be.c Page: 7 272: onoff(x, y, xofs, yofs, mag, col) 273: int x, y, xofs, yofs, mag, col; 274: { 275: int x0, y0, a, i; 276: unsigned int d, m; 277: 278: gdcwait(); 279: a = y * BYTESOFLINE + x / 8; 280: d = (unsigned char)peekb(BUFSVRAM, a); 281: m = (unsigned)0x80 >> (x % 8); 282: if (col) { 283: d |= m; 284: } 285: else { 286: d &= ~m; 287: } 288: pokeb(BUFSVRAM, a, d); 289: x0 = (x - xofs) * mag; 290: y0 = (y - yofs) * mag; 291: a = y0 * 80 + x0 / 8; 292: m = getmask(x0 % 8, mag); 293: for (i = 0; i < mag; i++) { 294: if (mag == 1 || mag == 2 || i != 0) { 295: d = (unsigned char)peekb(EDITVRAM, a) * 256 296: + (unsigned char)peekb(EDITVRAM, a + 1); 297: if (col) { 298: d |= m; 299: } 300: else { 301: d &= ~m; 302: } 303: pokeb(EDITVRAM, a, d / 256); 304: pokeb(EDITVRAM, a + 1, d % 256); 305: } 306: a += BYTESOFLINE; 307: } 308: } 309: 310: Tue Nov 17 19:44:57 2020 Listing be.c Page: 8 311: setreset(x, y, left, right, xsize, ysize, mag, xofs, yofs) 312: int x, y, left, right, xsize, ysize, mag, xofs, yofs; 313: { 314: static int rx = -1; 315: static int ry = -1; 316: static int lx = -1; 317: static int ly = -1; 318: 319: x /= mag; 320: y /= mag; 321: if (x < xsize && y < ysize) { 322: x += xofs; 323: y += yofs; 324: if (left && (lx != x || ly != y)) { 325: gotoxy(60, 1); 326: printf("%3d %3d", x, y); 327: lx = x; ly = y; 328: rx = ry = -1; 329: onoff(x, y, xofs, yofs, mag, BLACK); 330: } 331: else if (right && (rx != x || ry != y)) { 332: gotoxy(60, 1); 333: printf("%3d %3d", x, y); 334: rx = x; ry = y; 335: lx = ly = -1; 336: onoff(x, y, xofs, yofs, mag, WHITE); 337: } 338: else if (!left && !right) { 339: gotoxy(60, 1); 340: printf("%3d %3d", x, y); 341: } 342: return(YES); 343: } 344: else { 345: gotoxy(60, 1); 346: printf("*** ***"); 347: return(NO); 348: } 349: } 350: 351: Tue Nov 17 19:44:57 2020 Listing be.c Page: 9 352: edit(width, height) 353: int width, height; 354: { 355: int x, y, left, right; 356: int xsize, ysize; 357: int mag, mag0; 358: int xofs, yofs, xofs0, yofs0; 359: int usesb, mesh; 360: int lxofs, lyofs, lxsize, lysize; 361: Tue Nov 17 19:44:57 2020 Listing be.c Page: 10 362: printmagmenu(); 363: mag = 4; 364: resetsize(width, height, mag, &xsize, &ysize, &usesb); 365: xofs = yofs = 0; 366: selscrn(BUFS); 367: if (usesb) { 368: sbscrn(width, height, xsize, ysize, xofs, yofs); 369: selscrn(BUFS); 370: lxofs = xofs; lyofs = yofs; 371: lxsize = xsize; lysize = ysize; 372: } 373: toboard(mag, xsize, ysize, xofs, yofs); 374: drawmesh(xsize, ysize, mag); 375: mesh = YES; 376: selscrn(DISPALL); 377: while (1) { 378: mstatus(&x, &y, &left, &right); 379: gotoxy(60, 0); 380: printf("%3d %3d", x, y); 381: if (!setreset(x, y, left, right, xsize, ysize, mag, xofs, yofs)) { 382: if (!mesh && !left && !right) { 383: drawmesh(xsize, ysize, mag); 384: selscrn(DISPALL); 385: mesh = YES; 386: } 387: xofs0 = xofs; yofs0 = yofs; 388: sb(width, height, xsize, ysize, &xofs, &yofs); 389: mag0 = mag; 390: checkmag(&mag); 391: if (xofs0 != xofs || yofs0 != yofs || mag0 != mag) { 392: selscrn(EDIT); 393: if (mag0 != mag) { 394: resetsize(width, height, mag, &xsize, &ysize, &usesb); 395: if (!usesb && mag < mag0) { 396: setfcolord(BLACK); 397: filledbox(0, 0, MAXSIZE, MAXSIZE); 398: setfcolord(WHITE); 399: } 400: if (usesb) { 401: xofs = newofs(width, xsize, lxsize, lxofs); 402: yofs = newofs(height, ysize, lysize, lyofs); 403: sbscrn(width, height, xsize, ysize, xofs, yofs); 404: lxofs = xofs; lxsize = xsize; 405: lyofs = yofs; lysize = ysize; 406: } 407: else { 408: xofs = 0; 409: yofs = 0; 410: } 411: } /* mag0 != mag */ 412: else if (usesb) { 413: lxofs = xofs; 414: lyofs = yofs; 415: } 416: toboard(mag, xsize, ysize, xofs, yofs); 417: mesh = NO; 418: selscrn(DISPALL); 419: } 420: else { 421: if (left && x > 624 && y > 384) { Tue Nov 17 19:44:57 2020 Listing be.c Page: 11 422: break; 423: } 424: else if (right && x > 600) { 425: mhide(); 426: ginit(); 427: initpalette(); 428: selscrn(DISPALL); 429: } 430: } 431: } 432: } 433: } Tue Nov 17 19:44:57 2020 Listing misc.c Page: 1 1: /* 2: 3: */ 4: 5: static char *progid = "@(#)misc.c 0.1 (Dai Ishijima) Nov. 18, 1991"; 6: 7: #include 8: #include 9: #include "gl.h" 10: #include "ms.h" 11: 12: #include "bed.h" 13: 14: static char pal[] = {0, 7, 0, 7, 2, 2, 2, 2}; 15: 16: initpalette() 17: { 18: int i; 19: 20: for (i = 0; i < 8; i++) { 21: gpalette(i, pal[i]); 22: } 23: } 24: 25: 26: selscrn(n) 27: int n; 28: { 29: switch(n) { 30: case DISPALL: 31: initpalette(); 32: gscreen(3, 0, 0, 1); 33: mdisplay(); 34: msetfreq(MFNORM); 35: break; 36: case SBAR: 37: msetfreq(MFOCT); 38: mhide(); 39: gscreen(2, 0, 0, 1); 40: break; 41: case BUFS: 42: msetfreq(MFOCT); 43: mhide(); 44: gscreen(2, 0, 1, 1); 45: break; 46: } 47: } 48:  Tue Nov 17 19:44:57 2020 Listing gl.c Page: 1 1: /* 2: 3: graphics lio handlers for PC-9801 series personal computer 4: 5: Copyright (C) by Dai Ishijima (ishijima@nuclear.dj.kit.ac.jp) 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: 16: */ 17: 18: static char *progid = "@(#)gl.c 0.3 (Dai Ishijima) Dec. 21, 1991"; 19: 20: /* 21: C A U T I O N : 22: 23: This program overwrites the table of interrupt vectors (0xa0..0xaf, 24: 0xc5, 0xce). If the DOS or TSR programs used these interrupts, the 25: machine might be out of order. 26: 27: */ 28: 29: #include 30: #include 31: #include 32: 33: #ifdef _MSC_VER 34: # include "poke.h" 35: #endif 36: 37: #include "gl.h" 38: 39: /* 40: local (static) constants 41: */ 42: /* about graphics logical input/output */ 43: #define SEGLIO 0xf990 /* segment of GLIO entry */ 44: #define SIZEOFWORK 0x1400 /* size of GLIO work area */ 45: #define TOPOFPWORK 0x06a0 /* GPAINT work area start address */ 46: #define ENDOFPWORK 0x0fff /* GPAINT work area end address */ 47: /* This area (0x6a0..0xfff) is not used by GLIO */ 48: #define OFSOFINT 4 /* offset of interrupt number */ 49: #define OFSOFVEC 6 /* offset of interrupt vector */ 50: #define SIZEOFVEC 4 /* size of vector: 4 bytes (seg + ofs) */ 51: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 2 52: /* interrupt numbers */ 53: #define GINIT 0xa0 54: #define GSCREEN 0xa1 55: #define GVIEW 0xa2 56: #define GCOLOR 0xa3 57: #define GPALETTE 0xa4 58: #define GCLS 0xa5 59: #define GPSET 0xa6 60: #define GLINE 0xa7 61: #define GCIRCLE 0xa8 62: #define GPAINT 0xa9 63: #define GTILE 0xaa 64: #define GGET 0xab 65: #define GPUT 0xac 66: #define GPRINT 0xad 67: #define GROLL 0xae 68: #define GPOINT 0xaf 69: #define GCOPY 0xce 70: #define INTFORSTOP 0xc5 /* interrupt No. for check STOP */ 71: 72: /* pset/preset flag in GPSET */ 73: #define PSETFLAG 1 74: #define PRESETFLAG 2 75: 76: /* about 80x86 */ 77: #define IRETCODE (unsigned char)0xcf 78: 79: /* about GDC (mPD7220) */ 80: #define GDCSTATUS 0xa0 /* GDC read status */ 81: #define ISEMPTY 4 82: #define ISDRAWING 8 83: 84: /* 85: macros 86: */ 87: /* get segment/offset of pointer *p */ 88: #define seg(p) (FP_SEG((char far *)(p))) 89: #define ofs(p) (FP_OFF((char far *)(p))) 90: 91: /* 92: variables 93: */ 94: /* GLIO work area */ 95: static union workarea { 96: unsigned char dummy[SIZEOFWORK]; 97: 98: struct screen_args { 99: unsigned char mode; 100: unsigned char sw; 101: unsigned char active; 102: unsigned char display; 103: } screen; 104: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 3 105: struct view_args { 106: int x1; 107: int y1; 108: int x2; 109: int y2; 110: unsigned char background; 111: unsigned char border; 112: } view; 113: 114: struct color_args { 115: unsigned char junk; 116: unsigned char background; 117: unsigned char border; 118: unsigned char foreground; 119: unsigned char palmode; 120: } color; 121: 122: struct palette_args { 123: unsigned char pal; 124: unsigned int col; 125: } palette; 126: 127: struct pset_args { 128: int x; 129: int y; 130: unsigned char pal; 131: } pset; 132: 133: struct line_args { 134: int x1; 135: int y1; 136: int x2; 137: int y2; 138: unsigned char pal; 139: unsigned char code; 140: unsigned char sw; 141: unsigned char pal2; 142: unsigned char stylehi; 143: unsigned char tile_len; 144: unsigned int tile_ofs; 145: unsigned int tile_seg; 146: } line; 147: 148: struct circle_args { 149: int cx; 150: int cy; 151: int rx; 152: int ry; 153: unsigned char pal; 154: unsigned char flag; 155: int sx; 156: int sy; 157: int ex; 158: int ey; 159: unsigned char pal2; 160: unsigned int tile_ofs; 161: unsigned int tile_seg; 162: } circle; 163: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 4 164: struct paint_args { 165: int x; 166: int y; 167: unsigned char region; 168: unsigned char border; 169: unsigned int work_end; 170: unsigned int work_start; 171: } paint; 172: 173: struct tile_args { 174: int x; 175: int y; 176: unsigned char junk; 177: unsigned char len; 178: unsigned int offset; 179: unsigned int segment; 180: unsigned char border; 181: unsigned char junk2[5]; 182: unsigned int work_end; 183: unsigned int work_start; 184: } tile; 185: 186: struct get_args { 187: int x1; 188: int y1; 189: int x2; 190: int y2; 191: unsigned int offset; 192: unsigned int segment; 193: unsigned int len; 194: } get; 195: 196: struct put_args { 197: int x; 198: int y; 199: unsigned int offset; 200: unsigned int segment; 201: unsigned int len; 202: unsigned char mode; 203: unsigned char sw; 204: unsigned char foreground; 205: unsigned char background; 206: } put; 207: 208: struct print_args { 209: int x; 210: int y; 211: int code; 212: unsigned char mode; 213: unsigned char sw; 214: unsigned char foreground; 215: unsigned char background; 216: } print; 217: 218: struct roll_args { 219: int vertical; 220: int horizontal; 221: unsigned char flag; 222: } roll; 223: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 5 224: struct point_args { 225: int x; 226: int y; 227: } point; 228: } args; 229: 230: /* registers */ 231: static union REGS inregs, outregs; 232: static struct SREGS segregs; 233: static unsigned int gseg, gofs; 234: 235: 236: /* set interrupt vector for check stop key */ 237: setstopvec() 238: { 239: unsigned int i; 240: 241: /* search IRET code in SYSTEM ROM area */ 242: for (i = 0; i < (unsigned)0xffff; i++) { 243: if ((unsigned char)peekb(SEGLIO, i) == IRETCODE) { 244: break; 245: } 246: } 247: if ((unsigned char)peekb(SEGLIO, i) != IRETCODE) { 248: fprintf(stderr, "GLIO: can't find IRET code\n"); 249: exit(1); 250: } 251: # ifdef DEBUG 252: fprintf(stderr, "GLIO: address of IRET = %x:%x\n", SEGLIO, i); 253: # endif 254: poke(0, INTFORSTOP * SIZEOFVEC, i); 255: poke(0, INTFORSTOP * SIZEOFVEC + 2, SEGLIO); 256: } 257: 258: 259: /* set interrupt vectors */ 260: setgvec() 261: { 262: int intno; 263: int vect; 264: int n; 265: int i; 266: 267: n = (unsigned char)peekb(SEGLIO, 0); 268: for (i = 0; i < n; i++) { 269: intno = (unsigned char)peekb(SEGLIO, i * SIZEOFVEC + OFSOFINT); 270: vect = peek(SEGLIO, i * SIZEOFVEC + OFSOFVEC); 271: poke(0, intno * SIZEOFVEC, vect); 272: poke(0, intno * SIZEOFVEC + 2, SEGLIO); 273: } 274: } 275: 276: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 6 277: /* call graphics logical I/O */ 278: int intglio(intno) 279: int intno; 280: { 281: inregs.x.bx = gofs; 282: segregs.ds = gseg; 283: segregs.es = gseg; 284: int86x(intno, &inregs, &outregs, &segregs); 285: # ifdef DEBUG 286: if (outregs.h.ah != 0) { 287: fprintf(stderr, "GLIO: int(%x) returns %x\n", intno, outregs.h.ah); 288: } 289: # endif 290: return(outregs.h.ah); 291: } 292: 293: 294: /* initialize graphics LIO */ 295: ginit() 296: { 297: gseg = seg(&args); 298: gofs = ofs(&args); 299: setstopvec(); 300: setgvec(); 301: intglio(GINIT); 302: } 303: 304: 305: /* wait until GDC buffer free */ 306: gdcwait() 307: { 308: while (!(inp(GDCSTATUS) & ISEMPTY )) 309: ; /* wait until GDC FIFO is empty */ 310: args.dummy[TOPOFPWORK] = args.dummy[ENDOFPWORK]; 311: /* This code is NO effect */ 312: /* Does above statement cost 26 cpu clocks? */ 313: while ( (inp(GDCSTATUS) & ISDRAWING)) 314: ; /* wait until GDC is not drawing */ 315: } 316: 317: 318: /* set screen mode */ 319: int gscreen(mode, sw, active, display) 320: int mode; 321: int sw; 322: int active; 323: int display; 324: { 325: args.screen.mode = mode; 326: args.screen.sw = sw; 327: args.screen.active = active; 328: args.screen.display = display; 329: return(intglio(GSCREEN)); 330: } 331: 332: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 7 333: /* set viewport */ 334: int gview(x1, y1, x2, y2, background, border) 335: int x1, y1, x2, y2; 336: unsigned char background, border; 337: { 338: args.view.x1 = x1; 339: args.view.y1 = y1; 340: args.view.x2 = x2; 341: args.view.y2 = y2; 342: args.view.background = background; 343: args.view.border = border; 344: return(intglio(GVIEW)); 345: } 346: 347: 348: /* set forground, background, border color */ 349: int gcolor(bg, bd, fg, pm) 350: int bg, bd, fg, pm; 351: { 352: args.color.junk = 0; 353: args.color.background = bg; 354: args.color.border = bd; 355: args.color.foreground = fg; 356: args.color.palmode = pm; 357: return(intglio(GCOLOR)); 358: } 359: 360: 361: /* set color palette */ 362: int gpalette(p, c) 363: int p, c; 364: { 365: args.palette.pal = p; 366: args.palette.col = c; 367: return(intglio(GPALETTE)); 368: } 369: 370: 371: /* clear graphics screen */ 372: int gcls() 373: { 374: return(intglio(GCLS)); 375: } 376: 377: 378: /* draw a dot */ 379: int gpset(x, y, c) 380: int x, y, c; 381: { 382: args.pset.x = x; 383: args.pset.y = y; 384: args.pset.pal = c; 385: inregs.h.ah = PSETFLAG; 386: return(intglio(GPSET)); 387: } 388: 389: Tue Nov 17 19:44:57 2020 Listing gl.c Page: 8 390: /* draw a line */ 391: int gline(x1, y1, x2, y2, c, code, sw, c2, style, tlen, tile) 392: int x1, y1, x2, y2; 393: unsigned int c, code, sw, c2, style, tlen; 394: char *tile; 395: { 396: args.line.x1 = x1; 397: args.line.y1 = y1; 398: args.line.x2 = x2; 399: args.line.y2 = y2; 400: args.line.pal = c; 401: args.line.code = code; 402: args.line.sw = sw; 403: if (code == FILLEDBOX) { 404: args.line.pal2 = c2; 405: args.line.stylehi = 0; 406: } 407: else { 408: args.line.pal2 = style % 256; 409: args.line.stylehi = style / 256; 410: } 411: args.line.tile_len = tlen; 412: args.line.tile_ofs = ofs(tile); 413: args.line.tile_seg = seg(tile); 414: return(intglio(GLINE)); 415: } 416: 417: 418: /* return palette code of (x, y) */ 419: int gpoint(x, y) 420: int x, y; 421: { 422: args.point.x = x; 423: args.point.y = y; 424: intglio(GPOINT); 425: return((unsigned char)outregs.h.al); 426: } Tue Nov 17 19:44:57 2020 Listing ms.c Page: 1 1: /* 2: 3: ms.c -- mouse handler 4: 5: 0.0: Sep. 8, 1991 by Dai Ishijima 6: 7: */ 8: 9: static char *progid = "@(#)ms.c 0.0 (Dai Ishijima) Sep. 8, 1991"; 10: 11: #include 12: #include "ms.h" 13: 14: #define MOUSEINT 0x33 15: 16: #define MINIT 0 17: #define MDISP 1 18: #define MHIDE 2 19: #define MWHERE 3 20: #define MSETXY 4 21: #define MLPRESS 5 22: #define MLRELEASE 6 23: #define MRPRESS 7 24: #define MRRELEASE 8 25: #define MCURSOR 9 26: #define MDIST 11 27: #define MSENSE 15 28: #define MXREGION 16 29: #define MYREGION 17 30: #define MSPLANE 18 31: 32: #define seg(p) (FP_SEG((char far *)(p))) 33: #define ofs(p) (FP_OFF((char far *)(p))) 34: 35: static union REGS inregs, outregs; 36: static struct SREGS segregs; 37: 38: /* call mouse driver */ 39: int mintr(function) 40: int function; 41: { 42: inregs.x.ax = function; 43: return(int86x(MOUSEINT, &inregs, &outregs, &segregs)); 44: } 45: 46: 47: /* initialize mouse driver, return status */ 48: int minit() 49: { 50: msetfreq(MFNORM); 51: mintr(MINIT); 52: return(outregs.x.ax); 53: } 54: 55: Tue Nov 17 19:44:57 2020 Listing ms.c Page: 2 56: mdisplay() 57: { 58: mintr(MDISP); 59: } 60: 61: 62: mhide() 63: { 64: mintr(MHIDE); 65: } 66: 67: 68: mstatus(x, y, left, right) 69: int *x, *y, *left, *right; 70: { 71: mintr(MWHERE); 72: *x = outregs.x.cx; 73: *y = outregs.x.dx; 74: *left = outregs.x.ax; 75: *right = outregs.x.bx; 76: } 77: 78: 79: mwhere(x, y) 80: int *x, *y; 81: { 82: int left, right; 83: 84: mstatus(x, y, &left, &right); 85: } 86: 87: 88: msetxy(x, y) 89: int x, y; 90: { 91: inregs.x.cx = x; 92: inregs.x.dx = y; 93: mintr(MSETXY); 94: } 95: 96: 97: mleftpress(pressed, times, x, y) 98: int *pressed, *times, *x, *y; 99: { 100: mintr(MLPRESS); 101: *pressed = outregs.x.ax; 102: *times = outregs.x.bx; 103: *x = outregs.x.cx; 104: *y = outregs.x.dx; 105: } 106: 107: Tue Nov 17 19:44:57 2020 Listing ms.c Page: 3 108: mrightpress(pressed, times, x, y) 109: int *pressed, *times, *x, *y; 110: { 111: mintr(MRPRESS); 112: *pressed = outregs.x.ax; 113: *times = outregs.x.bx; 114: *x = outregs.x.cx; 115: *y = outregs.x.dx; 116: } 117: 118: 119: mleftrelease(released, times, x, y) 120: int *released, *times, *x, *y; 121: { 122: mintr(MLRELEASE); 123: *released = outregs.x.ax; 124: *times = outregs.x.bx; 125: *x = outregs.x.cx; 126: *y = outregs.x.dx; 127: } 128: 129: 130: mrightrelease(released, times, x, y) 131: int *released, *times, *x, *y; 132: { 133: mintr(MRRELEASE); 134: *released = outregs.x.ax; 135: *times = outregs.x.bx; 136: *x = outregs.x.cx; 137: *y = outregs.x.dx; 138: } 139: 140: 141: mcursor(xhot, yhot, pattern) 142: int xhot, yhot; 143: char *pattern; 144: { 145: segregs.es = seg(pattern); 146: inregs.x.dx = ofs(pattern); 147: inregs.x.bx = xhot; 148: inregs.x.cx = yhot; 149: mintr(MCURSOR); 150: } 151: 152: 153: mdistance(dx, dy) 154: int *dx, *dy; 155: { 156: mintr(MDIST); 157: *dx = outregs.x.cx; 158: *dy = outregs.x.dx; 159: } 160: 161: Tue Nov 17 19:44:57 2020 Listing ms.c Page: 4 162: msensitive(xs, ys) 163: int xs, ys; 164: { 165: inregs.x.cx = xs; 166: inregs.x.dx = ys; 167: mintr(MSENSE); 168: } 169: 170: 171: mxregion(x1, x2) 172: int x1, x2; 173: { 174: inregs.x.cx = x1; 175: inregs.x.dx = x2; 176: mintr(MXREGION); 177: } 178: 179: 180: myregion(y1, y2) 181: int y1, y2; 182: { 183: inregs.x.cx = y1; 184: inregs.x.dx = y2; 185: mintr(MYREGION); 186: } 187: 188: 189: msetplane(plane) 190: int plane; 191: { 192: inregs.x.bx = plane; 193: mintr(MSPLANE); 194: }