Date : Mon, 25 Feb 2008 12:39:17 +0000 (WET)
From : PCOGHLAN@... (Peter Coghlan)
Subject: BBC FPGA Boots to BASIC... almost...
>
>I've spent the afternoon tracing through the FPGA execution.
>It gets as far as &BFEA, which appears to print an (error?) message (I've
>yet to check the BASIC disassembly). It calls &B50E, which appears to print
>each character in the message. Execution never reaches &BFF6 which is the
>end of the above-mentioned print message routine.
>
BBC BASIC has an ON ERROR directive which is used to trap errors. When it
encounters an ON ERROR in a program, BASIC stores the address of the statement
following the ON ERROR directive in a pair of bytes in memory. If an error
should later occur, a BRK is executed and control is returned to the BASIC
ROM which does a little tidying up and then starts interpreting the BASIC code
at the location stored earlier.
When in command mode or when running a BASIC program with no ON ERROR
directive, BASIC still uses the same mechanism but the pair of bytes mentioned
above are pointed to some BASIC statements held in the ROM and BASIC interprets
these statements to report the error.
The default error reporting action held in the ROM goes something like:
REPORT:IF ERL PRINT " at line ";ERL ELSE PRINT
It may be useful to see if REPORT works from the command line without an
error beforehand. REPORT is supposed to print the last error that occurred
or a copyright message if no error has occurred yet. It doesn't print a
newline after the message. If this works ok, perhaps the execution of BRK
is setting something up for a later failure.
Alternatively it might be useful to type in a short program with an ON ERROR
directive which does not involve REPORT to see if the problem stems from
processing a BRK or from processing REPORT.
>
>Anyway, I noticed a comment that the print routine occupies 40% of the MOS
>ROM - great! :( Execution is getting lost in there somewhere, and I don't
>really have any easy way to track it down on the live FPGA. I can trace
>execution at addresses which only get hit once, but something like the print
>routine is practically impossible to track down on a live system.
>
There is lots of code but only a small part of it is used to print a basic
alphabetic character. Lots more of it deals with control code processing etc.
Unfortunately, there is also a lot of fiddling about to decide whether a
character should go to the screen, printer and/or serial port.
>
>Anyway, if anyone has any more suggestions, I'd be glad to consider them.
>Otherwise I'm not sure what my options are at this point... :(
>
If it is possible to include a debug mode which outputs (maybe to a serial
port or possibly even to the same place as the BBC output) a one-line dissasembly
of the each 6502 instruction being executed and the contents of the 6502
registers
and flags, this can be very useful in tracking down the source of failure.
A large
amount of output will be produced, but it should make it easy to see if the 6502
goes off trying to execute invalid code somewhere or if it goes into a loop.
The one slightly dodgy thing BBC Basic does is on some occasions where it should
really do a JMP &FFEE, it does a JMP (&20E) which amounts to much the same thing.
I can't see any reason to do this except to save a fairly insignificant number of
cycles. If the 6502 emulation is correct, this should not cause any problems but
it may be worth looking into, just in case.
Regards,
Peter.