;

; Game "Ninja" by Icon Design Ltd - ZX-Spectrum

; http://www.worldofspectrum.org/infoseekid.cgi?id=0003433

;

; BUGFIX changes (POKEs) provided by Bandit.

; Modified "BUGFIX" file provided by Einar Saukas.

;

; This file describes the bugfixes applied to this game in order to solve the following bugs:

; * Interrupts are activated at the wrong time, erasing the location of an idol and thus making the game unfinishable;

; * The current room number is stored inside the enemy table, thus if too many enemies appear on the same location,

;   this information is corrupted.

;

; Fixing these problems require changing code usually loaded from tape, so these changes are directly performed on the

; CODE block stored on tape. Only the last set of changes located at addresses 65433 to 65441 is not directly loaded

; from tape, thus requiring a different solution. Luckily a sequence of 64 NOPs starting at address 23791 ($5cef) is

; executed right after loading the last block, that can store a routine to modify addresses 65433 to 65441 accordingly

; and then erase itself. The full list of changes applied to the last CODE block of this game is listed below:

;

        org $eabd

        defb $bb            ; POKE 60093,187

        org $eae7

        defb $bb            ; POKE 60135,187

        org $eafc

        defb $bb            ; POKE 60156,187

        org $eb3a

        defb $bb            ; POKE 60218,187

        org $ed08

        defb $bb            ; POKE 60680,187

        org $ed69

        defb $bb            ; POKE 60777,187

        org $ed71

        defb $bb            ; POKE 60785,187

        org $f108

        defb $bb            ; POKE 61704,187

        org $f59b

        defb $bb            ; POKE 62875,187

        org $f76f

        defb $bb            ; POKE 63343,187

        org $f806

        defb $bb            ; POKE 63494,187

        org $f818

        defb $bb            ; POKE 63512,187

        org $fa28

        defb $bb            ; POKE 64040,187

        org $fa40

        defb $bb            ; POKE 64064,187

        org $faf4

        defb $bb            ; POKE 64244,187

        org $fb2c

        defb $bb            ; POKE 64300,187

        org $fb3e

        defb $bb            ; POKE 64318,187

        org $fb44

        defb $bb            ; POKE 64324,187

        org $fb5a

        defb $bb            ; POKE 64346,187

        org $fd78

        defb $bb            ; POKE 64888,187

        org $fdcd

        defb $bb            ; POKE 64973,187

        org $fddd

        defb $bb            ; POKE 64989,187



        org $e2ca

        call $ff99          ; POKE 58059,153: POKE 58060,255



        org $f908

        call $ff99          ; POKE 63753,153: POKE 63754,255



        org $5cef

first:  nop                 ; previous 'ret' arrives here

        ld hl,pokes         ; copy POKEs

        ld de,$ff99

        ld bc,last-pokes+1

        ldir

        ld hl,first         ; erase itself

        ld de,first+1

        ld bc,last-first

        dec sp              ; repeat last return address

        dec sp

        jp $fa24            ; ldir/ret

pokes:  ld iy,$5c3a         ; POKE 65433,253: POKE 65434,33: POKE 65435,58: POKE 65436,92

        call $03b5          ; POKE 65437,205: POKE 65438,181: POKE 65439,3

        di                  ; POKE 65440,243

last:   ret                 ; POKE 65441,201

