From 19f7dbf8aa66effaafac73c080fcdf1fb72e77c8 Mon Sep 17 00:00:00 2001 From: Mark Moxon Date: Tue, 28 Feb 2023 12:46:57 +0000 Subject: [PATCH] Move code out of sight sprites and into the NOP part of the Trumble routine --- src/elite-flicker-free-plus4.asm | 177 +++++++++++++++++-------------- src/elite-modify-plus4.py | 41 ++++--- 2 files changed, 127 insertions(+), 91 deletions(-) diff --git a/src/elite-flicker-free-plus4.asm b/src/elite-flicker-free-plus4.asm index e8b72eb..1a0a871 100644 --- a/src/elite-flicker-free-plus4.asm +++ b/src/elite-flicker-free-plus4.asm @@ -535,6 +535,81 @@ GUARD $80F5 + $08F0 JMP WP1 \ Reset the ball line heap and return from the \ subroutine using a tail call +\ ****************************************************************************** +\ +\ Name: EraseRestOfPlanet +\ Type: Subroutine +\ Category: Drawing lines +\ Summary: Draw all remaining lines in the ball line heap to erase the rest +\ of the old planet +\ +\ ****************************************************************************** + +.EraseRestOfPlanet + + LDY XX14 \ Set Y to the offset in XX14, which points to the part + \ of the heap that we are overwriting with new points + + CPY XX14+1 \ If XX14 >= XX14+1, then we have already redrawn all of + BCS eras1 \ the lines from the old circle's ball line heap, so + \ skip the following + + JSR DrawPlanetLine \ Erase the next planet line from the ball line heap + + JMP EraseRestOfPlanet \ Loop back for the next line in the ball line heap + +.eras1 + + RTS \ Return from the subroutine + +\ ****************************************************************************** +\ +\ Name: BLINE +\ Type: Subroutine +\ Category: Drawing circles +\ Summary: Draw a circle segment and add it to the ball line heap +\ +\ ****************************************************************************** + +.PATCH3 + + \ These are the instructions from the end of BLINE that + \ we move here so there's room for the patch + + LDA K6+2 \ + STA K5+2 \ * K5(3 2) = screen y-coordinate of this point + LDA K6+3 \ + STA K5+3 \ They now become the "previous point" in the next call + + LDA CNT \ Set CNT = CNT + STP + CLC + ADC STP + STA CNT + + RTS \ Return from the subroutine + +\ ****************************************************************************** +\ +\ Name: PL9 (Part 1 of 3) +\ Type: Subroutine +\ Category: Drawing planets +\ Summary: Draw the planet, with either an equator and meridian, or a crater +\ +\ ****************************************************************************** + +.PATCH6 + + LDA TYPE \ If the planet type is 128 then it has an equator and + CMP #128 \ a meridian, so this jumps to PL26 if this is not a + BNE P%+5 \ planet with an equator - in other words, if it is a + \ planet with a crater + + JMP PL9_2 \ Otherwise this is a planet with an equator and + \ meridian, so jump to the equator routine in part 2 of + \ PL9 + + JMP PL26 \ Jump to the crater routine + SAVE "wpls2-plus4.bin", WPLS2, P% \ ****************************************************************************** @@ -546,7 +621,7 @@ SAVE "wpls2-plus4.bin", WPLS2, P% \ \ ****************************************************************************** -ORG $7100 +ORG $7200 GUARD $7300 @@ -699,33 +774,6 @@ GUARD $7300 JMP LL78 \ Jump down to part 11 -\ ****************************************************************************** -\ -\ Name: EraseRestOfPlanet -\ Type: Subroutine -\ Category: Drawing lines -\ Summary: Draw all remaining lines in the ball line heap to erase the rest -\ of the old planet -\ -\ ****************************************************************************** - -.EraseRestOfPlanet - - LDY XX14 \ Set Y to the offset in XX14, which points to the part - \ of the heap that we are overwriting with new points - - CPY XX14+1 \ If XX14 >= XX14+1, then we have already redrawn all of - BCS eras1 \ the lines from the old circle's ball line heap, so - \ skip the following - - JSR DrawPlanetLine \ Erase the next planet line from the ball line heap - - JMP EraseRestOfPlanet \ Loop back for the next line in the ball line heap - -.eras1 - - RTS \ Return from the subroutine - \ ****************************************************************************** \ \ Name: DrawPlanetLine @@ -854,6 +902,28 @@ GUARD $7300 RTS \ Return from the subroutine +SAVE "extra-plus4.bin", LLX30, P% + +\ ****************************************************************************** +\ +\ Name: Put patches into NOPs in Trumble code +\ Type: Subroutine +\ +\ ****************************************************************************** + +ORG $1E6A + +GUARD $1EB6 + +.TRUMBLE + + JMP PATCHEND \ We inject the following into the batch of NOPs that + \ the Plus/4 version has inserted into the middle of the + \ Trumble sprite-plotting routine, so this instruction + \ just skips over the patches so the routine can still + \ run (the Trumble routine does not have an entry point + \ within the NOPs, so this is safe) + \ ****************************************************************************** \ \ Name: DrawNewPlanetLine @@ -911,32 +981,6 @@ GUARD $7300 RTS \ Return from the subroutine -\ ****************************************************************************** -\ -\ Name: BLINE -\ Type: Subroutine -\ Category: Drawing circles -\ Summary: Draw a circle segment and add it to the ball line heap -\ -\ ****************************************************************************** - -.PATCH3 - - \ These are the instructions from the end of BLINE that - \ we move here so there's room for the patch - - LDA K6+2 \ - STA K5+2 \ * K5(3 2) = screen y-coordinate of this point - LDA K6+3 \ - STA K5+3 \ They now become the "previous point" in the next call - - LDA CNT \ Set CNT = CNT + STP - CLC - ADC STP - STA CNT - - RTS \ Return from the subroutine - \ ****************************************************************************** \ \ Name: PLS22 @@ -986,27 +1030,6 @@ GUARD $7300 RTS \ Return from the subroutine -\ ****************************************************************************** -\ -\ Name: PL9 (Part 1 of 3) -\ Type: Subroutine -\ Category: Drawing planets -\ Summary: Draw the planet, with either an equator and meridian, or a crater -\ -\ ****************************************************************************** - -.PATCH6 - - LDA TYPE \ If the planet type is 128 then it has an equator and - CMP #128 \ a meridian, so this jumps to PL26 if this is not a - BNE P%+5 \ planet with an equator - in other words, if it is a - \ planet with a crater - - JMP PL9_2 \ Otherwise this is a planet with an equator and - \ meridian, so jump to the equator routine in part 2 of - \ PL9 - - JMP PL26 \ Jump to the crater routine - -SAVE "extra-plus4.bin", LLX30, P% +.PATCHEND +SAVE "trumble-plus4.bin", TRUMBLE, P% diff --git a/src/elite-modify-plus4.py b/src/elite-modify-plus4.py index c7fef03..812a3c4 100644 --- a/src/elite-modify-plus4.py +++ b/src/elite-modify-plus4.py @@ -89,9 +89,9 @@ print("[ Read ] elite_+4_unpacked.prg") # Set the addresses for the extra routines (LLX30, PATCH1, PATCH2) that we will # load into unused portiong of the main game code -llx30 = 0x7100 -patch1 = 0x713E -patch2 = 0x7155 +llx30 = 0x7200 +patch1 = 0x723E +patch2 = 0x7255 # We now modify the code to implement flicker-free ship drawing. The code # changes are described here, which can be read alongside the following: @@ -304,27 +304,24 @@ insert_binary_file(data_block, 0xA15B + 0x900, "ll78-plus4.bin") insert_binary_file(data_block, 0xA178 + 0x900, "ll155-plus4.bin") # We now load the three extra routines required by the modifications into the -# memory used by the Trumble sprites, which are not used in the Plus/4 version: +# memory used by the explosion and Trumble sprites, which are not used in the +# Plus/4 version: # # LLX30 # PATCH1 # PATCH2 -# -# PATCH3 -# PATCH4 -# PATCH5 -# PATCH6 +# DrawPlanetLine -insert_binary_file(data_block, 0x7100, "extra-plus4.bin") +insert_binary_file(data_block, 0x7200, "extra-plus4.bin") # We now move on to the routines for drawing flicker-free planets # Set the addresses for the extra routines (EraseRestOfPlanet, PATCH4, PATCH5) # that we inserted above -erasep = 0x715B -patch4 = 0x7229 -patch5 = 0x722E +erasep = 0x89BC +patch4 = 0x1EA0 +patch5 = 0x1EA5 # PL9 (Part 1 of 3) # @@ -357,7 +354,12 @@ insert_bytes(data_block, 0x7DE2 + 0x8F0, [ # # We have already assembled the modified WPLS2 in BeebAsm and saved it as # the binary file wpls2.bin, so now we drop this over the top of the -# existing routine (which is quite a bit longer, so there is room). +# existing routine. This binary contains the following routines: +# +# WPLS2 +# EraseRestOfPlanet +# PATCH3 +# PATCH6 insert_binary_file(data_block, 0x80BB + 0x8F0, "wpls2-plus4.bin") @@ -411,6 +413,17 @@ insert_nops(data_block, 0x8061 + 0x8F0, 1) insert_binary_file(data_block, 0x2974, "bline-plus4.bin") +# We now load the extra routines required by the modifications into the memory +# used by the Trumble sprite-drawing routine, which contains a whole raft of +# NOPs in the Plus/4 version. We can therefore slip the following routines into +# this set of NOPs, adding a JMP beforehand to skip over the patches: +# +# DrawNewPlanetLine +# PATCH4 +# PATCH5 + +insert_binary_file(data_block, 0x1E6A, "trumble-plus4.bin") + # All the modifications are done, so write the output file for the modified PRG output_file = open("elite_+4_modified.prg", "wb")