Jspice3
mfbopen.c File Reference
#include "mfb.h"
#include "mfbP.h"
#include <dos.h>
#include <ctype.h>
Include dependency graph for mfbopen.c:

Go to the source code of this file.

Data Structures

struct  ctext
 

Macros

#define alloc(zzz)   (struct zzz *)malloc(sizeof(struct zzz))
 

Functions

int get_new_mode ()
 
void set_default_colors ()
 
static void set_vmode ()
 
static void reset_vmode ()
 
static int get_vmode ()
 
static int check_drv ()
 
MFBMFBOpen (char *name, char *device, int *error)
 
int MFBInitialize ()
 
int MFBClose ()
 
int MFBHalt ()
 
int MFBUpdate ()
 
int MFBGetchar ()
 
static int get_new_mode (char *name, int *xsize, int *ysize, int *mfbmode)
 
void GetScreenSizeParameters (int **x, int **y, int **bytpline)
 
int MFBSetGhost (void(*callback)(), int x, int y)
 
static void set_vmode (int mode, int *width, int *height, int numcolors)
 
static void reset_vmode (mode)
 

Variables

MFBMFBCurrent
 
struct mfbpc pc
 
char mfb_trash
 
static struct ctextClist
 
static int mfb_vmode
 

Macro Definition Documentation

#define alloc (   zzz)    (struct zzz *)malloc(sizeof(struct zzz))

Definition at line 43 of file mfbopen.c.

Function Documentation

static int check_drv ( )
static
int get_new_mode ( )
static int get_new_mode ( char *  name,
int *  xsize,
int*  ysize,
int*  mfbmode 
)
static

Definition at line 272 of file mfbopen.c.

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 }
static int xsize
Definition: output.c:49
static int ysize
Definition: output.c:49
static int get_vmode ( )
static

Definition at line 523 of file mfbopen.c.

524 {
525  union REGS r;
526 
527  r.x.ax = 0x0f00;
528  int86(0x10,&r,&r);
529  return (r.x.ax & 0xff);
530 }
Definition: cddefs.h:162
void GetScreenSizeParameters ( int **  x,
int**  y,
int**  bytpline 
)

Definition at line 448 of file mfbopen.c.

450 {
451  *x = &pc.xsize;
452  *y = &pc.ysize;
453  *bytpline = &pc.bytpline;
454 }
int ysize
Definition: mfbp.h:54
struct mfbpc pc
Definition: mfbopen.c:14
int xsize
Definition: mfbp.h:53
int bytpline
Definition: mfbp.h:39
int MFBClose ( )

Definition at line 193 of file mfbopen.c.

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 }
void load_font(int scanheight)
Definition: loadfont.c:11
Definition: mfbopen.c:18
#define MFBOK
Definition: mfb.h:491
struct ctext * next
Definition: mfbopen.c:20
static struct ctext * Clist
Definition: mfbopen.c:22
int mfbMODE
Definition: mfbp.h:41
int video_mode
Definition: mfbp.h:40
#define NULL
Definition: spdefs.h:121
void MFBPointerInit()
Definition: mfbcursr.c:440
struct mfbpc pc
Definition: mfbopen.c:14
void MFBPointerClose()
Definition: mfbcursr.c:481
int MFBSetColor()
void MFBFlood()
Definition: mfbflood.c:21
struct mfbpc * pc
Definition: mfbopen.c:19
static void reset_vmode()
void free()
void vga_set_cpblock()
int scan_height
Definition: mfbp.h:42
int MFBGetchar ( )

Definition at line 259 of file mfbopen.c.

262 {
263  int k;
264 
265  k = (getch() & 0xff);
266  if (!k) k = 256 + getch();
267  return (k);
268 }
int MFBHalt ( )

Definition at line 232 of file mfbopen.c.

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 }
void load_font(int scanheight)
Definition: loadfont.c:11
#define MFBBADDEV
Definition: mfb.h:509
#define MFBOK
Definition: mfb.h:491
static struct ctext * Clist
Definition: mfbopen.c:22
int mfbMODE
Definition: mfbp.h:41
int video_mode
Definition: mfbp.h:40
#define NULL
Definition: spdefs.h:121
struct mfbpc pc
Definition: mfbopen.c:14
void MFBPointerClose()
Definition: mfbcursr.c:481
static void reset_vmode()
int scan_height
Definition: mfbp.h:42
int MFBInitialize ( )

Definition at line 168 of file mfbopen.c.

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 }
#define MFBBADDEV
Definition: mfb.h:509
#define MFBOK
Definition: mfb.h:491
static struct ctext * Clist
Definition: mfbopen.c:22
int mfbMODE
Definition: mfbp.h:41
void vga_set_cblock()
int ysize
Definition: mfbp.h:54
void vga_get_cblock()
#define NULL
Definition: spdefs.h:121
void MFBPointerInit()
Definition: mfbcursr.c:440
static void set_vmode()
struct mfbpc pc
Definition: mfbopen.c:14
void set_default_colors()
Definition: mfbopen.c:372
int xsize
Definition: mfbp.h:53
static void reset_vmode()
unsigned char colormap[256][3]
Definition: mfbp.h:71
static int mfb_vmode
Definition: mfbopen.c:24
void vga_set_cpblock()
MFB* MFBOpen ( char *  name,
char *  device,
int *  error 
)

Definition at line 47 of file mfbopen.c.

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 }
int charwidth
Definition: mfbp.h:65
unsigned short * chartab
Definition: mfbp.h:63
#define MFBNOMEM
Definition: mfb.h:517
Definition: mfbopen.c:18
#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
#define alloc(zzz)
Definition: mfbopen.c:43
unsigned char linestyles[NSTYLES]
Definition: mfbp.h:69
Definition: mfbp.h:36
void vga_set_cblock()
char * vidmptr
Definition: mfbp.h:17
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
static void set_vmode()
struct mfbpc pc
Definition: mfbopen.c:14
int buttonMask[12]
Definition: mfb.h:238
void set_default_colors()
Definition: mfbopen.c:372
int functkey_yband
Definition: mfbp.h:66
struct mfbpc * pc
Definition: mfbopen.c:19
int xsize
Definition: mfbp.h:53
static void reset_vmode()
int bytpline
Definition: mfbp.h:39
int cursor_color
Definition: mfbp.h:50
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()
static int mfb_vmode
Definition: mfbopen.c:24
int cursy
Definition: mfbp.h:52
void vga_set_cpblock()
int scan_height
Definition: mfbp.h:42
int MFBSetGhost ( void (*)()  callback,
int  x,
int  y 
)

Definition at line 458 of file mfbopen.c.

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 }
#define MFBOK
Definition: mfb.h:491
void(* drawghost)()
Definition: mfbp.h:78
#define NULL
Definition: spdefs.h:121
struct mfbpc pc
Definition: mfbopen.c:14
int refx
Definition: mfbp.h:73
int refy
Definition: mfbp.h:73
int MFBUpdate ( )

Definition at line 252 of file mfbopen.c.

253 {
254  return (MFBOK);
255 }
#define MFBOK
Definition: mfb.h:491
static void reset_vmode ( )
static
static void reset_vmode ( mode  )
static

Definition at line 513 of file mfbopen.c.

514 {
515  union REGS r;
516 
517  r.x.ax = mode & 0xff;
518  int86(0x10,&r,&r);
519 }
Definition: cddefs.h:162
static void set_default_colors ( )

Definition at line 372 of file mfbopen.c.

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 }
struct mfbpc pc
Definition: mfbopen.c:14
Definition: cddefs.h:177
unsigned char colormap[256][3]
Definition: mfbp.h:71
static void set_vmode ( )
static
static void set_vmode ( int  mode,
int *  width,
int *  height,
int  numcolors 
)
static

Definition at line 490 of file mfbopen.c.

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 }
Definition: cddefs.h:162

Variable Documentation

struct ctext* Clist
static

Definition at line 22 of file mfbopen.c.

char mfb_trash

Definition at line 15 of file mfbopen.c.

int mfb_vmode
static

Definition at line 24 of file mfbopen.c.

MFB* MFBCurrent

Definition at line 13 of file mfbopen.c.

struct mfbpc pc

Definition at line 14 of file mfbopen.c.