10 GOTO 1010 : REM MOVE ALL VARIABLE DECLARATIONS INTO INITIALIZATION.
20 REM (GOSUB 30) PRINT CURRENT CELL.
30 PRINT CM%(CP%);"(CELL";CP%;", $";AP;")" : RETURN
1000 REM INITIALIZATION.
1010 RA%=0 : RB%=0 : RC%=0          : REM VARIABLES USED LIKE REGISTERS.
1020 IN$="" : C%=0 : IS%=0 : I=0    : REM FOR PROCESSING INPUT.
1030 IC%=0 : N=0 : F%=0 : REM COUNTING INSTRUCTIONS, CONDITIONS, LOOP FAIL FLAG.
1040 K=0 : IP%=0 : B%=0 : OB%=0 :REM ITERATOR, INPUT POINTER, BRACKET VARAIBLES.
1050 D%=0 : NV%=0 : K$="" : K%=0    : REM DEPTH, TEMP. VALUE, KEYBOARD INPUT.
1060 CP%=0 : AP=0 : PP=0           : REM CELL, C64, AND PROGRAM MEMORY POINTERS.
1070 PS% = 160 - 1   : DIM PM%(PS%) : REM PROGRAM MEMORY & FINAL INDEX.
1080 CC% = 16500 - 1 : DIM CM%(CC%) : REM CELL MEMORY & FINAL INDEX.
1090 PRINT CHR$(147);"BASICFUCK C64 BRAINFUCK REPL V2.1","TYPE ? FOR HELP."
1100 PRINT "TYPE ! TO EXIT."
2000 REM (GOTO 2010) INPUT LOOP.
2010 INPUT "$"; IN$ : IF IN$ = "" THEN GOSUB 30 : GOTO 2010
2020 C% = ASC(IN$) : IF C% = 33 THEN END    : REM !
2030 IF C% = 63 THEN GOSUB 4010 : GOTO 2010 : REM ?
2040 PP = 0 : IS% = LEN(IN$) : REM PROGRAM POINTER & INPUT SIZE.
2050 FOR I = 1 TO IS% : C% = ASC(MID$(IN$, I, 1))
2060 IF C% = 43 THEN RA%=43 : RB%=45 : RC%=1 : GOSUB 3010 : GOTO 2310 : REM +
2070 IF C% = 45 THEN RA%=43 : RB%=45 : RC%=1 : GOSUB 3010 : GOTO 2310 : REM -
2080 IF C% = 60 THEN RA%=62 : RB%=60 : RC%=2 : GOSUB 3010 : GOTO 2310 : REM <
2090 IF C% = 62 THEN RA%=62 : RB%=60 : RC%=2 : GOSUB 3010 : GOTO 2310 : REM >
2100 IF C% = 91 THEN PM%(PP)=3 : PM%(PP+1)=-1 : PP=PP+2   : GOTO 2310 : REM [
2110 IF C% = 93 THEN PM%(PP)=4 : PM%(PP+1)=-1 : PP=PP+2   : GOTO 2310 : REM ]
2120 IF C% = 46 THEN PM%(PP) = 5 : PP = PP + 2            : GOTO 2310 : REM .
2130 IF C% = 59 THEN PM%(PP) = 6 : PP = PP + 2            : GOTO 2310 : REM ;
2140 IF C% = 40 THEN RA%=41 : RB%=40 : RC%=7 : GOSUB 3010 : GOTO 2310 : REM (
2150 IF C% = 41 THEN RA%=41 : RB%=40 : RC%=7 : GOSUB 3010 : GOTO 2310 : REM )
2160 IF C% = 64 THEN PM%(PP) = 8 : PP = PP + 2            : GOTO 2310 : REM @
2170 IF C% = 42 THEN PM%(PP) = 9 : PP = PP + 2            : GOTO 2310 : REM *
2310 NEXT I
2320 IF PP < PS% THEN PM%(PP) = 0 : GOTO 5000
2330 GOTO 5000
3000 REM (GOSUB 3010) MAKES +/- INSTRUCTIONS. RA% +CHAR RB% -CHAR RC% TYPE -> 0.
3010 IC% = 0 : FOR N = 0 TO 1 STEP 0 : IF I > IS% GOTO 3080
3020 C% = ASC(MID$(IN$,I,1)) : IF C%=RA% THEN IC%=IC%+1 : I=I+1 : GOTO 3090
3030 IF C% = RB% THEN IC% = IC% - 1 : I = I + 1 : GOTO 3090
3080 N = 1
3090 NEXT N
3100 I = I - 1 : IF IC% = 0 THEN RETURN
3110 PM%(PP) = RC% : PM%(PP+1) = IC% : PP = PP + 2 : RETURN
4000 REM (GOSUB 4010) HELP MESSAGES.
4010PRINT" ! EXITS THE REPL. ? DISPLAYS HELP INFORMATION.":PRINT"THE PREVIOUS ";
4020PRINT"TWO COMMANDS MUST BE THE FIRST CHARACTER IN INPUT TO FUNCTION."
4030PRINT" +/- INCREMENTS/DECREMENTS THE CURRENT CELL.":PRINT" </> MOVES THE M";
4040PRINT"EMORY POINTER TO THE LEFT/RIGHT.":PRINT" [ JUMPS PAST THE CORRESPOND";
4050PRINT"ING ] IF THE CURRENT CELL IS 0.":PRINT" ] JUMPS TO THE CORRESPONDING";
4060PRINT" [ IF THE CURRENT CELL IS NOT 0.":PRINT" . PRINTS THE VALUE OF THE C";
4070PRINT"URRENT CELL AS A CHARACTER.":PRINT" ; TAKES ONE CHARACTER FROM THE K";
4080PRINT"EYBOARD AS INPUT AND STORES IT INTO THE CURRENT CELL.":PRINT" (/) MO";
4090PRINT"VES THE C64 MEMORY POINTER TO THE LEFT/RIGHT.":PRINT" @ READS THE VA";
4100PRINT"LUE FROM C64 MEMORY INTO THE CURRENT CELL.":PRINT" * PUTS THE VALUE ";
4110PRINT"OF THE CURRENT CELL INTO C64 MEMORY." : RETURN
5000 F% = 0 : FOR PP = 0 TO PS% STEP 2
5010 C% = PM%(PP) : IF C% = 0 THEN PP = PS% + 1 : GOTO 5120
5020 IF C% = 3 OR C% = 4 THEN IF PM%(PP+1) = -1 THEN GOSUB 6010
5030 IF F% THEN PP = PS% + 1
5120 NEXT PP
5130 IF F% THEN PRINT "?UNTERMINATED LOOP" : GOTO 2010
5140 GOTO 7010
6000 REM (GOSUB 6010) MAKE [ AND ] INSTRUCTIONS.
6010 B% = C% : IF B% = 3 THEN OB% = 4 : K = 2 : GOTO 6150
6020 OB% = 3 : K = -2
6150 IP% = PP : D% = 0 : FOR N = 0 TO 1 STEP 0 : IP% = IP% + K
6160 IF IP% > PS% OR IP% < 0   THEN N = 1 : F% = -1 : GOTO 6400
6170 C% = PM%(IP%) : IF C% = 0 THEN N = 1 : F% = -1 : GOTO 6400
6180 IF C% = B% THEN D% = D% + 1 : GOTO 6400
6190 IF C% <> OB% GOTO 6400
6200 IF D% > 0 THEN D% = D% - 1 : GOTO 6400
6210 N = 1
6400 NEXT N
6410 IF F% THEN RETURN
6420 PM%(PP+1) = IP% : PM%(IP%+1) = PP : RETURN
7000 REM INTERPRETER.
7010 K$ = "" : FOR PP = 0 TO PS% STEP 2
7020 GET K$ : IF K$ <> "" THEN IF ASC(K$) = 133 THEN PP = PS% + 1 : GOTO 7680
7030 ON PM%(PP) GOTO 7430, 7440, 7450, 7460, 7470, 7480, 7490, 7500, 7510
7040 PP = PS% + 1          : GOTO 7680
7430 GOSUB 8010            : GOTO 7680 : REM + & -
7440 GOSUB 9010            : GOTO 7680 : REM < & >
7450 GOSUB 10010           : GOTO 7680 : REM [
7460 GOSUB 10510           : GOTO 7680 : REM ]
7470 PRINT CHR$(CM%(CP%)); : GOTO 7680 : REM .
7480 GOSUB 11010           : GOTO 7680 : REM ;
7490 GOSUB 12010           : GOTO 7680 : REM ( & )
7500 CM%(CP%) = PEEK(AP)   : GOTO 7680 : REM @
7510 POKE AP, CM%(CP%)     : GOTO 7680 : REM *
7680 NEXT PP
7690 GOSUB 30 : GOTO 2010
8000 REM (GOSUB 8010) RUN + & - INSTRUCTIONS.
8010 NV% = CM%(CP%) + PM%(PP+1)
8020 IF NV% < 0   THEN NV% = NV% + 256 : GOTO 8020
8030 IF NV% > 255 THEN NV% = NV% - 256 : GOTO 8030
8040 CM%(CP%) = NV% : RETURN
9000 REM (GOSUB 9010) RUN < & > INSTRUCTIONS.
9010 CP% = CP% + PM%(PP+1) : IF CP% < 0 THEN CP% = 0 : RETURN
9020 IF CP% > CC% THEN CP% = CC%                     : RETURN
9030 RETURN
10000 REM (GOSUB 10010) RUNS [ INSTRUCTIONS.
10010 IF CM%(CP%) = 0 THEN PP = PM%(PP+1) : RETURN
10020 RETURN
10500 REM (GOSUB 10510) RUNS ] INSTRUCTIONS.
10510 IF CM%(CP%) <> 0 THEN PP = PM%(PP+1) : RETURN
10520 RETURN
11000 REM (GOSUB 11010) RUNS ; INSTRUCTIONS.
11010 K$ = "" : GET K$ : IF K$ = "" GOTO 11010
11020 K% = ASC(K$) : IF K% = 133 THEN PP = PS% + 1 : RETURN
11030 CM%(CP%) = K% : RETURN
12000 REM (GOSUB 12010) RUNS ( & ) INSTRUCTIONS.
12010 AP = AP + PM%(PP+1) : IF AP < 0 THEN AP = 0 : RETURN
12020 IF AP > 65535 THEN AP = 65535               : RETURN
12030 RETURN
