jhallen / cpm

Run CP/M commands in Linux/Cygwin with this Z80 / BDOS / ADM-3A emulator.
Other
108 stars 26 forks source link

Modularising the emulator #11

Open algodesigner opened 5 years ago

algodesigner commented 5 years ago

These are a few steps towards modularising the emulator and decoupling the key components, namely: z80, bdos, bios, vm (virtual machine) and subsequently peripherals, terminal emulators, generalised hooks, etc. I made them backward-compatible.

I have encapsulated most of the states into the respective classes. vm will be shortly separated from main.c. The naming convention is mostly preserved, the class method prefixes along with constructors and destructors have been added.

It is worth spending some time on the initial set of unit tests when the model stabilises.

The CPU fails ZEXALL. There are more compliant implementations out there. It appears to be easier to replace it than incrementally fixing it. I could write a new one, but that might take a little bit longer.

It has the remaining dependencies on vm class:

vm_read_mem
vm_write_mem
vm_haltcpu
vm_input
vm_output
vm_undefinstr

We can have a single pure virtual class (well, a table of of function pointers for those hooks) or hide them and provide binding methods, e.g. z80_set_memory_man, z80_set_io, z80_set_inst_brk.

Functionally, bdos needs some work and tidying up, but most of the hard work has been done. (The proposed change set contains an intermittent fix of BDOS 33 resulting in an endless loop in GEN80 with the files sizes == 128 bytes)

I fully understand that these changes might come across as too radical and deviate from your vision on how the emulator should evolve, but if you are interested, please let me know.

algodesigner commented 5 years ago

I have decoupled z80 and added the binding methods for:

proc_halt_cpu
proc_undefinstr

io_input
io_output

mem_read
mem_write