|Home||Gadgetman||Forum||Book Reviews||Links||Contact me||X-UFO|
|Gadgets||Processors||Programming School||Old news|
The PB-100's is a 'classic' Basic variant. It uses Linenumbers, Goto and gosub for subroutine handling.
Valid line numbers are from 1 to 9999. The programs are stored as P0 to P9, and seleted on the numeric keypad.
The classic test program would therefore look like this:
10 PRINT "Hello World"This line takes 17Bytes.
In the following examples I will be using multiples of 10 as linenumbers. This is common in older Basic programs. (Leaves a lot of linenumbers free so that the program can more easily be changed later)
It was also common to let 'subroutines' begin on lines that were multiples of 100... (Makes a easier reading :-)
(Commands that can be used directly in RUN mode is marked)
|This should be self explanatory...
10 PRINT N REM to display a variable 20 PRINT "String" REM prints the string... 30 PRINT N*12 REM Prints out the result.Also note that it seems to pause execution after a PRINT command, and won't continue until you press [Exe]
|INPUT||Asks the user to input a value...
10 INPUT N REM asks for a value 20 PRINT N*1.23 REM 23% VAT in Norway
|GOTO||This jumps to the specified line number and continues execution there.
10 PRINT "Here" 20 GOTO 100 100 PRINT "There"I don't like GOTO! It allows sloppy and unstructured programming! Don't use if you don't have to.
|These are used for 'subroutines'.
The difference between GOTO and GOSUB is that GOSUB stores information of where it jumped FROM, and returns to the next command after GOSUB when it encounters RETURN.
10 PRINT "Here" 20 GOSUB 100 30 PRINT "Back again" ---- ---- 100 PRINT "There" 110 RETURN
|END||Some might have spotted a problem with the code in the GOSUB example... After finishing line 30,
it'll go on executing and might get to 100 and the 110, resulting in an Error situation...
Since the program isn't supposed to keep on running after 30, we just add this:
|To do or not to do, that's the problem.
A simple use might be:
10 IF N=5 THEN 40 20 GOSUB 2000 30 N=5 40 PRINT "All is well" 50 END ---- ---- 2000 ?????As we see here, it is used to jump to another part of the program if the condition is fulfilled.
|The FOR loop is an essential command in many languages...
This is a simple way to use it:
10 FOR N=1 TO 100 20 PRINT N 30 NEXT NThat example prints all numbers between 1 and 100... Replacing a single line:
10 FOR N=1 TO 100 STEP 5This will result in the program counting only every fifth number.
Also, take note that even if 'STEP 1' is implied if nothing else is specified, that IS NOT the case when counting backwards. Then you MUST use 'STEP -1'
FOR-NEXT loops can be nested. But there is a maximum of 4 levels. Other constructs might limit it even more.
|STOP||This command seems to pause execution of the program. You can then read out variables and do simple maths. Pressing [EXE] without any query will make the program continue. Running BASIC Commands like LIST will make the PB-100 cancel the continue option. And no, there don't seem to bee a CONT command.|
|DEFM||Seems to have something to do with variables, but what?|
|Special commands (Not found on keyboard. There might be more of them)|
|CLEAR||Used in Write mode. Clears the selected program. (Use with caution)|
|LOAD||R||Loads a program from tape and into current position. See the FP-12 page for usage.|
|LOAD A||R||Loads ALL programs from tape. See the FP-12 page for usage.|
|SAVE||R||Stores Current program on tape. See the FP-12 page for usage.|
|SAVE A||R||Stores ALL programs on tape. See the FP-12 page for usage.|
|PUT||R||Stores variables on tape. See the FP-12 page for usage.|
|GET||R||Retrieves variables stored on a tape. See the FP-12 page for usage.|
|Other operators. Also not found on keyboard|
|ABS(X)||R||the ABSolute value of the input parameter.|
|INT(X)||R||Returns the INTEGER part of a floating point variable. (Rounds down)|
|LN(X)||R||The Natural Logaritm of the supplied variable.|
|LOG(X)||R||Base 10 Logaritm (1->0, 10->1, 100->2...)|
|SQR(X)||R||The SQuare Root of the variable. (And don't try working with Imaginary numbers like the Square of -1)|
Valid variable names are supposedly A-Z, A$-Z$.
A and A$ cannot be used at the same time, and Strings($) can only be a maximum of 7 Characters.
Strings must be enclosed in "".
It also supports ARRAYS, but I don't know all about them yet. What I can say work is A(0)-A(20) and A$(0) to A$(20) and that A$ and A$(0) is functionally equivalent. A(1) is equivalent to B$...
Numbers are represented by Floating point variables internally. Since it's a 8Byte variable, I assume something like 8 or 10 digit accuracy.
Please note that ALL programs share the same variables.
You can have more than one command on a line by separating them with a ':'. (It's a good idea too, for every time you do it, you save two Bytes. Not much, but then you don't have much memory to start with :-)
This version of Basic does not have a REM (REMark) statement. Quite understandably, given the small RAM size.
You can call one program from within another by using the # sign. Either use GOTO #x or GOSUB #x where the x is the program that you want to call up. I recommend that you use the GOSUB command since that one allows you to use the RETURN command to return to the calling program.
Error codes. You know, even with such small programs, you will occasionally get it wrong. These codes should help you out...
|ERR2||General 'Syntax error'. Misspelled command or wrong number of parameters.|
|ERR3||Out of Range? One or more parameters is out of the allowed range. (Like SQR(-1) ) Also 'divide by ZERO'.|
|ERR6||'String too long' Possibly a general string error. Goes off if you try to assign a value to a string variable and then try to print out the Floating point value.|
|ERR7||'Stack overflow or underflow'. Caused by'NEXT without FOR' and 'FOR without NEXT'. The PB-100 ran into a NEXT command without first executing a FOR, or it didn't find the matching next after a FOR. It can also indicate too many levels of FOR-NEXT loops.|