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