From d4aca52380b9ff623d37c4043b27778e7ef57444 Mon Sep 17 00:00:00 2001 From: Mark Moxon Date: Fri, 14 Apr 2023 13:39:56 +0100 Subject: [PATCH] Updated flicker-free code with new BBC Master labels --- src/elite-flicker-free-plus4.asm | 104 ++++++++++++++++--------------- src/elite-flicker-free.asm | 104 ++++++++++++++++--------------- 2 files changed, 106 insertions(+), 102 deletions(-) diff --git a/src/elite-flicker-free-plus4.asm b/src/elite-flicker-free-plus4.asm index 0991afe..e075bc4 100644 --- a/src/elite-flicker-free-plus4.asm +++ b/src/elite-flicker-free-plus4.asm @@ -31,9 +31,10 @@ \ from the BBC Micro version (which is very similar, if you ignore any different \ addresses). \ -\ XX14 is an unused variable in BBC Micro Elite, and the corresponding address +\ LSNUM is an unused variable in BBC Micro Elite, and the corresponding address \ in Commodore 64 Elite is used by something else. Luckily locations $FB to $FE -\ are unused by Elite and the OS, so we can sneak XX14 in there instead. +\ are unused by Elite and the OS, so we can sneak LSNUM and LSNUM2 in there +\ instead. \ \ Also, the Y variable contains the height of the space view in pixels, divided \ by 2. This is 96 on the BBC Micro, but the space view is 144 pixels on the @@ -58,7 +59,8 @@ CNT = $00AA XX4 = $00AD XX20 = $00AE - XX14 = $00FB + LSNUM = $00FB + LSNUM2 = $00FC PROJ = $7D1F + $08F0 LL75 = $9FB8 + $0900 LL30 = $AB91 + $090C @@ -162,7 +164,7 @@ STA X2 \ Store the x-coordinate of the ship dot in X1, as this \ is where the dash starts - JMP LLX30 \ Draw this edge using flicker-free animation, by first + JMP LSPUT \ Draw this edge using flicker-free animation, by first \ drawing the ship's new line and then erasing the \ corresponding old line from the screen, and return \ from the subroutine using a tail call @@ -183,11 +185,11 @@ .LL78 - LDA XX14 \ If XX14 >= CNT, skip to LL81 so we don't loop back for - CMP CNT \ the next edge (CNT was set to the maximum heap size - BCS LL81 \ for this ship in part 10, so this checks whether we - \ have just run out of space in the ship line heap, and - \ stops drawing edges if we have) + LDA LSNUM \ If LSNUM >= CNT, skip to LL81 so we don't loop back + CMP CNT \ for the next edge (CNT was set to the maximum heap + BCS LL81 \ size for this ship in part 10, so this checks whether + \ we have just run out of space in the ship line heap, + \ and stops drawing edges if we have) LDA V \ Increment V by 4 so V(1 0) points to the data for the CLC \ next edge @@ -231,17 +233,17 @@ .LL155 - LDY XX14 \ Set Y to the offset in the line heap XX14 + LDY LSNUM \ Set Y to the offset in the line heap LSNUM .LL27 - CPY XX14+1 \ If Y >= XX14+1, jump to LLEX to return from the ship + CPY LSNUM2 \ If Y >= LSNUM2, jump to LLEX to return from the ship BCS LLEX \ drawing routine, because the index in Y is greater \ than the size of the existing ship line heap, which \ means we have alrady erased all the old ships lines \ when drawing the new ship - \ If we get here then Y < XX14+1, which means Y is + \ If we get here then Y < LSNUM2, which means Y is \ pointing to an on-screen line from the old ship that \ we need to erase @@ -273,7 +275,7 @@ .LLEX - LDA XX14 \ Store XX14 in the first byte of the ship line heap + LDA LSNUM \ Store LSNUM in the first byte of the ship line heap LDY #0 STA (XX19),Y @@ -522,12 +524,12 @@ BNE WP1 \ heap is empty), jump to WP1 to reset the line heap \ without redrawing the planet - STY XX14 \ Reset XX14 to the start of the ball line heap (we can + STY LSNUM \ Reset LSNUM to the start of the ball line heap (we can \ set this to 0 rather than 1 to take advantage of the \ fact that Y is 0 - the effect is the same) - LDA LSP \ Set XX14+1 to the end of the ball line heap - STA XX14+1 + LDA LSP \ Set LSNUM2 to the end of the ball line heap + STA LSNUM2 JSR EraseRestOfPlanet \ Draw the contents of the ball line heap to erase the \ old planet @@ -547,11 +549,11 @@ .EraseRestOfPlanet - LDY XX14 \ Set Y to the offset in XX14, which points to the part + LDY LSNUM \ Set Y to the offset in LSNUM, 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 + CPY LSNUM2 \ If LSNUM >= LSNUM2, then we have already redrawn all + BCS eras1 \ of 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 @@ -614,7 +616,7 @@ \ ****************************************************************************** \ -\ Name: LLX30 +\ Name: LSPUT \ Type: Subroutine \ Category: Drawing lines \ Summary: Draw a ship line using flicker-free animation @@ -625,12 +627,12 @@ GUARD $7300 -.LLX30 +.LSPUT - LDY XX14 \ Set Y = XX14, to get the offset within the ship line + LDY LSNUM \ Set Y = LSNUM, to get the offset within the ship line \ heap where we want to insert our new line - CPY XX14+1 \ Compare XX14 and XX14+1 and store the flags on the + CPY LSNUM2 \ Compare LSNUM and LSNUM2 and store the flags on the PHP \ stack so we can retrieve them later LDX #3 \ We now want to copy the line coordinates (X1, Y1) and @@ -679,13 +681,13 @@ STA (XX19),Y INY \ Increment the index to point to the next coordinate - STY XX14 \ and store the updated index in XX14 + STY LSNUM \ and store the updated index in LSNUM PLP \ Restore the result of the comparison above, so if the - BCS LL82a \ original value of XX14 >= XX14+1, then we have already - \ redrawn all the lines from the old ship's line heap, - \ so return from the subroutine (as LL82 contains an - \ RTS) + BCS LL82a \ original value of LSNUM >= LSNUM2, then we have + \ alreadyredrawn all the lines from the old ship's line + \ heap, so return from the subroutine (as LL82 contains + \ an RTS) JMP LL30 \ Otherwise there are still more lines to erase from the \ old ship on-screen, so the coordinates in (X1, Y1) and @@ -722,15 +724,15 @@ \ We now set things up for flicker-free ship plotting, \ by setting the following: \ - \ XX14 = offset to the first coordinate in the ship's - \ line heap + \ LSNUM = offset to the first coordinate in the ship's + \ line heap \ - \ XX14+1 = the number of bytes in the heap for the + \ LSNUM2 = the number of bytes in the heap for the \ ship that's currently on-screen (or 0 if \ there is no ship currently on-screen) - LDY #1 \ Set XX14 = 1, the offset of the first set of line - STY XX14 \ coordinates in the ship line heap + LDY #1 \ Set LSNUM = 1, the offset of the first set of line + STY LSNUM \ coordinates in the ship line heap DEY \ Decrement Y to 0 @@ -739,7 +741,7 @@ BNE P%+5 \ following two instructions LDA #0 \ The ship is not being drawn on screen, so set A = 0 - \ so that XX14+1 gets set to 0 below (as there are no + \ so that LSNUM2 gets set to 0 below (as there are no \ existing coordinates on the ship line heap for this \ ship) @@ -747,8 +749,8 @@ \ $2C $B1 $BD, or BIT $BDB1 which does nothing apart \ from affect the flags - LDA (XX19),Y \ Set XX14+1 to the first byte of the ship's line heap, - STA XX14+1 \ which contains the number of bytes in the heap + LDA (XX19),Y \ Set LSNUM2 to the first byte of the ship's line heap, + STA LSNUM2 \ which contains the number of bytes in the heap RTS @@ -766,9 +768,9 @@ \ We replace the JMP LL78 instruction at the end of part \ 10 of LL9 with JSR PATCH2, so this effectively inserts - \ the call to LLX30 at the end of part 10, as required + \ the call to LSPUT at the end of part 10, as required - JSR LLX30 \ Draw the laser line using flicker-free animation, by + JSR LSPUT \ Draw the laser line using flicker-free animation, by \ first drawing the new laser line and then erasing the \ corresponding old line from the screen @@ -798,7 +800,7 @@ LDA #0 \ Clear bit 7 of K3+9 to indicate that there is no line STA K3+9 \ to draw (we may change this below) - LDA XX14 \ If XX14 = 1, then this is the first point from the + LDA LSNUM \ If LSNUM = 1, then this is the first point from the CMP #2 \ heap, so jump to plin3 to set the previous coordinate BCC plin3 \ and return from the subroutine @@ -813,11 +815,11 @@ TYA PHA - LDY XX14 \ Set Y to the offset in XX14, which points to the part + LDY LSNUM \ Set Y to the offset in LSNUM, 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 plin1 \ the lines from the old circle's ball line heap, so + CPY LSNUM2 \ If LSNUM >= LSNUM2, then we have already redrawn all + BCS plin1 \ of the lines from the old circle's ball line heap, so \ jump to plin1 to return from the subroutine \ Otherwise we need to draw the line from the heap, to @@ -829,19 +831,19 @@ LDA K3+3 \ Set Y1 = K3+3 = screen y-coordinate of previous point STA Y1 \ from the old heap - LDA LSX2,Y \ Set X2 to the y-coordinate from the XX14-th point in + LDA LSX2,Y \ Set X2 to the y-coordinate from the LSNUM-th point in STA X2 \ the heap STA K3+2 \ Store the x-coordinate of the point we are overwriting \ in K3+2, so we can use it on the next iteration - LDA LSY2,Y \ Set Y2 to the y-coordinate from the XX14-th point in + LDA LSY2,Y \ Set Y2 to the y-coordinate from the LSNUM-th point in STA Y2 \ the heap STA K3+3 \ Store the y-coordinate of the point we are overwriting \ in K3+3, so we can use it on the next iteration - INC XX14 \ Increment XX14 to point to the next coordinate, so we + INC LSNUM \ Increment LSNUM to point to the next coordinate, so we \ work our way through the current heap LDA Y1 \ If Y1 or Y2 = &FF then this indicates a break in the @@ -897,12 +899,12 @@ LDA LSY2+1 STA K3+3 - INC XX14 \ Increment XX14 to point to the next coordinate, so we + INC LSNUM \ Increment LSNUM to point to the next coordinate, so we \ work our way through the current heap RTS \ Return from the subroutine - SAVE "extra-plus4.bin", LLX30, P% + SAVE "extra-plus4.bin", LSPUT, P% \ ****************************************************************************** \ @@ -1012,11 +1014,11 @@ .PATCH5 - LDX #0 \ Set XX14 = 0, to point to the offset before the first - STX XX14 \ set of circle coordinates in the ball line heap + LDX #0 \ Set LSNUM = 0, to point to the offset before the first + STX LSNUM \ set of circle coordinates in the ball line heap - LDX LSP \ Set XX14+1 to the last byte of the ball line heap - STX XX14+1 + LDX LSP \ Set LSNUM2 to the last byte of the ball line heap + STX LSNUM2 LDX #1 \ Set LSP = 1 to reset the ball line heap pointer STX LSP diff --git a/src/elite-flicker-free.asm b/src/elite-flicker-free.asm index 99aa437..00e038f 100644 --- a/src/elite-flicker-free.asm +++ b/src/elite-flicker-free.asm @@ -31,9 +31,10 @@ \ from the BBC Micro version (which is very similar, if you ignore any different \ addresses). \ -\ XX14 is an unused variable in BBC Micro Elite, and the corresponding address +\ LSNUM is an unused variable in BBC Micro Elite, and the corresponding address \ in Commodore 64 Elite is used by something else. Luckily locations $FB to $FE -\ are unused by Elite and the OS, so we can sneak XX14 in there instead. +\ are unused by Elite and the OS, so we can sneak LSNUM and LSNUM2 in there +\ instead. \ \ Also, the Y variable contains the height of the space view in pixels, divided \ by 2. This is 96 on the BBC Micro, but the space view is 144 pixels on the @@ -58,7 +59,8 @@ CNT = $00AA XX4 = $00AD XX20 = $00AE - XX14 = $00FB + LSNUM = $00FB + LSNUM2 = $00FC PROJ = $7D1F LL75 = $9FB8 LL30 = $AB91 @@ -162,7 +164,7 @@ STA X2 \ Store the x-coordinate of the ship dot in X1, as this \ is where the dash starts - JMP LLX30 \ Draw this edge using flicker-free animation, by first + JMP LSPUT \ Draw this edge using flicker-free animation, by first \ drawing the ship's new line and then erasing the \ corresponding old line from the screen, and return \ from the subroutine using a tail call @@ -183,11 +185,11 @@ .LL78 - LDA XX14 \ If XX14 >= CNT, skip to LL81 so we don't loop back for - CMP CNT \ the next edge (CNT was set to the maximum heap size - BCS LL81 \ for this ship in part 10, so this checks whether we - \ have just run out of space in the ship line heap, and - \ stops drawing edges if we have) + LDA LSNUM \ If LSNUM >= CNT, skip to LL81 so we don't loop back + CMP CNT \ for the next edge (CNT was set to the maximum heap + BCS LL81 \ size for this ship in part 10, so this checks whether + \ we have just run out of space in the ship line heap, + \ and stops drawing edges if we have) LDA V \ Increment V by 4 so V(1 0) points to the data for the CLC \ next edge @@ -231,17 +233,17 @@ .LL155 - LDY XX14 \ Set Y to the offset in the line heap XX14 + LDY LSNUM \ Set Y to the offset in the line heap LSNUM .LL27 - CPY XX14+1 \ If Y >= XX14+1, jump to LLEX to return from the ship + CPY LSNUM2 \ If Y >= LSNUM2, jump to LLEX to return from the ship BCS LLEX \ drawing routine, because the index in Y is greater \ than the size of the existing ship line heap, which \ means we have alrady erased all the old ships lines \ when drawing the new ship - \ If we get here then Y < XX14+1, which means Y is + \ If we get here then Y < LSNUM2, which means Y is \ pointing to an on-screen line from the old ship that \ we need to erase @@ -273,7 +275,7 @@ .LLEX - LDA XX14 \ Store XX14 in the first byte of the ship line heap + LDA LSNUM \ Store LSNUM in the first byte of the ship line heap LDY #0 STA (XX19),Y @@ -522,12 +524,12 @@ BNE WP1 \ heap is empty), jump to WP1 to reset the line heap \ without redrawing the planet - STY XX14 \ Reset XX14 to the start of the ball line heap (we can + STY LSNUM \ Reset LSNUM to the start of the ball line heap (we can \ set this to 0 rather than 1 to take advantage of the \ fact that Y is 0 - the effect is the same) - LDA LSP \ Set XX14+1 to the end of the ball line heap - STA XX14+1 + LDA LSP \ Set LSNUM2 to the end of the ball line heap + STA LSNUM2 JSR EraseRestOfPlanet \ Draw the contents of the ball line heap to erase the \ old planet @@ -539,7 +541,7 @@ \ ****************************************************************************** \ -\ Name: LLX30 +\ Name: LSPUT \ Type: Subroutine \ Category: Drawing lines \ Summary: Draw a ship line using flicker-free animation @@ -550,12 +552,12 @@ GUARD $CE00 -.LLX30 +.LSPUT - LDY XX14 \ Set Y = XX14, to get the offset within the ship line + LDY LSNUM \ Set Y = LSNUM, to get the offset within the ship line \ heap where we want to insert our new line - CPY XX14+1 \ Compare XX14 and XX14+1 and store the flags on the + CPY LSNUM2 \ Compare LSNUM and LSNUM2 and store the flags on the PHP \ stack so we can retrieve them later LDX #3 \ We now want to copy the line coordinates (X1, Y1) and @@ -604,13 +606,13 @@ STA (XX19),Y INY \ Increment the index to point to the next coordinate - STY XX14 \ and store the updated index in XX14 + STY LSNUM \ and store the updated index in LSNUM PLP \ Restore the result of the comparison above, so if the - BCS LL82a \ original value of XX14 >= XX14+1, then we have already - \ redrawn all the lines from the old ship's line heap, - \ so return from the subroutine (as LL82 contains an - \ RTS) + BCS LL82a \ original value of LSNUM >= LSNUM2, then we have + \ alreadyredrawn all the lines from the old ship's line + \ heap, so return from the subroutine (as LL82 contains + \ an RTS) JMP LL30 \ Otherwise there are still more lines to erase from the \ old ship on-screen, so the coordinates in (X1, Y1) and @@ -647,15 +649,15 @@ \ We now set things up for flicker-free ship plotting, \ by setting the following: \ - \ XX14 = offset to the first coordinate in the ship's - \ line heap + \ LSNUM = offset to the first coordinate in the ship's + \ line heap \ - \ XX14+1 = the number of bytes in the heap for the + \ LSNUM2 = the number of bytes in the heap for the \ ship that's currently on-screen (or 0 if \ there is no ship currently on-screen) - LDY #1 \ Set XX14 = 1, the offset of the first set of line - STY XX14 \ coordinates in the ship line heap + LDY #1 \ Set LSNUM = 1, the offset of the first set of line + STY LSNUM \ coordinates in the ship line heap DEY \ Decrement Y to 0 @@ -664,7 +666,7 @@ BNE P%+5 \ following two instructions LDA #0 \ The ship is not being drawn on screen, so set A = 0 - \ so that XX14+1 gets set to 0 below (as there are no + \ so that LSNUM2 gets set to 0 below (as there are no \ existing coordinates on the ship line heap for this \ ship) @@ -672,8 +674,8 @@ \ $2C $B1 $BD, or BIT $BDB1 which does nothing apart \ from affect the flags - LDA (XX19),Y \ Set XX14+1 to the first byte of the ship's line heap, - STA XX14+1 \ which contains the number of bytes in the heap + LDA (XX19),Y \ Set LSNUM2 to the first byte of the ship's line heap, + STA LSNUM2 \ which contains the number of bytes in the heap RTS @@ -691,9 +693,9 @@ \ We replace the JMP LL78 instruction at the end of part \ 10 of LL9 with JSR PATCH2, so this effectively inserts - \ the call to LLX30 at the end of part 10, as required + \ the call to LSPUT at the end of part 10, as required - JSR LLX30 \ Draw the laser line using flicker-free animation, by + JSR LSPUT \ Draw the laser line using flicker-free animation, by \ first drawing the new laser line and then erasing the \ corresponding old line from the screen @@ -711,11 +713,11 @@ .EraseRestOfPlanet - LDY XX14 \ Set Y to the offset in XX14, which points to the part + LDY LSNUM \ Set Y to the offset in LSNUM, 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 + CPY LSNUM2 \ If LSNUM >= LSNUM2, then we have already redrawn all + BCS eras1 \ of 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 @@ -750,7 +752,7 @@ LDA #0 \ Clear bit 7 of K3+9 to indicate that there is no line STA K3+9 \ to draw (we may change this below) - LDA XX14 \ If XX14 = 1, then this is the first point from the + LDA LSNUM \ If LSNUM = 1, then this is the first point from the CMP #2 \ heap, so jump to plin3 to set the previous coordinate BCC plin3 \ and return from the subroutine @@ -765,11 +767,11 @@ TYA PHA - LDY XX14 \ Set Y to the offset in XX14, which points to the part + LDY LSNUM \ Set Y to the offset in LSNUM, 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 plin1 \ the lines from the old circle's ball line heap, so + CPY LSNUM2 \ If LSNUM >= LSNUM2, then we have already redrawn all + BCS plin1 \ of the lines from the old circle's ball line heap, so \ jump to plin1 to return from the subroutine \ Otherwise we need to draw the line from the heap, to @@ -781,19 +783,19 @@ LDA K3+3 \ Set Y1 = K3+3 = screen y-coordinate of previous point STA Y1 \ from the old heap - LDA LSX2,Y \ Set X2 to the y-coordinate from the XX14-th point in + LDA LSX2,Y \ Set X2 to the y-coordinate from the LSNUM-th point in STA X2 \ the heap STA K3+2 \ Store the x-coordinate of the point we are overwriting \ in K3+2, so we can use it on the next iteration - LDA LSY2,Y \ Set Y2 to the y-coordinate from the XX14-th point in + LDA LSY2,Y \ Set Y2 to the y-coordinate from the LSNUM-th point in STA Y2 \ the heap STA K3+3 \ Store the y-coordinate of the point we are overwriting \ in K3+3, so we can use it on the next iteration - INC XX14 \ Increment XX14 to point to the next coordinate, so we + INC LSNUM \ Increment LSNUM to point to the next coordinate, so we \ work our way through the current heap LDA Y1 \ If Y1 or Y2 = &FF then this indicates a break in the @@ -849,7 +851,7 @@ LDA LSY2+1 STA K3+3 - INC XX14 \ Increment XX14 to point to the next coordinate, so we + INC LSNUM \ Increment LSNUM to point to the next coordinate, so we \ work our way through the current heap RTS \ Return from the subroutine @@ -911,7 +913,7 @@ RTS \ Return from the subroutine - SAVE "extra.bin", LLX30, P% + SAVE "extra.bin", LSPUT, P% \ ****************************************************************************** \ @@ -974,11 +976,11 @@ .PATCH5 - LDX #0 \ Set XX14 = 0, to point to the offset before the first - STX XX14 \ set of circle coordinates in the ball line heap + LDX #0 \ Set LSNUM = 0, to point to the offset before the first + STX LSNUM \ set of circle coordinates in the ball line heap - LDX LSP \ Set XX14+1 to the last byte of the ball line heap - STX XX14+1 + LDX LSP \ Set LSNUM2 to the last byte of the ball line heap + STX LSNUM2 LDX #1 \ Set LSP = 1 to reset the ball line heap pointer STX LSP