📄 tmap.nas
字号:
sub edx,eax
mov ebx,edx
shr ebx,16 ;; frac int.
and ebx,byte +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,[colormaps]
test dh,3
je sh4quadloop
;;
;; do un-even pixel
;;
test dh,0x1
je shf2
mov ah,[esi+ebx] ;; fetch texel : colormap number
add edx,ebp
adc bl,cl
mov al,[edi] ;; fetch dest : index into colormap
and bl,0x7f
mov dl,[eax]
mov [edi],dl
pl: add edi,0x12345678
;;
;; do two non-quad-aligned pixels
;;
shf2:
test dh,0x2
je shf3
mov ah,[esi+ebx] ;; fetch texel : colormap number
add edx,ebp
adc bl,cl
mov al,[edi] ;; fetch dest : index into colormap
and bl,0x7f
mov dl,[eax]
mov [edi],dl
pm: add edi,0x12345678
mov ah,[esi+ebx] ;; fetch texel : colormap number
add edx,ebp
adc bl,cl
mov al,[edi] ;; fetch dest : index into colormap
and bl,0x7f
mov dl,[eax]
mov [edi],dl
pn: add edi,0x12345678
;;
;; test if there was at least 4 pixels
;;
shf3:
test ch,0xff ;; test quad count
je near shdone
;;
;; ebp : ystep frac. upper 24 bits
;; edx : y frac. upper 24 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
;;
sh4quadloop:
mov dh,0x7f ;; prep mask
mov ah,[esi+ebx] ;; fetch texel : colormap number
mov [tystep],ebp
po: add edi,0x12345678
mov al,[edi] ;; fetch dest : index into colormap
pp: sub edi,0x12345678
mov ebp,edi
pq: sub edi,0x12345678
jmp short shinloop
align 4
shquadloop:
add edx,[tystep]
adc bl,cl
and bl,dh
q5: add ebp,0x12345678
mov dl,[eax]
mov ah,[esi+ebx] ;; fetch texel : colormap number
mov [edi],dl
mov al,[ebp] ;; fetch dest : index into colormap
shinloop:
add edx,[tystep]
adc bl,cl
and bl,dh
q6: add edi,0x12345678
mov dl,[eax]
mov ah,[esi+ebx] ;; fetch texel : colormap number
mov [ebp],dl
mov al,[edi] ;; fetch dest : index into colormap
add edx,[tystep]
adc bl,cl
and bl,dh
q7: add ebp,0x12345678
mov dl,[eax]
mov ah,[esi+ebx] ;; fetch texel : colormap number
mov [edi],dl
mov al,[ebp] ;; fetch dest : index into colormap
add edx,[tystep]
adc bl,cl
and bl,dh
q8: add edi,0x12345678
mov dl,[eax]
mov ah,[esi+ebx] ;; fetch texel : colormap number
mov [ebp],dl
mov al,[edi] ;; fetch dest : index into colormap
dec ch
jne shquadloop
shdone:
pop ebx ;; restore register variables
pop edi
pop esi
pop ebp ;; restore caller's stack frame pointer
ret
;;----------------------------------------------------------------------
;;
;; R_DrawSpan
;;
;; Horizontal texture mapping
;;
;;----------------------------------------------------------------------
[SECTION .data]
oldcolormap dd 0
[SECTION CODE_SEG write]
cglobal R_DrawSpan_8
R_DrawSpan_8:
push ebp ;; preserve caller's stack frame pointer
push esi ;; preserve register variables
push edi
push ebx
;;
;; initilise registers
;;
mov edx, [ds_xfrac]
mov eax, [ds_ystep]
ror edx, 14
ror eax, 15
mov bl, dl
mov ecx, [ds_xstep]
mov dh, al
mov ax, 1
mov [tystep], eax
mov eax, [ds_yfrac]
ror ecx, 13
ror eax, 16
mov dl, cl
mov bh, al
xor cx, cx
and ebx, 0x3fff
mov [pixelcount],ecx
mov ecx, [ds_x2]
mov edi, [ds_y]
mov esi, [ds_x1]
mov edi, [ylookup+edi*4]
mov ebp, ebx
add edi, [columnofs+esi*4]
sub esi, ecx ;; pixel count
shr ebp, 2
mov ecx, [ds_colormap]
mov ax, si
mov esi, [ds_source]
sar ax,1
jnc near .midloop ;; check parity
; summary
; edx = high16bit xfrac[0..13], ah=ystep[16..24] al=xtep[14..21]
; ebx = high16bit =0, bh=yfrac[16..24], bl=xfrac[14..21]
; ecx = colormap table cl=0 (colormap is aligned 8 bits)
; eax = high16bit yfrac[0..15], dx = count
; esi = flat texture source
; edi = screeen buffer destination
; ebp = work register
; pixelcount = high16bit xstep[0..13] rest to 0
; tystep = high16bit ystep[0..15] low 16 bit = 2 (increment of count)
align 4
.loop
add eax, [tystep]
mov cl, [esi+ebp]
adc bh, dh
mov cl, [ecx]
and bh, 0x3f
mov [edi], cl
mov ebp, ebx
inc edi
shr ebp, 2
.midloop:
add edx, [pixelcount]
mov cl, [esi+ebp]
adc bl, dl
mov cl, [ecx]
mov ebp, ebx
mov [edi], cl
inc edi
shr ebp, 2
test eax, 0xffff
jnz near .loop
.hdone: pop ebx ;; restore register variables
pop edi
pop esi
pop ebp ;; restore caller's stack frame pointer
ret
[SECTION .data]
obelix dd 0
etaussi dd 0
[SECTION CODE_SEG]
cglobal R_DrawSpan_8_old
R_DrawSpan_8_old:
push ebp ;; preserve caller's stack frame pointer
push esi ;; preserve register variables
push edi
push ebx
;;
;; find loop count
;;
mov eax,[ds_x2]
inc eax
sub eax,[ds_x1] ;; pixel count
mov [pixelcount],eax ;; save for final pixel
js near .hdone ;; nothing to scale
shr eax,0x1 ;; double pixel count
mov [loopcount],eax
;;
;; build composite position
;;
mov ebp,[ds_xfrac]
shl ebp,10
and ebp,0xffff0000
mov eax,[ds_yfrac]
shr eax,6
and eax,0xffff
mov edi,[ds_y]
or ebp,eax
mov esi,[ds_source]
;;
;; calculate screen dest
;;
mov edi,[ylookup+edi*4]
mov eax,[ds_x1]
add edi,[columnofs+eax*4]
;;
;; build composite step
;;
mov ebx,[ds_xstep]
shl ebx,10
and ebx,0xffff0000
mov eax,[ds_ystep]
shr eax,6
and eax,0xffff
or ebx,eax
mov [obelix],ebx
mov [etaussi],esi
;; %eax aligned colormap
;; %ebx aligned colormap
;; %ecx,%edx scratch
;; %esi virtual source
;; %edi moving destination pointer
;; %ebp frac
mov eax,[ds_colormap]
mov ecx,ebp
add ebp,ebx ;; advance frac pointer
shr cx,10
rol ecx,6
and ecx,4095 ;; finish calculation for third pixel
mov edx,ebp
shr dx,10
rol edx,6
add ebp,ebx ;; advance frac pointer
and edx,4095 ;; finish calculation for fourth pixel
mov ebx,eax
mov al,[esi+ecx] ;; get first pixel
mov bl,[esi+edx] ;; get second pixel
test dword [pixelcount],0xfffffffe
mov dl,[eax] ;; color translate first pixel
;; movw $0xf0f0,%dx ;;see visplanes start
je .hchecklast
mov dh,[ebx] ;; color translate second pixel
mov esi,[loopcount]
align 4
.hdoubleloop:
mov ecx,ebp
shr cx,10
rol ecx,6
add ebp,[obelix] ;; advance frac pointer
mov [edi],dx ;; write first pixel
and ecx,4095 ;; finish calculation for third pixel
mov edx,ebp
shr dx,10
rol edx,6
add ecx,[etaussi]
and edx,4095 ;; finish calculation for fourth pixel
mov al,[ecx] ;; get third pixel
add ebp,[obelix] ;; advance frac pointer
add edx,[etaussi]
mov bl,[edx] ;; get fourth pixel
mov dl,[eax] ;; color translate third pixel
add edi,byte +0x2 ;; advance to third pixel destination
dec esi ;; done with loop?
mov dh,[ebx] ;; color translate fourth pixel
jne .hdoubleloop
;; check for final pixel
.hchecklast:
test dword [pixelcount],0x1
je .hdone
mov [edi],dl ;; write final pixel
.hdone: pop ebx ;; restore register variables
pop edi
pop esi
pop ebp ;; restore caller's stack frame pointer
ret
;; ========================================================================
;; Rasterization des segments d'un polyg搉e textur
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -