Part 2
kernel/fs/fs.bas:
Code: Select all
'
' fs.bas
'
'$INCLUDE:'include/qbinux.bi'
SUB AscendDir
END SUB
SUB bufferinit
EditArr = CreateArray(131074, 80)
IF EditArr = STRING$(8, 0) THEN
PRINT "Failed..."
END IF
END SUB
FUNCTION CreateArray$ (slots&, bytes%)
IF bytes > 8192 THEN EXIT FUNCTION
DO
arrn$ = RHEX(8)
LOOP WHILE FindFATFILE("ARR\" + arrn$ + ".Arr")
ff = FREEFILE
OPEN "ARR\" + arrn$ + ".Arr" FOR OUTPUT AS #FF
t$ = MKL$(slots&) + MKI$(bytes)
PRINT #ff, t$
FOR a = 8193 TO bytes STEP - 1
i! = a / bytes
n! = slots& / ( a / bytes)
IF i! = INT(a / bytes) AND n! = INT(n!) THEN EXIT FOR
NEXT
END FUNCTION
FUNCTION FindFATFile (fil AS STRING)
spec$ = fil + CHR$(0)
RegsX.AX = &H4E00
RegsX.CX = 39
RegsX.DX = SADD(Spec$)
RegsX.DS = SSEG(Spec$)
InterruptX &H21, RegsX, RegsX
IF RegsX.flags AND 1 THEN
FindFATFile = VAL("0")
ELSE
FindFATFile = VAL("1")
END IF
END FUNCTION
FUNCTION GetID& (filedir AS STRING, typ AS INTEGER)
IF filedir = "" THEN EXIT FUNCTION
ff = FREEFILE
IF typ = 0 THEN 'file
IF FindFATFile("NVXFS/FileList.nff") = 0 THEN GetID = 0: EXIT FUNCTION
OPEN "NVXFS/FileList.nff" FOR BINARY AS #ff
mt$ = " "
GET #ff, 1, mt$
k = CVI(mt$)
FOR a = 0 TO k
offs& = a * 272& + 3
t$ = SPACE$(271)
GET #ff, offs&, t$
dnam$ = MID$(t$, 2, ASC(MID$(t$, 1, 1)))
ddrive$ = MID$(t$, 257, 4)
ddir$ = MID$(t$, 261, 4)
ID$ = MID$(t$, 265, 4)
IF dnam$ = filedir THEN
IF ddrive$ = CurDrive THEN
IF ddir$ = CurDir THEN
GetID& = CVL(ID$)
CLOSE #ff
EXIT FUNCTION
END IF
END IF
END IF
NEXT
CLOSE #FF
ELSEIF typ = 1 THEN 'directory
IF FindFATFile("NVXFS/DirList.nfd") = 0 THEN GetID = 0: EXIT FUNCTION
OPEN "NVXFS/DirList.nfd" FOR BINARY AS #FF
mt$ = " "
GET #ff, 1, mt$
k = CVI(mt$)
FOR a = 0 TO k
offs& = a * 272& + 3
t$ = SPACE$(271)
GET #ff, offs&, t$
dnam$ = MID$(t$, 2, ASC(MID$(t$, 1, 1)))
ddrive$ = MID$(t$, 257, 4)
ddir$ = MID$(t$, 261, 4)
ID$ = MID$(t$, 265, 4)
IF dnam$ = filedir THEN
IF ddrive$ = CurDrive THEN
IF ddir$ = CurDir THEN
GetID& = CVL(ID$)
CLOSE #ff
EXIT FUNCTION
END IF
END IF
END IF
NEXT
CLOSE #ff
ELSE 'drive
IF FindFATFile("NVXFS/DrvList.drv") = 0 THEN GetID = 0: EXIT FUNCTION
END IF
END FUNCTION
SUB MakDir (dir AS STRING)
odir$ = CurDir
dirn$ = WorkPath(dir)
END SUB
FUNCTION RHEX$ (lenght AS INTEGER)
FOR A = 1 to lenght
s$ = s$ + HEX$(INT(16 * RND))
NEXT
RHEX$ = s$
END FUNCTION
SUB SetDir (DirID AS LONG)
CurDir = MKL$(DirID)
END SUB
SUB SetDrv (DrvID AS LONG)
CurDrive = MKL$(DrvID)
END SUB
FUNCTION WorkPath$ (file AS STRING)
h$ = file
Ompa$ = CurDir
IF INSTR(file, "/") THEN
DO
t$ = LEFT$(h$, INSTR(h$, "/") - 1)
IF t$ = "..." THEN
SetDir 0
ELSEIF t$ = ".." THEN
AscendDir
ELSE
IF GetID(t$, 1) <> 0 THEN
SetDir GetID(t$, 1)
ELSE
WorkPath$ = "DNF"
CurDir = Ompa$
EXIT FUNCTION
END IF
END IF
h$ = RIGHT$(h$, LEN(h$) - (LEN(t$) + 1))
LOOP WHILE INSTR(h$, "/")
END IF
WorkPath$ = h$
END FUNCTION
kernel/init/main.bas:
Code: Select all
'
' main.bas
'
'$INCLUDE:'include/qbinux.bi'
'
' Yeah, yeah, it's ugly, but I cannot find how to do this correctly
' and this seems to work. If anybody has more info on the real-time
' clock I'd be interested. Most of this was trial and error, and some
' bios-listing reading. Urghh.
'
REM $STATIC
FUNCTION BCD2BIN (Value AS INTEGER)
BCD2BIN = ((Value) AND 15) + (BitShift(Value, ">>", 4) * 10)
END FUNCTION
'Needs to be moved to proper library
REM $DYNAMIC
FUNCTION BitShift (Value%, way$, count%)
IF way$ = "<<" THEN
X = Value% * (2 ^ count%)
temp& = x%
temp& = (temp% * (X ^ count%)) AND &HFFFF
BitShift = temp&
ELSEIF way$ = ">>" THEN
BitShift = INT(Value% / 2 ^ count%)
END IF
END FUNCTION
FUNCTION CMOS.Read (Addr)
OUT &H70, Addr
CMOS.Read = INP(&H71)
END FUNCTION
SUB init
setup
END SUB
SUB main
timeinit
sched.init
bufferinit
hdinit
movetousermode
rem init
END SUB
SUB movetousermode
PriPub = CHR$(BITS2NUM("11000000"))
IsSystem = CHR$(BITS2NUM("00000000"))
END SUB
SUB timeinit
DO
tme.sec = CMOS.READ(0)
tme.min = CMOS.READ(2)
tme.hour = CMOS.READ(4)
tme.mday = CMOS.READ(7)
tme.mon = CMOS.READ(8)
tme.year = CMOS.READ(9)
LOOP WHILE (tme.sec = CMOS.READ(0))
x% = BCD2BIN(tme.sec): tme.sec = x%
x% = BCD2BIN(tme.min): tme.min = x%
x% = BCD2BIN(tme.hour): tme.hour = x%
x% = BCD2BIN(tme.mday): tme.mday = x%
x% = BCD2BIN(tme.mon): tme.mon = x%
x% = BCD2BIN(tme.year): tme.year = x%
startuptime = Kernel.MkTime(tme)
END SUB