NAME__
NAME__

Reputation: 635

MOS 6502 Emulator Causing Enhanced Basic to Output in Scientific Notation

I've been working on an emulator for the MOS 6502, and I nearly have it fully completed at this point. It has one small problem though. It seems to pass all of the tests that I put it through, but for some reason it causes Enhanced Basic to output everything, including characters, in scientific notation.

Enhanced Basic is only supposed to put numbers into scientific notation if they are > 999999.4375.

Where should I start to look? What emulation issues could cause a response like this from EhBasic? I have no idea where to even start with such a large program, and considering my emulator passes all of the tests I have fed it, I can't exactly find problems with the tests.

Here is a sample output from enhanced basic.

6502 EhBASIC [C]old/[W]arm ?



Memory size ? $C000



4.8383E+04 Bytes free


Enhanced BASIC 2.22


Ready

The 4.8383 should actually be 48383.

I took the liberty to re-write the code and comment out anything that was not required to see this issue. It should be much more readable to anyone now.

To reproduce this, run EhBASIC Cold by pressing C, and for the memory size, enter $C000.

EDIT: To clarify

The Accumulator is memory[memory_size]

Some variables have [0] after them because I took advantage of javaScript Uint8 arrays to have unsigned 8 bit integers, and unsigned 16 bit integers.

Upvotes: 0

Views: 269

Answers (1)

HBP
HBP

Reputation: 16033

This is indeed the bane of all emulator developers. All the tests helpful in locating errors pass, but the large programs fail.

I am assuming that the source code to the Basic is unavailable, otherwise perusing that can at least find the code which performs the check on the value.

I have found that getting an instruction execution trace can help. If you can isolate the region of memory used to display the values you can limit the trace to just that part of memory.

A trace should output the PC, disassemble the instruction to be executed and, show all register contents. It should also indicate in the trace when output occurs - this helps identify what the different blocks of code do.

Traces can be very large and take time to generate, then even more time to analyse. One way of isolating the problem is to run you emulator with trace and a known good emulator outputting an identical trace. When the traces differ you have a good pointer to the source of the problem.

Upvotes: 3

Related Questions