1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;;$uservar
"XEMIT" ua_ofs_xemit
0
10 $uservar
"(EMIT)" ua_ofs_emit cfa
"(STDTTY-EMIT)"
13 ;; this doesn
't count columns
14 $uservar "(XEMIT)" ua_ofs_xemit cfa "(STDTTY-XEMIT)"
17 $uservar "(TYPE)" ua_ofs_emit_type cfa "(STDTTY-TYPE)"
20 ;; this doesn't count columns
21 $uservar
"(XTYPE)" ua_ofs_emit_xtype cfa
"(STDTTY-XTYPE)"
24 $uservar
"(CR)" ua_ofs_emit_cr cfa
"(STDTTY-CR)"
27 $uservar
"(BELL)" ua_ofs_emit_bell cfa
"(STDTTY-BELL)"
30 $uservar
"(ENDCR)" ua_ofs_emit_endcr cfa
"(STDTTY-ENDCR)"
33 ;; should
"ENDCR" do "CR"?
34 $uservar
"(?ENDCR)" ua_ofs_emit_isendcr cfa
"(STDTTY-?ENDCR)"
37 $uservar
"(RESET-EMIT-COL)" ua_ofs_emit_resetcol cfa
"(STDTTY-RESET-EMIT-COL)"
40 $uservar
"(KEY)" ua_ofs_emit_key cfa
"(STDTTY-GETCH)"
43 $uservar
"(KEY?)" ua_ofs_emit_iskey cfa
"(STDTTY-KEY?)"
46 $uservar
"(EKEY)" ua_ofs_emit_ekey
0
49 $uservar
"(EKEY?)" ua_ofs_emit_isekey
0
53 : emit
( ch
-- ) (emit
) @execute
-tail
;
54 : xemit
( ch
-- ) (xemit
) @execute
-tail
;
55 : type
( addr count
-- ) (type
) @execute
-tail
;
56 : xtype
( addr count
-- ) (xtype
) @execute
-tail
;
57 : cr
( -- ) (cr
) @execute
-tail
;
58 : bell
( -- ) (bell
) @execute
-tail
;
59 : endcr
( -- ) (endcr
) @execute
-tail
;
60 : ?endcr
( -- flag
) (?endcr
) @execute
-tail
;
61 : reset
-emitcol
( -- ) (reset
-emit
-col
) @execute
-tail
;
62 : key
( -- key
) (key
) @execute
-tail
;
63 : key?
( -- flag
) (key?
) @ dup
if execute
-tail
endif ;
64 : ekey
( -- key
) (ekey
) @ ?dup
if execute
-tail
else key
endif ;
65 : ekey?
( -- flag
) (ekey?
) @ ?dup
if execute
-tail
else key?
endif ;
68 $uservar
"(SAFE-EMIT-HIGH-ASCII?)" ua_ofs_safe_emit_highascii
1
70 : (safe
-for-emit
) ( ch
-- ch true
// 63 false
)
72 dup bl
< if ;; < 32: allow tab
, cr
, lf
73 dup
9 = over nl
= or over
13 = or ?dup ifnot drop
[char
] ? false
endif
75 dup
(safe
-emit
-high
-ascii?
) @
if 127 0xa0 within
else 127 >= endif
76 if drop
[char
] ? false
else true
endif
80 : safe
-emit
( ch
-- ) (safe
-for-emit
) drop emit
;
81 : safe
-emit
-printable
( ch
-- ) (safe
-for-emit
) drop dup bl
< if drop
[char
] ?
endif emit
;
82 : safe
-emit
-xdump
( ch
-- ) (safe
-for-emit
) if dup bl
<= if drop
[char
] . endif else drop
[char
] . endif emit
;
85 : type
-with
( addr length emitcfa
-- ) over
+if nrot bounds
do i c@ over execute loop
else 2drop
endif drop
;
87 \
: type
( addr length
-- ) ['] emit type-with ;
89 : safe-type ( addr length -- ) ['] safe
-emit type
-with
;
90 : safe
-type
-printable
( addr length
-- ) ['] safe-emit-printable type-with ;
92 : space ( -- ) bl emit ;
93 : spaces ( n -- ) for space endfor ;
96 : type-asciiz ( addr -- ) zcount type ;
97 : safe-type-asciiz ( addr -- ) zcount safe-type ;
98 : safe-type-printable-asciiz ( addr -- ) zcount safe-type-printable ;
101 : dump ( addr count -- )
102 endcr begin dup +while
103 over .hex8 [char] : emit
104 2dup 8 for space dup +if over c@ .hex2 else 2 spaces endif /char endfor space
105 8 for space dup +if over c@ .hex2 else 2 spaces endif /char endfor 2 spaces
106 2drop 2dup 8 for dup +if over c@ safe-emit-xdump else space endif /char endfor space
107 8 for dup +if over c@ safe-emit-xdump else space endif /char endfor
114 r@ ccount type r> ccount + 3 or 1+ >r
115 ; (hidden) (arg-c1strz)