Debug.Asm – Z80 Development Tool

If you are going to be doing any serious z80 programming then you will quickly find a need for this program. It is code that you can include at the end of your z80 source code and then call it with a simple JP CodeDump command. When you do this it will show you the values of all the registers when it was called and let you move around memory starting at the value you put in the source code at CD_CurLoc.  The only caveat is that you need to be in 32 column mode when you enter it. Any other mode will be hard if not impossible to read.

Download

Hello World – Z80 development

(I want to apologize in advance, I am not a fantastic writer)

I like to code in machine language. Using ML you have (almost) complete control over the Adam and can make it do things as fast as it is possible for it to do it.

Writing ML code on the actual Adam for me is hard because I have been been using modern computers for so long I am used to being able to cut and paste, have multiple files, compile fast etc.  So I like to create my code in Windows, compile it and then transfer it to a disk image for testing in the AdamEM emulator and if I want moving it to the real hardware.

Doing so has involved using my editor of choice (ConTEXT), and then using DosBox to emulate a DOS machine and compiling the code using the TeleMark cross-assembler. On a 32 bit machine I could have eliminated DosBox and just used the Command prompt in Windows, but with a 64 bit machine DosBox is required because TeleMark is a 16 bit program.  Once I compiled the program I would then use various methods to get it into an image, mostly WRDISK and sometimes TDOS if I was programming for a CP/M environment but I always felt these were cumbersome so I have been working on a method of creating a disk (or tape) image of the compiled program I am working on and have it just load when I start the emulator (or real hardware). After disassembling the Smart Basic Loader, studying the EOS programmers Guide and banging my head against the wall with disk interleaving I finally was able to create a “simple” process to take my machine language source code, compile it and create a working disk image using just one command.

Hello World

At some point every programmer has made a “Hello World” program. In Smart Basic this is as simple as:

10 PRINT “Hello World”

Writing one in machine language to use under EOS is a little more convoluted to get started as you have to initialize the Video Display Processor to even see anything. Once you get that setup then you can print to the screen.  (Click here to view the source code).

Compiling the Code

To compile the code use the Assemble batch file. If all goes well and there are no errors you will have a usable disk (and tape) image. If you look at the assemble.bat file you will see how it works:

echo off
cls

rem This batch file will assemble the source code file
rem passed on the command line for example: assemble filename
rem where filename is the name of z80 code you wish to
rem assemble and has the extension of .asm. Do not add an
rem extension. The batch file will use filename for the
rem name of the resulting disk and tape images it creates

rem Did they pass a filename to assemble? If not then exit
if "%1"=="" goto NoFileName

rem Do some clean up of old .obj, .lst, .dsk and .ddp files
if exist %1.obj del %1.obj
if exist %1.lst del %1.lst
if exist %1.dsk del %1.dsk
if exist %1.ddp del %1.ddp

rem Now to assemble the file passed TASM will return an error if
rem we could not assemble it and if that happens we will exit

tasm -80 -b %1.asm
if ERRORLEVEL 1 goto AsmError

rem The code assembled ok so now we need to put it in the disk
rem image for use with the emulator and a real Adam. If you are
rem curious how ImageMkr works just run type imagemkr at the prompt

imagemkr %1.obj %1

rem We are all done so lets exit

goto Exit

:NoFileName
echo No file name was passed to assemble
goto Exit

:AsmError
echo Error while assembling
if exist %1.obj del %1.obj
if exist %1.lst del %1.lst
goto Exit

rem All done so exit
:Exit
echo on

Download:

Help – resolved

Can you do the following and let me know your results:

  1. Download this zip file
  2. Unzip it and start AdamEm with File Manager as disk 1 and the image called Heather as disk 2
  3. Press F5 to switch to disk 2, F2 for Media Functions and F4 for edit
  4. Press F3 for Block Number and type in a 2 and hit enter.
  5. Press Enter again
  6. Now you are looking at Block 2 Sector 0. On a real Adam press Home and Up arrow until you are looking at Sector 4. In the emulator press the “5” on the keypad and the up Arrow (at same time)
  7. Does it look like the screen shot to the right? All zeros?
  8. If it doesn’t let me know
  9. If it does then  humor me and go to Hex Edit and upload the file called HEATHER.DSK and then scroll down till you get to the section starting with 00000A00
  10. You will see that there is code there, but the same corresponding bytes in the image are zeros. You can verify this by scrolling up a to sector 3 in the image on the emulator and seeing the last of the code that loads

Please let me know your results – either here or on Facebook

 

Thanks to the information from Eric I was able to determine that I was not taking into account the interleaving of the data on a disk image. The tape images do not use that so it confused me when I started working with disk images. If you are curious how it works here it is where the first number is a 256 byte sector and the second number is the actual sector it should go in. This is using 4kb blocks:

0 -> 0
1 -> 1
2 -> 10
3 -> 11
4 -> 4
5 -> 5
6 -> 14
7 -> 15
8 -> 8
9 -> 9
10 -> 2
11 -> 3
12 -> 12
13 -> 13
14 -> 6
15 -> 7

 

MakeRRom – a simple utility

Based on a conversation I had on FaceBook and after reviewing the disassembly of the program written by Stephen Munnings in 1985 called GameSave that would dump the contents of a cartridge plugged into the Adam to a file in CP/M that you could then execute I have created a newer hybrid version of this: MakeRRom.

MakeRRom (Make Run-able ROM) is a program written in Turbo Basic, an old MS-DOS compiler created by Borland that I have been using for almost 30 years. MakeRRom will take a PC file that contains a ROM cartridge dump and create a CP/M (or TDOS) compatible program that you can then import into a disk image for use in the ADAMEm emulator or copy over to your real Adam. Unlike GameSave you do not have to have the cartridge and you create your files on your PC.

How it works:

The heart of MakeRRom is a 32 byte Z80 assembler routine that handles setting up the Adam to execute the file as if it was a ROM cartridge:

The program MakeRRom then takes this code, appends the code for the ROM cartridge and then saves it as a .COM file to be used in CP/M or TDOS.

When you run the created file the Z80 code will copy the appended ROM data to 8000H (the upper 32KB bank of RAM) and then copy the small loader called JumpCode to the top of memory and execute it. JumpCode in turn sets up the Colecovision OS7 Rom in the lower 32K bank and jumps to the cartridge start point.

How to use MakeRRom

MakeRRom.exe is a 16 bit program so you may need to run this either in DosBox or on an older PC. To use it, copy MakeRRom.exe and the ROM file you want to work with into the same folder. Then at the dos prompt type:

C:\> makerrom filename.ext

And after a few moments it will create a file called filename.com that is your ROM file and the loader.  Then you can use the process I described here to import it into TDOS or CP/M.

In the download below I have included a copy of the Cabbage Patch Kids Adventure ROM called patch.rom and the resulting patch.com file. If you use Debug to view the ROM file and the .COM file you will see how the first 32 bytes of the .COM file are the Z80 loader.

Cool – but why do it?

The simple answer is because I can. The more complex one? I can download all the Colecovision ROMs online, batch convert them into .COM files, import them all into a TDOS IDE image, copy the image to compact flash and now have all of them available to run at anytime on my Adam 🙂

Downloads:

Random Thoughts

I was just looking through some older newsletters and I came across some advertising for Adult software for the Adam. Not to be “strange” but I would be interested in seeing this software. Anyone have any of it? It is on Page 5 and 6 of the Network Adam newsINFOletter linked below: