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
46 create color-palette 100 cells allot
54 0 value openbios-video-addr
55 0 value openbios-video-height
56 0 value openbios-video-width
58 \ The following wordset is called the "defer word interface" of the
59 \ terminal-emulator support package. It gets overloaded by fb1-install
60 \ or fb8-install (initiated by the framebuffer fcode driver)
62 defer draw-character ( char -- )
63 defer reset-screen ( -- )
64 defer toggle-cursor ( -- )
65 defer erase-screen ( -- )
66 defer blink-screen ( -- )
67 defer invert-screen ( -- )
68 defer insert-characters ( n -- )
69 defer delete-characters ( n -- )
70 defer insert-lines ( n -- )
71 defer delete-lines ( n -- )
72 defer draw-logo ( line# addr width height -- )
74 defer fb-emit ( x -- )
76 : depth-bytes ( -- bytes )
81 \ 5.3.6.2 Frame-buffer support routines
84 : default-font ( -- addr width height advance min-char #glyphs )
85 (romfont) (romfont-width) (romfont-height) (romfont-height) 0 100
88 : set-font ( addr width height advance min-char #glyphs -- )
92 font-spacing + to char-height
97 : >font ( char -- addr )
105 \ 5.3.6.3 Display device support
109 \ 5.3.6.3.1 Frame-buffer package interface
112 : is-install ( xt -- )
114 \ Create open and other methods for this display device.
115 \ Methods to be created: open, write, draw-logo, restore
117 1 , \ colon definition
123 s" : write dup >r bounds do i c@ fb-emit loop r> ; " evaluate
124 s" : draw-logo draw-logo ; " evaluate
125 s" : restore reset-screen ; " evaluate
128 : is-remove ( xt -- )
130 \ Create close method for this display device.
132 1 , \ colon definition
138 : is-selftest ( xt -- )
140 \ Create selftest method for this display device.
142 1 , \ colon definition
149 \ 5.3.6.3.2 Generic one-bit frame-buffer support (optional)
152 ." Monochrome framebuffer support is not implemented." cr
156 : fb1-draw-character fb1-nonimplemented ; \ historical
157 : fb1-reset-screen fb1-nonimplemented ;
158 : fb1-toggle-cursor fb1-nonimplemented ;
159 : fb1-erase-screen fb1-nonimplemented ;
160 : fb1-blink-screen fb1-nonimplemented ;
161 : fb1-invert-screen fb1-nonimplemented ;
162 : fb1-insert-characters fb1-nonimplemented ;
163 : fb1-delete-characters fb1-nonimplemented ;
164 : fb1-insert-lines fb1-nonimplemented ;
165 : fb1-delete-lines fb1-nonimplemented ;
166 : fb1-slide-up fb1-nonimplemented ;
167 : fb1-draw-logo fb1-nonimplemented ;
168 : fb1-install fb1-nonimplemented ;
171 \ 5.3.6.3.3 Generic eight-bit frame-buffer support
173 \ bind to low-level C function later
178 : fb8-line2addr ( line -- addr )
180 screen-width * depth-bytes *
182 window-left depth-bytes * +
185 : fb8-curpos2addr ( col line -- addr )
186 char-height * fb8-line2addr
187 swap char-width * depth-bytes * +
190 : fb8-copy-lines ( count from to -- )
193 #columns char-width * depth-bytes *
197 : fb8-clear-lines ( count line -- )
200 #columns char-width *
206 : fb8-draw-character ( char -- )
207 \ erase the current character
209 column# char-width * window-left +
210 line# char-height * window-top +
211 char-width char-height fb8-fillrect
212 \ draw the character:
214 line# char-height * window-top + screen-width * depth-bytes *
215 column# char-width * depth-bytes *
216 window-left depth-bytes * + + frame-buffer-adr +
217 swap char-width char-height font-spacing -
219 foreground-color background-color
226 : fb8-reset-screen ( -- )
228 false to inverse-screen?
229 0 to foreground-color
230 d# 15 to background-color
232 \ override with OpenBIOS defaults
233 fe to background-color
234 0 to foreground-color
237 : fb8-toggle-cursor ( -- )
238 column# char-width * window-left +
239 line# char-height * window-top +
240 char-width char-height font-spacing -
241 foreground-color background-color
245 : fb8-erase-screen ( -- )
251 0 0 screen-width screen-height
255 : fb8-invert-screen ( -- )
256 0 0 screen-width screen-height
257 background-color foreground-color
261 : fb8-blink-screen ( -- )
262 fb8-invert-screen 2000 ms
266 : fb8-insert-characters ( n -- )
267 \ numcopy = ( #columns - column# - n )
268 #columns over - column# -
269 char-width * depth-bytes * ( n numbytescopy )
271 over column# + line# fb8-curpos2addr
272 column# line# fb8-curpos2addr ( n numbytescopy destaddr srcaddr )
275 line-bytes + swap line-bytes + swap
279 column# char-width * window-left + line# char-height * window-top +
280 3 pick char-width * char-height
285 : fb8-delete-characters ( n -- )
286 \ numcopy = ( #columns - column# - n )
287 #columns over - column# -
288 char-width * depth-bytes * ( n numbytescopy )
290 over column# + line# fb8-curpos2addr
291 column# line# fb8-curpos2addr swap ( n numbytescopy destaddr srcaddr )
294 line-bytes + swap line-bytes + swap
298 over #columns swap - char-width * window-left + line# char-height * window-top +
299 3 pick char-width * char-height
304 : fb8-insert-lines ( n -- )
305 \ numcopy = ( #lines - n )
306 #lines over - char-height *
307 over line# char-height *
308 swap char-height * over +
311 char-height * line# char-height *
315 : fb8-delete-lines ( n -- )
316 \ numcopy = ( #lines - ( line# + n )) * char-height
317 #lines over line# + - char-height *
318 over line# + char-height *
322 #lines over - char-height *
323 dup #lines char-height * swap - swap
329 : fb8-draw-logo ( line# addr width height -- )
331 char-height * window-top +
332 screen-width * window-left +
335 \ in-fb-start-adr logo-adr logo-width logo-height
337 fb8-blitmask ( fbaddr mask-addr width height -- )
341 : fb8-install ( width height #columns #lines -- )
343 \ set state variables
349 screen-width #columns char-width * - 2/ to window-left
350 screen-height #lines char-height * - 2/ to window-top
357 my-self to display-ih
359 \ set defer functions to 8bit versions
361 ['] fb8-draw-character to draw-character
362 ['] fb8-toggle-cursor to toggle-cursor
363 ['] fb8-erase-screen to erase-screen
364 ['] fb8-blink-screen to blink-screen
365 ['] fb8-invert-screen to invert-screen
366 ['] fb8-insert-characters to insert-characters
367 ['] fb8-delete-characters to delete-characters
368 ['] fb8-insert-lines to insert-lines
369 ['] fb8-delete-lines to delete-lines
370 ['] fb8-draw-logo to draw-logo
371 ['] fb8-reset-screen to reset-screen
373 \ recommended practice
374 s" iso6429-1983-colors" get-my-property if
379 to foreground-color to background-color
382 10101 ['] color-palette cell+ ff 0 do
383 dup 2 pick i * swap ! cell+
386 \ special background color
387 ffffcc ['] color-palette cell+ fe cells + !
389 \ load palette onto the hardware
390 ['] color-palette cell+ ff 0 do
391 dup @ ff0000 and d# 16 rshift
392 1 pick @ ff00 and d# 8 rshift
395 s" hw-set-color" $find if
403 \ ... but let's override with some better defaults
404 fe to background-color
405 0 to foreground-color
409 \ If we have a startup splash then display it
411 startup-splash 2000 ms