Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
math_routines [2016/05/31 19:43] ex_writer [DADD] |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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 [[http://www.ballyalley.com/basic/bally_on-board_rom_subroutines.pdf|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 | | ||
- | | [[math routines#indexb|INDEXB]] | Returns byte at address + displacement | | ||
- | | [[math routines#indexn|INDEXN]] | Look up a given nibble in a linear list | | ||
- | | [[math routines#indexw|INDEXW]] | Look up a given word in a linear list | | ||
- | | [[math routines#move|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) | | ||
- | | [[math routines#ranged|RANGED]] | Generate ranged random number | | ||
- | | [[math routines#setb|SETB]] | Store byte at a specified address | | ||
- | | [[math routines#setw|SETW]] | Store 16-bit word at specified address | | ||
- | | SHIFTU* | Shift up digit in A | | ||
- | | [[math routines#storen|STOREN]] | Store 4-bit nibble in a linear list | | ||
- | ===== Math System Routine Descriptions ===== | ||
- | |||
- | ==== BCDADD ==== | ||
- | |||
- | BCD ADDITION | ||
- | |||
- | | Calling Sequence: | <code z80>SYSTEM BCDADD</code> or <code z80>SYSSUK BCDADD | ||
- | DW () | ||
- | DW () | ||
- | DB ()</code>| | ||
- | | Arguments: | B = SIZE/2 + 1\\ DE = Argument 1\\ HL = Argument 2 | | ||
- | | Output: | DE = Answer | | ||
- | | Notes: | None | | ||
- | | Description: | | | ||
- | ==== BCDCHS ==== | ||
- | |||
- | BCD CHANGE SIGN | ||
- | ==== BCDDIV ==== | ||
- | |||
- | BCD DIVISION | ||
- | ==== BCDMUL ==== | ||
- | |||
- | BCD MULTIPLY | ||
- | ==== BCDNEG ==== | ||
- | |||
- | BCD NEGATE TO DECIMAL | ||
- | ==== BCDSUB ==== | ||
- | |||
- | ==== DABS ==== | ||
- | |||
- | ==== DADD ==== | ||
- | |||
- | DECIMAL ADDITION | ||
- | ==== DSMG ==== | ||
- | |||
- | DECIMAL CONVERT TO SIGN MAGNITUDE | ||
- | ==== INDEXB ==== | ||
- | |||
- | INDEX BYTE | ||
- | |||
- | | Calling Sequence: | <code z80>SYSTEM INDEXB</code> or <code z80>SYSSUK INDEX | ||
- | DW (base address)</code>| | ||
- | | 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: | <code z80>SYSTEM INDEXN</code> or <code z80>SYSSUK INDEXN | ||
- | DW (base address)</code>| | ||
- | | 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 | | ||
- | |||
- | {{indexn.png}} | ||
- | ==== INDEXW ==== | ||
- | |||
- | INDEX WORD | ||
- | |||
- | | Calling Sequence: | <code z80>SYSTEM INDEXW</code> or <code z80>SYSSUK INDEXW | ||
- | DW (base address)</code>| | ||
- | | 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 | | ||
- | |||
- | {{indexw.png}} | ||
- | ==== MOVE ==== | ||
- | |||
- | MOVE BYTES | ||
- | |||
- | | Calling Sequence: | <code z80>SYSTEM MOVE</code> or <code z80>SYSSUK MOVE | ||
- | DW (destination) | ||
- | DW (number of bytes) | ||
- | DW (source)</code>| | ||
- | | 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: | <code z80>SYSTEM RANGED</code> or <code z80>SYSSUK RANGED | ||
- | DB (N)</code>| | ||
- | | 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 rom#system ram memory cells|system RAM]]. RANGED is called in [[human interface#getnum|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: | <code z80>SYSTEM SETB</code> or <code z80>SYSSUK SETB | ||
- | DB (value to store) | ||
- | DW (address)</code>| | ||
- | | 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: | <code z80>SYSTEM SETW</code> or <code z80>SYSSUK SETW | ||
- | DW (value to store) | ||
- | DW (address)</code>| | ||
- | | 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: | <code z80>SYSTEM ????</code>| | ||
- | | Arguments: | | | ||
- | | Notes: | Currently undocumented | | ||
- | | Description: | Shift up digit in A | | ||
- | | Restrictions: | None | | ||
- | ==== STOREN ==== | ||
- | |||
- | STORE NIBBLE | ||
- | |||
- | | Calling Sequence: | <code z80>SYSTEM STOREN</code> or <code z80>SYSSUK STOREN | ||
- | DW (base address)</code>| | ||
- | | Arguments: | C = Nibble displacement (not loaded)\\ HL = Base address\\ A = Nibble value to store (not loaded) | | ||
- | | Notes: | None | | ||
- | | Description: | STOREN is the inverse of [[math routines#indexn|INDEXN]] but functions identically. | | ||
- | | Restrictions: | None | |