home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / mailpro / fastwr.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-23  |  18.2 KB  |  439 lines

  1. ;       FASTWR.ASM
  2. ;       Fast screen writing routines
  3. ;       By Brian Foley
  4. ;       Last update: 11/08/87
  5.  
  6.  
  7. ;****************************************************** Equates
  8.  
  9.         Mono    = 0
  10.         CGA     = 1
  11.         EGA     = 2
  12.         MCGA    = 3
  13.         VGA     = 4
  14.  
  15. ;****************************************************** Data
  16.  
  17. DATA    SEGMENT BYTE PUBLIC
  18.  
  19.         EXTRN   BaseOfScreen : WORD     ;Pascal variables
  20.         EXTRN   WaitForRetrace : BYTE
  21.  
  22.         CurrentMode     DB      ?       ;local variables
  23.         Display         DB      ?
  24.  
  25. DATA    ENDS
  26.  
  27. ;****************************************************** Code
  28.  
  29. CODE    SEGMENT BYTE PUBLIC
  30.  
  31.         ASSUME  CS:CODE,DS:DATA
  32.  
  33.         PUBLIC  FastWrite, FastWriteNA, ChangeAttribute, MoveFromScreen
  34.         PUBLIC  MoveToScreen, CurrentDisplay, CurrentVideoMode
  35.  
  36. ;****************************************************** CalcOffset
  37.  
  38. ;Calculates offset in video memory corresponding to Row,Column
  39. ;On entry, CH has Row, BX has Column (both 1-based)
  40. ;On exit, ES:DI points to proper address in video memory, AX = 0
  41.  
  42. CalcOffset      PROC NEAR
  43.  
  44.         XOR     AX,AX                   ;AX = 0
  45.         MOV     CL,AL                   ;CL = 0
  46.         MOV     BH,AL                   ;BH = 0
  47.         DEC     CH                      ;Row (in CH) to 0..24 range
  48.         SHR     CX,1                    ;CX = Row * 128
  49.         MOV     DI,CX                   ;Store in DI
  50.         SHR     DI,1                    ;DI = Row * 64
  51.         SHR     DI,1                    ;DI = Row * 32
  52.         ADD     DI,CX                   ;DI = (Row * 160)
  53.         DEC     BX                      ;Col (in BX) to 0..79 range
  54.         SHL     BX,1                    ;Account for attribute bytes
  55.         ADD     DI,BX                   ;DI = (Row * 160) + (Col * 2)
  56.         MOV     ES,BaseOfScreen         ;ES:DI points to BaseOfScreen:Row,Col
  57.         RET                             ;Return
  58.  
  59. CalcOffset      ENDP
  60.  
  61. ;****************************************************** FastWrite
  62.  
  63. ;procedure FastWrite(St : String; Row, Col, Attr : Byte);
  64. ;Write St at Row,Col in Attr (video attribute) without snow
  65.  
  66. ;equates for parameters:
  67. FWAttr          EQU     BYTE PTR [BP+6]
  68. FWCol           EQU     BYTE PTR [BP+8]
  69. FWRow           EQU     BYTE PTR [BP+10]
  70. FWSt            EQU     DWORD PTR [BP+12]
  71.  
  72. FastWrite       PROC FAR
  73.  
  74.         PUSH    BP                      ;Save BP
  75.         MOV     BP,SP                   ;Set up stack frame
  76.         PUSH    DS                      ;Save DS
  77.         MOV     CH,FWRow                ;CH = Row
  78.         MOV     BL,FWCol                ;BL = Column
  79.         CALL    CalcOffset              ;Call routine to calculate offset
  80.         MOV     CL,WaitForRetrace       ;Grab this before changing DS
  81.         LDS     SI,FWSt                 ;DS:SI points to St[0]
  82.         CLD                             ;Set direction to forward
  83.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  84.         XCHG    AX,CX                   ;CX = Length; AL = WaitForRetrace
  85.         JCXZ    FWExit                  ;If string empty, exit
  86.         MOV     AH,FWAttr               ;AH = Attribute
  87.         RCR     AL,1                    ;If WaitForRetrace is False...
  88.         JNC     FWMono                  ; use "FWMono" routine
  89.         MOV     DX,03DAh                ;Point DX to CGA status port
  90. FWGetNext:
  91.         LODSB                           ;Load next character into AL
  92.                                         ; AH already has Attr
  93.         MOV     BX,AX                   ;Store video word in BX
  94.         CLI                             ;No interrupts now
  95. FWWaitNoH:
  96.         IN      AL,DX                   ;Get 6845 status
  97.         TEST    AL,8                    ;Vertical retrace in progress?
  98.         JNZ     FWStore                 ;If so, go
  99.         RCR     AL,1                    ;Else, wait for end of
  100.         JC      FWWaitNoH               ; horizontal retrace
  101. FWWaitH:
  102.         IN      AL,DX                   ;Get 6845 status again
  103.         RCR     AL,1                    ;Wait for horizontal
  104.         JNC     FWWaitH                 ; retrace
  105. FWStore:
  106.         MOV     AX,BX                   ;Move word back to AX...
  107.         STOSW                           ; and then to screen
  108.         STI                             ;Allow interrupts!
  109.         LOOP    FWGetNext               ;Get next character
  110.         JMP     FWExit                  ;Done
  111. FWMono:
  112.         LODSB                           ;Load next character into AL
  113.                                         ; AH already has Attr
  114.         STOSW                           ;Move video word into place
  115.         LOOP    FWMono                  ;Get next character
  116. FWExit:
  117.         POP     DS                      ;Restore DS
  118.         MOV     SP,BP                   ;Restore SP
  119.         POP     BP                      ;Restore BP
  120.         RET     10                      ;Remove parameters and return
  121.  
  122. FastWrite       ENDP
  123.  
  124. ;****************************************************** FastWriteNA
  125.  
  126. ;procedure FastWriteNA(St : String; Row, Col : Byte);
  127. ;Write St at Row,Col without snow, and don't change video attributes
  128.  
  129. ;equates for parameters:
  130. FNCol           EQU     BYTE PTR [BP+6]
  131. FNRow           EQU     BYTE PTR [BP+8]
  132. FNSt            EQU     DWORD PTR [BP+10]
  133.  
  134. FastWriteNA     PROC FAR
  135.  
  136.         PUSH    BP                      ;Save BP
  137.         MOV     BP,SP                   ;Set up stack frame
  138.         PUSH    DS                      ;Save DS
  139.         MOV     CH,FNRow                ;CH = Row
  140.         MOV     BL,FNCol                ;BL = Column
  141.         CALL    CalcOffset              ;Call routine to calculate offset
  142.         MOV     CL,WaitForRetrace       ;Grab this before changing DS
  143.         LDS     SI,FNSt                 ;DS:SI points to St[0]
  144.         CLD                             ;Set direction to forward
  145.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  146.         XCHG    AX,CX                   ;CX = Length; AL = Wait
  147.         JCXZ    FNExit                  ;If string empty, exit
  148.         RCR     AL,1                    ;If WaitForRetrace is False...
  149.         JNC     FNNoWait                ; use FNNoWait routine
  150.         MOV     DX,03DAh                ;Point DX to CGA status port
  151. FNGetNext:
  152.         LODSB                           ;Load next character into AL
  153.         MOV     AH,AL                   ;Store char in AH
  154.         CLI                             ;No interrupts now
  155. FNWaitNoH:
  156.         IN      AL,DX                   ;Get 6845 status
  157.         TEST    AL,8                    ;Check for vertical retrace
  158.         JNZ     FNStore                 ; In progress? go
  159.         RCR     AL,1                    ;Else, wait for end of
  160.         JC      FNWaitNoH               ; horizontal retrace
  161. FNWaitH:
  162.         IN      AL,DX                   ;Get 6845 status again
  163.         RCR     AL,1                    ;Wait for horizontal
  164.         JNC     FNWaitH                 ; retrace
  165. FNStore:
  166.         MOV     AL,AH                   ;Move char back to AL...
  167.         STOSB                           ; and then to screen
  168.         STI                             ;Allow interrupts
  169.         INC     DI                      ;Skip attribute bytes
  170.         LOOP    FNGetNext               ;Get next character
  171.         JMP     FNExit                  ;Done
  172. FNNoWait:
  173.         MOVSB                           ;Move character to screen
  174.         INC     DI                      ;Skip attribute bytes
  175.         LOOP    FNNoWait                ;Get next character
  176. FNExit:
  177.         POP     DS                      ;Restore DS
  178.         MOV     SP,BP                   ;Restore SP
  179.         POP     BP                      ;Restore BP
  180.         RET     8                       ;Remove parameters and return
  181.  
  182. FastWriteNA     ENDP
  183.  
  184. ;****************************************************** ChangeAttribute
  185.  
  186. ;procedure ChangeAttribute(Number : Word; Row, Col, Attr : Byte);
  187. ;Change Number video attributes to Attr starting at Row,Col
  188.  
  189. ;equates for parameters:
  190. CAAttr          EQU     BYTE PTR [BP+6]
  191. CACol           EQU     BYTE PTR [BP+8]
  192. CARow           EQU     BYTE PTR [BP+10]
  193. CANumber        EQU     WORD PTR [BP+12]
  194.  
  195. ChangeAttribute PROC FAR
  196.  
  197.         PUSH    BP                      ;Save BP
  198.         MOV     BP,SP                   ;Set up stack frame
  199.         MOV     CH,CARow                ;CH = Row
  200.         MOV     BL,CACol                ;BL = Column
  201.         CALL    CalcOffset              ;Call routine to calculate offset
  202.         INC     DI                      ;Skip character
  203.         CLD                             ;Set direction to forward
  204.         MOV     CX,CANumber             ;CX = Number to change
  205.         JCXZ    CAExit                  ;If zero, exit
  206.         MOV     AL,CAAttr               ;AL = Attribute
  207.         CMP     WaitForRetrace,1        ;Get wait state
  208.         JNE     CANoWait                ;If WaitForRetrace is False
  209.                                         ; use CANoWait routine
  210.         MOV     AH,AL                   ;Store attribute in AH
  211.         MOV     DX,03DAh                ;Point DX to CGA status port
  212. CAGetNext:
  213.         CLI                             ;No interrupts now
  214. CAWaitNoH:
  215.         IN      AL,DX                   ;Get 6845 status
  216.         TEST    AL,8                    ;Check for vert. retrace
  217.         JNZ     CAGo                    ;In progress? Go
  218.         RCR     AL,1                    ;Wait for end of horizontal
  219.         JC      CAWaitNoH               ; retrace
  220. CAWaitH:
  221.         IN      AL,DX                   ;Get 6845 status again
  222.         RCR     AL,1                    ;Wait for horizontal
  223.         JNC     CAWaitH                 ; retrace
  224. CAGo:
  225.         MOV     AL,AH                   ;Move Attr back to AL...
  226.         STOSB                           ; and then to screen
  227.         STI                             ;Allow interrupts
  228.         INC     DI                      ;Skip characters
  229.         LOOP    CAGetNext               ;Look for next opportunity
  230.         JMP     CAExit                  ;Done
  231. CANoWait:
  232.         STOSB                           ;Change the attribute
  233.         INC     DI                      ;Skip characters
  234.         LOOP    CANoWait                ;Get next character
  235. CAExit:                                 ;Next instruction
  236.         MOV     SP,BP                   ;Restore SP
  237.         POP     BP                      ;Restore BP
  238.         RET     8                       ;Remove parameters and return
  239.  
  240. ChangeAttribute ENDP
  241.  
  242. ;****************************************************** MoveFromScreen
  243.  
  244. ;procedure MoveFromScreen(var Source, Dest; Length : Word);
  245. ;Move Length words from Source (video memory) to Dest without snow
  246.  
  247. ;equates for parameters:
  248. MFLength        EQU     WORD PTR [BP+6]
  249. MFDest          EQU     DWORD PTR [BP+8]
  250. MFSource        EQU     DWORD PTR [BP+12]
  251.  
  252. MoveFromScreen  PROC FAR
  253.  
  254.         PUSH    BP                      ;Save BP
  255.         MOV     BP,SP                   ;Set up stack frame
  256.         MOV     BX,DS                   ;Save DS in BX
  257.         MOV     AL,WaitForRetrace       ;Grab before changing DS
  258.         LES     DI,MFDest               ;ES:DI points to Dest
  259.         LDS     SI,MFSource             ;DS:SI points to Source
  260.         MOV     CX,MFLength             ;CX = Length
  261.         CLD                             ;Set direction to forward
  262.         RCR     AL,1                    ;Check WaitForRetrace
  263.         JNC     MFNoWait                ;False? Use MFNoWait routine
  264.         MOV     DX,03DAh                ;Point DX to CGA status port
  265. MFNext:
  266.         CLI                             ;No interrupts now
  267. MFWaitNoH:
  268.         IN      AL,DX                   ;Get 6845 status
  269.         TEST    AL,8                    ;Check for vertical retrace
  270.         JNZ     MFGo                    ;In progress? go
  271.         RCR     AL,1                    ;Wait for end of horizontal
  272.         JC      MFWaitNoH               ; retrace
  273. MFWaitH:
  274.         IN      AL,DX                   ;Get 6845 status again
  275.         RCR     AL,1                    ;Wait for horizontal
  276.         JNC     MFWaitH                 ; retrace
  277. MFGo:
  278.         LODSW                           ;Load next video word into AX
  279.         STI                             ;Allow interrupts
  280.         STOSW                           ;Store video word in Dest
  281.         LOOP    MFNext                  ;Get next video word
  282.         JMP     MFExit                  ;All Done
  283. MFNoWait:
  284.         REP     MOVSW                   ;That's it!
  285. MFExit:
  286.         MOV     DS,BX                   ;Restore DS
  287.         MOV     SP,BP                   ;Restore SP
  288.         POP     BP                      ;Restore BP
  289.         RET     10                      ;Remove parameters and return
  290.  
  291. MoveFromScreen  ENDP
  292.  
  293. ;****************************************************** MoveToScreen
  294.  
  295. ;procedure MoveToScreen(var Source, Dest; Length : Word);
  296. ;Move Length words from Source to Dest (video memory) without snow
  297.  
  298. ;equates for parameters:
  299. MTLength        EQU     WORD PTR [BP+6]
  300. MTDest          EQU     DWORD PTR [BP+8]
  301. MTSource        EQU     DWORD PTR [BP+12]
  302.  
  303. MoveToScreen    PROC FAR
  304.  
  305.         PUSH    BP                      ;Save BP
  306.         MOV     BP,SP                   ;Set up stack frame
  307.         PUSH    DS                      ;Save DS
  308.         MOV     AL,WaitForRetrace       ;Grab before changing DS
  309.         LES     DI,MTDest               ;ES:DI points to Dest
  310.         LDS     SI,MTSource             ;DS:SI points to Source
  311.         MOV     CX,MTLength             ;CX = Length
  312.         CLD                             ;Set direction to forward
  313.         RCR     AL,1                    ;Check WaitForRetrace
  314.         JNC     MTNoWait                ;False? Use MTNoWait routine
  315.         MOV     DX,03DAh                ;Point DX to CGA status port
  316. MTGetNext:
  317.         LODSW                           ;Load next video word into AX
  318.         MOV     BX,AX                   ;Store video word in BX
  319.         CLI                             ;No interrupts now
  320. MTWaitNoH:
  321.         IN      AL,DX                   ;Get 6845 status
  322.         TEST    AL,8                    ;Check for vertical retrace
  323.         JNZ     MTGo                    ;In progress? Go
  324.         RCR     AL,1                    ;Wait for end of horizontal
  325.         JC      MTWaitNoH               ; retrace
  326. MTWaitH:
  327.         IN      AL,DX                   ;Get 6845 status again
  328.         RCR     AL,1                    ;Wait for horizontal
  329.         JNC     MTWaitH                 ; retrace
  330. MTGo:
  331.         MOV     AX,BX                   ;Move word back to AX...
  332.         STOSW                           ; and then to screen
  333.         STI                             ;Allow interrupts
  334.         LOOP    MTGetNext               ;Get next video word
  335.         JMP     MTExit                  ;All done
  336. MTNoWait:
  337.         REP     MOVSW                   ;That's all!
  338. MTExit:
  339.         POP     DS                      ;Restore DS
  340.         MOV     SP,BP                   ;Restore SP
  341.         POP     BP                      ;Restore BP
  342.         RET     10                      ;Remove parameters and return
  343.  
  344. MoveToScreen    ENDP
  345.  
  346. ;****************************************************** CurrentModePrim
  347.  
  348. ;Returns current video mode in AL
  349.  
  350. CurrentModePrim PROC NEAR
  351.  
  352.         MOV     AH,0Fh                  ;Get video mode function
  353.         INT     10h                     ;Call BIOS
  354.         MOV     CurrentMode,AL          ;Save it
  355.         RET                             ;Return
  356.  
  357. CurrentModePrim ENDP
  358.  
  359. ;****************************************************** CurrentDisplay
  360.  
  361. ;function CurrentDisplay : DisplayType;
  362. ;Returns type of the currently active display.
  363.  
  364. JunkValue       = 0FFFFh
  365.  
  366. CurrentDisplay  PROC FAR
  367.  
  368.         ;get the current video mode
  369.         CALL     CurrentModePrim        ;Call primitive routine
  370.  
  371.         ;test for VGA
  372.         MOV     Display,VGA             ;Assume VGA
  373.         MOV     CX,JunkValue            ;Load CX with junk value
  374.         MOV     AX,1C00h                ;Save/Restore video state
  375.         INT     10h
  376.         CMP     AL,1Ch                  ;AL = $1C signals valid call
  377.         JE      CDexit                  ;Adapter type known
  378.  
  379.         ;test for MCGA
  380.         MOV     Display,MCGA            ;Assume MCGA
  381.         MOV     BL,32h                  ;Choose Enable
  382.         MOV     AX,1200h                ;Enable/Disable video addressing
  383.         INT     10h
  384.         CMP     AL,12h                  ;AL = $12 signals valid call
  385.         JE      CDexit                  ;Adapter type known
  386.  
  387.         ;test for EGA
  388.         MOV     Display,EGA             ;Assume EGA
  389.         MOV     BX,0FF10h               ;Return EGA information
  390.         MOV     CX,JunkValue            ;Load CX with junk value
  391.         MOV     AX,1200h                ;Alternate function select
  392.         INT     10h
  393.         XOR     AL,AL                   ;AL = 0
  394.         CMP     CX,JunkValue            ;CX unchanged?
  395.         JE      CDplain                 ;If so, not an EGA
  396.         CMP     BH,1                    ;BH should be 0 or 1
  397.         JA      CDplain                 ;Mono or CGA if it isn't
  398.  
  399.         ;See if EGA is the active display
  400.         CMP     BH,1                    ;mono display?
  401.         JE      CDegaMono               ;If so, use mono check
  402.         CMP     CurrentMode,7           ;In mono mode?
  403.         JE      CDplain                 ;If so, we're not on the EGA
  404.         JMP     SHORT CDexit            ;else, it's an EGA
  405.  
  406. CDegaMono:
  407.         CMP     CurrentMode,7           ;Current mode = 7?
  408.         JNE     CDplain                 ;Exit if not
  409.  
  410. CDexit:
  411.         MOV     AL,Display              ;set return value
  412.         RET                             ;Return
  413.  
  414. CDplain:
  415.         MOV     Display,CGA             ;Assume CGA
  416.         CMP     CurrentMode,7           ;Mono mode
  417.         JNE     CDexit                  ;Done if not
  418.         MOV     Display,Mono            ;Else, Mono
  419.         JMP     SHORT CDexit            ;Done
  420.  
  421. CurrentDisplay  ENDP
  422.  
  423. ;****************************************************** CurrentVideoMode
  424.  
  425. ;function CurrentVideoMode : Byte;
  426. ;Returns current video mode in AL
  427.  
  428. CurrentVideoMode        PROC FAR
  429.  
  430.         CALL     CurrentModePrim        ;Call primitive routine
  431.         RET                             ;Return
  432.  
  433. CurrentVideoMode        ENDP
  434.  
  435. CODE    ENDS
  436.  
  437.         END
  438. 
  439.