home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / fileutil / unld8615.arj / UNLOAD86.A86 < prev    next >
Encoding:
Text File  |  1992-06-04  |  23.9 KB  |  743 lines

  1. ;************************************************************************
  2. ;*                                    *
  3. ;*    UNLOAD86.A86  This is a MS-DOS unload program.    See the help    *
  4. ;*    screen at the end of this file for details on its use.        *
  5. ;*    Written by:  Mark D. Pickerill 9 Aug. 1988            *
  6. ;*    Assemble with the 2500 A.D. X8086 assembler.            *
  7. ;*                                    *
  8. ;************************************************************************
  9.                 ;
  10. CR:    EQU    0DH        ; Carriage return
  11. LF:    EQU    0AH        ; Line feed
  12. EOF:    EQU    1AH        ; End of file
  13.                 ;
  14.     CHIP    8086        ; 8086 mode
  15.                 ;
  16.     ORG    0100H        ; Start of tpa
  17.                 ;
  18. UNLOAD:    JMP    SHORT START    ; Skip data area
  19.                 ;
  20. FILDAT:                ;
  21.     DB    0FFH        ; Data to fill empty space in rom (if selected)
  22. BNPFTYP:            ;
  23.     DB    'PN'        ; Pn for bnpf, hl for bhlf, or 10 for b10f
  24. FTYPE:                ;
  25.     DB    '.HEX',00H    ; File type
  26. FTYPE1:                ;
  27.     DB    '.BNP',00H    ; File type for bnpf files
  28. DOEOF:                ;
  29.     DB    00H        ; Zero for no eof (cntrl-z, 1ah) on end of file
  30.                 ; End of user patchable options
  31. OUTTYPE:            ;
  32.     DB    00H        ; 00 for hex, non-zero for bnpf
  33. USELIN:                ;
  34.     DB    00H        ; 00 for no extended linear address
  35. USEEXT:                ;
  36.     DB    00H        ; 00 for no extended address records
  37. DOFILL:                ;
  38.     DB    00H        ; 00 not to fill to end of rom
  39. OVERRIDE:            ;
  40.     DB    00H        ; Ff if overriding forced extended addressing
  41. ENDSEG:                ;
  42.     DW    0000H        ; Space to store end segment for rom fill
  43. ENDADDR:            ;
  44.     DW    0000H        ; Space to store end address for rom fill
  45. OOD:                ;
  46.     DB    00H        ; Flag 0 for read from disk, ff to use fildat
  47.                 ;
  48. NOPARMS:JMP    HELP        ; Extend short jump
  49.                 ;
  50. START:    PUSH    CS        ; Set data segment
  51.     POP    DS        ; It's set
  52.     PUSH    DS        ; Get this segment
  53.     POP    ES        ; And set es as well
  54.     CALL    ILPRT        ; Print signon message
  55.     DB    CR,LF,'UNLOAD86 ver. 1.5a',00H
  56.     MOV    SI,0080H    ; Point to parameter field in psp
  57.     LODSB            ; Get parameter length
  58.     MOV    CL,AL        ; Into cl
  59.     OR    CL,CL        ; Force flags
  60.     JZ    NOPARMS        ; Print help screen
  61.     MOV    CH,00H        ; Zero ch
  62. LOOP1:    LODSB            ; Get byte from parameter field
  63.     CMP    AL,' '        ; Space?
  64.     LOOPZ    LOOP1        ; Wait until you get a non-space char
  65.     JZ    NOPARMS        ; Just spaces, print help screen
  66.     CMP    AL,'/'        ; Switch char?
  67.     JZ    NOPARMS        ; No filename!, print help screen
  68.     CMP    AL,'-'        ; Alt switch for unix types
  69.     JZ    NOPARMS        ; No filename!, print help screen
  70.     CMP    AL,'['        ; Alt switch for cp/m types
  71.     JZ    NOPARMS        ; No filename!, print help screen
  72.     LEA    DI,INFN        ; Point to input filename area
  73.     STOSB            ; Stuff this char
  74. LOOP2:    LODSB            ; Get byte
  75.     CMP    AL,' '        ; Space?
  76.     JZ    NOSP        ; Yes,ignore
  77.     CMP    AL,'/'        ; Or switch char?
  78.     JZ    SWITCH        ; Yes
  79.     CMP    AL,'-'        ; Alt switch for unix types
  80.     JZ    SWITCH        ; Yes
  81.     CMP    AL,'['        ; Alt switch for cp/m types
  82.     JZ    SWITCH        ; Yes
  83.     STOSB            ; Stuff char
  84. NOSP:    LOOP    LOOP2        ; Nope
  85.     JMP    CONT        ; No more
  86. SWITCH:    LODSB            ; Get switch options
  87.     AND    AL,5FH        ; Make upper case as ibm types
  88.                 ; Usualy use lower case!
  89.     CMP    AL,'B'        ; Bnpf option?
  90.     JZ    SETBNPF        ; Yes
  91.     CMP    AL,'O'        ; Override forced extended address records?
  92.     JZ    SETOVR        ; Yes
  93.     CMP    AL,'E'        ; Use extended addressing?
  94.     JZ    SETEXT        ; Yes
  95.     CMP    AL,'P'        ; Set eprom type?
  96.     JZ    SETROM        ; Yes
  97.     CMP    AL,'L'        ; Use extended linear addressing?
  98.     JZ    SETLIN        ; Yes
  99.     CMP    AL,'Z'        ; Put control-z at end of file?
  100.     JZ    SETEOF        ; Yes
  101.     LOOP    SWITCH        ; Look for more options
  102.     JMP    CONT        ; No more
  103.                 ;
  104. SETOVR:    XOR    AL,AL        ; Turn off extended addressing
  105.     MOV    [USEEXT],AL    ; Do it
  106.     MOV    [USELIN],AL    ; Turn of extended linear addressing
  107.     DEC    AL        ; Indicate override of extended addressing
  108.     MOV    [OVERRIDE],AL    ; Flag it as such
  109.     LOOP    SWITCH        ; Look for more options
  110.     JMP    CONT        ; No more
  111.                 ;
  112. SETEXT:    XOR    AL,AL        ; Turn off extended linear addressing
  113.     MOV    [USELIN],AL    ; Do it
  114.     DEC    AL        ; Indicate use of extended addressing
  115.     MOV    [USEEXT],AL    ; Flag it as such
  116.     LOOP    SWITCH        ; Look for more options
  117.     JMP    CONT        ; No more
  118.                 ;
  119. SETLIN:    XOR    AL,AL        ; Turn off extended addressing
  120.     MOV    [USEEXT],AL    ; Do it
  121.     MOV    [DOFILL],AL    ; Turn off fill to end of rom
  122.     DEC    AL        ; Get an ff
  123.     MOV    [OVERRIDE],AL    ; Flag extended override
  124.     MOV    [USELIN],AL    ; Flag use of extended linear addressing
  125.     LOOP    SWITCH        ; Look for more options
  126.     JMP    CONT        ; No more options
  127.                 ;
  128. SETBNPF:NOT    BYTE PTR [OUTTYPE] ; Indicate bnpf option
  129.     JMP    SHORT LOOKMOR    ; Look for more options
  130.                 ;
  131. SETEOF:    NOT    BYTE PTR [DOEOF] ; Put eof at end of file
  132.                 ;
  133. LOOKMOR:LOOP    SWITCH        ; If more, look for additional options
  134.     JMP    CONT        ; No more
  135.                 ;
  136. SETROM:    MOV    [USELIN],BYTE PTR 00H ; Turn off linear extended addressing
  137.     DEC    CX        ; Decrement loop counter
  138.     LODSB            ; Get char
  139.     CMP    AL,'0'        ; At least a zero?
  140.     JC    LOOKMOR        ; No,ignore
  141.     CMP    AL,'A'        ; At least an a?
  142.     JC    NUM        ; Numeric
  143.     AND    AL,5FH        ; Force upper case
  144.     CMP    AL,'G'        ; More garbage?
  145.     JNC    LOOKMOR        ; Yes, ignore
  146.     SUB    AL,37H        ; Remove alpha bias
  147.     JMP    SHORT FOUNDIT    ; And continue
  148. NUM:    CMP    AL,3AH        ; Above numeric?
  149.     JNC    LOOKMOR        ; Yes, ignore
  150.     SUB    AL,30H        ; Remove numeric bias
  151. FOUNDIT:CMP    AL,0CH        ; Big rom?
  152.     JC    SMALL        ; No
  153.     CALL    CHKOVR        ; Unless user has overridden
  154. SMALL:    PUSH    SI        ; Save pointer
  155.     LEA    SI,ATABLE    ; Point to address table
  156.     ADD    AL,AL        ; Multiply by two
  157.     ADD    AL,AL        ; And by four
  158.     XOR    AH,AH        ; Clear ah
  159.     ADD    SI,AX        ; Add in offset
  160.     LODSW            ; Get segment address
  161.     MOV    [ENDSEG],AX    ; Stuff it
  162.     LODSW            ; Get offset address
  163.     MOV    [ENDADDR],AX    ; Stuff it
  164.     MOV    [DOFILL],BYTE PTR 0FFH ; Flag fillrom operation
  165.     POP    SI        ; Restore si
  166.     JMP    LOOKMOR        ; Go look for more options
  167.                 ;
  168. CONT:    MOV    [DI],BYTE PTR 00H ; Terminate string
  169.     LEA    SI,INFN        ; Copy input to output fn
  170.     LEA    DI,OUTFN    ; Pointing to output filename
  171.     MOV    CX,60D        ; 64-4 for 'hex0' is 60
  172. LOOP3:    LODSB            ; Get byte
  173.     STOSB            ; Stash it (need it in al, movsb won't work)
  174.     CMP    AL,'.'        ; Looking for that file extension
  175.     JZ    DONE        ; Found the dot
  176.     CMP    AL,00H        ; End?
  177.     LOOPNZ    LOOP3        ; Continue
  178. DONE:    DEC    DI        ; Backup over dot or zero
  179.     MOV    CX,0005H    ; Five bytes to move
  180.     MOV    AL,[OUTTYPE]    ; Hex or bnpf?
  181.     OR    AL,AL        ; Force flags
  182.     JZ    OHEX        ; Hex
  183.     LEA    SI,FTYPE1    ; Point to file type for bnpf
  184.     JMP    SHORT ALL    ; And continue
  185. OHEX:    LEA    SI,FTYPE    ; Point to file type for hex
  186. ALL:    REP    MOVSB        ; Move the rest
  187.                 ;
  188.     MOV    AL,00H        ; Read access code
  189.     MOV    AH,3DH        ; Open file function
  190.     LEA    DX,INFN        ; Point to input file name
  191.     INT    21H        ; Open the file
  192.     MOV    [INHDL],AX    ; Save handle
  193.     JNC    OK        ; Ok
  194.     CALL    ILPRT        ; Print this...
  195.     DB    CR,LF,'Failure to Open Input file',00H
  196.     JMP    FINIS        ; Go to error handler
  197.                 ;
  198. OK:    MOV    BX,AX        ; Handle in bx
  199.     MOV    AX,4202H    ; Move to end of file
  200.     XOR    CX,CX        ; Clear offsets
  201.     MOV    DX,CX        ; Inc. dx
  202.     INT    21H        ; Do it
  203.     OR    DX,DX        ; Longer than 64k?
  204.     JZ    LT64K        ; No
  205.     CALL    CHKOVR        ; Check extended addressing override
  206.                 ;
  207. LT64K:    XOR    CX,CX        ; Clear offsets
  208.     MOV    DX,CX        ; All 32 bits
  209.     MOV    AX,4200H    ; Move back to start of file
  210.     MOV    BX,[INHDL]    ; Get handle
  211.     INT    21H        ; Moved back
  212.     MOV    CL,00H        ; Normal addributes
  213.     MOV    AH,3CH        ; Create file function
  214.     LEA    DX,OUTFN    ; Point to file name
  215.     INT    21H        ; Open the file
  216.     JNC    OK1        ; Ok
  217.     CALL    ILPRT        ; Print this...
  218.     DB    CR,LF,'Failure to Open output file',00H
  219.     JMP    FINIS        ; Go to error handler
  220. OK1:    MOV    [OUTHDL],AX    ; Save handle
  221.     MOV    AL,[OUTTYPE]    ; Get output format
  222.     OR    AL,AL        ; Force flags
  223.     JZ    READ        ; Don't do start char for bnpf
  224.     LEA    DX,CNTRLB    ; Point to start byte
  225.     MOV    BX,[OUTHDL]    ; Get output handle
  226.     MOV    AH,40H        ; Write function
  227.     MOV    CX,0003H    ; One byte + crlf
  228.     INT    21H        ; Do it
  229.     JNC    READ        ; Ok
  230.     JMP    BADWR        ; Error
  231.                 ;
  232. READ:    LEA    DI,INBUF    ; Point to input buffer
  233.     MOV    CX,16D        ; Fill entire buffer
  234.     MOV    AL,[FILDAT]    ; Get fill data
  235.     MOV    AH,AL        ; Dup into ah
  236.     REP    STOSW        ; Do it
  237.                 ;
  238.     MOV    AL,[OOD]    ; Already out of data?
  239.     OR    AL,AL        ; Force flags
  240.     JNZ    FILLIT        ; Yup
  241.     LEA    DX,INBUF    ; Point to buffer
  242.     MOV    BX,[INHDL]    ; Get handle
  243.     CALL    DSKRD        ; Go get data
  244.     JNC    ROK        ; Ok
  245.     CALL    ILPRT        ; Print this...
  246.     DB    CR,LF,'Error Reading Input file',00H
  247.     JMP    FINIS        ; Go to error handler
  248.                 ;
  249. CNTRLB:                ;
  250.     DB    02H,CR,LF    ; Bnpf start
  251.                 ;
  252. ROK:    OR    AX,AX        ; Completely finished?
  253.     JNZ    NOPE        ; Nope
  254.     MOV    AL,[OUTTYPE]    ; Check for bnpf
  255.     OR    AL,AL        ; Force flags
  256.     JNZ    EXIT        ; Bnpf ignores all this...
  257.     MOV    AL,0FFH        ; Indicate we're finished reading from disk
  258.     MOV    [OOD],AL    ; Flag it
  259.     MOV    AL,[DOFILL]    ; Check for fillrom function
  260.     OR    AL,AL        ; Force flags
  261.     JZ    EXIT        ; Not selected
  262. FILLIT:    MOV    AX,[EXTEND]    ; Get current segment
  263.     SUB    AX,1000H    ; Compensate to what is in use
  264.     CMP    [ENDSEG],AX    ; Check against selected end segment
  265.     JC    TOOBIG        ; Warn operator that his data won't fit
  266.     JNZ    NOPE        ; Segment hasn't been reached yet, continue
  267.     MOV    AX,[ADDRESS]    ; Get current address
  268.     DEC    AX        ; To last location, not next avail loc
  269.     CMP    [ENDADDR],AX    ; Check against selected end address
  270.     JC    TOOBIG        ; Warn operator that his data won't fit
  271.     JNZ    NOPE        ; Address hasn't been reached yet
  272.                 ;
  273. EXIT:    JMP    FINISHUP    ; Yes, finish up & terminate
  274. TOOBIG:    JMP    WARN        ; Tell operator
  275. NOPE:    MOV    AL,[OUTTYPE]    ; Get output format
  276.     OR    AL,AL        ; Force flags
  277.     JZ    HEX        ; Do hex
  278.                 ; Drop through to bnpf
  279.     LEA    SI,INBUF    ; Point to input buffer
  280.     MOV    CX,32D        ; 32 bytes to process
  281. BNPF:    LEA    DI,OUTBUF    ; Output buffer
  282.     MOV    [DI],BYTE PTR 'B' ; The b for begin
  283.     INC    DI        ; Next location
  284. BIGLP:    LODSB            ; Get byte
  285.     PUSH    CX        ; Save byte loop
  286.     MOV    CX,0008H    ; 8 bits in a byte
  287. BNPFLP:    RCL    AL,1        ; Rotate through carry
  288.     JC    P        ; High
  289.     MOV    AH,[BNPFTYP+1]    ; Get the byte for low
  290.     MOV    [DI],AH        ; Put in buffer
  291.     INC    DI        ; Next location
  292.     LOOP    BNPFLP        ; Do entire byte
  293.     JMP    ONEBYTE        ; Complete & write
  294. P:    MOV    AH,[BNPFTYP]    ; Get the byte for high
  295.     MOV    [DI],AH        ; Put in buffer
  296.     INC    DI        ; Next location
  297.     LOOP    BNPFLP        ; Do entire byte
  298. ONEBYTE:MOV    [DI],BYTE PTR 'F' ; The f for finish
  299.     POP    CX        ; Recover byte loop
  300.     INC    DI        ; Next dest
  301.     MOV    [DI],BYTE PTR 0DH ; Send a cr
  302.     INC    DI        ; Next
  303.     MOV    [DI],BYTE PTR 0AH ; Send a lf
  304.     INC    DI        ; Next
  305.     PUSH    CX        ; Save loop counter
  306.     PUSH    SI        ; Save input counter
  307.     MOV    CX,12D        ; Twelve bytes every time
  308.     CALL    WRITE        ; Write byte
  309.     POP    SI        ; Recover input counter
  310.     POP    CX        ; Recover loop counter
  311.     LOOP    BNPF        ; Do next byte
  312.     JMP    READ        ; Read next 32 bytes
  313.                 ;
  314. HEX:    XOR    BX,BX        ; Output counter
  315.     MOV    CX,32D        ; Input counter
  316.     XOR    DX,DX        ; Dl is checksum reg
  317.     MOV    AX,[ADDRESS]    ; Get current load address
  318.     OR    AX,AX        ; Force flags
  319.     JNZ    NOEXT        ; No extended address record needed
  320.     CALL    EAR        ; Do extended addressing if selected
  321. NOEXT:    LEA    SI,INBUF    ; Point to input buffer
  322.     LEA    DI,OUTBUF    ; Point to output buffer
  323.     MOV    [DI],BYTE PTR ':' ; Stuff that colon
  324.     INC    DI        ; And point to next
  325.     INC    BX        ; And increment counter
  326.     MOV    AL,20H        ; All are 32 byte records
  327.     CALL    BITE        ; Stuff it
  328.     MOV    AX,[ADDRESS]    ; Get load address
  329.     XCHG    AL,AH        ; Do high byte first
  330.     CALL    BITE        ; Send it
  331.     XCHG    AH,AL        ; Now do low byte
  332.     CALL    BITE        ; Send it
  333.     MOV    AX,[ADDRESS]    ; Get load address
  334.     ADD    AX,20H        ; Increment to next
  335.     MOV    [ADDRESS],AX    ; Put back
  336.     MOV    AL,00H        ; Record type 00
  337.     CALL    BITE        ; Send it
  338. LOOP4:    LODSB            ; Get input
  339.     CALL    BITE        ; Process
  340.     LOOP    LOOP4        ; Until done
  341.     MOV    AL,DL        ; Get checksum
  342.     CALL    BITE        ; Process, [clobbering dl]
  343.     MOV    [DI], WORD PTR 0A0DH ; Append crlf
  344.     ADD    BX,02H        ; Bump output counter appropiately
  345.     MOV    CX,BX        ; Get count into cx
  346.     CALL    WRITE        ; Write output
  347.     JMP    READ        ; Read more
  348.                 ;
  349. WRITE:    LEA    DX,OUTBUF    ; Point to beginning of output buffer
  350.     MOV    BX,[OUTHDL]    ; Get output handle
  351.     MOV    AH,40H        ; Write function
  352.     CALL    DSKWRT        ; Write data
  353.     JNC    WOK        ; Ok
  354. BADWR:    CALL    ILPRT        ; Print this...
  355.     DB    CR,LF,'Error Writing Output file',00H
  356.     JMP    FINIS        ; Go to error handler
  357. WOK:    RET            ; Near
  358.                 ;
  359. EAR:    PUSH    AX        ; Save everything
  360.     MOV    AL,[USEEXT]    ; Get extended address flag
  361.     OR    AL,[USELIN]    ; Or in extended linear flag
  362.     JNZ    GOAHEAD        ; If either set, go do it!
  363.                 ;
  364.     MOV    AX,[EXTEND]    ; Get extended address anyway
  365.     ADD    AX,1000H    ; Increment to next 64k block
  366.     MOV    [EXTEND],AX    ; Put back for consistancy
  367.     POP    AX        ; Restore ax
  368.     RET            ; Go home
  369.                 ;
  370. GOAHEAD:PUSH    DI        ;
  371.     PUSH    CX        ;
  372.     PUSH    DX        ;
  373.     PUSH    SI        ;
  374.     PUSH    BX        ;
  375.     LEA    DI,OUTBUF    ; Point to output buffer
  376.     MOV    [DI],BYTE PTR ':' ; Stuff that colon
  377.     INC    DI        ; And point to next
  378.     INC    BX        ; And increment counter
  379.     MOV    AL,02H        ; Two bytes of data in extended record
  380.     CALL    BITE        ; Stuff it
  381.     MOV    AX,0000H    ; Extended address records have load addr of 0
  382.     XCHG    AL,AH        ; Do high byte first
  383.     CALL    BITE        ; Send it
  384.     XCHG    AH,AL        ; Now do low byte
  385.     CALL    BITE        ; Send it
  386.     CMP    BYTE PTR [USELIN],0FFH ; Extended linear addressing?
  387.     JNZ    DOEXTS        ; Yes
  388.     MOV    AL,04H        ; Record type 04 extended linear addressing
  389.     JMP    SHORT BOTH    ; Continue
  390.                 ;
  391. DOEXTS:    MOV    AL,02H        ; Record type 02 extended addressing
  392. BOTH:    CALL    BITE        ; Send it
  393.     MOV    AX,[EXTEND]    ; Get current extended address
  394.     XCHG    AL,AH        ; Do high byte first
  395.     CALL    BITE        ; Send it
  396.     XCHG    AH,AL        ; Now do low byte
  397.     CALL    BITE        ; Send it
  398.     CMP    BYTE PTR [USELIN],0FFH ; Extended linear addressing
  399.     JNZ    DOEXTSS        ; Yes
  400.     ADD    WORD PTR [EXTEND],0001H    ; Bump to next block
  401.     JMP    SHORT BOTH1    ; Continue
  402.                 ;
  403. DOEXTSS:ADD    WORD PTR [EXTEND],1000H    ; Bump to next segment
  404. BOTH1:    MOV    AL,DL        ; Get checksum
  405.     CALL    BITE        ; Process, [clobbering dl]
  406.     MOV    [DI], WORD PTR 0A0DH ; Append crlf
  407.     ADD    BX,02H        ; Bump output counter appropiately
  408.     MOV    CX,BX        ; Get count into cx
  409.     CALL    WRITE        ; Write output
  410.     POP    BX        ; Recover everything
  411.     POP    SI        ;
  412.     POP    DX        ;
  413.     POP    CX        ;
  414.     POP    DI        ;
  415.     POP    AX        ;
  416.     RET            ; Go home
  417.                 ;
  418. CHKOVR:    PUSH    AX        ; Save ax
  419.     MOV    AL,[OVERRIDE]    ; Check to see if extended override selected
  420.     OR    AL,AL        ; Force flags
  421.     JNZ    OVR        ; Overridden by user
  422.     MOV    AL,0FFH        ; Otherwise flag extended addressing
  423.     MOV    [USEEXT],AL    ; Flagged
  424. OVR:    POP    AX        ; Restore ax
  425.     RET            ; Go home
  426.                 ;
  427. FINISHUP:            ;
  428.     CALL    ILPRT        ; Print this...
  429.     DB    CR,LF,'Function Complete.',CR,LF,00H
  430.     MOV    AL,[OUTTYPE]    ; Get output format
  431.     OR    AL,AL        ; Force flags
  432.     JZ    HEXEND        ; Do hex
  433.                 ; Drop through to bnpf
  434.                 ;
  435. BNPFEND:LEA    DX,CNTRLC    ; Point to eof marker
  436.     MOV    CX,0003H    ; Three bytes
  437.     CALL    DSKWRT        ; Write it
  438.     JNC    WOKK        ; Ok
  439.     JMP    BADWR        ; Error
  440.                 ;
  441. WARN:    CALL    ILPRT        ; Print this...
  442.     DB    CR,LF,LF,'WARNING:  Input data file too large for output size'
  443.     DB    ' selected.',07H,LF,00H    ;
  444.     JMP    FINISHUP    ; Terminate
  445.                 ;
  446. CNTRLC:                ;
  447.     DB    03H,CR,LF    ; Termination for bnpf
  448.                 ;
  449. HEXEND:    LEA    DX,EOFREC    ; Point to eof record
  450.     MOV    CX,000DH    ; Thirteen bytes
  451.     CALL    DSKWRT        ; Write it
  452.     JNC    WOKK        ; Ok
  453.     JMP    BADWR        ; Error
  454.                 ;
  455. ENDOF:                ;
  456.     DB    1AH        ; End of file mark
  457.                 ;
  458. WOKK:    MOV    AL,[DOEOF]    ; Do we want a ctrl-z?
  459.     OR    AL,AL        ; Force flags
  460.     JZ    NOEOF        ; No eof
  461.     LEA    DX,ENDOF    ; Point to eof
  462.     MOV    CX,0001H    ; One byte
  463.     CALL    DSKWRT        ; Write it
  464.                 ;
  465. NOEOF:    CALL    FLUSH        ; Force disk write
  466.     MOV    AH,3EH        ; Close the file now
  467.     MOV    BX,[OUTHDL]    ; Close output
  468.     INT    21H        ; Close the damn thing
  469.     JNC    CLOK        ; Closed ok
  470.     CALL    ILPRT        ; Print this...
  471.     DB    CR,LF,'Error Closing Output file!',00H
  472.                 ;
  473. CLOK:    MOV    AH,3EH        ; Close the file now
  474.     MOV    BX,[INHDL]    ; Close input
  475.     INT    21H        ; Close the damn thing
  476.     JNC    FINISH        ; Closed ok
  477.     CALL    ILPRT        ; Print this...
  478.     DB    CR,LF,'Error Closing Input file!',00H
  479.                 ;
  480. FINISH:    MOV    AX,4C00H    ; No-error termination
  481.     INT    21H        ; Bye-bye
  482.                 ;
  483. FINIS:    MOV    AX,4CFFH    ; Error termination
  484.     INT    21H        ; Bye-bye
  485.                 ;
  486. EOFREC:                ;
  487.     DB    ':00000001FF',CR,LF ; End of file record
  488.                 ;
  489. ;************************************************************************
  490. ;*                                    *
  491. ;*    ILPRT:    This is an 8088 in-line print routine.    It will print    *
  492. ;*    the string following the CALL NEAR instruction until a 00H is    *
  493. ;*    encountered.  Accepts:    Data string to print in memory following*
  494. ;*    the CALL NEAR used to invoke this routine.  Returns:  Nothing.    *
  495. ;*    Calls:    CONOUT.  Clobbers:  ES,SI                *
  496. ;*                                    *
  497. ;************************************************************************
  498.                 ;
  499. ILPRT:    PUSH    CS        ; Get code segment
  500.     POP    ES        ; Into es
  501.     POP    SI        ; Get offset
  502.     PUSH    AX        ; Save ax
  503.     PUSH    DX        ; And dx
  504. ILLP:    LODSB            ; Get char
  505.     OR    AL,AL        ; Force flags
  506.     JZ    ILEXIT        ; Exit if last
  507.     CALL    CONOUT        ; Send char
  508.     JMP    SHORT ILLP    ; Loop til done
  509. ILEXIT:    POP    DX        ; Restore dx
  510.     POP    AX        ; And ax
  511.     PUSH    SI        ; And return offset
  512.     RET            ; Near
  513.                 ;
  514. CONOUT:    MOV    AH,02H        ; Conout call
  515.     MOV    DL,AL        ; Get char
  516.     INT    21H        ; Do it
  517.     RET            ; Near
  518.                 ;
  519. BITE:    SUB    DL,AL        ; Generate checksum
  520.     PUSH    AX        ; Save
  521.     AND    AL,0F0H        ; Mask out lower nybble
  522.     ROR    AL,1        ; Get msn into lower nybble
  523.     ROR    AL,1        ; (8088 compatibility sucks...)
  524.     ROR    AL,1        ;
  525.     ROR    AL,1        ; Now it's there
  526.     CALL    NYB        ; Process nybble
  527.     MOV    [DI],AL        ; Save in disk buffer
  528.     INC    BX        ; Increment count
  529.     INC    DI        ; Next location in buffer
  530.     POP    AX        ; Recover byte
  531.     AND    AL,0FH        ; Mask lsn
  532.     CALL    NYB        ; Process nybble
  533.     MOV    [DI],AL        ; Save in disk buffer
  534.     INC    BX        ; Increment count
  535.     INC    DI        ; Next location in buffer
  536.     RET            ; Near
  537.                 ;
  538.                 ; Converts lower nybble in al to ascii hex
  539. NYB:    CMP    AL,0AH        ; Letter?
  540.     JNC    NYB1        ; Yes
  541.     ADD    AL,30H        ; Add in numeric bias
  542.     RET            ; Go home (near)
  543. NYB1:    ADD    AL,37H        ; Add in letter bias
  544.     RET            ; Go home (near)
  545.                 ;
  546. ;************************************************************************
  547. ;*                                    *
  548. ;*    DSKWRT:  This routine implements a double buffer disk write.    *
  549. ;*    It accepts the write request and blocks larger writes to    *
  550. ;*    the disk for increased performance.  Accepts: Pointer to ouput    *
  551. ;*    data in DX, byte count in CX.  Returns:  Status in carry flag,    *
  552. ;*    carry set if error.  Clobbers:    CX,AX,SI,DI.  Calls:  INT 21    *
  553. ;*                                    *
  554. ;************************************************************************
  555.                 ;
  556. DSKWRT:    MOV    SI,DX        ; Get data pointer in si
  557.     LEA    DI,REALOUT    ; Point to output buffer
  558.     ADD    DI,WORD    PTR [OUTPTR] ; Point to 1st free location
  559.     PUSH    CX        ; Save byte count
  560.     REP    MOVSB        ; Move the data
  561.     POP    CX        ; Get the byte count back
  562.     ADD    [OUTPTR],CX    ; Bump up counter/pointer
  563.     MOV    AX,[OUTPTR]    ; Get it
  564.     CMP    AX,16384D    ; Have we used at least 16k?
  565.     JGE    FLUSH        ; Yes we have, flush output buffer to disk
  566.     CLC            ; Everyone's ok
  567.     RET            ; Not yet
  568.                 ;
  569. FLUSH:    LEA    DX,REALOUT    ; Point to beginning of output buffer
  570.     MOV    BX,[OUTHDL]    ; Get output handle
  571.     MOV    AH,40H        ; Write function
  572.     MOV    CX,[OUTPTR]    ; Get output count
  573.     OR    CX,CX        ; Anything there?
  574.     JZ    NOFLUSH        ; Nope, don't bother
  575.     INT    21H        ; Do it
  576.     PUSHF            ; Save status
  577.     XOR    AX,AX        ; A zero
  578.     MOV    [OUTPTR],AX    ; Re-init output pointer/counter
  579.     POPF            ; Recover status
  580. NOFLUSH:RET            ; Go home
  581.                 ;
  582. ;************************************************************************
  583. ;*                                    *
  584. ;*    DSKRD:    This routine implements a double buffer disk read.    *
  585. ;*    It accepts the 32 byte read request and deblocks larger     *
  586. ;*    reads from the disk for increased performance.    Accepts:    *
  587. ;*    Place to stuff this stuff in DX.  Returns:  Status in        *
  588. ;*    carry flag, carry set if error, Number of bytes returned in AX. *
  589. ;*    This number will only be smaller than 32 at the end of the    *
  590. ;*    input file. Clobbers:  CX,AX,SI,DI.  Calls:  INT 21        *
  591. ;*                                    *
  592. ;************************************************************************
  593.                 ;
  594. DSKRD:    MOV    DI,DX        ; Get destination
  595.     LEA    SI,REALIN    ; Point to input buffer
  596.     ADD    SI,WORD    PTR [INPTR] ; Add in pointer
  597.     MOV    CX,[INCNT]    ; Get number of bytes left
  598.     OR    CX,CX        ; Force flags
  599.     JZ    RD        ; Outta data here, go get more from disk
  600.     CMP    CX,32D        ; How many?
  601.     JL    LAST        ; Last time through
  602.     MOV    CX,32D        ; Xfer 32 bytes
  603.     REP    MOVSB        ; Move bytes into program's input buffer
  604.     MOV    AX,32D        ; We moved 32 bytes
  605.     ADD    [INPTR],AX    ; Bump up input pointer
  606.     SUB    [INCNT],AX    ; Bump down input count
  607.     CLC            ; Clear carry
  608.     RET            ; Go home
  609.                 ;
  610. LAST:    REP    MOVSB        ; Move bytes into program's input buffer
  611.     MOV    AX,[INCNT]    ; Last number of bytes moved
  612.     XOR    CX,CX        ; A zero
  613.     MOV    [INCNT],CX    ; No more avail
  614.     MOV    [INPTR],CX    ; Zero pointer
  615.     CLC            ; Clear carry
  616.     RET            ; Go home
  617.                 ;
  618. RD:    PUSH    DX        ; Save program's input pointer
  619.     LEA    DX,REALIN    ; Point to buffer
  620.     MOV    CX,4096D    ; Read another 4k bytes
  621.     MOV    BX,[INHDL]    ; Get handle
  622.     MOV    AH,3FH        ; Read function
  623.     INT    21H        ; Do it
  624.     POP    DX        ; Recover program's input pointer
  625.     JNC    RD1        ; If error, return immediately
  626.     RET            ; Go away
  627.                 ;
  628. RD1:    XOR    CX,CX        ; Get a zero
  629.     MOV    [INPTR],CX    ; Zero input pointer
  630.     MOV    [INCNT],AX    ; Init number of bytes avail
  631.     OR    AX,AX        ; Force flags
  632.     JNZ    DSKRD        ; Recursively re-enter routine if any data
  633.     RET            ; No data, program will handle...
  634.                 ;
  635. INHDL:                ;
  636.     BLKB    2        ; Storage for input file handle
  637. OUTHDL:                ;
  638.     BLKB    2        ; Storage for output file handle
  639. ADDRESS:            ;
  640.     DW    0000H        ; Current address
  641. EXTEND:                ;
  642.     DW    0000H        ; Current extended address
  643. OUTPTR:                ;
  644.     DW    0000H        ; Output pointer
  645. INPTR:                ;
  646.     DW    0000H        ; Input buffer pointer
  647. INCNT:                ;
  648.     DW    0000H        ; Bytes left in buffer
  649. INFN:    EQU    $        ; 64 bytes input filename storage
  650. OUTFN:    EQU    INFN+64D    ; Plenty of room for a filename & path
  651. INBUF:    EQU    OUTFN+64D    ; Thirty two byte input buffer
  652. OUTBUF:    EQU    INBUF+32D    ; 128 byte output buffer
  653. REALIN:    EQU    OUTBUF+128D    ; 4k 'real' input buffer
  654. REALOUT:EQU    REALIN+4096D    ; All these buffers overlay the help file
  655.                 ;
  656. HELP:                ; Called only if nothing is going to happen
  657.                 ; Otherwise, this routine is overwritten
  658.     MOV    AX,[BNPFTYP]    ; Check for change to bnpf
  659.     CMP    AX,'NP'        ; Un-changed?
  660.     JZ    YES        ; Yes
  661.     MOV    [BNPFPATCH],AX    ; No, patch instructions
  662.     MOV    [BNPFPTCH],AX    ; Again
  663. YES:    LEA    SI,FTYPE    ; Point to hex filename
  664.     LEA    DI,F        ; Point to hex filename in instructions
  665.     MOV    CX,0002H    ; 2 words = 4 bytes
  666.     REP    MOVSW        ; Move them
  667.                 ;
  668.     LEA    SI,FTYPE1    ; Point to bnpf filename
  669.     LEA    DI,F1        ; Point to bnpf filename in instructions
  670.     MOV    CX,0002H    ; 2 words = 4 bytes
  671.     REP    MOVSW        ; Move them
  672.     JMP    SHORT NEXT    ; Self-modifying code, flush queu
  673. NEXT:    CALL    ILPRT        ; Print help screen
  674.     DB    ', Binary --> Intel hex or Binary --> BNPF conversion.'
  675.     DB    CR,LF,'Usage:  UNLOAD86 FILENAME.TYP [/OPTIONS]                 '
  676.     DB    CR,LF,'Where Options are:'
  677.     DB    CR,LF,'     B for B'
  678. BNPFPTCH:            ;
  679.     DB    'NPF instead of INTeL hex.'
  680.     DB    CR,LF,'     E to use extended addressing on files <=64K'
  681.     DB    CR,LF,'     L to use extended linear addressing'
  682.     DB    CR,LF,'     O to override forced extended addressing.'
  683.     DB    CR,LF,'     Z to place a Control-Z at end of file.'
  684.     DB    CR,LF,'     P to fill output file to end of EPROM.'
  685.     DB    CR,LF,'       Uses the following subcommands:'
  686.     DB    CR,LF,'         0  32 Bytes         1  64 Bytes'
  687.     DB    CR,LF,'         2  128 Bytes        3  256 Bytes'
  688.     DB    CR,LF,'         4  512 Bytes        5  1K Bytes'
  689.     DB    CR,LF,'         6  2K Bytes         7  4K Bytes'
  690.     DB    CR,LF,'         8  8K Bytes         9  16K Bytes'
  691.     DB    CR,LF,'         A  32K Bytes        B  64K Bytes'
  692.     DB    CR,LF,'         C  *128K Bytes      D  *256K Bytes'
  693.     DB    CR,LF,'         E  *512K Bytes      F  *1Meg Bytes'
  694.     DB    CR,LF,LF,'         * Forces extended addressing'
  695.     DB    CR,LF,'INTeL hex output files are '
  696. F:                ; Self patch instructions
  697.     DB    '.HEX'        ;
  698.     DB    CR,LF,'B'    ;
  699. BNPFPATCH:            ;
  700.     DB    'NP'        ;
  701.     DB    'F output files are '
  702. F1:                ; Self patch instructions
  703.     DB    '.BNP'        ;
  704.     DB    CR,LF,'Note:  - or [ may be used instead of / for switches.'
  705.     DB    CR,LF,00H    ;
  706.     JMP    FINIS        ; Terminate
  707.                 ;
  708. ATABLE:                ; Table of rom sizes for fillrom option
  709.     DW    0000H        ; Segment for 32 byter
  710.     DW    001FH        ; Address for 32 byter
  711.     DW    0000H        ; Segment for 64 byter
  712.     DW    003FH        ; Address for 64 byter
  713.     DW    0000H        ; Segment for 128 byter
  714.     DW    007FH        ; Address for 128 byter
  715.     DW    0000H        ; Segment for 256 byter
  716.     DW    00FFH        ; Address for 256 byter
  717.     DW    0000H        ; Segment for 512 byter
  718.     DW    01FFH        ; Address for 512 byter
  719.     DW    0000H        ; Segment for 1k byter
  720.     DW    03FFH        ; Address for 1k byter
  721.     DW    0000H        ; Segment for 2k byter
  722.     DW    07FFH        ; Address for 2k byter
  723.     DW    0000H        ; Segment for 4k byter
  724.     DW    0FFFH        ; Address for 4k byter
  725.     DW    0000H        ; Segment for 8k byter
  726.     DW    1FFFH        ; Address for 8k byter
  727.     DW    0000H        ; Segment for 16k byter
  728.     DW    3FFFH        ; Address for 16k byter
  729.     DW    0000H        ; Segment for 32k byter
  730.     DW    7FFFH        ; Address for 32k byter
  731.     DW    0000H        ; Segment for 64k byter
  732.     DW    0FFFFH        ; Address for 64k byter
  733.     DW    1000H        ; Segment for 128k byter
  734.     DW    0FFFFH        ; Address for 128k byter
  735.     DW    3000H        ; Segment for 256k byter
  736.     DW    0FFFFH        ; Address for 256k byter
  737.     DW    7000H        ; Segment for 512k byter
  738.     DW    0FFFFH        ; Address for 512k byter
  739.     DW    0F000H        ; Segment for 1m byter
  740.     DW    0FFFFH        ; Address for 1m byter
  741.                 ;
  742.     END            ;
  743.