Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

For PB DOS'ers. Read sectors in LBA mode.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • For PB DOS'ers. Read sectors in LBA mode.

    Code:
    $if 0
    	For all you DOS'ers out there...
    '
            Well, it seems I finally went and dun't. Seems I figured a
            way of reading absolute disk sectors in LBA mode.
    '
            This program was written in PB/DOS 3.5 and is released to
            public domain to use as you see fit.
    '
            For LBA writes, you are on your own. I ain't gonna take that
            resonsibility.
    '
            To reference where I got a lot of the info to do this and give
            credit where credit is due, check out:
    '
            [url="http://home.no.net/tkos/info/hd.html"]http://home.no.net/tkos/info/hd.html[/url] 
    '
            As a word of note, the partition sector is absolute sector
            ZERO. With CHS int13 functions, it's sector 1. Little bit of
    	a difference here.
    '
            Now I'll be the first to admit that these functions may not
            be the most elegantly written code around, but they work.....
    '
            Feedback in the PB/DOS forum welcome and appreciated.
    '
            Oh, I forgot to add, if you are using xp and (probably) nt
            this program won't work. You will have to format a system 
            floppy with DOS 6.2, win/95/98 or maybe me. These will allow
            int13 functions. xp won't.
    $endif
    '
    	$lib all off
            color 14,1
    	cls
    '
    	sector&& = -1
            fmt$ = "###,###,###"
            drive = 0
    '
    REM ************************
    REM * Get drive parameters *
    REM ************************
    '
            dummy = getdriveparameters(drive,tracks,heads,spt)
            if CheckCarryFlag = 1 then
    '	Do something drastic here
    	end if
    '
    REM *****************************************************
    REM * The total number of sectors is in the data packet *
    REM * but it's just as easy to do some math rather than *
    REM * process 8-bytes. But that's just me.              *
    REM *****************************************************
    '
            TotalSectors = tracks * heads * spt
    '
            locate 15,1 : print;"    Cylinders: " + using$(fmt$,tracks)
            locate 16,1 : print;"  Total Heads: " + using$(fmt$,heads)
            locate 17,1 : print;"Sectors Track: " + using$(fmt$,spt)
            locate 18,1 : print;"Total sectors: " + using$(fmt$,totalsectors)
            number = 1
    '
            do
            if inkey$ = chr$(27) then exit loop
    '
    	sector&& = sector&& + number
            dummy$   = readlbasector$(drive,sector&&,number,d$)
    '
            locate  1,1 : print;"Sector: " + using$(fmt$,sector&&)
            locate  5,1 : print;d$;len(d$)
            if d$ = "-1" then beep
    '
    '	if abort = 1 then exit loop
    '
            loop
            end
    '
    REM *****************************************************************
    REM * These three parameters are not needed for reading sectors but *
    REM * may prove useful elsewhere.                                   *
    REM *****************************************************************
    '
    function GetDriveParameters(drive,tracks,heads,spt)
    '
    REM ***************************************************************
    REM * For some reason, I cannot stuff the buffer with chr$(0). It *
    REM * just won't work. Any other character will but not zero.     *
    REM ***************************************************************
    '
            buffer$ = string$(28,chr$(2))
    '
    	reg 1,&h4800
            reg 4,drive + &h80
    	reg 5, strptr(buffer$)
    	reg 8, strseg(buffer$)
            call interrupt &h13
            if CheckCarryFlag = 1 then
            function = 1 : exit function
            end if
    '
    '
    REM ********************************
    REM * Get total cylinders on drive *
    REM ********************************
    '
    	t1 = asc(mid$(buffer$, 5,1))
            t2 = asc(mid$(buffer$, 6,1))
    	t3 = asc(mid$(buffer$, 7,1))
            t4 = asc(mid$(buffer$, 8,1))
    '
            t1 = t1 + (t2 * 256)
            t2 = t3 + ((t4 * 256) * 65536)
            tracks = t1 + t2
    '
    REM *******************
    REM * Number of heads *
    REM *******************
    '
    	t1 = asc(mid$(buffer$, 9,1))
            t2 = asc(mid$(buffer$,10,1))
    	t3 = asc(mid$(buffer$,11,1))
            t4 = asc(mid$(buffer$,12,1))
    '
            t1 = t1 + (t2 * 256)
            t2 = t3 + ((t4 * 256) * 65536)
            heads = t1 + t2
    '
    REM *********************
    REM * Sectors per track *
    REM *********************
    '
    	t1 = asc(mid$(buffer$,13,1))
            t2 = asc(mid$(buffer$,14,1))
    	t3 = asc(mid$(buffer$,15,1))
            t4 = asc(mid$(buffer$,16,1))
    '
            t1 = t1 + (t2 * 256)
            t2 = t3 + ((t4 * 256) * 65536)
            spt = t1 + t2
    '
    	end function
    '
    function ReadLBAsector$(drive,Sector&&,ToRead,d$)
    '
            d$ = string$(ToRead * 512,chr$(1))
            divider = 256				'I was playing with this #
    '
            buffseg    = strseg(d$)			'Sector buffer segment
            buffoffset = strptr(d$)			'and offset
    '
    	packet$ = chr$(16)			'Packet length
    '
            packet$ = packet$ + chr$(0)		'Reserved (always chr$(0))
    '
            r1 = int(ToRead/divider)		'Number of sectors to read
            r2 = ToRead - r1			'Two bytes (why???)
            packet$ = packet$ + chr$(r2)		'Can't go more than 63
            packet$ = packet$ + chr$(r1)		'anway.
    '
            buff1 = int(buffoffset / divider)	'Buffer offset (2-bytes)
            buff2 = buffoffset - (buff1 * divider)
    '
            packet$ = packet$ + chr$(buff2)
            packet$ = packet$ + chr$(buff1)
    '
            seg1 = int(buffseg / divider)		'Buffer segment (2-bytes)
            seg2 = buffseg - (seg1 * divider)
    '
            packet$ = packet$ + chr$(seg2)
            packet$ = packet$ + chr$(seg1)
    '
            te$ = binari$(sector&&)			'ABS sector to read.
            do until len(te$) = 64			'8-bytes long.
            te$ = "0" + te$
            loop
    '
    '        locate 23,1 : print;te$;		'For debuging purposes.
    '
    	t1$ = mid$(te$,57,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$,49,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$,41,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$,33,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$,25,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$,17,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$, 9,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    	t1$ = mid$(te$, 1,8) : packet$ = packet$ + chr$(val("&b" + t1$))
    '
    	reg 1, &h4200
            reg 4, drive + &h80
    	reg 5, strptr(packet$)
    	reg 8, strseg(packet$)
            call interrupt &h13
    '
    REM **************************************************************
    REM *                                                            *
    REM * Check the flags register to see of CF is set. If it is.... *
    REM *                                                            *
    REM **************************************************************
    '
            if CheckCarryFlag = 1 then
            function = "-1"			'Or whatever you choose to put here.
            end if
            end function
    '
    REM *************************************************
    REM *                                               *
    REM * Sorry PB-n-Staff. PB just won't go to 64 bits *
    REM *                                               *
    REM *************************************************
    '
    function binari$(t&&)
    	if t&& = 0 then
    	 binari$ = "0"
    	  exit function
    	   end if
    '
            p&& = t&& + 1
    	 te$ = ""
    	  test&& = 1
    '
            do until test&& => p&&
             test&& = test&& * 2
              loop
    '
            test&& = test&& / 2
            do until test&& = 0
             if test&& < p&& then
              te$ = te$ + "1"
               p&& = p&& - test&&
            else
             te$ = te$ + "0"
             end if
    '
               test&& = test&& / 2
            loop
            binari$ = te$
            end function
    '
    function CheckCarryFlag
    	te$ = bin$(reg(0))
    	if right$(te$,1) = "1" then
            function = 1
            else
            function = 0
            end if
            end function
    '
    function abort
    	while instat=0:wend
            an$ = inkey$
            if an$ = chr$(27) then function = 1
    	end function

    ------------------




    [This message has been edited by Mel Bishop (edited December 19, 2004).]
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.
Working...
X