home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / graphics / pcxbe05.zip / PCXBE.DOC next >
Text File  |  1993-07-16  |  7KB  |  220 lines

  1.         PCX block extractor  Ver 0.5
  2.                      S. Hyun Yim
  3.                      07/16/93
  4.  
  5. This is a freeware originally written for my own programming needs and
  6. modified for publication as freeware.
  7.  
  8. You can use this program to:
  9.  1. View a 320*200*256 PCX file
  10.  2. Extract a bitmap block from a 320*200*256 PCX file.
  11.  3. Extract palette from a 320*200*256 PCX file.
  12.  
  13. This program only works with 320*200*256 PCX file that's smaller than 64k.
  14. If you specify any other type of file, the program would NOT crash, but
  15. wouldn't do any good either.
  16.  
  17. The sample assembly codes to use with the bitmap you saved follows:
  18. (You need Turbo Assember to use this codes.
  19.  To use with any other assembler, you would need to convert the codes to
  20.  MASM mode.)
  21.  
  22.  
  23. %TITLE "VGA graphic module
  24. ;---------------------------------------------------------------------
  25. ;      S.Hyun Yim
  26. ;
  27. ;      This module contains simple VGA 320*200*256 graphic functions
  28. ;      useful for the manipulation (and animation) of arbitrary
  29. ;      bitmap images.
  30. ;------------------------------------------------------------------------
  31. ; CAUTION!
  32. ;      1. This module is written in Ideal-Small model, meaning you need
  33. ;         Borland Turbo Assembler to compile it.
  34. ;         (You can easily change this module to a memory model other than
  35. ;          small.)
  36. ;      2. All the functions in this module assumes that video mode is
  37. ;         already set to 13h using BIOS 10h service AND es points to the
  38. ;         video buffer (0A000h) Both conditions must be met prior to
  39. ;         calling any functions here.
  40. ;      3. The functions does not test if VGA card is present. It's the
  41. ;         job of the caller to make sure!
  42. ;------------------------------------------------------------------------
  43. ;
  44. ;---------------------------------------------------------------------
  45.  
  46.        IDEAL
  47.        DOSSEG
  48.        MODEL small
  49.  
  50.        DATASEG
  51.  
  52.  
  53. space        DW   0
  54.  
  55.  
  56.        CODESEG
  57.  
  58.        PUBLIC    putXor,putAND,putAnywhere
  59.  
  60. %NEWPAGE
  61. PROC putXOR
  62. ;------------------------------------------------------------
  63. ; This function puts the bitmap image using XOR method.
  64. ; You can use this function to create simple XOR animation.
  65. ;------------------------------------------------------------
  66. ; input: ax=y coord. of top left   bx=x coord. of top left
  67. ;        ds:si=offset of bitblockimage
  68. ;---------------------------------------------------------
  69.      call getAddr256
  70.  
  71.        mov     cx,[si]         ; X size of the bitmap
  72.        mov     dx,[si+2]       ; Y size of the bitmap
  73.  
  74.       mov     bh,dl             ; bh now hold Y dim
  75.       xor     bl,bl
  76.       mov     dx,cx
  77.       cld
  78. XBB1:
  79.       lodsb                       ; load [ds:si] to al
  80.       xor     [es:di],al          ; xor [es:di] with al
  81.       inc     di                  ; inc di by 1
  82.       loop    XBB1                ; loop instruction
  83.  
  84.       add     di, 320
  85.       sub     di, dx
  86.       mov     cx, dx
  87.       inc     bl
  88.       cmp     bl,bh               ; did it reach end of line?
  89.       jne     XBB1                ; if not go back
  90.  
  91.  
  92.      ret
  93. ENDP putXOR
  94.  
  95. PROC putAND
  96. ;------------------------------------------------------------------
  97. ; This function puts bitmap image to the video buffer(es).
  98. ; But before copying each pixel down, it tests if the color of the
  99. ; bit map pixel is Zero. If it is, it does not update the video
  100. ; buffer and skips to the next.
  101. ; You can use this function to display any arbitrary bitmap sprite
  102. ; against a complex background.
  103. ;
  104. ;    input : same as putXOR
  105. ;-------------------------------------------------------------------
  106.      call getAddr256
  107.  
  108.       mov     cx,[si]           ; x size
  109.       mov     dx,[si+2]         ; y size
  110.  
  111.       mov     bh,dl             ; bh now hold Y dim
  112.       xor     bl,bl
  113.       mov     dx,cx
  114.       cld
  115. ABB1:
  116.       lodsb
  117.       or      al,al              ; is pixel of bit block zero?
  118.       jz      @@abb              ; if yes, skip putting the pixel down
  119.       stosb                      ; if not, put the pixel
  120.       jmp     @@abb2             ; go on
  121. @@abb:inc     di
  122. @@abb2:loop    ABB1              ; loop instruction
  123.  
  124.       add     di, 320
  125.       sub     di, dx             ; set di to the next line
  126.       mov     cx, dx
  127.       inc     bl                 ; increase bl by 1
  128.       cmp     bl,bh              ; did it reach last line?
  129.       jne     ABB1               ; if not go back
  130.  
  131.       ret
  132. ENDP putAND
  133.  
  134. %NEWPAGE
  135. PROC putAnywhere
  136. ;------------------------------------------------------------------
  137. ; Same as putAND, except for it trims the image outside the screen
  138. ; (COOL!)
  139. ;------------------------------------------------------------------
  140.      mov      cx,[si]
  141.      mov      dx,[si+2]
  142.      mov      [space],0
  143.      cmp      bx,0          ; is X less than 0?
  144.      jge      @@bigX?
  145.      add      cx,bx
  146.      neg      bx
  147.      mov      [space],bx
  148.      xor      bx,bx
  149.      add      si,[space]
  150.      jmp      @@y?
  151. @@bigX?:                    ; does image go beyond the X limit?
  152.      add      cx,bx
  153.      cmp      cx,320
  154.      jle      @@restoreReg
  155.      sub      cx,320
  156.      mov      [space],cx
  157.      mov      cx,320
  158. @@restoreReg:
  159.      sub      cx,bx
  160.  
  161. @@y?:                      ; is y less than 0?
  162.      cmp      ax,0
  163.      jge      @@y?2
  164.      add      dx,ax      ; add ax(negative value) to y dimension
  165.      neg      ax         ; get absolute value
  166.      mul      cl
  167.      add      si,ax
  168.      xor      ax,ax
  169.  
  170. @@y?2:                   ; is a portion of image beyond y limit?
  171.      add      dx,ax
  172.      cmp      dx,200
  173.      jle      @@restoreReg2
  174.      mov      dx,200
  175. @@restoreReg2:
  176.      sub      dx,ax            ; restore the value of dx
  177.  
  178. ;-----put
  179.      call getAddr256
  180.  
  181.       mov     bh,dl             ; bh now hold Y dim
  182.       xor     bl,bl
  183.       mov     dx,cx
  184.       cld
  185. PBB1:
  186.       lodsb
  187.       cmp     al,0   ; is pixel of bit block zero?
  188.       je      @@abb             ; if not, put the pixel
  189.       stosb
  190.       jmp     @@abb2             ; go on
  191. @@abb:inc     di
  192. @@abb2:loop    PBB1              ; loop instruction
  193.  
  194.       add     di, 320
  195.       sub     di, dx             ; set pointer to next line
  196.       mov     cx, dx
  197.       inc     bl                 ; increase bl by 1
  198.       cmp     bl,bh              ; did it reach last line?
  199.       jne     PBB1               ; if not go back
  200.  
  201.       ret
  202. ENDP putanywhere
  203.  
  204. PROC getAddr256
  205. ;-------------------------------------------------------
  206. ; an internal routine calculating offset of the pixel
  207. ;------------------------------------------------------
  208.      xchg     ah,al
  209.      add      bx,ax
  210.      shr      ax,1
  211.      shr      ax,1
  212.      add      bx,ax
  213.      mov      di,bx           ; move address to di
  214.      ret
  215. ENDP getAddr256
  216.  
  217.       END                     ; End of module
  218.  
  219.  
  220.      END