123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784 |
- /*
- Copyright (C) 1996-1997 Id Software, Inc.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- //
- // surf8.s
- // x86 assembly-language 8 bpp surface block drawing code.
- //
- #include "asm_i386.h"
- #include "quakeasm.h"
- #include "asm_draw.h"
- #if id386
- .data
- sb_v: .long 0
- .text
- .align 4
- .globl C(R_Surf8Start)
- C(R_Surf8Start):
- //----------------------------------------------------------------------
- // Surface block drawer for mip level 0
- //----------------------------------------------------------------------
- .align 4
- .globl C(R_DrawSurfaceBlock8_mip0)
- C(R_DrawSurfaceBlock8_mip0):
- pushl %ebp // preserve caller's stack frame
- pushl %edi
- pushl %esi // preserve register variables
- pushl %ebx
- // for (v=0 ; v<numvblocks ; v++)
- // {
- movl C(r_lightptr),%ebx
- movl C(r_numvblocks),%eax
- movl %eax,sb_v
- movl C(prowdestbase),%edi
- movl C(pbasesource),%esi
- Lv_loop_mip0:
- // lightleft = lightptr[0];
- // lightright = lightptr[1];
- // lightdelta = (lightleft - lightright) & 0xFFFFF;
- movl (%ebx),%eax // lightleft
- movl 4(%ebx),%edx // lightright
- movl %eax,%ebp
- movl C(r_lightwidth),%ecx
- movl %edx,C(lightright)
- subl %edx,%ebp
- andl $0xFFFFF,%ebp
- leal (%ebx,%ecx,4),%ebx
- // lightptr += lightwidth;
- movl %ebx,C(r_lightptr)
- // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- // 0xF0000000;
- movl 4(%ebx),%ecx // lightptr[1]
- movl (%ebx),%ebx // lightptr[0]
- subl %eax,%ebx
- subl %edx,%ecx
- sarl $4,%ecx
- orl $0xF0000000,%ebp
- sarl $4,%ebx
- movl %ecx,C(lightrightstep)
- subl %ecx,%ebx
- andl $0xFFFFF,%ebx
- orl $0xF0000000,%ebx
- subl %ecx,%ecx // high word must be 0 in loop for addressing
- movl %ebx,C(lightdeltastep)
- subl %ebx,%ebx // high word must be 0 in loop for addressing
- Lblockloop8_mip0:
- movl %ebp,C(lightdelta)
- movb 14(%esi),%cl
- sarl $4,%ebp
- movb %dh,%bh
- movb 15(%esi),%bl
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch0:
- movb 13(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch1:
- movb 12(%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch2:
- movb 11(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch3:
- movb 10(%esi),%cl
- movl %eax,12(%edi)
- movb %dh,%bh
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch4:
- movb 9(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch5:
- movb 8(%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch6:
- movb 7(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch7:
- movb 6(%esi),%cl
- movl %eax,8(%edi)
- movb %dh,%bh
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch8:
- movb 5(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch9:
- movb 4(%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch10:
- movb 3(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch11:
- movb 2(%esi),%cl
- movl %eax,4(%edi)
- movb %dh,%bh
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch12:
- movb 1(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch13:
- movb (%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- movb 0x12345678(%ebx),%ah
- LBPatch14:
- movl C(lightright),%edx
- movb 0x12345678(%ecx),%al
- LBPatch15:
- movl C(lightdelta),%ebp
- movl %eax,(%edi)
- addl C(sourcetstep),%esi
- addl C(surfrowbytes),%edi
- addl C(lightrightstep),%edx
- addl C(lightdeltastep),%ebp
- movl %edx,C(lightright)
- jc Lblockloop8_mip0
- // if (pbasesource >= r_sourcemax)
- // pbasesource -= stepback;
- cmpl C(r_sourcemax),%esi
- jb LSkip_mip0
- subl C(r_stepback),%esi
- LSkip_mip0:
- movl C(r_lightptr),%ebx
- decl sb_v
- jnz Lv_loop_mip0
- popl %ebx // restore register variables
- popl %esi
- popl %edi
- popl %ebp // restore the caller's stack frame
- ret
- //----------------------------------------------------------------------
- // Surface block drawer for mip level 1
- //----------------------------------------------------------------------
- .align 4
- .globl C(R_DrawSurfaceBlock8_mip1)
- C(R_DrawSurfaceBlock8_mip1):
- pushl %ebp // preserve caller's stack frame
- pushl %edi
- pushl %esi // preserve register variables
- pushl %ebx
- // for (v=0 ; v<numvblocks ; v++)
- // {
- movl C(r_lightptr),%ebx
- movl C(r_numvblocks),%eax
- movl %eax,sb_v
- movl C(prowdestbase),%edi
- movl C(pbasesource),%esi
- Lv_loop_mip1:
- // lightleft = lightptr[0];
- // lightright = lightptr[1];
- // lightdelta = (lightleft - lightright) & 0xFFFFF;
- movl (%ebx),%eax // lightleft
- movl 4(%ebx),%edx // lightright
- movl %eax,%ebp
- movl C(r_lightwidth),%ecx
- movl %edx,C(lightright)
- subl %edx,%ebp
- andl $0xFFFFF,%ebp
- leal (%ebx,%ecx,4),%ebx
- // lightptr += lightwidth;
- movl %ebx,C(r_lightptr)
- // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- // 0xF0000000;
- movl 4(%ebx),%ecx // lightptr[1]
- movl (%ebx),%ebx // lightptr[0]
- subl %eax,%ebx
- subl %edx,%ecx
- sarl $3,%ecx
- orl $0x70000000,%ebp
- sarl $3,%ebx
- movl %ecx,C(lightrightstep)
- subl %ecx,%ebx
- andl $0xFFFFF,%ebx
- orl $0xF0000000,%ebx
- subl %ecx,%ecx // high word must be 0 in loop for addressing
- movl %ebx,C(lightdeltastep)
- subl %ebx,%ebx // high word must be 0 in loop for addressing
- Lblockloop8_mip1:
- movl %ebp,C(lightdelta)
- movb 6(%esi),%cl
- sarl $3,%ebp
- movb %dh,%bh
- movb 7(%esi),%bl
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch22:
- movb 5(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch23:
- movb 4(%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch24:
- movb 3(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch25:
- movb 2(%esi),%cl
- movl %eax,4(%edi)
- movb %dh,%bh
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch26:
- movb 1(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch27:
- movb (%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- movb 0x12345678(%ebx),%ah
- LBPatch28:
- movl C(lightright),%edx
- movb 0x12345678(%ecx),%al
- LBPatch29:
- movl C(lightdelta),%ebp
- movl %eax,(%edi)
- movl C(sourcetstep),%eax
- addl %eax,%esi
- movl C(surfrowbytes),%eax
- addl %eax,%edi
- movl C(lightrightstep),%eax
- addl %eax,%edx
- movl C(lightdeltastep),%eax
- addl %eax,%ebp
- movl %edx,C(lightright)
- jc Lblockloop8_mip1
- // if (pbasesource >= r_sourcemax)
- // pbasesource -= stepback;
- cmpl C(r_sourcemax),%esi
- jb LSkip_mip1
- subl C(r_stepback),%esi
- LSkip_mip1:
- movl C(r_lightptr),%ebx
- decl sb_v
- jnz Lv_loop_mip1
- popl %ebx // restore register variables
- popl %esi
- popl %edi
- popl %ebp // restore the caller's stack frame
- ret
- //----------------------------------------------------------------------
- // Surface block drawer for mip level 2
- //----------------------------------------------------------------------
- .align 4
- .globl C(R_DrawSurfaceBlock8_mip2)
- C(R_DrawSurfaceBlock8_mip2):
- pushl %ebp // preserve caller's stack frame
- pushl %edi
- pushl %esi // preserve register variables
- pushl %ebx
- // for (v=0 ; v<numvblocks ; v++)
- // {
- movl C(r_lightptr),%ebx
- movl C(r_numvblocks),%eax
- movl %eax,sb_v
- movl C(prowdestbase),%edi
- movl C(pbasesource),%esi
- Lv_loop_mip2:
- // lightleft = lightptr[0];
- // lightright = lightptr[1];
- // lightdelta = (lightleft - lightright) & 0xFFFFF;
- movl (%ebx),%eax // lightleft
- movl 4(%ebx),%edx // lightright
- movl %eax,%ebp
- movl C(r_lightwidth),%ecx
- movl %edx,C(lightright)
- subl %edx,%ebp
- andl $0xFFFFF,%ebp
- leal (%ebx,%ecx,4),%ebx
- // lightptr += lightwidth;
- movl %ebx,C(r_lightptr)
- // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- // 0xF0000000;
- movl 4(%ebx),%ecx // lightptr[1]
- movl (%ebx),%ebx // lightptr[0]
- subl %eax,%ebx
- subl %edx,%ecx
- sarl $2,%ecx
- orl $0x30000000,%ebp
- sarl $2,%ebx
- movl %ecx,C(lightrightstep)
- subl %ecx,%ebx
- andl $0xFFFFF,%ebx
- orl $0xF0000000,%ebx
- subl %ecx,%ecx // high word must be 0 in loop for addressing
- movl %ebx,C(lightdeltastep)
- subl %ebx,%ebx // high word must be 0 in loop for addressing
- Lblockloop8_mip2:
- movl %ebp,C(lightdelta)
- movb 2(%esi),%cl
- sarl $2,%ebp
- movb %dh,%bh
- movb 3(%esi),%bl
- addl %ebp,%edx
- movb %dh,%ch
- addl %ebp,%edx
- movb 0x12345678(%ebx),%ah
- LBPatch18:
- movb 1(%esi),%bl
- movb 0x12345678(%ecx),%al
- LBPatch19:
- movb (%esi),%cl
- movb %dh,%bh
- addl %ebp,%edx
- rorl $16,%eax
- movb %dh,%ch
- movb 0x12345678(%ebx),%ah
- LBPatch20:
- movl C(lightright),%edx
- movb 0x12345678(%ecx),%al
- LBPatch21:
- movl C(lightdelta),%ebp
- movl %eax,(%edi)
- movl C(sourcetstep),%eax
- addl %eax,%esi
- movl C(surfrowbytes),%eax
- addl %eax,%edi
- movl C(lightrightstep),%eax
- addl %eax,%edx
- movl C(lightdeltastep),%eax
- addl %eax,%ebp
- movl %edx,C(lightright)
- jc Lblockloop8_mip2
- // if (pbasesource >= r_sourcemax)
- // pbasesource -= stepback;
- cmpl C(r_sourcemax),%esi
- jb LSkip_mip2
- subl C(r_stepback),%esi
- LSkip_mip2:
- movl C(r_lightptr),%ebx
- decl sb_v
- jnz Lv_loop_mip2
- popl %ebx // restore register variables
- popl %esi
- popl %edi
- popl %ebp // restore the caller's stack frame
- ret
- //----------------------------------------------------------------------
- // Surface block drawer for mip level 3
- //----------------------------------------------------------------------
- .align 4
- .globl C(R_DrawSurfaceBlock8_mip3)
- C(R_DrawSurfaceBlock8_mip3):
- pushl %ebp // preserve caller's stack frame
- pushl %edi
- pushl %esi // preserve register variables
- pushl %ebx
- // for (v=0 ; v<numvblocks ; v++)
- // {
- movl C(r_lightptr),%ebx
- movl C(r_numvblocks),%eax
- movl %eax,sb_v
- movl C(prowdestbase),%edi
- movl C(pbasesource),%esi
- Lv_loop_mip3:
- // lightleft = lightptr[0];
- // lightright = lightptr[1];
- // lightdelta = (lightleft - lightright) & 0xFFFFF;
- movl (%ebx),%eax // lightleft
- movl 4(%ebx),%edx // lightright
- movl %eax,%ebp
- movl C(r_lightwidth),%ecx
- movl %edx,C(lightright)
- subl %edx,%ebp
- andl $0xFFFFF,%ebp
- leal (%ebx,%ecx,4),%ebx
- movl %ebp,C(lightdelta)
- // lightptr += lightwidth;
- movl %ebx,C(r_lightptr)
- // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- // 0xF0000000;
- movl 4(%ebx),%ecx // lightptr[1]
- movl (%ebx),%ebx // lightptr[0]
- subl %eax,%ebx
- subl %edx,%ecx
- sarl $1,%ecx
- sarl $1,%ebx
- movl %ecx,C(lightrightstep)
- subl %ecx,%ebx
- andl $0xFFFFF,%ebx
- sarl $1,%ebp
- orl $0xF0000000,%ebx
- movl %ebx,C(lightdeltastep)
- subl %ebx,%ebx // high word must be 0 in loop for addressing
- movb 1(%esi),%bl
- subl %ecx,%ecx // high word must be 0 in loop for addressing
- movb %dh,%bh
- movb (%esi),%cl
- addl %ebp,%edx
- movb %dh,%ch
- movb 0x12345678(%ebx),%al
- LBPatch16:
- movl C(lightright),%edx
- movb %al,1(%edi)
- movb 0x12345678(%ecx),%al
- LBPatch17:
- movb %al,(%edi)
- movl C(sourcetstep),%eax
- addl %eax,%esi
- movl C(surfrowbytes),%eax
- addl %eax,%edi
- movl C(lightdeltastep),%eax
- movl C(lightdelta),%ebp
- movb (%esi),%cl
- addl %eax,%ebp
- movl C(lightrightstep),%eax
- sarl $1,%ebp
- addl %eax,%edx
- movb %dh,%bh
- movb 1(%esi),%bl
- addl %ebp,%edx
- movb %dh,%ch
- movb 0x12345678(%ebx),%al
- LBPatch30:
- movl C(sourcetstep),%edx
- movb %al,1(%edi)
- movb 0x12345678(%ecx),%al
- LBPatch31:
- movb %al,(%edi)
- movl C(surfrowbytes),%ebp
- addl %edx,%esi
- addl %ebp,%edi
- // if (pbasesource >= r_sourcemax)
- // pbasesource -= stepback;
- cmpl C(r_sourcemax),%esi
- jb LSkip_mip3
- subl C(r_stepback),%esi
- LSkip_mip3:
- movl C(r_lightptr),%ebx
- decl sb_v
- jnz Lv_loop_mip3
- popl %ebx // restore register variables
- popl %esi
- popl %edi
- popl %ebp // restore the caller's stack frame
- ret
- .globl C(R_Surf8End)
- C(R_Surf8End):
- //----------------------------------------------------------------------
- // Code patching routines
- //----------------------------------------------------------------------
- .data
- .align 4
- LPatchTable8:
- .long LBPatch0-4
- .long LBPatch1-4
- .long LBPatch2-4
- .long LBPatch3-4
- .long LBPatch4-4
- .long LBPatch5-4
- .long LBPatch6-4
- .long LBPatch7-4
- .long LBPatch8-4
- .long LBPatch9-4
- .long LBPatch10-4
- .long LBPatch11-4
- .long LBPatch12-4
- .long LBPatch13-4
- .long LBPatch14-4
- .long LBPatch15-4
- .long LBPatch16-4
- .long LBPatch17-4
- .long LBPatch18-4
- .long LBPatch19-4
- .long LBPatch20-4
- .long LBPatch21-4
- .long LBPatch22-4
- .long LBPatch23-4
- .long LBPatch24-4
- .long LBPatch25-4
- .long LBPatch26-4
- .long LBPatch27-4
- .long LBPatch28-4
- .long LBPatch29-4
- .long LBPatch30-4
- .long LBPatch31-4
- .text
- .align 4
- .globl C(R_Surf8Patch)
- C(R_Surf8Patch):
- pushl %ebx
- movl C(colormap),%eax
- movl $LPatchTable8,%ebx
- movl $32,%ecx
- LPatchLoop8:
- movl (%ebx),%edx
- addl $4,%ebx
- movl %eax,(%edx)
- decl %ecx
- jnz LPatchLoop8
- popl %ebx
- ret
- #endif // id386
|