home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sources / apple2 / 7 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  56.9 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: v001SRC066:  coff (OMF Disassembler) 01/09
  5. Message-ID: <Nov.8.19.11.17.1992.16603@yoko.rutgers.edu>
  6. Date: 9 Nov 92 00:11:18 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 2598
  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:66
  14. Archive-name: utility/gs/disassem/coff/part01
  15. Architecture: ONLY_2gs
  16. Version-number: 1.1
  17.  
  18.  
  19. Coff is an OMF disassembler designed for OMF 1.0 and 2.0 files. Output
  20. is similar to the Orca and APW utility 'dumpobj', although OMF and 65816
  21. disassemblies are much cleaner and more readable.
  22.  
  23. This is the first of 9 parts.
  24.  
  25. Enjoy.
  26.  
  27. =Read.Me
  28. -* UNIX coff utility
  29. -* README file
  30. -*
  31. -* 1990-1992, tao Developer Project
  32. -*
  33. -* albert chin-a-young ... 26285659t@servax.fiu.edu
  34. -
  35. -Coff is an OMF disassembler designed for OMF 1.0 and 2.0 files. Output is
  36. -similar to the Orca and APW utility 'dumpobj', although OMF and 65816
  37. -disassemblies are much cleaner and more readable.
  38. -
  39. -v1.1 marks the first update to coff.
  40. -
  41. -The attached manual, coff.tex, describes all available options to the coff
  42. -utility in addition to a thorough description of the OMF file format. The
  43. -manual is formatted with the TeX text processing system. If you would like
  44. -a printed copy of this manual, contact me at the address below.
  45. -
  46. -The 'Apple IIgs GS/OS Reference, Volume 1' describes the OMF file format.
  47. -The manual also contains a description of the OMF file format.
  48. -
  49. -To assemble coff, you must have the Merlin 16+ assembler. Modifications to the
  50. -link file must occur if you have older versions of Merlin. Versions of coff
  51. -for the following environments are available: Merlin, Orca, and GNO. Edit the
  52. -env.h file for the environment you are compiling for.
  53. -
  54. -To compile coff, invoke the following command from the Merlin command-line:
  55. -    link make[.orca|.gno]
  56. -To compile the resource fork:
  57. -    compile coff.r keep=[pathname of coff] rez=(-d [MERLIN|ORCA|GNO])
  58. -Make sure to change any absolute pathnames in the Merlin link script.
  59. -
  60. -
  61. -Merlin and Orca:
  62. -    While coff is executing, pressing any key will pause the output.
  63. -    Press any other key to resume output. CTRL-C will end coff.
  64. -GNO:
  65. -    Coff supports the GNO signal SIGINT. Thus, CTRL-C will end coff.
  66. -    CTRL-S will pause output and CTRL-Q resumes output as usual.
  67. -
  68. -
  69. -Coff is free software. Source code is available. If you have any comments,
  70. -bug reports, or suggestions on this utility, please contact me at the
  71. -following:
  72. -    e-mail:    26285659t@servax.fiu.edu
  73. -    post:    Albert Chin-A-Young                [ preferred ]
  74. -        PO Box 4133
  75. -        Miramar, FL 33083-4133
  76. -
  77. -
  78. -Below is a short description of the options available in coff.
  79. -
  80. -----------------------------------------------------------------------
  81. -
  82. -calling parameters:
  83. -coff [-OPTIONS] filename [segments..] [loadsegments..]
  84. -
  85. -OPTIONS            DESCRIPTION
  86. --v [+version]        display coff's version number
  87. --d [+asm]        dump segment body in 65816-format disassembly
  88. --T [+tool]        interpret Toolbox, GS/OS, ProDOS, ROM calls
  89. --x [+hex]        dump segment body in hex (can be used with '+asm')
  90. --l [+label]        print expressions using labels (default is offsets)
  91. --t [+infix]        display expressions in infix form
  92. --p [+postfix]        display expressions in postfix form (default)
  93. --m [+merlin]        format of '+asm' to use merlin opcodes (default)
  94. --o [+orca]        format of '+asm' to use orca/m opcodes
  95. --a [+shorta]        8-bit accumulator
  96. --i [+shorti]        8-bit index registers
  97. --s [+header]        dump segment headers only
  98. --n [+noheader]        do not print segment headers
  99. --f [+nooffset]        do not print offset into file
  100. --h [+help]        print this information, then quit
  101. --D [+nodefault]        disable default options
  102. --c [+compress]        print short form of CONST, LCONST records
  103. --e [+exact]        match segment, loadsegment names exactly
  104. -   [+thanks]        those who helped in the development of coff
  105. -
  106. -filename        name of file to dump
  107. -[segments]        names of segments in file to dump
  108. -[loadsegments]        names of load segments in file to dump
  109. -
  110. -
  111. -Source files for coff v1.1.
  112. -
  113. -----------------------------------------------------------------------
  114. -
  115. -(Place these files in your Merlin PFX4 directory):
  116. -
  117. -    datatype.mac.s    HLL data type macros
  118. -    env.h.s        environment defines
  119. -    env.mac.s    environment macros
  120. -    getopt.h.s    GNU getopt defines
  121. -    getopt.mac.s    GNU getopt macros
  122. -    signal.h.s    GNO signal defines
  123. -    signal.mac.s    GNU signal macros
  124. -
  125. -(Place these files in a 'coff' directory):
  126. -
  127. -    asm.s        65816 OMF disassembler
  128. -    coff.h.s    coff defines
  129. -    coff.mac.s    coff macros
  130. -    coff.r        resource definitions
  131. -    coff.s        main coff source
  132. -    coff.tex    TeX coff manual
  133. -    data.s        coff variables
  134. -    general.s    general purpose routines
  135. -    gsos.s        GS/OS calls
  136. -    make.gno.s    link file for GNO environment
  137. -    make.orca.s    link file for Orca environment
  138. -    make.rez    make file for resource fork
  139. -    make.s        link file for Merlin environment
  140. -    omf.s        OMF disassembler
  141. -    output.s    output routines
  142. -    structure.s    data structure routines
  143. -    tool.s        toolbox call parser
  144. -    x.*        external routine files
  145. -
  146. -(Place this file in a 'getopt' directory):
  147. -
  148. -    getopt.s    GNU getopt utility (not fully functional yet)
  149. -
  150. -
  151. -albert chin-a-young
  152. -26285659t@servax.fiu.edu
  153. -Version 1.1
  154. -October 1992
  155. -
  156. =Manifest
  157. -
  158. -HISTORY
  159. -Read.Me
  160. -asm.s
  161. -coff.h.s
  162. -coff.mac.s
  163. -coff.r
  164. -coff.s
  165. -coff.tex
  166. -data.s
  167. -datatype.mac.s
  168. -env.h.s
  169. -env.mac.s
  170. -general.s
  171. -getopt.h.s
  172. -getopt.mac.s
  173. -getopt.s
  174. -make.gno.s
  175. -make.orca.s
  176. -make.rez
  177. -make.s
  178. -omf.s
  179. -output.s
  180. -structure.s
  181. -tool.s
  182. -x.asm.s
  183. -x.data.s
  184. -x.general.s
  185. -x.gsos.s
  186. -x.omf.s
  187. -x.output.s
  188. -x.structure.s
  189. -x.tool.s
  190. -
  191. =HISTORY
  192. -* UNIX coff utility
  193. -* HISTORY file
  194. -*
  195. -* 1990-1992, tao Developer Project
  196. -*
  197. -* albert chin-a-young ... 26285659t@servax.fiu.edu
  198. -
  199. -v1.1    28 September 1992
  200. -    added '+compress' option
  201. -    made relative branch offsets 2 bytes (i.e. BPL, BMI, etc.)
  202. -    fixed pos/neg bug in relative branch output
  203. -    fixed parsing of SUPER records
  204. -    added support for cINTERSEG and INTERSEG records
  205. -    fixed offset values in SUPER, cRELOC, RELOC records
  206. -    added length of CONST, LCONST records to output
  207. -    redirection under Orca now works if filename is last on command-line
  208. -        (thanks to Jerry Penner for above)
  209. -    added '+exact' option
  210. -    a list of all segment/loadsegment names not matched is displayed at
  211. -        the end of a coff run
  212. -    changed '+default' option to '+nodefault'
  213. -    a message is now displayed if coff is unable to parse an OMF record
  214. -        (which is the case if a test file could not be generated
  215. -         for the OMF record)
  216. -    when +hex is added to +header, headers are printed in hex
  217. -    added a few more error messages
  218. -    manual rewritten in TeX
  219. -
  220. -v1.0    16 june 1992
  221. -    converted to assembly
  222. -    parse_kind_1() and parse_kind_2() work
  223. -    unary expressions printed correctly
  224. -    MEM disassembly works
  225. -    xEXPR disassembly more intelligent
  226. -    extended floating values recognized
  227. -    moved GS/OS, ROM, Toolbox defines to data fork
  228. -    support for System 6.0 Toolbox calls
  229. -    added '+thanks' option
  230. -    support for pause and cancel options in Merlin and Orca versions
  231. -    support for CTRL-C GNO cancel signal in GNO version
  232. -        (thanks to jawaid bazyar)
  233. -
  234. -v1.0g    30 june 1991
  235. -    changed defaults to +label, +infix, +tool
  236. -    +orca option only enables Orca/M disassembly
  237. -    +merlin option only enables Merlin disassembly
  238. -    fixed bug in parse_relexpr()
  239. -    fixed bug in recognize_record()
  240. -    meaning of +default reversed
  241. -    reorganized code
  242. -    fixed prototype of parse_opcode_1()
  243. -
  244. -v1.0f    11 june 1991
  245. -    added record types: RELOC, cRELOC, SUPER
  246. -
  247. -v1.0e    5 june 1991
  248. -    jsr (addr,x) and jmp (addr,x) where addr is a number are
  249. -        handled correctly
  250. -        (thanks to jerry brenne)
  251. -    mvn opcode now parsed correctly
  252. -    +hex with dangling asm opcodes at end of OMF segment print in
  253. -        correct position
  254. -    exit status changed to 0 from 1
  255. -    library file are properly handled
  256. -    support for verbose kind description fields
  257. -
  258. -v1.0d    2 may 1991
  259. -    +longa, +longi removed and replaced by +shorta, +shorti
  260. -    fixed bug if OMF file looked like
  261. -        pea $<num>
  262. -        jsl ><name>
  263. -        (thanks to tim meekins)
  264. -    fixed bug for dangling asm opcodes at end of OMF segment
  265. -        (thanks to tim meekins)
  266. -
  267. -v1.0c   30 april 1991
  268. -    new implementation of hex mode
  269. -        (thanks to tim meekins)
  270. -    +tool option recognizes toolbox, GS/OS, ProDOS calls, ROM addresses
  271. -        (thanks to morgan davis, dave lyons)
  272. -    removed all global variables except flags
  273. -    removed inline asm bug fix (my fault)
  274. -    cleaned up code
  275. -    minimal speed improvement
  276. -    program name changed to 'coff' to match UNIX coff utility
  277. -    minor bug fixes
  278. -    bug fix to 65816 expression at end of CONST record. parsing the
  279. -        syntax of this opcode was dead wrong.
  280. -    minimize parentheses routine for disassembly
  281. -        (thanks to tim meekins)
  282. -
  283. -v1.0b    22 january 1991
  284. -    fix pause, oa-period
  285. -        (thanks to jawaid bazyar, tim meekins)
  286. -    fix to disassembly routines
  287. -    set reload bit
  288. -
  289. -v0.9b    12 january 1991
  290. -    fix to disasm routines
  291. -    fix to displacement, code counter
  292. -    +infix option working
  293. -    +nooffset option working
  294. -    +postfix option added
  295. -    +label option added
  296. -    all file i/o converted to GS/OS calls
  297. -    added record tyep: BEXPR
  298. -
  299. -v0.8b    21 december 1990
  300. -    support for OMF v2.0 headers
  301. -    added record type: LCONST
  302. -
  303. -v0.7b    19 december 1990
  304. -    added record types: GEQU, MEM, EQU
  305. -
  306. -v0.6b    18 december 1990
  307. -    initial release of beta
  308. -
  309. =coff.h.s
  310. -* UNIX coff utility
  311. -* defines
  312. -*
  313. -* 1990-1992, The UNIX Consortium Developer Project
  314. -*
  315. -* albert chin-a-young ... 26285659t@servax.fiu.edu
  316. -
  317. -
  318. -NULL equ 0
  319. -EOF equ $ffff
  320. -FALSE equ 0 ;boolean false value
  321. -TRUE equ 1 ;boolean true value
  322. -
  323. -CTRL_C equ $03 ;ctrl-c keypress (cancel)
  324. -
  325. -MERLIN_16 equ %00000001 ;output code for Merlin 16
  326. -ORCA_M equ %00000010 ;output code for Orca/M
  327. -
  328. -;error messages
  329. -ERROR_STRING equ %00000001_00000000 ;parameter to error is C-String
  330. -ERROR_LHEX_VALUE equ %00000010_00000000 ;parameter to error is long hex value
  331. -ERROR_DEC_VALUE equ %00000100_00000000 ;parameter to error is decimal value
  332. -NO_FILENAME equ ERROR_STRING+$00 ;no OMF filename given
  333. -INVALID_FILENAME equ ERROR_STRING+$02 ;filename given is incorrect
  334. -PREMATURE_END equ ERROR_STRING+$04 ;premature end of file
  335. -OMF_VERSION equ ERROR_DEC_VALUE+$06 ;invalid OMF version
  336. -INVALID_LENGTH equ ERROR_LHEX_VALUE+$08 ;invalid length of OMF file
  337. -MORE_DATA equ ERROR_STRING+$0a ;not enough data in file to make sense of
  338. -
  339. -MERLIN equ %00000001 ;merlin assembler
  340. -ORCA equ %00000010 ;orca assembler
  341. -
  342. -ERROR equ $ffff
  343. -LOADNAME_LEN equ 10 ;length of loadname in OMF header
  344. -KIND_LEN equ 40 ;length of kind descriptor
  345. -DC equ $0100
  346. -HEADER_LEN equ $38 ;approximate length of OMF header
  347. -
  348. -HEADER_EDGE equ 15
  349. -ADDRESS_EDGE equ 36
  350. -CHAR_EDGE equ 40
  351. -CONST_EDGE equ 10
  352. -DOUBLE_EDGE equ 36
  353. -EXTENDED_EDGE equ 36
  354. -FLOAT_EDGE equ 36
  355. -HEX_EDGE equ 20
  356. -INT_EDGE equ 36
  357. -INFIX_EDGE equ 32
  358. -POSTFIX_EDGE equ 30
  359. -SOFT_REFERENCE_EDGE equ 36
  360. -SUPER_EDGE equ 11
  361. -INVALID_NAME_EDGE equ 65
  362. -
  363. -TRUE_OFFSET equ $80
  364. -FALSE_OFFSET equ $81
  365. -LIBRARY equ $b2 ;library file
  366. -
  367. -USAGE equ $0001 ;short usage parameters
  368. -USAGE_VERBOSE equ $0002 ;verbose usage parameters
  369. -VERSION equ $0003 ;coff version number
  370. -THANKS equ $0004 ;those who helped in development of coff
  371. -DEFAULT equ $0005 ;default options
  372. -
  373. -GSOS_INLINE equ $e100a8 ;GS/OS inline entry
  374. -GSOS_STACK equ $e100b0 ;GS/OS stack entry
  375. -PRODOS_MLI equ $bf00 ;ProDOS 8 MLI entry
  376. -TOOL_STACK equ $e10000 ;ToolBox stack entry
  377. -TOOL_STACK_ALT equ $e10004 ;alt ToolBox stack entry
  378. -
  379. -KBD equ $e0c000 ;read keyboard
  380. -KBDSTRB equ $e0c010 ;clear keyboard
  381. -
  382. -* segment type subfield
  383. -*
  384. -CODE equ $0000
  385. -DATA equ $0001
  386. -JUMP_TABLE equ $0002
  387. -PATHNAME equ $0004
  388. -LIBRARY_DICTIONARY equ $0008
  389. -INITIALIZATION equ $0010
  390. -ABSOLUTE_BANK_SEG equ $0011
  391. -DIRECT_PAGE equ $0012
  392. -
  393. -* segment attributes bits
  394. -*
  395. -BANK_RELATIVE equ $0100
  396. -SKIP equ $0200
  397. -RELOAD equ $0400
  398. -ABSOLUTE_BANK equ $0800
  399. -POSITION_INDEPENDENT equ $2000
  400. -PRIVATE equ $4000
  401. -DYNAMIC equ $8000
  402. -
  403. -* segment-body record types
  404. -*
  405. -END equ $00
  406. -ALIGN equ $e0
  407. -ORG equ $e1
  408. -RELOC equ $e2
  409. -INTERSEG equ $e3
  410. -USING equ $e4
  411. -STRONG equ $e5
  412. -GLOBAL equ $e6
  413. -GEQU equ $e7
  414. -MEM equ $e8
  415. -EXPR equ $eb
  416. -ZEXPR equ $ec
  417. -BEXPR equ $ed
  418. -RELEXPR equ $ee
  419. -LOCAL equ $ef
  420. -EQU equ $f0
  421. -DS equ $f1
  422. -LCONST equ $f2
  423. -LEXPR equ $f3
  424. -ENTRY equ $f4
  425. -cRELOC equ $f5
  426. -cINTERSEG equ $f6
  427. -SUPER equ $f7
  428. -GENERAL equ $fb
  429. -
  430. -SUPER_RELOC2 equ 0
  431. -SUPER_RELOC3 equ 1
  432. -
  433. -* expressions
  434. -*
  435. -ADD equ $01
  436. -SUB equ $02
  437. -MUL equ $03
  438. -DIV equ $04
  439. -MOD equ $05
  440. -NEGATION equ $06
  441. -BIT_SHIFT equ $07
  442. -AND equ $08
  443. -OR equ $09
  444. -EOR equ $0a
  445. -NOT equ $0b
  446. -LESS_EQUAL equ $0c
  447. -GREATER_EQUAL equ $0d
  448. -NOT_EQUAL equ $0e
  449. -LESS equ $0f
  450. -GREATER equ $10
  451. -EQUAL equ $11
  452. -LOGICAL_AND equ $12
  453. -INCLUSIVE_OR equ $13
  454. -EXCLUSIVE_OR equ $14
  455. -COMPLEMENT equ $15
  456. -
  457. -LEFT equ 0
  458. -RIGHT equ 1
  459. -LEFT_RIGHT equ 2
  460. -
  461. -LOCATION_COUNTER equ $80
  462. -CONSTANT_OPERAND equ $81
  463. -LABEL_WEAK equ $82
  464. -LABEL_VALUE equ $83
  465. -LABEL_LENGTH equ $84
  466. -LABEL_TYPE equ $85
  467. -LABEL_COUNT equ $86
  468. -RELATIVE_OFFSET equ $87
  469. -
  470. -LONGI equ $10
  471. -LONGA equ $20
  472. -
  473. -ASL equ $0a
  474. -INC equ $1a
  475. -ROL equ $2a
  476. -DEC equ $3a
  477. -LSR equ $4a
  478. -ROR equ $6a
  479. -
  480. -JSR equ $20
  481. -JSL equ $22
  482. -LDX equ $a2
  483. -PEA equ $f4
  484. -
  485. -BPL equ $10
  486. -BMI equ $30
  487. -BVC equ $50
  488. -BVS equ $70
  489. -BRA equ $80
  490. -BCC equ $90
  491. -BCS equ $b0
  492. -REP equ $c2
  493. -BNE equ $d0
  494. -SEP equ $e2
  495. -BEQ equ $f0
  496. -
  497. -* addressing modes
  498. -*
  499. -ABSOLUTE equ $01
  500. -ABSOLUTE_INDEX_X equ $02
  501. -ABSOLUTE_INDEX_Y equ $03
  502. -ABSOLUTE_INDEX_INDIRECT equ $04
  503. -ABSOLUTE_INDIRECT equ $05
  504. -ABSOLUTE_INDIRECT_LONG equ $06
  505. -ABSOLUTE_LONG equ $07
  506. -ABSOLUTE_LONG_INDEX_X equ $08
  507. -ACCUMULATOR equ $09
  508. -BLOCK_MOVE equ $0a
  509. -DP equ $0b
  510. -DP_INDEX_X equ $0c
  511. -DP_INDEX_Y equ $0d
  512. -DP_INDEX_INDIRECT_X equ $0e
  513. -DP_INDIRECT equ $0f
  514. -DP_INDIRECT_LONG equ $10
  515. -DP_INDIRECT_INDEX_Y equ $11
  516. -DP_INDIRECT_LONG_INDEX_Y equ $12
  517. -IMMEDIATE equ $13
  518. -IMPLIED equ $14
  519. -PC_RELATIVE equ $15
  520. -PC_RELATIVE_LONG equ $16
  521. -STACK_ABSOLUTE equ $17
  522. -STACK_DP_INDIRECT equ $18
  523. -STACK_INTERRUPT equ $19
  524. -STACK_PC_RELATIVE equ $1a
  525. -STACK_PULL equ $1b
  526. -STACK_PUSH equ $1c
  527. -STACK_RTI equ $1d
  528. -STACK_RTL equ $1e
  529. -STACK_RTS equ $1f
  530. -STACK_RELATIVE equ $20
  531. -SR_INDIRECT_INDEX_Y equ $21
  532. -WDM equ $22
  533. -
  534. -;@label structure references
  535. -`label_name equ $00 ;name of label
  536. -`expr_name equ `label_name+4 ;expression label evaluates to
  537. -`type equ `expr_name+4 ;GLOBAL or LOCAL label
  538. -`next equ `type+2 ;next label reference
  539. -`prev equ `next+4 ;previous label reference
  540. -`last equ `prev+4
  541. -
  542. -;@stack structure references
  543. -stack`str equ $00 ;handle to expression name (string)
  544. -stack`oper equ stack`str+4 ;if expression is an operator
  545. -
  546. -;@label data structure offsets
  547. -`lo equ $00 ;handle to array of labels
  548. -`hi equ `lo+4
  549. -
  550. -;offsets to elements in binary tree
  551. -`str equ $00
  552. -`oper equ `str+4
  553. -`left equ `oper+2 ;left tree
  554. -`right equ `left+2 ;right tree
  555. -
  556. -   ;@btree data structure offsets
  557. -`ptr equ $00 ;pointer to array of binary trees
  558. -
  559. -;~operator data structure offsets
  560. -`prec equ $00 ;operator precedence
  561. -`assoc equ `prec+2 ;operator associativity
  562. -
  563. -;~opcodes data structure offsets
  564. -`num_bytes equ $00 ;number of bytes the opcode takes
  565. -`m equ `num_bytes+2 ;if 16-bit mode accumulator
  566. -`i equ `m+2 ;if 16-bit mode index registers
  567. -`mode equ `i+2 ;addressing mode
  568. -`syntax equ `mode+2 ;how to format opcode
  569. -
  570. -;@omf data structure offsets
  571. -`offset equ $00 ;offset from beginning of file for this segment
  572. -`bytecnt equ `offset+4 ;number of bytes in file that segment requires
  573. -`resspc equ `bytecnt+4 ;number of bytes of zeros to add to end of segment
  574. -`length equ `resspc+4 ;memory size of segment
  575. -`kind equ `length+4 ;type and attributes of segment
  576. -`lablen equ `kind+2 ;length of each name or label record in segment
  577. -`numlen equ `lablen+2 ;length of each number field in segment body
  578. -`version equ `numlen+2 ;version number of OMF segment is compatible with
  579. -`revision equ `version+2 ;revision number of OMF v2.0 segment is compatible with
  580. -`banksize equ `revision+2 ;maximum memory-bank size for segment
  581. -`org equ `banksize+4 ;absolute address at which to load segment
  582. -`align equ `org+4 ;boundary on which to align segment
  583. -`numsex equ `align+4 ;order of bytes in a number field
  584. -`lcbank equ `numsex+2 ;load segment into language card
  585. -`segnum equ `lcbank+2 ;segment number
  586. -`entry equ `segnum+2 ;offset into segment that corresponds to entry point
  587. -`dispname equ `entry+4 ;displacement of the loadname field within segment header
  588. -`dispdata equ `dispname+2 ;displacement from start of segment header to start of segment body
  589. -`temporg equ `dispdata+2 ;temporary origin of object segment for OMF v2.0
  590. -`loadname equ `temporg+4 ;name of load segment
  591. -`segname equ `loadname+LOADNAME_LEN ;name of segment
  592. -`displacement equ `segname+4
  593. -`counter equ `displacement+4
  594. -`library equ `counter+4 ;if file is a library
  595. -`refNum equ `library+2 ;reference number associated with file
  596. -
  597. -;global/local data parsing structure
  598. -`on equ $00 ;test if parsing on
  599. -`data_type equ `on+2 ;type of data to parse
  600. -`count equ `data_type+2 ;number of records to parse
  601. -`edge equ `count+2 ;right margin for output of data
  602. -
  603. -;@stack data structure offsets
  604. -`lo equ $00 ;array of handles containing stack
  605. -`hi equ `lo+4 ;elements
  606. -`size equ `hi+4 ;number of elements in stack
  607. -
  608. -;@expr_list data structure offsets
  609. -`lo equ $00 ;array of handles containing stack
  610. -`hi equ `lo+4 ;elements
  611. -`size equ `hi+4 ;number of elements in stack
  612. -
  613. -;offset for @Close data structure
  614. -Close`pCount equ $00
  615. -Close`refNum equ Close`pCount+2
  616. -
  617. -;offset for @Open data structure
  618. -Open`pCount equ $00
  619. -Open`refNum equ Open`pCount+2
  620. -Open`pathname equ Open`refNum+2
  621. -Open`requestAccess equ $08
  622. -Open`resourceNumber equ $0a
  623. -Open`access equ $0c
  624. -Open`fileType equ $0e
  625. -Open`auxType equ $10
  626. -Open`storageType equ $14
  627. -Open`createDateTime equ $16
  628. -Open`modDateTime equ $1e
  629. -Open`optionList equ $26
  630. -Open`eof equ $2a
  631. -Open`blocksUsed equ $2e
  632. -Open`resourceEOF equ $32
  633. -Open`resourceBlocks equ $36
  634. -
  635. -;offset for @SetMark data structure
  636. -SetMark`pCount equ $00
  637. -SetMark`refNum equ SetMark`pCount+2
  638. -SetMark`base equ SetMark`refNum+2
  639. -SetMark`displacement equ SetMark`base+2
  640. -
  641. -;offset for @GetMark data structure
  642. -GetMark`pCount equ $00
  643. -GetMark`refNum equ $02
  644. -GetMark`position equ $04
  645. -
  646. -;offset for @Quit data structure
  647. -Quit`pCount equ $00
  648. -Quit`pathname equ $02
  649. -Quit`flags equ $06
  650. -
  651. -;offset for @Read data structure
  652. -Read`pCount equ $00
  653. -Read`refNum equ $02
  654. -Read`dataBuffer equ $04
  655. -Read`requestCount equ $08
  656. -Read`transferCount equ $0c
  657. -Read`cachePriority equ $10
  658. -
  659. -GSOSstack equ $e100b0 ;gs/os stack entry point
  660. -
  661. -Open equ $2010 ;Open call number
  662. -Read equ $2012 ;Read call number
  663. -Close equ $2014 ;Close call number
  664. -SetMark equ $2016 ;SetMark call number
  665. -GetMark equ $2017 ;GetMark call number
  666. -Quit equ $2029 ;Quit call number
  667. =coff.mac.s
  668. -* UNIX coff utility
  669. -* macros
  670. -*
  671. -* 1990-1992, tao Developer Project
  672. -
  673. -
  674. -cstr mac
  675. - asc '    ' ;space between opcode and operand
  676. - asc ]1
  677. - db 0
  678. - eom
  679. -absolute mac
  680. - dw 3,0,0
  681. - dw ABSOLUTE
  682. - asc ]1
  683. - cstr '$%4'
  684. - eom
  685. -absolute_index_x mac
  686. - dw 3,0,0
  687. - dw ABSOLUTE_INDEX_X
  688. - asc ]1
  689. - cstr '$%4,x'
  690. - eom
  691. -absolute_index_y mac
  692. - dw 3,0,0
  693. - dw ABSOLUTE_INDEX_Y
  694. - asc ]1
  695. - cstr '$%4,y'
  696. - eom
  697. -absolute_index_indirect mac
  698. - dw 3,0,0
  699. - dw ABSOLUTE_INDEX_INDIRECT
  700. - asc ]1
  701. - cstr '($%4,x)'
  702. - eom
  703. -absolute_indirect mac
  704. - dw 3,0,0
  705. - dw ABSOLUTE_INDIRECT
  706. - asc ]1
  707. - cstr '($%4)'
  708. - eom
  709. -absolute_indirect_long mac
  710. - dw 3,0,0
  711. - dw ABSOLUTE_INDIRECT_LONG
  712. - asc ]1
  713. - cstr '[$%4]'
  714. - eom
  715. -absolute_long mac
  716. - dw 4,0,0
  717. - dw ABSOLUTE_LONG
  718. - asc ]1
  719. - cstr '%c$%6'
  720. - eom
  721. -absolute_long_index_x mac
  722. - dw 4,0,0
  723. - dw ABSOLUTE_LONG_INDEX_X
  724. - asc ]1
  725. - cstr '%c$%6,x'
  726. - eom
  727. -accumulator macm
  728. - dw 1,0,0
  729. - dw ACCUMULATOR
  730. - asc ]1
  731. - asc '    ',00
  732. - eom
  733. -block_move mac
  734. - dw 3,0,0
  735. - dw BLOCK_MOVE
  736. - asc ]1
  737. - asc '    $',00
  738. - eom
  739. -dp mac
  740. - dw 2,0,0
  741. - dw DP
  742. - asc ]1
  743. - cstr '$%2'
  744. - eom
  745. -dp_index_x mac
  746. - dw 2,0,0
  747. - dw DP_INDEX_X
  748. - asc ]1
  749. - cstr '$%2,x'
  750. - eom
  751. -dp_index_y mac
  752. - dw 2,0,0
  753. - dw DP_INDEX_Y
  754. - asc ]1
  755. - cstr '$%2,y'
  756. - eom
  757. -dp_index_indirect_x mac
  758. - dw 2,0,0
  759. - dw DP_INDEX_INDIRECT_X
  760. - asc ]1
  761. - cstr '($%2,x)'
  762. - eom
  763. -dp_indirect mac
  764. - dw 2,0,0
  765. - dw DP_INDIRECT
  766. - asc ]1
  767. - cstr '($%2)'
  768. - eom
  769. -dp_indirect_long mac
  770. - dw 2,0,0
  771. - dw DP_INDIRECT_LONG
  772. - asc ]1
  773. - cstr '[$%2]'
  774. - eom
  775. -dp_indirect_index_y mac
  776. - dw 2,0,0
  777. - dw DP_INDIRECT_INDEX_Y
  778. - asc ]1
  779. - cstr '($%2),y'
  780. - eom
  781. -dp_indirect_long_index_y mac
  782. - dw 2,0,0
  783. - dw DP_INDIRECT_LONG_INDEX_Y
  784. - asc ]1
  785. - cstr '[$%2],y'
  786. - eom
  787. -immediate_m mac
  788. - dw 2,1,0
  789. - dw IMMEDIATE
  790. - asc ]1
  791. - cstr '#$%2'
  792. - eom
  793. -immediate_i mac
  794. - dw 2,0,1
  795. - dw IMMEDIATE
  796. - asc ]1
  797. - cstr '#$%2'
  798. - eom
  799. -immediate_rep mac
  800. - dw 2,0,0
  801. - dw IMMEDIATE
  802. - asc ]1
  803. - cstr '#$%2'
  804. - eom
  805. -immediate_sep mac
  806. - dw 2,0,0
  807. - dw IMMEDIATE
  808. - asc ]1
  809. - cstr '#$%2'
  810. - eom
  811. -implied mac
  812. - dw 1,0,0
  813. - dw IMPLIED
  814. - asc ]1
  815. - asc '    ',00
  816. - eom
  817. -pc_relative mac
  818. - dw 2,0,0
  819. - dw PC_RELATIVE
  820. - asc ]1
  821. - cstr '$%4'
  822. - eom
  823. -pc_relative_long mac
  824. - dw 3,0,0
  825. - dw PC_RELATIVE_LONG
  826. - asc ]1
  827. - cstr '$%4'
  828. - eom
  829. -stack_absolute mac
  830. - dw 3,0,0
  831. - dw STACK_ABSOLUTE
  832. - asc ]1
  833. - cstr '$%4'
  834. - eom
  835. -stack_dp_indirect mac
  836. - dw 2,0,0
  837. - dw STACK_DP_INDIRECT
  838. - asc ]1
  839. - cstr '($%2)'
  840. - eom
  841. -stack_interrupt mac
  842. - dw 2,0,0
  843. - dw STACK_INTERRUPT
  844. - asc ]1
  845. - cstr '$%2'
  846. - eom
  847. -stack_pc_relative mac
  848. - dw 3,0,0
  849. - dw STACK_PC_RELATIVE
  850. - asc ]1
  851. - cstr '$%4'
  852. - eom
  853. -stack_pull mac
  854. - dw 1,0,0
  855. - dw STACK_PULL
  856. - asc ]1
  857. - asc '    ',00
  858. - eom
  859. -stack_push mac
  860. - dw 1,0,0
  861. - dw STACK_PUSH
  862. - asc ]1
  863. - asc '    ',00
  864. - eom
  865. -stack_rti mac
  866. - dw 1,0,0
  867. - dw STACK_RTI
  868. - asc ]1
  869. - asc '    ',00
  870. - eom
  871. -stack_rtl mac
  872. - dw 1,0,0
  873. - dw STACK_RTL
  874. - asc ]1
  875. - asc '    ',00
  876. - eom
  877. -stack_rts mac
  878. - dw 1,0,0
  879. - dw STACK_RTS
  880. - asc ]1
  881. - asc '    ',00
  882. - eom
  883. -sr mac
  884. - dw 2,0,0
  885. - dw STACK_RELATIVE
  886. - asc ]1
  887. - cstr '$%2,s'
  888. - eom
  889. -sr_indirect_index_y mac
  890. - dw 2,0,0
  891. - dw SR_INDIRECT_INDEX_Y
  892. - asc ]1
  893. - cstr '($%2,s),y'
  894. - eom
  895. -wdm_ mac
  896. - dw 2,0,0
  897. - dw WDM
  898. - asc ]1
  899. - cstr '$%2'
  900. - eom
  901. -
  902. -operator mac
  903. - dw ]1 ;operator precedence
  904. - dw ]2 ;operator associativity
  905. - eom
  906. -
  907. -read_char mac ;read one byte
  908. - if ],]1 ;special case reading into a
  909. - clc ;dp location
  910. - tdc
  911. - adc #]1
  912. - tax
  913. - ldy #0
  914. - else
  915. - ldx #]1
  916. - ldy #^]1
  917. - fin
  918. - lda #1
  919. - jsr GSOSread
  920. - eom
  921. -read_short mac ;read two bytes
  922. - if ],]1 ;special case reading into a
  923. - clc ;dp location
  924. - tdc
  925. - adc #]1
  926. - tax
  927. - ldy #0
  928. - else
  929. - ldx #]1
  930. - ldy #^]1
  931. - fin
  932. - lda #2
  933. - jsr GSOSread
  934. - eom
  935. -read_long mac ;read four bytes
  936. - if ],]1 ;special case reading into a
  937. - clc ;dp location
  938. - tdc
  939. - adc #]1
  940. - tax
  941. - ldy #0
  942. - else
  943. - ldx #]1
  944. - ldy #^]1
  945. - fin
  946. - lda #4
  947. - jsr GSOSread
  948. - eom
  949. -read_float mac ;read one byte
  950. - if ],]1 ;special case reading into a
  951. - clc ;dp location
  952. - tdc
  953. - adc #]1
  954. - tax
  955. - ldy #0
  956. - else
  957. - ldx #]1
  958. - ldy #^]1
  959. - fin
  960. - lda #4
  961. - jsr GSOSread
  962. - eom
  963. -read_double mac ;read one byte
  964. - if ],]1 ;special case reading into a
  965. - clc ;dp location
  966. - tdc
  967. - adc #]1
  968. - tax
  969. - ldy #0
  970. - else
  971. - ldx #]1
  972. - ldy #^]1
  973. - fin
  974. - lda #8
  975. - jsr GSOSread
  976. - eom
  977. -read_extended mac ;read one byte
  978. - if ],]1 ;special case reading into a
  979. - clc ;dp location
  980. - tdc
  981. - adc #]1
  982. - tax
  983. - ldy #0
  984. - else
  985. - ldx #]1
  986. - ldy #^]1
  987. - fin
  988. - lda #10
  989. - jsr GSOSread
  990. - eom
  991. -
  992. -_DebugStr mac
  993. - pea #^]1
  994. - pea #]1
  995. - ldx #$09ff
  996. - jsl $e10000
  997. - eom
  998. -_GSOS mac
  999. - pea #^]2
  1000. - pea #]2
  1001. - pea #]1
  1002. - jsl GSOSstack
  1003. - eom
  1004. -shorta mac
  1005. - mx %10
  1006. - sep %00100000
  1007. - eom
  1008. -longa mac
  1009. - mx %00
  1010. - rep %00100000
  1011. - eom
  1012. -shorti mac
  1013. - mx %01
  1014. - sep %00010000
  1015. - eom
  1016. -longi mac
  1017. - mx %00
  1018. - rep %00010000
  1019. - eom
  1020. -
  1021. -incr mac ;longword inc
  1022. - if 1,]0
  1023. - inc ]1
  1024. - bne end
  1025. - inc ]1+2
  1026. - else
  1027. - clc
  1028. - lda ]2
  1029. - adc ]1
  1030. - sta ]2
  1031. - bcc end
  1032. - inc ]2+2
  1033. -end fin
  1034. - eom
  1035. -decr mac ;longword dec
  1036. - if 1,]0
  1037. - dec ]1
  1038. - bpl end
  1039. - dec ]1+2
  1040. - else
  1041. - sec
  1042. - lda ]2
  1043. - sbc ]1
  1044. - sta ]2
  1045. - bcs end
  1046. - dec ]2+2
  1047. -end fin
  1048. - eom
  1049. -
  1050. -_TLStartUp mac
  1051. - Tool $201
  1052. - eom
  1053. -_TLShutDown mac
  1054. - Tool $301
  1055. - eom
  1056. -_MMStartUp mac
  1057. - Tool $202
  1058. - eom
  1059. -_MMShutDown mac
  1060. - Tool $302
  1061. - eom
  1062. -_DisposeAll mac
  1063. - Tool $1102
  1064. - eom
  1065. -_StartUpTools mac
  1066. - Tool $1801
  1067. - eom
  1068. -_ShutDownTools mac
  1069. - Tool $1901
  1070. - eom
  1071. -Tool mac
  1072. - ldx #]1
  1073. - jsl $e10000
  1074. - eom
  1075. -_LoadResource mac
  1076. - Tool $e1e
  1077. - eom
  1078. -_WriteCString mac
  1079. - Tool $200c
  1080. - eom
  1081. -_WriteString mac
  1082. - Tool $1c0c
  1083. - eom
  1084. -_ErrWriteCString mac
  1085. - Tool $210c
  1086. - eom
  1087. -_ErrWriteChar mac
  1088. - Tool $190c
  1089. - eom
  1090. -_WriteChar mac
  1091. - Tool $180c
  1092. - eom
  1093. -_TextWriteBlock mac
  1094. - Tool $1e0c
  1095. - eom
  1096. -_ResourceStartUp mac
  1097. - Tool $021e
  1098. - eom
  1099. -_ResourceShutDown mac
  1100. - Tool $031e
  1101. - eom
  1102. -_CloseResourceFile mac
  1103. - Tool $0b1e
  1104. - eom
  1105. -_OpenResourceFile mac
  1106. - Tool $0a1e
  1107. - eom
  1108. -_GetOutputDevice mac
  1109. - Tool $130c
  1110. - eom
  1111. -_GetErrorDevice mac
  1112. - Tool $140c
  1113. - eom
  1114. -_LGetPathname2 mac
  1115. - Tool $2211
  1116. - eom
  1117. -_HLock mac
  1118. - Tool $2002
  1119. - eom
  1120. -_GetResourceSize mac
  1121. - Tool $1d1e
  1122. - eom
  1123. -_HUnlock mac
  1124. - Tool $2202
  1125. - eom
  1126. -_NewHandle mac
  1127. - Tool $902
  1128. - eom
  1129. -_DisposeHandle mac
  1130. - Tool $1002
  1131. - eom
  1132. -_SetHandleSize mac
  1133. - Tool $1902
  1134. - eom
  1135. -_Int2Hex mac
  1136. - Tool $220b
  1137. - eom
  1138. -_Int2Dec mac
  1139. - Tool $260b
  1140. - eom
  1141. -_Long2Hex mac
  1142. - Tool $230b
  1143. - eom
  1144. -_Long2Dec mac
  1145. - Tool $270b
  1146. - eom
  1147. -_SysBeep mac
  1148. - Tool $2c03
  1149. - eom
  1150. -
  1151. -_SANEDecStr816 mac
  1152. - Tool $0A0A
  1153. - eom
  1154. -_SANEFP816 mac
  1155. - Tool $090A
  1156. - eom
  1157. -_Float2Decimal mac
  1158. - pea #$020b
  1159. - _SANEFP816
  1160. - eom
  1161. -_Double2Decimal mac
  1162. - pea #$010b
  1163. - _SANEFP816
  1164. - eom
  1165. -_Extended2Decimal mac
  1166. - pea #$000b
  1167. - _SANEFP816
  1168. - eom
  1169. -_Dec2Str mac
  1170. - pea #1
  1171. - _SANEDecStr816
  1172. - eom
  1173. =datatype.mac.s
  1174. -* data types
  1175. -*
  1176. -* albert chin-a-young ... 26285659t@servax.fiu.edu
  1177. -
  1178. -* integer types
  1179. -*
  1180. -UnsignedLong mac
  1181. - if 0,]0
  1182. - ds 4
  1183. - else
  1184. - adrl ]1
  1185. - fin
  1186. - eom
  1187. -Long mac
  1188. - if 0,]0
  1189. - ds 4
  1190. - else
  1191. - adrl ]1
  1192. - fin
  1193. - eom
  1194. -UnsignedShort mac
  1195. - if 0,]0
  1196. - ds 2
  1197. - else
  1198. - dw ]1
  1199. - fin
  1200. - eom
  1201. -Short mac
  1202. - if 0,]0
  1203. - ds 2
  1204. - else
  1205. - dw ]1
  1206. - fin
  1207. - eom
  1208. -UnsignedChar mac
  1209. - if 0,]0
  1210. - ds 1
  1211. - else
  1212. - db ]1
  1213. - fin
  1214. - eom
  1215. -Char mac
  1216. - if 0,]0
  1217. - ds 1
  1218. - else
  1219. - ds ]1
  1220. - fin
  1221. - eom
  1222. -Boolean mac
  1223. - if 0,]0
  1224. - ds 2
  1225. - else
  1226. - adrl ]1
  1227. - fin
  1228. - eom
  1229. -
  1230. -* pointer types
  1231. -*
  1232. -Handle mac
  1233. - if 0,]0
  1234. - adrl 0
  1235. - else
  1236. - adrl ]1
  1237. - fin
  1238. - eom
  1239. -Pointer mac
  1240. - if 0,]0
  1241. - adrl 0
  1242. - else
  1243. - adrl ]1
  1244. - fin
  1245. - eom
  1246. -CharPtr mac
  1247. - if 0,]0
  1248. - ds 4
  1249. - else
  1250. - adrl ]1
  1251. - fin
  1252. - eom
  1253. -ShortPtr mac
  1254. - if 0,]0
  1255. - ds 4
  1256. - else
  1257. - adrl ]1
  1258. - fin
  1259. - eom
  1260. -
  1261. -* string types
  1262. -*
  1263. -cStr mac ;C-style string with trailing 0
  1264. - asc ]1
  1265. - db 0
  1266. - eom
  1267. -pStr mac ;Pascal-style string with leading
  1268. - str ]1 ;length byte
  1269. - eom
  1270. -gsStr mac ;GS/OS-style string with leading
  1271. - strl ]1 ;length word
  1272. - eom
  1273. -
  1274. -* gs/os types
  1275. -*
  1276. -Word mac
  1277. - if 0,]0
  1278. - dw 0
  1279. - else
  1280. - dw ]1
  1281. - fin
  1282. - eom
  1283. =coff.r
  1284. -/*
  1285. -    coff - utility to dump contents of OMF files
  1286. -
  1287. -    1990-1992, The tao Developer Project
  1288. -
  1289. -    albert chin-a-young ... 26285659t@servax.fiu.edu
  1290. -*/
  1291. -
  1292. -#include "types.rez"
  1293. -
  1294. -#define USAGE        0x0001
  1295. -#define USAGE_VERBOSE    0x0002
  1296. -#define VERSION        0x0003
  1297. -#define THANKS        0x0004
  1298. -#define DEFAULT        0x0005
  1299. -
  1300. -#if defined(MERLIN)
  1301. -#define RETURN        "\n"
  1302. -#elif defined(ORCA)
  1303. -#define RETURN          "\n\r"
  1304. -#elif defined(GNO)
  1305. -#define RETURN          "\n\r"
  1306. -#endif
  1307. -
  1308. -resource rText (USAGE)
  1309. -{
  1310. -    $$Format (" [-vDdTxltpmoaisnfceh] <filename> [segment..] [loadsegment..]%s", RETURN)
  1311. -    $$Format ("       [+version] [+nodefault] [+asm] [+tool] [+hex] [+label] [+infix]%s", RETURN)
  1312. -    $$Format ("       [+postfix] [+merlin] [+orca] [+shorta] [+shorti] [+header]%s", RETURN)
  1313. -    $$Format ("       [+noheader] [+nooffset] [+compress] [+exact] [+thanks] [+help]%s", RETURN)
  1314. -    "\000"
  1315. -};
  1316. -
  1317. -#if defined(MERLIN)
  1318. -resource rText (USAGE_VERBOSE)
  1319. -{
  1320. -    " [-OPTIONS] filename [segment..] [loadsegment..]\n\n"
  1321. -    "     OPTIONS         DESCRIPTION\n"
  1322. -    "     -v [+version]   display version number\n"
  1323. -    "     -D [+nodefault] disable default options\n"
  1324. -    "     -d [+asm]       dump segment body in 65816-format disassembly\n"
  1325. -    "     -T [+tool]      interpret Toolbox, GS/OS, ProDOS, ROM calls\n"
  1326. -    "     -x [+hex]       dump segment body in hex (can be used with '+asm')\n"
  1327. -    "     -l [+label]     print expressions using labels (default is offsets)\n"
  1328. -    "     -t [+infix]     display expressions in infix form\n"
  1329. -    "     -p [+postfix]   display expressions in postfix form (default)\n"
  1330. -    "     -m [+merlin]    format of '+asm' to use merlin opcodes (default)\n"
  1331. -    "     -o [+orca]      format of '+asm' to use orca/m opcodes\n"
  1332. -    "     -a [+shorta]    assume 8-bit accumulator for disassembly\n"
  1333. -    "     -i [+shorti]    assume 8-bit index registers for disassembly\n"
  1334. -    "     -s [+header]    dump segment headers only\n"
  1335. -    "     -n [+noheader]  do not print segment headers\n"
  1336. -    "     -f [+nooffset]  do not print offset into file\n"
  1337. -    "     -c [+compress]  print short form of CONST, LCONST records\n"
  1338. -    "     -e [+exact]     match segment, loadsegment names exactly\n"
  1339. -    "        [+thanks]    those who helped in the development of coff\n"
  1340. -    "     -h [+help]      print this information, then quit\n\n"
  1341. -    "     filename        name of OMF file to dump\n"
  1342. -    "     [segment]       names of segments in file to dump\n"
  1343. -    "     [loadsegment]   names of load segments in file to dump\n\000"
  1344. -};
  1345. -#elif defined(ORCA)
  1346. -resource rText (USAGE_VERBOSE)
  1347. -{
  1348. -    " [-OPTIONS] filename [segment..] [loadsegment..]\n\r\n\r"
  1349. -    "     OPTIONS         DESCRIPTION\n\r"
  1350. -    "     -v [+version]   display version number\n\r"
  1351. -    "     -D [+nodefault] disable default options\n\r"
  1352. -    "     -d [+asm]       dump segment body in 65816-format disassembly\n\r"
  1353. -    "     -T [+tool]      interpret Toolbox, GS/OS, ProDOS, ROM calls\n\r"
  1354. -    "     -x [+hex]       dump segment body in hex (can be used with '+asm')\n\r"
  1355. -    "     -l [+label]     print expressions using labels (default is offsets)\n\r"
  1356. -    "     -t [+infix]     display expressions in infix form\n\r"
  1357. -    "     -p [+postfix]   display expressions in postfix form (default)\n\r"
  1358. -    "     -m [+merlin]    format of '+asm' to use merlin opcodes (default)\n\r"
  1359. -    "     -o [+orca]      format of '+asm' to use orca/m opcodes\n\r"
  1360. -    "     -a [+shorta]    assume 8-bit accumulator for disassembly\n\r"
  1361. -    "     -i [+shorti]    assume 8-bit index registers for disassembly\n\r"
  1362. -    "     -s [+header]    dump segment headers only\n\r"
  1363. -    "     -n [+noheader]  do not print segment headers\n\r"
  1364. -    "     -f [+nooffset]  do not print offset into file\n\r"
  1365. -    "     -c [+compress]  print short form of CONST, LCONST records\n\r"
  1366. -    "     -e [+exact]     match segment, loadsegment names exactly\n\r"
  1367. -    "        [+thanks]    those who helped in the development of coff\n\r"
  1368. -    "     -h [+help]      print this information, then quit\n\r\n\r"
  1369. -    "     filename        name of OMF file to dump\n\r"
  1370. -    "     [segment]       names of segments in file to dump\n\r"
  1371. -    "     [loadsegment]   names of load segments in file to dump\n\r\000"
  1372. -};
  1373. -#elif defined(GNO)
  1374. -resource rText (USAGE_VERBOSE)
  1375. -{
  1376. -    " [OPTIONS] filename [segment..] [loadsegment..]\n\r\n\r"
  1377. -    "\tOPTIONS\t\tDESCRIPTION\n\r"
  1378. -    "\t-v [+version]\tdisplay version number\n\r"
  1379. -    "\t-D [+nodefault]\tdisable default options\n\r"
  1380. -    "\t-d [+asm]\tdump segment body in 65816-format disassembly\n\r"
  1381. -    "\t-T [+tool]\tinterpret Toolbox, GS/OS, ProDOS, ROM calls\n\r"
  1382. -    "\t-x [+hex]\tdump segment body in hex (can be used with '+asm')\n\r"
  1383. -    "\t-l [+label]\tprint expressions using labels (default is offsets)\n\r"
  1384. -    "\t-t [+infix]\tdisplay expressions in infix form\n\r"
  1385. -    "\t-p [+postfix]\tdisplay expressions in postfix form (default)\n\r"
  1386. -    "\t-m [+merlin]\tformat of '+asm' to use merlin opcodes (default)\n\r"
  1387. -    "\t-o [+orca]\tformat of '+asm' to use orca/m opcodes\n\r"
  1388. -    "\t-a [+shorta]\tassume 8-bit accumulator for disassembly\n\r"
  1389. -    "\t-i [+shorti]\tassume 8-bit index registers for disassembly\n\r"
  1390. -    "\t-s [+header]\tdump segment headers only\n\r"
  1391. -    "\t-n [+noheader]\tdo not print segment headers\n\r"
  1392. -    "\t-f [+nooffset]\tdo not print offset into file\n\r"
  1393. -    "\t-c [+compress]\tprint short form of CONST, LCONST records\n\r"
  1394. -    "\t-e [+exact]\tmatch segment, loadsegment names exactly\n\r"
  1395. -    "\t   [+thanks]\tthose who helped in the development of coff\n\r"
  1396. -    "\t-h [+help]\tprint this information, then quit\n\r\n\r"
  1397. -    "\tfilename\tname of OMF file to dump\n\r"
  1398. -    "\t[segment]\tnames of segments in file to dump\n\r"
  1399. -    "\t[loadsegment]\tnames of load segments in file to dump\n\r\000"
  1400. -};
  1401. -#endif
  1402. -
  1403. -resource rText (VERSION)
  1404. -{
  1405. -    $$Format ("v1.1%s1990-1992, tao Developer Project%s%s", RETURN, RETURN, RETURN)
  1406. -    "\000"
  1407. -};
  1408. -
  1409. -resource rText (THANKS)
  1410. -{
  1411. -    $$Format ("Special thanks to the following:%s", RETURN)
  1412. -    $$Format ("Jawaid Bazyar : Beta Tester, GNO support%s", RETURN)
  1413. -    $$Format ("Soenke Behrens: Reviewing manual%s", RETURN)
  1414. -    $$Format ("Gregg Brekke  : Reviewing manual%s", RETURN)
  1415. -    $$Format ("Morgan Davis  : Beta Tester, alt Toolbox entry option%s", RETURN)
  1416. -    $$Format ("Dave Lyons    : Permission to use NiftyList 'nlist.data' file data%s", RETURN)
  1417. -    $$Format ("Tim Meekins   : Beta Tester, minimal parentheses option%s", RETURN)
  1418. -    $$Format ("Jerry Penner  : Beta Tester, +compress option, reviewing manual%s", RETURN)
  1419. -    $$Format ("Rose Miller   : Thanks%s%s", RETURN, RETURN)
  1420. -    "\000"
  1421. -};
  1422. -
  1423. -resource rText (DEFAULT)
  1424. -{
  1425. -    "+label\000"
  1426. -    "+infix\000"
  1427. -    "+tool\000"
  1428. -};
  1429. -
  1430. -resource rVersion (0x0001)
  1431. -{
  1432. -    {
  1433. -        0x01,                // version 1.1
  1434. -        0x01,                // no minor release
  1435. -        0x00,                // bug version
  1436. -        final,                // final release
  1437. -        0x00,                // non-final release number
  1438. -    },
  1439. -    verUS,                    // USA version
  1440. -    "coff",
  1441. -    "1990-1992, tao Developer Project"
  1442. -};
  1443. -
  1444. -resource rComment (0x0001)
  1445. -{
  1446. -    "coff, an Object Module Format (OMF) disassembler.\n\n"
  1447. -    "post:\tAlbert Chin-A-Young\n"
  1448. -    "\tP.O. Box 4133\n"
  1449. -    "\tMiramar, Florida 33083-4133\n\n"
  1450. -    "email:\trichard@serss0.fiu.edu\n"
  1451. -    "\t26285659t@servax.fiu.edu"
  1452. -};
  1453. =make.gno.s
  1454. -* UNIX coff utility
  1455. -* GNO link script
  1456. -*
  1457. -* 1990-1992, tao Developer Project
  1458. -
  1459. - nol
  1460. - fas ;fast linker mode
  1461. -
  1462. - if 4/env.h
  1463. -
  1464. - asm coff
  1465. - asm gsos
  1466. - asm omf
  1467. - asm asm
  1468. - asm output
  1469. - asm general
  1470. - asm structure
  1471. - asm data
  1472. - asm tool
  1473. - asm 1/getopt/getopt
  1474. -
  1475. - lnk coff.l
  1476. - lnk gsos.l
  1477. - lnk omf.l
  1478. - lnk asm.l
  1479. - lnk output.l
  1480. - lnk general.l
  1481. - lnk structure.l
  1482. - lnk data.l
  1483. - lnk tool.l
  1484. - lnk 5/getopt.l
  1485. -
  1486. -
  1487. -**************************************************
  1488. - typ exe
  1489. - sav /dev/gno/bin/coff
  1490. =make.orca.s
  1491. -* UNIX coff utility
  1492. -* Orca link script
  1493. -*
  1494. -* 1990-1992, tao Developer Project
  1495. -
  1496. - nol
  1497. - fas ;fast linker mode
  1498. -
  1499. - if 4/env.h
  1500. -
  1501. - asm coff
  1502. - asm gsos
  1503. - asm omf
  1504. - asm asm
  1505. - asm output
  1506. - asm general
  1507. - asm structure
  1508. - asm data
  1509. - asm tool
  1510. - asm 1/getopt/getopt
  1511. -
  1512. - lnk coff.l
  1513. - lnk gsos.l
  1514. - lnk omf.l
  1515. - lnk asm.l
  1516. - lnk output.l
  1517. - lnk general.l
  1518. - lnk structure.l
  1519. - lnk data.l
  1520. - lnk tool.l
  1521. - lnk 5/getopt.l
  1522. -
  1523. -
  1524. -**************************************************
  1525. - typ exe
  1526. - sav /dev/orca/utilities/coff
  1527. =make.rez
  1528. -echo Compiling resource file for Merlin 16+
  1529. -compile coff.r keep=/usr/bin/coff rez=(-d MERLIN)
  1530. -echo Compiling resource file for Orca
  1531. -compile coff.r keep=/dev/orca/utilities/coff rez=(-d ORCA)
  1532. -echo Compiling resource file for GNO
  1533. -compile coff.r keep=/dev/gno/bin/coff rez=(-d GNO)
  1534. =make.s
  1535. -* UNIX coff utility
  1536. -* Merlin link script
  1537. -*
  1538. -* 1990-1992, tao Developer Project
  1539. -
  1540. - nol
  1541. - fas ;fast linker mode
  1542. -
  1543. - if 4/env.h
  1544. -
  1545. - asm coff
  1546. - asm gsos
  1547. - asm omf
  1548. - asm asm
  1549. - asm output
  1550. - asm general
  1551. - asm structure
  1552. - asm data
  1553. - asm tool
  1554. - asm 1/getopt/getopt
  1555. -
  1556. - lnk coff.l
  1557. - lnk gsos.l
  1558. - lnk omf.l
  1559. - lnk asm.l
  1560. - lnk output.l
  1561. - lnk general.l
  1562. - lnk structure.l
  1563. - lnk data.l
  1564. - lnk tool.l
  1565. - lnk 5/getopt.l
  1566. -
  1567. -
  1568. -**************************************************
  1569. - typ exe
  1570. - sav 6/coff
  1571. =x.asm.s
  1572. -* UNIX coff utility
  1573. -* 65816 OMF disassembler externals
  1574. -*
  1575. -* 1990-1992, tao Developer Project
  1576. -
  1577. -display_header_asm ext ;display asm disassembly header
  1578. -parse_CONST_asm ext ;disassembly entry point
  1579. -parse_type_attribute ext ;disassemble label type
  1580. =x.data.s
  1581. -* UNIX coff utility
  1582. -* variable externals
  1583. -*
  1584. -* 1990-1992, tao Developer Project
  1585. -
  1586. -* variables
  1587. -*
  1588. -userID ext ;userID returned by MMStartUp
  1589. -coff ext
  1590. -long_hex_str ext ;string hex representation of long value
  1591. -short_hex_str ext ;string hex representation of short value
  1592. -char_hex_str ext ;string hex representation of char value
  1593. -long_dec_str ext ;string decimal representation of long value
  1594. -short_dec_str ext ;string decimal representation of short value
  1595. -char_dec_str ext ;string decimal representation of char value
  1596. -blank_str ext ;blank string
  1597. -vert_separator ext ;separate displacement/bytes
  1598. -space_vert_bar ext ;spaced vertical bar
  1599. -space_12 ext ;space between left edge and operand
  1600. -
  1601. -DS_asm ext ;ds directive name
  1602. -GEQU_asm ext ;GEQU directive name
  1603. -EQU_asm ext ;EQU directive name
  1604. -hex_asm ext ;merlin hex directive
  1605. -db_asm ext ;merlin db directive
  1606. -dw_asm ext ;merlin dw directive
  1607. -adr_asm ext ;merlin adr directive
  1608. -adrl_asm ext ;merlin adrl directive
  1609. -dc_a_asm ext ;orca address directive
  1610. -dc_d_asm ext ;orca double directive
  1611. -dc_e_asm ext ;orca extended directive
  1612. -dc_f_asm ext ;orca float directive
  1613. -dc_h_asm ext ;orca hex directive
  1614. -dc_i_asm ext ;orca integer directive
  1615. -
  1616. -* boolean variables
  1617. -*
  1618. -}version ext ;display version number
  1619. -}tool ext ;interpret ToolBox, GS/OS, ProDOS, ROM calls
  1620. -}assembly ext ;dump in asm format
  1621. -}label ext ;print expressions with labels, not offsets
  1622. -}infix ext ;display expressions in infix (default for +asm)
  1623. -}postfix ext ;display expressions in postfix (default)
  1624. -}hex ext ;nonzero means dump in hex format
  1625. -}header ext ;nonzero means dump
  1626. -}noheader ext ;nonzero does not display segment headers
  1627. -}nooffset ext ;nonzero means don't print offset into file
  1628. -}help ext ;nonzero means print switch descriptions
  1629. -}shorta ext ;8-bit accumulator
  1630. -}shorti ext ;8-bit index registers
  1631. -}compress ext ;compress OMF listing
  1632. -}exact ext ;match segment, loadsegment names exactly
  1633. -}default_opt ext ;disable default options
  1634. -
  1635. -* constant variables
  1636. -*
  1637. -~assembler ext ;output code for which assembler
  1638. -~error_msg ext ;error messages
  1639. -~opcodes ext ;65816 opcodes
  1640. -~operator ext ;operator precedence
  1641. -~long_options ext ;command-line options accepted by coff
  1642. -
  1643. -* data structures
  1644. -*
  1645. -@omf ext ;OMF header structure
  1646. -@parse_data ext ;global/local data parsing structure
  1647. -@label ext ;label references
  1648. -@expr_list ext ;expression list
  1649. -@btree ext ;binary-tree structure
  1650. -@stack ext ;stack structure
  1651. -
  1652. -* gs/os data structures
  1653. -*
  1654. -@Close ext
  1655. -@GetDirEntry ext
  1656. -@GetPrefix ext
  1657. -@Open ext
  1658. -@GetMark ext
  1659. -@SetMark ext
  1660. -@Quit ext
  1661. -@Read ext
  1662. =x.general.s
  1663. -* UNIX coff utility
  1664. -* general routine externals
  1665. -*
  1666. -* 1990-1992, tao Developer Project
  1667. -
  1668. -dp_argv ext ;move @argv to dp
  1669. -error ext ;error routine
  1670. -get_progname ext ;get program name minus path string
  1671. -isprint ext ;if character is a printing character
  1672. -lowercase_hex ext ;convert uppercase hex alpha to lowercase
  1673. -name_GSOS ext ;convert GSOS call to equivalent name
  1674. -name_ROM ext ;convert ROM call to equivalent name
  1675. -name_TOOL ext ;convert TOOLBOX call to equivalent name
  1676. -print_char_dec ext ;print char value as decimal string
  1677. -print_short_dec ext ;print short value as decimal string
  1678. -print_long_dec ext ;print long value as decimal string
  1679. -print_char_sdec ext ;print signed char value as decimal string
  1680. -print_char_hex ext ;print char value as hex string
  1681. -print_short_hex ext ;print short value as hex string
  1682. -print_long_hex ext ;print long value as hex string
  1683. -print_fix_char_dec ext ;print char value as fixed decimal string
  1684. -print_fix_long_dec ext ;print long value as fixed decimal string
  1685. -print_fix_short_dec ext ;print short value as fixed decimal string
  1686. -print_fix_char_hex ext ;print char value as fixed hex string
  1687. -print_fix_long_hex ext ;print long value as fixed hex string
  1688. -print_fix_short_hex ext ;print short value as fixed hex string
  1689. -print_double ext ;print double-precision float value
  1690. -print_extended ext ;print extended-precision float value
  1691. -print_float ext ;print floating-point value
  1692. -print_offset ext ;print displacement, counter offset
  1693. -printf ext ;print formatted output
  1694. -strchr ext ;search for character in string
  1695. -strlen ext ;get length of C-string
  1696. -test_key ext ;test for pause/cancel keypress
  1697. -usage ext ;print usage string
  1698. -usage_verbose ext ;print usage-verbose string
  1699. =x.gsos.s
  1700. -* UNIX coff utility
  1701. -* GS/OS i/o external routines
  1702. -*
  1703. -* 1990-1992, tao Developer Project
  1704. -
  1705. -GSOSclose ext ;close a file
  1706. -GSOSget_mark ext ;get position in file
  1707. -GSOSopen ext ;open a file
  1708. -GSOSread ext ;read data from file
  1709. -GSOSset_mark ext ;set position in file
  1710. -GSOSset_mark_plus ext ;set relative position in file
  1711. =x.omf.s
  1712. -* UNIX coff utility
  1713. -* OMF parser externals
  1714. -*
  1715. -* 1990-1992, tao Developer Project
  1716. -
  1717. -read_header ext ;read header of OMF file
  1718. -parse_DS ext ;parse DS record
  1719. -parse_record ext ;parse OMF record
  1720. -parse_segment_hex ext ;parse segment for +hex option
  1721. -parse_segment ext ;parse OMF segment
  1722. -parse_STRONG ext ;parse STRONG record
  1723. =x.output.s
  1724. -* UNIX coff utility
  1725. -* output routine externals
  1726. -*
  1727. -* 1990-1992, tao Developer Project
  1728. -
  1729. -print_header ext ;print OMF header
  1730. -parse_kind_1 ext ;parse kind string for OMF 1.0
  1731. -parse_kind_2 ext ;parse kind string for OMF 2.0
  1732. -print_stack_postfix ext ;output postfix expression
  1733. -print_stack_infix ext ;output infix expression
  1734. -newline ext ;generate newline in expression output
  1735. -print_inorder ext ;output expression inorder
  1736. =x.structure.s
  1737. -* UNIX coff utility
  1738. -* external data structure routines
  1739. -*
  1740. -* 1990-1992, tao Developer Project
  1741. -
  1742. -add_label ext ;add label to label array
  1743. -delete_labels ext ;delete labels from label array
  1744. -delete_expr_list ext ;delete expression list stack
  1745. -find_operator ext ;match operator with its string representation
  1746. -match_label ext ;match label name with expression string
  1747. -push_expr_list ext ;push object on stack
  1748. =x.tool.s
  1749. -* UNIX coff utility
  1750. -* tool, GSOS, ROM externals
  1751. -*
  1752. -* 1990-1992, tao Developer Project
  1753. -
  1754. -~tool ext ;toolbox names
  1755. -~gsos ext ;GS/OS call names
  1756. -~rom ext ;ROM address names
  1757. =getopt.s
  1758. - lst off
  1759. -
  1760. -* UNIX getopt library utility
  1761. -*
  1762. -* 1992, tao Developer Project
  1763. -
  1764. - rel
  1765. - xc
  1766. - xc
  1767. - mx %00
  1768. -
  1769. - put 4/memory.h ;memory manager defines
  1770. - put 4/env.h ;run-time environment settings
  1771. -
  1772. - use 4/datatype.mac ;HLL data type macros
  1773. - use 4/env.mac ;run-time environment macros
  1774. - use 4/memory.mac ;memory manager macros
  1775. - use 4/utility.mac ;utility macros
  1776. - use 4/texttool.mac ;text toolset macros
  1777. -
  1778. -
  1779. -option mac
  1780. - cStr ]1 ;name of option
  1781. - Short ]2 ;if option has arguments
  1782. - ShortPtr ]3 ;flags
  1783. - Short ]4 ;value of variable if no option assigned
  1784. - eom
  1785. -
  1786. -shorta mac
  1787. - mx %10
  1788. - sep %00100000
  1789. - eom
  1790. -longa mac
  1791. - mx %00
  1792. - rep %00100000
  1793. - eom
  1794. -incr mac ;longword inc
  1795. - if 1,]0
  1796. - inc ]1
  1797. - bne end
  1798. - inc ]1+2
  1799. - else
  1800. - clc
  1801. - lda ]2
  1802. - adc ]1
  1803. - sta ]2
  1804. - bcc end
  1805. - inc ]2+2
  1806. -end fin
  1807. - eom
  1808. -
  1809. -_DebugStr mac
  1810. - pea #^]1
  1811. - pea #]1
  1812. - ldx #$09ff
  1813. - jsl $e10000
  1814. - eom
  1815. -
  1816. -OTHER_OPTION_EDGE equ 70 ;right edge to display alternate partial matches
  1817. -
  1818. -TAB_CHAR equ $09 ;tab character
  1819. -EOF equ $ffff
  1820. -UNRECOGNIZED_OPT equ '?'
  1821. -
  1822. -;option data structure offsets
  1823. -`has_arg equ $00 ;if option has arguments
  1824. -`flag equ `has_arg+2 ;pointer to variable to set
  1825. -`val equ `flag+4 ;default value of option
  1826. -`name equ `val+2 ;long name of option
  1827. -
  1828. -;argv data structure offsets
  1829. -`lo equ $00 ;handle to array of command-line
  1830. -`hi equ $04 ;options
  1831. -
  1832. -
  1833. -**************************************************
  1834. -* initialize command-line arguments. setup argc  *
  1835. -* value and argv pointers.                       *
  1836. -* ---------------------------------------------- *
  1837. -* (input)                                        *
  1838. -*  a - userID of calling program.                *
  1839. -*  x - LOW of pointer to command-line.           *
  1840. -*  y - HOW of pointer to command-line.           *
  1841. -**************************************************
  1842. -init_getopt ent
  1843. -]argv_lo = $01
  1844. -]argv_hi = ]argv_lo+4
  1845. -]argc = ]argv_hi+4
  1846. -]db = ]argc+4
  1847. -]dp = ]db+2
  1848. -]rtl = ]dp+1
  1849. -]userID = ]rtl+3
  1850. -]command_line = ]userID+2
  1851. -
  1852. - phd ;save direct page
  1853. - phb ;save data bank register
  1854. -
  1855. - sec
  1856. - tsc
  1857. - sbc #]dp-3 ;make local dp space
  1858. - tcs
  1859. - tcd
  1860. -
  1861. - phk
  1862. - plb
  1863. -
  1864. - incr #8;]command_line ;update command-line to first
  1865. - ;character in command-line
  1866. - lda #1
  1867. - sta ]argc
  1868. - ldy #0
  1869. - lda #0
  1870. -:loop shorta
  1871. - lda []command_line],y
  1872. - longa
  1873. - beq :make_argv
  1874. - cmp #' ' ;spaces and TABS separate arguments
  1875. - beq :0
  1876. - cmp #TAB_CHAR
  1877. - beq :0
  1878. - iny
  1879. - bra :loop
  1880. -:0 iny ;test next character. if it is also
  1881. - shorta ;a space or tab, then the next
  1882. - lda []command_line],y ;argument hasn't begun. keep scanning.
  1883. - longa
  1884. - beq :zero_last ;if at end of command-line, zero
  1885. - cmp #' ' ;previous space/tab
  1886. - beq :1
  1887. - cmp #TAB_CHAR
  1888. - bne :next_arg
  1889. -:zero_last dey
  1890. - shorta
  1891. - lda #0
  1892. - sta []command_line],y
  1893. - longa
  1894. - bra :make_argv
  1895. -:1 dey
  1896. - shorta
  1897. - lda #0 ;pad extra spaces with zeros
  1898. - sta []command_line],y
  1899. - iny
  1900. - sta []command_line],y
  1901. - longa
  1902. - bra :0
  1903. -:next_arg dey
  1904. - inc ]argc
  1905. - shorta
  1906. - lda #0 ;separate arguments with 0
  1907. - sta []command_line],y
  1908. - longa
  1909. - iny
  1910. - bra :loop
  1911. -
  1912. -:make_argv pha ;long - space for result
  1913. - pha
  1914. - lda ]argc ;long - size of block
  1915. - sta argc
  1916. - asl
  1917. - sta ]argc
  1918. - pea #0
  1919. - pha
  1920. - pei ]userID ;word - userID to associate with block
  1921. - pea #attrNoSpec+attrLocked
  1922. - pha
  1923. - pha
  1924. - _NewHandle
  1925. - plx
  1926. - ply
  1927. - stx ]argv_lo
  1928. - sty ]argv_lo+2
  1929. - ldy #2
  1930. - lda []argv_lo],y
  1931. - tay
  1932. - lda []argv_lo]
  1933. - sta argv+`lo
  1934. - sty argv+`lo+2
  1935. - sta ]argv_lo
  1936. - sty ]argv_lo+2
  1937. -
  1938. - pha ;long - space for result
  1939. - pha
  1940. - pea #0 ;long - size of block
  1941. - pei ]argc
  1942. - pei ]userID ;word - userID to associate with block
  1943. - pea #attrNoSpec+attrLocked
  1944. - pha
  1945. - pha
  1946. - _NewHandle
  1947. - plx
  1948. - ply
  1949. - stx ]argv_hi
  1950. - sty ]argv_hi+2
  1951. - ldy #2
  1952. - lda []argv_hi],y
  1953. - tay
  1954. - lda []argv_hi]
  1955. - sta argv+`hi
  1956. - sty argv+`hi+2
  1957. - sta ]argv_hi
  1958. - sty ]argv_hi+2
  1959. -
  1960. - ldx #0 ;argument counter
  1961. -:2 ldy #$ffff ;create pointers to command-line arguments
  1962. - lda #0
  1963. -:3 iny
  1964. - shorta
  1965. - lda []command_line],y
  1966. - longa
  1967. - bne :3
  1968. - txa
  1969. - inc ;always take last argument
  1970. - inc
  1971. - cmp ]argc
  1972. - beq :5
  1973. -:4 iny
  1974. - shorta
  1975. - lda []command_line],y
  1976. - longa
  1977. - beq :4
  1978. -:5 phy
  1979. - txy
  1980. - lda ]command_line
  1981. - sta []argv_lo],y
  1982. - lda ]command_line+2
  1983. - sta []argv_hi],y
  1984. - clc
  1985. - pla
  1986. - adc ]command_line
  1987. - sta ]command_line
  1988. - bcc :6
  1989. - inc ]command_line+2
  1990. -:6 inx
  1991. - inx
  1992. - cpx ]argc
  1993. - bne :2
  1994. -
  1995. - lda #1 ;initialize index into command-line arguments
  1996. - sta optind
  1997. - sta argind
  1998. - stz first_nonopt
  1999. - stz last_nonopt
  2000. - stz optarg
  2001. - stz optarg+2
  2002. -
  2003. - lda ]rtl,s ;move return address to top of stack
  2004. - sta ]command_line+1,s
  2005. - lda ]rtl+1,s
  2006. - sta ]command_line+2,s
  2007. -
  2008. - clc
  2009. - tsc
  2010. - adc #]dp-3
  2011. - tcs
  2012. -
  2013. - plb
  2014. - pld
  2015. -
  2016. - clc
  2017. - tsc
  2018. - adc #]command_line-]rtl+1
  2019. - tcs
  2020. - rtl
  2021. -
  2022. -
  2023. -**************************************************
  2024. -* retrieve short options from command-line.      *
  2025. -* ---------------------------------------------- *
  2026. -* (input)                                        *
  2027. -*  shortopts - C-string of options to search     *
  2028. -*              for.                              *
  2029. -* (output)                                       *
  2030. -*  a - option found.                             *
  2031. -**************************************************
  2032. -getopt ent
  2033. -
  2034. - rts
  2035. -
  2036. -
  2037. -**************************************************
  2038. -* parse argument list by scanning for short      *
  2039. -* options.                                       *
  2040. -**************************************************
  2041. -parse_argument_1 equ *
  2042. -
  2043. - rts
  2044. -
  2045. -
  2046. -**************************************************
  2047. -* retrieve long-options and short-options from   *
  2048. -* command-line.                                  *
  2049. -* ---------------------------------------------- *
  2050. -* (input)                                        *
  2051. -*  shortopts - C-string of options to search     *
  2052. -*              for.                              *
  2053. -*  longopts - pointer to long-option structure.  *
  2054. -*  longind - index into long options.            *
  2055. -* (output)                                       *
  2056. -*  a - option found.                             *
  2057. -**************************************************
  2058. -getopt_long ent
  2059. -]buffer = $01
  2060. -]argv_lo = ]buffer+4
  2061. -]argv_hi = ]argv_lo+4
  2062. -]argv = ]argv_hi+4
  2063. -]option_struct = ]argv+4
  2064. -]long_option_name = ]option_struct+4
  2065. -]db = ]long_option_name+4
  2066. -]dp = ]db+2
  2067. -]rtl = ]dp+1
  2068. -]longind = ]rtl+3
  2069. -]longopts = ]longind+4
  2070. -]shortopts = ]longopts+4
  2071. -]retValue = ]shortopts+4
  2072. -
  2073. - phd ;save direct page
  2074. - phb ;save data bank register
  2075. -
  2076. - sec
  2077. - tsc
  2078. - sbc #]dp-3 ;make local dp space
  2079. - tcs
  2080. - tcd
  2081. -
  2082. - phk
  2083. - plb
  2084. -
  2085. - lda #EOF
  2086. - sta ]retValue
  2087. -
  2088. - lda argc ;end if no arguments to parse
  2089. - cmp #1
  2090. - beq :0
  2091. -
  2092. - jsr parse_argument_2
  2093. -
  2094. -:0 lda ]rtl,s ;move return address to first
  2095. - sta ]retValue-3,s ;parameter
  2096. - lda ]rtl+1,s
  2097. - sta ]retValue-2,s
  2098. -
  2099. - clc
  2100. - tsc
  2101. - adc #]dp-3
  2102. - tcs
  2103. -
  2104. - plb
  2105. - pld
  2106. -
  2107. - clc
  2108. - tsc
  2109. - adc #]retValue-]longind
  2110. - tcs
  2111. - rtl
  2112. -
  2113. -
  2114. -**************************************************
  2115. -* parse argument list by scanning for short      *
  2116. -* and long options.                              *
  2117. -**************************************************
  2118. -parse_argument_2 equ *
  2119. -
  2120. - ldx argv+`lo
  2121. - ldy argv+`lo+2
  2122. - stx ]argv_lo
  2123. - sty ]argv_lo+2
  2124. - ldx argv+`hi
  2125. - ldy argv+`hi+2
  2126. - stx ]argv_hi
  2127. - sty ]argv_hi+2
  2128. - lda #0
  2129. - shorta
  2130. - lda []shortopts]
  2131. - sta shortopt_len
  2132. - longa
  2133. -
  2134. -:loop lda optind
  2135. - cmp argc
  2136. - blt :1
  2137. - lda first_nonopt
  2138. - beq :0
  2139. - sta optind
  2140. -:0 rts ;end, no more arguments to parse
  2141. -
  2142. -:1 asl
  2143. - tay
  2144. - lda []argv_lo],y
  2145. - sta ]argv
  2146. - lda []argv_hi],y
  2147. - sta ]argv+2
  2148. -
  2149. - lda #0
  2150. - shorta
  2151. - lda []argv]
  2152. - longa
  2153. - cmp #'-' ;parse short options
  2154. - bne :2
  2155. - jsr parse_short
  2156. - bra :4
  2157. -:2 cmp #'+' ;parse long options
  2158. - bne :3
  2159. - jsr parse_long
  2160. - bra :4
  2161. -:3 lda first_nonopt
  2162. - bne :set_last
  2163. - lda optind
  2164. - sta first_nonopt
  2165. -:set_last lda optind
  2166. - sta last_nonopt
  2167. - sec
  2168. -:4 longa
  2169. - bcc :end ;if a matching argument was found,
  2170. - inc optind ;return it, else search next argument
  2171. - lda #1
  2172. - sta argind
  2173. - bra :loop
  2174. -:end rts
  2175. -
  2176. -
  2177. -**************************************************
  2178. -* parse short options.                           *
  2179. -* ---------------------------------------------- *
  2180. -* (output)                                       *
  2181. -*  c - set if match found. clear if not.         *
  2182. -**************************************************
  2183. -parse_short equ *
  2184. -
  2185. - jsr exchange_argv ;move option before non-options
  2186. - shorta
  2187. - ldy argind
  2188. - lda []argv],y
  2189. - beq :end_argind
  2190. - ldy shortopt_len
  2191. -:test_shortopt cmp []shortopts],y
  2192. - beq :arg_found
  2193. - dey
  2194. - bne :test_shortopt
  2195. -:end_opt longa
  2196. - and #$ff
  2197. - pha ;invalid option character.
  2198. - jsr get_progname ;option not found. display error
  2199. - phy ;message and return '?' to user
  2200. - phx ;indicating unrecognized option.
  2201. - _WriteCString
  2202. - pea #^unrecognized_opt
  2203. - pea #unrecognized_opt
  2204. - _WriteCString
  2205. - pea #'-'
  2206. - _WriteChar
  2207. - _WriteChar
  2208. - pea #'''
  2209. - _WriteChar
  2210. - put_cr
  2211. - lda #UNRECOGNIZED_OPT ;return '?' to user
  2212. - sta ]retValue
  2213. - clc
  2214. - rts
  2215. -:arg_found longa ;argument found so return value
  2216. - sta ]retValue ;and prepare to parse next option
  2217. - inc argind ;character
  2218. - clc
  2219. - rts
  2220. -:end_argind longa ;at end of current option string.
  2221. - sec ;set to parse next option string
  2222. - rts
  2223. -
  2224. -
  2225. -**************************************************
  2226. -* parse long options.                            *
  2227. -**************************************************
  2228. -parse_long equ *
  2229. -
  2230. - stz :option_offset
  2231. - stz :option_found
  2232. - stz :print_partial
  2233. - stz :offset
  2234. - stz :option_name_len
  2235. - jsr exchange_argv ;move option before non-options
  2236. -
  2237. -:loop lda :option_offset
  2238. - asl
  2239. - tay
  2240. - lda []longopts],y
  2241. - sta ]option_struct
  2242. - clc
  2243. - adc #`name
  2244. - sta ]long_option_name
  2245. - shorta
  2246. - lda (]long_option_name)
  2247. - sta :option_name_len
  2248. - longa
  2249. - bne :test_longopt ;end of long-options
  2250. - brl :end
  2251. -
  2252. -:test_longopt ldy #1
  2253. - shorta
  2254. -:0 lda []argv],y
  2255. - beq :1
  2256. - cmp (]long_option_name),y
  2257. - beq :next_char
  2258. - brl :6
  2259. -:next_char iny
  2260. - cpy :option_name_len
  2261. - blt :0
  2262. - beq :0
  2263. -:1 ldy :option_found ;if first option found, test other
  2264. - bne :2 ;options for partial matches.
  2265. - ldy :option_offset ;mark first option as found
  2266. - iny
  2267. - sty :option_found
  2268. - brl :6
  2269. -:2 longa
  2270. - lda :print_partial
  2271. - beq :print_option
  2272. - brl :3
  2273. -:print_option jsr get_progname
  2274. - phy
  2275. - phx
  2276. - phy
  2277. - phx
  2278. - _WriteCString
  2279. - pea #^partial_match
  2280. - pea #partial_match
  2281. - _WriteCString
  2282. - lda optind
  2283. - asl
  2284. - tay
  2285. - lda []argv_hi],y
  2286. - pha
  2287. - lda []argv_lo],y
  2288. - pha
  2289. - _WriteCString
  2290. - pea #'''
  2291. - _WriteChar
  2292. - put_cr
  2293. - _WriteCString
  2294. - pea #^other_options
  2295. - pea #other_options
  2296. - _WriteCString
  2297. - lda :option_found
  2298. - dec
  2299. - asl
  2300. - tay
  2301. - lda []longopts],y
  2302. - clc
  2303. - adc #`name
  2304. - pei ]longopts+2
  2305. - pha
  2306. - clc
  2307. - lda #0
  2308. - tay
  2309. - shorta
  2310. - lda (1,s),y
  2311. - longa
  2312. - adc #20
  2313. - sta :offset
  2314. - _WriteString
  2315. - inc :print_partial
  2316. -:3 inc :print_partial
  2317. - clc
  2318. - lda :offset
  2319. - adc #3
  2320. - adc :option_name_len
  2321. - sta :offset
  2322. - cmp #OTHER_OPTION_EDGE
  2323. - blt :4
  2324. - pea #','
  2325. - _WriteChar
  2326. - put_cr
  2327. - jsr get_progname
  2328. - phy
  2329. - phx
  2330. - _WriteCString
  2331. - pea #':'
  2332. - _WriteChar
  2333. - pea #' '
  2334. - _WriteChar
  2335. - lda :option_name_len
  2336. - inc
  2337. - sta :offset
  2338. - bra :5
  2339. -:4 pea #','
  2340. - _WriteChar
  2341. - pea #' '
  2342. - _WriteChar
  2343. -:5 pea #'+'
  2344. - _WriteChar
  2345. - pei ]longopts+2
  2346. - pei ]long_option_name
  2347. - _WriteString
  2348. -:6 longa
  2349. - inc :option_offset
  2350. - brl :loop
  2351. -
  2352. -:end lda :option_found ;error if no options found
  2353. - beq :error
  2354. - ldx :print_partial
  2355. - bne :multiple_opt
  2356. - dec
  2357. - asl
  2358. - tay
  2359. - lda []longopts],y
  2360. - sta ]option_struct
  2361. - ldy #`val ;return short-option of default
  2362. - lda (]option_struct),y ;long-option or short-option
  2363. - sta ]retValue
  2364. - inc optind ;prepare to search next argument next
  2365. - lda #1 ;time through getopt
  2366. - sta argind
  2367. - clc
  2368. - rts
  2369. -
  2370. -:error jsr get_progname ;option not found. display error
  2371. - phy ;message and return '?' to user
  2372. - phx ;indicating unrecognized option.
  2373. - _WriteCString
  2374. - pea #^unrecognized_opt
  2375. - pea #unrecognized_opt
  2376. - _WriteCString
  2377. - lda optind
  2378. - asl
  2379. - tay
  2380. - lda []argv_hi],y
  2381. - pha
  2382. - lda []argv_lo],y
  2383. - pha
  2384. - _WriteCString
  2385. - pea #'''
  2386. - _WriteChar
  2387. -:multiple_opt put_cr
  2388. - lda #UNRECOGNIZED_OPT ;return '?' to user
  2389. - sta ]retValue
  2390. - clc
  2391. - rts
  2392. -
  2393. -:option_offset UnsignedShort ;offset into long option structure
  2394. -:option_name_len UnsignedShort ;length of long option name
  2395. -:option_found UnsignedShort ;if first option (partial?) found
  2396. -:print_partial UnsignedShort
  2397. -:offset UnsignedShort ;right edge offset
  2398. -
  2399. -
  2400. -**************************************************
  2401. -* retrieve long-options from command-line.       *
  2402. -* ---------------------------------------------- *
  2403. -* (input)                                        *
  2404. -*  shortopts - C-string of options to search     *
  2405. -*              for.                              *
  2406. -*  longopts - pointer to long-option structure.  *
  2407. -*  longind - index into long options.            *
  2408. -* (output)                                       *
  2409. -*  opt - option found.                           *
  2410. -**************************************************
  2411. -getopt_long_only ent
  2412. -]dp = $0c+3
  2413. -]rtl = ]dp+1
  2414. -]longind = ]rtl+3
  2415. -]longopts = ]longind+4
  2416. -]shortopts = ]longopts+4
  2417. -]retValue = ]shortopts+4
  2418. -
  2419. - phd ;save direct page
  2420. - phb ;save data bank register
  2421. -
  2422. - sec
  2423. - tsc
  2424. - sbc #]dp-3 ;make local dp space
  2425. - tcs
  2426. - tcd
  2427. -
  2428. - phk
  2429. - plb
  2430. - stz ]retValue
  2431. -
  2432. - lda ]rtl,s ;move return address to first
  2433. - sta ]retValue-3,s ;parameter
  2434. - lda ]rtl+1,s
  2435. - sta ]retValue-1,s
  2436. -
  2437. - clc
  2438. - tsc
  2439. - adc #]dp-3
  2440. - tcs
  2441. -
  2442. - plb
  2443. - pld
  2444. -
  2445. - clc
  2446. - tsc
  2447. - adc #]retValue-]longind
  2448. - tcs
  2449. - rts
  2450. -
  2451. -
  2452. -**************************************************
  2453. -* move non-option arguments before option        *
  2454. -* arguments.                                     *
  2455. -**************************************************
  2456. -exchange_argv equ *
  2457. -
  2458. - lda first_nonopt ;end if no exchange to take place
  2459. - beq :end
  2460. -
  2461. - lda optind ;save pointer to current option
  2462. - asl ;argument
  2463. - tay
  2464. - lda []argv_lo],y
  2465. - pha
  2466. - lda []argv_hi],y
  2467. - pha
  2468. -
  2469. -:0 lda last_nonopt ;move non-options up one
  2470. - asl
  2471. - tay
  2472. - lda []argv_lo],y
  2473. - iny
  2474. - iny
  2475. - sta []argv_lo],y
  2476. - dey
  2477. - dey
  2478. - lda []argv_hi],y
  2479. - iny
  2480. - iny
  2481. - sta []argv_hi],y
  2482. - dec last_nonopt
  2483. - lda last_nonopt
  2484. - cmp first_nonopt
  2485. - bge :0
  2486. -
  2487. - lda first_nonopt ;store current option in first
  2488. - asl ;non-option position. all previous
  2489. - tay ;non-options are now after it.
  2490. - pla
  2491. - sta []argv_hi],y
  2492. - pla
  2493. - sta []argv_lo],y
  2494. -
  2495. - lda first_nonopt
  2496. - sta optind
  2497. - stz first_nonopt
  2498. - stz last_nonopt
  2499. -:end rts
  2500. -
  2501. -
  2502. -**************************************************
  2503. -* return pointer to program name string minus    *
  2504. -* path.                                          *
  2505. -* ---------------------------------------------- *
  2506. -* (output)                                       *
  2507. -*  x - LOW of pointer to program name.           *
  2508. -*  y - HOW of pointer to program name.           *
  2509. -**************************************************
  2510. -get_progname equ *
  2511. -]progname = $01
  2512. -
  2513. - lda []argv_lo] ;first argument on command-line is
  2514. - sta ]progname ;program name
  2515. - lda []argv_hi]
  2516. - sta ]progname+2
  2517. -
  2518. - shorta
  2519. -:start_loop ldy #0
  2520. -:loop lda []progname],y
  2521. - beq :end
  2522. - cmp #'/'
  2523. - beq :separator
  2524. - cmp #':'
  2525. - beq :separator
  2526. - iny
  2527. - bra :loop
  2528. -:separator clc
  2529. - tya
  2530. - inc
  2531. - adc ]progname
  2532. - sta ]progname
  2533. - bcc :start_loop
  2534. - inc ]progname+2
  2535. - bra :start_loop
  2536. -
  2537. -:end longa
  2538. - ldx ]progname
  2539. - ldy ]progname+2
  2540. - rts
  2541. -
  2542. -
  2543. -**************************************************
  2544. -
  2545. -* For communication from 'getopt' to the caller.
  2546. -* When 'getopt' finds an option that takes an argument,
  2547. -* the argument value is returned here.
  2548. -* Also, when 'ordering' is RETURN_IN_ORDER,
  2549. -* each non-option ARGV-element is returned here.
  2550. -
  2551. -optarg ent
  2552. - CharPtr
  2553. -
  2554. -* Index in ARGV of the next element to be scanned.
  2555. -* This is used for communication to and from the caller
  2556. -* and for communication between successive calls to 'getopt'.
  2557. -*
  2558. -* On entry to 'getopt', zero means this is the first call; initialize.
  2559. -*
  2560. -* When 'getopt' returns EOF, this is the index of the first of the
  2561. -* non-option elements that the caller should itself scan.
  2562. -*
  2563. -* Otherwise, 'optind' communicates from one call to the next
  2564. -* how much of ARGV has been scanned so far.
  2565. -
  2566. -optind ent ;index into list of arguments
  2567. - UnsignedShort
  2568. -argind UnsignedShort ;index into argument
  2569. -
  2570. -* Callers store zero here to inhibit the error message 'getopt' prints
  2571. -* for unrecognized options.
  2572. -
  2573. -opterr ent
  2574. - UnsignedShort
  2575. -
  2576. -* If nonzero, '-' can introduce long-named options.
  2577. -* Set by getopt_long_only.
  2578. -
  2579. -_getopt_long_only ent
  2580. - UnsignedShort
  2581. -
  2582. -* The index in GETOPT_LONG_OPTIONS of the long-named option found.
  2583. -* Only valid when a long-named option has been found by the most
  2584. -* recent call to 'getopt'.
  2585. -
  2586. -option_index ent
  2587. - UnsignedShort
  2588. -
  2589. -argc ent ;number of command-line options
  2590. - UnsignedShort
  2591. -argv ent ;array of pointers to command-line options
  2592. -:lo Pointer
  2593. -:hi Pointer
  2594. -
  2595. -first_nonopt UnsignedShort ;index to first non-option argument
  2596. -last_nonopt UnsignedShort ;index to last non-option argument
  2597. -shortopt_len dw 0 ;number of short options
  2598. -
  2599. -Getopt str 'getopt'
  2600. -
  2601. -unrecognized_opt asc !: unrecognized option '!,00
  2602. -partial_match asc !: partial match found for option '!,00
  2603. -other_options cStr ': other options are: +'
  2604. -
  2605. -
  2606. -**************************************************
  2607. - sav 5/getopt.l
  2608. + END OF ARCHIVE
  2609.