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

📄 bg8.asm

📁 NES game Emulator in Linux.c and asm codes.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
 mov edi,[R8x8_Output]
 xor ebx,ebx
 xor ecx,ecx
 mov bl,[edx+2]

 mov cl,[edx+3]
 add edx,byte 2
 sub cl,bl
 mov [R8x8_RunListPtr],edx
 mov edx,[R8x8_BG_Table]

 mov [R8x8R_Next_Pixel],ebx
 mov [R8x8R_Pixel_Count],ecx

 mov al,[R8x8_Runs_Left]
 dec al
 jne .not_last_run
.last_run:
 call Render_8x8_Run

.done:

 mov ebp,[BGLineCount] ;*
%if %2 == 0
 mov edx,[R8x8_BG_Table]
%endif
 mov eax,[R8x8_Current_Line]

%if %2 == 0
 mov bx,[Tile_Priority_Used]
 or [Priority_Used+edx],bx
 mov [Priority_Used+edx+eax*2],bx
%endif

 mov ecx,[R8x8_Lines]
 add eax,ebp
 sub ecx,ebp
 mov [R8x8_Current_Line],eax
 mov [R8x8_Lines],ecx

%ifndef LAYERS_PER_LINE
;cmp dword [R8x8_Lines],0
 jnz .next_line
%endif

%if %2 == 0
;mov edx,[R8x8_BG_Table]
;mov al,[Tile_Priority_Used]
;mov [Priority_Used+edx],al
;mov ah,[Tile_Priority_Unused]
;mov [Priority_Unused+edx],ah

 add esp,byte R8x8_Local_Bytes
%else
 add esp,byte R8x8_Local_Bytes_H
%endif
 ret

%if %2 > 0
ALIGNC
.no_plot:
 mov ebp,[R8x8_Lines]
 cmp ebp,byte 1
 je .no_plot_no_multi
                                
 mov edi,[VScroll+edx]
 mov eax,[R8x8_Current_Line]
 add edi,eax
 mov eax,8
 and edi,byte 7
 sub eax,edi

 cmp eax,ebp
 ja .no_plot_no_multi
 mov ebp,eax
.no_plot_no_multi:
 mov edi,[R8x8_BaseDestPtr]
 mov eax,ebp
 shl eax,8
 lea ecx,[edi+ebp*GfxBufferLineSlack]
 add eax,ecx
 mov [R8x8_BaseDestPtr],eax

 mov eax,[R8x8_Current_Line]
 mov ecx,[R8x8_Lines]
 add eax,ebp
 sub ecx,ebp
 mov [R8x8_Current_Line],eax
 mov [R8x8_Lines],ecx

%ifndef LAYERS_PER_LINE
;cmp dword [R8x8_Lines],0
 jnz .next_line
%endif

 add esp,byte R8x8_Local_Bytes_H
 ret
%endif
%endmacro

Render_8x8_Base Render_8x8_Low,0
Render_8x8_Base Render_8x8_High,1

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high, %3 = multi-line
%macro Plot_Lines_8x8_C2 3
%if %2 > 0
%%return:
 ret

ALIGNC
%1_check:
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add ebx,byte 2     ; Update screen pointer
 add edi,byte 8
 dec cl
 jz %%return
%else
ALIGNC
%endif

EXPORT_C %1     ; Define label, entry point
%%next_tile:
 mov al,[ebx+1]

 Check_Tile_Priority %2, %1_check

%if %3
 push ecx
 mov ecx,-1
%endif
 mov ebp,[LineAddressY]
 test al,al         ; Check Y flip
 mov si,[ebx]       ; Get tile #
 js %%flip_y
 mov ebp,[LineAddress]
%if %3
 add ecx,byte (1 * 2)
%endif

%%flip_y:
 shl esi,3
 mov edx,eax
 add esi,ebp
 mov ebp,[TilesetAddress]
 and esi,0x3FF * 8 + 7  ; Clip to tileset
 and edx,byte 7*4   ; Get palette
 add esi,ebp

 mov ebp,[Palette_Base]
 and esi,0xFFFF * 4 / 8 ; Clip to VRAM

 mov edx,[palette_2bpl+edx]
 add ebx,byte 2     ; Update screen pointer
 or ebp,edx         ; Adjust palette for mode 0

%if %3
 push ebx
 mov ebx,[BGLineCount]
%endif

%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif

 add al,al      ; Get X flip (now in MSB)
 js %%xflip

 Plot_8_Paletted_Lines_Clip_noflip (%3),C_LABEL(TileCache2)+esi*8,0,TileClip1
%if %3
 pop ebx
 pop ecx
%endif

 add edi,byte 8
 dec cl
 jnz %%next_tile
 ret

ALIGNC
%%xflip:
 Plot_8_Paletted_Lines_Clip_Xflip (%3),C_LABEL(TileCache2)+esi*8,0,TileClip1
%if %3
 pop ebx
 pop ecx
%endif

 add edi,byte 8
 dec cl
 jnz %%next_tile
 ret
%endmacro

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high, %3 = multi-line
%macro Plot_Lines_8x8_C4 3
%if %2 > 0
%%return:
 ret

ALIGNC
%1_check:
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add ebx,byte 2     ; Update screen pointer
 add edi,byte 8
 dec cl
 jz %%return
%else
ALIGNC
%endif

EXPORT_C %1     ; Define label, entry point
%%next_tile:
 mov al,[ebx+1]

 Check_Tile_Priority %2, %1_check

%if %3
 push ecx
 mov ecx,-1
%endif
 mov ebp,[LineAddressY]
 test al,al         ; Check Y flip
 mov si,[ebx]       ; Get tile #
 js %%flip_y
 mov ebp,[LineAddress]
%if %3
 add ecx,byte (1 * 2)
%endif

%%flip_y:
 shl esi,3
 mov edx,eax
 add esi,ebp
 mov ebp,[TilesetAddress]
 and esi,0x3FF * 8 + 7  ; Clip to tileset
 and edx,byte 7*4   ; Get palette
 add esi,ebp

 add ebx,byte 2     ; Update screen pointer
 and esi,0xFFFF * 2 / 8 ; Clip to VRAM
 mov ebp,[palette_4bpl+edx]

%if %3
 push ebx
 mov ebx,[BGLineCount]
%endif

%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif

 add al,al      ; Get X flip (now in MSB)
 js %%xflip

 Plot_8_Paletted_Lines_Clip_noflip (%3),C_LABEL(TileCache4)+esi*8,0,TileClip1
%if %3
 pop ebx
 pop ecx
%endif

 add edi,byte 8
 dec cl
 jnz %%next_tile
 ret

ALIGNC
%%xflip:
 Plot_8_Paletted_Lines_Clip_Xflip (%3),C_LABEL(TileCache4)+esi*8,0,TileClip1
%if %3
 pop ebx
 pop ecx
%endif

 add edi,byte 8
 dec cl
 jnz %%next_tile
 ret
%endmacro

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high, %3 = multi-line
%macro Plot_Lines_8x8_C8 3
%if %2 > 0
%%return:
 ret

ALIGNC
%1_check:
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add ebx,byte 2     ; Update screen pointer
 add edi,byte 8
 dec cl
 jz %%return
%else
ALIGNC
%endif

EXPORT_C %1     ; Define label, entry point
%%next_tile:
 mov al,[ebx+1]

 Check_Tile_Priority %2, %1_check

 mov si,[ebx]       ; Get tile #
 add ebx,byte 2     ; Update screen pointer
 shl esi,3
%if %3
 push ecx
 mov ecx,-1
%endif
 test al,al         ; Check Y flip
 mov ebp,[LineAddressY]
 js %%flip_y
 mov ebp,[LineAddress]
%if %3
 add ecx,byte (1 * 2)
%endif

%%flip_y:
 add esi,ebp
 mov ebp,[TilesetAddress]
 and esi,0x3FF * 8 + 7  ; Clip to tileset
 add esi,ebp
 and esi,0xFFFF / 8 ; Clip to VRAM

%if %3
 push ebx
 mov ebx,[BGLineCount]
%endif

%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif

 add al,al      ; Get X flip (now in MSB)
 js %%xflip

 Plot_8_Lines_Clip_noflip (%3),C_LABEL(TileCache8)+esi*8,0,TileClip1
%if %3
 pop ebx
 pop ecx
%endif

 add edi,byte 8
 dec cl
 jnz %%next_tile
 ret

ALIGNC
%%xflip:
 Plot_8_Lines_Clip_Xflip (%3),C_LABEL(TileCache8)+esi*8,0,TileClip1
%if %3
 pop ebx
 pop ecx
%endif

 add edi,byte 8
 dec cl
 jnz %%next_tile
 ret
%endmacro

;%1 = depth, %2 = count
%macro Generate_Line_Plotters_8x8 2
%ifndef NO_NP_RENDER
 Plot_Lines_8x8_C%1 Plot_Lines_%2_NP_8x8_C%1,0,%2
%endif
 Plot_Lines_8x8_C%1 Plot_Lines_%2_V_8x8_C%1,3,%2
%endmacro

%macro Generate_Line_Plotters_8x8_Depth 1
Generate_Line_Plotters_8x8 %1,0
Generate_Line_Plotters_8x8 %1,1
%endmacro

Generate_Line_Plotters_8x8_Depth 2
Generate_Line_Plotters_8x8_Depth 4
Generate_Line_Plotters_8x8_Depth 8

section .data
ALIGND

;%1 = type, %2 = depth
%macro Generate_Line_Plotter_Table_8x8 2
EXPORT_C Plot_Lines_%1_8x8_Table_C%2
dd C_LABEL(Plot_Lines_0_%1_8x8_C%2)
dd C_LABEL(Plot_Lines_1_%1_8x8_C%2)
%endmacro

%ifndef NO_NP_RENDER
Generate_Line_Plotter_Table_8x8 NP,2
Generate_Line_Plotter_Table_8x8 NP,4
Generate_Line_Plotter_Table_8x8 NP,8
%endif

Generate_Line_Plotter_Table_8x8 V,2
Generate_Line_Plotter_Table_8x8 V,4
Generate_Line_Plotter_Table_8x8 V,8

section .text
ALIGNC
section .data
ALIGND
section .bss
ALIGNB

⌨️ 快捷键说明

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