]>
git.gir.st - Chiptunes.git/blob - foo.c
ac7d6ad37c07babff4d9618fc9edbd89a796d84f
3 typedef unsigned char u8
;
15 u8 x
;/*==Ml*/ //r26 (Xlo)
16 u8 t
;/*==Mh*/ //r27 (Xhi)
21 #define Mh x //mod3 vars
26 /*.byte*/ 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
27 /*.byte*/ 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
32 //http://homepage.divms.uiowa.edu/~jones/bcd/mod.shtml
38 ADC (Mh
, zero
, carry
) //Mh only holds the carry bit
63 //.macro definitions for mul-tree:
64 #define always(_bit) //nop; for when a test() is not necessary (see tree)
65 #define never(_bit) //nop; for when a test() is not necessary (see tree)
66 #define test(_bit,_jmpto) \
72 #define shift8 /*top three bits don't need to be corrrect, so save cycles by not carrying*/ \
74 #define shift0 //nop; last shift is common
79 #define add_shift8 /*ditto with carrying*/ \
82 #define add_shift0 /*last shift is common*/ \
86 // tempvars: `x` and `_`
97 MOV (tmp
, t
) //NOTE: must move value away from `t`, as that is also hi(X)
101 ADD Xlo, tmp ;<-- the offset (formerly `t`) into data[]
113 /* decision tree multiplication saves cycles and (hopefully) reduces code size
120 _?000 _?100 _?001 _?101
122 _0000 _1000 _0100 _1100 _1001 _0101 _1101
124 ... ... ... ... ... ... ...
126 B0 58 84 8C 69 75 9D */
143 RJMP (end_mul
) // calc'd 0xb0
154 RJMP (end_mul
) // calc'd 0x58
159 RJMP (upper_8
) //'ll calc 0x84
162 upper_8
: /* used twice, so deduplicated */
171 RJMP (end_mul
) // calc'd 0x8c
188 RJMP (end_mul
) // calc'd 0x69
201 RJMP (end_mul
) // calc'd 0x75
215 LSR (a1
) //final shift is a common operation for all
217 MOV (t
, a1
) //TODO: use a1 in main() directly
221 RET
//TODO: replace CALL/RET with IJMP? (requires undoing goto-mul-hack)
375 putchar(acc
<<4); //TODO
377 ADC (i1
, zero
, !i0
) //XXX: must use "sbci i1,-1" in the assembly version
378 ADC (i2
, zero
, !i0
&&!i1
) // sbci i2,-1
379 ADC (i3
, zero
, !i0
&&!i1
&&!i2
) // sbci i3,-1