Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Good free and open source Z80 emulation code?

709 views
Skip to first unread message

Linards Ticmanis

unread,
Aug 26, 2010, 1:29:38 PM8/26/10
to
Hello to all the Amstrad/Schneider, MSX and Sinclair people!

do you maybe know if there is low level Z80 CPU emulation code available
(maybe as part of some existing emulator) that

1.) supports undocumented instructions and flags and
2.) is licensed under GPL or some compatible license?

(The code in MAME/MESS is unfortunately not GPL).

Thanks for any help,

--
Linards Ticmanis

Edward

unread,
Aug 26, 2010, 2:12:43 PM8/26/10
to
As I understand it, the FUSE (Free Unix Spectrum Emulator, by Phil
Kendall) source code is GPL; you could use that.

-Edward
--
"Sanity" is the last refuge of the unimaginative.
visit my useless website -- http://dev-null.chu.cam.ac.uk

David Cantrell

unread,
Aug 27, 2010, 7:23:56 AM8/27/10
to

There's my Z80 emulator!

http://search.cpan.org/~dcantrell/CPU-Emulator-Z80-1.0/lib/CPU/Emulator/Z80.pm

although it doesn't implement all the interrupt modes yet.

Most of the unit tests came from http://fuse-emulator.sourceforge.net/,
which is GPLed.

Both support all the undocumented instructions and flags.

--
David Cantrell | Enforcer, South London Linguistic Massive

You can't spell "slaughter" without "laughter"

Philip Kendall

unread,
Aug 27, 2010, 4:47:54 PM8/27/10
to
On 26/08/10 18:29, Linards Ticmanis wrote:
>
> do you maybe know if there is low level Z80 CPU emulation code available
> (maybe as part of some existing emulator) that
>
> 1.) supports undocumented instructions and flags and
> 2.) is licensed under GPL or some compatible license?

http://fuse-emulator.svn.sourceforge.net/viewvc/fuse-emulator/trunk/fuse/z80/

Disclaimer: I wrote it.

It doesn't support MEMPTR (bits 3 and 5 of the flags register after BIT
n, (HL)), but other than that you'll be pushed to find a difference
between it and a real Z80. If you do, let me know :-)

Cheers,

Phil

Darrell Stec

unread,
Aug 27, 2010, 6:29:38 PM8/27/10
to
Philip Kendall wrote:

You left out such an important feature? How could you? :-)

--
Later,
Darrell

Philip Kendall

unread,
Aug 28, 2010, 4:17:05 AM8/28/10
to
On 27/08/10 23:29, Darrell Stec wrote:
> Philip Kendall wrote:
>
>> http://fuse-emulator.svn.sourceforge.net/viewvc/fuse-
> emulator/trunk/fuse/z80/

>>
>> It doesn't support MEMPTR (bits 3 and 5 of the flags register after BIT
>> n, (HL)), but other than that you'll be pushed to find a difference
>> between it and a real Z80. If you do, let me know :-)
>
> You left out such an important feature? How could you? :-)

[ I know the above comment was in jest ]

No software (other than programs written deliberately to test MEMPTR)
make any use of the feature, so adding it would be a) tedious, b) of
little benefit and c) slow down the emulation, which is an issue on some
mobile platforms.

If anybody else wants to add it (probably as a compile-time option), I'm
more than happy to accept a patch :-)

Cheers,

Phil

jgharston

unread,
Aug 28, 2010, 9:47:08 AM8/28/10
to
Anybody is free to use the code in Z80Tube and cZ80Tube at
http://mdfs.net/Apps/Emulators/Tube

JGH

Martijn Dekker

unread,
Sep 1, 2010, 4:10:00 PM9/1/10
to
In article <4c76a483$0$7656$9b4e...@newsspool1.arcor-online.net>,
Linards Ticmanis <ticm...@gmx.de> wrote:

> Hello to all the Amstrad/Schneider, MSX and Sinclair people!
>
> do you maybe know if there is low level Z80 CPU emulation code available
> (maybe as part of some existing emulator) that
>
> 1.) supports undocumented instructions and flags and
> 2.) is licensed under GPL or some compatible license?

Have you tried YAZE-AG? It is GPL and claims to emulate undocumented
opcodes. (It also comes with a CP/M clone operating system.)

http://www.mathematik.uni-ulm.de/users/ag/yaze/

- M.

Prai Jei

unread,
Sep 2, 2010, 4:01:08 PM9/2/10
to
Philip Kendall set the following eddies spiralling through the space-time
continuum:

> Disclaimer: I wrote it.
>
> It doesn't support MEMPTR (bits 3 and 5 of the flags register after BIT
> n, (HL)), but other than that you'll be pushed to find a difference
> between it and a real Z80. If you do, let me know :-)

How would it interpret the opcode DD CB 01 91 ? More important, how would it
emulate that instruction?
--
ξ:) Proud to be curly

Interchange the alphabetic letter groups to reply

jgharston

unread,
Sep 2, 2010, 6:08:32 PM9/2/10
to
Prai Jei wrote:
> How would it interpret the opcode DD CB 01 91 ? More important, how would it
> emulate that instruction?

Should do res 2,(ix+1),c

Z80Tube doesn't, sorry.

JGH

Philip Kendall

unread,
Sep 3, 2010, 3:53:06 PM9/3/10
to
On 02/09/10 21:01, Prai Jei wrote:
> Philip Kendall set the following eddies spiralling through the space-time
> continuum:
>
>> Disclaimer: I wrote it.
>>
>> It doesn't support MEMPTR (bits 3 and 5 of the flags register after BIT
>> n, (HL)), but other than that you'll be pushed to find a difference
>> between it and a real Z80. If you do, let me know :-)
>
> How would it interpret the opcode DD CB 01 91 ? More important, how would it
> emulate that instruction?

[ Paraphrasing the code slightly ]

tempaddr = IX + readbyte(PC + 2);
C = readbyte(tempaddr) & 0xfb;
writebyte(tempaddr, C);

I refer you to the unit test suite included with Fuse, which includes a
test for DD CB 11 91.

It's the opcode 37 you want to be looking at, by the way :-)

Cheers,

Phil


Stephane

unread,
Sep 16, 2010, 10:02:35 AM9/16/10
to

I also offer my z80 cpu core for free, but it needs some more
debugging
(however I have found the compatibility rate to be quite high,
probably more than I would have thought ) ;-)

_tyrell_ (DC Speccyal'K)

M.O.B. i L.

unread,
Dec 4, 2010, 4:03:28 PM12/4/10
to
Linards Ticmanis wrote:
> Hello to all the Amstrad/Schneider, MSX and Sinclair people!
>
> do you maybe know if there is low level Z80 CPU emulation code available
> (maybe as part of some existing emulator) that
>
> 1.) supports undocumented instructions and flags and
> 2.) is licensed under GPL or some compatible license?
>
> (The code in MAME/MESS is unfortunately not GPL).

This is LGPL and probably handles all undocumented instructions:
Filename: tilem0.975win32bin.zip
Title: TilEm 0.975
Description: TilEm is a Z80 TI emulator (73, 82, 83, 83+, 83+ SE, 84+,
84+ SE, 85, 86) with a GTK+ interface. It fully supports FlashROM,
automatic variable linking, external linking through libticables2, and
all ROM/OS versions. New in this version: libticables2 (included), fixed
buffer overflow, fixed ti-85 keypad, fixed struct definition, etc.

http://www.ticalc.org/archives/files/fileinfo/412/41292.html

Philip Kendall

unread,
Dec 6, 2010, 2:41:16 AM12/6/10
to
On 04/12/10 21:03, M.O.B. i L. wrote:
>
> This is LGPL and probably handles all undocumented instructions:
> Filename: tilem0.975win32bin.zip

[ ... ]

> http://www.ticalc.org/archives/files/fileinfo/412/41292.html

Doesn't look to me like it does:

static opcode_fn opcode_fd_cb[256] = {
no_op_xx, no_op_xx, no_op_xx, no_op_xx, no_op_xx, no_op_xx,

All those opcodes have an effect.

Cheers,

Phil

--
Philip Kendall <phi...@shadowmagic.org.uk>
http://www.shadowmagic.org.uk/

M.O.B. i L.

unread,
Dec 6, 2010, 4:03:52 PM12/6/10
to
Philip Kendall wrote:
> On 04/12/10 21:03, M.O.B. i L. wrote:
>>
>> This is LGPL and probably handles all undocumented instructions:
>> Filename: tilem0.975win32bin.zip
>
> [ ... ]
>
>> http://www.ticalc.org/archives/files/fileinfo/412/41292.html
>
> Doesn't look to me like it does:
>
> static opcode_fn opcode_fd_cb[256] = {
> no_op_xx, no_op_xx, no_op_xx, no_op_xx, no_op_xx, no_op_xx,
>
> All those opcodes have an effect.

You're probably right. I've found this page that explains what these
opcodes should do: <http://www.z80.info/decoding.htm#ddcb>.

I thought it supported all Z80 instructions because one of the
developers has made an assembler that runs on the calculator (TI-83
Plus/TI-84 Plus/Silver Edition), that supported undocumented
instructions (but perhaps not all):
<http://www.ticalc.org/archives/files/fileinfo/431/43140.html>.

Here is a quote from the manual of the assembler:
"
*Z80 instructions*

Mimas supports all of the Z80 instructions, both documented and
undocumented. For details of the documented instructions, see the
official Z80 documentation.

For convenience, when setting, resetting, or testing a system flag, you
can simply type the name of the flag (or select it from the System Flags
menu), omitting the IY offset. For instance, SET textInverse will be
automatically replaced with SET textInverse, (IY + textFlags).

The undocumented instructions are described below. Note, however, that
undocumented instructions will not work on the TI-Nspire, so you should
avoid using them in programs that are intended to be portable.

*IX/IY Half Registers*
The upper and lower halves of the IX and IY registers can be
manipulated independently, just as H and L can; these “half registers”
are referred to as IXH, IXL, IYH, and IYL. Half registers can be used in
all of the basic 8-bit operations (ADD, SUB, ADC, SBC, AND, OR, XOR, CP,
INC, DEC), can have constant values loaded into them, and can be loaded
to and from the A, B, C, D, and E registers.
*Shift Left Inverted*
SLIA is similar to the documented SLA, except that the low bit of
the result is set to 1 instead of 0. (SLIA arg has the same effect as
SCF followed by RL arg.) SLIA can be used with any of the same arguments
that can be used with SLA.
*Shift/Rotate/Set/Reset Bit with Copy*
The instructions SLA, SRA, SLIA, SRL, RL, RLC, RR, and RRC can be
used with two arguments, where the first is one of the registers B, C,
D, E, H, L, and A, and the second is an indexed address (either (IX+n)
or (IY+n).) The instructions SET and RES can be used with three
arguments, where the first is a bit number, the second is a register,
and the third is an indexed address. This means that a value is read
from that indexed address, the appropriate operation is performed on
that value, and the result is both written back to memory and also
copied into the given register. For instance, SLA H,(IX+2) has the same
effect as LD H,(IX+2) / SLA H / LD (IX+2),H. SET 3,H,(IX+2) has the same
effect as LD H,(IX+2) / SET 3,H / LD (IX+2),H.
*Test-Only Input*
IN (C) reads a byte from I/O port C, without storing it anywhere,
but sets or clears the sign, zero, and parity flags according to the
input value, just as the documented IN r,(C) instructions do. (IN (C)
has essentially the same effect as PUSH BC / IN B,(C) / POP BC.)
*Zero Output*
OUT (C),0 writes a zero byte to I/O port C. (OUT (C),0 has
essentially the same effect as PUSH BC / LD B,0 / OUT (C),B / POP BC.)
"

David Cantrell

unread,
Dec 8, 2010, 8:10:35 AM12/8/10
to
On Mon, Dec 06, 2010 at 07:41:16AM +0000, Philip Kendall wrote:
> On 04/12/10 21:03, M.O.B. i L. wrote:
> > This is LGPL and probably handles all undocumented instructions:
> > Filename: tilem0.975win32bin.zip
> > http://www.ticalc.org/archives/files/fileinfo/412/41292.html
> Doesn't look to me like it does:
> static opcode_fn opcode_fd_cb[256] = {
> no_op_xx, no_op_xx, no_op_xx, no_op_xx, no_op_xx, no_op_xx,

I know that my emulator handles those, but I don't handle all the
interrupt modes. Nor do I handle all the stupid DD DD ...., DD FD ....
etc instructions.

http://search.cpan.org/~dcantrell/CPU-Emulator-Z80-1.0/lib/CPU/Emulator/Z80.pm

FUSE, on the other hand, whose test suite I use, *does* handle them
IIRC, so that would be a good place to start.

http://fuse-emulator.sourceforge.net/

When I was reading the code, it looked like the Z80 emulation bit would
be fairly simple to extract from it's Spectrummy wrappings.

--
David Cantrell | even more awesome than a panda-fur coat

More people are driven insane through religious hysteria than
by drinking alcohol. -- W C Fields

sam coupe

unread,
May 27, 2012, 9:00:26 AM5/27/12
to
how does the assembler explain where the scan line drawing the tv screen is while you are compiling code?

Curlytop

unread,
May 27, 2012, 4:11:20 PM5/27/12
to
sam coupe set the following eddies spiralling through the space-time
continuum:

> On Thursday, 26 August 2010 18:29:38 UTC+1, Linards Ticmanis wrote:
>> Hello to all the Amstrad/Schneider, MSX and Sinclair people!
>>
>> do you maybe know if there is low level Z80 CPU emulation code available
>> (maybe as part of some existing emulator) that
>>
>> 1.) supports undocumented instructions and flags and
>> 2.) is licensed under GPL or some compatible license?
>>
>> (The code in MAME/MESS is unfortunately not GPL).
>>
>> Thanks for any help,

Long ago I wrote a debugging program for the CPC called "Virtual Processor".
Since it is totally my own program I have no qualms about releasing the
source code and the little driver programs to assemble it using Maxam.

It certainly handles the undocumented Z80 functions e.g. DD CB 01 91 appears
as RES 2,C,(IX~1). Actually for all but a handful of instructions, it lets
the processor execute them itself and so show the flags as accurately set
by the processor.

Interested? If you can work out my real email address please send an address
I can post this to.

> how does the assembler explain where the scan line drawing the tv screen
> is while you are compiling code?

Sorry not sure what you mean here. This is not a task for the assembler but
for whatever program is being assembled, if that is relevant to the
program's function. There is probably a firmware call that will give this
info if it is absolutely necessary, but such low-level details can usually
be disregarded.
0 new messages