Current version: v1.25
LK-BASIC does not give you any way to declare normal 'variables'. Instead, it gives you memory from VAR_OFFSET (0xB000) to 0xFFFF. To access this memory you use $
(word) and #
(byte) operators. $xx
returns word (2 bytes, 0 to 65535 (FFFF hex)) from xx+VAR_OFFSET
, and #xx
returns byte from xx+VAR_OFFSET
. If xx+VAR_OFFSET
is bigger than 0xFFFF
program returns memory error (it should but it doesn't). To set variable's value you use VAR
or PTR
(PTR == VAR) keywords, eg. VAR 0=12
, that translates to C's *(0+VAR_OFFSET)=12
. VAR $0=12
coresponds to C's *(*(0+VAR_OFFSET))=12
.
LK-BASIC can interpret statements just after you press enter, or save statements to memory. To save statement to memory just type line number before statement, for example:
10 PRINT "Hello World!"
20 STOP
It is good to use numbers divisible by 10, if you do that you can insert lines between 10 and 20 without rewritting entire program. Statements are saved in [line_number*LINE_SIZE+CODE_START]
, where LINE_SIZE is 40 and CODE_START is 0x2000.
LK-BASIC supports 18 (plus 3 synonyms and 1 not working) statements ( [] is optional parameter, <> is required parameter):
PRINT ["string"] [,] [variable [+|-|*] ] [;]
- prints text on screen, for examplePRINT "Hello World! Content of 0=",$0
.REM [comment]
- comment.VAR <address> = <value>
- sets[number+VAR_OFFSET]
to value, for exampleVAR 5=123
.INPUT <address>[;]
- sets[address]
to user input (only number), for exampleINPUT 12
. Without;
it prints?
before input.STOP
- Stops program.IF <number> < == | != | \< | \> > <number> STATEMENT
- doesSTATEMENT
if condition is true, for exampleIF $0==12 GOTO 10
.RND <address>
- returns pseudo-random number in[address]
.INSTR <address>
- reads line toaddress
.CLS
- clears screen.NEW
- deletes program.LIST [line number]
- lists program lines.GOTO <line number>
- sets next line pointer toline number
, for exampleGOTO 10
will go to 10th line of your code.BACK
- returns to executing program afterSTOP
statement.RUN
- runs your program from line1
until it reaches MAX_CODEOF orSTOP
instruction.GOSUB <line number>
- same as GOTO, but saves next line number and is able to return to it using...RETURN
- returns to lastGOSUB
statement.XY <x>,<y>
- sets cursor position to x,y (x can be 0 to 79 and y 0 to 24 (80x25 screen)).PTR <address> = <value>
- see:VAR
.? ["string"] [,] [variable [+|-|*] ] [;]
- see:PRINT
.IN <address>[;]
- see:INPUT
.GETCH <address>
- gets character from keyboard buffer and saves in<address>
(high = ASCII), for exampleGETCH 0
.GETCHASYNC <address>
- same as above but without waiting for keystroke (if buffer is empty returns 65535), for exampleGETCHASYNC 0
.PUTARR <number [number [,] ...] >
- puts char array on screen, for examplePUTARR 65,66,67,13,10
.POKE <address>,<value>
- sets[address]
tovalue
, for examplePOKE 1025,0
.PUTCH <ascii>
put<ascii>
on screenOUTNUMB <nr>
put<nr>
on screen as decimal number
BASIC can return 3 errors:
?Number error
- returned if number is beyond 16 bits?Syntax error
- basically every error.
- Separating statements by
:
. - any form of loop.
tbh idk.
Ctrl+C is life Ctrl+C is love.