Skip to navigation

Elite on the BBC Micro

Version analysis of gnum

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.

Code variation 1 of 12A variation in the comments only

This variation is blank in the Cassette and Electron versions.

Docked, 6502SP, Master

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

Code variation 2 of 12A variation in the comments only

This variation is blank in the Cassette, Disc (docked), 6502 Second Processor and Electron versions.

Master

Other entry points: OUT The OUTX routine jumps back here after printing the key that was just pressed
.gnum

Code variation 3 of 12Related to the screen mode

This variation is blank in the Cassette, Disc (docked) and Electron versions.

Tap on a version to expand it, and tap it again to show to all variations.

Master

6502SP

LDA #MAGENTA \ Switch to colour 2, which is magenta in the trade view STA COL
LDA #MAGENTA \ Send a #SETCOL MAGENTA command to the I/O processor to JSR DOCOL \ switch to colour 2, which is magenta in the trade view
 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)

Code variation 4 of 12Related to an enhanced feature

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 version to expand it, and tap it again to show to all variations.

Docked, 6502SP

Master

LDX R \ If R is non-zero then skip to NWDAV2, as we are BNE NWDAV2 \ already building a number CMP #'y' \ If "Y" was pressed, jump to NWDAV1 to return the BEQ NWDAV1 \ maximum number allowed (i.e. buy/sell the whole stock) CMP #'n' \ If "N" was pressed, jump to NWDAV3 to return from the BEQ NWDAV3 \ subroutine with a result of 0 (i.e. abort transaction) .NWDAV2
LDX R \ If R is non-zero then skip to NWDAV2, as we are BNE NWDAV2 \ already building a number CMP #'Y' \ If "Y" was pressed, jump to NWDAV1 to return the BEQ NWDAV1 \ maximum number allowed (i.e. buy/sell the whole stock) CMP #'N' \ If "N" was pressed, jump to NWDAV3 to return from the BEQ NWDAV3 \ subroutine with a result of 0 (i.e. abort transaction) .NWDAV2
 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 return from the subroutine
                        \ with a result of 0, as the key pressed was not a
                        \ number or letter and is 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

Code variation 5 of 12Related to the Master version

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 version to expand it, and tap it again to show to all variations.

Cassette, Docked, 6502SP, Electron

Master

CMP #26 \ If A >= 26, where A is the number entered so far, then BCS OUT \ adding a further digit will make it bigger than 256, \ so jump to OUT to return from the subroutine with the \ result in R (i.e. ignore the last key press)
CMP #26 \ If A >= 26, where A is the number entered so far, then BCS OUTX \ adding a further digit will make it bigger than 256, \ so jump to OUTX to print the key that was just pressed \ before jumping to OUT below with the C flag still set
 ASL A                  \ Set A = (A * 2) + (A * 8) = A * 10
 STA T
 ASL A
 ASL A
 ADC T

Code variation 6 of 12Related to the Master version

See variation 5 above for details.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Docked, 6502SP, Electron

Master

ADC S \ Add the pressed digit to A and store in R, so R now STA R \ contains its previous value with the new key press \ tacked onto the end
ADC S \ Add the pressed digit to A BCS OUTX \ If the addition overflowed, then jump to OUTX to print \ the key that was just pressed before jumping to OUT \ below with the C flag still set STA R \ Otherwise store the result in R, so R now contains \ its previous value with the new key press tacked onto \ the end
 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 12Related to the Master version

See variation 5 above for details.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Docked, 6502SP, Electron

Master

BCS OUT \ If the result in R > QQ25, jump to OUT to return from \ the subroutine with the result in R
BCS OUTX \ If the result in R > QQ25, jump to OUTX to print \ the key that was just pressed before jumping to OUT \ below with the C flag still set
.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

Code variation 8 of 12Related to the screen mode

This variation is blank in the Cassette, Disc (docked) and Electron versions.

Tap on a version to expand it, and tap it again to show to all variations.

Master

6502SP

LDA #CYAN \ Switch to colour 3, which is white in the trade view STA COL
PHP \ Store the processor flags, so we can return the C flag \ without the call to DOCOL corrupting it LDA #CYAN \ Send a #SETCOL CYAN command to the I/O processor to JSR DOCOL \ switch to colour 3, which is white in the trade view PLP \ Restore the processor flags, in particular the C flag
 LDA R                  \ Set A to the result we have been building in R

 RTS                    \ Return from the subroutine

Code variation 9 of 12Related to an enhanced feature

See variation 4 above for details.

This variation is blank in the Cassette and Electron versions.

Docked, 6502SP, Master

.NWDAV1 \ If we get here then "Y" was pressed, so we return the \ maximum number allowed, which is in QQ25 JSR TT26 \ Print the character for the key that was pressed LDA QQ25 \ Set R = QQ25, so we return the maximum value allowed STA R

Code variation 10 of 12Minor and very low-impact

This variation is blank in the Cassette and Electron versions.

Tap on a version to expand it, and tap it again to show to all variations.

Docked

Master

6502SP

RTS \ Return from the subroutine
JMP OUT \ Jump to OUT to return from the subroutine
BRA OUT \ Jump to OUT to return from the subroutine

Code variation 11 of 12Related to an enhanced feature

See variation 4 above for details.

This variation is blank in the Cassette and Electron versions.

Tap on a version to expand it, and tap it again to show to all variations.

Docked, 6502SP

Master

.NWDAV3 \ If we get here then "N" was pressed, so we return 0 JSR TT26 \ Print the character for the key that was pressed LDA #0 \ Set R = 0, so we return 0 STA R
.NWDAV3 \ If we get here then "N" was pressed, so we return 0 JSR TT26 \ Print the character for the key that was pressed STZ R \ Set R = 0, so we return 0

Code variation 12 of 12Minor and very low-impact

This variation is blank in the Cassette and Electron versions.

Tap on a version to expand it, and tap it again to show to all variations.

Docked

Master

6502SP

RTS \ Return from the subroutine
JMP OUT \ Jump to OUT to return from the subroutine
BRA OUT \ Jump to OUT to return from the subroutine
RSS Feed