Shop OBEX P1 Docs P2 Docs Learn Events
ZX81 Emulator on HYDRA — Parallax Forums

ZX81 Emulator on HYDRA

GiemmeGiemme Posts: 85
edited 2009-10-17 00:48 in Propeller 1
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
«1

Comments

  • mahjonggmahjongg Posts: 141
    edited 2008-01-09 16:13
    I think that you will be much better off, (using less resources, and gaining a more exact emulation) when you write your own video driver, using the exact same methodology as the real ZX81 instead of using any of the existing "normal" memory mapped video drivers.

    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" smile.gif 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.
  • BaggersBaggers Posts: 3,019
    edited 2008-01-09 16:45
    Don't forget to have a FAST mode [noparse]:)[/noparse] for authenticity [noparse]:)[/noparse]
  • BamseBamse Posts: 561
    edited 2008-01-09 17:33
    First of all, I know very little about the ZX81... wink.gif

    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
  • BamseBamse Posts: 561
    edited 2008-01-09 19:40
    This was a fun "over the lunch" project...

    Maybe a ZX64 emulator ? devil.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • BaggersBaggers Posts: 3,019
    edited 2008-01-09 20:01
    Nice 1 Bamse lol
  • VIRANDVIRAND Posts: 656
    edited 2008-01-09 21:31
    Useful info...

    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.)
  • GiemmeGiemme Posts: 85
    edited 2008-01-09 21:54
    I Bamse

    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
  • BamseBamse Posts: 561
    edited 2008-01-09 22:26
    Cant help you there...

    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... wink.gif
    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
  • mahjonggmahjongg Posts: 141
    edited 2008-01-10 11:48
    More info can be found here:

    http://en.wikipedia.org/wiki/Zx81#TV_picture_generation

    and through the links provided on that page.
  • BamseBamse Posts: 561
    edited 2008-01-10 14:52
    I know it's not PAL, but it might be of help to write your video driver...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • BaggersBaggers Posts: 3,019
    edited 2008-01-10 15:52
    You could slightly modify the tv.spin object file, to handle a ZX81 font, and it would then be PAL(50Hz)/NTSC compatible ( as it wouldn't need the PAL60 hack, because it's B&W anyway, so shouldn't need to worry too much about the colour burst timing issues with PAL50 )

    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]
  • GiemmeGiemme Posts: 85
    edited 2008-01-10 19:30
    Hi Baggers

    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
  • BaggersBaggers Posts: 3,019
    edited 2008-01-10 21:27
    Hi 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.
  • VIRANDVIRAND Posts: 656
    edited 2008-01-11 05:33
    I never noticed the PAL version of the ZX81, nor how the difference was implemented.
    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.
  • BaggersBaggers Posts: 3,019
    edited 2008-01-11 10:13
    But it would have to be a CYCLE perfect Z80 emu and display driver, although tbh I'm not sure what they did with the NTSC version either lol, I'm guessing they sped that up to 60fps, since the original was at 50fps.
  • mahjonggmahjongg Posts: 141
    edited 2008-01-11 13:52
    There is no need for a cycle perfect Z80 emulator, as the WAITVID pixel delay would fix the synchonisation.

    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.
  • BaggersBaggers Posts: 3,019
    edited 2008-01-11 16:08
    What I meant by cycle perfect emulator, was every instruction would have to be emulated at a speed => than the Z80 originally did it because otherwise the timing of the Z80 hence the display/list would be out, if you see what I mean. [noparse];)[/noparse]

    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.
  • BaggersBaggers Posts: 3,019
    edited 2008-01-11 17:49
    That's using·the ZX81 font Giemme, I've even written a bmp·to scrmap converter [noparse]:)[/noparse] as you can see, I had·my screen grab from a ZX81 emu with my fav ZX81 game 3D Monster Maze.
    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.


    PropZX81.jpg
  • BamseBamse Posts: 561
    edited 2008-01-11 18:02
    Awesome...

    I might have to check out the ZX81 games... wink.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • GiemmeGiemme Posts: 85
    edited 2008-01-11 21:06
    WOW!
    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
  • BaggersBaggers Posts: 3,019
    edited 2008-01-12 08:59
    Don't be getting too excited, you'll need lots of memory for GBC you'd be better doing a spectrum emu before GBC as the spectrum only needs 64K ( 16K ROM + 48K RAM before someone says spectrum had 48K lol ) whereas the GBC had at least double that, and that's just ROM, and before ram, and video ram.

    Baggers.
  • GiemmeGiemme Posts: 85
    edited 2008-01-12 19:57
    I know, but I ordered the Hydra 512K ram card and I have to do something intersting with it.idea.gif
    Gianni
  • BaggersBaggers Posts: 3,019
    edited 2008-01-12 20:01
    very true [noparse]:)[/noparse]

    roll on ZX81 emu, and GBC emu [noparse]:)[/noparse]
  • BaggersBaggers Posts: 3,019
    edited 2008-01-14 14:13
    yes, but surely in order for it to be faster, would be using the wait, to become cycle precise?

    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.
  • mahjonggmahjongg Posts: 141
    edited 2008-01-14 14:18
    Baggers said...
    What I meant by cycle perfect emulator, was every instruction would have to be emulated at a speed => then the Z80 originally did it because otherwise the timing of the Z80 hence the display/list would be out, if you see what I mean. [noparse];)[/noparse]

    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.
  • mahjonggmahjongg Posts: 141
    edited 2008-01-14 14:25
    Ah, you are answering my post before I posted it smile.gif.

    (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.
  • BaggersBaggers Posts: 3,019
    edited 2008-01-14 14:32
    lol
    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.
  • mahjonggmahjongg Posts: 141
    edited 2008-01-14 17:51
    Hmm-yes, I suppose that would be do-able, I am not sure if the ZX-81 executed BASIC interpreter code inbetween drawing each TV-line, but your code could take care of that too. And it probably does not matter, as it would only affect software that changes the video output buffer halfway through a screen paint.

    The ZX-81, by the way, is -always- drawing all 32 charaters (and all 24 lines) only most of them are blanks smile.gif. 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.
  • GiemmeGiemme Posts: 85
    edited 2008-03-23 21:08
    Hi all

    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
  • Spork FrogSpork Frog Posts: 212
    edited 2008-03-24 16:20
    Are you using the VGA drivers that came on the Hydra disk? Because those never worked like they were supposed to for me. Use the Parallax Library ones instead.
Sign In or Register to comment.