Jump to content


Photo

Free space and code optimisation in "JSW"


  • Please log in to reply
238 replies to this topic

#191 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 19 December 2017 - 03:50 PM

The two chunks of code at #8E12-#8E24 and at #8E81-#8E93 are identical, and could be put into a subroutine CALLed from both places. That would save a net total of twelve bytes I think (2x19 bytes replaced by 1x19+1 RET at the end, called by 2x3-byte CALL commands).

****

The JR at #961C may be eliminated if the subroutine at #961E is relocated to after the code at #9637-#967F (or elsewhere).

Edited by IRF, 28 December 2017 - 10:21 AM.


#192 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 20 December 2017 - 01:20 AM

I've now managed to fix the 'Move Willy' routine, in order to prevent Willy from jumping into wall tiles/earth blocks, and also to implement the check for head-height wall tiles in a symmetrical manner, but without preventing Willy from jumping into a gap that is two rows high and located below a wall platform (a la The Wine Cellar, Ballroom East, etc).

 

Please see the attached test file.  The fix is best illustrated in Emergency Generator, where it was previously impossible to jump rightwards from the right-hand chimney and escape via the gap at the top-right that leads to the Priest's Hole.  (Previously, Willy fell through the Earth block beneath that gap, and plunged to his death - a similar phenomenon to the way he sinks into the floor at the bottom-right corner of First Landing, but here it has more deadly consequences!)

 

Now the same manoeuvre in Emergency Generator can be done in three different ways, namely: starting off at a height two rows below the gap (i.e. by simply jumping from the start-up position in the test file); jumping from a height that is one row below the gap (I've removed a bit of the chimney to make it easier to reach that position); or jumping from the same height as the gap (i.e. from the top of the right-hand chimney stack).

 

The basis of the fix is a rewrite of the code which SkoolKid calls 'Move Willy (1)' i.e. the code dealing with his vertical movement (jumping/falling).  The code now tests whether Willy has landed on a solid platform before his y-coordinate is adjusted during a jump.  Previously, his y-coordinate was adjusted first, and only then was a check done for an underfoot solid platform - that illogical sequence is the fundamental reason why Willy can jump into solid blocks in the original game engine.

 

Several other quirky manoeuvres are prevented by this fix, such as the ability to jump through so-called 'Innocent-Looking Blocks', and the way in which Willy can, in some circumstances, fall through a standonable block that lies adjacent to a Fire cell.

 

Other unintended consequences may also occur - for example, if Willy stands adjacent to a pillar of Earth blocks that is two cells high and tries to jump onto the pillar, he leaps all the way over and falls down on the far side of the pillar.  This actually makes The Banyan Tree more difficult to climb/cross!

 

N.B. These code changes do not prevent Willy's ability to walk into wall tiles by proceeding up or down a ramp.

Attached Files



#193 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 22 December 2017 - 09:51 AM

Other unintended consequences may also occur - for example, if Willy stands adjacent to a pillar of Earth blocks that is two cells high and tries to jump onto the pillar, he leaps all the way over and falls down on the far side of the pillar. This actually makes The Banyan Tree more difficult to climb/cross!


Actually, it's worth resetting Willy's starting position in the 'Jump Code rewrite' test file to The Banyan Tree (somewhere near the entrance from The Nightmare Room), and then try climbing to the top of the Banyan Tree, and also crossing through the Tree in both directions.

The subtle difference in Willy's jumping mechanics end up causing quite a significant difference to the outcomes in that room in particular. For example, crossing from left to right used to be extremely tricky (requiring a well-timed jump to avoid the two 'central' vertical guardians); now it's actually impossible I believe - not because Willy hits the guardians, but because he gets caught by the water cells at the top right which he previously fell straight through. (In a sense, climbing the Banyan Tree [up the right hand side] is now easier, if you approach it from The Swimming Pool!)

#194 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 24 December 2017 - 09:25 AM

Another example of a change to the jump dynamics is in the Orangery, where in order to collect the bottom-left item, you have to steep further back before making the jump over Moon-Face, otherwise the water platform/floor tile above the item catches Willy, where beforehand he fell through it.

The first jump in East Wall Base may also be trickier - I think Willy will have to use every floor tile in the room to climb it, rather than being able to skip the second one up.

Edited by IRF, 24 December 2017 - 09:29 AM.


#195 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 24 December 2017 - 09:31 AM

Some jumps might now be possible that previously were not. E.g. jumping over the cyan 'spider web' guardian in the Orangery from right to left at the upper level?

On the other hand, some of the jumps in 'Out on a Limb' might now be impossible with the original layout and this patch in place! Look into this I must...

Also, check that jumping through the base of a ramp, as in 'The Chapel' or 'Crow's Nest', is still possible.

And the tricky sequence of well-timed jumps along the conveyor in 'Under the Drive'.

Finally, it might not be possible for Willy to collect one of the items in 'Watch Tower' in particular without jumping right over the parapet and dropping into an infinite-death scenario in 'Quirkafleeg'!! (Definitely need to check that one!)

Edited by IRF, 24 December 2017 - 09:44 AM.


#196 Spider

Spider

    XOR (HL)

  • Administrator
  • 3,209 posts

Posted 24 December 2017 - 01:24 PM

I do find Watch Tower sometimes slightly tricky given you need to be perfectly positioned to jump to get the item without losing a life. If life loss is not a concern ( ! ) its easy to jump onto the item and subsequent fire cell although I do try to avoid that out of "good practise" :)


Changing order to chaos since 1984

#197 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 24 December 2017 - 01:38 PM

Another example of a change to the jump dynamics is in the Orangery, where in order to collect the bottom-left item, you have to steep further back before making the jump over Moon-Face, otherwise the water platform/floor tile above the item catches Willy, where beforehand he fell through it.

True.

The first jump in East Wall Base may also be trickier - I think Willy will have to use every floor tile in the room to climb it, rather than being able to skip the second one up.

Not true.


Edited by IRF, 24 December 2017 - 02:01 PM.


#198 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 24 December 2017 - 01:41 PM

Some jumps might now be possible that previously were not. E.g. jumping over the cyan 'spider web' guardian in the Orangery from right to left at the upper level?

Yes, that is now possible (it wasn't before).

On the other hand, some of the jumps in 'Out on a Limb' might now be impossible with the original layout and this patch in place! Look into this I must...

It is still possible to complete Out on a Limb.

Also, check that jumping through the base of a ramp, as in 'The Chapel' or 'Crow's Nest', is still possible.

No problems with these manouevres.

And the tricky sequence of well-timed jumps along the conveyor in 'Under the Drive'.

That is now in fact impossible with this patch in place! (Should be fine with my alternative patch though - the 'Inverted ILB' patch.) EDIT: Or maybe not?

Finally, it might not be possible for Willy to collect one of the items in 'Watch Tower' in particular without jumping right over the parapet and dropping into an infinite-death scenario in 'Quirkafleeg'!! (Definitely need to check that one!)

Not a problem, as it turns out.


Edited by IRF, 24 December 2017 - 02:04 PM.


#199 IRF

IRF

    Advanced Member

  • Contributor
  • 3,682 posts

Posted 04 January 2018 - 05:11 PM

Move Willy into the room to the left:
#9493 OR #1F
#9495 AND #FE

can be replaced (I think?) with:
OR #1E

Move Willy into the room above:
#94BD LD (#85D3),A
#94C0 LD A, #5D
#94C2 LD (#85D4),A

replace with:
LD L,A
LD H, #5D
LD (#85D3),HL

Move Willy into the room below:
#94ED LD (#85D3),A
#94F0 LD A, #5C
#94F2 LD (#85D4),A

replace with:
LD L,A
LD H, #5C
LD (#85D3),HL

****

Some other savings can be made across the four 'move to another room' routines, by sharing a common ending (POP HL/JP #8912) via relative jumps.

Also, rearrange the various components of 'Move up' and 'Move down' so that the LD (#85CF), A and LD (#85D3), HL commands are shared by those two routines.

I think all of the above should cumulatively save about 18 bytes?

#200 Norman Sword

Norman Sword

    Advanced Member

  • Member
  • PipPipPip
  • 124 posts

Posted 04 January 2018 - 07:45 PM

The room jump routines -- about 40 bytes shorter

 

ROOM_L                EQU $80E9
ROOM_R               EQU $80EA
ROOM_U               EQU $80EB
ROOM_D               EQU $80EC

CURRENT_ROOM EQU $8420
WILLY_Y                EQU $85CF
AIRBORNE             EQU $85D1
;ANIMATION           EQU $85D2
WILLY_ATT           EQU $85D3
WILLY_ATT_H       EQU $85D4
NEW_ROOM          EQU $8912

;----------------------------------------------
GO_ROOM_LEFT:              ;L948A
    LD BC,$FE1E        ;;; OR    LD BC $E01E
    LD HL,ROOM_L

 

GO_NEW_ROOM:

    LD A,(HL)   

    LD (CURRENT_ROOM),A 
    LD HL,WILLY_ATT
    LD A,(HL)
    AND B
    OR C
    LD (HL),A                        ;L85D3 
    POP HL   ;
    JP NEW_ROOM              ;L8912

 

GO_ROOM_RIGHT:           ;L949E
    LD BC,$E000
    LD HL,ROOM_R
    JR GO_NEW_ROOM

 

GO_ROOM_UP:                 ;L94B0

    LD BC,$1FA0
    LD HL,ROOM_U

    LD DE,$D05D

    XOR A

VERT_PROCESS:
    LD (AIRBORNE),A
    LD A,E
    LD (WILLY_ATT_H),A
    LD A,D
    LD (WILLY_Y),A
    JR GO_NEW_ROOM

 

GO_ROOM_DOWN           ;L94D2
    LD BC,$1F00

    LD HL,ROOM_D

    LD DE,$005C  

    LD A,(AIRBORNE)  

    CP $0B

    JR NC,VERT_PROCESS
    LD A,$02

    JR VERT_PROCESS

 

Slight edit to set up variables in a more consistent manner.


Edited by Norman Sword, 05 January 2018 - 09:19 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users