Sharp logo
A powerful S-Basic: The K-Basic v.5 
( K-Basic is written by Bernard Kokanosky / Amiens / France, August / September 1984 )  

General

K-Basic started
K-Basic loaded and started

The K-Basic is a BASIC interpreter to program the MZ-700 and it is a changed and expanded version of the S-Basic, but largely compatible to the S-Basic. It has a lot of new and powerful features, a lot of new instructions, uses functions and procedures like PASCAL, local variables, parameters, it has its evaluator, it is compatible to the S-BASIC, but it is very far from the S-BASIC.

The K-Basic is a standard BASIC interpreter with all functions / commands of the S-Basic and additional it allows structured programming by new commands for loops, tests, and subprogramming commands:

FOR-DISP-EXIT-NEXT
REPEAT-UNTIL
WHILE-DO-WEND
IF-DO-THEN-ELSE-DO-ELSIF-DO-ENDIF
CASE-OF-WHEN-OTHERWISE-ENDCASE
DEF PROC-PROC-ENDPROC-LOCAL-DEF FN ( DEF FN more mighty than in S-Basic )

Overview of the S-Basic expansions made for the K-Basic

command
/ function
remarks
ELSE
ELSIF
DO
ENDIF
expands the command IF
INKEY
KEY
both with additional functions of the GET command
MAX
MIN
OR
AND
XOR
DIV
MODULO
ASN
ACS
SH
TH
ASH
ACH
ATH
FACT
CH
additional computations
GRAPH
DRAW
POINT
SPOKE
semi-graphics additions for the monitor screen
BEEP BEEP command
EXC
VARPTR
to manage variables
SWAP
NULL
COPY
to manage arrays ( < 128 dimensions )
WAIT
PWAIT
controlled program waits
INV$
IN$
STRING$
INSTR
to manage character strings
VPOS
HPOS
to get and process the actual cursor location
RESULT= to expand "DEF FN=expression"
DISP used with FOR will jump to the line defined by DISP n
EVAL formular checker; checks a formular contained in a string

Additional important notes

Note In K-Basic you have to seperate each keyword by space(s). "IFA=BTHENPRINT" is not allowed! Use "IF A=B THEN PRINT".

Note Keys are automatically repeated while holding down the key continously. You can change the timing of this to slow down or to speed up the repetition by setting the bytes $288 ( 648 dec. ) and $2BC ( 700 dec. ). At $2BC you change the reaction time until the repetition will start ( default value is 96 dec. = $60 ). At $288 you change the speed of the repetition ( default value is 16 dec. = $10 ). Setting to 0 is quick and to 255 is slow. Do not use very slow or very quick values - in this case you cannot handle the computer.

Note The areas from $FD00 to $FFFF are used by the K-Basic.

Loading the K-Basic

After loading the K-Basic by the monitor command "L" the K-Basic beeps. Press either CR to execute the K-Basic, or SHIFT and BREAK to return to the monitor program, or "S" to make a tape copy of your K-Basic.

If you make a copy, you get the french message "Appuyez sur une touche" ( Press any key - to continue ) and the cursor is waiting for any input key. Next the K-Basic will be copied to your data recorder. Before pressing any key, you should have inserted and positioned a new tape which can be overwritten for your K-Basic copy. Then you can press the PLAY / RECORD keys at your data recorder to start your tape. Then press any key at your MZ-keyboard and the copy will be written to tape. The message will be "WRITING K-Basic V.5":

K-Basic copy process

If the copy process is completed, the K-Basic beeps again. Now you can again enter "S", "CR", or SHIFT and BREAK as described above.

If you have stopped the process by SHIFT and BREAK or you immediately called the monitor by these keys, you can return to the process described above by entering "J8670" while executing the monitor.

Commands / functions with tokens one byte in length

Note The additional functions and commands to the S-Basic are marked red in all tables below.

token command / function entry point in K-Basic v.5
$80 GOTO $2EEC
$81 GOSUB $2E1A
$82 DISP n $2D75
$83 RUN $1A87
$84 RETURN $2DF4
$85 RESTORE $24FB
$86 RESUME $2E36
$87 LIST $3A3B
$88 ENDPROC $667D
$89 DELETE $6900
$8A RENUM $2BA6
$8B AUTO $2209
$8C ENDCASE $67D2
( = ENDIF / ENDCASE / DATA / REM )
$8D FOR $1AD8
$8E NEXT $1B37
$8F PRINT $1BFB
$90 ELSIF $3119
$91 INPUT $22FB
$92 ENDIF $67D2
( = ENDCASE / DATA / REM )
$93 IF $30A3
$94 DATA $67D2
( = ENDIF / ENDCASE / REM )
$95 READ $2541
$96 DIM $55D6
$97 REM $67D2
( = ENDIF / ENDCASE / DATA )
$98 END $21EB
$99 STOP $202C
$9A CONT $2060
$9B CLS $3185
$9C DO
WHILE condition DO;
or used within IF construct
$3132
$9D ON $2EA5
$9E LET $194B
$9F NEW $2288
$A0 POKE $6892
$A1 OFF $20B8 ( error )
$A2 MODE $48BA
$A3 SKIP $491D
$A4 PLOT $3386
$A5 LINE $4977
$A6 RLINE $49E4
$A7 MOVE $49EB
$A8 RMOVE $49F5
$A9 TRON $22C8
$AA TROFF $22CC
$AB INP# $6802
$AC INKEY
INKEY X or INKEY X$
$6845
$AD GET $684C
$AE PCOLOR $49FC
$AF PHOME $4A31
$B0 HSET $4A3F
$B1 GPRINT $4A4C
$B2 KEY $3C38
$B3 AXIS $4AC9
$B4 LOAD $3B03
$B5 SAVE $3BBB
$B6 MERGE $3AE3
$B7 OF
CASE ... OF
$20B8 ( error )
$B8 CONSOLE $3320
$B9 PROC
DEF PROC / PROC
$637E
$BA OUT# $67EB
$BB CIRCLE $4B17
$BC TEST $4D1C
$BD PAGE $4D2A
$BE REPEAT
REPEAT UNTIL
$2F60
$BF UNTIL
REPEAT UNTIL
$2F33
$C0 ERASE
S-Basic keyword without interpretation
$20B8 ( error )
$C1 ERROR $214C
$C2 ELSE
IF ... THEN ... ELSE
$3122
$C3 USR $67B2
$C4 BYE $13C2
$C5 WHILE
WHILE condition DO
$2F78
$C6 WEND
WHILE ... WEND
$2FDC
$C7 DEF $24C1
$C8 RESULT=expression
example: DEF FN"A"(X)=3*X+5
$668D
$C9

BEEP n,f,d
n = number of beeps ( 0 - 255 )
f = frequency ( 0 - 65,535;
0 high, 65,535 low tone;
frequency is 895kHz / f )
d = period ( 0 - 65,535;
0 short, 65,535 long tone;
period is d / 100 seconds;
if d is omitted d = 1 second )
Can be stopped by BREAK key.
BEEP can be executed too by
CTRL+G or PRINT CHR$(7)

$1F9A
$CE WOPEN $3F89
$CF CLOSE $3E57
$D0 ROPEN $3FC5
$D1 GRAPH x,y
sets a pseudo graphical cursor
$3238
$D2 DRAW $3259
$D3 SWAP A,B
exchange elements of already
dimensioned arrays of the same type
$2A8B
$D4 NULL A,B$,C
sets A and C to 0, B$ to empty string
$2AE5
$D5 COPY A,B
copies array B to array A;
already dimensioned arrays
$2A9F
$D6 EXC A,B
or EXC A$,B$
variable contents exchange;
dimensioned or normal variable
$2A15
$D7 WAIT n
waits n / 100 seconds until
execution goes on;
n = 1 - 65,535;
can be interrupted by BREAK.
To this check $1FFF for 0.
$1FE7
$D8 PWAIT n
n = 1 - 255; waits "n" at the end of
PRINT like a POKE in S-BASIC only ( !! )
at $3900
$2017
$D9 KILL
S-Basic keyword without interpretation
$20B8 ( error )
$DA LOCAL A,I,H$
local variables definition at PROC or FN
$656E
$DB CASE
CASE ... OF ... ENDCASE
$301D
$DC WHEN
CASE ... ENDCASE
$3014
$DD OTHERWISE
CASE ... ENDCASE
$3014
$DE EXIT n
exits a FOR - NEXT after n loops
$5398
$DF SPOKE adr,n
adr = 53,248 - 55,295 ( $D000 - $D7FF ),
n = 0 - 255
color poke / 2nd characterset switching
SPOKE 43248,0,2,5...
$634A
$E0 TO  
$E1 STEP  
$E2 THEN  
$E3 USING  
$E4 π ( pi )  
$E6 TAB  
$E7 SPC  
$E8 VARPTR variablename
returns address of a variable,
its 1st byte is the length field
-
$E9

A=X MAX B
A will be >= B
A is set to the value of X if X > B
A is set to the value of B if X <= B

-
$EA

A=X MIN B
A will be <= B
A is set to the value of B if X >= B
A is set to the value of X if X < B

-
$EB

OR

X Y X OR Y
0 0 0
0 1 1
1 0 1
1 1 1
-
$EC

AND

X Y X AND Y
0 0 0
0 1 0
1 0 0
1 1 1
-
$ED

XOR

X Y X XOR Y
0 0 0
0 1 1
1 0 1
1 1 0
-
$EE ><  
$EF <>  
$F0 =<  
$F1 <=  
$F2 =>  
$F3 >=  
$F4 =  
$F5 >  
$F6 <  
$F7 +  
$F8 -  
$F9 A DIV B
e.g. 1000 DIV 3 returns 333;
like INT(A/B)
-
$FA A MODULO B
e.g. 10 MODULO 6 returns
remainder 4 by the division 10 / 6;
like A-B*INT(A/B)
-
$FB /  
$FC *  
$FD
( exponential function,
power of x )
 

Commands with tokens two byte in length

token function entry
$FE81 SET $318A
$FE82 RESET $31AD
$FE83 COLOR $3D87
$FEA2 MUSIC $3D53
$FEA3 TEMPO $3D78
$FEA4 CURSOR $682B
$FEA5 VERIFY $3BE8
$FEA6 CLR $229D
$FEA7 LIMIT $68C3
$FEAE BOOT $33BC

Functions

token function entry
$FF80 INT $5B60
$FF81 ABS $5B5B
$FF82 SIN $5C7C
$FF83 COS $5C6C
$FF84 TAN $5D5F
$FF85 LN $5F78
$FF86 EXP $5EAA
$FF87 SQR $5B9C
$FF88 RND $5E65
$FF89 PEEK $5E4B
$FF8A ATN $5BBA
$FF8B SGN $5E1C
$FF8C LOG $5F6C
$FF8E PAI $5E38
$FF8F RAD $5E33
$FF90
ASN(X)
arc sine ( sin-1 )
ASN(X)=ATN(X/SQR(-X*X+1))
$60C9
$FF91
ACS(X)
arc cosine ( cos-1 )
ACS(X)=ATN(X/SQR(-X*X+1))+PI/2
$6100
$FF95 EOF
S-Basic keyword without interpretation
$20B8 ( error )
$FF96
SH(X)
sine hyperbolic ( sinh )
SH(X)=(EXP(X)-EXP(-X))/2
$6149
$FF98
TH(X)
tangent hyperbolic ( tanh )
TH(X)=-EXP(-X)/(EXP(X)+EXP(-X))*2+1
$616A
$FF99 ASH(X)
arc sine hyperbolic ( sinh-1 )
( inactive ? )
$618B
$FF9A ACH(X)
arc cosine hyperbolic ( cosh-1 )
( inactive ? )
$61A0
$FF9B ATH(X)
arc tangent hyperbolic ( tanh-1 )
$61C3
$FF9C FACT(X)
factorial ( X! ) maximum is 33!
If X > 33 then ERN = 6 is set.
$6111
$FF9E JOY $32F8
$FFA0 CHR$ $20B8
$FFA1 STR$ $5202
$FFA2 HEX$ $517D
$FFA3 CH(X)
cosine hyperbolic ( cosh )
$6144
$FFAA INV$(string)
PRINT INV$("HELLO") prints OLLEH
$29FB
$FFAB ASC $5221
$FFAC LEN $5226
$FFAD VAL $522A
$FFB1 EVAL string $20B8
$FFB3 ERN $511A
$FFB4 ERL $5122
$FFB5 SIZE $5102
$FFB6 VPOS
returns line # from cursor, 0 - 24
$5110
$FFB7 HPOS
returns col. # from cursor, 0 - 39
$5115
$FFBA LEFT$ $524D
$FFBB RIGHT$ $5263
$FFBC MID$ $5287
$FFBD IN$(A$,n,p,B$)
Inserts B$ into A$ between n and p of A$;
n defines the first position in A$
p defines the second position in A$
p is always greater than n and lower than 255,
The range of n can be from 0 to LEN(A$).
The range of p can be from n+1 to 254.
The contents of A$ and B$ remain unchanged.
Examples: A$="ABCD" B$="12345"
PRINT IN$(A$,LEN(A$),255,B$ results into
ABCD12345 ( same as A$+B$ )
PRINT IN$(A$,0,1,B$) results into
12345ABCD ( same as B$+A$ )
PRINT IN$(A$,2,3,B$) results into
AB12345CD
$2B10
$FFBE A=POINT(x,y)
returns the color code of (x,y) set by SET to A.
If not previous set or (x,y) is alphanumeric
A contains 8.
$3206
$FFBF

INSTR(A$,B$,n)
(A$,"U",1) search from pos. 1 for "U" in A$.
0 = not found, x = found at x
n = 1 - 255

$6731
$FFC3 STRING$ $1ED7
$FFC4 TI$ $2447
$52D3
$FFC7 FN $6382

Hints to change / expand your K-Basic

Name start end length
FREE1 $6AF2 $6CE5 $1F4 ( 500 bytes )
FREE2 $6D3B $6F2E $1F4 ( 500 bytes )
FREE2 $6FF3 $70DE $EE ( 236 bytes )
 


There are 3 free areas within K-Basic. These areas can be used to expand it for your own purposes.

Note The areas can vary between different versions of the K-Basic. The areas shown here are compatible to the one you can download from my site.


start end tokens
$6912 $6AF0 $80 - $FD
$6CE6 $6D39 $FE80 - $FEAE
$6F2F $6FF1 $FF80 - $FFCF
 


The areas follow immediately the K-Basic keyword areas.


start end tokens
$70DF $719E $80 - $DF
$719F $71FC $FE80 - $FEAE
$71FD $728C $FF80 - $FFC7
 


You'll find the associated address tables at these locations.

Error messages

The K-BASIC was written by Bernard Kokanosky / France and all error messages are given in french. The following table shows all french messages translated:

Error number
( in ERN )
French Error Message Translation
1 Plus de memoire memory capacity error
2 Type de variable illegal illegal type of variable
3 Erreur de pile stack overflow
4 Nombre non entier number is not an integer
5 Valeur incorrecte incorrect value
6 Depassement de capacite overflow error
7 Operation illegale illegal operation
8 Chaine trop longue string too long
9 Division par 0 division by 0
10 Pas d'argument no argument
11 Syntaxe incorrecte incorrect syntax
12 Il manque ')' missing ")"
13 Il manque ',' missing ","
14 Il manque '(' missing "("
15 Mauvais nom de variable incorrect name of variable
16 Argument negatif argument negative
17 Mauvais dimensionnement array out of bounds
18 Indice trop grand index too big
19 Tableau inconnu unknown array
20 Trop de parametres too much parameters
( number of parameters )
21 Ligne trop longue Basic line too long
22 RESUME impossible RESUME impossible
23 Pas de ':' ou fin de ligne BASIC line error
( no ":" or line end )
24 Il manque '=' missing "="
25 Mot-cle inconnu unknown keyword
26 6 chiffres pour TI$ TI$ needs 6 digits
27 Ce n'est pas un chiffre not a numeric value
28 Ligne inconnue unknown BASIC line
29 Argument nul no / null argument
30 UNTIL sans REPEAT UNTIL without REPEAT
31 NEXT sans FOR NEXT without FOR
32 Mauvaise variable incorrect variable
33 Il manque ']' missing "]"
34 CONT impossible CONT impossible
35 Il manque ';' missing ";"
36 Pas de DATA DATA not found
37 WHILE sans WEND WHILE without WEND
38 Ce n'est pas un nombre not a numeric value
39 N° de ligne trop grand line number too big
40 RETURN sans GOSUB RETURN without GOSUB
41 Il n‘y a pas eu d‘erreur terminated without error(s)
42 Mode imprimante incorrect printer / plotter mode error
43 Mauvais type de fichier incorrect type of file
44 Caractere illegal (USING) illegal character ( USING )
45 Fin de fichier end of file
46 Fichier deja ouvert file already opened
47 Erreur de lecture read error
48 Imprimante non connectee printer not connected
49 Pas d'ENDIF ENDIF missing ( all lines searched ! )
50 Mode IF incorrect incorrect IF usage
51 Il manque DO DO missing
52 WEND sans WHILE WEND without WHILE
53 Il manque OF OF missing
54 PROC ou FN inconnue PROC or FN unknown
55 Mauvais nombre de parametres wrong number of parameters
56 ENDPROC sans PROC ENDPROC without PROC
57 RESULT sans FN RESULT without FN
58 Il manque WHEN WHEN missing
59 Pas d'ENDCASE ENDCASE missing

Further french messages

French message Translation
J'ecris Writing
Voici Found
Je charge Loading
Je verifie Verifying
Octets libres bytes free
Pret Ready
Break en Break in
Appuyez sur une touche Press any key
Demo programs written by Bernard Kukanosky

Plotter demo Plotter demo K-Basic program
You can download this plotter demo now ( ZIP, 1 KB, MZF-formatted )

Download

Download the K-BASIC V5.0 now ( ZIP, 21 Kb ).


Go to the top of this page Home

last updated August 5, 2002
sharpmz@sharpmz.org