Computer Gammon - The Bugs!

 

Issue 29

Sep/Oct 87

Next Article >>

<< Prev Article

 

 

Fancy being a Bug-Hunter? Or doing a bit of Sherlock Holmes work? Dave Hitchens tried to track down a bug in his Computer Gammon program from Issue 27 only to find part of the solution. Can you throw any light on the problem?

Shortly after Computer Gammon was published in Issue 27, the Editor wrote to me and asked if I could sort out a bug. Apparently, 400/800 owners experienced a problem with the right hand die jiggling back and forth slightly – something which does not happen on the XL or XE. It turns out that this is one of those bugs that does not respond to conventional debugging techniques, in fact it's real weird!

FIRST THE FIX ...

Before going into the technicalities, let's have the cure, which involves modifying three lines, and while we're at it there are a couple of corrections to the scoring routines you might like to make. The cure for the jiggling is:

 

Line 1730 – alter the DATA

141,2,208,24,105,20,141,3,208 to

141,3,208,56,233,20,141,2,208.
Line 1760 – alter the 201,70 to 201,90

Line 2440 – alter the 70 to 90

For the scoring routine make the following changes:

 

Line 8045 – the (N < 6) should be (N < 7)

Line 8046 – the (N > 19) should be (N > 18)

... THEN THE MYSTERY!

Now to the Sherlock Holmes section!

The dice are represented by players 3 and 4, overwritten by substrings from DICE$ and their horizontal locations correspond to the value in location 1. Once initialised, this location holds '70' and is POKEd into memory location 53250. Adding 20 produces the value to POKE into address 53251. Now, because the program makes multiple use of both players and colour registers, I introduced three DLI's along with a VBI with the latter pulsing the colours and cursor etc. The positional instructions for the dice are contained in this VBI and could not be more simple viz: LDA 1, STA 53250, CLC, ADC#20, STA 53251. The XE accepts this routine and gives stable dice but the 400 doesn't! The left die is steady as a rock but the right one dithers.

It turns out that replacing the CLC/ADC instruction with LDA #90 cures the jiggling. In addition, using SBC #20 with either CLC or SEC also cures it. Finally, pressing the BREAK key stops the jiggling but the fault returns when CONT is typed or even if BASIC is sent into a tight loop (e.g. GOTO 5 where line 5 simply reads GOTO 5).

A memory location was chosen so as to scroll the dice into view at the start of the game but its selection does not affect the Bug (I think it deserves the capital letter!). There is obviously a very strange interaction taking place when BASIC is running and when this particular ADC instruction is used. (I tried ADCing a memory location and the die still jiggled).

A second, and more intermittent, bug which affects both machines (but which has not been commented on by readers as far as I know) is an apparent breakdown of the DLI sequencing. It's as though they go out of sync in a totally random fashion causing colour flashing and player positioning fluctuations. In particular, DLI3 (the final one) appears to intermittently affect previously scanned areas of the TV display. In fact I've seen this on two items of commercial software so suspected my machine was at fault but I have since checked it out on two 400's as well as my XE and the problem appears on all of them. The DLI's are, incidentally, simply a string of load/stores, no ADC's are used here!

I have tried everything I know to cure this – resetting the DLI vector in the VBI, using Immediate/deferred VBI's, using a normal graphics 0 Display List instead of the modified one etc., etc. It's all to no avail – until I press the BREAK key when, hey presto, no flashing! As with the dice Bug, however, if you send BASIC into one of its tight one-line loops, then back comes the problem.

I should be very interested to hear from anyone who can shed light on these problems. There appears to be a common interactive cause, and the effect with the BREAK key, in particular, must offer a clue to just where the problem lies.

To summarise, the problems are as follows.

1. Player horizontal positions are perfectly stable on the XE.
2. They are only stable on the 400/800 system if the ADC instruction is not incorporated.
3. The BREAK key effectively removes the bugs.
4. Bugs return even if BASIC is operating a closed loop.

So, you clever programmers, how about some real detective work? To help you out, the VBI code for the game is shown. There's no better way to improve your programming techniques than sorting out some really obscure bugs! And don't forget, if you solve it, let me know!

 

COMPUTER GAMMON – VBI CODE

 
PLA   STA (704) also used for
LDX #6 activate STA (705) dice energisers
LDY #11 the VBI    
LDA #7   DEC 0  
JSR (SET)   LDA 0 cursor blink
RTS   BNE 4 routine
    LDA #12  
LDA #0 reset DLI STA 0  
STA 512 vector STA 1702  
       
STA 53252 set 'dice energisers' LDA #1 dice sizes i.e.
STA 53253 off screen STA 53258 double width
    STA 53259  
LDA 1700      
CLC smooth colour change LDA 1703  
    BEQ 10 show the energisers
ADC #16 used in DLI2 LDA #56 if 'shaking' dice
STA 1700   STA 53252  
    LDA #116  
LDA 1   STA 53253  
STA 53250 horizontal dice    
CLC locations LDA 1 scroll the
ADC #20   BEQ 6 dice into view
STA 53251   CMP #70 when required
    BEQ 2  
LDA 53770 rapid colour change INC 1  
STA 1701 for DLI3    
    JMP (END) End of VBI

 top