Shop OBEX P1 Docs P2 Docs Learn Events
Z80 emulation for P2 (Cluso’s Pullmoll version) — Parallax Forums

Z80 emulation for P2 (Cluso’s Pullmoll version)

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 :)

Comments

  • Cluso99Cluso99 Posts: 18,069
    I will post the latest code here...

    Currently just a placeholder as forum software does not allow attachments after initial posting :(
  • Cluso99 wrote: »
    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 :)

    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! :innocent:

    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
  • Cluso99Cluso99 Posts: 18,069
    I have mine compiling as of this evening using FastSpin :smiley:
    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.
  • Well you have way more time spend with this stuff, I even haven't looked at Pullmoll's code, I just play around and try to grasp XBYTE and this skipping stuff.

    And it seems to elude me every time I think I got it.

    Mike
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-08-06 00:00
    I took a quick look at Tony’s code. It didn’t seem to be all there so I continued on my path.
    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.
  • msrobotsmsrobots Posts: 3,709
    edited 2019-08-06 02:01
    yeah Tonys code is good to play with but has lots of quirks in it.

    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
  • Cluso99 wrote: »
    I have mine compiling as of this evening using FastSpin :smiley:
    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.
    A good reason to ping @pullmoll. Don't we all miss him? :-D
    Cluso99 wrote: »
    There is a test code build for verifying emulations. I’ll need to find a link to the code.
    See attachment.
  • Cluso99Cluso99 Posts: 18,069
    Thanks yeti.
    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.
  • msrobotsmsrobots Posts: 3,709
    edited 2019-08-06 07:46
    Yes FastSpin is cool, even the Spin2Gui tool, I like the less is more aspect, its just plain and does what one need.

    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
  • msrobots wrote: »
    I hope that he not died at the console of hunger and thirst and next day was buried. Face down, nine edge first.
    Nonoooooo... he's alive and well... and busy committing stuff into voidlinux's repositories. \o/
  • Cluso99Cluso99 Posts: 18,069
    Pullmoll poured out Code extremely fast. No doubt hes a great asset in that arena..
  • Cluso99Cluso99 Posts: 18,069
    As the next phase will be testing, I needed to dig out my serial code. I am using the ROM Monitor/Debugger for this so here is the code to exercise the ROM monitor. At the end of just some test output, the code jumps into the ROM Monitor where I can enter code, dump hub/cog/lut, etc.

    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)
  • So after shift I discovered this and thought - whoohoo.

    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
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-08-07 11:03
    @msrobots,
    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 :smiley:
  • msrobotsmsrobots Posts: 3,709
    edited 2019-08-07 14:37
    yes I do and yes you can be sure I will run it as soon as get hold of it somewhere here.

    Mike
  • Cluso99Cluso99 Posts: 18,069
    As soon as i can post the tester code i will. Been assembling wardrobes today ;)
    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).
  • Hiya! I've been looking at the Parallax forums every now and then over the last couple of years waiting for the Propeller2 to appear.
    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.
  • pullmoll wrote: »
    Hiya! I've been looking at the Parallax forums every now and then over the last couple of years waiting for the Propeller2 to appear.
    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.
  • Cluso99Cluso99 Posts: 18,069
    Gooday Jurgen,
    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 :smiley:
  • Cluso99Cluso99 Posts: 18,069
    @msrobots and all,
    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 :smiley:
  • Cluso99Cluso99 Posts: 18,069
    Here is the latest ready for my testing. There are simplifications possible, but I now want to just get it going first.
  • Like pullmoll I also check in occasionally to see how the P2 is going. Tinkering at the moment with a ESP32 CP/M emulation runCPM - this has the nice advantage of being able to read FAT32 files from CP/M. Building a series of little terminals with PS2 keyboard, display, RS232 connection. Got Kermit sending files. NRF24 modules for long distance transparent serial links. Following this thread with interest :)
  • Cluso99Cluso99 Posts: 18,069
    Hey Drac, nice to see you following.

    Do you mean cpm can read and write fat32 files? That’s what I’ve pondered for a long time.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2019-08-13 13:18
    Cluso said: Do you mean cpm can read and write fat32 files?
    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...
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-08-13 18:08
    Drac,
    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 :(
  • Cluso99Cluso99 Posts: 18,069
    Some of the code is now running...
    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.
  • Cluso99Cluso99 Posts: 18,069
    Here is the latest v024. Looking good so far :smiley:

    The Z80 code...
                  orgh      Z80_MEM
    {0000}          byte    $01, $12, $34           ' LD    BC,#$1234
    {0003}          byte    $0C                     ' INC   C
    {0004}          byte    $79                     ' LD    A,C
    {0005}          byte    $80                     ' ADD   A,B
    {0006}          byte    $5F                     ' LD    E,A
    {0007}          byte    $C6, $CC                ' ADD   A,#$CC
    {0009}          byte    $57                     ' LD    D,A
    {000A}          byte    $00[100]                ' NOP...
    
    And the debug output...
    not an ELF file
    ( Entering terminal mode.  Press Ctrl-] to exit. )
    Z80 Emulation: P2-qz80-rr024
    PC   B C  D E  H L  A  F  R  R2 IF SP     ea    Op Vector3   V-1 V-2 V-3  PC++
    0000 0000 0000 0000 00 40 00 00 03 0000 = 0000: 01 0009A05D: 05D 09A 000  0001
    0000 3412 0000 0000 00 40 00 00 03 0000 = 0003: 0C 27CDF063: 063 0DF 09F  0004
    0000 3413 0000 0000 00 00 00 00 03 0000 = 0004: 79 000B7063: 063 0B7 000  0005
    0000 3413 0000 0000 13 00 00 00 03 0000 = 0005: 80 0011B062: 062 11B 000  0006
    0000 3413 0000 0000 47 00 00 00 03 0000 = 0006: 5F 000A706A: 06A 0A7 000  0007
    0000 3413 0047 0000 47 00 00 00 03 0000 = 0007: C6 0011B05B: 05B 11B 000  0008
    0000 3413 0047 0000 13 11 00 00 03 0000 = 0009: 57 000A506A: 06A 0A5 000  000A
    0000 3413 1347 0000 13 11 00 00 03 0000 = 000A: 00 00000003: 003 000 000  000B
    0000 3413 1347 0000 13 11 00 00 03 0000 = 000B: 00 00000003: 003 000 000  000C
    *
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-08-17 05:45
    Spent some time yesterday looking thru zexall and zexdoc and bdos to see what I need ready to test/verify all the emulated instructions. Seems I need the list out device call for bdos (call 5). So I hope to do this in the next few days.
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-08-18 21:55
    It's now partially executing the zexdoc validation code.

    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 :smiley:
Sign In or Register to comment.