home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0430 - 0439 / ibm0430-0439 / ibm0436.tar / ibm0436 / CQMP321.ZIP / OVTOC.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-15  |  5.9 KB  |  184 lines

  1.     page    ,132
  2.     title    Overlay linkage to Microsoft 'C' tiny model programs.
  3.  
  4.     .model    tiny,c
  5.  
  6. ;*    OVERLAY LINKING MICROSOFT/BORLAND TINY MODEL PROGRAMS.
  7. ;    ------------------------------------------------------
  8. ;
  9. ;    Copyright 1993, Sydex.    All rights reserved.
  10. ;
  11. ;    Notes:
  12. ;
  13. ;        1.    This overlay is written for the assembly by the
  14. ;        Microsoft MASM 6.0 assembler.  Other versions of
  15. ;        MASM or other vendors' assemblers may require
  16. ;        modification of this program.
  17. ;
  18. ;        2.    The code in this overlay must be contained in
  19. ;        a single segment and created as an absolute overlay
  20. ;        origined at 0.    No segment address constants are
  21. ;        permitted.
  22. ;
  23. ;        3.    The overlay is called by CopyQM/SyDupe in the
  24. ;        following manner:
  25. ;
  26. ;        a.  A far (doubleword) address which points to a
  27. ;            structure used for communication (detailed
  28. ;            below).
  29. ;
  30. ;        b.  A far CALL is made to this segment, offset 0.
  31. ;
  32. ;        Any and all registers may be used by this overlay.
  33. ;
  34. ;    To use this overlay with your Borland or Microsoft 'C' code:
  35. ;    ------------------------------------------------------------
  36. ;
  37. ;    1.    Declare your main routine as follows:
  38. ;
  39. ;        #include "ovpacket.h"
  40. ;
  41. ;        void OverlayEntry( OVERLAY_PACKET _far *CQP_Packet)
  42. ;        {
  43. ;            ...body of code...
  44. ;        }
  45. ;
  46. ;
  47. ;        All static data structures should be initialized.  That is,
  48. ;        uninitialized data is not allocated space by CopyQM and
  49. ;        attempts to write to uninitialized cells will most likely
  50. ;        result in a program crash.
  51. ;
  52. ;        A statically-allocated stack is set up here.  By default,
  53. ;        we make it 2,048 bytes, but this can be changed by re-
  54. ;        assembling this code with the value of STATIC_STACK set
  55. ;        to a different value.
  56. ;
  57. ;        You must compile your code OMITTING any stack-limit
  58. ;        checking code.    (Microsoft /Gs option).
  59. ;
  60. ;
  61. ;    2.    Link it with this code, using the /T LINK switch, or
  62. ;        use EXE2BIN to create a .COM file.
  63. ;
  64. ;    3.    Rename the executable file to have a .OVR extension.
  65. ;
  66. ;    You should avoid using 'C' library routines that require the
  67. ;    environment set up by the normal 'C' entry code.  These include
  68. ;    most stdio.h functions and systems requests.  If you need to do
  69. ;    file I/O, use either the I/O primitives (open, close, write, etc.),
  70. ;    or direct DOS calls via INT86.    If you end up with a pile of un-
  71. ;    defined externals in your LINK map, you'll need to look for what's
  72. ;    causing the problem.
  73. ;
  74.  
  75. OVERLAY_PACKET    struc
  76. Drive        db    ?        ; letter of drive used for copying
  77. SFFlag        db    ?        ; success/fail/initialize flag:
  78.                     ;  255 - drive just selected
  79.                     ;    0 - copy complete; failed
  80.                     ;    1 - copy complete; success
  81. SerialType    db    ?        ; serial number type:
  82.                     ; 0 - ASCII, 1 - Binary
  83. SerialLength    db    ?        ; length of serial number in bytes
  84. ThisCopy    dw    ?        ; current number of this copy
  85. TotalCopies    dw    ?        ; total copies requested
  86. VolumeName    dd    ?        ; pointer to volume/label name,
  87.                     ; ASCII with null terminator
  88. SerialNo    dd    ?        ; pointer to current serial number
  89. DriveAddr    dd    ?        ; pointer to drive table for this unit
  90. BufferAddr    dd    ?        ; one-track buffer area for use
  91.                     ; by this overlay
  92. DiskOpFunction    dd    ?        ; pointer to disk operation function
  93.                     ; for use in reading or writing
  94.                     ; sectors on the current drive
  95. Refresh        db    ?        ; * if set nonzero on return to CopyQM,
  96.                     ; * the display is re-painted
  97. DiskFunction    db    ?        ; * disk function to perform:
  98.                     ; *   1 = Read sectors into buffer
  99.                     ; *   2 = Write sectors from buffer
  100.                     ; *   3 = Verify sectors
  101. DiskStatus    db    ?        ; status of last disk function
  102. Cylinder    db    ?        ; * cylinder number for disk functions
  103. Side        db    ?        ; * side (0 or 1) for disk functions
  104. Sector        db    ?        ; * starting sector number for function
  105. SectorLength    db    ?        ; * sector length code: 1 = 256, 2 = 512
  106. Count        db    ?        ; * count of sectors to transfer
  107. OVERLAY_PACKET    ends
  108.  
  109. ;    Items in the above structure whose comments contain a "*" are
  110. ;    cells the overlay code may modify.  All other cells should be
  111. ;    left undisturbed.
  112. ;
  113. ;    A few words are necessary concerning the diskette read, write and
  114. ;    verify functions provided by CopyQM.  If diskette accesses are
  115. ;    required, they must be performed by means of this interface;
  116. ;    using any other method will probably result in a system crash.
  117. ;
  118. ;    Performing a diskette function is simple.  Just place the
  119. ;    Cylinder, Side, Sector, Sector length code and transfer count
  120. ;    in the appropriate cells within the overlay packet, then
  121. ;    set the DiskFunction byte ( 1 - read, 2 - write, 3 - verify)
  122. ;    and issue a far CALL to the routine pointed to by DiskOpFunction.
  123. ;    The disk operation will take place using the buffer pointed to
  124. ;    by BufferAddr, and the status of the operation will be returned
  125. ;    in the DiskStatus byte:
  126. ;
  127. ;        00h - No error
  128. ;        01h - Parameter error
  129. ;        02h - Data address mark not found
  130. ;        03h - Drive is write-protected
  131. ;        04h - Sector not found
  132. ;        10h - Data CRC error
  133. ;        20h - General failure
  134. ;        40h - Seek Error
  135. ;        80h - Drive not ready
  136. ;
  137.  
  138. STATIC_STACK    equ    1024        ; size, in words of static stack
  139.  
  140.     .data
  141.  
  142. Stack_Save    dd    0        ; stack pointer save area
  143.  
  144.     .stack
  145.     dw    STATIC_STACK dup (0)
  146. StackArea    label    word
  147.     .code
  148.  
  149.     extrn    OverlayEntry:near
  150.  
  151.  
  152.     org    0000h
  153.  
  154. ;    At entry, the request pointer is just below the far return address
  155. ;    on the stack.  We needn't worry about cleaning the stack up; CQ+
  156. ;    will handle that.  What is important here is to get the stack set
  157. ;    up, along with a default data segment.
  158.  
  159. Entry    proc    far
  160.     mov    ax,cs
  161.     mov    ds,ax
  162.     mov    word ptr Stack_Save,sp    ; save stack pointer
  163.     mov    word ptr Stack_Save+2,ss
  164.     cli
  165.     lea    sp,StackArea        ; establish the stack
  166.     mov    ss,ax
  167.     sti
  168.     mov    bp,sp            ; frame our stack
  169.     les    bx,Stack_Save        ; back to stack pointer
  170.     push    es:[bx+6]        ; push segment of overlay packet
  171.     push    es:[bx+4]        ; push offset
  172.     call    OverlayEntry        ; call the user routine
  173.  
  174. ;    Re-establish the original stack.
  175.  
  176.     cli
  177.     mov    ss,word ptr Stack_Save+2
  178.     mov    sp,word ptr Stack_Save
  179.     sti
  180.     retf                ; exit to CopyQM
  181. Entry    endp
  182.  
  183.     end    Entry
  184.