home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Languages / Masm V6.11 / SAMPLES / DEMOS / DEMO.IN$ / DEMO
Encoding:
Text File  |  1992-11-12  |  10.1 KB  |  248 lines

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