1 \ tag
: Display device
management
3 \ this
code implements
IEEE 1275-1994 ch
. 5.3.6
5 \
Copyright (C) 2003 Stefan Reinauer
7 \
See the file
"COPYING" for further information about
8 \
the copyright and warranty status
of this
work.
14 \
5.3.6.1 Terminal emulator routines
17 \
The following values
are used
and set
by the terminal emulator
18 \ defined
and described
in 3.8.4.2
19 0 value
line# ( -- line# )
20 0 value
column# ( -- column# )
21 0 value
inverse? ( -- white
-on
-black
? )
22 0 value
inverse-screen
? ( -- black
? )
23 0 value
#lines ( -- rows )
24 0 value
#columns ( -- columns )
26 \
The following values
are used internally
by both
the 1-bit
and the
27 \
8-bit
frame-buffer support
routines.
29 0 value
frame-buffer
-adr
( -- addr
)
30 0 value
screen-height
( -- height
)
31 0 value
screen-width
( -- width
)
32 0 value
window-top
( -- border
-height
)
33 0 value
window-left
( -- border
-width
)
34 0 value
char-height
( -- height
)
35 0 value
char-width
( -- width
)
36 0 value
fontbytes ( -- bytes
)
38 \ these
values are used internally
and do not
represent any
39 \ official
open firmware
words
44 0 value
foreground-color
45 0 value
background-color
48 \
The following wordset
is called
the "defer word interface" of the
49 \
terminal-emulator support
package. It gets overloaded
by fb1
-install
50 \
or fb8
-install
(initiated
by the framebuffer fcode
driver)
52 defer draw
-character
( char -- )
53 defer reset
-screen ( -- )
54 defer toggle
-cursor
( -- )
55 defer erase
-screen ( -- )
56 defer blink
-screen ( -- )
57 defer invert
-screen ( -- )
58 defer insert
-characters
( n
-- )
59 defer delete
-characters
( n
-- )
60 defer insert
-lines
( n
-- )
61 defer delete
-lines
( n
-- )
62 defer draw
-logo
( line# addr width height -- )
64 defer fb
-emit
( x
-- )
67 \
5.3.6.2 Frame-buffer support
routines
70 : default-font ( -- addr width height
advance min
-char #glyphs )
71 \
(romfont
-8x16) 8 10 10 0 100
74 : set
-font ( addr width height
advance min
-char #glyphs -- )
83 : >font ( char -- addr
)
91 \
5.3.6.3 Display device
support
95 \
5.3.6.3.1 Frame-buffer
package interface
98 : is-install
( xt
-- )
100 \
Create open and other methods
for this
display device
.
101 \
Methods to be
created: open, write
, draw
-logo
, restore
103 1 , \ colon definition
107 s" : write dup >r bounds do i c@ fb-emit loop r> ; " evaluate
108 s" : draw-logo draw-logo ; " evaluate
109 s" : restore reset-screen ; " evaluate
112 : is-remove ( xt -- )
114 \ Create close method for this display device.
116 1 , \ colon definition
122 : is-selftest
( xt
-- )
124 \
Create selftest method
for this
display device
.
126 1 , \ colon definition
133 \ 5.3.6.3.2 Generic one-bit frame-buffer support (optional)
136 ." Monochrome framebuffer support is not implemented." cr
140 : fb1-draw-character fb1-nonimplemented ; \ historical
141 : fb1-reset-screen fb1-nonimplemented ;
142 : fb1-toggle-cursor fb1-nonimplemented ;
143 : fb1-erase-screen fb1-nonimplemented ;
144 : fb1-blink-screen fb1-nonimplemented ;
145 : fb1-invert-screen fb1-nonimplemented ;
146 : fb1-insert-characters fb1-nonimplemented ;
147 : fb1-delete-characters fb1-nonimplemented ;
148 : fb1-insert-lines fb1-nonimplemented ;
149 : fb1-delete-lines fb1-nonimplemented ;
150 : fb1-slide-up fb1-nonimplemented ;
151 : fb1-draw-logo fb1-nonimplemented ;
152 : fb1-install fb1-nonimplemented ;
155 \ 5.3.6.3.3 Generic eight-bit frame-buffer support
157 \ The following two functions are unrolled for speed.
160 \ blit 8 continuous pixels described by the 8bit
161 \ value in bitmask8. The most significant bit is
164 \ this function should honour fg and bg colors
166 : fb8-write-mask8 ( bitmask8 faddr -- )
167 over 1 and 0<> over 7 + c!
168 over 2 and 0<> over 6 + c!
169 over 4 and 0<> over 5 + c!
170 over 8 and 0<> over 4 + c!
171 over 10 and 0<> over 3 + c!
172 over 20 and 0<> over 2 + c!
173 over 40 and 0<> over 1 + c!
174 over 80 and 0<> over 0 + c!
178 : fb8-blitmask ( fbaddr mask-addr width height -- )
179 over >r \ save width ( -- R: width )
180 * 3 >> \ fbaddr mask-addr width*height/8
181 bounds \ fbaddr mask-end mask
182 r> 0 2swap \ fbaddr width 0 mask-end mask
183 ?do \ ( fbaddr width l-cnt )
184 2 pick over + \ fbaddr-current
187 ( fbaddr width l-cnt )
189 drop swap screen-width +
192 ( fbaddr width l-cnt )
197 : fb8-line2addr ( line -- addr )
204 : fb8-copy-line ( from to -- )
207 #columns char-width * move
210 : fb8-clear-line ( line -- )
212 #columns char-width *
213 background-color fill
217 : fb8-draw-character ( char -- )
218 \ draw the character:
220 line# char-height * window-top + screen-width *
221 column# char-width * window-left + + frame-buffer-adr +
222 swap char-width char-height
224 \ now advance the position
231 \ FIXME move up screen (and keep position)
240 : fb8-reset-screen ( -- )
242 false to inverse-screen?
243 0 to foreground-color
244 d# 15 to background-color
247 : fb8-toggle-cursor ( -- )
248 line# char-height * window-top + screen-width *
249 column# char-width * window-left + + frame-buffer-adr +
252 dup i + dup c@ invert ff and swap c!
259 : fb8-erase-screen ( -- )
261 screen-height screen-width *
270 : fb8-invert-screen ( -- )
272 screen-height screen-width *
275 foreground-color of background-color endof
276 background-color of foreground-color endof
283 : fb8-blink-screen ( -- )
284 fb8-invert-screen fb8-invert-screen
287 : fb8-insert-characters ( n -- )
290 : fb8-delete-characters ( n -- )
293 : fb8-insert-lines ( n -- )
296 : fb8-delete-lines ( n -- )
297 \ numcopy = ( #lines - ( line# + n )) * char-height
298 #lines over #line + - char-height *
301 dup line# + char-height * i +
302 line# char-height * i +
306 #lines over - char-height *
309 dup i + fb8-clear-line
316 : fb8-draw-logo ( line# addr width height -- )
318 char-height * window-top +
319 screen-width * window-left +
322 \ in-fb-start-adr logo-adr logo-width logo-height
324 fb8-blitmask ( fbaddr mask-addr width height -- )
328 : fb8-install ( width height #columns #lines -- )
330 \ set state variables
336 screen-width #columns char-width * - 2/ to window-left
337 screen-height #lines char-height * - 2/ to window-top
344 \ set defer functions to 8bit versions
346 ['] fb8
-draw
-character to draw
-character
347 ['] fb8-toggle-cursor to toggle-cursor
348 ['] fb8
-erase
-screen to erase
-screen
349 ['] fb8-blink-screen to blink-screen
350 ['] fb8
-invert
-screen to invert
-screen
351 ['] fb8-insert-characters to insert-characters
352 ['] fb8
-delete
-characters
to delete
-characters
353 ['] fb8-insert-lines to insert-lines
354 ['] fb8
-delete
-lines
to delete
-lines
355 ['] fb8-draw-logo to draw-logo
356 ['] fb8
-reset-screen to reset-screen
358 \ recommended practice
359 s
" iso6429-1983-colors" get
-my
-property
if
364 to foreground-color
to background-color