]>
wirehaze git hosting - MS-DOS.git/blob - v2.0/source/EXE2BIN.ASM
3 ;Loader for EXE files under 86-DOS
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
12 ; 05/21/82 Added rev number
15 ; 07/01/82 A little less choosy about size matches
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
21 ; 10/27/82 Added the DOS version check
26 OLDLINK EQU
0 ;1 to enable, 0 to disable
40 DATA SEGMENT PUBLIC BYTE
43 EXTRN bad_vers_err
:BYTE,NOTFND
:BYTE,NOROOM
:BYTE,DIRFULL
:BYTE
44 EXTRN CANTFIX
:BYTE,RDBAD
:BYTE,FULL
:BYTE,PROMPT
:BYTE,CRLF
:BYTE
46 make db "MAUlloa/Microsoft/V20"
49 file1_ext db ".EXE",00h
50 file2_ext db ".BIN",00h
65 ;The following locations must be defined for storing the header:
67 RUNVAR
LABEL BYTE ;Start of RUN variables
71 SIZ
LABEL WORD ;Share these locations
83 RUNVARSIZ EQU
$-RUNVAR
87 STACK SEGMENT WORD STACK
102 HEADER
DB "Vers 2.00"
108 PUSH AX ;Push return address to DS:0
110 ;Code to print header
114 ; MOV DX,OFFSET HEADER
115 ; MOV AH,STD_CON_STRING_OUTPUT
119 ;----- Check Version Number --------------------------------------------;
123 jge vers_ok
; version >= 2, enter locate
127 mov dx,offset bad_vers_err
128 MOV AH,STD_CON_STRING_OUTPUT
131 ret ;long return to DOS
133 ;-----------------------------------------------------------------------;
137 MOV BX,WORD PTR DS:2 ;Get size of memory
143 ;-----------------------------------------------------------------------;
145 ;----- Get the first file name
153 lodsb ;get character of file name
158 cmp al,'.' ;an extension separator found?
166 mov byte ptr es:[di],00h ;nul terminate the filename
170 ;----- Get the second file name
173 lodsb ;get character of file name
178 cmp al,'.' ;an extension separator found?
185 mov byte ptr es:[di],00h ;nul terminate
188 ;----- Copy file1 to file2
205 mov byte ptr [di],00h
207 ;----- Check that files have an extension, otherwise set default
221 mov si,offset file1_ext
233 mov si,offset file2_ext
237 ;----- Fill in the default extent
240 mov cx,5 ;move extent: period,extent,null
245 ;----- Find the first non-blank
263 ;-----------------------------------------------------------------------;
267 mov al,0 ;ror reading only
268 INT 21H
;Open input file
276 MOV AH,STD_CON_STRING_OUTPUT
278 RET ;FAR return to MS-DOS
283 MOV DX,OFFSET CANTFIX
287 MOV DX,OFFSET RUNVAR
;Read header in here
288 MOV CX,RUNVARSIZ
;Amount of header info we need
292 INT 21H
;Read in header
294 CMP [RELPT
],5A4DH
;Check signature word
296 MOV AX,[HEADSIZ
] ;size of header in paragraphs
297 ADD AX,31 ;Round up first
298 CMP AX,1000H
;Must not be >=64K
302 SHL AX,CL ;Header size in bytes
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?
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
332 CMP AX,4 ;Produced by old linker?
333 JZ WHOLEP
;If so, use all of last page too
336 SUB DX,200H
;Subtract last page
337 ADD DX,AX ;Add in byte count for last page
341 SHR DX,CL ;Convert bytes to paragraphs
343 ADD DX,BP ;Size + start = minimum memory (paragr.)
344 CMP DX,BX ;Enough memory?
346 MOV DX,OFFSET CANTFIX
352 JMP ERRORJ
;Must not have SS, SP, or CS to init.
354 OR AX,AX ;If IP=0, do binary fix
356 CMP AX,100H
;COM file must be set up for CS:100
363 mov dx,100h
;chop off first 100h
365 mov al,1 ;seek from current position
374 SUB [SIZ
],AX ;And count decreased size
375 CMP [RELCNT
],0 ;Must have no fixups
378 XOR BX,BX ;Initialize fixup segment
379 ;See if segment fixups needed
384 MOV AH,STD_CON_STRING_OUTPUT
386 MOV AH,STD_CON_STRING_INPUT
388 INT 21H
;Get user response
390 MOV AH,STD_CON_STRING_OUTPUT
392 MOV SI,OFFSET INBUF
+2
393 MOV BYTE PTR [SI-1],0 ;Any digits?
401 AND AL,5FH
;Convert to upper case
416 CMP BYTE PTR [SI-1],0DH ;Is last char. a CR?
419 XCHG BX,BP ;BX has LOAD, BP has fixup
430 INT 21H
;Read in up to 64K
434 Jnc HAVEXE
;Did we get it all?
436 jmp xERROR
;Non fatal, print warning
438 CMP [RELCNT
],0 ;Any fixups to do?
440 MOV AX,[RELTAB
] ;Get position of table
457 MOV DX,OFFSET RELPT
;4-byte buffer for relocation address
459 MOV DX,OFFSET RELPT
;4-byte buffer for relocation address
464 INT 21H
;Read in one relocation pointer
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
473 ADD ES:[DI],BP ;Relocate
474 DEC [RELCNT
] ;Count off
489 XOR DX,DX ;Address 0 in segment
496 Jc WRTERR
;Must be zero if more to come
508 MOV DX,OFFSET DIRFULL