1336
|
1 ********************************************************************
|
|
2 * PadROM - ROM padding utility
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Edt/Rev YYYY/MM/DD Modified by
|
|
7 * Comment
|
|
8 * ------------------------------------------------------------------
|
|
9 * 1 2003/09/06 Boisy G. Pitre
|
|
10 * Started.
|
|
11
|
|
12 nam PadROM
|
|
13 ttl ROM padding utility
|
|
14
|
|
15 ifp1
|
|
16 use defsfile
|
|
17 endc
|
|
18
|
|
19 * Here are some tweakable options
|
|
20 DOHELP set 0 1 = include help info
|
|
21 STACKSZ set 128 estimated stack size in bytes
|
|
22 PARMSZ set 256 estimated parameter size in bytes
|
|
23
|
|
24 * Module header definitions
|
|
25 tylg set Prgrm+Objct
|
|
26 atrv set ReEnt+rev
|
|
27 rev set $00
|
|
28 edition set 1
|
|
29
|
|
30 mod eom,name,tylg,atrv,start,size
|
|
31
|
|
32 * Your utility's static storage vars go here
|
|
33 org 0
|
|
34 * These vars are used by the base template and shouldn't be removed
|
|
35 parmptr rmb 2 pointer to our command line params
|
|
36 filecnt rmb 1
|
|
37 * These vars are used for this example, it will probably change for you
|
|
38 hexcnt rmb 1 used by hex routine
|
|
39 hexvalue rmb 2 maximum size is $FFFF
|
|
40 openmode rmb 1
|
|
41 openpath rmb 1
|
|
42 filesize rmb 2
|
|
43 gota rmb 1
|
|
44 gotb rmb 1
|
|
45 padbyte rmb 1
|
|
46 padpage rmb 256
|
|
47 cleartop equ .
|
|
48 rmb STACKSZ+PARMSZ
|
|
49 size equ .
|
|
50
|
|
51 * The utility name and edition goes here
|
|
52 name fcs /PadROM/
|
|
53 fcb edition
|
|
54
|
|
55 * Place constant strings here
|
|
56 IFNE DOHELP
|
|
57 HlpMsg fcb C$LF
|
|
58 fcc /Use: NGU [<opts>] <path> [<path>] [<opts>]/
|
|
59 fcb C$LF
|
|
60 fcc / -a option 1/
|
|
61 fcb C$LF
|
|
62 fcc / -b option 2/
|
|
63 fcb C$LF
|
|
64 fcc / -c=f option 3/
|
|
65 fcb C$LF
|
|
66 CR fcb C$CR
|
|
67 HlpMsgL equ *-HlpMsg
|
|
68 ENDC
|
|
69 BadSize fcc /padrom only pads up to $FFFF bytes/
|
|
70 fcb C$CR
|
|
71 BadSizeL equ *-BadSize
|
|
72 BadPad fcc /file size exceeds pad size/
|
|
73 fcb C$CR
|
|
74 BadPadL equ *-BadPad
|
|
75 UnkOpt fcc /unknown option: /
|
|
76 UnkOptL equ *-UnkOpt
|
|
77
|
|
78 * Here's how registers are set when this process is forked:
|
|
79 *
|
|
80 * +-----------------+ <-- Y (highest address)
|
|
81 * ! Parameter !
|
|
82 * ! Area !
|
|
83 * +-----------------+ <-- X, SP
|
|
84 * ! Data Area !
|
|
85 * +-----------------+
|
|
86 * ! Direct Page !
|
|
87 * +-----------------+ <-- U, DP (lowest address)
|
|
88 *
|
|
89 * D = parameter area size
|
|
90 * PC = module entry point abs. address
|
|
91 * CC = F=0, I=0, others undefined
|
|
92
|
|
93 * The start of the program is here.
|
|
94 * Before any command line processing is done, we clear out
|
|
95 * our static memory from U to cleartop, then determine the
|
|
96 * size of our data area (minus the stack).
|
|
97 start subd #$0001 subtract 1 from D (param length)
|
|
98 lbeq ShowHelp if zero, no params were on line
|
|
99
|
|
100 pshs u,x save registers for later
|
|
101 leax cleartop,u point to end of area to zero out
|
|
102 IFNE H6309
|
|
103 subr u,x subtract U from X
|
|
104 tfr x,w and put X in W
|
|
105 clr ,-s put a zero on the stack
|
|
106 tfm s,u+ and use TFM to clear starting at U
|
|
107 leas 1,s clean up the stack
|
|
108 ELSE
|
|
109 pshs x save end pointer on stack
|
|
110 clrnxt clr ,u+ clear out
|
|
111 cmpu ,s done?
|
|
112 bne clrnxt branch if not
|
|
113 leas 2,s else clear stack
|
|
114 ENDC
|
|
115 puls x,u and restore our earlier saved registers
|
|
116
|
|
117 InitVars stx <parmptr save parameter pointer
|
|
118 lda #UPDAT. get default open mode
|
|
119 sta <openmode and save it
|
|
120 lda #$FF
|
|
121 sta <padbyte assume a default pad byte
|
|
122
|
|
123 * At this point we have determined our buffer space and saved pointers
|
|
124 * for later use. Now we will parse the command line for options that
|
|
125 * begin with a dash.
|
|
126 * Note that X will NOT point to a space, but to either a CR (if no
|
|
127 * parameters were passed) or the first non-space character of the
|
|
128 * parameter.
|
|
129 * Here we merely grab the byte at X into A and test for end of line,
|
|
130 * exiting if so. Utilities that don't require arguments should
|
|
131 * comment out the following three lines.
|
|
132 GetChar lda ,x+ get next character on cmd line
|
|
133 cmpa #C$CR CR?
|
|
134 beq DoPadROM if so, do whatever this utility does
|
|
135 cmpa #'- is it an option?
|
|
136 beq GetDash if so, process it
|
|
137 inc <filecnt else must be a non-option argument (file)
|
|
138 lbsr SkipNSpc move past the argument
|
|
139 ChkDash lbsr SkipSpcs and any following spaces
|
|
140 bra GetChar start processing again
|
|
141 GetDash clr -1,x wipe out the dash from the cmd line
|
|
142 GetDash2 ldd ,x+ load option char and char following
|
|
143 ora #$20 make lowercase
|
|
144 IsItX cmpa #'x is it this option?
|
|
145 bne IsItC branch if not
|
|
146 lda #EXEC.+UPDAT.
|
|
147 sta <openmode
|
|
148 bra FixCmdLn
|
|
149 IsItC cmpa #'c is it this option?
|
|
150 bne BadOpt branch if not
|
|
151 cmpb #'= 2nd char =?
|
|
152 lbne ShowHelp show help if not
|
|
153 clr -$01,x write over c
|
|
154 clr ,x+ and = sign, inc X to dest dir
|
|
155 * check for valid char after -c=
|
|
156 lbsr Hex2Int get value of hex pad char
|
|
157 lda <hexvalue+1
|
|
158 sta <padbyte save pad character byte
|
|
159 lda ,x get char at X (should be space or CR)
|
|
160 cmpa #C$SPAC
|
|
161 beq ChkDash
|
|
162 cmpa #C$CR
|
|
163 beq ChkDash
|
|
164 lbra ShowHelp neither, so show help
|
|
165
|
|
166 FixCmdLn clr -$01,x wipe out option character
|
|
167 cmpb #'0
|
|
168 blt ChkDash start dash option processing again
|
|
169 bra GetDash possibly another option following?
|
|
170
|
|
171 * We branch here if we encounter an unknown option character
|
|
172 * A = bad option character
|
|
173 BadOpt leax UnkOpt,pcr
|
|
174 ldy #UnkOptL
|
|
175 ldb #C$CR
|
|
176 pshs d save bad option and CR on stack
|
|
177 lda #$02 stderr
|
|
178 os9 I$Write
|
|
179 leax ,s point X at option char on stack
|
|
180 os9 I$WritLn print option and CR
|
|
181 puls d clean up stack
|
|
182 lbra ShowHelp
|
|
183
|
|
184
|
|
185 * At this point options are processed.
|
|
186 * We load X with our parameter pointer and go down the command line
|
|
187 * looking at each file to process (options have been wiped out with
|
|
188 * spaces)
|
|
189 *
|
|
190 * Note, the following two instructions may not be needed, depending on
|
|
191 * if your utility requires a non-option on the command line.
|
|
192 DoPadROM
|
|
193 * Before processing any parameters, fill <padpage with <padchar
|
|
194 clrb
|
|
195 lda <padbyte
|
|
196 leax padpage,u
|
|
197 fillpage sta ,x+
|
|
198 decb
|
|
199 bne fillpage
|
|
200
|
|
201 * Get parameter pointer and skip leading spaces
|
|
202 ldx <parmptr get our parameter pointer
|
|
203 lbsr SkipSpcs skip any leading spaces
|
|
204 * First parameter should be a hex pad size (maximum 4 hex bytes)
|
|
205 lbsr Hex2Int get hex value
|
|
206 dec <filecnt decrement file count
|
|
207 lbeq ShowHelp if no other file, exit with error
|
|
208 DoLoop lbsr SkipSpcs skip any leading spaces
|
|
209 cmpa #C$CR end of parameters?
|
|
210 beq ExitOk if so, end the utility
|
|
211 pshs x save pointer to arg
|
|
212 bsr ProcFile process file at X
|
|
213 puls x get arg pointer
|
|
214 lbsr SkipNSpc skip the argument we just processed
|
|
215 bra DoLoop
|
|
216
|
|
217 * This routine processes one file at a time.
|
|
218 * Entry: X = ptr to argument on the command line.
|
|
219 * On exit, X can point to the argument or past it.
|
|
220 * Note that there are NO leading spaces.
|
|
221 * They have been skipped by the caller.
|
|
222 * The following code just echos the command line argument, followed
|
|
223 * by a carriage return.
|
|
224 ProcFile
|
|
225 lda <openmode get open mode
|
|
226 ldy #256
|
|
227 os9 I$Write
|
|
228 os9 I$Open open file
|
|
229 bcs Exit exit if error
|
|
230 sta <openpath save path
|
|
231 ldb #SS.Size we want the file size
|
|
232 pshs u,x save
|
|
233 os9 I$GetStt get the size
|
|
234 stu <filesize save file size
|
|
235 bcs Exit branch if error
|
|
236 cmpx #$0000 file bigger than 65535?
|
|
237 bne toobig yup
|
|
238 lda <openpath get path to file
|
|
239 os9 I$Seek seek to the end of the file
|
|
240 bcs Exit branch if error
|
|
241 puls x,u restore
|
|
242 * Expand the file out to the desired size
|
|
243 ldd <hexvalue get pad size
|
|
244 subd <filesize get remaining size left
|
|
245 bcs padbad
|
|
246 * D now holds the number of bytes we need to write
|
|
247 pshs d save count on stack
|
|
248 lda <openpath get path to file
|
|
249 leax padpage,u point to pad page
|
|
250 tst ,s greater than 256 bytes left?
|
|
251 beq cont2 no, write remaining
|
|
252 ldy #256 for 256 bytes
|
|
253 cont os9 I$Write write it out
|
|
254 bcs Exit branch if error
|
|
255 dec ,s decrement page count
|
|
256 bne cont
|
|
257 cont2 puls y get count off stack into Y
|
|
258 os9 I$Write write out remaining bytes
|
|
259 bcs Exit branch if error
|
|
260
|
|
261 * Now close the file and return
|
|
262 os9 I$Close close it
|
|
263 rts
|
|
264
|
|
265 toobig lda #$02 stdout
|
|
266 ldy #BadSizeL get length of bad size message
|
|
267 leax BadSize,pcr and point to it
|
|
268 os9 I$WritLn send out the message
|
|
269 bra error1
|
|
270
|
|
271 padbad lda #$02
|
|
272 ldy #BadPadL
|
|
273 leax BadPad,pcr
|
|
274 os9 I$WritLn
|
|
275 error1 ldb #$01
|
|
276 bra Exit
|
|
277
|
|
278 ShowHelp equ *
|
|
279 IFNE DOHELP
|
|
280 leax >HlpMsg,pcr point to help message
|
|
281 ldy #HlpMsgL get length
|
|
282 lda #$02 std error
|
|
283 os9 I$WritLn write it
|
|
284 ENDC
|
|
285 ExitOk clrb clear carry
|
|
286 Exit os9 F$Exit and exit
|
|
287
|
|
288
|
|
289 * This routine skip over spaces and nul bytes
|
|
290 *
|
|
291 * Entry:
|
|
292 * X = ptr to data to parse
|
|
293 * Exit:
|
|
294 * X = ptr to first non-whitespace char
|
|
295 * A = non-whitespace char
|
|
296 SkipSpcs lda ,x+
|
|
297 beq SkipSpcs
|
|
298 cmpa #C$SPAC
|
|
299 beq SkipSpcs
|
|
300 leax -1,x
|
|
301 rts
|
|
302
|
|
303 * This routine skips over everything but spaces, nul bytes and CRs
|
|
304 *
|
|
305 * Entry:
|
|
306 * X = ptr to data to parse
|
|
307 * Exit:
|
|
308 * X = ptr to first whitespace char
|
|
309 * A = whitespace char
|
|
310 SkipNSpc lda ,x+
|
|
311 beq EatOut
|
|
312 cmpa #C$SPAC
|
|
313 beq EatOut
|
|
314 cmpa #C$CR
|
|
315 bne SkipNSpc
|
|
316 EatOut leax -1,x
|
|
317 rts
|
|
318
|
|
319
|
|
320 * Hex2Int
|
|
321 *
|
|
322 * Entry:
|
|
323 * X = address of hex string (1-4 bytes)
|
|
324 * Exit:
|
|
325 * <hexvalue = value of hex string
|
|
326 * X = address of character after hex string
|
|
327 Hex2Int clr <hexcnt clear our counter
|
|
328 lda ,x
|
|
329 cmpa #'$ hex sign?
|
|
330 bne Hex2Int2
|
|
331 clr ,x+ clear it and move to next char
|
|
332 Hex2Int2 bsr Hex2Nib get hex nibble at ,X
|
|
333 bcs HexW2 branch if done
|
|
334 pshs b save good hex byte on stack
|
|
335 inc <hexcnt increment counter
|
|
336 lda <hexcnt get counter
|
|
337 cmpa #$04 max size?
|
|
338 beq HexW3
|
|
339 bra Hex2Int2 and continue
|
|
340
|
|
341 * Here, <hexcnt contains a count of the bytes on the stack that contain
|
|
342 * hex values
|
|
343 HexW2 tst <hexcnt any valid hex data?
|
|
344 beq HexWDone no, exit
|
|
345
|
|
346 HexW3 clra clear out return hex value
|
|
347 clrb
|
|
348 std <hexvalue
|
|
349
|
|
350 puls b get nibble off the stack
|
|
351 stb <hexvalue+1
|
|
352 dec <hexcnt decrement counter
|
|
353 beq HexWDone branch if done
|
|
354 lsl ,s else move lo-nib on stack to hi-nib
|
|
355 lsl ,s
|
|
356 lsl ,s
|
|
357 lsl ,s
|
|
358 addb ,s+ and add it to lonibble in B
|
|
359 stb <hexvalue+1
|
|
360 dec <hexcnt decrement counter
|
|
361 beq HexWDone
|
|
362 puls b get nibble off the stack
|
|
363 stb <hexvalue+0
|
|
364 dec <hexcnt decrement counter
|
|
365 beq HexWDone
|
|
366 lsl ,s else move lo-nib on stack to hi-nib
|
|
367 lsl ,s
|
|
368 lsl ,s
|
|
369 lsl ,s
|
|
370 addb ,s+ and add it to lonibble in A
|
|
371 stb <hexvalue+0
|
|
372
|
|
373 HexWDone rts
|
|
374
|
|
375
|
|
376
|
|
377 * Hex2Nib - Convert byte at X from hex to byte integer
|
|
378 *
|
|
379 * Entry:
|
|
380 * X = address of byte to convert
|
|
381 * Exit:
|
|
382 * A = ASCII value of char at X
|
|
383 * B = byte value of hex char at X (if carry clear)
|
|
384 * OR error (if carry set)
|
|
385 Hex2Nib lda ,x get char at X
|
|
386 tfr a,b transfer it to working reg (B)
|
|
387 subb #$30 subtract '0
|
|
388 cmpb #$09 compare against 9
|
|
389 bls L02B1 branch if valid number
|
|
390 cmpb #$31 uppercase?
|
|
391 bcs L02A7 branch if so
|
|
392 subb #$20 else make uppercase
|
|
393 L02A7 subb #$07 subtract
|
|
394 cmpb #$0F compare against 0x0F
|
|
395 bhi L02B6 branch if higher
|
|
396 cmpb #$0A compare against 0x0A
|
|
397 bcs L02B6
|
|
398 L02B1 andcc #^Carry clear carry
|
|
399 clr ,x clear byte on cmd line
|
|
400 leax $01,x move X to next char
|
|
401 rts return
|
|
402 L02B6 comb
|
|
403 rts
|
|
404
|
|
405 emod
|
|
406 eom equ *
|
|
407 end
|