ZX81 Emulator on HYDRA
Giemme
Posts: 85
Update document. Regards Gianni
Hi
as promised here is my ZX81 emulator·on Hydra. Tonight I was brainstorming about "how to do it" and then I collected all my thought into this draft document.
I will appreciate all your·feedback. Positive and also negative.
Thanks
Gianni
P.S. Andrè could this project be·a candidate for your next book?
Post Edited (Giemme) : 1/10/2008 12:01:11 AM GMT
Hi
as promised here is my ZX81 emulator·on Hydra. Tonight I was brainstorming about "how to do it" and then I collected all my thought into this draft document.
I will appreciate all your·feedback. Positive and also negative.
Thanks
Gianni
P.S. Andrè could this project be·a candidate for your next book?
Post Edited (Giemme) : 1/10/2008 12:01:11 AM GMT
Comments
The ZX81 used very minimalistic "video hardware", not much more than a shift register, to create the video signal with software.
this ZX81 "video hardware" should be very simple to re-implement using the "waitvid" instruction, which also would take care of emulation timing, (because the waitvid instruction actually synchonizes the Z80 emulator, to the pixel generator, so the ZX81 will run at the "real" speed when generating a vide signal) and then "all you have to do" is to accurately emulate the Z80.
If done well the emulated ZX81 will be able to run all the original ZX81 software, even non text mode ("high resolution" generating) software.
However you are welcome to use the Commodore demo driver if you want to.
As I understand the ZX81 only had a black and white font which the commodore driver could do.
I can also scale it down for you to correct columns and rows to make it more authentic.
And if you happen to have the font in a bitmap, please send it to me and I'm pretty sure I can convert it to a font for the commodore driver...
Anyone know where I can find the specifications for the ZX81 video?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse
Maybe a ZX64 emulator ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse
emulating z-80 instructions: (This helps simplify the job alot, because there are so many.)
http://www.z80.info/decoding.htm
basic rom:
http://www.howell1964.freeserve.co.uk/ZX81/ZX81_CPLD/ZX81_CPLD.htm
I couldn't find much ULA info except for what's in the above link and site.
I know it scans the keyboard and screen, but I don't remember all the exact details.
(But I used a very similar trick with a different processor once.)
thank you very much for the videodriver. Unfortunatelly in europe the standard is Pal.
Attached you will find the character set of the zx81 and also video specification:
http://home.germany.net/nils.eilers/zx81/wilfvid.htm
Regards
Gianni
Post Edited (Giemme) : 1/9/2008 10:26:43 PM GMT
I moved to the U.S. 12 years ago and it seems to me that you really cannot go into a store and buy a PAL TV here in the U.S.
Guess you would have to special order one...
On the other hand, even the cheap little TV I had in Sweden 12 years ago could display NTSC from an American VCR...
I think it even had two different settings for NTSC...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse
http://en.wikipedia.org/wiki/Zx81#TV_picture_generation
and through the links provided on that page.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse
Or if you want, I could knock one up for you to use, it wouldn't be that hard, as I've already done so many before [noparse]:)[/noparse]
Baggers.
But don't feel that you have to, as if you're using this as a learning curve, then enjoy [noparse];)[/noparse]
Actually I am learning more, reading others code. I am a theorical, first I have an idea... then I manifest it ->design then I implement it and at the I verify the results.
If you see the document that I published, you understand what I mean.
So, if you enjoy to adapt the tv pal driver for the zx81 then welcome [noparse]:)[/noparse]
Regards
Gianni
Yeah, I'll do a tv driver for you, question is are you going to want just a character map driver or one that can handle the hires? ie one that would have to have access to DFile or whatever it's called, and I/R registers,
or haven't you looked deeply into ZX81 enough yet to decide which way your going with it?
Cheers,
Baggers.
Simply slow it down to 50 fps?
Methinks a Z80 emulator running the ROM code would make the video driver really simple,
as it would just have to recognize the ULA's logic states.
Because the video signal generated by a ZX81 is monochrome, without a color burst, the differences between PAL/NTSC generation would simply boil down to the number of display lines generated and the 50/60Hz framerate.
Using an existing text mode video generator could be done, but remember that the ZX-81 way to treat video memory was by nature dynamic and could use anywhere from just 2 bytes, upto 768 bytes (it had just 1K of RAM, so the display alone would take almost all of the available RAM otherwise!).
So the ZX-81 is -not- using a 32x24 array of character locations (bytes) to hold the video, but to conserve memory it used a "display list". The screen bytes were stored as minimal length strings: for example, if a screen line was only 12 characters long, it would be stored as only those 12 characters followed by the code for a new line, the rest of the line being automatically assumed to be spaces.
But yes, for an initial version, it might be easiest, at first, to ignore the ZX81 unique video generator and just have COG that reads out the display list of the emulated ZX81, and copy it to the 32x24 array of the standard text mode video generator. Then as the rest of the ZX81 emulation works you might try to do a more exact emulation of the real video hardware.
also, yes, at the moment, it's using 768 bytes, for initial tests, until the emu is close enough to do the real screen emulation.
run the program, which generated 768byte file, which I just included in the main spin file·and viola [noparse]:)[/noparse]
the excitement is almost unbearable, I might have to port my PIC 3DMM to this driver while we wait for the real thing.
Baggers.
I might have to check out the ZX81 games...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse
The Hydra Time Machine went 28 years back.
I like your 3D Monster Maze avatar Baggers. As soon as the ZX81 emulator will be ready, then the whole forum will get a ZX81 corporate identity.
I found this usefull java utility to convert the tape streams into *.p file:
http://www.zx81stuff.org.uk/zx81/tapeutils/overview.html
More that 100 games are yet converted and ready into·this database (flight-simulator, ZXchess, Adventure,Invaders, 3D Monster Maze, VuCalc spreadsheet, VuFile database etc.....).
http://www.zx81stuff.org.uk/zx81/generated/packages/
But this is only the beginning because next step will be the emulation of a gameboy color and then the Hydra game machine will have a Quantum Leap....
Regards
Gianni
Post Edited (Giemme) : 1/11/2008 9:24:37 PM GMT
Baggers.
Gianni
roll on ZX81 emu, and GBC emu [noparse]:)[/noparse]
or failing that, to emulate it so that it didn't need to be in sync with the display, it would need it's own screen buffer, that was generated by the emulation software, for the tv driver to display in real time?
or is it me misunderstanding your theory [noparse]:)[/noparse]
the way i see your saying it is...
1. the Z80 emu runs faster than the original, and uses waitvid ( or waitcnt ) to keep it in sync with timings, ( thus becoming cycle precise )
2. the Z80 emu runs slower than the original, and therefore has to have a video buffer that the emulator creates from emulating the video timing bits too, as the TV display would be going too fast for said emulation.
Yes, I understood very well what you meant Baggers, but if the Propellers Z80 emulator is just too slow to keep up with the original, than a cycle perfect ZX81 emulator (one that runs at the same speed as the original) is simply impossible.
What I meant is (given a Z80 emulator of sufficient speed) that in reality this Z80 emulator does not have to emulate cycle precise Z80 opcodes, in this practical situation, with this ZX81 emulator, and when you implement the real ZX81 video driver, because of the way the ZX81 works!
Say the ZX81 is excecuting a BASIC program, and is displaying video at the same time, the real ZX81 would excecute some code to interpret the BASIC instructions, and at some time it would be interrupted (at the start of a new display line, with a hardware interrupt from the video hardware) and then would start to drive the video hardware. The -emulated- ZX81 would use emulated Z80 instructions to execute exactly the same amount of Z80 instructions as the real hardware, before being interrupted through the emulated hardware at the exact same instruction as the real ZX81 would. But the emulated Z80 instructions do not need to be executed at the exact same speed as the real Z80, only faster! The video driver (using the Waitvid instruction) would wait (synchronise) the output of a pixel, thereby halting the emulated execution of further Z80 instructions, untill it was at the exact time as the real ZX81 to output the pixel.
In short, because a ZX81 uses software to output pixels, it does not matter if the Z80 emulator doesn't emulate it's instructions cycle perfect, because when the ZX81 emulator hits the video routine it will be delayed until it syncs with a real ZX81 again.
The only exception I can think of is when trying to drive the casette driver, then other measures must be taken to sync the Z80 emulator.
However, the Z80 emulator must still count instruction cycle times, (as to trigger the interrupt routine at the right moment) so in practice there is not that much difference with a Z80 emulator that -is- written to be cycle perfect.
(its just because I post-edited it, I was not content with the original, too many spelling mistakes)
No, it would be possible -not- to completely emulate the ZX81's video hardware, you could do it with the semi-emulated version, but you should still emulate the interrupt mechanism, then just copy the ZX81's video buffer every n-th emulated interrupt.
or I suppose it could just simply assume that it would be displaying all 32 characters, or until it found a 64 ( or whatever the end of line character is ) that way, the emu might then even be able to skip the interrupt code until it finds a return, thus bringing the speed back up?
now that would work, except for intricate display handlers, but I doubt they'd be over complex, for 99% of the games, it'd just be the hi-res ones you'd have trouble with.
The ZX-81, by the way, is -always- drawing all 32 charaters (and all 24 lines) only most of them are blanks . But yes, you could use the "end of display" character to trigger the screen buffer copy routine, that would actually be a very good way to do it.
Only if you try to emulate sound output (through the casette port) this method might not work to satisfaction. But I think very few games had any sound at all.
Just give it a shot, and see how far you get.
Before I started coding the emulator, I tried to connect my Hydra to a VGA LCD screen but the output·was not the best.
Any idea how to improve it? I need 640x480 or 800x600
Thanks
Gianni