source: buchla-68k/orig/LATTICE/EGVDI.C@ 703d4d0

Last change on this file since 703d4d0 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 7.8 KB
Line 
1/*
2 =============================================================================
3 egvdi.c -- a C library test set.
4 Version 2 -- 1989-01-24 -- Metacomco / Lattice / D.N. Lynx Crowe
5
6 Watch out for data sizes.
7
8 All pointers in arg lists of GEM functions must be 16 bit WORD's.
9
10 BYTE, WORD, LONG etc are defined in the portab.h include file.
11 =============================================================================
12*/
13
14/* load fonts not implemented in current ST GEM */
15
16#define HASFNTLD 0 /* non-zero if vst_load_fonts() is implemented */
17
18#include "stdio.h"
19#include "gemlib.h" /* assorted useful GEM macro's */
20#include "portab.h" /* include type def macro's etc */
21
22#define MYLINE 0x5ABC /* a user defined line style mask */
23
24/* GLOBALS needed below */
25
26WORD phys_handle;
27WORD handle;
28WORD dummy;
29WORD pxyarray[4];
30
31setpxy(x1, y1, x2, y2)
32WORD x1, y1, x2, y2;
33{
34 pxyarray[0] = x1; /* set global points array */
35 pxyarray[1] = y1; /* from data points supplied */
36 pxyarray[2] = x2;
37 pxyarray[3] = y2;
38}
39
40line(x1, y1, x2, y2)
41WORD x1, y1, x2, y2;
42{
43 pxyarray[0] = x1;
44 pxyarray[1] = y1;
45 pxyarray[2] = x2;
46 pxyarray[3] = y2; /* set-up array for v_pline() */
47
48 v_pline(handle, 2, pxyarray); /* call polyline to draw line */
49
50 /* that was ( handle, npoints, array_of_points ) */
51}
52
53/*
54
55*/
56
57line_test()
58{
59 int j; /* loop counter*/
60
61 vsl_udsty(handle, MYLINE); /* define user def. line (No 7) */
62
63 /* polymarkers are point marker shapes for graphs etc */
64
65 vsm_type(handle, 4); /* use square polymarker (1 to 6) */
66 vsm_height(handle, 10); /* and make it nice and big. */
67 vsm_color(handle, BLACK); /* set marker color */
68
69 for (j = 1; j < 8; j++) { /* draw lines with diff attributes */
70
71 vsl_type(handle, j); /* try each line style */
72 vsl_color(handle, j); /* and each available color */
73
74 /* You can set line termination style too */
75 /* N.B: there are only 3 end types */
76
77 vsl_ends(handle, (j-1) & 3, (j-1) & 3);
78 line(10, j*10+10, 100, j*10+10); /* draw a line */
79 v_pmarker(handle, 2, pxyarray); /* mark ends */
80
81 /* v_pmarker has same syntax as v_pline */
82 }
83
84 vsl_color(handle, BLACK); /* reset */
85 vsl_type(handle, SOLID); /* and line type */
86 vsl_ends(handle, ARROWED, ARROWED); /* set end type for thickness loop */
87
88 for(j = 1; j < 10; j += 2) { /* i.e. for 1,3,5,7,9 */
89
90 /* you can select line thickness too */
91
92 vsl_width(handle, j); /* set thickness */
93 line(105, j*10+10, 195, j*10+10); /* draw a line */
94 }
95
96 vsl_ends(handle, SQUARED, SQUARED); /* reset end types */
97
98 vsl_width(handle, 1); /* reset the width in case it's used again */
99}
100
101/*
102
103*/
104
105circ_test()
106{
107 int radius,k;
108
109 /* vsf_ functions select fill attributes */
110
111 vsf_interior(handle, PATTERN); /* tell gem to pattern fill */
112 vsf_color(handle, BLACK); /* in fill color black */
113
114 for(k = 10; k > 0; k--) {
115
116 vsf_style(handle, k); /* set fill pattern */
117 radius = k * 10;
118 v_circle(handle, radius+2, 100, radius);
119 }
120}
121
122box_test()
123{
124 setpxy(320, 5, 635, 195);
125 vsf_color(handle, BLACK);
126 vsf_interior(handle, SOLID);
127 v_bar(handle, pxyarray); /* do a rectangle (no border) */
128
129 setpxy(330, 15, 625, 185);
130 vsf_interior(handle, PATTERN);
131 vsf_style(handle, DOTS);
132 vr_recfl(handle, pxyarray); /* filled rectangle */
133
134 setpxy(340, 25, 615, 175);
135 vsf_style(handle, BRICKS);
136 v_rfbox(handle, pxyarray); /* try a rounded & filled box */
137
138 vsf_interior(handle, HATCH);
139 vsf_color(handle, 3);
140 vsf_style(handle, GRID);
141 v_ellipse(handle, 479, 130, 120, 35); /* put filled ellipse */
142
143 /* that was xpos, ypos, xradius, yradius */
144
145 vsf_color(handle, BLACK);
146}
147
148/*
149
150*/
151
152arc_test()
153{
154 int radius, revs, da, ang;
155
156 radius = 10; /* start with a radius of 10 */
157 da = 360; /* delta-angle for spiral steps */
158
159 /* NOTE: GEM angles are in tenths of a degree */
160
161 vswr_mode(handle, MD_REPLACE); /* make sure we're in replace mode */
162
163 /* vswr_mode sets writing mode to one of 4 */
164
165 vsl_color(handle, 2); /* reset color */
166 vsl_type(handle, SOLID); /* and line type */
167 vsl_width(handle, 3); /* use fairly thick lines */
168
169 /* now draw the spiral */
170
171 for (revs = 0; revs < 6; revs++) {
172
173 for (ang = 0; ang < 3600; ang += da) {
174
175 v_arc(handle, 190, 160, radius, ang, ang+da);
176 radius++;
177 }
178 }
179
180 vsl_color(handle, BLACK); /* reset color */
181 vsl_type(handle, SOLID); /* and line type */
182 vsl_width(handle, 1); /* reset line width */
183}
184
185pie_test()
186{
187 int nsegs, da, ang, seg;
188
189 vsf_interior(handle, HATCH);
190
191 /* making pies has never been easier */
192
193 nsegs = 12; /* No. of segments in pie */
194 da = 3600 / nsegs; /* angle for each segment */
195
196 for (seg = 0; seg < nsegs; seg++) {
197
198 ang = seg * da;
199 vsf_style(handle, seg+2);
200 v_pieslice(handle, 472, 100, 90, ang, ang+da);
201 }
202}
203
204/*
205
206*/
207
208text_test()
209{
210
211 int s; /* somewhere to put returned values */
212
213#if HASLDFNT
214 s = vst_load_fonts(handle, 0);
215 printf("%d extra fonts loaded.\n", s);
216#endif
217
218 vswr_mode(handle, MD_TRANS); /* writing mode so only fg drawn */
219 vst_height(handle, 50, &dummy, &dummy, &dummy, &dummy); /* BIG */
220 s = vst_color(handle, BLACK); /* text color */
221 v_gtext(handle, 390, 100, "Metacomco!"); /* print text at x,y */
222
223 vswr_mode(handle ,MD_REPLACE); /* change writing mode to REPLACE */
224 vst_height(handle, 100, &dummy, &dummy, &dummy, &dummy); /* BIGGER */
225 s = vst_color(handle, RED); /* text color */
226 s = vst_effects(handle, SKEWED); /* make it skewed */
227 v_justified(handle, 380, 155, "Hi There!", 180, 1, 1);
228
229 /* justified text is fill justified to required length (180) */
230}
231
232fill_test()
233{
234 vsf_interior(handle, HATCH);
235 vsf_style(handle, GRID);
236 vsf_color(handle, 3);
237 v_contourfill(handle, 5, 5, -1);
238
239 /*
240 that last value is the boundary color.
241 -1 implies any color change is to be
242 regarded as a boundary condition
243 */
244}
245
246gem_close()
247{
248
249 /* anything to do just before finishing should go here */
250
251 v_clsvwk(handle); /* close virtual workstation */
252}
253
254/*
255
256*/
257
258gem_init()
259{
260 WORD i;
261 WORD work_in[11],work_out[57];
262
263 /* NOTE: if the data out from opnvwk() is needed elsewhere */
264 /* it may be more convenient to declare it as an */
265 /* external static or global */
266
267 appl_init(); /* open the application (tell GEM AES were here) */
268
269 /* find system handle ... */
270
271 phys_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
272
273 handle = phys_handle; /* handle will contain our vdi handle */
274
275 /* use this handle for all future VDI calls */
276
277 for (i = 0; i < 10; i++)
278 work_in[i] = 1; /* set all defaults before we open it */
279
280 work_in[10] = 2; /* use raster co-ordinates */
281
282 v_opnvwk(work_in, &handle, work_out); /* open the workstation */
283
284 v_hide_c(handle); /* hide the mouse */
285 v_clrwk(handle); /* clear workstation */
286 v_show_c(handle, 1); /* show the mouse again */
287
288 /* turn clipping on to stop screen overflow... */
289
290 setpxy(0, 0, 639, 399);
291 vs_clip(handle, TRUE, pxyarray); /* clip full screen */
292}
293
294/*
295
296*/
297
298wait4it()
299{
300 WORD c;
301
302 putchar(7); /* ring bell */
303
304 do {
305
306 vq_mouse(handle, &c, &dummy, &dummy);
307
308 /* reads mouse buttons (bits 0 & 1), xpos, ypos respect. */
309
310 } while( !c ); /* loop until button pressed */
311}
312
313main()
314{
315 gem_init(); /* initialise a virtual workstation */
316
317 box_test(); /* test assorted square primitives */
318 line_test(); /* test polyline and polymarker f's */
319 wait4it(); /* wait for a mouse button */
320
321 arc_test(); /* test arc functions */
322 circ_test(); /* test circle & ellipse primitives */
323 pie_test(); /* test pie segment functions */
324 wait4it(); /* wait for a mouse button */
325
326 text_test(); /* test text related GEM functions */
327 fill_test(); /* test contour fill op */
328 wait4it(); /* wait for a mouse button */
329
330 gem_close(); /* close up the workstation before we exit */
331}
Note: See TracBrowser for help on using the repository browser.