Skip to content

@anall /gist:e16bc88d4ab7a97d95f8 secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
.word $1000
.org $1000
jmp main
.alias program $1f00
.alias data_array $2000
.alias loop_stack $2100
.alias loop_cache $1e00
.global prg_off
prg_off: ; stores 1 byte offset
.byte 0 ; for program data
data_off:
.byte 0 ; for data pointer
loop_stack_off:
.byte 0 ; for loop stack
loop_begin_to_eat:
.byte 0
loop_entry:
.byte 0
.global main
main: ; clear memory and offsets
ldx #$00
lda #$00
sta prg_off
sta loop_stack_off
sta data_off
_clear_data:
sta data_array,X
sta loop_stack,X
sta loop_cache,X
inx
bne _clear_data
.global decode_next
decode_next:
ldx prg_off
inc prg_off
lda program, X
cmp #$00 ; end
beq done
cmp #$2b ; '+'
beq opj_add
cmp #$2d ; '-'
beq opj_sub
cmp #$3e ; '>'
beq opj_fwd
cmp #$3c ; '<'
beq opj_back
cmp #$5b ; '['
beq opj_loop_beg
cmp #$5d ; ']'
beq opj_loop_end
cmp #$2e ; '.'
beq opj_print
jmp decode_next
.global done
done:
rts
; silly jump distance limitations
opj_add:
jmp op_add
opj_sub:
jmp op_sub
opj_fwd:
jmp op_fwd
opj_back:
jmp op_back
opj_loop_beg:
jmp op_loop_beg
opj_loop_end:
jmp op_loop_end
opj_print:
jmp op_print
.global op_add
op_add:
ldx data_off
inc data_array,X
jmp decode_next
op_sub:
ldx data_off
dec data_array,X
jmp decode_next
op_fwd:
inc data_off
jmp decode_next
op_back:
dec data_off
jmp decode_next
.scope
op_loop_beg:
ldx data_off
lda data_array,X
cmp #$00
beq _exit_loop
dec loop_stack_off
ldx loop_stack_off
lda prg_off
sta loop_stack,X
jmp decode_next
_exit_loop:
lda #$01
sta loop_begin_to_eat
ldx prg_off
dex
inc prg_off
lda loop_cache,X
cmp #$00
bne _cache_hit
stx loop_entry
_consume:
ldx prg_off
inc prg_off
lda program,X
cmp #$00 ; end
beq done
cmp #$5b ; '['
beq _eat_more
cmp #$5d ; ']'
beq _got_end
jmp _consume
_eat_more:
inc loop_begin_to_eat
jmp _consume
_got_end:
dec loop_begin_to_eat
bne _consume
_exit:
ldx loop_entry
lda prg_off
sta loop_cache,X
jmp decode_next
_cache_hit:
sta prg_off
jmp decode_next
.scend
.scope
op_loop_end:
ldx data_off
lda data_array,X
cmp #$00
beq _exit_loop
ldx loop_stack_off
lda loop_stack,X
sta prg_off
jmp decode_next
_exit_loop:
inc loop_stack_off
jmp decode_next
.scend
.global op_print
op_print:
ldx data_off
lda data_array,X
jsr $FFD2
jmp decode_next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.