DECLARE SUB BINInterface ()
DECLARE SUB updateCPU ()
DECLARE SUB portopen ()
DECLARE SUB BNRY (NUMBER, BIN$)
DECLARE SUB dokeyboard (ch$, LHR, LVR, W$)
DECLARE SUB STAG ()
DECLARE SUB EXICUTE ()
COMMON SHARED ll, X, LX, MNU
DIM SHARED PA$(200), MU$(200, 4), MAL$(200)
DIM vxtb$(200, 10): REM variable table

0 CLEAR 20000


BNCHART = 0
ON ERROR GOTO er:
WIDTH 80
SCREEN 0, 0, 0
10 SP = 20: ch = 219: WS = 2: X = 1: XL = 1
20 CLS
21 LOCATE 5, 50: PRINT "# Main Frame Basic ."
22 LOCATE 6, 50: PRINT "# ----------------- "
23 LOCATE 7, 50: PRINT "#     2002 "
24 LOCATE 8, 50: PRINT "#  HIT <S> TO BEGIN."
   LOCATE 19, 50: PRINT "E-mail to"
   LOCATE 20, 45: PRINT "adam_raccoon@yahoo.com "
30 DEF FNR (a) = a * 3.14 / 180
60 R = 5
80 SA = 0
90 SA = FNR(SA)
100 EA = 360
110 EA = FNR(EA)
120 AI = 5
140 AI = FNR(AI)
160 PX = 140 + R: PY = 80
170 FOR TH = (SA) TO (EA) STEP AI
180 T1 = T1 + AA: IF T1 > (EA) THEN T1 = SA
182 FOR RI = 1 TO 8
183 R = RI
190 X = R * COS(TH) * WS
210 Y = R * SIN(TH)
228 H = 30 + X
229 V = 10 + Y
230 LOCATE V, H: PRINT CHR$(ch);
235 NEXT RI
240 FOR RI = 1 TO 7
241 X = RI * COS(T5) * WS
243 Y = RI * SIN(T5)
250 HH = 30 + X
260 VV = 10 + Y
270 LOCATE VV, HH: PRINT " ";
275 NEXT RI
300 T5 = TT: TT = T4: T4 = T3: T3 = T2: T2 = T1: T1 = T0: T0 = TH
301 FOR RI = 0 TO 7
302 X = RI * COS(L5) * WS
303 Y = RI * SIN(L5)
304 HH = 30 + X
305 VV = 10 + Y
306 LOCATE VV, HH: PRINT CHR$(ch);
307 NEXT RI
308 L5 = ll: ll = L4: L4 = L3: L3 = L2: L2 = L1: L1 = L0: L0 = T5
400 FOR RI = 0 TO 7
401 X = RI * COS(Z5) * WS
402 Y = RI * SIN(Z5)
403 HH = 30 + X
404 VV = 10 + Y
405 LOCATE VV, HH: PRINT " ";
406 NEXT RI
409 Z5 = ZZ: ZZ = Z4: Z4 = Z3: Z3 = Z2: Z2 = Z1: Z1 = Z0: Z0 = L5
420 FOR RI = 0 TO 7
421 X = RI * COS(Q5) * WS
422 Y = RI * SIN(Q5)
423 HH = 30 + X
424 VV = 10 + Y
425 LOCATE VV, HH: PRINT CHR$(ch);
426 NEXT RI
427 Q5 = QQ: QQ = Q4: Q4 = Q3: Q3 = Q2: Q2 = Q1: Q1 = Q0: Q0 = Z5
430 FOR RI = 0 TO 7
431 X = RI * COS(W5) * WS
432 Y = RI * SIN(W5)
433 HH = 30 + X
434 VV = 10 + Y
435 LOCATE VV, HH: PRINT " ";
436 NEXT RI
437 W5 = WW: WW = W4: W4 = W3: W3 = W2: W2 = W1: W1 = W0: W0 = Q5
500 FOR RI = 0 TO 7
501 X = RI * COS(E5)
502 Y = RI * SIN(E5)
503 HH = 30 + X * WS
504 VV = 10 + Y
505 LOCATE VV, HH: PRINT CHR$(ch)
506 NEXT RI
507 E5 = EE: EE = E4: E4 = E3: E3 = E2: E2 = E1: E1 = E0: E0 = W5
510 FOR RI = 0 TO 7
511 X = RI * COS(N5)
512 Y = RI * SIN(N5)
513 HH = 30 + X * WS
514 VV = 10 + Y
515 LOCATE VV, HH: PRINT " ";
516 NEXT RI
519 N5 = NN: NN = N4: N4 = N3: N3 = N2: N2 = N1: N1 = N0: N0 = E5

3020 ke$ = INKEY$: ke$ = UCASE$(ke$): IF ke$ = "S" OR ke$ = CHR$(27) THEN 4000
3300 NEXT TH
3400 GOTO 170
4000 CLS : X = 1
6000  REM
6010 KEY OFF
6120  CALL STAG
      LOCATE 1, 2
      PRINT "TYPE IN YOUR WORDS THEN PRESS </> WHEN FINISHED."
6130  LOCATE 2, 1: PRINT STRING$(79, " ")
      LOCATE 3, 1: PRINT STRING$(79, " ")
      LOCATE 3, 1: PRINT "NUMBER"
                  CALL dokeyboard(ch$, 1, 2, "CODE"): PA$ = ch$
                  IF MNU = 1 THEN 6220
6140 IF PA$ = "/" THEN GOTO 6190
                   PA$(X) = PA$(X) + PA$
6145               CALL dokeyboard(ch$, 1, 3, "Math "): MU$ = ch$: CALL BNRY(VAL(ch$), BIN$): MAL$(X) = BIN$
6146 IF MU$ = "/" THEN 6220
6150 REM
                  CALL dokeyboard(ch$, 1, 4, "Place"):

6160 REM
6165 MU$(X, 0) = MU$(X, 0) + MU$
6170 PRINT X, PA$(X): PRINT MU$(X, 0)
6174 IF MU$(X, 0) = "" THEN 6180
6176
6180 GOTO 6120
6190 FOR Y = 1 TO X
6200 PRINT Y; " "; PA$(Y): PRINT MU$(Y, 0)
6210 NEXT Y
6220 MNU = 0: CLS : LOCATE 3, 1
     PRINT "PRESS <P> TO PRINT,<S> TO SAVE,<L> TO LOAD,<R> TO RETURN TO TYPING"
     PRINT "<N> TO START A NEW FILE,<E> TO EDIT A LINE,AND <D> TO RETURN TO DOS.<B> RETURNS YOU TO START.<K> TO DELETE A NUMBER <BIN> to access the Binary interface "
6222 PRINT "TYPE <PLAY> TO PLAY MUSIC";
         
     CALL dokeyboard(ch$, 1, 8, " menu #")
    
     ch$ = UCASE$(ch$)

     IF mn1 = 1 THEN MNU = 0
     IF ch$ = "" THEN SOUND 255, 4: GOTO 6220
     ch$ = UCASE$(ch$)
     IF ch$ = "BIN" THEN CALL BINInterface
     IF ch$ = "COM" OR ch$ = "COM1" OR ch$ = "COM2" THEN CALL portopen
     IF ch$ = "FILES" THEN FILES
     IF ch$ = "RUN" THEN CALL EXICUTE: ch$ = ""
6230 IF ch$ = "B" OR ch$ = "b" THEN 4000
6240 IF ch$ = "DIR" THEN CLS : FILES
6245 IF ch$ = "PLAY" THEN 7000

6250 IF ch$ = "K" THEN INPUT "NUMBER OF LINE TO BE DELETED"; NU: IF NU < 1 OR NU > (X) THEN PRINT "OUT OF RANGE": SOUND 200, 5:  ELSE PRINT PA$(NU): INPUT "IS THIS THE LINE YOU WANT TO ERASE? "; YN$: IF YN$ = "Y" OR YN$ = "YES" THEN PA$(NU) = "": IF NU = (X) THEN X = X - 1: GOTO 6220
6260 IF ch$ = "P" THEN CLS : FOR YY = 1 TO X: PRINT PA$(YY): PRINT MU$(YY, 0): LPRINT PA$(YY): LPRINT MU$(YY, 0): NEXT YY: PRINT "DONE": SOUND 255, 4: GOTO 6220
6270 IF ch$ = "S" THEN LINE INPUT "NAME OF FILE TO BE SAVED."; NA$: IF NA$ = "" THEN BEEP: GOTO 6220 ELSE OPEN "O", #1, NA$: PA$(0) = STR$(X): PRINT #1, PA$(0): FOR Y1 = 1 TO X: PRINT #1, PA$(Y1): PRINT #1, MU$(Y1, 0): NEXT Y1: CLOSE #1: PRINT "DONE": SOUND 255, 4
6280 IF ch$ = "L" THEN LINE INPUT "NAME OF FILE TO BE LOADED."; NA$: OPEN "I", #1, NA$: LINE INPUT #1, PA$(0): XL = VAL(PA$(0)): X = VAL(PA$(0)): FOR Y2 = 1 TO X: LINE INPUT #1, PA$(Y2): LINE INPUT #1, MU$(Y2, 0): NEXT Y2: CLOSE #1: PRINT "DONE": SOUND 255, 4: GOTO 6220
6290 IF ch$ = "R" THEN CLS : GOTO 6120
6300 IF ch$ = "EDIT" OR ch$ = "E" THEN 6380
6310 IF ch$ = "D" THEN CHDIR "C:\": PRINT "RETURNING TO DOS": SYSTEM
6320 IF ch$ = "N" THEN PRINT "EXISTING DATA DELETED.": SOUND 360, 10: GOTO 6000
6330 IF ch$ = "C" THEN INPUT "TYPE IN LETTER OF DRIVE YOU WANT TO USE."; DR$: CHDIR DR$ + ":\TYPER": PRINT "SWITCH TO "; DR$; " DRIVE AT TYPER"
6340 REM IF CH$ = "START" THEN CHDIR "C:\UTIL": RUN "START"
6350 IF ch$ = "program" OR ch$ = "PROGRAM" THEN CLS : CHDIR "C:\UTIL": KEY ON: LOCATE 1, 1: PRINT "YOU MAY NOW BEGIN TO PROGRAM SCOTT.": SOUND 3000, 2: END
     IF ch$ = "BIN" OR ch$ = "BINARY" THEN BNCHART = 1
     IF ch$ = "XOFF" THEN BNCHART = 0
6360 GOTO 6220
6370 END
6380 INPUT "ENTER LINE NUMBER TO BE EDITED."; LN: IF LN < 0 OR LN > X THEN SOUND 2000, 5: PRINT "THAT LINE DOES NOT EXIST.": GOTO 6380
6390 PRINT PA$(LN): PRINT "TYPE IN REPLACEMENT LINE FOR TEXT"; LN: LINE INPUT "REPLACEMENT"; PA$
6400 IF PA$ = "" THEN PRINT "NO REPLACEMENT MADE": GOTO 6411
6410 PA$(LN) = PA$
6411 PRINT MU$(LN, 0): PRINT "TYPE IN REPLACEMENT LINE FOR NOTES"; LN: LINE INPUT "REPLACEMENT"; MU$
6412 IF MU$ = "" THEN PRINT "NO REPLACEMENT": GOTO 6420
6415 MU$(LN, 0) = MU$
6420 GOTO 6190
6430 END
7000 FOR xx = 1 TO X
7010 INPUT "HIT RETURN"; RE$: IF RE$ = "R" THEN 6010
7020 PRINT PA$(xx)
7030 PRINT MU$(xx, 0)
7040 IF MU$(xx, 0) = "" THEN 7050
 CALL STAG

7050 NEXT xx
7060 GOTO 7000
END



er:

LOCATE 2, 2


PRINT "                "
PRINT "   #########    "
PRINT "   # error #    "; ERR
PRINT "   #########    "
PRINT "                "
IF X <= 200 THEN MU$(X, 0) = ""
SLEEP
GOTO 10
RESUME

REM leave this for comments

REM revisions made 2002 April 26 Friday
REM

SUB BINInterface

REM
CLS
DO
ke$ = INKEY$

LOCATE 2, 1
PRINT STICK(0), STICK(1), STICK(2), STICK(3)
PRINT " #### Joysticks  ######"





















LOOP UNTIL ke$ = CHR$(27)


END SUB

SUB BNRY (NUMBER, BIN$)
REM this sub deals with displaying and process numbers in the binary 1 0 format
REM binary math works in multiple of onn off


REM    example
REM  represent 136 in binary math
REM

REM 0  0  0  1  0  0  0  1  0  0  0   =  128 + 8 = 136
REM
REM 1  5  2  1  6  3  1  8  4  2  1
REM 0  1  5  2  4  2  6
REM 2  2  6  8   
REM 4
REM
REM

  N = NUMBER
  BIT12$ = "0"
  BIT11$ = "0"
  bit10$ = "0"
  bit9$ = "0"
  bit8$ = "0"
  bit7$ = "0"
  bit5$ = "0"
  bit4$ = "0"
  bit3$ = "0"
  bit2$ = "0"
  bit1$ = "0"
  BIT0$ = "0"
 

  IF NUMBER >= 4096 THEN bit10$ = "1": NUMBER = NUMBER - 4096
  IF NUMBER >= 2048 THEN BIT11$ = "1": NUMBER = NUMBER - 2048
  IF NUMBER >= 1024 THEN bit10$ = "1": NUMBER = NUMBER - 1024
  IF NUMBER >= 512 THEN bit9$ = "1": NUMBER = NUMBER - 512
  IF NUMBER >= 256 THEN bit8$ = "1": NUMBER = NUMBER - 256
  IF NUMBER >= 128 THEN bit7$ = "1": NUMBER = NUMBER - 128
  IF NUMBER >= 64 THEN bit6$ = "1": NUMBER = NUMBER - 64
  IF NUMBER >= 32 THEN bit5$ = "1": NUMBER = NUMBER - 32
  IF NUMBER >= 16 THEN bit4$ = "1": NUMBER = NUMBER - 16
  IF NUMBER >= 8 THEN bit3$ = "1": NUMBER = NUMBER - 8
  IF NUMBER >= 4 THEN bit2$ = "1": NUMBER = NUMBER - 4
  IF NUMBER >= 2 THEN bit1$ = "1": NUMBER = NUMBER - 2
  IF NUMBER = 1 THEN BIT0$ = "1": NUMBER = NUMBER - 1




  BIN$ = BIT12$ + BIT11$ + bit10$ + bit9$ + bit8$ + bit7$ + bit6$ + bit5$ + bit4$ + bit3$ + bit2$ + bit1$ + BIT0$

  LOCATE 8, 40: PRINT OCT$(N)
  LOCATE 9, 40: PRINT HEX$(N)
  LOCATE 10, 40: PRINT BIN$
  
  

END SUB

SUB dokeyboard (ch$, LHR, LVR, W$)
      ch$ = ""
  DO
   LOCATE 2, 1
  
   ke$ = INKEY$
     IF ke$ <> "" THEN
     a = ASC(ke$)
     ab = ASC(LEFT$(ke$, 1))
     LOCATE 1, 72: PRINT a; " "; ab
     END IF
    
     IF LVR >= 1 AND LVR < 22 AND LHR >= 1 AND LHR < 79 THEN
      LOCATE LVR, LHR
     END IF
  
  
  
    PRINT W$ + " ; " + ch$; CUR$; "  "

   IF ke$ = CHR$(8) THEN CL = LEN(ch$): IF CL > 0 THEN ch$ = LEFT$(ch$, CL - 1)

   IF ke$ = CHR$(27) THEN MNU = 1: ke$ = CHR$(13)
 
   IF ke$ = CHR$(0) + "P" THEN ke$ = "": X = X + 1
   IF ke$ = CHR$(0) + "H" THEN ke$ = "": X = X - 1: IF X < 0 THEN X = 0
   IF ke$ = CHR$(0) + CHR$(59) THEN ch$ = PA$(X): ke$ = ""
   IF ke$ = CHR$(0) + CHR$(60) THEN PA$(X) = "": CALL STAG: ke$ = ""
   IF ke$ = CHR$(0) + CHR$(61) THEN MU$(X, 0) = "": CALL STAG: ke$ = ""
 
  
   

   IF ke$ <> CHR$(0) AND ke$ <> CHR$(13) AND ke$ <> CHR$(8) THEN ch$ = ch$ + ke$

    CU = CU + 1
    IF CU > 50 THEN CU = 0

    IF CU = 1 THEN CUR$ = " "
    IF CU = 30 THEN CUR$ = CHR$(219)
 


    IF X <> (LX) THEN CALL STAG: LX = X
 
    IF ke$ <> "" THEN
    LOCATE 20, 70: PRINT ASC(ke$)
    END IF

     lptimer = lptimer + 1: IF lptimer > 20 THEN CALL updateCPU

 
  LOOP UNTIL ke$ = CHR$(13)


END SUB

SUB EXICUTE

PEND = 0
X = 0

DO
CALL STAG
LOCATE 1, 1: PRINT X
ke$ = INKEY$

IF X <= 200 THEN WORD$ = PA$(X): ADDR$ = MU$(X, 0)
WORD$ = UCASE$(WORD$)


DX = 0
WDL = LEN(WORD$)
 FOR V = 1 TO (WDL)
  ch$ = MID$(WORD$, V, 1)

   IF ch$ = CHR$(32) THEN DX = 1
   IF DX = 0 THEN WD$ = WD$ + ch$



 NEXT V

LOCATE 1, 45: PRINT WORD$; "   "



IF X > 200 THEN LOCATE 23, 1: PRINT "RUN "; RNNUM; X = 0; RNNUM = RNNUM + 1




SELECT CASE (WD$)
CASE IS = "END"

ke$ = CHR$(27): PEND = 1
  
CASE IS = "GOTO"

X = VAL(MU$(X, 0)): CALL STAG
CASE IS = "BEEP"
BEEP
CASE IS = "CLS"
CLS

CASE IS = "INPUT$"

INPUT "> "; W$

CASE IS = "INPUT"
INPUT "> "; NUMBER: CALL BNRY(NUMBER, BIN$)

BINL$ = BIN$

CASE IS = "SND", "SOUND", "TONE"

SOUND 2, 100 + VAL(MU$(X, 0))


CASE IS = "LIST"


FOR T = 1 TO 200


PRINT PA$(T), MU$(T, 0)

NEXT T

CASE IS = "SAVE"

'LOCATE 20, 1: PRINT "##########################"
'INPUT "SAVE AS #"; NA$

CASE IS = "INC"

VAR = VAL(MU$(X, 0))

VAR = VAR + 1
MU$(X, 0) = STR$(VAR)





END SELECT

LX = X

X = X + 1

LOOP UNTIL ke$ = CHR$(27) OR PEND = 1
ch$ = ""
  LOCATE 20, 39: PRINT " stoped at "; X
LX = 0
 LOCATE 20, 1: PRINT " hit any key "
SLEEP
END SUB

SUB portopen

CLS
LOCATE 5, 5: PRINT ": cls"
LOCATE 6, 5: PRINT ": seriol port < 1 or 2 >"
LOCATE 7, 5: INPUT " 1-2 "; pt$


OPEN "com1:19200,n,8,1,RB2048,TB2048" FOR RANDOM AS #1


END SUB

SUB STAG
           
   LOCATE 11, 1
  
   FOR DTX = (X - 7) TO (X + 3)
  
   IF DTX > 0 AND DTX < 200 THEN
  
    PRINT "# "; LX;

    IF DTX = (X) THEN PRINT " --> ";
   
   PRINT "#"; PA$(DTX) + "-"; MU$(DTX, 0); "-"; MAL$(DTX); STRING$((79 - POS(0)), " ")
   
   END IF

NEXT DTX


END SUB

SUB updateCPU

REM Very important # is used with VB 4.0 Project to simulat multi Processing


'OPEN "b:\RAMHEXDump.txt" FOR INPUT AS #4



'INPUT #4, a$







'CLOSE #1




END SUB

