home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / masm / masm6 / demos / demo.inc < prev    next >
Encoding:
Text File  |  1990-10-04  |  10.1 KB  |  249 lines

  1.  
  2. BUFFERSIZE      EQU     2048            ; Buffer size in bytes for disk I/O
  3.  
  4. MDA             EQU     0               ; Adapter constants
  5. CGA             EQU     1
  6. MCGA            EQU     2
  7. EGA             EQU     3
  8. VGA             EQU     4
  9. MONO            EQU     0               ; Display constants
  10. COLOR           EQU     1
  11.  
  12. BACKSP          EQU     08              ; ASCII code for Back Space key
  13. TAB             EQU     09              ; ASCII code for Tab key
  14. LF              EQU     10              ; ASCII code for line feed
  15. CR              EQU     13              ; ASCII code for Enter key
  16. ESCAPE          EQU     27              ; ASCII code for Escape key
  17. LEFT            EQU     75              ; Scan code for left arrow
  18. CRLF            EQU     0A0Dh           ; Value for carriage return/line feed
  19.  
  20. ; Bit masks for shift status
  21.  
  22. shIns           EQU   80h
  23. shCaps          EQU   40h
  24. shNum           EQU   20h
  25. shScroll        EQU   10h
  26. shAlt           EQU   08h
  27. shCtl           EQU   04h
  28. shLeft          EQU   02h
  29. shRight         EQU   01h
  30.  
  31. ;* LoadPtr - Macro to load far address into segment:register pair, or
  32. ;* near address into register.
  33. ;*
  34. ;* Params:  sgmnt - Segment to be loaded with segment address
  35. ;*          reg - Register to be loaded with offset address
  36. ;*          pointer - Pointer to address
  37. ;*
  38. ;* Shows:   Instructions - lds     les
  39. ;*          Directives - MACRO     IF        IFIDNI     ELSE
  40. ;*                       ELSE      IFENDIF   .ERR       ENDM
  41. ;*          Operators - < >       ;;
  42.  
  43. LoadPtr MACRO sgmnt, reg, pointer       ;; Macro definition
  44.     IF @DataSize                        ;; If far pointer, and
  45.         IFIDNI <sgmnt>, <ds>            ;;   if 1st argument is DS,
  46.             lds reg, pointer            ;;   load DS:reg with far address
  47.         ELSEIFIDNI <sgmnt>, <es>        ;;   or if 1st argument is ES,
  48.             les reg, pointer            ;;   load ES:reg with far address
  49.         ELSE                            ;; Generate error if not DS or ES
  50.             .ERR <First argument must be DS or ES>
  51.         ENDIF
  52.     ELSE                                ;; If near pointer,
  53.         IFIDNI <sgmnt>, <es>            ;;   and if segment is ES,
  54.             push ds                     ;;   ensure ES points to
  55.             pop  es                     ;;   same segment as DS
  56.         ENDIF
  57.         mov reg, pointer                ;; Then load reg with near address
  58.     ENDIF
  59. ENDM
  60.  
  61. ;* GetVidOffset - Macro to determine offset in video segment that corresponds
  62. ;* to given screen coordinates.
  63. ;*
  64. ;* Params:  Row - Screen row (top line = 0)
  65. ;*          Col - Screen column (leftmost column = 0)
  66.  
  67. GetVidOffset MACRO Row, Col
  68.     mov ax, Row
  69.     mov bl, vconfig.cols
  70.     mul bl
  71.     add ax, Col
  72.     shl ax, 1
  73. ENDM
  74.  
  75. ;* Vector - Macro to read current interrupt vector, store it, and replace it.
  76. ;*
  77. ;* Shows:   Equates - @CodeSize     @code
  78. ;*
  79. ;* Params:  num - Vector number
  80. ;*          old - Pointer to doubleword for storing old vector
  81. ;*          new - Pointer to new handler
  82.  
  83. Vector MACRO num, old, new              ;; Macro definition
  84.     push ds                             ;; Save DS and ES registers
  85.     push es
  86.     mov  ah, 35h                        ;; AH = DOS function number
  87.     mov  al, num                        ;; AL = interrupt number
  88.     int  21h                            ;; Get Interrupt Vector
  89.     mov  WORD PTR old[0], bx            ;; Store it
  90.     mov  WORD PTR old[2], es
  91.     IF @CodeSize                        ;; If medium or large model,
  92.         lds dx, new                     ;;    load DS from parameter
  93.     ELSE
  94.         mov bx, @code                   ;; Else ensure DS points to
  95.         mov ds, bx                      ;;    to code segment
  96.         mov dx, WORD PTR new            ;; DS:DX equals new vector
  97.     ENDIF
  98.     mov ah, 25h                         ;; AH = DOS function number
  99.     int 21h                             ;; Set Interrupt Vector
  100.     pop es                              ;; Restore ES and DS
  101.     pop ds
  102. ENDM
  103.  
  104. PBYTE   TYPEDEF      PTR BYTE   ; Type for pointer to bytes
  105. PWORD   TYPEDEF      PTR WORD   ; Type for pointer to words
  106. PSWORD  TYPEDEF      PTR SWORD  ; Type for pointer to integers
  107. PDWORD  TYPEDEF      PTR DWORD  ; Type for pointer to integers
  108. NPBYTE  TYPEDEF NEAR PTR BYTE   ; Type for near pointer to bytes
  109. FPBYTE  TYPEDEF FAR  PTR BYTE   ; Type for far pointer to bytes
  110. FPVOID  TYPEDEF FAR  PTR        ; Type for far pointer to void
  111. PSEG    TYPEDEF WORD            ; Type for segment value
  112.  
  113. ; Structure for video configuration.
  114. VIDCONFIG       STRUCT
  115.   mode          BYTE    ?
  116.   dpage         BYTE    ?
  117.   rows          BYTE    ?
  118.   cols          BYTE    ?
  119.   display       BYTE    ?
  120.   adapter       BYTE    ?
  121.   sgmnt         WORD    ?
  122. VIDCONFIG       ENDS
  123. PVIDCONFIG      TYPEDEF PTR VIDCONFIG
  124.  
  125. ; Structure for FindFirst and FindNext
  126. FILEINFO        STRUCT
  127.   pad           BYTE    21 DUP (?)      ; pad to 43 bytes
  128.   attrib        BYTE    ?               ; file attribute
  129.   time          WORD    ?               ; file time
  130.   date          WORD    ?               ; file date
  131.   count         DWORD   ?               ; file size
  132.   filename      BYTE    13 DUP (?)      ; file name
  133. FILEINFO        ENDS
  134. PFILEINFO       TYPEDEF PTR FILEINFO
  135.  
  136. ; Structure for disk statistics
  137. DISKSTAT        STRUCT
  138.   total         WORD    ?               ; Total clusters
  139.   avail         WORD    ?               ; Available clusters
  140.   sects         WORD    ?               ; Sectors per cluster
  141.   bytes         WORD    ?               ; Bytes per sector
  142. DISKSTAT        ENDS
  143. PDISKSTAT       TYPEDEF PTR DISKSTAT
  144.  
  145. ; Structure for parameter block
  146. PARMBLK         STRUCT
  147.   env           PSEG    ?               ; Segment of environment block
  148.   taddr         FPBYTE  ?               ; Segment:offset address of tail
  149.   fcb1          FPBYTE  ?               ; Segment:offset address of 1st FCB
  150.   fcb2          FPBYTE  ?               ; Segment:offset address of 2nd FCB
  151. PARMBLK         ENDS
  152. PPARMBLK        TYPEDEF PTR PARMBLK
  153.  
  154. ; Prototypes from COMMON.ASM
  155.  
  156. GetVer          PROTO PASCAL
  157. GetVidConfig    PROTO PASCAL 
  158. StrWrite        PROTO PASCAL Row:WORD, Col:WORD, Sptr:PBYTE
  159. ClearBox        PROTO PASCAL Attr:WORD, Row1:WORD, Col1:WORD,
  160.                                         Row2:WORD, Col2:WORD
  161. DisableCga    PROTO PASCAL 
  162. EnableCga    PROTO PASCAL 
  163. SetCurPos       PROTO PASCAL Row:WORD, Col:WORD
  164. GetCurPos    PROTO PASCAL 
  165. StrInput        PROTO PASCAL Row:WORD, Col:WORD, Max:WORD, Sptr:PBYTE
  166.  
  167. ; Prototypes from MISC.ASM
  168.  
  169. WinOpen         PROTO PASCAL Row1:WORD, Col1:WORD,
  170.                              Row2:WORD, Col2:WORD, Attr:WORD
  171. WinClose        PROTO PASCAL Adr:WORD
  172. SetCurSize    PROTO PASCAL Scan1:WORD, Scan2:WORD
  173. GetCurSize    PROTO PASCAL 
  174. GetShift    PROTO PASCAL 
  175. GetMem          PROTO PASCAL
  176. GetKeyClock     PROTO PASCAL Row:WORD, Col:WORD
  177. VeriAnsi    PROTO PASCAL 
  178. VeriPrint    PROTO PASCAL 
  179. VeriCop         PROTO PASCAL
  180. SetLineMode     PROTO PASCAL Line:WORD
  181. Pause           PROTO PASCAL Duration:WORD
  182. Sound           PROTO PASCAL Freq:WORD, Duration:WORD
  183. WriteTTY        PROTO PASCAL Sptr:PBYTE, icolor:WORD
  184. Colors          PROTO PASCAL Logic:WORD, Attr:WORD,
  185.                              Row1:WORD, Col1:WORD, Row2:WORD, Col2:WORD
  186. Exec            PROTO PASCAL Spec:PBYTE, Block:PPARMBLK,
  187.                              CtrBrk:PTR FAR,
  188.                              CtrlC:PTR FAR,
  189.                              Criterr:PTR FAR
  190. BinToHex        PROTO PASCAL Num:WORD, Sptr:PBYTE
  191. NewBlockSize    PROTO PASCAL Adr:WORD, Resize:WORD
  192. Initialize      PROTO PASCAL
  193.                 EXTERNDEF    IntToAsc:PROC
  194.  
  195. ; Prototypes from MATH.ASM
  196. AddLong         PROTO PASCAL Long1:SDWORD, Long2:SDWORD
  197. SubLong         PROTO PASCAL Long1:SDWORD, Long2:SDWORD
  198. ImulLong        PROTO PASCAL Long1:SDWORD, Long2:SDWORD
  199. MulLong         PROTO PASCAL Long1:DWORD, Long2:DWORD
  200. IdivLong        PROTO PASCAL Long1:SDWORD, Short2:SWORD, Remn:PSWORD
  201. DivLong         PROTO PASCAL Long1:DWORD, Short2:WORD, Remn:PWORD
  202. Quadratic       PROTO PASCAL aa:DWORD, bb:DWORD, cc:DWORD,
  203.                              r1:PDWORD, r2:PDWORD
  204.  
  205. ; Prototypes from FILE.ASM
  206. ChangeDrive     PROTO PASCAL Drive:WORD
  207. GetDiskSize     PROTO PASCAL Drive:WORD, Disk:PDISKSTAT
  208. SetDta          PROTO PASCAL Dta:FPBYTE
  209. GetDta          PROTO PASCAL Dta:FPBYTE
  210. ReadCharAttr    PROTO PASCAL Attr:PWORD
  211. GetCurDir       PROTO PASCAL Spec:PBYTE
  212. GetCurDrive     PROTO PASCAL
  213. CopyFile        PROTO PASCAL Imode:WORD, Fspec1:PBYTE, Fspec2:PBYTE
  214. DelFile         PROTO PASCAL Fspec:PBYTE
  215. MakeDir         PROTO PASCAL Pspec:PBYTE
  216. RemoveDir       PROTO PASCAL Pspec:PBYTE
  217. ChangeDir       PROTO PASCAL Pspec:PBYTE
  218. GetAttribute    PROTO PASCAL Fspec:PBYTE
  219. SetAttribute    PROTO PASCAL Attr:WORD, Fspec:PBYTE
  220. RenameFile      PROTO PASCAL Fspec1:PBYTE, Fspec2:PBYTE
  221. GetFileTime     PROTO PASCAL Handle:WORD, Sptr:PBYTE
  222. FindFirst       PROTO PASCAL Attr:WORD, Fspec:PBYTE, Finfo:PFILEINFO
  223. FindNext        PROTO PASCAL Finfo:PFILEINFO
  224. UniqueFile      PROTO PASCAL Attr:WORD, Pspec:PBYTE
  225. OpenFile        PROTO PASCAL Access:WORD, Fspec:PBYTE
  226. CloseFile       PROTO PASCAL Handle:WORD
  227. CreateFile      PROTO PASCAL Attr:WORD, Fspec:PBYTE
  228. CreateNewFile   PROTO PASCAL Attr:WORD, Fspec:PBYTE
  229. ReadFile        PROTO PASCAL Handle:WORD, Len:WORD, Pbuff:PBYTE
  230. WriteFile       PROTO PASCAL Handle:WORD, Sptr:PBYTE
  231. Rewind          PROTO PASCAL Handle:WORD
  232. GetFileSize     PROTO PASCAL Handle:WORD
  233. GetStr          PROTO PASCAL Strbuf:PBYTE, Maxlen:WORD
  234. StrCompare      PROTO PASCAL Sptr1:PBYTE, Sptr2:PBYTE, Len:WORD
  235. StrFindChar     PROTO PASCAL Ichar:SBYTE, Sptr:PBYTE, Direct:WORD
  236.  
  237. ;* Global variables defined with EXTERNDEF are public in the module
  238. ;* in which they are defined, and external in other modules in which
  239. ;* they are used.
  240. ;*
  241. ;* Shows:   Directive             - EXTERNDEF
  242. ;*          Predefined text macro - @CurSeg
  243.  
  244.         .DATA
  245.         EXTERNDEF   vconfig:VIDCONFIG   ; Video configuration
  246.         EXTERNDEF   _psp:PSEG           ; Segment of Program Segment Prefix
  247.         EXTERNDEF   _env:PSEG           ; Segment of environment block
  248. @CurSeg ENDS    ; End .DATA so any subsequent include is outside segment
  249.