annotate 3rdparty/utils/view/view_gifcol.a @ 1706:6b23465701c0

Tim Kientzle's VIEW
author boisy
date Tue, 10 Aug 2004 23:46:24 +0000
parents
children b7fb6a9aead4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1706
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
1 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
2 * GIFcolors: Analyze GIF color map, generate CoCo palette and Gif->coco
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
3 * translation tables. Expects X to point to GIF color map, D to hold
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
4 * number of palettes in that color map, and U to point to buffer
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
5 * to receive translation table.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
6 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
7 * Data structures
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
8 * Color translation table contains three bytes for each GIF color:
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
9 * primary color, secondary color, fraction of secondary color for dither
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
10 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
11 * Algorithm
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
12 * First, convert each GIF color to closest CoCo color, and choose
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
13 * 16 "furthest" apart from those for the palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
14 * For each GIF color in the original GIF palette, interpolate it
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
15 * between 2 closest colors in the palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
16 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
17 * Notes&Assumptions
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
18 * There are no more than 256 colors in the GIF palette. So, B holds
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
19 * the number of palettes, where 0 indicates 256.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
20 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
21 ifp1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
22 use /dd/defs/os9defs.a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
23 endc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
24
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
25 psect view_gifcol_a,0,0,0,0,0
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
26
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
27 check macro
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
28 pshs b,cc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
29 ldb #\1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
30 os9 F$PErr
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
31 puls b,cc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
32 endm
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
33
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
34 vsect dp
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
35 numpals rmb 1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
36 endsect
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
37
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
38 GIFcolors:
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
39 pshs a,b,x,y,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
40 pshs a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
41 lda <format
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
42 cmpa #GIFBWFormat Or if GIFBW format specified.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
43 beq GIFcol0
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
44 lda <type
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
45 cmpa #5 Was type 5,6,7 forced?
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
46 blo GIFcol1 Illegal mode, do auto-determine
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
47 cmpa #7
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
48 bhi GIFcol1 Type 8, use full color.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
49 GIFcol0
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
50 puls a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
51 bsr bwpals If yes, convert pals to grey scales, gen b/w palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
52 bra GIFcol2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
53
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
54 GIFcol1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
55 puls a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
56 leau linebuff,y Temporary storage.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
57 bsr copypals Copy the palettes over.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
58 tfr u,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
59 lbsr genpals Use GIF palettes to generate a CoCo palette
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
60 GIFcol2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
61
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
62 ldx 2,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
63 ldu 6,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
64 lbsr gentable Generate a GIF->CoCo translation table
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
65
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
66 lbsr palconv Now convert actual palette values
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
67
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
68 lda <type
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
69 cmpa #5
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
70 blo GIFcol3 If legal screen type already, skip this.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
71 cmpa #8
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
72 bls GIFcolend
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
73 GIFcol3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
74 lda #8 Default to type 8 screen
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
75 ldb numpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
76 cmpb #4
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
77 bhi GIFcolend
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
78 lda #7 Use type 7 if 4 or fewer palette colors.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
79 GIFcolend
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
80 sta <type
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
81
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
82 puls a,b,x,y,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
83
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
84 * Copy D pals from X to U
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
85 copypals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
86 pshs a,b,x,y,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
87 tfr d,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
88 leay d,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
89 leay d,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
90 copyloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
91 lda ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
92 sta ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
93 leay -1,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
94 bne copyloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
95 puls a,b,x,y,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
96
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
97 * Convert palettes to grey scale values.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
98 * D pals pointed to by X.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
99 bwpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
100 pshs a,b,x,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
101 tfr x,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
102 pshs b
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
103 bwpals1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
104 ldb ,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
105 lda #5
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
106 mul
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
107 tfr d,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
108 ldb 1,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
109 lda #3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
110 mul
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
111 leax d,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
112 ldb 2,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
113 lda #1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
114 mul
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
115 leax d,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
116 lda #9
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
117 lbsr div168
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
118 stb ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
119 stb ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
120 stb ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
121 dec ,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
122 bne bwpals1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
123 puls b
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
124
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
125 clra
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
126 leax palette,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
127 bwpals2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
128 sta ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
129 sta ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
130 sta ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
131 adda #$55
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
132 bcc bwpals2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
133 lda #4
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
134 sta numpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
135
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
136 lda <type Type 5 only has 2 colors
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
137 cmpa #5
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
138 bne bwpals3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
139 leax palette+3,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
140 ldb #$ff
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
141 stb ,x+ Set 2nd color to white
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
142 stb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
143 stb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
144 lda #2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
145 sta numpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
146 bwpals3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
147
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
148 puls a,b,x,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
149
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
150 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
151 * Use D pals pointed to by X to create a CoCo palette stored in "palette"
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
152 * in 3-byte format. (one byte each of R, G, B)
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
153 genpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
154 pshs a,b,x,y,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
155 lbsr normpals Normalize palettes
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
156 leau palette,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
157 clra
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
158 bsr copypal First one we get for free
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
159 inca
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
160 * X points to GIF palettes, U points to palettes, A holds number
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
161 * of palettes we've generated so far.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
162 genloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
163 ldb 1,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
164 ldx 2,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
165 bsr minmax Get the farthest palette from the ones already chosen.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
166 tstb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
167 beq genpend If dist is zero, quit now.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
168 bsr copypal Copy it to the palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
169 inca
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
170 cmpa #16
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
171 bne genloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
172 genpend
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
173 sta numpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
174 puls a,b,x,y,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
175
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
176 * From the B many GIF palettes at [X], choose the one farthest from the A many
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
177 * palettes already selected at [U].
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
178 * Local vars: ,s -- counts down GIF palettes
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
179 * 1,s -- Max dist so far
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
180 * 2:3,s -- Farthest palette seen so far.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
181 minmax
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
182 pshs a,y,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
183 pshs x Init farthest to first
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
184 clr ,-s Init max dist to zero
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
185 pshs b Init counter
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
186 minmaxloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
187 bsr setdist Get distance from first palette to set of pals.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
188 cmpb 1,s Is it further??
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
189 bls minmaxend If no farther, keep going.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
190 stb 1,s Set new dist, palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
191 stx 2,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
192 minmaxend
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
193 leax 3,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
194 dec ,s Count down palettes.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
195 bne minmaxloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
196 puls b Remove null counter.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
197 puls b Get distance into B.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
198 puls x Get pointer to farthest one.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
199 puls a,y,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
200
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
201 * X points to a palette, U points to A many palettes.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
202 * Return (in B) the minimum distance from [X] to [U]
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
203 setdist
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
204 pshs u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
205 bsr closest
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
206 puls u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
207
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
208 vsect dp
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
209 nextclose rmb 2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
210 nextdist rmb 1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
211 endsect
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
212 * X points to one palette, U to A many palettes.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
213 * Return minimum distance in B, pointer to closest in U.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
214 closest
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
215 pshs a,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
216 pshs a Number of pals on stack.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
217 ldb #$ff Min dist starts out as $FF.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
218 pshs b,u Store the min so far on the stack
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
219 stb nextdist ... and in the 2nd closest vars.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
220 stu nextclose
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
221 setdistloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
222 bsr distance
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
223 cmpb ,s Is this one closer than the closest so far?
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
224 bhs setdist1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
225 lda ,s Yes, make old closest into 2nd closest.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
226 sta nextdist
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
227 stb ,s and make this closest.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
228 ldd 1,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
229 std nextclose
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
230 stu 1,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
231 bra setdist2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
232 setdist1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
233 cmpb nextdist Is it closer than the 2nd closest so far?
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
234 bhs setdist2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
235 stb nextdist Yes, store it.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
236 stu nextclose
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
237 setdist2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
238 leau 3,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
239 dec 3,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
240 bne setdistloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
241 puls b,u Get the minimum into B, and the closest in U.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
242 puls a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
243 puls a,x,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
244
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
245 * Copy one palette from [X] to [3*A,U]
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
246 copypal
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
247 pshs a,u,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
248 leau a,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
249 leau a,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
250 leau a,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
251 lda ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
252 sta ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
253 lda ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
254 sta ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
255 lda ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
256 sta ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
257 puls a,u,x,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
258
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
259 * Return the distance from the palette value pointed to by X to the value
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
260 * pointed to by U in B
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
261 distance
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
262 pshs a,x,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
263 clra
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
264 ldb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
265 subb ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
266 bhi dist1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
267 negb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
268 dist1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
269 pshs d
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
270 ldb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
271 subb ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
272 bhi dist2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
273 negb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
274 dist2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
275 pshs d
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
276 ldb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
277 subb ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
278 bhi dist3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
279 negb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
280 dist3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
281 addd ,s++
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
282 addd ,s++
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
283 lsra divide to get it in one byte.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
284 rorb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
285 lsra
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
286 rorb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
287 puls a,x,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
288
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
289
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
290 * Normalize D pals pointed to by X into a CoCo 3-byte format
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
291 normpals
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
292 pshs a,b,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
293 normloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
294 bsr normcoord
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
295 bsr normcoord
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
296 bsr normcoord
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
297 subd #1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
298 bne normloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
299 puls a,b,x,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
300 normcoord
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
301 pshs a,b
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
302 lda ,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
303 ldb #85
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
304 lbsr divAB Divide by 85.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
305 lslb Round to nearest integer.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
306 adca #0
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
307 ldb #85 Mult by 85 to get normed value.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
308 mul
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
309 stb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
310 puls a,b,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
311
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
312 * X points to D many GIF palettes
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
313 * U points to destination for translation table.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
314 *
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
315 * Stage 2 algorithm:
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
316 * For each GIF color, dither the two closest CoCo colors.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
317 * Use the ratio of distances as the dithering percentage.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
318 csect
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
319 gentpals rmb 2 Pointer to CoCo palette
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
320 gentcnt rmb 1 Counts down number of GIF colors
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
321 gentgif rmb 2 Ptr to GIF colors
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
322 gentred rmb 1 Holds one palette value.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
323 gentgrn rmb 1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
324 gentblu rmb 1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
325 genttrans rmb 2 Ptr to trans table.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
326 gent1dist rmb 1 Distance to primary color
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
327 gent2dist rmb 1 Distance to secondary color.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
328 gent1pal rmb 2 Ptr to primary color
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
329 gent2pal rmb 2 Ptr to secondary color
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
330 gentvars rmb 0 Total number of local vars.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
331 endsect
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
332
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
333 gentable
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
334 pshs a,b,x,y,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
335 leas -gentvars,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
336 stx gentgif,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
337 stb gentcnt,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
338 leay palette,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
339 sty gentpals,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
340 tfr u,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
341 * Y points to trans table address
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
342 * gentgif,s points to GIF palettes
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
343 * gentpals,s points to CoCo palettes.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
344 gentloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
345
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
346 * First, try to get a "primary" color. Use the closest match.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
347 lda numpals Number of palettes.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
348 ldu gentpals,s Palette ptr.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
349 ldx gentgif,s Ptr to GIF palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
350 lbsr closest Get closest coco palette (U points to it)
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
351 stu gent1pal,s Save primary color ptr
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
352 tfr u,d Set primary color.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
353 subd gentpals,s D holds offset to closest palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
354 lbsr div3 Divide B by 3 to get a palette #.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
355 stb ,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
356
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
357 * Now, get an "ideal" secondary color to dither with it.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
358 sty genttrans,s Save Y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
359 ldx gentgif,s Get ptr to GIF palette that we're trying to match
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
360 leay gentred,s Put result in gentred, etc.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
361 bsr opp3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
362 ldy genttrans,s restore Y.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
363
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
364 * The closest to this "ideal" color will be our secondary color
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
365 lda numpals Number of palettes.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
366 ldu gentpals,s Palette ptr.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
367 * leax gentred,s Ptr to "ideal" dither match.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
368 ldx gentgif,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
369 lbsr closest
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
370 cmpu gent1pal,s Is the closest same as the primary color?
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
371 bne gent2c2 No, use the closest.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
372 ldu nextclose Otherwise, use the second closest.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
373 gent2c2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
374 tfr u,d
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
375 stu gent2pal,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
376 subd gentpals,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
377 bsr div3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
378 stb 1,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
379
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
380 * Calculate distance from desired color to primary color
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
381 ldu gent1pal,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
382 ldx gentgif,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
383 lbsr distance
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
384 stb gent1dist,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
385
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
386 * Calculate distance from desired color to secondary color
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
387 ldu gent2pal,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
388 ldx gentgif,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
389 lbsr distance
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
390 stb gent2dist,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
391
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
392 * Now, use the two distances to get the dithering percentage.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
393 ldb gent1dist,s Set % secondary.= (1st dist) / ( (1st dist) + (2nd dist) )
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
394 beq gentzero
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
395 tfr b,a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
396 addb gent2dist,s Add distances, 9 bit result (B + Carry)
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
397 rorb Divide B by 2 (include carry from addition)
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
398 lsra Div A by 2.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
399 lbsr divAB
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
400 gentzero
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
401 stb 2,y
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
402
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
403 leay 3,y Point to next trans table entry.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
404
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
405 ldx gentgif,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
406 leax 3,x
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
407 stx gentgif,s Point to next GIF palette.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
408
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
409 dec gentcnt,s Count down number.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
410 bne gentloop
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
411
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
412 leas gentvars,s Clean up stack.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
413 puls a,b,x,y,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
414
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
415 * Returns in [Y], palette value on other side of [X] from [U]
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
416 opp3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
417 pshs a,b,x,y,u
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
418 bsr opp31
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
419 bsr opp31
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
420 bsr opp31
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
421 puls a,b,x,y,u,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
422 opp31
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
423 ldb ,x+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
424 lda ,u+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
425 bsr opposite
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
426 stb ,y+
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
427 rts
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
428
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
429 * returns in B palette value on other side of B from A.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
430 * i.e. calculate 2B-A, truncating at zero and at $ff.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
431 opposite
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
432 pshs a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
433 clra
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
434 lslb
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
435 rola
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
436 subb ,s
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
437 sbca #0
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
438 bpl opp1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
439 ldd #0 If result is negative, chop at zero.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
440 opp1
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
441 tsta If >255, chop there.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
442 beq opp2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
443 ldb #$ff
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
444 opp2
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
445 puls a,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
446
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
447 * Divide positive B by 3.
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
448 div3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
449 pshs a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
450 tfr b,a
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
451 ldb #3
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
452 lbsr divAB
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
453 tfr a,b
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
454 puls a,pc
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
455
6b23465701c0 Tim Kientzle's VIEW
boisy
parents:
diff changeset
456 endsect