This is an old revision of the document!
Math
The Math Routines manipulate floating BCD and decimal numbers, transfer data, and halt cartridge execution.
Note: Most of the Math routines are undocumented in the Nutting Manual. Their definitions and usage are largely found in the operating system source listing and Bally On-Board ROM Subroutines.
Math System Routines
Undocumented routines are marked with an asterisk (*)
Name | Description |
---|---|
BCDADD* | BCD add |
BCDCHS* | BCD change sign |
BCDDIV* | BCD divide |
BCDMUL* | BCD multiply |
BCDNEG* | BCD negate |
BCDSUB* | BCD subtract |
DABS* | Decimal absolute value |
DADD* | Decimal add |
DSMG* | Decimal convert to sign magnitude |
INDEXB | Returns byte at address + displacement |
INDEXN | Look up a given nibble in a linear list |
INDEXW | Look up a given word in a linear list |
MOVE | Block transfer, copies bytes from source to destination |
NEGT* | Decimal negate |
QUIT* | Quit cartridge execution (holds present game score until key hit or game over) |
RANGED | Generate ranged random number |
SETB | Store byte at a specified address |
SETW | Store 16-bit word at specified address |
SHIFTU* | Shift up digit in A |
STOREN | Store 4-bit nibble in a linear list |
Math System Routine Descriptions
BCDADD
BCD ADDITION
Calling Sequence: | SYSTEM BCDADD or SYSSUK BCDADD DW () DW () DB () |
Arguments: | B = SIZE/2 + 1 DE = Argument 1 HL = Argument 2 |
Output: | DE = Answer |
Notes: | None |
Description: |
BCDCHS
BCD CHANGE SIGN
BCDDIV
BCDMUL
BCDNEG
BCDSUB
DABS
DADD
DSMG
INDEXB
INDEX BYTE
Calling Sequence: | SYSTEM INDEXB or SYSSUK INDEX DW (base address) |
Arguments: | A = Displacement (0–255) HL = Base address of table |
Output: | A = Entry looked up HL = Address of entry looked up |
Notes: | None |
Description: | INDEXB returns the byte at address (Base address) + (Displacement) |
Restrictions: | None |
INDEXN
INDEX NIBBLE
Calling Sequence: | SYSTEM INDEXN or SYSSUK INDEXN DW (base address) |
Arguments: | C = Nibble displacement (0–255) HL = Base address of table |
Output: | A = Nibble value |
Notes: | Indexing illustration below |
Description: | INDEXN looks up a specified nibble in a linear list. |
Restrictions: | None |
INDEXW
INDEX WORD
Calling Sequence: | SYSTEM INDEXW or SYSSUK INDEXW DW (base address) |
Arguments: | A = Displacement (0–255) HL = Base address of table |
Output: | DE = Entry looked up HL = Address of entry looked up |
Notes: | Indexing illustration below |
Description: | None |
MOVE
MOVE BYTES
Calling Sequence: | SYSTEM MOVE or SYSSUK MOVE DW (destination) DW (number of bytes) DW (source) |
Arguments: | DE = Destination address HL = Source address BC = Number of bytes to transfer |
Notes: | None |
Description: | MOVE uses LDIR to copy bytes from source to destination. |
Restrictions: | None |
NEGT
QUIT
RANGED
RANGED RANDOM NUMBER
Calling Sequence: | SYSTEM RANGED or SYSSUK RANGED DB (N) |
Arguments: | A = Range |
Output: | A = Random Number (0 to Range - 1) |
Notes: | If N is a power of 2, it is considerably faster to use N=0, which causes an 8-bit value to be returned without ranging. Use an AND instruction to range it yourself. RANGED uses a polynomial shift register RANSHT in system RAM. RANGED is called in GETNUM while waiting for game selection/parameter entry. Thus each execution of a program will receive different random numbers. For 'predictable' random numbers, alter RANSHT yourself after parameter acceptance. |
Description: | Returns a ranged random number. |
Restrictions: | None |
SETB
STORE BYTE
Calling Sequence: | SYSTEM SETB or SYSSUK SETB DB (value to store) DW (address) |
Arguments: | A = Byte value to store HL = Storage address |
Notes: | None |
Description: | Stores an 8-bit value at a specified address. |
Restrictions: | None |
SETW
STORE WORD
Calling Sequence: | SYSTEM SETW or SYSSUK SETW DW (value to store) DW (address) |
Arguments: | DE = Word value to store HL = Storage address |
Notes: | None |
Description: | Stores a 16-bit value at a specified address. |
Restrictions: | None |
SHIFTU
SHIFT UP DIGIT IN A
Calling Sequence: | SYSTEM ????
|
Arguments: | |
Notes: | Currently undocumented |
Description: | Shift up digit in A |
Restrictions: | None |
STOREN
STORE NIBBLE
Calling Sequence: | SYSTEM STOREN or SYSSUK STOREN DW (base address) |
Arguments: | C = Nibble displacement (not loaded) HL = Base address A = Nibble value to store (not loaded) |
Notes: | None |
Description: | STOREN is the inverse of INDEXN but functions identically. |
Restrictions: | None |