March 22, 2023 Correction: I changed the relative speeds that my emulator runs at because I learned that WinOSI running at 100% is actually 1 MHz not 2 MHz. The CPU vs Disk setting does not factor in.
April 2, 2023 Update: Using Python3.11 and pypy broke access to the GPIO pins necessary to support the hardware keyboard. I ended up switching from the RPi.GPIO library to using pigpio which was easier to install into these new Python environment.
Throughout the build I had the nagging feeling that my emulator was a little sluggish performance wise, but there were so many other things to do I never followed up. Well now that the project was nearing completion it was time to look into this.
I don't have a real Challenger 4P to compare with so how could I determine if my emulator was running slowly? Well I do have another emulator to compare with, WinOSI. One has to assume from the Adjust Emulator Speed dialog seen below, that the author took a lot of care getting the speed that the emulator runs at to be accurate.
So I wrote a small BASIC program.
10 I = 0 20 Print I 30 I = I + 1 40 IF I = 1000 GOTO 60 50 GOTO 20 60 END
Setting WinOSI to run at 1 MHz as shown above I ran this program and timed how long it took to finish. Then I ran the same program on my emulator. The results confirmed that my emulator wasn't quite in up to snuff.
Emulator Runtime Environment Time To Run ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ WinOSI Windows 10/C++ Executable 1:02 Project Raspberry Pi OS/Python 3.9 2:04
In fact it was running at half the speed, about .5 MHz. Yikes!
So what to do. Hitting google, "Speeding up Python" offered a number of suggestions. Many of the suggestion involved making changes to the code to use more efficient Python constructs. OK good to know. I also found out that the folks at python.org had recently issued a new release, Python 3.11, with some good performance enhancements. So I tried that and had some success.
Emulator Runtime Environment Time To Run ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ WinOSI Windows 10/C++ Executable 1:02 Project Raspberry Pi OS/Python 3.11 1:13
That gets me to about .85 MHz. I could almost live with that but I also wanted to try PyPy, an alternative implementation of Python. Pypy has a Just In Time (JIT) compiler that will optimize heavily used parts of your Python code by converting those parts to native code. I suspected that the JIT would be a good fit for the 6502 emulator inside my Challenger 4P which is essentially one big loop, and I was right.
Emulator Runtime Environment Time To Run ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ WinOSI Windows 10/C++ Executable 1:02 Project Raspberry Pi OS/PyPy 7.3.5 0:38
Roughly twice the speed, about 2 MHz, the maximum speed of a Challenger 4P. OK speed problem solved.
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.