home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sources / apple2 / 15 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  42.2 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: v001SRC073:  coff (OMF Disassembler) 08/09
  5. Message-ID: <Nov.8.19.12.41.1992.16626@yoko.rutgers.edu>
  6. Date: 9 Nov 92 00:12:42 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 1929
  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:73
  14. Archive-name: utility/gs/disassem/coff/part08
  15. Architecture: ONLY_2gs
  16. Version-number: 1.1
  17.  
  18.  
  19. =structure.s
  20. - lst off
  21. -
  22. -* UNIX coff utility
  23. -* data structure 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.output ;external output 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. -
  43. - use coff.mac ;macro definitions
  44. - use 4/datatype.mac ;HLL data types
  45. -
  46. -
  47. -**************************************************
  48. -* add label name and expression evaluation to    *
  49. -* label stack.                                   *
  50. -* ---------------------------------------------- *
  51. -* (input)                                        *
  52. -*  long - handle to replacement label name.      *
  53. -*  long - handle to label expression.            *
  54. -*  word - label type.                            *
  55. -**************************************************
  56. -add_label ent
  57. -]type = $e0 ;type of label
  58. -]name_handle = $e2 ;handle to label name
  59. -]expr_handle = $e6 ;expression label evaluates to
  60. -]node_handle = $ea ;label node
  61. -]node_ptr = $ee
  62. -]label_last_handle = $f2 ;handle to first element in linked list
  63. -]label_last_ptr = $f6
  64. -
  65. - pla ;return address
  66. - plx
  67. - stx ]type
  68. - plx
  69. - ply
  70. - stx ]expr_handle
  71. - sty ]expr_handle+2
  72. - plx
  73. - ply
  74. - stx ]name_handle
  75. - sty ]name_handle+2
  76. - pha ;push return address back on stack
  77. -
  78. - pha ;long - result
  79. - pha
  80. - pea #0 ;long - block size
  81. - pea #18
  82. - lda userID ;word - user ID of block
  83. - pha
  84. - pea #attrNoSpec ;word - block attributes
  85. - pha ;long - start of block
  86. - pha
  87. - _NewHandle
  88. - plx
  89. - ply
  90. - stx ]node_handle
  91. - sty ]node_handle+2
  92. - lda []node_handle]
  93. - sta ]node_ptr
  94. - ldy #2
  95. - lda []node_handle],y
  96. - sta ]node_ptr+2
  97. -
  98. - lda @label+`last
  99. - ora @label+`last+2
  100. - bne :0
  101. - ldx ]node_handle
  102. - ldy ]node_handle+2
  103. - stx @label+`next
  104. - sty @label+`next+2
  105. - ldy #`prev ;make first previous node NULL
  106. - lda #NULL
  107. - sta []node_ptr],y
  108. - ldy #`prev+2
  109. - sta []node_ptr],y
  110. - bra :1
  111. -
  112. -:0 ldx @label+`last
  113. - ldy @label+`last+2
  114. - stx ]label_last_handle
  115. - sty ]label_last_handle+2
  116. - lda []label_last_handle]
  117. - sta ]label_last_ptr
  118. - ldy #2
  119. - lda []label_last_handle],y
  120. - sta ]label_last_ptr+2
  121. - ldy #`next ;make next label after last current node
  122. - lda ]node_handle
  123. - sta []label_last_ptr],y
  124. - ldy #`next+2
  125. - lda ]node_handle+2
  126. - sta []label_last_ptr],y
  127. - ldy #`prev ;make previous node last node
  128. - lda ]label_last_handle
  129. - sta []node_ptr],y
  130. - ldy #`prev+2
  131. - lda ]label_last_handle+2
  132. - sta []node_ptr],y
  133. -
  134. -:1 ldy #`label_name ;store label name
  135. - lda ]name_handle
  136. - sta []node_ptr],y
  137. - ldy #`label_name+2
  138. - lda ]name_handle+2
  139. - sta []node_ptr],y
  140. - ldy #`expr_name ;store expression evaluation string
  141. - lda ]expr_handle
  142. - sta []node_ptr],y
  143. - ldy #`expr_name+2
  144. - lda ]expr_handle+2
  145. - sta []node_ptr],y
  146. - ldy #`type ;store label type
  147. - lda ]type
  148. - sta []node_ptr],y
  149. - ldy #`next ;make next node NULL
  150. - lda #NULL
  151. - sta []node_ptr],y
  152. - ldy #`next+2
  153. - sta []node_ptr],y
  154. -
  155. - ldx ]node_handle ;make new last node
  156. - ldy ]node_handle+2
  157. - stx @label+`last
  158. - sty @label+`last+2
  159. - rts
  160. -
  161. -
  162. -**************************************************
  163. -* delete labels from label array.                *
  164. -* ---------------------------------------------- *
  165. -* (input)                                        *
  166. -*  a - delete LOCAL or GLOBAL labels.            *
  167. -**************************************************
  168. -delete_labels ent
  169. -]label_type = $e0 ;type of label to delete
  170. -]label_handle = $e2 ;handle to current label
  171. -]label_ptr = $e6
  172. -]prev_label_handle = $ea ;handle to previous label
  173. -]prev_label_ptr = $ee
  174. -
  175. - sta ]label_type
  176. -
  177. - ldx #^@label ;make first label previous label. first
  178. - ldy #@label ;label structure is header node.
  179. - stx ]prev_label_ptr+2
  180. - sty ]prev_label_ptr
  181. -
  182. - stz @label+`last ;re-initialize last node
  183. - stz @label+`last+2
  184. - ldx @label+`next
  185. - ldy @label+`next+2
  186. - stx ]label_handle
  187. - sty ]label_handle+2
  188. - lda []label_handle]
  189. - sta ]label_ptr
  190. - ldy #2
  191. - lda []label_handle],y
  192. - sta ]label_ptr+2
  193. - lda ]label_handle
  194. - ora ]label_handle+2
  195. - bne :delete_label
  196. - rts
  197. -
  198. -:delete_label ldy #`type
  199. - lda []label_ptr],y
  200. - cmp ]label_type
  201. - bne :0
  202. - ldy #`next
  203. - lda []label_ptr],y
  204. - sta []prev_label_ptr],y
  205. - ldy #`next+2
  206. - lda []label_ptr],y
  207. - sta []prev_label_ptr],y
  208. - pei ]label_handle+2
  209. - pei ]label_handle
  210. - _DisposeHandle
  211. - bra :next_label
  212. -
  213. -:0 ldx ]label_handle
  214. - ldy ]label_handle+2
  215. - stx @label+`last
  216. - sty @label+`last+2
  217. - stx ]prev_label_handle
  218. - sty ]prev_label_handle+2
  219. - lda []prev_label_handle]
  220. - sta ]prev_label_ptr
  221. - ldy #2
  222. - lda []prev_label_handle],y
  223. - sta ]prev_label_ptr+2
  224. -
  225. -:next_label ldy #`next ;prepare to examine next label in
  226. - lda []label_ptr],y ;linked list
  227. - sta ]label_handle
  228. - ldy #`next+2
  229. - lda []label_ptr],y
  230. - sta ]label_handle+2
  231. - lda []label_handle]
  232. - sta ]label_ptr
  233. - ldy #2
  234. - lda []label_handle],y
  235. - sta ]label_ptr+2
  236. - lda ]label_handle ;end if at end of linked list
  237. - ora ]label_handle+2
  238. - bne :delete_label
  239. - rts
  240. -
  241. -
  242. -**************************************************
  243. -* delete @expr_list stack.                       *
  244. -**************************************************
  245. -delete_expr_list ent
  246. -]list_lo_handle = $f0
  247. -]list_hi_handle = $f4
  248. -]list_lo_ptr = $f8
  249. -]list_hi_ptr = $fc
  250. -
  251. - ldx @expr_list+`lo
  252. - ldy @expr_list+`lo+2
  253. - stx ]list_lo_handle
  254. - sty ]list_lo_handle+2
  255. - ldx @expr_list+`hi
  256. - ldy @expr_list+`hi+2
  257. - stx ]list_hi_handle
  258. - sty ]list_hi_handle+2
  259. - lda []list_lo_handle]
  260. - sta ]list_lo_ptr
  261. - ldy #2
  262. - lda []list_lo_handle],y
  263. - sta ]list_lo_ptr+2
  264. - lda []list_hi_handle],y
  265. - sta ]list_hi_ptr
  266. - ldy #2
  267. - lda []list_hi_handle],y
  268. - sta ]list_hi_ptr+2
  269. -
  270. - ldy @expr_list+`size
  271. -:delete_list phy
  272. - lda []list_hi_ptr],y
  273. - pha
  274. - lda []list_lo_ptr],y
  275. - pha
  276. - _DisposeHandle
  277. - ply
  278. - dey
  279. - bne :delete_list
  280. -
  281. - pei ]list_lo_handle+2
  282. - pei ]list_lo_handle
  283. - _DisposeHandle
  284. - pei ]list_hi_handle+2
  285. - pei ]list_hi_handle
  286. - _DisposeHandle
  287. - rts
  288. -
  289. -
  290. -**************************************************
  291. -* match operator value with its string           *
  292. -* representation.                                *
  293. -* ---------------------------------------------- *
  294. -* (input)                                        *
  295. -*  a - operator value.                           *
  296. -* (output)                                       *
  297. -*  x - HOW of string representing operator.      *
  298. -*  y - LOW of string representing operator.      *
  299. -**************************************************
  300. -find_operator ent
  301. -
  302. - ldx #0 ;default is NULL string
  303. - ldy #0
  304. -
  305. - cmp #ADD
  306. - bne :sub
  307. - ldx #^:add_str
  308. - ldy #:add_str
  309. - rts
  310. -:sub cmp #SUB
  311. - bne :mul
  312. - ldx #^:sub_str
  313. - ldy #:sub_str
  314. - rts
  315. -:mul cmp #MUL
  316. - bne :div
  317. - ldx #^:mul_str
  318. - ldy #:mul_str
  319. - rts
  320. -:div cmp #DIV
  321. - bne :mod
  322. - ldx #^:div_str
  323. - ldy #:div_str
  324. - rts
  325. -:mod cmp #MOD
  326. - bne :negation
  327. - ldx #^:mod_str
  328. - ldy #:mod_str
  329. - rts
  330. -:negation cmp #NEGATION
  331. - bne :bit_shift
  332. - ldx #^:negation_str
  333. - ldy #:negation_str
  334. - rts
  335. -:bit_shift cmp #BIT_SHIFT
  336. - bne :and
  337. - ldx #^:bit_shift_str
  338. - ldy #:bit_shift_str
  339. - rts
  340. -:and cmp #AND
  341. - bne :or
  342. - ldx #^:and_str
  343. - ldy #:and_str
  344. - rts
  345. -:or cmp #OR
  346. - bne :eor
  347. - ldx #^:or_str
  348. - ldy #:or_str
  349. - rts
  350. -:eor cmp #EOR
  351. - bne :not
  352. - ldx #^:eor_str
  353. - ldy #:eor_str
  354. - rts
  355. -:not cmp #NOT
  356. - bne :less_equal
  357. - ldx #^:not_str
  358. - ldy #:not_str
  359. - rts
  360. -:less_equal cmp #LESS_EQUAL
  361. - bne :greater_equal
  362. - ldx #^:less_equal_str
  363. - ldy #:less_equal_str
  364. - rts
  365. -:greater_equal cmp #GREATER_EQUAL
  366. - bne :not_equal
  367. - ldx #^:greater_equal_str
  368. - ldy #:greater_equal_str
  369. - rts
  370. -:not_equal cmp #NOT_EQUAL
  371. - bne :less
  372. - ldx #^:not_equal_str
  373. - ldy #:not_equal_str
  374. - rts
  375. -:less cmp #LESS
  376. - bne :greater
  377. - ldx #^:less_str
  378. - ldy #:less_str
  379. - rts
  380. -:greater cmp #GREATER
  381. - bne :equal
  382. - ldx #^:greater_str
  383. - ldy #:greater_str
  384. - rts
  385. -:equal cmp #EQUAL
  386. - bne :logical_and
  387. - ldx #^:equal_str
  388. - ldy #:equal_str
  389. - rts
  390. -:logical_and cmp #LOGICAL_AND
  391. - bne :inclusive_or
  392. - ldx #^:logical_and_str
  393. - ldy #:logical_and_str
  394. - rts
  395. -:inclusive_or cmp #INCLUSIVE_OR
  396. - bne :exclusive_or
  397. - ldx #^:inclusive_or_str
  398. - ldy #:inclusive_or_str
  399. - rts
  400. -:exclusive_or cmp #EXCLUSIVE_OR
  401. - bne :complement
  402. - ldx #^:exclusive_or_str
  403. - ldy #:exclusive_or_str
  404. - rts
  405. -:complement cmp #COMPLEMENT
  406. - bne :label_length
  407. - ldx #^:complement_str
  408. - ldy #:complement_str
  409. - rts
  410. -:label_length cmp #LABEL_LENGTH
  411. - bne :end
  412. - ldx #^:label_length_str
  413. - ldy #:label_length_str
  414. -:end rts
  415. -
  416. -:add_str strl '+'
  417. -:sub_str strl '-'
  418. -:mul_str strl '*'
  419. -:div_str strl '/'
  420. -:mod_str strl '%%'
  421. -:negation_str strl '~'
  422. -:bit_shift_str strl '|'
  423. -:and_str strl '&&'
  424. -:or_str strl '||'
  425. -:eor_str strl '.eor.'
  426. -:not_str strl '!'
  427. -:less_equal_str strl '<='
  428. -:greater_equal_str strl '>='
  429. -:not_equal_str strl '<>'
  430. -:less_str strl '<'
  431. -:greater_str strl '>'
  432. -:equal_str strl '='
  433. -:logical_and_str strl '&'
  434. -:inclusive_or_str strl '.ior.'
  435. -:exclusive_or_str strl '.beor.'
  436. -:complement_str strl '.bnot.'
  437. -:label_length_str strl 'length ('
  438. -
  439. -
  440. -**************************************************
  441. -* match label name with expression name.         *
  442. -* ---------------------------------------------- *
  443. -* (input)                                        *
  444. -*  x - LOW of expression name.                   *
  445. -*  y - HOW of expression name.                   *
  446. -* (output)                                       *
  447. -*  x - HOW of label name (NULL if not found).    *
  448. -*  y - LOW of label name (NULL if not found).    *
  449. -**************************************************
  450. -match_label ent
  451. -]expr_ptr = $f0 ;expression name string
  452. -]label_handle = $f4 ;linked list of labels
  453. -]label_ptr = $f8
  454. -]expr_name_handle = $fc ;expression evaluation
  455. -]expr_name_ptr = $fc
  456. -]label_name_handle = $fc ;label name
  457. -
  458. - stx ]expr_ptr
  459. - sty ]expr_ptr+2
  460. -
  461. - lda @label+`next ;fail if no labels in list
  462. - ora @label+`next+2
  463. - beq :fail
  464. - ldx @label+`next
  465. - ldy @label+`next+2
  466. - stx ]label_handle
  467. - sty ]label_handle+2
  468. -:loop lda []expr_ptr]
  469. - sta :expr_len
  470. - lda []label_handle]
  471. - sta ]label_ptr
  472. - ldy #2
  473. - lda []label_handle],y
  474. - sta ]label_ptr+2
  475. - ldy #`expr_name
  476. - lda []label_ptr],y
  477. - sta ]expr_name_handle
  478. - ldy #`expr_name+2
  479. - lda []label_ptr],y
  480. - sta ]expr_name_handle+2
  481. - ldy #2
  482. - lda []expr_name_handle],y
  483. - tay
  484. - lda []expr_name_handle]
  485. - sta ]expr_name_ptr
  486. - sty ]expr_name_ptr+2
  487. -
  488. - lda []expr_name_ptr] ;no comparison if lengths different
  489. - cmp :expr_len
  490. - bne :end_loop
  491. -
  492. - ldy #2 ;compare strings
  493. - shorta
  494. -:0 lda []expr_name_ptr],y
  495. - cmp []expr_ptr],y
  496. - bne :end_loop
  497. - iny
  498. - dec :expr_len
  499. - bne :0
  500. - longa
  501. -
  502. - ldy #`label_name
  503. - lda []label_ptr],y
  504. - sta ]label_name_handle
  505. - ldy #`label_name+2
  506. - lda []label_ptr],y
  507. - sta ]label_name_handle+2
  508. - lda []label_name_handle]
  509. - tax
  510. - ldy #2
  511. - lda []label_name_handle],y
  512. - tay
  513. - rts
  514. -
  515. -:end_loop longa
  516. - ldy #`next
  517. - lda []label_ptr],y
  518. - sta ]label_handle
  519. - ldy #`next+2
  520. - lda []label_ptr],y
  521. - sta ]label_handle+2
  522. - ora ]label_handle
  523. - bne :loop
  524. -
  525. -:fail ldx #NULL
  526. - ldy #NULL
  527. - rts
  528. -
  529. -:expr_len dw 0 ;length of expression string
  530. -
  531. -
  532. -**************************************************
  533. -* push value onto @expr_list stack.              *
  534. -* ---------------------------------------------- *
  535. -* (input)                                        *
  536. -*  a - expression value.                         *
  537. -*  x - LOW of expression label.                  *
  538. -*  y - HOW of expression label.                  *
  539. -**************************************************
  540. -push_expr_list ent
  541. -]list_lo_handle = $e0
  542. -]list_hi_handle = $e4
  543. -]list_lo_ptr = $e8
  544. -]list_hi_ptr = $ec
  545. -]expr_value = $f0 ;expression value
  546. -]expr_handle = $f2 ;handle to expression name
  547. -]expr_ptr = $f6
  548. -
  549. - sta ]expr_value
  550. - stx ]expr_handle
  551. - sty ]expr_handle+2
  552. -
  553. - txa ;alloc handle if operator is being
  554. - ora ]expr_handle+2 ;pushed on stack
  555. - bne :0
  556. -
  557. - pha ;long - result
  558. - pha
  559. - pea #0 ;long - block size
  560. - pea #2
  561. - lda userID ;word - user ID of block
  562. - pha
  563. - pea #attrNoCross ;word - block attributes
  564. - pha ;long - start of block
  565. - pha
  566. - _NewHandle
  567. - plx
  568. - ply
  569. - stx ]expr_handle
  570. - sty ]expr_handle+2
  571. -
  572. -:0 lda []expr_handle]
  573. - sta ]expr_ptr
  574. - ldy #2
  575. - lda []expr_handle],y
  576. - sta ]expr_ptr+2
  577. - lda ]expr_value
  578. - sta []expr_ptr]
  579. -
  580. - lda @expr_list+`size
  581. - inc
  582. - asl
  583. - pea #0
  584. - pha
  585. - pea #0
  586. - pha
  587. - ldx @expr_list+`lo
  588. - ldy @expr_list+`lo+2
  589. - phy
  590. - phx
  591. - _SetHandleSize
  592. - ldx @expr_list+`hi
  593. - ldy @expr_list+`hi+2
  594. - phy
  595. - phx
  596. - _SetHandleSize
  597. -
  598. - ldx @expr_list+`lo
  599. - ldy @expr_list+`lo+2
  600. - stx ]list_lo_handle
  601. - sty ]list_lo_handle+2
  602. - ldx @expr_list+`hi
  603. - ldy @expr_list+`hi+2
  604. - stx ]list_hi_handle
  605. - sty ]list_hi_handle+2
  606. - lda []list_lo_handle]
  607. - sta ]list_lo_ptr
  608. - ldy #2
  609. - lda []list_lo_handle],y
  610. - sta ]list_lo_ptr+2
  611. - lda []list_hi_handle]
  612. - sta ]list_hi_ptr
  613. - ldy #2
  614. - lda []list_hi_handle],y
  615. - sta ]list_hi_ptr+2
  616. -
  617. - lda @expr_list+`size
  618. - asl
  619. - tay
  620. - lda ]expr_handle
  621. - sta []list_lo_ptr],y
  622. - lda ]expr_handle+2
  623. - sta []list_hi_ptr],y
  624. - inc @expr_list+`size
  625. - rts
  626. -
  627. -
  628. -**************************************************
  629. - sav structure.l
  630. =general.s
  631. - lst off
  632. -
  633. -* UNIX coff utility
  634. -* general routines
  635. -*
  636. -* 1990-1992, tao Developer Project
  637. -
  638. - rel
  639. - xc
  640. - xc
  641. - mx %00
  642. -
  643. - put coff.h ;global defines
  644. - put x.data ;data externals
  645. - put x.gsos ;GS/OS i/o externals
  646. - put x.tool ;ToolBox, GS/OS, ROM externals
  647. -
  648. - put 4/gsos.h ;GS/OS defines
  649. - put 4/memory.h ;memory manager defines
  650. - put 4/resource.h ;resouce manager defines
  651. - put 4/texttool.h ;text tool defines
  652. - put 4/getopt.h ;getopt command-line option defines
  653. - put 4/env.h ;run-time environment settings
  654. -
  655. - use coff.mac ;macro definitions
  656. - use 4/datatype.mac ;HLL data types
  657. - use 4/env.mac ;run-time environment macros
  658. -
  659. -
  660. -FloatDecimal equ $00 ;input to @dec_form is float
  661. -FixedDecimal equ $01 ;input to @dec_form is fixed
  662. -
  663. -;@dec_form data structure offsets
  664. -`style equ $00 ;output style (FloatDecimal, FixedDecimal)
  665. -`digits equ `style+2 ;number of significant digits
  666. -
  667. -;@decimal data structure offsets
  668. -`sgn equ $00 ;sign of number
  669. -`exp equ `sgn+2 ;exponent value
  670. -`sig equ `exp+2
  671. -
  672. -
  673. -**************************************************
  674. -* store global command-line pointer to local     *
  675. -* dp variables.                                  *
  676. -* ---------------------------------------------- *
  677. -* (input)                                        *
  678. -*  a - offset into dp for where to store `lo,    *
  679. -*      `hi pointers.                             *
  680. -**************************************************
  681. -dp_argv ent
  682. -]argv_lo = $00 ;pointer to argv+`lo data
  683. -]argv_hi = $04 ;pointer to argv+`hi data
  684. -
  685. - sta $fe ;offset into dp
  686. - clc
  687. - tdc
  688. - tax ;save dp register
  689. - adc $fe
  690. - tcd
  691. - lda argv+`lo
  692. - sta ]argv_lo
  693. - lda argv+`lo+2
  694. - sta ]argv_lo+2
  695. -
  696. - lda argv+`hi
  697. - sta ]argv_hi
  698. - lda argv+`hi+2
  699. - sta ]argv_hi+2
  700. - txa ;restore dp register
  701. - tcd
  702. - rts
  703. -
  704. -
  705. -**************************************************
  706. -* display error messages.                        *
  707. -* ---------------------------------------------- *
  708. -* (input)                                        *
  709. -*  a - error number.                             *
  710. -*  x - possible parameter (depending on error).  *
  711. -*  y - possible parameter (depending on error).  *
  712. -**************************************************
  713. -error ent
  714. -]argv_lo = $f0
  715. -]argv_hi = $f4
  716. -]parm_ptr = $f8 ;pointer to parameter
  717. -
  718. - stx ]parm_ptr
  719. - sty ]parm_ptr+2
  720. - tax
  721. - and #%11111111_00000000 ;get error type
  722. - sta :parm_type
  723. - txa
  724. - and #%00000000_11111111 ;get error number
  725. -
  726. - pea #^error ;offset into ~error_msg for error string
  727. - tax  ;bank address is program bank address
  728. - lda ~error_msg,x ;for error message
  729. - pha
  730. - lda #]argv_lo
  731. - jsr dp_argv
  732. - jsr get_progname
  733. -
  734. - phy ;long - pointer to C-string
  735. - phx
  736. - _WriteCString
  737. - pea #':'
  738. - _WriteChar
  739. - pea #' '
  740. - _WriteChar
  741. - _WriteCString
  742. - lda :parm_type
  743. - cmp #ERROR_STRING ;special case string parameter
  744. - bne :error_value
  745. - lda ]parm_ptr ;output usage information if no
  746. - ora ]parm_ptr+2 ;added parameter
  747. - beq :end
  748. - pei ]parm_ptr+2
  749. - pei ]parm_ptr
  750. - _WriteCString
  751. -:end bra :usage
  752. -
  753. -:error_value cmp #ERROR_LHEX_VALUE
  754. - beq :lhex_value
  755. - ldx ]parm_ptr
  756. - ldy ]parm_ptr+2
  757. - jsr print_long_dec
  758. - bra :usage
  759. -
  760. -:lhex_value ldx ]parm_ptr
  761. - ldy ]parm_ptr+2
  762. - lda #8
  763. - jsr print_fix_long_hex
  764. -
  765. -:usage put_cr
  766. - lda []argv_lo] ;first argument on command-line is
  767. - tax ;program name
  768. - lda []argv_hi]
  769. - tay
  770. - jmp usage
  771. -
  772. -:parm_type UnsignedShort ;parmater type
  773. -
  774. -
  775. -**************************************************
  776. -* return pointer to program name string minus    *
  777. -* path.                                          *
  778. -* ---------------------------------------------- *
  779. -* (output)                                       *
  780. -*  x - LOW of pointer to program name.           *
  781. -*  y - HOW of pointer to program name.           *
  782. -**************************************************
  783. -get_progname ent
  784. -]argv_lo = $f0
  785. -]argv_hi = $f4
  786. -]progname = $fc
  787. -
  788. - lda #]argv_lo
  789. - jsr dp_argv
  790. - lda []argv_lo] ;first argument on command-line is
  791. - sta ]progname ;program name
  792. - lda []argv_hi]
  793. - sta ]progname+2
  794. -
  795. - shorta
  796. -:start_loop ldy #0
  797. -:loop lda []progname],y
  798. - beq :end
  799. - cmp #'/'
  800. - beq :separator
  801. - cmp #':'
  802. - beq :separator
  803. - iny
  804. - bra :loop
  805. -:separator clc
  806. - tya
  807. - inc
  808. - adc ]progname
  809. - sta ]progname
  810. - bcc :start_loop
  811. - inc ]progname+2
  812. - bra :start_loop
  813. -
  814. -:end longa
  815. - ldx ]progname
  816. - ldy ]progname+2
  817. - rts
  818. -
  819. -
  820. -**************************************************
  821. -* check if character is a printing character.    *
  822. -* ---------------------------------------------- *
  823. -* (input)                                        *
  824. -*  a - character to test.                        *
  825. -* (output)                                       *
  826. -*  c - set if non-printing character.            *
  827. -**************************************************
  828. -isprint ent
  829. -
  830. - cmp #' ' ;' ' to '~' is a printing character
  831. - blt :non_printing
  832. - cmp #'~'+1
  833. - bge :non_printing
  834. -:printing clc
  835. - rts
  836. -:non_printing sec
  837. - rts
  838. -
  839. -
  840. -**************************************************
  841. -* make alpha characters in hex string lowercase. *
  842. -* ---------------------------------------------- *
  843. -* (input)                                        *
  844. -*  a - number of characters in string.           *
  845. -*  x - address of hex string in current bank.    *
  846. -**************************************************
  847. -lowercase_hex ent
  848. -]str = $fe
  849. -
  850. - stx ]str
  851. - dec
  852. - tay
  853. - shorta
  854. -:loop lda (]str),y
  855. - ora #%00100000 ;make lowercase
  856. - sta (]str),y
  857. - dey
  858. - bpl :loop
  859. - longa
  860. - rts
  861. -
  862. -
  863. -**************************************************
  864. -* convert GSOS call number to equivalent name.   *
  865. -* ---------------------------------------------- *
  866. -* (input)                                        *
  867. -*  a - call number.                              *
  868. -* (output)                                       *
  869. -*  x - LOW pointer to equivalent name.           *
  870. -*  y - HOW pointer to equivalent name.           *
  871. -*  c - set if call number not found.             *
  872. -**************************************************
  873. -name_GSOS ent
  874. -]callnum = $f0 ;GSOS call number
  875. -]offset = $f2 ;offset into ~gsos for call name
  876. -
  877. - sta ]callnum
  878. - lsr
  879. - lsr
  880. - lsr
  881. - lsr
  882. - lsr
  883. - lsr
  884. - lsr
  885. - lsr
  886. - asl
  887. - tax
  888. - lda ~gsos,x
  889. - beq :end ;call number undefined
  890. - sta ]offset
  891. - tay
  892. -
  893. - lda (]offset) ;get number of name equivalents
  894. - tax
  895. - iny
  896. - iny
  897. - sty ]offset
  898. - ldy #2
  899. -
  900. -:loop lda (]offset)
  901. - cmp ]callnum
  902. - bne :next_name
  903. - ldx ]offset
  904. - inx
  905. - inx
  906. - ldy #^~gsos
  907. - clc
  908. - rts
  909. -
  910. -:next_name lda (]offset),y
  911. - and #$ff ;get length of pStr-defined name
  912. - clc
  913. - adc #3
  914. - adc ]offset
  915. - sta ]offset
  916. - dex
  917. - bne :loop
  918. -
  919. -:end sec
  920. - rts
  921. -
  922. -
  923. -**************************************************
  924. -* convert ROM address to equivalent name.        *
  925. -* ---------------------------------------------- *
  926. -* (input)                                        *
  927. -*  x - LOW of ROM address.                       *
  928. -*  y - HOW of ROM address.                       *
  929. -* (output)                                       *
  930. -*  x - LOW pointer to equivalent name.           *
  931. -*  y - HOW pointer to equivalent name.           *
  932. -*  c - set if call number not found.             *
  933. -**************************************************
  934. -name_ROM ent
  935. -]rom_adr = $f0 ;ROM address
  936. -]offset = $f4 ;offset into ~gsos for call name
  937. -
  938. - stx ]rom_adr
  939. - sty ]rom_adr+2
  940. - tya
  941. - asl
  942. - tay
  943. - lda ~rom,y
  944. - beq :end ;call number undefined
  945. - sta ]offset
  946. - lda ]rom_adr
  947. - lsr
  948. - lsr
  949. - lsr
  950. - lsr
  951. - lsr
  952. - lsr
  953. - lsr
  954. - lsr
  955. - asl
  956. - tay
  957. - lda (]offset),y
  958. - beq :end
  959. - sta ]offset
  960. - tay
  961. -
  962. - lda (]offset) ;get number of name equivalents
  963. - tax
  964. - iny
  965. - iny
  966. - sty ]offset
  967. - ldy #2
  968. -
  969. -:loop lda (]offset)
  970. - cmp ]rom_adr
  971. - bne :next_name
  972. - ldx ]offset
  973. - inx
  974. - inx
  975. - ldy #^~rom
  976. - clc
  977. - rts
  978. -
  979. -:next_name lda (]offset),y
  980. - and #$ff ;get length of pStr-defined name
  981. - clc
  982. - adc #3
  983. - adc ]offset
  984. - sta ]offset
  985. - dex
  986. - bne :loop
  987. -
  988. -:end sec
  989. - rts
  990. -
  991. -
  992. -**************************************************
  993. -* convert ToolBox call number to equivalent      *
  994. -* name.                                          *
  995. -* ---------------------------------------------- *
  996. -* (input)                                        *
  997. -*  a - call number.                              *
  998. -* (output)                                       *
  999. -*  x - LOW pointer to equivalent name.           *
  1000. -*  y - HOW pointer to equivalent name.           *
  1001. -*  c - set if call number not found.             *
  1002. -**************************************************
  1003. -name_TOOL ent
  1004. -]toolnum = $f0 ;Toolbox call number
  1005. -]offset = $f2 ;offset into ~gsos for call name
  1006. -
  1007. - sta ]toolnum
  1008. - and #$ff
  1009. - asl
  1010. - tax
  1011. - lda #^~tool
  1012. - lda ~tool,x
  1013. - beq :end ;call number undefined
  1014. - sta ]offset
  1015. - tay
  1016. -
  1017. - lda (]offset) ;get number of name equivalents
  1018. - tax
  1019. - iny
  1020. - iny
  1021. - sty ]offset
  1022. - ldy #2
  1023. -
  1024. -:loop lda (]offset)
  1025. - cmp ]toolnum
  1026. - bne :next_name
  1027. - ldx ]offset
  1028. - inx
  1029. - inx
  1030. - ldy #^~tool
  1031. - clc
  1032. - rts
  1033. -
  1034. -:next_name lda (]offset),y
  1035. - and #$ff ;get length of pStr-defined name
  1036. - clc
  1037. - adc #3
  1038. - adc ]offset
  1039. - sta ]offset
  1040. - dex
  1041. - bne :loop
  1042. -
  1043. -:end sec
  1044. - rts
  1045. -
  1046. -
  1047. -**************************************************
  1048. -* output number as char decimal string.          *
  1049. -* ---------------------------------------------- *
  1050. -* (input)                                        *
  1051. -*  x - value to output.                          *
  1052. -* (output)                                       *
  1053. -*  a - number of characters output.              *
  1054. -**************************************************
  1055. -print_char_dec ent
  1056. -
  1057. - phx
  1058. - phx ;word - longint to convert
  1059. - pea #^char_dec_str ;long - pointer to output string
  1060. - pea #char_dec_str
  1061. - pea #3 ;word - length of string
  1062. - pea #FALSE ;word - unsigned number
  1063. - _Int2Dec
  1064. - plx
  1065. - bne :0
  1066. - ldx #2
  1067. - bra :2
  1068. -:0 ldx #$ffff
  1069. -:1 inx
  1070. - lda char_dec_str,x
  1071. - and #$ff
  1072. - cmp #' '
  1073. - beq :1
  1074. -:2 pea #^char_dec_str ;long - pointer to string
  1075. - pea #char_dec_str
  1076. - phx ;word - offset into text
  1077. - sec ;word - number of characters to print
  1078. - lda #3
  1079. - sbc 1,s
  1080. - sta :strlen
  1081. - pha
  1082. - _TextWriteBlock
  1083. -
  1084. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1085. - jsr test_key
  1086. - fin
  1087. -
  1088. - lda :strlen
  1089. - rts
  1090. -
  1091. -:strlen ds 2 ;number of characters output
  1092. -
  1093. -
  1094. -**************************************************
  1095. -* output number as short decimal string.         *
  1096. -* ---------------------------------------------- *
  1097. -* (input)                                        *
  1098. -*  x - value to output.                          *
  1099. -**************************************************
  1100. -print_short_dec ent
  1101. -
  1102. - phx
  1103. - phx ;word - longint to convert
  1104. - pea #^short_dec_str ;long - pointer to output string
  1105. - pea #short_dec_str
  1106. - pea #5 ;word - length of string
  1107. - pea #FALSE ;word - unsigned number
  1108. - _Int2Dec
  1109. - plx
  1110. - bne :0
  1111. - ldx #4
  1112. - bra :2
  1113. -:0 ldx #$ffff
  1114. -:1 inx
  1115. - lda short_dec_str,x
  1116. - and #$ff
  1117. - cmp #' '
  1118. - beq :1
  1119. -:2 pea #^short_dec_str ;long - pointer to string
  1120. - pea #short_dec_str
  1121. - phx ;word - offset into text
  1122. - sec ;word - number of characters to print
  1123. - lda #5
  1124. - sbc 1,s
  1125. - pha
  1126. - _TextWriteBlock
  1127. -
  1128. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1129. - jsr test_key
  1130. - fin
  1131. - rts
  1132. -
  1133. -
  1134. -**************************************************
  1135. -* output number as long decimal string.          *
  1136. -* ---------------------------------------------- *
  1137. -* (input)                                        *
  1138. -*  x - LOW of value to output.                   *
  1139. -*  y - HOW of value to output.                   *
  1140. -**************************************************
  1141. -print_long_dec ent
  1142. -
  1143. - phy
  1144. - phx
  1145. - phy ;long - longint to convert
  1146. - phx
  1147. - pea #^long_dec_str ;long - pointer to output string
  1148. - pea #long_dec_str
  1149. - pea #10 ;word - length of string
  1150. - pea #FALSE ;word - unsigned number
  1151. - _Long2Dec
  1152. - pla
  1153. - ora 1,s
  1154. - plx
  1155. - cmp #0
  1156. - bne :0
  1157. - ldx #9
  1158. - bra :2
  1159. -:0 ldx #$ffff
  1160. -:1 inx
  1161. - lda long_dec_str,x
  1162. - and #$ff
  1163. - cmp #' '
  1164. - beq :1
  1165. -:2 pea #^long_dec_str ;long - pointer to string
  1166. - pea #long_dec_str
  1167. - phx ;word - offset into text
  1168. - sec ;word - number of characters to print
  1169. - lda #10
  1170. - sbc 1,s
  1171. - pha
  1172. - _TextWriteBlock
  1173. -
  1174. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1175. - jsr test_key
  1176. - fin
  1177. - rts
  1178. -
  1179. -
  1180. -**************************************************
  1181. -* output signed number as char decimal string.   *
  1182. -* ---------------------------------------------- *
  1183. -* (input)                                        *
  1184. -*  x - value to output.                          *
  1185. -* (output)                                       *
  1186. -*  a - number of characters output.              *
  1187. -**************************************************
  1188. -print_char_sdec ent
  1189. -
  1190. - phx
  1191. - phx ;word - longint to convert
  1192. - pea #^char_dec_str ;long - pointer to output string
  1193. - pea #char_dec_str
  1194. - pea #4 ;word - length of string
  1195. - pea #TRUE ;word - signed number
  1196. - _Int2Dec
  1197. - plx
  1198. - bne :0
  1199. - ldx #3
  1200. - bra :2
  1201. -:0 ldx #$ffff
  1202. -:1 inx
  1203. - lda char_dec_str,x
  1204. - and #$ff
  1205. - cmp #' '
  1206. - beq :1
  1207. -:2 pea #^char_dec_str ;long - pointer to string
  1208. - pea #char_dec_str
  1209. - phx ;word - offset into text
  1210. - sec ;word - number of characters to print
  1211. - lda #4
  1212. - sbc 1,s
  1213. - sta :strlen
  1214. - pha
  1215. - _TextWriteBlock
  1216. -
  1217. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1218. - jsr test_key
  1219. - fin
  1220. -
  1221. - lda :strlen
  1222. - rts
  1223. -
  1224. -:strlen ds 2 ;number of characters output
  1225. -
  1226. -
  1227. -**************************************************
  1228. -* output number as fixed char decimal string.    *
  1229. -* ---------------------------------------------- *
  1230. -* (input)                                        *
  1231. -*  a - number of bytes to output.                *
  1232. -*  x - value to output.                          *
  1233. -**************************************************
  1234. -print_fix_char_dec ent
  1235. -]num_bytes = $f0 ;number of bytes to output
  1236. -
  1237. - sta ]num_bytes
  1238. -
  1239. - phx ;word - char to convert
  1240. - pea #^char_dec_str ;long - pointer to output string
  1241. - pea #char_dec_str
  1242. - pha ;word - length of string
  1243. - pea #FALSE ;word - unsigned number
  1244. - _Int2Dec
  1245. - pea #^char_dec_str ;long - pointer to string
  1246. - pea #char_dec_str
  1247. - pea #0 ;word - offset into text
  1248. - pei ]num_bytes ;word - number of characters to print
  1249. - _TextWriteBlock
  1250. -
  1251. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1252. - jsr test_key
  1253. - fin
  1254. - rts
  1255. -
  1256. -
  1257. -**************************************************
  1258. -* output number as fixed short decimal string.   *
  1259. -* ---------------------------------------------- *
  1260. -* (input)                                        *
  1261. -*  a - number of bytes to output.                *
  1262. -*  x - value to output.                          *
  1263. -**************************************************
  1264. -print_fix_short_dec ent
  1265. -]num_bytes = $f0 ;number of bytes to output
  1266. -
  1267. - sta ]num_bytes
  1268. -
  1269. - phx ;word - short to convert
  1270. - pea #^short_dec_str ;long - pointer to output string
  1271. - pea #short_dec_str
  1272. - pha ;word - length of string
  1273. - pea #FALSE ;word - unsigned number
  1274. - _Int2Dec
  1275. - pea #^short_dec_str ;long - pointer to string
  1276. - pea #short_dec_str
  1277. - pea #0 ;word - offset into text
  1278. - pei ]num_bytes ;word - number of characters to print
  1279. - _TextWriteBlock
  1280. -
  1281. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1282. - jsr test_key
  1283. - fin
  1284. - rts
  1285. -
  1286. -
  1287. -**************************************************
  1288. -* output number as fixed long decimal string.    *
  1289. -* ---------------------------------------------- *
  1290. -* (input)                                        *
  1291. -*  a - number of bytes to output.                *
  1292. -*  x - LOW of value to output.                   *
  1293. -*  y - HOW of value to output.                   *
  1294. -**************************************************
  1295. -print_fix_long_dec ent
  1296. -]num_bytes = $f0 ;number of bytes to output
  1297. -
  1298. - sta ]num_bytes
  1299. -
  1300. - phy ;long - longint to convert
  1301. - phx
  1302. - pea #^long_dec_str ;long - pointer to output string
  1303. - pea #long_dec_str
  1304. - pha ;word - length of string
  1305. - pea #FALSE ;word - unsigned number
  1306. - _Long2Dec
  1307. - pea #^long_dec_str ;long - pointer to string
  1308. - pea #long_dec_str
  1309. - pea #0 ;word - offset into text
  1310. - pei ]num_bytes ;word - number of characters to print
  1311. - _TextWriteBlock
  1312. -
  1313. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1314. - jsr test_key
  1315. - fin
  1316. - rts
  1317. -
  1318. -
  1319. -**************************************************
  1320. -* output number as long hex string.              *
  1321. -* ---------------------------------------------- *
  1322. -* (input)                                        *
  1323. -*  x - LOW of value to output.                   *
  1324. -*  y - HOW of value to output.                   *
  1325. -**************************************************
  1326. -print_long_hex ent
  1327. -
  1328. - phy
  1329. - phx
  1330. - phy ;long - longint to convert
  1331. - phx
  1332. - pea #^long_hex_str ;long - pointer to output string
  1333. - pea #long_hex_str
  1334. - pea #8 ;word - length of string
  1335. - _Long2Hex
  1336. - pla
  1337. - ora 1,s
  1338. - plx
  1339. - cmp #0
  1340. - bne :0
  1341. - ldx #7
  1342. - bra :2
  1343. -:0 ldx #long_hex_str ;make hex alpha lowercase
  1344. - ldy #^long_hex_str
  1345. - lda #8
  1346. - jsr lowercase_hex
  1347. - ldx #$ffff
  1348. -:1 inx
  1349. - lda long_dec_str,x
  1350. - and #$ff
  1351. - cmp #'0'
  1352. - beq :1
  1353. -:2 pea #^long_hex_str ;long - pointer to string
  1354. - pea #long_hex_str
  1355. - phx ;word - offset into text
  1356. - sec ;word - number of characters to print
  1357. - lda #8
  1358. - sbc 1,s
  1359. - pha
  1360. - _TextWriteBlock
  1361. -
  1362. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1363. - jsr test_key
  1364. - fin
  1365. - rts
  1366. -
  1367. -
  1368. -**************************************************
  1369. -* output number as fixed char hex string.        *
  1370. -* ---------------------------------------------- *
  1371. -* (input)                                        *
  1372. -*  x - value to output.                          *
  1373. -**************************************************
  1374. -print_fix_char_hex ent
  1375. -
  1376. - phx ;word - char to convert
  1377. - pea #^char_hex_str ;long - pointer to output string
  1378. - pea #char_hex_str
  1379. - pea #2 ;word - length of string
  1380. - _Int2Hex
  1381. - ldx #char_hex_str ;make hex alpha lowercase
  1382. - ldy #^char_hex_str
  1383. - lda #2
  1384. - jsr lowercase_hex
  1385. - pea #^char_hex_str ;long - pointer to string
  1386. - pea #char_hex_str
  1387. - pea #0 ;word - offset into text
  1388. - pea #2 ;word - number of characters to print
  1389. - _TextWriteBlock
  1390. -
  1391. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1392. - jsr test_key
  1393. - fin
  1394. - rts
  1395. -
  1396. -
  1397. -**************************************************
  1398. -* output number as fixed short hex string.       *
  1399. -* ---------------------------------------------- *
  1400. -* (input)                                        *
  1401. -*  a - number of bytes to output.                *
  1402. -*  x - value to output.                          *
  1403. -**************************************************
  1404. -print_fix_short_hex ent
  1405. -
  1406. - pha
  1407. - phx ;word - short to convert
  1408. - pea #^short_hex_str ;long - pointer to output string
  1409. - pea #short_hex_str
  1410. - pha ;word - length of string
  1411. - _Int2Hex
  1412. - ldx #short_hex_str ;make hex alpha lowercase
  1413. - ldy #^short_hex_str
  1414. - lda 1,s
  1415. - jsr lowercase_hex
  1416. - pla
  1417. - pea #^short_hex_str ;long - pointer to string
  1418. - pea #short_hex_str
  1419. - pea #0 ;word - offset into text
  1420. - pha ;word - number of characters to print
  1421. - _TextWriteBlock
  1422. -
  1423. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1424. - jsr test_key
  1425. - fin
  1426. - rts
  1427. -
  1428. -
  1429. -**************************************************
  1430. -* output number as fixed long hex string.        *
  1431. -* ---------------------------------------------- *
  1432. -* (input)                                        *
  1433. -*  a - number of bytes to output.                *
  1434. -*  x - LOW of value to output.                   *
  1435. -*  y - HOW of value to output.                   *
  1436. -**************************************************
  1437. -print_fix_long_hex ent
  1438. -
  1439. - pha
  1440. - phy ;long - longint to convert
  1441. - phx
  1442. - pea #^long_hex_str ;long - pointer to output string
  1443. - pea #long_hex_str
  1444. - pha ;word - length of string
  1445. - _Long2Hex
  1446. - ldx #long_hex_str ;make hex alpha lowercase
  1447. - ldy #^long_hex_str
  1448. - lda 1,s
  1449. - jsr lowercase_hex
  1450. - pla
  1451. - pea #^long_hex_str ;long - pointer to string
  1452. - pea #long_hex_str
  1453. - pea #0 ;word - offset into text
  1454. - pha ;word - number of characters to print
  1455. - _TextWriteBlock
  1456. -
  1457. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1458. - jsr test_key
  1459. - fin
  1460. - rts
  1461. -
  1462. -
  1463. -**************************************************
  1464. -* format and print @decimal record.              *
  1465. -* ---------------------------------------------- *
  1466. -* (output)                                       *
  1467. -*  a - number of characters output.              *
  1468. -**************************************************
  1469. -print_@decimal equ *
  1470. -]str_len = $f0 ;length of output string
  1471. -
  1472. - pea #^@dec_form
  1473. - pea #@dec_form
  1474. - pea #^@decimal
  1475. - pea #@decimal
  1476. - pea #^:dec_str
  1477. - pea #:dec_str
  1478. - _Dec2Str
  1479. -
  1480. - lda :dec_str
  1481. - and #$ff
  1482. - tax
  1483. -:0 lda :dec_str,x
  1484. - and #$ff
  1485. - cpx #1
  1486. - beq :1
  1487. - cmp #'0'
  1488. - bne :1
  1489. - dex
  1490. - bra :0
  1491. -
  1492. -:1 cmp #'.'
  1493. - bne :2
  1494. - dex
  1495. -:2 shorti
  1496. - stx :dec_str
  1497. - longi
  1498. - pea #^:dec_str
  1499. - pea #:dec_str
  1500. - _WriteString
  1501. - lda :dec_str
  1502. - and #$ff
  1503. - rts
  1504. -
  1505. -:dec_str ds $50
  1506. -
  1507. -
  1508. -**************************************************
  1509. -* output number as double floating-point string. *
  1510. -* ---------------------------------------------- *
  1511. -* (input)                                        *
  1512. -*  a - dp address of double float value.         *
  1513. -* (output)                                       *
  1514. -*  a - number of characters output.              *
  1515. -**************************************************
  1516. -print_double ent
  1517. -
  1518. - pea #^@dec_form ;long - address of decform record
  1519. - pea #@dec_form
  1520. - pea #0 ;long - address of float value
  1521. - pha
  1522. - clc
  1523. - tdc
  1524. - adc 1,s
  1525. - sta 1,s
  1526. - pea #^@decimal ;long - address of decimal record
  1527. - pea #@decimal
  1528. - lda #FixedDecimal
  1529. - sta @dec_form+`style
  1530. - lda #5 ;5 digits to right of decimal
  1531. - sta @dec_form+`digits
  1532. - _Double2Decimal
  1533. - jsr print_@decimal
  1534. -
  1535. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1536. - jsr test_key
  1537. - fin
  1538. - rts
  1539. -
  1540. -
  1541. -**************************************************
  1542. -* output number as extended float string.        *
  1543. -* ---------------------------------------------- *
  1544. -* (input)                                        *
  1545. -*  a - dp address of extended value.             *
  1546. -* (output)                                       *
  1547. -*  a - number of characters output.              *
  1548. -**************************************************
  1549. -print_extended ent
  1550. -
  1551. - pea #^@dec_form ;long - address of decform record
  1552. - pea #@dec_form
  1553. - pea #0 ;long - address of float value
  1554. - pha
  1555. - clc
  1556. - tdc
  1557. - adc 1,s
  1558. - sta 1,s
  1559. - pea #^@decimal ;long - address of decimal record
  1560. - pea #@decimal
  1561. - lda #FixedDecimal
  1562. - sta @dec_form+`style
  1563. - lda #10 ;10 digits to right of decimal
  1564. - sta @dec_form+`digits
  1565. - _Extended2Decimal
  1566. - jsr print_@decimal
  1567. -
  1568. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1569. - jsr test_key
  1570. - fin
  1571. - rts
  1572. -
  1573. -
  1574. -**************************************************
  1575. -* output number as floating-point string.        *
  1576. -* ---------------------------------------------- *
  1577. -* (input)                                        *
  1578. -*  a - dp address of float value.                *
  1579. -* (output)                                       *
  1580. -*  a - number of characters output.              *
  1581. -**************************************************
  1582. -print_float ent
  1583. -
  1584. - pea #^@dec_form ;long - address of decform record
  1585. - pea #@dec_form
  1586. - pea #0 ;long - address of float value
  1587. - pha
  1588. - clc
  1589. - tdc
  1590. - adc 1,s
  1591. - sta 1,s
  1592. - pea #^@decimal ;long - address of decimal record
  1593. - pea #@decimal
  1594. - lda #FixedDecimal
  1595. - sta @dec_form+`style
  1596. - lda #5 ;5 digits to right of decimal
  1597. - sta @dec_form+`digits
  1598. - _Float2Decimal
  1599. - jsr print_@decimal
  1600. -
  1601. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1602. - jsr test_key
  1603. - fin
  1604. - rts
  1605. -
  1606. -
  1607. -**************************************************
  1608. -* print displacement, counter offset.            *
  1609. -**************************************************
  1610. -print_offset ent
  1611. -
  1612. - lda }nooffset
  1613. - bne :end
  1614. - lda #6
  1615. - ldx @omf+`displacement
  1616. - ldy @omf+`displacement+2
  1617. - jsr print_fix_long_hex
  1618. - pea #' '
  1619. - _WriteChar
  1620. - lda #6
  1621. - ldx @omf+`counter
  1622. - ldy @omf+`counter+2
  1623. - jsr print_fix_long_hex
  1624. - pea #^vert_separator+1
  1625. - pea #vert_separator+1
  1626. - _WriteCString
  1627. -:end rts
  1628. -
  1629. -
  1630. -**************************************************
  1631. -* format printed output.                         *
  1632. -* ---------------------------------------------- *
  1633. -* (input)                                        *
  1634. -*  a - address of string to parse.               *
  1635. -*  x - HOW of argument.                          *
  1636. -*  y - LOW of argument.                          *
  1637. -* (output)                                       *
  1638. -*  x - number of characters output.              *
  1639. -**************************************************
  1640. -printf ent
  1641. -]arg_str = $e0 ;address of string to parse
  1642. -]arg = $e2 ;argument
  1643. -]print_begin = $e6 ;location of first character to print
  1644. -]print_end = $e8 ;location of last character to print
  1645. -]count = $ea ;number of characters output
  1646. -
  1647. - sta ]arg_str
  1648. - stx ]arg+2
  1649. - sty ]arg
  1650. - stz ]count
  1651. -
  1652. - ldy #0
  1653. - sty ]print_begin
  1654. - sty ]print_end
  1655. -:parse_arg_str lda #0
  1656. - shorta
  1657. - lda (]arg_str),y
  1658. - longa
  1659. - beq :end
  1660. - cmp #'%'
  1661. - beq :parse_format
  1662. - iny
  1663. - inc ]count
  1664. - bra :parse_arg_str
  1665. -
  1666. -:end sty ]print_end
  1667. - cpy ]print_begin ;end if nothing left to print
  1668. - beq :rts
  1669. - pea #^printf
  1670. - pei ]arg_str
  1671. - pei ]print_begin
  1672. - sec
  1673. - lda ]print_end
  1674. - sbc ]print_begin
  1675. - pha
  1676. - _TextWriteBlock
  1677. -:rts ldx ]count
  1678. - rts
  1679. -
  1680. -:parse_format phy
  1681. - sty ]print_end
  1682. - pea #^printf
  1683. - pei ]arg_str
  1684. - pei ]print_begin
  1685. - sec
  1686. - lda ]print_end
  1687. - sbc ]print_begin
  1688. - pha
  1689. - _TextWriteBlock
  1690. - lda 1,s
  1691. - tay
  1692. - iny
  1693. - lda #0
  1694. - shorta
  1695. - lda (]arg_str),y
  1696. - longa
  1697. - cmp #'2'
  1698. - bne :hex_4
  1699. - lda #2
  1700. - ldx ]arg
  1701. - jsr print_fix_char_hex
  1702. - inc ]count
  1703. - inc ]count
  1704. - bra :end_parse
  1705. -:hex_4 cmp #'4'
  1706. - bne :hex_6
  1707. - lda #4
  1708. - ldx ]arg
  1709. - jsr print_fix_short_hex
  1710. - inc ]count
  1711. - inc ]count
  1712. - inc ]count
  1713. - inc ]count
  1714. - bra :end_parse
  1715. -:hex_6 cmp #'6'
  1716. - bne :char
  1717. - lda #6
  1718. - ldx ]arg
  1719. - ldy ]arg+2
  1720. - jsr print_fix_long_hex
  1721. - inc ]count
  1722. - inc ]count
  1723. - inc ]count
  1724. - inc ]count
  1725. - inc ]count
  1726. - inc ]count
  1727. - bra :end_parse
  1728. -:char pea #'>'
  1729. - lda ~assembler
  1730. - cmp #MERLIN
  1731. - beq :0
  1732. - lda #'|'
  1733. - sta 1,s
  1734. -:0 _WriteChar
  1735. - inc ]count
  1736. -:end_parse ply
  1737. - iny
  1738. - iny
  1739. - sty ]print_begin
  1740. - sty ]print_end
  1741. - brl :parse_arg_str
  1742. -
  1743. -
  1744. -**************************************************
  1745. -* find first occurrence of a character in a      *
  1746. -* string in current bank.                        *
  1747. -* ---------------------------------------------- *
  1748. -* (input)                                        *
  1749. -*  a - character to find.                        *
  1750. -*  x - address of search string in current bank. *
  1751. -* (output)                                       *
  1752. -*  x - address of where character is located.    *
  1753. -*      0 if character not found.                 *
  1754. -**************************************************
  1755. -strchr ent
  1756. -]char = $f0 ;character to find
  1757. -]string = $f2 ;string to search
  1758. -
  1759. - sta ]char
  1760. - stx ]string
  1761. -
  1762. - ldy #0
  1763. - shorta
  1764. -:loop lda (]string),y
  1765. - cmp ]char
  1766. - beq :end
  1767. - cmp #0
  1768. - beq :error
  1769. - iny
  1770. - bra :loop
  1771. -:end longa
  1772. - clc
  1773. - tya
  1774. - adc ]string
  1775. - tax
  1776. - rts
  1777. -:error longa
  1778. - ldx #0
  1779. - rts
  1780. -
  1781. -
  1782. - do ENV&{MERLIN_ENV.ORCA_ENV}
  1783. -**************************************************
  1784. -* test for special keypresses:                   *
  1785. -*  ctrl-s: pause output                          *
  1786. -*  ctrl-c: terminate program                     *
  1787. -**************************************************
  1788. -test_key ent
  1789. -
  1790. - lda #0
  1791. - shorta
  1792. - ldal KBD
  1793. - longa
  1794. - bpl :print
  1795. - cmp #CTRL_C.$80
  1796. - beq :exit
  1797. -
  1798. - shorta
  1799. - stal KBDSTRB
  1800. -:pause ldal KBD
  1801. - bpl :pause
  1802. - bra :clear_kbd
  1803. -
  1804. -:exit pla
  1805. - bne :exit
  1806. - do ENV&MERLIN_ENV
  1807. - put_cr
  1808. - fin
  1809. -:clear_kbd shorta
  1810. - stal KBDSTRB
  1811. - longa
  1812. -:print rts
  1813. - fin
  1814. -
  1815. -
  1816. -**************************************************
  1817. -* get length of C-string.                        *
  1818. -* ---------------------------------------------- *
  1819. -* (input)                                        *
  1820. -*  x - LOW of pointer to C-string.               *
  1821. -*  y - HOW of pointer to C-string.               *
  1822. -* (output)                                       *
  1823. -*  y - length of C-string.                       *
  1824. -**************************************************
  1825. -strlen ent
  1826. -]cstr = $f0
  1827. -
  1828. - stx ]cstr
  1829. - sty ]cstr+2
  1830. -
  1831. - ldy #0
  1832. - shorta
  1833. -:0 lda []cstr],y
  1834. - beq :end
  1835. - iny
  1836. - bra :0
  1837. -
  1838. -:end longa
  1839. - rts
  1840. -
  1841. -
  1842. -**************************************************
  1843. -* display options strings of all coff options    *
  1844. -* and exit coff.                                 *
  1845. -* ---------------------------------------------- *
  1846. -* (input)                                        *
  1847. -*  x - LOW of program name.                      *
  1848. -*  y - HOW of program name.                      *
  1849. -**************************************************
  1850. -usage ent
  1851. -]usage_handle = $f0 ;handle to verbose usage string
  1852. -]usage_ptr = $f4
  1853. -]progname = $f8 ;name of program
  1854. -
  1855. - stx ]progname
  1856. - sty ]progname+2
  1857. -
  1858. - pha ;long - result
  1859. - pha
  1860. - pea #rText ;word - type of resource
  1861. - pea #^USAGE ;long - ID Of resource
  1862. - pea #USAGE
  1863. - _LoadResource
  1864. - plx
  1865. - ply
  1866. - stx ]usage_handle
  1867. - sty ]usage_handle+2
  1868. - pea #^usage_str
  1869. - pea #usage_str
  1870. - _WriteCString
  1871. - pei ]progname+2
  1872. - pei ]progname
  1873. - _WriteCString
  1874. - ldy #2
  1875. - lda []usage_handle],y
  1876. - pha
  1877. - lda []usage_handle]
  1878. - pha
  1879. - _WriteCString
  1880. -:0 pla
  1881. - bne :0
  1882. - rts
  1883. -
  1884. -
  1885. -**************************************************
  1886. -* display options strings and descriptions of    *
  1887. -* all coff options and exit coff.                *
  1888. -* ---------------------------------------------- *
  1889. -* (input)                                        *
  1890. -*  x - LOW of program name.                      *
  1891. -*  y - HOW of program name.                      *
  1892. -**************************************************
  1893. -usage_verbose ent
  1894. -]usage_handle = $f0 ;handle to verbose usage string
  1895. -]usage_ptr = $f4
  1896. -]progname = $f8 ;name of program
  1897. -
  1898. - stx ]progname
  1899. - sty ]progname+2
  1900. -
  1901. - pha ;long - result
  1902. - pha
  1903. - pea #rText ;word - type of resource
  1904. - pea #^USAGE_VERBOSE ;long - ID Of resource
  1905. - pea #USAGE_VERBOSE
  1906. - _LoadResource
  1907. - plx
  1908. - ply
  1909. - stx ]usage_handle
  1910. - sty ]usage_handle+2
  1911. - pei ]progname+2
  1912. - pei ]progname
  1913. - _WriteCString
  1914. - ldy #2
  1915. - lda []usage_handle],y
  1916. - pha
  1917. - lda []usage_handle]
  1918. - pha
  1919. - _WriteCString
  1920. -:0 pla
  1921. - bne :0
  1922. - rts
  1923. -
  1924. -
  1925. -**************************************************
  1926. -usage_str cStr 'usage: '
  1927. -
  1928. -@dec_form equ * ;SANE Decform record
  1929. -:style UnsignedShort ;output style (FloatDecimal, FixedDecimal)
  1930. -:digits UnsignedShort ;number of significant digits
  1931. -
  1932. -@decimal equ * ;SANE Decimal record
  1933. -:sgn UnsignedShort ;sign of number
  1934. -:exp UnsignedShort ;exponent value
  1935. -:sig ds 20
  1936. -
  1937. -**************************************************
  1938. - sav general.l
  1939. + END OF ARCHIVE
  1940.