You could make a simple interpreter by taking a cli to the next stage,
Example of a simple basic interpreter
Main program
Code: Select all
use32
ORG 0x400000 ; where our program is loaded to
jmp start ; jump to the start of program.
db 'DEX1' ; We check for this, to make shore it a valid DexOS file.
;----------------------------------------------------;
; Start of program. ;
;----------------------------------------------------;
start:
mov ax,18h
mov ds,ax
mov es,ax
;----------------------------------------------------;
; Get calltable address. ;
;----------------------------------------------------;
mov edi,Functions ; this is the interrupt
mov al,0 ; we use to load the DexFunction.inc
mov ah,0x0a ; with the address to dex4u functions.
int 40h
;----------------------------------------------------;
; get_params. ;
;----------------------------------------------------;
get_params:
call [GetParams] ; ****needs error checking?****
add esi,7 ; <------hard coded for 7 letter step over
cmp byte[esi],'?' ; looking for help?
je help
mov edi,BasicFileBuff; Load the basic file
call [FloppyfileLoad]
jc load_error
;----------------------------------------------------;
; Main loop. ;
;----------------------------------------------------;
mov [BFPointer],BasicFileBuff
CommandsLoop:
mov esi,[BFPointer]
cmp byte[esi],13 ; check for a ret
jne No_Ret
inc esi ; inc past
mov [BFPointer],esi
jmp CommandsLoop ; in case of more then one
No_Ret:
cmp byte[esi],10 ; check for line feed
jne Commands
inc esi ; inc past
mov [BFPointer],esi
jmp CommandsLoop ; in case of more then one
;====================================================;
; Commands. ;
;====================================================;
Commands:
mov esi,[BFPointer] ; Check for 'end'
mov ecx,3 ; Number of letters to check
mov edi,cEND1
repe cmpsb
je ExitHere ; it's a match / jump to exit
mov esi,[BFPointer] ; Check for 'END'
mov ecx,3
mov edi,cEND
repe cmpsb
je ExitHere
mov esi,[BFPointer] ; Check for 'beep'
mov ecx,4
mov edi,cBEEP1
repe cmpsb
je Beep
mov esi,[BFPointer] ; Check for 'BEEP'
mov ecx,4
mov edi,cBEEP
repe cmpsb
je Beep
mov esi,[BFPointer] ; Check for 'print'
mov ecx,5
mov edi,cPRINT
repe cmpsb
je ItIsPrint
mov esi,[BFPointer] ; Check for 'PRINT'
mov ecx,5
mov edi,cPRINT1
repe cmpsb
je ItIsPrint
;====================================================;
; Print Bad Command. ;
;====================================================;
not_Command:
mov esi,BadCommand ; *****needs to end program*****
call [PrintString]
mov al,byte[BFPointer]
call [WriteHex8]
mov esi,[BFPointer]
call [PrintString]
call [WaitForKeyPress]
cmp ah,1
jne CommandsLoop
jmp ExitHere
;====================================================;
; Load file error ;
;====================================================;
load_error:
mov esi,LError ; error loading file
call [PrintString] ; print message
call [WaitForKeyPress] ; end program
jmp ExitHere
;====================================================;
; Print end of command message. ;
;====================================================;
PrintEndMessage1:
mov esi,PrintEndMessage ;**** needs to end program ****
call [PrintString]
call [WaitForKeyPress]
cmp ah,1
jne CommandsLoop
;====================================================;
; Exit.. ;
;====================================================;
ExitHere:
mov esi,PrintEndMessage
call [PrintString]
call [WaitForKeyPress]
ret
;====================================================;
; Print Bacic command error message. ;
;====================================================;
ErrorMessage:
mov esi,ErrorMessage1 ; ****needs to end program****
call [PrintString]
call [WaitForKeyPress]
cmp ah,1
je ExitHere
jmp CommandsLoop
;=====================================================;
; Help ;
;=====================================================;
help:
mov esi,StartMessage
call [PrintString]
mov esi,HInstr
call [PrintString]
call [WaitForKeyPress]
jmp ExitHere
;----------------------------------------------------;
; Data. ;
;----------------------------------------------------;
NextLine db 13,0
PrintEndMessage db 0xd2,0x07,13,13,"Thanks for using the Team DexOS Basic interpretor",13,0
StartMessage db 0xd2,0x02,"Team DexOS Basic interpretor",13," ver. alpha2",13,13,0
HInstr db 0xd2,0x03,"Comand line format: dbasic sample.bas",13,13
db 0xd2,0x07,"Supported Instructions:",13,13
db "print...supports text inside quots and , for no CR",13
db "beep....makes a tone",13
db "beep1",13
db "-----...makes different tones",13
db "beep9",13
db "end.....ends program",13,0
BadCommand db 0xd2,0x07,13,13, "Command not found, press anykey to try again or esc for exit ",13,13,0
ErrorMessage1 db 0xd2,0x07,13,13,"Error, Press anykey to continue or esc to exit",13,0
LError db 0xd2,0x02,13,13,"Error loading Basic file",13,13
db 0xd2,0x07,"format is: ",0xd2,0x04," dbasic sample.bas",13,13,0
BasicFileBuff: times 8192 db ? ;8kb Basic language file buffer
BFPointer dd 0
Hz dw 0
;---------------;
; Commands. ;
;---------------;
cPRINT db 'PRINT ',0
cPRINT1 db 'print ',0
cBEEP db 'BEEP ',0
cBEEP1 db 'beep ',0
cEND db 'END ',0
cEND1 db 'end ',0
;----------------------------------------------------;
; calltable include goes here. ;
;----------------------------------------------------;
include 'Dex.inc'
include 'sound.inc'
include 'print.inc'
Sound.inc
Code: Select all
;----------------------------------------------------;
; Sound.inc for DexBasic ;
; by Dex mods by Roboman ;
;----------------------------------------------------;
Beep:
mov [Hz],0x200 ; set in case of no number
mov esi,[BFPointer]
add esi,4 ; set pointer to end of word beep
xor ax,ax ; clear ax
mov ah,byte[es:esi] ; get beep number
cmp ah,31h ; check if it's a number
jb Beep_now ; to low to be a number use def tone
cmp ah,39h
ja Beep_now ; to high to be a number use def tone
sub ah,30h ; ascii to num
mov [Hz],ax ; set beep tone
Beep_now:
call Sound ; make tone
call DeLay ; leave it on a second
call NoSound ; turn it off
add [BFPointer],5 ; move pointer to about end of line
jmp CommandsLoop
;----------------------------------------------------;
; Sound ;
;----------------------------------------------------;
Sound:
mov bx,[Hz]
mov ax,0x34dd
mov dx,0x0012
cmp dx,bx
jnc Done1
div bx
mov bx,ax
in al,0x61
test al,3
jnz A99
or al,3
out 0x61,al
mov al,0xb6
out 0x43,al
A99:
mov al,bl
out 0x42,al
mov al,bh
out 0x42,al
Done1:
ret
;----------------------------------------------------;
; NoSound ;
;----------------------------------------------------;
NoSound:
in al,0x61
and al,11111100b
out 0x61,al
ret
;----------------------------------------------------;
; NoSound ;
;----------------------------------------------------;
DeLay:
push eax
mov ax,8
call [SetDelay]
pop eax
ret
Print.inc
Code: Select all
;----------------------------------------------------;
; Print.inc for DexBasic ;
; by Dex mods by Roboman ;
;----------------------------------------------------;
ItIsPrint:
mov edi,[BFPointer] ; get pointer to the print command we are working with
add edi,5 ; move past word print
cmp byte[es:edi],' ' ; did they leave a space
jne PrintLoop
PrintLoop1:
inc edi
PrintLoop:
cmp byte[es:edi],'"' ; ***need to add check for var.***
je PrintText ; display text inside quots
cmp byte[es:edi],','
je PrintComma ; Do comma command functions
cmp byte[es:edi],13 ; End of line?
je PrintEnd
jmp ErrorMessage
PrintText:
inc edi ; add one to basic file pointer
cmp byte[es:edi],'"' ; end of text?
je PrintLoop1
cmp byte[es:edi],13 ; end of line?
je PrintEnd
mov al,byte[es:edi] ; grab byte from file and display it
call [PrintCharCursor]
jmp PrintText ; check for more text in quots
PrintComma:
inc edi
cmp byte[es:edi],13 ; end of line?
je PrintEnd1 ; skip cr / end print
jmp PrintLoop ; inc and check next char
PrintEnd:
mov esi,NextLine
call [PrintString]
PrintEnd1:
inc edi
mov [BFPointer],edi ; update basic file pointer to next command
jmp CommandsLoop
The test .bas would be like this:
Code: Select all
print "test tone"
beep
print "test tone 1"
beep1
print "test tone 2"
beep2
print "test tone 3"
beep3
print "test tone 4"
beep4
print "test tone 5"
beep5
print "test tone 6"
beep6
print "test tone 7"
beep7
print "test tone 8"
beep8
print "test tone 9"
beep9
print "test tone"
beep
print "Text ",
print "on ",
print "more ",
print "then ",
print "one ",
print "line."
print
print "A skipped line"
print "line: ","test"
end
This is in it simplest forum and to run on DexOS.