home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sources / apple2 / 12 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  27.0 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!rutgers!igor.rutgers.edu!yoko.rutgers.edu!jac
  2. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC072:  coff (OMF Disassembler) 07/09
  5. Message-ID: <Nov.8.19.12.26.1992.16623@yoko.rutgers.edu>
  6. Date: 9 Nov 92 00:12:27 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 1454
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: Albert Chin-A-Young (26285659t@servax.fiu.edu)
  13. Posting-number: Volume 1, Source:72
  14. Archive-name: utility/gs/disassem/coff/part07
  15. Architecture: ONLY_2gs
  16. Version-number: 1.1
  17.  
  18.  
  19. =output.s
  20. - lst off
  21. -
  22. -* UNIX coff utility
  23. -* output routines
  24. -*
  25. -* 1990-1992, tao Developer Project
  26. -
  27. - rel
  28. - xc
  29. - xc
  30. - mx %00
  31. -
  32. - put coff.h ;global defines
  33. - put x.data ;external data definitions
  34. - put x.general ;external general definitions
  35. - put x.gsos ;external GS/OS i/o definitions
  36. - put x.structure ;external data structure definitions
  37. -
  38. - put 4/gsos.h ;GS/OS defines
  39. - put 4/memory.h ;memory manager defines
  40. - put 4/resource.h ;resouce manager defines
  41. - put 4/texttool.h ;text tool defines
  42. - put 4/getopt.h ;getopt command-line option defines
  43. - put 4/env.h ;run-time environment settings
  44. -
  45. - use coff.mac ;macro definitions
  46. - use 4/datatype.mac ;HLL data types
  47. - use 4/env.mac ;run-time environment macros
  48. -
  49. -
  50. -long_header mac
  51. - pea #^]1
  52. - pea #]1
  53. - _WriteCString
  54. - lda #8
  55. - ldx @omf+`]2
  56. - ldy @omf+`]2+2
  57. - jsr print_fix_long_hex
  58. - pea #^blank_str ;long - pointer to string
  59. - pea #blank_str
  60. - pea #0 ;word - offset into text
  61. - pea #25 ;word - number of characters to print
  62. - _TextWriteBlock
  63. - lda #10
  64. - ldx @omf+`]2
  65. - ldy @omf+`]2+2
  66. - jsr print_fix_long_dec
  67. - put_cr
  68. - eom
  69. -short_header mac
  70. - pea #^]1
  71. - pea #]1
  72. - _WriteCString
  73. - lda #4
  74. - ldx @omf+`]2
  75. - jsr print_fix_short_hex
  76. - pea #^blank_str ;long - pointer to string
  77. - pea #blank_str
  78. - pea #0 ;word - offset into text
  79. - pea #34 ;word - number of characters to print
  80. - _TextWriteBlock
  81. - lda #5
  82. - ldx @omf+`]2
  83. - jsr print_fix_short_dec
  84. - put_cr
  85. - eom
  86. -char_header mac
  87. - pea #^]1
  88. - pea #]1
  89. - _WriteCString
  90. - ldx @omf+`]2
  91. - jsr print_fix_char_hex
  92. - pea #^blank_str ;long - pointer to string
  93. - pea #blank_str
  94. - pea #0 ;word - offset into text
  95. - pea #38 ;word - number of characters to print
  96. - _TextWriteBlock
  97. - lda #3
  98. - ldx @omf+`]2
  99. - jsr print_fix_char_dec
  100. - put_cr
  101. - eom
  102. -
  103. -
  104. -**************************************************
  105. -* print OMF header.                              *
  106. -**************************************************
  107. -print_header ent
  108. -]segname_handle = $20 ;handle of @omf+`segname
  109. -]segname_ptr = $24
  110. -]count = $28 ;number of bytes in header
  111. -]edge = $2c ;rightmost edge
  112. -]num_read = $2e ;number of characters read
  113. -]offset = $30 ;current offset into file
  114. -
  115. - lda }hex ;print hex of header?
  116. - bne :test_header
  117. - brl :print_header
  118. -:test_header lda }header
  119. - bne :hex_header
  120. - brl :print_header
  121. -
  122. -:hex_header jsr GSOSget_mark
  123. - phx
  124. - phy
  125. - sec
  126. - tya
  127. - sbc @omf+`offset
  128. - sta ]count
  129. - txa
  130. - sbc @omf+`offset+2
  131. - sta ]count+2
  132. -
  133. - ldx @omf+`offset
  134. - ldy @omf+`offset+2
  135. - stx ]offset
  136. - sty ]offset+2
  137. - tya
  138. - ora ]offset
  139. - beq :set_mark
  140. - put_cr
  141. -
  142. -:set_mark ldy @omf+`offset ;reset file pointer to beginning
  143. - ldx @omf+`offset+2 ;of header
  144. - jsr GSOSset_mark
  145. -
  146. - lda #HEADER_EDGE
  147. - sta ]edge
  148. -
  149. -:loop lda #6
  150. - ldx ]offset
  151. - ldy ]offset+2
  152. - jsr print_fix_long_hex
  153. - pea #^vert_separator+1
  154. - pea #vert_separator+1
  155. - _WriteCString
  156. -
  157. - lda ]count+2 ;if number of bytes to read is less
  158. - bne :0 ;than the default, output only
  159. - lda ]count ;default many bytes
  160. - cmp ]edge
  161. - blt :1
  162. -:0 lda ]edge ;read in default number of characters
  163. -:1 ldx #:hex
  164. - ldy #^:hex
  165. - jsr GSOSread
  166. - stx ]num_read
  167. -
  168. - ldx #0 ;output bytes just read
  169. -:print_byte phx
  170. - lda :hex,x
  171. - and #$ff
  172. - tax
  173. - jsr print_fix_char_hex
  174. - pea #' '
  175. - _WriteChar
  176. - plx
  177. - inx
  178. - cpx ]num_read
  179. - blt :print_byte
  180. -
  181. - pea #^blank_str ;long - pointer to string
  182. - pea #blank_str
  183. - pea #0 ;word - offset into text
  184. - sec ;word - number of characters to print
  185. - lda ]edge ;3 * (]edge - ]num_read)
  186. - sbc ]num_read
  187. - tax
  188. - asl
  189. - pha
  190. - clc
  191. - txa
  192. - adc 1,s
  193. - sta 1,s
  194. - _TextWriteBlock
  195. - pea #^:horz_separator
  196. - pea #:horz_separator
  197. - _WriteCString
  198. -
  199. - ldx #0
  200. -:print_char phx
  201. - lda :hex,x
  202. - and #$ff
  203. - jsr isprint
  204. - bcs :print_period
  205. - pha
  206. - _WriteChar
  207. - bra :end_loop
  208. -:print_period pea #'.'
  209. - _WriteChar
  210. -:end_loop plx
  211. - inx
  212. - cpx ]num_read
  213. - blt :print_char
  214. - put_cr
  215. -
  216. - decr ]num_read;]count
  217. - incr ]num_read;]offset
  218. -
  219. - lda ]count
  220. - ora ]count+2
  221. - beq :end
  222. - brl :loop
  223. -
  224. -:end ply
  225. - plx
  226. - jsr GSOSset_mark
  227. - rts
  228. -
  229. -:print_header lda @omf+`version
  230. - cmp #1
  231. - bne :omf_2
  232. - pea #^:block_count
  233. - pea #:block_count
  234. - _WriteCString
  235. - bra :2
  236. -:omf_2 pea #^:byte_count
  237. - pea #:byte_count
  238. - _WriteCString
  239. -:2 lda #8
  240. - ldx @omf+`bytecnt
  241. - ldy @omf+`bytecnt+2
  242. - jsr print_fix_long_hex
  243. - pea #^blank_str ;long - pointer to string
  244. - pea #blank_str
  245. - pea #0 ;word - offset into text
  246. - pea #25 ;word - number of characters to print
  247. - _TextWriteBlock
  248. - lda #10
  249. - ldx @omf+`bytecnt
  250. - ldy @omf+`bytecnt+2
  251. - jsr print_fix_long_dec
  252. - put_cr
  253. -
  254. - long_header :reserved_space;resspc
  255. - long_header :length;length
  256. - char_header :label_length;lablen
  257. - char_header :number_length;numlen
  258. - char_header :version;version
  259. -
  260. - lda @omf+`revision
  261. - bne :print_revision
  262. - brl :print_bank_size
  263. -:print_revision char_header :revision;revision
  264. -:print_bank_size long_header :bank_size;banksize
  265. -
  266. - lda @omf+`version
  267. - cmp #1
  268. - bne :print_kind_2
  269. - jsr print_kind_1
  270. - bra :3
  271. -:print_kind_2 jsr print_kind_2
  272. -
  273. -:3 long_header :org;org
  274. - long_header :alignment;align
  275. - char_header :number_sex;numsex
  276. - short_header :segment_number;segnum
  277. - long_header :entry;entry
  278. - short_header :disp_to_names;dispname
  279. - short_header :disp_to_data;dispdata
  280. -
  281. - pea #^:load_name
  282. - pea #:load_name
  283. - _WriteCString
  284. - pea #^@omf+`loadname ;long - pointer to string
  285. - pea #@omf+`loadname
  286. - pea #0 ;word - offset into text
  287. - pea #LOADNAME_LEN ;word - number of characters to print
  288. - _TextWriteBlock
  289. - put_cr
  290. -
  291. - ldx @omf+`segname
  292. - ldy @omf+`segname+2
  293. - stx ]segname_handle
  294. - sty ]segname_handle+2
  295. - phy
  296. - phx
  297. - phy
  298. - phx
  299. - _HLock
  300. - lda []segname_handle]
  301. - sta ]segname_ptr
  302. - ldy #2
  303. - lda []segname_handle],y
  304. - sta ]segname_ptr+2
  305. - pea #^:segment_name
  306. - pea #:segment_name
  307. - _WriteCString
  308. - pei ]segname_ptr+2 ;long - pointer to string
  309. - pei ]segname_ptr
  310. - pea #2 ;word - offset into text
  311. - lda []segname_ptr] ;word - number of characters to print
  312. - pha
  313. - _TextWriteBlock
  314. - put_cr
  315. - _HUnlock
  316. -
  317. - put_cr
  318. - rts
  319. -
  320. -:byte_count cStr 'byte count    : $'
  321. -:block_count cStr 'block count   : $'
  322. -:reserved_space cStr 'reserved space: $'
  323. -:length cStr 'length        : $'
  324. -:label_length cStr 'label length  : $'
  325. -:number_length cStr 'number length : $'
  326. -:version cStr 'version       : $'
  327. -:revision cStr 'revision      : $'
  328. -:bank_size cStr 'bank size     : $'
  329. -:org cStr 'org           : $'
  330. -:alignment cStr 'alignment     : $'
  331. -:number_sex cStr 'number sex    : $'
  332. -:segment_number cStr 'segment number: $'
  333. -:entry cStr 'entry         : $'
  334. -:disp_to_names cStr 'disp to names : $'
  335. -:disp_to_data cStr 'disp to data  : $'
  336. -:load_name cStr 'load name     : '
  337. -:segment_name cStr 'segment name  : '
  338. -:horz_separator cStr '- '
  339. -:hex ds HEADER_EDGE+6
  340. -
  341. -
  342. -**************************************************
  343. -* print kind string for OMF 1.0.                 *
  344. -**************************************************
  345. -print_kind_1 equ *
  346. -]space = $80
  347. -]kind_str = $82
  348. -
  349. - jsr parse_kind_1
  350. - lda kind_str
  351. - cmp #32
  352. - bge :0
  353. - pea #^:kind
  354. - pea #:kind
  355. - _WriteCString
  356. - ldx @omf+`kind
  357. - jsr print_fix_char_hex
  358. - pea #^blank_str ;long - pointer to string
  359. - pea #blank_str
  360. - pea #0 ;word - offset into text
  361. - sec ;word - number of characters to print
  362. - lda #41
  363. - sbc kind_str
  364. - pha
  365. - _TextWriteBlock
  366. - pea #^kind_str ;long - pointer to string
  367. - pea #kind_str
  368. - pea #2 ;word - offset into text
  369. - lda kind_str ;word - number of characters to print
  370. - pha
  371. - _TextWriteBlock
  372. - put_cr
  373. - rts
  374. -
  375. -:0 lda #kind_str+2
  376. - sta ]kind_str
  377. -:loop lda #' ' ;find next occurrence of space
  378. - ldx ]kind_str ;character
  379. - jsr strchr
  380. - stx ]space
  381. - bne :1
  382. - clc
  383. - lda #kind_str
  384. - adc kind_str
  385. - sta ]space
  386. -:1 sec
  387. - lda ]space
  388. - sbc #kind_str+2
  389. - cmp #32
  390. - bge :2
  391. - brl :3
  392. -:2 pea #^:kind
  393. - pea #:kind
  394. - _WriteCString
  395. - ldx @omf+`kind
  396. - jsr print_fix_char_hex
  397. - pea #^blank_str ;long - pointer to string
  398. - pea #blank_str
  399. - pea #0 ;word - offset into text
  400. - sec ;word - number of characters to print
  401. - lda ]kind_str
  402. - sbc #kind_str+2
  403. - dec
  404. - pha
  405. - sec
  406. - lda #41
  407. - sbc 1,s
  408. - sta 1,s
  409. - _TextWriteBlock
  410. - pea #^kind_str ;long - pointer to string
  411. - pea #kind_str
  412. - pea #2 ;word - offset into text
  413. - sec ;word - number of characters to print
  414. - lda ]kind_str
  415. - sbc #kind_str+2
  416. - dec
  417. - pha
  418. - _TextWriteBlock
  419. - put_cr
  420. - bra :4
  421. -:3 lda ]space
  422. - inc
  423. - sta ]kind_str
  424. - brl :loop
  425. -
  426. -:4 pea #^blank_str ;long - pointer to string
  427. - pea #blank_str
  428. - pea #0 ;word - offset into text
  429. - clc ;word - number of characters to print
  430. - lda #kind_str+2
  431. - adc kind_str
  432. - sec
  433. - sbc ]kind_str
  434. - pha
  435. - sec
  436. - lda #60
  437. - sbc 1,s
  438. - sta 1,s
  439. - _TextWriteBlock
  440. - phb ;long - pointer to string
  441. - phb
  442. - pla
  443. - and #$ff
  444. - pha
  445. - pei ]kind_str
  446. - _WriteCString
  447. - put_cr
  448. - rts
  449. -
  450. -:kind cStr 'kind          : $'
  451. -
  452. -
  453. -**************************************************
  454. -* print kind string for OMF 2.0.                 *
  455. -**************************************************
  456. -print_kind_2 equ *
  457. -]space = $80
  458. -]kind_str = $82
  459. -
  460. - jsr parse_kind_2
  461. - lda kind_str
  462. - cmp #30
  463. - bge :0
  464. - pea #^:kind
  465. - pea #:kind
  466. - _WriteCString
  467. - lda #4
  468. - ldx @omf+`kind
  469. - jsr print_fix_short_hex
  470. - pea #^blank_str ;long - pointer to string
  471. - pea #blank_str
  472. - pea #0 ;word - offset into text
  473. - sec ;word - number of characters to print
  474. - lda #39
  475. - sbc kind_str
  476. - pha
  477. - _TextWriteBlock
  478. - pea #^kind_str ;long - pointer to string
  479. - pea #kind_str
  480. - pea #2 ;word - offset into text
  481. - lda kind_str ;word - number of characters to print
  482. - pha
  483. - _TextWriteBlock
  484. - put_cr
  485. - rts
  486. -
  487. -:0 lda #kind_str+2
  488. - sta ]kind_str
  489. -:loop lda #' ' ;find next occurrence of space
  490. - ldx ]kind_str ;character
  491. - jsr strchr
  492. - stx ]space
  493. - bne :1
  494. - clc
  495. - lda #kind_str+2
  496. - adc kind_str
  497. - sta ]space
  498. -:1 sec
  499. - lda ]space
  500. - sbc #kind_str+2
  501. - cmp #30
  502. - bge :2
  503. - brl :3
  504. -:2 pea #^:kind
  505. - pea #:kind
  506. - _WriteCString
  507. - lda #4
  508. - ldx @omf+`kind
  509. - jsr print_fix_short_hex
  510. - pea #^blank_str ;long - pointer to string
  511. - pea #blank_str
  512. - pea #0 ;word - offset into text
  513. - sec ;word - number of characters to print
  514. - lda ]kind_str
  515. - sbc #kind_str+2
  516. - dec
  517. - pha
  518. - sec
  519. - lda #39
  520. - sbc 1,s
  521. - sta 1,s
  522. - _TextWriteBlock
  523. - pea #^kind_str ;long - pointer to string
  524. - pea #kind_str
  525. - pea #2 ;word - offset into text
  526. - sec ;word - number of characters to print
  527. - lda ]kind_str
  528. - sbc #kind_str+2
  529. - dec
  530. - pha
  531. - _TextWriteBlock
  532. - put_cr
  533. - bra :4
  534. -:3 lda ]space
  535. - inc
  536. - sta ]kind_str
  537. - brl :loop
  538. -
  539. -:4 pea #^blank_str ;long - pointer to string
  540. - pea #blank_str
  541. - pea #0 ;word - offset into text
  542. - clc ;word - number of characters to print
  543. - lda #kind_str+2
  544. - adc kind_str
  545. - sec
  546. - sbc ]kind_str
  547. - pha
  548. - sec
  549. - lda #60
  550. - sbc 1,s
  551. - sta 1,s
  552. - _TextWriteBlock
  553. - phb ;long - pointer to string
  554. - phb
  555. - pla
  556. - and #$ff
  557. - pha
  558. - pei ]kind_str
  559. - _WriteCString
  560. - put_cr
  561. - rts
  562. -
  563. -:kind cStr 'kind          : $'
  564. -
  565. -
  566. -**************************************************
  567. -* convert kind value to string equivalents for   *
  568. -* OMF 1.0.                                       *
  569. -**************************************************
  570. -parse_kind_1 equ *
  571. -
  572. - stz kind_str ;0 length of string
  573. - lda @omf+`kind
  574. - and #DYNAMIC
  575. - beq :static
  576. - ldx #dynamic
  577. - jsr append_kind_str
  578. - bra :0
  579. -:static ldx #static
  580. - jsr append_kind_str
  581. -
  582. -:0 ldx #0
  583. -:loop lda @omf+`kind
  584. - asl
  585. - asl
  586. - asl
  587. - asl
  588. - asl
  589. - asl
  590. - asl
  591. - asl
  592. - phx
  593. - and :type,x
  594. - cmp #POSITION_INDEPENDENT
  595. - bne :private
  596. - ldx #position_independent
  597. - jsr append_kind_str
  598. - bra :end_loop
  599. -:private cmp #PRIVATE
  600. - bne :end_loop
  601. - ldx #private
  602. - jsr append_kind_str
  603. -:end_loop plx
  604. - inx
  605. - inx
  606. - cpx #4
  607. - blt :loop
  608. -
  609. - lda @omf+`kind
  610. - and #$1f
  611. -:check_code cmp #CODE
  612. - bne :data
  613. - ldx #code
  614. - jsr append_kind_str
  615. - rts
  616. -:data cmp #DATA
  617. - bne :jump_table
  618. - ldx #data
  619. - jsr append_kind_str
  620. - rts
  621. -:jump_table cmp #JUMP_TABLE
  622. - bne :pathname
  623. - ldx #jump_table
  624. - jsr append_kind_str
  625. - rts
  626. -:pathname cmp #PATHNAME
  627. - bne :library_dictionary
  628. - ldx #pathname
  629. - jsr append_kind_str
  630. - rts
  631. -:library_dictionary cmp #LIBRARY_DICTIONARY
  632. - bne :initialization
  633. - ldx #library_dictionary
  634. - jsr append_kind_str
  635. - rts
  636. -:initialization cmp #INITIALIZATION
  637. - bne :absolute_bank_seg
  638. - ldx #initialization
  639. - jsr append_kind_str
  640. - rts
  641. -:absolute_bank_seg cmp #ABSOLUTE_BANK_SEG
  642. - bne :direct_page
  643. - ldx #absolute_bank
  644. - jsr append_kind_str
  645. - rts
  646. -:direct_page cmp #DIRECT_PAGE
  647. - bne :end
  648. - ldx #dp_stack
  649. - jsr append_kind_str
  650. -:end rts
  651. -
  652. -:type dw POSITION_INDEPENDENT
  653. - dw PRIVATE
  654. -
  655. -
  656. -**************************************************
  657. -* convert kind value to string equivalents for   *
  658. -* OMF 2.0.                                       *
  659. -**************************************************
  660. -parse_kind_2 equ *
  661. -
  662. - stz kind_str ;0 length of string
  663. - lda @omf+`kind
  664. - and #DYNAMIC
  665. - beq :static
  666. - ldx #dynamic
  667. - jsr append_kind_str
  668. - bra :0
  669. -:static ldx #static
  670. - jsr append_kind_str
  671. -
  672. -:0 ldx #0
  673. -:loop lda @omf+`kind
  674. - phx
  675. - and :type,x
  676. - cmp #BANK_RELATIVE
  677. - bne :skip
  678. - ldx #bank_relative
  679. - jsr append_kind_str
  680. - bra :end_loop
  681. -:skip cmp #SKIP
  682. - bne :reload
  683. - ldx #skip
  684. - jsr append_kind_str
  685. - bra :end_loop
  686. -:reload cmp #RELOAD
  687. - bne :absolute_bank
  688. - ldx #reload
  689. - jsr append_kind_str
  690. - bra :end_loop
  691. -:absolute_bank cmp #ABSOLUTE_BANK
  692. - bne :position_independent
  693. - ldx #absolute_bank
  694. - jsr append_kind_str
  695. - bra :end_loop
  696. -:position_independent cmp #POSITION_INDEPENDENT
  697. - bne :private
  698. - ldx #position_independent
  699. - jsr append_kind_str
  700. - bra :end_loop
  701. -:private cmp #PRIVATE
  702. - bne :end_loop
  703. - ldx #private
  704. - jsr append_kind_str
  705. -:end_loop plx
  706. - inx
  707. - inx
  708. - cpx #12
  709. - blt :loop
  710. -
  711. - lda @omf+`kind
  712. - and #$1f
  713. -:check_code cmp #CODE
  714. - bne :data
  715. - ldx #code
  716. - jsr append_kind_str
  717. - rts
  718. -:data cmp #DATA
  719. - bne :jump_table
  720. - ldx #data
  721. - jsr append_kind_str
  722. - rts
  723. -:jump_table cmp #JUMP_TABLE
  724. - bne :pathname
  725. - ldx #jump_table
  726. - jsr append_kind_str
  727. - rts
  728. -:pathname cmp #PATHNAME
  729. - bne :library_dictionary
  730. - ldx #pathname
  731. - jsr append_kind_str
  732. - rts
  733. -:library_dictionary cmp #LIBRARY_DICTIONARY
  734. - bne :initialization
  735. - ldx #library_dictionary
  736. - jsr append_kind_str
  737. - rts
  738. -:initialization cmp #INITIALIZATION
  739. - bne :absolute_bank_seg
  740. - ldx #initialization
  741. - jsr append_kind_str
  742. - rts
  743. -:absolute_bank_seg cmp #ABSOLUTE_BANK_SEG
  744. - bne :direct_page
  745. - ldx #absolute_bank
  746. - jsr append_kind_str
  747. - rts
  748. -:direct_page cmp #DIRECT_PAGE
  749. - bne :end
  750. - ldx #dp_stack
  751. - jsr append_kind_str
  752. -:end rts
  753. -
  754. -:type dw PRIVATE
  755. - dw POSITION_INDEPENDENT
  756. - dw ABSOLUTE_BANK
  757. - dw RELOAD
  758. - dw SKIP
  759. - dw BANK_RELATIVE
  760. -
  761. -
  762. -**************************************************
  763. -* output expression list stack as infix          *
  764. -* expression.                                    *
  765. -* ---------------------------------------------- *
  766. -* (input)                                        *
  767. -*  x - offset into current line.                 *
  768. -* (output)                                       *
  769. -*  x - offset into current line.                 *
  770. -**************************************************
  771. -print_stack_infix ent
  772. -]offset = $d0 ;offset into line
  773. -]btree_ptr = $d2 ;pointer to binary tree
  774. -]size = $d4 ;size of stack
  775. -]list_lo_handle = $d6 ;handle to @expr_list stack
  776. -]list_lo_ptr = $da
  777. -]list_hi_handle = $de
  778. -]list_hi_ptr = $e2
  779. -]list_offset = $e6 ;offset into @expr_list for current expression
  780. -]element_handle = $e8 ;current list element
  781. -]element_ptr = $ec
  782. -]count = $f0
  783. -
  784. - stx ]offset
  785. -
  786. - ldx @expr_list+`lo
  787. - ldy @expr_list+`lo+2
  788. - stx ]list_lo_handle
  789. - sty ]list_lo_handle+2
  790. - phy
  791. - phx
  792. - phy
  793. - phx
  794. - _HLock
  795. - ldx @expr_list+`hi
  796. - ldy @expr_list+`hi+2
  797. - stx ]list_hi_handle
  798. - sty ]list_hi_handle+2
  799. - phy
  800. - phx
  801. - phy
  802. - phx
  803. - _HLock
  804. - lda []list_lo_handle]
  805. - sta ]list_lo_ptr
  806. - ldy #2
  807. - lda []list_lo_handle],y
  808. - sta ]list_lo_ptr+2
  809. - lda []list_hi_handle]
  810. - sta ]list_hi_ptr
  811. - ldy #2
  812. - lda []list_hi_handle],y
  813. - sta ]list_hi_ptr+2
  814. - stz ]list_offset
  815. - stz ]size
  816. - stz ]count
  817. -
  818. -:loop lda ]list_offset
  819. - asl
  820. - tay
  821. - lda []list_lo_ptr],y
  822. - sta ]element_handle
  823. - lda []list_hi_ptr],y
  824. - sta ]element_handle+2
  825. - lda []element_handle]
  826. - sta ]element_ptr
  827. - ldy #2
  828. - lda []element_handle],y
  829. - sta ]element_ptr+2
  830. -
  831. - lda ]size
  832. - asl
  833. - tay
  834. - lda ]count
  835. - asl
  836. - tax
  837. - lda @btree+`ptr,x
  838. - sta ]btree_ptr
  839. - sta :order,y
  840. -
  841. - ldy #`str ;store handle to expression string
  842. - lda ]element_handle
  843. - sta (]btree_ptr),y
  844. - ldy #`str+2
  845. - lda ]element_handle+2
  846. - sta (]btree_ptr),y
  847. - ldy #`left
  848. - lda #NULL
  849. - sta (]btree_ptr),y
  850. - ldy #`oper ;store operation code
  851. - lda []element_ptr]
  852. - sta (]btree_ptr),y
  853. - beq :string
  854. - cmp #LABEL_LENGTH
  855. - beq :string
  856. - tax
  857. - lda #NULL ;zero out string (won't be used)
  858. - ldy #`str
  859. - sta (]btree_ptr),y
  860. - ldy #`str+2
  861. - sta (]btree_ptr),y
  862. - dec ]size ;make right node last known expression
  863. - lda ]size
  864. - asl
  865. - tay
  866. - lda :order,y
  867. - ldy #`right
  868. - sta (]btree_ptr),y
  869. - cpx #NEGATION ;special case unary operators
  870. - beq :update_order
  871. - cpx #NOT
  872. - beq :update_order
  873. - cpx #COMPLEMENT
  874. - beq :update_order
  875. - cpx #LABEL_LENGTH
  876. - beq :update_order
  877. - dec ]size ;make left node second last known
  878. - lda ]size ;expression
  879. - asl
  880. - tay
  881. - lda :order,y
  882. - ldy #`left
  883. - sta (]btree_ptr),y
  884. - bra :update_order
  885. -:string lda #NULL
  886. - ldy #`right
  887. - sta (]btree_ptr),y
  888. - ldy #`left
  889. - sta (]btree_ptr),y
  890. -
  891. -:update_order lda ]size
  892. - asl
  893. - tax
  894. - lda ]btree_ptr
  895. - sta :order,x
  896. - inc ]size
  897. - inc ]count
  898. - inc ]list_offset
  899. - lda ]list_offset
  900. - cmp @expr_list+`size
  901. - beq :print_offset
  902. - brl :loop
  903. -
  904. -:print_offset _HUnlock
  905. - _HUnlock
  906. - lda }assembly
  907. - bne :print_inorder
  908. - jsr print_offset
  909. - pea #^space_vert_bar
  910. - pea #space_vert_bar
  911. - _WriteCString
  912. -
  913. -:print_inorder pei ]btree_ptr
  914. - pei ]offset
  915. - ldy #`oper
  916. - lda (]btree_ptr),y
  917. - beq :0
  918. - cmp #LABEL_LENGTH
  919. - beq :0
  920. - asl
  921. - asl
  922. - tax
  923. - lda ~operator+`prec,x
  924. - inc
  925. -:0 pha
  926. - jsr print_inorder
  927. - stx ]offset
  928. - cpx #0
  929. - beq :end
  930. - lda }assembly
  931. - bne :end
  932. - put_cr
  933. -
  934. -:end ldx ]offset
  935. - rts
  936. -
  937. -:order ds 50*2 ;order in which trees are allocated
  938. -
  939. -
  940. -**************************************************
  941. -* print binary tree 'inorder'.                   *
  942. -* ---------------------------------------------- *
  943. -* (input)                                        *
  944. -*  word - pointer to binary tree.                *
  945. -*  word - offset into line.                      *
  946. -*  word - operator precedence.                   *
  947. -* (output)                                       *
  948. -*  x - current offset into line.                 *
  949. -**************************************************
  950. -print_inorder equ *
  951. -]oper = $01 ;operator
  952. -]oper_str = ]oper+2 ;string representation of operator
  953. -]expr_str = ]oper_str+4 ;expression string
  954. -]db = ]expr_str+4
  955. -]dp = ]db+1
  956. -]rts = ]dp+1
  957. -]precedence = ]rts+2 ;operator precedence
  958. -]offset = ]precedence+2 ;current offset into line
  959. -]btree_ptr = ]offset+2 ;pointer to binary tree
  960. -
  961. - phd ;save direct page
  962. - tdc ;save copy of dp for calls that access
  963. - sta :dp ;dp space in coff
  964. -
  965. - sec
  966. - tsc
  967. - sbc #]dp-2 ;make local dp space
  968. - tcs
  969. - tcd
  970. -
  971. - lda ]btree_ptr
  972. - bne :print
  973. - ldx ]offset
  974. -
  975. -:end lda ]rts,s ;move return address to position
  976. - sta ]btree_ptr,s ;of last parameter
  977. -
  978. - clc
  979. - tsc
  980. - adc #]dp-2
  981. - tcs
  982. -
  983. - pld
  984. -
  985. - clc
  986. - tsc
  987. - adc #]btree_ptr-]rts
  988. - tcs
  989. - rts
  990. -
  991. -
  992. -:print ldy #`str ;if no string for expression,
  993. - lda (]btree_ptr),y ;parse operator token
  994. - sta ]oper_str
  995. - ldy #`str+2
  996. - lda (]btree_ptr),y
  997. - sta ]oper_str+2
  998. - ora ]oper_str
  999. - bne :print_str
  1000. - brl :operator
  1001. -
  1002. -:print_str pei ]oper_str+2 ;output string representation of
  1003. - pei ]oper_str ;expression
  1004. - pei ]oper_str+2
  1005. - pei ]oper_str
  1006. - _HLock
  1007. - ldy #2
  1008. - lda []oper_str],y
  1009. - tay
  1010. - lda []oper_str]
  1011. - sta ]oper_str
  1012. - tax
  1013. - inx
  1014. - inx
  1015. - sty ]oper_str+2
  1016. -
  1017. - phd
  1018. - lda :dp
  1019. - tcd
  1020. - jsr match_label
  1021. - pld
  1022. - stx ]expr_str
  1023. - sty ]expr_str+2
  1024. - txa
  1025. - ora ]expr_str+2
  1026. - beq :0
  1027. - lda }label
  1028. - bne :1
  1029. -:0 ldx ]oper_str
  1030. - inx
  1031. - inx
  1032. - ldy ]oper_str+2
  1033. - stx ]expr_str
  1034. - sty ]expr_str+2
  1035. -:1 ldx #0
  1036. - lda []oper_str]  ;update offset into line by length
  1037. - pha
  1038. - cmp #LABEL_LENGTH
  1039. - bne :2
  1040. - ldx #9
  1041. -:2 clc
  1042. - txa
  1043. - adc []expr_str] ;of string to print
  1044. - adc ]offset
  1045. - sta ]offset
  1046. - tax
  1047. - phd
  1048. - lda :dp
  1049. - tcd
  1050. - jsr newline
  1051. - pld
  1052. - stx ]offset
  1053. - pla
  1054. - cmp #LABEL_LENGTH
  1055. - bne :3
  1056. - pea #^:length
  1057. - pea #:length
  1058. - _WriteCString
  1059. - pei ]expr_str+2 ;output expression string
  1060. - pei ]expr_str
  1061. - pea #2
  1062. - lda []expr_str]
  1063. - pha
  1064. - _TextWriteBlock
  1065. - pea #')'
  1066. - _WriteChar
  1067. - bra :4
  1068. -:3 pei ]expr_str+2 ;output expression string
  1069. - pei ]expr_str
  1070. - pea #2
  1071. - lda []expr_str]
  1072. - pha
  1073. - _TextWriteBlock
  1074. -:4 lda ]offset
  1075. - bne :unlock
  1076. - lda []expr_str]
  1077. - sta ]offset
  1078. -
  1079. -:unlock _HUnlock
  1080. - ldx ]offset
  1081. - brl :end
  1082. -
  1083. -:operator ldy #`oper ;minimize output of parentheses
  1084. - lda (]btree_ptr),y ;in expressions by considering
  1085. - sta ]oper ;precedence of operators
  1086. - asl
  1087. - asl
  1088. - tax
  1089. - lda ]precedence
  1090. - cmp ~operator+`prec,x
  1091. - blt :5
  1092. - bne :6
  1093. - lda #LEFT
  1094. - cmp ~operator+`assoc,x
  1095. - bne :6
  1096. -:5 pea #'('
  1097. - _WriteChar
  1098. - inc ]offset
  1099. -:6 ldy #`left
  1100. - lda (]btree_ptr),y
  1101. - pha
  1102. - pei ]offset
  1103. - lda ]oper
  1104. - asl
  1105. - asl
  1106. - tax
  1107. - lda ~operator+`prec,x
  1108. - pha
  1109. - jsr print_inorder
  1110. - stx ]offset
  1111. -
  1112. - lda ]oper
  1113. - jsr find_operator ;uses no dp space
  1114. - stx ]oper_str+2
  1115. - sty ]oper_str
  1116. -
  1117. - clc ;test if at right margin
  1118. - lda []oper_str]
  1119. - adc ]offset
  1120. - adc #2
  1121. - sta ]offset
  1122. - tax
  1123. - phd
  1124. - lda :dp
  1125. - tcd
  1126. - jsr newline
  1127. - pld
  1128. - stx ]offset
  1129. - cpx #0 ;if at left margin, don't prepend space
  1130. - beq :7 ;to separate operator from expression
  1131. - cpx #3
  1132. - beq :7
  1133. - pea #' '
  1134. - _WriteChar
  1135. -:7 pei ]oper_str+2
  1136. - pei ]oper_str
  1137. - pea #2
  1138. - lda []oper_str]
  1139. - pha
  1140. - _TextWriteBlock
  1141. - ldx ]oper ;don't append space to unary operators
  1142. - cpx #NEGATION ;special case unary operators
  1143. - beq :8
  1144. - cpx #NOT
  1145. - beq :8
  1146. - cpx #COMPLEMENT
  1147. - beq :8
  1148. - pea #' '
  1149. - _WriteChar
  1150. -:8 lda ]offset
  1151. - bne :9
  1152. - lda []oper_str]
  1153. - sta ]offset
  1154. -
  1155. -:9 ldy #`right
  1156. - lda (]btree_ptr),y
  1157. - pha
  1158. - pei ]offset
  1159. - lda ]oper
  1160. - asl
  1161. - asl
  1162. - tax
  1163. - lda ~operator+`prec,x
  1164. - pha
  1165. - jsr print_inorder
  1166. - stx ]offset
  1167. -
  1168. - lda ]oper
  1169. - asl
  1170. - asl
  1171. - tax
  1172. - lda ]precedence
  1173. - cmp ~operator+`prec,x
  1174. - blt :10
  1175. - bne :11
  1176. - lda #LEFT
  1177. - cmp ~operator+`assoc,x
  1178. - bne :11
  1179. -:10 pea #')'
  1180. - _WriteChar
  1181. - inc ]offset
  1182. -
  1183. -:11 ldx ]offset
  1184. - brl :end
  1185. -
  1186. -:dp dw 0 ;direct page register
  1187. -:length cStr 'length ('
  1188. -
  1189. -
  1190. -**************************************************
  1191. -* check to output newline in current expression  *
  1192. -* output.                                        *
  1193. -* ---------------------------------------------- *
  1194. -* (input)                                        *
  1195. -*  x - offset into line.                         *
  1196. -* (output)                                       *
  1197. -*  x - offset into line.                         *
  1198. -**************************************************
  1199. -newline equ *
  1200. -]offset = $f0
  1201. -]edge = $f2
  1202. -
  1203. - stx ]offset
  1204. -
  1205. - lda #0
  1206. - ldx }nooffset
  1207. - beq :0
  1208. - lda #16
  1209. -:0 clc
  1210. - adc #INFIX_EDGE
  1211. - sta ]edge
  1212. -
  1213. - lda ]edge ;if past right boundary for
  1214. - cmp ]offset ;INFIX expressions, move to next
  1215. - bge :end ;line and output rest of
  1216. - put_cr ;expression
  1217. - jsr print_offset
  1218. - stz ]offset
  1219. - lda }assembly
  1220. - beq :1
  1221. - pea #^blank_str ;19 blank spaces indents assembly
  1222. - pea #blank_str ;output
  1223. - pea #0
  1224. - pea #19
  1225. - _TextWriteBlock
  1226. - bra :end
  1227. -:1 pea #^space_vert_bar
  1228. - pea #space_vert_bar
  1229. - _WriteCString
  1230. -
  1231. -:end ldx ]offset
  1232. - rts
  1233. -
  1234. -
  1235. -**************************************************
  1236. -* output expression list stack as postfix        *
  1237. -* expression.                                    *
  1238. -* ---------------------------------------------- *
  1239. -* (input)                                        *
  1240. -*  x - offset into line.                         *
  1241. -* (output)                                       *
  1242. -*  x - offset into line.                         *
  1243. -**************************************************
  1244. -print_stack_postfix ent
  1245. -]offset = $d0 ;offset into line
  1246. -]edge = $d2
  1247. -]list_lo_handle = $d4
  1248. -]list_hi_handle = $d8
  1249. -]list_lo_ptr = $dc
  1250. -]list_hi_ptr = $e0
  1251. -]list_offset = $e4 ;offset into @expr_list for current expression
  1252. -]list = $e6 ;current list element
  1253. -]expr_str = $ea ;expression string
  1254. -
  1255. - stx ]offset
  1256. - stz ]list_offset
  1257. -
  1258. - ldx @expr_list+`lo
  1259. - ldy @expr_list+`lo+2
  1260. - stx ]list_lo_handle
  1261. - sty ]list_lo_handle+2
  1262. - phy
  1263. - phx
  1264. - phy
  1265. - phx
  1266. - _HLock
  1267. - ldx @expr_list+`hi
  1268. - ldy @expr_list+`hi+2
  1269. - stx ]list_hi_handle
  1270. - sty ]list_hi_handle+2
  1271. - phy
  1272. - phx
  1273. - phy
  1274. - phx
  1275. - _HLock
  1276. - lda []list_lo_handle]
  1277. - sta ]list_lo_ptr
  1278. - ldy #2
  1279. - lda []list_lo_handle],y
  1280. - sta ]list_lo_ptr+2
  1281. - lda []list_hi_handle]
  1282. - sta ]list_hi_ptr
  1283. - ldy #2
  1284. - lda []list_hi_handle],y
  1285. - sta ]list_hi_ptr+2
  1286. -
  1287. - lda #0
  1288. - ldx }nooffset
  1289. - beq :0
  1290. - lda #16
  1291. -:0 clc
  1292. - adc #POSTFIX_EDGE
  1293. - sta ]edge
  1294. -
  1295. - lda }assembly
  1296. - bne :loop
  1297. - jsr print_offset
  1298. - pea #^space_vert_bar
  1299. - pea #space_vert_bar
  1300. - _WriteCString
  1301. -
  1302. -:loop lda ]list_offset
  1303. - cmp @expr_list+`size
  1304. - bne :print_postfix
  1305. - brl :end
  1306. -:print_postfix lda ]list_offset
  1307. - asl
  1308. - tay
  1309. - lda []list_lo_ptr],y
  1310. - sta ]list
  1311. - lda []list_hi_ptr],y
  1312. - sta ]list+2
  1313. - ldy #2
  1314. - lda []list],y
  1315. - tay
  1316. - lda []list]
  1317. - sta ]list
  1318. - tax
  1319. - sty ]list+2
  1320. -
  1321. - lda []list]
  1322. - bne :find_operator
  1323. - inx
  1324. - inx
  1325. - jsr match_label
  1326. - stx ]expr_str
  1327. - sty ]expr_str+2
  1328. - txa
  1329. - ora ]expr_str+2
  1330. - beq :1
  1331. - lda }label
  1332. - bne :print_expr
  1333. -:1 ldx ]list
  1334. - inx
  1335. - inx
  1336. - ldy ]list+2
  1337. - stx ]expr_str
  1338. - sty ]expr_str+2
  1339. - bra :print_expr
  1340. -:find_operator jsr find_operator
  1341. - stx ]expr_str+2
  1342. - sty ]expr_str
  1343. -
  1344. -:print_expr clc
  1345. - lda ]offset
  1346. - adc []expr_str]
  1347. - sta ]offset
  1348. - pei ]expr_str+2
  1349. - pei ]expr_str
  1350. - pea #2
  1351. - lda []expr_str]
  1352. - pha
  1353. - _TextWriteBlock
  1354. - lda []list] ;special case EXPR sub-type $84 (label length)
  1355. - cmp #LABEL_LENGTH
  1356. - bne :2
  1357. - pei ]list+2
  1358. - pei ]list
  1359. - pea #4
  1360. - clc
  1361. - ldy #2
  1362. - lda []list],y
  1363. - pha
  1364. - adc ]offset
  1365. - inc
  1366. - sta ]offset
  1367. - _TextWriteBlock
  1368. - pea #')'
  1369. - _WriteChar
  1370. -
  1371. -:2 inc ]list_offset
  1372. - lda ]list_offset
  1373. - cmp @expr_list+`size
  1374. - beq :end
  1375. - lda ]offset
  1376. - cmp ]edge
  1377. - bge :end_print
  1378. - pea #' '
  1379. - _WriteChar
  1380. - inc ]offset
  1381. -:end_print lda ]offset
  1382. - dec
  1383. - cmp ]edge
  1384. - bge :3
  1385. - brl :print_postfix
  1386. -
  1387. -:3 put_cr
  1388. - lda }nooffset
  1389. - bne :4
  1390. - jsr print_offset
  1391. -:4 lda }assembly
  1392. - beq :5
  1393. - pea #^:vert_separator
  1394. - pea #:vert_separator
  1395. - _WriteCString
  1396. - bra :6
  1397. -:5 pea #^space_vert_bar
  1398. - pea #space_vert_bar
  1399. - _WriteCString
  1400. -:6 stz ]offset
  1401. - brl :loop
  1402. -
  1403. -:end _HUnlock
  1404. - _HUnlock
  1405. - lda }assembly
  1406. - bne :return
  1407. - put_cr
  1408. -:return ldx ]offset
  1409. - rts
  1410. -
  1411. -:vert_separator cStr '                   |'
  1412. -
  1413. -
  1414. -**************************************************
  1415. -* append string to kind_str.                     *
  1416. -* ---------------------------------------------- *
  1417. -* (input)                                        *
  1418. -*  x - LOW of string in current bank.            *
  1419. -**************************************************
  1420. -append_kind_str equ *
  1421. -]append_str = $f0 ;address of C-string to append
  1422. -
  1423. - stx ]append_str
  1424. -
  1425. - ldy #0
  1426. - ldx kind_str
  1427. - shorta
  1428. -:loop lda (]append_str),y
  1429. - sta kind_str+2,x
  1430. - iny
  1431. - inx
  1432. - cmp #0
  1433. - bne :loop
  1434. -:end longa
  1435. - dex
  1436. - stx kind_str ;update length of kind string
  1437. - rts
  1438. -
  1439. -
  1440. -**************************************************
  1441. -kind_str ds KIND_LEN+2
  1442. -
  1443. -code cStr ' code'
  1444. -data cStr ' data'
  1445. -jump_table cStr ' jump-table'
  1446. -pathname cStr ' pathname'
  1447. -library_dictionary cStr ' library-dictionary'
  1448. -initialization cStr ' initialization'
  1449. -absolute_bank cStr ' absolute-bank'
  1450. -dp_stack cStr ' direct-page/stack'
  1451. -
  1452. -bank_relative cStr ' bank-relative'
  1453. -skip cStr ' skip'
  1454. -reload cStr ' reload'
  1455. -position_independent cStr ' position-independent'
  1456. -private cStr ' private'
  1457. -
  1458. -dynamic cStr 'dynamic'
  1459. -static cStr 'static'
  1460. -
  1461. -
  1462. -**************************************************
  1463. - sav output.l
  1464. + END OF ARCHIVE
  1465.