CB2 micro BASIC programming language reference manual |
| priority | operators |
| highest | * , / , % , # , ^ |
| ... | << , >> |
| ... | + , - , & |
| lowest | = , <> , < , <= , > , >= |
| ABS( | Calculates the absolute value of the bracketed expression |
| SGN( | Computes the sign (-1,0,1) of the parenthesized expression |
| NOT( | inverts the parenthetical expression |
| SQR( | pulls the square root out of the bracketed expression |
| RND( | generates a random number between 0 and the parenthesized expression |
| IN( | returns the level value of the specified port pin (0-7) at the parallel interface, if the parameter value is 255, the port pins are read in as byte, |
| SPI( | outputs a byte via the SPI interface and returns the read-in value |
| TEMP( | returns the temperature value of the specified LM75 sensor (0-7) |
| ADC( | provides the analog value of the voltage of the specified port pin (0-7) at the parallel interface |
| XPEEK( | reads a byte of data from the optional data EEPROM, the parenthetical expression determines the address |
| EPEEK( | reads a data byte from the internal EEPROM, address 0 ... 999 |
| VPEEK( | reads a byte of data from the frame buffer |
| LO( | returns the low byte of the bracketed expression |
| HI( | returns the high byte of the bracketed expression |
| KEY( | provides various keyboard queries, see section Keyboard |
| AR( | Array value (see below) |
| SIN( | returns the sine of the angle (in 1/10 degrees) by 255 |
| COS( | returns the cosine of the angle (in 1/10 degrees) by 255 |
| FTYPE( | see section File Functions |
| FSIZE( | see section File Functions |
| ERR( | Error information, see section Error handling |
| XREC( | reads in a data block via XModem protocol |
| DBIT( | converts font data |
| PSTAT( | Sequencer status, see section Audio |
01 A=-4 |
01 A=-39 |
01 A=-39 >> 1 |
01 LIMIT A,1,6 |
01 V=180 |
Y = Y0 + ((Y1-Y0) * (X-X0) / (X1-X0)) |
01 DATA 0,"Hello",0 |
02 ACOPY 0,1029,10 |
01 DA 0,"Test",0 |
01 DA 100," north east south west" |
01 VM 4:? @0,0;%0;:BORDER 4 |
01 B=0:GOTO 2 |
01 IF A>5 THEN A=5 |
01 CLS |
01 A=0 |
01 REPEAT |
01 GOSUB 4,2,3 |
01 LFIND L,$1200 |
xx A=(A+1)&15:BORDER A: GOTO ~L |
01 REPEAT :UNTIL ~S<230:BO 4 |
| value | 0/8 | 1/9 | 2/10 | 3/11 | 4/12 | 5/13 | 6/14 | 7/15 |
| colour | black | blue | red | magenta | green | cyan | yellow | White |
| value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| colour | black | blue | red | magenta | green | cyan | yellow | light gray |
| value | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| colour | dark gray | light blue | light red | light magenta | lime | light cyan | light yellow | white |
01 COLOR 4,2 |
| "TEXT" | the text TEXT is output |
| #Expr | Determining the output channel (see below) |
| !Expr | Sets the format (see below) |
| @Expr1,Expr2 | Cursor positioning (Y=Expr1, X=Expr2) |
| %Expr | Direct output of a character with character code=Expr |
| &Expr | returns array elements as characters. Stopping at a zero byte or when the end of the array is reached. Works only in byte access to the array. |
| Expr | outputs the result of the printout with the set format |
| ; | Separator between expressions |
| , | Separator between expressions, spaces up to the next position divisible by 8 |
| #0 | Output to the screen, default setting |
| #1 | Output to the serial system interface |
| #2 | Output to the parallel interface |
| #3 | Output to the array |
| #4 | Output to the second serial interface (ATMega644P only) |
| #5... | Output via the I2C interface |
| Bit 7 | 0=decimal output, 1=hexadecimal output |
| Bit 6 | 1 switches to large display |
| Bit 4/5 | Comma position (0-3 decimal places), only for decimal output |
| Bit 2/3 | Number of digits issued (2-5), only for decimal output |
| Bit 0/1 | 0=compact, 1=leading spaces 2=leading zeros 3=leading zeros with sign |
| Bit 0 | 2/4 characters in hexadecimal output |
01 CBOX 3,3,5,5 |
01 COLOR 7,3:FRAME 0,0,22,29 |
01 COLOR 7,3:HFRAME 0,0,22,29 |
01 IBOX 0,0,0,0 |
| n | direction |
| 0 | up |
| 1 | to the right |
| 2 | downward |
| 3 | to the left |
10 SCROLL 2 |
11 GCH F,0,0 |
12 GAT F,0,0 |
| bit | function |
| 0 | Background color bit 0 |
| 1 | Background color bit 1 |
| 2 | Background color bit 2 |
| 3 | Background color bit 3 |
| 4 | Foreground color Bit 0 |
| 5 | Foreground color bit 1 |
| 6 | Foreground color bit 2 |
| 7 | Foreground color bit 3 |
| bit | function |
| 0 | Background color bit 3 |
| 1 | Background color bit 0 |
| 2 | Background color bit 1 |
| 3 | Background color bit 2 |
| 4 | Foreground color bit 3 |
| 5 | Foreground color Bit 0 |
| 6 | Foreground color bit 1 |
| 7 | Foreground color bit 2 |
01 INPUT "TASK: ",M |
01 INPUT "Text: ",M |
| Code Hexadecimal | Code decimal | Button |
| $C0 | 192 | Power |
| $C1 | 193 | Sleep |
| $C2 | 194 | Wake |
| $E0 | 224 | Pos1 |
| $E1 | 225 | End |
| $E2 | 226 | Arrow key to the left |
| $E3 | 227 | Arrow key to the right |
| $E4 | 228 | Arrow key up |
| $E5 | 229 | Arrow key down |
| $E6 | 230 | Picture up |
| $E7 | 231 | Picture down |
| $E8 | 232 | Ins |
| $E9 | 233 | Del |
| $EA | 234 | Enter |
| $EB | 235 | Tab |
| $EC | 236 | Backspace |
| $ED | 237 | Esc |
| $F1...$FC | 241...252 | F1...F12 |
| KEY(0) | The pressed key or 0x00 is returned |
| KEY(1) | It waits for a keystroke, result is the code of the pressed key. |
| KEY(2) | It waits until no key is pressed, the code of the last pressed key is returned. |
| KEY(3) | The status of the Shift and CTRL keys is returned. See below |
| KEY(4) | left shift key returns 1, left control key returns -1, both together 0 |
| KEY(5) | right shift key returns 1, right control key returns -1, both together 0 |
| KEY(6) | Cursor left key returns -1, cursor right key returns 1 |
| KEY(7) | Cursor down key returns -1 Cursor up key returns 1 |
| KEY(8) | The last scancode read is returned |
| KEY(9...255) | Waiting until the key with the corresponding key code is pressed |
| bit | function |
| 0 | Left shift key |
| 1 | Right shift key |
| 2 | Left CTRL key |
| 3 | Right CTRL key |
| 4 | ALT key |
| 5-7 | Internal Use |
10 WAIT 10 |
10 SYNC 300 |
10 TSET 0 |
10 TGET Z |
01 ONSYNC 5,50 |
01 ONERR 10 |
01 ONERR 10 |
| 01 | BREAK | The program was aborted with the key combination Ctrl+C. |
| 02 | OVERFLOW | For an arithmetic operation, the result is outside the limits of -32767...32767 |
| 03 | DIVIDE/0 | An attempt was made to divide by zero |
| 04 | SQR FROM <0 | An attempt was made to draw the square root from a negative number |
| 05 | CONSTANT TOO BIG | The specified number is outside the limits of -32767...32767 |
| 06 | WRONG EXPRESSION | The formula contains syntactical errors |
| 07 | SYNTAX ERROR | Missing parameters, invalid characters |
| 08 | UNKNOWN KEYWORD | Unknown keyword, the program code contains invalid bytes |
| 09 | WRONG FORMAT | Number formatting is invalid (more decimal places than visible) |
| 10 | BAD LINENUMBER | The line with the specified line number does not exist |
| 11 | NEXT W/O FOR | There is no corresponding FOR for this NEXT statement |
| 12 | RETURN W/O GOSUB | There is no corresponding GOSUB for this RETURN statement |
| 13 | STACK OVERFLOW | All in all, only 16 FOR/GOSUB/REPEAT may be "open" at the same time. The cause may be, for example, a recursive subroutine call. |
| 14 | UNTIL W/O REPEAT | There is no corresponding REPEAT for this UNTIL statement |
| 15 | I2C ERROR | No device reports at the specified address or not ready, for example, serial EEPROMs can be busy writing data. |
| 16 | UNKNOWN ERROR | unknown error. Unfortunately, all sorts of combinations of commands, functions, and parameters are not that easy to fully test, and it would be nice if you reported the error. |
| 17 | DFLASH ERROR | No data flash connected or the device is not responding. |
| 18 | OUT OF ARRAY | An attempt was made to access an array element that does not exist. The error also occurs if the space in the array is insufficient with BCOPY. |
| 19 | INCOMPLETE PAR | Too few parameters were specified for the command |
| 20 | KEYWORD IS MISSING | The specified statement does not start with a keyword, but rather with a number |
| 21 | WRONG BCOPY | The copy mode is not in the range (1...6) |
| 22 | OUT OF SCREEN | Attempt to draw outside the screen area (not implemented) |
| 23 | CAN NOT CREATE FILE | The file already exists or the file number is outside the valid range |
| 24 | DFLASH FULL | The file can not be created because the space on the dataflash is insufficient. |
| 25 | FILE NOT FOUND | The file does not exist (is free) |
| 26 | PAGE NOT IN FILE | The page to read/write does not exist in this file |
| 27 | PAGES NOT IN RANGE | Only files with 1...128 pages can be created |
| 28 | NOT IN GRAPHICS FASHION | The specified command can not be executed in graphics mode (VMODE 1...3/5) |
| 29 | NOT IN TEXT MODE | The specified command can not be executed in text mode (VMODE 0) |
| 30 | NO USR FILE | Only files of type USR can be read/written (obsolete) |
| 31 | SRC OUT OF SCREEN | The source block at BCOPY is not completely in the image area |
| 32 | DEST OUT OF SCREEN | The target block at BCOPY is not completely in the image area |
| 33 | WRONG SPRITE | The sprite definition has an error (eg greater than 8x8 characters) |
| 34 | WRONG EEPROM ADR | An attempt was made to access an internal EEPROM cell >1999 |
| 35 | NO PRG FILE | An attempt was made to load a non-program file with LOADP |
| 36 | XMODEM ERROR | A (checksum) error occurred during X-modem reception |
| 37 | CANT LOAD THIS | An attempt was made to overwrite the currently running program with LOADP |
| 38 | IO DISABLED | Output to the parallel port was deactivated by a driver on program location 8 |
| 39 | SERIAL1 NOT AVAILABLE | An attempt was made to access the second serial interface, but the controller type is a Mega644 or input pin of the serial system interface is connected to PD3 |
| 40 | NO IO DRIVER | An attempt was made to access a non-existent address from 0x0800 using IN/OUT |
| Mode | Resolution X | Resolution Y | Representable colors |
| 0 | Text 30 | Text 23 | 16 foreground and 16 background |
| 1 | 168 | 116 | 2 out of 16 |
| 2 | 120 | 76 | 4 out of 16 |
| 3 | 84 | 58 | 16 out of 16 |
| 4 | (User symbols) 30 | (User symbols) 23 | 16 foreground and 16 background |
| 5 | 128 | 64 | 2 out of 16 |
| 6 | (User symbols) 30 | (User symbols) 23 | 16 for each pixel |
| 7 | Text 30 | Text 2 | 16 foreground and 16 background |
| index | Mode 1 | Mode 2 | Mode 3 |
| 0 | black (0) | black (0) | black (0) |
| 1 | white (7) | red (2) | blue (1) |
| 2 | --- | cyan (5) | red (2) |
| 3 | --- | light gray (7) | magenta (3) |
| 4 | --- | --- | green (4) |
| 5 | --- | --- | cyan (5) |
| 6 | --- | --- | yellow (6) |
| 7 | --- | --- | light gray (7) |
| 8 | --- | --- | dark gray (8) |
| 9 | --- | --- | light blue (9) |
| 10 | --- | --- | light red (10) |
| 11 | --- | --- | light magenta (11) |
| 12 | --- | --- | light green (12) |
| 13 | --- | --- | light cyan (13) |
| 14 | --- | --- | pale yellow (14) |
| 15 | --- | --- | white (15) |
01 CLS:VMODE 1 |
01 CLS:VMODE 1,PLOT 55,0 |
01 CLS:VMODE 1,PLOT 55,0 |
11 BOX 0,0,115,167 |
10 FBOX 0,0,0,100 |
10 CIRCLE 50,50,20,20 |
10 FC 50,50,20,10 |
01 VM 1 |
01 VM 1 |
10 GPIX P,0,0 |
| Video mode | Pixels per subblock |
| 1 | 8x8 |
| 2 | 4x4 |
| 3 | 2x2 |
| Mode | Source | Aim | Additional parameter |
| 1 | image memory | image memory | Y1,X1,DY,DX,Y2,X2 |
| 2 | image memory | array | Y,X,DY,DX,ARRAYPOS |
| 3 | ARRAY | image memory | ARRAYPOS,Y,X |
| Video mode 1 | (8 * DX * DY) +2 |
| Video mode 2 | (4 * DX * DY) +2 |
| Video mode 3 | (2 * DX * DY) +2 |
01 DATA 0,1,1,$FF,$81,$81,$81 |
| mode | source | aim | zus.Parameter |
| 4 | image memory | image memory | Source address, destination address, number of bytes |
| 5 | image memory | array | Source address, destination address, number of bytes |
| 6 | ARRAY | image memory | Source address, destination address, number of bytes |
| Header byte | Address | Function |
| 1 | N | the collision flag (0/2) |
| 2 | N+1 | Y position (at the beginning $ff or -1) |
| 3 | N+2 | X position (at the beginning $ff or -1) |
| 4 | N+3 | Y extension in characters (dy) |
| 5 | N+4 | X extension in characters (dx) |
01 DA 0,0,-1,-1,1,1,"*",$86 |
01 DA 0,2,-1,-1,1,1,"*",$86 |
01 FOR N=0 to 255:NOTE N |
| value | meaning |
| 0...62 | Notes in a "dark" tone with fast envelope |
| 63 | Noise with fast envelope |
| 64...126 | Notes in a "bright" tone with fast envelope |
| 127 | Noise with fast envelope |
| 128...190 | Notes in a "dark" tone with a slow envelope |
| 191 | Noise with a slow envelope |
| 192...254 | Notes in a "light" tone with a slow envelope |
| 255 | Noise with a slow envelope |
01 DA 0,39,8,44,4,49,8,44,4 |
| value | meaning |
| 0 | Sequencer is stopped |
| 1 | Sequencer will run until the end of the current cycle and will stop |
| 2...127 | Sequencer runs, notes are played, after each cycle the cycle counter is reduced by 1 |
| 128...255 | Sequencer is running, notes are played, cycle counter does not change |
10 DIR $F0 |
10 OUT 7,0 |
10 OUT $1F0,$F0 |
| Bit | Bit=0 | Bit=1 |
| 0 | see SCK clock divider | see SCK clock divider |
| 1 | see SCK clock divider | see SCK clock divider |
| 2 | Data transfer with leading edge of the clock | Data transfer with trailing edge of the clock |
| 3 | Clock in rest LOW | Clock in rest HIGH |
| 4 | SPI slave | SPI master |
| 5 | Bit 7 is sent first | Bit 0 is sent first |
| 6 | Bit rate x 1 | Bit rate x 2 |
| Bit 6 | Bit 1 | Bit 0 | Frequency |
| 0 | 0 | 0 | 5 MHz |
| 0 | 0 | 1 | 1.25 MHz |
| 0 | 1 | 0 | 312.5 KHz |
| 0 | 1 | 1 | 156.25 KHz |
| 1 | 0 | 0 | 10 MHz |
| 1 | 0 | 1 | 2.5 MHz |
| 1 | 1 | 0 | 625 KHz |
| 1 | 1 | 1 | 312.5 KHz |
01 OUT $4B9,92 |
01 D=IN($426) |
10 IF SPI(67)<>67 PRINT "ERROR" |
01 SPISEL $F7 |
01 SPUT 65,10 |
01 SGET C |
| n | Bit rate (bps) |
| 0 | 1200 |
| 1 | 2400 |
01 BAUD 1 |
01 ESPUT 65,66,10 |
01 ESGET C |
| bbb | Bit rate (bps) |
| 000 | 1200 |
| 001 | 2400 |
| 010 | 4800 |
| 011 | 9600 (default) |
| 100 | 19200 |
| 101 | 31250 (MIDI) |
| 110 | 38400 |
| 111 | 57600 |
| b | Stop Bits |
| 0 | 1 stop bit |
| 1 | 2 stop bits |
| bbb | format |
| 000 | 8 bits, no parity bit |
| 001 | 8 bits, even parity |
| 010 | 6 bits, no parity bit |
| 011 | 8 bits, odd parity |
| 100 | 7 bits, no parity bit |
| 101 | 7 bits, even parity |
| 110 | 5 bits, no parity bit |
| 111 | 7 bits, odd parity |
01 EBAUD 5 |
01 PU 1 |
01 SGET C:IF C<>21 THEN GOTO 1 |
01 SPUT 21 |
01 DATA HI(B),LO(B),LO(A),HI(A):ICOMM $a0,0,4 |
02 EPOKE V,$12 |
02 W=EPEEK(V) |
01 XPOKE 100,C |
02 W=XPEEK(100) |
01 VPOKE 0,66:VPOKE 690,$08 |
01 DA 0,65,0,66,0,67,27+128 |
01 ? "A" |
01 PAGE 0 |
| value | meaning |
| 0 | no data flash connected |
| 2048 | 4MBit Dataflash connected |
| 4096 | 8MBit Dataflash connected |
| value | meaning |
| 252 | File is not used |
| 16 | BASIC program |
| 18 | Backup file |
| 20 | USR file |
| 22 | Chip-8 file |
| 24 | AVR binary |
| 26 | GPS location list |
| 28 | Sampling data |
| 30 | Logic block definition |
| 31 | Image file |
| 32 | Screenshot file |
| 34 | S12(X) binary |
| -1 | File number does not exist |
| n | return value |
| -1 | Number of free files |
| -2 | Number of free pages |
| 0...255 | Number of pages in the file or 0 (not used) |
40 'create file F with P pages |
| a | array area |
| 0 | 0...255 |
| 1 | 256...511 |
| 2 | 512...767 |
50 'write array 0...255 to |
| a | array area |
| 0 | 0...255 |
| 1 | 256...511 |
| 2 | 512...767 |
50 'read page P of file F to |
56 'delete file F |
60 'draw fileselct box |
10 DATA 0,252,0:F=FFIND(0) |
| a | array area |
| 0 | 0...255 |
| 1 | 256...511 |
| 2 | 512...767 |
| a | array area |
| 0 | 0...255 |
| 1 | 256...511 |
| 2 | 512...767 |
10 DATA 0,252,0:C=FFIND(0) |
01 DATA 0,97,"Hello World",0 |
01 DATA 0,97,"Continue?",0 |
| Character | Menu Properties |
| 0 | A menu level, function returns only when one of the keys listed in the next table is pressed. |
| 1 | Two menu levels, function returns only when one of the keys listed in the next table is pressed. |
| 2 | A menu level, function returns only when you press any key (except Shift, CTRL and Alt). |
| 3 | Two menu levels, function returns only when you press any key (except Shift, CTRL and Alt). |
| Offset | Button | Return value |
| 0...5 | ESC | 1 |
| 6...11 | F1 | 2 |
| 12...17 | F2 | 3 |
| 18...23 | F3 | 4 |
| 24...29 | F4 | 5 |
| 30...35 | left CTRL + ESC | 6 |
| 36...41 | left CTRL + F1 | 7 |
| 42...47 | left CTRL + F2 | 8 |
| 48...53 | left CTRL + F3 | 9 |
| 54...59 | left CTRL + F4 | 10 |
01 '1111112222223333334444445555551 |