Author Topic: Zynaps Pokes - quick hack for improved collisions  (Read 580 times)

0 Members and 1 Guest are viewing this topic.

Offline 8bitTinShed

  • CPC464
  • **
  • Posts: 4
  • Country: au
    • Awards
Zynaps Pokes - quick hack for improved collisions
« on: 12:36, 28 October 21 »
G'day fellow CPC fans, First time poster, hope this is the right place to post this. I was mucking around with z80 assembly and Zynaps collision detection on the CPC. Because it was one of my favourite games on my 6128, very good for 1987, but terrible collision bugs.

Here's a quick dirty hack for more forgiving scenery collisions in Zynaps, a 1 or 2 pixel sprite overlap with scenery, but at least you no longer explode alone in deep space!

---

These memory locations SEEM to be fixed "offsets" for the ship that are compared to the scrolling map values, there's more starting at 4980 but only 7 of them seemed to help me, maybe someone can improve on these?

Address(hex)  Value (hex)        Notes (do not put these in)
498C          00                 //01 - original values
498E          01                 //03
4990          05                 //07
4992          07                 //0E
4994          09                 //1C
4996          1C                 //38
4998          1C                 //70

Inject these pokes after Zynaps (CPC Wiki edition) is loaded into memory. I used WinApe poke system, choose Hex not decimal, I assume a multiface on a real CPC works too

---

I'm struggling to read the code but seems to me the collision code is imprecise by design for speed, this "fix" is just a quick dirty hack, but dodgy as this is it still feels a lot more playable like this.

I was wondering if there is anyone already working on a fix, maybe I can be at least a little bit useful, at least share all my debug notes and thoughts.


Thanks
Casey - "8Bit_Tin_Shed"


« Last Edit: 12:47, 28 October 21 by 8bitTinShed »
like
14
Members reacted like:
ervin,trocoloco,shaymanjohn,robcfg,GUNHED,ajcasado,Kris,Urusergi,
TotO,zeropolis79,eto,ComSoft6128,XeNoMoRPH,VincentGR,

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.454
  • Country: au
    • index.php?action=treasury
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #1 on: 12:53, 28 October 21 »
Great job!
And yes this is absolutely the right place to post stuff like this!
Looking forward to trying this out shortly.
like
3
Members reacted like:
8bitTinShed,GUNHED,ComSoft6128,

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.899
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #2 on: 18:12, 28 October 21 »
IIRC there was a special 'fixed' cpcwiki version of Zynaps, with enhanced menu and bigger loading picture, right?

I don't find it at the moment, but it would be cool the have the new pokes in there. Just mentioning it.  ;) :)
like
1
Members reacted like:
zeropolis79,
http://futureos.de --> Get the revolutionary FutureOS (Update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.07.15)

Offline Nich

  • Supporter
  • 6128 Plus
  • *
  • Posts: 806
  • Country: gb
  • CPC Game Reviews webmaster
    • CPC Game Reviews
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #3 on: 23:42, 28 October 21 »
IIRC there was a special 'fixed' cpcwiki version of Zynaps, with enhanced menu and bigger loading picture, right?

I don't find it at the moment, but it would be cool the have the new pokes in there. Just mentioning it.  ;) :)

I can't seem to find a download for the CPCWIki edition of Zynaps on CPCWiki any more, but it's still available from CPC-POWER (click on the black floppy disc icon and scroll down; it's labelled '(v2)').
like
1
Members reacted like:
8bitTinShed,

Offline 8bitTinShed

  • CPC464
  • **
  • Posts: 4
  • Country: au
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #4 on: 08:11, 29 October 21 »
That would be awesome if a final version of these pokes found its way into one of the dsk releases.
But I think we could improve these pokes a little.
Or even rewrite some of the collision routine that uses these values.

I’ll clean up my notes so they make more sense and share them here for the more experienced coders.

Cheers
Casey “8bitTinShed”

« Last Edit: 08:14, 29 October 21 by 8bitTinShed »
like
1
Members reacted like:
ajcasado,

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 4.055
  • Country: fr
    • ?area=showdonations;u=4
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #5 on: 09:40, 29 October 21 »
Great, because it was the missing work when we have done the improved cpcwiki version!
like
1
Members reacted like:
8bitTinShed,
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline 8bitTinShed

  • CPC464
  • **
  • Posts: 4
  • Country: au
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #6 on: 10:38, 29 October 21 »
I was so happy to find that version, thanks heaps! Before finding this version I had a version with the broken music.
« Last Edit: 17:43, 30 October 21 by 8bitTinShed »
like
0
No reactions

Offline 8bitTinShed

  • CPC464
  • **
  • Posts: 4
  • Country: au
    • Awards
Re: Zynaps Pokes - quick hack for improved collisions
« Reply #7 on: 17:31, 30 October 21 »
Finally cleaned up my (long & beginner level) notes for collision improvement "pokes" on disassembled Zynaps.
Hopefully something jumps out for the experienced CPC coders that helps make the pokes better or another approach to make the collisions more accurate.



Cheers - 8bitTinShed


Code: [Select]

Amstrad CPC "Zynaps" Collision Investigation and "Fix" Pokes
By 8bitTinShed, 2021
Covid19 Lockdown, Australia
Great game from 1987, with some collision detection issues.


SCOPE - "Your ship explodes a number of pixels above a map object"
DISCLAIMERS -
1. I'm a beginner at Amstrad CPC Assembly, huge knowledge / experience gaps.
2. Probably a few ludicrous assumptions.
3. But hey the pokes seem to mostly fix the worst of the collisions with the map.
-----------
MEMORY:
-----------
0000-4000
GFX Assets
4000-8000
program code
8000-FFFF
screen buffers for scrolling / flipping
----------------------
MEMORY DATA VARIABLES (used memory write breakpoints)
----------------------
7D45 = Ship Y collision data position? (default start position is value 08)
       //Top of screen ship position is 00 bottom is 0C - WTF only 12 possible Y values??
       //But means working with a nibble which is fast?
       //Ship can move smaller units than this? - collision code on Y axis imprecise?
       //If my assumptions are right this not gunna be very accurate by design, hard to rewrite too.
       //INTERESTING - SET back to 08 with a poke and the ship is LOWER than start position
7D43 = Ship X collision position? (default value 14)
       //min 11 left most edge, max 32?
       //more than nibble - and more accurately represents ship pixel position on X axis
4980 = Base addy for collision data Y axis offsets?
       //TODO - Are they offsets for height? why do they not increase or decrease more evenly?
4992 = e.g addy for data checked at default ship Y position offset from 4980 - when crashing into first blue tower
       //Data inside here never changes, these seem to be offsets
49A0 = Scrolling map position data - populated from scrolling routine noted below.
49AD = e.g addy - this is collision spot on first blue tower at default ship Y position
-----------------
HANDY BREAKPOINTS (I USED AT DIFFERENT TIMES)
-----------------
48C8 //start of the Y axis collision detection with map?
4922 //subroutine 
48DF //the collision jump when we hit a map spot in B,C registers from routine at 48C8
564B //Main loop's check of carry flag to jump to death code -
5659 //Death routine start.
48E2 //Collision - set carry flag.


-----------------
COLLISION ROUTINE   //identified by working backwards from death routine, collision 4 pixels above a tower
-----------------
...
48C8 LD HL,#4980    //(#4980 - 00 Registers (changing): BC C000 BC'2855, DE 0600, DE' 3F0B)
48CB CALL #4922
4922 LD A, (IY+#06) // Load Ship Y position into Accumulator
                    // (IY: nearly ALWAYS #7D3F = ALWAYS 55)
                    // (IY+#06 - 7D45 = 08 default --> trying -02 instead -> ship moved UP (ship Y position??)
4925 INC A          //Add 1 to the ship Y position
4926 AND #0F        //logical AND ship Y with 0F - ensures it's in range, clearing left nibble - eg 09 didnt change but 19 would become 08 again
4928 SLA A          //Shift left arithmetic A = result of 08 y position is A = 12 - it gains an order of magnitude? worth noting more than a nibble now
492A LD C,A         //put A into C - (C is now 12)
492B LD B,00        // blank B
492D ADD HL, BC     //4980 gets BC (0012) added to it result - HL = 4992
                    //(offset applied for address pointer based on ship's Y position - WHY!?)
                    //(try another ship position, see what addy it points at)
                    //(4992 is: 0E)
                    //(higher - HL is 498E = 03)
                    //hmm these never change - assuming an offset.
492E LD B, (HL)     //B now 0E - contents of memory at HL(4992)
492F INC HL         //now pointing at 4993 - why? something to check there too.
4930 LD C, (HL)     // C now 00 (default flying at start)
4931 LD HL, #49A0   // it's 00 atm, but might be a variable for collision
...


4934 LD A, (IY+#04) //load ship X position into accumulator
...
SKIP                //- B AND C registers SEEM set for Y POS checks
...                 //D & E are set here with ship X position, skipping for now, Y axis way less precise.
...
493F RET            //(back to 48CE)


48C3                //WE ARE BACK HERE NOW
...
SKIP
...
48D3 LD A, (HL)     //HL NOW 49AD = #78 - these populated from SCROLLING related routine.
48D4 AND B          //AND with B (still 0E from data var at 4992)
48D5 JR NZ, 48E2    //78 AND 0E = NZ result - FOUND A COLLISION
...
SKIP
...
48E2 SCF            //Set Carry Flag - we have a collision to flag - we check later
48E3 RET            //Last return before death routine?
...
NOTE                //runs same loop again, same result - jump from 48D5
...
SKIP
...
...
564B JR C,#5659     //IF CARRY FLAG SET trigger death routine (that's flag bit C from register F, not register C) 


-----
SCROLLING MAP -     //This is feeding into vars for the collision routine above
-----
NOTE                //As games scrolls we get one block write per frame everything is shifting left/ up in memory ->
420C LD HL,#49A2    //start reading from here and increment by 1 82 times (52 hex is in BD)
420F LD DE,#49A0    //write what we read into here - scrolling collision detection.
4215 LDIR           // writes to 49A0 -> 49AD too ->  BUT only once per frame, no AF block decrement


                    //SOOO what's feeding into the right hand side of all this?
                    //RIGHT SIDE IS: 49F0 -> 49F1
4217 JP #4277       
4277
...
SKIP
...
NOTE                //THIS BLOCK scrolls top half of map? i broke it to confirm
431A LD B,#40       // this value #40 is from A register on line below on the previous cycle
431C LC (#431B),A   // some simple self modifying code?
431F LD (#49F0),A
4322 OR B           //THIS! - Writing to 49F0 (but not earlier in the sliding window)
....
....
NOTE                //THIS BLOCK scrolls bottom half of map?
436D LD B, #40      //this value #40 is from A register on line below on the previous cycle
436F LD (#436E),A   //some simple self modifying code (always sets it to 40?)
4372 LD (#49F1),A
4375 OR B           //writing to 49F1 (second byte we write on the right hand side of the scrolling / sliding)
4376 XOR C          //this never seems to write to 49F1?? because C always same as B?


---------
THE "FIX" POKES (work in progress)
---------
These data memory locations seem to be data for comparing ship
at different Y positions to the scrolling map data.
I revised all the numbers in this range down by 1 over and over
And I did this until I didn't explode unfairly aginast the scrolling map at that Y position.


POKES - I stopped spontaneously combusting:
498C 00           //was 01 - top height bubble thingy lvl 1
498E 01           //was 03 - mid height bubble thingy lvl 1
4990 05           //was 07 - the first blue narrow tunnel thingy lvl 1
4992 07           //was 0E - the default starting position bllue tower crash lvl 1       
4994 09           //was 1C - the first bottom bit of the map on lvl 1
4996 1C           //was 38 - the tiny tiny little blue nob that you hit, and lowest pipes, lvl 1
4998 1C           //was 70 - very bottom map lvl 1


Test changes to these by setting a breakpoint at 5659 - and check value in register B.
Register B is populated by these vars, and persists until the death routine condition.
So this will tell you which of the offsets caused the collision in open space.


----------------------------
FURTHER THOUGHTS / QUESTIONS
----------------------------
Q1. What exactly are these "ship" data vars at 4980? Does anyone experienced know how to derive these values?
So we can set meaningful more accurate values rather than trial and error *wink*
Current guess - Assuming they are offsets for representation of the ship at certain screen positions
But then why do they not increase or decrease more evenly...
Or maybe a gfx format I don't know, but data seems too small for ship gfx


Q2. Assuming I'm right about low precision design can we find enough free memory to hack in a new routine to
improve the accuracy of the Y axis collision code? Maybe it would make scrolling to slow though...
Either way I've never done that sort of thing, maybe it's quick for an experienced coder.


If you read this far you are a bloody legend, and you need a stiff drink, cheers.

« Last Edit: 17:39, 30 October 21 by 8bitTinShed »
like
0
No reactions