I now have it assembled and running with my assembler Pasm
Code:
https://github.com/pebmeister/Pasm
Code:
Processing sweet16.asm
;***********************
;* *
;* APPLE-II PSEUDO *
;* MACHINE INTERPRETER *
;* *
;* COPYRIGHT 1977 *
;* APPLE COMPUTER INC *
;* *
;* ALL RIGHTS RESERVED *
;* S. WOZNIAK *
;* *
;***********************
; TITLE "SWEET16 INTERPRETER"
R0L .EQU $0
R0H .EQU $1
R14H .EQU $1D
R15L .EQU $1E
R15H .EQU $1F
SW16PAG .EQU >SET ; $F7
.ORG $F689
$F689: $20 $FD $F7 jsr $F7FD SW16 JSR SAVE ;PRESERVE 6502 REG CONTENTS
$F68C: $68 pla PLA
$F68D: $85 $1E sta $1E STA R15L ;INIT SWEET16 PC
$F68F: $68 pla PLA ;FROM RETURN
$F690: $85 $1F sta $1F STA R15H ; ADDRESS
$F692: $20 $98 $F6 jsr $F698 SW16B JSR SW16C ;INTERPRET AND EXECUTE
$F695: $4C $92 $F6 jmp $F692 JMP SW16B ;ONE SWEET16 INSTR.
$F698: $E6 $1E inc $1E SW16C INC R15L
$F69A: $D0 $02 bne $F69E BNE SW16D ;INCR SWEET16 PC FOR FETCH
$F69C: $E6 $1F inc $1F INC R15H
$F69E: $A9 $F7 lda #$F7 SW16D LDA #SW16PAG
$F6A0: $48 pha PHA ;PUSH ON STACK FOR RTS
$F6A1: $A0 $00 ldy #$00 LDY #$0
$F6A3: $B1 $1E lda ($1E),y LDA (R15L),Y ;FETCH INSTR
$F6A5: $29 $0F and #$0F AND #$F ;MASK REG SPECIFICATION
$F6A7: $0A asl ASL ;DOUBLE FOR TWO BYTE REGISTERS
$F6A8: $AA tax TAX ;TO X REG FOR INDEXING
$F6A9: $4A lsr LSR
$F6AA: $51 $1E eor ($1E),y EOR (R15L),Y ;NOW HAVE OPCODE
$F6AC: $F0 $0B beq $F6B9 BEQ TOBR ;IF ZERO THEN NON-REG OP
$F6AE: $86 $1D stx $1D STX R14H ;INDICATE'PRIOR RESULT REG'
$F6B0: $4A lsr LSR
$F6B1: $4A lsr LSR ;OPCODE*2 TO LSB'S
$F6B2: $4A lsr LSR
$F6B3: $A8 tay TAY ;TO Y REG FOR INDEXING
$F6B4: $B9 $E1 $F6 lda $F6E1,y LDA OPTBL-2,Y ;LOW ORDER ADR BYTE
$F6B7: $48 pha PHA ;ONTO STACK
$F6B8: $60 rts RTS ;GOTO REG-OP ROUTINE
$F6B9: $E6 $1E inc $1E TOBR INC R15L
$F6BB: $D0 $02 bne $F6BF BNE TOBR2 ;INCR PC
$F6BD: $E6 $1F inc $1F INC R15H
$F6BF: $BD $E4 $F6 lda $F6E4,x TOBR2 LDA BRTBL,X ;LOW ORDER ADR BYTE
$F6C2: $48 pha PHA ;ONTO STACK FOR NON-REG OP
$F6C3: $A5 $1D lda $1D LDA R14H ;'PRIOR RESULT REG' INDEX
$F6C5: $4A lsr LSR ;PREPARE CARRY FOR BC, BNC.
$F6C6: $60 rts RTS ;GOTO NON-REG OP ROUTINE
$F6C7: $68 pla RTNZ PLA ;POP RETURN ADDRESS
$F6C8: $68 pla PLA
$F6C9: $20 $08 $F8 jsr $F808 JSR RESTORE ;RESTORE 6502 REG CONTENTS
$F6CC: $6C $1E $00 jmp ($001E) JMP (R15L) ;RETURN TO 6502 CODE VIA PC
$F6CF: $B1 $1E lda ($1E),y SETZ LDA (R15L),Y ;HIGH-ORDER BYTE OF CONSTANT
$F6D1: $95 $01 sta $01,x STA R0H,X
$F6D3: $88 dey DEY
$F6D4: $B1 $1E lda ($1E),y LDA (R15L),Y ;LOW-ORDER BYTE OF CONSTANT
$F6D6: $95 $00 sta $00,x STA R0L,X
$F6D8: $98 tya TYA ;Y-REG CONTAINS 1
$F6D9: $38 sec SEC
$F6DA: $65 $1E adc $1E ADC R15L ;ADD 2 TO PC
$F6DC: $85 $1E sta $1E STA R15L
$F6DE: $90 $02 bcc $F6E2 BCC SET2
$F6E0: $E6 $1F inc $1F INC R15H
$F6E2: $60 rts SET2 RTS
OPTBL .BYTE SET-1 ;1X
BRTBL .BYTE RTN-1 ;0
.BYTE LD-1 ;2X
.BYTE BR-1 ;1
.BYTE ST-1 ;3X
.BYTE BNC-1 ;2
.BYTE LDAT-1 ;4X
.BYTE BC-1 ;3
.BYTE STAT-1 ;5X
.BYTE BP-1 ;4
.BYTE LDDAT-1 ;6X
.BYTE BM-1 ;5
.BYTE STDAT-1 ;7X
.BYTE BZ-1 ;6
.BYTE POP-1 ;8X
.BYTE BNZ-1 ;7
.BYTE STPAT-1 ;9X
.BYTE BM1-1 ;8
.BYTE ADD-1 ;AX
.BYTE BNM1-1 ;9
.BYTE SUB-1 ;BX
.BYTE BK-1 ;A
.BYTE POPD-1 ;CX
.BYTE RS-1 ;B
.BYTE CPR-1 ;DX
.BYTE BS-1 ;C
.BYTE INR-1 ;EX
.BYTE NUL-1 ;D
.BYTE DCR-1 ;FX
.BYTE NUL-1 ;E
.BYTE NUL-1 ;UNUSED
.BYTE NUL-1 ;F
$F703: $10 $CA bpl $F6CF SET BPL SETZ ;ALWAYS TAKEN
$F705: $B5 $00 lda $00,x LD LDA R0L,X
BK .EQU *-1
$F707: $85 $00 sta $00 STA R0L
$F709: $B5 $01 lda $01,x LDA R0H,X ;MOVE RX TO R0
$F70B: $85 $01 sta $01 STA R0H
$F70D: $60 rts RTS
$F70E: $A5 $00 lda $00 ST LDA R0L
$F710: $95 $00 sta $00,x STA R0L,X ;MOVE R0 TO RX
$F712: $A5 $01 lda $01 LDA R0H
$F714: $95 $01 sta $01,x STA R0H,X
$F716: $60 rts RTS
$F717: $A5 $00 lda $00 STAT LDA R0L
$F719: $81 $00 sta ($00,x) STAT2 STA (R0L,X) ;STORE BYTE INDIRECT
$F71B: $A0 $00 ldy #$00 LDY #$0
$F71D: $84 $1D sty $1D STAT3 STY R14H ;INDICATE R0 IS RESULT NEG
$F71F: $F6 $00 inc $00,x INR INC R0L,X
$F721: $D0 $02 bne $F725 BNE INR2 ;INCR RX
$F723: $F6 $01 inc $01,x INC R0H,X
$F725: $60 rts INR2 RTS
$F726: $A1 $00 lda ($00,x) LDAT LDA (R0L,X) ;LOAD INDIRECT (RX)
$F728: $85 $00 sta $00 STA R0L ;TO R0
$F72A: $A0 $00 ldy #$00 LDY #$0
$F72C: $84 $01 sty $01 STY R0H ;ZERO HIGH-ORDER R0 BYTE
$F72E: $F0 $ED beq $F71D BEQ STAT3 ;ALWAYS TAKEN
$F730: $A0 $00 ldy #$00 POP LDY #$0 ;HIGH ORDER BYTE = 0
$F732: $F0 $06 beq $F73A BEQ POP2 ;ALWAYS TAKEN
$F734: $20 $66 $F7 jsr $F766 POPD JSR DCR ;DECR RX
$F737: $A1 $00 lda ($00,x) LDA (R0L,X) ;POP HIGH ORDER BYTE @RX
$F739: $A8 tay TAY ;SAVE IN Y-REG
$F73A: $20 $66 $F7 jsr $F766 POP2 JSR DCR ;DECR RX
$F73D: $A1 $00 lda ($00,x) LDA (R0L,X) ;LOW-ORDER BYTE
$F73F: $85 $00 sta $00 STA R0L ;TO R0
$F741: $84 $01 sty $01 STY R0H
$F743: $A0 $00 ldy #$00 POP3 LDY #$0 ;INDICATE R0 AS LAST RESULT REG
$F745: $84 $1D sty $1D STY R14H
$F747: $60 rts RTS
$F748: $20 $26 $F7 jsr $F726 LDDAT JSR LDAT ;LOW-ORDER BYTE TO R0, INCR RX
$F74B: $A1 $00 lda ($00,x) LDA (R0L,X) ;HIGH-ORDER BYTE TO R0
$F74D: $85 $01 sta $01 STA R0H
$F74F: $4C $1F $F7 jmp $F71F JMP INR ;INCR RX
$F752: $20 $17 $F7 jsr $F717 STDAT JSR STAT ;STORE INDIRECT LOW-ORDER
$F755: $A5 $01 lda $01 LDA R0H ;BYTE AND INCR RX. THEN
$F757: $81 $00 sta ($00,x) STA (R0L,X) ;STORE HIGH-ORDER BYTE.
$F759: $4C $1F $F7 jmp $F71F JMP INR ;INCR RX AND RETURN
$F75C: $20 $66 $F7 jsr $F766 STPAT JSR DCR ;DECR RX
$F75F: $A5 $00 lda $00 LDA R0L
$F761: $81 $00 sta ($00,x) STA (R0L,X) ;STORE R0 LOW BYTE @RX
$F763: $4C $43 $F7 jmp $F743 JMP POP3 ;INDICATE R0 AS LAST RSLT REG
$F766: $B5 $00 lda $00,x DCR LDA R0L,X
$F768: $D0 $02 bne $F76C BNE DCR2 ;DECR RX
$F76A: $D6 $01 dec $01,x DEC R0H,X
$F76C: $D6 $00 dec $00,x DCR2 DEC R0L,X
$F76E: $60 rts RTS
$F76F: $A0 $00 ldy #$00 SUB LDY #$0 ;RESULT TO R0
$F771: $38 sec CPR SEC ;NOTE Y-REG = 13*2 FOR CPR
$F772: $A5 $00 lda $00 LDA R0L
$F774: $F5 $00 sbc $00,x SBC R0L,X
$F776: $99 $00 $00 sta $0000,y STA R0L,Y ;R0-RX TO RY
$F779: $A5 $01 lda $01 LDA R0H
$F77B: $F5 $01 sbc $01,x SBC R0H,X
$F77D: $99 $01 $00 sta $0001,y SUB2 STA R0H,Y
$F780: $98 tya TYA ;LAST RESULT REG*2
$F781: $69 $00 adc #$00 ADC #$0 ;CARRY TO LSB
$F783: $85 $1D sta $1D STA R14H
$F785: $60 rts RTS
$F786: $A5 $00 lda $00 ADD LDA R0L
$F788: $75 $00 adc $00,x ADC R0L,X
$F78A: $85 $00 sta $00 STA R0L ;R0+RX TO R0
$F78C: $A5 $01 lda $01 LDA R0H
$F78E: $75 $01 adc $01,x ADC R0H,X
$F790: $A0 $00 ldy #$00 LDY #$0 ;R0 FOR RESULT
$F792: $F0 $E9 beq $F77D BEQ SUB2 ;FINISH ADD
$F794: $A5 $1E lda $1E BS LDA R15L ;NOTE X-REG IS 12*2!
$F796: $20 $19 $F7 jsr $F719 JSR STAT2 ;PUSH LOW PC BYTE VIA R12
$F799: $A5 $1F lda $1F LDA R15H
$F79B: $20 $19 $F7 jsr $F719 JSR STAT2 ;PUSH HIGH-ORDER PC BYTE
$F79E: $18 clc BR CLC
$F79F: $B0 $0E bcs $F7AF BNC BCS BNC2 ;NO CARRY TEST
$F7A1: $B1 $1E lda ($1E),y BR1 LDA (R15L),Y ;DISPLACEMENT BYTE
$F7A3: $10 $01 bpl $F7A6 BPL BR2
$F7A5: $88 dey DEY
$F7A6: $65 $1E adc $1E BR2 ADC R15L ;ADD TO PC
$F7A8: $85 $1E sta $1E STA R15L
$F7AA: $98 tya TYA
$F7AB: $65 $1F adc $1F ADC R15H
$F7AD: $85 $1F sta $1F STA R15H
$F7AF: $60 rts BNC2 RTS
$F7B0: $B0 $EC bcs $F79E BC BCS BR
$F7B2: $60 rts RTS
$F7B3: $0A asl BP ASL ;DOUBLE RESULT-REG INDEX
$F7B4: $AA tax TAX ;TO X REG FOR INDEXING
$F7B5: $B5 $01 lda $01,x LDA R0H,X ;TEST FOR PLUS
$F7B7: $10 $E8 bpl $F7A1 BPL BR1 ;BRANCH IF SO
$F7B9: $60 rts RTS
$F7BA: $0A asl BM ASL ;DOUBLE RESULT-REG INDEX
$F7BB: $AA tax TAX
$F7BC: $B5 $01 lda $01,x LDA R0H,X ;TEST FOR MINUS
$F7BE: $30 $E1 bmi $F7A1 BMI BR1
$F7C0: $60 rts RTS
$F7C1: $0A asl BZ ASL ;DOUBLE RESULT-REG INDEX
$F7C2: $AA tax TAX
$F7C3: $B5 $00 lda $00,x LDA R0L,X ;TEST FOR ZERO
$F7C5: $15 $01 ora $01,x ORA R0H,X ;(BOTH BYTES)
$F7C7: $F0 $D8 beq $F7A1 BEQ BR1 ;BRANCH IF SO
$F7C9: $60 rts RTS
$F7CA: $0A asl BNZ ASL ;DOUBLE RESULT-REG INDEX
$F7CB: $AA tax TAX
$F7CC: $B5 $00 lda $00,x LDA R0L,X ;TEST FOR NON-ZERO
$F7CE: $15 $01 ora $01,x ORA R0H,X ;(BOTH BYTES)
$F7D0: $D0 $CF bne $F7A1 BNE BR1 ;BRANCH IF SO
$F7D2: $60 rts RTS
$F7D3: $0A asl BM1 ASL ;DOUBLE RESULT-REG INDEX
$F7D4: $AA tax TAX
$F7D5: $B5 $00 lda $00,x LDA R0L,X ;CHECK BOTH BYTES
$F7D7: $35 $01 and $01,x AND R0H,X ;FOR $FF (MINUS 1)
$F7D9: $49 $FF eor #$FF EOR #$FF
$F7DB: $F0 $C4 beq $F7A1 BEQ BR1 ;BRANCH IF SO
$F7DD: $60 rts RTS
$F7DE: $0A asl BNM1 ASL ;DOUBLE RESULT-REG INDEX
$F7DF: $AA tax TAX
$F7E0: $B5 $00 lda $00,x LDA R0L,X
$F7E2: $35 $01 and $01,x AND R0H,X ;CHECK BOTH BYTES FOR NO $FF
$F7E4: $49 $FF eor #$FF EOR #$FF
$F7E6: $D0 $B9 bne $F7A1 BNE BR1 ;BRANCH IF NOT MINUS 1
$F7E8: $60 rts NUL RTS
$F7E9: $A2 $18 ldx #$18 RS LDX #$18 ;12*2 FOR R12 AS STACK POINTER
$F7EB: $20 $66 $F7 jsr $F766 JSR DCR ;DECR STACK POINTER
$F7EE: $A1 $00 lda ($00,x) LDA (R0L,X) ;POP HIGH RETURN ADDRESS TO PC
$F7F0: $85 $1F sta $1F STA R15H
$F7F2: $20 $66 $F7 jsr $F766 JSR DCR ;SAME FOR LOW-ORDER BYTE
$F7F5: $A1 $00 lda ($00,x) LDA (R0L,X)
$F7F7: $85 $1E sta $1E STA R15L
$F7F9: $60 rts RTS
$F7FA: $4C $C7 $F6 jmp $F6C7 RTN JMP RTNZ
;*
;* SAVE/RESTORE ROUTINES
;* FOR NON APPLE-II SYSTEMS
;*
ASAVE .EQU $45
XSAVE .EQU $46
YSAVE .EQU $47
PSAVE .EQU $48
SAVE
$F7FD: $85 $45 sta $45 STA ASAVE
$F7FF: $86 $46 stx $46 STX XSAVE ;SAVE 6502 CONTENTS *
$F801: $84 $47 sty $47 STY YSAVE
$F803: $08 php PHP
$F804: $68 pla PLA
$F805: $85 $48 sta $48 STA PSAVE
$F807: $60 rts RTS
RESTORE
$F808: $A5 $48 lda $48 LDA PSAVE
$F80A: $48 pha PHA
$F80B: $A5 $45 lda $45 LDA ASAVE
$F80D: $A6 $46 ldx $46 LDX XSAVE ; RESTORE 6502 REG CONTENTS
$F80F: $A4 $47 ldy $47 LDY YSAVE
$F811: $28 plp PLP
$F812: $60 rts RTS