summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/slof/fs/display.fs
blob: 5bb8797a2adbd6ea031aaed3cb4b234c6a527537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

0 VALUE char-height
0 VALUE char-width
0 VALUE fontbytes

CREATE display-emit-buffer 20 allot

\ \\\\\\\\\\\\\\ Global Data

\ \\\\\\\\\\\\\\ Structure/Implementation Dependent Methods

\ \\\\\\\\\\\\\\ Implementation Independent Methods (Depend on Previous)
\ *
\ *
defer dis-old-emit
' emit behavior to dis-old-emit

: display-write terminal-write ;
: display-emit dup dis-old-emit display-emit-buffer tuck c! 1 terminal-write drop ;

\ \\\\\\\\\\\\\\ Exported Interface:
\ *
\ Generic device methods:
\ *


\ \\\\\\\\\\\\\\ Exported Interface:
\ *
\ IEEE 1275 : display device driver initialization
\ *
: is-install ( 'open -- )
	s" defer vendor-open to vendor-open" eval
	s" : open deadbeef vendor-open dup deadbeef = IF drop true ELSE nip THEN ;" eval
	s" defer write ' display-write to write" eval
	s" : draw-logo ['] draw-logo CATCH IF 2drop 2drop THEN ;" eval
	s" : reset-screen ['] reset-screen CATCH drop ;" eval
;

: is-remove ( 'close -- )
	s" defer close to close" eval
;

: is-selftest ( 'selftest -- )
	s" defer selftest to selftest" eval
;


STRUCT
	cell FIELD font>addr
	cell FIELD font>width
	cell FIELD font>height
	cell FIELD font>advance
	cell FIELD font>min-char
	cell FIELD font>#glyphs
CONSTANT /font

CREATE default-font-ctrblk /font allot default-font-ctrblk
	dup font>addr 0 swap !
	dup font>width 8 swap !
	dup font>height -10 swap !
	dup font>advance 1 swap !
	dup font>min-char 20 swap !
	font>#glyphs 7f swap !

: display-default-font ( str len -- )
   romfs-lookup dup 0= IF drop EXIT THEN
   600 <> IF ." Only support 60x8x16 fonts ! " drop EXIT THEN
   default-font-ctrblk font>addr !
;

s" default-font.bin" display-default-font

\ \\\\\\\\\\\\\\ Implementation Independent Methods (Depend on Previous)
\ *
\ *


\ \\\\\\\\\\\\\\ Exported Interface:
\ *
\ Generic device methods:
\ *
: .scan-lines ( height -- scanlines ) dup 0>= IF 1- ELSE negate THEN ;


\ \\\\\\\\\\\\\\ Exported Interface:
\ *
\ *

: set-font ( addr width height advance min-char #glyphs -- )
   default-font-ctrblk /font + /font 0
   DO
      1 cells - dup >r ! r> 1 cells
   +LOOP drop
   default-font-ctrblk dup font>height @ abs to char-height
   dup font>width @ to char-width font>advance @ to fontbytes
;

: >font ( char -- addr )
   dup default-font-ctrblk dup >r font>min-char @ dup r@ font>#glyphs + within
   IF
      r@ font>min-char @ -
      r@ font>advance @ * r@ font>height @ .scan-lines *
      r> font>addr @ +
   ELSE
      drop r> font>addr @
   THEN
;

: default-font ( -- addr width height advance min-char #glyphs )
    default-font-ctrblk /font 0 DO dup cell+ >r @ r> 1 cells +LOOP drop
;