Z80 MBC2 - Re-compile QP/M Bios and Loader

by coopzone in Circuits > Arduino

971 Views, 2 Favorites, 0 Comments

Z80 MBC2 - Re-compile QP/M Bios and Loader

IMG_0572.jpg

If, like me, you find yourself in a position where you need to re-compile the QP/M bios for your MBC2 - then this is how you do it.

I documented the process, of how to recompile the existing version. It’s up to you to make changes to the actual Bios files, if you need to. I only made changes to be able to keep my installation of QP/M inline with the version of CP/M 2.2 Bios I am using (these changes are not shown just the process of how to)

The first part of the process is almost identical to the CP/M 2.2 Bios, so if you already have your build computer set up feel free to skip over that part.

The main difference is that QP/M has to load from the first track of the boot disk - not a .bin file like CP/M 2.2, described bellow.

Supplies

A windows machine to run the compiler on. I used a windows xp virtual machine running on a KVM, because it’s very small and will never go on the internet. But it works under windows 10 perfectly ok.

The TASM 3.2 z80 compiler, search for this on google, you should end up at https://www.ticalc.org/archives/files/fileinfo/25...

A copy of the SD zip file from the z80-mbc2 home page, at the time of writing it was https://www.ticalc.org/archives/files/fileinfo/25...

CPMTools for windows from http://www.cpm8680.com/cpmtools/cpmtoolsWin32.zip this is a 32bit version but works ok on 64bit systems.

Adding the Software to Your Build Computer

pic2.png
pic1.png

Once you have got your windows machine up and running, copy or download the files mentioned in the “you will need” section above.

Create a working directory on your machine, I suggest (to avoid a lot of typing and typo’s) you create a directory on drive C, for example c:\z80mbc . I strongly recommend that you avoid spaces in the names, if possible and long directory paths. Keep it simple.

Create a folder inside this directory for the TASM files to go in, c:\z80mbc\tasm

Create a folder for the SD card image to go in, c:\z90mbc\SD

Right click on each of the files and extract the contents to the directories you created above. So tasm.zip is extracted to c:\z80mbc\tasm and the scared zip file to c:\z80mbc\SD

To make some of the next steps easier you can also unpack cpmtool32.zip to another directory, for example c:\z80mbc\cpmtools.

Adding Your Tools to Windows Path

pic3.png
pic4.png

Depending on your version of windows do one on the following

Windows 10

Open the properties menu by right clicking on the “This PC” item from an explorer window.

Click on “Advanced system settings”, this will open a window called “System Properties” (You can also get to system properties in other ways, but I don’t use windows very much so this is my way!)

Click on “Environment Variables”

Windows XP

Click start button, right click on “my computer”, then you can click properties to get “system properties”.

Click on the Advanced Tab

Click on “Environment Variables”

When you have the Environment Variables window on screen you need to do two things;

Add a new variable

In the top part of the windows, under "user variables for ..."

Click New

For the Name type in TASMTABS

For the Value type in c:\z80mbc\tasm

Modify the PATH variable

In the bottom part of the window, under "System Variables"

choose (highlight) Path, then click Edit

At the end of the existing content add ;c:\z80mbc\tasm;c:\z80mbc\cpmtools

(Don't forget the semi-colon at the start!)

You now need to restart the computer for these additions to take effect.

Testing Tasm

pic10.png
number1.png
number2.png

In order to test we can compile an exact copy of the existing QP/M BIOS, we have to do a little more preparation. The files in this directory are:

BIOS QPM271 - S150918.asm - The main BIOS file, this is most likely the file you will be altering.

QPM271_ColdLoader - S160918.asm - this is the QP/M loader, it reads the first tracks from the disk image into memory. In a more traditional CP/m system this would be referred to as a bootstrap and would be in EEPROM or ROM. You should not need to modify this file it's already compiled and on the SD card image as QPMLDR.BIN

SYSGENQ - S140918.asm - This program is used in conjunction with the QP/M installer, again you norammly will not need to alter it, it already exists in the boot disk image ready for use. It essentially reads and writes the tracks used by the cold loader above.

Before we test our TASM install you need one more file, cpm22_Z80MBC2.asm, it's not in this directory by default as it's the same file used for cpm 2.2. We need this file to provide the original CBIOS/CCP for the initial boot of QP/M. You can copy this file form the CPM_22_Custom_BIOS directory.

Either use windows explorer to copy it or from a command (CMD) prompt do

cd c:\z80mbc\sd\src\QPM_271_Custom_BIOS

copy ..\CPM_22_Custom_BIOS\cpm22_Z80MBC2.asm .

You now need to change this file to include the QP/M BIOS, open the file with notepad:

search for "QPM" (CTRL-F, or edit menu and find) See above picture

change the file from:

;-----------------------------------------------------------------------
;                                Z80-MBC2
;-----------------------------------------------------------------------
;#include    "BIOS QPM271 - S150918.asm"  ; Included CBIOS for the Z80-MBC2
#include    "BIOS CPM22 - S030818-R140319.asm"  ; Included CBIOS for the Z80-MBC2
<br>

To:

;-----------------------------------------------------------------------
;                                Z80-MBC2
;-----------------------------------------------------------------------
#include    "BIOS QPM271 - S150918.asm"  ; Included CBIOS for the Z80-MBC2
;#include    "BIOS CPM22 - S030818-R140319.asm"  ; Included CBIOS for the Z80-MBC2
<br>

You should also check the value of iLoadMode in the copied cpm22_Z80MBC2.asm file, around line 40:

;-----------------------------------------------------------------------
;                                    Z80-MBC2
;-----------------------------------------------------------------------
iLoadMode   .equ    0       ; Set to 1 for iLoad mode (for testing), 
                            ; set to 0 for track 0 image generation, 
                            ; set to 2 for cpm22.bin binary file generation
;-----------------------------------------------------------------------

It needs to be at 0, this is the default - but check anyway!

Once done, save the file.

you can now run tasm:

tasm -b -g3 -80 cpm22_Z80MBC2.asm qpm22.bin

Note the different output filename, if all goes well you should see output like this:

c:\z80mbc\sd\src\QPM_271_Custom_BIOS>tasm -b -g3 -80 cpm22_Z80MBC2.asm qpm22.bin
TASM Z80 Assembler.       Version 3.2 September, 2001.
 Copyright (C) 2001 Squak Valley Software
tasm: pass 1 complete.
tasm: pass 2 complete.
tasm: Number of errors = 0

c:\z80mbc\sd\src\QPM_271_Custom_BIOS><br>

You are ready to make any changes you need to the BIOS! file.

Find Your Real Time Clock Address

Before you install the new version of the BIOS, part of the QP/M install needs to know the entry address for the real time clock routines. If you don't set this any time functions in QP/M will return "No Clock" as an error message.

To get the address, edit the LST file produced when you compile the qpm22.bin file, ie.

notepad cpm22_Z80MBC2.lst

Search for the TIMDAT label, Ctrl-f (or find) search for TIMDAT, you will find a section like this:

0855+  EC16             ; =========================================================================== ;
0856+  EC16             ; TIMDAT                                                                      ;
0857+  EC16             ; =========================================================================== ;
0858+  EC16             ; This ia a QP/M specific routine for the QP/M-to-real-time-clock interface   ;
0859+  EC16             ; to fully utilize the time/date stamping features of QP/M.                   ;
0860+  EC16             ; The address of TIMDAT must be specified during QINSTALL via option <2> of   ;
0861+  EC16             ; the QDOS installation menu (see pages 26-27 of the QP/M Installation Guide) ; 
0862+  EC16             ;                                                                             ;
0863+  EC16             ; NOTE: If the RTC is not present, IOS will give all 0s bytes. This is        ;
0864+  EC16             ;       "interpreted" by QP/M as a "NO CLOCK".                                ;
0865+  EC16             ; =========================================================================== ;
0866+  EC16             TIMDAT
0867+  EC16 C3 19 EC        jp      USERCLK<br>

Make a note of the second column HEX address, in this case EC16. Take the value off the line bellow the comments, just above the JP USERCLK jump instruction. Where it says TIMDAT.

Now you have the vale, you can exit the file and proceed with the QP/M intsall

Add the Bios to a New Disk Image

In this step we will make our own copy of the DS1N00.DSK boot disk and add our own version of the BIOS to it ready to complete the installation of QP/M

To start with make a temp folder of drive C to keep your working copies in. Open a CMD prompt and type the following

cd c:\z80mbc

mkdir temp

cd temp

Next copy the original disk image from the SD directory

copy c:\z80mbc\sd\DS1N00.DSK . 

Get the current files from the disk image:

cd c:\z80mbc\temp cpmcp -f z80mbc2-d0 DS1N00.DSK 0:* disk0

The above sequence will create another temporary folder inside the temp directory called disk0, them copy all the existing files from the disk image into the directory. Use DIR after to make sure you have the files.

Next we can format the disk image as a new disk, this is the only easy way to add the boot tracks to the disk image, without having to create a whole new disk from scratch. Note the “-b” option uses the BIOS we compiled above.

mkfs.cpm -f z80mbc2-d0 -b c:\z80mbc\sd\src\QPM_271_Custom_BIOS\qpm22.bin DS1N00.DSK

Now the boot tracks are updated, you can add the original files back to the image:

cpmcp -f z80mbc2-d0 DS1N00.DSK disk0/* 0:

You now have a bootable disk, it will actually boot CP/M not QP/M in the next step we use the QP/M installer to replace the CBIOS part of the CP/M system

Make sure you have a working copy of your boot up SD card, then copy the DS1N00.DSK file you create in this step to the root folder of the SD card it will replace the existing file.

Boot Into Your New Disk Image

Connect a serial terminal to the z80mbc2

hold the user switch, keep it held, press and release reset switch. When the user LED goes out and the IOS light flashes release the user switch.

You should now be at the "Boot" screen on the terminal, like this:Z80-MBC2 - A040618
IOS - I/O Subsystem - S220718-R240620

IOS: Z80 clock set at 8MHz
IOS: Found RTC DS3231 Module (26/10/20 16:46:45)
IOS: RTC DS3231 temperature sensor: 20C
IOS: Found GPE Option
IOS: CP/M Autoexec is OFF

IOS: Select boot mode or system parameters:

 0: No change (3)
 1: Basic
 2: Forth
 3: Load OS from Disk Set 1 (QP/M 2.71)
 4: Autoboot
 5: iLoad
 6: Change Z80 clock speed (->4MHz)
 7: Toggle CP/M Autoexec (->ON)
 8: Change Disk Set 1 (QP/M 2.71)
 9: Change RTC time/date

Enter your choice >

Use Option 8 to change the disk set to QP/M, When you select it you should load your QP/M BIOS. I would also recommend pressing reset, as i have seen the first load after option 8 fail several times. Like this:

IOS: Current Disk Set 1 (QP/M 2.71)
IOS: Loading boot program (QPMLDR.BIN)... Done
IOS: Z80 is running from now

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

Custom Version of Z80-MBC2 QP/M 2.71 BIOS - S150918

A>

Note I added the "Custom Version" above when I edited the BIOS File, just as a demo for this step.

At this point you are actually running CP/M 2.2 Cbios with the custom BIOS for QP/M, so things like the TIME command don't work, for example if you type TIME (should respond with date+time) you will get the CP/M 2.2 response of TIME? - it thinks it's a command on the disk and can't find it.

It's now time to install the QP/M replacement CBIOS onto the disk image.

Start the qinstall.com program:

A>qinstall

QP/M 2.7  Installation/Configuration Program  v2.1

QINSTALL uses your SYSGEN program to install QP/M
onto your disk.  After configuring your system, you will
be prompted for the name of your SYSGEN program.  This
utility should be available on one of your disks.

For QINSTALL to successfully finish, the system image on
disk and the system currently in memory MUST be identical.

(Use <CTRL+C> to abort the program.)

        Do you wish to proceed? (Y/N):  

Then answer Y to proceed.

You will be asked next about QCP Settings (you can play later !) for now say N

Do you wish to examine and/or modify
        the default QCP settings? (Y/N):N

Next you will be asked about QDOS Settings, press Y

        Do you wish to examine or modify
        the default QDOS settings? (Y/N): Y

You will have a menu like this:

     ***   QDOS System Installation settings   ***

<0>     Save character obtained during console scan .. YES
<1>     BIOS supports BDOS error code table .......... NO
<2>     Address of time/date jump vector ............. DISABLED
<3>     Drive/user search feature .................... ENABLED
<4>     Automatic disk re-log ........................ ENABLED
<R>     Restore initial settings
<X>     Exit QDOS installation

        Enter option:  <br>

At this point you need to enter the HEX number from Step 4 above (find your real time clock address)

Press 2, and enter the HEX address EC16, if you made no changes to the bios, in my case it's EC04 since i added some text etc.

Enter address of time/date vector in hex (0 to DISABLE): EC04

Now you can exit the QDOS menu and proceed.

The next screen shows:

Enter name of your SYSGEN program and press RETURN.
(Specify drive if necessary; do not use .COM extension):SYSGENQ

Enter the special version of sysgen, called SYSGENQ

You will then see:

***  Creating 59k QP/M image  ***

QINSTALL will now execute A:SYSGENQ.COM.
You must instruct A:SYSGENQ.COM to read the system tracks.

When the READ is complete, exit the SYSGEN program.
The message "*** QINSTALL searching for system image  ***"
will appear followed by further instructions.

Press <C> to continue  -OR-  <A> to abort --<br>

Press C to continue:

SYSGENQ - S140918 - Z80-MBC2
CP/M 2.2 SYSGEN-like Utility

Use only to install QP/M 2.71 using QINSTALL.COM
WARNING: W command will overwrite system track!

Read system tracks and load to RAM or write them back to disk? [R/W] >

The first time you see this message choose R to read the system tracks, you will then get:

Reading... done

***  QINSTALL searching for system image  ***

System image found starting at 0900H.  Installing QP/M.

Your SYSGEN program will now resume execution.
You must instruct the program to WRITE the system tracks.

Press <C> to continue  -OR-  <A> to abort --

Again press C to continue:

SYSGENQ - S140918 - Z80-MBC2
CP/M 2.2 SYSGEN-like Utility

Use only to install QP/M 2.71 using QINSTALL.COM
WARNING: W command will overwrite system track!

Read system tracks and load to RAM or write them back to disk? [R/W] >

This time press W to write the new QP/M and BISO back to the disk tracks:

Writing... done
A>

You can now press reset and boot back into your new QP/M bios. If you now type TIME at the prompt it will be running the full version of QP/M and will respond like this:

Z80-MBC2 - A040618
IOS - I/O Subsystem - S220718-R240620

IOS: Z80 clock set at 8MHz
IOS: Found RTC DS3231 Module (26/10/20 17:10:48)
IOS: RTC DS3231 temperature sensor: 20C
IOS: Found GPE Option
IOS: CP/M Autoexec is OFF
IOS: Current Disk Set 1 (QP/M 2.71)
IOS: Loading boot program (QPMLDR.BIN)... Done
IOS: Z80 is running from now

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

Custom Version of Z80-MBC2 QP/M 2.71 BIOS - S150918

A>time
26-Oct-20       17:10:56
A>

Your up and running with the new BIOS, note the "Custom Version" text above. You should probably read the rest of the QP/M documentation at http://www.microcodeconsulting.com/z80/qpm.htm?fbc...

Fin