xref: /illumos-gate/usr/src/boot/forth/frames.4th (revision 63f91fbc3c024870d86dc3332a4a0080fb29bc40)
1\ Copyright (c) 2003 Scott Long <scottl@FreeBSD.org>
2\ Copyright (c) 2012-2015 Devin Teske <dteske@FreeBSD.org>
3\ Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
4\ All rights reserved.
5\
6\ Redistribution and use in source and binary forms, with or without
7\ modification, are permitted provided that the following conditions
8\ are met:
9\ 1. Redistributions of source code must retain the above copyright
10\    notice, this list of conditions and the following disclaimer.
11\ 2. Redistributions in binary form must reproduce the above copyright
12\    notice, this list of conditions and the following disclaimer in the
13\    documentation and/or other materials provided with the distribution.
14\
15\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25\ SUCH DAMAGE.
26\
27
28marker task-frames.4th
29
30vocabulary frame-drawing
31only forth also frame-drawing definitions
32
33\ XXX Filled boxes are left as an exercise for the reader... ;-/
34
35variable h_el
36variable v_el
37variable lt_el
38variable lb_el
39variable rt_el
40variable rb_el
41variable fill
42
43\ ASCII frames (used when serial console is detected)
44 45 constant ascii_dash
45 61 constant ascii_equal
46124 constant ascii_pipe
47 43 constant ascii_plus
48
49\ Single frames
50$2500 constant sh_el
51$2502 constant sv_el
52$250c constant slt_el
53$2514 constant slb_el
54$2510 constant srt_el
55$2518 constant srb_el
56\ Double frames
57$2550 constant dh_el
58$2551 constant dv_el
59$2554 constant dlt_el
60$255a constant dlb_el
61$2557 constant drt_el
62$255d constant drb_el
63\ Fillings
640 constant fill_none
6532 constant fill_blank
66$2591 constant fill_dark
67$2592 constant fill_med
68$2593 constant fill_bright
69
70only forth definitions also frame-drawing
71
72: hline	( len x y -- )	\ Draw horizontal single line
73	at-xy		\ move cursor
74	0 do
75		h_el @ xemit
76	loop
77;
78
79: f_ascii ( -- )	( -- )	\ set frames to ascii
80	ascii_dash h_el !
81	ascii_pipe v_el !
82	ascii_plus lt_el !
83	ascii_plus lb_el !
84	ascii_plus rt_el !
85	ascii_plus rb_el !
86;
87
88: f_single	( -- )	\ set frames to single
89	boot_serial? if f_ascii exit then
90	sh_el h_el !
91	sv_el v_el !
92	slt_el lt_el !
93	slb_el lb_el !
94	srt_el rt_el !
95	srb_el rb_el !
96;
97
98: f_double	( -- )	\ set frames to double
99	boot_serial? if
100		f_ascii
101		ascii_equal h_el !
102		exit
103	then
104	dh_el h_el !
105	dv_el v_el !
106	dlt_el lt_el !
107	dlb_el lb_el !
108	drt_el rt_el !
109	drb_el rb_el !
110;
111
112: vline	( len x y -- )	\ Draw vertical single line
113	2dup 4 pick
114	0 do
115		at-xy
116		v_el @ xemit
117		1+
118		2dup
119	loop
120	2drop 2drop drop
121;
122
123: box	( w h x y -- )	\ Draw a box
124	framebuffer? if
125		rot		( w x y h )
126		over + >R	( w x y -- R: y+h )
127		swap rot	( y x w -- R: y+h )
128		over + >R	( y x -- R: y+h x+w )
129		swap R> R> term-drawrect
130		exit
131	then
132	\ Non-framebuffer version
133	2dup 1+ 4 pick 1- -rot
134	vline		\ Draw left vert line
135	2dup 1+ swap 5 pick + swap 4 pick 1- -rot
136	vline		\ Draw right vert line
137	2dup swap 1+ swap 5 pick 1- -rot
138	hline		\ Draw top horiz line
139	2dup swap 1+ swap 4 pick + 5 pick 1- -rot
140	hline		\ Draw bottom horiz line
141	2dup at-xy lt_el @ xemit	\ Draw left-top corner
142	2dup 4 pick + at-xy lb_el @ xemit	\ Draw left bottom corner
143	2dup swap 5 pick + swap at-xy rt_el @ xemit	\ Draw right top corner
144	2 pick + swap 3 pick + swap at-xy rb_el @ xemit
145	2drop
146;
147
148f_single
149fill_none fill !
150
151only forth definitions
152