Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A serial monitor KERNAL output device #194

Open
dansanderson opened this issue Feb 10, 2025 · 0 comments
Open

A serial monitor KERNAL output device #194

dansanderson opened this issue Feb 10, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@dansanderson
Copy link
Collaborator

dansanderson commented Feb 10, 2025

Problem to solve
MEGA65 machine code programs can call hyppo_serial_monitor_wait_and_write and hyppo_serial_monitor_write to send ASCII characters to the serial monitor, displayed by a connected JTAG/UART serial terminal and the built-in Matrix Mode terminal. It would be useful for BASIC programs to be able to send debugging messages to this as well.

Proposed solution
Reserve device 30 as an output-only device, such that a BASIC program can open an I/O channel to this device and use PRINT# to emit messages. Output would use hyppo_serial_monitor_wait_and_write to send the characters sent to the device.

10 OPEN 14,30
20 XP=0:YP=0:REM PLAYER PROPERTIES
...
1000 PRINT#14,"CURRENT PLAYER POS: X="+XP+" Y="+YP
...

Considerations
Wikipedia lists IEC device numbers from 0 to 31, with well-known reservations for keyboard, screen, datasette, RS-232, printers and plotters, and disk drives, with 31 reserved for command broadcasts to all devices. C64 Wiki implies that, in theory, device numbers 8-30 could be assigned to disk drives, but Wikipedia refers to 16-30 as "unknown." Device 30 is a guess at a device number that we can reserve that won't interfere with common tasks. I'm wary of trying to take printer, plotter, or RAMDisk device IDs, which might be uncommonly used with a MEGA65 but seem more likely than a disk with device 30.

This wouldn't be used for sending commands to the serial debugger, which is not currently offered by Hyppo APIs. Nor is there a way to treat it as an input device. If these were possible in the future, we could use the Secondary Address to establish those connections, e.g. OPEN 14,30,2 : PRINT#14,"F1700 17FF 00" : CLOSE 14 Maybe there are reasons to not do this even if it were an option.

This would mostly be useful for debugging BASIC programs, especially games that take up the full screen. ML programs are best left to write their own routines that call the Hyppo trap directly. (I'm always copy-pasting my routines for printing messages and hexadecimal numbers to all my programs—which is the correct solution in this case. The KERNAL is not in the business of hosting libraries of routines it doesn't itself use. 😅) Implemented as a device like this, ML programs could use KERNAL serial operations to emit debug messages, but it's probably easier to just call Hyppo directly.

I considered not making this a device and just introducing a new DEBUG keyword that behaved like PRINT to the screen. I would want to retain some degree of data formatting, either by assembling a string expression or re-using all of the capabilities of PRINT (with some minor conversions like converting PRINT's use of right-cursor chars to spaces). Treating this like an output device allows it to take advantage of PRINT# as it is currently implemented, without having to instrument outch with some kind of target flag.

@dansanderson dansanderson added new New report, not classified yet enhancement New feature or request and removed new New report, not classified yet labels Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant