Author Topic: Ghosts'n'Goblins two buttons hack  (Read 644 times)

0 Members and 1 Guest are viewing this topic.

Offline pmeier

  • CPC464
  • **
  • Posts: 40
  • Country: de
  • Liked: 43
  • Likes Given: 22
Ghosts'n'Goblins two buttons hack
« on: 19:04, 28 May 20 »
Hi folks,
one of my favorite games is Ghosts'n'Goblins. Too bad it didn't support two button joysticks.
But yesterday I managed to apply a patch!  8) Now you can jump even right in front of a ladder!
Just as it was supposed to be!
I also added a simple menu to activate some cheats.

The patch does not just remap keys, I had to inject some code. The source is also included on the disk.
I'm not a Z80 expert, so I'm very proud that it worked.
Thanks to @Phantomz for giving me some hints.

Code: [Select]
org #1000

;; Ghosts'n'Goblins hack:
;; joy0-fire-2 to jump
;; joy0-up for climbing up ladders

;; USAGE
;; load Ghosts'n'Goblins
;; then assemble this file (WinAPE)

;; NOTES
;; I noticed that at #8f5c the zero flag is set if the player is in front of a ladder and will start climbing
;; otherwise he's not and jumps.
;; So I had just to add a routine to detect if joy up is pressed.

;; PSEUDO CODE (to inject at #8f5c)
;; if joy up, then #8f86 (start climbing up ladder)
;; else #8f5e (jump even at a ladder)

check_joy_up

        call keyscan

;; check if joy up is pressed
;; according to scancode table it's line 9, bit 0
        ld a,(keymap+9) ; line 9
        bit 0,a         ; bit 0 (bit=0 key is pressed)
        ret z           ; player will climb

        ld a,(#a607)    ; moved line here from original #8f5e (not enough space to leave instruction in place)
        ret             ; player will jump

;; http://www.cpcwiki.eu/index.php/Programming:Keyboard_scanning

keyscan di              ;1 ##%%## C P C   VERSION ##%%##
        ld hl,keymap    ;3
        ld bc,#f782     ;3
        out (c),c       ;4
        ld bc,#f40e     ;3
        ld e,b          ;1
        out (c),c       ;4
        ld bc,#f6c0     ;3
        ld d,b          ;1
        out (c),c       ;4
        ld c,0          ;2
        out (c),c       ;4
        ld bc,#f792     ;3
        out (c),c       ;4
        ld a,#40        ;2
        ld c,#4a        ;2 44
loop    ld b,d          ;1
        out (c),a       ;4 select line
        ld b,e          ;1
        ini             ;5 read bits and write into KEYMAP
        inc a           ;1
        cp c            ;1
        jr c,loop       ;2/3 9*16+1*15=159
        ld bc,#f782     ;3
        out (c),c       ;4
        ei              ;1 8 =211 microseconds
        ret

keymap  ds 10  ;map with 10*8 = 80 key status bits (bit=0 key is pressed)

;; original code I had to replace with call check_joy_up
;org #8f5c
;jr z,#8f86   ; 28 28
;ld a,(#a607) ; 3a 07 a6

;; replaced code (enable two button hack)
org #8f5c
call check_joy_up ; cd 00 10
; zero flag is only set if joy is up
jr z,#8f86        ; 28 25

;; replace keyboard button up 'Q' with 'joy0-fire-2'
;; (playing with keyboard is not longer possible!)
org #586b
db #00,#09,#20

;; inscrease highscores, so that it's impossible to reach keyboard dialog
org #5537
defb "9999999"
org #5548
defb "9999999"
org #5559
defb "9999999"
org #556A
defb "9999999"
org #557B
defb "9999999"
org #558C
defb "9999999"
org #559D
defb "9999999"
org #55AE
defb "9999999"
org #55BF
defb "9999999"
org #55D0
defb "9999999"
« Last Edit: 16:14, 29 June 20 by pmeier »

Offline DanyPPC

  • CPC6128
  • ****
  • Posts: 189
  • Country: it
  • Liked: 74
  • Likes Given: 414
Re: Ghosts'n'Goblins two buttons hack
« Reply #1 on: 19:07, 28 May 20 »
You are great !!!  :)
CPC 464 with USB Floppy Emulator / CPC 464+ with USB Floppy Emulator / CPC 6128+ with C4CPC and Gotek HxC USB Drive Emulator

Offline Phantomz

  • 6128 Plus
  • ******
  • Posts: 1.179
  • Country: gb
  • Liked: 1769
  • Likes Given: 569
Re: Ghosts'n'Goblins two buttons hack
« Reply #2 on: 19:22, 28 May 20 »
@pmeier Nice work, well done.  8)

Offline ||C|-|E||

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 1.843
  • Country: gb
    • index.php?action=treasury
    • Mundo CPC
  • Liked: 1025
  • Likes Given: 1115
Re: Ghosts'n'Goblins two buttons hack
« Reply #3 on: 16:01, 31 May 20 »
Very cool! I always liked G&G for the CPC, despite its obvious flaws. I it a shame, because everything is basically there in terms of game engine and level design, and with some more polishing it could had been truly great.

Offline pmeier

  • CPC464
  • **
  • Posts: 40
  • Country: de
  • Liked: 43
  • Likes Given: 22
Re: Ghosts'n'Goblins two buttons hack
« Reply #4 on: 16:23, 29 June 20 »
Fixed version for 464.
My start menu previously used some string concatenation, but only if you change the start level. Then the start screen will be messed up (464/6128) and on 464 it crashes after game over. I noticed that after copying to my real 464, but WinAPE behaves the same.

If wish I knew the details about that. Where is the memory dumped? Why does GNG care about it...Back in the days I wasn't aware that the @ operator shows the address of a string.