home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / reldmp.mac < prev    next >
Encoding:
Text File  |  1994-09-02  |  13.6 KB  |  463 lines

  1. ;
  2. ;       Reldmp - Print dump of Microsoft relocatable file
  3. ;
  4. ;    Syntax : 
  5. ;        reldmp object.rel
  6. ;    Where :
  7. ;        object.rel is the MICROSOFT Relocatable format file
  8. ;        to dump.
  9. ;
  10. ;    Originally Written By T. Stockman
  11. ;
  12. ;    Extension Link Item Processing Added By D. Bloodgood
  13. ;
  14.         .z80
  15.         aseg
  16. bdos    equ     5
  17. ifcb    equ     5ch
  18. buf     equ     80h
  19. cr      equ     'M'-40h
  20. lf      equ     'J'-40h
  21.         cseg
  22. ;
  23. reldmp::        ld      sp,(6)          ;set stack
  24.         ld      a,79            ;set width
  25.         ld      (width),a
  26.         sub     a               ;clear column
  27.         ld      (column),a
  28.         ld      de,ifcb         ;open input file
  29.         ld      c,15
  30.         call    bdos
  31.         inc     a               ;error if can't open
  32.         ld      de,opnmsg
  33.         jp      z,error
  34.         sub     a               ;set to first sector
  35.         ld      (ifcb+32),a
  36.         call    filbuf          ;prime input buffer
  37.         ld      (bytep),hl
  38.         ld      (bitc),de
  39.         ld      hl,0            ;clear record counter
  40.         ld      (record),hl
  41. rdmp0:: ld      de,recmsg       ;print out file position
  42.         call    pmsg
  43.         ld      a,(record+1)
  44.         call    phb
  45.         ld      a,(record)
  46.         call    phb
  47.         ld      de,bytmsg
  48.         call    pmsg
  49.         ld      hl,bitc+1
  50.         ld      a,80h
  51.         sub     (hl)
  52.         call    phb
  53.         call    endln0
  54.         ld      hl,0            ;clear loading location
  55.         ld      (loc),hl
  56.         ld      a,''''          ;clear loading loaction mode
  57.         ld      (locm),a
  58. ;
  59. ;       rdmp - main program loop
  60. ;
  61. rdmp::  ld      b,1             ;get item type bit
  62.         call    gbits
  63.         or      a               ;jump if not absolute item
  64.         jr      nz,rdmp1
  65.         ld      a,2
  66.         call    lstnxt          ;advance listing for another item
  67.         ld      b,8             ;get and print byte
  68.         call    gbits
  69.         call    phb
  70.         ld      hl,(loc)        ;advance loading location
  71.         inc     hl
  72.         ld      (loc),hl
  73.         jr      rdmp
  74. ;
  75. rdmp1:: ld      b,2             ;get item relocation mode
  76.         call    gbits
  77.         or      a               ;jump if special link item
  78.         jr      z,rdmp2
  79.         push    af
  80.         ld      a,5
  81.         call    lstnxt          ;advance listing for another item
  82.         pop     af
  83.         call    pafld0          ;let pafld worry about printing it
  84.         ld      hl,(loc)        ;advance loading location
  85.         inc     hl
  86.         inc     hl
  87.         ld      (loc),hl
  88.         jr      rdmp
  89. ;
  90. rdmp2:: call    endln           ;end line if not at beginning of line
  91.         ld      b,4             ;get special item type
  92.         call    gbits
  93.         push    af
  94.         ld      hl,types        ;print out item type
  95.         call    addmsg
  96.         call    pmsg
  97.         pop     af
  98.         cp      4               ;B field only?
  99.         jr      c,rdmp3
  100.         cp      5               ;Special Link Item
  101.         jr      c,rdmp31
  102.         cp      8               ;both A and B fields?
  103.         jr      c,rdmp4
  104.         cp      11              ;set location?
  105.         jr      z,rdmp5
  106.         cp      14              ;check for end of program
  107.         jr      z,rdmp6
  108.         cp      15              ;end of file?
  109.         jr      z,rdmp7
  110.         call    pafld           ;print A field
  111.         call    endln0
  112.         jr      rdmp
  113. ;
  114. rdmp3:: call    pbfld           ;print B field
  115.         call    endln0
  116.         jr      rdmp
  117. ;
  118. rdmp31::        call    pextlk
  119.         call    endln0
  120.         jp      rdmp
  121. ;
  122. rdmp4:: call    pafld           ;print A field
  123.         ld      a,' '
  124.         call    putc
  125.         call    pbfld           ;print B field
  126.         call    endln0
  127.         jp      rdmp
  128. ;
  129. rdmp5:: call    pafld           ;print A field
  130.         ld      (loc),hl        ;save loading location
  131.         ld      (locm),a        ;save loading mode
  132.         call    endln0
  133.         jp      rdmp
  134. ;
  135. rdmp6:: call    pafld           ;print A field
  136.         call    endln0
  137.         call    endln0
  138.         call    endln0
  139.         ld      a,(bitc)        ;force to next byte
  140.         cp      8
  141.         jp      z,rdmp0
  142.         ld      b,a
  143.         call    gbits
  144.         jp      rdmp0
  145. ;
  146. rdmp7:: call    endln
  147.         jp      0
  148. ;
  149. ;       pafld - print out "A" type field
  150. ;
  151. ;       exit::  a  = mode character ( '"!)
  152. ;               hl = address
  153. ;       uses::  af, bc, de, hl
  154. ;       calls:: gbits, phb, putc
  155. ;
  156. pafld:: ld      b,2             ;address mode
  157. pafld8::        call    gbits
  158.         ld      b,' '           ;absolute mode?
  159.         or      a
  160.         jr      z,pafld1
  161. pafld0::        ld      b,''''          ;program (code) relative?
  162.         dec     a
  163.         jr      z,pafld1
  164.         ld      b,'"'           ;data relative?
  165.         dec     a
  166.         jr      z,pafld1
  167.         ld      b,'!'           ;then it's common relative
  168. pafld1::        push    bc              ;save mode indicator
  169.         ld      b,8             ;get low byte of address
  170.         call    gbits
  171.         push    af              ;save it
  172.         ld      b,8             ;get and print high byte of address
  173.         call    gbits
  174.         ld      h,a
  175.         call    phb
  176.         pop     af
  177.         ld      l,a
  178.         call    phb             ;print low byte of address
  179.         pop     af
  180.         jp      putc            ;print mode indicator
  181. ;
  182. ;       pbfld - print out "B" type field
  183. ;
  184. ;       uses::  af, bc, de, hl
  185. ;       calls:: gbits, putc
  186. ;
  187. pbfld:: ld      b,3             ;get symbol length
  188.         call    gbits
  189.         or      a               ;return if zero length
  190.         ret     z
  191.         ld      b,a
  192. pbfld1::        push    bc
  193.         ld      b,8             ;get a byte of symbol
  194.         call    gbits
  195.         call    putc            ;print it
  196.         pop     bc
  197.         djnz    pbfld1
  198.         ret
  199. ;
  200. ;       pextlk - prints extension link item
  201. ;
  202. pextlk::        ld      b,3             ;get length field
  203.         call    gbits
  204.         push    af              ;save length
  205.         ld      b,8             ;get type
  206.         call    gbits
  207.         sub     'A'             ;convert to 0-2
  208.         push    af              ;save type
  209.         ld      hl,extypes
  210.         call    addmsg
  211.         call    pmsg            ;print message describing type 
  212.         pop     af              ;restore type ( 0-2 )
  213.         cp      1               ;compare to 0,1 or 2
  214.         jr      c,extop         ;have an operator
  215.         jr      z,extext        ;have a label field
  216. ;
  217. ;   Must have an local symbol
  218. ;
  219.         pop     af              ;throw away length
  220.         ld      b,8             ;get 8 bits for type
  221.         jp      pafld8          ;print it as an A field
  222. ;
  223. ;   Have an Operator
  224. ;
  225. extop:: pop     af      ;discard length 
  226.         ld      b,8
  227.         call    gbits           ;get operator
  228.         ld      hl,opertab      ;operator table
  229.         call    addmsg
  230.         jp      pmsg            ;print operator
  231. ;
  232. ;   Must be a Symbol
  233. ;
  234. extext::        pop     af      ;restore count
  235.         dec     a               ;account for type byte
  236.         ld      b,a             ;into b for counter
  237. extex1::        push    bc
  238.         ld      b,8             ;get a byte of symbol
  239.         call    gbits
  240.         call    putc            ;print it
  241.         pop     bc
  242.         djnz    extex1
  243.         ret
  244. ;
  245. ;       gbits - get bits from rel file
  246. ;
  247. ;       Note::  The following code must be executed before the first
  248. ;               call to gbits (after openning the rel file) to "prime"
  249. ;               the input buffer.
  250. ;
  251. ;       call    filbuf
  252. ;       ld      (bytep),hl
  253. ;       ld      (bitc),de
  254. ;
  255. ;       entry:: b  = # of bits to get (1 - 8)
  256. ;       exit::  a  = assembled bits (right justified)
  257. ;       uses::  af, bc, de, hl
  258. ;       calls:: filbuf
  259. ;
  260. gbits:: ld      hl,(bytep)      ;get current pos'n
  261.         ld      de,(bitc)
  262.         xor     a               ;clear assembly register
  263. gbit1:: rlc     (hl)            ;move a bit into the assembly
  264.         rla
  265.         dec     e               ;skip advance if still bits in this byte
  266.         jr      nz,gbit2
  267.         ld      e,8             ;reset bit counter
  268.         inc     hl              ;advance byte pointer
  269.         dec     d               ;refill buffer if last byte
  270.         call    z,filbuf
  271. gbit2:: djnz    gbit1           ;loop if more bits needed
  272.         ld      (bytep),hl      ;save pos'n
  273.         ld      (bitc),de
  274.         ret
  275. ;
  276. ;       filbuf - fill input buffer from rel file
  277. ;
  278. ;       exit::  d  = 128 (# bytes in buffer)
  279. ;               e  = 8 (# bits in byte)
  280. ;               hl = fwa buffer
  281. ;       uses::  de, hl
  282. ;       calls:: bdos, error
  283. ;
  284. filbuf::        push    af
  285.         push    bc
  286.         ld      de,ifcb         ;read a sector
  287.         ld      c,20
  288.         call    bdos
  289.         or      a               ;trap errors
  290.         ld      de,rdmsg
  291.         jp      nz,error
  292.         pop     bc
  293.         pop     af
  294.         ld      hl,(record)     ;increment record count
  295.         inc     hl
  296.         ld      (record),hl
  297.         ld      hl,buf          ;set pointers for return
  298.         ld      de,128*256+8
  299.         ret
  300. ;
  301. ;       lstnxt - advance listing for next item
  302. ;
  303. ;       entry:: a  = # columns item will occupy
  304. ;       uses::  af, bc
  305. ;       calls:: endln, phb, putc
  306. ;
  307. lstnxt::        push    af
  308.         inc     a               ;add one column for the space
  309.         ld      bc,(column)     ;go print location if beginning of line
  310.         inc     c
  311.         dec     c
  312.         jr      z,lstn2
  313.         add     a,c             ;try adding item on this line
  314.         ld      bc,(width)      ;jump if line would be too wide
  315.         cp      c
  316.         jr      nc,lstn1
  317.         ld      (column),a      ;update column counter
  318.         pop     af
  319.         ld      a,' '           ;push out a space
  320.         jp      putc
  321. ;
  322. lstn1:: call    endln0          ;go to the next line
  323. lstn2:: pop     bc
  324.         ld      a,(loc+1)       ;print out the loading location
  325.         call    phb
  326.         ld      a,(loc)
  327.         call    phb
  328.         ld      a,(locm)
  329.         call    putc
  330.         ld      a,' '           ;space over
  331.         call    putc
  332.         call    putc
  333.         ld      a,7             ;init column counter
  334.         add     a,b             ;add in width of this item
  335.         ld      (column),a
  336.         ret
  337. ;
  338. ;       endln - end the current listing line
  339. ;
  340. ;       uses::  af
  341. ;       calls:: putc
  342. ;
  343. endln:: ld      a,(column)      ;return if already at beginning of line
  344.         or      a
  345.         ret     z
  346. endln0::        sub     a               ;clear column counter
  347.         ld      (column),a
  348.         ld      a,cr
  349.         call    putc
  350.         ld      a,lf
  351.         jp      putc
  352. ;
  353. ;       amsgadd - return pointer to the a'th message in table 
  354. ;       at (de)
  355. ;
  356. addmsg::        ld      d,0
  357.         ld      e,a
  358.         add     hl,de
  359.         add     hl,de           ;get to table entry
  360.         ld      e,(hl)
  361.         inc     hl
  362.         ld      d,(hl)
  363.         ret
  364. pmsg::  ld      a,(de)
  365.         call    putc
  366.         bit     7,a
  367.         ret     nz
  368.         inc     de
  369.         jr      pmsg
  370. ;
  371. phb::   push    psw
  372.         rrca
  373.         rrca
  374.         rrca
  375.         rrca
  376.         call    phb1
  377.         pop     psw
  378. phb1::  and     0fh
  379.         add     a,90h
  380.         daa
  381.         adc     a,40h
  382.         daa
  383. ;       jr      putc
  384. ;
  385. putc::  push    af
  386.         push    bc
  387.         push    de
  388.         push    hl
  389.         and     7fh
  390.         ld      e,a
  391.         ld      c,2
  392.         call    bdos
  393.         pop     hl
  394.         pop     de
  395.         pop     bc
  396.         pop     af
  397.         ret
  398. ;
  399. error:: ld      c,9
  400.         call    bdos
  401.         jp      0
  402. ;
  403. ;       Special link item types
  404. ;
  405. types:: dw      type0,type1,type2,type3
  406.         dw      type4,type5,type6,type7
  407.         dw      type8,type9,type10,type11
  408.         dw      type12,type13,type14,type15
  409. ;
  410. type0:: dc      'Entry Symbol='
  411. type1:: dc      'Common Block='
  412. type2:: dc      'Program Name='
  413. type3:: dc      'Search Library='
  414. type4:: dc      'Extension Link Item '
  415. type5:: dc      'Common Size='
  416. type6:: dc      'Chain External='
  417. type7:: dc      'Entry Point='
  418. type8:: dc      'External-Offset='
  419. type9:: dc      'External+Offset='
  420. type10::        dc      'Data Area Size='
  421. type11::        dc      'Loading Location='
  422. type12::        dc      'Chain Address='
  423. type13::        dc      'Program Size='
  424. type14::        dc      'End Program, Xfer='
  425. type15::        dc      'End of File'
  426. ;
  427. extypes::       dw      etype0,etype1,etype2
  428. etype0::        dc      'Operator = '
  429. etype1::        dc      'External = '
  430. etype2::        dc      'Local Symbol = '
  431. ;
  432. opertab::       dw      op0,op1,op2,op3,op4,op5,op6,op7
  433.         dw      op8,op9,opa,opb
  434. op0:    dc      '???'
  435. op1:    dc      'Store Byte'
  436. op2:    dc      'Store Word'
  437. op3:    dc      'High'
  438. op4:    dc      'Low'
  439. op5:    dc      '???'
  440. op6:    dc      '???'
  441. op7:    dc      '-'
  442. op8:    dc      '+'
  443. op9:    dc      '*'
  444. opa:    dc      '/'
  445. opb:    dc      'Mod'
  446. ;
  447. recmsg::        dc      '+ Record='
  448. bytmsg::        dc      ' Byte='
  449. ;
  450. opnmsg::        db      'Can''t open input file$'
  451. rdmsg:: db      'Read error$'
  452. ;
  453. loc::   ds      2               ;current loading location
  454. locm::  ds      1               ;loading location mode
  455. record::        ds      2               ;current record of rel file
  456. bytep:: ds      2               ;input byte pointer
  457. bitc::  ds      2               ;bit counter + byte counter
  458. column::        ds      1               ;current output column
  459. width:: ds      1               ;maximum output width
  460. ;
  461.         end     reldmp
  462.  
  463. 0B>