BALSYS Tutor
By NightBird
Hello!
This is a very basic step-by-step example, for a simple BalSys application, or rather a game.
At any time you don't understand something, please consult the BalSYS
documentation, it's very thoroughly written.
The rules are simple, you surely know them; the computer
thinks of a number between a given range, and you have to guess what the number
could be.
1) Fire up BalSys, and think over
what we need.
- In this
example, we'll use Register #0 only as a temporary register, as all data
generated by commands is stored there, and we don't want our stored values
overwritten by accident.
Each Register takes away 8 bytes.
- So we need a
Register #1 for the random number generated by the computer.
- We need
Register #2 to store the number user enters.
- We have 3
registers each taking 8 bytes, and 8*3=24, so we need 24 bytes to store all
variables we need, and that means, we can begin the code at .24
- We will have
a greeting message, used at the beginning of the program. Its text data will
reside at address marked by a Label: -> LAB 1
- We will also
have a query for the tip from the user -> Text will be at Label 2
- There are 3
messages for the values entered (equal,bigger,less) -> Texts will be at
Labels 3, 4, 5
- The end
message -> Text will be at Label 6
2) Go into service mode, by
pressing CBM-S (Control-S if PC
keyboard).
If you dont
see on screen the monitor-panel with counters, please hit .SET [RETURN] then N then [ESC], only once, then the setting
will be stored in Preferences.
Remember, that you have two counters; a Program Counter (PC) and a Service Counter (SP). With the Program
Counter you can edit/view the execution addresses points of the program, and
with the Service Counter you can edit the program itself. Now we begin with
setting the Service Counter.
Enter the following:
.TSP 24 ; above, we determined that we need 24 bytes
for variables
;
and now we Transfer Service Pointer to address .24
LAB 255 ;
each program must begin with this statement
//
LAB 100 ; This is the label for the printing out of
the greeting message area,
; its value is free to choose, just watch that the
values do not conflict,
; but BalSYS will notify you
if this happens. Under this label, we put
; the code to print out our message. We need this
Label if the user wants
; to play again, this marks the actual beginning of
the executable program
PA 3,1 ; Print out a string from Label 1 until
$00 is reached
/I have thought of a number
between 0 and 100/
RAND 100 ; Generate a random number between 0 and 100, in Register #0
LR 1,0 ; Copy the value of Register #0 into
Register #1; this is our random number
//
LAB 110 ; This is the label, for printing out the
user query
PA 3,2 ; Print out a string from Label 2 until
$00 is reached
/Your guess?/
K 3,0 ; This is the user input, you are allowed
to input 3 decimal cyphers, the
; values are stored in Register #0, as previously
discussed
LR 2,0 ; Now we move the user input from Register
#0 in Register #2
CR
1,2 ; We Compare Registers #1 and #2.
This command returns 3 possible values,
; that can be processed later in correlation with
Branch commands
; 0=EQUAL,1=LESS,2=BIGGER
B0
120 ; If Register #1 is EQUAL
Register #2, jump to Label 120
B1 130 ; If Register #1 is LESS than Register #2,
jump to Label 130
B2 140 ; If Register #1 is BIGGER than Register
#2, jump to Label 140
//
LAB 120 ; Label for EQUAL HANDLING
PA 3,3 ; Print out a string from Label 3 until
$00 is reached
/You have tipped right
Another game?/
KAC
2 ; This command takes only a single
character without echoing, and we
; store this character in address aimed by Pointer
2 (.0 at this moment)
CBI
2,'59' ; We compare Register #2, with the
ASCII hex value 59 ('y'), to see whether
; the user wants to play another game
B0 100 ; Is the value entered $59 ('y')? Then
jump to Label 100-> restart
WAIT ; Otherwise,
halt process, so the user can exit, or go to service mode
//
LAB 130 ; Label for LESS HANDLING
PA 3,4 ; Print out a string from Label 4 until
$00 is reached
/The number is less/
B 110 ;
Unconditional jump to Label 110->query
//
LAB 140 ; Label for BIGGER HANDLING
PA 3,5 ; Print out a string from Label until $00
is reached
/The number is bigger/
B 110 ;
Unconditional jump to Label 110->query
Now we can enter Labels
1...5 data in the remaining memory area.
Be advised, that Labels
(as per all other mnemonics) can only be entered on EVEN addresses, so whenever
you finish entering data, please check that the counter is on an even number.
If it is not, relocate it to the next available even number by using .TSP xxx!
In our example .DCX 00
could actually be left out as it is followed by another Label and BalSYS
automatically ends the previous Label there, but just to be on the safe side we
use .DCX 00 to signal the end of the printable string area for the PA 3,x
command.
LAB 1 ; Label for greeting string
.DCX 93 ; Enter a hex value of $93 into memory to
clear the screen ($93=CLS)
.DCC I
thought of a number ; Enter string
.DCX 0D ; Enter a hex value of $0D into memory to
line feed ($0D=new line)
.DCC between 0 and
100 ; Enter string
.DCX 0D00 ; New Line ($0D), and value of $00 into memory
to signal end of print data
//
LAB 2 ; Label for user query
.DCX 0D ; New Line
.DCC Your guess? ; Enter string
.DCX 0D00 ; New Line; End of string (flag for PA 3,xxx
mnemonic)
//
LAB 3 ; Label for EQUAL MESSAGE
.DCX 0D ; New Line
.DCC You tipped
right ; Enter string
.DCX 0D ; New Line
.DCC Another game? ; Enter string
.DCX 00 ; Enter a hex value of $00 into memory to
signal end of print data
//
LAB 4 ; Label for LESS MESSAGE
.DCX 0D ; New Line
.DCC The number is
less ; Enter string
.DCX 00 ; Enter a hex value of $00 into memory to
signal end of print data
LAB 5 ; Label for BIGGER MESSAGE
.DCX 0D ; New Line
.DCC The number is
bigger ; Enter string
.DCC 00 ; Enter a hex value of $00 into memory to
signal end of print data
3) We used PA 3,X in the example above, but that is
not a standard BAL command. If you would like to stick to the original
language, this would be the way to print a text from a Label area; BalSYS uses
two separate pointers, they can be set to a Label area by the command TL, then
you use either PA 1, or PA 2 (depending on which pointer you use), and specify
how many characters to be printed out:
TL 1,101 ; Pointer 1 is Transfered to Label 101.
Label 101 is where our message is
; stored.
PA 1,39 ; We print 39 characters (alphanumerical or even control
characters) from the area pointed to by Pointer 1.
4) If you are interested, you can now simply
write a routine that asks for the range of random numbers generated, or you can
mask the generated random number, so that one peeking Registers (.SET, R) has
a harder time guessing the value.
PSEUDO COMMANDS:
Name
|
Operand
|
Description
|
Range
|
.TSP |
xxxx |
Transfers SC to address xxxx |
xxx=0
4095 |
xxxx
|
Writes in memory the hex string xxxx
|
Lenght of xxx: 2
16 hex |
xxx
|
Writes on memory the alpha-numerical string xxxxxx
. |
Lenght of xxxx
: 1
255 |
BAL MNEMONICS:
Name |
Ope-rands |
Description |
Range Oper. 1 |
Range Oper. 2 |
Di 0 |
Resulting 1 |
Condition 2 |
code 3 |
LAB |
nnn |
Set a Label point inside a program |
0
255 |
- |
- |
- |
- |
- |
PA |
x,nnn |
x=0:
Reserved for future (now the same as x=1) x=1 or x=2: Print nnn+1 characters from memory addressed
by Pointer x x=3:
Print a string located at LABEL nnn, of any lenght, until a $00 value is met |
1
2 |
1
255 |
- |
- |
- |
- |
RAND
|
nnn |
Generate a random value, between 0 and nnn, on Register# 0 |
0
255 |
- |
- |
- |
- |
- |
LR |
x,y |
Register x = Register y |
0
15 |
0
15 |
- |
- |
- |
- |
K |
nn,k |
Input a positive value and store it onto Register#0 (nn=max number of cyphers of
which k are decimal) |
0
15 |
0
3 |
Key S0 (Enter) |
Key S1 |
Key S2 |
Key S3, S5, or S6 |
CR |
x,y |
Compare Register x with Register y |
0
15 |
0
15 |
Res.=0 |
Res.<0 |
Res.>0 |
- |
B* |
nnn |
Branch to label nnn if Condition=* |
0
255 |
- |
- |
- |
- |
- |
KAC |
n |
Input an alphanumerical character and store it onto memory addressed
by Pointer n( (without echo on screen) |
1
2 |
- |
- |
- |
- |
- |
CBI |
x,hh |
Compare the byte addressed by Pointer x with hex value hh |
1
2 |
00
FF |
Mem=hh |
Mem<hh |
Mem>hh |
- |
TL |
x,nnn |
Pointer x = Label
nnn |
1
2 |
0
255 |
- |
- |
- |
- |