home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / filutl / unload22.lbr / UNLOAD22.AZM / UNLOAD22.ASM
Assembly Source File  |  1987-09-10  |  8KB  |  229 lines

  1. ;************************************************************************
  2. ;*                                    *
  3. ;*    UNLOAD22:  This is an enhancement of the old unload 2.1     *
  4. ;*    It has the ability to output 8 byte,16 byte, 32 byte, or    *
  5. ;*    64 byte Intel hex records.  It also no-longer requires the    *
  6. ;*    input file to be .COM, it can be anything.  Also fixed the    *
  7. ;*    EOF record output, the previous style of EOF record has been    *
  8. ;*    known to cause some equipment/software to "choke".        *
  9. ;*                                    *
  10. ;*        --->Needs MAC and SEQIO.LIB to assemble<---        *
  11. ;*                                    *
  12. ;************************************************************************
  13. ;*                                    *
  14. ;*    Revision history:                        *
  15. ;*                                    *
  16. ;*09/05/87  Major revision.  Added run-time switch for record size,    *
  17. ;*      allowed file types other than .COM to be used, and added    *
  18. ;*      code to output a true EOF record instead of the "fake"    *
  19. ;*      MAC style previously output by the program.  Also added    *
  20. ;*      COMMENTS, the program was poorly commented.            *
  21. ;*      By Mark D. Pickerill.                     *
  22. ;*                                    *
  23. ;*05/20/81 Modified for 32 bytes/record instead of 16, for less     *
  24. ;*      overhead in the .HEX output file, by Dav Holle.        *
  25. ;*                                    *
  26. ;*11/07/80 Modified to default to 100H, increase size of buffers,    *
  27. ;*      add signon message.  By Keith Petersen, W8SDZ         *
  28. ;*                                    *
  29. ;*Originally from CPMUG 29.23                        *
  30. ;*                                    *
  31. ;*To use, type: UNLOAD <FILENAME><.EXT> <ADDR></X>            *
  32. ;*                                    *
  33. ;*Where: <FILENAME> is the source file, <.EXT> if not given defaults    *
  34. ;*    to .COM                             *
  35. ;*    <FILENAME>.HEX will be the output file                *
  36. ;*    <ADDR> is the optional start address in hex (default=100)    *
  37. ;*    </X> is the optional record size, where /X is:            *
  38. ;*                                    *
  39. ;*    /S  Small, 08 bytes per record                    *
  40. ;*    /M  Medium, 16 bytes per record  (default)            *
  41. ;*    /L  Large, 32 bytes per record                    *
  42. ;*    /E  Extra, 64 bytes per record                    *
  43. ;*        Note that this format is known to make PIP's [H] "choke"    *
  44. ;*                                    *
  45. ;************************************************************************
  46.                 ;
  47. FCB2    EQU    006CH        ; Location of second fcb
  48. FCB1EXT:EQU    0065H        ; Location of ext field of first fcb
  49.     ORG    100H        ; Start of tpa
  50.     MACLIB    SEQIO        ; Define macro library used
  51.     LHLD    6        ; Get base of bdos
  52.     DCX    H        ; Back off one byte
  53.     SPHL            ; Set stack there
  54.     CALL    SIGNON        ; Jump around message w/msg addr on stack
  55.     DB    CR,LF,'UNLOAD ver 2.2',CR,LF,'$'
  56.     DB    '09/05/87'    ; Revision date (doesn't print)
  57. SIGNON:    POP    D        ; Get msg adr
  58.     MVI    C,@MSG        ; Print it
  59.     CALL    @BDOS        ; Do it
  60.     MVI    A,16        ; Default record size
  61.     STA    SIZE        ; Store it
  62.     LDA    FCB1EXT        ; Point to file ext field of fcb1
  63.     CPI    ' '        ; Ext specified?
  64.     CZ    PUTCOM        ; No ext, force default to .com
  65.     LXI    H,0100H        ; Default unload adrs
  66.     LXI    D,FCB2+1    ; Look at first location of second fcb
  67.     LDAX    D        ; Get option adrs
  68.     CPI    '/'        ; Check first for no address, opt. rec size
  69.     CZ    SETSIZE        ; Yes, change size
  70.     CPI    ' '        ; Any given?
  71.     JZ    INITFL        ; No, default to 0100h
  72.     LXI    H,0        ; Zero 16 bit accumulator
  73.     MVI    B,0        ; Zero b (unused)
  74.                 ;
  75. ADRLUP:    LDAX    D        ; Get char
  76.     CPI    '/'        ; Change size switch?
  77.     CZ    SETSIZE        ; Yes
  78.     INX    D        ; Point to next
  79.     SUI    '0'        ; Remove numeric bias
  80.     JC    INITFL        ;
  81.     CPI    10        ; Punctuation?
  82.     JC    ADDNIB        ; No
  83.     SUI    7        ; Yes, remove punctuation bias
  84.     JC    INITFL        ; Not valid hex, actually was punctuation
  85.     CPI    16        ; Higher than f?
  86.     JNC    INITFL        ; Yes, invalid
  87.                 ;
  88. ADDNIB:    DAD    H        ; Multiply 16 bit accumulator by 2
  89.     DAD    H        ; 4
  90.     DAD    H        ; 8
  91.     DAD    H        ; 16
  92.     MOV    C,A        ; Move current value
  93.     DAD    B        ; Add in current value to 16 bit acc
  94.     JMP    ADRLUP        ; And do until garbage is found
  95.                 ;
  96. SETSIZE:INX    D        ; Point to next
  97.     LDAX    D        ; Get it
  98.     CPI    'S'        ; Small (08)?
  99.     MVI    B,08D        ; In-case it is...
  100.     JZ    SETIT        ; Yes
  101.     CPI    'M'        ; Medium (16)?
  102.     MVI    B,16D        ; In-case it is...
  103.     JZ    SETIT        ; Yes
  104.     CPI    'L'        ; Large (32)?
  105.     MVI    B,32D        ; In-case it is...
  106.     JZ    SETIT        ; Yes
  107.     CPI    'E'        ; Extra (64)?
  108.     MVI    B,64D        ; In-case it is...
  109.     JZ    SETIT        ; Yes
  110.     MVI    B,16D        ; Garbage, retain default
  111. SETIT:    MOV    A,B        ; Get desired setting
  112.     STA    SIZE        ; Set mem location
  113.     MVI    A,' '        ; To force termination of option search routine
  114.     RET            ; Go home
  115.                 ;
  116. PUTCOM:    MVI    B,3        ; Three bytes in .com
  117.     LXI    H,FCB1EXT    ; Point to fcb1 ext field
  118.     LXI    D,COM        ; Point to the word 'com'
  119. PUTLP:    LDAX    D        ; Get byte
  120.     MOV    M,A        ; Put byte
  121.     DCR    B        ; Count down
  122.     INX    H        ; Increment destination
  123.     INX    D        ; Increment source
  124.     JNZ    PUTLP        ; Loop til done
  125.     RET            ; Go home
  126.                 ;
  127. COM:    DB    'COM'        ; Com files are default
  128.                 ;
  129. INITFL:    PUSH    H        ; Save load address
  130. ;    FILE    INFILE,SOURCE,,1,COM,2048 ; Invoke macro
  131.     FILE    INFILE,SOURCE,,1,,2048 ; Invoke macro
  132.     FILE    OUTFILE,OUTPUT,,1,HEX,2048 ; Invoke macro
  133.     POP    H        ; Restore load address
  134.                 ;
  135. ADRDON:    SHLD    LODADR        ; Save unload address
  136. UNLOOP:    GET    SOURCE        ; Get byte of source
  137.     JZ    GEOF        ; Done, generate eof record
  138.     PUSH    PSW        ; Save it
  139.     MVI    A,':'        ; Get a colon
  140.     PUT    OUTPUT        ; Write it to the output
  141.     XRA    A        ; Zero acc
  142.     STA    CHEKS        ; And store in checksum byte
  143.     LDA    SIZE        ; Get record size
  144.     CALL    PUTBYTE        ; Output the record lenth
  145.     LDA    LODADR+1    ; Get msb of load address
  146.     CALL    PUTBYTE        ; Output it
  147.     LDA    LODADR        ; Now the lsb
  148.     CALL    PUTBYTE        ; Output it
  149.     XRA    A        ; Record type 00
  150.     CALL    PUTBYTE        ; Dump it
  151.     LDA    SIZE        ; Get record size
  152.     MOV    B,A        ; And put in b
  153.     POP    PSW        ; Recover current byte
  154. LINLUP:    PUSH    B        ; Save line count
  155.     CALL    PUTBYTE        ; Output current byte
  156.     POP    B        ; Recover line count
  157.     DCR    B        ; Decrement it
  158.     JZ    NEXTL        ; If done, process end of line
  159.     GET    SOURCE        ; If not, get next byte
  160.     JMP    LINLUP        ; And loop until a whole line is done
  161.                 ;
  162. NEXTL:    LDA    CHEKS        ; Get checksum
  163.     CALL    PUTBYTE        ; Output it
  164.     MVI    A,CR        ; A carriage return
  165.     PUT    OUTPUT        ; Dump it
  166.     MVI    A,LF        ; A line feed
  167.     PUT    OUTPUT        ; Dump it
  168.     LHLD    LODADR        ; Get load address
  169.     LDA    SIZE        ; Get record size
  170.     MOV    E,A        ; Into e
  171.     MVI    D,00        ; Zero msb of de
  172.     DAD    D        ; Add in line length for next record
  173.     JMP    ADRDON        ; Do til done with file
  174.                 ;
  175. PUTBYTE:MOV    C,A        ; Save byte in c
  176.     LDA    CHEKS        ; Get current checksum
  177.     SUB    C        ; Subtract current byte (auto 2's comp.)
  178.     STA    CHEKS        ; Put back
  179.     MOV    A,C        ; Restore current byte
  180.     RRC            ; Get msn
  181.     RRC            ; Takes
  182.     RRC            ; Four
  183.     RRC            ; Rotates
  184.     CALL    PUTNIB        ; Stuff nybble
  185.     MOV    A,C        ; Get lsn back, and drop into putnib
  186.                 ;
  187. PUTNIB:    ANI    0FH        ; Strip upper nybble
  188.     ADI    '0'        ; Add numeric bias
  189.     CPI    '9'+1        ; 9 or less?
  190.     JC    PUTNB1        ; Yes
  191.     ADI    7        ; No, add in alpha bias
  192. PUTNB1:    PUSH    B        ; Save b
  193.     PUT    OUTPUT        ; Write the ascii byte
  194.     POP    B        ; Restore b
  195.     RET            ; Go home
  196.                 ;
  197. GEOF:    MVI    A,':'        ; A colon
  198.     PUT    OUTPUT        ; Output it
  199.     MVI    B,3        ; 5 bytes
  200. GEOF1:    XRA    A        ; Generate a zero
  201.     PUSH    B        ; Save count
  202.     CALL    PUTBYTE        ; Output the zero
  203.     POP    B        ; Recover count
  204.     DCR    B        ; Decrement
  205.     JNZ    GEOF1        ; Do till done
  206.     MVI    A,01H        ; Record type 01, eof
  207.     CALL    PUTBYTE        ; Output it
  208.     MVI    A,0FFH        ; Checksum for eof record
  209.     CALL    PUTBYTE        ; Output it
  210.     MVI    A,CR        ; Output the cr
  211.     PUT    OUTPUT        ; Do it
  212.     MVI    A,LF        ; Output the lf
  213.     PUT    OUTPUT        ; Do that too
  214.     FINIS    OUTPUT        ; Close output file
  215.     LXI    D,DMSG        ; Tell world we're done
  216.     MVI    C,@MSG        ; Function #
  217.     CALL    @BDOS        ; Do it
  218.     JMP    0        ; Good bye
  219.                 ;
  220. DMSG:    DB    'Done',CR,LF,'$' ; Message
  221.                 ;
  222. SIZE:    DS    1        ; Record size storage
  223. LODADR:    DS    2        ; Load address storage
  224. CHEKS:    DS    1        ; Checksum storage
  225. BUFFERS    EQU    $        ; Input/output buffers go here
  226.                 ;
  227.     END            ;
  228.  
  229.