Compare commits

..

7 Commits

Author SHA1 Message Date
beca477ff9 Update README.md 2026-03-03 20:14:38 +01:00
deadvey
02657c3fcd Added California & Colarado laws, copied & modifed from https://github.com/c3d/db48x/blob/stable/LEGAL-NOTICE.md 2026-03-03 19:13:16 +00:00
deadvey
a3ed2c801a BASIC DEVELOPMENT 2026-03-03 15:37:18 +00:00
696f8198ad Update README.md
mistake
2026-02-26 16:05:44 +01:00
04ab45dd36 Update README.md 2026-02-26 16:05:14 +01:00
deadvey
4a655e991e BASIC dev docs 2026-02-26 14:47:41 +00:00
deadvey
54d0665456 Modified the BASIC interpreter to support comments using #
and sol whitespace support (eg tabs or spaces for indentation)
2026-02-26 12:26:46 +00:00
9 changed files with 577 additions and 33 deletions

View File

@@ -35,6 +35,9 @@ qemu-system-i386 -drive file=disk_images/crawos.img,if=floppy,format=raw
``` ```
Or it can be burnt to a physical disk to be booted from<br/> Or it can be burnt to a physical disk to be booted from<br/>
hardware. hardware.
> [!NOTE]
> The VM setup has only been tested on OpenSUSE and NixOS Linux,<br/>
> please report any bugs.
# Development # Development
In order to run this project in testing mode you can use<br/> In order to run this project in testing mode you can use<br/>
@@ -49,6 +52,15 @@ To allow for easier debugging.
# BASIC development # BASIC development
Please refer to the [MikeOS BASIC documentation](https://mikeos.sourceforge.net/handbook-appdev-basic.html)<br/> Please refer to the [MikeOS BASIC documentation](https://mikeos.sourceforge.net/handbook-appdev-basic.html)<br/>
docs on writing BASIC code. In order to create new<br/> docs on writing BASIC code. In order to create new<br/>
files, place them in the /data/ directory, not the file<br/> files, place them in the /data/ directory, note the file<br/>
names are limited to 11 characters due to FAT12 limitations<br/> names are limited to 11 characters due to FAT12 limitations<br/>
(8 for the name and 3 for the extension). (8 for the name and 3 for the extension).
# Legal information
As a consequence of recent legislative activity in [California](https://leginfo.legislature.ca.gov/faces/billTextClient.xhtml?bill_id=202520260AB1043) and [Colororado](https://leg.colorado.gov/bill_files/111670/download):
* California residents may no longer use CrawOS after Jan 1st, 2027.
* Colorado residents may no longer use CrawOS after Jan 1st, 2028.
CrawOS is probably an operating system under these laws. However, it
does not, cannot and will not implement age verification.

View File

@@ -1,9 +1,11 @@
FOR A = 1 TO 100 # A cool fizzbuzz program
PRINT A ; PRINT "FizzBuzz!"
B = A % 3 FOR A = 1 TO 16
C = A % 5 PRINT A ; # Prints the number
IF B = 0 then PRINT "Fizz" ; B = A % 3
IF C = 0 then PRINT "Buzz" ; C = A % 5
PRINT "" IF B = 0 then PRINT "Fizz" ;
IF C = 0 then PRINT "Buzz" ;
PRINT ""
NEXT A NEXT A
END END

View File

@@ -1,17 +1,17 @@
$1 = "_________" $1 = "_________"
A = & $1 A = & $1
FOR X = 1 TO 9 FOR X = 1 TO 9
FOR Y = 1 TO 9 FOR Y = 1 TO 9
PEEK B A PEEK B A
IF B = 95 THEN PRINT "_" ; IF B = 95 THEN PRINT "_" ;
IF B = 88 THEN PRINT "X" ; IF B = 88 THEN PRINT "X" ;
IF B = 79 THEN PRINT "O" ; IF B = 79 THEN PRINT "O" ;
C = A % 3 C = A % 3
IF C = 0 THEN PRINT " " IF C = 0 THEN PRINT " "
A = A + 1 A = A + 1
NEXT Y NEXT Y
Z = X % 2 Z = X % 2
IF Z = 0 THEN PRINT "You are X" IF Z = 0 THEN PRINT "You are X"
IF Z = 1 THEN PRINT "You are O" IF Z = 1 THEN PRINT "You are O"
NEXT X NEXT X
END END

501
docs/BASIC_DEVELOPMENT.md Normal file
View File

@@ -0,0 +1,501 @@
This kernel uses a modified version of the MikeOS BASIC interpreter.<br/>
# Overview
## Features
The MikeOS BASIC interpreter runs a simple dialect of the BASIC programming language. There are commands for taking input, handling the screen, performing nested loops, loading/saving files, and so forth. You will find a full list of the included instructions later in this document. Here are the essentials you need to know.
Numeric variables -- These are A to Z, each storing one positive integer word (ie 0 to 65535). The R and S variables have special roles with LOAD and SAVE commands, as explained in the instruction list below.
String variables -- These are $1 to $8, each 128 bytes long.
Arrays -- You can use string variables as arrays via the PEEK and POKE commands. For instance, X = & $1 places the memory location of the $1 string variable into X. You can then put data into it with eg POKE 77 X (put 77 into the memory location pointed to by X).
Labels -- Such as box_loop: etc. Used by GOTO and GOSUB, they must have a trailing colon and be at the start of a line.
Ending -- Programs must finish with an END statement.
GOSUB calls can be nested up to ten times. FOR loops can be nested using different variables (eg you can have a FOR X = 1 TO 10 ... NEXT X loop surrounding a FOR Y = 30 TO 50 loop). You can enter code in uppercase or lowercase -- the interpreter doesn't mind either way. However, labels are case-sensitive.
If a MikeOS BASIC program is run from the command line, and one or more parameters was provided with the command, they are copied into the $1 string when the program starts.
## Example
Here's a small example program demonstrating a FizzBuzz program.
```
# A cool fizzbuzz program
PRINT "FizzBuzz!"
FOR A = 1 TO 16
PRINT A ; # Prints the number
B = A % 3
C = A % 5
IF B = 0 then PRINT "Fizz" ;
IF C = 0 then PRINT "Buzz" ;
PRINT ""
NEXT A
END
```
This example should be mostly self-explanatory. You can see that the subroutine is indented with tabs, but that's not necessary if you don't want it. You can follow IF ... THEN with any other instruction. Regarding this part:
```
PRINT A ; # Prints the number
B = A % 3
```
The space and semi-colon character (;) after the quoted string tells the interpreter not to print a newline after the string. So here, we print the user's name on the same line. You can do this with numerical variables as well, eg PRINT X ; etc.
See the Samples section at the end for more demonstration programs.
## Assignment
The following are valid ways to assign numeric variables in MikeOS BASIC:
```
a = 10
a = b
a = b + 10
a = b + c
a = b - 10
a = b - c
a = b * 10
a = b * c
a = b / 10
a = b / c
a = b % 10
a = b % c
```
So you can use combinations of numbers and variables. Note that you can perform multiple operations in the same line:
```
a = b + c * 2 / 3
```
But note that there is no operator precedence; the calculation is simply worked out one step at a time from left to right. For string variables:
```
$1 = "Hello"
$2 = $1
```
You can get the location of a string variable to use as an array:
```
x = & $3
```
You can get variables from the user with INPUT like this:
```
input x
input $1
```
## Keywords
You can do this to get the MikeOS API version number:
```
x = VERSION
```
Or you can retrieve the lower word of the system clock like this:
```
x = TIMER
```
To get the current ink colour, use:
```
x = INK
```
## The editor
You can run your .BAS programs by using the BAS core util eg.
```
bas <filename>.bas
```
# Instructions
## BREAK
Halts execution of the BASIC program and prints the line number in the BASIC file. Useful for debugging.
## CALL
Moves machine code execution to the specified point in RAM (using the x86 call instruction). The code must be terminated with a ret (C3 hex, 195 decimal) instruction. In this example, we simply add a ret instruction into RAM location 40000 and call it, which returns control straight back to the BASIC interpreter:
```
poke 195 40000
call 40000
```
## CASE
Changes the contents of a string to all upper-case or lower-case.
```
case lower $1
case upper $2
```
## CLS
Clears the screen and returns the cursor to the top-left corner of the screen. Example:
```
cls
```
## CURSOR
Determines whether to show the text cursor or not. Example:
cursor off
print "The cursor is off for five seconds!"
pause 50
cursor on
print "And now it's back on."
## CURSCHAR
Stores the character underneath the cursor location into the specified variable. Example:
```
move 0 0
print "Hello world"
move 0 0
curschar x
# The next command will print 'H'
print chr x
move 1 0
curschar x
# The next command will print 'e'
print chr x
```
## CURSCOL
Get the colour of the character under the cursor. Example:
```
move 20 15
curscol x
```
## CURSPOS
Get the position of the cursor. Example:
```
# First is column, then row
curspos a b
```
## DELETE
Removes a file from the disk. Returns 0 in the R variable if the operation was a success, 1 if the delete operation couldn't be completed, or 2 if the file doesn't exist. Example:
```
delete "myfile.txt"
```
## DO
Perform a loop until a condition is met (UNTIL or WHILE). You can also set up an infinite loop with LOOP ENDLESS at the end. Example:
```
do
# Code goes here
loop until x = 10
```
## ELSE
Executes code if the previous IF condition didn't match. Example:
```
x = 1
if x = 1 then print "Hello"
else print "Goodbye"
```
## END
Terminates execution of the BASIC program and hands control back to the operating system.
## FILES
Prints a list of files that are on the disk on the screen.
## FOR
Begins a loop, counting upwards using a variable. The loop must be finished with a NEXT instruction and the relevant variable. Example:
```
for x = 1 to 10
print "In a loop! X is " ;
print x
next x
```
## GETKEY
Checks the keyboard buffer for a key, and if one has been pressed, places it into the specified variable.
```
loop:
print "Infinite loop until m or Esc is pressed..." ;
getkey x
if x = 'm' then goto done
goto loop
done:
print "Finished loop!"
```
## GOSUB
Takes a label. It executes a subroutine, which must be finished with a RETURN instruction. You can nest GOSUB routines up to 10 times. Example:
```
print "About to go into a subroutine..."
gosub mylabel
print "Subroutine done!"
end
mylabel:
print "Inside a GOSUB here!"
return
```
## GOTO
Takes a label, and jumps to that label in the code. Example:
```
print "Going to miss the next 'PRINT' line of code..."
goto skippy
print "This'll never be printed."
skippy:
print "And now we're back home"
```
## IF
Executes a command depending on a condition (or multiple conditions with AND). After stating the condition (eg whether one number is bigger than another, or whether two strings match) you must use THEN and follow with another instruction. Examples:
```
if x = 10 then print "X is 10! Woohoo"
if x = y then print "X is the same as Y"
if x = 'm' then print "X contains the letter m"
if x < y then print "Now X is less than Y"
if x > y then goto xbiggerthany
if $1 = "quit" then end
if $1 = $2 then gosub stringsmatch
```
## INPUT
Gets input from the user and stores the result into a numeric or string variable. Examples:
```
input x
input $1
```
## LEN
Stores the length of a string variable in a numeric variable. Example:
```
$1 = "Hello world"
len $1 x
```
## LOAD
Loads the specified file into RAM at the specified point. The first argument is the filename, and the second the location into which it should be loaded. If the file cannot be found or loaded, the R variable contains 1 after the instruction; otherwise it contains 0 and the S variable contains the file size. Examples:
```
load "example.txt" 40000
if r = 1 then goto fail
print "File size is:"
print s
end
fail:
print "File couldn't be loaded"
end
$1 = "example.txt"
x = 40000
load $1 x
if r = 1 then goto fail
print "File size is:"
print s
end
fail:
print "File couldn't be loaded"
end
```
## NEXT
Continues the FOR loop specified previously, and must be followed by a variable. See FOR above. Example:
```
next x
```
## NUMBER
Converts strings to numbers and vice versa. Examples:
```
number $1 a
number a $1
```
## PAUSE
Delays execution of the program by the specified 10ths of a second. This ultimately results in a BIOS call and may be slower or faster in some PC emulators. Try it on real hardware to be sure. Example:
```
print "Now let's wait for three seconds..."
pause 30
print "Hey, and one more, this time with a variable..."
x = 10
pause x
```
## PAGE
Switch between working and active (display) pages. Example:
```
page 1 0
```
## PEEK
Retrieve the byte stored in the specifed location in RAM. Examples:
```
peek a 40000
print "The number stored in memory location 40000 is..."
print a
x = 32768
peek a x
```
> [!NOTE]
> You can use PEEKINT to work with words instead of bytes (up to 65536).
## POKE
Insert the byte (0 to 255) value into the specified location in RAM. Example:
```
print "Putting the number 126 into location 40000 in memory..."
poke 126 40000
print "Now doing the same, but using variables..."
x = 126
y = 40000
poke x y
```
> [!NOTE]
> You can use POKEINT to work with words instead of bytes (up to 65536).
## PORT
Sends and receives bytes from the specified port. Examples:
```
x = 1
port out 1234 x
port out 1234 15
port in 1234 x
```
## PRINT
Displays text or the contents of a variable onto the screen. This will also move the cursor onto a new line after printing, unless the command is followed by a space and semi-colon. Example:
```
print "Hello, world!"
$1 = "Some text"
print $1
x = 123
print x
$2 = "Mike"
print "No newlines here, " ;
print $2
```
> [!NOTE]
> For numerical variables, the PRINT command also supports two extra keywords:
```
x = 109
print x
print chr x
print hex x
```
In the first print command, the output is 109. In the second, the output is the ASCII character for 109 -- that is, 'm'. And in the third command, it shows the hexadecimal equivalent of 109.
## RAND
Generate a random integer number between two values (inclusive) and store it in a variable. Example:
```
Make X a random number between 50 and 2000
rand x 50 2000
```
## READ
Read data bytes from a label, first specifying the offset and a variable into which to read. For instance, in the following example we read a small program and poke it into memory locations 50000 to 50012. We then call that location to run the program:
```
y = 1
for x = 50000 to 50012
read mydata y a
poke a x
y = y + 1
next x
call 50000
waitkey x
end
mydata:
190 87 195 232 173 60 195 89 111 33 13 10 0
```
## RENAME
Renames one file to another. Literal strings and string variables are allowed. Afterwards, R contains 0 if the operation was a success, 1 if the file was not found, 2 if the write operation failed, or 3 if the target file already exists. Example:
```
$1 = "myfile.dat"
rename "oldfile.txt" $1
```
## RETURN
Switches execution back to the position of the prior GOSUB statement. See GOSUB above for more information. Example:
```
return
```
## SAVE
Saves data from memory to a file on the disk. The first parameter is the filename, the second the location in RAM where the data starts, and the third the number (in bytes) the amount of data to save. After execution, the R variable contains 1 if the file save operation failed (eg if it's a write-only medium), 2 if the file already exists, or 0 if it was successful. Examples:
```
save "myfile.txt" 40000 256
$1 = "myfile.txt"
x = 40000
y = 256
save $1 x y
```
## STRING
Get or set bytes in a string variable, specified by an offset. Examples:
```
$1 = "Hello world"
rem *** 121 = ASCII for "y" character ***
b = 121
string set $1 5 b
rem *** Now $1 contains "Helly world" ***
print $1
```
# Modifictions
The modifications include
- Inline comments starting with a hashtag (#)
- Start of line whitespaces for indentation, spaces or tabs (not fussy about indentation depth)

4
docs/MEMORY_LAYOUT.md Normal file
View File

@@ -0,0 +1,4 @@
The root directory is from byte 24000h to 26FFFh<br/>
The currently opened file's metadata is from 27000h to 2701Fh<br/>
The to be outputted string is stored from 27020h to 27FFFh<br/>
The currently opened file is from 28000h<br/>

View File

View File

@@ -3970,6 +3970,14 @@ get_token:
mov word si, [prog] mov word si, [prog]
lodsb lodsb
cmp al, 09h
je .whitespace
cmp al, 20h
je .whitespace
cmp al, '#'
je .comment
cmp al, 10 cmp al, 10
je .newline je .newline
@@ -3990,13 +3998,28 @@ get_token:
jmp get_string_token jmp get_string_token
.whitespace:
inc word [prog]
jmp get_token
.comment:
inc word [prog] ; Move past first quote (") char
mov word si, [prog]
mov di, token
.loop:
lodsb
cmp al, 0Ah
je .done
inc word [prog]
jmp .loop
.done:
inc word [prog] ; Move past final quote
jmp get_token
.newline: .newline:
inc word [prog] inc word [prog]
jmp get_token jmp get_token
get_number_token: get_number_token:
mov word si, [prog] mov word si, [prog]
mov di, token mov di, token
@@ -4273,6 +4296,8 @@ vars_loc:
work_page db 0 ; Page to print to work_page db 0 ; Page to print to
disp_page db 0 ; Page to display disp_page db 0 ; Page to display
tab_skip db " ", 0
space_skip db " ", 0
alert_cmd db "ALERT", 0 alert_cmd db "ALERT", 0
askfile_cmd db "ASKFILE", 0 askfile_cmd db "ASKFILE", 0
break_cmd db "BREAK", 0 break_cmd db "BREAK", 0

View File

@@ -20,8 +20,8 @@ os_read_input:
keyboard_display_input: keyboard_display_input:
pusha pusha
mov di, ax mov di, ax
mov ax, bx ; Lazy TODO mov ax, bx
mov cx, [prompt_length] mov bx,20
.loop: .loop:
jmp .check_key_pressed jmp .check_key_pressed
@@ -40,11 +40,11 @@ keyboard_display_input:
cmp al, 1Bh cmp al, 1Bh
je .esc_key je .esc_key
cmp cx, 0 dec bx
jb .check_key_pressed
cmp bx, 0
jae .print_current_input ; Echo the user input back
call .print_current_input
dec cx
jmp .check_key_pressed jmp .check_key_pressed
.esc_key: .esc_key:
@@ -57,8 +57,9 @@ keyboard_display_input:
ret ; Return to the parent function (whatever that may be) ret ; Return to the parent function (whatever that may be)
.backspace: .backspace:
jmp .move_cursor_back ; then .move_cursor_back cmp bx, 20 ; Cannot backspace if the cursor is at the start
jmp .loop ; Else .loop jb .move_cursor_back ; then .move_cursor_back
jmp .loop ; Else .loop
.move_cursor_back: .move_cursor_back:
mov ah, 0Eh mov ah, 0Eh
@@ -70,16 +71,15 @@ keyboard_display_input:
mov al, 08h mov al, 08h
int 10h int 10h
inc bx
dec di dec di
jmp .loop jmp .loop
.print_current_input: ; Echo back that character and return the key inputing .print_current_input: ; Echo back that character and return the key inputing
stosb stosb
mov ah, 0Eh mov ah, 0Eh
int 10h int 10h
jmp .check_key_pressed
ret
keyboard_get_cursor_pos: ;TODO keyboard_get_cursor_pos: ;TODO
ret ret

View File