⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmap.nas

📁 一个免费的汇编语言编译器的源代码
💻 NAS
📖 第 1 页 / 共 3 页
字号:
;; NASM note: this file abuses the section flags in such a way that

;; NASM 0.98.37 broke when this was compiled with:

;; nasm -o tmap.o -f elf -DLINUX tmap.nas



;;-----------------------------------------------------------------------------

;;

;; $Id: tmap.nas,v 1.10 2001/02/24 13:35:21 bpereira Exp $

;;

;; Copyright (C) 1998-2000 by DooM Legacy Team.

;;

;; 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.

;;

;;

;; $Log: tmap.nas,v $

;; Revision 1.10  2001/02/24 13:35:21  bpereira

;; no message

;;

;; Revision 1.9  2001/02/10 15:24:19  hurdler

;; Apply Rob's patch for Linux version

;;

;; Revision 1.8  2000/11/12 09:48:15  bpereira

;; no message

;;

;; Revision 1.7  2000/11/06 20:52:16  bpereira

;; no message

;;

;; Revision 1.6  2000/11/03 11:48:40  hurdler

;; Fix compiling problem under win32 with 3D-Floors and FragglScript (to verify!)

;;

;; Revision 1.5  2000/11/03 03:27:17  stroggonmeth

;; Again with the bug fixing...

;;

;; Revision 1.4  2000/11/02 17:50:10  stroggonmeth

;; Big 3Dfloors & FraggleScript commit!!

;;

;; Revision 1.3  2000/04/24 20:24:38  bpereira

;; no message

;;

;; Revision 1.2  2000/02/27 00:42:11  hurdler

;; fix CR+LF problem

;;

;; Revision 1.1.1.1  2000/02/22 20:32:32  hurdler

;; Initial import into CVS (v1.29 pr3)

;;

;;

;; DESCRIPTION:

;;      assembler optimised rendering code for software mode

;;      draw floor spans, and wall columns.

;;

;;-----------------------------------------------------------------------------





[BITS 32]



%ifdef LINUX

%macro cextern 1

[extern %1]

%endmacro



%macro cglobal 1

[global %1]

%endmacro



%define CODE_SEG .data

%else

%macro cextern 1

%define %1 _%1

[extern %1]

%endmacro



%macro cglobal 1

%define %1 _%1

[global %1]

%endmacro



%define CODE_SEG .text                         

%endif





;; externs

;; columns

cextern dc_x

cextern dc_yl

cextern dc_yh

cextern ylookup

cextern columnofs

cextern dc_source

cextern dc_texturemid

cextern dc_iscale

cextern centery

cextern dc_colormap

cextern dc_transmap

cextern colormaps



;; spans

cextern ds_x1

cextern ds_x2

cextern ds_y

cextern ds_xfrac

cextern ds_yfrac

cextern ds_xstep

cextern ds_ystep

cextern ds_source

cextern ds_colormap

;cextern ds_textureheight



; polygon edge rasterizer

cextern prastertab





;;----------------------------------------------------------------------

;;

;; R_DrawColumn

;;

;; New  optimised version 10-01-1998 by D.Fabrice and P.Boris

;; TO DO: optimise it much farther... should take at most 3 cycles/pix

;;      once it's fixed, add code to patch the offsets so that it

;;      works in every screen width.

;;

;;----------------------------------------------------------------------



[SECTION .data]



;;.align        4

loopcount       dd      0

pixelcount      dd      0

tystep          dd      0



[SECTION CODE_SEG write]



;----------------------------------------------------------------------------

;fixed_t FixedMul (fixed_t a, fixed_t b)

;----------------------------------------------------------------------------

cglobal FixedMul

;       align   16

FixedMul:

        mov     eax,[esp+4]

        imul    dword [esp+8]

        shrd    eax,edx,16

        ret



;----------------------------------------------------------------------------

;fixed_t FixedDiv2 (fixed_t a, fixed_t b);

;----------------------------------------------------------------------------

cglobal FixedDiv2

;       align   16

FixedDiv2:

        mov     eax,[esp+4]

        mov     edx,eax                 ;; these two instructions allow the next

        sar     edx,31                  ;; two to pair, on the Pentium processor.

        shld    edx,eax,16

        sal     eax,16

        idiv    dword [esp+8]

        ret



;----------------------------------------------------------------------------

; void  ASM_PatchRowBytes (int rowbytes);

;----------------------------------------------------------------------------

cglobal ASM_PatchRowBytes

;       align   16

ASM_PatchRowBytes:

        mov     eax,[esp+4]

        mov     [p1+2],eax

        mov     [p2+2],eax

        mov     [p3+2],eax

        mov     [p4+2],eax

        mov     [p5+2],eax

        mov     [p6+2],eax

        mov     [p7+2],eax

        mov     [p8+2],eax

        mov     [p9+2],eax

        mov     [pa+2],eax

        mov     [pb+2],eax

        mov     [pc+2],eax

        mov     [pd+2],eax

        mov     [pe+2],eax

        mov     [pf+2],eax

        mov     [pg+2],eax

        mov     [ph+2],eax

        mov     [pi+2],eax

        mov     [pj+2],eax

        mov     [pk+2],eax

        mov     [pl+2],eax

        mov     [pm+2],eax

        mov     [pn+2],eax

        mov     [po+2],eax

        mov     [pp+2],eax

        mov     [pq+2],eax

        add     eax,eax

        mov     [q1+2],eax

        mov     [q2+2],eax

        mov     [q3+2],eax

        mov     [q4+2],eax

        mov     [q5+2],eax

        mov     [q6+2],eax

        mov     [q7+2],eax

        mov     [q8+2],eax

        ret





;----------------------------------------------------------------------------

; 8bpp column drawer

;----------------------------------------------------------------------------



cglobal R_DrawColumn_8

;       align   16

R_DrawColumn_8:

        push    ebp                     ;; preserve caller's stack frame pointer

        push    esi                     ;; preserve register variables

        push    edi

        push    ebx

;;

;; dest = ylookup[dc_yl] + columnofs[dc_x];

;;

        mov     ebp,[dc_yl]

        mov     ebx,ebp

        mov     edi,[ylookup+ebx*4]

        mov     ebx,[dc_x]

        add     edi,[columnofs+ebx*4]  ;; edi = dest

;;

;; pixelcount = yh - yl + 1

;;

        mov     eax,[dc_yh]

        inc     eax

        sub     eax,ebp                 ;; pixel count

        mov     [pixelcount],eax        ;; save for final pixel

        jle     near vdone                   ;; nothing to scale

;;

;; frac = dc_texturemid - (centery-dc_yl)*fracstep;

;;

        mov     ecx,[dc_iscale]        ;; fracstep

        mov     eax,[centery]

        sub     eax,ebp

        imul    eax,ecx

        mov     edx,[dc_texturemid]

        sub     edx,eax

        mov     ebx,edx

        shr     ebx,16                  ;; frac int.

        and     ebx,0x7f

        shl     edx,16                  ;; y frac up



        mov     ebp,ecx

        shl     ebp,16                  ;; fracstep f. up

        shr     ecx,16                  ;; fracstep i. ->cl

        and     cl,0x7f

        mov     esi,[dc_source]

;;

;; lets rock :) !

;;

        mov     eax,[pixelcount]

        mov     dh,al

        shr     eax,2

        mov     ch,al                   ;; quad count

        mov     eax,[dc_colormap]

        test    dh,0x3

        je      near v4quadloop

;;

;;  do un-even pixel

;;

        test    dh,0x1

        je      two_uneven



        mov     al,[esi+ebx]            ;; prep un-even loops

        add     edx,ebp                 ;; ypos f += ystep f

        adc     bl,cl                   ;; ypos i += ystep i

        mov     dl,[eax]                ;; colormap texel

        and     bl,0x7f                 ;; mask 0-127 texture index

        mov     [edi],dl                ;; output pixel

p1:     add     edi,0x12345678

;;

;;  do two non-quad-aligned pixels

;;

two_uneven:

        test    dh,0x2

        je      f3



        mov     al,[esi+ebx]            ;; fetch source texel

        add     edx,ebp                 ;; ypos f += ystep f

        adc     bl,cl                   ;; ypos i += ystep i

        mov     dl,[eax]                ;; colormap texel

        and     bl,0x7f                 ;; mask 0-127 texture index

        mov     [edi],dl                ;; output pixel

        mov     al,[esi+ebx]

        add     edx,ebp                 ;; fetch source texel

        adc     bl,cl                   ;; ypos f += ystep f

        mov     dl,[eax]                ;; ypos i += ystep i

        and     bl,0x7f                 ;; colormap texel

p2:     add     edi,0x12345678          ;; mask 0-127 texture index

        mov     [edi],dl

p3:     add     edi,0x12345678          ;; output pixel

;;

;;  test if there was at least 4 pixels

;;

f3:

        test    ch,0xff                 ;; test quad count

        je      near vdone

;;

;; ebp : ystep frac. upper 16 bits

;; edx : y     frac. upper 16 bits

;; ebx : y     i.    lower 7 bits,  masked for index

;; ecx : ch = counter, cl = y step i.

;; eax : colormap aligned 256

;; esi : source texture column

;; edi : dest screen

;;

v4quadloop:

        mov     dh,0x7f                 ;; prep mask

align 4

vquadloop:

        mov     al,[esi+ebx]            ;; prep loop

        add     edx,ebp                 ;; ypos f += ystep f

        adc     bl,cl                   ;; ypos i += ystep i

        mov     dl,[eax]                ;; colormap texel

        mov     [edi],dl                ;; output pixel

        and     bl,0x7f                 ;; mask 0-127 texture index



        mov     al,[esi+ebx]            ;; fetch source texel

        add     edx,ebp

        adc     bl,cl

p4:     add     edi,0x12345678

        mov     dl,[eax]

        and     bl,0x7f

        mov     [edi],dl



        mov     al,[esi+ebx]            ;; fetch source texel

        add     edx,ebp

        adc     bl,cl

p5:     add     edi,0x12345678

        mov     dl,[eax]

        and     bl,0x7f

        mov     [edi],dl



        mov     al,[esi+ebx]            ;; fetch source texel

        add     edx,ebp

        adc     bl,cl

p6:     add     edi,0x12345678

        mov     dl,[eax]

        and     bl,0x7f

        mov     [edi],dl



p7:     add     edi,0x12345678



        dec     ch

        jne     vquadloop



vdone:

        pop     ebx                     ;; restore register variables

        pop     edi

        pop     esi

        pop     ebp                     ;; restore caller's stack frame pointer

        ret



;;----------------------------------------------------------------------

;;13-02-98:

;;      R_DrawSkyColumn : same as R_DrawColumn but:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -