<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Wed, 04 May 2005 15:03:55 +0100
From   : Richard_Talbot-Watkins@...
Subject: Chuckie Egg - better patch (and some mysteries solved!)

OK, it turns out there are certainly two different versions of the Chuckie
Egg executable around... they are mostly the same apart from some changes
of routine addresses in the critical place I'm patching (typical!).

According to Bill Carr, both versions are identical between &1100 and
&29AB, and &3000 and &3800.  The code between &29AB and &3000 seems to be
off by 10 bytes between the two versions, but the bits I've compared seem
to be pretty much the same code.

The cheats from Peter Edwards don't seem to apply to the StairwayToHell
archive version (they make no sense in that executable), so I assume
they're from the other version which is going around (Bill says his is from
the 'tosec' archives, whatever they are...), and as I don't have a copy of
that version, I can't provide a StairwayToHell-compatible cheat - sorry!
Maybe someone else will be able to do this?  Anyway this explains the
problems people have been having getting things to work correctly...

Anyway, I have a better patch for colour which doesn't require a raster
interrupt.  It only works with the StairwayToHell version of Chuckie Egg,
which can be found here:
http://www.stairwaytohell.com/bbc/archive/diskimages/AnF/ChuckieEgg.zip .

Just type in, save and run the following alternative loader:

  10 HIMEM=&3100
  20 P%=&380:[OPT2
  30 LDA&7F:PHA:LDA#136:STA&7F
  40 JSR&1902:PLA:STA&7F:RTS:]
  50 *L.CH_EGG 3100
  60 ?&4B7E=7:?&4B88=1
  70 ?&4CE6=32
  80 ?&3CC4=138:?&3D01=138
  90 ?&3DFD=136
 100 ?&3B0D=128:?&3B0E=3
 110 ?&3D23=128:?&3D24=3
 120 P%=&900:[OPT2
 130 LDX#&27:LDY#0:.q
 140 LDA&3100,Y:STA&1100,Y:INY:BNEq
 150 INCq+2:INCq+5:DEX:BNEq:JMP&29AB
 160 ]
 170 CALL&900


As an aside, I've noticed that the StairwayToHell version of the game seems
a little odd: upon completing a level, an extra life is awarded, and then
shortly taken away again.  This is not due to my patch - it just seems to
happen on the unpatched code.  Is this correct Chuckie Egg behaviour?  Does
the other version do this?




...and now for anyone who's interested, here's how it all works (long).
This might also help someone modify the patch for the 'other' version of
the game too.


We load the executable &2000 bytes higher than its load address to allow
room for that Basic loader.  All the code at lines 110-160 is concerned
with is relocating the executable down to the right place (quickly) and
running it.


Line 60:
these poke new colours into the palette used by the game.  We deduce that
the palette is stored at &2B7D from the following code in the game:

2B5B:  LDX #&0F   ; start at index 15
2B5D:  STX &88
2B5F:  LDX &88          ; loop start: get index
2B61:  STX &2B78  ; store colour index
2B64:  LDA &2B7D,X      ; lookup physical colour
2B67:  STA &2B79  ; store physical colour
2B6A:  LDX #&76
2B6C:  LDY #&2B
2B6E:  JSR &1A26  ; print string pointed to by &YYXX
2B71:  DEC &88          ; dec loop index
2B73:  BPL &2B5F  ; re-loop
2B75:  RTS
2B76:  <06>       ; length of string to print
2B77:  <13>       ; VDU 19
2B78:  <00>       ; poked with colour index
2B79:  <00>       ; poked with physical colour
2B7A:  <00> <00> <00>

As standard, the game makes special use of the following colours.

      0  black (background)
      1  yellow (eggs + lift)
      2  magenta (grain + ladders + score)
      3  green (platforms)
      4  yellow (you + big bird+cage)
      8  cyan (enemy birds)

The other palette entries echo these colours in appropriate ways.  Since
all sprites are EORed on the screen, other colours will arise, e.g. when a
cyan bird climbs a ladder, we will get pixels in colour (8 EOR 2)=10.
Hence the game sets colour 10 to cyan so we don't notice these artifacts
(birds appear in front of ladders).

Now, it turns out that eggs have an independent palette entry (colour 1) to
the main character and the big bird.  This is so the big bird doesn't
overprint eggs and leave a black egg-shaped hole (4 EOR 4 = 0).  But this
means we can trivially set this palette entry to colour 7 instead of 3
(?&4B7E=7).  Voila, white eggs.

It also turns out there's an overprint which is never possible - cyan birds
over green platforms (I think this is true anyway?).  This corresponds to
colour 11 (8 EOR 3), so we'll define this as red (?&4B88=1) and print our
status sprites in this new colour.


Line 70:
this is a cosmetic change.  We have changed colour 1 to white from yellow.
The main title 'CHUCKIE EGG' is printed in colour 1, so in order to make
sure it stays in yellow, we now explicitly change its print colour to
colour 4 (which is still yellow).  Here's where this appears in the
executable:

2CE5:  LDA #&02   ; select physical colour 1 (PATCHED)
2CE7:  STA &7F          ; store in 'colour' variable used by sprite plotter
2CE9:  LDA #&30   ; select sprite &30 ('C' in 'CHUCKIE EGG')
2CEB:  LDX #&02   ; X position 2
2CED:  LDY #&F0   ; Y position &F0 (0=bottom, &FF=top)
2CEF:  JSR &2DBE  ; plot sprite

2DBE is a generic routine which takes a colour in ?&7F, a sprite number in
A, and coordinates in X,Y, and draws a sprite.  By changing LDA#&02 to
LDA#&20, we plot the sprite in colour 4.  (The value used is the one which
would set the leftmost pixel of the byte to the desired colour in MODE 2).


Line 80:
these are involved with changing the colour the status sprites ('score',
'level', 'time', 'player', 'bonus') are printed in, from magenta (colour 2)
to red (colour 11).  In each case, there is code setting ?&7F to 8 (colour
2: magenta).  We just want to change it to 138 (colour 11: red).
?&3CC4=138 deals with the 'score' sprite:

1CC3:  LDA #&08   ; select colour 2 (PATCHED)
1CC5:  STA &7F
1CC7:  LDX #&00
1CC9:  LDY #&F8
1CCB:  JSR &1987  ; set up screen address from X/Y
1CCE:  LDA #&29   ; select sprite 'SCORE'
1CD0:  JSR &19DB  ; set up sprite address in A
1CD3:  JSR &1902  ; print sprite (screen+sprite addrs
                  ; must already be set up)

?&3D01=138 deals with the other status sprites:

1D00:  LDA #&08   ; (PATCHED)
1D02:  STA &7F
1D04:  LDX #&00
1D06:  LDY #&E8
1D08:  JSR &1987
etc


Line 90:
This pokes a routine which appears to print the score for the first time.
We want white scores, so we need to overprint the red background in colour
(11 (red) EOR 1 (white)) = 10.  This corresponds to a screen byte value of
136.  This does mean that scores not on a red background (i.e. other
players') will appear cyan (colour 10), but hey-ho, it's all a bit of extra
colour isn't it?  Here's the code (for cross-referencing with the other
version):

1DFC:  LDA #&08   ; (PATCHED)
1DFE:  STA &7F
1E00:  LDA &88
1E02:  ASL A
1E03:  ASL A
1E04:  ASL A
1E05:  ASL A
1E06:  ASL A
1E07:  ASL A
1E08:  TAX


Lines 20-40, 100, 110:
This is all to do with plotting digits.  We already know that we need to
print them in colour 10.  The game used to plot them in colour 2 (which,
overprinted on a background of colour 2 yields colour 0 - black).  In these
cases, colour 2 is already set up, so these pokes patch the call to the
sprite routine (JSR &1902) and replace it with a call to my own assembler
routine in lines 20-40:

; generic number printing code (A = digit to print)
1B01:  PHA        ; save A
1B02:  JSR &1987  ; set up scrn address from X/Y
1B05:  PLA        ; restore A
1B06:  CLC
1B07:  ADC #&1F   ; add 31 (digits are sprites 31-40)
1B09:  JSR &19DB  ; set up sprite address in A
1B0C:  JSR &1902  ; print sprite (PATCHED)
1B0F:  RTS

; print player number
1D1A:  LDA &5D          ; player number
1D1C:  CLC
1D1D:  ADC #&20   ; digit 1 base
1D1F:  JSR &19DB  ; set up sprite address in A
1D22:  JSR &1902  ; print sprite (PATCHED)

My assembler routine just saves the colour at ?&7F, sets it to colour 10,
calls the original routine, and then restores the old value of ?&7F.  This
seems to work very nicely because Chuckie Egg never touches the memory at
&380..&3E0, so we're free to fill it with any patch code we need.


....and that's it.

Please let us know if you spot any probs!

Cheers,
Rich


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
postmaster@...

This footnote also confirms that this email message has been checked
for all known viruses.

**********************************************************************
Sony Computer Entertainment Europe
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>