home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 2d / lbitblt.asm < prev    next >
Assembly Source File  |  1998-06-08  |  9KB  |  447 lines

  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/2d/rcs/lbitblt.asm $
  13. ; $Revision: 1.7 $
  14. ; $Author: mike $
  15. ; $Date: 1994/08/12 17:38:28 $
  16. ; Bitblt from linear to linear
  17. ; $Log: lbitblt.asm $
  18. ; Revision 1.7  1994/08/12  17:38:28  mike
  19. ; Fix bug.
  20. ; Revision 1.6  1994/08/11  17:59:33  mike
  21. ; Assembler versions for 3 rotations of merge functions.
  22. ; Revision 1.5  1994/01/22  14:35:16  john
  23. ; Added transparency as color index 255.
  24. ; Revision 1.4  1994/01/18  21:42:41  john
  25. ; unrolled loops in gr_merge_textures...
  26. ; Revision 1.3  1994/01/18  10:56:04  john
  27. ; Added code to merge two ttextures.
  28. ; Revision 1.2  1993/12/28  12:07:26  john
  29. ; initial version
  30. ; Revision 1.1  1993/12/22  11:05:46  john
  31. ; Initial revision
  32.  
  33.  
  34.  
  35. .386
  36.     option    oldstructs
  37.  
  38.     .nolist
  39.     include    types.inc
  40.     include    psmacros.inc
  41.     include gr.inc
  42.     .list
  43.  
  44.     assume    cs:_TEXT, ds:_DATA
  45.  
  46. _DATA    segment    dword public USE32 'DATA'
  47.  
  48. rcsid    db    "$Id: lbitblt.asm 1.7 1994/08/12 17:38:28 mike Exp $"
  49.     align    4
  50.  
  51.  
  52.     JumpTable    dd    RowAligned0, RowAligned1, RowAligned2, RowAligned3
  53.  
  54. row_count    dd    ?
  55.  
  56. _DATA    ends
  57.  
  58.  
  59. _TEXT    segment    dword public USE32 'CODE'
  60.  
  61. ; C-calling:
  62. ; void gr_lbitblt( grs_bitmap * source, grs_bitmap * dest, int height, int width )
  63.  
  64. PUBLIC    gr_lbitblt_
  65.  
  66. gr_lbitblt_:
  67.  
  68.     ; EAX = grs_bitmap * source
  69.     ; EDX = grs_bitmap * dest
  70.     ; EBX = height
  71.     ; ECX = width
  72.  
  73.     push    esi
  74.     push    edi
  75.     push    ebp
  76.  
  77.     dec    ebx
  78.     js    Done
  79.  
  80.     mov    esi, [eax].bm_data
  81.     mov    edi, [edx].bm_data
  82.  
  83.     movzx    eax, [eax].bm_rowsize
  84.     sub    eax, ecx
  85.  
  86.     movzx    edx, [edx].bm_rowsize
  87.     sub    edx, ecx
  88.  
  89.     ; Can use ebp, eax, edx, ecx
  90.     mov    ebp, ecx
  91.     cmp    ebp, 16
  92.     jb    RowAligned0        ; If not 16 pixels wide, don't worry about alignment
  93.  
  94.     mov    ecx, edi
  95.     and    ecx, 011b
  96.     jmp     NEAR32 PTR JumpTable[ecx*4]
  97.  
  98. RowAligned0:
  99. NextRowAligned0:    
  100.     mov    ecx, ebp
  101.     shr    ecx, 2
  102.     rep     movsd
  103.     mov    ecx, ebp
  104.     and    ecx, 11b
  105.     rep    movsb
  106.  
  107.     add    esi, eax
  108.     add    edi, edx
  109.     dec    ebx
  110.     jns    NextRowAligned0
  111.  
  112.     pop    ebp
  113.     pop    edi
  114.     pop    esi
  115.     ret
  116.  
  117. RowAligned1:
  118.     sub    ebp, 3
  119.  
  120. NextRowAligned1:
  121.     movsw    
  122.     movsb    
  123.     mov    ecx, ebp
  124.     shr    ecx, 2
  125.     rep     movsd
  126.     mov    ecx, ebp
  127.     and    ecx, 11b
  128.     rep    movsb
  129.  
  130.     add    esi, eax
  131.     add    edi, edx
  132.     dec    ebx
  133.     jns    NextRowAligned1
  134.  
  135.     pop    ebp
  136.     pop    edi
  137.     pop    esi
  138.     ret
  139.  
  140. RowAligned2:
  141.     sub    ebp, 2
  142. NextRowAligned2:
  143.     movsw
  144.     mov    ecx, ebp
  145.     shr    ecx, 2
  146.     rep     movsd
  147.     mov    ecx, ebp
  148.     and    ecx, 11b
  149.     rep    movsb
  150.  
  151.     add    esi, eax
  152.     add    edi, edx
  153.     dec    ebx
  154.     jns    NextRowAligned2
  155.  
  156.     pop    ebp
  157.     pop    edi
  158.     pop    esi
  159.     ret
  160.  
  161. RowAligned3:
  162.     dec    ebp
  163. NextRowAligned3:
  164.     movsb
  165.     mov    ecx, ebp
  166.     shr    ecx, 2
  167.     rep     movsd
  168.     mov    ecx, ebp
  169.     and    ecx, 11b
  170.     rep    movsb
  171.  
  172.     add    esi, eax
  173.     add    edi, edx
  174.     dec    ebx
  175.     jns    NextRowAligned3
  176.  
  177. Done:    pop    ebp
  178.     pop    edi
  179.     pop    esi
  180.     ret
  181.  
  182.  
  183. ; C-calling:
  184. ; void gr_merge_textures( ubyte * lower, ubyte * upper, ubyte * dest )
  185.  
  186. PUBLIC    gr_merge_textures_, gr_merge_textures_1_, gr_merge_textures_2_, gr_merge_textures_3_
  187.  
  188. ; case 1:
  189. ;    // 
  190. ;    for (y=0; y<64; y++ )
  191. ;       for (x=0; x<64; x++ )   {
  192. ;          c = top_data[ 64*x+(63-y) ];      
  193. ;          if (c==255)
  194. ;             c = bottom_data[ 64*y+x ];
  195. ;          *dest_data++ = c;
  196. ;       }
  197. ;    break;
  198. ; case 2:
  199. ;    // Normal
  200. ;    for (y=0; y<64; y++ )
  201. ;       for (x=0; x<64; x++ )   {
  202. ;          c = top_data[ 64*(63-y)+(63-x) ];
  203. ;          if (c==255)
  204. ;             c = bottom_data[ 64*y+x ];
  205. ;          *dest_data++ = c;
  206. ;       }
  207. ;    break;
  208. ; case 3:
  209. ;    // Normal
  210. ;    for (y=0; y<64; y++ )
  211. ;       for (x=0; x<64; x++ )   {
  212. ;          c = top_data[ 64*(63-x)+y  ];
  213. ;          if (c==255)
  214. ;             c = bottom_data[ 64*y+x ];
  215. ;          *dest_data++ = c;
  216. ;       }
  217. ;    break;
  218. gr_merge_textures_:
  219.  
  220.     ; EAX = lower data
  221.     ; EDX = upper data
  222.     ; EBX = dest data
  223.  
  224.     push    ebp
  225.     push    edi
  226.     push    ecx
  227.     push    esi
  228.  
  229.     mov    ebp, edx
  230.     mov    edi, ebx
  231.     mov    bl, 255
  232.     mov    bh, bl
  233.     and    ebx, 0ffffh
  234.     and    edx, 0ffffh
  235.     mov    esi, eax
  236.     mov    ecx, (64*64)/2
  237.  
  238.     jmp    gmt1
  239.  
  240. second_must_be_not_trans:
  241.     mov    ah, dh
  242.     mov    [edi],ax
  243.     add    edi,2
  244.     dec    ecx
  245.     je    donegmt
  246.  
  247. gmt1:    mov    dx, [ebp]
  248.     add     ebp, 2
  249.     cmp    edx, ebx
  250.     jne    not_transparent
  251.  
  252. ; both transparent
  253.     movsw
  254.     dec    ecx
  255.     jne    gmt1
  256.     jmp    donegmt
  257.  
  258. ; DH OR DL ARE INVISIBLE
  259. not_transparent:
  260.     mov    ax,[esi]
  261.     add    esi,2
  262.         
  263.     cmp    dl, bl
  264.     je    second_must_be_not_trans
  265.     mov    al, dl
  266.     cmp    dh, bh
  267.     je    @f
  268.     mov    ah, dh
  269. @@:    mov    [edi],ax
  270.     add    edi,2
  271.     dec    ecx
  272.     jne    gmt1
  273.  
  274. donegmt:
  275.  
  276.     pop    esi
  277.     pop    ecx    
  278.     pop    edi
  279.     pop    ebp
  280.     ret
  281.  
  282. ; -----------------------------------------------------------------------------------------
  283. ; case 1, normal in x, flip in y
  284. gr_merge_textures_1_:
  285.  
  286. ; eax = background data
  287. ; edx = foreground data
  288. ; ebx = destination address
  289.  
  290.     push    ebp
  291.     push    edi
  292.     push    ecx
  293.     push    esi
  294.     push    ebx
  295.  
  296.     mov    ch, 255    ; transparent color, stick in a register, is this faster?
  297.  
  298.     mov    esi, 63    ; esi will be the offset to the current pixel
  299.     mov    row_count, esi
  300.  
  301.     mov    ebp, 64    ; do for 64 pixels
  302.  
  303.     align    4
  304. gmt1_1:    mov    cl, [edx + esi]    ; get foreground pixel
  305.     add     esi, 64    ; point at next row
  306.     cmp    cl, ch    ; see if transparent
  307.     jne    not_transparent_1    ; dl contains a solid color, just write it
  308.  
  309.     mov    cl,[eax]    ; get background pixel
  310.  
  311. not_transparent_1:    mov    [ebx], cl    ; write pixel
  312.     inc    ebx    ; point at next destination address
  313.     inc    eax
  314.  
  315.     dec    ebp    ; see if done a whole row
  316.     jne    gmt1_1    ; no, so do next pixel
  317.  
  318.     mov    ebp, 64    ; do for 64 pixels
  319.  
  320.     dec    row_count    ; advance to next row
  321.     mov    esi, row_count    ; doing next row, get offset, DANGER: DOESN'T SET FLAGS, BEWARE ON 68000, POWERPC!!
  322.     jns    gmt1_1    ; no (going down to 0)
  323.  
  324.     pop    ebx
  325.     pop    esi
  326.     pop    ecx    
  327.     pop    edi
  328.     pop    ebp
  329.     ret
  330.  
  331. ; -----------------------------------------------------------------------------------------
  332. ; case 1, normal in x, flip in y
  333. gr_merge_textures_2_:
  334.  
  335. ; eax = background data
  336. ; edx = foreground data
  337. ; ebx = destination address
  338.  
  339.     push    ebp
  340.     push    edi
  341.     push    ecx
  342.     push    esi
  343.     push    ebx
  344.  
  345.     mov    ch, 255    ; transparent color, stick in a register, is this faster?
  346.  
  347.     mov    esi, 63 + 64*63    ; esi will be the offset to the current pixel
  348.  
  349.     align    4
  350. gmt1_2:    mov    cl, [edx + esi]    ; get foreground pixel
  351.     cmp    cl, ch    ; see if transparent
  352.     jne    not_transparent_2    ; dl contains a solid color, just write it
  353.  
  354.     mov    cl,[eax]    ; get background pixel
  355.  
  356. not_transparent_2:    mov    [ebx], cl    ; write pixel
  357.     inc    ebx    ; point at next destination address
  358.     inc    eax
  359.  
  360.     dec    esi    ; advance to next row
  361.     jns    gmt1_2    ; no (going down to 0)
  362.  
  363.     pop    ebx
  364.     pop    esi
  365.     pop    ecx    
  366.     pop    edi
  367.     pop    ebp
  368.     ret
  369.  
  370. ; -----------------------------------------------------------------------------------------
  371. ; case 1, normal in x, flip in y
  372. gr_merge_textures_3_:
  373.  
  374. ; eax = background data
  375. ; edx = foreground data
  376. ; ebx = destination address
  377.  
  378.     push    ebp
  379.     push    edi
  380.     push    ecx
  381.     push    esi
  382.     push    ebx
  383.  
  384.     mov    ch, 255    ; transparent color, stick in a register, is this faster?
  385.  
  386.     mov    esi, 64*63    ; esi will be the offset to the current pixel
  387.     mov    row_count, 64
  388.  
  389.     mov    ebp, 32    ; do for 64 pixels (2x loop)
  390.  
  391. ; first copy of loop
  392.     align    4
  393. gmt1_3:    mov    cl, [edx + esi]    ; get foreground pixel
  394.     sub     esi, 64    ; point at next row
  395.     cmp    cl, ch    ; see if transparent
  396.     jne    not_transparent_3    ; dl contains a solid color, just write it
  397.  
  398.     mov    cl,[eax]    ; get background pixel
  399.  
  400. not_transparent_3:    inc    eax
  401.     mov    [ebx], cl    ; write pixel
  402.     inc    ebx    ; point at next destination address
  403.  
  404. ; second copy of loop
  405.     mov    cl, [edx + esi]    ; get foreground pixel
  406.     sub     esi, 64    ; point at next row
  407.     cmp    cl, ch    ; see if transparent
  408.     jne    nt_3a    ; dl contains a solid color, just write it
  409.  
  410.     mov    cl,[eax]    ; get background pixel
  411.  
  412. nt_3a:    inc    eax
  413.     mov    [ebx], cl    ; write pixel
  414.     inc    ebx    ; point at next destination address
  415.  
  416.     dec    ebp    ; see if done a whole row
  417.     jne    gmt1_3    ; no, so do next pixel
  418.  
  419.     mov    ebp, 32    ; do for 64 pixels
  420.  
  421.     add    esi, 64*64+1    ; doing next row, get offset, DANGER: DOESN'T SET FLAGS, BEWARE ON 68000, POWERPC!!
  422.  
  423.     dec    row_count    ; advance to next row
  424.     jne    gmt1_3    ; no (going down to 0)
  425.  
  426.     pop    ebx
  427.     pop    esi
  428.     pop    ecx    
  429.     pop    edi
  430.     pop    ebp
  431.     ret
  432.  
  433. _TEXT    ends
  434.  
  435.     end
  436.  
  437.