Mercurial > hg > Members > kono > nitros9-code
comparison level2/cmds/mfree.asm @ 3194:2ecebda8716b
mfree.asm: Fix zero-day Block Map entry bug
Previously, code assumed that the final entry in the block map would be
used. This was true for CoCo but is not necessarily true (and is not
true for mc09). Slight mod removes that implicit assumption; the code
now works correctly on both platforms.
author | Neal Crook <foofoobedoo@gmail.com> |
---|---|
date | Tue, 30 May 2017 23:59:46 +0100 |
parents | 489617e567c5 |
children |
comparison
equal
deleted
inserted
replaced
3193:489617e567c5 | 3194:2ecebda8716b |
---|---|
6 * Edt/Rev YYYY/MM/DD Modified by | 6 * Edt/Rev YYYY/MM/DD Modified by |
7 * Comment | 7 * Comment |
8 * ------------------------------------------------------------------ | 8 * ------------------------------------------------------------------ |
9 * 2 ????/??/?? | 9 * 2 ????/??/?? |
10 * Original Tandy/Microware version. | 10 * Original Tandy/Microware version. |
11 * 3 2017/05/30 Neal Crook | |
12 * Original version misbehaved if final block in the map was free. | |
13 * That situation never occurs on coco, but it does occur on the mc09 | |
14 * target. Inferred behaviour and added comments as a side-effect of | |
15 * debugging effort. | |
11 | 16 |
12 nam Mfree | 17 nam Mfree |
13 ttl Show free memory | 18 ttl Show free memory |
14 | 19 |
15 * Disassembled 98/09/11 12:07:32 by Disasm v1.6 (C) 1988 by RML | 20 * Disassembled 98/09/11 12:07:32 by Disasm v1.6 (C) 1988 by RML |
19 endc | 24 endc |
20 | 25 |
21 tylg set Prgrm+Objct | 26 tylg set Prgrm+Objct |
22 atrv set ReEnt+rev | 27 atrv set ReEnt+rev |
23 rev set $00 | 28 rev set $00 |
24 edition set 2 | 29 edition set 3 |
25 | 30 |
26 mod eom,name,tylg,atrv,start,size | 31 mod eom,name,tylg,atrv,start,size |
27 | 32 |
28 freeblks rmb 2 | 33 freeblks rmb 2 |
29 mapsiz rmb 2 | 34 mapsiz rmb 2 |
76 loop ldu #$0000 number of free blocks in this sequence | 81 loop ldu #$0000 number of free blocks in this sequence |
77 L00AD tst ,x+ is this block 0? | 82 L00AD tst ,x+ is this block 0? |
78 beq L00BA yes - found a free block | 83 beq L00BA yes - found a free block |
79 leay $01,y total number of blocks we have inspected | 84 leay $01,y total number of blocks we have inspected |
80 cmpy <mapsiz at the end of the map? | 85 cmpy <mapsiz at the end of the map? |
81 bcs L00AD no, so carry on looking | 86 bne L00AD no, so carry on looking |
82 bra alldone yes, and the last block was not free, so we're done. | 87 bra alldone yes, and the last block was not free, so we're done. |
83 | 88 |
84 * Block number in Y is the first free block of a sequence (tho maybe a sequence of 1) | 89 * Block number in Y is the first free block of a sequence (tho maybe a sequence of 1) |
85 L00BA tfr y,d | 90 L00BA tfr y,d |
86 bsr buf4hex append start block, in hex, to output buffer | 91 bsr buf4hex append start block, in hex, to output buffer |
98 | 103 |
99 * Look for the last free block in this sequence | 104 * Look for the last free block in this sequence |
100 L00D2 leau $01,u | 105 L00D2 leau $01,u |
101 leay $01,y | 106 leay $01,y |
102 cmpy <mapsiz | 107 cmpy <mapsiz |
103 beq alldone ??should never exit at this point, but | 108 beq last |
104 * on mc09 we do - terminate part-way through an entry. | 109 |
105 tst ,x+ | 110 tst ,x+ |
106 beq L00D2 haven't found it yet.. | 111 beq L00D2 haven't found it yet.. |
107 last lda <ppblk | 112 last lda <ppblk |
108 pshs y,a | 113 pshs y,a |
109 clra | 114 clra |
116 std <u0006 2 MS bytes of block end address | 121 std <u0006 2 MS bytes of block end address |
117 lda #$FF | 122 lda #$FF |
118 sta <u0008 1 LS byte of block end address is $FF | 123 sta <u0008 1 LS byte of block end address is $FF |
119 bsr buf6hex append block end address in hex, to output buffer | 124 bsr buf6hex append block end address in hex, to output buffer |
120 leax -$01,x | 125 leax -$01,x |
121 tfr u,d | 126 tfr u,d number of blocks in this sequence u->d |
122 bsr buf4hex append number of blocks, in hex, to output buffer | 127 bsr buf4hex append number of blocks, in hex, to output buffer |
123 lbsr L0199 append size, in decimal, to output buffer | 128 lbsr L0199 append size, in decimal, to output buffer |
124 | 129 |
125 addd <freeblks | 130 addd <freeblks |
126 std <freeblks total number of blocks | 131 std <freeblks total number of blocks |
127 bsr wrbuf print this entry | 132 bsr wrbuf print this entry |
128 bra loop loop for next entry | 133 cmpy <mapsiz |
134 bne loop loop for next entry | |
129 | 135 |
130 * All of the entries have been printed. Print the trailer and totals. | 136 * All of the entries have been printed. Print the trailer and totals. |
131 * Bug: if the last block is unused, it and any unused blocks before it will | |
132 * not get reported, *and* the formatting of the last entry will be messed up. | |
133 * That never happens on the Coco, because the last block is always used. | |
134 * It does happen on mc09 though. | |
135 alldone leay >Ftr,pcr | 137 alldone leay >Ftr,pcr |
136 bsr tobuf 1st line of footer to output buffer | 138 bsr tobuf 1st line of footer to output buffer |
137 bsr wrbuf ..print it | 139 bsr wrbuf ..print it |
138 bsr tobuf 2nd line of footer to output buffer | 140 bsr tobuf 2nd line of footer to output buffer |
139 tfr u,d ..add total #blocks, total memory size | 141 ldd <freeblks get total number of blocks |
140 addd <freeblks | |
141 std <freeblks | |
142 bsr buf4hex append total number of blocks, in hex, to output buffer | 142 bsr buf4hex append total number of blocks, in hex, to output buffer |
143 bsr L0199 append total size, in decimal, to output buffer | 143 bsr L0199 append total size, in decimal, to output buffer |
144 bsr wrbuf ..print it | 144 bsr wrbuf ..print it |
145 * Successful exit | 145 * Successful exit |
146 clrb | 146 clrb |