This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
Name: gnum Type: Subroutine Category: Market Summary: Get a number from the keyboard
Get a number from the keyboard, up to the maximum number in QQ25, for the buying and selling of cargo and equipment.
Pressing "Y" will return the maximum number (i.e. buy/sell all items), while pressing "N" will abort the sale and return a 0.
Pressing a key with an ASCII code less than ASCII "0" will return a 0 in A (so that includes pressing Space or Return), while pressing a key with an ASCII code greater than ASCII "9" will jump to the Inventory screen (so that includes all letters and most punctuation).
Arguments: QQ25 The maximum number allowed
Returns: A The number entered R Also contains the number entered C flag Set if the number is too large (> QQ25), clear otherwise
This variation is blank in the Cassette, Disc (docked), 6502 Second Processor and Electron versions.
Other entry points: OUT The OUTX routine jumps back here after printing the key that was just pressed
.gnum
This variation is blank in the Cassette, Disc (docked) and Electron versions.
Tap on a block to expand it, and tap it again to revert.
LDX #0 \ We will build the number entered in R, so initialise STX R \ it with 0 LDX #12 \ We will check for up to 12 key presses, so set a STX T1 \ counter in T1 .TT223 JSR TT217 \ Scan the keyboard until a key is pressed, and return \ the key's ASCII code in A (and X)
When buying or selling cargo in the enhanced versions, you can specify an exact amount of cargo for the transaction, or you can press "Y" to buy/sell everything, or "N" to buy/sell nothing. In the cassette version, you have to enter the exact amount you want to buy, and if you want to sell an item, then you have to sell your entire stock of that item, rather than part of it.
See below for more variations related to this code.
This variation is blank in the Cassette and Electron versions.
Tap on a block to expand it, and tap it again to revert.
STA Q \ Store the key pressed in Q SEC \ Subtract ASCII "0" from the key pressed, to leave the SBC #'0' \ numeric value of the key in A (if it was a number key) BCC OUT \ If A < 0, jump to OUT to load the current number and \ return from the subroutine, as the key pressed was \ RETURN (or some other ncharacter with a value less \ than ASCII "0") CMP #10 \ If A >= 10, jump to BAY2 to display the Inventory BCS BAY2 \ screen, as the key pressed was a letter or other \ non-digit and is greater than ASCII "9" STA S \ Store the numeric value of the key pressed in S LDA R \ Fetch the result so far into A
If you try to enter a number that is too big when buying or selling in the Master version, all your key presses are displayed, whereas in the other versions the key press that pushes you over the edge is not shown.
See below for more variations related to this code.
Tap on a block to expand it, and tap it again to revert.
ASL A \ Set A = (A * 2) + (A * 8) = A * 10 STA T ASL A ASL A ADC T
Code variation 6 of 12
See variation 5 above for details.
Tap on a block to expand it, and tap it again to revert.
CMP QQ25 \ If the result in R = the maximum allowed in QQ25, jump BEQ TT226 \ to TT226 to print the key press and keep looping (the \ BEQ is needed because the BCS below would jump to OUT \ if R >= QQ25, which we don't want)
Code variation 7 of 12
See variation 5 above for details.
Tap on a block to expand it, and tap it again to revert.
.TT226 LDA Q \ Print the character in Q (i.e. the key that was JSR TT26 \ pressed, as we stored the ASCII value in Q earlier) DEC T1 \ Decrement the loop counter BNE TT223 \ Loop back to TT223 until we have checked for 12 digits .OUT
This variation is blank in the Cassette, Disc (docked) and Electron versions.
Tap on a block to expand it, and tap it again to revert.
LDA R \ Set A to the result we have been building in R RTS \ Return from the subroutine
Code variation 9 of 12
See variation 4 above for details.
This variation is blank in the Cassette and Electron versions.
This variation is blank in the Cassette and Electron versions.
Tap on a block to expand it, and tap it again to revert.
Code variation 11 of 12
See variation 4 above for details.
This variation is blank in the Cassette and Electron versions.
Tap on a block to expand it, and tap it again to revert.