home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sources / apple2 / 9 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  62.8 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: v001SRC067:  coff (OMF Disassembler) 02/09
  5. Message-ID: <Nov.8.19.11.28.1992.16608@yoko.rutgers.edu>
  6. Date: 9 Nov 92 00:11:29 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 3531
  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:67
  14. Archive-name: utility/gs/disassem/coff/part02
  15. Architecture: ONLY_2gs
  16. Version-number: 1.1
  17.  
  18.  
  19. =asm.s
  20. - lst off
  21. -
  22. -* UNIX coff utility
  23. -* 65816 OMF disassembler
  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 ;data externals
  34. - put x.general ;general externals
  35. - put x.gsos ;GS/OS i/o externals
  36. - put x.omf ;OMF parser externals
  37. - put x.output ;output externals
  38. - put x.structure ;data structure externals
  39. -
  40. - put 4/gsos.h ;GS/OS defines
  41. - put 4/memory.h ;memory manager defines
  42. - put 4/resource.h ;resouce manager defines
  43. - put 4/texttool.h ;text tool defines
  44. - put 4/env.h ;run-time environment settings
  45. -
  46. - use coff.mac ;macro definitions
  47. - use 4/datatype.mac ;HLL data types
  48. - use 4/env.mac ;run-time environment macros
  49. -
  50. -
  51. -* dp $9x-$cx taken
  52. -
  53. -**************************************************
  54. -* display header for asm disassembly.            *
  55. -**************************************************
  56. -display_header_asm ent
  57. -]segname_handle = $f0 ;handle to segment name
  58. -]segname_ptr = $f4
  59. -]segname_len = $f8 ;length of segment name
  60. -
  61. - ldx @omf+`segname+2
  62. - ldy @omf+`segname
  63. - stx ]segname_handle+2
  64. - sty ]segname_handle
  65. - ldy #2
  66. - lda []segname_handle],y
  67. - sta ]segname_ptr+2
  68. - lda []segname_handle]
  69. - sta ]segname_ptr
  70. - lda []segname_ptr]
  71. - sta ]segname_len
  72. -
  73. - lda ~assembler
  74. - cmp #MERLIN
  75. - bne :orca
  76. - lda #LONGA
  77. - jsr asm_status_bit
  78. - jsr print_offset
  79. - pei ]segname_ptr+2
  80. - pei ]segname_ptr
  81. - pea #2
  82. - pei ]segname_len
  83. - _TextWriteBlock
  84. - lda ]segname_len
  85. - cmp #12
  86. - blt :0
  87. - pea #' '
  88. - _WriteChar
  89. - bra :1
  90. -:0 pea #^blank_str
  91. - pea #blank_str
  92. - pea #0
  93. - sec
  94. - lda #12
  95. - sbc ]segname_len
  96. - pha
  97. - _TextWriteBlock
  98. -:1 pea #^EQU_asm
  99. - pea #EQU_asm
  100. - _WriteCString
  101. - pea #'*'
  102. - _WriteChar
  103. - bra :end
  104. -
  105. -:orca lda #LONGA
  106. - jsr asm_status_bit
  107. - lda #LONGI
  108. - jsr asm_status_bit
  109. - jsr print_offset
  110. - pei ]segname_ptr+2
  111. - pei ]segname_ptr
  112. - pea #2
  113. - pei ]segname_len
  114. - _TextWriteBlock
  115. - lda ]segname_len
  116. - cmp #12
  117. - blt :2
  118. - pea #' '
  119. - _WriteChar
  120. - bra :3
  121. -:2 pea #^blank_str
  122. - pea #blank_str
  123. - pea #0
  124. - sec
  125. - lda #12
  126. - sbc ]segname_len
  127. - pha
  128. - _TextWriteBlock
  129. -:3 lda @omf+`kind
  130. - and #DATA
  131. - cmp #DATA
  132. - bne :start
  133. - pea #^:data_str
  134. - pea #:data_str
  135. - _WriteCString
  136. - bra :end
  137. -:start pea #^:start_str
  138. - pea #:start_str
  139. - _WriteCString
  140. -:end put_cr
  141. - rts
  142. -
  143. -:data_str cStr 'data'
  144. -:start_str cStr 'start'
  145. -
  146. -
  147. -**************************************************
  148. -* display status of accumulator and index        *
  149. -* registers (short/long).                        *
  150. -* ---------------------------------------------- *
  151. -* (input)                                        *
  152. -*  a - display accumulator or index status.      *
  153. -**************************************************
  154. -asm_status_bit equ *
  155. -]status_bit = $e0
  156. -
  157. - sta ]status_bit
  158. -
  159. - jsr print_offset
  160. - pea #^space_12
  161. - pea #space_12
  162. - _WriteCString
  163. - lda ~assembler
  164. - cmp #MERLIN
  165. - bne :orca
  166. -
  167. -:merlin pea #^:mx_str
  168. - pea #:mx_str
  169. - _WriteCString
  170. - ldx #'0'
  171. - lda }shorti
  172. - bne :test_shorta
  173. - ldx #'1'
  174. -:test_shorta phx
  175. - ldx #'0'
  176. - lda }shorta
  177. - bne :merlin_end
  178. - ldx #'1'
  179. -:merlin_end phx
  180. - _WriteChar
  181. - _WriteChar
  182. - put_cr
  183. - rts
  184. -
  185. -:orca lda ]status_bit
  186. - cmp #LONGA
  187. - bne :longi
  188. - pea #^:longa_str
  189. - pea #:longa_str
  190. - _WriteCString
  191. - lda }shorta
  192. - beq :longa_off
  193. - pea #^:off_str
  194. - pea #:off_str
  195. - bra :end
  196. -:longa_off pea #^:on_str
  197. - pea #:on_str
  198. - bra :end
  199. -
  200. -:longi pea #^:longi_str
  201. - pea #:longi_str
  202. - _WriteCString
  203. - lda }shorti
  204. - beq :longi_off
  205. - pea #^:off_str
  206. - pea #:off_str
  207. - bra :end
  208. -:longi_off pea #^:on_str
  209. - pea #:on_str
  210. -
  211. -:end _WriteCString
  212. - put_cr
  213. - rts
  214. -
  215. -:mx_str cStr 'mx     %'
  216. -:longa_str cStr 'longa  '
  217. -:longi_str cStr 'longi  '
  218. -:on_str cStr 'on'
  219. -:off_str cStr 'off'
  220. -
  221. -
  222. -**************************************************
  223. -* parse CONST record for disassembling.          *
  224. -* ---------------------------------------------- *
  225. -* (input)                                        *
  226. -*  a - record number.                            *
  227. -**************************************************
  228. -parse_CONST_asm ent
  229. -]count = $90 ;number of bytes to read
  230. -]edge = $94 ;right margin for output
  231. -]record = $96 ;record number
  232. -]opcode = $98 ;opcode to parse
  233. -]opcode_adr = $9a ;address of opcode data
  234. -
  235. - sta ]record
  236. - stz ]opcode
  237. - stz ]count+2
  238. - stz ]count
  239. -
  240. - cmp #LCONST
  241. - bne :const
  242. - read_long ]count
  243. - clc
  244. - lda @omf+`displacement
  245. - adc #4
  246. - sta @omf+`displacement
  247. - bcc :loop
  248. - inc @omf+`displacement+2
  249. - bra :loop
  250. -:const sta ]count
  251. -
  252. -:loop lda ]count
  253. - ora ]count+2
  254. - bne :print_opcode
  255. - rts
  256. -:print_opcode read_char ]opcode
  257. - pea #^space_12 ;indent to print opcode and operand
  258. - pea #space_12
  259. - _WriteCString
  260. - lda ]opcode
  261. - asl
  262. - tax
  263. - lda ~opcodes,x
  264. - sta ]opcode_adr
  265. - ldy #`num_bytes ;parse opcode depending on number
  266. - lda (]opcode_adr),y ;of bytes it takes
  267. - cmp #1
  268. - bne :2_bytes
  269. - lda ]opcode
  270. - jsr parse_opcode_1
  271. - lda ]count
  272. - bne :0
  273. - dec ]count+2
  274. -:0 dec ]count
  275. - bra :end_loop
  276. -:2_bytes cmp #2
  277. - bne :3_bytes
  278. - lda ]opcode
  279. - ldx ]count+2
  280. - ldy ]count
  281. - jsr parse_opcode_2
  282. - stx ]count+2
  283. - sty ]count
  284. - bra :end_loop
  285. -:3_bytes cmp #3
  286. - bne :4_bytes
  287. - lda ]opcode
  288. - ldx ]count+2
  289. - ldy ]count
  290. - jsr parse_opcode_3
  291. - stx ]count+2
  292. - sty ]count
  293. - bra :end_loop
  294. -:4_bytes lda ]opcode
  295. - ldx ]count+2
  296. - ldy ]count
  297. - jsr parse_opcode_4
  298. - stx ]count+2
  299. - sty ]count
  300. -
  301. -:end_loop lda }nooffset
  302. - beq :1
  303. - brl :loop
  304. -:1 lda ]count+2
  305. - ora ]count
  306. - beq :end
  307. - jsr print_offset
  308. - brl :loop
  309. -:end rts
  310. -
  311. -
  312. -**************************************************
  313. -* parse opcodes that accept 1-byte operands.     *
  314. -* ---------------------------------------------- *
  315. -* (input)                                        *
  316. -*  a - opcode.                                   *
  317. -**************************************************
  318. -parse_opcode_1 equ *
  319. -]opcode = $a0 ;opcode
  320. -]opcode_adr = $a2 ;pointer to information about opcode
  321. -]opcode_syntax = $a4 ;string syntax of opcode
  322. -
  323. - sta ]opcode
  324. - asl
  325. - tax
  326. - lda ~opcodes,x
  327. - sta ]opcode_adr
  328. -
  329. - pea #^parse_opcode_1
  330. - clc
  331. - lda ]opcode_adr
  332. - adc #`syntax
  333. - pha
  334. - _WriteCString
  335. -
  336. - ldy #`mode
  337. - lda (]opcode_adr),y
  338. - cmp #ACCUMULATOR
  339. - bne :0
  340. - lda ~assembler
  341. - cmp #ORCA
  342. - bne :0
  343. - pea #'a'
  344. - bra :1
  345. -:0 pea #' '
  346. -:1 _WriteChar
  347. -
  348. - lda }hex
  349. - beq :2
  350. - pea #^blank_str ;separate asm/hex-ascii output
  351. - pea #blank_str
  352. - pea #0
  353. - pea #24
  354. - _TextWriteBlock
  355. -:2 lda ]opcode
  356. - ora #$0100
  357. - ldx #0
  358. - txy
  359. - jsr print_hex_ascii
  360. - incr @omf+`displacement
  361. - incr @omf+`counter
  362. -:end rts
  363. -
  364. -
  365. -**************************************************
  366. -* parse opcodes that accept 2-byte operands.     *
  367. -* ---------------------------------------------- *
  368. -* (input)                                        *
  369. -*  a - opcode.                                   *
  370. -*  x - HOW of number of bytes to disassemble.    *
  371. -*  y - LOW of number of bytes to disassemble.    *
  372. -* (output)                                       *
  373. -*  x - HOW of number of bytes to disassemble.    *
  374. -*  y - LOW of number of bytes to disassemble.    *
  375. -**************************************************
  376. -parse_opcode_2 equ *
  377. -]opcode = $a0 ;opcode
  378. -]count = $a2 ;number of bytes to disassemble
  379. -]operand = $a6 ;operand of opcode
  380. -]opcode_adr = $a8 ;pointer to information about opcode
  381. -
  382. - sta ]opcode
  383. - stx ]count+2
  384. - sty ]count
  385. - stz ]operand
  386. - asl
  387. - tax
  388. - lda ~opcodes,x
  389. - sta ]opcode_adr
  390. -
  391. - ldy #`m ;test if operand affected by short
  392. - lda (]opcode_adr),y ;accumulator
  393. - beq :test_i
  394. - lda }shorta
  395. - beq :short
  396. -:test_i ldy #`i ;test if operand affected by short
  397. - lda (]opcode_adr),y ;indexes
  398. - bne :test_short
  399. - brl :print_opcode
  400. -:test_short lda }shorti
  401. - beq :short
  402. - brl :print_opcode
  403. -:short lda ]count+2
  404. - bne :0
  405. - lda ]count
  406. - cmp #3
  407. - blt :3
  408. -:0 incr #3;@omf+`displacement
  409. - incr #3;@omf+`counter
  410. - read_short ]operand ;because shorta or shorti is not
  411. - lda }tool ;active, read in two byte operand
  412. - beq :1
  413. - lda ]opcode
  414. - cmp #LDX
  415. - bne :1
  416. - pei ]count+2
  417. - pei ]count
  418. - pei ]operand
  419. - pei ]opcode
  420. - jsr parse_stack
  421. - stx ]count+2
  422. - sty ]count
  423. - bra :2
  424. -:1 lda ]opcode
  425. - ldx ]operand
  426. - jsr print_opcode_3
  427. -:2 sec
  428. - lda ]count
  429. - sbc #3
  430. - tay
  431. - lda ]count+2
  432. - sbc #0
  433. - tax
  434. - rts
  435. -
  436. -:3 cmp #2
  437. - beq :5
  438. - clc
  439. - lda @omf+`counter
  440. - adc #3
  441. - tax
  442. - lda @omf+`counter+2
  443. - adc #0
  444. - cmp @omf+`length+2
  445. - blt :4
  446. - cpx @omf+`length
  447. - beq :4
  448. - blt :5
  449. -:4 lda ]opcode
  450. - jsr parse_expr_asm
  451. - bra :6
  452. -:5 lda ]opcode
  453. - ldx ]count
  454. - jsr print_byte
  455. -:6 ldx #0
  456. - txy
  457. - rts
  458. -
  459. -:print_opcode lda ]count+2
  460. - bne :8
  461. - lda ]count
  462. - cmp #2
  463. - blt :9
  464. -:8 lda ]opcode
  465. - jsr print_opcode_2
  466. - sec
  467. - lda ]count
  468. - sbc #2
  469. - tay
  470. - lda ]count+2
  471. - sbc #0
  472. - tax
  473. - rts
  474. -:9 clc
  475. - lda @omf+`counter
  476. - adc #2
  477. - tax
  478. - lda @omf+`counter+2
  479. - adc #0
  480. - cmp @omf+`length+2
  481. - blt :10
  482. - cpx @omf+`length
  483. - beq :10
  484. - bge :11
  485. -:10 lda ]opcode
  486. - jsr parse_expr_asm
  487. - bra :12
  488. -:11 lda ]opcode
  489. - ldx ]count
  490. - jsr print_byte
  491. -:12 ldx #0
  492. - txy
  493. - rts
  494. -
  495. -
  496. -**************************************************
  497. -* print opcodes that generate two bytes.         *
  498. -* ---------------------------------------------- *
  499. -* (input)                                        *
  500. -*  a - opcode.                                   *
  501. -**************************************************
  502. -print_opcode_2 equ *
  503. -]opcode = $b0 ;opcode
  504. -]operand = $b2 ;operand of opcode
  505. -]opcode_adr = $b4 ;pointer to information about opcode
  506. -]opcode_syntax = $b6 ;string syntax of opcode
  507. -]offset = $b8 ;offset into line
  508. -
  509. - sta ]opcode
  510. - stz ]operand
  511. - asl
  512. - tax
  513. - lda ~opcodes,x
  514. - sta ]opcode_adr
  515. -
  516. - read_char ]operand
  517. - ldy #`mode
  518. - lda (]opcode_adr),y
  519. - cmp #PC_RELATIVE
  520. - bne :2
  521. - lda ]operand
  522. - cmp #$80
  523. - bge :sub_operand
  524. -:add_operand clc
  525. - lda @omf+`counter
  526. - adc ]operand
  527. - bra :printf
  528. -:sub_operand sec ;@omf+`counter+($ff-]operand)
  529. - lda @omf+`counter
  530. - sbc #$100
  531. - clc
  532. - adc ]operand
  533. -:printf inc
  534. - inc
  535. - tay
  536. - ldx #0
  537. - clc
  538. - lda ]opcode_adr
  539. - adc #`syntax
  540. - jsr printf
  541. - stx ]offset
  542. - pea #^:space
  543. - pea #:space
  544. - _WriteCString
  545. - clc
  546. - lda #4
  547. - adc ]offset
  548. - sta ]offset
  549. - ldx #'+'
  550. - lda ]operand
  551. - cmp #$80
  552. - blt :print_char
  553. - ldx #'-'
  554. -:print_char phx
  555. - _WriteChar
  556. - inc ]offset
  557. - ldx ]operand
  558. - cpx #$80
  559. - blt :print_operand
  560. - sec
  561. - lda #$100
  562. - sbc ]operand
  563. - tax
  564. -:print_operand jsr print_fix_char_hex
  565. - inc ]offset
  566. - inc ]offset
  567. - pea #'}'
  568. - _WriteChar
  569. - inc ]offset
  570. - bra :print_hex
  571. -
  572. -:2 clc
  573. - lda ]opcode_adr
  574. - adc #`syntax
  575. - ldx ]operand+2
  576. - ldy ]operand
  577. - jsr printf
  578. - stx ]offset
  579. -
  580. -:print_hex lda }hex
  581. - beq :3
  582. - pea #^blank_str ;separate asm/hex-ascii output
  583. - pea #blank_str
  584. - pea #0
  585. - sec
  586. - lda #32
  587. - sbc ]offset
  588. - pha
  589. - _TextWriteBlock
  590. -:3 lda ]opcode
  591. - ora #$0200
  592. - ldx #0
  593. - ldy ]operand
  594. - jsr print_hex_ascii
  595. - lda ]opcode
  596. - cmp #REP
  597. - beq :parse_rep_sep
  598. - cmp #SEP
  599. - bne :4
  600. -
  601. -:parse_rep_sep lda ]opcode
  602. - ldx ]operand
  603. - jsr parse_rep_sep
  604. -
  605. -:4 incr #2;@omf+`displacement
  606. - incr #2;@omf+`counter
  607. - rts
  608. -
  609. -:space cStr '   {'
  610. -
  611. -
  612. -**************************************************
  613. -* parse opcodes that accept 3-byte operands.     *
  614. -* ---------------------------------------------- *
  615. -* (input)                                        *
  616. -*  a - opcode.                                   *
  617. -*  x - HOW of number of bytes to disassemble.    *
  618. -*  y - LOW of number of bytes to disassemble.    *
  619. -* (output)                                       *
  620. -*  x - HOW of number of bytes to disassemble.    *
  621. -*  y - LOW of number of bytes to disassemble.    *
  622. -**************************************************
  623. -parse_opcode_3 equ *
  624. -]opcode = $a0 ;opcode
  625. -]count = $a2 ;number of bytes to disassemble
  626. -]tmp_count = $a6
  627. -]operand = $aa ;operand of opcode
  628. -
  629. - sta ]opcode
  630. - stx ]count+2
  631. - sty ]count
  632. -
  633. - cpx #1 ;expand opcode only if 3 bytes
  634. - bge :print_opcode ;available
  635. - cpy #3
  636. - bge :print_opcode
  637. - cpy #2 ;test if two bytes left in three-byte
  638. - beq :1 ;opcode/operand. if so, print bytes.
  639. - clc ;test if at end of OMF segment
  640. - lda @omf+`counter
  641. - adc #3
  642. - tax
  643. - lda @omf+`counter+2
  644. - adc #0
  645. - cmp @omf+`length+2
  646. - blt :0
  647. - cpx @omf+`length
  648. - beq :0
  649. - bge :1
  650. -:0 lda ]opcode
  651. - jsr parse_expr_asm
  652. - bra :2
  653. -:1 lda ]opcode
  654. - ldx ]count
  655. - jsr print_byte
  656. -:2 ldx #0
  657. - txy
  658. - rts
  659. -
  660. -:print_opcode incr #3;@omf+`displacement
  661. - incr #3;@omf+`counter
  662. - read_short ]operand
  663. - lda }tool
  664. - beq :5
  665. - lda ]opcode
  666. - cmp #JSR
  667. - bne :4
  668. - lda ]operand
  669. - ldx ]count+2
  670. - ldy ]count
  671. - jsr parse_inline_3
  672. - stx ]tmp_count+2
  673. - sty ]tmp_count
  674. - cpx ]count+2
  675. - bne :3
  676. - cpy ]count
  677. - bne :3
  678. - lda ]opcode
  679. - ldx ]operand
  680. - jsr print_opcode_3
  681. - bra :end
  682. -:3 ldx ]tmp_count+2
  683. - ldy ]tmp_count
  684. - stx ]count+2
  685. - sty ]count
  686. - bra :end
  687. -:4 lda ]opcode
  688. - cmp #PEA
  689. - bne :5
  690. - pei ]count+2
  691. - pei ]count
  692. - pei ]operand
  693. - pei ]opcode
  694. - jsr parse_stack
  695. - stx ]count+2
  696. - sty ]count
  697. - bra :end
  698. -:5 lda ]opcode
  699. - ldx ]operand
  700. - jsr print_opcode_3
  701. -
  702. -:end sec
  703. - lda ]count
  704. - sbc #3
  705. - tay
  706. - lda ]count+2
  707. - sbc #0
  708. - tax
  709. - rts
  710. -
  711. -
  712. -**************************************************
  713. -* print opcodes that generate three bytes.       *
  714. -* ---------------------------------------------- *
  715. -* (input)                                        *
  716. -*  a - opcode.                                   *
  717. -*  x - operand.                                  *
  718. -**************************************************
  719. -print_opcode_3 equ *
  720. -]opcode = $b0 ;opcode
  721. -]operand = $b2 ;operand of opcode
  722. -]opcode_adr = $b4 ;pointer to information about opcode
  723. -]offset = $b6 ;offset into line
  724. -]ROM_ptr = $b8 ;pointer to ROM name
  725. -
  726. - sta ]opcode
  727. - stx ]operand
  728. - asl
  729. - tax
  730. - lda ~opcodes,x
  731. - sta ]opcode_adr
  732. - stz ]offset
  733. -
  734. - ldy #`mode
  735. - lda (]opcode_adr),y
  736. - cmp #ABSOLUTE
  737. - bne :pc_relative_long
  738. - lda }tool
  739. - bne :ROM_tool
  740. - brl :default
  741. -:ROM_tool ldx ]operand
  742. - ldy #0
  743. - jsr name_ROM
  744. - stx ]ROM_ptr
  745. - sty ]ROM_ptr+2
  746. - bcc :print_ROM
  747. - brl :default
  748. -:print_ROM phy
  749. - phx
  750. - pea #^print_opcode_3
  751. - clc
  752. - lda ]opcode_adr
  753. - adc #`syntax
  754. - pha
  755. - pea #0
  756. - pea #7
  757. - _TextWriteBlock
  758. - _WriteString
  759. - lda []ROM_ptr]
  760. - and #$ff
  761. - clc
  762. - adc #7
  763. - sta ]offset
  764. - brl :end
  765. -
  766. -:pc_relative_long cmp #PC_RELATIVE_LONG
  767. - bne :block_move
  768. - lda ]operand
  769. - bmi :sub_operand
  770. -:add_operand clc
  771. - lda @omf+`counter
  772. - adc ]operand
  773. - bra :printf
  774. -:sub_operand sec
  775. - lda @omf+`counter
  776. - sbc ]operand
  777. -:printf inc
  778. - inc
  779. - tay
  780. - ldx #0
  781. - clc
  782. - lda ]opcode_adr
  783. - adc #`syntax
  784. - jsr printf
  785. - stx ]offset
  786. - pea #^:space
  787. - pea #:space
  788. - _WriteCString
  789. - ldx #'+'
  790. - lda ]operand
  791. - bpl :print_char
  792. - ldx #'-'
  793. -:print_char phx
  794. - _WriteChar
  795. - ldx ]operand
  796. - bpl :print_operand
  797. - sec
  798. - lda #$ffff
  799. - sbc ]operand
  800. - inc
  801. - tax
  802. -:print_operand lda #4
  803. - jsr print_fix_short_hex
  804. - clc
  805. - lda ]offset
  806. - adc #10
  807. - sta ]offset
  808. - pea #'}'
  809. - _WriteChar
  810. - brl :end
  811. -
  812. -:block_move cmp #BLOCK_MOVE
  813. - bne :immediate
  814. - pea #^print_opcode_3
  815. - clc
  816. - lda ]opcode_adr
  817. - adc #`syntax
  818. - pha
  819. - _WriteCString
  820. - lda ]operand
  821. - xba
  822. - and #$ff
  823. - tax
  824. - jsr print_fix_char_hex
  825. - pea #','
  826. - _WriteChar
  827. - pea #'$'
  828. - _WriteChar
  829. - lda ]operand
  830. - and #$ff
  831. - tax
  832. - jsr print_fix_char_hex
  833. - lda #14
  834. - sta ]offset
  835. - bra :end
  836. -
  837. -:immediate cmp #IMMEDIATE
  838. - bne :default
  839. - ldy #`syntax+10
  840. - shorta
  841. - lda (]opcode_adr),y
  842. - pha
  843. - lda #'4'
  844. - sta (]opcode_adr),y
  845. - longa
  846. - clc
  847. - lda ]opcode_adr
  848. - adc #`syntax
  849. - ldx #0
  850. - ldy ]operand
  851. - jsr printf
  852. - stx ]offset
  853. - ldy #`syntax+10
  854. - shorta
  855. - pla
  856. - sta (]opcode_adr),y
  857. - longa
  858. - bra :end
  859. -
  860. -:default clc
  861. - lda ]opcode_adr
  862. - adc #`syntax
  863. - ldx #0
  864. - ldy ]operand
  865. - jsr printf
  866. - stx ]offset
  867. -
  868. -:end lda }hex
  869. - beq :9
  870. - pea #^blank_str ;separate asm/hex-ascii output
  871. - pea #blank_str
  872. - pea #0
  873. - sec
  874. - lda #32
  875. - sbc ]offset
  876. - pha
  877. - _TextWriteBlock
  878. -:9 lda ]opcode
  879. - ora #$0300
  880. - ldx #0
  881. - ldy ]operand
  882. - jsr print_hex_ascii
  883. - rts
  884. -
  885. -:space cStr '   {'
  886. -
  887. -
  888. -**************************************************
  889. -* parse GS/OS inline calls for opcodes           *
  890. -* generating three bytes.                        *
  891. -* ---------------------------------------------- *
  892. -* (input)                                        *
  893. -*  a - operand (GS/OS entry point).              *
  894. -*  x - HOW of number of bytes to disassemble.    *
  895. -*  y - LOW of number of bytes to disassemble.    *
  896. -* (output)                                       *
  897. -*  x - HOW of number of bytes to disassemble.    *
  898. -*  y - LOW of number of bytes to disassemble.    *
  899. -**************************************************
  900. -parse_inline_3 equ *
  901. -]callnum = $b0 ;GS/OS call number
  902. -]assembler = $b2 ;temp copy of ~assembler
  903. -]count = $b2 ;number of bytes left to disassemble
  904. -]mark = $b6 ;current offset into OMF file
  905. -]parmblock = $ba ;parameter block number for call
  906. -
  907. - sta ]callnum
  908. - stx ]count+2
  909. - sty ]count
  910. -
  911. - cmp #PRODOS_MLI
  912. - beq :parse_inline
  913. - ldx ]count+2
  914. - ldy ]count
  915. - rts
  916. -
  917. -:parse_inline jsr GSOSget_mark
  918. - stx ]mark+2
  919. - sty ]mark
  920. -
  921. - ldx ]count+2
  922. - bne :4_bytes
  923. - lda ]count
  924. - cmp #3
  925. - bne :4_bytes
  926. - brl :end
  927. -
  928. -:4_bytes cpx #0
  929. - bne :default
  930. - cmp #4
  931. - beq :0
  932. - bra :default
  933. -:0 stz ]callnum
  934. - read_char ]callnum
  935. - lda ]callnum
  936. - jsr name_GSOS
  937. - bcc :1
  938. - ldx ]mark+2
  939. - ldy ]mark
  940. - jsr GSOSset_mark
  941. - brl :end
  942. -:1 phy
  943. - phx
  944. - incr @omf+`displacement
  945. - incr @omf+`counter
  946. - pea #'_'
  947. - _WriteChar
  948. - _WriteString
  949. - pea #' '
  950. - _WriteChar
  951. - lda ~assembler
  952. - sta ]assembler
  953. - lda #MERLIN
  954. - sta ~assembler
  955. - lda #DC
  956. - jsr parse_expr_asm
  957. - lda ]assembler
  958. - sta ~assembler
  959. - ldx #0
  960. - ldy #3
  961. - rts
  962. -
  963. -:default stz ]callnum
  964. - read_char ]callnum
  965. - read_short ]parmblock
  966. - lda ]callnum
  967. - jsr name_GSOS
  968. - bcc :2
  969. - ldx ]mark+2
  970. - ldy ]mark
  971. - jsr GSOSset_mark
  972. - brl :end
  973. -:2 phy
  974. - phx
  975. - pea #'_'
  976. - _WriteChar
  977. - _WriteString
  978. - pea #' '
  979. - _WriteChar
  980. - pea #'$'
  981. - _WriteChar
  982. - lda #4
  983. - ldx ]parmblock
  984. - jsr print_fix_short_hex
  985. - put_cr
  986. - incr #3;@omf+`displacement
  987. - incr #3;@omf+`counter
  988. - decr #3;]count
  989. -
  990. -:end ldx ]count+2
  991. - ldy ]count
  992. - rts
  993. -
  994. -
  995. -**************************************************
  996. -* parse stack-based GS/OS call.                  *
  997. -* ---------------------------------------------- *
  998. -* (input)                                        *
  999. -*  long - number of bytes to disassemble.        *
  1000. -*  word - operand.                               *
  1001. -*  word - opcode.                                *
  1002. -* (output)                                       *
  1003. -*  x - HOW of number of bytes to disassemble.    *
  1004. -*  y - LOW of number of bytes to disassemble.    *
  1005. -**************************************************
  1006. -parse_stack equ *
  1007. -]opcode = $c0 ;opcode
  1008. -]operand = $c2 ;opcode operand
  1009. -]count = $c4 ;number of bytes left to disassemble
  1010. -]mark = $c8 ;offset into OMF file
  1011. -]jsl = $cc ;next operand
  1012. -]callnum = $ce ;operand call address
  1013. -
  1014. - pla ;return address
  1015. - plx
  1016. - ply
  1017. - stx ]opcode
  1018. - sty ]operand
  1019. - plx ;number of bytes to disassemble
  1020. - ply
  1021. - stx ]count
  1022. - sty ]count+2
  1023. - pha ;push return back on stack
  1024. -
  1025. - bne :parse_stack
  1026. - cpx #7
  1027. - bge :parse_stack
  1028. - brl :2
  1029. -
  1030. -:parse_stack jsr GSOSget_mark
  1031. - stx ]mark+2
  1032. - sty ]mark
  1033. - stz ]jsl
  1034. - stz ]callnum+2
  1035. - read_char ]jsl ;test if next opcode is JSL
  1036. - clc
  1037. - tdc
  1038. - adc #]callnum
  1039. - tax
  1040. - ldy #0
  1041. - lda #3
  1042. - jsr GSOSread
  1043. -
  1044. - ldx ]jsl
  1045. - lda }tool
  1046. - beq :1
  1047. - cpx #JSL
  1048. - bne :1
  1049. - lda ]callnum+2
  1050. - cmp #^GSOS_STACK ;and TOOL_STACK and TOOL_STACK_ALT
  1051. - bne :1
  1052. - lda ]callnum
  1053. - cmp #TOOL_STACK
  1054. - beq :name_tool
  1055. - cmp #TOOL_STACK_ALT
  1056. - beq :name_tool
  1057. - cmp #GSOS_STACK
  1058. - bne :1
  1059. -
  1060. -:name_gsos lda ]operand
  1061. - jsr name_GSOS
  1062. - bra :0
  1063. -:name_tool lda ]operand
  1064. - jsr name_TOOL
  1065. -:0 bcs :1
  1066. - phy
  1067. - phx
  1068. - incr #4;@omf+`displacement
  1069. - incr #4;@omf+`counter
  1070. - pea #'_'
  1071. - _WriteChar
  1072. - _WriteString
  1073. - put_cr
  1074. - decr #4;]count
  1075. - bra :end
  1076. -
  1077. -:1 ldx ]mark+2
  1078. - ldy ]mark
  1079. - jsr GSOSset_mark
  1080. -:2 lda ]opcode
  1081. - ldx ]operand
  1082. - jsr print_opcode_3
  1083. -
  1084. -:end ldx ]count+2
  1085. - ldy ]count
  1086. - rts
  1087. -
  1088. -
  1089. -**************************************************
  1090. -* parse opcodes that accept 4-byte operands.     *
  1091. -* ---------------------------------------------- *
  1092. -* (input)                                        *
  1093. -*  a - opcode.                                   *
  1094. -*  x - HOW of number of bytes to disassemble.    *
  1095. -*  y - LOW of number of bytes to disassemble.    *
  1096. -* (output)                                       *
  1097. -*  x - HOW of number of bytes to disassemble.    *
  1098. -*  y - LOW of number of bytes to disassemble.    *
  1099. -**************************************************
  1100. -parse_opcode_4 equ *
  1101. -]opcode = $a0 ;opcode
  1102. -]count = $a2 ;number of bytes to disassemble
  1103. -]tmp_count = $a6
  1104. -]operand = $aa ;operand of opcode
  1105. -
  1106. - sta ]opcode
  1107. - stx ]count+2
  1108. - sty ]count
  1109. - stz ]operand+2
  1110. -
  1111. - cpx #0
  1112. - bne :print_opcode
  1113. - cpy #4
  1114. - bge :print_opcode
  1115. - cpy #3
  1116. - beq :1
  1117. - cpy #2
  1118. - beq :1
  1119. - clc
  1120. - lda @omf+`counter
  1121. - adc #4
  1122. - tax
  1123. - lda @omf+`counter+2
  1124. - adc #0
  1125. - cmp @omf+`length+2
  1126. - blt :0
  1127. - cpx @omf+`length
  1128. - beq :0
  1129. - bge :1
  1130. -:0 lda ]opcode
  1131. - jsr parse_expr_asm
  1132. - bra :2
  1133. -:1 lda ]opcode
  1134. - ldx ]count
  1135. - jsr print_byte
  1136. -:2 ldx #0
  1137. - txy
  1138. - pla
  1139. - rts
  1140. -
  1141. -:print_opcode incr #4;@omf+`displacement
  1142. - incr #4;@omf+`counter
  1143. - clc
  1144. - tdc
  1145. - adc #]operand
  1146. - tax
  1147. - ldy #0
  1148. - lda #3
  1149. - jsr GSOSread
  1150. - lda }tool
  1151. - beq :4
  1152. - lda ]opcode
  1153. - cmp #JSL
  1154. - bne :4
  1155. - pei ]count+2
  1156. - pei ]count
  1157. - pei ]operand+2
  1158. - pei ]operand
  1159. - jsr parse_inline_4
  1160. - stx ]tmp_count+2
  1161. - sty ]tmp_count
  1162. - cpx ]count+2
  1163. - bne :3
  1164. - cpy ]count
  1165. - bne :3
  1166. - lda ]opcode
  1167. - ldx ]operand+2
  1168. - ldy ]operand
  1169. - jsr print_opcode_4
  1170. - bra :end
  1171. -:3 ldx ]tmp_count+2
  1172. - ldy ]tmp_count
  1173. - stx ]count+2
  1174. - sty ]count
  1175. - bra :end
  1176. -:4 lda ]opcode
  1177. - ldx ]operand+2
  1178. - ldy ]operand
  1179. - jsr print_opcode_4
  1180. -
  1181. -:end sec
  1182. - lda ]count
  1183. - sbc #4
  1184. - tay
  1185. - lda ]count+2
  1186. - sbc #0
  1187. - tax
  1188. - rts
  1189. -
  1190. -
  1191. -**************************************************
  1192. -* print opcodes that generate four bytes.        *
  1193. -* ---------------------------------------------- *
  1194. -* (input)                                        *
  1195. -*  a - opcode.                                   *
  1196. -*  x - HOW of operand.                           *
  1197. -*  y - LOW of operand.                           *
  1198. -**************************************************
  1199. -print_opcode_4 equ *
  1200. -]opcode = $b0 ;opcode
  1201. -]operand = $b2 ;operand of opcode
  1202. -]opcode_adr = $b6 ;pointer to information about opcode
  1203. -]ROM_handle = $b8 ;handle to ROM equivalent call
  1204. -]ROM_ptr = $b8
  1205. -]offset = $bc
  1206. -
  1207. - sta ]opcode
  1208. - stx ]operand+2
  1209. - sty ]operand
  1210. - asl
  1211. - tax
  1212. - lda ~opcodes,x
  1213. - sta ]opcode_adr
  1214. -
  1215. - lda }tool
  1216. - bne :test_mode
  1217. - brl :print_opcode
  1218. -:test_mode ldy #`mode
  1219. - lda (]opcode_adr),y
  1220. - cmp #ABSOLUTE_LONG
  1221. - beq :print_ROM
  1222. - brl :print_opcode
  1223. -:print_ROM lda ]operand+2
  1224. - cmp #$e0
  1225. - bne :0
  1226. - ldx ]operand
  1227. - ldy #0
  1228. - jsr name_ROM
  1229. - stx ]ROM_ptr
  1230. - sty ]ROM_ptr+2
  1231. - bra :1
  1232. -:0 ldx ]operand
  1233. - ldy ]operand+2
  1234. - jsr name_ROM
  1235. - stx ]ROM_ptr
  1236. - sty ]ROM_ptr+2
  1237. -:1 bcs :print_opcode ;if ROM call not found
  1238. - phy
  1239. - phx
  1240. - pea #^print_opcode_4
  1241. - clc
  1242. - lda ]opcode_adr
  1243. - adc #`syntax
  1244. - pha
  1245. - pea #0
  1246. - pea #7
  1247. - _TextWriteBlock
  1248. - lda #7
  1249. - sta ]offset
  1250. - lda ]operand+2
  1251. - cmp #$e0
  1252. - bne :2
  1253. - pea #^:e0_str
  1254. - pea #:e0_str
  1255. - _WriteCString
  1256. - inc ]offset
  1257. - inc ]offset
  1258. - inc ]offset
  1259. -:2 _WriteString
  1260. - lda []ROM_ptr]
  1261. - and #$ff
  1262. - adc ]offset
  1263. - sta ]offset
  1264. - bra :end
  1265. -
  1266. -:print_opcode clc
  1267. - lda ]opcode_adr
  1268. - adc #`syntax
  1269. - ldx ]operand+2
  1270. - ldy ]operand
  1271. - jsr printf
  1272. - stx ]offset
  1273. -
  1274. -:end lda }hex
  1275. - beq :3
  1276. - pea #^blank_str ;separate asm/hex-ascii output
  1277. - pea #blank_str
  1278. - pea #0
  1279. - sec
  1280. - lda #32
  1281. - sbc ]offset
  1282. - pha
  1283. - _TextWriteBlock
  1284. -:3 lda ]opcode
  1285. - ora #$0400
  1286. - ldx ]operand+2
  1287. - ldy ]operand
  1288. - jsr print_hex_ascii
  1289. - rts
  1290. -
  1291. -:e0_str cStr 'e0_'
  1292. -
  1293. -
  1294. -**************************************************
  1295. -* parse GS/OS inline calls for opcodes           *
  1296. -* generating four bytes.                         *
  1297. -* ---------------------------------------------- *
  1298. -* (input)                                        *
  1299. -*  long - number of bytes left to disassemble.   *
  1300. -*  long - value of operand.                      *
  1301. -* (output)                                       *
  1302. -*  x - HOW of number of bytes to disassemble.    *
  1303. -*  y - LOW of number of bytes to disassemble.    *
  1304. -**************************************************
  1305. -parse_inline_4 equ *
  1306. -]callnum = $b0 ;GS/OS call number
  1307. -]assembler = $b4 ;temp copy of ~assembler
  1308. -]count = $b4 ;number of bytes left to disassemble
  1309. -]mark = $b8 ;current offset into OMF file
  1310. -]parmblock = $bc ;parameter block number for call
  1311. -
  1312. - pla ;return address
  1313. - plx
  1314. - ply
  1315. - stx ]callnum
  1316. - sty ]callnum+2
  1317. - plx
  1318. - ply
  1319. - stx ]count
  1320. - sty ]count+2
  1321. - pha ;push return address back on stack
  1322. -
  1323. - ldx ]callnum
  1324. - cpx #GSOS_INLINE
  1325. - bne :false
  1326. - ldx ]callnum+2
  1327. - cpx #^GSOS_INLINE
  1328. - beq :parse_inline
  1329. -:false ldx ]count+2
  1330. - ldy ]count
  1331. - rts
  1332. -
  1333. -:parse_inline jsr GSOSget_mark
  1334. - stx ]mark+2
  1335. - sty ]mark
  1336. -
  1337. - ldx ]count+2
  1338. - bne :6_bytes
  1339. - lda ]count
  1340. - cmp #4
  1341. - bne :6_bytes
  1342. - brl :end
  1343. -
  1344. -:6_bytes cpx #0
  1345. - bne :default
  1346. - cmp #6
  1347. - beq :0
  1348. - bra :default
  1349. -:0 read_short ]callnum
  1350. - lda ]callnum
  1351. - jsr name_GSOS
  1352. - bcc :1
  1353. - ldx ]mark+2
  1354. - ldy ]mark
  1355. - jsr GSOSset_mark
  1356. - brl :end
  1357. -:1 phy
  1358. - phx
  1359. - incr #2;@omf+`displacement
  1360. - incr #2;@omf+`counter
  1361. - pea #'_'
  1362. - _WriteChar
  1363. - _WriteString
  1364. - pea #' '
  1365. - _WriteChar
  1366. - lda ~assembler
  1367. - sta ]assembler
  1368. - lda #MERLIN
  1369. - sta ~assembler
  1370. - lda #DC
  1371. - jsr parse_expr_asm
  1372. - lda ]assembler
  1373. - sta ~assembler
  1374. - ldx #0
  1375. - ldy #4
  1376. - rts
  1377. -
  1378. -:default read_short ]callnum
  1379. - read_long ]parmblock
  1380. - lda ]callnum
  1381. - jsr name_GSOS
  1382. - bcc :2
  1383. - ldx ]mark+2
  1384. - ldy ]mark
  1385. - jsr GSOSset_mark
  1386. - brl :end
  1387. -:2 phy
  1388. - phx
  1389. - pea #'_'
  1390. - _WriteChar
  1391. - _WriteString
  1392. - pea #' '
  1393. - _WriteChar
  1394. - pea #'$'
  1395. - _WriteChar
  1396. - lda #6
  1397. - ldx ]parmblock
  1398. - ldy ]parmblock+2
  1399. - jsr print_fix_long_hex
  1400. - put_cr
  1401. - incr #6;@omf+`displacement
  1402. - incr #6;@omf+`counter
  1403. - decr #6;]count
  1404. -
  1405. -:end ldx ]count+2
  1406. - ldy ]count
  1407. - rts
  1408. -
  1409. -
  1410. -**************************************************
  1411. -* output hex and ascii equivalent of operand     *
  1412. -* bytes.                                         *
  1413. -* ---------------------------------------------- *
  1414. -* (input)                                        *
  1415. -*  a - LOB opcode.                               *
  1416. -*    - HOB number of bytes generated by opcode.  *
  1417. -*  x - HOW of operand.                           *
  1418. -*  y - LOW of operand.                           *
  1419. -**************************************************
  1420. -print_hex_ascii equ *
  1421. -]opcode = $b0 ;opcode
  1422. -]operand = $b2 ;operand
  1423. -]opcode_adr = $b6 ;pointer to information about opcode
  1424. -]num_bytes = $b8 ;number of bytes generated by opcode
  1425. -
  1426. - stx ]operand+2
  1427. - sty ]operand
  1428. - tax
  1429. - xba
  1430. - and #$ff
  1431. - sta ]num_bytes
  1432. - txa
  1433. - and #$ff
  1434. - sta ]opcode
  1435. - asl
  1436. - tax
  1437. - lda ~opcodes,x
  1438. - sta ]opcode_adr
  1439. -
  1440. - lda }hex
  1441. - bne :print_hex
  1442. - put_cr
  1443. - rts
  1444. -
  1445. -:print_hex pea #' '
  1446. - _WriteChar
  1447. - lda ]num_bytes ;parse opcode depending on number of
  1448. - cmp #1 ;bytes generated
  1449. - bne :2_bytes
  1450. - ldx ]opcode
  1451. - jsr print_fix_char_hex
  1452. - pea #^:space_1
  1453. - pea #:space_1
  1454. - _WriteCString
  1455. - lda ]opcode
  1456. - jsr print_ascii
  1457. - brl :end
  1458. -:2_bytes cmp #2
  1459. - bne :3_bytes
  1460. - ldx ]opcode
  1461. - jsr print_fix_char_hex
  1462. - pea #' '
  1463. - _WriteChar
  1464. - ldx ]operand
  1465. - jsr print_fix_char_hex
  1466. - pea #^:space_2
  1467. - pea #:space_2
  1468. - _WriteCString
  1469. - lda ]opcode
  1470. - jsr print_ascii
  1471. - lda ]operand
  1472. - jsr print_ascii
  1473. - brl :end
  1474. -:3_bytes cmp #3
  1475. - bne :4_bytes
  1476. - ldx ]opcode
  1477. - jsr print_fix_char_hex
  1478. - pea #' '
  1479. - _WriteChar
  1480. - lda ]operand
  1481. - and #$ff
  1482. - tax
  1483. - jsr print_fix_char_hex
  1484. - pea #' '
  1485. - _WriteChar
  1486. - lda ]operand
  1487. - xba
  1488. - and #$ff
  1489. - pha
  1490. - tax
  1491. - jsr print_fix_char_hex
  1492. - pea #^:space_3
  1493. - pea #:space_3
  1494. - _WriteCString
  1495. - lda ]opcode
  1496. - jsr print_ascii
  1497. - lda ]operand
  1498. - and #$ff
  1499. - jsr print_ascii
  1500. - pla
  1501. - jsr print_ascii
  1502. - bra :end
  1503. -:4_bytes ldx ]opcode
  1504. - jsr print_fix_char_hex
  1505. - pea #' '
  1506. - _WriteChar
  1507. - lda ]operand
  1508. - and #$ff
  1509. - tax
  1510. - jsr print_fix_char_hex
  1511. - pea #' '
  1512. - _WriteChar
  1513. - lda ]operand
  1514. - xba
  1515. - and #$ff
  1516. - pha
  1517. - tax
  1518. - jsr print_fix_char_hex
  1519. - pea #' '
  1520. - _WriteChar
  1521. - ldx ]operand+2
  1522. - jsr print_fix_char_hex
  1523. - pea #^:space_4
  1524. - pea #:space_4
  1525. - _WriteCString
  1526. - lda ]opcode
  1527. - jsr print_ascii
  1528. - lda ]operand
  1529. - and #$ff
  1530. - jsr print_ascii
  1531. - pla
  1532. - jsr print_ascii
  1533. - lda ]operand+2
  1534. - jsr print_ascii
  1535. -
  1536. -:end put_cr
  1537. - rts
  1538. -
  1539. -:space_1 cStr '          - '
  1540. -:space_2 cStr '       - '
  1541. -:space_3 cStr '    - '
  1542. -:space_4 cStr ' - '
  1543. -
  1544. -
  1545. -**************************************************
  1546. -* print ascii equivalent of hex byte, or '.' if  *
  1547. -* hex is non-printing character.                 *
  1548. -* ---------------------------------------------- *
  1549. -* (input)                                        *
  1550. -*  a - hex byte.                                 *
  1551. -**************************************************
  1552. -print_ascii equ *
  1553. -
  1554. - jsr isprint
  1555. - bcc :0
  1556. - lda #'.'
  1557. -:0 pha
  1558. - _WriteChar
  1559. - rts
  1560. -
  1561. -
  1562. -**************************************************
  1563. -* parse opcode with expression as its operand.   *
  1564. -* ---------------------------------------------- *
  1565. -* (input)                                        *
  1566. -*  a - opcode.                                   *
  1567. -**************************************************
  1568. -parse_expr_asm equ *
  1569. -]opcode = $c0 ;opcode
  1570. -]record = $c2 ;OMF record number
  1571. -]assembler = $c4 ;tmp copy of ~assembler
  1572. -]opcode_adr = $c6 ;address of opcode data
  1573. -]syntax_str = $c8 ;address of opcode syntax
  1574. -]opcode_str = $ca
  1575. -
  1576. - sta ]opcode
  1577. - stz ]record
  1578. -
  1579. - read_char ]record
  1580. - lda ]record
  1581. - jsr recognize_record
  1582. - bcc :parse_expr
  1583. - lda ]opcode
  1584. - cmp #DC
  1585. - bne :parse_mode
  1586. - lda ]record
  1587. - ldx #0
  1588. - ldy #FALSE
  1589. - jsr parse_record
  1590. - cpx #0
  1591. - beq :0
  1592. - put_cr
  1593. -:0 brl :end
  1594. -
  1595. -:parse_expr lda ]opcode
  1596. - ldx #1
  1597. - jsr print_byte
  1598. - lda ]record
  1599. - cmp #END
  1600. - beq :2
  1601. - jsr print_offset
  1602. - lda ]record
  1603. - ldx #0
  1604. - ldy #FALSE
  1605. - jsr parse_record
  1606. - beq :2
  1607. - lda ~assembler
  1608. - cmp #MERLIN
  1609. - beq :1
  1610. - pea #'''
  1611. - _WriteChar
  1612. -:1 put_cr
  1613. -:2 brl :end
  1614. -
  1615. -:parse_mode lda ]opcode
  1616. - asl
  1617. - tax
  1618. - lda ~opcodes,x
  1619. - sta ]opcode_adr
  1620. -
  1621. - lda ~assembler ;make copy of ~assembler to restore
  1622. - sta ]assembler ;after change below
  1623. - clc
  1624. - lda ]opcode_adr
  1625. - adc #`syntax
  1626. - sta ]syntax_str
  1627. - ldy #`mode
  1628. - lda (]opcode_adr),y
  1629. - cmp #BLOCK_MOVE
  1630. - beq :test_mode
  1631. - lda #'%'
  1632. - ldx ]syntax_str
  1633. - jsr strchr
  1634. - stx ]opcode_str
  1635. -
  1636. -:test_mode ldy #`mode
  1637. - lda (]opcode_adr),y
  1638. - cmp #ABSOLUTE_LONG
  1639. - beq :absolute_long
  1640. - cmp #ABSOLUTE_LONG_INDEX_X
  1641. - bne :block_move
  1642. -:absolute_long pea #^parse_expr_asm
  1643. - pei ]syntax_str
  1644. - pea #0
  1645. - sec
  1646. - lda ]opcode_str
  1647. - sbc ]syntax_str
  1648. - dec
  1649. - pha
  1650. - _TextWriteBlock
  1651. - pea #' '
  1652. - _WriteChar
  1653. - ldx #'>'
  1654. - lda ~assembler
  1655. - cmp #MERLIN
  1656. - beq :3
  1657. - ldx #'|'
  1658. -:3 phx
  1659. - _WriteChar
  1660. - lda #MERLIN
  1661. - sta ~assembler
  1662. - lda ]record
  1663. - ldx #0
  1664. - ldy #FALSE
  1665. - jsr parse_record
  1666. - clc ;move past '%c$%6'
  1667. - lda ]opcode_str
  1668. - adc #5
  1669. - sta ]opcode_str
  1670. - pea #^parse_expr_asm
  1671. - pei ]opcode_str
  1672. - _WriteCString
  1673. - brl :end_parse
  1674. -
  1675. -:block_move cmp #BLOCK_MOVE
  1676. - bne :default
  1677. - lda #'$'
  1678. - ldx ]syntax_str
  1679. - jsr strchr
  1680. - stx ]opcode_str
  1681. - pea #^parse_expr_asm
  1682. - pei ]syntax_str
  1683. - pea #0
  1684. - sec
  1685. - lda ]opcode_str
  1686. - sbc ]syntax_str
  1687. - dec
  1688. - pha
  1689. - _TextWriteBlock
  1690. - pea #' '
  1691. - _WriteChar
  1692. - lda ]record
  1693. - ldx #0
  1694. - ldy #FALSE
  1695. - jsr parse_record
  1696. - stx ]offset
  1697. - pea #','
  1698. - _WriteChar
  1699. - pea #' '
  1700. - _WriteChar
  1701. - read_char ]record
  1702. - lda ]record
  1703. - ldx ]offset
  1704. - inx
  1705. - inx
  1706. - ldy #FALSE
  1707. - jsr parse_record
  1708. - bra :end_parse
  1709. -
  1710. -:default lda #MERLIN
  1711. - sta ~assembler
  1712. - pea #^parse_expr_asm
  1713. - pei ]syntax_str
  1714. - pea #0
  1715. - sec
  1716. - lda ]opcode_str
  1717. - sbc ]syntax_str
  1718. - dec
  1719. - pha
  1720. - _TextWriteBlock
  1721. - lda ]record
  1722. - ldx #0
  1723. - ldy #FALSE
  1724. - jsr parse_record
  1725. - inc ]opcode_str
  1726. - inc ]opcode_str
  1727. - pea #^parse_expr_asm
  1728. - pei ]opcode_str
  1729. - _WriteCString
  1730. -:end_parse put_cr
  1731. - lda ]assembler
  1732. - sta ~assembler
  1733. - incr @omf+`counter
  1734. -
  1735. -:end incr @omf+`displacement
  1736. - rts
  1737. -
  1738. -
  1739. -**************************************************
  1740. -* print byte as hex and ascii equivalent.        *
  1741. -* ---------------------------------------------- *
  1742. -* (input)                                        *
  1743. -*  a - opcode.                                   *
  1744. -*  x - number of bytes to print.                 *
  1745. -**************************************************
  1746. -print_byte equ *
  1747. -]opcode = $e0 ;opcode value
  1748. -]count = $e2 ;number of bytes to print
  1749. -]byte = $e4 ;data value
  1750. -]offset = $e6
  1751. -
  1752. - sta ]opcode
  1753. - stx ]count
  1754. - stz ]byte
  1755. -
  1756. - lda #2
  1757. - sta ]offset
  1758. - incr ]count;@omf+`displacement
  1759. - incr ]count;@omf+`counter
  1760. - lda ~assembler
  1761. - cmp #MERLIN
  1762. - bne :orca
  1763. - pea #^hex_asm
  1764. - pea #hex_asm
  1765. - bra :2
  1766. -:orca pea #^dc_h_asm
  1767. - pea #dc_h_asm
  1768. - inc ]offset
  1769. - inc ]offset
  1770. -:2 _WriteCString
  1771. - ldx ]opcode
  1772. - jsr print_fix_char_hex
  1773. -
  1774. - lda ]opcode
  1775. - ldx ]count
  1776. - sta :hex,x
  1777. -:read_loop dex
  1778. - beq :3
  1779. - phx
  1780. - read_char ]byte
  1781. - ldx ]byte
  1782. - jsr print_fix_char_hex
  1783. - plx
  1784. - shorta
  1785. - lda ]byte
  1786. - sta :hex,x
  1787. - longa
  1788. - inc ]offset
  1789. - inc ]offset
  1790. - bra :read_loop
  1791. -
  1792. -:3 lda ~assembler
  1793. - cmp #ORCA
  1794. - bne :4
  1795. - pea #'''
  1796. - _WriteChar
  1797. - inc ]offset
  1798. -:4 lda }hex
  1799. - bne :hex_ascii
  1800. - brl :end
  1801. -:hex_ascii pea #^blank_str
  1802. - pea #blank_str
  1803. - pea #0
  1804. - sec
  1805. - lda #26
  1806. - sbc ]offset
  1807. - pha
  1808. - _TextWriteBlock
  1809. -
  1810. - ldy ]count
  1811. -:hex_loop phy
  1812. - lda :hex,y
  1813. - and #$ff
  1814. - tax
  1815. - jsr print_fix_char_hex
  1816. - pea #' '
  1817. - _WriteChar
  1818. - ply
  1819. - dey
  1820. - bne :hex_loop
  1821. -
  1822. - pea #^blank_str ;separate hex and ascii values
  1823. - pea #blank_str
  1824. - pea #0
  1825. - lda ]count ;12 - (3 * ]count) is number of
  1826. - asl ;blanks separating hex and ascii
  1827. - clc ;output
  1828. - adc ]count
  1829. - pha
  1830. - sec
  1831. - lda #12
  1832. - sbc 1,s
  1833. - sta 1,s
  1834. - _TextWriteBlock
  1835. -
  1836. - pea #'-'
  1837. - _WriteChar
  1838. - pea #' '
  1839. - _WriteChar
  1840. - ldy ]count
  1841. -:print_loop phy
  1842. - pea #'.' ;character for non-printing ascii code
  1843. - lda :hex,y
  1844. - and #$ff
  1845. - jsr isprint
  1846. - bcs :print_char ;use default if non-printing character
  1847. - lda :hex,y ;else output character
  1848. - and #$ff
  1849. - sta 1,s
  1850. -:print_char _WriteChar
  1851. - ply
  1852. - dey
  1853. - bne :print_loop
  1854. -
  1855. -:end put_cr
  1856. - rts
  1857. -
  1858. -:hex ds 6 ;bytes read in
  1859. -
  1860. -
  1861. -**************************************************
  1862. -* modify flags in coff depending on REP and SEP  *
  1863. -* opcodes.                                       *
  1864. -* ---------------------------------------------- *
  1865. -* (input)                                        *
  1866. -*  a - opcode.                                   *
  1867. -*  x - operand.                                  *
  1868. -**************************************************
  1869. -parse_rep_sep equ *
  1870. -]opcode = $c0 ;opcode
  1871. -]operand = $c2 ;opcode operand
  1872. -
  1873. - sta ]opcode
  1874. - stx ]operand
  1875. -
  1876. - cmp #REP
  1877. - bne :sep
  1878. - txa
  1879. - and #LONGA
  1880. - beq :test_rep_longi
  1881. - stz }shorta
  1882. - lda ~assembler
  1883. - cmp #ORCA
  1884. - bne :test_rep_longi
  1885. - lda #LONGA
  1886. - jsr asm_status_bit
  1887. -:test_rep_longi lda ]operand
  1888. - and #LONGI
  1889. - beq :0
  1890. - stz }shorti
  1891. - lda ~assembler
  1892. - cmp #ORCA
  1893. - bne :0
  1894. - jsr asm_status_bit
  1895. -:0 lda ~assembler
  1896. - cmp #MERLIN
  1897. - bne :end
  1898. - lda #LONGI
  1899. - jmp asm_status_bit
  1900. -
  1901. -:sep lda ]operand
  1902. - and #LONGA
  1903. - beq :test_sep_longi
  1904. - lda #TRUE
  1905. - sta }shorta
  1906. - lda ~assembler
  1907. - cmp #ORCA
  1908. - bne :test_sep_longi
  1909. - lda #LONGA
  1910. - jsr asm_status_bit
  1911. -:test_sep_longi lda ]operand
  1912. - and #LONGI
  1913. - beq :1
  1914. - lda #TRUE
  1915. - sta }shorti
  1916. - lda ~assembler
  1917. - cmp #ORCA
  1918. - bne :1
  1919. - jsr asm_status_bit
  1920. -:1 lda ~assembler
  1921. - cmp #MERLIN
  1922. - bne :end
  1923. - lda #LONGA
  1924. - jmp asm_status_bit
  1925. -:end rts
  1926. -
  1927. -
  1928. -**************************************************
  1929. -* test OMF record to parse.                      *
  1930. -* ---------------------------------------------- *
  1931. -* (input)                                        *
  1932. -*  a - record number.                            *
  1933. -* (output)                                       *
  1934. -*  c - set if record not recognized.             *
  1935. -**************************************************
  1936. -recognize_record equ *
  1937. -
  1938. - cmp #USING
  1939. - beq :true
  1940. - cmp #STRONG
  1941. - beq :true
  1942. - cmp #GLOBAL
  1943. - beq :true
  1944. - cmp #GEQU
  1945. - beq :true
  1946. - cmp #MEM
  1947. - beq :true
  1948. - cmp #LOCAL
  1949. - beq :true
  1950. - cmp #EQU
  1951. - beq :true
  1952. - cmp #DS
  1953. - beq :true
  1954. - cmp #LCONST
  1955. - beq :true
  1956. - cmp #$01
  1957. - blt :true
  1958. - cmp #$e0
  1959. - bge :false
  1960. -
  1961. -:true clc
  1962. - rts
  1963. -:false sec
  1964. - rts
  1965. -
  1966. -
  1967. -**************************************************
  1968. -* parse type of label.                           *
  1969. -* ---------------------------------------------- *
  1970. -* (input)                                        *
  1971. -*  a - LOB label length.                         *
  1972. -*      HOB label type.                           *
  1973. -*  x - LOW handle of label name.                 *
  1974. -*  y - HOW handle of label name.                 *
  1975. -**************************************************
  1976. -parse_type_attribute ent
  1977. -]type = $a0 ;label type
  1978. -]length = $a2 ;label length
  1979. -]length_type = $a4 ;length and type
  1980. -]label_handle = $a6 ;handle to label name
  1981. -
  1982. - sta ]length_type
  1983. - stx ]label_handle
  1984. - sty ]label_handle+2
  1985. - tax
  1986. - and #$ff
  1987. - sta ]length
  1988. - txa
  1989. - xba
  1990. - and #$ff
  1991. - sta ]type
  1992. -
  1993. - sta @parse_data+`data_type
  1994. - cmp #'A' ;address-type
  1995. - bne :character
  1996. - lda ]length
  1997. - ldx ]label_handle+2
  1998. - ldy ]label_handle
  1999. - jsr parse_GLOBAL_type_A
  2000. - rts
  2001. -:character cmp #'C' ;character-type
  2002. - bne :double_precision
  2003. - ldx ]label_handle+2
  2004. - ldy ]label_handle
  2005. - jsr parse_GLOBAL_type_C
  2006. - rts
  2007. -:double_precision cmp #'D' ;double-precision floating-point
  2008. - bne :floating_point
  2009. - lda ]length
  2010. - ldx ]label_handle+2
  2011. - ldy ]label_handle
  2012. - jsr parse_GLOBAL_type_D
  2013. - rts
  2014. -:floating_point cmp #'F' ;floating-point
  2015. - bne :hexadecimal
  2016. - lda ]length
  2017. - ldx ]label_handle+2
  2018. - ldy ]label_handle
  2019. - jsr parse_GLOBAL_type_F
  2020. - rts
  2021. -:hexadecimal cmp #'H' ;hexadecimal-type
  2022. - bne :integer
  2023. - ldx ]label_handle+2
  2024. - ldy ]label_handle
  2025. - jsr parse_GLOBAL_type_H
  2026. - rts
  2027. -:integer cmp #'I' ;integer
  2028. - bne :reference_adr
  2029. - lda ]length
  2030. - ldx ]label_handle+2
  2031. - ldy ]label_handle
  2032. - jsr parse_GLOBAL_type_I
  2033. - rts
  2034. -:reference_adr cmp #'K' ;reference-address
  2035. - bne :soft_reference
  2036. - ldx ]label_handle+2
  2037. - ldy ]label_handle
  2038. - jsr parse_GLOBAL_type_K
  2039. - rts
  2040. -:soft_reference cmp #'L' ;soft-reference
  2041. - bne :assembler
  2042. - lda ]length
  2043. - ldx ]label_handle+2
  2044. - ldy ]label_handle
  2045. - jsr parse_GLOBAL_type_L
  2046. - rts
  2047. -:assembler cmp #'N' ;assembler
  2048. - bne :ds
  2049. - ldx ]label_handle+2
  2050. - ldy ]label_handle
  2051. - jsr parse_GLOBAL_type_N
  2052. - rts
  2053. -:ds cmp #'S' ;DS
  2054. - bne :end
  2055. - ldx ]label_handle+2
  2056. - ldy ]label_handle
  2057. - jsr parse_GLOBAL_type_S
  2058. -:end rts
  2059. -
  2060. -
  2061. -**************************************************
  2062. -* parse address-type DC statement.               *
  2063. -* ---------------------------------------------- *
  2064. -* (input)                                        *
  2065. -*  a - label length.                             *
  2066. -*  x - HOW handle of label name.                 *
  2067. -*  y - LOW handle of label name.                 *
  2068. -**************************************************
  2069. -parse_GLOBAL_type_A equ *
  2070. -]label_handle = $b0 ;handle to label name
  2071. -]label_ptr = $b4
  2072. -]label_len = $b8
  2073. -]record = $b0 ;record number
  2074. -]const_count = $b0 ;counter for CONST
  2075. -]edge = $b2 ;right margin
  2076. -]num_char = $b4 ;length of output
  2077. -]adr_value = $b6 ;address value read in
  2078. -]count = $b8 ;number of address values to display
  2079. -
  2080. - sta ]count
  2081. - sta @parse_data+`count
  2082. - sta @parse_data+`on ;enable flag to parse data
  2083. - stx ]label_handle+2
  2084. - sty ]label_handle
  2085. -
  2086. - lda []label_handle]
  2087. - sta ]label_ptr
  2088. - ldy #2
  2089. - lda []label_handle],y
  2090. - sta ]label_ptr+2
  2091. -
  2092. - lda #0
  2093. - ldx }nooffset
  2094. - beq :0
  2095. - lda #16
  2096. -:0 clc
  2097. - adc #ADDRESS_EDGE
  2098. - sta ]edge
  2099. -
  2100. - pei ]label_ptr+2
  2101. - pei ]label_ptr
  2102. - pea #2
  2103. - lda []label_ptr]
  2104. - sta ]label_len
  2105. - pha
  2106. - _TextWriteBlock
  2107. - lda ]label_len
  2108. - cmp #12
  2109. - blt :1
  2110. - pea #' '
  2111. - _WriteChar
  2112. - bra :2
  2113. -:1 pea #^blank_str
  2114. - pea #blank_str
  2115. - pea #0
  2116. - sec
  2117. - lda #12
  2118. - sbc ]label_len
  2119. - pha
  2120. - _TextWriteBlock
  2121. -
  2122. -:2 ldx ]edge
  2123. - lda ~assembler
  2124. - cmp #MERLIN
  2125. - beq :3
  2126. - dex
  2127. - dex
  2128. - dex
  2129. - dex
  2130. -:3 stx @parse_data+`edge
  2131. - stx ]edge
  2132. - stz ]adr_value
  2133. - stz ]record
  2134. - stz ]num_char
  2135. -
  2136. -:read_record read_char ]record ;read record to parse
  2137. - lda ]record
  2138. - ldx ]num_char
  2139. - jsr parse_GLOBAL_type
  2140. - beq :print_const
  2141. - lda @parse_data+`count
  2142. - sta ]count
  2143. - beq :end_read
  2144. -:4 jsr print_offset
  2145. - pea #^space_12
  2146. - pea #space_12
  2147. - _WriteCString
  2148. - bra :read_record
  2149. -:end_read brl :rts
  2150. -
  2151. -:print_const stz ]num_char
  2152. - ldx #^db_asm
  2153. - ldy #db_asm
  2154. - lda ~assembler
  2155. - cmp #MERLIN
  2156. - beq :5
  2157. - ldx #^dc_a_asm
  2158. - ldy #dc_a_asm
  2159. -:5 phx
  2160. - phy
  2161. - _WriteCString
  2162. -
  2163. - lda ~assembler
  2164. - cmp #MERLIN
  2165. - beq :loop
  2166. - pea #'1'
  2167. - _WriteChar
  2168. - pea #'''
  2169. - _WriteChar
  2170. -:loop read_char ]adr_value
  2171. - ldx ]adr_value
  2172. - jsr print_char_dec
  2173. - inc ;add comma character
  2174. - clc
  2175. - adc ]num_char
  2176. - sta ]num_char
  2177. - dec ]const_count
  2178. - dec @parse_data+`count
  2179. -
  2180. - incr @omf+`displacement
  2181. - incr @omf+`counter
  2182. -
  2183. - lda ]num_char
  2184. - cmp ]edge
  2185. - blt :9
  2186. - beq :9
  2187. - lda ~assembler
  2188. - cmp #MERLIN
  2189. - beq :6
  2190. - pea #'''
  2191. - _WriteChar
  2192. -:6 put_cr
  2193. - lda @parse_data+`count ;end if no more records to display
  2194. - beq :rts
  2195. - lda ]const_count ;if at end of CONST record, read next
  2196. - bne :7 ;record
  2197. - stz ]num_char
  2198. - brl :4
  2199. -:7 stz ]num_char
  2200. - jsr print_offset
  2201. - pea #^space_12
  2202. - pea #space_12
  2203. - _WriteCString
  2204. - ldx #^db_asm
  2205. - ldy #db_asm
  2206. - lda ~assembler
  2207. - cmp #MERLIN
  2208. - beq :8
  2209. - ldx #^:dc_a_asm
  2210. - ldy #:dc_a_asm
  2211. -:8 phx
  2212. - phy
  2213. - _WriteCString
  2214. - brl :loop
  2215. -:9 lda ]const_count
  2216. - beq :end
  2217. - pea #','
  2218. - _WriteChar
  2219. - brl :loop
  2220. -
  2221. -:end lda ]num_char
  2222. - beq :rts
  2223. - lda ~assembler
  2224. - cmp #MERLIN
  2225. - beq :10
  2226. - pea #'''
  2227. - _WriteChar
  2228. -:10 put_cr
  2229. - lda @parse_data+`count
  2230. - beq :rts
  2231. - brl :4
  2232. -:rts stz @parse_data+`on ;turn off parsing of data
  2233. - rts
  2234. -
  2235. -:dc_a_asm asc !dc     a1'!,00
  2236. -
  2237. -
  2238. -**************************************************
  2239. -* parse character-type DC statement.             *
  2240. -* ---------------------------------------------- *
  2241. -* (input)                                        *
  2242. -*  x - HOW handle of label name.                 *
  2243. -*  y - LOW handle of label name.                 *
  2244. -**************************************************
  2245. -parse_GLOBAL_type_C equ *
  2246. -]label_handle = $b0 ;handle to label name
  2247. -]label_ptr = $b4
  2248. -]record = $b8 ;record number
  2249. -]count = $b8 ;number of characters to display
  2250. -]edge = $ba ;right margin
  2251. -]num_read = $bc ;number of bytes read
  2252. -
  2253. - stx ]label_handle+2
  2254. - sty ]label_handle
  2255. -
  2256. - lda []label_handle]
  2257. - sta ]label_ptr
  2258. - tax
  2259. - ldy #2
  2260. - lda []label_handle],y
  2261. - sta ]label_ptr+2
  2262. -
  2263. - pha
  2264. - phx
  2265. - pea #2
  2266. - lda []label_ptr]
  2267. - sta ]label_len
  2268. - pha
  2269. - _TextWriteBlock
  2270. - lda ]label_len
  2271. - cmp #12
  2272. - blt :0
  2273. - pea #' '
  2274. - _WriteChar
  2275. - bra :1
  2276. -:0 pea #^blank_str
  2277. - pea #blank_str
  2278. - pea #0
  2279. - sec
  2280. - lda #12
  2281. - sbc ]label_len
  2282. - pha
  2283. - _TextWriteBlock
  2284. -
  2285. -:1 stz ]record
  2286. - read_char ]record
  2287. -
  2288. - lda ]record
  2289. - cmp #DS
  2290. - beq :3
  2291. - ldx #^:asc
  2292. - ldy #:asc
  2293. - lda ~assembler
  2294. - cmp #MERLIN
  2295. - beq :2
  2296. - ldx #^:dc_c
  2297. - ldy #:dc_c
  2298. -:2 phx
  2299. - phy
  2300. - _WriteCString
  2301. -
  2302. -:3 lda ]record
  2303. - ldx #0
  2304. - jsr parse_GLOBAL_type
  2305. - beq :display_char
  2306. - rts
  2307. -
  2308. -:display_char lda #0
  2309. - ldx }nooffset
  2310. - beq :4
  2311. - lda #16
  2312. -:4 clc
  2313. - adc #CHAR_EDGE
  2314. - sta ]edge
  2315. -
  2316. -:loop lda ]count ;if number of bytes to read is less
  2317. - cmp ]edge ;than the default, output only
  2318. - blt :5 ;default many bytes
  2319. - lda ]edge ;read in default number of characters
  2320. -:5 ldx #:hex
  2321. - ldy #^:hex
  2322. - jsr GSOSread
  2323. - stx ]num_read
  2324. -
  2325. - ldx #0 ;output characters just read
  2326. -:print_char phx
  2327. - lda :hex,x
  2328. - and #$ff
  2329. - pha
  2330. - _WriteChar
  2331. - plx
  2332. - inx
  2333. - cpx ]num_read
  2334. - blt :print_char
  2335. -
  2336. - pea #'''
  2337. - _WriteChar
  2338. - put_cr
  2339. -
  2340. - sec
  2341. - lda ]count
  2342. - sbc ]num_read
  2343. - sta ]count
  2344. - incr ]num_read;@omf+`counter ;update counter
  2345. - incr ]num_read;@omf+`displacement ;update offset into OMF file
  2346. -
  2347. - lda ]count
  2348. - beq :end
  2349. - jsr print_offset
  2350. - pea #^space_12
  2351. - pea #space_12
  2352. - _WriteCString
  2353. - ldx #^:asc
  2354. - ldy #:asc
  2355. - lda ~assembler
  2356. - cmp #MERLIN
  2357. - beq :6
  2358. - ldx #^:dc_c
  2359. - ldy #:dc_c
  2360. -:6 phx
  2361. - phy
  2362. - _WriteCString
  2363. - brl :loop
  2364. -:end rts
  2365. -
  2366. -:asc asc !asc    '!,00
  2367. -:dc_c asc !dc     c'!,00
  2368. -:hex ds CHAR_EDGE+17 ;space for input string
  2369. -
  2370. -
  2371. -**************************************************
  2372. -* parse double-precision floating-point DC       *
  2373. -* statement.                                     *
  2374. -* ---------------------------------------------- *
  2375. -* (input)                                        *
  2376. -*  a - number of double floats to display.       *
  2377. -*  x - HOW handle of label name.                 *
  2378. -*  y - LOW handle of label name.                 *
  2379. -**************************************************
  2380. -parse_GLOBAL_type_D equ *
  2381. -]label_handle = $b0 ;handle to label name
  2382. -]label_ptr = $b4
  2383. -]label_len = $b8
  2384. -]const_count = $b0 ;counter for CONST
  2385. -]edge = $b2 ;right margin
  2386. -]num_char = $b4 ;length of output
  2387. -]double_value = $b6 ;double value read in
  2388. -]count = $be ;number of double values to display
  2389. -
  2390. - sta ]count
  2391. - lsr
  2392. - lsr
  2393. - bcs :extended
  2394. - lsr
  2395. - bcc :0
  2396. -:extended jmp parse_GLOBAL_type_E
  2397. -:0 stx ]label_handle+2
  2398. - sty ]label_handle
  2399. -
  2400. - lda []label_handle]
  2401. - sta ]label_ptr
  2402. - ldy #2
  2403. - lda []label_handle],y
  2404. - sta ]label_ptr+2
  2405. -
  2406. - lda #0
  2407. - ldx }nooffset
  2408. - beq :1
  2409. - lda #16
  2410. -:1 clc
  2411. - adc #DOUBLE_EDGE-3
  2412. - sta ]edge
  2413. -
  2414. - pei ]label_ptr+2
  2415. - pei ]label_ptr
  2416. - pea #2
  2417. - lda []label_ptr]
  2418. - sta ]label_len
  2419. - pha
  2420. - _TextWriteBlock
  2421. - lda ]label_len
  2422. - cmp #12
  2423. - blt :2
  2424. - pea #' '
  2425. - _WriteChar
  2426. - bra :3
  2427. -:2 pea #^blank_str
  2428. - pea #blank_str
  2429. - pea #0
  2430. - sec
  2431. - lda #12
  2432. - sbc ]label_len
  2433. - pha
  2434. - _TextWriteBlock
  2435. -
  2436. -:3 pea #^dc_d_asm
  2437. - pea #dc_d_asm
  2438. - _WriteCString
  2439. -
  2440. - stz ]const_count
  2441. - stz ]num_char
  2442. -
  2443. - read_char ]const_count ;read record to parse
  2444. - lsr ]const_count ;since we read in 8 bytes
  2445. - lsr ]const_count
  2446. - lsr ]const_count
  2447. -:loop read_double ]double_value
  2448. - lda #]double_value
  2449. - jsr print_double
  2450. - inc ;add comma character
  2451. - clc
  2452. - adc ]num_char
  2453. - sta ]num_char
  2454. - dec ]const_count
  2455. -
  2456. - incr #8;@omf+`displacement
  2457. - incr #8;@omf+`counter
  2458. -
  2459. - lda ]num_char
  2460. - cmp ]edge
  2461. - blt :4
  2462. - beq :4
  2463. - pea #'''
  2464. - _WriteChar
  2465. - put_cr
  2466. - lda ]const_count ;if not at end of CONST record, read
  2467. - beq :rts ;next record
  2468. - stz ]num_char
  2469. - jsr print_offset
  2470. - pea #^space_12
  2471. - pea #space_12
  2472. - _WriteCString
  2473. - pea #^dc_d_asm
  2474. - pea #dc_d_asm
  2475. - _WriteCString
  2476. - brl :loop
  2477. -:4 lda ]const_count
  2478. - beq :end
  2479. - pea #','
  2480. - _WriteChar
  2481. - brl :loop
  2482. -
  2483. -:end lda ]num_char
  2484. - beq :rts
  2485. - pea #'''
  2486. - _WriteChar
  2487. - put_cr
  2488. -:rts rts
  2489. -
  2490. -
  2491. -**************************************************
  2492. -* parse extended floating-point DC statement.    *
  2493. -* ---------------------------------------------- *
  2494. -* (input)                                        *
  2495. -*  a - number of extended floats to display.     *
  2496. -*  x - HOW handle of label name.                 *
  2497. -*  y - LOW handle of label name.                 *
  2498. -**************************************************
  2499. -parse_GLOBAL_type_E equ *
  2500. -]label_handle = $b0 ;handle to label name
  2501. -]label_ptr = $b4
  2502. -]label_len = $b8
  2503. -]const_count = $b0 ;counter for CONST
  2504. -]edge = $b2 ;right margin
  2505. -]num_char = $b4 ;length of output
  2506. -]extended_value = $b6 ;extended value read in
  2507. -]count = $be ;number of extended values to display
  2508. -
  2509. - sta ]count
  2510. - stx ]label_handle+2
  2511. - sty ]label_handle
  2512. -
  2513. - lda []label_handle]
  2514. - sta ]label_ptr
  2515. - ldy #2
  2516. - lda []label_handle],y
  2517. - sta ]label_ptr+2
  2518. -
  2519. - lda #0
  2520. - ldx }nooffset
  2521. - beq :0
  2522. - lda #16
  2523. -:0 clc
  2524. - adc #EXTENDED_EDGE-3
  2525. - sta ]edge
  2526. -
  2527. - pei ]label_ptr+2
  2528. - pei ]label_ptr
  2529. - pea #2
  2530. - lda []label_ptr]
  2531. - sta ]label_len
  2532. - pha
  2533. - _TextWriteBlock
  2534. - lda ]label_len
  2535. - cmp #12
  2536. - blt :1
  2537. - pea #' '
  2538. - _WriteChar
  2539. - bra :2
  2540. -:1 pea #^blank_str
  2541. - pea #blank_str
  2542. - pea #0
  2543. - sec
  2544. - lda #12
  2545. - sbc ]label_len
  2546. - pha
  2547. - _TextWriteBlock
  2548. -
  2549. -:2 ldx #^flo_asm
  2550. - ldy #flo_asm
  2551. - lda ~assembler
  2552. - cmp #MERLIN
  2553. - beq :3
  2554. - ldx #^dc_e_asm
  2555. - ldy #dc_e_asm
  2556. -:3 phx
  2557. - phy
  2558. - _WriteCString
  2559. -
  2560. - stz ]const_count
  2561. - stz ]num_char
  2562. -
  2563. - read_char ]const_count ;read record to parse
  2564. -:loop read_extended ]extended_value
  2565. - lda #]extended_value
  2566. - jsr print_extended
  2567. - inc ;add comma character
  2568. - clc
  2569. - adc ]num_char
  2570. - sta ]num_char
  2571. - sec
  2572. - lda ]const_count
  2573. - sbc #10
  2574. - sta ]const_count
  2575. -
  2576. - incr #10;@omf+`displacement
  2577. - incr #10;@omf+`counter
  2578. -
  2579. - lda ]num_char
  2580. - cmp ]edge
  2581. - blt :5
  2582. - beq :5
  2583. - pea #'''
  2584. - _WriteChar
  2585. - put_cr
  2586. - lda ]const_count ;if not at end of CONST record, read
  2587. - beq :rts ;next record
  2588. - stz ]num_char
  2589. - jsr print_offset
  2590. - pea #^space_12
  2591. - pea #space_12
  2592. - _WriteCString
  2593. - ldx #^flo_asm
  2594. - ldy #flo_asm
  2595. - lda ~assembler
  2596. - cmp #MERLIN
  2597. - beq :4
  2598. - ldx #^dc_e_asm
  2599. - ldy #dc_e_asm
  2600. -:4 phx
  2601. - phy
  2602. - _WriteCString
  2603. - brl :loop
  2604. -:5 lda ]const_count
  2605. - beq :end
  2606. - pea #','
  2607. - _WriteChar
  2608. - brl :loop
  2609. -
  2610. -:end lda ]num_char
  2611. - beq :rts
  2612. - pea #'''
  2613. - _WriteChar
  2614. - put_cr
  2615. -:rts rts
  2616. -
  2617. -
  2618. -**************************************************
  2619. -* parse floating-point-type DC statement.        *
  2620. -* ---------------------------------------------- *
  2621. -* (input)                                        *
  2622. -*  a - number of floats to display.              *
  2623. -*  x - HOW handle of label name.                 *
  2624. -*  y - LOW handle of label name.                 *
  2625. -**************************************************
  2626. -parse_GLOBAL_type_F equ *
  2627. -]label_handle = $b0 ;handle to label name
  2628. -]label_ptr = $b4
  2629. -]label_len = $b8
  2630. -]const_count = $b0 ;counter for CONST
  2631. -]edge = $b2 ;right margin
  2632. -]num_char = $b4 ;length of output
  2633. -]float_value = $b6 ;float value read in
  2634. -]count = $ba ;number of integer values to display
  2635. -
  2636. - sta ]count
  2637. - stx ]label_handle+2
  2638. - sty ]label_handle
  2639. -
  2640. - lda []label_handle]
  2641. - sta ]label_ptr
  2642. - ldy #2
  2643. - lda []label_handle],y
  2644. - sta ]label_ptr+2
  2645. -
  2646. - lda #0
  2647. - ldx }nooffset
  2648. - beq :0
  2649. - lda #16
  2650. -:0 clc
  2651. - adc #FLOAT_EDGE-3
  2652. - sta ]edge
  2653. -
  2654. - pei ]label_ptr+2
  2655. - pei ]label_ptr
  2656. - pea #2
  2657. - lda []label_ptr]
  2658. - sta ]label_len
  2659. - pha
  2660. - _TextWriteBlock
  2661. - lda ]label_len
  2662. - cmp #12
  2663. - blt :1
  2664. - pea #' '
  2665. - _WriteChar
  2666. - bra :2
  2667. -:1 pea #^blank_str
  2668. - pea #blank_str
  2669. - pea #0
  2670. - sec
  2671. - lda #12
  2672. - sbc ]label_len
  2673. - pha
  2674. - _TextWriteBlock
  2675. -
  2676. -:2 pea #^dc_f_asm
  2677. - pea #dc_f_asm
  2678. - _WriteCString
  2679. -
  2680. - stz ]num_char
  2681. - stz ]const_count
  2682. -
  2683. - read_char ]const_count ;number of bytes
  2684. - lsr ]const_count ;since we read in 4 bytes
  2685. - lsr ]const_count
  2686. -:loop read_float ]float_value
  2687. - lda #]float_value
  2688. - jsr print_float
  2689. - inc ;add comma character
  2690. - clc
  2691. - adc ]num_char
  2692. - sta ]num_char
  2693. - dec ]const_count
  2694. -
  2695. - incr #4;@omf+`displacement
  2696. - incr #4;@omf+`counter
  2697. -
  2698. - lda ]num_char
  2699. - cmp ]edge
  2700. - blt :3
  2701. - beq :3
  2702. - pea #'''
  2703. - _WriteChar
  2704. - put_cr
  2705. - lda ]const_count ;if at end of CONST record, read next
  2706. - beq :rts ;record
  2707. - stz ]num_char
  2708. - jsr print_offset
  2709. - pea #^space_12
  2710. - pea #space_12
  2711. - _WriteCString
  2712. - pea #^dc_f_asm
  2713. - pea #dc_f_asm
  2714. - _WriteCString
  2715. - brl :loop
  2716. -:3 lda ]const_count
  2717. - beq :end
  2718. - pea #','
  2719. - _WriteChar
  2720. - brl :loop
  2721. -
  2722. -:end lda ]num_char
  2723. - beq :rts
  2724. - pea #'''
  2725. - _WriteChar
  2726. - put_cr
  2727. -:rts rts
  2728. -
  2729. -
  2730. -**************************************************
  2731. -* parse hexadecimal-type DC statement.           *
  2732. -* ---------------------------------------------- *
  2733. -* (input)                                        *
  2734. -*  x - HOW handle of label name.                 *
  2735. -*  y - LOW handle of label name.                 *
  2736. -**************************************************
  2737. -parse_GLOBAL_type_H equ *
  2738. -]label_handle = $b0 ;handle to label name
  2739. -]label_ptr = $b4
  2740. -]record = $b8 ;record number
  2741. -]count = $b8 ;number of characters to display
  2742. -]edge = $ba ;right margin
  2743. -]num_read = $bc ;number of bytes read
  2744. -
  2745. - stx ]label_handle+2
  2746. - sty ]label_handle
  2747. -
  2748. - lda []label_handle]
  2749. - sta ]label_ptr
  2750. - tax
  2751. - ldy #2
  2752. - lda []label_handle],y
  2753. - sta ]label_ptr+2
  2754. -
  2755. - pha
  2756. - phx
  2757. - pea #2
  2758. - lda []label_ptr]
  2759. - sta ]label_len
  2760. - pha
  2761. - _TextWriteBlock
  2762. - lda ]label_len
  2763. - cmp #12
  2764. - blt :0
  2765. - pea #' '
  2766. - _WriteChar
  2767. - bra :1
  2768. -:0 pea #^blank_str
  2769. - pea #blank_str
  2770. - pea #0
  2771. - sec
  2772. - lda #12
  2773. - sbc ]label_len
  2774. - pha
  2775. - _TextWriteBlock
  2776. -
  2777. -:1 stz ]record
  2778. - read_char ]record
  2779. -
  2780. - lda ]record
  2781. - cmp #DS
  2782. - beq :3
  2783. - ldx #^hex_asm
  2784. - ldy #hex_asm
  2785. - lda ~assembler
  2786. - cmp #MERLIN
  2787. - beq :2
  2788. - ldx #^dc_h_asm
  2789. - ldy #dc_h_asm
  2790. -:2 phx
  2791. - phy
  2792. - _WriteCString
  2793. -
  2794. -:3 lda ]record
  2795. - ldx #0
  2796. - jsr parse_GLOBAL_type
  2797. - beq :display_char
  2798. - rts
  2799. -
  2800. -:display_char lda #0
  2801. - ldx }nooffset
  2802. - beq :4
  2803. - lda #16
  2804. -:4 clc
  2805. - adc #HEX_EDGE
  2806. - sta ]edge
  2807. -
  2808. -:loop lda ]count ;if number of bytes to read is less
  2809. - cmp ]edge ;than the default, output only
  2810. - blt :5 ;default many bytes
  2811. - lda ]edge ;read in default number of characters
  2812. -:5 ldx #:hex
  2813. - ldy #^:hex
  2814. - jsr GSOSread
  2815. - stx ]num_read
  2816. -
  2817. - ldx #0 ;output characters just read
  2818. -:print_char phx
  2819. - lda :hex,x
  2820. - and #$ff
  2821. - tax
  2822. - jsr print_fix_char_hex
  2823. - plx
  2824. - inx
  2825. - cpx ]num_read
  2826. - blt :print_char
  2827. -
  2828. - lda ~assembler
  2829. - cmp #MERLIN
  2830. - beq :cr
  2831. - pea #'''
  2832. - _WriteChar
  2833. -:cr put_cr
  2834. -
  2835. - sec
  2836. - lda ]count
  2837. - sbc ]num_read
  2838. - sta ]count
  2839. - incr ]num_read;@omf+`counter ;update counter
  2840. - incr ]num_read;@omf+`displacement ;update offset into OMF file
  2841. -
  2842. - lda ]count
  2843. - beq :end
  2844. - jsr print_offset
  2845. - pea #^space_12
  2846. - pea #space_12
  2847. - _WriteCString
  2848. - ldx #^hex_asm
  2849. - ldy #hex_asm
  2850. - lda ~assembler
  2851. - cmp #MERLIN
  2852. - beq :6
  2853. - ldx #^dc_h_asm
  2854. - ldy #dc_h_asm
  2855. -:6 phx
  2856. - phy
  2857. - _WriteCString
  2858. - brl :loop
  2859. -:end rts
  2860. -
  2861. -:hex ds HEX_EDGE+17 ;space for input string
  2862. -
  2863. -
  2864. -**************************************************
  2865. -* parse integer-type DC statement.               *
  2866. -* ---------------------------------------------- *
  2867. -* (input)                                        *
  2868. -*  a - number of integers to display.            *
  2869. -*  x - HOW handle of label name.                 *
  2870. -*  y - LOW handle of label name.                 *
  2871. -**************************************************
  2872. -parse_GLOBAL_type_I equ *
  2873. -]label_handle = $b0 ;handle to label name
  2874. -]label_ptr = $b4
  2875. -]label_len = $b8
  2876. -]record = $b0 ;record number
  2877. -]const_count = $b0 ;counter for CONST
  2878. -]edge = $b2 ;right margin
  2879. -]num_char = $b4 ;length of output
  2880. -]int_value = $b6 ;integer value read in
  2881. -]count = $b8 ;number of integer values to display
  2882. -
  2883. - sta ]count
  2884. - sta @parse_data+`count
  2885. - sta @parse_data+`on ;enable flag to parse data
  2886. - stx ]label_handle+2
  2887. - sty ]label_handle
  2888. -
  2889. - lda []label_handle]
  2890. - sta ]label_ptr
  2891. - ldy #2
  2892. - lda []label_handle],y
  2893. - sta ]label_ptr+2
  2894. -
  2895. - lda #0
  2896. - ldx }nooffset
  2897. - beq :0
  2898. - lda #16
  2899. -:0 clc
  2900. - adc #INT_EDGE
  2901. - sta ]edge
  2902. -
  2903. - pei ]label_ptr+2
  2904. - pei ]label_ptr
  2905. - pea #2
  2906. - lda []label_ptr]
  2907. - sta ]label_len
  2908. - pha
  2909. - _TextWriteBlock
  2910. - lda ]label_len
  2911. - cmp #12
  2912. - blt :1
  2913. - pea #' '
  2914. - _WriteChar
  2915. - bra :2
  2916. -:1 pea #^blank_str
  2917. - pea #blank_str
  2918. - pea #0
  2919. - sec
  2920. - lda #12
  2921. - sbc ]label_len
  2922. - pha
  2923. - _TextWriteBlock
  2924. -
  2925. -:2 ldx ]edge
  2926. - lda ~assembler
  2927. - cmp #MERLIN
  2928. - beq :3
  2929. - dex
  2930. - dex
  2931. - dex
  2932. - dex
  2933. -:3 stx @parse_data+`edge
  2934. - stx ]edge
  2935. - stz ]int_value
  2936. - stz ]record
  2937. - stz ]num_char
  2938. -
  2939. -:read_record read_char ]record ;read record to parse
  2940. - lda ]record
  2941. - ldx ]num_char
  2942. - jsr parse_GLOBAL_type
  2943. - beq :print_const
  2944. - lda @parse_data+`count
  2945. - sta ]count
  2946. - beq :end_read
  2947. -:4 jsr print_offset
  2948. - pea #^space_12
  2949. - pea #space_12
  2950. - _WriteCString
  2951. - bra :read_record
  2952. -:end_read brl :rts
  2953. -
  2954. -:print_const stz ]num_char
  2955. - ldx #^db_asm
  2956. - ldy #db_asm
  2957. - lda ~assembler
  2958. - cmp #MERLIN
  2959. - beq :5
  2960. - ldx #^dc_i_asm
  2961. - ldy #dc_i_asm
  2962. -:5 phx
  2963. - phy
  2964. - _WriteCString
  2965. -
  2966. - lda ~assembler
  2967. - cmp #MERLIN
  2968. - beq :loop
  2969. - pea #'1'
  2970. - _WriteChar
  2971. - pea #'''
  2972. - _WriteChar
  2973. -:loop read_char ]int_value
  2974. - ldx ]int_value
  2975. - jsr print_char_dec
  2976. - inc ;add comma character
  2977. - clc
  2978. - adc ]num_char
  2979. - sta ]num_char
  2980. - dec ]const_count
  2981. - dec @parse_data+`count
  2982. -
  2983. - incr @omf+`displacement
  2984. - incr @omf+`counter
  2985. -
  2986. - lda ]num_char
  2987. - cmp ]edge
  2988. - blt :9
  2989. - beq :9
  2990. - lda ~assembler
  2991. - cmp #MERLIN
  2992. - beq :6
  2993. - pea #'''
  2994. - _WriteChar
  2995. -:6 put_cr
  2996. - lda @parse_data+`count ;end if no more records to display
  2997. - beq :rts
  2998. - stz ]num_char
  2999. - lda ]const_count ;if at end of CONST record, read next
  3000. - bne :7 ;record
  3001. - brl :4
  3002. -:7 jsr print_offset
  3003. - pea #^space_12
  3004. - pea #space_12
  3005. - _WriteCString
  3006. - ldx #^db_asm
  3007. - ldy #db_asm
  3008. - lda ~assembler
  3009. - cmp #MERLIN
  3010. - beq :8
  3011. - ldx #^:dc_i_asm
  3012. - ldy #:dc_i_asm
  3013. -:8 phx
  3014. - phy
  3015. - _WriteCString
  3016. - brl :loop
  3017. -:9 lda ]const_count
  3018. - beq :end
  3019. - pea #','
  3020. - _WriteChar
  3021. - brl :loop
  3022. -
  3023. -:end lda ]num_char
  3024. - beq :rts
  3025. - lda ~assembler
  3026. - cmp #MERLIN
  3027. - beq :10
  3028. - pea #'''
  3029. - _WriteChar
  3030. -:10 put_cr
  3031. - lda @parse_data+`count
  3032. - beq :rts
  3033. - brl :4
  3034. -:rts stz @parse_data+`on ;turn off parsing of data
  3035. - rts
  3036. -
  3037. -:dc_i_asm asc !dc     i1'!,00
  3038. -
  3039. -
  3040. -**************************************************
  3041. -* parse reference-address-type DC statement.     *
  3042. -* ---------------------------------------------- *
  3043. -* (input)                                        *
  3044. -*  x - HOW handle of label name.                 *
  3045. -*  y - LOW handle of label name.                 *
  3046. -**************************************************
  3047. -parse_GLOBAL_type_K equ *
  3048. -]label_handle = $b0 ;handle to name of label
  3049. -]label_ptr = $b4
  3050. -]label_len = $b8 ;length of label
  3051. -]record = $b8 ;record number
  3052. -
  3053. - stx ]label_handle+2
  3054. - sty ]label_handle
  3055. -
  3056. - lda []label_handle]
  3057. - sta ]label_ptr
  3058. - tax
  3059. - ldy #2
  3060. - lda []label_handle],y
  3061. - sta ]label_ptr+2
  3062. -
  3063. - pha
  3064. - phx
  3065. - pea #2
  3066. - lda []label_ptr]
  3067. - sta ]label_len
  3068. - pha
  3069. - _TextWriteBlock
  3070. - lda ]label_len
  3071. - cmp #12
  3072. - blt :0
  3073. - pea #' '
  3074. - _WriteChar
  3075. - bra :1
  3076. -:0 pea #^blank_str
  3077. - pea #blank_str
  3078. - pea #0
  3079. - sec
  3080. - lda #12
  3081. - sbc ]label_len
  3082. - pha
  3083. - _TextWriteBlock
  3084. -
  3085. -:1 stz ]record
  3086. - read_char ]record
  3087. -
  3088. - lda ]record
  3089. - jmp parse_STRONG
  3090. -
  3091. -
  3092. -**************************************************
  3093. -* parse soft-reference-type DC statement.        *
  3094. -* ---------------------------------------------- *
  3095. -* (input)                                        *
  3096. -*  a - length.                                   *
  3097. -*  x - HOW handle of label name.                 *
  3098. -*  y - LOW handle of label name.                 *
  3099. -**************************************************
  3100. -parse_GLOBAL_type_L equ *
  3101. -]label_handle = $b0 ;handle to label name
  3102. -]label_ptr = $b4
  3103. -]label_len = $b8
  3104. -]record = $b0 ;record number
  3105. -]const_count = $b0 ;counter for CONST
  3106. -]edge = $b2 ;right margin
  3107. -]num_char = $b4 ;length of output
  3108. -]soft_value = $b6 ;reference value read in
  3109. -]count = $b8 ;number of soft-reference values to display
  3110. -]tmp_asm = $ba ;copy of ~assembler
  3111. -
  3112. - sta ]count
  3113. - sta @parse_data+`count
  3114. - sta @parse_data+`on ;enable flag to parse data
  3115. - stx ]label_handle+2
  3116. - sty ]label_handle
  3117. -
  3118. - lda ~assembler ;short-reference type DC statement
  3119. - sta ]tmp_asm ;only available for Orca assembler
  3120. - lda #ORCA
  3121. - sta ~assembler
  3122. -
  3123. - lda []label_handle]
  3124. - sta ]label_ptr
  3125. - tax
  3126. - ldy #2
  3127. - lda []label_handle],y
  3128. - sta ]label_ptr+2
  3129. -
  3130. - pha
  3131. - phx
  3132. - pea #2
  3133. - lda []label_ptr]
  3134. - sta ]label_len
  3135. - pha
  3136. - _TextWriteBlock
  3137. - lda ]label_len
  3138. - cmp #12
  3139. - blt :0
  3140. - pea #' '
  3141. - _WriteChar
  3142. - bra :1
  3143. -:0 pea #^blank_str
  3144. - pea #blank_str
  3145. - pea #0
  3146. - sec
  3147. - lda #12
  3148. - sbc ]label_len
  3149. - pha
  3150. - _TextWriteBlock
  3151. -
  3152. -:1 lda #0
  3153. - ldx }nooffset
  3154. - beq :2
  3155. - lda #16
  3156. -:2 clc
  3157. - adc #SOFT_REFERENCE_EDGE
  3158. - sta ]edge
  3159. - sta @parse_data+`edge
  3160. - stz ]soft_value
  3161. - stz ]record
  3162. - stz ]num_char
  3163. -
  3164. -:read_record read_char ]record ;read record to parse
  3165. - lda ]record
  3166. - ldx ]num_char
  3167. - jsr parse_GLOBAL_type
  3168. - beq :print_const
  3169. - lda @parse_data+`count
  3170. - sta ]count
  3171. - beq :end_read
  3172. -:3 jsr print_offset
  3173. - pea #^space_12
  3174. - pea #space_12
  3175. - _WriteCString
  3176. - bra :read_record
  3177. -:end_read brl :rts
  3178. -
  3179. -:print_const stz ]num_char
  3180. - pea #^:REFERENCE_asm
  3181. - pea #:REFERENCE_asm
  3182. - _WriteCString
  3183. -:loop read_char ]soft_value
  3184. - ldx ]soft_value
  3185. - jsr print_char_dec
  3186. - inc ;add comma character
  3187. - clc
  3188. - adc ]num_char
  3189. - sta ]num_char
  3190. - dec ]const_count
  3191. - dec @parse_data+`count
  3192. -
  3193. - incr @omf+`displacement
  3194. - incr @omf+`counter
  3195. -
  3196. - lda ]num_char
  3197. - cmp ]edge
  3198. - blt :5
  3199. - beq :5
  3200. - pea #'''
  3201. - _WriteChar
  3202. - put_cr
  3203. - lda @parse_data+`count ;end if no more records to display
  3204. - beq :rts
  3205. - stz ]num_char
  3206. - lda ]const_count ;if at end of CONST record, read next
  3207. - bne :4 ;record
  3208. - brl :3
  3209. -:4 jsr print_offset
  3210. - pea #^space_12
  3211. - pea #space_12
  3212. - _WriteCString
  3213. - pea #^:REFERENCE_asm
  3214. - pea #:REFERENCE_asm
  3215. - _WriteCString
  3216. - brl :loop
  3217. -:5 lda ]const_count
  3218. - beq :end
  3219. - pea #','
  3220. - _WriteChar
  3221. - brl :loop
  3222. -
  3223. -:end lda ]num_char
  3224. - beq :rts
  3225. - pea #'''
  3226. - _WriteChar
  3227. - put_cr
  3228. - lda @parse_data+`count
  3229. - beq :rts
  3230. - brl :3
  3231. -:rts stz @parse_data+`on ;turn off parsing of data
  3232. - lda ]tmp_asm
  3233. - sta ~assembler
  3234. - rts
  3235. -
  3236. -:REFERENCE_asm asc !dc     s1'!,00
  3237. -
  3238. -
  3239. -**************************************************
  3240. -* parse assembler entry directive.               *
  3241. -* ---------------------------------------------- *
  3242. -* (input)                                        *
  3243. -*  x - HOW handle of label name.                 *
  3244. -*  y - LOW handle of label name.                 *
  3245. -**************************************************
  3246. -parse_GLOBAL_type_N equ *
  3247. -]label_handle = $b0 ;handle to label name
  3248. -]label_ptr = $b4
  3249. -]label_len = $b8 ;length of label
  3250. -]segname_handle = $ba ;handle to segment name
  3251. -]segname_ptr = $ba
  3252. -]segname_len = $be ;length of segment name
  3253. -]expr_handle = $b0 ;handle to resulting expression
  3254. -]expr_ptr = $b4
  3255. -
  3256. - stx ]label_handle+2
  3257. - sty ]label_handle
  3258. - phx
  3259. - phy
  3260. - phx
  3261. - phy
  3262. - _HLock
  3263. -
  3264. - lda []label_handle]
  3265. - sta ]label_ptr
  3266. - tax
  3267. - ldy #2
  3268. - lda []label_handle],y
  3269. - sta ]label_ptr+2
  3270. -
  3271. - pha
  3272. - phx
  3273. - pea #2
  3274. - lda []label_ptr]
  3275. - sta ]label_len
  3276. - pha
  3277. - _TextWriteBlock
  3278. - lda ]label_len
  3279. - cmp #12
  3280. - blt :0
  3281. - pea #' '
  3282. - _WriteChar
  3283. - bra :1
  3284. -:0 pea #^blank_str
  3285. - pea #blank_str
  3286. - pea #0
  3287. - sec
  3288. - lda #12
  3289. - sbc ]label_len
  3290. - pha
  3291. - _TextWriteBlock
  3292. -
  3293. -:1 ldx #^:equ
  3294. - ldy #:equ
  3295. - lda ~assembler
  3296. - cmp #MERLIN
  3297. - beq :2
  3298. - ldx #^:entry
  3299. - ldy #:entry
  3300. -:2 phx
  3301. - phy
  3302. - _WriteCString
  3303. - put_cr
  3304. -
  3305. - lda }label
  3306. - bne :add_label
  3307. - _HUnlock
  3308. - rts
  3309. -:add_label ldx @omf+`segname
  3310. - ldy @omf+`segname+2
  3311. - stx ]segname_handle
  3312. - sty ]segname_handle+2
  3313. - phy
  3314. - phx
  3315. - phy
  3316. - phx
  3317. - _HLock
  3318. - ldy #2
  3319. - lda []segname_handle],y
  3320. - tax
  3321. - lda []segname_handle]
  3322. - sta ]segname_ptr
  3323. - stx ]segname_ptr+2
  3324. - lda []segname_ptr]
  3325. - sta ]segname_len
  3326. -
  3327. - pha ;long - result
  3328. - pha
  3329. - clc  ;long - block size
  3330. - lda ]segname_len
  3331. - adc #14
  3332. - pea #0
  3333. - pha
  3334. - lda userID ;word - user ID of block
  3335. - pha
  3336. - pea #attrNoSpec+attrLocked ;word - block attributes
  3337. - pha ;long - start of block
  3338. - pha
  3339. - _NewHandle
  3340. - lda 1,s
  3341. - sta ]expr_handle
  3342. - lda 3,s
  3343. - sta ]expr_handle+2
  3344. - lda []expr_handle]
  3345. - sta ]expr_ptr
  3346. - ldy #2
  3347. - lda []expr_handle],y
  3348. - sta ]expr_ptr+2
  3349. -
  3350. - ldy #2
  3351. - lda #'('
  3352. - sta []expr_ptr],y
  3353. -
  3354. - ldy #2
  3355. - ldx #3
  3356. - shorta
  3357. -:copy_segname lda []segname_ptr],y
  3358. - phy
  3359. - txy
  3360. - sta []expr_ptr],y
  3361. - ply
  3362. - inx
  3363. - iny
  3364. - dec ]segname_len
  3365. - bne :copy_segname
  3366. - txy
  3367. - lda #'+'
  3368. - sta []expr_ptr],y
  3369. - iny
  3370. - lda #'$'
  3371. - sta []expr_ptr],y
  3372. - iny
  3373. - longa
  3374. - phy
  3375. -
  3376. - ldx @omf+`counter ;long - longint to convert
  3377. - ldy @omf+`counter+2
  3378. - phy
  3379. - phx
  3380. - pea #^long_hex_str ;long - pointer to output string
  3381. - pea #long_hex_str
  3382. - pea #8 ;word - length of string
  3383. - _Long2Hex
  3384. - ldx #7
  3385. - lda @omf+`counter ;special case value of 0
  3386. - ora @omf+`counter+2
  3387. - beq :4
  3388. - lda #8
  3389. - ldx #long_hex_str ;make hex alpha lowercase
  3390. - ldy #^long_hex_str
  3391. - jsr lowercase_hex
  3392. - ldx #$ffff
  3393. -:3 inx
  3394. - lda long_hex_str,x
  3395. - and #$ff
  3396. - cmp #'0'
  3397. - beq :3
  3398. -:4 ply
  3399. - shorta
  3400. -:copy_value lda long_hex_str,x
  3401. - sta []expr_ptr],y
  3402. - inx
  3403. - iny
  3404. - cpx #8
  3405. - blt :copy_value
  3406. - lda #')'
  3407. - sta []expr_ptr],y
  3408. - longa
  3409. - tya  ;y holds length of label string - 1
  3410. - dec
  3411. - sta []expr_ptr]
  3412. - _HUnlock
  3413. - _HUnlock
  3414. - _HUnlock
  3415. -
  3416. - pei ]label_handle+2
  3417. - pei ]label_handle
  3418. - pei ]expr_handle+2
  3419. - pei ]expr_handle
  3420. - pea #GLOBAL
  3421. - jsr add_label
  3422. - rts
  3423. -
  3424. -:equ cStr 'equ    *'
  3425. -:entry cStr 'entry'
  3426. -
  3427. -
  3428. -**************************************************
  3429. -* parse DS statement.                            *
  3430. -* ---------------------------------------------- *
  3431. -* (input)                                        *
  3432. -*  x - HOW handle of label name.                 *
  3433. -*  y - LOW handle of label name.                 *
  3434. -**************************************************
  3435. -parse_GLOBAL_type_S equ *
  3436. -]label_handle = $b0 ;handle to name of label
  3437. -]label_ptr = $b4
  3438. -]label_len = $b8
  3439. -]record = $b8
  3440. -
  3441. - stx ]label_handle+2
  3442. - sty ]label_handle
  3443. -
  3444. - lda []label_handle]
  3445. - sta ]label_ptr
  3446. - tax
  3447. - ldy #2
  3448. - lda []label_handle],y
  3449. - sta ]label_ptr+2
  3450. -
  3451. - pha
  3452. - phx
  3453. - pea #2
  3454. - lda []label_ptr]
  3455. - sta ]label_len
  3456. - pha
  3457. - _TextWriteBlock
  3458. - lda ]label_len
  3459. - cmp #12
  3460. - blt :0
  3461. - pea #' '
  3462. - _WriteChar
  3463. - bra :1
  3464. -:0 pea #^blank_str
  3465. - pea #blank_str
  3466. - pea #0
  3467. - sec
  3468. - lda #12
  3469. - sbc ]label_len
  3470. - pha
  3471. - _TextWriteBlock
  3472. -
  3473. -:1 stz ]record
  3474. - read_char ]record
  3475. -
  3476. - lda ]record
  3477. - jmp parse_GLOBAL_type
  3478. -
  3479. -
  3480. -**************************************************
  3481. -* parse arguments to LOCAL/GLOBAL labels.        *
  3482. -* ---------------------------------------------- *
  3483. -* (input)                                        *
  3484. -*  a - record number.                            *
  3485. -* (output)                                       *
  3486. -*  a - if expression parsed by this routine.     *
  3487. -**************************************************
  3488. -parse_GLOBAL_type equ *
  3489. -
  3490. - cmp #EXPR
  3491. - beq :expr
  3492. - cmp #BEXPR
  3493. - beq :expr
  3494. - cmp #RELEXPR
  3495. - beq :expr
  3496. - cmp #LEXPR
  3497. - bne :ds
  3498. -:expr ldx #0
  3499. - ldy #TRUE
  3500. - jsr parse_record
  3501. - phx
  3502. - lda ~assembler
  3503. - cmp #ORCA
  3504. - bne :0
  3505. - pea #'''
  3506. - _WriteChar
  3507. -:0 pla
  3508. - beq :true
  3509. - lda }assembly
  3510. - beq :true
  3511. - put_cr
  3512. - bra :true
  3513. -
  3514. -:ds cmp #DS
  3515. - bne :end
  3516. - jsr parse_DS
  3517. - bra :true
  3518. -
  3519. -:end cmp #END
  3520. - bne :default
  3521. - put_cr
  3522. - put_cr
  3523. - lda #PREMATURE_END ;if at EOF of OMF file, premature end
  3524. - ldx #0 ;of file reached
  3525. - txy
  3526. - jsr error
  3527. -
  3528. -:default lda #FALSE
  3529. - rts
  3530. -
  3531. -:true lda #TRUE
  3532. - rts
  3533. -
  3534. -
  3535. -**************************************************
  3536. -flo_asm asc !flo    '!,00 ;merlin extended directive
  3537. -
  3538. -
  3539. -**************************************************
  3540. - sav asm.l
  3541. + END OF ARCHIVE
  3542.