home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / MISC_ASM.ZIP / BL5.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-01-08  |  8.4 KB  |  212 lines

  1. ;             BL5.ASM -- A PROGRAM FOR USE WITH QBasic 4.0 TO SAVE
  2. ;                        AND RESTORE SCREENS
  3.  
  4. ;                           AUTHOR:  JOHN HICKMAN
  5.  
  6. ;                   REQUIRES  MICROSOFT MASM 5.O TO ASSEMBLE
  7. ;    (BL5.QLB and BL5.LIB are included for those who do not have MASM 5.0)
  8. ;
  9. ;        Background:  When using data entry templates, it is often convenient 
  10. ;to design a BLOAD screen, load it and then enter whatever data is needed 
  11. ;through the template.  There is a disadvantage to this if you repeat this 
  12. ;process over and over..... it is slow, plus your disk gets beat to death with 
  13. ;all those BLOADs.   These disk accesses may be avoided by BLOADing the 
  14. ;template into an internal QB array then moving the array to the screen 
  15. ;whenever it is needed.  Alas, there is a problem with QBasic 4.0 that makes
  16. ;it difficult to BLOAD a screen into an internal array.  This program,
  17. ;BL5.ASM, is a "work-around" solution that allows you to save a screen in a 
  18. ;machine language buffer then restore it as needed.   To use, BLOAD your screen 
  19. ;the first time as usual & call SAVESCRN, then later, as needed, call RESTSCRN.
  20.  
  21. ; EXAMPLE:               DEF SEG=&hB800
  22. ;                        BLOAD "XYZ.SCN"
  23. ;                        CALL SAVESCRN
  24. ;                             .
  25. ;                             .
  26. ;                             .  do your thing
  27. ;                             .
  28. ;                        CALL RESTSCRN
  29. ;                             .
  30. ;                             .
  31. ;---------------------------------------------------------------------------
  32. ;  WARNING --- THERE MAY BE A PROBLEM WITH MONO ADAPTERS.  IF SO, SEE
  33. ;              THE VIDEO_ENABLE SUB.   
  34.  
  35. ;---------------------------------------------------------------------------
  36. ;  NEW MASM 5.0 STUFF
  37. ;---------------------------------------------------------------------------
  38.  
  39.    DOSSEG
  40.   .MODEL medium
  41.    PUBLIC SAVESCRN, RESTSCRN
  42.  
  43.    ASSUME DS:DGROUP, ES:DGROUP
  44.  
  45. ;---------------------------------------------------------------------------
  46. ;                          DATA SEGMENT
  47. ;---------------------------------------------------------------------------
  48.  
  49. .DATA
  50.  
  51. BLBUF              DW     01020h   DUP(0)           ;THE BUFFER
  52.  
  53. STAT_REG_ADRS      DW     (?)         ;03DAh or 03BAh  as read by AD_TYPE
  54.  
  55. ADAPTER_ADRS       DW     (?)         ;B800h or B000h  as read by AD_TYPE
  56.  
  57. MODE_CTRL_REG      DW     (?)         ;03D8h or 03B8h  as read by AD_TYPE
  58.  
  59. DISPLAY_MODE       DW     (?)         ;whatever ...... as read by AD_TYPE
  60.  
  61. DISPLAY_TABLE      DB     2Dh,29h     ;used by VIDEO_ENABLE for CGA modes 2 & 3
  62.                                       ;add others as needed
  63. ;---------------------------------------------------------------------------
  64. ;                         CODE SEGMENT
  65. ;---------------------------------------------------------------------------
  66.  
  67. .code
  68.  
  69. ;-----------------------  SAVE SCREEN ---------------------------------
  70. SAVESCRN      proc      far
  71.  
  72.               PUSH      BP                       ;save for BASIC
  73.               MOV       BP,SP                    ;set up Base Pointer
  74.               PUSH      DS                       ;save for BASIC
  75.               PUSH      ES                       ;      "
  76.               PUSH      SI                       ;      "
  77.               PUSH      DI                       ;      "
  78.  
  79.               MOV       AX,DGROUP                ;set this program's DS
  80.               MOV       DS,AX
  81.               CALL      AD_TYPE
  82.               LEA       SI, BLBUF
  83.               XOR       DI,DI
  84.               MOV       CX,02000                ;number of transfers to do
  85.               MOV       AX,ADAPTER_ADRS         ;MONO OR CGA
  86.               MOV       ES,AX                   ;PUT IT'S address in ES
  87.  
  88.               PUSH      ES                       ;exchange ES and DS registers
  89.               PUSH      DS                       ;since we are moving data
  90.               POP       ES                       ;from screen to array
  91.               POP       DS                       ;using DS:SI=>ES:DI
  92.                                                  ;     screen=>buffer
  93.               XCHG      SI,DI                    ;exchange indices too
  94.  
  95.               CALL      MOVE_IT                  ;do transfer
  96.  
  97.               POP       DI                       ;prepare to return to BASIC
  98.               POP       SI
  99.               POP       ES
  100.               POP       DS
  101.               POP       BP
  102.               CLD
  103.               RET
  104. SAVESCRN      ENDP
  105.  
  106. ;-----------------------  RESTORE SCREEN -----------------------------------
  107. RESTSCRN      PROC      FAR
  108.               PUSH      BP                       ;save for BASIC
  109.               MOV       BP,SP                    ;set up Base Pointer
  110.               PUSH      DS
  111.               PUSH      ES                       ;save for BASIC
  112.               PUSH      SI
  113.               PUSH      DI
  114.  
  115.               MOV       AX,DGROUP
  116.               MOV       DS,AX
  117.               CALL      AD_TYPE
  118.               LEA       SI, BLBUF
  119.  
  120.               XOR       DI,DI
  121.               MOV       CX,02000                ;number of transfers to do
  122.               MOV       AX,ADAPTER_ADRS         ;MONO OR CGA
  123.               MOV       ES,AX                   ;PUT IT'S address in ES
  124.               CALL      VIDEO_DISABLE
  125.               CALL      MOVE_IT                 ;do transfer
  126.               CALL      VIDEO_ENABLE
  127.               POP       DI
  128.               POP       SI
  129.               POP       ES                      ;prepare to return to BASIC
  130.               POP       DS
  131.               POP       BP
  132.               CLD
  133.               RET                               ;EXIT BACK TO BASIC
  134.  
  135. RESTSCRN      ENDP
  136.  
  137. ;-------------------------  TRANSFER ---------------------------------
  138.  
  139. MOVE_IT       PROC      NEAR
  140.  
  141. MI1:          MOVSW                           ;move character and attribute
  142.               loop      MI1                   ;do CX=2000 times
  143.               ret                             ;DS:SI  & ES:DI
  144.                                               ;srce     dest
  145. MOVE_IT       endp
  146.  
  147.  
  148. ;---------------------------------------------------------------------------
  149. ;------------ DETERMINE ADAPTER TYPE MONO or GRAPHICS-----------------------
  150. ;---------------------------------------------------------------------------
  151.  
  152. AD_TYPE     PROC  NEAR
  153.  
  154.             MOV   AH,0Fh
  155.             INT   10h
  156.             XOR   AH,AH
  157.             MOV   DISPLAY_MODE, AX
  158.             CMP   AL,7
  159.             JE    ITS_MONO
  160.  
  161.             MOV   DX,03DAh                  ;STATUS REG FOR CGA (FOR
  162.             MOV   STAT_REG_ADRS, DX         ;USE IN VRETRACE RTN)
  163.             MOV   DX,03D8h
  164.             MOV   MODE_CTRL_REG, DX
  165.             MOV   DX, 0B800h
  166.             JMP   SETVID
  167.  
  168.  
  169. ITS_MONO:   MOV   DX,03BAh                   ;STATUS REG FOR MONO (FOR USE
  170.             MOV   STAT_REG_ADRS, DX          ;IN VRETRACE RTN)
  171.             MOV   DX, 03B8h
  172.             MOV   MODE_CTRL_REG,DX
  173.             MOV   DX, 0B000h
  174.  
  175. SETVID:     MOV   ADAPTER_ADRS, DX
  176.             RET
  177.  
  178. AD_TYPE     ENDP
  179.  
  180. ;---------------------------------------------------------------------------
  181. ;VIDEO_ENABLE and VIDEO_DISABLE routines
  182. ;---------------------------------------------------------------------------
  183.  
  184. VIDEO_DISABLE PROC NEAR
  185.  
  186.               MOV DX,STAT_REG_ADRS          ;read CGA status port
  187. DISABLE1:     IN AL,DX                      ;wait for vertical retrace to occur
  188.               TEST AL,8                     ;is bit 3 set?
  189.               JE DISABLE1                   ;no, wait until it is
  190.               MOV DX,MODE_CTRL_REG          ;now disable the display
  191.               MOV AL,25h                    ;by clearing bit 3 of the
  192.               OUT DX,AL                     ;mode control register
  193.               RET
  194.  
  195. VIDEO_DISABLE ENDP
  196.  
  197.  
  198. VIDEO_ENABLE  PROC NEAR
  199.  
  200.               MOV DX,MODE_CTRL_REG        ;Mode Control Register (3D8h or 3B8h)
  201.               MOV BX,DISPLAY_MODE         ;get value to re-enable display
  202.               SUB BX,2
  203.               MOV AL,DISPLAY_TABLE[BX]    ;029h for 80X25 16 color text
  204.               OUT DX,AL                   ;and send it to the port
  205.               RET                         ;note- there will probably be a
  206.                                           ;problem with mono adapters, since
  207. VIDEO_ENABLE  ENDP                        ;no DISPLAY_TABLE codes for mono
  208.  
  209. ;----------------------------------------------------------------------------
  210.            END
  211.  
  212.