home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TPCOMMON.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  6.1 KB  |  290 lines

  1. ;******************************************************
  2. ;          TPCOMMON.ASM 5.07
  3. ;        Widely used    macros and equates
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10. COMMENT    |
  11.   For maximum snow prevention on color graphics    adapters, set SuppressAllSnow
  12.   to 1 and reassemble TPCRT.ASM    and TPFAST.ASM:
  13.  
  14.     MASM TPCRT;
  15.     MASM TPFAST;
  16.  
  17.   You will also    need to    recompile the TPCRT unit, of course.
  18. |
  19.  
  20. SuppressAllSnow    = 0
  21.  
  22. ;******************************************************    Macros
  23.  
  24. StackFrame    MACRO
  25.         MOV    BX,SP        ;Set BX    to point to stack
  26.         ENDM
  27.  
  28. StackFrameBP    MACRO
  29.         PUSH    BP
  30.         MOV    BP,SP
  31.         ENDM
  32.  
  33. ExitCode    MACRO    PopCount
  34.         MOV    SP,BP
  35.         POP    BP
  36.         RET    PopCount
  37.         ENDM
  38.  
  39. SetZero        MACRO Reg
  40.         XOR    Reg,Reg        ;Reg = 0
  41.         ENDM
  42.  
  43. SetPtr        MACRO    P, S, O
  44.         MOV    P.Ofst,    O    ;set offset
  45.         MOV    P.Segm,    S    ;set segment
  46.         ENDM
  47.  
  48. SetPtrByOfst    MACRO    P, S, O
  49.         MOV    AX,Offset O
  50.         MOV    P.Ofst,    AX    ;set offset
  51.         MOV    P.Segm,    S    ;set segment
  52.         ENDM
  53.  
  54. GetPtr        MACRO    GPtr
  55.         LES    DI, GPtr    ;Load ES:DI with GPtr
  56.         ENDM
  57.  
  58. GetDSPtr    MACRO    GDPtr
  59.         LDS    SI, GDPtr    ;Load DS:SI with GDPtr
  60.         ENDM
  61.  
  62. NullJump    MACRO
  63.         JMP SHORT $+2        ;jump to next instruction
  64.         ENDM
  65.  
  66. GetVector    MACRO    VecNum,    PtrVar
  67.         MOV    AH,35h        ;Get vector
  68.         MOV    AL,VecNum    ;AL = vector number
  69.         INT    21h        ;call DOS
  70.         SetPtr    PtrVar,    ES, BX    ;save the vector in PtrVar
  71.         ENDM
  72.  
  73. JmpFar        MACRO JAddr
  74.         JMP    DWORD PTR JAddr    ;Jump far to JAddr
  75.         ENDM
  76.  
  77. CallFar        MACRO CAddr
  78.         CALL    DWORD PTR CAddr    ;Call far to CAddr
  79.         ENDM
  80.  
  81. ;Work around bug in the    POPF instruction on certain 80286 chips
  82. FakePOPF    MACRO
  83.         LOCAL X1, X2
  84.         JMP    SHORT X2    ;skip over IRET
  85.     X1:    IRET            ;POP flags and do a RETF
  86.     X2:    PUSH    CS        ;fake a    FAR CALL
  87.         CALL    X1
  88.         ENDM
  89.  
  90. WaitForRetrace    MACRO
  91.         LOCAL WaitNoH, WaitH, Go
  92.         ;Note DX must be initialized to    03DAh
  93.         CLI            ;Interrupts off
  94.     WaitNoH:
  95.         IN    AL,DX        ;Get 6845 status
  96.         TEST    AL,8        ;Check for vertical retrace
  97.         JNZ    Go        ;In progress? go
  98.         SHR    AL,1        ;Wait for end of horizontal
  99.         JC    WaitNoH        ; retrace
  100.     WaitH:
  101.         IN    AL,DX        ;Get 6845 status again
  102.         SHR    AL,1        ;Wait for horizontal
  103.         JNC    WaitH        ; retrace
  104.     Go:
  105.         ENDM
  106.  
  107. IF SuppressAllSnow
  108.  
  109. WordMoveNoSnow    MACRO
  110.         LOCAL Wait1, Wait2, Go,    Next
  111.         ;Note DX must be initialized to    03DAh, CX to loop count
  112.         SHL    CX,1        ;Words to bytes
  113.     Next:    CLI            ;Interrupts off
  114.     Wait1:    IN    AL,DX        ;Get 6845 status
  115.         TEST    AL,8        ;Check for vertical retrace
  116.         JNZ    Go        ;In progress? go
  117.         SHR    AL,1        ;Wait for end of horizontal
  118.         JC    Wait1        ; retrace
  119.     Wait2:    IN    AL,DX        ;Get 6845 status again
  120.         SHR    AL,1        ;Wait for horizontal
  121.         JNC    Wait2        ;  retrace
  122.     Go:    MOVSB            ;Move one byte
  123.         STI            ;Allow interrupts
  124.         LOOP    Next        ;Move next byte
  125.         ENDM
  126.  
  127. ELSE
  128.  
  129. WordMoveNoSnow    MACRO
  130.         LOCAL Wait1, Wait2, Go,    Next
  131.         ;Note DX must be initialized to    03DAh, CX to loop count
  132.     Next:    CLI            ;Interrupts off
  133.     Wait1:    IN    AL,DX        ;Get 6845 status
  134.         SHR    AL,1        ;Wait for end of horizontal
  135.         JC    Wait1        ; retrace
  136.     Wait2:    IN    AL,DX        ;Get 6845 status again
  137.         SHR    AL,1        ;Wait for horizontal
  138.         JNC    Wait2        ;  retrace
  139.     Go:    MOVSW            ;Move one word
  140.         STI            ;Allow interrupts
  141.         LOOP    Next        ;Move next byte
  142.         ENDM
  143.  
  144. ENDIF
  145.  
  146. FastMoveNoSnow    MACRO
  147.         LOCAL Wait1, Wait2, Go,    Next
  148.         ;Note DX must be initialized to    03DAh, CX to loop count
  149.     Next:    CLI            ;Interrupts off
  150.     Wait1:    IN    AL,DX        ;Get 6845 status
  151.         TEST    AL,8        ;Check for vertical retrace
  152.         JNZ    Go        ;In progress? go
  153.         SHR    AL,1        ;Wait for end of horizontal
  154.         JC    Wait1        ; retrace
  155.     Wait2:    IN    AL,DX        ;Get 6845 status again
  156.         SHR    AL,1        ;Wait for horizontal
  157.         JNC    Wait2        ;  retrace
  158.     Go:    MOVSW            ;Move one word
  159.         STI            ;Allow interrupts
  160.         LOOP    Next        ;Move next byte
  161.         ENDM
  162.  
  163. VideoPrim    MACRO
  164.         PUSH    BP        ;save BP
  165.         INT    10h        ;call BIOS
  166.         POP    BP        ;restore BP
  167.         ENDM
  168.  
  169. VideoCall    MACRO    VidService
  170.         MOV    AH, VidService    ;service number
  171.         VideoPrim        ;primitive form
  172.         ENDM
  173.  
  174. VidCallAX    MACRO    VidServAX
  175.         MOV    AX, VidServAX    ;service number
  176.         VideoPrim        ;primitive form
  177.         ENDM
  178.  
  179. KbdCall        MACRO    KbdService
  180.         MOV    AH, KbdService    ;service number
  181.         INT    16h        ;BIOS keyboard interrupt
  182.         ENDM
  183.  
  184. DosCall        MACRO    DosFuncNum
  185.         MOV    AH,DosFuncNum    ;AH = Function number
  186.         INT    21h        ;Call DOS
  187.         ENDM
  188.  
  189. DosCallAX    MACRO    AXval
  190.         MOV    AX,AXval    ;AH = Function #, AL has modifier
  191.         INT    21h        ;Call DOS
  192.         ENDM
  193.  
  194. WordToCGA    MACRO    MVreg
  195.         MOV    AX,MVreg    ;Move video word into AX
  196.         STOSW            ; and then to screen
  197.         STI            ;Allow interrupts
  198.         ENDM
  199.  
  200. ;saves all basic registers in order of a Registers variable,
  201. ;but assumes that flags    are already pushed
  202. SaveAllNoFlags    MACRO
  203.         PUSH    ES        ;save all basic    registers
  204.         PUSH    DS
  205.         PUSH    DI
  206.         PUSH    SI
  207.         PUSH    BP
  208.         PUSH    DX
  209.         PUSH    CX
  210.         PUSH    BX
  211.         PUSH    AX
  212.         ENDM
  213.  
  214. ;Save all registers, including flags
  215. SaveAllRegs    MACRO
  216.         PUSHF            ;save flags
  217.         SaveAllNoFlags        ;save all basic    registers
  218.         ENDM
  219.  
  220. ;Restore all registers saved in    order of SaveAllRegs
  221. RestoreAllRegs    MACRO
  222.         POP    AX        ;restore all basic registers
  223.         POP    BX
  224.         POP    CX
  225.         POP    DX
  226.         POP    BP
  227.         POP    SI
  228.         POP    DI
  229.         POP    DS
  230.         POP    ES
  231.         FakePOPF
  232.         ENDM
  233.  
  234. ;Reset the PIC with an end of interrupt    command    sent to    the proper port.
  235. ResetPIC    MACRO
  236.         MOV    AL,20h        ;end of    interrupt to PIC
  237.         OUT    20h,AL        ;send it
  238.         ENDM
  239.  
  240. ;Reset the keyboard on an IBM PC
  241.  
  242. ResetKbd    MACRO
  243.         IN    AL,61h        ;get keyboard control
  244.         MOV    AH,AL        ;in AH and AL
  245.         OR    AL,80h        ;reset keyboard
  246.         OUT    61h,AL        ;back out
  247.         NullJump        ;delay
  248.         MOV    AL,AH        ;original value
  249.         OUT    61h,AL        ;keyboard is reset
  250.         ENDM
  251.  
  252. ;******************************************************    Equates
  253.  
  254. True        =    1
  255. False        =    0
  256. WP        EQU    WORD PTR
  257.  
  258. ;constants for referring to window coordinates
  259.  
  260. XLow        =    (BYTE PTR 0)
  261. YLow        =    (BYTE PTR 1)
  262. XHigh        =    (BYTE PTR 0)
  263. YHigh        =    (BYTE PTR 1)
  264.  
  265. ;display types
  266.  
  267. UnknownD    =    -1
  268. Unenhanced    =    0
  269. Mono        =    0
  270. CGA        =    1
  271. MCGA        =    2
  272. EGA        =    3
  273. VGA        =    4
  274. PGC        =    5
  275.  
  276. ;miscellaneous constants and equates
  277.  
  278. Font8x8        =    256
  279. TurboBlink    =    16
  280. Blink        =    10000000b
  281.  
  282. ;******************************************************    Structures
  283.  
  284. ;Structure of a    pointer
  285. Pointer    STRUC
  286.     Ofst    DW    0
  287.     Segm    DW    0
  288. Pointer    ENDS
  289.  
  290.