Math in cc65
Math in cc65
The assembler include file lynx.inc in the asminc folder of cc65 holds the definitions for all math registers and their hardware addresses. You can see them in the fragment below, with some editing to highlight the groups of addresses. Note that the address space is not contiguous and has some unused address ranges.
MATHD = $FC52 MATHP = $FC56 MATHH = $FC60 MATHM = $FC6C
MATHC = $FC53 MATHN = $FC57 MATHG = $FC61 MATHL = $FC6D
MATHB = $FC54 MATHF = $FC62 MATHK = $FC6E
MATHA = $FC55 MATHE = $FC63 MATHJ = $FC6F
SPRSYS = $FC92
In cc65 there is no type byte available, but you can use an alias definition if you are more comfortable with this keyword. However, not all IDEs will recognize the alias as a keyword.
#define byte unsigned char
Let’s revisit the single, double and quad byte numbers. The table below expands on the previous list of minimum and maximum values for 8, 16 and 32 bit numbers. It shows the keywords char, short and long as variable types corresponding to these respective sizes. The number types exist in higher level languages, such as C in cc65 or newcc65, and is not known in Mikey or Suzy as such. In the Atari Lynx everything is still a byte, although the Suzy math performs 16-bit and 32-bit math operations.
| Type | #bytes | Signed | Alias | Min | Max | Min | Max |
|---|---|---|---|---|---|---|---|
char |
1 | No | uchar |
0 | 255 | $00 | $FF |
signed char |
1 | Yes | schar |
-128 | 127 | $80 | $7f |
short |
2 | Yes | -32768 | 32767 | $8000 | $7FFF | |
unsigned short |
2 | No | ushort |
0 | 65535 | $0000 | $FFFF |
long |
4 | Yes | -2147483648 | 2147483647 | $80000000 | $7FFFFFFF | |
unsigned long |
4 | No | ulong |
0 | 4294967295 | $00000000 | $FFFFFFFF |
or use a function or macro definition in C:
#define MATHWAIT asm("notready: bit $fc92"); asm(" bmi notready");
while (SUZY.sprsys & MATHWORKING != 0) ;