
Clock Signal: A latency-hating emulator of 8- and 16-bit platforms - AnthonBerg
https://github.com/TomHarte/CLK
======
azinman2
So how does this fit into the world of cycle accurate emulation? Seems like
this video approach is new of emulating the decay of a CRT?

The screenshots looked closer to what a CRT looks like but still seemed more
pixelated than I’d expect.

~~~
pjc50
Phosphor-decay simulation isn't new - xscreensaver has had it for ages. What
_is_ new, and slightly mindboggling, is that they're going below "treat
display as pixels and post-process them" and _generating an actual PAL
signal_.

I've not checked to see whether they're keeping that in frequency space or
actually emitting samples at some rate above 4MHz. But it's an interesting
approach.

[https://github.com/TomHarte/CLK/blob/master/Outputs/CRT/CRT....](https://github.com/TomHarte/CLK/blob/master/Outputs/CRT/CRT.cpp)
seems to be well-commented.

~~~
AnthonBerg
Ah! Cool!! If they're generating an actual PAL signal I guess that explains
why the picture in the emulated Macintosh Plus started to jump around like a
bad VHS tape when I set the emulation speed too high for the host to keep up.

Edit: I confirm that the code is really pleasant to work on and understand!
Found this project by pure accident this morning and was able to hack
meaningfully on it right away. Kudos to the developer.

~~~
pjc50
Yes - it looks like the system advances a certain number of scanline elements
per CPU clock, so if you run the CPU clock faster than the video pixel clock
you start missing elements.

------
tempodox
There is a screenshot of Stunt Car Racer in there! How I miss that.

~~~
mrlonglong
That V8! Sublime!

------
mzs
Where is the file that defines the host keyboard to emulated joystick mapping?
Like where is # for colecovision?

~~~
TomHa
Author here; I'm still not sure I've done the right thing here, but for the
ColecoVision you need to type something that is literally a hash, since it's
mapped logically. So e.g. on my keyboard it's shift+3. But if you have a UK
keyboard then you might well have a hash key.

I've probably allowed myself to stretch an early implementation decision too
far here. My approach is usually to run with something good enough until it
stops working and then replace it rather than to try elaborately to plan
ahead; I may have crossed that threshold on joystick input.

~~~
mzs
Thanks for the reply. I really like the authentic video emulation.

The game I tried was Boulder Dash. You need to press # to start I tried every
key on the keyboard. Maybe shift-3 is mapped to # on the second emulated
joystick? If you could point me to the correct file I could hack on it.

Or maybe I need to install a BIOS file somewhere?

~~~
TomHa
There's some ugliness to acknowledge here in the fact that user remapping of
controls is not yet implemented. That being acknowledged.

The easiest place to hack would be
[https://github.com/TomHarte/CLK/blob/master/Machines/ColecoV...](https://github.com/TomHarte/CLK/blob/master/Machines/ColecoVision/ColecoVision.cpp#L36)
— change the Input('#') to declare a key you prefer (e.g. Input('-'), and then
change the corresponding case statement within the block starting on line 62.

If you follow that approach, you'll have modified the ColecoVision so that it
declares a joystick with a minus key rather than a hash key, which it's hard
to imagine the host binding getting confused about.

If you'd prefer to look at the other side of the interface and figure out why
your host isn't posting '#' properly then you'll see the SDL fragment at
[https://github.com/TomHarte/CLK/blob/master/OSBindings/SDL/m...](https://github.com/TomHarte/CLK/blob/master/OSBindings/SDL/main.cpp#L1195)
— it takes the first character of whatever SDL provides as the string input
produced by a key (and always posts only to the first joystick).

You'll see similar logic for the Cocoa port at
[https://github.com/TomHarte/CLK/blob/master/OSBindings/Mac/C...](https://github.com/TomHarte/CLK/blob/master/OSBindings/Mac/Clock%20Signal/Machine/CSMachine.mm#L525)
varying only in that if Cocoa doesn't provide typed characters then it
defaults to the first fire button.

I definitely need to go back and look at this stuff again. As I said, it's
sort of a model that did make sense but has become overloaded. I think I need
to switch to an internal representation of joysticks and joypads that
preserves some information about layout (even if it's just number of rows of
fire buttons, number of fire buttons per row, whether there's a start/select,
whether there's a number pad, etc) and work forwards from there.

~~~
mzs
Thank you for he pointers. I will be camping but will try when I get back. And
don't feel anything but pride for your code.

------
mkesper
Even in full size, the naive images look much better to me.

~~~
mschuster91
Of course they look better, but the simulated CRT images show how the game was
supposed to look like back at the time it was created.

~~~
Narishma
I disagree that they look better. They certainly look sharper but that's not
necessarily what you want.

