Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .setcpu "65C02"
- ACIA_DATA = $7F00
- ACIA_STATUS = $7F01
- ACIA_COMMAND = $7F02
- ACIA_CONTROL = $7F03
- BF_MEMORY = $1000
- BF_JUMP_TABLE = $1100
- .segment "VECTORS"
- .word nmi
- .word reset
- .word irq
- .zeropage
- temp_2: .res 2
- bf_ip: .res 1
- bf_next_ip: .res 1
- bf_dp: .res 1
- .code
- reset: jmp main
- nmi: rti
- irq: rti
- main:
- init_acia: lda #%00001011
- sta ACIA_COMMAND
- lda #%00011111
- sta ACIA_CONTROL
- ldx #0
- : stz BF_MEMORY,x
- stz BF_JUMP_TABLE,x
- inx
- bne :-
- jsr compute_jump_table
- stz bf_ip
- stz bf_dp
- loop: ldx bf_ip
- lda brainfuck_code,x
- bne :+
- jmp end
- : inx
- stx bf_next_ip
- cmp #'+'
- bne :+
- ldx bf_dp
- inc BF_MEMORY,x
- bra @op_end
- : cmp #'-'
- bne :+
- ldx bf_dp
- dec BF_MEMORY,x
- bra @op_end
- : cmp #'>'
- bne :+
- inc bf_dp
- bra @op_end
- : cmp #'<'
- bne :+
- dec bf_dp
- bra @op_end
- : cmp #'.'
- bne :+
- ldx bf_dp
- lda BF_MEMORY,x
- jsr acia_putc
- bra @op_end
- : cmp #','
- bne :+
- ; ,
- bra @op_end
- : cmp #'['
- bne :+
- ldx bf_dp
- lda BF_MEMORY,x
- bne @op_end
- ldx bf_ip
- lda BF_JUMP_TABLE,x
- inc a
- sta bf_next_ip
- bra @op_end
- : cmp #']'
- bne @op_end
- ldx bf_dp
- lda BF_MEMORY,x
- beq @op_end
- ldx bf_ip
- lda BF_JUMP_TABLE,x
- inc a
- sta bf_next_ip
- @op_end: lda bf_next_ip
- sta bf_ip
- jmp loop
- end: wai
- bra end
- compute_jump_table: ldx #0
- @loop: lda brainfuck_code,x
- cmp #'['
- bne :+
- phx
- bra :++
- : cmp #']'
- bne :+
- pla
- sta BF_JUMP_TABLE,x
- tay
- txa
- sta BF_JUMP_TABLE,y
- : inx
- bne @loop
- rts
- acia_putc: pha
- : lda ACIA_STATUS
- and #$10
- beq :-
- pla
- sta ACIA_DATA
- rts
- brainfuck_code: .byte "++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+>>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]<<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]", 0
- ;.byte "++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<]>.>+[>>]>+]", 0
- ;.byte "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.", 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement