PDA

View Full Version : ZX81 Emulator on HYDRA



Giemme
01-09-2008, 08:40 AM
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

mahjongg
01-10-2008, 12:13 AM
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" http://forums.parallax.com/images/smilies/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.

Baggers
01-10-2008, 12:45 AM
Don't forget to have a FAST mode :) for authenticity :)

Bamse
01-10-2008, 01:33 AM
First of all, I know very little about the ZX81... http://forums.parallax.com/images/smilies/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:
[ ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[ ] OK, I got my resistors hooked up with the LEDs.
[X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[ ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[ ] I dream in SX28 assembler...

/Bamse

Bamse
01-10-2008, 03:40 AM
This was a fun "over the lunch" project...

Maybe a ZX64 emulator ? http://forums.parallax.com/images/smilies/devil.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...

Experience level:
[ ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[ ] OK, I got my resistors hooked up with the LEDs.
[X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[ ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[ ] I dream in SX28 assembler...

/Bamse

Baggers
01-10-2008, 04:01 AM
Nice 1 Bamse lol

VIRAND
01-10-2008, 05:31 AM
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.)

Giemme
01-10-2008, 05:54 AM
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

Bamse
01-10-2008, 06:26 AM
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... http://forums.parallax.com/images/smilies/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:
[ ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[ ] OK, I got my resistors hooked up with the LEDs.
[X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[ ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[ ] I dream in SX28 assembler...

/Bamse

mahjongg
01-10-2008, 07:48 PM
More info can be found here:

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

and through the links provided on that page.

Bamse
01-10-2008, 10:52 PM
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:
[ ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[ ] OK, I got my resistors hooked up with the LEDs.
[X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[ ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[ ] I dream in SX28 assembler...

/Bamse

Baggers
01-10-2008, 11:52 PM
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 :)

Baggers.

But don't feel that you have to, as if you're using this as a learning curve, then enjoy ;)

Giemme
01-11-2008, 03:30 AM
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 :)

Regards
Gianni

Baggers
01-11-2008, 05:27 AM
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.

VIRAND
01-11-2008, 01:33 PM
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.

Baggers
01-11-2008, 06:13 PM
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.

mahjongg
01-11-2008, 09:52 PM
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.

Baggers
01-12-2008, 12:08 AM
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. ;)

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.

Baggers
01-12-2008, 01:49 AM
That's using·the ZX81 font Giemme, I've even written a bmp·to scrmap converter :) 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 :)
the excitement is almost unbearable, I might have to port my PIC 3DMM to this driver while we wait for the real thing.

Baggers.


http://www.propgfx.co.uk/Baggers/Images/PropZX81.jpg

Bamse
01-12-2008, 02:02 AM
Awesome...

I might have to check out the ZX81 games... http://forums.parallax.com/images/smilies/wink.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...

Experience level:
[ ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[ ] OK, I got my resistors hooked up with the LEDs.
[X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[ ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[ ] I dream in SX28 assembler...

/Bamse

Giemme
01-12-2008, 05:06 AM
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

Baggers
01-12-2008, 04:59 PM
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.

Giemme
01-13-2008, 03:57 AM
I know, but I ordered the Hydra 512K ram card and I have to do something intersting with it.http://forums.parallax.com/images/smilies/idea.gif
Gianni

Baggers
01-13-2008, 04:01 AM
very true :)

roll on ZX81 emu, and GBC emu :)

Baggers
01-14-2008, 10:13 PM
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 :)

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.

mahjongg
01-14-2008, 10:18 PM
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. ;)


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.

mahjongg
01-14-2008, 10:25 PM
Ah, you are answering my post before I posted it http://forums.parallax.com/images/smilies/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.

Baggers
01-14-2008, 10:32 PM
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.

mahjongg
01-15-2008, 01:51 AM
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 http://forums.parallax.com/images/smilies/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.

Giemme
03-24-2008, 05:08 AM
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 Frog
03-25-2008, 12:20 AM
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.

JT Cook
03-25-2008, 04:24 AM
I think there is a bitmap driver in the object exchange that works pretty well. I personally have been trying to write a VGA driver that would work similar to the TV drivers, but I haven't had any luck on that. But since the ZX has a color limitation, the bitmapped VGA drivers may work well for your project.

Giemme
03-25-2008, 03:20 PM
Thanks

I am using now following drivers and it works properly:

vga_1024x768_tile_driver_with_cursor.spin
vga_1024x1024_tile_driver_with_cursor.spin

Regards
Gianni

Giemme
04-01-2008, 02:23 PM
Hi All

after some issue (http://forums.parallax.com/showthread.php?p=717850)·related to the VGA <-> HR512KSRAM pin compatibility, I am happy to announce that the prototype·one based on a TV driver is finished http://forums.parallax.com/images/smilies/hop.gif

Well.... don't expect to much from this prototype.. I am in a learning phase now

Anyway.. this feature are available:
- Format 64K of ram
- Load the 8k ZX81 Rom into the address $0000 - $1FFF
- Verify the loaded ROM
- Copy the 8k ZX81 Rom into the address $2000 - $3FFF ( this is how the memory map on a real ZX81 looks)

Next iterations:

Prototype two
- ROM hacks (patch the Load / Save Rom so that the zx81 games can be loaded and saved from/to the HR512KSRAM instead of the rom trying to use the tape via ULA)
- doKey (Map the ZX81 keyboard with the Hydra keyboard)
- Emulate 10 Z80 opcodes·and test it

Prototype three
- TapeLoad (FileNamePtr)
- TapeSave (FileNamePtr)
- Continue emulating opcodes

Prototype four
- Screen emulation
- Slow / Fast emulation
- conclude opcodes emulation.

Regards

Gianni



Post Edited (Giemme) : 4/1/2008 9:59:46 AM GMT

JT Cook
04-01-2008, 09:22 PM
My recommendation would be to emulate all the Z80 op codes first before you do any routines to load programs. Then when it can boot the system OS, that is when you should start focusing on running external programs.

Loading programs without a CPU core is really a waste, put most of your effort into the CPU core before anything else.


Post Edited (JT Cook) : 4/1/2008 1:27:29 PM GMT

Baggers
04-01-2008, 09:24 PM
yeah, that's my thoughts too. you'd need the full Z80 or a fair chunk, not just 10 instructions, to get the screen to boot up.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

·

Giemme
04-01-2008, 10:47 PM
The Idea was to create a working ZX81 scheleton and then going into detail work. As I told before I am in a learning phase... and emulate all z80 opcodes I will get boring

Regards
Gianni

Baggers
04-01-2008, 11:01 PM
ok, sorry to give you my support and direction, enjoy your journey of discovery :D it's a fantastic journey for anyone, you will have a great time. :)
I will still look forward to seeing the progress though.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

·

Giemme
04-02-2008, 12:09 AM
Baggers thanks for your advice. You don't have to sorry. the great think on this forum is that we are all open mind.

I can change my mind during my journey ;)
Regards
Gianni

Baggers
04-02-2008, 12:41 AM
k, I don't mind, was just helping, but glad to take a back seat too lol,

PS, I think sorry was me choosing the wrong wording, :) meant to mean that I along with JTCook was just giving our support and knowledge, of ways to approach things.

and that with what we've learnt over our years of coding is that you'll be a LOT happier with the outcome when you run it and it boots up the OS, than doing a bit of it, then doing rom mods etc.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

·

Giemme
01-23-2009, 07:10 AM
Hi

here is an update of the z80 emulator project (not all command are emulated)

the scheleton of the zx81 is setup (see zx81 library)

all your comments are welcome

regards

Gianni

skylight
01-23-2009, 08:01 AM
If you want true zx 81 emulation don't forget to add the funny shaped 16K ram pack with dodgy edge connector that resets the emulator everytime you get to inputting the very last line of fifty lines of code http://forums.parallax.com/images/smilies/turn.gif

Baggers
01-25-2009, 10:40 PM
Giemme, I've had a look at the code now :D
Looks great and very tidy,
Just out of curiosity, are you going to convert it to PASM when you've finished it?
As my only criticisms are with all those calls, like getD getE etc, and spin is slow enough as it is, You'd need more than the 8* speed increase of the PropII to get it running at a decent speed.
Other than that, it's really shaping up well :)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

·

hinv
08-28-2009, 10:27 PM
Hi,

Has there been any progress on this since ZiCog has come out and preforms better then the actual Z80 chip.
It seems that the ZX81 and TS1000 emulators is one of the easiest to do(especially now thanks to heater) and would open up a bunch of software to use on the propeller.

Thanks,
Doug

Humanoido
09-01-2009, 02:04 AM
Anyone have this running ZX81 BASIC?

humanoido

mikediv
10-17-2009, 12:54 AM
Guys is there any Z80 emulators that would let us run CPM?

Forrest
10-17-2009, 08:48 AM
mikediv said...
Guys is there any Z80 emulators that would let us run CPM?


Yes - ZiCog http://forums.parallax.com/showthread.php?p=788511