Can't see the wood for the trees. Help!

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
dave.steadman
Newbie
Posts:2
Joined:Wed Oct 09, 2002 5:25 pm
Can't see the wood for the trees. Help!

Post by dave.steadman » Tue Oct 15, 2002 1:13 am

I'm trying to manipulate the boot record of a floppy disk in various ways. One such way is allocating the Floppy an 'Illegal' label - Yes I can hear you now saying, but why? and that's stupid!
I'm trying because ... well that's it really, because ...

I'm not going to ask you for code on this one, but if some sole could tell me where I'm going wrong with the code - OR - why the code will not work I would be very grateful.  I'm seeing spots now I've looked at it for so long.

Cheers
Steady ...   ???

Code: Select all

' $DYNAMIC
DEFINT A-Z
' declaring the registers
TYPE RegTypeX
        ax      AS INTEGER
        bx      AS INTEGER
        cx      AS INTEGER
        dx      AS INTEGER
        bp      AS INTEGER
        si      AS INTEGER
        di      AS INTEGER
        FLAGS   AS INTEGER
        Ds      AS INTEGER
        es      AS INTEGER
END TYPE
CLS
DIM inregs AS RegTypeX, outregs AS RegTypeX

'Set up a buffer large enough to hold one disk sector (512bytes)
Sbuffer$ = STRING$(512, " ")

'Read from the floppy boot record, repeating the read 4 times
'to allow the floppy time to spin up to speed.
FOR Re = 1 TO 4
        inregs.dx = 0           'DRIVE0(A:)
        inregs.ax = 0           'function0
        CALL INTERRUPTX(&H13, inregs, outregs)
        'Interrupt 13, function 0 - reset disk system
        inregs.es = VARSEG(Sbuffer$)
        'Es and BX point to address of disk buffer
        inregs.bx = SADD(Sbuffer$)
        inregs.ax = &H201       'function 2, read 1 sector
        inregs.cx = &H1         'sector #1, the boot record
        CALL INTERRUPTX(&H13, inregs, outregs)
NEXT

PRINT "Boot Record acquired :-"

'Create a buffer large enough to hold 14 disk sectors
RootBuffer$ = STRING$(7168, 0)
'Get the root directory entries
FOR Re = 1 TO 4
        inregs.dx = 0: inregs.ax = 0
        CALL INTERRUPTX(&H13, inregs, outregs)
        inregs.dx = &H100               'side 1,drive0
        inregs.es = VARSEG(RootBuffer$)
        inregs.bx = SADD(RootBuffer$)
        inregs.ax = &H20E               'function 2 read, 14 sectors
        inregs.cx = 2                   'starting at sector #2
        CALL INTERRUPTX(&H13, inregs, outregs)
NEXT
PRINT "Root directory entries acquired :- "


'lets give th floppy an "illegal" volume label.
'First give it a legal label using the DOS LABEL command.  
'using that value to search the floppy's root directory entries.
LBL$ = "QWERTYUIOPA"
SHL$ = "LABEL A: " + LBL$
SHELL SHL$
PRINT "Legal name allocated :- "; LBL$

'set the volume label to spomething strange
NLabel$ = "Xxx-Xxxx?!?"
PRINT "New Floppy Label chosen is :- "; NLabel$

PRINT "Searching for :- "; LBL$
MID$(RootBuffer$, INSTR(UCASE$(RootBuffer$), LBL$), 11) = NLabel$

'Set the volume label in the boot sector, too
MID$(Sbuffer$, 44, 11) = NLabel$
a$ = MID$(Sbuffer$, 44, 11)
PRINT "New label to boot string is :- "; a$

PRINT "writing to boot record !"
'write the changes to the floppy boot record
FOR Re = 1 TO 4
        inregs.dx = 0
        inregs.ax = 0
        CALL INTERRUPTX(&H13, inregs, outregs)
        inregs.es = VARSEG(Sbuffer$)
        inregs.bx = SADD(Sbuffer$)
        inregs.ax = &H301                       'function 3, write one sector
        inregs.cx = &H1                         'at sector #1
        CALL INTERRUPTX(&H13, inregs, outregs)
NEXT
PRINT "New label written to boot record !"

PRINT "Writing to root directory !"
'Write the changes to the root directory
FOR Re = 1 TO 4
        inregs.dx = 0: inregs.ax = 0
        CALL INTERRUPTX(&H13, inregs, outregs)
        inregs.dx = &H100                       'side 1, drive 0
        inregs.es = VARSEG(RootBuffer$)
        inregs.bx = SADD(RootBuffer$)
        inregs.ax = &H30E                       'function 3, write 14 sectors
        inregsCX = 2                            'starting at sector #2
        CALL INTERRUPTX(&H13, inregs, outregs)
NEXT
PRINT "New label written to root directory !"


Guest

Re: Can't see the wood for the trees. Help!

Post by Guest » Tue Oct 15, 2002 7:38 am

It looks like ti will work. What does it not do?

dave.steadman
Newbie
Posts:2
Joined:Wed Oct 09, 2002 5:25 pm

Re: Can't see the wood for the trees. Help!

Post by dave.steadman » Wed Oct 16, 2002 12:35 am

Yea you're right it does look like it should work but It seems to bomb out somewhere after the write to the root directory.
It set's the valid ID but when I check the finished article the label is blank.     ???

Steady ...

Guest

Re: Can't see the wood for the trees. Help!

Post by Guest » Fri May 16, 2003 8:58 am

Could be cause it's missing a period?

'Write the changes to the root directory
FOR Re = 1 TO 4
  inregs.dx = 0: inregs.ax = 0
  CALL INTERRUPTX(&H13, inregs, outregs)
  inregs.dx = &H100        'side 1, drive 0
  inregs.es = VARSEG(RootBuffer$)
  inregs.bx = SADD(RootBuffer$)
  inregs.ax = &H30E        'function 3, write 14 sectors
    inregsCX = 2        'starting at sector #2
  CALL INTERRUPTX(&H13, inregs, outregs)
NEXT
PRINT "New label written to root directory !"


I think it should read:

  inregs.CX = 2        'starting at sector #2

I haven't tried it but that's the only thing that I can see.  Anyone else have any other ideas?

--MiggyD

jakykong
Full Member
Posts:30
Joined:Wed Jun 25, 2003 1:05 pm

Re: Can't see the wood for the trees. Help!

Post by jakykong » Thu Jun 26, 2003 4:09 pm

someone notices these things! geez, i would have died before i noticed that! oh, well, it looks very plausible, i don't know if it is any consolation, i do those little things all the time!(especially trying to type on six different keyboards!)
I've not been a QBasic programmer since at least 2004. It was fun; I've moved on. Best of luck.

Post Reply