1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: atariaes.trm,v 1.19 2006/07/21 02:35:45 sfeam Exp $
6 /* GNUPLOT - atari.trm */
9 * Copyright 1992, 1993, 1998, 2004
11 * Permission to use, copy, and distribute this software and its
12 * documentation for any purpose with or without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and
14 * that both that copyright notice and this permission notice appear
15 * in supporting documentation.
17 * Permission to modify the software is granted, but not the right to
18 * distribute the complete modified source code. Modifications are to
19 * be distributed as patches to the released version. Permission to
20 * distribute binaries produced by compiling modified sources is granted,
22 * 1. distribute the corresponding source modifications from the
23 * released version in the form of a patch file along with the binaries,
24 * 2. add special version identification to distinguish your version
25 * in addition to the base release version number,
26 * 3. provide your name and address as the primary contact for the
27 * support of your modified version, and
28 * 4. retain our contact information in regard to use of the base
30 * Permission to distribute the released version of the source code along
31 * with corresponding source modifications in the form of a patch file is
32 * granted with same provisions 2 through 4 for binary distributions.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
42 * Atari Screens working with the normal VDI
43 * (this should include TT and big screens)
49 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
51 * ATARI-related comments please to alexlehm@iti.informatik.th-darmstadt.de
63 /* function-prototypes */
64 TERM_PUBLIC void ATARI_options __PROTO((void));
65 TERM_PUBLIC void ATARI_init __PROTO((void));
66 TERM_PUBLIC void ATARI_reset __PROTO((void));
67 TERM_PUBLIC void ATARI_graphics __PROTO((void));
68 TERM_PUBLIC void ATARI_text __PROTO((void));
69 TERM_PUBLIC void ATARI_move __PROTO((unsigned int x, unsigned int y));
70 TERM_PUBLIC void ATARI_vector __PROTO((unsigned int x, unsigned int y));
71 TERM_PUBLIC void ATARI_linetype __PROTO((int lt));
72 TERM_PUBLIC void ATARI_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
73 TERM_PUBLIC int ATARI_text_angle __PROTO((int ang));
74 TERM_PUBLIC int ATARI_justify_text __PROTO((enum JUSTIFY mode));
75 TERM_PUBLIC void ATARI_point __PROTO((unsigned int x, unsigned int y, int number));
77 /* default to hi-res */
78 #define ATARI_XMAX 640
79 #define ATARI_YMAX 400
80 #define ATARI_VCHAR 16
82 #define ATARI_HTIC (ATARI_XMAX/100)
83 #define ATARI_VTIC ATARI_HTIC
85 #endif /* TERM_PROTO */
87 #ifndef TERM_PROTO_ONLY
91 /* why did they have to change these names ??? */
95 #else /* !__PUREC__ i.e. __GNUC__, maybe others */
99 extern short _global[];
104 static void open_window __PROTO((void));
105 static void close_window __PROTO((void));
106 static void text_mode __PROTO((void));
107 static void mouse_mode __PROTO((void));
108 static void application_exit __PROTO((void));
109 void application_init __PROTO((void));
110 static int intersect __PROTO((int *x1, int *y1, int *w1, int *h1, int x2, int y2, int w2, int h2));
111 static void walk_rects __PROTO((void (*draw) (int, int, int, int), int x1, int y1, int w1, int h1));
112 static void clear __PROTO((int x, int y, int w, int h));
113 static void process_message __PROTO((int *msg));
114 long poll_events __PROTO((int waitkey));
115 static void f_line __PROTO((int x, int y, int w, int h));
116 static void flush_line __PROTO((void));
117 static void put_text __PROTO((int x, int y, int w, int h));
119 static int multi_aes;
120 static int window_id = -1;
121 static int vdi_handle = -1;
122 static int win_xpos, win_ypos;
123 static int win_xsize, win_ysize;
125 #define ATARI_yc(y) (ATARI_maxycoord-(y))
126 static int ATARI_linetypes[] =
129 0xffff, 0x5555, 0x3333, 0x7777,
130 0x3f3f, 0x0f0f, 0x5f5f, 0xe4e4, 0x55f5
133 #define ATARI_LINETYPES_MAX (sizeof(ATARI_linetypes)/sizeof(int))
136 static int ATARI_maxycoord;
137 static int ATARI_rotation;
138 static int ATARI_numcolors;
139 static int pxy[128]; /* Maximum of 64 pixels per v_pline */
140 static int pxy_index;
141 static int ATARI_colors[16];
142 static int ATARI_savecolors[16][3];
143 static int ATARI_numpalette;
145 #define ATARI_c_height_default 6 /* well, well ... */
147 static int ATARI_c_height = ATARI_c_height_default;
149 static int cursor_is_on = FALSE;
150 static int put_text_x;
151 static int put_text_y;
152 static char *put_text_str;
154 /* don't change this without changing process_message() below */
155 #define WINTYPE (NAME|CLOSER|FULLER|MOVER|SIZER)
162 if (window_id == -1) {
163 wind_calc(WC_BORDER, WINTYPE, win_xpos, win_ypos,
164 win_xsize, win_ysize, &x, &y, &w, &h);
165 window_id = wind_create(WINTYPE, x, y, w, h);
169 int_error(NO_CARET, "Can't create window");
171 wind_set(window_id, WF_NAME, "gnuplot output");
172 wind_open(window_id, x, y, w, h);
179 if (window_id != -1) {
180 wind_close(window_id);
181 wind_delete(window_id);
192 graf_mouse(M_OFF, NULL);
193 fputs("\033e", stderr);
195 fputs("\033E", stderr);
204 cursor_is_on = FALSE;
205 graf_mouse(M_ON, NULL);
206 fputs("\033f", stderr);
216 if (vdi_handle != -1) {
217 v_clsvwk(vdi_handle);
226 if ((aesid = appl_init()) < 0)
227 int_error(NO_CARET, "APPL_INIT failed !");
230 multi_aes = _GemParBlk.global[1] == -1;
232 /* tested with gcc only */
233 multi_aes = _global[1] == -1;
237 graf_mouse(ARROW, NULL);
239 menu_register(aesid, " Terminal: atari");
242 atexit(application_exit);
246 intersect(int *x1, int *y1, int *w1, int *h1, int x2, int y2, int w2, int h2)
273 return (*w1) > 0 && (*h1) > 0;
277 walk_rects(void (*draw) (int, int, int, int), int x1, int y1, int w1, int h1)
282 wind_update(BEG_UPDATE);
283 graf_mouse(M_OFF, NULL);
285 wind_get(window_id, WF_FIRSTXYWH, &x, &y, &w, &h);
286 while (w > 0 && h > 0) {
287 if (intersect(&x, &y, &w, &h, x1, y1, w1, h1)) {
292 vs_clip(vdi_handle, 1, pxy);
293 (*draw) (x, y, w, h);
295 wind_get(window_id, WF_NEXTXYWH, &x, &y, &w, &h);
297 vs_clip(vdi_handle, 0, pxy);
298 graf_mouse(M_ON, NULL);
299 wind_update(END_UPDATE);
303 clear(int x, int y, int w, int h)
305 static MFDB mfdb = { NULL };
310 pxy[2] = pxy[6] = x + w - 1;
311 pxy[3] = pxy[7] = y + h - 1;
313 vro_cpyfm(vdi_handle, ALL_WHITE /*0 */ , pxy, &mfdb, &mfdb);
317 process_message(int *msg)
319 static int is_fulled = FALSE;
320 static int small_xpos, small_ypos, small_xsize, small_ysize;
323 if (window_id == -1 || msg[3] != window_id)
328 walk_rects(clear, msg[4], msg[5], msg[6], msg[7]);
336 wind_set(window_id, WF_TOP, window_id);
342 wind_calc(WC_WORK, WINTYPE, msg[4], msg[5], msg[6], msg[7],
343 &win_xpos, &win_ypos, &win_xsize, &win_ysize);
344 wind_set(window_id, WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]);
350 small_xpos = win_xpos;
351 small_ypos = win_ypos;
352 small_xsize = win_xsize;
353 small_ysize = win_ysize;
355 wind_get(0, WF_WORKXYWH, &x, &y, &w, &h);
356 wind_calc(WC_WORK, WINTYPE, x, y, w, h, &win_xpos, &win_ypos,
357 &win_xsize, &win_ysize);
360 win_xpos = small_xpos;
361 win_ypos = small_ypos;
362 win_xsize = small_xsize;
363 win_ysize = small_ysize;
365 wind_calc(WC_BORDER, WINTYPE, win_xpos, win_ypos, win_xsize,
366 win_ysize, &x, &y, &w, &h);
367 wind_set(window_id, WF_CURRXYWH, x, y, w, h);
373 poll_events(int waitkey)
379 /* 1/10th second when waiting for key, poll otherwise */
380 unsigned long time = (waitkey ? 100L : 1L);
384 (waitkey ? (MU_MESAG | MU_KEYBD | MU_TIMER) : (MU_MESAG | MU_TIMER)),
394 &dummy, &dummy, &dummy, &dummy, &key, &dummy);
396 if (which & MU_MESAG) {
397 process_message(msg);
399 } while (which & MU_MESAG);
401 if (which & MU_KEYBD) {
402 return ((Kbshift(-1) & 7) << 24) | ((long) (key & 0xff00) << 8) | (key & 0xff);
409 f_line(int x, int y, int w, int h)
411 v_pline(vdi_handle, pxy_index, pxy);
421 if (pxy_index >= 2) {
422 if (ATARI_numcolors == 2) { /* Monochrome */
424 line_type = ATARI_lt;
426 line_type %= (ATARI_LINETYPES_MAX - 2);
430 line_type = ATARI_lt;
432 color_index = 2 + ATARI_lt % (ATARI_numcolors - 2);
433 line_type = (ATARI_lt / (ATARI_numcolors - 2)) % (ATARI_LINETYPES_MAX - 2);
437 vswr_mode(vdi_handle, MD_TRANS);
438 vsl_color(vdi_handle, color_index);
440 vsl_type(vdi_handle, 7);
441 vsl_udsty(vdi_handle, ATARI_linetypes[line_type + 2]);
442 walk_rects(f_line, win_xpos, win_ypos, win_xsize, win_ysize);
444 if (pxy_index >= 1) {
445 pxy[0] = pxy[2 * (pxy_index - 1)];
446 pxy[1] = pxy[2 * (pxy_index - 1) + 1];
452 put_text(int x, int y, int w, int h)
454 v_gtext(vdi_handle, put_text_x, put_text_y, put_text_str);
460 #define ATARIHEXERROR "palette values 3 hex digits, please"
461 #define ATARIHEIGHTERROR "expecting a character height"
462 char opt[6]; /* maximum: 'fff'\0 */
466 term_options[0] = NUL;
467 ATARI_c_height = ATARI_c_height_default;
469 for (i = 0; i < 17; i++) {
472 if (token[c_token].length > 5) {
473 ATARI_numpalette = 0;
474 ATARI_c_height = ATARI_c_height_default;
475 term_options[0] = NUL;
476 int_error(c_token, ATARIHEXERROR);
478 capture(opt, c_token, c_token, 6);
480 ATARI_c_height = strtoul(opt, &tok_end, 10);
481 if (*tok_end != NUL) {
482 ATARI_numpalette = 0;
483 ATARI_c_height = ATARI_c_height_default;
484 term_options[0] = NUL;
485 int_error(c_token, ATARIHEIGHTERROR);
487 if (ATARI_c_height > 999)
488 ATARI_c_height = 999; /* avoid opt length overflow */
489 sprintf(opt, "%d ", ATARI_c_height);
491 if (*opt == '"' || *opt == '\'') {
492 opt[strlen(opt) - 1] = NUL;
493 strcpy(opt, opt + 1);
495 ATARI_colors[i - 1] = strtoul(opt, &tok_end, 16);
496 if (*tok_end != NUL) {
497 ATARI_numpalette = 0;
498 ATARI_c_height = ATARI_c_height_default;
499 term_options[0] = NUL;
500 int_error(c_token, ATARIHEXERROR);
502 sprintf(opt, "%X ", ATARI_colors[i - 1]);
504 /* do we need to quote? */
505 if (isdigit((unsigned char) *opt) && strpbrk(opt, "ABCDEF")) {
506 sprintf(opt, "\"%X\" ", ATARI_colors[i - 1]);
509 strcat(term_options, opt);
512 ATARI_numpalette = (i == 0 ? 0 : i - 1);
513 /* printf("Number of linetypes:%d\n", ATARI_LINETYPES_MAX); */
522 int hchar, wchar, dummy;
525 char *colors, *tok_end;
527 static int have_win_size = 0;
531 if (ATARI_numpalette == 0 && (colors = getenv("GNUCOLORS")) && *colors) {
532 for (i = 0; i < 17; i++) {
534 ATARI_c_height = strtoul(colors, &tok_end, 10);
535 if (colors == tok_end) {
537 ATARI_c_height = ATARI_c_height_default;
543 ATARI_colors[i] = strtoul(colors, &tok_end, 16);
544 if (colors == tok_end || (unsigned) ATARI_colors[i] > 0xfff) {
551 while (*colors == ' ')
554 ATARI_numpalette = (i == 0 ? 0 : i - 1);
556 vdi_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
559 int_error(NO_CARET, "Fatal error opening virtual workstation");
561 for (i = 0; i < 10; work_in[i++] = 1);
562 work_in[10] = 2; /* use raster coordinates */
563 v_opnvwk(work_in, &vdi_handle, work_out);
566 int_error(NO_CARET, "Fatal error opening virtual workstation");
568 if (!have_win_size) {
569 wind_get(0, WF_WORKXYWH, &x, &y, &w, &h);
570 wind_calc(WC_WORK, WINTYPE, x, y, w, h, &win_xpos, &win_ypos,
571 &win_xsize, &win_ysize);
574 term->xmax = win_xsize;
575 term->ymax = win_ysize;
577 vst_height(vdi_handle, ATARI_c_height, &dummy, &dummy, &wchar, &hchar);
579 term->h_char = wchar;
580 term->v_char = hchar; /* hchar stands for height this time */
581 term->h_tic = win_xsize / 100;
582 term->v_tic = term->h_tic;
584 ATARI_maxycoord = win_ysize - 1;
585 ATARI_numcolors = work_out[13];
587 for (i = 0; i < ATARI_numpalette; i++) {
588 vq_color(vdi_handle, i, 1, ATARI_savecolors[i]);
590 rgb[0] = 1000 * (ATARI_colors[i] >> 8);
592 rgb[1] = 1000 * ((ATARI_colors[i] >> 4) & 15);
594 rgb[2] = 1000 * (ATARI_colors[i] & 15);
596 vs_color(vdi_handle, i, rgb);
607 if (vdi_handle != -1) {
608 for (i = 0; i < ATARI_numpalette; i++) {
609 vs_color(vdi_handle, i, ATARI_savecolors[i]);
611 v_clsvwk(vdi_handle);
619 ATARI_maxycoord = win_ysize - 1;
621 term->xmax = win_xsize;
622 term->ymax = win_ysize;
627 walk_rects(clear, win_xpos, win_ypos, win_xsize, win_ysize);
637 while (window_id != -1 && !poll_events(1));
644 ATARI_move(unsigned int x, unsigned int y)
648 pxy[0] = x + win_xpos;
649 pxy[1] = ATARI_yc(y) + win_ypos;
654 ATARI_vector(unsigned int x, unsigned int y)
656 pxy[2 * pxy_index] = x + win_xpos;
657 pxy[2 * pxy_index + 1] = ATARI_yc(y) + win_ypos;
660 if (pxy_index == 64) { /* we're all full */
666 ATARI_linetype(int lt)
674 ATARI_put_text(unsigned int x, unsigned int y, const char *str)
676 int vchar = term->v_char;
687 /* align text left and to middle of char height */
688 vst_alignment(vdi_handle, 0, 5, &dummy, &dummy);
689 vst_rotation(vdi_handle, (ATARI_rotation ? 900 : 0));
690 if (ATARI_rotation) {
691 put_text_x = x - vchar / 2 + 1 + win_xpos;
692 put_text_y = ATARI_yc(y) - 1 + win_ypos;
695 put_text_x = x + 1 + win_xpos;
696 put_text_y = ATARI_yc(y) - vchar / 2 + 1 + win_ypos;
699 walk_rects(put_text, win_xpos, win_ypos, win_xsize, win_ysize);
703 ATARI_text_angle(int ang)
705 ATARI_rotation = ang;
711 ATARI_justify_text(enum JUSTIFY mode)
717 ATARI_point(unsigned int x, unsigned int y, int number)
721 if (ATARI_numcolors == 2) {
722 line_and_point(x, y, number); /* monochrome */
724 /* we map colors that exceed our limit to dotted lines, but we can't do
725 that with the markers (sortof a generalized line_and_point) */
726 old_linetype = ATARI_lt;
727 if (ATARI_lt > ATARI_numcolors - 2)
728 ATARI_linetype(ATARI_lt % (ATARI_numcolors - 2)); /* same color, but no dots */
729 do_point(x, y, number);
730 ATARI_linetype(old_linetype);
734 #endif /* TERM_BODY */
738 TERM_TABLE_START(atari_driver)
739 "atari", "Atari AES-Terminal",
740 ATARI_XMAX, ATARI_YMAX, ATARI_VCHAR, ATARI_HCHAR,
741 ATARI_VTIC, ATARI_HTIC, ATARI_options, ATARI_init, ATARI_reset,
742 ATARI_text, null_scale, ATARI_graphics, ATARI_move, ATARI_vector,
743 ATARI_linetype, ATARI_put_text, ATARI_text_angle,
744 ATARI_justify_text, ATARI_point, do_arrow, set_font_null,
745 0, TERM_CAN_MULTIPLOT, 0, 0
746 TERM_TABLE_END(atari_driver)
749 #define LAST_TERM atari_driver
751 #endif /* TERM_TABLE */
753 #endif /* TERM_PROTO_ONLY */
757 "1 atari ST (via AES)",
758 "?commands set terminal atari",
759 "?set terminal atari",
764 " The `atari` terminal has options to set the character size and the screen",
768 " set terminal atari {<fontsize>} {<col0> <col1> ... <col15>}",
770 " The character size must appear if any colors are to be specified. Each of",
771 " the (up to 16) colors is given as a three-digit hex number, where the digits",
772 " represent RED, GREEN and BLUE (in that order). The range of 0--15 is scaled",
773 " to whatever color range the screen actually has. On a normal ST screen, odd",
774 " and even intensities are the same.",
777 " set terminal atari 4 # use small (6x6) font",
778 " set terminal atari 6 0 # set monochrome screen to white on black",
779 " set terminal atari 13 0 fff f00 f0 f ff f0f",
780 " # set first seven colors to black, white, red, green,",
781 " # blue, cyan, and purple and use large font (8x16).",
783 " Additionally, if an environment variable GNUCOLORS exists, its contents are",
784 " interpreted as an options string, but an explicit terminal option takes",
787 #endif /* TERM_HELP */