Shop OBEX P1 Docs P2 Docs Learn Events
ZX Spectrum Emulator — Parallax Forums

ZX Spectrum Emulator

maccamacca Posts: 806
edited 2023-05-23 09:00 in Propeller 2

Hello,

Well, you asked for it and here it is! :)

The P2 ZX Spectrum Emulator.

This is an initial alpha version but already works quite well, and believe it or not, it can also load programs from a tape (see video).

Here is a short video https://youtu.be/zD0FVfs1r6c

The PS/2 keyboard driver emulates the real Spectrum keyboard with the same mappings used by the Fuse Emulator: CTRL=SYMBOL SHIFT, SHIFT=CAPS SHIFT. Backspace and the arrow keys also works by emulating the corresponding key combinations. You need a picture of the keyboard to know where are the symbols.

The video driver is still a bit rough. The VGA and PAL modes seems to work well, the NTSC mode is very waving and I don't know why since it is nearly identical to the ColecoVision driver which seems to not have these problems. Fixed with the alpha2 refactorings.

On the Z80 side, I had to modify the I/O routines to allow the full 16 bit addresses, because the keyboard is readed by setting the row selection on the upper address bits (A15-A8) and reading from the ULA address at $FE.

Another thing to do is implement at least IM2 because some games (I think) uses this mode to disable the ROM interrupt routine while still receiving the frame interrupts. IM2 implemented from aplha2.

Of course it is completely missing the ULA/CPU bus contention hell of a real Spectrum, will see if this cause problems... ULA contention implemented in 2022.03.26 release.

On the games side, I have successfully loaded Manic Miner (haven't dared to try other games yet...) !

Refer to the P2 GitHub repository for the latest code:
https://github.com/maccasoft/P2

Enjoy!

Best regards,
Marco

Comments

  • RaymanRayman Posts: 14,744

    Neat! Think I use to have a Spectrum (or maybe was the ZX81) in high school...

  • pik33pik33 Posts: 2,387

    Now, wow!. :o

  • This is cool. B) The ZX Spectrum was the first computer I have programmed in BASIC. We had Commodore PETs in school. The first computer I owned was a C64. It was more powerful than the ZX Spectrum but you couldn't program the graphics in BASIC unless you had special extensions (Simons' Basic cartridge, for example).

  • pik33pik33 Posts: 2,387

    I didn't manage to compile this. :(

    What is strange, the compiler created the .lst file, but not a binary.

    "/home/pik33/Programy/flexprop/bin/flexspin" -2 -l --tabs=8 -D_BAUD=2000000 -O0    --charset=utf8 -I "/home/pik33/Programy/flexprop/include"  "/home/pik33/Pobrane/spectrum/zx_spectrum.spin2" -DFF_USE_LFN
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2022 Total Spectrum Software Inc.
    Version 5.9.9-HEAD-v5.9.9 Compiled on: Mar  1 2022
    error: unexpected operator ++ in constant expression
    zx_spectrum.spin2
    zx_spectrum.spin2
    Done.
    child process exited abnormally
    Finished at Wed Mar 16 09:24:19 2022
    
  • @pik33 said:
    I didn't manage to compile this. :(

    What is strange, the compiler created the .lst file, but not a binary.

    "/home/pik33/Programy/flexprop/bin/flexspin" -2 -l --tabs=8 -D_BAUD=2000000 -O0    --charset=utf8 -I "/home/pik33/Programy/flexprop/include"  "/home/pik33/Pobrane/spectrum/zx_spectrum.spin2" -DFF_USE_LFN
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2022 Total Spectrum Software Inc.
    Version 5.9.9-HEAD-v5.9.9 Compiled on: Mar  1 2022
    error: unexpected operator ++ in constant expression
    zx_spectrum.spin2
    zx_spectrum.spin2
    Done.
    child process exited abnormally
    Finished at Wed Mar 16 09:24:19 2022
    

    Well, ++ is used only with the ptr registers, I don't know where it sees it in a constant... and seems it doesn't have much clues either since it doesn't shows the line number on the error...

  • pik33pik33 Posts: 2,387

    What did you use to compile the emulator? Maybe there is a bug in my Flexprop version

  • On line 31, there's a wrlong t0, #ptra++, which uhhhhhh, shouldn't compile in anything ever.

  • Beyond that, Propeller Tool implodes on zk_irq_mem being a label in cog assembly mode that would end up at a non-integer address - hub data should go under orgh

  • @pik33 said:
    What did you use to compile the emulator? Maybe there is a bug in my Flexprop version

    I'm using my own of course...

    @Wuerfel_21 said:
    On line 31, there's a wrlong t0, #ptra++, which uhhhhhh, shouldn't compile in anything ever.

    Ah yes, missed that. Guess I need to better the errors checking.

    @Wuerfel_21 said:
    Beyond that, Propeller Tool implodes on zk_irq_mem being a label in cog assembly mode that would end up at a non-integer address - hub data should go under orgh

    zk_irq_mem and zk_nmi_mem can be changed to long, they are never read as a whole. Maybe my compiler is bit more flexible on that matter, not sure how much useful may be...

  • Posted a new alpha2.

    I have changed the video drivers to be more "clean" and optimized without all that wrlut mess, and in the process I have also found why the NTSC driver was behaving so bad (missing a sync element...).

    I have implemented IM2, tried with a couple of games that are using it and seems to work well.
    Also fixed those issue with flexprop and Propeller Tools so you should be able to compile without problems.

    Now I'll look at the timings and bus contention things... this may take a while...

    Best regards,
    Marco

  • Nice! I am going to have to try it out this weekend!

  • Posted a new release with memory and I/O contention implemented (hopefully) correctly, at least for PAL.

    The images below shows the ULA tests I have run to check the implementation:


    ulatest3 tests the memory and I/O contention as well as the floating bus state, the results looks correct.
    This test is very critical since it relyes on the exact interrupt and instruction timings to show the results, a slight difference cause a reset or lock.
    For reference http://www.zxdesign.info/wideMemContention.shtml


    This is the ULA check from a diagnostic ROM, it identifies the ULA as ZX Spectrum 48k and floating bus (also the CPU as NMOS original...).
    The test is not very sophisticated and just shows that the interrupt timing is correct.


    Aquaplane relyes on the contention delay to time the horizon, you can see that the border color is aligned with the screen horizon.
    There are still some glitches with this game that I wasn't yet able to fix (you can see the last line that should be blue and not cyan, and other "flashes" while playing).

    All this for PAL only!
    There isn't much documentation about NTSC versions and all I have are the timing configuration used by the Fuse emulator but when applied the NTSC output is very bad so I have reverted to the original for now.

  • Posted a new release.

    I have fixed the NTSC video driver and made consistent with the informations I found about the real NTSC Spectrum.
    Also, hopefully, fixed all the contended / timing issues. All tests I ran so far (ulatest3, diagnostic rom, TactMeter, fusetest and some games) shows the expected results, consistent with a real Spectrum.
    The glitches with Aquaplane are fixed.
    The VGA mode is identified as NTSC.

    So I think it is done, unless I find some other bug.

    Now, I would like to implement the 128k version (I need an AY-3-8910 emulator...).

  • @macca said:
    Now, I would like to implement the 128k version (I need an AY-3-8910 emulator...).

    Well, if you need it, I can try getting one going. I had wanted to do a YM2608 at some point and it'd be a subcomponent of that, too.

  • @Wuerfel_21 said:

    @macca said:
    Now, I would like to implement the 128k version (I need an AY-3-8910 emulator...).

    Well, if you need it, I can try getting one going. I had wanted to do a YM2608 at some point and it'd be a subcomponent of that, too.

    That would be wonderful, thank you!
    I tried to make a straight port from the P1 version, with some modifications picked from your SN76489 emulator for the pwm and smart pins, but isn't working (or at least nothing is heard from the speakers...), most probably because I haven't yet understood how it should work...

  • maccamacca Posts: 806
    edited 2022-04-03 17:02

    After fighting a nasty bug for the past 3 days, finally I have added the ZX Spectrum 128K emulator to the archive on the first post (it uses @Wuerfel_21 AY-3-8912 emulator).

    It still has problems with some games but should generally work. To be honest I haven't implemented the 128 timing because they are really weird (228 T states per line instead of 224 and 311 lines for PAL instead of 312, my LCD TV screams with these settings so I decided to postpone the implementation). It is more a "retrofitted" 48K with 128K RAM and a sound chip. Implementing the correct timings may require a big change on how the screen rendering is handled, will see if it is worth the effort...

    Enjoy!

  • pik33pik33 Posts: 2,387

    I can see a famous screen (c) 1982 Sinclair Research Ltd - I have now to solder a contraption to connect a PS2 keyboard or make a hack to use my interface instead

  • pik33pik33 Posts: 2,387
    edited 2023-05-23 08:53

    I returned to this emulator - as we have now a proper USB driver, maybe it is possible to replace PS2 one with this?

  • @pik33 said:
    I returned to this emulator - as we have now a proper USB driver, maybe it is possible to replace PS2 one with this?

    This code in the thread may be a bit old.
    The code on my P2 Github repository https://github.com/maccasoft/P2 is updated with the USB driver (not the very latest changes, but supports HUBs).

Sign In or Register to comment.