Closed jkotlinski closed 3 years ago
I can put something together for this - one of the main things I want to use DurexForth for, is to control my Commodore 1520 plotter, which works very much like a printer.
However, relevant to the discussion in #233, OPENW
is not completely suitable for printer output, for the following reasons:
OPENW
cannot open secondary address 0
OPENW
uses the secondary address as the file number, which prevents opening SA 0 because 0 is not a valid file number. SA 0 is used by both the common MPS-803 printer (for the 'graphics' font), and the 1520 plotter (for drawing text).
The only way to return output to the screen, or a different device or SA, is to CLOSEW
the current file.
This seems to work for real physical devices, but VICE's printer and plotter emulation assumes that a program will hold the device open until it is finished printing. When all addresses are closed, it flushes the current page to output and starts a new one. This behavior is a bit strange, but it makes sense, given how most programs access the printer. However, it makes it impossible to switch addresses or output 'incrementally' to a printer when using OPENW
.
One solution would be to make OPENW
and CLOSEW
use a different file number for SA 0. I have tested this, and it works, but I feel it's a bit of an ugly hack, and still doesn't solve the problem with VICE's printer emulation.
Alternatively, this gist defines a set of words whose behavior is closer to the underlying Kernal calls, plus an example that shows the SA 0 and VICE issues when using OPENW
. Note, too, that OPENW
and CLOSEW
can easily be defined in terms of the new words.
I put together some disk stuff here: https://gist.github.com/burnsauce/5974c33febe552fd703a3ad5824bb5b6
it covers some of the same stuff but includes a higher level API for commands and uses ASM for speed over size.
More to the point, I agree that OPEN
et al should be more compatible in their base implementation.
That's great! A lot more full-featured than my novice attempt too. I'll have a play around with it
I would welcome improvement of openw
/closew
so that it is compatible with plotters and printers!
It's pretty simple to change OPENW to expect the actual device#, sa, and file# on the stack when the file# is zero. It would remain compatible but more useful. Maybe a kludge? As for CLOSEW, I don't understand why it calls CHKOUT, so maybe I should just shut up. :) -edit Perhaps it should be CLRCHN? It seems that doing files with Kernal calls i.e. SYS, is pretty straightforward. I don't mind rolling my own.
Upon further study, OPENW and CLOSEW are only used by V when performing a scratch. Which explains why they're so useful for dos commands. It is again simple enough to replace the OPENW and CLOSEW calls in V with SYS calls within V, and replacing OPENW and CLOSEW with more versatile file calls in disk.asm.
I'm not sure why closew
calls chkout
. It used to have some functionality to read the error channel, but that was changed with commit b3680cf0580cff65874bc9af0c81b07c0e6f587c . Maybe it's a remain of that?
Yeah I'd love to see some better commands in place. I'm not at all good at I/O and it's a miracle things are working at all.
Upon further study, OPENW and CLOSEW are only used by V when performing a scratch. Which explains why they're so useful for dos commands. It is again simple enough to replace the OPENW and CLOSEW calls in V with SYS calls within V, and replacing OPENW and CLOSEW with more versatile file calls in disk.asm.
Depending on how hard we want to try to avoid the 1541 save-with-replace bug, we could just prepend @0:
to the filename instead. This would let us free some more cart space by moving OPENW
and CLOSEW
out of the default dictionary entirely.
This discussion has digressed somewhat from the original issue; should I open a new one to talk about file I/O words, and leave this one to be about printers?
@rhalkyard https://github.com/jkotlinski/durexforth/pull/308/ Looks good?
Oh, I see you are working on something :) Please proceed.
See discussion in #233
This could be added to the manual, and/or example source code on disk.