|
Revision cece96bdd71da5ad1492c2d96485320f78ba8a83, 5.2 KB
(checked in by H. Peter Anvin <hpa@…>, 2 years ago)
|
|
dosutil: move copybs here, update Makefile
Move copybs to dosutil, change the Makefile to deal with UPX being
able to compress (e.g. very small files.)
Signed-off-by: H. Peter Anvin <hpa@…>
|
-
Property mode set to
100644
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | absolute 0 |
|---|
| 24 | pspInt20: resw 1 |
|---|
| 25 | pspNextParagraph: resw 1 |
|---|
| 26 | resb 1 |
|---|
| 27 | |
|---|
| 28 | pspTerminateVector: resd 1 |
|---|
| 29 | pspControlCVector: resd 1 |
|---|
| 30 | pspCritErrorVector: resd 1 |
|---|
| 31 | resw 11 |
|---|
| 32 | |
|---|
| 33 | resw 23 |
|---|
| 34 | |
|---|
| 35 | pspFCB_2: resb 16 |
|---|
| 36 | resd 1 |
|---|
| 37 | |
|---|
| 38 | pspCommandArg: resb 127 |
|---|
| 39 | |
|---|
| 40 | section .text |
|---|
| 41 | org 100h |
|---|
| 42 | |
|---|
| 43 | mov ax,3000h |
|---|
| 44 | |
|---|
| 45 | xchg al,ah |
|---|
| 46 | mov [DOSVersion],ax |
|---|
| 47 | cmp ax,0200h |
|---|
| 48 | |
|---|
| 49 | mov dx,msg_ancient_err |
|---|
| 50 | jmp die |
|---|
| 51 | |
|---|
| 52 | section .bss |
|---|
| 53 | alignb 2 |
|---|
| 54 | DOSVersion: resw 1 |
|---|
| 55 | |
|---|
| 56 | section .text |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | xor cx,cx |
|---|
| 62 | mov si,pspCommandArg |
|---|
| 63 | mov cl,[pspCommandLen] |
|---|
| 64 | |
|---|
| 65 | cmdscan1: jcxz bad_usage |
|---|
| 66 | |
|---|
| 67 | dec cx |
|---|
| 68 | cmp al,' ' |
|---|
| 69 | |
|---|
| 70 | or al,020h |
|---|
| 71 | |
|---|
| 72 | jb bad_usage |
|---|
| 73 | cmp al,'z' |
|---|
| 74 | ja bad_usage |
|---|
| 75 | sub al,'a' |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | section .bss |
|---|
| 79 | DriveNo: resb 1 |
|---|
| 80 | |
|---|
| 81 | section .text |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | lodsb |
|---|
| 87 | dec cx |
|---|
| 88 | cmp al,':' |
|---|
| 89 | jne bad_usage |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | got_colon: jcxz bad_usage |
|---|
| 95 | lodsb |
|---|
| 96 | dec cx |
|---|
| 97 | cmp al,' ' |
|---|
| 98 | ja bad_usage |
|---|
| 99 | |
|---|
| 100 | skipspace: jcxz bad_usage |
|---|
| 101 | lodsb |
|---|
| 102 | dec cx |
|---|
| 103 | cmp al,' ' |
|---|
| 104 | jbe skipspace |
|---|
| 105 | |
|---|
| 106 | mov di,FileName |
|---|
| 107 | copyfile: stosb |
|---|
| 108 | jcxz got_cmdline |
|---|
| 109 | lodsb |
|---|
| 110 | dec cx |
|---|
| 111 | cmp al,' ' |
|---|
| 112 | ja copyfile |
|---|
| 113 | jmp short got_cmdline |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | jmp die |
|---|
| 120 | |
|---|
| 121 | section .data |
|---|
| 122 | msg_unfair: db 'Usage: copybs <drive>: <filename>', 0Dh, 0Ah, '$' |
|---|
| 123 | |
|---|
| 124 | section .bss |
|---|
| 125 | alignb 4 |
|---|
| 126 | FileName resb 256 |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | struc DPB |
|---|
| 133 | dpbDrive: resb 1 |
|---|
| 134 | dpbUnit: resb 1 |
|---|
| 135 | dpbSectorSize: resw 1 |
|---|
| 136 | dpbClusterMask: resb 1 |
|---|
| 137 | dpbClusterShift: resb 1 |
|---|
| 138 | dpbFirstFAT: resw 1 |
|---|
| 139 | dpbFATCount: resb 1 |
|---|
| 140 | dpbRootEntries: resw 1 |
|---|
| 141 | dpbFirstSector: resw 1 |
|---|
| 142 | dpbMaxCluster: resw 1 |
|---|
| 143 | dpbFATSize: resw 1 |
|---|
| 144 | dpbDirSector: resw 1 |
|---|
| 145 | dpbDriverAddr: resd 1 |
|---|
| 146 | dpbMedia: resb 1 |
|---|
| 147 | dpbFirstAccess: resb 1 |
|---|
| 148 | dpbNextDPB: resd 1 |
|---|
| 149 | dpbNextFree: resw 1 |
|---|
| 150 | dpbFreeCnt: resw 1 |
|---|
| 151 | endstruc |
|---|
| 152 | |
|---|
| 153 | section .bss |
|---|
| 154 | alignb 2 |
|---|
| 155 | SectorSize resw 1 |
|---|
| 156 | |
|---|
| 157 | section .text |
|---|
| 158 | got_cmdline: |
|---|
| 159 | xor al,al |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | mov dl,[DriveNo] |
|---|
| 163 | inc dl |
|---|
| 164 | |
|---|
| 165 | int 21h |
|---|
| 166 | |
|---|
| 167 | and al,al |
|---|
| 168 | jnz filesystem_error |
|---|
| 169 | |
|---|
| 170 | mov dx,[bx+dpbSectorSize] |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | section .data |
|---|
| 175 | align 4, db 0 |
|---|
| 176 | DISKIO equ $ |
|---|
| 177 | diStartSector: dd 0 |
|---|
| 178 | |
|---|
| 179 | diBuffer: dw SectorBuffer |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | section .text |
|---|
| 183 | read_bootsect: |
|---|
| 184 | mov ax,cs |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | mov [SectorSize],dx |
|---|
| 188 | |
|---|
| 189 | cmp word [DOSVersion],0400h |
|---|
| 190 | |
|---|
| 191 | .old: |
|---|
| 192 | mov bx,SectorBuffer |
|---|
| 193 | mov cx,1 |
|---|
| 194 | |
|---|
| 195 | .new: |
|---|
| 196 | mov [diBuffer+2],ax |
|---|
| 197 | |
|---|
| 198 | mov cx,-1 |
|---|
| 199 | .common: |
|---|
| 200 | xor dx,dx |
|---|
| 201 | |
|---|
| 202 | int 25h |
|---|
| 203 | |
|---|
| 204 | jc disk_read_error |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | mov cx,0020h |
|---|
| 211 | |
|---|
| 212 | int 21h |
|---|
| 213 | jc file_write_error |
|---|
| 214 | |
|---|
| 215 | mov bx,ax |
|---|
| 216 | push ax |
|---|
| 217 | |
|---|
| 218 | mov cx,[SectorSize] |
|---|
| 219 | mov dx,SectorBuffer |
|---|
| 220 | mov ah,40h |
|---|
| 221 | |
|---|
| 222 | jc file_write_error |
|---|
| 223 | cmp ax,[SectorSize] |
|---|
| 224 | jne file_write_error |
|---|
| 225 | |
|---|
| 226 | pop bx |
|---|
| 227 | |
|---|
| 228 | int 21h |
|---|
| 229 | jc file_write_error |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | int 21h |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | mov dx,msg_filesystem_err |
|---|
| 241 | jmp short die |
|---|
| 242 | disk_read_error: |
|---|
| 243 | mov dx,msg_read_err |
|---|
| 244 | jmp short die |
|---|
| 245 | file_write_error: |
|---|
| 246 | mov dx,msg_write_err |
|---|
| 247 | die: |
|---|
| 248 | push cs |
|---|
| 249 | pop ds |
|---|
| 250 | push dx |
|---|
| 251 | mov dx,msg_error |
|---|
| 252 | mov ah,09h |
|---|
| 253 | int 21h |
|---|
| 254 | pop dx |
|---|
| 255 | |
|---|
| 256 | mov ah,09h |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | mov ax,4C01h |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | section .data |
|---|
| 263 | msg_error: db 'ERROR: $' |
|---|
| 264 | msg_ancient_err: db 'DOS version 2.00 or later required', 0Dh, 0Ah, '$' |
|---|
| 265 | msg_filesystem_err: db 'Filesystem not found on disk', 0Dh, 0Ah, '$' |
|---|
| 266 | msg_read_err: db 'Boot sector read failed', 0Dh, 0Ah, '$' |
|---|
| 267 | msg_write_err: db 'File write failed', 0Dh, 0Ah, '$' |
|---|
| 268 | |
|---|
| 269 | section .bss |
|---|
| 270 | alignb 4 |
|---|
| 271 | SectorBuffer: resb 4096 |
|---|