home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_32.arc / DISK.FIG < prev    next >
Text File  |  1979-12-31  |  5KB  |  196 lines

  1.  
  2. ((Disk Figs 1,2, and A printouts go with this article))
  3.  
  4. ((Disk Figure 1 - Program PC-DU))
  5.  
  6. ; PC-DU, a program to read and write disk sectors
  7. ; Illustrates disk I/O using ROM-BIOS interrupt 13h
  8. ;
  9. ;
  10. STACK    SEGMENT    PARA STACK 'STACK'
  11.     DB    256 DUP (0) ; 256 bytes for the stack
  12. STACK    ENDS
  13. ;
  14. ;
  15. DATA    SEGMENT    PARA PUBLIC 'DATA'
  16. BUFFER    DB    2048 DUP (0); Enough buffer space for 4 sectors
  17. ERRMSG    DB    'Something isn't working ! '
  18. SUCCES  DB    'Something is    working ! '          
  19. DATA    ENDS
  20. ;
  21. ;
  22. CODE    SEGMENT    PARA PUBLIC 'CODE'
  23. START    PROC    FAR
  24. ;
  25. ;
  26. ; Program prologue
  27. ;
  28.     ASSUME    CS:CODE
  29.     PUSH    DS    ; Save PSP Seg Addr
  30.     MOV    AX,0
  31.     PUSH    AX    ; Save Ret Addr offset (PSP + 0)
  32.     MOV    AX,DATA
  33.     MOV    DS,AX    ; Setup Data Seg 
  34.     ASSUME    DS:DATA
  35.     MOV    ES,AX    ; Setup Extra Seg
  36.     ASSUME    ES:DATA
  37. ;
  38. ;
  39. ; Read sectors from disk into memory
  40. ; In this example we'll read the 4 directory tracks --
  41. ; Side 0, Track 0, Sectors 4,5,6,7
  42. ;
  43. ;
  44.     MOV    CX,3    ; Retry 3 times if necessary
  45. RETRY:    PUSH    CX    ; Save retry count
  46.     MOV    BX,OFFSET BUFFER; We'll read the sectors into 
  47.             ; a buffer
  48.     MOV    DL,0    ; DL gets the drive (0=A;1=B)
  49.     MOV    DH,0    ; DH gets the side(0 or 1)
  50.     MOV    CH,0    ; CH gets the track(0-39)
  51.     MOV    CL,4    ; CL gets the sector(1-8)
  52.     MOV    AL,4    ; No. of sectors to read
  53.     MOV    AH,2    ; Service call 2 = read
  54.     INT    13h    ; BIOS disk I/O routine
  55.     POP    CX    ; Restore retry count
  56.     JNC    WRITSEC    ; Branch to write, if read ok
  57.     MOV    AH,0    ; Otherwise, reset
  58.     INT    13h
  59.     LOOP    RETRY    ; Try again (up to 3 times)
  60. ERROR:    MOV    BX,OFFSET ERRMSG
  61.     CALL    DISPLAY ; Display the error message 
  62.     RET        ; Return control to DOS
  63. ;
  64. ;
  65. ; Write sectors back out to disk
  66. ;
  67. WRITSEC:MOV    BX,OFFSET BUFFER; Here's the buffer where the 
  68.             ; read sectors are
  69.     MOV    DL,0    ; DL gets the drive (0=A;1=B)
  70.             ; Change this to 1 for a copy (see text)
  71.     MOV    DH,0    ; DH gets the side(0 or 1)
  72.     MOV    CH,0    ; CH gets the track(0-39)
  73.     MOV    CL,4    ; CL gets the sector(1-8)
  74.     MOV    AL,4    ; No. of sectors to write
  75.     MOV    AH,3    ; Service call 3 = write
  76.     INT    13h    ; BIOS disk I/O routine
  77.     JNC    SUCCESS ; Branch to ok message, if ok
  78.     JNC    ERROR    ; Else branch to error message
  79. ;
  80. ; Go get the message we want and display it
  81. SUCCESS:MOV    BX,OFFSET SUCCES; Here's where the good message 
  82.             ; is
  83.     CALL    DISPLAY    ; Display the good message
  84.     RET        ; Return control to DOS
  85. ;
  86. ; Subroutine (or procedure) to set up display 
  87. ;
  88. DISPLAY    PROC    NEAR
  89.     MOV    CX,26    ; Display 26 characters
  90. DISP:    MOV    AL,[BX] ; Get next char to display
  91.     CALL    DISPCHAR; Display char
  92.     INC    BX    ; Point to next char
  93.     LOOP    DISP    ; Loop 26 times (value of CX reg)
  94.     MOV    AL,0DH    ; carriage return
  95.     CALL    DISPCHAR;
  96.     MOV    AL,0AH    ; line feed
  97.     CALL    DISPCHAR
  98.     RET        ; Return control to caller of DISPLAY
  99. DISPLAY    ENDP
  100. ;
  101. ; Subroutine to actually display messages
  102. ;
  103. DISPCHAR PROC    NEAR
  104.     PUSH    BX      ; Save BX
  105.     MOV    BX,0    ; Select display page 0
  106.     MOV    AH,14    ; Function code for write
  107.     INT    10H    ; Video interrupt
  108.     POP    BX    ; Restore BX
  109.     RET        ; Return control to caller of DISPCHAR
  110. DISPCHAR ENDP
  111. ;
  112. ;
  113. START    ENDP
  114. CODE    ENDS
  115.     END    START
  116.     
  117.  
  118.  
  119. ((Disk Figure 2 - Turbo Pascal & external assembler shell))
  120.  
  121. program PC_DU;       {  Turbo Pascal & assembler shell:
  122.                          for interactive PC-DU;
  123.                          does not include retries for reads
  124.                          or interactive details  }
  125.                                            
  126. TYPE
  127.     Size_of_Sector = ARRAY[0..511] of BYTE; { set up buffer 
  128.                                                to hold 1 sector }
  129.     
  130. VAR
  131.     Buffer : Size_of_Sector;
  132.         Drive, Track, Side, Sector : integer;
  133.  
  134. function SECREAD(
  135.     VAR    B : Size_of_Sector;
  136.         Drive : integer;
  137.         Track : integer;
  138.         Side : integer;
  139.         Sector : integer)
  140.     : BYTE;
  141.     
  142.     external 'secread.com';  { Secread is an external assembly 
  143.                                   language subroutine  }
  144.  
  145. function SECWRIT(
  146.     VAR    B : Size_of_Sector;
  147.         Drive : integer;
  148.         Track : integer;
  149.         Side : integer;
  150.         Sector : integer)
  151.     : BYTE;
  152.     
  153.     external 'secwrit.com';  { Secwrite is an external assembly
  154.                   language subroutine }
  155.  
  156. BEGIN
  157.   IF SECREAD(Buffer,Drive,Track,Side,Sector)= 0 {If no error}
  158.      THEN 
  159.         IF SECWRIT(Buffer,Drive,Track,Side,Sector)=0 {If no error}
  160.             THEN  Writeln('success is ours!')
  161.            ELSE write('Unable to read Track', Track,
  162.                             'Side',Side, 'Sector',Sector);
  163. END.
  164.  
  165. SECWRIT.ASM             ;subroutine to write 1 disk sector
  166.  
  167. code    segment    'code'
  168.     assume    cs:code
  169. ;
  170. SECWRIT    proc    near
  171.     push    BP
  172.     MOV    BP,SP
  173.     PUSH    DS
  174.     POP    ES
  175.     MOV    BX,[BP+12]
  176.     MOV    BL,[BP+10]
  177.     MOV    CH,[BP+8]
  178.     MOV    DH,[BP+6]
  179.     MOV    CL,[BP+4]
  180.     MOV    AL,1
  181.     MOV    AH,3
  182.     INT    19
  183.     MOV    AL,AH
  184.     POP    BP
  185.     RET    10
  186. SECREAD ENDP
  187. code    ends
  188.     end
  189.  
  190.  
  191. ((this is Disk Fig. A))
  192.  
  193. MOV    AH,0
  194. INT    13H
  195.