qbinux - several questions

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Seb McClouth

qbinux - several questions

Post by Seb McClouth »

I'm at work and can't download nor view zip-files.

* I want to make my own filesystem for qbinux, how can I achieve this?

* BIOS support, I want to extract lots of data from the BIOS, but never get what I want...

grtz

Seb
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

For your own filesystem do you mean not merely intreface the DOS filesystem? In this case, create a huge file (2 GB) and manage it as you like.
You could divid it in chunks of perhps 2 to 4 k and break files in pieces of the same size.You should maintain a table of which chunk is allocated, and which chunk follows any one. Directories would be files...Not a trivial task.

For bios reference you should check Ralf Brown interrupt reference. Check to o ABC packets at QBasicNews for samples.
Seb McClouth

Post by Seb McClouth »

How can I manage this file, build this table...

Another question: my hd only contains about 800mb... it's an old 486 IBM Thinkpad laptop...

grtz

Seb
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

To make a filesystem is not trivial work, I have never done it, my ideas are from how DOS filesystem works. You should ask some GUI guru...


You should create two RANDOM files, one for the sector table, one forthe actual data.

The size of the datafile is up to you, DOS supports up to 2GB.You should decide the sector size for your filesystem, too big will waste space, too small it will slow down the read and write of big files. The filesystem must be open for RANDOM with a record size equal to the sector size. This way you can read and write sector n in a simple operation.
The table should have a record with a single field per sector, it should index the next sector,with a special mark for empty sector, another for end of file.

Directory is just a file with a special format, holding several entries in a single sector. Each entry should have the file name and an index to the first sector(with a special value for unused directory entry) , and whatever else you want to put in. The directory must start in the first sector so you can find it.

To create a file you should:
Find the first sector available (marked as empty) in the table.
Make a directory entry with the filename and the index to the first record.
Split the file in chunks of sector size, to be able to write them in the free sectors (they can be non-adjacent). Every time you write a new sector you add the index to it in the table entry for the previous sector. The last sector is marked as EOF in the table.
To read a file you find your entry in the directory, get the index to the
first sector,then you can find the next sectors from the table, keep retrieving them up to the EOF mark.

To erase a file simply mark all its table entries as empty and mark its directory entry as empty.

The directory is a file starting in the first sector, if it grows more sectors can be allocated to it. A directory entry can be marked as deleted, so a new file can reuse it's entry.

Every read and write to the files should be buffred, to write a char in a position you retrieve the full sector, write the char to the buffre and write it to its sector.

Hope it helps....
User avatar
SebMcClouth
Veteran
Posts: 240
Joined: Fri Apr 29, 2005 2:20 am
Location: Inside the Matrix

Post by SebMcClouth »

okay, could you give some code examples?? That would make things a bit easier...

grtz
Guest

Post by Guest »

Do you mean WORKING code? ...That's a serious project...Sorry, I have no time for it. I can elaborate on my explanation if you want. Just ask!
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

SebMcClouth wrote:okay, could you give some code examples?? That would make things a bit easier...

grtz
Hi Seb,

You can do this using BINARY files as well (might save a few bytes depending on what you do with it).

If you go here: http://www.petesqbsite.com/sections/exp ... inaryfiles

And read that thouroughly, you will have your working sample of how to work with bynary files....using TYPE definitions to store your data. but to create a sample, will need a bit of time. here's a few guidelines.

The Binary file that will hold the File records could be something like.
TYPE FileRecord
FileName AS STRING
Position AS LONG
END TYPE

Then when you add a file in there you just calculate the position in the second file and position yourself at Position to start reading the file.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Seb McClouth

Post by Seb McClouth »

It's starting to look really good here... the code that is...
'nother question... if I for example give a command... which I want
to be executed within lets say 15 seconds, but still want to continue the program, how can I do this?

E.G.:

Code: Select all

'begin
input "", cmd$
if cmd$ = "start game2 15" then
   'start game in 15 seconds, return to begin
elseif cmd$="exit" then
   end
end if
'goto begin
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

you could do something like:

Code: Select all

'begin
StartingPoint:
    input "", cmd$
    if cmd$ = "start game2 15" then
       'start game in 15 seconds, return to begin
       SLEEP 15 ' 15000 in FreeBasic
       SHELL "Game2"
    elseif cmd$="exit" then
       end
    end if
    goto StartingPoint

Approoximitaly :-)
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

Use timer variables:
When starting a timeout, set a timing variable to the number of seconds to wait.
In your main loop check regularly for the timer, each time a second passes decrease all active timer variables
If one active timer reaches zero, the timeout has expired, so run whatever program you tied to it.

After reaching 0, in the next check you could set the variable to -1, to indicate a not active timer.
Seb McClouth

Post by Seb McClouth »

MystikShadows wrote:you could do something like:

Code: Select all

'begin
StartingPoint:
    input "", cmd$
    if cmd$ = "start game2 15" then
       'start game in 15 seconds, return to begin
       SLEEP 15 ' 15000 in FreeBasic
       SHELL "Game2"
    elseif cmd$="exit" then
       end
    end if
    goto StartingPoint

Approoximitaly :-)
Yes but doesn't that just stop the program for 15 sec without running the input?
Seb McClouth

Post by Seb McClouth »

Antoni wrote:Use timer variables:
When starting a timeout, set a timing variable to the number of seconds to wait.
In your main loop check regularly for the timer, each time a second passes decrease all active timer variables
If one active timer reaches zero, the timeout has expired, so run whatever program you tied to it.

After reaching 0, in the next check you could set the variable to -1, to indicate a not active timer.
Okay... to use some real core code:

Code: Select all

Input "", cmd$
if left$(cmd$,8)="shutdown" then
  on timer val(right$(cmd$,2)) end
end if
Sumfin like this, or... how then?

grtz
Guest

Post by Guest »

Someting like this....

Code: Select all

'main loop
type timertype
t as integer
p as string*12
end type[code]
'main loop
type timertype
 t as integer
 p as string*12
end type
dim timers(10) as timertype
for i=0 to 10:timers(i).time=-1:next i
dim shared t!
'
'--------------------------------------
sub startimer(timeout,prog$)
 'search for an unused timer
 i=0
 while timers(i).t>0
  i=i+1
 wend
 if i>10 then print "No timers available":exit sub
 'inmitialize the timer 
 timers(i).t=timeout
 timers(i).p=prog$
end sub
'
'--------------------------------------
sub updatetimers
'if more than a second is passed from last update, do an update 
if timer>t!+1 then
  t!=timer
  'check for all timers 
  for i=0 to 10
    'if timer active
    if timers(i).t>0 then
      'decrease it   
      timers(i).t=timers(i).t-1
      'if 0     
      if timers(i).t=0 then
         'disable it 
         timers(i).t=-1
         'run the program   
         run timers(i).p
      end if
    end if
  next
end timer     
end sub
'
'--------------------------------------
'main program

'start some timers
settimer(15,"foo.exe")
settimer(5,"bar.exe")
'
do
  updatetimers
  'do other things.....
loop







do


loop
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

Forgot to login again...
Someting like this:

Code: Select all

'main loop
type timertype
 t as integer
 p as string*12
end type
dim shared timers(10) as timertype
for i=0 to 10:timers(i).time=-1:next i
dim shared t!
'
'--------------------------------------
sub startimer(timeout,prog$)
 'search for an unused timer
 i=0
 while timers(i).t>0
  i=i+1
 wend
 if i>10 then print "No timers available":exit sub
 'inmitialize the timer 
 timers(i).t=timeout
 timers(i).p=prog$
end sub
'
'--------------------------------------
sub updatetimers
'if more than a second is passed from last update, do an update 
if timer>t!+1 then
  t!=timer
  'check for all timers 
  for i=0 to 10
    'if timer active
    if timers(i).t>0 then
      'decrease it   
      timers(i).t=timers(i).t-1
      'if 0     
      if timers(i).t=0 then
         'disable it 
         timers(i).t=-1
         'run the program   
         run timers(i).p
      end if
    end if
  next
end timer     
end sub
'
'--------------------------------------
'main program

'start some timers
settimer(15,"foo.exe")
settimer(5,"bar.exe")
do
 .....
 updatetimers
 ......
loop
User avatar
SebMcClouth
Veteran
Posts: 240
Joined: Fri Apr 29, 2005 2:20 am
Location: Inside the Matrix

Post by SebMcClouth »

So I noticed... but how can I put this in my code... I actually need for the following:

If I give the command: shutdown -h +15

I need Quickbasic to exit the program in e.g. 15 mins or secs (not sure yet)

For some splainy: -h means halt...

grtz
Seb
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

You must parse the input line and set the timer accordingly...
Seb McClouth

Post by Seb McClouth »

I've copied your code and will try to adapt and add it today to see if it works. It looks great.

Thx mate.

Grtz

Seb
Post Reply