remove host-get and proc-get
This commit is contained in:
parent
da202786ec
commit
8cd1974d14
177
console.txt
177
console.txt
|
@ -4,8 +4,8 @@ CONSOLE DEVICE
|
||||||
0x11 (vector) 0x19 @stderr
|
0x11 (vector) 0x19 @stderr
|
||||||
0x12 stdin 0x1a @proc-put
|
0x12 stdin 0x1a @proc-put
|
||||||
0x13 0x1b
|
0x13 0x1b
|
||||||
0x14 proc-get 0x1c param*
|
0x14 0x1c param*
|
||||||
0x15 host-get 0x1d (param)
|
0x15 0x1d (param)
|
||||||
0x16 0x1e opts
|
0x16 0x1e opts
|
||||||
0x17 type 0x1f @host-put
|
0x17 type 0x1f @host-put
|
||||||
|
|
||||||
|
@ -17,13 +17,8 @@ available. when the vector fires one byte can be read from the read
|
||||||
port (0x12), and its meaning is defined by the type (0x17).
|
port (0x12), and its meaning is defined by the type (0x17).
|
||||||
|
|
||||||
the stdin port (0x12) contains one byte of data to be read. the byte
|
the stdin port (0x12) contains one byte of data to be read. the byte
|
||||||
represents input read from the emulator's stdin.
|
represents input read from one of the following: arguments, stdin,
|
||||||
|
child processes, or host messages. the type port (0x17) says which.
|
||||||
the proc-get port (0x14) contains one byte of data to be read. the byte
|
|
||||||
represents input read from one of the emulator's subprocesses.
|
|
||||||
|
|
||||||
the host-get port (0x15) contains one byte of data to be read. the byte
|
|
||||||
represents part of a response to a host-put (0x1f).
|
|
||||||
|
|
||||||
the type (0x17) field explains how to interpret calls to the console
|
the type (0x17) field explains how to interpret calls to the console
|
||||||
vector (0x10) and where data can be read from:
|
vector (0x10) and where data can be read from:
|
||||||
|
@ -32,21 +27,21 @@ vector (0x10) and where data can be read from:
|
||||||
- 0x02 - argument (stdin)
|
- 0x02 - argument (stdin)
|
||||||
- 0x03 - argument spacer (-)
|
- 0x03 - argument spacer (-)
|
||||||
- 0x04 - argument end (-)
|
- 0x04 - argument end (-)
|
||||||
- 0x05 - host response (host-get)
|
- 0x05 - host response
|
||||||
- 0x06 - host response end (-)
|
- 0x06 - host response end (-)
|
||||||
- 0x07 - stdin end (-)
|
- 0x07 - stdin end (-)
|
||||||
- 0x20 - child 0 sent data (proc-get)
|
- 0x20 - child 0 sent data
|
||||||
- 0x21 - child 1 sent data (proc-get)
|
- 0x21 - child 1 sent data
|
||||||
- 0x22 - child 2 sent data (proc-get)
|
- 0x22 - child 2 sent data
|
||||||
- 0x23 - child 3 sent data (proc-get)
|
- 0x23 - child 3 sent data
|
||||||
- 0x40 - child 0 data end (proc-get)
|
- 0x40 - child 0 data end
|
||||||
- 0x41 - child 1 data end (proc-get)
|
- 0x41 - child 1 data end
|
||||||
- 0x42 - child 2 data end (proc-get)
|
- 0x42 - child 2 data end
|
||||||
- 0x43 - child 3 data end (proc-get)
|
- 0x43 - child 3 data end
|
||||||
- 0x80 - child 0 exited (host-get contains exit code)
|
- 0x80 - child 0 exited (stdin contains exit code)
|
||||||
- 0x81 - child 1 exited (host-get contains exit code)
|
- 0x81 - child 1 exited (stdin contains exit code)
|
||||||
- 0x82 - child 2 exited (host-get contains exit code)
|
- 0x82 - child 2 exited (stdin contains exit code)
|
||||||
- 0x83 - child 3 exited (host-get contains exit code)
|
- 0x83 - child 3 exited (stdin contains exit code)
|
||||||
|
|
||||||
writing a byte to the stdout port (0x18) will send one byte of data to
|
writing a byte to the stdout port (0x18) will send one byte of data to
|
||||||
the emulator's stdout.
|
the emulator's stdout.
|
||||||
|
@ -94,140 +89,4 @@ the host-put port (0x1f) specifies which host action to take:
|
||||||
- 0x10 - getenv: looks up a name (e.g. TERM) in env, responds with value
|
- 0x10 - getenv: looks up a name (e.g. TERM) in env, responds with value
|
||||||
- 0x11 - setenv: reads an assignment (e.g. TERM=vt100), updates env
|
- 0x11 - setenv: reads an assignment (e.g. TERM=vt100), updates env
|
||||||
|
|
||||||
EXAMPLE PROGRAM FRAGMENTS
|
( FRAGMENTS REMOVED UNTIL I VERIFY THEM WORKING )
|
||||||
|
|
||||||
( ----------------------------------- )
|
|
||||||
|
|
||||||
0. The following fragment uses `stty raw -echo` to enable a raw tty:
|
|
||||||
|
|
||||||
|0100 ( -- BRK )
|
|
||||||
run-stty ( ; set up raw mode )
|
|
||||||
... BRK ( ; do other initialization )
|
|
||||||
|
|
||||||
@run-stty ( -- )
|
|
||||||
;stty-cmd .Console/param DEO2 ( ; set up make to run )
|
|
||||||
#00 .Console/opts DEO ( ; use child 0 without pipelines )
|
|
||||||
#01 .Console/host-put DEO JMP2r ( ; run the command now and return )
|
|
||||||
|
|
||||||
@stty-cmd "stty 20 "raw 20 "-echo 00 ( ; buffer containing cmd to run )
|
|
||||||
|
|
||||||
( ----------------------------------- )
|
|
||||||
|
|
||||||
1. The following fragment runs `make` and acts based on its exit code:
|
|
||||||
|
|
||||||
|0100 ( -- BRK )
|
|
||||||
;on-console .Console/vector DEO2 ( ; set up console vector callback )
|
|
||||||
... BRK ( ; do other initialization )
|
|
||||||
|
|
||||||
@on-console ( -- BRK )
|
|
||||||
.Console/type DEI #41 ?on-child-exit ( ; 0x41 signals child 1's exit )
|
|
||||||
... BRK ( ; handle other console input )
|
|
||||||
|
|
||||||
@on-child-exit ( -- BRK )
|
|
||||||
.Console/host-get DEI ( ; read child 1's exit code )
|
|
||||||
?{ display-success-msg BRK } ( ; zero exit code means success )
|
|
||||||
display-failure-msg BRK ( ; non-zero exit code means failure )
|
|
||||||
|
|
||||||
@run-make ( -- )
|
|
||||||
;make-cmd .Console/param DEO2 ( ; set up make to run )
|
|
||||||
#01 .Console/opts DEO ( ; use child without pipelines )
|
|
||||||
#01 .Console/host-put DEO JMP2r ( ; run the command now and return )
|
|
||||||
|
|
||||||
@make-cmd "make $3c ( ; buffer containing cmd to run )
|
|
||||||
|
|
||||||
( ----------------------------------- )
|
|
||||||
|
|
||||||
2. The `mpg123 <path>` commands plays an mp3 from the given path. The
|
|
||||||
following fragment demonstrates part of an mp3 jukebox:
|
|
||||||
|
|
||||||
|0000
|
|
||||||
@running $1
|
|
||||||
|
|
||||||
|0100
|
|
||||||
#01 .running STZ ( ; start running )
|
|
||||||
;on-console .Console/vector DEO2 ( ; set up console vector callback )
|
|
||||||
... BRK ( ; do other initialization and exit )
|
|
||||||
|
|
||||||
@on-console ( -- BRK )
|
|
||||||
.Console/type DEI #04 ?play-jukebox ( ; start jukebox after parsing cmd line )
|
|
||||||
.Console/type DEI #42 ?on-child-exit ( ; 0x42 signals child 2's exit )
|
|
||||||
... BRK ( ; handle other console input )
|
|
||||||
|
|
||||||
@on-child-exit ( -- BRK )
|
|
||||||
.running LDZ ?{ exit } ( ; if we are done, exit )
|
|
||||||
( ; else fall-through to play-jukebox )
|
|
||||||
@play-jukebox ( -- BRK )
|
|
||||||
next-song-path run-mpg123 BRK ( ; play the next song )
|
|
||||||
|
|
||||||
@exit ( -- BRK )
|
|
||||||
#80 .System/halt DEO BRK ( ; exit immediately with code 0 )
|
|
||||||
|
|
||||||
@quit-immediately ( -- BRK )
|
|
||||||
#00 .running STZ ( ; note that we are stopping )
|
|
||||||
#02 .Console/opts DEO ( ; set host action to use child 2 )
|
|
||||||
#03 .Console/host-put BRK ( ; kill child process 2 )
|
|
||||||
( ; this will trigger on-console )
|
|
||||||
( ; and then on-child-exit. )
|
|
||||||
|
|
||||||
@run-mpg123 ( path* -- )
|
|
||||||
;mpg123-cmd/buf scpy ( ; copy path into cmd buffer )
|
|
||||||
;mpg123-cmd .Console/param DEO2 ( ; set up `mpg123 <path>` cmd to run )
|
|
||||||
#02 .Console/opts DEO ( ; use child 2 without pipelines )
|
|
||||||
#01 .Console/host-put DEO JMP2r ( ; start playing mp3 now and return )
|
|
||||||
|
|
||||||
@mpg123-cmd "mpg123 20 &buf $100
|
|
||||||
|
|
||||||
@next-song-path ( -- path* ) ... JMP2r ( ; load the next song's path )
|
|
||||||
|
|
||||||
@scpy ( s* dest* -- ) ... JMP2r ( ; copy string, including null, to dest )
|
|
||||||
|
|
||||||
( ----------------------------------- )
|
|
||||||
|
|
||||||
3. The `ispell -a` command accepts a line. It prints "*\n\n" if the input
|
|
||||||
is a correctly-spelled word; otherwise it prints "<some other text>\n\n".
|
|
||||||
|
|
||||||
The following fragment uses `ispell -a` to implement a basic spell checker:
|
|
||||||
|
|
||||||
|0000
|
|
||||||
@spelled-ok? $1 ( ; was the last word spelled ok? )
|
|
||||||
@resume $2 ( ; if set should have effect ` -- BRK` )
|
|
||||||
|
|
||||||
|0100 ( -- BRK )
|
|
||||||
init-ispell ( ; set up ispell child process )
|
|
||||||
;on-ispell-init .Console/vector DEO2 ( ; set up console vector callback )
|
|
||||||
... BRK ( ; do other initialization )
|
|
||||||
|
|
||||||
@init-ispell ( -- )
|
|
||||||
;ispell-cmd .Console/param DEO2 ( ; set up `ispell -a` to run )
|
|
||||||
#61 .Console/opts DEO ( ; child 1: write to stdin, read from stdout )
|
|
||||||
#01 .Console/host-put DEO JMP2r ( ; run the command now and return )
|
|
||||||
|
|
||||||
@ispell-cmd "ispell 20 "-a 00 ( ; "ispell -a" )
|
|
||||||
|
|
||||||
@on-ispell-init ( -- BRK )
|
|
||||||
.Console/type DEI #81 EQU ?{ BRK } ( ; 0x81 signals input from child 1 )
|
|
||||||
.Console/proc-get #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
|
|
||||||
;on-ispell-ready .Console/vector DEO2 ( ; finished banner, checker is ready )
|
|
||||||
|
|
||||||
@on-ispell-ready ( -- BRK )
|
|
||||||
.Console/type DEI #81 EQU ?{ BRK } ( ; 0x81 signals input from child 1 )
|
|
||||||
.Console/proc-get LIT "* EQU ( ; line starting with "*" means ok )
|
|
||||||
.spelled-ok STZ ( ; store spelling result )
|
|
||||||
#00 ,on-spell-drain/done STR ( ; drain two lines )
|
|
||||||
;on-ispell-drain .Console/vector DEO2 ( ; ignore rest of line )
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@on-spell-drain ( -- BRK )
|
|
||||||
.Console/type DEI #81 EQU ?{ BRK } ( ; 0x81 signals input from child 1 )
|
|
||||||
.Console/proc-get #0a EQU ?{ BRK } ( ; skip ispell's outupt )
|
|
||||||
LIT [ &done $1 ] ?{ ( ; is this the second newline? )
|
|
||||||
#01 ,on-spell-drain/done STR BRK ( ; no, but next one will be. )
|
|
||||||
}
|
|
||||||
;on-ispell-ready .Console/vector DEO2 ( ; drain finished, checker is ready )
|
|
||||||
!resume ( ; resume whatever we wanted to do after checking )
|
|
||||||
|
|
||||||
@check-spelling ( word* continue* -- )
|
|
||||||
#01 .Console/opts DEO ( ; act on child 1 )
|
|
||||||
.resume STZ2 ( ; write continuation to resume )
|
|
||||||
&loop LDAk ?{ POP2 JMP2r } ( ; when we read \0 we are done )
|
|
||||||
LDAk .Console/proc-put DEO INC2 !&loop ( ; send byte to child 1 and loop )
|
|
||||||
|
|
|
@ -301,12 +301,12 @@ console_monitor(Uxn *u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO ignore port
|
||||||
int
|
int
|
||||||
console_input(Uxn *u, int port, char c, int type)
|
console_input(Uxn *u, int port, char c, int type)
|
||||||
{
|
{
|
||||||
Uint8 *d = &u->dev[0x10];
|
Uint8 *d = &u->dev[0x10];
|
||||||
d[0x2] = d[0x4] = d[0x5] = 0;
|
d[0x2] = c;
|
||||||
d[port] = c;
|
|
||||||
d[0x7] = type;
|
d[0x7] = type;
|
||||||
return uxn_eval(u, PEEK2(d));
|
return uxn_eval(u, PEEK2(d));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
( kind of brittle in the same ways as `ispell -a` on raw input )
|
( kind of brittle in the same ways as `ispell -a` on raw input )
|
||||||
|
|
||||||
|10 @Console [
|
|10 @Console [
|
||||||
&vector $2 &stdin $1 &pad1 $1 &proc-get $1 &host-get $1 &pad2 $1 &type $1
|
&vector $2 &stdin $1 &pad1 $4 &type $1
|
||||||
&stdout $1 &stderr $1 &proc-put $1 &pad3 $1 ¶m $2 &opts $1 &host-put $1
|
&stdout $1 &stderr $1 &proc-put $1 &pad2 $1 ¶m $2 &opts $1 &host-put $1
|
||||||
]
|
]
|
||||||
|
|
||||||
|0000
|
|0000
|
||||||
|
@ -40,8 +40,8 @@
|
||||||
|
|
||||||
@on-ispell-input ( -> BRK )
|
@on-ispell-input ( -> BRK )
|
||||||
.ready LDZ ?{ !on-console-init } ( ; if not ready, parse ispell banner )
|
.ready LDZ ?{ !on-console-init } ( ; if not ready, parse ispell banner )
|
||||||
.Console/proc-get DEI LIT "* EQU ( ; line starting with "*" means ok )
|
.Console/stdin DEI LIT "* EQU ( ; line starting with "*" means ok )
|
||||||
.Console/proc-get DEI LIT "+ EQU ORA ( ; line starting with "+" means ok too )
|
.Console/stdin DEI LIT "+ EQU ORA ( ; line starting with "+" means ok too )
|
||||||
.correct STZ ( ; store spelling result )
|
.correct STZ ( ; store spelling result )
|
||||||
#20 print ( ; print a space )
|
#20 print ( ; print a space )
|
||||||
LIT "0 .correct LDZ ADD println ( ; print 1 if ok, 0 otherwise )
|
LIT "0 .correct LDZ ADD println ( ; print 1 if ok, 0 otherwise )
|
||||||
|
@ -50,13 +50,13 @@
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@on-console-init ( -- BRK )
|
@on-console-init ( -- BRK )
|
||||||
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
|
.Console/stdin DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
|
||||||
#01 .ready STZ ( ; after newline we are ready )
|
#01 .ready STZ ( ; after newline we are ready )
|
||||||
LIT "> print BRK ( ; print simple prompt and return )
|
LIT "> print BRK ( ; print simple prompt and return )
|
||||||
|
|
||||||
@on-ispell-drain ( -> BRK )
|
@on-ispell-drain ( -> BRK )
|
||||||
.Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 )
|
.Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 )
|
||||||
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt )
|
.Console/stdin DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt )
|
||||||
LIT &done $1 ?{ #01 ,&done STR BRK } ( ; only exit if second newline )
|
LIT &done $1 ?{ #01 ,&done STR BRK } ( ; only exit if second newline )
|
||||||
;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready )
|
;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready )
|
||||||
word-reset LIT "> print BRK ( ; reset buffer, print prompt, return )
|
word-reset LIT "> print BRK ( ; reset buffer, print prompt, return )
|
||||||
|
|
Loading…
Reference in New Issue