File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,9 @@ x_pos: sta tmp3
85
85
ldy #16
86
86
lda #0
87
87
sta tmp2+1
88
+ ; Detect we are dividing by numbers < 256 and use a faster algorithm.
89
+ ; The assumption is that smaller divisors are much more common than
90
+ ; larger ones, so this pays off.
88
91
ldx tmp1+1
89
92
beq udiv16x8
90
93
@@ -111,11 +114,15 @@ L1: txa
111
114
rts
112
115
113
116
udiv16x8:
114
- ldx tmp1
115
- beq L0
117
+ ; This is needed to return modulo > 255 on division by 0. We could also
118
+ ; set an error flag, but it is simpler to just return an invalid value.
119
+ ; ldx tmp1
120
+ ; beq L0
116
121
L2: asl tmp3
117
122
rol tmp3+1
118
123
rol
124
+ ; When the current modulo is > 255, we always need to subtract the
125
+ ; divisor, and we already have C=1.
119
126
bcs L3
120
127
121
128
cmp tmp1
You can’t perform that action at this time.
0 commit comments