Thread overview
possible bug in biosdisk() library function?
Sep 06, 2003
Scott
Sep 06, 2003
Walter
Sep 06, 2003
Scott
Sep 06, 2003
Scott
Sep 06, 2003
Walter
September 06, 2003
Am I doing something wrong or have I encountered a bug in the biosdisk() library
function?

While the biosdisk function reads sectors fine, it does not seem to write using the following short program (it is modelled on the Digital Mars bios.h information page). Note that it seems that even though biosdisk should return 0 when successful, it is instead returning a value of 768 when successful, and 0 upon failure. I verified this return value error by many correct sector reads from several sectors with the return value from biosdisk() always coming back with a return value of 768, not 0. I should note that this program writes to the disk just fine when compiled on DJGPP (with the proper result "if" lines exchanged in that expect a 0 return when the function has been successful.

Thanks for any feedback,
Scott

___________________

#include <stdio.h>
#include <stdlib.h>
#include <bios.h>

int main(int argc, char **argv) {

const int amountToReadConstant=1;
int disk, target;
int result = 1;
unsigned char buf[512];
FILE *fp;
int i;
unsigned char pattern;

disk = 128;
pattern = 0x5a;
target = 60;

printf("\n\nAttempting direct disk read and write operations.\n\n\n\n");

for(i=0;i<512;i++)
buf[i]=pattern;

result = (int) biosdisk(_DISK_WRITE, disk, 0, 0, target, amountToReadConstant,
buf);
//if (result != 0) {
if (result == 0) {
printf("Disk write operation did not complete correctly.\n");
printf("Result error code was: %d \n\n\n", result);
return 0;
}
else
printf("Wrote a sector.\n\n");

// Read back the sector.
result = (int) biosdisk(_DISK_READ, disk, 0, 0, target, amountToReadConstant,
buf);
//if (result != 0) {
if (result == 0) {
printf("Disk read operation did not complete correctly.\n");
printf("Result error code was: %d \n\n\n", result);
return 0;
}
else
printf("Read a sector.\n\n");

if ( buf[0] != pattern )
printf("Write seems to have failed.\n\n");

fp=fopen("now-is.img","wb");
if(fp==NULL) {
printf("\nCould not open the file for writing.\n\n");
return 0;
}
printf("Writing the sector that was read to a file.\n\n\n");
for(i=0;i<512;i++)
fputc(buf[i],fp);
fclose(fp);

return 1; }


September 06, 2003
Which memory model are you using?

"Scott" <Scott_member@pathlink.com> wrote in message news:bjbfgh$4fk$1@digitaldaemon.com...
> Am I doing something wrong or have I encountered a bug in the biosdisk()
library
> function?
>
> While the biosdisk function reads sectors fine, it does not seem to write
using
> the following short program (it is modelled on the Digital Mars bios.h information page). Note that it seems that even though biosdisk should
return 0
> when successful, it is instead returning a value of 768 when successful,
and 0
> upon failure. I verified this return value error by many correct sector
reads
> from several sectors with the return value from biosdisk() always coming
back
> with a return value of 768, not 0. I should note that this program writes
to the
> disk just fine when compiled on DJGPP (with the proper result "if" lines exchanged in that expect a 0 return when the function has been successful.
>
> Thanks for any feedback,
> Scott
>
> ___________________
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <bios.h>
>
> int main(int argc, char **argv) {
>
> const int amountToReadConstant=1;
> int disk, target;
> int result = 1;
> unsigned char buf[512];
> FILE *fp;
> int i;
> unsigned char pattern;
>
> disk = 128;
> pattern = 0x5a;
> target = 60;
>
> printf("\n\nAttempting direct disk read and write operations.\n\n\n\n");
>
> for(i=0;i<512;i++)
> buf[i]=pattern;
>
> result = (int) biosdisk(_DISK_WRITE, disk, 0, 0, target,
amountToReadConstant,
> buf);
> //if (result != 0) {
> if (result == 0) {
> printf("Disk write operation did not complete correctly.\n");
> printf("Result error code was: %d \n\n\n", result);
> return 0;
> }
> else
> printf("Wrote a sector.\n\n");
>
> // Read back the sector.
> result = (int) biosdisk(_DISK_READ, disk, 0, 0, target,
amountToReadConstant,
> buf);
> //if (result != 0) {
> if (result == 0) {
> printf("Disk read operation did not complete correctly.\n");
> printf("Result error code was: %d \n\n\n", result);
> return 0;
> }
> else
> printf("Read a sector.\n\n");
>
> if ( buf[0] != pattern )
> printf("Write seems to have failed.\n\n");
>
> fp=fopen("now-is.img","wb");
> if(fp==NULL) {
> printf("\nCould not open the file for writing.\n\n");
> return 0;
> }
> printf("Writing the sector that was read to a file.\n\n\n");
> for(i=0;i<512;i++)
> fputc(buf[i],fp);
> fclose(fp);
>
> return 1;
> }
>
>


September 06, 2003
Hello Walter, and thank you for your swift reply, and your compiler.

I tried -ms, -mc, -mm, and -ml. Each compilation would read the sectors correctly, but none would write.


In article <bjbq94$j97$1@digitaldaemon.com>, Walter says...
>
>Which memory model are you using?
>
>"Scott" <Scott_member@pathlink.com> wrote in message news:bjbfgh$4fk$1@digitaldaemon.com...
>> Am I doing something wrong or have I encountered a bug in the biosdisk()
>library
>> function?
>>
>> While the biosdisk function reads sectors fine, it does not seem to write
>using
>> the following short program (it is modelled on the Digital Mars bios.h information page). Note that it seems that even though biosdisk should
>return 0
>> when successful, it is instead returning a value of 768 when successful,
>and 0
>> upon failure. I verified this return value error by many correct sector
>reads
>> from several sectors with the return value from biosdisk() always coming
>back
>> with a return value of 768, not 0. I should note that this program writes
>to the
>> disk just fine when compiled on DJGPP (with the proper result "if" lines exchanged in that expect a 0 return when the function has been successful.
>>
>> Thanks for any feedback,
>> Scott
>>
>> ___________________
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <bios.h>
>>
>> int main(int argc, char **argv) {
>>
>> const int amountToReadConstant=1;
>> int disk, target;
>> int result = 1;
>> unsigned char buf[512];
>> FILE *fp;
>> int i;
>> unsigned char pattern;
>>
>> disk = 128;
>> pattern = 0x5a;
>> target = 60;
>>
>> printf("\n\nAttempting direct disk read and write operations.\n\n\n\n");
>>
>> for(i=0;i<512;i++)
>> buf[i]=pattern;
>>
>> result = (int) biosdisk(_DISK_WRITE, disk, 0, 0, target,
>amountToReadConstant,
>> buf);
>> //if (result != 0) {
>> if (result == 0) {
>> printf("Disk write operation did not complete correctly.\n");
>> printf("Result error code was: %d \n\n\n", result);
>> return 0;
>> }
>> else
>> printf("Wrote a sector.\n\n");
>>
>> // Read back the sector.
>> result = (int) biosdisk(_DISK_READ, disk, 0, 0, target,
>amountToReadConstant,
>> buf);
>> //if (result != 0) {
>> if (result == 0) {
>> printf("Disk read operation did not complete correctly.\n");
>> printf("Result error code was: %d \n\n\n", result);
>> return 0;
>> }
>> else
>> printf("Read a sector.\n\n");
>>
>> if ( buf[0] != pattern )
>> printf("Write seems to have failed.\n\n");
>>
>> fp=fopen("now-is.img","wb");
>> if(fp==NULL) {
>> printf("\nCould not open the file for writing.\n\n");
>> return 0;
>> }
>> printf("Writing the sector that was read to a file.\n\n\n");
>> for(i=0;i<512;i++)
>> fputc(buf[i],fp);
>> fclose(fp);
>>
>> return 1;
>> }
>>
>>
>
>


September 06, 2003
Hello Walter, and thank you for your swift reply, and your compiler.

I tried -ms, -mc, -mm, and -ml. Each compilation would read the sectors correctly, but none would write.


In article <bjbq94$j97$1@digitaldaemon.com>, Walter says...
>
>Which memory model are you using?
>
>"Scott" <Scott_member@pathlink.com> wrote in message news:bjbfgh$4fk$1@digitaldaemon.com...
>> Am I doing something wrong or have I encountered a bug in the biosdisk()
>library
>> function?
>>
>> While the biosdisk function reads sectors fine, it does not seem to write
>using
>> the following short program (it is modelled on the Digital Mars bios.h information page). Note that it seems that even though biosdisk should
>return 0
>> when successful, it is instead returning a value of 768 when successful,
>and 0
>> upon failure. I verified this return value error by many correct sector
>reads
>> from several sectors with the return value from biosdisk() always coming
>back
>> with a return value of 768, not 0. I should note that this program writes
>to the
>> disk just fine when compiled on DJGPP (with the proper result "if" lines exchanged in that expect a 0 return when the function has been successful.
>>
>> Thanks for any feedback,
>> Scott
>>
>> ___________________
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <bios.h>
>>
>> int main(int argc, char **argv) {
>>
>> const int amountToReadConstant=1;
>> int disk, target;
>> int result = 1;
>> unsigned char buf[512];
>> FILE *fp;
>> int i;
>> unsigned char pattern;
>>
>> disk = 128;
>> pattern = 0x5a;
>> target = 60;
>>
>> printf("\n\nAttempting direct disk read and write operations.\n\n\n\n");
>>
>> for(i=0;i<512;i++)
>> buf[i]=pattern;
>>
>> result = (int) biosdisk(_DISK_WRITE, disk, 0, 0, target,
>amountToReadConstant,
>> buf);
>> //if (result != 0) {
>> if (result == 0) {
>> printf("Disk write operation did not complete correctly.\n");
>> printf("Result error code was: %d \n\n\n", result);
>> return 0;
>> }
>> else
>> printf("Wrote a sector.\n\n");
>>
>> // Read back the sector.
>> result = (int) biosdisk(_DISK_READ, disk, 0, 0, target,
>amountToReadConstant,
>> buf);
>> //if (result != 0) {
>> if (result == 0) {
>> printf("Disk read operation did not complete correctly.\n");
>> printf("Result error code was: %d \n\n\n", result);
>> return 0;
>> }
>> else
>> printf("Read a sector.\n\n");
>>
>> if ( buf[0] != pattern )
>> printf("Write seems to have failed.\n\n");
>>
>> fp=fopen("now-is.img","wb");
>> if(fp==NULL) {
>> printf("\nCould not open the file for writing.\n\n");
>> return 0;
>> }
>> printf("Writing the sector that was read to a file.\n\n\n");
>> for(i=0;i<512;i++)
>> fputc(buf[i],fp);
>> fclose(fp);
>>
>> return 1;
>> }
>>
>>
>
>


September 06, 2003
Here are the library functions that implement it:

#include <bios.h>
#if __INTSIZE != 4
int biosdisk(int cmd, int drive, int head, int track, int sector,
     int nsects, void *buffer)
{
 struct diskinfo_t dinfo;

 dinfo.drive = drive;
 dinfo.head = head;
 dinfo.track = track;
 dinfo.sector = sector;
 dinfo.nsectors = nsects;
 dinfo.buffer = buffer;

 return(_bios_disk(cmd,&dinfo));
}
#endif

and:

include macros.asm

DISKINFO STRUC
        drive           DW      ?
        head            DW      ?
        track           DW      ?
        sector          DW      ?
        nsectors        DW      ?
        buffer          DD      ?
DISKINFO ENDS

[...]

T2:
    if LPTR
        pop     DS
    endif ;LPTR
        WINLEAVE
        ret
c_endp  _bios_timeofday


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Access BIOS disk (int 0x13)  functions
;       #include <bios.h>
;       int _bios_disk(int service, struct diskinfo_t *diskinfo)
; Usage:
;       service = 0     reset the disk system
;       service = 1     get diskette status
;       service = 2     read diskette sectors
;       service = 3     write diskette sectors
;       service = 4     verify diskette sectors
;       service = 5     format diskette sectors
        c_public _bios_disk
func    _bios_disk
        WINENTER
    if LPTR
        push    DS
        lds     BX,P+2[BP]
    else ;LPTR
        mov     BX,P+2[BP]
    endif ;LPTR
        mov     DL,byte ptr drive[BX]
        mov     DH,byte ptr head[BX]
        mov     CL,byte ptr sector[BX]
        mov     CH,byte ptr track[BX]
        mov     AL,byte ptr nsectors[BX]
        les     BX,buffer[BX]
        mov     AH,P[BP]
        int     13h
        jc      D1              ;error (error code is in AH)
        _if     <byte ptr P[BP]> e 0, D1
        _if     <byte ptr P[BP]> e 1, D2
        _if     <byte ptr P[BP]> ne 5, T2
D1:     clr     AL
        jmp     T2

D2:     xchg    AH,AL           ;put status bits in AH, 0 in AL
        jmp     T2
c_endp  _bios_disk

        endcode bios

        end

"Scott" <Scott_member@pathlink.com> wrote in message news:bjdgbs$3rl$1@digitaldaemon.com...
> Hello Walter, and thank you for your swift reply, and your compiler.
>
> I tried -ms, -mc, -mm, and -ml. Each compilation would read the sectors correctly, but none would write.
>
>
> In article <bjbq94$j97$1@digitaldaemon.com>, Walter says...
> >
> >Which memory model are you using?
> >
> >"Scott" <Scott_member@pathlink.com> wrote in message news:bjbfgh$4fk$1@digitaldaemon.com...
> >> Am I doing something wrong or have I encountered a bug in the
biosdisk()
> >library
> >> function?
> >>
> >> While the biosdisk function reads sectors fine, it does not seem to
write
> >using
> >> the following short program (it is modelled on the Digital Mars bios.h information page). Note that it seems that even though biosdisk should
> >return 0
> >> when successful, it is instead returning a value of 768 when
successful,
> >and 0
> >> upon failure. I verified this return value error by many correct sector
> >reads
> >> from several sectors with the return value from biosdisk() always
coming
> >back
> >> with a return value of 768, not 0. I should note that this program
writes
> >to the
> >> disk just fine when compiled on DJGPP (with the proper result "if"
lines
> >> exchanged in that expect a 0 return when the function has been
successful.
> >>
> >> Thanks for any feedback,
> >> Scott
> >>
> >> ___________________
> >>
> >> #include <stdio.h>
> >> #include <stdlib.h>
> >> #include <bios.h>
> >>
> >> int main(int argc, char **argv) {
> >>
> >> const int amountToReadConstant=1;
> >> int disk, target;
> >> int result = 1;
> >> unsigned char buf[512];
> >> FILE *fp;
> >> int i;
> >> unsigned char pattern;
> >>
> >> disk = 128;
> >> pattern = 0x5a;
> >> target = 60;
> >>
> >> printf("\n\nAttempting direct disk read and write
operations.\n\n\n\n");
> >>
> >> for(i=0;i<512;i++)
> >> buf[i]=pattern;
> >>
> >> result = (int) biosdisk(_DISK_WRITE, disk, 0, 0, target,
> >amountToReadConstant,
> >> buf);
> >> //if (result != 0) {
> >> if (result == 0) {
> >> printf("Disk write operation did not complete correctly.\n");
> >> printf("Result error code was: %d \n\n\n", result);
> >> return 0;
> >> }
> >> else
> >> printf("Wrote a sector.\n\n");
> >>
> >> // Read back the sector.
> >> result = (int) biosdisk(_DISK_READ, disk, 0, 0, target,
> >amountToReadConstant,
> >> buf);
> >> //if (result != 0) {
> >> if (result == 0) {
> >> printf("Disk read operation did not complete correctly.\n");
> >> printf("Result error code was: %d \n\n\n", result);
> >> return 0;
> >> }
> >> else
> >> printf("Read a sector.\n\n");
> >>
> >> if ( buf[0] != pattern )
> >> printf("Write seems to have failed.\n\n");
> >>
> >> fp=fopen("now-is.img","wb");
> >> if(fp==NULL) {
> >> printf("\nCould not open the file for writing.\n\n");
> >> return 0;
> >> }
> >> printf("Writing the sector that was read to a file.\n\n\n");
> >> for(i=0;i<512;i++)
> >> fputc(buf[i],fp);
> >> fclose(fp);
> >>
> >> return 1;
> >> }
> >>
> >>
> >
> >
>
>