📄 smallbasic.doc
字号:
Console____________________________\t tab (32 pixels)\a beep\r\n new line (cr/lf)\xC clear screen\e[K clear to EOL\e[0m reset all attributes to their defaults\e[1m set bold on\e[4m set underline on\e[7m reverse video\e[21m set bold off\e[24m set underline off\e[27m set reverse off\e[3nm set foreground color. where n: 0 black 1 red 2 green 3 brown 4 blue 5 magenta 6 cyan 7 white\e[4nm set background color. (see set foreground)PalmOS only:\e[8nm (n=0..7) select system font\e[9nm (n=0..3) select buildin font____________________________?|PRINT [expr|str [{,|;} [expr|str]] ...Displays a text or the valueof an expression.____________________________CAT(x)Returns console codes0 - reset1 - bold on2 - underline on3 - reverse onPalmOS only:80..87 - select system font90..93 - select custom fontExample:? cat(1);"Bold";cat(0)____________________________INPUT [prompt {,|;}] var[, var [, ...]]Reads from "keyboard" a textand store it to variable.____________________________INPUT$(len[,fileN])____________________________CLSClears the screen.____________________________AT x,y (in pixels)Moves the console cursorto the specified position.x,y are in pixels____________________________LOCATE y,xMoves the console cursorto the specified position.x,y are in character cells.File system____________________________Special file names:"COM1:[speed]" - Serial port 1Non PalmOS:"COM2:[speed]" - Serial port 2Example:OPEN "COM1:" AS #1OPEN "COM2:38400" AS #2____________________________FREEFILEReturns an unused filehandle____________________________OPEN "file" [FOR {INPUT| OUTPUT|APPEND}] AS #fileNOpens a file or device____________________________CLOSE #fileN____________________________EXIST(fileName)Returns true if the fileNameexists____________________________EOF(fileN)Returns true if the filepointer is at end of thefile____________________________PRINT #fileN{,|;} var1 [,varN]____________________________LINEINPUT #fileN{,|;} var$____________________________INPUT$(len[,fileN])____________________________SEEK #fileN{,|;} posSets file position forthe next read/write____________________________SEEK(fileN)Returns the current fileposition____________________________LOF(fileN)Returns the length of filein bytesFor devices; returns thenumber of available data____________________________KILL "file"Deletes the specified fileGraphics & Sound____________________________Colors:Mono: 0=black, 15=white, any=gray2bit: 0=black, 15=white 1-6,8=dark-gray, 7,9-14=light-gray4bit: 16 colors of gray8bit: 16 Standard VGA colorsSTEP keyword:The STEP keyword calculatesthe next x,y parameters relative to current position____________________________ARC [STEP] x,y,r, astart,aend[,aspect] [COLOR color]Draws an arcastart,aend = first,lastangle in rads.____________________________CHART {LINECHART|BARCHART} , array() [, {0|1|2|3} [, x1, y1, x2, y2]]Draws a chart of arrayvalues in the rectangulararea x1,y1,x2,y2type:0 = simple1 = with marks2 = with ruler3 = with marks & ruler____________________________CIRCLE [STEP] x,y,r [,aspect] [COLOR color] [FILLED]Draws a circle/ellipse.____________________________COLOR fg [, text_bg]Changes the current pencolor____________________________DRAWPOLY array() [,x-origin ,y-origin [, scalef]] [COLOR color]Draws a polylineeven elements for x (starting from 0)odd elements for y____________________________LINE [STEP] x,y [{,|STEP} x2,y2] [COLOR color]Draws a line____________________________PSET [STEP] x,y [COLOR color]Draw a pixel at x,y position____________________________RECT [STEP] x,y [{,|STEP} x2,y2] [COLOR color] [FILLED]Draws a rectangular parallelogram____________________________TXTW(s), TXTH(s)Returns the text width/height of string sin pixels____________________________BEEPGenerates a beep sound____________________________PLAY stringPlay musical notesA-G[-|+|#][nnn][.] Play note A..G +|# - sharp - - flat . - multiplier 1.5On - Octave 0..6< - Moves down one octave> - Moves up one octaveNnn - Play note 0..84 (0 = pause)Pnnn - Pause 1..64Lnnn - Length of note 1..64 (1/nnn)Tnnn - Tempo 32..255 Number of 1/4 notes per minute.MS - Staccato (1/2)MN - Normal (3/4)ML - LegatoVnnn - Volume 0..100MF - Play on foregroundMB - Play on background____________________________SOUND freq, dur_ms [, vol]Plays a soundMiscellaneous____________________________RANDOMIZE [int]Seeds the random numbergenerator____________________________RNDReturns a random numberfrom the range 0 to 1____________________________LBOUND(array [, dim])UBOUND(array [, dim])Returns the lower/upperbound of the 'array'The parameter 'dim' is thearray dimension whose boundis returnedExample:DIM v1(-4 TO 7)DIM v2(1 TO 2, 3 TO 4)? LBOUND(v1):REM -4? UBOUND(v1):REM 7? LBOUND(v2):REM 1? LBOUND(v2,2):REM 3____________________________CINT(x) - convert x to 32b integerCDBL(x) - convert x to 64b real number____________________________PEN ON|OFFEnables/Disables thePEN/MOUSE mechanism.____________________________PEN(0..14)Returns the PEN/MOUSE data.Values:0 - true (non zero) if there is a new pen or mouse event1 - PEN: last pen-down x; MOUSE: last mouse button down x 2 - Same as 1 for y3 - true if the PEN is down; mouse left-button is pressed4 - PEN: last/current x, MOUSE: the current x position only if the left mouse button is pressed (like PEN is down)5 - Same as PEN(4) for yMouse buttons (non PalmOS):10 - current mouse x pos.11 - current mouse y pos.12 - true if the left mouse button is pressed13 - true if the right mouse button is pressed14 - true if the middle mouse button is pressed____________________________PAUSE [secs]Pauses the execution for aspecified length of time, oruntil user hit the keyboard.Mathematics:____________________________All angles are in RADs.ABS(x) - Absolute value of xCOS(x) - Cosine of xSIN(x) - Sine of xTAN(x) - Tangent of xACOS(x) - Arc cosine of xASIN(x) - Arc sine of xATAN(x) - Arc tangent of xATAN2(x,y) - Arc tangent of two variablesHyperbolic functions:COSH(x), SINH(x), TANH(x)ACOSH(x), ASINH(x), ATANH(x)EXP(x) - the value of e raised to the power of xLOG(x) - natural logarithm of xLOG10(x) - the base-10 logarithm of xPOW(x,y) - x raised to power of ySQR(x) - square root of xINT(x) - rounds x downwards to the nearest integerFIX(x) - rounds x upwards to the nearest integerROUND(x [,decs]) rounds the x to the nearest integer or fp with 'decs' decimal digits.SGN(x) - sign of x +1 for positive, -1 for negative and 0 for zeroDEG(x) - rads to degreesRAD(x) - degrees to rads____________________________MAX(...), MIN(...)Maximum/Minimum value ofparameters. Parameters canbe anything (arrays, ints,reals, strings).Example:? MAX(3,4,8)? MIN(array(),2,3)? MAX("abc","def")____________________________Strings:____________________________LEN(s) - length of stringSPACE$(n) - returns a string of 'n' spacesOCT$(x) - octal value string of xHEX$(x) - hexadecimal value string of xVAL(s) - numeric value of string sSTR$(x) - convert x to stringASC(s) - ASCII code of first character of sCHR$(x) - returns one-char string of character with ASCII code x____________________________LCASE$(s), UCASE$(s)Converts the string s to lower/upper caseExample:? LCASE$("Hi"):REM hi? UCASE$("Hi"):REM HI____________________________LTRIM$(s), RTRIM$(s)Removes leading/trailingspaces from string s? LEN(LTRIM$(" Hi")):REM 2____________________________LEFT$(s,n), RIGHT$(s,n)Returns the n number ofleftmost/rightmost charsof string s____________________________MID$(s, start [,length])Returns the part (length)of the string s startingfrom 'start' positionIf the 'length' parameter isomitted, MID$ returns thewhole string from the pos.'start'.____________________________INSTR([start,] s1, s2)Returns the position of thefirst occurrence of thestring s2 into string s1(starting from the position'start')If there is no match, INSTRreturns 0____________________________STRING$(len,{ascii|str})GenericLimits:____________________________Max. length of code text line: 511 charsMax. keyword length: 32 charMax. num. of parameters: 64Max. arrays dimentions: 4Numeric value range: 64b FPNMax. string size: 32KBMax. number of file handles: PalmOS: 16 Other: 256INPUT/LINEINPUT limit: 255B per call.____________________________Variables:____________________________There is no data types. Alluser variables (includearrays) are 'VARIANT'.SB uses internaly 3 types1. Integer (32bit)2. Real (64bit)3. String (<32KB)Variable names can use anyalphanumeric characters,and the '$'. The first charof the name cannot bea digit.The symbol '$' is supportedfor compatibility. Its useis meanless.For compatibility;the arrays can have thesame names with simplevariables.So x and x() are twodifferent variables.Example:a="123"a$=1? a<>a$REM displays 1 (true)DIM x(10)x=1x(1)=2? x, x(1):REM displays: 1 2____________________________System Variables:____________________________OSVER - OS VersionOSNAME - OS NameSBVER - SmallBASIC VersionPI - 3.14..XMAX,YMAX graphics display max.BPP - Bits per pixel____________________________Operators (by priority):____________________________( ) = parenthesis- = unary^ = power* / \ = mul, div, idiv% MOD = modulus+ - = add, sub=> =< = >= <= <> = compareAND & OR |NOT ! XOR ~ = logical: = EOL____________________________Base convertion:____________________________&H|0x hex. ex: 0x1F + &H1F&o|0o oct. ex: 0o33 = &o33&b|0b bin. ex: 0b11 = &b11____________________________Subroutines/Functions:____________________________SUB name [([BYREF] par1 [, ...[BYREF] parN)]] LOCAL var[, var[, ...]]ENDFUNC name [([BYREF] par1 [, ...[BYREF] parN)]] LOCAL var[, var[, ...]]ENDUse function's nameto return the value.Nested procedures/functionsare allowed (like Pascal).Example:FUNC f(x) FUNC f11 FUNC f21 f21=21 END END FUNC f12 f12=12 END? f11? f21: REM ERRORf=x+f11+fENDThe parameters are 'by value' by default.Use BYREF keyword for'by reference'Use the LOCAL keywordfor local variables.You can send arrays asparameters with ().When using arrays asparameters its betterto use them as BYREF. Example:SUB FV(BYREF tbl())...END' MAINDIM dt(128)...FV dt()On a multi-section applications sub/funcs needsdeclaration on the mainsection.Example:#sec:Maindeclare func f(x)#sec:another sectionfunc f(x)...endPassing & returing arraysExample:func fill(a()) local b(), i dim b(16) for i=0 to 16 b(i)=16-a(i) next fill=b()endDIM v(4)v()=fill(v())____________________________Statements:____________________________'|#|REM ...Remarks.The # can be used as remarksonly in the first pos. ofthe text line.____________________________[LET] var = exprAssign 'expr' to variable'var'.Example:z=1z="Change to string"DIM v(4)v2()=v()z=v():REM make z copy of v()____________________________CONST var = exprAssign 'expr' to variable'var' and make it READ-ONLY.____________________________DIM var( [lower TO] upper [, ...])Creates an array.____________________________[LABEL] labelDefines a label. There aretwo kinds of labels. Numericand alphanumeric.Numeric labels does not needed the keyword LABEL,but alphanumeric does.Example:1000 ? "Hello"LABEL AlphaLabel? "Hello"...GOTO 1000GOTO AlphaLabel____________________________GOTO labelBranches to a specifiedlabel.____________________________GOSUB label - RETURNBranches to a old-stylesubroutine. The subroutinereturns to GOSUB's nextinstruction with RETURN.____________________________ON expr GOTO label-listON expr GOSUB label-listBranches to one of the several locations, dependingof the value of the 'expr'.____________________________FOR var = expr TO expr [STEP expr] - NEXTRepeats a code block fora specified number of times.____________________________WHILE expr - WENDWHILE/WEND code block, loopswhile 'expr' is true.____________________________REPEAT - UNTIL exprREPEAT/UNTIL code block, loops while 'expr' is false.____________________________IF expr [THEN] - [ELSE|ELIF|ELSEIF] - ENDIF|FIExecutes a code blockdepending on specifiedconditions.____________________________IF expr THEN [num-label]|[...] [ELSE [num-label]|[...]]Old-style inline-IFs.____________________________STOP|ENDStops the program execution.____________________________RESTORE labelREAD var[, var ...]DATA n[,n ...]DATA specifies values tobe read by READ.RESTORE specifies theposition of the nextdata to be read.READ reads values fromcurrent data position.Example:RESTORE MyDataBlockFOR I=1 TO 3 READ v PRINT vNEXTENDLABEL MyDataBlockDATA 1,2,3____________________________EXIT [FOR|LOOP|SUB|FUNC]By itself exits from lastcommand block (loop, foror routine)FOR - Exit from the last FOR-NEXT loopLOOP - Exit from the last WHILE/REPEAT loopSUB - Return from the current routineFUNC - Return from the current functionSystem____________________________FRE(0|-1|-2|-3)Returns information aboutsystem memory 0 - free memory-1 - largest block of integers-2 - free stack-3 - largest free block____________________________TICKS() - the system-ticks countTICKSPERSEC() - the number of ticks per second____________________________TIMER - returns the number of seconds from midnightTIME$ - returns the current time as string "HH:MM:SS"DATE$ - returns the current day as string "DD/MM/YYYY"____________________________DELAY msDelay for a specified amountof milliseconds____________________________CHAIN fileRuns another SB programExample:CHAIN "PROG2.BAS"____________________________RUN fileRuns an executablePalmOS: the 'file' is the creator ID ____________________________Debug:____________________________TRON/TROFFTRACE ON/OFF. When tracemechanism is ON, the SBdisplays each line numberas the program is executed____________________________LOGPRINT ...PRINT to SB's logfile____________________________BCDUMP [len]Displays the 'len' nextbytes of byte-code____________________________STKDUMPDisplays the SB's internalexecutor's stack
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -