Browse code

Extended Console to write to FD 2-8 (most useful for 2, stderr)

Andrew Alderwick authored on 11/07/2021 16:51:11
Showing 4 changed files
... ...
@@ -13,7 +13,7 @@
13 13
 ( devices )
14 14
 
15 15
 |00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g      $2 &b     $2 ]
16
-|10 @Console    [ &vector $2 &read     $1 &pad    $5 &write $1 ]
16
+|10 @Console    [ &vector $2 &read     $1 &pad    $5 &write $1 &error  $1 ]
17 17
 |20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y      $2 &addr  $2 &color $1 ]
18 18
 |30 @Audio0     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr  $2 &volume $1 &pitch $1 ]
19 19
 |40 @Audio1     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr  $2 &volume $1 &pitch $1 ]
... ...
@@ -1,8 +1,12 @@
1 1
 ( dev/console )
2 2
 
3
+(
4
+	Copies data from stdin to both stdout and stderr.
5
+)
6
+
3 7
 %RTN { JMP2r }
4 8
 
5
-|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 ]
9
+|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
6 10
 
7 11
 ( init )
8 12
 
... ...
@@ -14,7 +18,9 @@ BRK
14 18
 
15 19
 @on-stdin ( -> )
16 20
 
17
-	.Console/read DEI .Console/write DEO
21
+	.Console/read DEI
22
+	DUP .Console/write DEO
23
+	.Console/error DEO
18 24
 
19 25
 BRK
20 26
 
... ...
@@ -45,8 +45,8 @@ printstack(Stack *s)
45 45
 static void
46 46
 console_talk(Device *d, Uint8 b0, Uint8 w)
47 47
 {
48
-	if(w && b0 == 0x8)
49
-		write(1, (char *)&d->dat[0x8], 1);
48
+	if(w && b0 > 0x7)
49
+		write(b0 - 0x7, (char *)&d->dat[b0], 1);
50 50
 }
51 51
 
52 52
 static void
... ...
@@ -238,8 +238,8 @@ system_talk(Device *d, Uint8 b0, Uint8 w)
238 238
 static void
239 239
 console_talk(Device *d, Uint8 b0, Uint8 w)
240 240
 {
241
-	if(w && b0 == 0x8)
242
-		write(1, (char *)&d->dat[0x8], 1);
241
+	if(w && b0 > 0x7)
242
+		write(b0 - 0x7, (char *)&d->dat[b0], 1);
243 243
 }
244 244
 
245 245
 static void