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

📄 bg8m.asm

📁 NES game Emulator in Linux.c and asm codes.
💻 ASM
📖 第 1 页 / 共 2 页
字号:

 cmp ebp,byte 8
 jb %%flip_none_same_tile

 pop ebx
 jmp %%next_tile

ALIGNC
%%flip_none_empty_run:
 add edi,eax
 add ebp,eax
 sub ecx,eax
 jz %%flip_none_return

 cmp ebp,byte 8
 jb %%flip_none_same_tile

 pop ebx
 jmp %%next_tile

%%flip_none_return:
 pop ebx
 ret

ALIGNC
%%xflip:
 lea esi,[C_LABEL(TileCache2)+esi*8+8]
 xor ebp,byte -1
%%flip_x_same_tile:
 cmp ecx,eax
 ja %%flip_x_partial
 mov eax,ecx
%%flip_x_partial:
 mov bl,[esi+ebp]
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],al
%endif
 and bl,dl
 jz %%flip_x_empty_run

;eax = count, esi = source base, ebp = offset, edi = dest, ecx = # left
;edx = palette, bl = pixel
 sub ebp,eax
 sub ecx,eax

%%flip_x_next_pixel:
%assign PLM8x8_Dest_Offset 0
%rep %3
 mov [edi+PLM8x8_Dest_Offset],bl
%assign PLM8x8_Dest_Offset (PLM8x8_Dest_Offset + GfxBufferLinePitch)
%endrep
 inc edi
 dec eax
 jnz %%flip_x_next_pixel

 mov eax,[Mosaic_Size]
 test ecx,ecx
 jz %%flip_x_return

 cmp ebp,byte ~8
 ja %%flip_x_same_tile

 pop ebx
 xor ebp,byte -1
 jmp %%next_tile

%%flip_x_empty_run:
 add edi,eax
 sub ebp,eax
 sub ecx,eax
 jz %%flip_x_return

 cmp ebp,byte ~8
 ja %%flip_x_same_tile

 pop ebx
 xor ebp,byte -1
 jmp %%next_tile

%%flip_x_return:
 pop ebx
 ret
%endmacro

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high, %3 = lines
%macro Plot_Lines_8x8M_C4 3
ALIGNC
%if %2 > 0
%%wrong_priority_last:
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add edi,ecx
 add ebp,ecx
%%return:
 ret

ALIGNC
%1_check:
 mov eax,[Mosaic_Size]
%%wrong_priority_same_tile:
 cmp ecx,eax
 jbe %%wrong_priority_last
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],al
%endif
 add edi,eax
 add ebp,eax
 sub ecx,eax

 cmp ebp,byte 8
 jb %%wrong_priority_same_tile
%endif

%%next_tile:
 mov eax,ebp
 and ebp,byte 7
 shr eax,3
 add eax,eax
 add ebx,eax        ; Update screen pointer

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

 Check_Tile_Priority %2, %1_check

 push ebx
 push ebp
 mov ebp,[LineAddressY]
 test al,al         ; Check Y flip
 mov si,[ebx]       ; Get tile #
 js %%flip_y
 mov ebp,[LineAddress]

%%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

 and esi,0xFFFF * 2 / 8 ; Clip to VRAM
 mov edx,[palette_4bpl+edx]
 pop ebp

 add al,al      ; Get X flip (now in MSB)
 mov eax,[Mosaic_Size]
 js %%xflip

 lea esi,[C_LABEL(TileCache4)+esi*8]
%%flip_none_same_tile:
 cmp ecx,eax
 ja %%flip_none_partial
 mov eax,ecx
%%flip_none_partial:
 mov bl,[esi+ebp]
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],al
%endif
 and bl,dl
 jz %%flip_none_empty_run

;eax = count, esi = source base, ebp = offset, edi = dest, ecx = # left
;edx = palette, bl = pixel
 add ebp,eax
 sub ecx,eax

%%flip_none_next_pixel:
%assign PLM8x8_Dest_Offset 0
%rep %3
 mov [edi+PLM8x8_Dest_Offset],bl
%assign PLM8x8_Dest_Offset (PLM8x8_Dest_Offset + GfxBufferLinePitch)
%endrep
 inc edi
 dec eax
 jnz %%flip_none_next_pixel

 mov eax,[Mosaic_Size]
 test ecx,ecx
 jz %%flip_none_return

 cmp ebp,byte 8
 jb %%flip_none_same_tile

 pop ebx
 jmp %%next_tile

%%flip_none_empty_run:
 add edi,eax
 add ebp,eax
 sub ecx,eax
 jz %%flip_none_return

 cmp ebp,byte 8
 jb %%flip_none_same_tile

 pop ebx
 jmp %%next_tile

%%flip_none_return:
 pop ebx
 ret

ALIGNC
%%xflip:
 lea esi,[C_LABEL(TileCache4)+esi*8+8]
 xor ebp,byte -1
%%flip_x_same_tile:
 cmp ecx,eax
 ja %%flip_x_partial
 mov eax,ecx
%%flip_x_partial:
 mov bl,[esi+ebp]
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],al
%endif
 and bl,dl
 jz %%flip_x_empty_run

;eax = count, esi = source base, ebp = offset, edi = dest, ecx = # left
;edx = palette, bl = pixel
 sub ebp,eax
 sub ecx,eax

%%flip_x_next_pixel:
%assign PLM8x8_Dest_Offset 0
%rep %3
 mov [edi+PLM8x8_Dest_Offset],bl
%assign PLM8x8_Dest_Offset (PLM8x8_Dest_Offset + GfxBufferLinePitch)
%endrep
 inc edi
 dec eax
 jnz %%flip_x_next_pixel

 mov eax,[Mosaic_Size]
 test ecx,ecx
 jz %%flip_x_return

 cmp ebp,byte ~8
 ja %%flip_x_same_tile

 pop ebx
 xor ebp,byte -1
 jmp %%next_tile

%%flip_x_empty_run:
 add edi,eax
 sub ebp,eax
 sub ecx,eax
 jz %%flip_x_return

 cmp ebp,byte ~8
 ja %%flip_x_same_tile

 pop ebx
 xor ebp,byte -1
 jmp %%next_tile

%%flip_x_return:
 pop ebx
 ret
%endmacro

;for mosaic, keep track of # pixels done, return # tiles in next set skipped

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high, %3 = lines
%macro Plot_Lines_8x8M_C8 3
ALIGNC
%if %2 > 0
%%wrong_priority_last:
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add edi,ecx
 add ebp,ecx
%%return:
 ret

ALIGNC
%1_check:
 mov eax,[Mosaic_Size]
%%wrong_priority_same_tile:
 cmp ecx,eax
 jbe %%wrong_priority_last
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],al
%endif
 add edi,eax
 add ebp,eax
 sub ecx,eax

 cmp ebp,byte 8
 jb %%wrong_priority_same_tile
%endif

%%next_tile:
 mov eax,ebp
 and ebp,byte 7
 shr eax,3
 add eax,eax
 add ebx,eax        ; Update screen pointer

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

 Check_Tile_Priority %2, %1_check

 push ebp
 mov si,[ebx]       ; Get tile #
 shl esi,3          ; 8
 test al,al ; Check Y flip
 mov ebp,[LineAddressY]
 js %%flip_y
 mov ebp,[LineAddress]

%%flip_y:

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

 add al,al      ; Get X flip (now in MSB)
 mov eax,[Mosaic_Size]
 js %%xflip

 lea esi,[C_LABEL(TileCache8)+esi*8]
%%flip_none_same_tile:
 cmp ecx,eax
 ja %%flip_none_partial
 mov eax,ecx
%%flip_none_partial:
 mov dl,[esi+ebp]
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],al
%endif
 test dl,dl
 jz %%flip_none_empty_run

;eax = count, esi = source base, ebp = offset, edi = dest, ecx = # left
;ebx = screen map, dl = pixel
 add ebp,eax
 sub ecx,eax

%%flip_none_next_pixel:
%assign PLM8x8_Dest_Offset 0
%rep %3
 mov [edi+PLM8x8_Dest_Offset],dl
%assign PLM8x8_Dest_Offset (PLM8x8_Dest_Offset + GfxBufferLinePitch)
%endrep
 inc edi
 dec eax
 jnz %%flip_none_next_pixel

 mov eax,[Mosaic_Size]
 test ecx,ecx
 jz %%flip_none_return

 cmp ebp,byte 8
 jb %%flip_none_same_tile

 jmp %%next_tile

ALIGNC
%%flip_none_empty_run:
 add edi,eax
 add ebp,eax
 sub ecx,eax
 jz %%flip_none_return

 cmp ebp,byte 8
 jb %%flip_none_same_tile

 jmp %%next_tile

%%flip_none_return:
 ret

ALIGNC
%%xflip:
 lea esi,[C_LABEL(TileCache8)+esi*8+8]
 xor ebp,byte -1
%%flip_x_same_tile:
 cmp ecx,eax
 ja %%flip_x_partial
 mov eax,ecx
%%flip_x_partial:
 mov dl,[esi+ebp]
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],al
%endif
 test dl,dl
 jz %%flip_x_empty_run

;eax = count, esi = source base, ebp = offset, edi = dest, ecx = # left
;ebx = screen map, dl = pixel
 sub ebp,eax
 sub ecx,eax

%%flip_x_next_pixel:
%assign PLM8x8_Dest_Offset 0
%rep %3
 mov [edi+PLM8x8_Dest_Offset],dl
%assign PLM8x8_Dest_Offset (PLM8x8_Dest_Offset + GfxBufferLinePitch)
%endrep
 inc edi
 dec eax
 jnz %%flip_x_next_pixel

 mov eax,[Mosaic_Size]
 test ecx,ecx
 jz %%flip_x_return

 cmp ebp,byte ~8
 ja %%flip_x_same_tile

 xor ebp,byte -1
 jmp %%next_tile

ALIGNC
%%flip_x_empty_run:
 add edi,eax
 sub ebp,eax
 sub ecx,eax
 jz %%flip_x_return

 cmp ebp,byte ~8
 ja %%flip_x_same_tile

 xor ebp,byte -1
 jmp %%next_tile

%%flip_x_return:
 ret
%endmacro

;%1 = depth, %2 = count
%macro Generate_Line_Plotters_8x8M 2
%ifndef NO_NP_RENDER
 Plot_Lines_8x8M_C%1 Plot_Lines_%2_NP_8x8M_C%1,0,%2
%endif
 Plot_Lines_8x8M_C%1 Plot_Lines_%2_V_8x8M_C%1,3,%2
%endmacro

%macro Generate_Line_Plotters_8x8M_Depth 1
Generate_Line_Plotters_8x8M %1,1
Generate_Line_Plotters_8x8M %1,2
Generate_Line_Plotters_8x8M %1,3
Generate_Line_Plotters_8x8M %1,4
Generate_Line_Plotters_8x8M %1,5
Generate_Line_Plotters_8x8M %1,6
Generate_Line_Plotters_8x8M %1,7
Generate_Line_Plotters_8x8M %1,8
%endmacro

Generate_Line_Plotters_8x8M_Depth 2
Generate_Line_Plotters_8x8M_Depth 4
Generate_Line_Plotters_8x8M_Depth 8

section .data
;%1 = type, %2 = depth
%macro Generate_Line_Plotter_Table_8x8M 2
ALIGND
EXPORT_C Plot_Lines_%1_8x8M_Table_C%2
dd C_LABEL(Plot_Lines_1_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_2_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_3_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_4_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_5_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_6_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_7_%1_8x8M_C%2)
dd C_LABEL(Plot_Lines_8_%1_8x8M_C%2)
%endmacro

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

Generate_Line_Plotter_Table_8x8M V,2
Generate_Line_Plotter_Table_8x8M V,4
Generate_Line_Plotter_Table_8x8M V,8

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

⌨️ 快捷键说明

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