Bugs be gone!

I fixed quite a few problems in the code last night.

First up was the DAA instruction.  I scrapped what I had there already and re-wrote it.  It now seems to be working as it should.  The scores in various games are now being shown correctly, which is nice.

Second was the flash routine.  I had noticed that when flashing, the ink colour was always displayed as black.  A couple of altered lines in the screen drawing routine and it was fixed.  The result of this is that Jetpac and Atic Atac now work perfectly! (apart from sound).

After forcing myself away from Atic Atac (I had forgot how much I enjoy that game!) I decided to have a look at theproblem with Interrupt Mode 2 that was causing Chuckie Egg to crash.  What I found was quite surprising…

In my notes, I have this info about IM2

In IM 2, the Z80 reads a byte b from the data bus. The memory at location 256 * I + b is then treated as a 16 bit word (LSB of course) and PC is set to this value. On an unexpanded Spectrum, the byte read from the data bus in IM 2 will always be 0xff.

Pretty straight forward.  Take the value in I, multiply it by 256 and add 0xFF.  Basically, if the ‘I’ register contains 0xB0 then the new PC should be set to 0xB0FF.

This is the code I had written (r7 is the current Program Counter, r3 = 0xFFFF and is used to mask 16-bit values).  Please excuse the bad formatting…

ldrb r1, [r4, #OFFSET_I]   @ r1 = I
mov r1, r1, lsl#5    @ r1 *= 256
and r7, r7, r3
add r7, r1, #0xFF    @ PC = r1 + 0xFF
and r7, r7, r3

I must have been drunk or something when I did this.  First of all, to multiply a number by 256 you have to bit shift it left by 8, not 5.  And what are those ‘and’ instructions all about?  I must have put them in to make sure the PC didn’t overflow, but it never will even if I = 0xFF.

Anyway, I have now changed it to the following…

ldrb r1, [r4, #OFFSET_I]   @ r1 = I
mov r1, r1, lsl#8    @ r1 *= 256
add r7, r1, #0xFF    @ PC = r1 + 0xFF

Much better!  I ran Chuckie Egg after making the changes and now it just hangs on the startup screen instead of crashing, which is progress!

I’m going to leave this problem over the next few days and see if I can track down the few Z80 instructions that are still causing problems.  The teleports in Earth Shaker look like a good place to start…

Advertisements

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: