1 /* screen.c - Generic screen manipulation
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * This file is part of Frotz.
6 * Frotz is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Frotz is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 extern void set_header_extension (int, zword
);
25 extern int direct_call (zword
);
33 { ZORK_ZERO
, 5, 497, 498 },
34 { ZORK_ZERO
, 6, 501, 502 },
35 { ZORK_ZERO
, 7, 499, 500 },
36 { ZORK_ZERO
, 8, 503, 504 },
37 { ARTHUR
, 54, 170, 171 },
38 { SHOGUN
, 50, 61, 62 },
42 static int font_height
= 1;
43 static int font_width
= 1;
45 static bool input_redraw
= FALSE
;
46 static bool more_prompts
= TRUE
;
47 static bool discarding
= FALSE
;
48 static bool cursor
= TRUE
;
50 static int input_window
= 0;
75 * Return the window number in zargs[0]. In V6 only, -3 refers to the
80 static zword
winarg0 (void)
83 if (h_version
== V6
&& (short) zargs
[0] == -3)
86 if (zargs
[0] >= ((h_version
== V6
) ? 8 : 2))
87 runtime_error (ERR_ILL_WIN
);
96 * Return the (optional) window number in zargs[2]. -3 refers to the
97 * current window. This optional window number was only used by some
98 * V6 opcodes: set_cursor, set_margins, set_colour.
102 static zword
winarg2 (void)
105 if (zargc
< 3 || (short) zargs
[2] == -3)
109 runtime_error (ERR_ILL_WIN
);
118 * Move the hardware cursor to make it match the window properties.
122 static void update_cursor (void)
126 cwp
->y_pos
+ cwp
->y_cursor
- 1,
127 cwp
->x_pos
+ cwp
->x_cursor
- 1);
134 * Reset the cursor of a given window to its initial position.
138 static void reset_cursor (zword win
)
142 if (h_version
<= V4
&& win
== 0)
143 lines
= wp
[0].y_size
/ hi (wp
[0].font_size
) - 1;
145 wp
[win
].y_cursor
= hi (wp
[0].font_size
) * lines
+ 1;
146 wp
[win
].x_cursor
= wp
[win
].left
+ 1;
156 * Turn more prompts on/off.
160 void set_more_prompts (bool flag
)
163 if (flag
&& !more_prompts
)
168 }/* set_more_prompts */
173 * Return the #screen units from the cursor to the end of the line.
177 static int units_left (void)
180 return cwp
->x_size
- cwp
->right
- cwp
->x_cursor
+ 1;
187 * Return maximum width of a line in the given window. This is used in
188 * connection with the extended output stream #3 call in V6.
192 zword
get_max_width (zword win
)
195 if (h_version
== V6
) {
198 runtime_error (ERR_ILL_WIN
);
200 return wp
[win
].x_size
- wp
[win
].left
- wp
[win
].right
;
202 } else return 0xffff;
209 * Decrement the newline counter. Call the newline interrupt when the
210 * counter hits zero. This is a helper function for screen_new_line.
214 static void countdown (void)
217 if (cwp
->nl_countdown
!= 0)
218 if (--cwp
->nl_countdown
== 0)
219 direct_call (cwp
->nl_routine
);
226 * Print a newline to the screen.
230 void screen_new_line (void)
233 if (discarding
) return;
235 /* Handle newline interrupts at the start (for most cases) */
237 if (h_interpreter_number
!= INTERP_MSDOS
|| story_id
!= ZORK_ZERO
|| h_release
!= 393)
240 /* Check whether the last input line gets destroyed */
242 if (input_window
== cwin
)
245 /* If the cursor has not reached the bottom line, then move it to
246 the next line; otherwise scroll the window or reset the cursor
249 cwp
->x_cursor
= cwp
->left
+ 1;
251 if (cwp
->y_cursor
+ 2 * font_height
- 1 > cwp
->y_size
)
253 if (enable_scrolling
) {
255 zword y
= cwp
->y_pos
;
256 zword x
= cwp
->x_pos
;
264 } else cwp
->y_cursor
= 1;
266 else cwp
->y_cursor
+= font_height
;
270 /* See if we need to print a more prompt (unless the game has set
271 the line counter to -999 in order to suppress more prompts). */
273 if (enable_scrolling
&& (short) cwp
->line_count
!= -999) {
275 zword above
= (cwp
->y_cursor
- 1) / font_height
;
276 zword below
= (cwp
->y_size
- cwp
->y_cursor
+ 1) / font_height
;
280 if ((short) cwp
->line_count
>= (short) above
+ below
- 1) {
285 cwp
->line_count
= f_setup
.context_lines
;
291 /* Handle newline interrupts at the end for Zork Zero under DOS */
293 if (h_interpreter_number
== INTERP_MSDOS
&& story_id
== ZORK_ZERO
&& h_release
== 393)
296 }/* screen_new_line */
301 * Display a single character on the screen.
305 void screen_char (zchar c
)
309 if (discarding
) return;
311 if (c
== ZC_INDENT
&& cwp
->x_cursor
!= cwp
->left
+ 1)
314 if (units_left () < (width
= os_char_width (c
))) {
316 if (!enable_wrapping
)
317 { cwp
->x_cursor
= cwp
->x_size
- cwp
->right
; return; }
323 os_display_char (c
); cwp
->x_cursor
+= width
;
330 * Display a string of characters on the screen. If the word doesn't fit
331 * then use wrapping or clipping depending on the current setting of the
332 * enable_wrapping flag.
336 void screen_word (const zchar
*s
)
340 if (discarding
) return;
342 if (*s
== ZC_INDENT
&& cwp
->x_cursor
!= cwp
->left
+ 1)
345 if (units_left () < (width
= os_string_width (s
))) {
347 if (!enable_wrapping
) {
351 while ((c
= *s
++) != 0)
353 if (c
== ZC_NEW_FONT
|| c
== ZC_NEW_STYLE
) {
355 int arg
= (int) *s
++;
357 if (c
== ZC_NEW_FONT
)
359 if (c
== ZC_NEW_STYLE
)
360 os_set_text_style (arg
);
362 } else screen_char (c
);
368 if (*s
== ' ' || *s
== ZC_INDENT
|| *s
== ZC_GAP
)
369 width
= os_string_width (++s
);
372 if (cwin
== 0) Justifiable ();
379 os_display_string (s
); cwp
->x_cursor
+= width
;
386 * Display an input line on the screen. This is required during playback.
390 void screen_write_input (const zchar
*buf
, zchar key
)
394 if (units_left () < (width
= os_string_width (buf
)))
397 os_display_string (buf
); cwp
->x_cursor
+= width
;
399 if (key
== ZC_RETURN
)
402 }/* screen_write_input */
407 * Remove an input line that has already been printed from the screen
408 * as if it was deleted by the player. This could be necessary during
413 void screen_erase_input (const zchar
*buf
)
418 int width
= os_string_width (buf
);
423 cwp
->x_cursor
-= width
;
425 y
= cwp
->y_pos
+ cwp
->y_cursor
- 1;
426 x
= cwp
->x_pos
+ cwp
->x_cursor
- 1;
428 os_erase_area (y
, x
, y
+ font_height
- 1, x
+ width
- 1);
429 os_set_cursor (y
, x
);
433 }/* screen_erase_input */
438 * Read an input line from the keyboard and return the terminating key.
442 zchar
console_read_input (int max
, zchar
*buf
, zword timeout
, bool continued
)
447 /* Make sure there is some space for input */
449 if (cwin
== 0 && units_left () + os_string_width (buf
) < 10 * font_width
)
452 /* Make sure the input line is visible */
454 if (continued
&& input_redraw
)
455 screen_write_input (buf
, -1);
458 input_redraw
= FALSE
;
460 /* Get input line from IO interface */
462 cwp
->x_cursor
-= os_string_width (buf
);
463 key
= os_read_line (max
, buf
, timeout
, units_left (), continued
);
464 cwp
->x_cursor
+= os_string_width (buf
);
466 if (key
!= ZC_TIME_OUT
)
467 for (i
= 0; i
< 8; i
++)
468 wp
[i
].line_count
= 0;
470 /* Add a newline if the input was terminated normally */
472 if (key
== ZC_RETURN
)
477 }/* console_read_input */
482 * Read a single keystroke and return it.
486 zchar
console_read_key (zword timeout
)
491 key
= os_read_key (timeout
, cursor
);
493 if (key
!= ZC_TIME_OUT
)
494 for (i
= 0; i
< 8; i
++)
495 wp
[i
].line_count
= 0;
499 }/* console_read_key */
504 * Set the three enable_*** variables to make them match the attributes
505 * of the current window.
509 static void update_attributes (void)
511 zword attr
= cwp
->attribute
;
513 enable_wrapping
= attr
& 1;
514 enable_scrolling
= attr
& 2;
515 enable_scripting
= attr
& 4;
516 enable_buffering
= attr
& 8;
518 /* Some story files forget to select wrapping for printing hints */
520 if (story_id
== ZORK_ZERO
&& h_release
== 366)
522 enable_wrapping
= TRUE
;
523 if (story_id
== SHOGUN
&& h_release
<= 295)
525 enable_wrapping
= TRUE
;
527 }/* update_attributes */
532 * Set the right text style. This can be necessary when the fixed font
533 * flag is changed, or when a new window is selected, or when the game
534 * uses the set_text_style opcode.
538 void refresh_text_style (void)
542 if (h_version
!= V6
) {
546 if (cwin
!= 0 || h_flags
& FIXED_FONT_FLAG
)
547 style
|= FIXED_WIDTH_STYLE
;
549 } else style
= cwp
->style
;
551 if (!ostream_memory
&& ostream_screen
&& enable_buffering
) {
553 print_char (ZC_NEW_STYLE
);
556 } else os_set_text_style (style
);
558 }/* refresh_text_style */
563 * Set the current window. In V6 every window has its own set of window
564 * properties such as colours, text style, cursor position and size.
568 static void set_window (zword win
)
573 cwin
= win
; cwp
= wp
+ win
;
575 update_attributes ();
577 if (h_version
== V6
) {
579 os_set_colour (lo (cwp
->colour
), hi (cwp
->colour
));
581 if (os_font_data (cwp
->font
, &font_height
, &font_width
))
582 os_set_font (cwp
->font
);
584 os_set_text_style (cwp
->style
);
586 } else refresh_text_style ();
588 if (h_version
!= V6
&& win
!= 0) {
589 wp
[win
].y_cursor
= 1;
590 wp
[win
].x_cursor
= 1;
600 * Erase a window to background colour.
604 void erase_window (zword win
)
606 zword y
= wp
[win
].y_pos
;
607 zword x
= wp
[win
].x_pos
;
609 if (h_version
== V6
&& win
!= cwin
&& h_interpreter_number
!= INTERP_AMIGA
)
610 os_set_colour (lo (wp
[win
].colour
), hi (wp
[win
].colour
));
614 y
+ wp
[win
].y_size
- 1,
615 x
+ wp
[win
].x_size
- 1);
617 if (h_version
== V6
&& win
!= cwin
&& h_interpreter_number
!= INTERP_AMIGA
)
618 os_set_colour (lo (cwp
->colour
), hi (cwp
->colour
));
622 wp
[win
].line_count
= 0;
629 * Divide the screen into upper (1) and lower (0) windows. In V3 the upper
630 * window appears below the status line.
634 void split_window (zword height
)
636 zword stat_height
= 0;
640 /* Calculate height of status line and upper window */
643 height
*= hi (wp
[1].font_size
);
646 stat_height
= hi (wp
[7].font_size
);
648 /* Cursor of upper window mustn't be swallowed by the lower window */
650 wp
[1].y_cursor
+= wp
[1].y_pos
- 1 - stat_height
;
652 wp
[1].y_pos
= 1 + stat_height
;
653 wp
[1].y_size
= height
;
655 if ((short) wp
[1].y_cursor
> (short) wp
[1].y_size
)
658 /* Cursor of lower window mustn't be swallowed by the upper window */
660 wp
[0].y_cursor
+= wp
[0].y_pos
- 1 - stat_height
- height
;
662 wp
[0].y_pos
= 1 + stat_height
+ height
;
663 wp
[0].y_size
= h_screen_height
- stat_height
- height
;
665 if ((short) wp
[0].y_cursor
< 1)
668 /* Erase the upper window in V3 only */
670 if (h_version
== V3
&& height
!= 0)
678 * Erase the entire screen to background colour.
682 static void erase_screen (zword win
)
686 os_erase_area (1, 1, h_screen_height
, h_screen_width
);
688 if ((short) win
== -1) {
694 for (i
= 0; i
< 8; i
++)
695 wp
[i
].line_count
= 0;
704 * Try to adapt the window properties to a new screen size.
708 void resize_screen (void)
711 if (h_version
!= V6
) {
713 wp
[0].x_size
= h_screen_width
;
714 wp
[1].x_size
= h_screen_width
;
715 wp
[7].x_size
= h_screen_width
;
717 wp
[0].y_size
= h_screen_height
- wp
[1].y_size
- wp
[7].y_size
;
728 * Prepare the screen for a new game.
732 void restart_screen (void)
735 /* Use default settings */
737 os_set_colour (h_default_foreground
, h_default_background
);
739 if (os_font_data (TEXT_FONT
, &font_height
, &font_width
))
740 os_set_font (TEXT_FONT
);
742 os_set_text_style (0);
746 /* Initialise window properties */
750 for (cwp
= wp
; cwp
< wp
+ 8; cwp
++) {
760 cwp
->nl_countdown
= 0;
762 cwp
->colour
= (h_default_background
<< 8) | h_default_foreground
;
763 cwp
->font
= TEXT_FONT
;
764 cwp
->font_size
= (font_height
<< 8) | font_width
;
768 /* Prepare lower/upper windows and status line */
770 wp
[0].attribute
= 15;
772 wp
[0].left
= f_setup
.left_margin
;
773 wp
[0].right
= f_setup
.right_margin
;
775 wp
[0].x_size
= h_screen_width
;
776 wp
[1].x_size
= h_screen_width
;
779 wp
[7].x_size
= h_screen_width
;
781 os_restart_game (RESTART_WPROP_SET
);
783 /* Clear the screen, unsplit it and select window 0 */
785 erase_screen ((zword
) (-1));
787 }/* restart_screen */
792 * Return false if the last mouse click occured outside the current
793 * mouse window; otherwise write the mouse arrow coordinates to the
794 * memory of the header extension table and return true.
798 bool validate_click (void)
803 if (mouse_y
< wp
[mwin
].y_pos
|| mouse_y
>= wp
[mwin
].y_pos
+ wp
[mwin
].y_size
)
805 if (mouse_x
< wp
[mwin
].x_pos
|| mouse_x
>= wp
[mwin
].x_pos
+ wp
[mwin
].x_size
)
808 hx_mouse_y
= mouse_y
- wp
[mwin
].y_pos
+ 1;
809 hx_mouse_x
= mouse_x
- wp
[mwin
].x_pos
+ 1;
813 if (mouse_y
< 1 || mouse_y
> h_screen_height
)
815 if (mouse_x
< 1 || mouse_x
> h_screen_width
)
818 hx_mouse_y
= mouse_y
;
819 hx_mouse_x
= mouse_x
;
823 if (h_version
!= V6
) {
824 hx_mouse_y
= (hx_mouse_y
- 1) / h_font_height
+ 1;
825 hx_mouse_x
= (hx_mouse_x
- 1) / h_font_width
+ 1;
828 set_header_extension (HX_MOUSE_Y
, hx_mouse_y
);
829 set_header_extension (HX_MOUSE_X
, hx_mouse_x
);
833 }/* validate_click */
838 * Start printing a so-called debugging message. The contents of the
839 * message are passed to the message stream, a Frotz specific output
840 * stream with maximum priority.
844 void screen_mssg_on (void)
847 if (cwin
== 0) { /* messages in window 0 only */
849 os_set_text_style (0);
851 if (cwp
->x_cursor
!= cwp
->left
+ 1)
854 screen_char (ZC_INDENT
);
856 } else discarding
= TRUE
; /* discard messages in other windows */
858 }/* screen_mssg_on */
863 * Stop printing a "debugging" message.
867 void screen_mssg_off (void)
870 if (cwin
== 0) { /* messages in window 0 only */
874 refresh_text_style ();
876 } else discarding
= FALSE
; /* message has been discarded */
878 }/* screen_mssg_off */
881 * z_buffer_mode, turn text buffering on/off.
883 * zargs[0] = new text buffering flag (0 or 1)
887 void z_buffer_mode (void)
890 /* Infocom's V6 games rarely use the buffer_mode opcode. If they do
891 then only to print text immediately, without any delay. This was
892 used to give the player some sign of life while the game was
893 spending much time on parsing a complicated input line. (To turn
894 off word wrapping, V6 games use the window_style opcode instead.)
895 Today we can afford to ignore buffer_mode in V6. */
897 if (h_version
!= V6
) {
901 wp
[0].attribute
&= ~8;
904 wp
[0].attribute
|= 8;
906 update_attributes ();
913 * z_draw_picture, draw a picture.
915 * zargs[0] = number of picture to draw
916 * zargs[1] = y-coordinate of top left corner
917 * zargs[2] = x-coordinate of top left corner
921 void z_draw_picture (void)
923 zword pic
= zargs
[0];
932 if (y
== 0) /* use cursor line if y-coordinate is 0 */
934 if (x
== 0) /* use cursor column if x-coordinate is 0 */
940 /* The following is necessary to make Amiga and Macintosh story
941 files work with MCGA graphics files. Some screen-filling
942 pictures of the original Amiga release like the borders of
943 Zork Zero were split into several MCGA pictures (left, right
944 and top borders). We pretend this has not happened. */
946 for (i
= 0; mapper
[i
].story_id
!= UNKNOWN
; i
++)
948 if (story_id
== mapper
[i
].story_id
&& pic
== mapper
[i
].pic
) {
955 os_picture_data (pic
, &height1
, &width1
);
956 os_picture_data (mapper
[i
].pic2
, &height2
, &width2
);
958 if (story_id
== ARTHUR
&& pic
== 54)
959 delta
= h_screen_width
/ 160;
961 os_draw_picture (mapper
[i
].pic1
, y
+ height1
, x
+ delta
);
962 os_draw_picture (mapper
[i
].pic2
, y
+ height1
, x
+ width1
- width2
- delta
);
966 os_draw_picture (pic
, y
, x
);
968 if (story_id
== SHOGUN
)
974 os_picture_data (59, &height
, &width
);
975 os_draw_picture (59, y
, h_screen_width
- width
+ 1);
979 }/* z_draw_picture */
982 * z_erase_line, erase the line starting at the cursor position.
984 * zargs[0] = 1 + #units to erase (1 clears to the end of the line)
988 void z_erase_line (void)
990 zword pixels
= zargs
[0];
995 /* Clipping at the right margin of the current window */
997 if (--pixels
== 0 || pixels
> units_left ())
998 pixels
= units_left ();
1000 /* Erase from cursor position */
1002 y
= cwp
->y_pos
+ cwp
->y_cursor
- 1;
1003 x
= cwp
->x_pos
+ cwp
->x_cursor
- 1;
1005 os_erase_area (y
, x
, y
+ font_height
- 1, x
+ pixels
- 1);
1010 * z_erase_picture, erase a picture with background colour.
1012 * zargs[0] = number of picture to erase
1013 * zargs[1] = y-coordinate of top left corner (optional)
1014 * zargs[2] = x-coordinate of top left corner (optional)
1018 void z_erase_picture (void)
1027 if (y
== 0) /* use cursor line if y-coordinate is 0 */
1029 if (x
== 0) /* use cursor column if x-coordinate is 0 */
1032 os_picture_data (zargs
[0], &height
, &width
);
1034 y
+= cwp
->y_pos
- 1;
1035 x
+= cwp
->x_pos
- 1;
1037 os_erase_area (y
, x
, y
+ height
- 1, x
+ width
- 1);
1039 }/* z_erase_picture */
1042 * z_erase_window, erase a window or the screen to background colour.
1044 * zargs[0] = window (-3 current, -2 screen, -1 screen & unsplit)
1048 void z_erase_window (void)
1053 if ((short) zargs
[0] == -1 || (short) zargs
[0] == -2)
1054 erase_screen (zargs
[0]);
1056 erase_window (winarg0 ());
1058 }/* z_erase_window */
1061 * z_get_cursor, write the cursor coordinates into a table.
1063 * zargs[0] = address to write information to
1067 void z_get_cursor (void)
1076 if (h_version
!= V6
) { /* convert to grid positions */
1077 y
= (y
- 1) / h_font_height
+ 1;
1078 x
= (x
- 1) / h_font_width
+ 1;
1081 storew ((zword
) (zargs
[0] + 0), y
);
1082 storew ((zword
) (zargs
[0] + 2), x
);
1087 * z_get_wind_prop, store the value of a window property.
1089 * zargs[0] = window (-3 is the current one)
1090 * zargs[1] = number of window property to be stored
1094 void z_get_wind_prop (void)
1100 runtime_error (ERR_ILL_WIN_PROP
);
1102 store (((zword
*) (wp
+ winarg0 ())) [zargs
[1]]);
1104 }/* z_get_wind_prop */
1107 * z_mouse_window, select a window as mouse window.
1109 * zargs[0] = window number (-3 is the current) or -1 for the screen
1113 void z_mouse_window (void)
1116 mwin
= ((short) zargs
[0] == -1) ? -1 : winarg0 ();
1118 }/* z_mouse_window */
1121 * z_move_window, place a window on the screen.
1123 * zargs[0] = window (-3 is the current one)
1124 * zargs[1] = y-coordinate
1125 * zargs[2] = x-coordinate
1129 void z_move_window (void)
1131 zword win
= winarg0 ();
1135 wp
[win
].y_pos
= zargs
[1];
1136 wp
[win
].x_pos
= zargs
[2];
1141 }/* z_move_window */
1144 * z_picture_data, get information on a picture or the graphics file.
1146 * zargs[0] = number of picture or 0 for the graphics file
1147 * zargs[1] = address to write information to
1151 void z_picture_data (void)
1153 zword pic
= zargs
[0];
1154 zword table
= zargs
[1];
1159 bool avail
= os_picture_data (pic
, &height
, &width
);
1161 for (i
= 0; mapper
[i
].story_id
!= UNKNOWN
; i
++)
1163 if (story_id
== mapper
[i
].story_id
) {
1165 if (pic
== mapper
[i
].pic
) {
1167 int height2
, width2
;
1169 avail
&= os_picture_data (mapper
[i
].pic1
, &height2
, &width2
);
1170 avail
&= os_picture_data (mapper
[i
].pic2
, &height2
, &width2
);
1174 } else if (pic
== mapper
[i
].pic1
|| pic
== mapper
[i
].pic2
)
1179 storew ((zword
) (table
+ 0), (zword
) (height
));
1180 storew ((zword
) (table
+ 2), (zword
) (width
));
1184 }/* z_picture_data */
1187 * z_picture_table, prepare a group of pictures for faster display.
1189 * zargs[0] = address of table holding the picture numbers
1193 void z_picture_table (void)
1196 /* This opcode is used by Shogun and Zork Zero when the player
1197 encounters built-in games such as Peggleboz. Nowadays it is
1198 not very helpful to hold the picture data in memory because
1199 even a small disk cache avoids re-loading of data. */
1201 }/* z_picture_table */
1204 * z_print_table, print ASCII text in a rectangular area.
1206 * zargs[0] = address of text to be printed
1207 * zargs[1] = width of rectangular area
1208 * zargs[2] = height of rectangular area (optional)
1209 * zargs[3] = number of char's to skip between lines (optional)
1213 void z_print_table (void)
1215 zword addr
= zargs
[0];
1221 /* Supply default arguments */
1228 /* Write text in width x height rectangle */
1232 for (i
= 0; i
< zargs
[2]; i
++) {
1238 cwp
->y_cursor
+= font_height
;
1245 for (j
= 0; j
< zargs
[1]; j
++) {
1260 }/* z_print_table */
1263 * z_put_wind_prop, set the value of a window property.
1265 * zargs[0] = window (-3 is the current one)
1266 * zargs[1] = number of window property to set
1267 * zargs[2] = value to set window property to
1271 void z_put_wind_prop (void)
1277 runtime_error (ERR_ILL_WIN_PROP
);
1279 ((zword
*) (wp
+ winarg0 ())) [zargs
[1]] = zargs
[2];
1281 }/* z_put_wind_prop */
1284 * z_scroll_window, scroll a window up or down.
1286 * zargs[0] = window (-3 is the current one)
1287 * zargs[1] = #screen units to scroll up (positive) or down (negative)
1291 void z_scroll_window (void)
1293 zword win
= winarg0 ();
1298 /* Use the correct set of colours when scrolling the window */
1300 if (win
!= cwin
&& h_interpreter_number
!= INTERP_AMIGA
)
1301 os_set_colour (lo (wp
[win
].colour
), hi (wp
[win
].colour
));
1308 y
+ wp
[win
].y_size
- 1,
1309 x
+ wp
[win
].x_size
- 1,
1312 if (win
!= cwin
&& h_interpreter_number
!= INTERP_AMIGA
)
1313 os_set_colour (lo (cwp
->colour
), hi (cwp
->colour
));
1315 }/* z_scroll_window */
1318 * z_set_colour, set the foreground and background colours.
1320 * zargs[0] = foreground colour
1321 * zargs[1] = background colour
1322 * zargs[2] = window (-3 is the current one, optional)
1326 void z_set_colour (void)
1328 zword win
= (h_version
== V6
) ? winarg2 () : 0;
1330 zword fg
= zargs
[0];
1331 zword bg
= zargs
[1];
1335 if ((short) fg
== -1) /* colour -1 is the colour at the cursor */
1336 fg
= os_peek_colour ();
1337 if ((short) bg
== -1)
1338 bg
= os_peek_colour ();
1340 if (fg
== 0) /* colour 0 means keep current colour */
1341 fg
= lo (wp
[win
].colour
);
1343 bg
= hi (wp
[win
].colour
);
1345 if (fg
== 1) /* colour 1 is the system default colour */
1346 fg
= h_default_foreground
;
1348 bg
= h_default_background
;
1350 if (h_version
== V6
&& h_interpreter_number
== INTERP_AMIGA
)
1352 /* Changing colours of window 0 affects the entire screen */
1358 for (i
= 1; i
< 8; i
++) {
1360 zword bg2
= hi (wp
[i
].colour
);
1361 zword fg2
= lo (wp
[i
].colour
);
1364 bg2
= (bg2
== lo (wp
[0].colour
)) ? fg
: bg
;
1366 fg2
= (fg2
== lo (wp
[0].colour
)) ? fg
: bg
;
1368 wp
[i
].colour
= (bg2
<< 8) | fg2
;
1374 wp
[win
].colour
= (bg
<< 8) | fg
;
1376 if (win
== cwin
|| h_version
!= V6
)
1377 os_set_colour (fg
, bg
);
1382 * z_set_font, set the font for text output and store the previous font.
1384 * zargs[0] = number of font or 0 to keep current font
1388 void z_set_font (void)
1390 zword win
= (h_version
== V6
) ? cwin
: 0;
1391 zword font
= zargs
[0];
1395 if (os_font_data (font
, &font_height
, &font_width
)) {
1397 store (wp
[win
].font
);
1399 wp
[win
].font
= font
;
1400 wp
[win
].font_size
= (font_height
<< 8) | font_width
;
1402 if (!ostream_memory
&& ostream_screen
&& enable_buffering
) {
1404 print_char (ZC_NEW_FONT
);
1407 } else os_set_font (font
);
1411 } else store (wp
[win
].font
);
1416 * z_set_cursor, set the cursor position or turn the cursor on/off.
1418 * zargs[0] = y-coordinate or -2/-1 for cursor on/off
1419 * zargs[1] = x-coordinate
1420 * zargs[2] = window (-3 is the current one, optional)
1424 void z_set_cursor (void)
1426 zword win
= (h_version
== V6
) ? winarg2 () : 1;
1433 /* Supply default arguments */
1438 /* Handle cursor on/off */
1440 if ((short) y
< 0) {
1442 if ((short) y
== -2)
1444 if ((short) y
== -1)
1451 /* Convert grid positions to screen units if this is not V6 */
1453 if (h_version
!= V6
) {
1458 y
= (y
- 1) * h_font_height
+ 1;
1459 x
= (x
- 1) * h_font_width
+ 1;
1463 /* Protect the margins */
1465 if (y
== 0) /* use cursor line if y-coordinate is 0 */
1466 y
= wp
[win
].y_cursor
;
1467 if (x
== 0) /* use cursor column if x-coordinate is 0 */
1468 x
= wp
[win
].x_cursor
;
1469 if (x
<= wp
[win
].left
|| x
> wp
[win
].x_size
- wp
[win
].right
)
1470 x
= wp
[win
].left
+ 1;
1472 /* Move the cursor */
1474 wp
[win
].y_cursor
= y
;
1475 wp
[win
].x_cursor
= x
;
1483 * z_set_margins, set the left and right margins of a window.
1485 * zargs[0] = left margin in pixels
1486 * zargs[1] = right margin in pixels
1487 * zargs[2] = window (-3 is the current one, optional)
1491 void z_set_margins (void)
1493 zword win
= winarg2 ();
1497 wp
[win
].left
= zargs
[0];
1498 wp
[win
].right
= zargs
[1];
1500 /* Protect the margins */
1502 if (wp
[win
].x_cursor
<= zargs
[0] || wp
[win
].x_cursor
> wp
[win
].x_size
- zargs
[1]) {
1504 wp
[win
].x_cursor
= zargs
[0] + 1;
1511 }/* z_set_margins */
1514 * z_set_text_style, set the style for text output.
1516 * zargs[0] = style flags to set or 0 to reset text style
1520 void z_set_text_style (void)
1522 zword win
= (h_version
== V6
) ? cwin
: 0;
1523 zword style
= zargs
[0];
1525 wp
[win
].style
|= style
;
1530 refresh_text_style ();
1532 }/* z_set_text_style */
1535 * z_set_window, select the current window.
1537 * zargs[0] = window to be selected (-3 is the current one)
1541 void z_set_window (void)
1544 set_window (winarg0 ());
1551 * Pad the status line with spaces up to the given position.
1555 static void pad_status_line (int column
)
1561 spaces
= units_left () / os_char_width (' ') - column
;
1563 /* while (spaces--) */
1564 /* Justin Wesley's fix for narrow displays (Agenda PDA) */
1565 while (spaces
-- > 0)
1568 }/* pad_status_line */
1571 * z_show_status, display the status line for V1 to V3 games.
1577 void z_show_status (void)
1586 /* One V5 game (Wishbringer Solid Gold) contains this opcode by
1587 accident, so just return if the version number does not fit */
1589 if (h_version
>= V4
)
1592 /* Read all relevant global variables from the memory of the
1593 Z-machine into local variables */
1596 LOW_WORD (addr
, global0
)
1598 LOW_WORD (addr
, global1
)
1600 LOW_WORD (addr
, global2
)
1602 /* Frotz uses window 7 for the status line. Don't forget to select
1603 reverse and fixed width text style */
1607 print_char (ZC_NEW_STYLE
);
1608 print_char (REVERSE_STYLE
| FIXED_WIDTH_STYLE
);
1610 /* If the screen width is below 55 characters then we have to use
1611 the brief status line format */
1613 if (h_screen_cols
< 55)
1616 /* Print the object description for the global variable 0 */
1619 print_object (global0
);
1621 /* A header flag tells us whether we have to display the current
1622 time or the score/moves information */
1624 if (h_config
& CONFIG_TIME
) { /* print hours and minutes */
1626 zword hours
= (global1
+ 11) % 12 + 1;
1628 pad_status_line (brief
? 15 : 20);
1630 print_string ("Time: ");
1640 print_num (global2
);
1644 print_char ((global1
>= 12) ? 'p' : 'a');
1647 } else { /* print score and moves */
1649 pad_status_line (brief
? 15 : 30);
1651 print_string (brief
? "S: " : "Score: ");
1652 print_num (global1
);
1654 pad_status_line (brief
? 8 : 14);
1656 print_string (brief
? "M: " : "Moves: ");
1657 print_num (global2
);
1661 /* Pad the end of the status line with spaces */
1663 pad_status_line (0);
1665 /* Return to the lower window */
1669 }/* z_show_status */
1672 * z_split_window, split the screen into an upper (1) and lower (0) window.
1674 * zargs[0] = height of upper window in screen units (V6) or #lines
1678 void z_split_window (void)
1681 split_window (zargs
[0]);
1683 }/* z_split_window */
1686 * z_window_size, change the width and height of a window.
1688 * zargs[0] = window (-3 is the current one)
1689 * zargs[1] = new height in screen units
1690 * zargs[2] = new width in screen units
1694 void z_window_size (void)
1696 zword win
= winarg0 ();
1700 wp
[win
].y_size
= zargs
[1];
1701 wp
[win
].x_size
= zargs
[2];
1703 /* Keep the cursor within the window */
1705 if (wp
[win
].y_cursor
> zargs
[1] || wp
[win
].x_cursor
> zargs
[2])
1708 }/* z_window_size */
1711 * z_window_style, set / clear / toggle window attributes.
1713 * zargs[0] = window (-3 is the current one)
1714 * zargs[1] = window attribute flags
1715 * zargs[2] = operation to perform (optional, defaults to 0)
1719 void z_window_style (void)
1721 zword win
= winarg0 ();
1722 zword flags
= zargs
[1];
1726 /* Supply default arguments */
1731 /* Set window style */
1734 case 0: wp
[win
].attribute
= flags
; break;
1735 case 1: wp
[win
].attribute
|= flags
; break;
1736 case 2: wp
[win
].attribute
&= ~flags
; break;
1737 case 3: wp
[win
].attribute
^= flags
; break;
1741 update_attributes ();
1743 }/* z_window_style */