Disassembling my old code from 1988 – part 3

Introduction

This is part 3 of a blog series I’m doing to catalog my adventures through some of the programs I wrote back in 1988.

Other parts of this series, including this one are listed below.

  • Disassembling my old code part 1 – Getting started with WinAPE
  • Disassembling my old code part 2 – Setting screen mode & Soft 968
  • Disassembling my old code part 3 – Text operations <—- you are here
  • Disassembling my old code part 4 – Set cursor position & disc cache
  • Disassembling my old code part 5 – Get Shift key and set translate
  • Disassembling my old code part 6 – Processing disc activities
  • Disassembling my old code part 7 – Drawing rectangles
  • Disassembling my old code part 8 – Processing HEX in the left pane

So let’s get stuck in. I resumed where I left off in the last part and that was to continue converting the source code into meaningful blocks of code, so that means converting the ASCII to readable text and once done, modifying the labels pointing to those text blocks. I also hope to understand how those blocks of TEXT are formed in order to understand how the functions that print them to screen know where the beginning and end of a TEXT block occurs.

At the moment I’m doing this on my Surface Book 2, but it would probably make more sense to run this on my gaming computer downstairs in my office to avail of my 3 monitor setup, I might try that later.

In the screenshot below you can see the WinApe emulator running Disced, and in the left pane we have the disassembly showing the section I’m working on (Press F7 in WinAPE to disassemble), with the source code on top and the hexadecimal/ASCII representation of that code to the right of the lower left pane.

In the Lower right, you can just make out that I’ve got Notepad++ with my source code  that I exported in Part 1 and I’m slowly adding the text but more importantly including every space, and opcode that is listed.

Marking the end of a block of text

I’ve already noticed that two lines of text ended with a NOP (or NULL) code (&00). For example:

TEXT "Press Control + H for Help or Press ESC to Exit",&00

Hopefully this means I’ve found out how my TEXT writing functions are working within the program as those functions must know where the beginning and end of a text block is.

We already know that the start of the text blocks are referred to within the code as Labels, but that only marks the start of the text block, it doesn’t show where it ends.

Here you can see two of those NOP (or NULL) codes at the end of some TEXT blocks.

A slight scroll down through the code and I can see this pattern of ending TEXT blocks with NOP codes (or NULL) repeated, so I think I’m on to something here.

I also noticed that if  I want to see the text within the program on WinAPE that I have to close the disassembler and activate that page in Disced before going back to the disassembler, I guess this is because it freezes the program while disassembling.

If you look at the repeated blocks of code after some TEXT you’ll see

 &0d,&0a,&0a

This pattern signifies a carriage return (&0d) followed by two line feeds (&0a). I use this pattern or a similar pattern with just one line feed repeatedly throughout the text blocks.

&0d,&0a

This is to make the TEXT displayed on screen more readable (formatting the text).

This use of line feed and carriage returns to denote Newlines is explained here and is not Amstrad CPC specific. My next challenge was the character set of the Amstrad CPC in relation to up arrow, down arrow, left arrow and right arrow. These characters are listed in the following wiki.

https://en.wikipedia.org/wiki/Amstrad_CPC_character_set

But when I looked at CharMap in Windows 10 I didn’t see anything quite the same, so I instead added those special characters as byte codes in the TEXT blocks, like so.

Turn off text cursor

After reading that Amstrad Character MAP wiki page, I could see that the &02 code was used to turn off the text cursor, this makes sense as it was just after the the title text and before the graphics routines start on the front page of Disced, so I added a comment to that effect in my source code.

This brings back memories to me from when I coded it originally, I think that if you didn’t turn off the text cursor prior to drawing graphics (lines etc), that you’d see a flashing cursor move across the screen, I can experiment with this later on when I actually try to Assemble the finished source code (if I ever finish it :P).

The next oddity I found was the use of &07,&18 just before the last two (Y/N) prompts.

&07,&18

As you can see highlighted here…

So when I looked at the WIKI page it explains that those codes could be for BEEP and  to exchange the PEN and PAPER inks (reverse video effect).

So I tested it, and sure enough, when I press ESC in Disced it BEEPS and shows the text in reverse video ! as you can see here in the GIF (it won’t BEEP however, but trust me that’s what happened).

So I decided that was enough for this part ! here’s the final look at the source code I modified this morning.

Recommended reading

Please join me in Part 4 where we’ll no doubt learn more about the inner workings of Z80 machine code on a CPC.

Posted in Disassemble, Disced, WinApe, Z80 Machine code | 6 Comments

Disassembling my old code from 1988 – Part 2

Introduction

In Part 1 of this series of blog posts I showed you how I started disassembling one of my old programs that I wrote in Z80 Machine code way back in 1988, my end goal is to not only have the source code all clearly laid out and readable, but once it’s done, I want to edit it and re-release it with a 2020 date stamp (assuming I get it finished this year).

Other parts of this series, including this one are listed below.

  • Disassembling my old code part 1 – Getting started with WinAPE
  • Disassembling my old code part 2 – Setting screen mode & Soft 968 <—- you are here
  • Disassembling my old code part 3 – Text operations
  • Disassembling my old code part 4 – Set cursor position & disc cache
  • Disassembling my old code part 5 – Get Shift key and set translate
  • Disassembling my old code part 6 – Processing disc activities
  • Disassembling my old code part 7 – Drawing rectangles
  • Disassembling my old code part 8 – Processing HEX in the left pane

 

But it’s harder than I thought, just looking through the code I realize that in order to properly label things in the source code I’ll need to re-learn about Z80 Machine code and how assemblers (like MAXAM which is what I will use to compile it) deal with it, so I’ve started doing that.

For example, I needed to know that the Assembler can use directives in the source code to decide what to do with various data. So how did I find out about that, well there’s a great website called https://archive.org and in there you can search for many things, I searched for Amstrad Assembly

and that revealed quite a few hits, I selected a few of the books listed and found the following page *after searching for DEFB* in a book called Mastering Machine Code on your Amstrad 464 664 6128.

Armed with that knowledge I continued reviewing the disassembled code side by side with the source code and started filling in some data.

Such as the following block of code used for changing the mode to 2 and then setting the ram memory address to &C000.

In the screenshot below you can see the WinAPE debugger showing the block of code i’m interested in, and to the right you have the source code opened in the excellent notepad++ which I’m manually editing to add clarity.

In this very small block of code a few things are happening. First of all the block of code (I’m not sure what we call that yet) is marked with a label which contains some descriptive text and has a colon appended to the label name “:” e.g.

change_screen_mode:

directly after that label, you’ll see I’ve used a semi-colon “;” to allow me to type in clear text and add notes about what each line is doing.

change_screen_mode: ; change screen mode

These are comments to make it clear to me what is happening in certain areas of code.

The label allows you to add labels to blocks of code in your source code and the assembler will rewrite those labels as hard coded addresses when you compile the source code.

As I’m re-learning Z80 machine code and assembly language I need to also understand exactly what each block of code is doing in this program, it’s going to take a lot of time but I think it’ll be worth it (for me at least).

If I look at Soft 968 which describes the innards of  the Amstrad Firmware (you can see that book here) you’ll see exactly what the firmware address &BC0e does and what it needs to carry out the function.

So we can see what this firmware address does. What about the remaining instructions, well I can see that I’m loading the register A with a value of &C0, and then I jump (rather than call) to an address of &BC08.

Here’s what Soft 968 tells us about that firmware call.

 

How do I actually call my block of code ? It actually happens at the start of the program using a call label format.

Actually, the change_screen_mode: block of code has me confused as I don’t see how it’s returning back to the source call, there’s no RET statement, but maybe after changing to mode 2 and setting the memory address to C000 the jp doesn’t need a RET.

The data available online for Amstrad is truly impressive and I’m really enjoying re-learning about how this all works. So much so that I purchased an original Soft 968 from Jason Brooks (member of the Amstrad CPC 464 facebook group).

Next I moved on to starting to modify some of the text in the code, as you can see here.

And after chatting with Jason Brooks and Chris Perver in that facebook group, it seems I need to edit this section so it looks something like this, I do recall TEXT being used in Maxam so maybe this is how I did it originally. I won’t really know until I try to compile it later.

So as you can see the progress is slow but I have to relearn all of this while I’m doing it, and I want to be sure I understand everything.

Well that’s it for part 2, please join me in the part 3 and we’ll see how far I’m getting.

Recommended reading

Posted in Disassemble, Disced, MAXAM, WinApe, Z80 Machine code | 6 Comments

Disassembling my old code from 1988 – Part 1

Introduction

I’ve always regretted losing the original discs (and CPC computer itself) that came with my original CPC 6128 as those discs contained every program I wrote using Z80 machine code. Losing that source code and all the comments I had inserted at the time is a major bummer, I’d love to look through it today.

Other parts of this series, including this one are listed below.

  • Disassembling my old code part 1 – Getting started with WinAPE <—- you are here
  • Disassembling my old code part 2 – Setting screen mode & Soft 968
  • Disassembling my old code part 3 – Text operations
  • Disassembling my old code part 4 – Set cursor position & disc cache
  • Disassembling my old code part 5 – Get Shift key and set translate
  • Disassembling my old code part 6 – Processing disc activities
  • Disassembling my old code part 7 – Drawing rectangles
  • Disassembling my old code part 8 – Processing HEX in the left pane

I wrote the code using a ROM in a Rombo Rombox called MAXAM, it was an assembler/disassembler/text editor for Amstrad CPC and it was using that hardware that I learned how to program in Z80 machine code.

This blog post is going to explain how I’m trying to get back into my old code and to see why I coded it the way I did, I will slowly work my way through the code and document it here.

This is the first part, how I actually disassembled my old Z80 machine code on a Windows 10 computer using the WINAPE Amstrad CPC Emulator. I wrote this code back in 1988 and I was 21 years old at the time, a long time ago indeed, I’m 53 now at the time of writing this blog post.

I didn’t instantly understand how to program in Z80 machine code, I had to teach myself by trial and error over a period of years, and that involved reading books and acquiring hardware to assist me to program (such as Maxam). Back then the internet was not really a thing so anything you wanted to learn was done via college courses, books, magazines or strangely enough Encyclopedias.

So now you have an idea of what I’m trying to do, let’s get on with it.

Download Winape

Head over to http://www.winape.net/ and download the latest version of the software. Extract the zip file somewhere useful.

Download Disced

Download Disced (which is what I will be using to disassemble) from here.

Now that you’ve got what you need, start Winape by clicking on the winape.exe file.

When the program loads, click on File, select Drive A: then selct Insert Disc Image…

Point it to a disk image file (file.dsk) such as my disc called niall.dsk

Click Open. In Winape type the following

|a

and then press

Enter

Next, type

cat

and then press

Enter

Here’s the output.

So those are 3 programs I wrote back in 1988 and my intention is to disassemble all 3 and re-write (with comments) the source code. But how do we do that ? First of all, you could load one of the applications and then run it, they are three basic listings which poke in the machine code into RAM.

To see what those basic programs look like, let’s load disced.bas and then change the mode of the screen to 2 and then type list.

Type

load "disced.bas

then

mode 2

then

list

This will show all of the text in the basic listing.

If you look at the listing in detail you’ll see it’s pokes the machine code instructions into address memory &9000.

Ok, now that we have the data loaded, let’s run the program.

Type

run

then press

Enter

You should see Disced load.

Disassembling the code

Ok, now that we’ve got a program up on screen, how do we disassemble it. Well I know that my code is loaded into the CPC ram at the following address &9000, so we need to disassemble from that address onwards to see the actual Z80 machine code. To bring up the disassembler built into Winape, press F7.

A little disassembler window should appear like below.

Maximize the window and click on the hand icon to enter an address, enter 9000 and press enter.

The code will be revealed

Select the first line (line &9000) and scroll down to where the code ends (at &962e)

Exporting Z80 code to file

Now that you’ve marked the code, let’s export it to a file. Right click on the marked code and choose Disassemble from the options.

And next select the output location to File, and change the Number format as well if you wish

Once done, open the exported .asm file with Notepad++

Here’s the resulting output and I’ve started adding comments to my code. The first ORG &9000 tells the assembler to load the code at that address

 

and the first call is to a block of code which loads the A register with a value of &0002 and then calls an Amstrad Firmware Jumpblock which does a mode change, let’s look at that little block of code at L933D

how do I know, because I looked up the codes here.

90 #BC0E    SCR SET MODE    Set screen into new mode.

So that’s it ! this is the end of Part 1 of this new mini-series, please continue on to Part 2.

Resources

Cheers

Niall

Posted in Disassemble, Disced, MAXAM, WinApe, Z80 Machine code | 6 Comments

Amstrad CPC 472 facebook group

Introduction

This is an extremely short post to let you know I’ve created a Facebook group devoted to the Amstrad CPC 472 – we will use this group to post about anything related to the Amstrad CPC 472 including for sale ad or photos of newly acquired 472’s etc.

You can join it at the following link

 

thanks !

cheers

niall

Posted in CPC 472 | Leave a comment

My second CPC 472 !

Well I think i’ll take a break from buying CPC’s as i’ve now got 7 of them,

2x CPC 472

2x CPC 664

2x CPC 464

1x CPC6128

This is 6 more CPC’s than I had back in the 80’s, oh well, it’s fun. Yesterday my 2nd CPC 472 arrived and it’s working great, it even came with a Colour Monitor (in Spanish) and a game and the TV modulator. I’ve no idea what I’ll do with the TV modulator. Oh it also came with a joystick.

So here it is

I have seen read error a and read error b on some tape games but it improved after I cleaned the read head with IPA alcohol. I played my first game on it, Airwolf. Everything works perfectly but I can hear something rattling around on the inside so I’ll need to open it up and inspect it.

There you can see the ‘new’ monitor sitting on top of my old one, it works but when i adjust the brightness knob on the right side it flashes white across the screen, so that probably needs to be addressed.

Here’s the game that came with this CPC, it’s called Satan 2, seems to be a very colourful box.

and here’s the QuickShot joystick which looks brand new 🙂

The photos below are all from the ebay ad for posterity sake.

Posted in CPC 472 | Leave a comment

CPC 472 user manual arrived in the post

I bought this manual on the Spanish version of ebay, and it arrived today !. The interesting thing to note is that the cover states CPC 464 but the manual’s title stated CPC 472.

The CPC472 came with some bizarre aspects, too. Reading 464 on the cover, but 472 on the bookneck. And, claiming that the 72K RAM would be required because of using the ROM of the CPC664 (whilst, the real CPC664 has only 64K RAM).

You can see photos of it here.

 

Posted in CPC 472 | Leave a comment

My second CPC 464

Introduction

I got this grey keyed 464 in February 11th or so 2020, but never got around to posting about it here.

But, better late than never 🙂

Unfortunately It wouldn’t power on at all.

Dead !

The motherboard is much smaller than the one in my original colour CPC 464, and the following wiki shows the different motherboards manufactured for CPC’s.

http://www.cpcwiki.eu/index.php/Mainboard_Versions

 

So I took it apart and found a loose connection, and after wiggling it (I’m pointing at the connection), the computer came to life !

This particular CPC was made in Germany using Schneider parts (keyboard and colouring) but made after the partnership with Amstrad/Schneider ended, so they used the parts remaining, in other words the grey keyboard, but with the Amstrad logo.

for details on the keyboard types see here https://www.cpcwiki.eu/index.php/Keyboard_Versions

and for help with non starting CPC’s see here

www.cpcwiki.eu/forum/cpcwiki-discussion/cpc-464-with-no-display

Posted in CPC 464 | Leave a comment

Today I got a CPC 472 !

I’m growing my collection bit by bit, after doing a swap with Noel Llopis (in Spain), I got back a CPC 472 in the mail today, and it’s in lovely condition.

 

here’s the basic info (notice, BASIC 1.0) and it has the Spanish ROM, so (s1)

Here’s my entire family of CPC’s together.

Posted in CPC 472 | Leave a comment

My 3rd 664 ! and this one is lovely !!

Introduction

I don’t know what’s happening, maybe it’s my age (53), or maybe it’s Corona (Covid19), or maybe I’m just re-living my youth, but lately I’ve been very interested in anything Amstrad CPC 664 related.

When these old CPC’s come up on ebay, they sell very fast indeed, or if it’s an auction, they easily sell for 400 Euros or more. A year ago it was 200 Euros. There is a lot of demand for these rare CPC’s (only 70,000 built, and according to Amstrad Action, Issue 1, Oct 1985, page 8, the 664 was produced only from May until August 1985).

Here’s the new one (bought July 3rd, 2020), it works perfectly and looks awesome.

For comparison details you can see my second 664 on top of my CPC 6128, and that was before I completed retro-brighting it which you can read about here.

 

 

 

Posted in CPC 664 | Leave a comment

Retro brighting attempts on a CPC 664

Introduction

Since I got my CPC 664’s, I was very interested in getting the blue keys looking deep blue just like in so many photos I’ve seen of the original CPC 664’s.

So after a wee bit of research I attempted two different methods, both with mixed positive results, the first method was to let the sun’s power alone ‘treat’ the keyboard, and the second method was with 6% peroxide and sunlight.

Yes I could have used stronger peroxide but that might cause damage, either way I’ll use the data I’ve gathered in these attempts to fine tune how I do retro brighting in the future.

Method #1 – Sunlight

The first method involves placing the keyboard itself out in the sunlight for a few hours over a couple of days. So that was approx 4 hours per day over a 2 day period where it was sunny (no clouds).

Here’s the result of leaving it outside for a few hours over a couple of days in the May sunshine.

Before pic

After pic

This method did lighten the overall colour of all the keys on the keyboard, and that was exactly what I wanted, but I also I wanted to see the blue colours pop out at me. So that meant more methods to try.

It did improve the look, that’s for sure, for example look at the spacebar and the left Shift and Caps lock keys, they are definitely improved, the yellowing is almost all gone!

If you do try this method, remove the keyboard assembly from the computer case, and place it outside on a table and keep an eye on it to verify what happens.

Method #2 – Peroxide  & Sunlight

Next I tried using weak peroxide gel (6%) from ebay (hair gel) in conjunction with sunlight from fairly sunny days in July. Normally people use a strength of 12% or up to 30% so I wanted to start gently as 30% will definitely get a good result but can also whiten your blue keys in patches, and you don’t want that.

Warning !

Too much bleach or sunlight can cause damage ! If you want to see what 30% can do (including the white patches), see this photo (not mine), look closely and you’ll see that the ESC key, ENTER keys and left cursor keys (and other) are bleached/whitened.

Retro brighting with 6%

Note that removing the blue keys is fairly easy to do (using a key puller tool), but getting them back in (with the associated metal bits) took me a few hours to do as the metal bits are very fiddly. Be Patient, you will succeed.

Simply place the keys you want to brighten in a suitable glass or bottle and add the 6% gel, make sure to cover all the keys and stir regularly so that the most yellow keys get properly exposed to the sun.

In this photo you can see that I added only all of the blue keys into a suitable glass and poured in enough gel to cover them. Also in the glass is a fork which I used to stir the mixture.

After they were out for a few hours (maybe 5 in total), I washed and dried each key and made sure there was no gel remaining. I used a toothbrush to assist in removing the gel (and warm water).

  

Then i spent a few hours reassembling them back into their correct position.

Finally ! The Enter key was difficult to get in place as was the Caps Lock key.

And the fully assembled and finished result is shown below.

It’s by no means perfect, but it is better than it was originally, the blues are ‘more blue’ especially those on the left side and it’s not bleached out.

Posted in CPC 664, Retrobright | 1 Comment