Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
system_routines:math [2016/06/02 10:04]
ex_writer [SETW]
system_routines:math [2016/06/14 10:41]
ex_writer [DADD]
Line 7: Line 7:
  
 Undocumented routines are marked with an asterisk (*) Undocumented routines are marked with an asterisk (*)
 +
 +<WRAP todo>​Need documentation for most math routines</​WRAP>​
  
 ^ Name ^ Description ^ ^ Name ^ Description ^
-| [[#bcdadd|BCDADD]]* | BCD add | +| [[#​BCDADD]]* | BCD add | 
-| [[#bcdchs|BCDCHS]]* | BCD change sign |+| [[#​BCDCHS]]* | BCD change sign |
 | [[#​bcddiv|BCDDIV]]* | BCD divide | | [[#​bcddiv|BCDDIV]]* | BCD divide |
 | [[#​bcdmul|BCDMUL]]* | BCD multiply | | [[#​bcdmul|BCDMUL]]* | BCD multiply |
Line 35: Line 37:
  
 | Calling Sequence: | <code z80>​SYSTEM ​   BCDADD</​code>​ or <code z80>​SYSSUK ​   BCDADD | Calling Sequence: | <code z80>​SYSTEM ​   BCDADD</​code>​ or <code z80>​SYSSUK ​   BCDADD
-DW       () +DW       (arg 1
-DW       () +DB       (size/2 + 1
-DB       ()</​code>​|+DW       (arg 2)</​code>​|
 | Arguments: | B = SIZE/2 + 1\\ DE = Argument 1\\ HL = Argument 2 | | Arguments: | B = SIZE/2 + 1\\ DE = Argument 1\\ HL = Argument 2 |
 | Output: | DE = Answer | | Output: | DE = Answer |
Line 45: Line 47:
  
 BCD CHANGE SIGN BCD CHANGE SIGN
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   BCDCHS</​code>​ or <code z80>​SYSSUK ​   BCDCHS
 +DB       ()
 +DW       ​()</​code>​|
 +| Arguments: | B =\\ HL = |
 +| Output: |  |
 +| Notes: | None |
 +| Description:​ |  |
 ==== BCDDIV ==== ==== BCDDIV ====
  
 BCD DIVISION BCD DIVISION
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   BCDDIV</​code>​ or <code z80>​SYSSUK ​   BCDDIV
 +DW       (arg 1)
 +DB       ()
 +DW       (arg 2)</​code>​|
 +| Arguments: | B = \\ DE = \\ HL = Argument 2 |
 +| Output: | ??? |
 +| Notes: | None |
 +| Description:​ |  |
 ==== BCDMUL ==== ==== BCDMUL ====
  
 BCD MULTIPLY BCD MULTIPLY
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   BCDMUL</​code>​ or <code z80>​SYSSUK ​   BCDMUL
 +DW       (arg 1)
 +DB       ()
 +DW       (arg 2)</​code>​|
 +| Arguments: | B =\\ DE =\\ HL = |
 +| Output: | DE = Answer |
 +| Notes: | None |
 +| Description:​ |  |
 ==== BCDNEG ==== ==== BCDNEG ====
  
 BCD NEGATE TO DECIMAL BCD NEGATE TO DECIMAL
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   BCDNEG</​code>​ or <code z80>​SYSSUK ​   BCDNEG
 +DW       ()
 +DB       ​()</​code>​|
 +| Arguments: | B =\\ DE = |
 +| Output: | ??? |
 +| Notes: | None |
 +| Description:​ |  |
 ==== BCDSUB ==== ==== BCDSUB ====
  
 BCD SUBTRACTION BCD SUBTRACTION
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   BCDSUB</​code>​ or <code z80>​SYSSUK ​   BCDSUB
 +DW       (arg 1)
 +DB       ()
 +DW       (arg 2)</​code>​|
 +| Arguments: | B =\\ DE =\\ HL = |
 +| Output: | DE = Answer |
 +| Notes: | None |
 +| Description:​ |  |
 ==== DABS ==== ==== DABS ====
  
 DECIMAL ABSOLUTE VALUE DECIMAL ABSOLUTE VALUE
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   DABS</​code>​ or <code z80>​SYSSUK ​   DABS
 +DW       ()
 +DB       ​()</​code>​|
 +| Arguments: | B =\\ DE = |
 +| Output: |  |
 +| Notes: | None |
 +| Description:​ |  |
 ==== DADD ==== ==== DADD ====
  
 DECIMAL ADDITION DECIMAL ADDITION
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   DADD</​code>​ or <code z80>​SYSSUK ​   DADD
 +DW       (arg 1)
 +DB       ()
 +DW       (arg 2)</​code>​|
 +| Arguments: | B = \\ DE = \\ HL = |
 +| Output: | ??? |
 +| Notes: | None |
 +| Description:​ |  |
 ==== DSMG ==== ==== DSMG ====
  
Line 74: Line 136:
 | Arguments: | A = Displacement (0–255)\\ HL = Base address of table | | Arguments: | A = Displacement (0–255)\\ HL = Base address of table |
 | Output: | A = Entry looked up\\ HL = Address of entry looked up | | Output: | A = Entry looked up\\ HL = Address of entry looked up |
-| Notes: | None | 
 | Description:​ | INDEXB returns the byte at address (Base address) + (Displacement) | | Description:​ | INDEXB returns the byte at address (Base address) + (Displacement) |
-| Restrictions:​ | None | 
  
 ==== INDEXN ==== ==== INDEXN ====
Line 88: Line 148:
 | Notes: | Indexing illustration below | | Notes: | Indexing illustration below |
 | Description:​ | INDEXN looks up a specified nibble in a linear list. | | Description:​ | INDEXN looks up a specified nibble in a linear list. |
-| Restrictions:​ | None | 
  
 {{:​indexn.png}} {{:​indexn.png}}
Line 112: Line 171:
 DW       ​(source)</​code>​| DW       ​(source)</​code>​|
 | Arguments: | DE = Destination address\\ HL = Source address\\ BC = Number of bytes to transfer | | 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. | | Description:​ | MOVE uses LDIR to copy bytes from source to destination. |
-| Restrictions:​ | None |+
 ==== NEGT ==== ==== NEGT ====
  
 DECIMAL NEGATE DECIMAL NEGATE
  
 +| Calling Sequence: | <code z80>​SYSTEM ​   NEGT</​code>​ or <code z80>​SYSSUK ​   NEGT
 +DB       (B)
 +DW       ​(HL)</​code>​|
 +| Arguments: | B =\\ HL = |
 +| Output: | ??? |
 +| Notes: | None |
 +| Description:​ |  |
 ==== RANGED ==== ==== RANGED ====
  
Line 127: Line 192:
 | Arguments: | A = Range | | Arguments: | A = Range |
 | Output: | A = Random Number (0 to Range - 1) | | 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. |+| 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 [[software: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. | | Description:​ | Returns a ranged random number. |
-| Restrictions:​ | None | 
 ==== SETB ==== ==== SETB ====
  
Line 156: Line 220:
 | Calling Sequence: | <code z80>​SYSTEM ​   ????</​code>​| | Calling Sequence: | <code z80>​SYSTEM ​   ????</​code>​|
 | Arguments: |  | | Arguments: |  |
-| Notes: | Currently undocumented ​|+| Notes: |  |
 | Description:​ | Shift up digit in A | | Description:​ | Shift up digit in A |
-| Restrictions:​ | None | 
 ==== STOREN ==== ==== STOREN ====
  
Line 166: Line 229:
 DW       (base address)</​code>​| DW       (base address)</​code>​|
 | Arguments: | C = Nibble displacement (not loaded)\\ HL = Base address\\ A = Nibble value to store (not loaded) | | 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. | 
-| Description:​ | STOREN is the inverse of [[math routines#indexn|INDEXN]] but functions identically. | +
-| Restrictions:​ | None |+