home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
microcrn
/
issue_32.arc
/
DISK.FIG
< prev
next >
Wrap
Text File
|
1979-12-31
|
5KB
|
196 lines
((Disk Figs 1,2, and A printouts go with this article))
((Disk Figure 1 - Program PC-DU))
; PC-DU, a program to read and write disk sectors
; Illustrates disk I/O using ROM-BIOS interrupt 13h
;
;
STACK SEGMENT PARA STACK 'STACK'
DB 256 DUP (0) ; 256 bytes for the stack
STACK ENDS
;
;
DATA SEGMENT PARA PUBLIC 'DATA'
BUFFER DB 2048 DUP (0); Enough buffer space for 4 sectors
ERRMSG DB 'Something isn't working ! '
SUCCES DB 'Something is working ! '
DATA ENDS
;
;
CODE SEGMENT PARA PUBLIC 'CODE'
START PROC FAR
;
;
; Program prologue
;
ASSUME CS:CODE
PUSH DS ; Save PSP Seg Addr
MOV AX,0
PUSH AX ; Save Ret Addr offset (PSP + 0)
MOV AX,DATA
MOV DS,AX ; Setup Data Seg
ASSUME DS:DATA
MOV ES,AX ; Setup Extra Seg
ASSUME ES:DATA
;
;
; Read sectors from disk into memory
; In this example we'll read the 4 directory tracks --
; Side 0, Track 0, Sectors 4,5,6,7
;
;
MOV CX,3 ; Retry 3 times if necessary
RETRY: PUSH CX ; Save retry count
MOV BX,OFFSET BUFFER; We'll read the sectors into
; a buffer
MOV DL,0 ; DL gets the drive (0=A;1=B)
MOV DH,0 ; DH gets the side(0 or 1)
MOV CH,0 ; CH gets the track(0-39)
MOV CL,4 ; CL gets the sector(1-8)
MOV AL,4 ; No. of sectors to read
MOV AH,2 ; Service call 2 = read
INT 13h ; BIOS disk I/O routine
POP CX ; Restore retry count
JNC WRITSEC ; Branch to write, if read ok
MOV AH,0 ; Otherwise, reset
INT 13h
LOOP RETRY ; Try again (up to 3 times)
ERROR: MOV BX,OFFSET ERRMSG
CALL DISPLAY ; Display the error message
RET ; Return control to DOS
;
;
; Write sectors back out to disk
;
WRITSEC:MOV BX,OFFSET BUFFER; Here's the buffer where the
; read sectors are
MOV DL,0 ; DL gets the drive (0=A;1=B)
; Change this to 1 for a copy (see text)
MOV DH,0 ; DH gets the side(0 or 1)
MOV CH,0 ; CH gets the track(0-39)
MOV CL,4 ; CL gets the sector(1-8)
MOV AL,4 ; No. of sectors to write
MOV AH,3 ; Service call 3 = write
INT 13h ; BIOS disk I/O routine
JNC SUCCESS ; Branch to ok message, if ok
JNC ERROR ; Else branch to error message
;
; Go get the message we want and display it
;
SUCCESS:MOV BX,OFFSET SUCCES; Here's where the good message
; is
CALL DISPLAY ; Display the good message
RET ; Return control to DOS
;
; Subroutine (or procedure) to set up display
;
DISPLAY PROC NEAR
MOV CX,26 ; Display 26 characters
DISP: MOV AL,[BX] ; Get next char to display
CALL DISPCHAR; Display char
INC BX ; Point to next char
LOOP DISP ; Loop 26 times (value of CX reg)
MOV AL,0DH ; carriage return
CALL DISPCHAR;
MOV AL,0AH ; line feed
CALL DISPCHAR
RET ; Return control to caller of DISPLAY
DISPLAY ENDP
;
; Subroutine to actually display messages
;
DISPCHAR PROC NEAR
PUSH BX ; Save BX
MOV BX,0 ; Select display page 0
MOV AH,14 ; Function code for write
INT 10H ; Video interrupt
POP BX ; Restore BX
RET ; Return control to caller of DISPCHAR
DISPCHAR ENDP
;
;
START ENDP
CODE ENDS
END START
((Disk Figure 2 - Turbo Pascal & external assembler shell))
program PC_DU; { Turbo Pascal & assembler shell:
for interactive PC-DU;
does not include retries for reads
or interactive details }
TYPE
Size_of_Sector = ARRAY[0..511] of BYTE; { set up buffer
to hold 1 sector }
VAR
Buffer : Size_of_Sector;
Drive, Track, Side, Sector : integer;
function SECREAD(
VAR B : Size_of_Sector;
Drive : integer;
Track : integer;
Side : integer;
Sector : integer)
: BYTE;
external 'secread.com'; { Secread is an external assembly
language subroutine }
function SECWRIT(
VAR B : Size_of_Sector;
Drive : integer;
Track : integer;
Side : integer;
Sector : integer)
: BYTE;
external 'secwrit.com'; { Secwrite is an external assembly
language subroutine }
BEGIN
IF SECREAD(Buffer,Drive,Track,Side,Sector)= 0 {If no error}
THEN
IF SECWRIT(Buffer,Drive,Track,Side,Sector)=0 {If no error}
THEN Writeln('success is ours!')
ELSE write('Unable to read Track', Track,
'Side',Side, 'Sector',Sector);
END.
SECWRIT.ASM ;subroutine to write 1 disk sector
code segment 'code'
assume cs:code
;
SECWRIT proc near
push BP
MOV BP,SP
PUSH DS
POP ES
MOV BX,[BP+12]
MOV BL,[BP+10]
MOV CH,[BP+8]
MOV DH,[BP+6]
MOV CL,[BP+4]
MOV AL,1
MOV AH,3
INT 19
MOV AL,AH
POP BP
RET 10
SECREAD ENDP
code ends
end
((this is Disk Fig. A))
MOV AH,0
INT 13H