1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 $variable
"(STDTTY-EMIT-COL)" 0
15 code: (STDTTY-XEMIT) ( ch -- )
20 ld ebx
,[pfa
"stdout-fd"]
34 code: (STDTTY-XTYPE) ( addr length -- )
35 ;; positive length is guaranteed by the caller
, but
...
44 ld ebx
,[pfa
"stdout-fd"]
63 ;; returns
-1 on EOF
, or
[0..255]
64 code: (STDTTY-GETCH) ( -- ch )
71 ld ebx
,[pfa
"stdin-fd"]
87 : (STDTTY
-RESET
-EMIT
-COL
) ( -- ) (stdtty
-emit
-col
) 0! ;
89 : (STDTTY
-EMIT
-FIX
-COL
) ( ch
-- ch
)
91 8 of
(stdtty
-emit
-col
) @
1- 0 max
(stdtty
-emit
-col
) ! endof
92 9 of
(stdtty
-emit
-col
) @
7 or
1+ (stdtty
-emit
-col
) ! endof
93 10 of
(stdtty
-reset
-emit
-col
) endof
94 13 of
(stdtty
-reset
-emit
-col
) endof
96 otherwise bl
>= (stdtty
-emit
-col
) +! ;; FIXME
: assumes that `true` is
1
100 : (STDTTY
-BELL
) ( -- ) 7 (stdtty
-xemit
) ; (hidden
)
101 : (STDTTY
-EMIT
) ( ch
-- ) (stdtty
-emit
-fix
-col
) (stdtty
-xemit
) ; (hidden
)
102 : (STDTTY
-CR
) ( -- ) (stdtty
-reset
-emit
-col
) nl
(stdtty
-xemit
) ; (hidden
)
103 : (STDTTY
-ENDCR
) ( -- ) (stdtty
-emit
-col
) @
if (stdtty
-cr
) endif ; (hidden
)
104 : (STDTTY
-?ENDCR
) ( -- flag
) (stdtty
-emit
-col
) @
0<> ; (hidden
)
106 : (STDTTY
-TYPE
) ( addr length
-- )
107 ;; positive length is guaranteed by the caller
, but
...
109 2dup bounds
do i c@
(stdtty
-emit
-fix
-col
) drop loop
115 : (STDTTY
-KEY?
) ( -- flag
)
116 os
:#pollfd alloca
>r
0
118 drop stdin
-fd r@ os
:pollfd
.fd
!
119 os
:poll
-in r@ os
:pollfd
.events
! ;; this also clears revents
120 r@
1 0 os
:poll dup
-4 <>
122 0> rdrop
>r os
:#pollfd dealloca r
>