Mercurial > hg > Members > kono > nitros9-code
annotate level1/cmds/cmp.asm @ 1919:028161cd3535
uses ss.fd
author | boisy |
---|---|
date | Fri, 25 Nov 2005 12:39:54 +0000 |
parents | 20841f236e32 |
children |
rev | line source |
---|---|
0 | 1 ******************************************************************** |
936 | 2 * Cmp - Binary file comparison utility |
0 | 3 * |
4 * $Id$ | |
5 * | |
1325
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
936
diff
changeset
|
6 * Edt/Rev YYYY/MM/DD Modified by |
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
936
diff
changeset
|
7 * Comment |
0 | 8 * ------------------------------------------------------------------ |
1325
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
936
diff
changeset
|
9 * 1 2003/01/20 Boisy G. Pitre |
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
936
diff
changeset
|
10 * Rewritten in assembly for size. |
0 | 11 |
936 | 12 nam Cmp |
13 ttl Binary file comparison utility | |
0 | 14 |
15 ifp1 | |
322 | 16 use defsfile |
0 | 17 endc |
200
e9ce43cc215e
Made major changes to headers for consistency and identification
boisy
parents:
0
diff
changeset
|
18 |
936 | 19 * Here are some tweakable options |
20 DOHELP set 0 1 = include help info | |
21 CMPBUFSZ set 1024 | |
22 STACKSZ set 128 estimated stack size in bytes | |
23 PARMSZ set 256 estimated parameter size in bytes | |
24 | |
25 * Module header definitions | |
0 | 26 tylg set Prgrm+Objct |
27 atrv set ReEnt+rev | |
1325
84ea83668304
Redid comments, reset all rev nibbles that weren't explictly set to 0
boisy
parents:
936
diff
changeset
|
28 rev set $00 |
936 | 29 edition set 1 |
200
e9ce43cc215e
Made major changes to headers for consistency and identification
boisy
parents:
0
diff
changeset
|
30 |
0 | 31 mod eom,name,tylg,atrv,start,size |
200
e9ce43cc215e
Made major changes to headers for consistency and identification
boisy
parents:
0
diff
changeset
|
32 |
936 | 33 org 0 |
34 headdone rmb 1 if 1, means byte #1 #2 header shown | |
35 noneflag rmb 1 if 1, means there were differences | |
36 f1path rmb 1 file 1 path | |
37 f2path rmb 1 file 2 path | |
38 f1read rmb 2 | |
39 f2read rmb 2 | |
40 f1namptr rmb 2 | |
41 f2namptr rmb 2 | |
42 f1namsiz rmb 2 | |
43 f2namsiz rmb 2 | |
44 cmpbytes rmb 4 bytes compared | |
45 difbytes rmb 4 bytes different | |
46 cleartop equ . everything up to here gets cleared at start | |
47 diffbuff rmb 32 | |
48 f1buff rmb CMPBUFSZ | |
49 f2buff rmb CMPBUFSZ | |
50 * Finally the stack for any PSHS/PULS/BSR/LBSRs that we might do | |
51 rmb STACKSZ+PARMSZ | |
0 | 52 size equ . |
200
e9ce43cc215e
Made major changes to headers for consistency and identification
boisy
parents:
0
diff
changeset
|
53 |
936 | 54 * The utility name and edition goes here |
55 name fcs /Cmp/ | |
56 fcb edition | |
57 | |
58 * Place constant strings here | |
59 IFNE DOHELP | |
60 HlpMsg fcb C$LF | |
61 fcc /Use: Cmp <file1> <file2>/ | |
62 fcb C$CR | |
63 HlpMsgL equ *-HlpMsg | |
64 ENDC | |
65 CmpHead fcb C$LF | |
322 | 66 fcc " Differences" |
67 fcb C$LF | |
936 | 68 CrRtn fcb C$CR |
69 None fcc " None ..." | |
70 fcb C$CR | |
71 CmpHead2 fcc "byte #1 #2" | |
72 fcb C$CR | |
73 CmpHead3 fcc "======== == ==" | |
74 fcb C$CR | |
75 ByteCmp fcb C$LF | |
76 fcc "Bytes compared: " | |
77 ByteCmpL equ *-ByteCmp | |
78 ByteDif fcc "Bytes different: " | |
79 ByteDifL equ *-ByteDif | |
80 IsLonger fcc " is longer" | |
81 fcb C$CR | |
82 | |
83 * Here's how registers are set when this process is forked: | |
84 * | |
85 * +-----------------+ <-- Y (highest address) | |
86 * ! Parameter ! | |
87 * ! Area ! | |
88 * +-----------------+ <-- X, SP | |
89 * ! Data Area ! | |
90 * +-----------------+ | |
91 * ! Direct Page ! | |
92 * +-----------------+ <-- U, DP (lowest address) | |
93 * | |
94 * D = parameter area size | |
95 * PC = module entry point abs. address | |
96 * CC = F=0, I=0, others undefined | |
97 | |
98 * This routine skip over spaces and commas | |
99 * | |
100 * Entry: | |
101 * X = ptr to data to parse | |
102 * Exit: | |
103 * X = ptr to first non-whitespace char | |
104 * A = non-whitespace char | |
105 SkipSpcs lda ,x+ | |
106 cmpa #C$SPAC | |
107 beq SkipSpcs | |
108 leax -1,x | |
109 rts | |
110 | |
111 * This routine counts the number of non-whitespace characters | |
112 * starting at X | |
113 * | |
114 * Entry: | |
115 * X = ptr to string (space, comma or CR terminated) | |
116 * Exit: | |
117 * Y = length of string | |
118 * X = ptr to byte after string | |
119 StrLen pshs a | |
120 ldy #$0000 | |
121 StrLenLp lda ,x+ | |
122 cmpa #C$SPAC | |
123 beq StrLenEx | |
124 cmpa #C$CR | |
125 beq StrLenEx | |
126 leay 1,y | |
127 bra StrLenLp | |
128 StrLenEx puls a,pc | |
129 | |
130 * The start of the program is here. | |
131 * Before any command line processing is done, we clear out | |
132 * our static memory from U to cleartop, then determine the | |
133 * size of our data area (minus the stack). | |
134 start pshs u,x save registers for later | |
135 leax <cleartop,u point to end of area to zero out | |
136 IFNE H6309 | |
137 subr u,x subtract U from X | |
138 tfr x,w and put X in W | |
139 clr ,-s put a zero on the stack | |
140 tfm s,u+ and use TFM to clear starting at U | |
141 leas 1,s clean up the stack | |
142 ELSE | |
143 pshs x save end pointer on stack | |
144 clrnxt clr ,u+ clear out | |
145 cmpu ,s done? | |
146 bne clrnxt branch if not | |
147 leas 2,s else clear stack | |
148 ENDC | |
149 puls x,u and restore our earlier saved registers | |
150 | |
151 lda ,x get first char | |
152 cmpa #C$CR CR? | |
153 lbeq ShowHelp if so, no parameters... show help and exit | |
154 * Open first file on command line | |
155 bsr SkipSpcs | |
156 stx f1namptr,u | |
157 bsr StrLen | |
158 sty f1namsiz | |
159 ldx f1namptr,u | |
160 lda #READ. | |
161 os9 I$Open | |
162 lbcs ShutDown | |
163 sta <f1path | |
164 * Open second file on command line | |
165 bsr SkipSpcs | |
166 stx f2namptr,u | |
167 bsr StrLen | |
168 sty f2namsiz | |
169 ldx f2namptr,u | |
170 lda #READ. | |
171 os9 I$Open | |
172 lbcs ShutDown | |
173 sta <f2path | |
174 | |
175 * Write "Differences" to standard output | |
176 lda #$01 | |
177 leax CmpHead,pcr | |
178 ldy #128 | |
179 os9 I$WritLn | |
180 | |
181 DoCmp lda f1path | |
182 leax f1buff,u | |
183 ldy #CMPBUFSZ | |
184 os9 I$Read | |
185 lbcs ShutDown | |
186 sty <f1read | |
187 | |
188 lda f2path | |
189 leax f2buff,u | |
190 ldy #CMPBUFSZ | |
191 os9 I$Read | |
192 lbcs ShutDown | |
193 sty <f2read | |
194 | |
195 * Actual compare is done here | |
196 ldd f1read,u get read amount for file 1 | |
197 cmpd f2read,u compare against read amount for file2 | |
198 ble Compare branch if f1read less than or equal | |
199 ldd f2read,u else get f2read size | |
200 Compare leax f1buff,u point X to f1 buff | |
201 leay f2buff,u point Y to f2 buff | |
202 CmpLoop pshs d | |
203 lda ,x get f1 byte in A | |
204 cmpa ,y compare against f2 byte at Y | |
205 beq CmpOk if same, go on | |
206 bsr ShowDiff else show diff | |
207 CmpOk leax 1,x | |
208 leay 1,y | |
209 ldd <cmpbytes+2 get lo 16 bits | |
210 addd #$0001 | |
211 std <cmpbytes+2 | |
212 bcc CmpFwd | |
213 ldd <cmpbytes | |
214 addd #$0001 | |
215 std <cmpbytes | |
216 CmpFwd ldd ,s++ | |
217 subd #$0001 | |
218 bne CmpLoop | |
219 bra DoCmp else read more | |
220 | |
221 ShowDiff pshs x,y | |
222 tst <headdone did we already show header? | |
223 bne ShowDif1 branch if so | |
224 lda #$01 stdout | |
225 sta <noneflag we won't be showing none when done! | |
226 sta <headdone set head done flag | |
227 leax CmpHead2,pcr print header 2 | |
228 ldy #128 | |
229 os9 I$WritLn | |
230 leax CmpHead3,pcr and header 3 | |
231 os9 I$WritLn | |
232 ShowDif1 leax diffbuff,u | |
233 ldd <cmpbytes | |
234 bsr MkHexWrd | |
235 ldd <cmpbytes+2 | |
236 bsr MkHexWrd | |
237 ldd #C$SPAC*256+C$SPAC | |
238 std ,x++ | |
239 ldb [,s] | |
240 bsr MkHexByt | |
241 lda #C$SPAC | |
242 sta ,x+ | |
243 ldb [2,s] | |
244 bsr MkHexByt | |
245 lda #C$CR | |
246 sta ,x | |
247 leax diffbuff,u | |
248 lda #$01 | |
249 ldy #128 | |
250 os9 I$WritLn | |
251 | |
252 * Increment diff count | |
253 ldd <difbytes+2 get lo 16 bits | |
254 addd #$0001 | |
255 std <difbytes+2 | |
256 bcc ShowDif2 | |
257 ldd <difbytes | |
258 addd #$0001 | |
259 std <difbytes | |
260 ShowDif2 | |
261 puls x,y,pc | |
262 | |
263 * Entry: X = buffer to place 4 byte Hex char in | |
264 * D = word to convert to Hex | |
265 * Exit : X = ptr to location after 4 byte Hex | |
266 MkHexWrd exg a,b | |
267 bsr MkHexByt | |
268 exg a,b | |
269 bsr MkHexByt | |
270 rts | |
271 | |
272 * Entry: X = buffer to place 2 byte Hex char in | |
273 * B = byte to convert to Hex | |
274 * Exit : X = ptr to location after 2 byte Hex | |
275 MkHexByt pshs d | |
276 tfr b,a | |
277 lsrb shift upper nibble to lower | |
278 lsrb | |
279 lsrb | |
280 lsrb | |
281 bsr MakeChar | |
282 tfr a,b | |
283 andb #$0F | |
284 bsr MakeChar | |
285 puls d,pc | |
286 MakeChar cmpb #$09 | |
287 bhi IsLetter | |
288 addb #'0 | |
289 fcb $8C skip next two bytes | |
290 IsLetter addb #55 | |
291 stb ,x+ | |
292 rts | |
293 | |
294 ShutDown lda <f1path get file 1 path number | |
295 beq CloseF2 if empty, close file 2 | |
296 os9 I$Close | |
297 CloseF2 lda <f2path get file 2 path number | |
298 lbeq ExitOk | |
299 os9 I$Close | |
300 lda #$01 stdout for later | |
301 tst <noneflag any differences? | |
302 bne Summary1 | |
303 leax None,pcr | |
304 ldy #128 | |
305 os9 I$WritLn | |
306 Summary1 leax ByteCmp,pcr | |
307 ldy #ByteCmpL | |
308 os9 I$Write | |
309 leax diffbuff,u | |
310 ldd <cmpbytes | |
311 bsr MkHexWrd | |
312 ldd <cmpbytes+2 | |
313 bsr MkHexWrd | |
314 ldb #C$CR | |
315 stb ,x | |
316 leax diffbuff,u | |
317 lda #$01 | |
318 ldy #128 | |
319 os9 I$WritLn | |
320 Summary2 leax ByteDif,pcr | |
321 ldy #ByteDifL | |
322 os9 I$Write | |
323 leax diffbuff,u | |
324 ldd <difbytes | |
325 bsr MkHexWrd | |
326 ldd <difbytes+2 | |
327 lbsr MkHexWrd | |
328 ldb #C$CR | |
329 stb ,x | |
330 leax diffbuff,u | |
331 lda #$01 | |
332 ldy #128 | |
333 os9 I$WritLn | |
334 | |
335 * See if one file is longer than other | |
336 ldd <f1read | |
337 cmpd <f2read | |
338 beq ExitOk if same, go on | |
339 * Write CR | |
340 lda #1 | |
341 leax CrRtn,pcr | |
342 ldy #1 | |
343 os9 I$WritLn | |
344 ldx <f1namptr | |
345 ldy <f1namsiz | |
346 * Assume file 1 is longer | |
347 ldd <f1read | |
348 cmpd <f2read | |
349 bgt ShowLong | |
350 * Otherwise file 2 is longer | |
351 ldx <f2namptr | |
352 ldy <f2namsiz | |
353 ShowLong lda #1 | |
354 os9 I$Write | |
355 leax IsLonger,pcr | |
356 ldy #128 | |
357 os9 I$WritLn | |
358 | |
359 ExitOk clrb | |
360 Exit os9 F$Exit | |
361 | |
362 ShowHelp equ * | |
363 IFNE DOHELP | |
364 leax >HlpMsg,pcr point to help message | |
365 ldy #HlpMsgL get length | |
366 lda #$02 std error | |
367 os9 I$WritLn write it | |
368 ENDC | |
369 bra ExitOk | |
322 | 370 |
0 | 371 emod |
372 eom equ * | |
322 | 373 end |