Skip to navigation

Elite on the BBC Micro and NES

Equipment: refund

[NES version, Bank 0]

Name: refund [Show more] Type: Subroutine Category: Equipment Summary: Install a new laser, processing a refund if applicable
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * EQSHP calls refund

Arguments: A The power of the new laser to be fitted X The view number for fitting the new laser (0-3)
Returns: A A is preserved X X is preserved
.refund STA T1 ; Store A in T1 so we can retrieve it later LDA LASER,X ; If there is no laser in view X (i.e. the laser power BEQ ref3 ; is zero), jump to ref3 to skip the refund code LDY #4 ; If the current laser has power #POW+9 (pulse laser), CMP #POW+9 ; jump to ref1 with Y = 4 (the item number of a pulse BEQ ref1 ; laser in the table at PRXS) LDY #5 ; If the current laser has power #POW+128 (beam laser), CMP #POW+128 ; jump to ref1 with Y = 5 (the item number of a beam BEQ ref1 ; laser in the table at PRXS) LDY #12 ; If the current laser has power #Armlas (military CMP #Armlas ; laser), jump to ref1 with Y = 12 (the item number of a BEQ ref1 ; military laser in the table at PRXS) LDY #13 ; Otherwise this is a mining laser, so fall through into ; ref1 with Y = 13 (the item number of a mining laser in ; the table at PRXS) .ref1 ; We now want to refund the laser of type Y that we are ; exchanging for the new laser STX ZZ ; Store the view number in ZZ so we can retrieve it ; later TYA ; Copy the laser type to be refunded from Y to A JSR prx ; Call prx to set (Y X) to the price of equipment item ; number A JSR MCASH ; Call MCASH to add (Y X) to the cash pot LDX ZZ ; Retrieve the view number from ZZ .ref3 ; Finally, we install the new laser LDA T1 ; Retrieve the new laser's power from T1 into A STA LASER,X ; Set the laser view to the new laser's power JSR BEEP_b7 ; Call the BEEP subroutine to make a short, high beep JMP EQSHP ; Jump back to the EQSHP routine (which called this ; routine using a JMP), to redisplay the Equip Ship ; screen RTS ; Return from the subroutine