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

Go to the source code of this file.

Macros

#define ror(x, n)   ((x >> n) | (x << (8-n)))
 

Functions

static void mode_1_line ()
 
static void mode_2_line ()
 
void MFBLine (int x0, int y0, int x1, int y1)
 
void MFBDrawLineTo (int x, int y)
 
void MFBMoveTo (int x, int y)
 
int MFBSetLineStyle (int style)
 
int MFBDefineLineStyle (int num, int mask)
 
static void mode_1_line (int x, int y)
 
static void mode_2_line (int x, int y)
 

Macro Definition Documentation

#define ror (   x,
 
)    ((x >> n) | (x << (8-n)))

Definition at line 11 of file mfbline.c.

Function Documentation

int MFBDefineLineStyle ( int  num,
int  mask 
)

Definition at line 71 of file mfbline.c.

74 {
75  if ((num < 0) || (num >= NSTYLES))
76  return (MFBBADLST);
77  if (num == 0) return (MFBOK);
78  pc.linestyles[num] = (unsigned char) mask;
79  pc.curstyle = num;
80  return (MFBOK);
81 }
#define MFBOK
Definition: mfb.h:491
unsigned char linestyles[NSTYLES]
Definition: mfbp.h:69
int curstyle
Definition: mfbp.h:47
#define MFBBADLST
Definition: mfb.h:498
struct mfbpc pc
Definition: mfbopen.c:14
void MFBDrawLineTo ( int  x,
int  y 
)

Definition at line 37 of file mfbline.c.

40 {
41  if (pc.mfbMODE & 2)
42  mode_2_line(x,y);
43  else
44  mode_1_line(x,y);
45 }
int mfbMODE
Definition: mfbp.h:41
static void mode_1_line()
static void mode_2_line()
struct mfbpc pc
Definition: mfbopen.c:14
void MFBLine ( int  x0,
int  y0,
int  x1,
int  y1 
)

Definition at line 23 of file mfbline.c.

26 {
27  pc.curx = x0;
28  pc.cury = y0;
29  if (pc.mfbMODE & 2)
30  mode_2_line(x1,y1);
31  else
32  mode_1_line(x1,y1);
33 }
int mfbMODE
Definition: mfbp.h:41
static void mode_1_line()
int cury
Definition: mfbp.h:45
static void mode_2_line()
struct mfbpc pc
Definition: mfbopen.c:14
int curx
Definition: mfbp.h:44
void MFBMoveTo ( int  x,
int  y 
)

Definition at line 49 of file mfbline.c.

52 {
53  pc.curx = x;
54  pc.cury = y;
55 }
int cury
Definition: mfbp.h:45
struct mfbpc pc
Definition: mfbopen.c:14
int curx
Definition: mfbp.h:44
int MFBSetLineStyle ( int  style)

Definition at line 59 of file mfbline.c.

62 {
63  if ((style < 0) || (style >= NSTYLES))
64  return (MFBBADLST);
65  pc.curstyle = style;
66  return (MFBOK);
67 }
#define MFBOK
Definition: mfb.h:491
int curstyle
Definition: mfbp.h:47
#define MFBBADLST
Definition: mfb.h:498
struct mfbpc pc
Definition: mfbopen.c:14
static void mode_1_line ( )
static
static void mode_1_line ( int  x,
int  y 
)
static

Definition at line 85 of file mfbline.c.

87 {
88  int xl, yl, dx, dy, dy2, errterm = 0, next, lcnt;
89  vidmptr rgen;
90  unsigned char cbuf, left, right;
91  union { unsigned short color2; unsigned char c[2]; } c;
92 
93  xl = pc.curx;
94  yl = pc.cury;
95  pc.curx = x;
96  pc.cury = y;
97 
98  c.c[0] = pc.curcolor;
99  c.c[1] = c.c[0];
100 
101  outpw(0x3ce,0x0b05); /* read mode 1, write mode 3 */
102  outpw(0x3ce,c.color2 & 0xff00); /* set/reset */
103  outpw(0x3ce,0x7); /* zero color dont care */
104  outpw(0x3ce,pc.alumode); /* set alu mode */
105 
106  if (y == yl) {
107  if (x < xl) MFBSwapInt(x,xl);
108  x++;
109  left = (0xff >> (xl & 7));
110  right = ~(0xff >> (x & 7));
111  dx = (x >> 3) - (xl >>= 3) - 1;
112  if (dx < 0) { left &= right; dx = 0; right = 0; }
113  rgen = pc.base + xl + (long) (pc.ysize-1-y)*pc.bytpline;
114 
115  cbuf = 0xff;
116  if (pc.curstyle) {
117  cbuf = pc.linestyles[pc.curstyle];
118  left &= cbuf;
119  right &= cbuf;
120  }
121  mfb_trash = *rgen;
122  *rgen = left;
123  rgen++;
124  while (dx--) {
125  mfb_trash = *rgen;
126  *rgen = cbuf;
127  rgen++;
128  }
129  mfb_trash = *rgen;
130  *rgen = right;
131 
132  goto done;
133  }
134 
135  if (x == xl) {
136 
137  if (y < yl) MFBSwapInt(y,yl);
138  yl--;
139  dy = y - yl;
140 
141  cbuf = 0x80 >> (xl & 7);
142 
143  next = pc.bytpline;
144 
145  if (!pc.curstyle) {
146  rgen = pc.base + (x >> 3) + (long) (pc.ysize-1-y)*next;
147  while (dy--) {
148  mfb_trash = *rgen;
149  *rgen = cbuf;
150  rgen += next;
151  }
152  }
153  else {
154  lcnt = pc.ysize-1-y;
155  rgen = pc.base + (x >> 3) + (long) lcnt*next;
156  left = 0x80 >> ((lcnt+xl) & 7);
157  right = pc.linestyles[pc.curstyle];
158 
159  while (dy--) {
160  if (left & right) {
161  mfb_trash = *rgen;
162  *rgen = cbuf;
163  }
164  left = ror(left,1);
165  rgen += next;
166  }
167  }
168  goto done;
169  }
170 
171  if (x < xl) {
172  MFBSwapInt(xl,x);
173  MFBSwapInt(yl,y);
174  }
175  dx = x - xl;
176 
177  next = pc.bytpline;
178  dy = yl - y;
179 
180  if (!pc.curstyle) {
181  rgen = pc.base + (xl >> 3) + (long) (pc.ysize-1-yl)*next;
182  if (yl < y) {
183  next = -next;
184  dy = -dy;
185  }
186 
187  cbuf = 0x80 >> (xl & 7);
188 
189  dy2 = dy;
190  dy++;
191  while (dy--) {
192  errterm += dx;
193  if (errterm <= 0) {
194  mfb_trash = *rgen;
195  *rgen = cbuf;
196  rgen += next;
197  continue;
198  }
199  while (errterm > 0 && xl <= x) {
200  mfb_trash = *rgen;
201  *rgen = cbuf;
202  cbuf = ror(cbuf,1);
203  if (cbuf & 0x80) rgen++;
204  xl++;
205  errterm -= dy2;
206  }
207  rgen += next;
208  }
209  }
210  else {
211  lcnt = pc.ysize-1-yl;
212  rgen = pc.base + (xl >> 3) + (long) lcnt*next;
213  left = 0x80 >> ((lcnt+xl) & 7);
214  right = pc.linestyles[pc.curstyle];
215 
216  if (yl < y) {
217  next = -next;
218  dy = -dy;
219  }
220 
221  cbuf = 0x80 >> (xl & 7);
222 
223  dy2 = dy;
224  dy++;
225  while (dy--) {
226  errterm += dx;
227  if (errterm <= 0) {
228  if (left & right) {
229  mfb_trash = *rgen;
230  *rgen = cbuf;
231  }
232  rgen += next;
233  left = ror(left,1);
234  continue;
235  }
236  while (errterm > 0 && xl <= x) {
237  if (left & right) {
238  mfb_trash = *rgen;
239  *rgen = cbuf;
240  }
241  left = ror(left,1);
242  cbuf = ror(cbuf,1);
243  if (cbuf & 0x80) rgen++;
244  xl++;
245  errterm -= dy2;
246  }
247  rgen += next;
248  left = ror(left,1);
249  }
250  }
251 done:
252  outpw(0x3ce,0xff07);
253  outpw(0x3ce,0x5);
254 }
#define ror(x, n)
Definition: mfbline.c:11
char mfb_trash
Definition: mfbopen.c:15
unsigned char linestyles[NSTYLES]
Definition: mfbp.h:69
char * vidmptr
Definition: mfbp.h:17
int ysize
Definition: mfbp.h:54
int cury
Definition: mfbp.h:45
vidmptr base
Definition: mfbp.h:38
int alumode
Definition: mfbp.h:56
static double c
Definition: vectors.c:16
int curstyle
Definition: mfbp.h:47
Definition: cddefs.h:177
int bytpline
Definition: mfbp.h:39
#define MFBSwapInt(f1, f2)
Definition: mfb.h:35
int curcolor
Definition: mfbp.h:46
struct mfbpc pc
Definition: mfbopen.c:14
int curx
Definition: mfbp.h:44
static void mode_2_line ( )
static
static void mode_2_line ( int  x,
int  y 
)
static

Definition at line 261 of file mfbline.c.

263 {
264  int xl, yl, dy, dy2, errterm = 0, next, lcnt;
265  unsigned short dx;
266  unsigned char cbuf, left, right;
267  union { unsigned short o[2]; long l; } p1, p2;
268  union { unsigned short color2; unsigned char c[2]; } c;
269  vidmptr rgen;
270 
271  xl = pc.curx;
272  yl = pc.cury;
273  pc.curx = x;
274  pc.cury = y;
275 
276  c.c[0] = pc.curcolor;
277  c.c[1] = c.c[0];
278 
279  outpw(0x3ce,0xff08); /* set bit mask */
280  outpw(0x3ce,pc.alumode); /* set alu mode */
281 
282  if (y == yl) {
283  if (x < xl) MFBSwapInt(x,xl);
284  x++;
285  dx = x - xl;
286  p1.l = xl + (long) (pc.ysize-1-y)*pc.xsize;
287  p2.l = p1.l + dx;
288  if (p1.o[1] != p2.o[1])
289  dx = ~(p1.o[0]) + 1;
290  cbuf = p1.o[1];
291  cbuf |= (cbuf << 4);
292  outp(0x3cd,cbuf);
293  rgen = pc.base + p1.o[0];
294 
295  if (!pc.curstyle) {
296 
297  if (pc.alumode == 0x3) {
298  if ((unsigned)rgen & 1) {
299  *rgen = c.c[0];
300  rgen++;
301  dx--;
302  }
303  if (dx & 1)
304  *(rgen + dx - 1) = c.c[0];
305  dx >>= 1;
306  while (dx--) {
307  *(short far *)rgen = c.color2;
308  rgen += 2;
309  }
310  }
311  else {
312  while (dx--) {
313  mfb_trash = *rgen;
314  *rgen = c.c[0];
315  rgen++;
316  }
317  }
318 
319  if (p1.o[1] != p2.o[1]) {
320  outp(0x3cd,cbuf + 0x11);
321  dx = p2.o[0];
322  rgen = pc.base;
323  if (pc.alumode == 0x3) {
324  if (dx & 1)
325  *(rgen + dx - 1) = c.c[0];
326  dx >>= 1;
327  while (dx--) {
328  *(short far *)rgen = c.color2;
329  rgen += 2;
330  }
331  }
332  else {
333  while (dx--) {
334  mfb_trash = *rgen;
335  *rgen = c.c[0];
336  rgen++;
337  }
338  }
339  }
340  }
341  else {
342 
343  lcnt = pc.ysize-1-y;
344  p1.l = xl + (long) lcnt*pc.xsize;
345  left = 0x80 >> ((lcnt+xl) & 7);
346  right = pc.linestyles[pc.curstyle];
347 
348  while (dx--) {
349  if (left & right) {
350  if (pc.alumode != 3)
351  mfb_trash = *rgen;
352  *rgen = c.c[0];
353  }
354  left = ror(left,1);
355  rgen++;
356  }
357 
358  if (p1.o[1] != p2.o[1]) {
359  outp(0x3cd,cbuf + 0x11);
360  dx = p2.o[0];
361  rgen = pc.base;
362  while (dx--) {
363  if (left & right) {
364  if (pc.alumode != 3)
365  mfb_trash = *rgen;
366  *rgen = c.c[0];
367  }
368  left = ror(left,1);
369  rgen++;
370  }
371  }
372  }
373  return;
374  }
375 
376 
377  if (x == xl) {
378  if (y < yl) MFBSwapInt(y,yl);
379  yl--;
380  dy = y - yl;
381  next = pc.xsize;
382  lcnt = pc.ysize-1-y;
383  p1.l = xl + (long) lcnt*next;
384  cbuf = p1.o[1];
385  cbuf |= (cbuf << 4);
386  outp(0x3cd,cbuf);
387 
388  if (!pc.curstyle) {
389  while (dy--) {
390  rgen = pc.base + p1.o[0];
391  if (pc.alumode != 3)
392  mfb_trash = *rgen;
393  *rgen = c.c[0];
394  p1.l += next;
395  if ((cbuf & 0xf) != p1.o[1]) {
396  cbuf += 0x11;
397  outp(0x3cd,cbuf);
398  }
399  }
400  }
401  else {
402  left = 0x80 >> ((lcnt+xl) & 7);
403  right = pc.linestyles[pc.curstyle];
404 
405  while (dy--) {
406  rgen = pc.base + p1.o[0];
407  if (left & right) {
408  if (pc.alumode != 3)
409  mfb_trash = *rgen;
410  *rgen = c.c[0];
411  }
412  left = ror(left,1);
413  p1.l += next;
414  if ((cbuf & 0xf) != p1.o[1]) {
415  cbuf += 0x11;
416  outp(0x3cd,cbuf);
417  }
418  }
419  }
420  return;
421  }
422 
423  cbuf = inp(0x3cd);
424  cbuf |= (cbuf << 4);
425 
426  if (x < xl) {
427  MFBSwapInt(xl,x);
428  MFBSwapInt(yl,y);
429  }
430  dx = x - xl;
431 
432  next = pc.xsize;
433  dy = yl - y;
434 
435  if (!pc.curstyle) {
436  p1.l = xl + (long) (pc.ysize-1-yl)*next;
437 
438  if (yl < y) {
439  next = -next;
440  dy = -dy;
441  }
442 
443  dy2 = dy;
444  dy++;
445  while (dy--) {
446  errterm += dx;
447  if (errterm <= 0) {
448  if ((cbuf & 0xf) != p1.o[1]) {
449  cbuf = p1.o[1];
450  cbuf |= (cbuf << 4);
451  outp(0x3cd,cbuf);
452  }
453  if (pc.alumode != 3)
454  mfb_trash = *(pc.base + p1.o[0]);
455  *(pc.base + p1.o[0]) = c.c[0];
456  p1.l += next;
457  continue;
458  }
459  while (errterm > 0 && xl <= x) {
460  if ((cbuf & 0xf) != p1.o[1]) {
461  cbuf = p1.o[1];
462  cbuf |= (cbuf << 4);
463  outp(0x3cd,cbuf);
464  }
465  if (pc.alumode != 3)
466  mfb_trash = *(pc.base + p1.o[0]);
467  *(pc.base + p1.o[0]) = c.c[0];
468  p1.l++;
469  xl++;
470  errterm -= dy2;
471  }
472  p1.l += next;
473 
474  }
475  }
476  else {
477  lcnt = pc.ysize-1-yl;
478  p1.l = xl + (long) lcnt*next;
479  left = 0x80 >> ((lcnt+xl) & 7);
480  right = pc.linestyles[pc.curstyle];
481 
482  if (yl < y) {
483  next = -next;
484  dy = -dy;
485  }
486 
487  dy2 = dy;
488  dy++;
489  while (dy--) {
490 
491  errterm += dx;
492  if (errterm <= 0) {
493  if (left & right) {
494  if ((cbuf & 0xf) != p1.o[1]) {
495  cbuf = p1.o[1];
496  cbuf |= (cbuf << 4);
497  outp(0x3cd,cbuf);
498  }
499  if (pc.alumode != 3)
500  mfb_trash = *(pc.base + p1.o[0]);
501  *(pc.base + p1.o[0]) = c.color2;
502  }
503  p1.l += next;
504  left = ror(left,1);
505  continue;
506  }
507  while (errterm > 0 && xl <= x) {
508  if (left & right) {
509  if ((cbuf & 0xf) != p1.o[1]) {
510  cbuf = p1.o[1];
511  cbuf |= (cbuf << 4);
512  outp(0x3cd,cbuf);
513  }
514  if (pc.alumode != 3)
515  mfb_trash = *(pc.base + p1.o[0]);
516  *(pc.base + p1.o[0]) = c.color2;
517  }
518  left = ror(left,1);
519  p1.l++;
520  xl++;
521  errterm -= dy2;
522  }
523  p1.l += next;
524  left = ror(left,1);
525 
526  }
527  }
528 }
#define ror(x, n)
Definition: mfbline.c:11
char mfb_trash
Definition: mfbopen.c:15
Definition: cddefs.h:312
unsigned char linestyles[NSTYLES]
Definition: mfbp.h:69
char * vidmptr
Definition: mfbp.h:17
int ysize
Definition: mfbp.h:54
int cury
Definition: mfbp.h:45
vidmptr base
Definition: mfbp.h:38
int alumode
Definition: mfbp.h:56
static double c
Definition: vectors.c:16
Definition: cddefs.h:142
int curstyle
Definition: mfbp.h:47
int xsize
Definition: mfbp.h:53
while(TDesc->tSucc!=NULL)
Definition: cd.c:1335
Definition: cddefs.h:177
#define MFBSwapInt(f1, f2)
Definition: mfb.h:35
int curcolor
Definition: mfbp.h:46
struct mfbpc pc
Definition: mfbopen.c:14
int curx
Definition: mfbp.h:44