home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / appleii.zip / apxa1.c < prev    next >
Text File  |  1988-08-16  |  16KB  |  500 lines

  1. #!/bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #!/bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create the files:
  6. #    assmtest
  7. #    assmtest.l
  8. #    makefile
  9. #    user.nr
  10. # This archive created: Tue Apr  2 14:21:42 1985
  11. # By:    James Van Ornum (AT&T-Bell Laboratories)
  12. export PATH; PATH=/bin:$PATH
  13. if test -f 'assmtest'
  14. then
  15.     echo shar: over-writing existing file "'assmtest'"
  16. fi
  17. cat << \SHAR_EOF > 'assmtest'
  18. ;******************************************
  19. ; Test file for the 6502 assembler - as6502
  20. ; assemble as
  21. ;     as6502 -nisv assmtest
  22. ; and compare output with assmtest.l
  23. ;******************************************
  24. ;; comment treatment
  25. ;******************************************
  26. aa = $10; ';' immediately after the '0'
  27. B = $20 space to comment subfield
  28. C = $30    tab to comment subfield
  29. DEFGHIjkl = $FFEE
  30. D =DEFGHIjkl
  31. ;******************************************
  32. ; Number formats
  33. ;******************************************
  34. start *= $4 ; location counter adjust
  35.  .byte %0101 ; binary number
  36.  .byte 022,@22 ; octal numbers - two forms
  37.  .byte 22 ; decimal number
  38.  .byte $22,$ff,$FF ; hex - upper/lower case
  39.  .byte 'a,'b ; single ASCII characters
  40. ;******************************************
  41. ;; ASCII character string
  42. ;******************************************
  43.  .byte "abcd\t\n",0 ;   tab and new line escaped
  44. ;******************************************
  45. ; Operation checks
  46. ;******************************************
  47.  .word aa+B ; addition
  48.  .word aa-B ; subtraction
  49.  .word aa*B ; multiplication
  50.  .word B/aa ; division
  51.  .word C%B ; modulo
  52.  .word B^C ; exclusive OR
  53.  .word ~C ; one's complement
  54.  .word B&C ; logical AND
  55.  .word aa|B ; logical OR
  56.  .word <D ; high byte
  57.  .word >D ; low byte
  58.  .word * ; current location
  59.  .word aa,B,C
  60.  .word B*[aa+C] ; one level of parenthesis
  61.  .dbyt D ; high byte-low byte word
  62.  .word D/256,D%256
  63. ;******************************************
  64. ; Addressing Mode Check
  65. ;******************************************
  66.  *=$0100
  67.  lda =aa ; immediate addressing
  68.  lda #aa ; immediate addressing, alternate
  69.  lda D ; direct addessing
  70.  LDA aa ; page zero addressing, aa < 256
  71. a1 = 512
  72. a2 = 500
  73.  lda a1-a2 ; also page zero
  74.  asl A ; accumulator addressing
  75.  AsL a ; accumulator addressing also
  76.  brk ; implied addressing
  77.  lda (aa,X) ; indirect,X addressing
  78.  lda (aa),Y ; indirect,Y addressing
  79.  lda aa,X ; zero page,X addressing
  80.  lda D,X ; absolute,X addressing
  81.  lda D,Y ; absolute,Y addressing
  82.  bcc *-$10 ; relative addressing
  83.  jmp (D) ; indirect addressing
  84.  ldx aa,Y ; zero page,Y addressing
  85.  ldx aa,y ; alternate index name
  86.  .nlst
  87. ;******************************************
  88. ; opcode check
  89. ;******************************************
  90.  adc =01
  91.  and =01
  92.  asl A
  93.  bcc *+2
  94.  bcs *+2
  95.  beq *+2
  96.  bit $01
  97.  bmi *+2
  98.  bne *+2
  99.  bpl *+2
  100.  brk
  101.  bvc *+2
  102.  bvs *+2
  103.  clc
  104.  cld
  105.  cli
  106.  clv
  107.  cmp =01
  108.  cpx =01
  109.  cpy =01
  110.  dec $01
  111.  dex
  112.  dey
  113.  eor =01
  114.  inc $01
  115.  inx
  116.  iny
  117.  jmp *+3
  118.  jsr *+3
  119.  lda =01
  120.  ldx =01
  121.  ldy =01
  122.  lsr A
  123.  nop
  124.  ora =01
  125.  pha
  126.  php
  127.  pla
  128.  plp
  129.  rol A
  130.  ror A
  131.  rti
  132.  rts
  133.  sbc =01
  134.  sec
  135.  sed
  136.  sei
  137.  sta $01
  138.  stx $01
  139.  sty $01
  140.  tax
  141.  tay
  142.  tsx
  143.  txa
  144.  txs
  145.  tya
  146. SHAR_EOF
  147. if test -f 'assmtest.l'
  148. then
  149.     echo shar: over-writing existing file "'assmtest.l'"
  150. fi
  151. cat << \SHAR_EOF > 'assmtest.l'
  152. as6502 - version 4.1b - 11/22/84 - JHV [gvw]
  153.    1                   ;******************************************
  154.    2                   ; Test file for the 6502 assembler - as6502
  155.    3                   ; assemble as
  156.    4                   ;     as6502 -nisv assmtest
  157.    5                   ; and compare output with assmtest.l
  158.    6                   ;******************************************
  159.    7                   ;                      ; comment treatment
  160.    8                   ;******************************************
  161.    9         0010      aa      =     $10      ; ';' immediately after the '0'
  162.   10         0020      B       =     $20      space to comment subfield
  163.   11         0030      C       =     $30      tab to comment subfield
  164.   12         FFEE      DEFGHIjkl =   $FFEE
  165.   13         FFEE      D       =DEFGHIjkl
  166.   14                   ;******************************************
  167.   15                   ; Number formats
  168.   16                   ;******************************************
  169.   17         0004      start   *=    $4        ; location counter adjust
  170.   18  0004   05                .byte %0101     ; binary number
  171.   19  0005   12 12             .byte 022,@22   ; octal numbers - two forms
  172.   20  0007   16                .byte 22        ; decimal number
  173.   21  0008   22 FF FF          .byte $22,$ff,$FF  ; hex - upper/lower case
  174.   22  000B   61 62             .byte 'a,'b     ; single ASCII characters
  175.   23                   ;******************************************
  176.   24                   ;                      ; ASCII character string
  177.   25                   ;******************************************
  178.   26  000D   61 62 63          .byte "abcd\t\n",0  ;   tab and new line escaped
  179.       0010   64 09 0A  
  180.       0013   00        
  181.   27                   ;******************************************
  182.   28                   ; Operation checks
  183.   29                   ;******************************************
  184.   30  0014   30 00             .word aa+B      ; addition
  185.   31  0016   F0 FF             .word aa-B      ; subtraction
  186.   32  0018   00 02             .word aa*B      ; multiplication
  187.   33  001A   02 00             .word B/aa      ; division
  188.   34  001C   10 00             .word C%B       ; modulo
  189.   35  001E   10 00             .word B^C       ; exclusive OR
  190.   36  0020   CF FF             .word ~C        ; one's complement
  191.   37  0022   20 00             .word B&C       ; logical AND
  192.   38  0024   30 00             .word aa|B      ; logical OR
  193.   39  0026   FF 00             .word <D        ; high byte
  194.   40  0028   EE 00             .word >D        ; low byte
  195.   41  002A   2A 00             .word *         ; current location
  196.   42  002C   10 00             .word aa,B,C
  197.       002E   20 00     
  198.       0030   30 00     
  199.   43  0032   00 08             .word B*[aa+C]  ; one level of parenthesis
  200.   44  0034   FF EE             .dbyt D         ; high byte-low byte word
  201.   45  0036   FF 00             .word D/256,D%256
  202.       0038   EE 00     
  203.   46                   ;******************************************
  204.   47                   ; Addressing Mode Check
  205.   48                   ;******************************************
  206.   49         0100              *=$0100
  207.   50  0100   A9 10             lda   =aa       ; immediate addressing
  208.   51  0102   A9 10             lda   #aa       ; immediate addressing, alternate
  209.   52  0104   AD EE FF          lda   D         ; direct addessing
  210.   53  0107   A5 10             LDA   aa        ; page zero addressing, aa < 256
  211.   54         0200      a1      =     512
  212.   55         01F4      a2      =     500
  213.   56  0109   A5 0C             lda   a1-a2     ; also page zero
  214.   57  010B   0A                asl   A         ; accumulator addressing
  215.   58  010C   0A                AsL   a         ; accumulator addressing also
  216.   59  010D   00                brk            ; implied addressing
  217.   60  010E   A1 10             lda   (aa,X)    ; indirect,X addressing
  218.   61  0110   B1 10             lda   (aa),Y    ; indirect,Y addressing
  219.   62  0112   B5 10             lda   aa,X      ; zero page,X addressing
  220.   63  0114   BD EE FF          lda   D,X       ; absolute,X addressing
  221.   64  0117   B9 EE FF          lda   D,Y       ; absolute,Y addressing
  222.   65  011A   90 EE             bcc   *-$10     ; relative addressing
  223.   66  011C   6C EE FF          jmp   (D)       ; indirect addressing
  224.   67  011F   B6 10             ldx   aa,Y      ; zero page,Y addressing
  225.   68  0121   B6 10             ldx   aa,y      ; alternate index name
  226.   70                   ;******************************************
  227.   71                   ; opcode check
  228.   72                   ;******************************************
  229.   73  0123   69 01             adc   =01
  230.   74  0125   29 01             and   =01
  231.   75  0127   0A                asl   A
  232.   76  0128   90 00             bcc   *+2
  233.   77  012A   B0 00             bcs   *+2
  234.   78  012C   F0 00             beq   *+2
  235.   79  012E   24 01             bit   $01
  236.   80  0130   30 00             bmi   *+2
  237.   81  0132   D0 00             bne   *+2
  238.   82  0134   10 00             bpl   *+2
  239.   83  0136   00                brk
  240.   84  0137   50 00             bvc   *+2
  241.   85  0139   70 00             bvs   *+2
  242.   86  013B   18                clc
  243.   87  013C   D8                cld
  244.   88  013D   58                cli
  245.   89  013E   B8                clv
  246.   90  013F   C9 01             cmp   =01
  247.   91  0141   E0 01             cpx   =01
  248.   92  0143   C0 01             cpy   =01
  249.   93  0145   C6 01             dec   $01
  250.   94  0147   CA                dex
  251.   95  0148   88                dey
  252.   96  0149   49 01             eor   =01
  253.   97  014B   E6 01             inc   $01
  254.   98  014D   E8                inx
  255.   99  014E   C8                iny
  256.  100  014F   4C 52 01          jmp   *+3
  257.  101  0152   20 55 01          jsr   *+3
  258.  102  0155   A9 01             lda   =01
  259.  103  0157   A2 01             ldx   =01
  260.  104  0159   A0 01             ldy   =01
  261.  105  015B   4A                lsr   A
  262.  106  015C   EA                nop
  263.  107  015D   09 01             ora   =01
  264.  108  015F   48                pha
  265.  109  0160   08                php
  266.  110  0161   68                pla
  267.  111  0162   28                plp
  268.  112  0163   2A                rol   A
  269.  113  0164   6A                ror   A
  270.  114  0165   40                rti
  271.  115  0166   60                rts
  272.  116  0167   E9 01             sbc   =01
  273.  117  0169   38                sec
  274.  118  016A   F8                sed
  275.  119  016B   78                sei
  276.  120  016C   85 01             sta   $01
  277.  121  016E   86 01             stx   $01
  278.  122  0170   84 01             sty   $01
  279.  123  0172   AA                tax
  280.  124  0173   A8                tay
  281.  125  0174   BA                tsx
  282.  126  0175   8A                txa
  283.  127  0176   9A                txs
  284.  128  0177   98                tya
  285.  
  286. aa                      10:00    0010
  287. B                       20:00    0020
  288. C                       30:00    0030
  289. DEFGHIjkl               EE:FF    FFEE
  290. D                       EE:FF    FFEE
  291. start                   04:00    0004
  292. a1                      00:02    0200
  293. a2                      F4:01    01F4
  294. SHAR_EOF
  295. if test -f 'makefile'
  296. then
  297.     echo shar: over-writing existing file "'makefile'"
  298. fi
  299. cat << \SHAR_EOF > 'makefile'
  300. as6502:        assm0.o assm1.o assm2.o assm3.o
  301.         cc -s  assm0.o assm1.o assm2.o assm3.o -o as6502
  302.  
  303. assm0.o:    assm.d1 assm.d2 assm0.c
  304.         cc -c -O assm0.c
  305.  
  306. assm1.o:    assm.d1 assm.d2 assm1.c
  307.         cc -c -O assm1.c
  308.  
  309. assm2.o:    assm.d1 assm.d2    assm2.c
  310.         cc -c -O assm2.c
  311.  
  312. assm3.o:    assm.d1 assm.d2 assm3.c
  313.         cc -c -O assm3.c
  314.  
  315. check:        assmtest.l
  316.  
  317. assmtest.l:    as6502
  318.         as6502 -nisv assmtest > temp
  319.         touch assmtest.l
  320.         diff assmtest.l temp
  321.  
  322. manuals:    as6502.l user.l
  323.  
  324. as6502.l:    as6502.1
  325.         nroff -man as6502.1 > as6502.l
  326.  
  327. user.l:        user.nr
  328.         nroff user.nr > user.l
  329.  
  330. clean:
  331.         rm assm0.o assm1.o assm2.o assm3.o temp as6502.l user.l
  332. SHAR_EOF
  333. if test -f 'user.nr'
  334. then
  335.     echo shar: over-writing existing file "'user.nr'"
  336. fi
  337. cat << \SHAR_EOF > 'user.nr'
  338. .de hd
  339. 'sp 3
  340. .tl ''\fBas6502 User Notes\fR'Page %'
  341. 'sp 2
  342. ..
  343. .de fo
  344. 'bp
  345. ..
  346. .wh 0 hd
  347. .wh -3 fo
  348. .br
  349. \fBSOURCE LINE FORMAT\fR:
  350. .ti 0.5i
  351. .sp 1
  352. <label> <operation> <operand> <comment>
  353. .sp 1
  354. Each field is terminated by one or more spaces, a tab or a ';' (which
  355. begins the comment field immediately).
  356. .sp
  357. \fBLABEL FIELD\fR:
  358. .sp 1
  359. If first character is ';', entire line is a comment.
  360. If first character is space, label field is null.
  361. Labels are alphanumeric strings beginning
  362. with 'a' through 'z', 'A' through 'Z',
  363. underscore or period followed by any of the above
  364. characters or '0' through '9'.
  365. Currently, labels are limited to 19 characters.
  366. A, X, Y, a, x and y are reserved labels.
  367. .sp
  368. \fBOPERATION FIELD\fR:
  369. .sp 1
  370. Upper and lower case letters are equivalent.
  371. Machine operation mnemonics are:
  372. .in 0.5i
  373. .nf
  374. .sp 1
  375. ADC     BMI     CLD     DEX     JSR     PHA     RTS     STY
  376. AND     BNE     CLI     DEY     LDA     PHP     SBC     TAX
  377. ASL     BPL     CLV     EOR     LDX     PLA     SEC     TAY
  378. BCC     BRK     CMP     INC     LDY     PLP     SED     TSX
  379. BCS     BVC     CPX     INX     LSR     ROL     SEI     TXA
  380. BEQ     BVS     CPY     INY     NOP     ROR     STA     TXS
  381. BIT     CLC     DEC     JMP     ORA     RTI     STX     TYA
  382. .in 0
  383. .fi
  384. .sp 1
  385. Pseudo operation mnemonics are:
  386. .in 1.2i
  387. .ti 0.5i
  388. .sp 1
  389. =      equate label name to operand field value
  390. (space is not needed to terminate this operation).
  391. .ti 0.5i
  392. *=     set location counter to operand field value
  393. (space is not needed to terminate this operation).
  394. .ti 0.5i
  395. .tr*.
  396. *WORD  assign 16 bit value of operand field to next
  397. two locations; low byte of value first, then high byte.
  398. .ti 0.5i
  399. *DBYT  assign 16 bit value of operand field to next
  400. two locations; high byte of value first, then low byte.
  401. .ti 0.5i
  402. *BYTE  assign 8 bit value of operand field to next
  403. location.
  404. .ti 0.5i
  405. *NLST  turn listing mode off (this source
  406. line is not listed).
  407. .ti 0.5i
  408. *LIST  turn listing mode on (normal mode) (this
  409. source line is not listed).
  410. .tr**
  411. .in 0
  412. .sp 1
  413. \fBOPERAND FIELD\fR:
  414. .sp 1
  415. Operand field expressions use infix notation and are evaluated strictly
  416. from left to right.
  417. No imbedded spaces are permitted.
  418. .sp 1
  419. Operand field terms include labels and numbers.
  420. Asterisk (*) is the label for the location counter value.
  421. Numbers are binary, octal, decimal, hexadecimal or ASCII.
  422. Number type is indicated by the first character of the number string as follows:
  423. .nf
  424. .in 0.5i
  425. .sp 1
  426. %       binary prefix
  427. @ or 0  octal prefix
  428. 1 - 9   decimal by default (prefix is part of number)
  429. $       hexadecimal prefix
  430. .tr,'
  431. ,       ASCII character prefix
  432. .tr,,
  433. "       ASCII character string prefix and suffix; in the
  434.         string, \\t is a tab character, \\n is a new line.
  435. .in 0
  436. .fi
  437. .sp 1
  438. Operand field operations and the corresponding symbols are:
  439. .in 0.5i
  440. .nf
  441. .sp 1
  442. +       addition
  443. -       subtraction
  444. /       division
  445. *       multiplication
  446. %       modulo (remainder after integer division)
  447. ^       logical exclusive OR
  448. &       logical AND
  449. |       logical OR
  450. <       low byte
  451. >       high byte
  452. .in 0
  453. .fi
  454. .sp 1
  455. \fBERROR MESSAGES\fR:
  456. .in 0.5i
  457. .nf
  458. .sp 1
  459. Invalid operation code
  460. Invalid argument count (when as6502 was invoked)
  461. Open error for file
  462. Creat error for object file 6502.out
  463. Close error
  464. Close error (6502.out)
  465. Symbol table full
  466. Label multiply defined
  467. Sync error (pass 1 symbol value not equal pass 2 symbol value)
  468. Invalid branch address
  469. Operand field missing
  470. Invalid addressing mode
  471. Operand field size error
  472. Undefined symbol in operand field
  473. Invalid operand field
  474. .fi
  475. .in 0
  476. .sp 1
  477. \fBINVOKING as6502\fR:
  478. .sp 1
  479. .ti 0.5i
  480. as6502 {-ilnos} <source files descriptions>
  481. .sp 1
  482. Options:
  483. .in 0.5i
  484. .nf
  485. .sp 1
  486. -i   ignore any .nlst pseudo operations
  487. -l   list errors only
  488. -n   print addresses as <high byte><low byte>,
  489.      rather than as <low byte>:<high byte>.
  490. -o   generate ASCII object output in file 6502.out,
  491.      format is
  492.           ;<address lo><address hi><data>
  493. -s   print symbol table at end of listing
  494. -v   print assembler version
  495.  
  496.                      J. H. Van Ornum  11/5/84
  497. SHAR_EOF
  498. #    End of shell archive
  499. exit 0
  500.