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
system_routines:math [2016/06/05 16:35]
ex_writer [INDEXN]
system_routines:math [2016/06/14 10:42] (current)
ex_writer [DSMG]
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 ====
  
 DECIMAL CONVERT TO SIGN MAGNITUDE DECIMAL CONVERT TO SIGN MAGNITUDE
 +
 +| Calling Sequence: | <code z80>​SYSTEM ​   DSMG</​code>​ or <code z80>​SYSSUK ​   DSMG
 +DW       (arg 1)
 +DB       ​(size/​2 + 1)</​code>​|
 +| Arguments: | B = \\ DE = |
 +| Output: | ??? |
 +| Notes: | None |
 +| Description:​ |  |
 ==== INDEXB ==== ==== INDEXB ====
  
Line 109: Line 179:
 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 124: Line 200:
 | 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 153: Line 228:
 | 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 163: Line 237:
 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) |
-| Description:​ | STOREN is the inverse of [[math routines#indexn|INDEXN]] but functions identically. |+| Description:​ | STOREN is the inverse of [[#INDEXN]] but functions identically. |