-
Notifications
You must be signed in to change notification settings - Fork 1
first buffer script
Piko-piko OS has the capability to execute a series of predefined commands. In Piko-piko OS, buffer 0
is the execution buffer, which means it is a chunk of memory that is specifically for containing commands for execution.
To ensure you are editing buffer 0
, set the buffer 0
as active with this command:
> stb 0
Let's view what is in the buffer, dump the buffer with this command:
> lsb
It should be like this since we haven't add anything yet:
00000
00001
00002
00003
00004
But still, to ensure it is empty, run this command:
> clb
This will clear the currently active buffer, which is buffer 0
.
Now, we are finally ready to write a script.
Let's start with the most simple say
command, we insert the say
command with this command:
> = 0 "say n 'Hello world'"
The 0
means insert at line 0
, and the "say n 'Hello world'"
is the string we want to insert.
Now let's view the buffer again:
> lsb
It should show something like this:
00000 say n 'Hello world'
00001
00002
00003
00004
Now let's run our buffer, using this command:
> run
We should see this line:
Hello world
Great, we write our first buffer script, and run it!
Now, to save it to a file so it persists after shutting down.
> save 0
This save to file 0
. To load it back up, run this command:
> load 0
Now, let's try something harder, let's print to 100 with loop.
Here I'll just show what the buffer should look like.
00000 set 0 0
00001 say n $0
00002 cmp $0 100
00003 juge + 3
00004 add 0 $0 1
00005 jump - 4
In line 0
, it initialize variable 0
with 0
.
In line 1
, it print out the variable 0
. In a command, you can use ${variable}
to get the content of the variable.
Then, we compare with cmp
command, comparing the content of variable 0
and 100
.
If it is greater or equal, jump down 3 steps to line 6
which escape the whole sequence.
In line 4
, we add the content of variable 0
with 1
and store it back to variable 0
.
Lastly, we jump up four steps which go back to line 1
.