summaryrefslogtreecommitdiff
path: root/v2.0/source/EXE2BIN.ASM
diff options
context:
space:
mode:
Diffstat (limited to 'v2.0/source/EXE2BIN.ASM')
-rw-r--r--v2.0/source/EXE2BIN.ASM514
1 files changed, 514 insertions, 0 deletions
diff --git a/v2.0/source/EXE2BIN.ASM b/v2.0/source/EXE2BIN.ASM
new file mode 100644
index 0000000..80deb43
--- /dev/null
+++ b/v2.0/source/EXE2BIN.ASM
@@ -0,0 +1,514 @@
1 title LOCATE (EXE2BIN)
2
3;Loader for EXE files under 86-DOS
4
5;The following switch allows use with the "old linker", which put a version
6;number where the new linker puts the number of bytes used in the last page.
7;If enabled, this will cause a test for 0004 at this location (the old linker
8;version number), and if equal, change it to 200H so all of the last page
9;will be used.
10
11;VER. 1.5
12; 05/21/82 Added rev number
13;
14;VER. 1.6
15; 07/01/82 A little less choosy about size matches
16;
17;VER. 2.0 Rev. 1 M.A.Ulloa
18; 10/08/82 Modified to use new 2.0 system calls for file i/o
19;
20; Rev. 2 M.A.Ulloa
21; 10/27/82 Added the DOS version check
22
23FALSE EQU 0
24TRUE EQU NOT FALSE
25
26OLDLINK EQU 0 ;1 to enable, 0 to disable
27
28 .xlist
29 INCLUDE DOSSYM.ASM
30 .list
31
32
33 subttl Main Code Area
34 page
35
36
37code segment byte
38code ends
39
40DATA SEGMENT PUBLIC BYTE
41
42
43 EXTRN bad_vers_err:BYTE,NOTFND:BYTE,NOROOM:BYTE,DIRFULL:BYTE
44 EXTRN CANTFIX:BYTE,RDBAD:BYTE,FULL:BYTE,PROMPT:BYTE,CRLF:BYTE
45
46make db "MAUlloa/Microsoft/V20"
47rev db "2"
48
49file1_ext db ".EXE",00h
50file2_ext db ".BIN",00h
51
52per1 db 0
53per2 db 0
54
55file1 db 64 dup(?)
56handle1 dw 1 dup(?)
57
58file2 db 64 dup(?)
59handle2 dw 1 dup(?)
60
61
62INBUF DB 5,0
63 DB 5 DUP(?)
64
65;The following locations must be defined for storing the header:
66
67RUNVAR LABEL BYTE ;Start of RUN variables
68RELPT DW ?
69LASTP LABEL WORD
70RELSEG DW ?
71SIZ LABEL WORD ;Share these locations
72PAGES DW ?
73RELCNT DW ?
74HEADSIZ DW ?
75 DW ?
76LOADLOW DW ?
77INITSS DW ?
78INITSP DW ?
79 DW ?
80INITIP DW ?
81INITCS DW ?
82RELTAB DW ?
83RUNVARSIZ EQU $-RUNVAR
84
85DATA ENDS
86
87STACK SEGMENT WORD STACK
88 DB 80H DUP (?)
89STACK ENDS
90
91ZLOAD SEGMENT
92ZLOAD ENDS
93LOAD EQU ZLOAD
94
95CODE SEGMENT BYTE
96
97 ASSUME CS:CODE
98
99LOCATE PROC FAR
100 JMP SHORT LOCSTRT
101
102HEADER DB "Vers 2.00"
103
104LOCSTRT:
105 MOV SI,81H
106 PUSH DS
107 XOR AX,AX
108 PUSH AX ;Push return address to DS:0
109
110;Code to print header
111; PUSH DS
112; MOV DX,DATA
113; MOV DS,DX
114; MOV DX,OFFSET HEADER
115; MOV AH,STD_CON_STRING_OUTPUT
116; INT 21H
117; POP DS
118
119;----- Check Version Number --------------------------------------------;
120 mov ah,Get_Version
121 int 21h
122 cmp al,2
123 jge vers_ok ; version >= 2, enter locate
124 push ds
125 mov dx,data
126 mov ds,dx
127 mov dx,offset bad_vers_err
128 MOV AH,STD_CON_STRING_OUTPUT
129 INT 21H
130 pop ds
131 ret ;long return to DOS
132
133;-----------------------------------------------------------------------;
134vers_ok:
135
136
137 MOV BX,WORD PTR DS:2 ;Get size of memory
138 MOV DX,DATA
139 MOV ES,DX
140
141 assume es:data
142
143;-----------------------------------------------------------------------;
144
145;----- Get the first file name
146 call kill_bl
147 jnc sj01
148 mov ds,dx
149 jmp bad_file
150sj01:
151 mov di,offset file1
152sj0:
153 lodsb ;get character of file name
154 cmp al,' '
155 je sj2
156 cmp al,0dh
157 je sj2
158 cmp al,'.' ;an extension separator found?
159 jne sj1
160 mov es:[per1],-1
161sj1:
162 stosb
163 jmp short sj0
164sj2:
165 dec si
166 mov byte ptr es:[di],00h ;nul terminate the filename
167 call kill_bl
168 jc no_second
169
170;----- Get the second file name
171 mov di,offset file2
172sj3:
173 lodsb ;get character of file name
174 cmp al,' '
175 je sj5
176 cmp al,0dh
177 je sj5
178 cmp al,'.' ;an extension separator found?
179 jne sj4
180 mov es:[per2],-1
181sj4:
182 stosb
183 jmp short sj3
184sj5:
185 mov byte ptr es:[di],00h ;nul terminate
186 jmp short check_ext
187
188;----- Copy file1 to file2
189no_second:
190 mov ds,dx
191
192 assume ds:data
193
194 mov si,offset file1
195 mov di,offset file2
196sj6:
197 lodsb
198 cmp al,'.'
199 je sj7
200 cmp al,00h
201 je sj7
202 stosb
203 jmp short sj6
204sj7:
205 mov byte ptr [di],00h
206
207;----- Check that files have an extension, otherwise set default
208check_ext:
209 mov ds,dx
210
211 assume ds:data
212
213 cmp [per1],-1
214 je file1_ok
215 mov si,offset file1
216sj8:
217 lodsb
218 cmp al,00h
219 jne sj8
220 mov di,si
221 mov si,offset file1_ext
222 call put_ext
223
224file1_ok:
225 cmp [per2],-1
226 je file2_ok
227 mov si,offset file2
228sj9:
229 lodsb
230 cmp al,00h
231 jne sj9
232 mov di,si
233 mov si,offset file2_ext
234 call put_ext
235 jmp short file2_ok
236
237;----- Fill in the default extent
238put_ext proc near
239 dec di
240 mov cx,5 ;move extent: period,extent,null
241 rep movsb
242 ret
243put_ext endp
244
245;----- Find the first non-blank
246kill_bl proc near
247 cld
248sj10:
249 lodsb
250 cmp al,' '
251 je sj10
252 dec si
253 cmp al,0dh
254 clc
255 jne sj11
256 stc
257sj11:
258 ret
259kill_bl endp
260
261file2_ok:
262
263;-----------------------------------------------------------------------;
264
265 mov dx,offset file1
266 mov ah,open
267 mov al,0 ;ror reading only
268 INT 21H ;Open input file
269 jc bad_file
270 mov [handle1],ax
271 jmp exeload
272
273bad_file:
274 MOV DX,OFFSET NOTFND
275xERROR:
276 MOV AH,STD_CON_STRING_OUTPUT
277 INT 21H
278 RET ;FAR return to MS-DOS
279TOOBIG:
280 MOV DX,OFFSET NOROOM
281 JMP xERROR
282BADEXE:
283 MOV DX,OFFSET CANTFIX
284ERRORJ: JMP xERROR
285
286EXELOAD:
287 MOV DX,OFFSET RUNVAR ;Read header in here
288 MOV CX,RUNVARSIZ ;Amount of header info we need
289 push bx
290 mov bx,[handle1]
291 MOV AH,read
292 INT 21H ;Read in header
293 pop bx
294 CMP [RELPT],5A4DH ;Check signature word
295 JNZ BADEXE
296 MOV AX,[HEADSIZ] ;size of header in paragraphs
297 ADD AX,31 ;Round up first
298 CMP AX,1000H ;Must not be >=64K
299 JAE TOOBIG
300 AND AX,NOT 31
301 MOV CL,4
302 SHL AX,CL ;Header size in bytes
303
304 push dx
305 push cx
306 push ax
307 push bx
308 mov dx,ax
309 xor cx,cx
310 mov al,0
311 mov bx,[handle1]
312 mov ah,lseek
313 int 21h
314 pop bx
315 pop ax
316 pop cx
317 pop dx
318
319 XCHG AL,AH
320 SHR AX,1 ;Convert to pages
321 MOV DX,[PAGES] ;Total size of file in 512-byte pages
322 SUB DX,AX ;Size of program in pages
323 CMP DX,80H ;Fit in 64K?
324 JAE TOOBIG
325 XCHG DH,DL
326 SHL DX,1 ;Convert pages to bytes
327 MOV AX,[LASTP] ;Get count of bytes in last page
328 OR AX,AX ;If zero, use all of last page
329 JZ WHOLEP
330
331 IF OLDLINK
332 CMP AX,4 ;Produced by old linker?
333 JZ WHOLEP ;If so, use all of last page too
334 ENDIF
335
336 SUB DX,200H ;Subtract last page
337 ADD DX,AX ;Add in byte count for last page
338WHOLEP:
339 MOV [SIZ],DX
340 ADD DX,15
341 SHR DX,CL ;Convert bytes to paragraphs
342 MOV BP,LOAD
343 ADD DX,BP ;Size + start = minimum memory (paragr.)
344 CMP DX,BX ;Enough memory?
345 JA TOOBIG
346 MOV DX,OFFSET CANTFIX
347 MOV AX,[INITSS]
348 OR AX,[INITSP]
349 OR AX,[INITCS]
350ERRORNZ:
351 jz xj
352 JMP ERRORJ ;Must not have SS, SP, or CS to init.
353xj: MOV AX,[INITIP]
354 OR AX,AX ;If IP=0, do binary fix
355 JZ BINFIX
356 CMP AX,100H ;COM file must be set up for CS:100
357 JNZ ERRORNZ
358
359 push dx
360 push cx
361 push ax
362 push bx
363 mov dx,100h ;chop off first 100h
364 xor cx,cx
365 mov al,1 ;seek from current position
366 mov bx,[handle1]
367 mov ah,lseek
368 int 21h
369 pop bx
370 pop ax
371 pop cx
372 pop dx
373
374 SUB [SIZ],AX ;And count decreased size
375 CMP [RELCNT],0 ;Must have no fixups
376 JNZ ERRORNZ
377BINFIX:
378 XOR BX,BX ;Initialize fixup segment
379;See if segment fixups needed
380 CMP [RELCNT],0
381 JZ LOADEXE
382GETSEG:
383 MOV DX,OFFSET PROMPT
384 MOV AH,STD_CON_STRING_OUTPUT
385 INT 21H
386 MOV AH,STD_CON_STRING_INPUT
387 MOV DX,OFFSET INBUF
388 INT 21H ;Get user response
389 MOV DX,OFFSET CRLF
390 MOV AH,STD_CON_STRING_OUTPUT
391 INT 21H
392 MOV SI,OFFSET INBUF+2
393 MOV BYTE PTR [SI-1],0 ;Any digits?
394 JZ GETSEG
395DIGLP:
396 LODSB
397 SUB AL,"0"
398 JC DIGERR
399 CMP AL,10
400 JB HAVDIG
401 AND AL,5FH ;Convert to upper case
402 SUB AL,7
403 CMP AL,10
404 JB DIGERR
405 CMP AL,10H
406 JAE DIGERR
407HAVDIG:
408 SHL BX,1
409 SHL BX,1
410 SHL BX,1
411 SHL BX,1
412 OR BL,AL
413 JMP DIGLP
414
415DIGERR:
416 CMP BYTE PTR [SI-1],0DH ;Is last char. a CR?
417 JNZ GETSEG
418LOADEXE:
419 XCHG BX,BP ;BX has LOAD, BP has fixup
420
421 MOV CX,[SIZ]
422 MOV AH,read
423 push di
424 mov di,[handle1]
425 PUSH DS
426 MOV DS,BX
427 XOR DX,DX
428 push bx
429 mov bx,di
430 INT 21H ;Read in up to 64K
431 pop bx
432 POP DS
433 pop di
434 Jnc HAVEXE ;Did we get it all?
435 MOV DX,OFFSET RDBAD
436 jmp xERROR ;Non fatal, print warning
437HAVEXE:
438 CMP [RELCNT],0 ;Any fixups to do?
439 JZ STORE
440 MOV AX,[RELTAB] ;Get position of table
441
442 push dx
443 push cx
444 push ax
445 push bx
446 mov dx,ax
447 xor cx,cx
448 mov al,0
449 mov bx,[handle1]
450 mov ah,lseek
451 int 21h
452 pop bx
453 pop ax
454 pop cx
455 pop dx
456
457 MOV DX,OFFSET RELPT ;4-byte buffer for relocation address
458RELOC:
459 MOV DX,OFFSET RELPT ;4-byte buffer for relocation address
460 MOV CX,4
461 MOV AH,read
462 push bx
463 mov bx,[handle1]
464 INT 21H ;Read in one relocation pointer
465 pop bx
466 Jnc RDCMP
467 JMP BADEXE
468RDCMP:
469 MOV DI,[RELPT] ;Get offset of relocation pointer
470 MOV AX,[RELSEG] ;Get segment
471 ADD AX,BX ;Bias segment with actual load segment
472 MOV ES,AX
473 ADD ES:[DI],BP ;Relocate
474 DEC [RELCNT] ;Count off
475 JNZ RELOC
476STORE:
477 MOV AH,CREAT
478 MOV DX,OFFSET file2
479 xor cx,cx
480 INT 21H
481 Jc MKERR
482 mov [handle2],ax
483 MOV CX,[SIZ]
484 MOV AH,write
485 push di
486 mov di,[handle2]
487 PUSH DS
488 MOV DS,BX
489 XOR DX,DX ;Address 0 in segment
490 push bx
491 mov bx,di
492 INT 21H
493 pop bx
494 POP DS
495 pop di
496 Jc WRTERR ;Must be zero if more to come
497 MOV AH,CLOSE
498 push bx
499 mov bx,[handle2]
500 INT 21H
501 pop bx
502 RET
503
504WRTERR:
505 MOV DX,OFFSET FULL
506 JMP xERROR
507MKERR:
508 MOV DX,OFFSET DIRFULL
509 JMP xERROR
510
511LOCATE ENDP
512CODE ENDS
513 END LOCATE
514