Friday, October 25, 2013

Participation

Note: This is not validated by Hawwash Soft. Use at your own risk!

Author name: Arthur Morris
Description: "C64 BASIC V2 CONCISE LIST of COMMANDS"

63998 END
63999 REM "cmds.txt" Concise BASIC Commands File
^^^^^^^^^^^^^^SAFETY WALL^^^^^^^^^^^^^^^^^^^^^^^
In Editor write Program above WALL, SAVEing temporary back-ups as required.
To test: firstly COPY the Program from Editor, then while still in Editor delete all above L.63998 and tap Save Button to preserve this File
Go to C64 BASIC and PASTE. 
NB. RETURN all Lines before RUN. When testing is OK, SAVE as a FILE "name.bas".
================================================
CONCISE HAND-BASIC COMMANDS [File "cmds.txt"]
                I N D E X
  [1] VARIABLES         [6] DIRECT
  [2] STRINGS           [7] MATHS FUNCTIONS
  [3] ARRAYS            [8] LOGIC FUNCTIONS
  [4] PROGRAM FLOW      [9] GRAPHICS
  [5] IN/OUTPUT etc.   [10] MEMORY ACCESS
================================================
[1]***VARIABLES***
NUMBERS  (2.93873588E-39 TO 1.70141183E38)
SIMPLE   eg. A; B;TYPE;X  all number variables
         Most frequently used type.
         All computations are float precision
         without the '%' identifier (below)
NAMES    cannot be Direct Commands      
         only first two chars. are ever used
         CO=COUNT;CONCISE;COLOUR BUT NOT 'C'. 
         CO, CO%, CO$ are different names.
PRECISION  eg. AB%;X%;TYPE%  32 bit mantissa
           (apprx.9.6 decimal digits)+8bit exp.
INTEGER    AB% +/- 32767  Integer (16 Bit)
INT     Truncate number to Integer: rounded down
        INT(0)=0      INT(5)=5     INT(-5)=-5
            INT(6.25)=6    INT(-6.25)=-7 
================================================
[2]***STRING$*** (0-255 CHARS.)
NAMES   MN--$:M=letter(A-Z);N=letter (or no.0-9)
ASC(A$)or("A--Z")=the first ASCII Char. only
        ASC("P")=80   ASC("Power")=80
CHR$(X) ASCII character of (X)   CHR$(80)="P" 
STR$(X) Numeric value of X as a string
        STR$(6.25)=" 6.25"  STR$(-6.25)="-6.25"
VAL(X$) value to first non-numeric character
        VAL("6.25x")=6.25  VAL("6xx25")=6
        VAL("x6x25")=0
CONCATENATE STRING$(+/-)  "Pow"+"er64"="Power64"
ALGEBRAIC OPERATORS   <   <=   =   <>   >=   >- 
        "C64"<"Power64"=-1(true)
        "Alpha">"Omega"=0 (false)
LEN(A$) Number of characters in String
LEFT$(A$,X)  Chars. First to X
MID$(A$,X,Y) Chars. X to Y [X=1,Y=1 ok in IF-NEXT loop]
RIGHT$(A$,X) Chars. X to last
    10 FOR CODE=49 TO 81
    15 TEMP$=CHR$(CO): CODE$=CO$+TE$: NEXT
    20 TE$="...." 
    25 PRINT CO$:
    30 PRINT LEFT$(CO$,4);"-!-";TAB(4);
    35 PRINT MID$(CO$,9,12)"-!-"
    40 PRINT TE$; RIGHT$(CO$,9): END
      run: (Variables- CODE,TEMP$,CODE$)
      (25)   "123456789:;<=>?@ABCDEFGHIJKLMNOPQ"                        
      (30/5) "1234-!-    9:;<=>?@ABCD-!-"
      (40)   "....IJKLMNOPQ"
================================================
[3]***ARRAYS***
DIM Over eleven elements, (=subscripts 0-10+)
    requires program space reserved first.
DIM NAME(x(,y,z), DIM NAME$(x,(y,z)
    DIM A(11)=12 elements (0..11)
    DIM B$(40,5,6)=1200(40x5x6) total elements
     entries: A(3)=17  B$(0,2,3)="String"
================================================
[4]***PROGRAM FLOW***
GOTO X: program moves to Line X   
GOSUB XY: to Subroutine at XY
      100 PRINT"Main  Program": GOSUB 900
      110 PRINT"Back  to  Main": GOSUB 900
      120 PRINT"Back again to Main": END
      900 PRINT"At the Subroutine":RETURN
ON...GOTO  Multiway branch
ON...GOSUB    "        "
      100 ON X GOTO 100, 200, 300
         (X=1:GOTO100, 2:GOTO200, 3:GOTO300) 
IF..THEN.. Conditional branch
      100 IF A < B THEN MN = A: GOTO xxx
      105 REM if true goto Line xxx    
      110 MN=B: REM if false
      120 ....
FOR..TO..(STEP..):NEXT (default:Step=1)
      FOR I=1 TO 3:PRINT I;:NEXT        1 2 3 
      FOR I=1 TO 3 STEP 2:PRINT I;:NEXT   1 3 
      FOR I=3 TO 1 STEP-2:PRINT I;:NEXT   3 1
      FOR I=3 TO 1:PRINT I;:NEXT            3
================================================
[5]***INPUT/OUTPUT/PRINT/READ***
CHR$(X) ASCII character (X=code)  CHR$(80)="P"
ASC  ASCII CODE (first char. in string ONLY)
     ASC("A")=65  ASC("A STRING ")=65
GET(X) byte from data
       (no "?" or wait, eg. to read storage)
GET(A$) string from data    (ditto)  
      xxx GET K$:IF K$="": GOTO xxx
      xxy GOSUB zzzy
      xxz REM any[key] -goto subroutine
      zzzy FOR N=1TO6^9:NEXT:RETURN
      zzzz REM?1min.pause}
INPUT "Enter Number";A
          prints "data"; "?", waits for [key]entry
INPUT A "Enter  X,Y,C,"; A,B,C +[Ret]
          puts values X,Y,Z into A,B,C
INPUT A$: enters string A$ (or value as string)
INPUT "Enter data+[Ret]";A$; (PRINT A$)
          waits as above: (prints A$)

SPC(X) print SPC(X) = X spaces to next PRINT

       100 FORT=0TO2: PRINT "|";SPC(T);
       110 FOR I =1TO2: PRINT "*";SPC(T):NEXT
       120 PRINT"|   ";:NEXT  
       run "|**|   | * * |   |  *  *  |   "

CHR$(9)=8-column move TAB 

  10 PRINT "A";CHR$(9);"B";CHR$(9);"C";CHR$(9);"D"
  20 PRINT "A";CHR$(9);"B2";CHR$(9);"C234567";
     CHR$(9);"D"
  30 PRINT "A";CHR$(9);"B   5";CHR$(9);
     "C     7";CHR$(9);"D"
  run   A       B       C       D
        A       B2      C234567 D
        A       B   5   C     7 D
PRINT "a.."; Semi-colon= no gap   
PRINT "a..", Comma= 10 spaces
PRINT  "a.." =Next line
   10 PRINT "; =no space" ; "THUS"
   20 PRINT ", =10 spaces" , "THUS"
   30 PRINT "if no punctuation mark"
   40 PRINT "=HERE!"
      run (10) "; =no spaceTHUS"
          (20) ", =10 spaces          THUS"
          (30) "if no punctuation mark"
               "=HERE!"

   10 FOR NUM=7 TO 13:PRINT NU;";";:NEXT: PRINT

   20 FOR N=7 TO 13:NUM$=NU$+CHR$(48+N):NEXT
   25 PRINT " ";NU$
     run (10) " 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ;"
         (25) " 789:;<="
DATA    stores data,data, , , (items) 
RESTORE resets DATA pointer to
         the FIRST item again for next READ
READ "data" : items from DATA in order
  100 RESTORE:READ D$:PRINT D$;
  110 FOR I=1 TO 3:READ D:N=N+D:PRINT N;:NEXT I
  120 DATA "Power",12,34,18
    run (110)   Power 12  46  64
  100 RESTORE
  200 FOR I=1TO4:READ D$:PRINT D$;:NEXT
  210 FOR I=1TO3:READ N$:PRINTN$;:NEXT
  230 FOR I=1TO3:READ N:PRINTN;:NEXT 
  300 DATA "Tes ",TST,CHR$(64)@,
  310 DATA 3,111,5, 2,6,90,100,
    run (110) "Tes TSTCHR$(64)@31115 2  6  90 "
OPEN  creates a file (for data)
   10 OPEN 1,0,1,"TEST.DAT"
   15 REM "    1," open a file to store data
   20 PRINT#1, 1234: PRINT#1, "Hello":REM -data
   30 CLOSE 1
   50 OPEN 1,0,0,"TEST.DAT"
   55 REM "    0," open file to retrieve data
   60 INPUT#1, A: INPUT#1, I$: CLOSE 1
   90 PRINT I$: PRINT A
     run "Hello 1234" 
CLOSE file

Store/load user files using OPEN/CLOSE, PRINT#/INPUT#

 ASCII OFF: LOAD/SAVE "-.BAS" files
 ASCII ON (=default): LOAD/SAVE "-.TXT" files
 LOADing auto-detects format(Text/Encoded). 
 ASCII flag still used to specify SAVE format.
 OPEN ASCII BASIC Files with”.TXT” extension,
       <other apps.
================================================
[6]***DIRECT COMMANDS***~
NEW  deletes all code & variables
CLR  clears all variables        
CLS  clears screen {="PRINT CHR$(147)"}
REM  comments -ignored by program run.
LIST (all)  -X(start to X)  X-Y   X (X to end)
RUN (1-end)    RUN X (X to end)
STOP stops program: prints "BREAK IN L.xxx"
CONT continues program after a STOP
END  program completion
FILES ("filter" option) list files
LOAD "filename" to Screen 0 (then LIST & ENTER)
SAVE "filename" stores the program in a file 
EDIT "FileName" loads file to Editor
COPY  "FILE1"TO"FILE2"  1 is copied to 2
MERGE "FILE1"AND"FILE2"INTO"FILE3"  
       repeated lines overwritten by F.2 lines
RENUM "FILE1"[TO "FILE2" option] FROM N STEP M
RENUM "QUIZ.BAS" TO "QUIZ"
RENUM "QUIZ"
RENUM "QUIZ" TO "Q" FROM 1000
RENUM "QUIZ" TO "Q" FROM 1000 STEP 5
RENUM "Q" FROM 5 STEP 5
FONTS ("filter" option) lists all fonts
SET FONT "fontname",size (recommended 16-24 pt.)
SET FCLR R,G,B text col. Red,Green,Blue(0-255}
SET BCLR R,G,B background col,
SET STORE   save settings
SET RESTORE restore original col. settings
PRINT FRE(0)=-26625 (Power-on)
            = 38911 (65536-26625)
================================================
[7]***MATH FUNCTIONS***
ARITHMETIC calculating done from L.to R.
[1] contents of brackets: innermost-->outwards
[2] powers & roots     [3] *,/     [4] +,-
  ? 2+256/2^2-2+3*2+1         71
  ? 2+{(256/(2^2)}-2+(3*2)+1  71
  ? (2+256)/((2^2-2+2)*(2+1)) 21.5
      258  /(    4    *  3  ) 
  ? (2+256)/((2^2-2+3)*2)+1   26.8
      258  /       10    +1
  ? 2+(256/((2^2-2)+2*(2+1))) 34
    2+(256/   (2   +   6)

  = Equal          <> Unequal 

  > Greater than   >= Greater than or equal
  < Less than      <= Less than or equal

ABS  Absolute Value

ABS: (-6.25)=6.25  ABS: (0)=0  ABS: (6.25)=6.25
SGN: (-6.25)=-1    SGN: (0)=0  SGN: (6.25)=1
INT  Truncate to Integer (rounded down)
INT: (0)=0      INT: (50)=50   INT: (-56)=-56   
INT: (6.99.)=6  INT: (6.25)=6  INT: (-6.25)=-7 
SQR: Square Root  SQR: (6.25)=2.5               
SIN: (?/3)=0.866025404 radians (?=3.14159..)
COS: (?/3)=0.5
TAN: (?/3)=1.73205081
ATN  Arc Tan
ATN: (1)=0.785398163=?/4
       (Deg=R*360/? & R=Deg*?/360)
EXP  Exponent
EXP (6.25)=518.012825 (e = 2.71828183...)
LOG (6.25)=1.83258146
RND Seed<ABS: (0) = RND generator ON
RND(-625)=3.85114436E-06 
N=INT(RND(1)*(Y+1-X)+X):(random nos. X to Y)
DEF FN= Define a BASIC Function or Subroutine 
DEF FN=SI(A)=SIN(X)/Y   DEF FN =SI(?/3)=0.81699
================================================
[8]***LOGIC OPERATORS***
Boolean results use Integers.
TRUE   -1   (3<>6)
FALSE   0   (33<4)
AND  IF A>B AND C<=D GOTO xxx -done if both true
     12 AND 10 = 8(1100AND1010=1000)
OR   IF A>B OR C<=D GOTO xxx done if either true
     12 OR 10  = 14(1100OR1010=1110)
NOT  NOT 2 = -3(NOT 0002 = FFFD) 
================================================
================================================
[9]***GRAPHICS COMMANDS***
SCREEN 1 - Portrait or Landscape -but not both.
Portrait - X=0-767  Y=0-1023(Title Bar hides 0-63)
Landscape- Y=0-767  X=0-1023(Title Bar hides 0-63)   
    X Axis: L.to R.  Y Axis: Top to Bottom

Standard Variables used below

C=colour   F=flag(0{def.}/1=filled) Rad=radius
L=left     R=right      U=up        D=down
UL=up&L   UR=up&R      DL=down&L   DR=down&R

CSET I,R,G,B,A  I>15 (if used in Draw Commands)

Red,Green,Blue,A-transparency (all 0-255)
   10 SCREEN 1 : CLS: CSET 100,255,0,0,12
   30 CIRCLE 160,200,100,1,100
   40 GOTO 40

SLEEP T -waits T*0.001secs -CPU in sleep mode

TITLE   "My Title!": Graphics Title Bar.
         Hide/show bar: 2-finger touch
ANTIALIAS(X)  Smooths lines/curves
              0=disable 1=enable(default)

COMMODORE COLOURS(C=0-15)

  0 WHITE  4 BLACK    8 ORANGE   12 GREY
  1 RED    5 PURPLE   9 BROWN    13 Lt.GREEN
  2 GREEN  6 YELLOW  10 Lt.RED   14 Lt.BLUE
  3 BLUE   7 CYAN    11 Dk.GREY  15 Lt.GREY

MOVET X,Y  200,400:Move current point to

           X,  Y   (without drawing)
PSET X,Y,C  160,200,1 -pixel position,col.
LSET A,B    4,1 -pixel width,end shape
              0=Square   [default]
              1=Rounded (X.......Y)
              2=Squared [X.......Y]
LINE XS ,YS ,XE ,YE , C  S=start  E=end
     160,200,260,300, 2
LINETO X,Y,C from current point to X,Y
ARC  160,200,100,0,45,1,1
     X,Y,Rad,start/end angle(deg),C,F
CIRCLE  160,200,100,1,1
        centre X,Y,Rad,C,F{1=filled}
RECT  160,200,260,300,2,1  coloured rectangle
      XUL,YUL,XDR,YDR,C,F  L.Top,R.Bott. corners
ELLIPSE  160,200,300,300,3,1
         XUL,YUL,XDR,YDR,C,F
         rectangle limits L.Top,R.Bott. corners
FRAME    160,200,260,300,1,0  outlined rectangle
         XUL,YUL,XDR,YDR,C,F  L.Top,R.Bott.
TRIANGLE 160,200,260,300,360,200,1,1
         red filled triangle
         XDL,YDL,XU,YU,XDR,YDR,C,F
         <-    3 corners    ->
POLYGON  160,230,100,5,0,1,0 
         red frame,5 sides.
         X,Y-centre,Rad,Sides(3-20)
         rotation{0-360deg:0=nil}, C, F
STAR  160,230,120,40,5,0,6,0
      yellow frame,5 vertexes -centre X,Y,
      Rad outer,>Rad inner,vertexes(3-20),
      rotation(0-360),C,F
FSET "Courier",16
     "font name", size (recommended 16-24 pt.)
      to list FONTS (Direct Cmd see above)
GPRINT  "Hello World!", 160, 200, 2
         string,X,Y(lower left position),C
DRAW  "BM 100,100 C1 R2 0U 20 L20 D20"
        String of Parameters
       BM X,Y C RP UP LP DP
        B move, does not draw
          affects next command only
        M move to X,Y{+/- X/Y
          relative to last point}
        N draw & return to start X,Y
          from current point(last reached)
        P(Integer) no.of pixels to draw
        RP:pixels right,   EP:pixels up&right,
        LP:  "    left,    FP:  "    down&right,
        UP:  "    up,      GP:  "    down&left,
        DP:  "    down,    HP:  "    up&left,
BEGINFRAME: Begin Drawing into frame
            all draws are buffered, until-
ENDFRAME:   End Drawing into frame
            all buffered draws are screened
================================================
================================================
[10]***MEMORY ACCESS*** (not available on iPad!)
PEEK: PEEK(53280)=Current Frame ?
POKE: POKE 53280, 7 (Yellow Frame);POKE S+20,X
================================================


Monday, July 8, 2013

Your first Graphics Program

How to make my first graphics program?

Simplest graphics program has three parts:
1- Show the graphics screen
    to show graphics screen use SCREEN 1 command

2- Make your drawings
    invoke one or more drawing commands e.g. CIRCLE

3- Wait for some time in order to see the graphics before going back to text screen
    (text screen is restored automatically when program ends)
   you can for example use SLEEP command or make an infinite loop using GOTO command

Example:
    10 SCREEN 1
    20 CIRCLE 160, 200, 100, 1, 1
    30 SLEEP 10000
(the program ends after 10 seconds)


you can replace line 30 with:
    30 GOTO 30
(to stop the program the user has to tap on break button)

other choice will be using SLEEP and GOTO together
    30 SLEEP 200 : GOTO 30
(to stop the program the user has to tap on break button)

final resort is waiting user to tap some key on virtual keyboard
    30 GET K$
    40 IF K$ = "" THEN 30
(of course you can mix methods as needed)
Note: sample programs demonstrate using these methods.

Thursday, June 20, 2013

New Release v1.6.3

Whats New in v1.6.3
- Added Custom Keyboard keys for iPads
- Minor Fixes



Have Fun!

Thursday, May 30, 2013

New Release v1.6.2

Whats New in v1.6.2
- Document Interaction (Document Importing)
- iTunes File Sharing
- Fixed another Clearing issue with SCREEN 2

Now you can import BASIC programs from other Apps into CBM Hand BASIC easily!

Hint: to export a file from BASIC you can use EXPORT "filename" command.

Tuesday, May 28, 2013

Shared Program


From Jack.

Full Code:

10 SCREEN 2
20 DR=3.1415/180 
30 R=600
40 FOR S=0 TO 360 STEP 10
45 FOR E=20 TO 340 STEP 10
50 XS=R*COS(S*DR)
60 YS=R*SIN(S*DR)
70 XE=R*COS(E*DR)
80 YE=R*SIN(E*DR)
90 XP=1000+XP 
95 YP=500-YP 
100 MOVETO XS+1000,750-YS
103 LINETO XE+1000,750-YE ,4
110 NEXT
115 NEXT
120 GET A$ 
130 IF A$="" THEN 120



Thursday, May 16, 2013

New Release v1.6.1

Released CBM Hand BASIC v1.6.1

What's New in v1.6.1

+ Added Help button
+ iPad: Added Blog and FAQ's buttons
+ Fixed CLS after using SCREEN 2 issue

Monday, April 29, 2013

Baseball Game-Shared Program (1)

Narrative Baseball game by Jonathan Schor:
  It is a version of my baseball simulation program I originally wrote several decades ago for the C-64. Some of the features are not implemented - it is capable of a running narrative of a baseball game. It is a good example of what you can do with this basic program.
  I really do appreciate this implementation of BASIC for the iPad. I hope it proves popular as it is certainly the easiest language which really works.

full source:

10 REM BASEBALL SIMULATION
20 REM BY JONATHAN D. SCHOR.  W2IZM
30 N = 64
40 DIM AB(20)
50 DIM ST(20)
60 DIM L$(15)
70 DIM N$(10)
80 DIM P$(10)
90 DIM O%(30)
100 REM NUMBER OF TEAMS MUST BE DIVISABLE BY 4
110 REM COLOR 0,7
120 L$(0) = " Hits             "
130 L$(1) = " Walks            "
140 L$(2) = " Singles          "
150 L$(3) = " Doubles          "
160 L$(4) = " Triples          "
170 L$(5) = " HOME RUN         "
180 L$(6) = " Strike Outs      "
190 L$(7) = " Double Play      "
200 L$(8) = " Sacrifice        "
210 REM RANDOMIZE TIMER
220 REM
230 PRINT CHR$(12)
240 REM
250 DIM A$(13),S$(1,13),S(1,13),Q(1,5),Q$(N,13)
260 DIM SC(1,100),P(1,10),B(4)
270 REM
280 REM
290 REM
300 REM
310 REM
320 REM
330 REM
340 REM
350 FOR I = 1 TO N
360 REM
370 FOR J = 0 TO 13 : READ Q$(I,J)
380 NEXT J
390 NEXT I
400 CLS
410 REM
420 REM
430 REM
440 CLS
450 PRINT
460 FOR I = 1 TO N STEP 4
470 FOR J = 0 TO 3
480 PRINT I+J;Q$((I+J),1)
490 NEXT J
500 PRINT
510 NEXT I
520 PRINT
530 PRINT "Input away , home team numbers"
540 PRINT
550 INPUT A,H
560 QQA = A
570 QQH = H
580 Q1H = H
590 Q2A = A
600 PRINT CHR$(12)
610 REM PRINT "Enter the home team crowd factor   3 is normal"
620 REM
630 REM
640 REM
650 REM
660 REM
670 REM
680 REM
690 REM
700 REM INPUT FF
710 REM IF FF = 0 THEN FF = 3
720 PRINT CHR$(12)
730 REM
740 REM
750 N$(0) = Q$(A,1) : N$(1) = Q$(H,1)
760 P$(0) = Q$(A,9) : P$(1) = Q$(H,9)
770 FOR J = 1 TO 13
780 S(0,J) = VAL(Q$(A,J))
790 S(1,J) = VAL(Q$(H,J))
800 NEXT J
810 X = 0 : Y = 1 : GOSUB 840
820 X = 1 : Y = 0 : GOSUB 840
830 GOTO 1040
840 REM TO GENERATE TEAM PLAYING STATISTICS
850 X1 = S(X,2)+S(X,7) : REM MEN AT PLATE
860 X2 = S(X,3)+S(X,7) : REM MEN ON BASE
870 X3 = X2/X1 : REM % OF MEN ON BASE TO AT PLATE
880 Y1 = (S(Y,10)*3)+S(Y,11)+S(Y,12) : REM NUMBER OF BATTERS FACES
890 Y2 = S(Y,11)+S(Y,12) : REM BATTERS WHO REACHED BASE
900 Y3 = Y2/Y1 : REM % OF ON BASE PERCENTAGE
910 Q(X,0) = (X3+Y3)/2
920 X4 = X1-X2 : REM MEN OUT
930 Y4 = Y1-Y2 : REM MEN OUT
940 X5 = S(X,8)/X4 : REM % OF K'S
950 Y5 = S(Y,13)/Y4 : REM % OF K'S
960 Q(X,1) = (X5+Y5)/2
970 X6 = S(X,7)/X2 : REM % OF BB
980 Y6 = S(Y,12)/Y2 : REM % OF BB
990 Q(X,2) = (X6+Y6)/2
1000 Q(X,3) = (S(X,4)/X2)+Q(X,2)
1010 Q(X,4) = (S(X,5)/X2)+Q(X,3)
1020 Q(X,5) = (S(X,6)/X2)+Q(X,4)
1030 RETURN
1040 REM
1050 REM
1060 REM
1070 REM
1080 REM
1090 IN = 0 : O = 0
1100 TB = 0
1110 R = RND(1)
1120 GOSUB 2730 : IF FL = 99 THEN 2370
1130 IF TB = 0 THEN R = R+(FF/100)
1140 AB(TB) = AB(TB)+1
1150 B(4) = 0 : FOR I = 1 TO 3 : B(4) = B(4)+B(I) : NEXT I
1160 IF R > Q(TB,0) THEN 1870 : REM MAN IS OUT
1170 R = RND(1)
1180 IF R > Q(TB,5) THEN H = 1 : GOTO 1230 : REM SINGLE
1190 IF R > Q(TB,4) THEN H = 4 : GOTO 1230 : REM HOME RUN
1200 IF R > Q(TB,3) THEN H = 3 : GOTO 1230 : REM TRIPLE
1210 IF R > Q(TB,2) THEN H = 2 : GOTO 1230
1220 H = 0 : GOTO 1260 : REM WALK
1230 P(TB,0) = P(TB,0)+1
1240 P(TB,H+1) = P(TB,H+1)+1
1250 ON H GOTO 1390,1610,1690,1760
1260 REM WALK
1270 IF H = 0 THEN AB(TB) = AB(TB)+(-1)
1280 P$ = " walks                           "
1290 P(TB,1) = P(TB,1)+1
1300 B(1) = 1 : ON B(4)+1 GOTO 2370,1310,1340,1370
1310 REM 1 MAN ON BASE
1320 IF B(2)+B(3) = 0 THEN B(2) = 1 : GOTO 2370
1330 GOTO 2370
1340 REM 2 ON BASE
1350 IF B(2)+B(3) = 2 THEN 2370
1360 B(2) = 1 : B(3) = 1 : GOTO 2370
1370 REM 3 MEN ON BASE
1380 GOSUB 1830 : GOTO 2370
1390 REM SINGLE
1400 IF RND(I) < 0.333 THEN P$ = " single to left             " : GOTO 1450
1410 IF RND(I) < 0.333 THEN P$ = " single to right              " : GOTO 1450
1420 IF RND(I) < 0.333 THEN P$ = " single to center           " : GOTO 1450
1430 IF RND(I) < 0.9 THEN P$ = " infield single                 " : GOTO 1450
1440 P$ = " bunt single                       "
1450 B(1) = 1
1460 ON B(4)GOTO 1480,1560,1590
1470 GOTO 2370
1480 REM ONE ON BASE
1490 IF B(3) = 1 THEN B(3) = 0 : GOSUB 1830 : GOTO 2370
1500 FL = 0
1510 IF B(2) = 1 AND RND(1) < 0.3 THEN GOSUB 1830 : FL = 1
1520 IF FL = 1 THEN B(2) = 0 : B(3) = 1 : GOTO 2370
1530 IF B(2) = 1 THEN B(2) = 0 : B(3) = 1 : GOTO 2370
1540 IF R > 0.5 THEN B(3) = 1 : GOTO 2370
1550 B(2) = 1 : GOTO 2370
1560 REM TWO ON BASE
1570 IF B(2) = 1 THEN B(2) = 0
1580 B(3) = 1 : GOSUB 1830 : GOTO 2370
1590 REM THREE ON BASE
1600 B(2) = 0 : B(3) = 1 : GOSUB 1830 : GOSUB 1830 : GOTO 2370
1610 REM DOUBLE
1620 IF RND(I) < 0.333 THEN P$ = " double to left    " : GOTO 1660
1630 IF RND(I) < 0.333 THEN P$ = " double to right   " : GOTO 1660
1640 IF RND(I) < 0.8 THEN P$ = "double to center  " : GOTO 1660
1650 P$ = " ground rule double      "
1660 IF B(4) = 0 THEN B(2) = 1 : GOTO 2370
1670 FOR I = 1 TO B(4) : GOSUB 1830 : NEXT I : B(2) = 1
1680 B(1) = 0 : B(3) = 0 : GOTO 2370
1690 REM TRIPLE
1700 IF RND(I) < 0.5 THEN P$ = " triple to right    " : GOTO 1720
1710 P$ = " triple to left       "
1720 IF B(4) = 0 THEN B(3) = 1 : GOTO 2370
1730 FOR I = 1 TO B(4) : GOSUB 1830 : NEXT I
1740 B(1) = 0 : B(2) = 0 : B(3) = 1 : GOTO 2370
1750 B(1) = 0 : B(3) = 0 : GOTO 2370
1760 REM HOME RUN
1770 IF RND(I) < 0.333 THEN P$ = " Home Run to left      " : GOTO 1810
1780 IF RND(I) < 0.666 THEN P$ = " Home Run to right     " : GOTO 1810
1790 IF RND(I) < 0.99 THEN P$ = " Home Run to center    " : GOTO 1810
1800 P$ = " Inside the Park Home Run       "
1810 FOR I = 1 TO 3 : B(I) = 0 : NEXT I
1820 FOR I = 1 TO B(4)+1 : GOSUB 1830 : NEXT I : GOTO 2370
1830 REM SCORING ROUTINE
1840 SC(TB,INT(IN)) = SC(TB,INT(IN))+1 : ST(TB) = ST(TB)+1
1850 IF TB = 1 THEN GOSUB 2730
1860 RETURN
1870 REM OUT ROUTINE
1880 FL = 0
1890 IF RND(1) < Q(TB,1) THEN FL = 1
1900 IF FL = 0 THEN 1950
1910 IF RND(I) < 0.8 THEN P$ = " strikes out      " : GOTO 1930
1920 P$ = " strikes out swinging      "
1930 P(TB,6) = P(TB,6)+1
1940 GOTO 2310
1950 REM
1960 IF RND(I) < 0.3 THEN P$ = " flys out to right        " : GOTO 2120
1970 IF RND(I) < 0.3 THEN P$ = " flys out to left         " : GOTO 2120
1980 IF RND(I) < 0.3 THEN P$ = " flys out to center       " : GOTO 2120
1990 IF RND(I) < 0.3 THEN P$ = " grounds out to first    " : GOTO 2120
2000 IF RND(I) < 0.3 THEN P$ = " grounds out to second   " : GOTO 2120
2010 IF RND(I) < 0.3 THEN P$ = " grounds out to short    " : GOTO 2120
2020 IF RND(I) < 0.3 THEN P$ = " grounds out to third    " : GOTO 2120
2030 IF RND(I) < 0.3 THEN P$ = " grounds out to right    " : GOTO 2120
2040 IF RND(I) < 0.3 THEN P$ = " grounds out to center   " : GOTO 2120
2050 IF RND(I) < 0.3 THEN P$ = " grounds out to left     " : GOTO 2120
2060 IF RND(I) < 0.5 THEN P$ = " fouls out to catcher    " : GOTO 2120
2070 IF RND(I) < 0.5 THEN P$ = " fouls out to first      " : GOTO 2120
2080 IF RND(I) < 0.5 THEN P$ = " fouls out to third      " : GOTO 2120
2090 IF RND(I) < 0.5 THEN P$ = " fouls out to short      " : GOTO 2120
2100 IF RND(I) < 0.5 THEN P$ = " fouls out to second     " : GOTO 2120
2110 P$ = " fouls out to left       "
2120 IF B(4) > 1 AND O < 2 THEN IF RND(1) > 0.8 THEN FL = 1
2130 IF FL = 0 THEN 2230
2140 REM
2150 P(TB,8) = P(TB,8)+1
2160 P$ = " sacrifice             "
2170 ON B(4)GOTO 2180,2190,2220
2180 IF B(3) = 1 THEN B(3) = 0 : GOSUB 1830 : GOTO 2310
2190 IF B(3) = 0 THEN B(3) = 1 : B(1) = 0 : GOTO 2310
2200 IF B(2) = 0 THEN GOSUB 1830 : B(3) = 1 : B(2) = 1 : B(1) = 0 : GOTO 2310
2210 B(2) = 0 : GOSUB 1830 : GOTO 2320
2220 B(1) = 0 : GOSUB 1830 : GOTO 2320
2230 REM CK FOR DOUBLE PLAY
2240 IF O < 2 AND B(4) > 1 AND RND(1) > 0.8 THEN FL = 1 : P$ = " double play       "
2250 IF FL = 0 THEN 2310
2260 O = O+1 : O%(TB) = O%(TB)+1
2270 P(TB,7) = P(TB,7)+1
2280 IF B(3) = 1 THEN B(3) = 0 : GOTO 2310
2290 IF B(2) = 1 THEN B(2) = 0 : GOTO 2310
2300 B(1) = 0 : GOTO 2310
2310 FL = 0
2320 O = O+1 : O%(TB) = O%(TB)+1
2330 IF O > 2 THEN TB = TB+1 : IN = IN+0.5
2340 IF O > 2 THEN GOSUB 2730
2350 IF O > 2 THEN FOR I = 1 TO 3 : B(I) = 0 : NEXT I : O = 0
2360 IF O = 0 AND TB = 2 THEN TB = 0
2370 REM PRINT OUT ROUTINE
2380 CLS
2390 PRINT N$(0);"  at  ";N$(1),Q2H;Q1A
2400 PRINT
2410 OX = O%(0)
2420 OX = OX/3
2430 OX = INT(OX)
2440 PRINT P$(0);" vs ";P$(1),"  Inning  ";OX : PRINT
2450 FOR I = 0 TO 1
2460 IF I = 0 THEN PRINT "Visitor",
2470 IF I = 1 THEN PRINT "Home   ",
2480 A1 = 0 : A2 = 8 : IF O%(0) > 27 THEN A1 = 9 : A2 = 17
2490 FOR J = A1 TO A2
2500 PRINT SC(I,J);
2510 GOTO 2530
2520 IF B(3) = 1 THEN PRINT M$ ELSE PRINT MM$;
2530 REM
2540 NEXT J
2550 PRINT ,
2560 PRINT ST(I);P(I,0)
2570 NEXT I
2580 PRINT
2590 REM PRINT B(1);B(2);B(3),P$
2600 PRINT P$
2610 PRINT
2620 PRINT ,"           V   H     OUTS",O
2630 PRINT
2640 PRINT " At Bats          ";AB(0);AB(1)
2650 FOR I = 0 TO 8
2660 PRINT L$(I);P(0,I);" ";P(1,I)
2670 NEXT I
2680 IF FL = 99 THEN PRINT : GOTO 2890
2690 P$ = ""
2700 GOSUB 2730
2710 H = 0 : GOTO 1110
2720 PRINT Q(0,0),Q(1,0)
2730 REM CHECK FOR GAME OVER ROUTINE
2740 IF O%(0) < 27 THEN RETURN
2750 IF ST(1) > ST(0) AND O%(1) < O%(0) THEN FL = 99 : GOTO 2370
2760 IF O%(1) = O%(0) AND ST(0) > ST(1) THEN FL = 99 : GOTO 2370
2770 RETURN
2780 REM
2790 REM
2800 REM
2810 REM
2820 REM
2830 FOR J = 0 TO 1 : FOR K = 1 TO 100 : SC(J,K) = 0 : NEXT K
2840 FOR K = 0 TO 10 : P(J,K) = 0 : NEXT K : O%(J) = 0 : AB(J) = 0
2850 ST(J) = 0 : NEXT J
2860 FOR I = 1 TO 4 : B(I) = 0 : NEXT I
2870 FL = 0
2880 REM
2890 X$ = ""
2900 PRINT "r = run again;   s = stop program"
2910 INPUT X$
2920 IF X$ = "r" OR X$ = "R" THEN RUN
2930 IF X$ = "s" OR X$ = "S" THEN STOP
2940 GOTO 2910
2950 END
2960 REM
2970 REM
2980 DATA 1,"Chicago      .A01",4725,1303,173,89,32,475,375
2990 DATA "Clark Griffith",267,275,50,67
3000 DATA 2,"Pittsburgh.N01",4913,1407,182,92,28,386,286
3010 DATA "Deacon Phillippe",296,274,38,103
3020 DATA 3,"Philadelphia.A02",4762,1369,235,67,38,343,343
3030 DATA "Rube Waddell",276,224,64,210
3040 DATA 4,"Pittsburgh.N02",4976,1410,189,94,19,372,372
3050 DATA "Jack Chesbro",286,242,62,136
3060 DATA 5,"Boston    .A03",4919,1336,222,113,48,262,262
3070 DATA "Cy Young",342,294,37,176
3080 DATA 6,"Pittsburgh.N03",4991,1430,208,110,34,364,364
3090 DATA "Sam Leever",284,255,60,90
3100 DATA 7,"Detroit   .A08",5109,1347,199,86,19,320,320
3110 DATA "Ed Summers",301,271,55,103
3120 DATA 8,"Chicago   .N08",5085,1267,197,56,19,418,418
3130 DATA "Three Finger Brown",312,214,49,123
3140 DATA 9,"Detroit   .A09",5095,1360,209,58,19,387,387
3150 DATA "George Mullin",304,258,78,124
3160 DATA 10,"Pittsburgh.N09",5129,1332,218,92,25,479,479
3170 DATA "Howie Cannitz",283,207,68,133
3180 DATA 11,"Philadelphia.A10",5167,1376,194,106,19,409,409
3190 DATA "Jack Coombs",353,248,115,224
3200 DATA 12,"Chicago  .N10",4977,1333,219,84,34,542,501
3210 DATA "Three Finger Brown",295,258,64,143
3220 DATA 13,"Philadelphia.A10",5167,1376,194,106,19,409,409
3230 DATA "Jack Coombs",353,248,115,224
3240 DATA 14,"Chicago   .N10",4977,1333,219,84,34,542,501
3250 DATA "Three Finger Brown",295,256,64,143
3260 DATA 15,"New York  .N11",5006,1399,225,103,41,530,506
3270 DATA "Christy Mathewson",307,303,38,141
3280 DATA 16,"Indianapolis.F14",5176,1474,230,90,33,470,470
3290 DATA "Cy Falkenberg",377,332,89,236
3300 DATA 17,"Chicago   .F15",5133,1320,185,77,50,444,444
3310 DATA "George McConnell",303,262,89,151
3320 DATA 18,"Boston   .A18",3982,990,159,54,15,406,324
3330 DATA "Carl Mays",293,230,81,114
3340 DATA 19,"St. Louis      .A22",5416,1693,291,94,98,473,381
3350 DATA "Urban Shocker",255,240,85,92
3360 DATA 20,"Washington.A24",5304,1558,255,88,22,513,392
3370 DATA "Walter Johnson",278,233,77,158
3380 DATA 21,"New York      .A27",5337,1578,269,79,133,562,544
3390 DATA "George Pipgras",301,314,103,139
3400 DATA 22,"Pittsburgh.N27",5397,1648,258,78,54,437,355
3410 DATA "Carmen Hill",278,260,80,95
3420 DATA 23,"Detroit   .A40",5418,1549,312,65,134,684,556
3430 DATA "Bobo Newsom",264,235,100,164
3440 DATA 24,"St. Louis.A44",5269,1328,223,45,72,531,604
3450 DATA "Nels Potter",232,211,70,91
3460 DATA 25,"St. Louis.N44",5475,1507,274,59,100,544,473
3470 DATA "Mort Cooper",252,227,60,97
3480 DATA 26,"Chicago  .N45",5298,1465,229,52,57,554,482
3490 DATA "Hank Wyse",278,272,55,77
3500 DATA 27,"Boston   .A46",5318,1441,268,50,109,687,681
3510 DATA "Boo Ferris",274,274,71,106
3520 DATA 28,"Cleveland .A54",5222,1368,188,39,156,637,668
3530 DATA "Bob Lemon",258,228,92,110
3540 DATA 29,"Milwaukee .N58",5225,1388,221,21,167,478,646
3550 DATA "Warren Spahn",290,257,76,150
3560 DATA 30,"San Francisco.N62",5588,1552,235,32,204,523,822
3570 DATA "Jack Sanford",265,233,92,147
3580 DATA 31,"Los Angeles.N63",5428,1361,178,34,110,453,867
3590 DATA "Sandy Koufax",311,214,58,300
3600 DATA 32,"Baltimore.A66",5529,1426,243,35,175,514,926
3610 DATA "Jim Palmer",208,176,91,147
3620 DATA 33,"Boston   .A67",5471,1394,216,39,158,522,1020
3630 DATA "Jim Longborg",273,228,83,248
3640 DATA 34,"St. Louis.N67",5566,1462,225,40,115,443,919
3650 DATA "Bob Gibson",175,151,40,147
3660 DATA 35,"Baltimore    .A69",5518,1465,234,29,175,634,806
3670 DATA "Mike Cuellar",291,213,79,182
3680 DATA 36,"Minnesota     .A69",5677,1520,246,32,163,599,906
3690 DATA "Jim Perry",262,244,66,153
3700 DATA 37,"New York  .N69",5427,1311,184,41,109,527,1089
3710 DATA "Tom Seaver",273,202,82,208
3720 DATA 38,"Atlanta      .N69",5460,1411,195,22,141,485,665
3730 DATA "Phil Niekro",284,235,57,193
3740 DATA 39,"Oakland   .A73",5507,1430,216,28,147,595,919
3750 DATA "Catfish Hunter",256,222,69,124
3760 DATA 40,"New York  .N73",5457,1345,198,24,85,540,805
3770 DATA "Tom Seaver",290,219,64,251
3780 DATA 41,"Detroit   .A87",5649,1535,274,32,225,653,913
3790 DATA "Jack Morris",266,227,93,208
3800 DATA 42,"Boston      .A88",5545,1569,310,39,124,623,728
3810 DATA "Roger Clemens",264,217,62,291
3820 DATA 43,"New York   .N88",5408,1387,251,24,152,544,842
3830 DATA "David Cone",231,178,80,213
3840 DATA 44,"Los Angeles .N88",5431,1346,217,25,99,437,947
3850 DATA "Orel Hershiser",267,208,73,178
3860 DATA 45,"Oakland    .A89",5416,1414,220,25,127,562,855
3870 DATA "Dave Stewart",258,260,69,155
3880 DATA 46,"San Francisco.N89",5489,1365,241,52,141,508,1071
3890 DATA "Rick Reuschel",208,195,54,111
3900 DATA 47,"Toronto     .A91",5489,1412,295,45,133,499,1043
3910 DATA "Todd Stottlemyre",219,194,75,116
3920 DATA 48,"Minnesota.A91",5470,1390,236,26,79,449,888
3930 DATA "Scott Erickson",204,159,71,108
3940 DATA 49,"Pittsburgh .N91",5449,1433,259,50,126,620,901
3950 DATA "John Smiley",208,194,44,129
3960 DATA 50,"Atlanta   .N91",5458,1407,255,30,141,563,906
3970 DATA "Tom Glavine",247,201,69,192
3980 DATA 51,"Texas        .A94",3983,1114,198,27,124,437,730
3990 DATA "Kenny Rogers",187,169,52,120
4000 DATA 52,"Chicago  .A93",5483,1454,228,44,162,604,834
4010 DATA "Jack McDowell",257,261,69,261
4020 DATA 53,"Philadelphia.N93",5635,1555,297,61,156,665,1049
4030 DATA "Tommy Greene",200,175,62,167
4040 DATA 54,"Cleveland.A 1",5800,1559,294,37,22,577,1076
4050 DATA "Jamie Moyer",210,187,44,119
4060 DATA 55,"Houston  .N 1",5528,1500,313,29,208,581,1119
4070 DATA "Wade Miller",212,183,76,183
4080 DATA 56,"Arizona     .N 1",5595,1494,284,35,208,587,1052
4090 DATA "Curt Schilling",257,237,39,293
4100 DATA 57,"Oakland  .A 2",5558,1450,279,28,205,609,1008
4110 DATA "Barry Zito",229,182,78,182
4120 DATA 58,"Atlanta  .N 2",5495,1428,280,25,164,558,1026
4130 DATA "Tom Glavine",225,210,78,127
4140 DATA 59,"St. Louis.N 2",5505,1475,285,26,175,542,927
4150 DATA "Matt Morris",210,210,64,171
4160 DATA 60,"New York   .A 2",5601,1540,314,12,223,640,1171
4170 DATA "David Wells",206,210,45,137
4180 DATA 61,"Boston     .A 2",5640,1580,343,33,177,545,944
4190 DATA "Pedro Martinez",199,144,40,239
4200 DATA 62,"Minnesota .A 2",5582,1518,348,36,167,472,1089
4210 DATA "Rick Reed",188,192,26,121
4220 DATA 63,"Boston    .A 3",5769,1667,371,40,238,620,943
4230 DATA "Derek Lowe",1465,1503,488,1141
4240 DATA 64,"Chicago   .N 3",5519,1431,302,24,172,492,1158
4250 DATA "Mark Prior",1456,1307,617,1404


Thursday, March 21, 2013

Text Wave-Example (2)


This program teaches the basics of animation by animating text with sine wave. To keep program simple I made many parameters fixed.

Things to try:
- change the animated text or better make the user enter the text (LINE 50)
- change sine wave magnitude (LINE 2020)
- change the animation resolution D (LINE 1130)
- change the wave frequency F (LINE 1120)

full program:

10 SCREEN 1
20 TITLE "Text Wave"
30 W = 1024
40 H = 768-20
50 T$ = "CBM Hand BASIC"
60 L = LEN(T$)
70 DIM CC(5)
80 CC(0) = 3
90 CC(1) = 1
100 CC(2) = 6
110 CC(3) = 3
120 CC(4) = 2
130 CC(5) = 1
140 DIM P(20, 3)
150 FSET "Commodore_64_Angled", 64
1000 C = 0
1010 FOR I = 0 TO L-1
1020 E$ = MID$(T$, I+1, 1)
1030 P(I, 0) = ASC(E$)
1040 P(I, 1) = CC(C)
1050 P(I, 2) = 180 + 50 * I
1060 P(I, 3) = 0
1070 IF P(I, 0) <> 32 THEN C = C + 1 
1080 IF C = 6 THEN C = 0
1090 NEXT I
1100 PI = 3.14159
1110 T = PI * 3/4
1120 F = PI / 8
1130 D = PI / 220
2000 REM [WAVE MOVE]
2010 FOR I = 0 TO L-1
2020 P(I, 3) = H/2 + 120*SIN(T - F * I)
2030 T = T + D
2040 IF T >= 2*PI THEN T = T - 2 * PI
2050 NEXT I
3000 REM [DRAW]
3010 BEGINFRAME
3020 CLS
3030 FOR I = 0 TO L-1
3040 R$ = CHR$( P(I, 0) )
3050 C = P(I, 1)
3060 X = P(I, 2)
3070 Y = P(I, 3)
3080 GPRINT R$, X, Y, C
3090 NEXT I
3100 ENDFRAME
4000 GOTO 2000

Friday, March 8, 2013

Polar Plotter-Example (1)


This program plots polar functions of the form
radius = f(angle)
Program settings are made for iPad. To run on iPhone/iPod Touch change:
W = 320
H = 460
U = 20

change line 160 to plot other polar functions
160 DEF FN F(T) = 5
160 DEF FN F(T) = T / (2 * PI)
160 DEF FN F(T) = 5 * SIN(4 * T)
160 DEF FN F(T) = 4 * SIN(6 * T) + 4

to understand math behind polar plotting I recommened Wikipedia: Go Wiki

full program:

10 REM POLAR PLOT PROGRAM
20 REM INIT
30 SCREEN 1
40 W = 768
50 H = 1024-20
60 U = 40
70 XC = W / 2
80 YC = H / 2
90 DEF FN MX(X) = XC + X * U
100 DEF FN MY(Y) = YC - Y * U
110 S = 1 / U
120 PI = 3.1415926
130 REM DRAW AXIS
140 GOSUB 1000
150 REM SET PARAMETERS
160 DEF FN F(T) = 5*SIN(6*T)-1
170 C = 3
180 TS = 0
190 TF = 2 * PI
200 GPRINT "r = 5 sin(6 theta)-1", 10, 80, C
210 REM PLOT
220 GOSUB 2000
230 SLEEP 15000
240 END
1000 REM [DRAW AXIS]
1010 CLS
1020 N = INT(XC / U)
1030 FOR I = 1 TO N
1040 CIRCLE XC, YC, I * U, 15, 0
1050 NEXT I
1060 LINE XC, 0, XC, H, 1
1070 LINE 0, YC, W, YC, 1
1080 RETURN
2000 REM [PLOT]
2010 T = TS
2020 R = FN F(T)
2030 X = R * COS(T)
2040 Y = R * SIN(T)
2050 XX = FN MX(X)
2060 IF XX < 0 THEN XX = 0
2070 YY = FN MY(Y)
2080 IF YY < 0 THEN YY = 0
2090 MOVETO XX, YY
2100 T = T + S
2110 R = FN F(T)
2120 X = R * COS(T)
2130 Y = R * SIN(T)
2140 XX = FN MX(X)
2150 IF XX < 0 THEN XX = 0
2160 YY = FN MY(Y)
2170 IF YY < 0 THEN YY = 0
2180 LINETO XX, YY, C
2190 IF T <= TF THEN 2100
2200 FRAME 0, 0, W-1, H-1, 0
2210 RETURN