Modulo is easy, there are a few ways to do it. You'll have to figure out how to integerate it into C though. Here's a few ways:tschak909 wrote:The modulo is the problem here, given an integer divide by 24 such as:

How can I determine a modulo? Is it sitting here in temp at some point?Code: Select all

`;; void __fastcall__ div24(unsigned char d); _div24: lsr lsr lsr sta TEMP lsr lsr adc TEMP ror lsr adc TEMP ror lsr rts`

-Thom

Long slow division does not take too long in this case as 24 is a big divisor.

Code: Select all

```
;24-94 cycles
_div24_mod24:
ldy #$FF
sec
_div24:
iny
sbc #24
bcs _div24
adc #24
rts ; Y = integer division result, A = modulo result
```

Code: Select all

```
;54 cycles
_div24_mod24:
pha ; save original value
lsr
lsr
lsr
sta TEMP
lsr
lsr
adc TEMP
ror
lsr
adc TEMP
ror
lsr
tay ; integer division result
pla ; get original value
sec
sbc _multiply24,Y
rts ; Y = integer division result, A = modulo result
_multiply24:
.db 0,24,48,72,96,120
.db 144,168,192,216,240
```

Code: Select all

```
_div24_mod24:
pha ; save original value
lsr
lsr
lsr
sta TEMP
lsr
lsr
adc TEMP
ror
lsr
adc TEMP
ror
lsr
; C 76543210
sta intDiv24 ; x 0000xxxx integer division result (0-10 possible)
asl ; 0 000xxxx0 x2
asl ; 0 00xxxx00 x4
asl ; 0 0xxxx000 x8
sta TEMP
asl ; 0 xxxx0000 x16 (carry is always clear at this point)
adc TEMP ; x24
sta TEMP
pla ; get original value
sec
sbc TEMP ; A = modulo result, intDiv24 = integer division result
rts
```

Hope that helps!