home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol007 / reldump.asm < prev    next >
Encoding:
Assembly Source File  |  1984-04-29  |  7.4 KB  |  424 lines

  1. ;
  2. ;    Program to dump Microsoft format
  3. ;    rel files field by field
  4. ;    with field comments
  5. ;
  6. ;    See Microsoft 'linking loader' manual
  7. ;    for more information on .rel files
  8. ;
  9. ;
  10. ;    Requires Digital Research 'MAC'
  11. ;    assembler, or alternatively, you
  12. ;    can expand the macros and use
  13. ;    the cp/m assembler 'asm'.
  14. ;
  15. ;
  16. ;    8/22/80     by Ron Fowler
  17. ;               Westland, Mich.
  18. ;
  19. cr    equ    13
  20. lf    equ    10
  21. bdos    equ    5
  22. fcb    equ    5ch
  23. buf    equ    80h
  24. ;
  25. cifnc    equ    1
  26. prtchr    equ    2
  27. printf    equ    9
  28. cstsf    equ    11
  29. openf    equ    15
  30. readf    equ    20
  31. ;
  32. maxperline equ    16 ;abs items per line
  33. ;
  34. ;    define some macros
  35. ;
  36. pchar    macro    x
  37.     if not nul x
  38.     mvi    a,x
  39.     endif
  40.     call    outchr
  41.     endm
  42. ;
  43. print    macro    string
  44.     local    overstring
  45.     call    overstring
  46.     db    string
  47. overstring:
  48.     pop    d
  49.     mvi    c,printf
  50.     call    bdos
  51.     endm
  52. ;
  53. bits    macro    num
  54.     mvi    b,num
  55.     call    getbits
  56.     endm
  57.     page
  58. ;
  59. ;    get local stack and
  60. ;    set up fcb
  61. ;
  62.     ORG    100H
  63. ;
  64. base:    lxi    h,0
  65.     dad    sp
  66.     shld    stack
  67.     lxi    sp,stack
  68.     lda    fcb+9    ;look at filetype
  69.     cpi    ' '    ;see if type specified
  70.     jnz    sk1    ;jmp if so
  71.     lxi    h,'RE'    ;part of 'REl'
  72.     shld    fcb+9    ;store into fcb
  73.     mvi    a,'L'    ;rest of 'reL'
  74.     sta    fcb+11
  75. sk1:    mvi    c,openf ;open the .rel file
  76.     lxi    d,fcb
  77.     call    bdos
  78.     cpi    0ffh    ;should not be
  79.     jnz    main    ;jump if not
  80.     call    msgxit    ;else say can't find
  81.     db    'File not found.$'
  82.     page
  83. ;
  84. ;    main work loop
  85. ;
  86. main:    call    item    ;identify one item
  87.     jc    done    ;cy is eof indicator
  88.     call    stop    ;console says stop?
  89.     jnc    main    ;continue if not
  90. done:    call    msgxit    ;else print 'done'
  91.     db    cr,lf,'done.$'
  92. ;
  93. stop:    mvi    c,cstsf
  94.     call    bdos
  95.     ora    a
  96.     rz
  97.     mvi    c,cifnc
  98.     call    bdos
  99.     cpi    'C'-40h ;control-c?
  100.     stc        ;says stop
  101.     rz
  102.     cmc        ;false char
  103.     ret
  104.     page
  105. ;
  106. ;    decode an item
  107. ;
  108. item:    bits    1    ;get first bit of item
  109.     ora    a    ;test for zero
  110.     jnz    not$abs  ;not zero, jmp for rel
  111.     lxi    h,relflg
  112.     mov    a,m
  113.     mvi    m,0
  114.     ora    a
  115.     jz    cont1
  116.     call    crlf
  117.     mvi    a,maxperline+1
  118.     sta    abscnt
  119. cont1:    lxi    h,abscnt ;line up abs values
  120.     mov    a,m
  121.     inr    a
  122.     mov    m,a
  123.     cpi    maxperline
  124.     jc    lnok    ;max values per line
  125.     xra    a
  126.     mov    m,a
  127.     call    crlf
  128.     print    'ABS: $'
  129. lnok:    bits    8    ;get 8 absolute bits
  130.     call    hexout    ;display 'em
  131.     pchar    ' '
  132.     ora    a    ;no eof yet
  133.     ret
  134. ;
  135. not$abs:
  136.     call    crlf
  137.     call    crlf
  138.     mvi    a,0ffh    ;idntfy rel iterm
  139.     sta    relflg
  140.     mvi    a,maxperline+1 ;make new abs line
  141.     sta    abscnt
  142.     print    'REL: type $'
  143.     bits    2    ;get rel type spec
  144.     push    psw
  145.     call    hexout
  146.     pop    psw
  147.     ora    a
  148.     jz    spl    ;0 is special type
  149.     dcr    a
  150.     jz    prgrel ;1 is program relative
  151.     dcr    a
  152.     jz    datrel ;2 is data relative
  153. ;
  154. ;    must be 3, common relative
  155. ;
  156.     print    ', com rel, val=$'
  157.     jmp    prnt16
  158. prgrel: print    ', prg rel, val=$' 
  159.     jmp    prnt16
  160. datrel: print    ', dat rel, val=$'
  161. prnt16: bits    8    ;get rel byte
  162.     push    psw    ;save lst sig byte
  163.     bits    8    ;next
  164.     call    hexout    ;print most sig
  165.     pop    psw
  166.     call    hexout    ;print least sig
  167.     pchar    ' '    ;print a space
  168.     ora    a    ;not eof yet
  169.     ret
  170.     page
  171. ;
  172. ;    handle special relative field
  173. ;
  174. spl:    print    ', (special), ctrl fld=$'
  175.     bits    4    ;spl fld has..
  176.     sta    ctrlfld ;..4 bits
  177.     push    psw
  178.     call    hexout    ;print it
  179.     print    ', $'
  180.     pop    psw
  181.     mov    l,a
  182.     mvi    h,0    ;ctl fld in hl
  183.     dad    h    ;offset for table
  184.     lxi    d,msgtable
  185.     dad    d
  186.     mov    e,m    ;get lo byte
  187.     inx    h
  188.     mov    d,m    ;de has field msg
  189.     mvi    c,printf
  190.     call    bdos    ;identify type
  191.     lda    ctrlfld ;get control byte
  192.     cpi    15    ;15 is eof
  193.     stc        ;so say so
  194.     rz
  195.     push    psw    ;new lin for a & b flds
  196.     call    crlf
  197.     print    '     $';tab over
  198.     pop    psw
  199.     cpi    4+1    ;type 0-4 has no a fld
  200.     jc    bonly
  201.     call    afield    ;show the a field
  202.     lda    ctrlfld 
  203.     cpi    14    ;end program...
  204.     jnz    not14    ;..forces byte boundary
  205.     call    refill    ;go next byte
  206.     ora    a    ;return cy clr
  207.     ret
  208. not14:    cpi    9    ;type 9-15 has no b
  209.     rnc
  210. bonly:    call    bfield
  211.     ora    a    ;say no eof
  212.     ret
  213.     page
  214. ;
  215. ;    handle special rel fields
  216. ;
  217. afield: print    'a fld type: $'
  218.     bits    2    ;get the a field
  219.     push    psw
  220.     call    hexout    ;print it
  221.     print    ', $'    ;make a comma,spc
  222.     pop    psw    ;get back a field
  223.     ora    a    ;examine it for type
  224.     jz    absad    ;0=absolute adrs
  225.     dcr    a
  226.     jz    prg2    ;1=program rel
  227.     dcr    a
  228.     jz    data2    ;2=data rel
  229. ;
  230. ;    must be common relative
  231. ;
  232.     print    '(common rel) value= $'
  233.     jmp    prnt16
  234. data2:    print    '(data   rel) value= $'
  235.     jmp    prnt16
  236. prg2:    print    '(prog   rel) value= $'
  237.     jmp    prnt16
  238. absad:    print    '(absolute) value= $'
  239.     jmp    prnt16
  240. ;
  241. bfield: bits    3    ;get b-field size
  242.     mov    e,a    ;make a counter
  243.     pchar    '"'    ;enclose in quotes
  244. bsym:    mov    a,e    ;when e is zero
  245.     ora    a    ;then we are done
  246.     jz    brout
  247.     dcr    e    ;count down
  248.     bits    8    ;get sym char
  249.     pchar        ;print it
  250.     jmp    bsym    ;loop till done
  251. brout:    pchar    '"'    ;close quotes
  252.     ret
  253.     page
  254. ;
  255. ;*************************
  256. ;*     subroutines     *
  257. ;*************************
  258. ;
  259. ;
  260. ;    get number of bits from
  261. ;    input stream as in b reg
  262. ;
  263. getbits: 
  264.     push    h
  265.     push    d
  266.     xra    a    ;zero our byte
  267. bitlop: call    nxtbit    ;next bit into cy flg
  268.     ral        ;shift into our byte
  269.     dcr    b    ;count down
  270.     jnz    bitlop
  271.     pop    d
  272.     pop    h
  273.     ret
  274. ;
  275. ;    get next bit from input stream
  276. ;
  277. nxtbit: push    b
  278.     mov    b,a    ;can't alter a
  279.     lda    bitcnt    ;any left this byte?
  280.     ora    a
  281.     cz    refill    ;get another if not
  282.     dcr    a
  283.     sta    bitcnt    ;update for nxt time
  284.     lda    char    ;current byte
  285.     ral        ;bit into cy
  286.     sta    char
  287.     mov    a,b    ;restore accumulator
  288.     pop    b
  289.     ret
  290. ;
  291. ;    get the next byte from input buffer
  292. ;
  293. refill: push    b
  294.     lda    bufptr
  295.     cpi    80h    ;see if buf empty
  296.     cz    diskrd    ;fill if so
  297.     mov    l,a
  298.     mvi    h,0    ;form 16 bits
  299.     inr    a    ;update buf pntr
  300.     sta    bufptr
  301.     lxi    d,buf
  302.     dad    d    ;point into buffer
  303.     mov    a,m    ;reach in and get byte
  304.     sta    char    ;save it
  305.     mvi    a,8    ;new bit count
  306.     sta    bitcnt
  307.     pop    b
  308.     ret
  309. ;
  310. ;    read next sector from file
  311. ;
  312. diskrd: mvi    c,readf
  313.     lxi    d,fcb
  314.     call    bdos
  315.     cpi    0ffh    ;should not be..
  316.     mvi    a,0    ;..early eof
  317.     rnz
  318.     call    msgxit    ;oops!
  319.     db    '??? Unexpected end of file.$'
  320. ;
  321. ;    print message pointed
  322. ;    to by tos then exit
  323. ;
  324. msgxit: pop    d
  325.     mvi    c,printf
  326.     call    bdos
  327.     lhld    stack
  328.     sphl
  329.     ret        ;to ccp
  330. crlf:    mvi    a,cr
  331.     call    outx
  332.     mvi    a,lf
  333.     call    outx
  334.     lda    lincnt
  335.     inr    a
  336.     sta    lincnt
  337.     cpi    61    ;lines/page
  338.     rnz
  339.     mvi    b,6    ;lines to nxt page
  340. formfd: mvi    a,lf
  341.     call    outx    ;<<<
  342.     dcr    b
  343.     jnz    formfd
  344.     mvi    a,1    ;say first line
  345.     sta    lincnt
  346.     ret
  347. hexout: push    psw
  348.     rar
  349.     rar
  350.     rar
  351.     rar
  352.     call    nybble
  353.     pop    psw
  354. nybble: ani    0fh
  355.     cpi    10
  356.     jc    xnum
  357.     adi    7
  358. xnum:    adi    '0'
  359.     pchar
  360.     ret
  361.     page
  362. ;
  363. ;    print char in a (called from
  364. ;    macros only).
  365. ;
  366. outchr: cpi    ' '    ;check for printable..
  367.     jnc    chka    ;..characters, make...
  368. fix:    mvi    a,'.'    ;...non-printing chars....
  369. chka:    cpi    7fh    ;....dots
  370.     jnc    fix
  371. outx:    push    h
  372.     push    d
  373.     push    b
  374.     mvi    c,prtchr
  375.     mov    e,a
  376.     call    bdos
  377.     pop    b
  378.     pop    d
  379.     pop    h
  380.     ret
  381. ;
  382. ;    table of control-field
  383. ;    type messages
  384. ;
  385. msgtable:
  386.     dw    m0,m1,m2,m3
  387.     dw    m4,m5,m6,m7
  388.     dw    m8,m9,m10,m11
  389.     dw    m12,m13,m14,m15
  390. ;
  391. ;    the messages:
  392. ;
  393. m0:    db    '*      entry symbol      *$'
  394. m1:    db    '*      sel com blk       *$'
  395. m2:    db    '*      program name      *$'
  396. m3:    db    '* request library search *$'
  397. m4:    db    '*   extension link item  *$'
  398. m5:    db    '*       common size      *$'
  399. m6:    db    '*      chain external    *$'
  400. m7:    db    '*    define entry point  *$'
  401. m8:    db    '*    external - offset   *$'
  402. m9:    db    '*    external + offset   *$'
  403. m10:    db    '*    define data size    *$'
  404. m11:    db    '*     set loc counter    *$'
  405. m12:    db    '*      chain address     *$'
  406. m13:    db    '*      program size      *$'
  407. m14:    db    '*       end program      *$'
  408. m15:    db    '*       end of file      *$'
  409.     page
  410. ;
  411. ;    variables
  412. ;
  413. bufptr: db    80h    ;force initial read
  414. bitcnt: db    0    ;and empty char
  415. char:    db    0
  416. ctrlfld: db    0
  417. abscnt: db    maxperline+1  ;force initial crlf
  418. lincnt: db    1    ;start paper at line 1
  419. relflg: db    0
  420.     db    0
  421.     ds    50    ;stack space
  422. stack:            ;stk prt save
  423.     end
  424.