fruit-bat / pico-zxspectrum

ZX Spectrum for Raspberry Pico Pi RP2040
453 stars 48 forks source link

Add MURMULATOR platform & Fix I/O #76

Closed javavi closed 1 year ago

javavi commented 1 year ago

Added MURMULATOR platform (HDMI & VGA variant) https://t.me/ZX_MURMULATOR nMOS Zilog Z80 processor emulation enabled, as in the original Sinclair ZX-Spectrum Fix W/R IO port (games that didn't work started working) Fixed envelope shapes AY Add AY STEREO mode & Speeker Volume control . . .

fruit-bat commented 1 year ago

This looks great. I need to check it still works with the other targets. Unfortunately, I am quite unwell at the moment, so bear with me. Just wanted you to know that the pull request is appreciated.

javavi commented 1 year ago

I hope you'll get better soon! We are following the development of this project with great interest and have some ideas for improvement.

вс, 21 мая 2023 г. в 19:05, fruit-bat @.***>:

This looks great. I need to check it still works with the other targets. Unfortunately, I am quite unwell at the moment, so bear with me. Just wanted you to know that the pull request is appreciated.

— Reply to this email directly, view it on GitHub https://github.com/fruit-bat/pico-zxspectrum/pull/76#issuecomment-1556214899, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJPRDGIHYAT2BDFRTJDFITXHI4NHANCNFSM6AAAAAAYJM6CKQ . You are receiving this because you authored the thread.Message ID: @.***>

javavi commented 1 year ago

Thank you for your attention to my request! I am building a project on Pico SDC Toolchai on Windows 10.

There are a number of issues that I am currently working on and need your advice.

пн, 29 мая 2023 г. в 14:46, fruit-bat @.***>:

@.**** commented on this pull request.

I've added some review comments. Hopefully, you are happy to action them. Let me know if you are having any problems.

In CMakeLists.txt https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209149757 :

@@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.12) +#cmake_policy(VERSION 3.12) +cmake_policy(SET CMP0115 OLD)

Please comment the code to explain your build environment. I build on a Raspberry PI 4 and need the commented out line for cmake to work. Maybe we also need a note in the Readme build instructions to prompt folks to uncomment the appropriate line (which I could add later).

In README.md https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209153658 :

@@ -128,6 +130,12 @@ cp ZxSpectrumBreadboardHdmi4PinAudio.uf2 /media/pi/RPI-RP2/

These targets are discussed in more detail in the following sections.

+### MURMULATOR platform + + + + +

If you have diagrams for the function blocks and don't mind sharing them it would be nice to see them here. Particularly the audio in/out.

In src/ZxSpectrum.cpp https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209206168 :

_ear(false), _earInvert(0), _earDc(0), _buzzer(0) { z80Power(true); _Z80.context = this; +#ifdef MURMULATOR

Don't bother with the #define if you believe this is more correct. Just set it.

In src/ZxSpectrum.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207040 :

@@ -81,7 +81,36 @@ class ZxSpectrum { if (address < 0x4000) return; *(memaddr(address)) = value; }

+ +#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrum.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207407 :

@@ -107,7 +136,42 @@ class ZxSpectrum { return 0xff; } }

  • endif

  • +#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrumAy.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207894 :

@@ -36,9 +36,15 @@ static const uint8_t Envelopes[16][32] = };

// See https://github.com/retrofw/speccy/blob/master/devices/sound/ay.cpp +#ifdef https://github.com/retrofw/speccy/blob/master/devices/sound/ay.cpp+#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrumMenu.cpp https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209208278 :

@@ -340,6 +340,7 @@ ZxSpectrumMenu::ZxSpectrumMenu( };

onPaint([](PicoPen *pen) {

  • pen->printAt(0, 0, false, "ZX Spectrum 48K/128K by fruit-bat on MURMULATOR");

Add missing #ifdef

In src/murmulator/ps2kbd_mrmltr.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209231000 :

@@ -0,0 +1,61 @@ +// You may use, distribute and modify this code under the

This is similar to code in pico-emu-utils ps2kbd.cpp, ps2kbd.h & ps2kbd.pio https://github.com/fruit-bat/pico-emu-utils Please reuse if possible.

In src/murmulator/ps2kbd_mrmltr.pio https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209231689 :

@@ -0,0 +1,23 @@ +; Copyright (C) 1883 Thomas Edison - All Rights Reserved

This is similar to code in pico-emu-utils ps2kbd.cpp, ps2kbd.h & ps2kbd.pio https://github.com/fruit-bat/pico-emu-utils Please reuse if possible.

— Reply to this email directly, view it on GitHub https://github.com/fruit-bat/pico-zxspectrum/pull/76#pullrequestreview-1449237578, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJPRDGZHQNHRSJLKB2EPR3XISECVANCNFSM6AAAAAAYJM6CKQ . You are receiving this because you authored the thread.Message ID: @.***>

javavi commented 1 year ago

Я учту ваши указатия и рекомендации, внесу изменения в код, и в скором времени выполную еще один Pull Request! Благодарю за Ваше внимание к моим запросам!

вт, 30 мая 2023 г. в 21:55, Vadim Jatlov @.***>:

Thank you for your attention to my request! I am building a project on Pico SDC Toolchai on Windows 10.

  • In my environment, the new CMake version 3.25.2 is installed, which displays 8 warnings even before compilation. cmake_policy(SET CMP0115 OLD) hides these warnings.

  • Changes made to ZxSpectrum.h fixed input and output ports, which made it possible to run a paradise of games.

  • Changes made to ZxSpectrumAy.h made it possible to achieve the correct sound.

  • Changes in ZxSpectrumMenu.cpp are more for the amusement of the local audience :)

  • A problem with the PS/2 keyboard driver resulted in the need to replace the library and PIO file. In the MURMULATORA scheme, the DATA bits are not in the same sequence as the library processes them.

There are a number of issues that I am currently working on and need your advice.

  • 60Hz interrupt rate is not native to ZX Spectrum which has a 50Hz interrupt rate Because of this, the music is distorted, plays faster, a number of games crash. I've experimented with different approaches to convert interrupts to 50Hz. Music, gameplay restored to normal, but interrupts are out of sync with frame rate. Created a border buffer to display the border correctly but the border effects are jittery, maybe there is no clear stability in the execution time of processor command cycles. A more correct approach for negotiation is a frame buffer into which the input process writes to line emulation frequency of 50Hz, and the output process at VGA 60Hz. This approach is used by the authors of emulators for MURMULATOR and gives a good result.

пн, 29 мая 2023 г. в 14:46, fruit-bat @.***>:

@.**** commented on this pull request.

I've added some review comments. Hopefully, you are happy to action them. Let me know if you are having any problems.

In CMakeLists.txt https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209149757 :

@@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.12) +#cmake_policy(VERSION 3.12) +cmake_policy(SET CMP0115 OLD)

Please comment the code to explain your build environment. I build on a Raspberry PI 4 and need the commented out line for cmake to work. Maybe we also need a note in the Readme build instructions to prompt folks to uncomment the appropriate line (which I could add later).

In README.md https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209153658 :

@@ -128,6 +130,12 @@ cp ZxSpectrumBreadboardHdmi4PinAudio.uf2 /media/pi/RPI-RP2/

These targets are discussed in more detail in the following sections.

+### MURMULATOR platform + + + + +

If you have diagrams for the function blocks and don't mind sharing them it would be nice to see them here. Particularly the audio in/out.

In src/ZxSpectrum.cpp https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209206168 :

_ear(false), _earInvert(0), _earDc(0), _buzzer(0) { z80Power(true); _Z80.context = this; +#ifdef MURMULATOR

Don't bother with the #define if you believe this is more correct. Just set it.

In src/ZxSpectrum.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207040 :

@@ -81,7 +81,36 @@ class ZxSpectrum { if (address < 0x4000) return; *(memaddr(address)) = value; }

+ +#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrum.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207407 :

@@ -107,7 +136,42 @@ class ZxSpectrum { return 0xff; } }

  • endif

  • +#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrumAy.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207894 :

@@ -36,9 +36,15 @@ static const uint8_t Envelopes[16][32] = };

// See https://github.com/retrofw/speccy/blob/master/devices/sound/ay.cpp +#ifdef https://github.com/retrofw/speccy/blob/master/devices/sound/ay.cpp+#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrumMenu.cpp https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209208278 :

@@ -340,6 +340,7 @@ ZxSpectrumMenu::ZxSpectrumMenu( };

onPaint([](PicoPen *pen) {

  • pen->printAt(0, 0, false, "ZX Spectrum 48K/128K by fruit-bat on MURMULATOR");

Add missing #ifdef

In src/murmulator/ps2kbd_mrmltr.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209231000 :

@@ -0,0 +1,61 @@ +// You may use, distribute and modify this code under the

This is similar to code in pico-emu-utils ps2kbd.cpp, ps2kbd.h & ps2kbd.pio https://github.com/fruit-bat/pico-emu-utils Please reuse if possible.

In src/murmulator/ps2kbd_mrmltr.pio https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209231689 :

@@ -0,0 +1,23 @@ +; Copyright (C) 1883 Thomas Edison - All Rights Reserved

This is similar to code in pico-emu-utils ps2kbd.cpp, ps2kbd.h & ps2kbd.pio https://github.com/fruit-bat/pico-emu-utils Please reuse if possible.

— Reply to this email directly, view it on GitHub https://github.com/fruit-bat/pico-zxspectrum/pull/76#pullrequestreview-1449237578, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJPRDGZHQNHRSJLKB2EPR3XISECVANCNFSM6AAAAAAYJM6CKQ . You are receiving this because you authored the thread.Message ID: @.***>

javavi commented 1 year ago

I will follow your instructions and recommendations, make changes to the code, and soon execute another Pull Request! Thank you for your attention to my requests!

вт, 30 мая 2023 г. в 21:55, Vadim Jatlov @.***>:

Thank you for your attention to my request! I am building a project on Pico SDC Toolchai on Windows 10.

  • In my environment, the new CMake version 3.25.2 is installed, which displays 8 warnings even before compilation. cmake_policy(SET CMP0115 OLD) hides these warnings.

  • Changes made to ZxSpectrum.h fixed input and output ports, which made it possible to run a paradise of games.

  • Changes made to ZxSpectrumAy.h made it possible to achieve the correct sound.

  • Changes in ZxSpectrumMenu.cpp are more for the amusement of the local audience :)

  • A problem with the PS/2 keyboard driver resulted in the need to replace the library and PIO file. In the MURMULATORA scheme, the DATA bits are not in the same sequence as the library processes them.

There are a number of issues that I am currently working on and need your advice.

  • 60Hz interrupt rate is not native to ZX Spectrum which has a 50Hz interrupt rate Because of this, the music is distorted, plays faster, a number of games crash. I've experimented with different approaches to convert interrupts to 50Hz. Music, gameplay restored to normal, but interrupts are out of sync with frame rate. Created a border buffer to display the border correctly but the border effects are jittery, maybe there is no clear stability in the execution time of processor command cycles. A more correct approach for negotiation is a frame buffer into which the input process writes to line emulation frequency of 50Hz, and the output process at VGA 60Hz. This approach is used by the authors of emulators for MURMULATOR and gives a good result.

пн, 29 мая 2023 г. в 14:46, fruit-bat @.***>:

@.**** commented on this pull request.

I've added some review comments. Hopefully, you are happy to action them. Let me know if you are having any problems.

In CMakeLists.txt https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209149757 :

@@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.12) +#cmake_policy(VERSION 3.12) +cmake_policy(SET CMP0115 OLD)

Please comment the code to explain your build environment. I build on a Raspberry PI 4 and need the commented out line for cmake to work. Maybe we also need a note in the Readme build instructions to prompt folks to uncomment the appropriate line (which I could add later).

In README.md https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209153658 :

@@ -128,6 +130,12 @@ cp ZxSpectrumBreadboardHdmi4PinAudio.uf2 /media/pi/RPI-RP2/

These targets are discussed in more detail in the following sections.

+### MURMULATOR platform + + + + +

If you have diagrams for the function blocks and don't mind sharing them it would be nice to see them here. Particularly the audio in/out.

In src/ZxSpectrum.cpp https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209206168 :

_ear(false), _earInvert(0), _earDc(0), _buzzer(0) { z80Power(true); _Z80.context = this; +#ifdef MURMULATOR

Don't bother with the #define if you believe this is more correct. Just set it.

In src/ZxSpectrum.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207040 :

@@ -81,7 +81,36 @@ class ZxSpectrum { if (address < 0x4000) return; *(memaddr(address)) = value; }

+ +#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrum.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207407 :

@@ -107,7 +136,42 @@ class ZxSpectrum { return 0xff; } }

  • endif

  • +#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrumAy.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209207894 :

@@ -36,9 +36,15 @@ static const uint8_t Envelopes[16][32] = };

// See https://github.com/retrofw/speccy/blob/master/devices/sound/ay.cpp +#ifdef https://github.com/retrofw/speccy/blob/master/devices/sound/ay.cpp+#ifdef MURMULATOR

Always use this version if you believe it is more correct.

In src/ZxSpectrumMenu.cpp https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209208278 :

@@ -340,6 +340,7 @@ ZxSpectrumMenu::ZxSpectrumMenu( };

onPaint([](PicoPen *pen) {

  • pen->printAt(0, 0, false, "ZX Spectrum 48K/128K by fruit-bat on MURMULATOR");

Add missing #ifdef

In src/murmulator/ps2kbd_mrmltr.h https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209231000 :

@@ -0,0 +1,61 @@ +// You may use, distribute and modify this code under the

This is similar to code in pico-emu-utils ps2kbd.cpp, ps2kbd.h & ps2kbd.pio https://github.com/fruit-bat/pico-emu-utils Please reuse if possible.

In src/murmulator/ps2kbd_mrmltr.pio https://github.com/fruit-bat/pico-zxspectrum/pull/76#discussion_r1209231689 :

@@ -0,0 +1,23 @@ +; Copyright (C) 1883 Thomas Edison - All Rights Reserved

This is similar to code in pico-emu-utils ps2kbd.cpp, ps2kbd.h & ps2kbd.pio https://github.com/fruit-bat/pico-emu-utils Please reuse if possible.

— Reply to this email directly, view it on GitHub https://github.com/fruit-bat/pico-zxspectrum/pull/76#pullrequestreview-1449237578, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJPRDGZHQNHRSJLKB2EPR3XISECVANCNFSM6AAAAAAYJM6CKQ . You are receiving this because you authored the thread.Message ID: @.***>

fruit-bat commented 1 year ago

You can still make changes to this pull request. No need to make a new one 🙂

fruit-bat commented 1 year ago

I've created a new local branch based on your changes here:

https://github.com/fruit-bat/pico-zxspectrum/tree/feature/murmulator

I have also made a new pull request back to main from this branch.

On the branch I've made some of the changes I suggested in the pull request review. I have added a couple of executables. If you can confirm if they work correctly it would be appreciated.

If you wish to make changes I suggest you get the latest version of my code and switch to the murmulator branch, then pull request changes to my branch. That way we can both work on the code without committing to main :-) At some point I will close this pull request with out merging, as your code will get to main via the branch.

fruit-bat commented 1 year ago

I hope you don't mind but I have raised an issue about the 60Hz refresh rate on your behalf. I was worried the conversation was going to be lost in this pull request.

javavi commented 1 year ago

I have reviewed and agree with the changes you made in the thread https://github.com/fruit-bat/pico-zxspectrum/tree/feature/murmulator The code is built and works correctly on the device. Please look, in my fork, I added the schemes of the MURMULATOR device. The issue of 50Hz CPU interrupt frequency is the cornerstone for proper ZX Spectrum emulation, and I'll be glad if you raise it in your discussions with all developers. Good luck to you! And may the force be with you!

вс, 4 июн. 2023 г. в 21:08, fruit-bat @.***>:

I hope you don't mind but I have raised an issue about the 60Hz refresh rate on your behalf. I was worried the conversation was going to be lost in this pull request.

— Reply to this email directly, view it on GitHub https://github.com/fruit-bat/pico-zxspectrum/pull/76#issuecomment-1575660278, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJPRDC7L7DJAEV2UYOSYG3XJTFI7ANCNFSM6AAAAAAYJM6CKQ . You are receiving this because you authored the thread.Message ID: @.***>

javavi commented 1 year ago

Good health and spirit! In an attempt to make 50Hz interrupts normal for the ZX Spectrum, I tied to the line counter from the process (core1_main). Apparently the get_vga_line() function is only executed for rendered lines and does not execute vertical sync blanking lines. From here, apparently, a jitter of the interrupt period of 24 lines is obtained. Maybe you have some ideas where to get the counter of all lines of the video output process?

ср, 7 июн. 2023 г. в 09:21, fruit-bat @.***>:

Merged #76 https://github.com/fruit-bat/pico-zxspectrum/pull/76 into main.

— Reply to this email directly, view it on GitHub https://github.com/fruit-bat/pico-zxspectrum/pull/76#event-9453959309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJPRDBIEUHLPQC2TRPNQTDXKAMWJANCNFSM6AAAAAAYJM6CKQ . You are receiving this because you authored the thread.Message ID: @.***>