Page 1 of 1

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

Posted: Tue Oct 15, 2002 1:13 am
by dave.steadman
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 !"


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

Posted: Tue Oct 15, 2002 7:38 am
by Guest
It looks like ti will work. What does it not do?

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

Posted: Wed Oct 16, 2002 12:35 am
by dave.steadman
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 ...

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

Posted: Fri May 16, 2003 8:58 am
by Guest
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

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

Posted: Thu Jun 26, 2003 4:09 pm
by jakykong
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!)