home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c011 / 1.ddi / SOURCE / FXVI.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-06-01  |  9.9 KB  |  301 lines

  1.   PAGE    60,132
  2.   TITLE   fxVI.ASM -- PCX Effects
  3.   SUBTTL  Copyright (c) Genus Microprogramming, Inc. 1988-89
  4.  
  5. ; fxVI.ASM                                                                   ;
  6. ; Copyright (c) Genus Microprogramming, Inc. 1988-89  All Rights Reserved.   ;
  7.  
  8. ;****************************************************************************;
  9. ;                                                                            ;
  10. ; This file contains procedures for initializing and 'bumping' the virtual   ;
  11. ; pointer, for both conventional and expanded memory.                        ;
  12. ;                                                                            ;
  13. ; Procedures: fxVirtualInit                                                  ;
  14. ;             fxVirtualBump                                                  ;
  15. ;                                                                            ;
  16. ;                                                                            ;
  17. ; Microsoft ASM 5.x version.              Programmer: Chris Howard  3/15/89  ;
  18. ;                                                                            ;
  19. ;****************************************************************************;
  20.  
  21. ; Include files
  22.   INCLUDE ..\inc\pcxDefs.inc
  23.   INCLUDE ..\inc\pcxMacs.inc
  24.   INCLUDE ..\inc\pcxErrs.inc
  25.  
  26.   INCLUDE ..\inc\fxDefs.inc
  27.   INCLUDE ..\inc\fxMacs.inc
  28.   INCLUDE ..\inc\fxErrs.inc
  29.  
  30.   @SetModel
  31.  
  32.   @BegData
  33.  
  34.           EXTRN     pcxMCheck               : WORD
  35.  
  36. fxvtype   dw        ?
  37. fxvhandle dw        ?
  38. fxhpages  dw        ?
  39. fxlpage   dw        ?
  40.  
  41.   @EndData
  42.  
  43.   @BegCode
  44.  
  45.           EXTRN     pcxGetDisplay           : FAR
  46.           EXTRN     pcxGetDispStruc         : FAR
  47.  
  48.           PUBLIC    fxVirtualInit
  49.           PUBLIC    fxVirtualBump
  50.  
  51. ;**********
  52.  
  53. ;
  54. ; This procedure initializes the virtual buffer pointer, whether it is
  55. ; conventional or expanded.
  56. ;
  57. ;
  58.  
  59. ;Define variable locations on the stack  (pascal model)
  60. vivseg    equ       <[bp+ 8]>               ;Virtual buffer pointer
  61. vivofs    equ       <[bp+ 6]>               ; or EMM handle
  62. viparm    equ       4 
  63.  
  64. ;Define local variables
  65. viret     equ       <[bp- 2]>               ;return code
  66. vimcheck  equ       <[bp- 4]>               ;return code
  67. vilocal   equ       4                       ;Total local space needed
  68.  
  69. fxVirtualInit       PROC FAR
  70.  
  71.           @Entry    vilocal                 ;Set up frame and save regs
  72.  
  73.           mov       ax,pcxMCheck            ;Store mode check flag
  74.           mov       vimcheck,ax
  75.  
  76.           mov       ax,vivseg               ;Get the virtual memory type
  77.           cmp       ax,pcxEMM               ;Is it an expanded memory buffer?
  78.           je        fxVI_EMM
  79.  
  80.           jmp       SHORT fxVI_CMM          ;Assume conventional memory
  81.  
  82. fxVI_EMM:
  83.  
  84.           mov       WORD PTR fxvtype,pcxEMM ;Set virtual type flag
  85.  
  86.           mov       dx,vivofs               ;Virtual ofs is really EMM handle
  87.           mov       fxvhandle,dx
  88.  
  89.           @EMM      EMMhpages               ;Get the number of handle pages
  90.  
  91.           or        ah,ah                   ;See if successful
  92.           jz        fxVI_pages
  93.  
  94.           @SetRet   viret,fxERR_EMMFAIL     ;EMM failed
  95.           jmp       fxVI_exit
  96.  
  97. fxVI_pages:
  98.  
  99.           mov       fxhpages,bx             ;Store total handle pages
  100.           xor       ax,ax
  101.           mov       fxlpage,ax              ;And set the logical page to 0
  102.  
  103.           mov       cx,fxhpages             ;Put page count in cx
  104.           mov       ax,-1                   ;Use ax as physical page
  105.  
  106.           cmp       cx,4                    ;Are there less than 4 pages?
  107.           jbe       fxVI_mappages           ;If so, map them
  108.  
  109.           mov       cx,4                    ;Otherwise, map four
  110.  
  111. fxVI_mappages:
  112.  
  113.           mov       dx,fxvhandle            ;Get the handle
  114.           mov       bx,fxlpage              ;Get the logical page
  115.           inc       WORD PTR fxlpage        ; and bump it
  116.           inc       ax                      ;Bump physical page
  117.  
  118.           push      ax                      ; and save it
  119.           @EMM      EMMmpages               ;Map this page
  120.           or        ah,ah                   ;Successful?
  121.           pop       ax                      ; (retrieve physical ...)
  122.  
  123.           loope     fxVI_mappages           ;If so, map the next one
  124.           je        fxVI_frame              ;If done, continue
  125.  
  126.           @SetRet   viret,fxERR_EMMFAIL     ;EMM failed
  127.           jmp       fxVI_exit
  128.  
  129. fxVI_frame:
  130.  
  131.           @EMM      EMMpframe               ;Get the EMM page frame address
  132.  
  133.           or        ah,ah                   ;Successful?
  134.           jz        fxVI_loadseg
  135.  
  136.           @SetRet   viret,fxERR_EMMFAIL     ;EMM failed
  137.           jmp       SHORT fxVI_exit
  138.  
  139. fxVI_loadseg:
  140.  
  141.           @@LoadSeg ds,bx                   ;Frame segment returned in BX
  142.           xor       si,si                   ; (offset is always zero)
  143.  
  144.           jmp       SHORT fxVI_verify       ;Verify this is a PCX buffer
  145.  
  146. fxVI_CMM:
  147.  
  148.           mov       WORD PTR fxvtype,pcxCMM ;Set virtual type flag
  149.  
  150.           @@LoadSeg ds,vivseg               ;Point to the buffer
  151.           mov       si,vivofs
  152.  
  153. fxVI_verify:
  154.  
  155.           mov       al,ds:[si].manuf        ;Check the first byte
  156.           cmp       al,pcxmanuf             ;Is it the pcx sign?
  157.           je        fxVI_getdisp            ;If so, continue
  158.  
  159.           @SetRet   viret,pcxERR_NOTPCX     ;Not a PCX buffer
  160.           jmp       SHORT fxVI_exit         ; so exit
  161.  
  162. fxVI_getdisp:
  163.  
  164.           call      pcxGetDisplay           ;Get the current display type
  165.           cmp       ax,0
  166.           jge       fxVI_getstruc           ;If no error, continue
  167.  
  168.           @SetRet   viret,ax                ;Bad Display type
  169.           jmp       SHORT fxVI_exit         ; so exit
  170.  
  171. fxVI_getstruc:
  172.  
  173.           push      ax                      ;Argument is display type
  174.           call      pcxGetDispStruc         ;Get the display structure (dx:ax)
  175.           cmp       ax,0
  176.           jae       fxVI_chkmode            ;Successful?
  177.  
  178.           @SetRet   viret,fxERR_GENERAL     ;General error,
  179.           jmp       SHORT fxVI_exit         ; so exit
  180.  
  181. fxVI_chkmode:
  182.  
  183.           mov       di,ax                   ;Put returned pointer into regs
  184.           @@LoadSeg es,dx
  185.  
  186.           cmp       WORD PTR vimcheck,TRUE  ;Should we check the mode?
  187.           jne       fxVI_setptr  
  188.  
  189.           cmp       es:[di].dtype,pcxHERC   ;Is this Hercules?
  190.           je        fxVI_setptr  
  191.  
  192.           @GetMode                          ;Get the current display mode
  193.           cmp       al,es:[di].dmode        ;Is this correct for buffer?
  194.           je        fxVI_setptr  
  195.  
  196.           @SetRet   viret,pcxERR_BADMODE    ;Bad display mode
  197.           jmp       SHORT fxVI_exit         ; so exit
  198.  
  199. fxVI_setptr:  
  200.  
  201.           mov       dx,ds                   ;Return the pointer
  202.           mov       bx,si                   ; in DX:BX
  203.  
  204.           @SetRet   viret,fxSUCCESS         ;and set return code                
  205.  
  206. fxVI_exit:
  207.  
  208.           @Exit     viret,viparm            ;Return
  209.  
  210. fxVirtualInit       ENDP
  211.  
  212. ;**********
  213.  
  214. ;
  215. ; This procedure handles the virtual buffer pointer/page logic.  For
  216. ; conventional memory, it simply bumps the segment register by 64K.  For
  217. ; expanded memory, the next set of pages (if available) are swapped in.
  218. ;
  219.  
  220. fxVirtualBump       PROC FAR
  221.  
  222.           cmp       WORD PTR fxvtype,pcxEMM ;Is this expanded?
  223.           je        fxVB_EMM
  224.  
  225.           push      ax                      ;Save regs
  226.  
  227.           mov       ax,ds                   ;Bump segment (for total 64K)
  228.           add       ax,1000H
  229.           mov       ds,ax
  230.  
  231.           pop       ax                      ;Restore regs
  232.  
  233.           clc                               ;Successful, so clear carry
  234.           jmp       SHORT fxVB_ret          ; and return
  235.  
  236. fxVB_EMM:
  237.  
  238.           push      ax                      ;Save regs for EMM mapping
  239.           push      bx
  240.           push      cx
  241.           push      dx
  242.  
  243.           mov       cx,fxhpages             ;Put page count in cx
  244.           sub       cx,fxlpage              ; and sub current logical page
  245.  
  246.           cmp       cx,0                    ;Are there more pages?
  247.           ja        fxVB_morepages
  248.  
  249.           @SetRet   viret,pcxERR_BUFSMALL   ;Buffer was too small
  250.           jmp       SHORT fxVB_emmfail      ; so exit (where we can pop!)
  251.  
  252. fxVB_morepages:
  253.  
  254.           mov       ax,-1                   ;Use ax as physical page
  255.  
  256.           cmp       cx,4                    ;Are there less than 4 pages?
  257.           jbe       fxVB_bumppages          ;If so, map them
  258.  
  259.           mov       cx,4                    ;Otherwise, map four
  260.  
  261. fxVB_bumppages:
  262.  
  263.           mov       dx,fxvhandle            ;Get the handle
  264.           mov       bx,fxlpage              ;Get the logical page
  265.           inc       WORD PTR fxlpage        ; and bump it
  266.           inc       ax                      ;Bump physical page
  267.  
  268.           push      ax                      ; and save it
  269.           @EMM      EMMmpages               ;Map this page
  270.           or        ah,ah                   ;Successful?
  271.           pop       ax                      ; (retrieve physical ...)
  272.  
  273.           loope     fxVB_bumppages          ;If so, map the next one
  274.           jne       fxVB_emmfail            ;If error, failed
  275.  
  276.           clc                               ;Successful, so clear carry
  277.           jmp       SHORT fxVB_emmexit      ; and exit
  278.  
  279. fxVB_emmfail:
  280.  
  281.           @SetRet   viret,fxERR_EMMFAIL     ;EMM failed
  282.           stc                               ; so set carry to indicate error
  283.  
  284. fxVB_emmexit:
  285.  
  286.           pop       dx                      ;Restore regs
  287.           pop       cx
  288.           pop       bx
  289.           pop       ax
  290.  
  291. fxVB_ret:
  292.  
  293.           ret                               ;Return
  294.  
  295. fxVirtualBump       ENDP
  296.  
  297.   @EndCode
  298.  
  299.           END
  300.  
  301.