Skip to content

Commit 2448fa1

Browse files
committed
Update
1 parent 9ea51c1 commit 2448fa1

24 files changed

Lines changed: 6181 additions & 6206 deletions

File tree

CHANGES

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,9 @@ Release 20 (01/01/23):
111111
CHG: Checked font updated from Micah.
112112
CHG: zTemp0 in graphics should be gxzTemp0 ; they are the same but they needn't be.
113113

114-
Release 21 (01/01/23):
114+
Release 21 (01/01/23):
115+
116+
CHG: Remove capital neatening of file names.
117+
CHG: Corrected block write to monitor bytes actually written out.
118+
119+
Release 22 (01/01/23):

TODO

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Progress:
2-
Fix Save.
32
HIMEM
43
LOAD and SAVE memory.
54
- Break check
@@ -22,16 +21,3 @@ Progress:
2221
Ongoing:
2322
Code reading.
2423
Continue documentation.
25-
26-
Sorry for the misunderstanding. It is functioning as designed ... just like POSIX 'write', and for mostly the same reasons (tho if I could do IEC in an interrupt, I could take up to 256 bytes at a time instead of 64). Going into detail below so everyone can learn something:
27-
28-
Kernels don't want to buffer data ... they only want to take what they can immediately hand over to a device driver. This is for several reasons, but the most important one is that kernel memory is typically allocated statically or per-process, and kernels need to treat all processes fairly (not letting one bad actor starve the others). As a consequence, when a user performs a write, kernels have three choices:
29-
1. They can copy the immediately deliverable portion of the data into a small, per-socket buffer,
30-
2. They can block the process until they can deliver the data,
31-
3. They can ask the process not to move or alter the data until signaled.
32-
33-
#3 is hard on everyone, and #2 is a non-starter on an interactive system (even tho y'all are currently blocking yourselves, my games and operating systems won't be doing so). That leaves #1. Most unix-like kernels make the same choice for the same reason. Do a "man 2 read" and a "man 2 write" and you'll see the exact same interface.
34-
35-
Now if you look under the covers of stdio, you're going to find that it just sits in a loop until it completes the read or write (or hits an error). Why doesn't the kernel do it instead? As designed, if you use the POSIX style interface, and you find that a socket is busy, you can do something else until it's no longer busy. This lets you effect multi-tasking within a single process. If you want to give up that ability for convenience (stdio), you're free to do so, but if the kernel blocked until the full write was complete, then everyone would be forced to give up the ability to multi-task.
36-
37-
There's an extra little wrinkle with IEC. Without IEC interrupts, I basically have to do the transfer on the user's thread. This wouldn't be so bad, except IEC really is quite slow, and if I supported transactions of more than ~64 bytes at a time, the transfer could take so long that the kernel could run out of event objects and you would lose keystrokes or mouse events. Thus, I force the driver to take no more than 64 bytes at a time. This isn't a general limit (the kernel can take either 256 or 512 bytes depending on the device), and so it isn't an error to send more than 64 ... the kernel just won't take any more than that at a time for your own protection

bin/basic.rom

1 Byte
Binary file not shown.

modules/_build/_kernel.module

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ _KNLRBGetNextByte:
357357
sta kernel.args.recv.buflen
358358

359359
jsr kernel.ReadData ; Get the data from the kernel (Synchronous call, no error)
360-
lda event.file.data.read ; Return # of bytes read (in A)
360+
lda event.file.data.read ; Return # of bytes read (in A)
361361

362362
clc
363363
rts
@@ -397,52 +397,53 @@ _KGNBExitFail:
397397
;
398398
; Write data at (zTemp0) to Stream A, X bytes.
399399
;
400+
; On error CS ; A = code. On success, CC, A = bytes read.
401+
;
400402
; ************************************************************************************************
401403

402404
Export_KNLWriteBlock:
403-
pha
404405
phx
405406
phy
406407
;
407408
; Already handled OPENED so can write out.
408409
;
409-
sta kernel.args.file.write.stream ; save the stream.
410+
sta kernel.args.file.write.stream ; save the stream.
410411

411-
lda zTemp0 ; save the data location.
412-
sta kernel.args.file.write.buf+0
413-
lda zTemp0+1
414-
sta kernel.args.file.write.buf+1
412+
lda zTemp0 ; save the data location.
413+
sta kernel.args.file.write.buf+0
414+
lda zTemp0+1
415+
sta kernel.args.file.write.buf+1
415416

416-
stx kernel.args.file.write.buflen ; Set the buffer length
417+
stx kernel.args.file.write.buflen ; Set the buffer length
417418

418-
jsr kernel.File.Write ; write it out.
419-
lda #kernel.event.file.ERROR ; in case it fails.
420-
bcs _KWBFailed
419+
jsr kernel.File.Write ; write it out.
420+
lda #kernel.event.file.ERROR ; in case it fails.
421+
bcs _KWBFailed
421422

422423
_KNLWLoop: ; wait for an event.
423-
jsr kernel.Yield
424-
jsr kernel.NextEvent
425-
bcs _KNLWLoop
426-
427-
lda event.type ; various errors.
428-
cmp #kernel.event.file.CLOSED
429-
beq _KWBFailed
430-
cmp #kernel.event.file.ERROR
431-
beq _KWBFailed
432-
cmp #kernel.event.file.EOF
433-
beq _KWBFailed
434-
435-
cmp #kernel.event.file.WROTE ; wait until block write succeeds
436-
bne _KNLWLoop
437-
clc
438-
bra _KWBExit
424+
jsr kernel.Yield
425+
jsr kernel.NextEvent
426+
bcs _KNLWLoop
427+
428+
lda event.type ; various errors.
429+
cmp #kernel.event.file.CLOSED
430+
beq _KWBFailed
431+
cmp #kernel.event.file.ERROR
432+
beq _KWBFailed
433+
cmp #kernel.event.file.EOF
434+
beq _KWBFailed
435+
436+
cmp #kernel.event.file.WROTE ; wait until block write succeeds
437+
bne _KNLWLoop
438+
clc
439+
lda event.file.wrote.wrote ; get bytes written.
440+
bra _KWBExit
439441

440442
_KWBFailed:
441443
sec
442444
_KWBExit:
443445
ply
444446
plx
445-
pla
446447
rts
447448

448449
.send code

modules/kernel/readchar.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ _KNLRBGetNextByte:
121121
sta kernel.args.recv.buflen
122122

123123
jsr kernel.ReadData ; Get the data from the kernel (Synchronous call, no error)
124-
lda event.file.data.read ; Return # of bytes read (in A)
124+
lda event.file.data.read ; Return # of bytes read (in A)
125125

126126
clc
127127
rts

modules/kernel/writeblock.asm

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,53 @@
1717
;
1818
; Write data at (zTemp0) to Stream A, X bytes.
1919
;
20+
; On error CS ; A = code. On success, CC, A = bytes read.
21+
;
2022
; ************************************************************************************************
2123

2224
Export_KNLWriteBlock:
23-
pha
2425
phx
2526
phy
2627
;
2728
; Already handled OPENED so can write out.
2829
;
29-
sta kernel.args.file.write.stream ; save the stream.
30+
sta kernel.args.file.write.stream ; save the stream.
3031

31-
lda zTemp0 ; save the data location.
32-
sta kernel.args.file.write.buf+0
33-
lda zTemp0+1
34-
sta kernel.args.file.write.buf+1
35-
36-
stx kernel.args.file.write.buflen ; Set the buffer length
32+
lda zTemp0 ; save the data location.
33+
sta kernel.args.file.write.buf+0
34+
lda zTemp0+1
35+
sta kernel.args.file.write.buf+1
36+
37+
stx kernel.args.file.write.buflen ; Set the buffer length
3738

38-
jsr kernel.File.Write ; write it out.
39-
lda #kernel.event.file.ERROR ; in case it fails.
40-
bcs _KWBFailed
39+
jsr kernel.File.Write ; write it out.
40+
lda #kernel.event.file.ERROR ; in case it fails.
41+
bcs _KWBFailed
4142

4243
_KNLWLoop: ; wait for an event.
43-
jsr kernel.Yield
44-
jsr kernel.NextEvent
45-
bcs _KNLWLoop
44+
jsr kernel.Yield
45+
jsr kernel.NextEvent
46+
bcs _KNLWLoop
4647

47-
lda event.type ; various errors.
48-
cmp #kernel.event.file.CLOSED
49-
beq _KWBFailed
50-
cmp #kernel.event.file.ERROR
51-
beq _KWBFailed
52-
cmp #kernel.event.file.EOF
53-
beq _KWBFailed
48+
lda event.type ; various errors.
49+
cmp #kernel.event.file.CLOSED
50+
beq _KWBFailed
51+
cmp #kernel.event.file.ERROR
52+
beq _KWBFailed
53+
cmp #kernel.event.file.EOF
54+
beq _KWBFailed
5455

55-
cmp #kernel.event.file.WROTE ; wait until block write succeeds
56-
bne _KNLWLoop
57-
clc
58-
bra _KWBExit
56+
cmp #kernel.event.file.WROTE ; wait until block write succeeds
57+
bne _KNLWLoop
58+
clc
59+
lda event.file.wrote.wrote ; get bytes written.
60+
bra _KWBExit
5961

6062
_KWBFailed:
6163
sec
6264
_KWBExit:
6365
ply
6466
plx
65-
pla
6667
rts
6768

6869
.send code

source/build/02.bin

0 Bytes
Binary file not shown.

source/build/03.bin

0 Bytes
Binary file not shown.

source/build/04.bin

0 Bytes
Binary file not shown.

source/build/basic.rom

1 Byte
Binary file not shown.

0 commit comments

Comments
 (0)