Jspice3
mfbopen.c
Go to the documentation of this file.
1 /*************************************************************************
2  MFB graphics and miscellaneous library
3  Copyright (c) Stephen R. Whiteley 1992
4  Author: Stephen R. Whiteley
5  *************************************************************************/
6 
7 #include "mfb.h"
8 #include "mfbP.h"
9 #include <dos.h>
10 #include <ctype.h>
11 
12 
13 MFB *MFBCurrent; /* current MFB structure, not used */
14 struct mfbpc pc; /* special structure to store stuff in */
15 char mfb_trash; /* return from latch read */
16 
17 /* So we can nest calls to MFBOpen(), we save the mfbpc structure. */
18 struct ctext {
19  struct mfbpc *pc;
20  struct ctext *next;
21 };
22 static struct ctext *Clist;
23 
24 static int mfb_vmode;
25 
26 #ifdef __STDC__
27 static int get_new_mode(char*,int*,int*,int*);
28 static void set_default_colors(void);
29 static void set_vmode(int,int*,int*,int);
30 static void reset_vmode(int);
31 static int get_vmode();
32 static int check_drv(void);
33 #else
34 extern int get_new_mode();
35 extern void set_default_colors();
36 static void set_vmode();
37 static void reset_vmode();
38 static int get_vmode();
39 static int check_drv();
40 #endif
41 
42 
43 #define alloc(zzz) (struct zzz *)malloc(sizeof(struct zzz))
44 
45 
46 MFB *
47 MFBOpen(name, device, error)
48 
49 char *name, *device;
50 int *error;
51 {
52  char *malloc();
53  char palette[16];
54  int i;
55  static MFB thismfb;
56  struct ctext *cl;
57 
58  if (error) *error = MFBOK;
59 
60  MFBCurrent = &thismfb;
61  MFBCurrent->fileDesc = fileno(stdout);
62  MFBCurrent->buttonMask[0] = 1;
63  MFBCurrent->buttonMask[1] = 2;
64  MFBCurrent->buttonMask[2] = 3;
65  MFBCurrent->buttonMask[3] = 4;
66 
67  if (pc.mfbMODE != 0) {
68  /* already in a graphics mode, so save context */
69  cl = alloc(ctext);
70  if (cl == NULL) {
71  *error = MFBNOMEM;
72  return (NULL);
73  }
74  cl->pc = alloc(mfbpc);
75  if (cl->pc == NULL) {
76  *error = MFBNOMEM;
77  return (NULL);
78  }
79  *cl->pc = pc;
80  cl->next = Clist;
81  Clist = cl;
82  }
83 
84  /* default font */
86  pc.charheight = 14;
87  pc.charwidth = 8;
88 
89  pc.video_mode = get_vmode() & 0x7f;
91 
92 #ifdef __GNUC__
93  switch (check_drv()) {
94  case 0:
95  /* internal vga driver being used */
96  if (mfb_vmode > 0x13) {
97  pc.xsize = 640;
98  pc.ysize = 480;
99  pc.mfbMODE = 1;
100  mfb_vmode = 0x12;
101  }
103  break;
104 
105  case 1:
106  /* old style driver, force 256 color mode */
107  set_vmode(6,&pc.xsize,&pc.ysize,256);
108  mfb_vmode = 6;
109  pc.mfbMODE = 2;
110  break;
111 
112  case 2:
113  /* new driver, assume driver sets color mode properly */
114  set_vmode(9,&pc.xsize,&pc.ysize,pc.mfbMODE==2 ? 256 : 16);
115  mfb_vmode = 9;
116  break;
117  }
118 #else
119  set_vmode(mfb_vmode,0,0,0);
120 #endif
121 
122  /* store current font height */
123  outp(0x3d4,0x9);
124  pc.scan_height = inp(0x3d5) & 0x0f;
125 
126  pc.linestyles[0] = (unsigned char) 0xff;
127  pc.cursor_color = 1;
128  pc.alumode = 3; /* MFBALUJAM */
129  pc.curstep = 8;
130  pc.curleap = 64;
131  pc.pointerdelay = 250; /* 250 msec */
132  pc.functkey_yband = 10;
133 
134  if (!pc.base)
135 #if __NDPC__
136  pc.base = (char *) mapdev(0xa0000,0x10000);
137 #else
138 #if __GNUC__
139  pc.base = (char *) 0xd0000000;
140 #else
141 #if __TURBOC__
142  pc.base = (vidmptr) MK_FP(0xa000,0x0000);
143 #else
144  pc.base = I_cant_map_video_memory;
145 #endif
146 #endif
147 #endif
148 
149  pc.cursx = pc.xsize >> 1;
150  pc.cursy = pc.ysize >> 1;
151 
152  pc.bytpline = pc.xsize >> 3;
153 
154  if (pc.mfbMODE != 4)
155  MFBPointerInit();
156 
157  for (i = 0; i < 16; i++) palette[i] = (char) i;
158  vga_set_cpblock(palette);
160  vga_set_cblock((char (*)[3])pc.colormap,0,16);
161  vga_get_cblock((char (*)[3])pc.colormap[16],16,240);
162 
163  return (MFBCurrent);
164 }
165 
166 
167 int
169 
170 {
171  char palette[16];
172  int i;
173 
174  if (Clist != NULL)
175  return (MFBBADDEV);
176  if (mfb_vmode == 6 || mfb_vmode == 9)
177  set_vmode(mfb_vmode,&pc.xsize,&pc.ysize,pc.mfbMODE==2 ? 256 : 16);
178  else
180 
181  if (pc.mfbMODE != 4)
182  MFBPointerInit();
183  for (i = 0; i < 16; i++) palette[i] = (char) i;
184  vga_set_cpblock(palette);
186  vga_set_cblock((char(*)[3])pc.colormap,0,16);
187  vga_get_cblock((char(*)[3])pc.colormap[16],16,240);
188  return (MFBOK);
189 }
190 
191 
192 int
194 
195 {
196  int i;
197  struct ctext *cl;
198  char palette[16];
199 
200  if (pc.mfbMODE != 4)
201  MFBPointerClose();
202  MFBSetColor(0);
203  MFBFlood();
205  if (pc.video_mode < 4 || pc.video_mode == 7
206 #ifdef PARADISE
207  || (pc.video_mode < 0x58 && pc.video_mode > 0x53)
208 #endif
209  )
211 
212  if (Clist != NULL) {
213  /* have to reset some things for old graphics mode */
214  pc = *Clist->pc;
215  free(Clist->pc);
216  for (i = 0; i < 16; i++) palette[i] = (char) i;
217  vga_set_cpblock(palette);
218  if (pc.mfbMODE != 4)
219  MFBPointerInit();
220  cl = Clist;
221  Clist = Clist->next;
222  free(cl);
223  }
224  else
225  pc.mfbMODE = 0;
226 
227  return (MFBOK);
228 }
229 
230 
231 int
233 
234 {
235  if (Clist != NULL)
236  return (MFBBADDEV);
237  if (pc.mfbMODE != 4)
238  MFBPointerClose();
240  if (pc.video_mode < 4 || pc.video_mode == 7
241 #ifdef PARADISE
242  || (pc.video_mode < 0x58 && pc.video_mode > 0x53)
243 #endif
244  )
246 
247  return (MFBOK);
248 }
249 
250 
251 int
253 {
254  return (MFBOK);
255 }
256 
257 
258 int
260 
261 /* returns raw key */
262 {
263  int k;
264 
265  k = (getch() & 0xff);
266  if (!k) k = 256 + getch();
267  return (k);
268 }
269 
270 
271 static int
272 get_new_mode(name,xsize,ysize,mfbmode)
273 
274 /* returns TSENG ET4000 super-VGA modes */
275 char *name;
276 int *xsize,*ysize,*mfbmode;
277 {
278  /* pc.mfbMODE:
279  * 0, text mode
280  * 1, 16 color (4 bit planes) modes
281  * 2, 256 color (byte per pixel) modes
282  * 4, rasterizing
283  */
284 
285  if (!name) { /* 640 X 480 16 colors */
286  *mfbmode = 1;
287  *xsize = 640;
288  *ysize = 480;
289  return (0x12);
290  }
291  if (!strcmp(name,"vga0")) { /* 640 X 350 16 colors */
292  *mfbmode = 1;
293  *xsize = 640;
294  *ysize = 350;
295  return (0x10);
296  }
297  if (!strcmp(name,"vga1")) { /* 640 X 480 16 colors */
298  *mfbmode = 1;
299  *xsize = 640;
300  *ysize = 480;
301  return (0x12);
302  }
303  if (!strcmp(name,"vga2")) { /* 320 X 200 256 colors */
304  *mfbmode = 2;
305  *xsize = 320;
306  *ysize = 200;
307  return (0x13);
308  }
309  if (!strcmp(name,"vga3")) { /* 800 X 600 16 colors */
310  *mfbmode = 1;
311  *xsize = 800;
312  *ysize = 600;
313 #ifdef PARADISE
314  return (0x58);
315  }
316 #else
317  return (0x29);
318  }
319  if (!strcmp(name,"vga4")) { /* 1024 X 768 16 colors */
320  *mfbmode = 1;
321  *xsize = 1024;
322  *ysize = 768;
323  return (0x37);
324  }
325  if (!strcmp(name,"vga5")) { /* 640 X 480 256 colors */
326  *mfbmode = 2;
327  *xsize = 640;
328  *ysize = 480;
329  return (0x2e);
330  }
331  if (!strcmp(name,"vga6")) { /* 800 X 600 256 colors */
332  *mfbmode = 2;
333  *xsize = 800;
334  *ysize = 600;
335  return (0x30);
336  }
337  if (!strcmp(name,"vga7")) { /* 1024 X 768 256 colors */
338  *mfbmode = 2;
339  *xsize = 1024;
340  *ysize = 768;
341  return (0x38);
342  }
343 #endif
344  if (!strcmp(name,"core")) { /* 640 X 480 16 colors */
345 
346 /* Rasterizing for 16 color modes, for HP LasetJet.
347  * The HP Laserjet has a graphics map 2400 X 3180. This is written in
348  * segments from vga memory, which has 64K size. This works out to 15
349  * segments, each 300 chars X 208 lines.
350  */
351  *mfbmode = 4;
352  *xsize = 2400;
353  *ysize = 208;
354  /* 300 X 208, 15 pages
355  * 3180 is physical page length, 208
356  * set by 64K vga memory page size and
357  * mult of 16 for fillpattern
358  * continuity. Thus 3120 lines are used.
359  */
360  return (0x12);
361  }
362 
363  /* default - 640 X 480 16 colors */
364  *mfbmode = 1;
365  *xsize = 640;
366  *ysize = 480;
367  return (0x12);
368 }
369 
370 
371 static void
373 
374 {
375  unsigned char (*c)[3];
376 
377  c = pc.colormap;
378  (*c)[0] = (unsigned char) 0;
379  (*c)[1] = (unsigned char) 0;
380  (*c)[2] = (unsigned char) 0;
381  c++;
382  (*c)[0] = (unsigned char) 60;
383  (*c)[1] = (unsigned char) 60;
384  (*c)[2] = (unsigned char) 60;
385  c++;
386  (*c)[0] = (unsigned char) 60;
387  (*c)[1] = (unsigned char) 0;
388  (*c)[2] = (unsigned char) 0;
389  c++;
390  (*c)[0] = (unsigned char) 20;
391  (*c)[1] = (unsigned char) 60;
392  (*c)[2] = (unsigned char) 20;
393 
394  c++;
395  (*c)[0] = (unsigned char) 35;
396  (*c)[1] = (unsigned char) 25;
397  (*c)[2] = (unsigned char) 60;
398  c++;
399  (*c)[0] = (unsigned char) 60;
400  (*c)[1] = (unsigned char) 60;
401  (*c)[2] = (unsigned char) 30;
402  c++;
403  (*c)[0] = (unsigned char) 20;
404  (*c)[1] = (unsigned char) 60;
405  (*c)[2] = (unsigned char) 60;
406  c++;
407  (*c)[0] = (unsigned char) 60;
408  (*c)[1] = (unsigned char) 30;
409  (*c)[2] = (unsigned char) 60;
410 
411  c++;
412  (*c)[0] = (unsigned char) 40;
413  (*c)[1] = (unsigned char) 40;
414  (*c)[2] = (unsigned char) 40;
415  c++;
416  (*c)[0] = (unsigned char) 45;
417  (*c)[1] = (unsigned char) 45;
418  (*c)[2] = (unsigned char) 15;
419  c++;
420  (*c)[0] = (unsigned char) 0;
421  (*c)[1] = (unsigned char) 40;
422  (*c)[2] = (unsigned char) 0;
423  c++;
424  (*c)[0] = (unsigned char) 0;
425  (*c)[1] = (unsigned char) 0;
426  (*c)[2] = (unsigned char) 40;
427 
428  c++;
429  (*c)[0] = (unsigned char) 50;
430  (*c)[1] = (unsigned char) 30;
431  (*c)[2] = (unsigned char) 20;
432  c++;
433  (*c)[0] = (unsigned char) 25;
434  (*c)[1] = (unsigned char) 35;
435  (*c)[2] = (unsigned char) 40;
436  c++;
437  (*c)[0] = (unsigned char) 40;
438  (*c)[1] = (unsigned char) 0;
439  (*c)[2] = (unsigned char) 40;
440  c++;
441  (*c)[0] = (unsigned char) 63;
442  (*c)[1] = (unsigned char) 63;
443  (*c)[2] = (unsigned char) 63;
444 }
445 
446 
447 void
449 int **x,**y,**bytpline;
450 {
451  *x = &pc.xsize;
452  *y = &pc.ysize;
453  *bytpline = &pc.bytpline;
454 }
455 
456 
457 int
458 MFBSetGhost(callback,x,y)
459 
460 /* Nonstandard routine: when called with callback not NULL, the callback
461  * function will be called after cursor motion, and any drawing done in the
462  * callback will be xor'ed to the screen. This enables rubber banding,
463  * and "ghost" images to be attached to the cursor.
464  */
465 #ifdef __STDC__
466 void (*callback)(int,int,int,int);
467 #else
468 void (*callback)();
469 #endif
470 int x, y;
471 {
472  if (callback) {
473  pc.refx = x;
474  pc.refy = y;
475  pc.drawghost = callback;
476  return (MFBOK);
477  }
478  pc.drawghost = NULL;
479  return (MFBOK);
480 }
481 
482 
483 #if __NDPC__
484 #define REGS REGS16
485 #endif
486 
487 
488 /* ARGSUSED */
489 static void
490 set_vmode(mode,width,height,numcolors)
491 
492 int mode, *width, *height, numcolors;
493 {
494  union REGS r;
495 
496 #ifdef __GNUC__
497  r.x.ax = (mode & 0xff) | 0xff00;
498  r.x.bx = numcolors;
499  r.x.cx = *width;
500  r.x.dx = *height;
501 #else
502  r.x.ax = mode & 0xff;
503 #endif
504  int86(0x10,&r,&r);
505 #ifdef __GNUC__
506  *width = r.x.cx;
507  *height = r.x.dx;
508 #endif
509 }
510 
511 
512 static void
514 {
515  union REGS r;
516 
517  r.x.ax = mode & 0xff;
518  int86(0x10,&r,&r);
519 }
520 
521 
522 static int
524 {
525  union REGS r;
526 
527  r.x.ax = 0x0f00;
528  int86(0x10,&r,&r);
529  return (r.x.ax & 0xff);
530 }
531 
532 
533 #ifdef __GNUC__
534 
535 static int
536 check_drv()
537 
538 /* See if we have a new driver (.grn), an old driver (.grd),
539  * or no driver by parsing the GO32 environment variable.
540  * Returns 2 for new, 1 for old, 0 if none or unrecognized.
541  */
542 {
543  char *s, *t, buf[128];
544  char *getenv(), *strchr(), *strrchr();
545 
546  s = getenv("GO32");
547  if (s) {
548  strcpy(buf,s);
549  strlwr(buf);
550  s = buf;
551  while ((s = strchr(s,'d')) != NULL) {
552  if (s[1] == 'r' && s[2] == 'i' && s[3] == 'v')
553  break;
554  s++;
555  }
556  if (*s == 'd') {
557  while (*s && !isspace(*s)) s++;
558  if (*s) while (isspace(*s)) s++;
559  if (*s) {
560  t = s;
561  while (*t && !isspace(*t)) t++;
562  *t = '\0';
563  t = strrchr(s,'.');
564  if (t) {
565  if (!strncmp(t,".grd",4)) {
566  return (1);
567  }
568  else if (!strncmp(t,".grn",4)) {
569  return (2);
570  }
571  else
572  return (0);
573  }
574  }
575  }
576  }
577  return (0);
578 }
579 
580 #endif
static char buf[MAXPROMPT]
Definition: arg.c:18
int charwidth
Definition: mfbp.h:65
DISPDEVICE device[]
Definition: display.c:24
unsigned short * chartab
Definition: mfbp.h:63
#define MFBNOMEM
Definition: mfb.h:517
char mfb_trash
Definition: mfbopen.c:15
void load_font(int scanheight)
Definition: loadfont.c:11
void GetScreenSizeParameters(int **x, int **y, int **bytpline)
Definition: mfbopen.c:448
static int xsize
Definition: output.c:49
char * strcpy()
Definition: cddefs.h:119
#define MFBBADDEV
Definition: mfb.h:509
Definition: mfbopen.c:18
MFB * MFBOpen(char *name, char *device, int *error)
Definition: mfbopen.c:47
#define MFBOK
Definition: mfb.h:491
struct ctext * next
Definition: mfbopen.c:20
static struct ctext * Clist
Definition: mfbopen.c:22
int curleap
Definition: mfbp.h:59
int mfbMODE
Definition: mfbp.h:41
char * malloc()
int video_mode
Definition: mfbp.h:40
int MFBUpdate()
Definition: mfbopen.c:252
int MFBClose()
Definition: mfbopen.c:193
void(* drawghost)()
Definition: mfbp.h:78
#define alloc(zzz)
Definition: mfbopen.c:43
int MFBHalt()
Definition: mfbopen.c:232
unsigned char linestyles[NSTYLES]
Definition: mfbp.h:69
Definition: mfbp.h:36
void vga_set_cblock()
char * getenv(char *c)
Definition: libfuncs.c:106
char * vidmptr
Definition: mfbp.h:17
int MFBSetGhost(void(*callback)(), int x, int y)
Definition: mfbopen.c:458
int ysize
Definition: mfbp.h:54
void vga_get_cblock()
int pointerdelay
Definition: mfbp.h:62
Definition: mfb.h:215
vidmptr base
Definition: mfbp.h:38
int fileDesc
Definition: mfb.h:276
MFB * MFBCurrent
Definition: mfbopen.c:13
#define NULL
Definition: spdefs.h:121
int curstep
Definition: mfbp.h:58
int charheight
Definition: mfbp.h:64
int alumode
Definition: mfbp.h:56
int cursx
Definition: mfbp.h:51
unsigned short mfb_8X14font[]
Definition: 8x14font.c:11
void MFBPointerInit()
Definition: mfbcursr.c:440
int MFBGetchar()
Definition: mfbopen.c:259
static void set_vmode()
struct mfbpc pc
Definition: mfbopen.c:14
static int ysize
Definition: output.c:49
void MFBPointerClose()
Definition: mfbcursr.c:481
int MFBSetColor()
int buttonMask[12]
Definition: mfb.h:238
void set_default_colors()
Definition: mfbopen.c:372
int functkey_yband
Definition: mfbp.h:66
void MFBFlood()
Definition: mfbflood.c:21
struct mfbpc * pc
Definition: mfbopen.c:19
int xsize
Definition: mfbp.h:53
static void reset_vmode()
Definition: cddefs.h:177
int bytpline
Definition: mfbp.h:39
int MFBInitialize()
Definition: mfbopen.c:168
int cursor_color
Definition: mfbp.h:50
int refx
Definition: mfbp.h:73
int get_new_mode()
static int get_vmode()
Definition: mfbopen.c:523
unsigned char colormap[256][3]
Definition: mfbp.h:71
static int check_drv()
int refy
Definition: mfbp.h:73
static int mfb_vmode
Definition: mfbopen.c:24
Definition: cddefs.h:192
int cursy
Definition: mfbp.h:52
void free()
void vga_set_cpblock()
int scan_height
Definition: mfbp.h:42