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

  1.   PAGE    60,132
  2.   TITLE   fxFI.ASM -- PCX F/X
  3.   SUBTTL  Copyright (c) Genus Microprogramming, Inc. 1988-89
  4.  
  5. ; fxFI.ASM                                                                   ;
  6. ; Copyright (c) Genus Microprogramming, Inc. 1988-89  All Rights Reserved.   ;
  7.  
  8. ;****************************************************************************;
  9. ;                                                                            ;
  10. ; This file contains high-level procedures for creating virtual image        ;
  11. ; buffers and freeing them later.                                            ;
  12. ;                                                                            ;
  13. ; Procedures: fxFileImage                                                    ;
  14. ;             fxLibImage                                                     ;
  15. ;             fxFreeImage                                                    ;
  16. ;                                                                            ;
  17. ; Microsoft ASM 5.x version.              Programmer: Chris Howard  5/04/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     pcxHBuff                : BYTE
  35.  
  36.   @EndData
  37.  
  38.   @BegCode
  39.  
  40.           EXTRN     pcxGetDisplay           : FAR
  41.           EXTRN     pcxGetFileHeader        : FAR
  42.           EXTRN     pcxGetLibHeader         : FAR
  43.           EXTRN     pcxVirtualFree          : FAR
  44.           EXTRN     pcxVirtualSize          : FAR
  45.           EXTRN     pcxCreateVirtual        : FAR
  46.           EXTRN     pcxFileVirtual          : FAR
  47.           EXTRN     pcxLibVirtual           : FAR
  48.           EXTRN     pcxDestroyVirtual       : FAR
  49.  
  50.           PUBLIC    fxFileImage
  51.           PUBLIC    fxLibImage
  52.           PUBLIC    fxFreeImage
  53.  
  54. ;**********
  55.  
  56. ;
  57. ; This procedure combines the virtual buffer create and load in one step.
  58. ;
  59. ; Calling: retcode = fxFileImage(int vtype,long *vptr,char *filename)
  60. ;
  61. ;
  62.  
  63. ;Define variable locations on the stack  (pascal model)
  64. fitype    equ       <[bp+14]>
  65. fivseg    equ       <[bp+12]>
  66. fivofs    equ       <[bp+10]>
  67. fifseg    equ       <[bp+ 8]>
  68. fifofs    equ       <[bp+ 6]>
  69. fiparm    equ       10
  70.  
  71. ;Define local variables
  72. firet     equ       <[bp- 2]>               ;Return code
  73. fifreehi  equ       <[bp- 4]>               ;Free memory
  74. fifreelo  equ       <[bp- 6]>                           
  75. fiwidth   equ       <[bp- 8]>                           
  76. fidepth   equ       <[bp-10]>                           
  77. filocal   equ       10                      ;Total local space needed
  78.  
  79. fxFileImage         PROC FAR
  80.  
  81.           @Entry    filocal                 ;Set up frame and save regs
  82.  
  83.           mov       ax,fitype               ;Get the amount of free memory
  84.           push      ax
  85.           call      pcxVirtualFree
  86.  
  87.           mov       fifreehi,dx             ;Store locally
  88.           mov       fifreelo,ax
  89.  
  90.           mov       ax,fifseg               ;Try to get the file header
  91.           push      ax                      
  92.           mov       ax,fifofs
  93.           push      ax
  94.           push      ds
  95.           mov       si,OFFSET pcxHBuff
  96.           push      si
  97.           call      pcxGetFileHeader
  98.  
  99.           cmp       ax,fxSUCCESS            ;Were we successful?
  100.           je        fxFI_size
  101.  
  102.           @SetRet   firet,ax                ;Return code
  103.           jmp       fxFI_exit
  104.  
  105. fxFI_size:
  106.  
  107.           mov       cx,ds:[si].x2           ;Calc width
  108.           sub       cx,ds:[si].x1
  109.           inc       cx
  110.           mov       fiwidth,cx
  111.  
  112.           mov       dx,ds:[si].y2           ; and depth ...
  113.           sub       dx,ds:[si].y1
  114.           inc       dx
  115.           mov       fidepth,dx
  116.  
  117.           mov       ax,fitype               ;Now calculate required memory
  118.           push      ax
  119.           push      cx
  120.           push      dx
  121.           call      pcxVirtualSize
  122.  
  123.           cmp       dx,fifreehi             ;Make sure we have enough
  124.           jb        fxFI_create             
  125.           ja        fxFI_nomem
  126.                                             
  127.           cmp       ax,fifreelo
  128.           jbe       fxFI_create
  129.  
  130. fxFI_nomem:
  131.  
  132.           @SetRet   firet,pcxERR_CMMNOMEM   ;We don't, so set error
  133.           cmp       WORD PTR fitype,pcxEMM  ;Is this EMM?
  134.           jne       fxFI_nomemend           ;If not, we are all set
  135.  
  136.           @SetRet   firet,pcxERR_EMMNOMEM   ;Set correct error
  137.  
  138. fxFI_nomemend:
  139.  
  140.           jmp       SHORT fxFI_exit
  141.  
  142. fxFI_create:
  143.  
  144.           mov       ax,fitype               ;Create the buffer
  145.           push      ax
  146.           mov       ax,fivseg
  147.           push      ax
  148.           mov       ax,fivofs
  149.           push      ax
  150.  
  151.           call      pcxGetDisplay           ;Get the current display
  152.           cmp       ds:[si].nplanes,1       ;Is the image B/W?
  153.           jne       fxFI_pushtype
  154.           cmp       ds:[si].bitpx,1
  155.           jne       fxFI_pushtype           
  156.           mov       ax,pcxCGA_6             ;If yes, save space
  157.  
  158. fxFI_pushtype:
  159.  
  160.           push      ax
  161.           mov       ax,fiwidth
  162.           push      ax
  163.           mov       ax,fidepth
  164.           push      ax
  165.  
  166.           call      pcxCreateVirtual
  167.  
  168.           cmp       ax,pcxSUCCESS           ;Successful?
  169.           je        fxFI_file
  170.  
  171.           @SetRet   firet,ax                ;No, so set return code
  172.           jmp       SHORT fxFI_exit
  173.  
  174. fxFI_file:
  175.  
  176.           @@LoadSeg es,fivseg               ;Get a pointer to vptr
  177.           mov       di,fivofs
  178.  
  179.           mov       ax,fifseg               ;Load the file
  180.           push      ax
  181.           mov       ax,fifofs
  182.           push      ax
  183.           mov       ax,es:[di+2]
  184.           push      ax
  185.           mov       ax,es:[di]
  186.           push      ax
  187.  
  188.           call      pcxFileVirtual
  189.  
  190.           @SetRet   firet,ax                ;Return the code
  191.  
  192. fxFI_exit:
  193.  
  194.           @Exit     firet,fiparm            ;Return
  195.  
  196. fxFileImage         ENDP
  197.  
  198. ;**********
  199.  
  200. ;
  201. ; This procedure combines the virtual buffer create and load in one step.
  202. ;
  203. ; Calling: retcode = fxLibImage(int vtype,long vptr,char *libname,char *filename)
  204. ;
  205. ;
  206.  
  207. ;Define variable locations on the stack  (pascal model)
  208. litype    equ       <[bp+18]>
  209. livseg    equ       <[bp+16]>
  210. livofs    equ       <[bp+14]>
  211. lilseg    equ       <[bp+12]>
  212. lilofs    equ       <[bp+10]>
  213. lifseg    equ       <[bp+ 8]>
  214. lifofs    equ       <[bp+ 6]>
  215. liparm    equ       14
  216.  
  217. ;Define local variables
  218. liret     equ       <[bp- 2]>               ;Return code
  219. lifreehi  equ       <[bp- 4]>               ;Free memory
  220. lifreelo  equ       <[bp- 6]>                           
  221. liwidth   equ       <[bp- 8]>                           
  222. lidepth   equ       <[bp-10]>                           
  223. lilocal   equ       10                      ;Total local space needed
  224.  
  225. fxLibImage          PROC FAR
  226.  
  227.           @Entry    lilocal                 ;Set up frame and save regs
  228.  
  229.           mov       ax,litype               ;Get the amount of free memory
  230.           push      ax
  231.           call      pcxVirtualFree
  232.  
  233.           mov       lifreehi,dx             ;Store locally
  234.           mov       lifreelo,ax
  235.  
  236.           mov       ax,lilseg               ;Try to get the file header
  237.           push      ax                      
  238.           mov       ax,lilofs
  239.           push      ax
  240.           mov       ax,lifseg     
  241.           push      ax                      
  242.           mov       ax,lifofs
  243.           push      ax
  244.           push      ds
  245.           mov       si,OFFSET pcxHBuff
  246.           push      si
  247.           call      pcxGetLibHeader
  248.  
  249.           cmp       ax,fxSUCCESS            ;Were we successful?
  250.           je        fxLI_size
  251.  
  252.           @SetRet   liret,ax                ;Return code
  253.           jmp       fxLI_exit
  254.  
  255. fxLI_size:
  256.  
  257.           mov       cx,ds:[si].x2           ;Calc width
  258.           sub       cx,ds:[si].x1
  259.           inc       cx
  260.           mov       liwidth,cx
  261.  
  262.           mov       dx,ds:[si].y2           ; and depth ...
  263.           sub       dx,ds:[si].y1
  264.           inc       dx
  265.           mov       lidepth,dx
  266.  
  267.           mov       ax,litype               ;Now calculate required memory
  268.           push      ax
  269.           push      cx
  270.           push      dx
  271.           call      pcxVirtualSize
  272.  
  273.           cmp       dx,lifreehi             ;Make sure we have enough
  274.           jb        fxLI_create             
  275.           ja        fxLI_nomem
  276.  
  277.           cmp       ax,lifreelo
  278.           jbe       fxLI_create
  279.  
  280. fxLI_nomem:
  281.  
  282.           @SetRet   liret,pcxERR_CMMNOMEM   ;We don't, so set error
  283.           cmp       WORD PTR litype,pcxEMM  ;Is this EMM?
  284.           jne       fxLI_nomemend           ;If not, we are all set
  285.  
  286.           @SetRet   liret,pcxERR_EMMNOMEM   ;Set correct error
  287.  
  288. fxLI_nomemend:
  289.  
  290.           jmp       SHORT fxLI_exit
  291.  
  292. fxLI_create:
  293.  
  294.           mov       ax,litype               ;Create the buffer
  295.           push      ax
  296.           mov       ax,livseg
  297.           push      ax
  298.           mov       ax,livofs
  299.           push      ax
  300.  
  301.           call      pcxGetDisplay           ;Get the current display
  302.           cmp       ds:[si].nplanes,1       ;Is the image B/W?
  303.           jne       fxLI_pushtype
  304.           cmp       ds:[si].bitpx,1
  305.           jne       fxLI_pushtype           
  306.           mov       ax,pcxCGA_6             ;If yes, save space
  307.  
  308. fxLI_pushtype:
  309.  
  310.           push      ax
  311.           mov       ax,liwidth
  312.           push      ax
  313.           mov       ax,lidepth
  314.           push      ax
  315.  
  316.           call      pcxCreateVirtual
  317.  
  318.           cmp       ax,pcxSUCCESS           ;Successful?
  319.           je        fxLI_file
  320.  
  321.           @SetRet   liret,ax                ;No, so set return code
  322.           jmp       SHORT fxLI_exit
  323.  
  324. fxLI_file:
  325.  
  326.           @@LoadSeg es,livseg               ;Get a pointer to vptr
  327.           mov       di,livofs
  328.  
  329.           mov       ax,lilseg               ;Load the library file
  330.           push      ax    
  331.           mov       ax,lilofs
  332.           push      ax
  333.           mov       ax,lifseg
  334.           push      ax
  335.           mov       ax,lifofs
  336.           push      ax
  337.           mov       ax,es:[di+2]
  338.           push      ax
  339.           mov       ax,es:[di]
  340.           push      ax
  341.  
  342.           call      pcxLibVirtual
  343.  
  344.           @SetRet   liret,ax                ;Return the code
  345.  
  346. fxLI_exit:
  347.  
  348.           @Exit     liret,liparm            ;Return
  349.  
  350. fxLibImage          ENDP
  351.  
  352. ;**********
  353.  
  354. ;
  355. ; This procedure frees a previously loaded virtual image buffer.
  356. ;
  357. ; Calling: retcode = fxFreeImage(vptr)
  358. ;
  359. ;
  360.  
  361. ;Define variable locations on the stack, depending on model
  362. rivseg    equ       <[bp+ 8]>
  363. rivofs    equ       <[bp+ 6]>
  364. riparm    equ       4
  365.  
  366. ;Define local variables
  367. riret     equ       <[bp-2]>                ;return code
  368. rilocal   equ       2                       ;Total local space needed
  369.  
  370. fxFreeImage         PROC FAR
  371.  
  372.           @Entry    rilocal                 ;Set up frame and save regs
  373.  
  374.           mov       ax,rivseg               ;Just chain to DestroyVirtual
  375.           push      ax
  376.           mov       ax,rivofs
  377.           push      ax
  378.           call      pcxDestroyVirtual
  379.  
  380.           @SetRet   riret,ax                ;Get the return code, and return
  381.                                             ; it as ours
  382.  
  383.           @Exit     riret,riparm            ;Return
  384.  
  385. fxFreeImage         ENDP
  386.  
  387.   @EndCode
  388.  
  389.           END
  390.  
  391.