jkotlinski / durexforth

Modern C64 Forth
Other
233 stars 28 forks source link

Create Printer example #252

Closed jkotlinski closed 3 years ago

jkotlinski commented 4 years ago

See discussion in #233

This could be added to the manual, and/or example source code on disk.

rhalkyard commented 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:

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.

burnsauce commented 3 years ago

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.

rhalkyard commented 3 years ago

That's great! A lot more full-featured than my novice attempt too. I'll have a play around with it

jkotlinski commented 3 years ago

I would welcome improvement of openw/closew so that it is compatible with plotters and printers!

Whammo commented 3 years ago

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.

Whammo commented 3 years ago

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.

jkotlinski commented 3 years ago

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.

rhalkyard commented 3 years ago

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?

jkotlinski commented 3 years ago

@rhalkyard https://github.com/jkotlinski/durexforth/pull/308/ Looks good?

jkotlinski commented 3 years ago

Oh, I see you are working on something :) Please proceed.