Introduction: Z80-mbc Emulator From the RC2014 Emulator

The RC2014 is a z80 based DIY computer. Some time ago an emulator to simulate the hardware was published. Here we are using part of an RC2014 software emulator. The emulator has grown over time and now includes an MBC2.

In this article we will only build and use the MBC2 emulator, I used this to test and build software ready to run on a real z80-mbc2. This may sound a little odd, but when you are working on a real z80 computer you have to take it with you. Not always very easy or convenient to do. Hence I can run this on my laptop without having to pack extra hardware.

Supplies

You will need access to a Linux based computer, I have used a raspberry PI and Linux installed on a Intel I5 laptop. Both work fine.

You will need to install the C compiler and development tools, depends on your distro. Here I give examples based on Debian/ubuntu.

You need “git” installed to download the projects source code.

Once you have the above installed your ready to go…

Step 1:

 apt -y install build-essential git


Step 2:

root@deb1:~# git clone https://github.com/EtchedPixels/RC2014.git

Cloning into 'RC2014'...

remote: Enumerating objects: 1987, done.

remote: Counting objects: 100% (613/613), done.

remote: Compressing objects: 100% (87/87), done.

remote: Total 1987 (delta 537), reused 558 (delta 526), pack-reused 1374

Receiving objects: 100% (1987/1987), 1.03 MiB | 2.35 MiB/s, done.

Resolving deltas: 100% (1211/1211), done.

Step 3: Patch the Mbc.c File

With the current version (as of Nov 2022), the mbc2 emulation won’t start qp/m 2.7. This is due to the loader file being very small, less than 1024 bytes. mbc2.c has a line in it that says error “short image” if it’s les than 1024 bytes.

So to make qp/m work. You need to patch the mbc2.c file to allow smaller image sizes, below is a patch that changes the value to 192 bytes. You can use the patch as a reference to manually change the line or past it to a file and use linux patch to change the file:

patch <mbc2.patch

--- mbc2.c.orig 2022-10-31 13:32:02.141492142 +0000
+++ mbc2.c      2022-10-31 14:13:50.585566003 +0000
@@ -442,7 +442,7 @@
                exit(EXIT_FAILURE);
        }
        l = read(fd, ram + addr, 65536 - addr);
-       if (l < 1024) {
+       if (l < 192) {
                fprintf(stderr, "mbc2: short image '%s'.\n", image);
                exit(EXIT_FAILURE);
        }


You can also download the patch file from here

https://drive.google.com/file/d/1feT0YDTR-rE1dGPVx2HaS-oAc_cZs307/view?usp=sharing

Step 4: Compile Mbc2

Compile the mbc2 executable:


root@deb1:~/RC2014# make mbc2
cc -MT mbc2.o -MMD -MP -MF .deps/mbc2.d -Wall -pedantic -g3 -Werror   -c -o mbc2.o mbc2.c
cc -MT ide.o -MMD -MP -MF .deps/ide.d -Wall -pedantic -g3 -Werror   -c -o ide.o ide.c
make --directory libz80
make[1]: Entering directory '/root/RC2014/libz80'
cd codegen && make opcodes
make[2]: Entering directory '/root/RC2014/libz80/codegen'
gcc -g -o mktables mktables.c
./mktables
Reading specification...done
Generating opcode implementations...done
Determining opcode prefixes...DD FD ED CB DDCB FDCB 
Outputting table main...done
Outputting table CB...done
Outputting table DD...done
Outputting table DDCB...done
Outputting table ED...done
Outputting table FD...done
Outputting table FDCB...done
cat opcodes_impl.c | grep "static void" | sed "s/)/);/g" >opcodes_decl.h
make[2]: Leaving directory '/root/RC2014/libz80/codegen'
cc -Wall -ansi -g -c -o libz80.o z80.c
make[1]: Leaving directory '/root/RC2014/libz80'
cc -g3 mbc2.o libz80/libz80.o -o mbc2


You now have the mbc2 executable file.

Step 5: Unpack the Distribution Files

You now need a copy of the SD-CARD files to boot from, the original zip file can be downloaded from:

https://cdn.hackaday.io/files/1599736844284832/SD-S220718-R240620-v1.zip

(this is the actual authors project site: https://hackaday.io/project/159973-z80-mbc2-a-4-ics-homebrew-z80-computer)

Now unzip this file into a directory on your filesystem. To do this first create a director to unzip the files to:


mkdir SD
cd SD
unzip ../SD-S220718-R240620-v1.zip


Now copy the mbc2 executable file you created above into this folder.

cp ../RC2014/mbc2 .


You are now ready to go





Step 6: Running the Emulator

To boot cp/m 2.2

./mbc2 -s 0 -b cpm22.bin -a 53728
Loaded 6942 bytes at D1E0.
Z80 emulation flat


Z80-MBC2 CP/M 2.2 BIOS - S030818-R140319
CP/M 2.2 Copyright 1979 (c) by Digital Research

A>


To boot CP/M 3

./mbc2 -s2 -b CPMLDR.COM -a 256 
Loaded 5120 bytes at 0100.
Z80 emulation flat


Z80-MBC2 CPMLDR BIOS - S180918

CP/M V3.0 Loader
Copyright (C) 1982, Digital Research

 BNKBIOS3 SPR F600 0600
 BNKBIOS3 SPR 5300 2D00
 RESBDOS3 SPR F000 0600
 BNKBDOS3 SPR 2500 2E00

 60K TPA

Z80-MBC2 128KB (Banked) CP/M V3.0
Z80-MBC2 BIOS Modules: S200918, S210918-R170319, S220918-R180319, S290918,
 S170319

A>


For booting QP/M try

./mbc2 -s1 -b QPMLDR.BIN -a 128
Loaded 245 bytes at 0080.
Z80 emulation flat


Z80-MBC2 QP/M 2.71 Cold Loader - S160918
Loading... done


Z80-MBC2 QP/M 2.71 BIOS - S150918
QP/M 2.71 Copyright 1985 (c) by MICROCode Consulting

A>


UCSD Pascal

./mbc2 -s3 -b ucsdldr.bin -a 0
Loaded 1670 bytes at 0000.
Z80 emulation flat
64K UCSD p-System IV.0 CBIOS V1.1 for Z80-MBC2, Copyright (C) 2019 by GmEsoft
Build: Aug 24 2019 - 21:57:34

Reading Secondary Bootstrap

Booting to UCSD Pascal

And the main screen...

Command: E(dit, R(un, F(ile, C(omp, L(ink, X(ecute, A(ssem, D(ebug,? [IV.0 B3h]

Welcome SYS1, to

U.C.S.D. p-System IV.0

Current date is 24-Aug-19


CollapseOS

./mbc2 -s4 -b cos.bin -a 0
Loaded 6243 bytes at 0000.
Z80 emulation flat
CollapseOS


So far I have not yet managed to get Forth or Basic47 working.


Done