Finally getting around to writing a Raspberry pico-based Sharp MZ-80K emulator.
-
Finally getting around to writing a Raspberry pico-based Sharp MZ-80K emulator.
It should be relatively straightforward - I hope.
I'm not expecting progress to be fast as I'm making sure I properly understand & document each component I write (or incorporate from other projects).
I'm determined to have as little cruft as possible. My aim is to implement a MZ-80K, not every Z80-based computer (or even every Sharp MZ) ever released.
-
It may not look like much (and I guess it isn't), but it shows my Sharp MZ-80K emulator is now able to execute the SP-1002 monitor ROM up to the first input prompt!
I've started to understand how the 8255 works in the context of this machine (it's pretty straightforward), but the next jobs are to implement the graphics generator ROM and hook the pico vga libraries up so I can send output there, rather than to minicom via usb.
-
So, despite what I said about the VGA output being the next job, I've ended up down the rabbit hole of working out how to implement keyboard input for my pico MZ-80K emulator. This job was not helped by the rather non-standard approach to character handling, nor the keyboard layout.
Much rubber ducking later, I think I've finally figured it out and the code I write tomorrow (or whenever) will definitely work properly then ...
-
I finally have some rudimentary keyboard input working on my Sharp MZ-80K emulator.
The screenshot shows my debugging of the initial monitor output, the emulator accepting the LOAD command and then waiting for the tape to be activated by putting out the message v PLAY.
I need to complete the USB keyboard to MZ-80K keyboard map (design decisions need to be made for handling the Sharp's graphical character input) and work out how to best implement the VGA display.
-
Will be slow progress today as I've decided to refactor some parts of what I've already written, plus I'm going to see Despicable Me 4 this afternoon.
-
Refactoring done, keyboard input is good enough for testing. Monitor ROM responds as expected to the half dozen commands it implements.
Onto VGA. Looks like the pico-playground textmode example is a starting point, but boy is it complex, poorly commented & undocumented.
Others have used it - notably the #RC2014 picoterm authors, so I'm think I'm on the right track.
I could try implementing the MZ-80K font for picoterm as a starter for 10 - that might be fun!
-
I started work on the VGA output today. Having failed to decipher the pico-playground examples sufficiently, I decided to work from first principles.
I now have some starter code integrated with the rest of my emulator, generating random black & white pixels on the display.
Progress!
I've also hooked up the MZ-80K's character ROM.
Next - mapping VRAM to the display, but scanvideo_end_scanline_generation & its structure is defeating me at the moment.
Wine time!
-
VGA output success!
Now I need to work out a way of emulating tape input so I can get something more useful than just the monitor working ... like the SP-5025 BASIC tape for example.
-
Kludged a way of putting tape contents into memory. SP-5025 BASIC loads and initialises, but hangs before the READY prompt.
Going back to my real MZ-80K, I note that a beep is issued just before the READY prompt. The 8253 is generating the signals for the beep.
And ... I haven't implemented my 8253 handling for the emulator yet, which is why it hangs!
So that's the next job then ...
-
Tim Holyoakereplied to Tim Holyoake on last edited by
8253 impl. seems about right now. Sorted /vblank & cursor blinking, still need to deal with /vgate. 8255 impl. being fleshed out so cassette tape handling is a little less hacky. I also replaced the GPL licensed z80 core I started with for a MIT licenced one, as I prefer that licence (I'd have stuck with the original core, but it was GPL full-fat rather than LGPL, which would have made more sense as it was just a library). The alternative seems to work just as well.
-
Tim Holyoakereplied to Tim Holyoake on last edited by
Not done very much on the emulator for the last few days. Getting back into the swing of things by debugging my cassette tape handling code ...
-
Made some good progress with the pico #SharpMZ80K emulator this evening. For the first time (after merciless kludging of the 8253 code wot I wrote) I have SP-5025 BASIC up and running - and executing a "hello world" program!
-
Fixed the shift key glitching issue. Implemented more key codes (just SML codes left now - lower case alpha & graphics).
I want to get cassette read to work properly, even though I can bash programs directly into memory (not satisfying for some reason).
Oh, and then getting the SD card to work. The Raspberry Pico example code doesn't work for me, which means I have a bad SD card or a bad pico demo board.
And my 8253 code is driving the MZ-80K's clock backwards!
-
A big effort on 8253 emulation has pared it back to the bare minimum, fixing the time going backwards issue.
Time synchronises with the pico RTC, so I don't think implementing counter 1 (clock rate generator) is needed, beyond returning from any calls to read or write to it (at address E005).
I may be able to do something similar for sound generation at E004 & E008. That will probably make implementing E007 redundant, as there are no other PIT control words used!
-
Cassette tape read emulation now starting to work ... Eventually tracked down my main issue to a |= that should just have been an assignment. Load from SD card rather than hard coding 'tapes' in memory will be the next job, but it may be a few weeks before I get to that, as real life calls!
-
Cassette read is working well enough to load a program after boot, but not well enough to load a BASIC program - they all seem corrupt when listed or run. I'm clearly missing something subtle. But in the meantime, here's a video of the Sharp Invader program running in demo mode
-
The problem with my cassette read wasn't subtle at all, but a horrendous bug in my temporary bodges before I get sd card reading sorted. Doh. Took ages to find! May have been quicker just to write the sd card handling...
-
Emulator is generating the primes below 7500 in just over 13 minutes with all the debug output turned on, so should get close to the 10m12s the real machine takes to do this I hope. Otherwise I will need to optimise some stuff!
-
Ah, no - the real machine is 10m 18s, not 10m 12s. Less optimisation required, which is a good thing.
-
Diagnostics off has saved me a massive 4 seconds. I'm going to overclock the pico I think ...