Z80 emulation for P2 (Cluso’s Pullmoll version)
Cluso99
Posts: 18,069
in Propeller 2
Funny that Tonyb’s thread should reappear at this time.
Over the past few days I have been busy reworking Pullmoll’s P1 QZ80 for use on the P2. I chose this as the base because it was a more complete implementation than heater’s ZiCog even tho i never got QZ80 to run on my RamBlades or TriBlade.
Both QZ80 and ZiCog use the 3 vector approach I first used way back in my faster spin interpreter. While this doesn’t simply translate for P2 (there is no jmp/call for 9bit addresses) it is the easiest to convert.
I am just aiming to get it running - not for speed and not for cycle accuracy.
Currently I am away in the UK and fortunately I have my P2D2 with me so I can test it out
Over the past few days I have been busy reworking Pullmoll’s P1 QZ80 for use on the P2. I chose this as the base because it was a more complete implementation than heater’s ZiCog even tho i never got QZ80 to run on my RamBlades or TriBlade.
Both QZ80 and ZiCog use the 3 vector approach I first used way back in my faster spin interpreter. While this doesn’t simply translate for P2 (there is no jmp/call for 9bit addresses) it is the easiest to convert.
I am just aiming to get it running - not for speed and not for cycle accuracy.
Currently I am away in the UK and fortunately I have my P2D2 with me so I can test it out
Comments
Currently just a placeholder as forum software does not allow attachments after initial posting
Yes, guess why I want a Ramblade from you or whatever it is called now. Having a running CP/M makes things more easy. Your PropDos and CP/M would fit nicely on a P2. So I am fighting with @TonyB_ 's Version of @PullMoll 's Code, and Tony obviously has no P2.
I mingle around with his code to get it running, - hm - more wrestling. At least I have a Test harness around it with some Spin support for a Terminal and two longs as mailboxes to z80.
It is running on a 64K ram buffer filled with 0 and it does not die anymore, so the PC is ticking and NOP seems to work!
I have a hard time understanding the XBYTE stuff, the main loop is running but xbyte ret returns to fetch somehow I need to debug this deeper, A big plus is that I now can load the LUT from the HUB image, so it runs.
But does nothing except counting the PC, somehow I am missing something.
Enjoy!
Mike
Only had a quick gander at the listing.
Think I may have found a bug in pullmolls code too - an obscure part in the set/clear bit code. Much of this was not implemented in Zicog.
There is a test code build for verifying emulations. I’ll need to find a link to the code.
And it seems to elude me every time I think I got it.
Mike
IIRC my code compiles to around $2800 Bytes.
The tricky bits are removing lmm mode and replacing with LUT and hubexec, expanding the vectors to 3 * 10 bit addresses, and extracting to jump to.
The single most frustrating part in converting P1 assembler to P2 is the lack of a JMPRET equivalent. It’s a real PITA!!!
If I get some time tomorrow (doubtful atm) I want to test the basic step thru and then the base 250 instructions (exclude cb, did, fd, etc multi byte instructions). For this I’ll need to drive the monitor/debug serial code in P2 rom.
I see it as Training with emulators. Since @"Heater." is AWOL someone has to start building emulators. So please do not feel challenged in any form, I am just playing with TonyB_'code I doubt that I can get it running at all.
And with that jmpret, I am not sure.
What does the compiler do? You put labels there with xxx_Ret and the ins is no ret, but a modified jmp.
One can do that on the P2 also, and put a JMP instead of a RET and populate it with ALD or friends when you call it. The P1 is doing the same. Basically. You could even push and call.
You may need another long.
Mike
See attachment.
I found zexdoc and zexall last night with some additional info etc. I’ll download it to try on my emulator.
BTW I spoke with pullmoll (Juergen) a few years ago and received his permission to use qz80 as I please. He’s moved on to other things.
I just went thru the CP/M thread again, I had 2 relaxing days. This is over 10 Years ago!
Some things don't die and I have a COBOL-85 for Z80...
+1 for @Pullmoll,
I hope that he not died at the console of hunger and thirst and next day was buried. Face down, nine edge first.
Mike
Notes:
Select the clock for either the P2D2 board or the P2-EVAL board (both with v32i ES chips).
Adjust the _baud (Fastspin defaults to 230,400 baud)
Downloaded it and its just a memory dump for cog , lut and hub. Nice to have, kind of a basic debugging file to run, but no bytecode interpreter in the zip.
Do I miss something?
Mike
No, its the bones ready to add in to the z80 code. It serves as an example of using the ROM serial calls.
Now integrated but not tested. I need to be able to run some opcodes and check its working. Having the ability to dump the registers after each opcode is an essential first step. Without any diagnostics you’re just flying blind.
Once i get a little further I’ll post z80 code
Do you have a P2-EVAL board? If so, you can help me test
Mike
The tester will make testing this, tonys z80, and any other code easy and with a minimum of cog space.
And you can call the rom debugger from anywhere in your code, and return to your code when done with the debugger. This permits examining/changing any cog/lut/hub location(s).
As it seems it won't be too long from now that this happens and perhaps I should start to read about its final design, specs and assembler.
Great to see your post! Welcome back. It won't be long now to procure a real P2.
Pleased you’ve dropped in
Yes the P2 has arrived. We’ve been playing with the ES chip since xmas. There are around 110 chips in the wild, 100 on the P2-EVAL pcb and around 10 on Peters P2D2 board.
The respin, which we hope , and appears so, will be the release silicon. Chip has 10 of these, and there is 2500 IIRC just waiting for the go to package them.
We were quietly hoping that the design of 160MHz would do 200MHz. Well the ES chips reached 350MHz overclocked. The new chips look like reaching about 390MHz.
It’s 8 cores, 2KB cog ram and 2KB Lut ram which can also be used as cog code space. Hub ram is 512KB. Cog access to hub is via an eggbeater - All cogs can access hub simultaneously as the hub is built with 8 blocks that are interleaved to make sequential addresses. So when cog 0 accesses hub xxx0, cog 1 accesses xxx1, ... to cog 7 xxx7. Next clock the cogs hub addresses advance by one. There are block instructions to copy to/from cog/lut to/from hub with one long per clock. Instructions take mostly 2 clocks. And code can run from hub too (hubexec) very fast.
So, we are all very excited
Well, time to digest the code
I have tested fetching opcodes, decoding them (first byte only), and fetching the first set of vectors.
These vectors have been checked for correct addresses.
The code for each jmp/call routine has not been validated.
The test harness is currently intact.
Change the header for P2-EVAL pcbs as P2D2 is currently selected.
Serial is 230,400 baud on P62/63.
I used spingui to compile, load, and run the code, with its inbuilt terminal.
Output debugging uses the P2 ROM Monitor/debugger.
Enjoy
Do you mean cpm can read and write fat32 files? That’s what I’ve pondered for a long time.
Ah, yes, some very clever code over on https://github.com/MockbaTheBorg/RunCPM
You need to pull it apart a bit - get the arduino IDE, compile for a DUE or teensy or 8266 or (best) an ESP32. Then you can see all the tabs neatly lined up - the BIOS in one tab, the BDOS, the hardware specific code, and the Z80 emulation. It is all in C so fairly straightforward. To make the SD card, create folders A, B, C etc, and inside these, folders 0,1,2 for User 0,1,2 etc, and then copy files to these. Super simple. A port to the Propeller may be in order...
When I next power my laptop up I’ll download the code and take a look at the BDOS source. I believe this is the code I’ll need to convert.
I’m looking forward to using cpm (Wordstar or Vedit) to edit FAT32 text files
BTW I’m in the UK atm visiting my daughter and her family. I’ve been doing the z80 emulation while here. My pc back home refuses to connect remotely so I cannot access any of my code at home
Vectors are working. I can load registers, increment, snd add. Currently loading fixed bytes into $0000.
Debug (print) all regs and pc after each instruction executes.
The Z80 code... And the debug output...
I tried the prelim.z80 code suite but couldn't find a PC Z80 Assembler to assemble it. I have compiled the zexdoc.src successfully and this is what I am using to test. I also have zexall.src to try too. I am using ZMAC to assemble.
There is debug output for every z80 instruction executed.
Making progress