P2 opcode mask/match questions
pullmoll
Posts: 817
Since I have no P2 yet I started writing an emulator. I want to exercise some code on my box.
I used P2 instruction set.csv to extract the opcode bit masks and match values in order to decode the instruction.
However, I have duplicate entries for two groups of instructions now.
With mask 0x0fe001ff (binary 0000_1111111_000_000000000_111111111) I get this
DIRL, DIRH, DIRC, DIRNC, DIRZ, DIRNZ, DIRRND, DIRNOT
EEEE 1101011 CZL DDDDDDDDD 001000xxx
and also
TESTP WC/WZ, TESTPN WC/WZ, TESTP ANDC/ANDZ, TESTPN ANDC/ANDZ, TESTP ORC/ORZ, TESPN ORC/ORZ, TESTP XORC/XORZ, TESTPN XORC/XORZ
EEEE 1101011 CZL DDDDDDDDD 001000xxx
The other group of clashing is with mask 0x0fe00000 (binary 0000_1111111_000_000000000_000000000)
BITL, BITH, BITC, BITNC, BITZ, BITNZ, BITRND, BITNOT
EEEE 0100xxx CZI DDDDDDDDD SSSSSSSSS
and also
TESTB WC/WZ, TESTBN WC/WZ, TESTB ANDC/ANDZ, TESTBN ANDC/ANDZ, TESTB ORC/ORZ, TESTBN ORC/ORZ, TESTB XORC/XORZ, TESTBN XORC/XORZ
EEEE 0100xxx CZI DDDDDDDDD SSSSSSSSS
Am I missing something, or is this a bug in the table?
I used P2 instruction set.csv to extract the opcode bit masks and match values in order to decode the instruction.
However, I have duplicate entries for two groups of instructions now.
With mask 0x0fe001ff (binary 0000_1111111_000_000000000_111111111) I get this
DIRL, DIRH, DIRC, DIRNC, DIRZ, DIRNZ, DIRRND, DIRNOT
EEEE 1101011 CZL DDDDDDDDD 001000xxx
and also
TESTP WC/WZ, TESTPN WC/WZ, TESTP ANDC/ANDZ, TESTPN ANDC/ANDZ, TESTP ORC/ORZ, TESPN ORC/ORZ, TESTP XORC/XORZ, TESTPN XORC/XORZ
EEEE 1101011 CZL DDDDDDDDD 001000xxx
The other group of clashing is with mask 0x0fe00000 (binary 0000_1111111_000_000000000_000000000)
BITL, BITH, BITC, BITNC, BITZ, BITNZ, BITRND, BITNOT
EEEE 0100xxx CZI DDDDDDDDD SSSSSSSSS
and also
TESTB WC/WZ, TESTBN WC/WZ, TESTB ANDC/ANDZ, TESTBN ANDC/ANDZ, TESTB ORC/ORZ, TESTBN ORC/ORZ, TESTB XORC/XORZ, TESTBN XORC/XORZ
EEEE 0100xxx CZI DDDDDDDDD SSSSSSSSS
Am I missing something, or is this a bug in the table?
Comments
BTW there is no NR (no write) bit and the conditional instruction bits “0000” for never is now used for always plus a return instruction on an existing instruction with no time penalty. There is an 8 level stack.
Not sure if any of the P2 debug efforts include a software simulator mode ?
Someone also experimented with a Verilog derived simulator for the P1V.
eg https://forums.parallax.com/discussion/161755/p2-simulator
Gosh Guys, I was rooting for this, My favorite other German Member is back. Now things will get funny if @pullmoll starts to bite into something I can start to learn stuff from him again!
Just wonderful.
Now @TonyB_, @Cluso99 and me have a real challenge to get a Z-80 bytecode interpreter done, before he does...
Even without actual P2.
Enjoy!
Mike
@Cluso99 I think I can see where my fault is, or where there's something peculiar in the docs: for the BITL etc. group WCZ is optional, but not one of WC or WZ alone, while for TESTP/TESTB either one of the WC or WZ bits are required, but not both at the same time. So it's all about creating the correct mask: if (C xor Z == 0) then BITL else TESTP/TESTB. Tricky!
https://github.com/parallaxinc/spinsim
(I should note that "spinsim" is not an accurate name any more, it emulates raw processor instructions... although I think the bytecode emulator is still in there somewhere)
https://forums.parallax.com/discussion/comment/1449208/#Comment_1449208
you will enjoy the P2, it's tricky because it's Chips way. But very efficient, sometimes 30 lines of code shrink to two or three using smart pins. Have fun!
Mike
You will appreciate the xbyte and skip/skip instructions for emulators, although from what I can see, it’s of limited use for z80 emulation.
You will also like that we can run straight out of hub (hubexec) at full speed, without the lmm interpreter. There is just the wait for the hub cycle to come around every time the hub address jumps. So if you had 100 instructions without jumps, it would take just the initial hub latency to get going (~4-11 clocks) then every instruction will be 2 clocks with the few exceptions and hub read/writes. Nifty eh!
BTW I have your qz80 converted for P2. About to try it out
Then I need to get CPM running.
I also saw your qz80 changes and am sure that once it works it can be optimized (read: shrunk) for the P2 quite a bit.
I can hardly wait to get my hands on a P2 board
I've been working on a Qt5 project to emulate the P2 for about 15 hours now: defining enumerations for the flags and opcodes, the structure of the 32 instruction bits as bit fields, C++ templates to nicely handle required type casting etc. and several hundred op_xxx() functions for handling of each instruction. The latter were generated with comments taken from the CSV.
It's fun to flesh out the code and wrap my mind around how to efficiently do in C++ what the P2 does... well, enough babbling already
It’s probably not worth the trouble of finding an FPGA Nano-A9 at this late stage, or a a P2-EVAL lying idle.
http://forums.parallax.com/discussion/169964/z80-cpu-xbyte-interpreter#latest
I think the spreadsheet at http://forums.parallax.com/discussion/162298/prop2-fpga-files-updated-2-june-2018-final-version-32i/p1 is not up-to-date. I've attached the final version of the instruction set. New SETSCP & GETSCP added and RDLUT & WRLUT modified, the latter are the important ones for an emulator.
Does someone have a pointer to a ZIP or the file(s)?
v32i is the ES version and v32j is the respin (Aug 2019).