comparison level2/cmds/mfree.asm @ 3193:489617e567c5

mfree.asm: Improve comment and remove trailing white-space Infer functionality by code inspection and add comments accordingly. Document bug that occurs when final block is free (does not occur on coco but does occur on mc09).
author Neal Crook <foofoobedoo@gmail.com>
date Tue, 30 May 2017 23:45:40 +0100
parents fa494f2dca9a
children 2ecebda8716b
comparison
equal deleted inserted replaced
3192:5e48668f30b2 3193:489617e567c5
16 16
17 ifp1 17 ifp1
18 use defsfile 18 use defsfile
19 endc 19 endc
20 20
21 tylg set Prgrm+Objct 21 tylg set Prgrm+Objct
22 atrv set ReEnt+rev 22 atrv set ReEnt+rev
23 rev set $00 23 rev set $00
24 edition set 2 24 edition set 2
25 25
26 mod eom,name,tylg,atrv,start,size 26 mod eom,name,tylg,atrv,start,size
27 27
28 u0000 rmb 1 28 freeblks rmb 2
29 u0001 rmb 1 29 mapsiz rmb 2
30 u0002 rmb 2 30 * pages per block (ie, MS byte of block size)
31 u0004 rmb 1 31 ppblk rmb 1
32 u0005 rmb 1 32 * 0: print number with leading spaces. 1: print number with leading 0.
33 leadzero rmb 1
34 * u0006,7,8 store a 24-bit block begin/end address.
33 u0006 rmb 1 35 u0006 rmb 1
34 u0007 rmb 1 36 u0007 rmb 1
35 u0008 rmb 1 37 u0008 rmb 1
36 u0009 rmb 1 38 bufstrt rmb 2
37 u000A rmb 1 39 bufcur rmb 2
38 u000B rmb 2
39 linebuf rmb 80 40 linebuf rmb 80
40 u005D rmb 7 41 mapbuf rmb 1274
41 u0064 rmb 132
42 u00E8 rmb 1135
43 size equ . 42 size equ .
44 43
45 name fcs /Mfree/ 44 name fcs /Mfree/
46 fcb edition 45 fcb edition
47 46
48 Hdr fcs " Blk Begin End Blks Size" 47 Hdr fcs " Blk Begin End Blks Size"
49 fcs " --- ------ ------ ---- ------" 48 fcs " --- ------ ------ ---- ------"
50 Ftr fcs " ==== ======" 49 Ftr fcs " ==== ======"
51 fcs " Total: " 50 fcs " Total: "
52 51
53 start leax linebuf,u get line buffer address 52 start leax linebuf,u get line buffer address
54 stx <u0009 53 stx <bufstrt and store it away
55 stx <u000B 54 stx <bufcur current output position output buffer
56 lbsr L016E 55
56 lbsr wrbuf print CR
57 leay <Hdr,pcr 57 leay <Hdr,pcr
58 lbsr L0183 58 lbsr tobuf 1st line of header to output buffer
59 lbsr L016E 59 lbsr wrbuf ..print it
60 lbsr L0183 60 lbsr tobuf 2nd line of header to output buffer
61 lbsr L016E 61 lbsr wrbuf ..print it
62 clr <u0000 62
63 clr <u0001 63 clr <freeblks total number of free blocks
64 leax <u005D,u 64 clr <freeblks+1
65 os9 F$GBlkMp 65 leax <mapbuf,u
66 sty <u0002 66 * In: X = 1024-byte buffer
67 sta <u0004 67 * Out: D = number of bytes per block
68 ldy #$0000 68 * Y = system memory block map size
69 L00AA ldu #$0000 69 os9 F$GBlkMp
70 L00AD tst ,x+ 70 sty <mapsiz save map size
71 beq L00BA 71 sta <ppblk save MS byte of bytes per block
72 leay $01,y 72 ldy #$0000 count of how many blocks we have inspected
73 cmpy <u0002 73
74 bcs L00AD 74 * Main loop
75 bra L0109 75 * look for a free block (an entry of 0 in the block map)
76 loop ldu #$0000 number of free blocks in this sequence
77 L00AD tst ,x+ is this block 0?
78 beq L00BA yes - found a free block
79 leay $01,y total number of blocks we have inspected
80 cmpy <mapsiz at the end of the map?
81 bcs L00AD no, so carry on looking
82 bra alldone yes, and the last block was not free, so we're done.
83
84 * Block number in Y is the first free block of a sequence (tho maybe a sequence of 1)
76 L00BA tfr y,d 85 L00BA tfr y,d
77 bsr L0123 86 bsr buf4hex append start block, in hex, to output buffer
78 lda <u0004 87 lda <ppblk
79 pshs y,a 88 pshs y,a
80 clra 89 clra
81 clrb 90 clrb
82 L00C4 addd $01,s 91 L00C4 addd $01,s multiply start block by block size to get
83 dec ,s 92 dec ,s begin address
84 bne L00C4 93 bne L00C4
85 leas $03,s 94 leas $03,s
86 std <u0006 95 std <u0006 2 MS bytes of block begin address
87 clr <u0008 96 clr <u0008 1 LS byte of block begin address is 0
88 bsr L0133 97 bsr buf6hex append block begin address in hex, to output buffer
89 L00D2 leau u0001,u 98
99 * Look for the last free block in this sequence
100 L00D2 leau $01,u
90 leay $01,y 101 leay $01,y
91 cmpy <u0002 102 cmpy <mapsiz
92 beq L0109 103 beq alldone ??should never exit at this point, but
104 * on mc09 we do - terminate part-way through an entry.
93 tst ,x+ 105 tst ,x+
94 beq L00D2 106 beq L00D2 haven't found it yet..
95 lda <u0004 107 last lda <ppblk
96 pshs y,a 108 pshs y,a
97 clra 109 clra
98 clrb 110 clrb
99 L00E5 addd $01,s 111 L00E5 addd $01,s multiply end block by block size to get
100 dec ,s 112 dec ,s end address
101 bne L00E5 113 bne L00E5
102 leas $03,s 114 leas $03,s
103 subd #$0001 115 subd #$0001
104 std <u0006 116 std <u0006 2 MS bytes of block end address
105 lda #$FF 117 lda #$FF
106 sta <u0008 118 sta <u0008 1 LS byte of block end address is $FF
107 bsr L0133 119 bsr buf6hex append block end address in hex, to output buffer
108 leax -$01,x 120 leax -$01,x
109 tfr u,d 121 tfr u,d
110 bsr L0123 122 bsr buf4hex append number of blocks, in hex, to output buffer
111 lbsr L0199 123 lbsr L0199 append size, in decimal, to output buffer
112 addd <u0000 124
113 std <u0000 125 addd <freeblks
114 bsr L016E 126 std <freeblks total number of blocks
115 bra L00AA 127 bsr wrbuf print this entry
116 L0109 leay >Ftr,pcr 128 bra loop loop for next entry
117 bsr L0183 129
118 bsr L016E 130 * All of the entries have been printed. Print the trailer and totals.
119 bsr L0183 131 * Bug: if the last block is unused, it and any unused blocks before it will
120 tfr u,d 132 * not get reported, *and* the formatting of the last entry will be messed up.
121 addd <u0000 133 * That never happens on the Coco, because the last block is always used.
122 std <u0000 134 * It does happen on mc09 though.
123 bsr L0123 135 alldone leay >Ftr,pcr
124 bsr L0199 136 bsr tobuf 1st line of footer to output buffer
125 bsr L016E 137 bsr wrbuf ..print it
126 clrb 138 bsr tobuf 2nd line of footer to output buffer
127 os9 F$Exit 139 tfr u,d ..add total #blocks, total memory size
128 L0123 pshs b,a 140 addd <freeblks
129 clr <u0005 141 std <freeblks
142 bsr buf4hex append total number of blocks, in hex, to output buffer
143 bsr L0199 append total size, in decimal, to output buffer
144 bsr wrbuf ..print it
145 * Successful exit
146 clrb
147 os9 F$Exit
148
149 * convert value in D to ASCII hex (4 chars). Append to output buffer, then append "SPACE" to output buffer
150 buf4hex pshs b,a
151 clr <leadzero
130 bsr L0145 152 bsr L0145
131 tfr b,a 153 tfr b,a
132 bsr L0145 154 bsr L0145
133 lda #$20 155 lda #C$SPAC append a space
134 bsr L0164 156 bsr bufchr
135 puls pc,b,a 157 puls pc,b,a
136 L0133 clr <u0005 158
159 * convert value in u0006,7,8 to ASCII hex (6 chars). Append to output buffer, then append "SPACE" to output buffer
160 buf6hex clr <leadzero
137 lda <u0006 161 lda <u0006
138 bsr L0145 162 bsr L0145
139 lda <u0007 163 lda <u0007
140 bsr L0145 164 bsr L0145
141 lda <u0008 165 lda <u0008
142 bsr L0145 166 bsr L0145
143 lda #$20 167 lda #C$SPAC append a space
144 bra L0164 168 bra bufchr
169
170 * convert value in A to ASCII hex (2 chars). Append to output buffer.
145 L0145 pshs a 171 L0145 pshs a
146 lsra 172 lsra
147 lsra 173 lsra
148 lsra 174 lsra
149 lsra 175 lsra
150 bsr L014F 176 bsr L014F
151 puls a 177 puls a
152 L014F anda #$0F 178 L014F anda #$0F
153 tsta 179 tsta
154 beq L0156 180 beq L0156
155 sta <u0005 181 sta <leadzero
156 L0156 tst <u0005 182 L0156 tst <leadzero
157 bne L015C 183 bne L015C
158 lda #$F0 184 lda #$F0
185
186 * FALL THROUGH
187 * Convert digit to ASCII with leading spaces, add to output buffer
188 * A is a 0-9 or A-F or $F0.
189 * Add $30 converts 0-9 to ASCII "0" - "9"), $F0 to ASCII "SPACE"
190 * leaves A-F >$3A so a further 7 is added so $3A->$41 etc. (ASCII "A" - "F")
159 L015C adda #$30 191 L015C adda #$30
160 cmpa #$3A 192 cmpa #$3A
161 bcs L0164 193 bcs bufchr
162 adda #$07 194 adda #$07
163 L0164 pshs x 195
164 ldx <u000B 196 * FALL THROUGH
197 * Store A at next position in output buffer.
198 bufchr pshs x
199 ldx <bufcur
165 sta ,x+ 200 sta ,x+
166 stx <u000B 201 stx <bufcur
167 puls pc,x 202 puls pc,x
168 203
169 L016E pshs y,x,a 204 * Append CR to the output buffer then print the output buffer
205 wrbuf pshs y,x,a
170 lda #C$CR 206 lda #C$CR
171 bsr L0164 207 bsr bufchr
172 ldx <u0009 208 ldx <bufstrt address of data to write
173 stx <u000B 209 stx <bufcur reset output buffer pointer, ready for next line.
174 ldy #80 210 ldy #80 maximum # of bytes - otherwise, stop at CR
175 lda #$01 211 lda #$01 to STDOUT
176 os9 I$WritLn 212 os9 I$WritLn
177 puls pc,y,x,a 213 puls pc,y,x,a
178 L0183 lda ,y 214
215 * Append string at Y to output buffer. String is terminated by MSB=1
216 tobuf lda ,y
179 anda #$7F 217 anda #$7F
180 bsr L0164 218 bsr bufchr
181 tst ,y+ 219 tst ,y+
182 bpl L0183 220 bpl tobuf
183 rts 221 rts
184 222
185 DecTbl fdb 10000,1000,100,10,1 223 DecTbl fdb 10000,1000,100,10,1
186 fcb $FF 224 fcb $FF
187 225
226 * value in ?? is a number of blocks. Convert to bytes by multiplying by the page size.
227 * Convert to ASCII decimal, append to output buffer, append "k" to output buffer
188 L0199 pshs y,x,b,a 228 L0199 pshs y,x,b,a
189 lda <u0004 229 lda <ppblk
190 pshs a 230 pshs a
191 lda $01,s 231 lda $01,s
192 lsr ,s 232 lsr ,s
193 lsr ,s 233 lsr ,s
194 bra L01A9 234 bra L01A9
235
195 L01A7 lslb 236 L01A7 lslb
196 rola 237 rola
197 L01A9 lsr ,s 238 L01A9 lsr ,s
198 bne L01A7 239 bne L01A7
199 leas 1,s 240 leas 1,s
210 ldy #$2F30 251 ldy #$2F30
211 cmpd #'0*256+C$SPAC 252 cmpd #'0*256+C$SPAC
212 bne L01D8 253 bne L01D8
213 ldy #$2F20 254 ldy #$2F20
214 lda #C$SPAC 255 lda #C$SPAC
215 L01D8 bsr L0164 256 L01D8 bsr bufchr
216 puls b,a 257 puls b,a
217 bra L01B6 258 bra L01B6
218 L01DE bsr L0164 259
260 L01DE bsr bufchr
219 lda #'k 261 lda #'k
220 bsr L0164 262 bsr bufchr
221 leas $02,s 263 leas $02,s
222 puls pc,y,x,b,a 264 puls pc,y,x,b,a
223 265
224 emod 266 emod
225 eom equ * 267 eom equ *