ExtremeElectronics / RC2040

Z80 CP/M80 emulation of an RC2014 using the RP2040 (PI PICO) processor
GNU General Public License v3.0
40 stars 7 forks source link

Libz80 issue with SBC A,s instruction #27

Open psychotimmy opened 7 months ago

psychotimmy commented 7 months ago

Hi,

I think I've found (and have a tentative resolution for) an issue in the libz80 doArithmetic function. It shows itself when using the Digital Research CBASIC 2.0 compiler through (for example) the square root function. SQR(32) should be 5.65ish - the current code gives an answer of 4.02 ish however.

It looks as if the way that a carry (borrow) in to the function is dealt with is incorrect - I think it should be added to the value before the value is added to the accumulator and the half carry flag set - the current code adds the carry to the accumulator after the half carry flag is set. Zaks pgs 420/421 would seem to indicate the order is important (as does the real world result for SQR(32) and others!). The same version of the CBASIC compiler generates code that executes correctly on an RC2014.

I've written up more detail here: https://z80.timholyoake.uk/the-square-root-of-32-is-not-4-02/ and am happy to supply you with the code / all the other assets I have generated for further testing - or to the fork it's originally from? (Not sure of the etiquette here).

Hope this is of help - I'm enjoying playing with the RC2040!

Tim.