Shop OBEX P1 Docs P2 Docs Learn Events
Cluso's Z80 Emulation for RetroBlade2 & P2 — Parallax Forums

Cluso's Z80 Emulation for RetroBlade2 & P2

Cluso99Cluso99 Posts: 18,069
edited 2021-12-05 01:18 in Propeller 2

Here is my latest version V056b. Note I have not done any work on this since Jan 2021. MMBASIC was working.

It uses 8*8MB drives ZICOG_A2,ZICOG_B,ZICOG_C,ZICOG_D,DRAC_A,DRAC_B,ZICOG_SC,ZICOG_VP which must be on the SD card in the root directory of a FAT32 formatted card. These files must be contiguous so it's easiest to copy them to the root directory of a newly formatted card.

I compiled it with Erics Fastspin v5.0.7 & v5.9.6 so it should compile with later versions. See ff.bat for compile and download instructions, or rename the binary to _BOOT_P2.BIX and copy to your SD card and the P2 should boot straight into the emulation :)

Please report any bugs here.
Thanks and enjoy :sunglasses:

BTW I am working on getting zexdoc and zexall to compile so I can test the emulation.
https://forums.parallax.com/discussion/173467/p2-z80-emulator/p1
https://retrobrewcomputers.org/forum/index.php?t=msg&th=580&start=0&
https://retrobrewcomputers.org/forum/index.php?t=msg&th=663&start=0&

May I suggest you also try out my P2 Propeller OS too
https://forums.parallax.com/discussion/173395/clusos-propeller-os-v2-38-includes-sd-driver-and-fat32-object-plus-serial-driver
https://forums.parallax.com/discussion/comment/1499300

My RetroBlade2 P2 board
https://forums.parallax.com/discussion/172556/clusos-retroblade2-your-board-s-have-arrived-so-what-to-do-next/p1
https://forums.parallax.com/discussion/172262/clusos-retroblade2-single-chip-computer-first-orders-paid-and-shipped-taking-new-orders-payment/p1

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-11-27 02:37

    These are the SD files you will need in the root directory of the FAT32 formatted SD card. The 8MB CPM DISK emulation files must be contiguous files so it's best to copy them first to a freshly formatted SD card.

    Enjoy :sunglasses:

  • Cluso99Cluso99 Posts: 18,069

    reserved for future use

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-12-05 01:27

    I have built a Z80 daughter board for my RetroBlade2 using the Z84C0020 DIP40 CMOS Z80 20MHz.

    Now I can also use a real Z80 too! The P2 emulates attached ROM/RAM and I/O peripherals, and provides the clock. It's using spin2 so it's not fast yet. :sunglasses:

    I finally now have two versions of zexall assembling and working with both the real Z80 and my P2 Z80 emulation. There are some errors generated so my emulation is not precise in some areas. I do notice however, that the Z84C0020 also generates errors in some areas too on the later zexall tests.


  • TonyB_TonyB_ Posts: 2,178
    edited 2021-12-05 10:11

    @Cluso99 said:
    I finally now have two versions of zexall assembling and working with both the real Z80 and my P2 Z80 emulation. There are some errors generated so my emulation is not precise in some areas. I do notice however, that the Z84C0020 also generates errors in some areas too on the later zexall tests.

    Have you seen this Z80 tester?
    https://github.com/raxoft/z80test
    It's an improved version of zexall, written for ZX Spectrum but could be modified for CP/M without much work (e.g. print.asm and org in main.asm).

  • Cluso99Cluso99 Posts: 18,069

    @TonyB_ said:

    @Cluso99 said:
    I finally now have two versions of zexall assembling and working with both the real Z80 and my P2 Z80 emulation. There are some errors generated so my emulation is not precise in some areas. I do notice however, that the Z84C0020 also generates errors in some areas too on the later zexall tests.

    Have you seen this Z80 tester?
    https://github.com/raxoft/z80test
    It's an improved version of zexall, written for ZX Spectrum but could be modified for CP/M without much work (e.g. print.asm and org in main.asm).

    Thanks Tony. Yes I had seen this and dowloaded a copy. Looks like it's based on zexall.

    The problem with all these tests is they have been modified for a specific assembler and so the macros don't work with other assemblers, and, they are usually built for specific hardware and so need modifications to run. I have spent a lot of time getting the two versions of zexall I have to assemble - trying lots of assemblers.

    What is interesting is that the Z84C00 Z80 returns different results to the original NMOS Z80.

    Anyway, with these two versions I should be able to fix the emulation to make it pass as per the Z84C00 which I have for a comparison. And I can use the same hardware setup for both - just need to recompile the P2 code and download. When testing the emulation, the P2 just ignores the Z84C00 that it is connected to by it being held in reset.

  • TonyB_TonyB_ Posts: 2,178
    edited 2021-12-06 11:15

    @Cluso99 said:
    What is interesting is that the Z84C00 Z80 returns different results to the original NMOS Z80.

    The differences I know:
    1. If LD A,I or LD A,R interrupted then P/V flag is always reset for NMOS but correct for CMOS
    2. Undocumented "OUT (C),F" [ED 71] outputs 0 for NMOS and 255 for CMOS
    3. Flag bit 3 ("XF") after SCF/CCF if previous instruction did not modify the flags (not confirmed for genuine Zilog)

    Any more?

  • Cluso99Cluso99 Posts: 18,069

    I have been modifying the various versions of zexall Z80 instruction tester.

    Today I ran my zexall version thru my Z80 emulator and all instructions that were tested passed except the BIT instructions. I am looking at them - I did see that I am setting the S flag according to the bit7 result but according to the Z80 opcode list the S flag is undefined. I am only testing the defined flags. Not updating the S flag did not fix this so more work to do.

    FWIW I am comparing against a real Z84C0020 which is only connected to my P2 (ie P2 provides all the interface, clock, eeprom and ram).

  • @Cluso99 said:
    I have been modifying the various versions of zexall Z80 instruction tester.

    Today I ran my zexall version thru my Z80 emulator and all instructions that were tested passed except the BIT instructions. I am looking at them - I did see that I am setting the S flag according to the bit7 result but according to the Z80 opcode list the S flag is undefined. I am only testing the defined flags. Not updating the S flag did not fix this so more work to do.

    BIT n,s:
    SF = bit 7 of s AND 2^n

  • Cluso99Cluso99 Posts: 18,069

    @TonyB_ said:

    @Cluso99 said:
    I have been modifying the various versions of zexall Z80 instruction tester.

    Today I ran my zexall version thru my Z80 emulator and all instructions that were tested passed except the BIT instructions. I am looking at them - I did see that I am setting the S flag according to the bit7 result but according to the Z80 opcode list the S flag is undefined. I am only testing the defined flags. Not updating the S flag did not fix this so more work to do.

    BIT n,s:
    SF = bit 7 of s AND 2^n

    That is what I was doing.

    The Z80 Opcode list I found on the internet clearly says the S flag is undefined. Perhaps this is wrong, or perhaps it’s a different error. I will need to investigate further.

  • Cluso99Cluso99 Posts: 18,069

    One of the problems is the Parity Flag not being set correctly (appears the Z84C00 does indeed set the PV flag correctly). I am unsure about the original NMOS Z80.
    Still does not pass the test though.

    According to Z80 CPU User Manual UM008011-0816

    BIT b, r
    Condition Bits Affected
    S is unknown.
    Z is set if specified bit is 0; otherwise, it is reset.
    H is set.
    P/V is unknown.
    N is reset.
    C is not affected.

  • See page 15 of "The Undocumented Z80 Documented"
    http://z80.info/zip/z80-documented.pdf

  • Cluso99Cluso99 Posts: 18,069
    edited 2022-01-09 10:12

    Thanks Tony. The actual flag setting is a bit weird but i have implemented it correctly (excepting the y and x flags which are not done anywhere).

    About to run the full test suite again - takes a few hours.

    Update:
    All tests passed :sunglasses:

  • @Cluso99 said:
    Thanks Tony. The actual flag setting is a bit weird but i have implemented it correctly (excepting the y and x flags which are not done anywhere).

    About to run the full test suite again - takes a few hours.

    Update:
    All tests passed :sunglasses:

    Cluso, could you post the version of zexall.com that you used?

  • hinvhinv Posts: 1,255
    edited 2022-03-17 21:33

    What is interesting is that the Z84C00 Z80 returns different results to the original NMOS Z80.

    So can you get your emulation to match the NMOS Z80 with some setting?

    Anyway, with these two versions I should be able to fix the emulation to make it pass as per the Z84C00 which I have for a comparison. And I can use the same hardware setup for both - just need to recompile the P2 code and download. When testing the emulation, the P2 just ignores the Z84C00 that it is connected to by it being held in reset.

    When the Z80 is held in reset does it just let the pins float or as inputs only?

  • Cluso99Cluso99 Posts: 18,069

    @TonyB_
    I will post as soon as I can.
    @hinv
    IIRC pins should float when in reset but the Z80 docs are your friend.

Sign In or Register to comment.