Emulating ZX81 with mbed LPC1768

Emulator and emulator development specific topics
gertk
Posts: 14
Joined: Sun Oct 14, 2012 9:09 pm

Emulating ZX81 with mbed LPC1768

Post by gertk »

This is something I have been toying with for some time.
Just checking to see if there is any interest.

The NXP81 (as I named it) is a standard NXP mbed module with a LPC1768 cpu (ARM Cortex M3 with 64k RAM and 512k flash) mounted inside a ZX81 shell.
Some specs:

Mbed LPC1768 with only passive electronics to connect to SDcard, PS2 keyboard, joystick and VGA monitor
ZX81 emulator with VGA (monochrome) output on a 640x480 (double scan) canvas with the ZX81 screen display centered.
16k ram and added UDG ram at 0x3000
PS2 keyboard and original keyboard support.
ZXpand compatible joystick port
Built in Basic manual , Z80 disassembler, Z80 hexdumper with ZX81 characterset and Z80 register check function
SD card storage with FAT LFN support
Fileselector appears if you type LOAD "" but you can load and save programs by name.
Battery backed RTC for correct timestamps on the SDcard

Unoptimized speed is now roughly 4 times original ZX81 speed in 'turbo' mode and no annoying FAST/SLOW switching, display is always present.

Some ideas left to be done:
Subdirectory support from within the fileselector
Clean up the built in manual and add support for graphic images, maybe even add some Z80 reference books (the SDcard is the limit here)
Hex editor and assembler
Audio in/out support for tape loading/saving (possible through the onboard ADC/DAC pins which are already reserved)
AY-3-8910 or YM2149 emulation
Sorted directory (no ram space available for sorting the huge amount of files possible on the card)
ZX printer emulation over the USB serial link to a PC host
Adding the ZX80 rom, maybe even the Spectrum (alas no colour output possible)
Native conversion of ZX81 Basic to ARM for ridiculous fast speeds...
CVBS output when no VGA monitor detected

To get an idea of how it runs check:

http://youtu.be/2Q1VQDkFSwI

and

http://youtu.be/FTVhCxvLi2c

I can post some images/photos later on.
Last edited by gertk on Thu Oct 25, 2012 8:09 pm, edited 1 time in total.
gertk
Posts: 14
Joined: Sun Oct 14, 2012 9:09 pm

Re: Emulating ZX81 with mbed LPC1768

Post by gertk »

Some pictures..
Attachments
PS2, CVBS, audio and power input
PS2, CVBS, audio and power input
small_2012-06-23 18.41.56.jpg (56.32 KiB) Viewed 6509 times
VGA and joystick port fit perfectly in extension port
VGA and joystick port fit perfectly in extension port
small_2012-06-23 18.41.44.jpg (67.42 KiB) Viewed 6509 times
Outside is still standard
Outside is still standard
small_2012-06-23 18.42.17.jpg (70.27 KiB) Viewed 6509 times
gertk
Posts: 14
Joined: Sun Oct 14, 2012 9:09 pm

Re: Emulating ZX81 with mbed LPC1768

Post by gertk »

Some more.. Note this is just a prototype, no commercial intentions so far..
Attachments
The finished backside, SD card slot and mini USB port of the mbed accessible
The finished backside, SD card slot and mini USB port of the mbed accessible
small_2012-06-24 12.46.27.jpg (69.57 KiB) Viewed 6508 times
A view under the hood...
A view under the hood...
small_2012-07-18 22.01.16.jpg (133.85 KiB) Viewed 6509 times
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Emulating ZX81 with mbed LPC1768

Post by Andy Rea »

very nice indeed :-D

this is a software emulation then, with the Z80 core been emulated on the arm chip ?

does it do hi-res as well as udg ?

Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Emulating ZX81 with mbed LPC1768

Post by sirmorris »

Great job!!

You've really worked hard on this and it shows :ugeek:

C
gertk
Posts: 14
Joined: Sun Oct 14, 2012 9:09 pm

Re: Emulating ZX81 with mbed LPC1768

Post by gertk »

Andy Rea wrote:very nice indeed :-D

this is a software emulation then, with the Z80 core been emulated on the arm chip ?

does it do hi-res as well as udg ?

Regards Andy
No hires yet, the Z80 core is emulated in a non cycle perfect way although I am not sure if cycle perfect is really needed for Hires to work, my emulator is running without Z80 interrupts even.
The video timing is based on the refresh of the VGA output on which a flag is set which forces a mbed keyscan which fills in the pseudo IO registers for the keyboard and the ZX81 FRAMES variable is updated (only when not PAUSE-ed) so games which rely on FRAMES for timing run the video output at normal speed (60 Hz refresh that is)

I tried the new games from Revivalstudios and they work beautifully, they also gave me a chance to add the ZXpand joystick emulation.
gertk
Posts: 14
Joined: Sun Oct 14, 2012 9:09 pm

Re: Emulating ZX81 with mbed LPC1768

Post by gertk »

Some pictures from programs running
Attachments
ZX galaxians with UDG
ZX galaxians with UDG
small_2012-07-09 22.22.59.jpg (93.04 KiB) Viewed 6487 times
small_2012-06-18 21.48.44.jpg
small_2012-06-18 21.48.44.jpg (84.13 KiB) Viewed 6487 times
small_2012-06-16 13.50.57.jpg
small_2012-06-16 13.50.57.jpg (64.2 KiB) Viewed 6487 times
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Emulating ZX81 with mbed LPC1768

Post by Andy Rea »

ah, i suspected that you were doing something funky with the display when you mentioned that the display stays updated even in fast :geek: see the problem with hi-res is there are so many different ways to create it, so it would be very difficult to create a catch all software solution for re-creating what would be displayed.

Hence the question, but please don't take it the wrong way, writting a Z80 core of any sort is a great achievment, and your machine is certainly more tidy than my 20Mhz ZX81.... i really like the SD menu, thats pretty slick.

who would have thought... maybe we can have our own ZX-Evo ('81 edition) :mrgreen:

Regards Andy

P.s just in case anyone doesn;t know ZX-Evo is a rather splendid modern ZX Spectrum / pentagon Clone.
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
RetroTechie
Posts: 379
Joined: Tue Nov 01, 2011 12:16 am
Location: Hengelo, NL
Contact:

Re: Emulating ZX81 with mbed LPC1768

Post by RetroTechie »

Very cool project indeed! :ugeek:
gertk
Posts: 14
Joined: Sun Oct 14, 2012 9:09 pm

Re: Emulating ZX81 with mbed LPC1768

Post by gertk »

Andy Rea wrote:ah, i suspected that you were doing something funky with the display when you mentioned that the display stays updated even in fast :geek: see the problem with hi-res is there are so many different ways to create it, so it would be very difficult to create a catch all software solution for re-creating what would be displayed.
Yes I already tried to understand some of the hires routines, basically they end up having some sort of framebuffer.
The ways you can force the ULA to display anything are quite limited so that should not be such a problem.
The VGA (sub)system is a library which I created together with Ivo van Poorten on the mbed platform. He had made a text only 80x25 output to VGA using the I2S port of the mbed. I modified it heavily to get the timing right and make it into a full 640x480 framebuffer. Alas I needed more ram so the output is reduced to 640x240 which for the ZX81 emulation does not matter, only for the other screens I had to revert to 8x8 pixel font instead of the nice 8x16 pixel font.
So basically I have to video memory regions: one for the original ZX81 DFILE and a full bitmap 640x240 which is displayed. Each Vertical refresh the DFILE is read out and converted to the bitmap buffer... I first had a much simpler routine which bit tested the font bitmap and then put 4 pixels in black or white (pixel by pixel) onto the VGA framebuffer and it still could keep up.. This is how fast an ARM @ 100 MHz is.. I am currently fiddling with the RaspberryPi to create a programming environment based on the 'Bare Metal' lessons of the Cambridge University which uses no OS on the Pi, just your own program.
As the Pi runs at 700 MHz and has lots more ram and a dedicated GPU it should just fly, unfortunately the Pi is not as 'open' as the mbed...
Hence the question, but please don't take it the wrong way, writting a Z80 core of any sort is a great achievment, and your machine is certainly more tidy than my 20Mhz ZX81.... i really like the SD menu, thats pretty slick.
Thanks,
The hexdumper and disassembler helped a lot in debugging, the final addition is under F4 which displays the current Z80 register contents. There I could see that all of Revivalstudios programs waited for FRAMES to change which at first did not happen in my emulator (no interrupts)
who would have thought... maybe we can have our own ZX-Evo ('81 edition) :mrgreen:
Regards Andy
P.s just in case anyone doesn;t know ZX-Evo is a rather splendid modern ZX Spectrum / pentagon Clone.
Yes, the ZX-Evo looks really nice but nowadays storage media is shifting more and more to (micro)SD, newer keyboards and mice are USB only, monitors and TV's have HDMI instead of VGA inputs and microprocessors are becoming so ridiculously fast that they can take the place of FGPA's at a fraction of the cost with the added bonus of being much more easily reprogrammed. As I said earlier, my whole emulator at this moment consists of the mbed LPC1768 module and some passive stuff like diodes (ZX keyboard matrix) and resistors (PS2 keyboard and VGA output) The power supply input is 5 Volt at a few hundred milliamps (mbed + PS2 keyboard). The bare ARM CPU costs only a few Euros (note: the mbed module itself is rather expensive at 50 Euros, for prototyping you could also replace it with the LPCxpresso LPC1769 which costs about 25 Euros)
Attachments
hex-dumper under F2
hex-dumper under F2
small_2012-08-11 23.40.07.jpg (99.45 KiB) Viewed 6465 times
dis-assembler under F3 (still showing relative offsets)
dis-assembler under F3 (still showing relative offsets)
small_2012-08-09 23.00.07.jpg (126.78 KiB) Viewed 6465 times
Post Reply