annotate level1/cmds/ngu.asm @ 1020:c1a5613ffe7b

changes
author boisy
date Thu, 06 Mar 2003 01:41:03 +0000
parents c04528763543
children 84ea83668304
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
1 ********************************************************************
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
2 * NGU - The "Next Great Utility"
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
3 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
4 * $Id$
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
5 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
6 * NGU is a template for writing utilities under OS-9/6809. It has
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
7 * robust option handling and is littered with comments to help you
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
8 * write your own utilities.
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
9 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
10 * NGU uses a two-pass method for parsing the command line. On the
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
11 * first pass, dash options are processed and internal flags are set
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
12 * accordingly. As the options are processed, they are cleared to
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
13 * spaces so that they won't be present on the second pass.
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
14 *
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
15 * e.g.
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
16 * 1st pass: ngu -x foo1 -y foo2 -t=bar1 -ab
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
17 * 2nd pass: ngu foo1 foo2
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
18 *
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
19 * For the second pass, NGU parses the remaining arguments, which don't
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
20 * begin with -. Presumably these are filenames or other names that are to be
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
21 * processed.
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
22 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
23 * Features:
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
24 * - Written for 6809 and 6309 processors in fast, compact
357c62d55b8f Changes
boisy
parents: 822
diff changeset
25 * assembly language.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
26 *
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
27 * - Both options and files can be specified anywhere
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
28 * on the command line
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
29 * (i.e ngu -a test1 -b test2 -c=foo)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
30 *
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
31 * - Multiple options can be combined behind one dash:
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
32 * (i.e ngu -ab test1 -c=foo test2 test3)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
33 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
34 * - Several useful assembly routines are provided for
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
35 * copying strings and determining string length.
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
36 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
37 * Limitations:
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
38 * - Only single character option names can be processed.
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
39 * Multi-character option names (i.e. -delete) aren't supported.
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
40 *
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
41 * - The current file counter is one byte, counting a maximum
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
42 * of 255 files.
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
43 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
44 * Ed. Comments Who YY/MM/DD
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
45 * ------------------------------------------------------------------
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
46 * 1 Put your development info here BGP 03/01/11
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
47
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
48 nam NGU
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
49 ttl The "Next Great Utility"
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
50
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
51 ifp1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
52 use defsfile
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
53 use rbfdefs
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
54 endc
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
55
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
56 * Here are some tweakable options
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
57 DOHELP set 1 1 = include help info
929
c04528763543 stack/parameter size increased to prevent collisions with memory
boisy
parents: 902
diff changeset
58 STACKSZ set 128 estimated stack size in bytes
c04528763543 stack/parameter size increased to prevent collisions with memory
boisy
parents: 902
diff changeset
59 PARMSZ set 256 estimated parameter size in bytes
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
60 COPTSIZ set 64 max size of C option's parameter
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
61
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
62 * Module header definitions
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
63 tylg set Prgrm+Objct
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
64 atrv set ReEnt+rev
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
65 rev set $01
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
66 edition set 1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
67
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
68 mod eom,name,tylg,atrv,start,size
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
69
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
70 * Your utility's static storage vars go here
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
71 org 0
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
72 * These vars are used by the base template and shouldn't be removed
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
73 parmptr rmb 2 pointer to our command line params
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
74 bufptr rmb 2 pointer to user expandable buffer
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
75 bufsiz rmb 2 size of user expandable buffer
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
76 filecnt rmb 1
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
77 * These vars are used for this example, it will probably change for you
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
78 gota rmb 1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
79 gotb rmb 1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
80 coptflg rmb 1 1 = this option has been processed once already
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
81 cleartop equ . everything up to here gets cleared at start
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
82 copt rmb COPTSIZ buffer for what follows after -c=
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
83 * Next is a user adjustable buffer with # modifier on command line.
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
84 * Some utilities won't need this flexibility, some will.
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
85 * Currently set up to be larger for Level 2 than Level 1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
86 * Note: this buffer must come just before the stack
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
87 IFGT Level-1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
88 bigbuff rmb 8*1024 8K default buffer for Level 2
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
89 ELSE
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
90 bigbuff rmb 512 512 byte default buffer for Level 1
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
91 ENDC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
92 * Finally the stack for any PSHS/PULS/BSR/LBSRs that we might do
929
c04528763543 stack/parameter size increased to prevent collisions with memory
boisy
parents: 902
diff changeset
93 rmb STACKSZ+PARMSZ
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
94 size equ .
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
95
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
96 * The utility name and edition goes here
821
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
97 name fcs /NGU/
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
98 fcb edition
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
99
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
100 * Place constant strings here
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
101 IFNE DOHELP
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
102 HlpMsg fcb C$LF
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
103 fcc /Use: NGU [<opts>] <path> [<path>] [<opts>]/
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
104 fcb C$LF
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
105 fcc / -a option 1/
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
106 fcb C$LF
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
107 fcc / -b option 2/
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
108 fcb C$LF
822
83e3677c8b1f Made option comparisons lowercase, added more help
boisy
parents: 821
diff changeset
109 fcc / -c=f option 3/
83e3677c8b1f Made option comparisons lowercase, added more help
boisy
parents: 821
diff changeset
110 fcb C$LF
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
111 CR fcb C$CR
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
112 HlpMsgL equ *-HlpMsg
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
113 ENDC
821
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
114 UnkOpt fcc /unknown option: /
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
115 UnkOptL equ *-UnkOpt
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
116
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
117 * Here's how registers are set when this process is forked:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
118 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
119 * +-----------------+ <-- Y (highest address)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
120 * ! Parameter !
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
121 * ! Area !
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
122 * +-----------------+ <-- X, SP
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
123 * ! Data Area !
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
124 * +-----------------+
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
125 * ! Direct Page !
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
126 * +-----------------+ <-- U, DP (lowest address)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
127 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
128 * D = parameter area size
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
129 * PC = module entry point abs. address
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
130 * CC = F=0, I=0, others undefined
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
131
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
132 * The start of the program is here.
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
133 * Before any command line processing is done, we clear out
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
134 * our static memory from U to cleartop, then determine the
357c62d55b8f Changes
boisy
parents: 822
diff changeset
135 * size of our data area (minus the stack).
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
136 start pshs u,x save registers for later
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
137 leax <cleartop,u point to end of area to zero out
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
138 IFNE H6309
821
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
139 subr u,x subtract U from X
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
140 tfr x,w and put X in W
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
141 clr ,-s put a zero on the stack
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
142 tfm s,u+ and use TFM to clear starting at U
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
143 leas 1,s clean up the stack
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
144 ELSE
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
145 pshs x save end pointer on stack
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
146 clrnxt clr ,u+ clear out
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
147 cmpu ,s done?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
148 bne clrnxt branch if not
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
149 leas 2,s else clear stack
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
150 ENDC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
151 puls x,u and restore our earlier saved registers
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
152 leay bigbuff,u point Y to copy buffer offset in U
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
153 stx <parmptr save parameter pointer
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
154 sty <bufptr save pointer to buffer
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
155 tfr s,d place top of stack in D
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
156 IFNE H6309
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
157 subr y,d
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
158 ELSE
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
159 pshs y save Y on stack
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
160 subd ,s++ get size of space between copybuf and X
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
161 ENDC
929
c04528763543 stack/parameter size increased to prevent collisions with memory
boisy
parents: 902
diff changeset
162 subd #STACKSZ+PARMSZ subtract out our stack/param size
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
163 std <bufsiz size of our buffer
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
164
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
165 * At this point we have determined our buffer space and saved pointers
821
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
166 * for later use. Now we will parse the command line for options that
854
053078ef1289 Made some adjustments
boisy
parents: 829
diff changeset
167 * begin with a dash.
053078ef1289 Made some adjustments
boisy
parents: 829
diff changeset
168 * Note that X will NOT point to a space, but to either a CR (if no
053078ef1289 Made some adjustments
boisy
parents: 829
diff changeset
169 * parameters were passed) or the first non-space character of the
053078ef1289 Made some adjustments
boisy
parents: 829
diff changeset
170 * parameter.
053078ef1289 Made some adjustments
boisy
parents: 829
diff changeset
171 * Here we merely grab the byte at X into A and test for end of line,
902
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
172 * exiting if so. Utilities that don't require arguments should
bffd011cbef3 Made more changes
boisy
parents: 854
diff changeset
173 * comment out the following three lines.
854
053078ef1289 Made some adjustments
boisy
parents: 829
diff changeset
174 lda ,x get first char
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
175 cmpa #C$CR CR?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
176 lbeq ShowHelp if so, no parameters... show help and exit
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
177 GetChar lda ,x+ get next character on cmd line
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
178 cmpa #C$CR CR?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
179 lbeq DoNGU if so, do whatever this utility does
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
180 cmpa #'- is it an option?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
181 beq GetDash if so, process it
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
182 inc <filecnt else must be a non-option argument (file)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
183 lbsr SkipNSpc move past the argument
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
184 ChkDash lbsr SkipSpcs and any following spaces
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
185 bra GetChar start processing again
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
186 GetDash lda #C$SPAC get a space char
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
187 sta -1,x and wipe out the dash from the cmd line
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
188 GetDash2 ldd ,x+ load option char and char following
822
83e3677c8b1f Made option comparisons lowercase, added more help
boisy
parents: 821
diff changeset
189 ora #$20 make lowercase
83e3677c8b1f Made option comparisons lowercase, added more help
boisy
parents: 821
diff changeset
190 IsItA cmpa #'a is it this option?
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
191 bne IsItB branch if not
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
192 inc <gota
829
a114971abd3b Changed the name of a def because it collided with Level 2
boisy
parents: 823
diff changeset
193 bra FixCmdLn
822
83e3677c8b1f Made option comparisons lowercase, added more help
boisy
parents: 821
diff changeset
194 IsItB cmpa #'b is it this option?
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
195 bne IsItC branch if not
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
196 inc <gotb
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
197 bra FixCmdLn
822
83e3677c8b1f Made option comparisons lowercase, added more help
boisy
parents: 821
diff changeset
198 IsItC cmpa #'c is it this option?
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
199 bne BadOpt branch if not
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
200 tst <coptflg was this option already specified?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
201 bne BadOpt show help if so
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
202 cmpb #'= 2nd char =?
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
203 lbne ShowHelp show help if not
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
204 inc <coptflg else tag this option as parsed
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
205 ldb #C$SPAC get space
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
206 stb -$01,x write over c
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
207 stb ,x+ and = sign, inc X to dest dir
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
208 * check for valid char after -c=
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
209 lda ,x
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
210 cmpa #C$SPAC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
211 lbeq ShowHelp
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
212 cmpa #C$CR
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
213 lbeq ShowHelp
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
214 leay <copt,u point Y to parameber buffer
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
215 tfr y,d transfer Y to D
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
216 addd #COPTSIZ
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
217 pshs b,a save updated ptr value
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
218 ldb #C$SPAC get space
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
219 L0339 lda ,x get byte at X
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
220 stb ,x+ store space at X and inc
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
221 sta ,y+ save loaded byte at Y and inc
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
222 cmpy ,s are we at end?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
223 beq L035D branch if so (buffer too small)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
224 cmpa #C$SPAC else is char in A a space?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
225 beq L0350 branch if so
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
226 cmpa #C$CR cr?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
227 bne L0339 get next byte if not
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
228 L0350 leax -1,x
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
229 sta ,x restore previous A
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
230 leas $02,s kill stack
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
231 lbra ChkDash
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
232 L035D leas $02,s
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
233 ldb #$BF else buffer size too small
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
234 orcc #Carry
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
235 lbra Exit
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
236 FixCmdLn lda #C$SPAC get space
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
237 sta -$01,x and wipe out option character
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
238 cmpb #'0
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
239 lblt ChkDash start dash option processing again
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
240 lbra GetDash possibly another option following?
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
241
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
242 * We branch here if we encounter an unknown option character
821
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
243 * A = bad option character
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
244 BadOpt leax UnkOpt,pcr
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
245 ldy #UnkOptL
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
246 ldb #C$CR
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
247 pshs d save bad option and CR on stack
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
248 lda #$02 stderr
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
249 os9 I$Write
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
250 leax ,s point X at option char on stack
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
251 os9 I$WritLn print option and CR
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
252 puls d clean up stack
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
253 lbra ShowHelp
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
254
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
255
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
256 * At this point options are processed.
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
257 * We load X with our parameter pointer and go down the command line
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
258 * looking at each file to process (options have been wiped out with
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
259 * spaces)
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
260 *
357c62d55b8f Changes
boisy
parents: 822
diff changeset
261 * Note, the following two instructions may not be needed, depending on
357c62d55b8f Changes
boisy
parents: 822
diff changeset
262 * if your utility requires a non-option on the command line.
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
263 DoNGU tst <filecnt we should have at least one file on cmdline
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
264 lbeq ShowHelp if not, exit with error
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
265 ldx <parmptr get our parameter pointer off stack
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
266 DoLoop lbsr SkipSpcs skip any leading spaces
357c62d55b8f Changes
boisy
parents: 822
diff changeset
267 cmpa #C$CR end of parameters?
357c62d55b8f Changes
boisy
parents: 822
diff changeset
268 beq ExitOk if so, end the utility
357c62d55b8f Changes
boisy
parents: 822
diff changeset
269 pshs x save pointer to arg
357c62d55b8f Changes
boisy
parents: 822
diff changeset
270 bsr ProcFile process file at X
357c62d55b8f Changes
boisy
parents: 822
diff changeset
271 puls x get arg pointer
357c62d55b8f Changes
boisy
parents: 822
diff changeset
272 lbsr SkipNSpc skip the argument we just processed
357c62d55b8f Changes
boisy
parents: 822
diff changeset
273 bra DoLoop
357c62d55b8f Changes
boisy
parents: 822
diff changeset
274
357c62d55b8f Changes
boisy
parents: 822
diff changeset
275 * This routine processes one file at a time.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
276 * Entry: X = ptr to argument on the command line.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
277 * On exit, X can point to the argument or past it.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
278 * Note that there are NO leading spaces.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
279 * They have been skipped by the caller.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
280 * The following code just echos the command line argument, followed
357c62d55b8f Changes
boisy
parents: 822
diff changeset
281 * by a carriage return.
357c62d55b8f Changes
boisy
parents: 822
diff changeset
282 ProcFile
357c62d55b8f Changes
boisy
parents: 822
diff changeset
283 pshs x save ptr
357c62d55b8f Changes
boisy
parents: 822
diff changeset
284 lda #$01 standard output
357c62d55b8f Changes
boisy
parents: 822
diff changeset
285 bsr StrLen get length of argument in Y
357c62d55b8f Changes
boisy
parents: 822
diff changeset
286 puls x recover ptr
357c62d55b8f Changes
boisy
parents: 822
diff changeset
287 os9 I$Write write name out
357c62d55b8f Changes
boisy
parents: 822
diff changeset
288 leax CR,pcr point to carriage return
357c62d55b8f Changes
boisy
parents: 822
diff changeset
289 os9 I$WritLn write it out
357c62d55b8f Changes
boisy
parents: 822
diff changeset
290 rts
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
291
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
292 ShowHelp equ *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
293 IFNE DOHELP
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
294 leax >HlpMsg,pcr point to help message
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
295 ldy #HlpMsgL get length
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
296 lda #$02 std error
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
297 os9 I$WritLn write it
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
298 ENDC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
299 ExitOk clrb clear carry
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
300 Exit os9 F$Exit and exit
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
301
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
302 * This routine counts the number of non-whitespace characters
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
303 * starting at X
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
304 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
305 * Entry:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
306 * X = ptr to string (space, comma or CR terminated)
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
307 * Exit:
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
308 * Y = length of string
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
309 * X = ptr to byte after string
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
310 StrLen pshs a
357c62d55b8f Changes
boisy
parents: 822
diff changeset
311 ldy #$0000
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
312 StrLenLp lda ,x+
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
313 cmpa #C$SPAC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
314 beq StrLenEx
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
315 cmpa #C$CR
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
316 beq StrLenEx
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
317 leay 1,y
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
318 bra StrLenLp
823
357c62d55b8f Changes
boisy
parents: 822
diff changeset
319 StrLenEx puls a,pc
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
320
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
321 * This routine copies a string of text from X to Y until
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
322 * a whitespace character or CR is encountered
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
323 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
324 * Entry:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
325 * X = ptr to src string
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
326 * Y = ptr to dest string
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
327 * Exit:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
328 * D = number of bytes copied
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
329 * X = ptr to byte after original string
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
330 * Y = ptr to byte after copied string
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
331 StrCpy pshs u
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
332 ldu #$0000
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
333 CopyFnLp lda ,x+
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
334 cmpa #C$SPAC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
335 beq CopyFnEx
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
336 cmpa #C$CR
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
337 beq CopyFnEx
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
338 sta ,y+
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
339 leau 1,u
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
340 bra CopyFnLp
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
341 CopyFnEx tfr u,d
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
342 puls u,pc
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
343
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
344 * This routine skip over spaces and commas
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
345 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
346 * Entry:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
347 * X = ptr to data to parse
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
348 * Exit:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
349 * X = ptr to first non-whitespace char
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
350 * A = non-whitespace char
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
351 SkipSpcs lda ,x+
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
352 cmpa #C$SPAC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
353 beq SkipSpcs
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
354 leax -1,x
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
355 rts
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
356
821
b0b1886efbd0 added unknown option
boisy
parents: 820
diff changeset
357 * This routine skips over everything but spaces, commas and CRs
820
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
358 *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
359 * Entry:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
360 * X = ptr to data to parse
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
361 * Exit:
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
362 * X = ptr to first whitespace char
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
363 * A = whitespace char
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
364 SkipNSpc lda ,x+
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
365 cmpa #C$SPAC
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
366 beq EatOut
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
367 cmpa #C$CR
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
368 bne SkipNSpc
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
369 EatOut leax -1,x
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
370 rts
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
371
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
372 emod
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
373 eom equ *
2de53dfabcc8 Added for future development
boisy
parents:
diff changeset
374 end