Jspice3
dpinterf.c
Go to the documentation of this file.
1 /*************************************************************************
2  MFB graphics and miscellaneous library for protected mode MSDOS.
3  Copyright (c) Stephen R. Whiteley 1992
4  Author: Stephen R. Whiteley
5  *************************************************************************/
6 
7 /* routines for digitizing pad interface.
8  * In protected mode, the serial port interrupt handler and cursor drawing
9  * routines, located in the TSR "pointer", are accessed via int 62. In real
10  * mode, the TSR is not used, and the interrupt handler and drawing routines
11  * are included within the MFB library. The protected mode programs had
12  * problems servicing the hardware interupts from protected mode, therefor
13  * a real mode handler seemed to be required.
14  */
15 
16 #include "mfb.h"
17 #include "mfbP.h"
18 #include <dos.h>
19 
20 #ifdef __STDC__
21 static int pointer_on(void);
22 #else
23 static int pointer_on();
24 #endif
25 
26 
27 void
28 dp_start(irq,addr)
29 
30 /* initialize pointer */
31 int addr, irq;
32 {
33  union REGS r;
34 
35  /* presence test */
36  if (!pointer_on()) {
37  fprintf(stderr,"Error: \"pointer\" TSR not loaded.\n");
38  fprintf(stderr,"Hit any key to exit.\n");
39  (void)MFBGetchar();
42  MFBClose();
43  exit(0);
44  }
45  r.x.ax = 5;
46  /* in real mode, pass irq,irq+8 */
47 #if __NDPC__
48  /* Phar Lap */
49  r.x.bx = (irq << 8) | get_hwvec(irq);
50 #else
51  r.x.bx = (irq << 8) | irq + 8;
52 #endif
53  r.x.cx = addr;
54  r.x.dx = pc.xsize;
55  r.x.di = pc.ysize;
56  r.x.si = pc.mfbMODE;
57  int86(0x62,&r,&r);
58 }
59 
60 
61 void
63 
64 /* retire pointer */
65 {
66  union REGS r;
67 
68  r.x.ax = 6;
69  int86(0x62,&r,&r);
70 }
71 
72 
73 void
75 
76 /* make marker visible */
77 {
78  union REGS r;
79 
80  r.x.ax = 0;
81  r.x.bx = pc.cursor_color;
82  int86(0x62,&r,&r);
83 }
84 
85 
86 void
88 
89 /* make pointer invisible */
90 {
91  union REGS r;
92 
93  r.x.ax = 1;
94  int86(0x62,&r,&r);
95 }
96 
97 
98 void
99 dp_status(x,y,b)
100 
101 /* return coordinates, button press info */
102 int *x, *y, *b;
103 {
104  union REGS r;
105 
106  r.x.ax = 4;
107  int86(0x62,&r,&r);
108  *x = r.x.bx;
109  *y = r.x.cx;
110  *b = r.x.dx;
111 }
112 
113 
114 static int
116 
117 /* return 1 if pointer installed on int 62, 0 otherwise */
118 {
119 #define NAME_OFF 18
120 
121 #if __NDPC__
122 #define RP_OFF(rp) ((rp) & 0xFFFF)
123 #define RP_SEG(rp) ((rp) >> 16)
124  unsigned long r;
125  char c[8];
126 
127  blk_mb(&r,0x34,0,0x62*4,4); /* getvect(0x62) */
128  blk_mb(c,0x34,(RP_SEG(r) << 4) + RP_OFF(r) + NAME_OFF,8);
129 #else
130 #if __GNUC__
131  char *c;
132 
133  c = (char*)(0xe0000000 + 0x62);
134  c = (char*)(16*(*(short*)(c+2)) + *(short*)c + NAME_OFF);
135 #else
136  return (I_cant_convert_real_address);
137 #endif
138 #endif
139 
140  if (c[0] != 'p') return (0);
141  if (c[1] != 'o') return (0);
142  if (c[2] != 'i') return (0);
143  if (c[3] != 'n') return (0);
144  if (c[4] != 't') return (0);
145  if (c[5] != 'e') return (0);
146  if (c[6] != 'r') return (0);
147  return (1);
148 }
149 
150 
151 void
152 dp_point(x,y,k,b)
153 int *x, *y, *k, *b;
154 
155 {
156  int xx, yy, bb;
157  int xlst, ylst;
158 
159  dp_status(&xx,&yy,&bb);
160  yy = pc.ysize - yy - 1;
161  MFBDrawCursor(xx-8,yy+7);
162  for (;;) {
163  if (kbhit()) {
164  *k = 0xff & getch();
165  if (!*k)
166  *k = 256 + getch();
167  *b = 0;
168  break;
169  }
170  if (bb) {
171  *k = 0;
172  *b = bb;
173  break;
174  }
175  xlst = xx;
176  ylst = yy;
177  dp_status(&xx,&yy,&bb);
178  yy = pc.ysize - yy - 1;
179  if (xx == xlst && yy == ylst)
180  continue;
181  MFBEraseCursor(xlst-8,ylst+7);
182  MFBDrawCursor(xx-8,yy+7);
183  }
184  *x = xx;
185  *y = yy;
186  MFBEraseCursor(xx-8,yy+7);
187 }
188 
189 #if __NDPC__
190 
191 int
192 get_hwvec(num)
193 
194 /* get relocated hardware interrupt vector */
195 /* Phar Lap call */
196 int num;
197 {
198  union REGS r;
199 
200  r.x.ax = 0x250c;
201  int86(0x21,&r,&r);
202  if (num <= 7) return (num + (r.x.ax & 0xff));
203  return (r.x.ax >> 8);
204 }
205 
206 #endif
int pointertype
Definition: mfbp.h:60
static int pointer_on()
Definition: dpinterf.c:115
void MFBDrawCursor(int x, int y)
Definition: mfbmark.c:26
int MFBClose()
Definition: mfbopen.c:193
int mfbMODE
Definition: mfbp.h:41
#define KBRD
Definition: mfbp.h:90
int ysize
Definition: mfbp.h:54
void dp_pointer_off()
Definition: dpinterf.c:87
int MFBGetchar()
Definition: mfbopen.c:259
void MFBPointerInit()
Definition: mfbcursr.c:440
void dp_pointer_on()
Definition: dpinterf.c:74
static double c
Definition: vectors.c:16
int xsize
Definition: mfbp.h:53
void dp_end()
Definition: dpinterf.c:62
Definition: cddefs.h:177
void dp_point(int *x, int *y, int *k, int *b)
Definition: dpinterf.c:152
Definition: cddefs.h:162
int cursor_color
Definition: mfbp.h:50
#define NAME_OFF
struct mfbpc pc
Definition: mfbopen.c:14
void MFBEraseCursor(int x, int y)
Definition: mfbmark.c:48
void dp_status(int *x, int *y, int *b)
Definition: dpinterf.c:99
void dp_start(int irq, int addr)
Definition: dpinterf.c:28