How can I redirect BASIC output to file?

By pgimeno

Resident (62)

pgimeno's picture

17-01-2020, 11:50

I need the output of BASIC redirected to a file, in particular the error messages. Is there some way to accomplish that (for example, with RS232)?

Login or register to post comments

By Grauw

Ascended (8704)

Grauw's picture

17-01-2020, 12:18

With RS232 BASIC you can use OPEN along with PRINT to do something along these lines:

PRINT #1,"Test"

I think before this you need to initialise the RS232 with _COMINI, for more info real a manual :).

By pgimeno

Resident (62)

pgimeno's picture

17-01-2020, 16:04

Thanks Grauw, however that doesn't capture error messages emitted by BASIC, e.g. "Syntax error", which is what I would need. When I mentioned RS-232, I was thinking about remotely accessing the MSX with a terminal, in a Linux-like fashion, but I guess that's not possible.

Something Tcl-based would do as well. I'm wondering if it would be possible to add a breakpoint on entry to the printing routine, so that the text to print can be written to a file, similarly (I think) to how the fast tape loading hack works. It would be no problem if such a routine is machine-specific, i.e. tied to a particular BIOS.

The goal is unit testing. I expect certain errors from doing certain things, and I want to verify that they are indeed triggered.

The alternative is taking screen captures and comparing the output images, but that opens its own can of worms: they would need to be compared in decompressed form, and the graphic settings of the emulator would influence the result.

Edit: So as it turns out, what I'm after can be accomplished by setting a breakpoint at address 0018h, and each time it's triggered, saving the byte corresponding to the value of the accumulator to file and continuing. Help with accomplishing this would be welcome.

By pgimeno

Resident (62)

pgimeno's picture

17-01-2020, 18:44

With the help of people from IRC (special thanks to Vampier and BiFi) I've come up with this Tcl script which does exactly what I wanted:

debug set_bp 0x18 {[pc_in_slot 0 0]} {output_txt::out_char}

namespace eval output_txt {
  variable fout [open "output.txt" w]

  proc out_char {} {
    variable fout
    puts -nonewline $fout [format %c [reg A]]

You can execute it with: openmsx -script output.tcl <rest_of_options> (assuming it's saved as output.tcl). It writes to a file named output.txt in the current directory; it's up to you to find out where that is.