123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772 |
- .386P
- .model FLAT
- ;
- ; surf8.s
- ; x86 assembly-language 8 bpp surface block drawing code.
- ;
- include qasm.inc
- if id386
- _DATA SEGMENT
- sb_v dd 0
- _DATA ENDS
- _TEXT SEGMENT
- align 4
- public _R_Surf8Start
- _R_Surf8Start:
- ;----------------------------------------------------------------------
- ; Surface block drawer for mip level 0
- ;----------------------------------------------------------------------
- align 4
- public _R_DrawSurfaceBlock8_mip0
- _R_DrawSurfaceBlock8_mip0:
- push ebp ; preserve caller's stack frame
- push edi
- push esi ; preserve register variables
- push ebx
- ; for (v=0 ; v<numvblocks ; v++)
- ; {
- mov ebx,ds:dword ptr[_r_lightptr]
- mov eax,ds:dword ptr[_r_numvblocks]
- mov ds:dword ptr[sb_v],eax
- mov edi,ds:dword ptr[_prowdestbase]
- mov esi,ds:dword ptr[_pbasesource]
- Lv_loop_mip0:
- ; lightleft = lightptr[0];
- ; lightright = lightptr[1];
- ; lightdelta = (lightleft - lightright) & 0xFFFFF;
- mov eax,ds:dword ptr[ebx] ; lightleft
- mov edx,ds:dword ptr[4+ebx] ; lightright
- mov ebp,eax
- mov ecx,ds:dword ptr[_r_lightwidth]
- mov ds:dword ptr[_lightright],edx
- sub ebp,edx
- and ebp,0FFFFFh
- lea ebx,ds:dword ptr[ebx+ecx*4]
- ; lightptr += lightwidth;
- mov ds:dword ptr[_r_lightptr],ebx
- ; lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- ; lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- ; lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- ; 0xF0000000;
- mov ecx,ds:dword ptr[4+ebx] ; lightptr[1]
- mov ebx,ds:dword ptr[ebx] ; lightptr[0]
- sub ebx,eax
- sub ecx,edx
- sar ecx,4
- or ebp,0F0000000h
- sar ebx,4
- mov ds:dword ptr[_lightrightstep],ecx
- sub ebx,ecx
- and ebx,0FFFFFh
- or ebx,0F0000000h
- sub ecx,ecx ; high word must be 0 in loop for addressing
- mov ds:dword ptr[_lightdeltastep],ebx
- sub ebx,ebx ; high word must be 0 in loop for addressing
- Lblockloop8_mip0:
- mov ds:dword ptr[_lightdelta],ebp
- mov cl,ds:byte ptr[14+esi]
- sar ebp,4
- mov bh,dh
- mov bl,ds:byte ptr[15+esi]
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch0:
- mov bl,ds:byte ptr[13+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch1:
- mov cl,ds:byte ptr[12+esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch2:
- mov bl,ds:byte ptr[11+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch3:
- mov cl,ds:byte ptr[10+esi]
- mov ds:dword ptr[12+edi],eax
- mov bh,dh
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch4:
- mov bl,ds:byte ptr[9+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch5:
- mov cl,ds:byte ptr[8+esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch6:
- mov bl,ds:byte ptr[7+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch7:
- mov cl,ds:byte ptr[6+esi]
- mov ds:dword ptr[8+edi],eax
- mov bh,dh
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch8:
- mov bl,ds:byte ptr[5+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch9:
- mov cl,ds:byte ptr[4+esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch10:
- mov bl,ds:byte ptr[3+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch11:
- mov cl,ds:byte ptr[2+esi]
- mov ds:dword ptr[4+edi],eax
- mov bh,dh
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch12:
- mov bl,ds:byte ptr[1+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch13:
- mov cl,ds:byte ptr[esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch14:
- mov edx,ds:dword ptr[_lightright]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch15:
- mov ebp,ds:dword ptr[_lightdelta]
- mov ds:dword ptr[edi],eax
- add esi,ds:dword ptr[_sourcetstep]
- add edi,ds:dword ptr[_surfrowbytes]
- add edx,ds:dword ptr[_lightrightstep]
- add ebp,ds:dword ptr[_lightdeltastep]
- mov ds:dword ptr[_lightright],edx
- jc Lblockloop8_mip0
- ; if (pbasesource >= r_sourcemax)
- ; pbasesource -= stepback;
- cmp esi,ds:dword ptr[_r_sourcemax]
- jb LSkip_mip0
- sub esi,ds:dword ptr[_r_stepback]
- LSkip_mip0:
- mov ebx,ds:dword ptr[_r_lightptr]
- dec ds:dword ptr[sb_v]
- jnz Lv_loop_mip0
- pop ebx ; restore register variables
- pop esi
- pop edi
- pop ebp ; restore the caller's stack frame
- ret
- ;----------------------------------------------------------------------
- ; Surface block drawer for mip level 1
- ;----------------------------------------------------------------------
- align 4
- public _R_DrawSurfaceBlock8_mip1
- _R_DrawSurfaceBlock8_mip1:
- push ebp ; preserve caller's stack frame
- push edi
- push esi ; preserve register variables
- push ebx
- ; for (v=0 ; v<numvblocks ; v++)
- ; {
- mov ebx,ds:dword ptr[_r_lightptr]
- mov eax,ds:dword ptr[_r_numvblocks]
- mov ds:dword ptr[sb_v],eax
- mov edi,ds:dword ptr[_prowdestbase]
- mov esi,ds:dword ptr[_pbasesource]
- Lv_loop_mip1:
- ; lightleft = lightptr[0];
- ; lightright = lightptr[1];
- ; lightdelta = (lightleft - lightright) & 0xFFFFF;
- mov eax,ds:dword ptr[ebx] ; lightleft
- mov edx,ds:dword ptr[4+ebx] ; lightright
- mov ebp,eax
- mov ecx,ds:dword ptr[_r_lightwidth]
- mov ds:dword ptr[_lightright],edx
- sub ebp,edx
- and ebp,0FFFFFh
- lea ebx,ds:dword ptr[ebx+ecx*4]
- ; lightptr += lightwidth;
- mov ds:dword ptr[_r_lightptr],ebx
- ; lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- ; lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- ; lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- ; 0xF0000000;
- mov ecx,ds:dword ptr[4+ebx] ; lightptr[1]
- mov ebx,ds:dword ptr[ebx] ; lightptr[0]
- sub ebx,eax
- sub ecx,edx
- sar ecx,3
- or ebp,070000000h
- sar ebx,3
- mov ds:dword ptr[_lightrightstep],ecx
- sub ebx,ecx
- and ebx,0FFFFFh
- or ebx,0F0000000h
- sub ecx,ecx ; high word must be 0 in loop for addressing
- mov ds:dword ptr[_lightdeltastep],ebx
- sub ebx,ebx ; high word must be 0 in loop for addressing
- Lblockloop8_mip1:
- mov ds:dword ptr[_lightdelta],ebp
- mov cl,ds:byte ptr[6+esi]
- sar ebp,3
- mov bh,dh
- mov bl,ds:byte ptr[7+esi]
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch22:
- mov bl,ds:byte ptr[5+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch23:
- mov cl,ds:byte ptr[4+esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch24:
- mov bl,ds:byte ptr[3+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch25:
- mov cl,ds:byte ptr[2+esi]
- mov ds:dword ptr[4+edi],eax
- mov bh,dh
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch26:
- mov bl,ds:byte ptr[1+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch27:
- mov cl,ds:byte ptr[esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch28:
- mov edx,ds:dword ptr[_lightright]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch29:
- mov ebp,ds:dword ptr[_lightdelta]
- mov ds:dword ptr[edi],eax
- mov eax,ds:dword ptr[_sourcetstep]
- add esi,eax
- mov eax,ds:dword ptr[_surfrowbytes]
- add edi,eax
- mov eax,ds:dword ptr[_lightrightstep]
- add edx,eax
- mov eax,ds:dword ptr[_lightdeltastep]
- add ebp,eax
- mov ds:dword ptr[_lightright],edx
- jc Lblockloop8_mip1
- ; if (pbasesource >= r_sourcemax)
- ; pbasesource -= stepback;
- cmp esi,ds:dword ptr[_r_sourcemax]
- jb LSkip_mip1
- sub esi,ds:dword ptr[_r_stepback]
- LSkip_mip1:
- mov ebx,ds:dword ptr[_r_lightptr]
- dec ds:dword ptr[sb_v]
- jnz Lv_loop_mip1
- pop ebx ; restore register variables
- pop esi
- pop edi
- pop ebp ; restore the caller's stack frame
- ret
- ;----------------------------------------------------------------------
- ; Surface block drawer for mip level 2
- ;----------------------------------------------------------------------
- align 4
- public _R_DrawSurfaceBlock8_mip2
- _R_DrawSurfaceBlock8_mip2:
- push ebp ; preserve caller's stack frame
- push edi
- push esi ; preserve register variables
- push ebx
- ; for (v=0 ; v<numvblocks ; v++)
- ; {
- mov ebx,ds:dword ptr[_r_lightptr]
- mov eax,ds:dword ptr[_r_numvblocks]
- mov ds:dword ptr[sb_v],eax
- mov edi,ds:dword ptr[_prowdestbase]
- mov esi,ds:dword ptr[_pbasesource]
- Lv_loop_mip2:
- ; lightleft = lightptr[0];
- ; lightright = lightptr[1];
- ; lightdelta = (lightleft - lightright) & 0xFFFFF;
- mov eax,ds:dword ptr[ebx] ; lightleft
- mov edx,ds:dword ptr[4+ebx] ; lightright
- mov ebp,eax
- mov ecx,ds:dword ptr[_r_lightwidth]
- mov ds:dword ptr[_lightright],edx
- sub ebp,edx
- and ebp,0FFFFFh
- lea ebx,ds:dword ptr[ebx+ecx*4]
- ; lightptr += lightwidth;
- mov ds:dword ptr[_r_lightptr],ebx
- ; lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- ; lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- ; lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- ; 0xF0000000;
- mov ecx,ds:dword ptr[4+ebx] ; lightptr[1]
- mov ebx,ds:dword ptr[ebx] ; lightptr[0]
- sub ebx,eax
- sub ecx,edx
- sar ecx,2
- or ebp,030000000h
- sar ebx,2
- mov ds:dword ptr[_lightrightstep],ecx
- sub ebx,ecx
- and ebx,0FFFFFh
- or ebx,0F0000000h
- sub ecx,ecx ; high word must be 0 in loop for addressing
- mov ds:dword ptr[_lightdeltastep],ebx
- sub ebx,ebx ; high word must be 0 in loop for addressing
- Lblockloop8_mip2:
- mov ds:dword ptr[_lightdelta],ebp
- mov cl,ds:byte ptr[2+esi]
- sar ebp,2
- mov bh,dh
- mov bl,ds:byte ptr[3+esi]
- add edx,ebp
- mov ch,dh
- add edx,ebp
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch18:
- mov bl,ds:byte ptr[1+esi]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch19:
- mov cl,ds:byte ptr[esi]
- mov bh,dh
- add edx,ebp
- ror eax,16
- mov ch,dh
- mov ah,ds:byte ptr[12345678h+ebx]
- LBPatch20:
- mov edx,ds:dword ptr[_lightright]
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch21:
- mov ebp,ds:dword ptr[_lightdelta]
- mov ds:dword ptr[edi],eax
- mov eax,ds:dword ptr[_sourcetstep]
- add esi,eax
- mov eax,ds:dword ptr[_surfrowbytes]
- add edi,eax
- mov eax,ds:dword ptr[_lightrightstep]
- add edx,eax
- mov eax,ds:dword ptr[_lightdeltastep]
- add ebp,eax
- mov ds:dword ptr[_lightright],edx
- jc Lblockloop8_mip2
- ; if (pbasesource >= r_sourcemax)
- ; pbasesource -= stepback;
- cmp esi,ds:dword ptr[_r_sourcemax]
- jb LSkip_mip2
- sub esi,ds:dword ptr[_r_stepback]
- LSkip_mip2:
- mov ebx,ds:dword ptr[_r_lightptr]
- dec ds:dword ptr[sb_v]
- jnz Lv_loop_mip2
- pop ebx ; restore register variables
- pop esi
- pop edi
- pop ebp ; restore the caller's stack frame
- ret
- ;----------------------------------------------------------------------
- ; Surface block drawer for mip level 3
- ;----------------------------------------------------------------------
- align 4
- public _R_DrawSurfaceBlock8_mip3
- _R_DrawSurfaceBlock8_mip3:
- push ebp ; preserve caller's stack frame
- push edi
- push esi ; preserve register variables
- push ebx
- ; for (v=0 ; v<numvblocks ; v++)
- ; {
- mov ebx,ds:dword ptr[_r_lightptr]
- mov eax,ds:dword ptr[_r_numvblocks]
- mov ds:dword ptr[sb_v],eax
- mov edi,ds:dword ptr[_prowdestbase]
- mov esi,ds:dword ptr[_pbasesource]
- Lv_loop_mip3:
- ; lightleft = lightptr[0];
- ; lightright = lightptr[1];
- ; lightdelta = (lightleft - lightright) & 0xFFFFF;
- mov eax,ds:dword ptr[ebx] ; lightleft
- mov edx,ds:dword ptr[4+ebx] ; lightright
- mov ebp,eax
- mov ecx,ds:dword ptr[_r_lightwidth]
- mov ds:dword ptr[_lightright],edx
- sub ebp,edx
- and ebp,0FFFFFh
- lea ebx,ds:dword ptr[ebx+ecx*4]
- mov ds:dword ptr[_lightdelta],ebp
- ; lightptr += lightwidth;
- mov ds:dword ptr[_r_lightptr],ebx
- ; lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
- ; lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
- ; lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
- ; 0xF0000000;
- mov ecx,ds:dword ptr[4+ebx] ; lightptr[1]
- mov ebx,ds:dword ptr[ebx] ; lightptr[0]
- sub ebx,eax
- sub ecx,edx
- sar ecx,1
- sar ebx,1
- mov ds:dword ptr[_lightrightstep],ecx
- sub ebx,ecx
- and ebx,0FFFFFh
- sar ebp,1
- or ebx,0F0000000h
- mov ds:dword ptr[_lightdeltastep],ebx
- sub ebx,ebx ; high word must be 0 in loop for addressing
- mov bl,ds:byte ptr[1+esi]
- sub ecx,ecx ; high word must be 0 in loop for addressing
- mov bh,dh
- mov cl,ds:byte ptr[esi]
- add edx,ebp
- mov ch,dh
- mov al,ds:byte ptr[12345678h+ebx]
- LBPatch16:
- mov edx,ds:dword ptr[_lightright]
- mov ds:byte ptr[1+edi],al
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch17:
- mov ds:byte ptr[edi],al
- mov eax,ds:dword ptr[_sourcetstep]
- add esi,eax
- mov eax,ds:dword ptr[_surfrowbytes]
- add edi,eax
- mov eax,ds:dword ptr[_lightdeltastep]
- mov ebp,ds:dword ptr[_lightdelta]
- mov cl,ds:byte ptr[esi]
- add ebp,eax
- mov eax,ds:dword ptr[_lightrightstep]
- sar ebp,1
- add edx,eax
- mov bh,dh
- mov bl,ds:byte ptr[1+esi]
- add edx,ebp
- mov ch,dh
- mov al,ds:byte ptr[12345678h+ebx]
- LBPatch30:
- mov edx,ds:dword ptr[_sourcetstep]
- mov ds:byte ptr[1+edi],al
- mov al,ds:byte ptr[12345678h+ecx]
- LBPatch31:
- mov ds:byte ptr[edi],al
- mov ebp,ds:dword ptr[_surfrowbytes]
- add esi,edx
- add edi,ebp
- ; if (pbasesource >= r_sourcemax)
- ; pbasesource -= stepback;
- cmp esi,ds:dword ptr[_r_sourcemax]
- jb LSkip_mip3
- sub esi,ds:dword ptr[_r_stepback]
- LSkip_mip3:
- mov ebx,ds:dword ptr[_r_lightptr]
- dec ds:dword ptr[sb_v]
- jnz Lv_loop_mip3
- pop ebx ; restore register variables
- pop esi
- pop edi
- pop ebp ; restore the caller's stack frame
- ret
- public _R_Surf8End
- _R_Surf8End:
- ;----------------------------------------------------------------------
- ; Code patching routines
- ;----------------------------------------------------------------------
- _TEXT ENDS
- _DATA SEGMENT
- align 4
- LPatchTable8:
- dd LBPatch0-4
- dd LBPatch1-4
- dd LBPatch2-4
- dd LBPatch3-4
- dd LBPatch4-4
- dd LBPatch5-4
- dd LBPatch6-4
- dd LBPatch7-4
- dd LBPatch8-4
- dd LBPatch9-4
- dd LBPatch10-4
- dd LBPatch11-4
- dd LBPatch12-4
- dd LBPatch13-4
- dd LBPatch14-4
- dd LBPatch15-4
- dd LBPatch16-4
- dd LBPatch17-4
- dd LBPatch18-4
- dd LBPatch19-4
- dd LBPatch20-4
- dd LBPatch21-4
- dd LBPatch22-4
- dd LBPatch23-4
- dd LBPatch24-4
- dd LBPatch25-4
- dd LBPatch26-4
- dd LBPatch27-4
- dd LBPatch28-4
- dd LBPatch29-4
- dd LBPatch30-4
- dd LBPatch31-4
- _DATA ENDS
- _TEXT SEGMENT
- align 4
- public _R_Surf8Patch
- _R_Surf8Patch:
- push ebx
- mov eax,ds:dword ptr[_colormap]
- mov ebx,offset LPatchTable8
- mov ecx,32
- LPatchLoop8:
- mov edx,ds:dword ptr[ebx]
- add ebx,4
- mov ds:dword ptr[edx],eax
- dec ecx
- jnz LPatchLoop8
- pop ebx
- ret
- _TEXT ENDS
- endif ;id386
- END
|