
    !to "hbe"
    * = $0801
    !byte $0c,$08,$0a,$00,$9e,$32,$30,$36,$31,$00,$00,$00

ip  = $a4
ptr = $a6
sp  = $a8
col = $aa
saved = $ac

start:

    ldy #$04
.fill0:
    ldx #$00
.fill1:
    lda #$20
.fill2:
    sta $0400,x
    lda #$55
.fill3:
    sta $d800,x
    dex
    bne .fill1
    inc .fill2+2
    inc .fill3+2
    dey
    bne .fill0

    ldx #$f0
    lda #$22
.fill4:
    sta $d828,x
    dex
    bne .fill4

    ldx #$27
    lda #$11
.fill5:
    sta $d800,x
    dex
    bne .fill5

.copy0:
    lda program
    bmi .copied
    inc .copy0+1
    bne .copy1
    inc .copy0+2
.copy1:
    sta $0400
    inc .copy1+1
    bne .copy0
    inc .copy1+2
    jmp .copy0

.copied:

    lda #$04
    sta ip+1
    sta ptr+1
    lda #$00
    sta ip
    sta ptr
    sta $d020
    sta $d021

    lda #$c0
    sta sp+1
    lda #$fe
    sta sp

.loop:
    ldy #$00
    lda ip+1
    clc
    adc #$d4
    sta col+1
    lda ip
    sta col
    lda (col),y
    sta saved
    lda #$66
    sta (col),y
.sync0:
    lda $d011
    bpl .sync0
    jsr interpret
.sync1:
    lda $d011
    bmi .sync1
    lda saved
    ldy #$00
    sta (col),y
    jmp .loop

interpret:
    lda (ip),y
    inc ip
    bne .sincip
    inc ip+1
.sincip:
    cmp #'<'
    bne .nodecptr
    lda ptr
    bne .sdecptr
    dec ptr+1
.sdecptr:
    dec ptr
    rts
.nodecptr:
    cmp #'>'
    bne .noincptr
    inc ptr
    bne .done
    inc ptr+1
    rts
.noincptr:
    cmp #'+'
    bne .noinc
    lda (ptr),y
    adc #$00
    sta (ptr),y
    rts
.noinc:
    cmp #'-'
    bne .nodec
    lda (ptr),y
    sbc #$01
    sta (ptr),y
    rts
.nodec:
    cmp #'('
    bne .nowhile
    dec sp
    dec sp
    lda ip
    sta (sp),y
    iny
    lda ip+1
    sta (sp),y
    dey
    ldx #$01
.searchend:
    lda (ip),y
    cmp #'('
    bne .scountup
    inx
    jmp .scountnext
.scountup:
    cmp #')'
    bne .scountnext
    dex
    beq .done
.scountnext:
    inc ip
    bne .searchend
    inc ip+1
    jmp .searchend
.nowhile:
    cmp #')'
    bne interpret
    lda (ptr),y
    beq .nojmp
    lda (sp),y
    sta ip
    iny
    lda (sp),y
    sta ip+1
    rts
.nojmp:
    inc sp
    inc sp
.done:
    rts

program:
    !ct scr
    !tx "                                        "
    !tx "                                        "
    !tx "             >>>>>    >>>>>             "
    !tx "           (-)+++++   +(<----           "
    !tx "             >>--->--->->>-             "
    !tx "                ---->---                "
    !tx "                   ->                   "
    !tx "            -->-->---->-----            "
    !tx "       >-----              >->++>       "
    !tx "     >--           ->           ---     "
    !tx "   -->             --             >--   "
    !tx "  >-               --               ->  "
    !tx " --                -<                << "
    !tx " <<                <<                << "
    !tx "<<                 <<                 <<"
    !tx "<<                 <<                 <-"
    !tx ")+               >++>++               >-"
    !tx " >>            >+  >-  ->            >> "
    !tx " ++          >-    >-    >>          >- "
    !tx "  >-       >-      ->      >+       >>  "
    !tx "   +(>   )+        ++        +(   <++   "
    !tx "     <++           +<           +++     "
    !tx "       <+++>>              >>>++<       "
    !tx "            x-)>+<<<+<+<+</x            "
    !tx "                                     @  "
    !byte 0x80


