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-height
55 0 value openbios-video-width
57 \ The following wordset is called the "defer word interface" of the
58 \ terminal-emulator support package. It gets overloaded by fb1-install
59 \ or fb8-install (initiated by the framebuffer fcode driver)
61 defer draw-character ( char -- )
62 defer reset-screen ( -- )
63 defer toggle-cursor ( -- )
64 defer erase-screen ( -- )
65 defer blink-screen ( -- )
66 defer invert-screen ( -- )
67 defer insert-characters ( n -- )
68 defer delete-characters ( n -- )
69 defer insert-lines ( n -- )
70 defer delete-lines ( n -- )
71 defer draw-logo ( line# addr width height -- )
73 defer fb-emit ( x -- )
75 : depth-bytes ( -- bytes )
80 \ 5.3.6.2 Frame-buffer support routines
83 : default-font ( -- addr width height advance min-char #glyphs )
84 (romfont) (romfont-width) (romfont-height) (romfont-height) 0 100
87 : set-font ( addr width height advance min-char #glyphs -- )
91 font-spacing + to char-height
96 : >font ( char -- addr )
104 \ 5.3.6.3 Display device support
108 \ 5.3.6.3.1 Frame-buffer package interface
111 : is-install ( xt -- )
113 \ Create open and other methods for this display device.
114 \ Methods to be created: open, write, draw-logo, restore
116 1 , \ colon definition
122 s" : write dup >r bounds do i c@ fb-emit loop r> ; " evaluate
123 s" : draw-logo draw-logo ; " evaluate
124 s" : restore reset-screen ; " evaluate
127 : is-remove ( xt -- )
129 \ Create close method for this display device.
131 1 , \ colon definition
137 : is-selftest ( xt -- )
139 \ Create selftest method for this display device.
141 1 , \ colon definition
148 \ 5.3.6.3.2 Generic one-bit frame-buffer support (optional)
151 ." Monochrome framebuffer support is not implemented." cr
155 : fb1-draw-character fb1-nonimplemented ; \ historical
156 : fb1-reset-screen fb1-nonimplemented ;
157 : fb1-toggle-cursor fb1-nonimplemented ;
158 : fb1-erase-screen fb1-nonimplemented ;
159 : fb1-blink-screen fb1-nonimplemented ;
160 : fb1-invert-screen fb1-nonimplemented ;
161 : fb1-insert-characters fb1-nonimplemented ;
162 : fb1-delete-characters fb1-nonimplemented ;
163 : fb1-insert-lines fb1-nonimplemented ;
164 : fb1-delete-lines fb1-nonimplemented ;
165 : fb1-slide-up fb1-nonimplemented ;
166 : fb1-draw-logo fb1-nonimplemented ;
167 : fb1-install fb1-nonimplemented ;
170 \ 5.3.6.3.3 Generic eight-bit frame-buffer support
172 \ bind to low-level C function later
177 : fb8-line2addr ( line -- addr )
179 screen-width * depth-bytes *
181 window-left depth-bytes * +
184 : fb8-curpos2addr ( col line -- addr )
185 char-height * fb8-line2addr
186 swap char-width * depth-bytes * +
189 : fb8-copy-lines ( count from to -- )
192 #columns char-width * depth-bytes *
196 : fb8-clear-lines ( count line -- )
199 #columns char-width *
205 : fb8-draw-character ( char -- )
206 \ erase the current character
208 column# char-width * window-left +
209 line# char-height * window-top +
210 char-width char-height fb8-fillrect
211 \ draw the character:
213 line# char-height * window-top + screen-width * depth-bytes *
214 column# char-width * depth-bytes *
215 window-left depth-bytes * + + frame-buffer-adr +
216 swap char-width char-height font-spacing -
218 foreground-color background-color
225 : fb8-reset-screen ( -- )
227 false to inverse-screen?
228 0 to foreground-color
229 d# 15 to background-color
231 \ override with OpenBIOS defaults
232 fe to background-color
233 0 to foreground-color
236 : fb8-toggle-cursor ( -- )
237 column# char-width * window-left +
238 line# char-height * window-top +
239 char-width char-height font-spacing -
240 foreground-color background-color
244 : fb8-erase-screen ( -- )
250 0 0 screen-width screen-height
254 : fb8-invert-screen ( -- )
255 0 0 screen-width screen-height
256 background-color foreground-color
260 : fb8-blink-screen ( -- )
261 fb8-invert-screen 2000 ms
265 : fb8-insert-characters ( n -- )
266 \ numcopy = ( #columns - column# - n )
267 #columns over - column# -
268 char-width * depth-bytes * ( n numbytescopy )
270 over column# + line# fb8-curpos2addr
271 column# line# fb8-curpos2addr ( n numbytescopy destaddr srcaddr )
274 line-bytes + swap line-bytes + swap
278 column# char-width * window-left + line# char-height * window-top +
279 3 pick char-width * char-height
284 : fb8-delete-characters ( n -- )
285 \ numcopy = ( #columns - column# - n )
286 #columns over - column# -
287 char-width * depth-bytes * ( n numbytescopy )
289 over column# + line# fb8-curpos2addr
290 column# line# fb8-curpos2addr swap ( n numbytescopy destaddr srcaddr )
293 line-bytes + swap line-bytes + swap
297 over #columns swap - char-width * window-left + line# char-height * window-top +
298 3 pick char-width * char-height
303 : fb8-insert-lines ( n -- )
304 \ numcopy = ( #lines - n )
305 #lines over - char-height *
306 over line# char-height *
307 swap char-height * over +
310 char-height * line# char-height *
314 : fb8-delete-lines ( n -- )
315 \ numcopy = ( #lines - ( line# + n )) * char-height
316 #lines over line# + - char-height *
317 over line# + char-height *
321 #lines over - char-height *
322 dup #lines char-height * swap - swap
328 : fb8-draw-logo ( line# addr width height -- )
330 char-height * window-top +
331 screen-width * window-left +
334 \ in-fb-start-adr logo-adr logo-width logo-height
336 fb8-blitmask ( fbaddr mask-addr width height -- )
340 : fb8-install ( width height #columns #lines -- )
342 \ set state variables
348 screen-width #columns char-width * - 2/ to window-left
349 screen-height #lines char-height * - 2/ to window-top
356 my-self to display-ih
358 \ set /chosen display property
359 my-self active-package 0 to my-self
360 " /chosen" (find-dev) 0<> if
362 display-ih encode-int " display" property
364 active-package! to my-self
366 \ set defer functions to 8bit versions
368 ['] fb8-draw-character to draw-character
369 ['] fb8-toggle-cursor to toggle-cursor
370 ['] fb8-erase-screen to erase-screen
371 ['] fb8-blink-screen to blink-screen
372 ['] fb8-invert-screen to invert-screen
373 ['] fb8-insert-characters to insert-characters
374 ['] fb8-delete-characters to delete-characters
375 ['] fb8-insert-lines to insert-lines
376 ['] fb8-delete-lines to delete-lines
377 ['] fb8-draw-logo to draw-logo
378 ['] fb8-reset-screen to reset-screen
380 \ recommended practice
381 s" iso6429-1983-colors" get-my-property if
386 to foreground-color to background-color
389 10101 ['] color-palette cell+ ff 0 do
390 dup 2 pick i * swap ! cell+
393 \ special background color
394 ffffcc ['] color-palette cell+ fe cells + !
396 \ load palette onto the hardware
397 ['] color-palette cell+ ff 0 do
398 dup @ ff0000 and d# 16 rshift
399 1 pick @ ff00 and d# 8 rshift
410 \ ... but let's override with some better defaults
411 fe to background-color
412 0 to foreground-color
416 \ If we have a startup splash then display it
418 mol-startup-splash 2000 ms