ivanizag / iz-cpm

Portable CP/M emulation to run CP/M 2.2 binaries for Z80
BSD 3-Clause "New" or "Revised" License
86 stars 11 forks source link

BBC BASIC doesn't save/load programs #18

Closed skx closed 2 months ago

skx commented 2 months ago

[ugly PR coming shortly. Feel free to ignore/close]

The version of BBC BASIC you have in your download script doesn't fully work - specifically SAVE and LOAD both fail:

$ ./target/debug/iz-cpm --disk-a ./software/bbcbasic/
iz-cpm https://github.com/ivanizag/iz-cpm
CP/M 2.2 Emulation
Press ctrl-c ctrl-c Y to return to host

A>bbcbasic
BBC BASIC (Z80) Version 3.00
(C) Copyright R.T.Russell 1987
>10 PRINT "STEVE"
>SAVE "FOO"
CP/M Error
>SAVE "FOO.BBC"
CP/M Error
>*CPM
A>
Press Y to exit iz-cpm. Any other key to continue.

I had the same issue in my emulator, which I worked around but it looks like I'm going to have to go back and fix it properly.

Looking at what happens when a successfull result is achieved we end up with the following series of calls:

>SAVE "FOO"
[[BDOS command 19: F_DELETE(005c)]][[Delete file FOO.BBC]][[=>0000]]
[[BDOS command 22: F_MAKE(005c)]][[Create file FOO.BBC]][[=>0000]]
[[BDOS command 26: F_DMAOFF(3e00)]][[BDOS command 40: F_WRITEZ(005c)]][Write random record 0 into 3e00][[=>0000]]
[[BDOS command 16: F_CLOSE(005c)]][[=>0000]]

If the F_DELETE fails then the F_MAKE is skipped and we get an error. Similarly the rest of the calls - if one of them fails the chain is broken and the save fails.

I eventually worked out that the issue here seems to be that H/L are tested rather than A, and that meant we needed to use your 16-bit return value.

Additionally a failure to delete the file, if it didn't exist, killed things dead too. So I faked an OK result in that in my PR.

ivanizag commented 2 months ago

Fixed updating HL on all BDOS calls and setting H to 0 an calls that have an 8 bit result.

Thank you for the report. I learned a new thing today.