Clock Signal: back again for the Mac and UNIX-ishes

Emulator and emulator development specific topics
Thommy
Posts: 52
Joined: Wed Sep 28, 2011 6:37 pm

Clock Signal: back again for the Mac and UNIX-ishes

Post by Thommy » Mon Mar 05, 2018 9:54 pm

Hi all. I wrote a ZX80/81 emulator back in 2011, of which I am sure any recollection has long ago fallen by the wayside. If you recall it at all, it might be as the emulator that burnt your CPU by simulating and propagating every single bus transition, or it might be because it was a good OS X-centric option.

I failed to keep this forum abreast of what happened next, so: what amounts to a version 2.0 is available. It's a rewrite and, nowadays, a multimachine emulator. Compared to the previous:
  • it retains the original's half-cycle timing precision and full bus communication fidelity;
  • but, it rearranges itself to talk at a higher level: partial machine cycles, not individual signal transitions;
  • it therefore communicates exactly the same quality of information and samples all the correct inputs exactly as well as it ever did, but substantially reduces your CPU's load;
  • it spends some of that saving on a full hardware-level emulation of a CRT. Composite input, flywheel syncs, the lot. Though since neither the ZX80 nor the ZX81 generate a colour burst, the signal isn't filtered all that strongly and there are no false colour artefacts. But it is low-pass filtered a little, because that's what happens in real life.
It builds for two targets: (i) macOS; and (ii) anything UNIXy with SDL 2.x and OpenGL 3.2+.

The full CRT emulation has a potentially-interesting outcome: a new frame is generated every time your computer wants one. Each frame is different, just like it would be if you pointed a high-refresh-rate video camera at a CRT.

This means:
  • no emulator-classic judder as the fiction of pushing a whole frame at a time causes a 50Hz to your display mapping that, if it's 60Hz, just shows every fifth frame twice; and
  • if you're a gaming type who obsesses about latency to the extent of having bought a 120Hz or a 144Hz monitor, this emulator will accordingly benefit. Get a full 120 or 144 distinct frames a second. Have a video latency of only 1/120th or 1/144th of a second.
The macOS version is an idiomatic macOS document-centric application although possibly a little old-school in not having a forced welcome dialogue. So when you launch it, you'll not be presented with anything really. Use File->Open... to open a tape image and a corresponding ZX80 or ZX81 will launch with the media inserted and load it. Though it's not quite smart enough to RUN yet. So work to do. You know what you're doing, I trust you.

Run as many ZX80s and ZX81s as you like at the same time. Put them on various screens. Put them into tabs. Have fun.

The SDL version is primarily intended for launching from the command-line. I expect people to associate it with the appropriate file type — O, P or TZX [EDIT: and CSW] — then just double click to launch the ZX80 or ZX81 software. Like there's no emulator at all. You want to run a piece of classic software so you launch it exactly like any other piece of software. No additional level of indirection as you launch an emulator and navigate.

There are a bunch of other machines supported, all 6502 or Z80s at the minute, and it's in its third year of active development so feedback is likely to be acted upon.

It would also be greatly appreciated.

EDIT: having failed to record any videos lately, here's an animated GIF of the emulated ZX80 that I happen to have posted elsewhere:
Image
That hopefully demonstrates what I'm talking about re: CRT emulation. You'll notice that other things come for free, such as having the proper pixel aspect ratio. And don't worry! Since it is a real emulation of the real electronics, the ZX81 doesn't bounce around. It's not some subjective post hoc effect, it's just the emulated CRT trying to regain synchronisation after the emulated ZX80 introduces an abrupt phase change.

sirmorris
Posts: 2813
Joined: Thu May 08, 2008 5:45 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by sirmorris » Mon Mar 05, 2018 11:07 pm

Welcome back Thommy! I've actually been keeping an eye on your most impressive work for a long while now. I'm often found over at *. and seeing as I like my emulators minimal and potentially seizure-inducing - well there was only one choice really. As a Mac owner I've built from source a few times and tried my best to understand how it works but I value my sanity so I try and limit my examinations to a couple of lines of code per night :lol:

McKlaud
Posts: 142
Joined: Tue Dec 19, 2017 10:02 pm
Location: St Albans, UK

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by McKlaud » Mon Mar 05, 2018 11:15 pm

As OS X user I am glad that this emulator exists :) Nice work.
Claudius
----------

Thommy
Posts: 52
Joined: Wed Sep 28, 2011 6:37 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by Thommy » Mon Mar 05, 2018 11:30 pm

sirmorris wrote:
Mon Mar 05, 2018 11:07 pm
Welcome back Thommy! I've actually been keeping an eye on your most impressive work for a long while now. I'm often found over at *. and seeing as I like my emulators minimal and potentially seizure-inducing - well there was only one choice really. As a Mac owner I've built from source a few times and tried my best to understand how it works but I value my sanity so I try and limit my examinations to a couple of lines of code per night :lol:
In that case I apologise for the relatively fast code churn; the recent addition of dynamic analysis in particular has had quite a seismic effect, not to mention the liberalisation of audio processing before that. Neither of which is ZX80/81-relevant, other than that I really should go back and add ZonX support because it'd be really easy now.

Also I should check out whether any of the SID add-ons every gained traction. I've had my eye off the ball.
McKlaud wrote:
Mon Mar 05, 2018 11:15 pm
As OS X user I am glad that this emulator exists :) Nice work.
Thanks! My obsession with minimalism is a good match for the Mac, I think. No need to set up any file associations manually even on the Mac, and all normal manipulations should work. Double click a tape image if it isn't associated with something else, drag and drop onto the Dock icon, etc.

Oh, and the secret one I always forget: drag and drop a piece of media onto a running machine to insert it into that machine. It doesn't even matter if it's for a different machine as long as it can physically fit. So if you ever wanted to test your ZX81 code for reading Commodore, Oric, MSX or Acorn-format tapes, or any other that you have encoded as CSW or TZX, have fun. There's no inherent coupling between file formats and machines, just an analyser that inspects them for a machine type if it is expected to create a new one.

Thommy
Posts: 52
Joined: Wed Sep 28, 2011 6:37 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by Thommy » Wed Mar 07, 2018 10:55 pm

Quick minor update: as I thought I would quickly be able to do, I've added ZON X support to the emulated ZX81. Binaries and source code available as usual.

It should be cycle perfect, actually internally generating an audio wave at 1.625Mhz and then resampling it. So I'm optimistic of no aliasing or other approximation errors. But, as ever, we'll see.

I'm going to have a bit of a think about Quicksilva support since that obviously requires more selectivity in when it should be enabled but hopefully I'll work something out.

EDIT:
A Youtube video of the emulator in action. It seems that as soon as I start screen recording there is no game that I cannot lose in two minutes or less.

Also: some ZX80 and ZX81 hardware documentation I wrote while producing the emulator. In case that helps add to the sum total.

sirmorris
Posts: 2813
Joined: Thu May 08, 2008 5:45 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by sirmorris » Sat Apr 14, 2018 8:28 am

It looks like something I'm doing in BiggOil upsets Clock Signal. Let me know if there's anything you would like from me if you choose to investigate.

C

Thommy
Posts: 52
Joined: Wed Sep 28, 2011 6:37 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by Thommy » Tue May 01, 2018 4:40 pm

sirmorris wrote:
Sat Apr 14, 2018 8:28 am
It looks like something I'm doing in BiggOil upsets Clock Signal. Let me know if there's anything you would like from me if you choose to investigate.

C
I'll look into as soon as I get a chance; I'm fairly deep in Apple II emulation right now but I'm sure that'll all be tied up in the near future. I'll grab the binary here and check it out. I've ticketed it so that should prevent it falling off the table.

In case it helps to reveal a misapprehension trivially, my redocumentation of the ZX80/81 architecture is almost the only interesting thing in the project's wiki. The emulator attempts to implement exactly that.

EDIT: I see the issue you're talking about; the line counter — the three-bit counter that provides three bits of the index into the character table — is off by one. As per the documentation, my understanding was that "the line counter is reset on any port output". I guess either that's not true (?) or I've made an implementation error. I'll investigate.

Thommy
Posts: 52
Joined: Wed Sep 28, 2011 6:37 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by Thommy » Wed May 02, 2018 3:59 am

Okay, so what I had implemented was the Martin Korth version of the world: exiting vsync resets the counter. I switched to resetting the counter on any port output that occurs while NMIs are disabled. That seems to fix my testing set, though I worry a little about comprehensiveness.

So, from:
Before.png
To:
After.png
EDIT: so that'll be in the next release, which I shall return and announce at the appropriate moment.

sirmorris
Posts: 2813
Joined: Thu May 08, 2008 5:45 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by sirmorris » Wed May 02, 2018 8:00 am

Excellent! If you search the forum for 'hsync reset' there is a lot of discussion about the issue, along with empirical and experimentational data. It might reassure you.

Thommy
Posts: 52
Joined: Wed Sep 28, 2011 6:37 pm

Re: Clock Signal: back again for the Mac and UNIX-ishes

Post by Thommy » Wed May 02, 2018 4:26 pm

I think I'm fine on hsync, I just had the three-bit graphics-indexing line counter reset awry. I guess time will tell whether I'm actually fine and/or whether my line counter is still off.

I have hsync as the forums suggest: on the ZX81 only, incrementing with the CPU clock, wrapping at 207, being reset by INTACK.

I now have the line counter incremented by horizontal sync, reset by any port output that occurs on a ZX80, or on a ZX81 while NMIs are disabled. An out to enable NMIs resets the counter (as NMIs aren't enabled yet), an out to disable NMIs doesn't (as they are).

The distinction in handling based on NMI state is inspired by the Korth document just as resetting the line counter based on vsync was, so I guess we'll see.

EDIT: but as per the asymmetrical image, I seem to have lost my back porch. I consider that minor in an emulated machine when brightness ends up being correct anyway, but might take a look.

Post Reply