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

📄 bg8o.asm

📁 NES game Emulator in Linux.c and asm codes.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
 mov [RO8x8_RunListPtr],edx
 mov edx,[RO8x8_BG_Table]

 mov [RO8x8R_Next_Pixel],ebx
 mov [RO8x8R_Pixel_Count],ecx

 mov al,[RO8x8_Runs_Left]
 dec al
 jne .not_last_run
.last_run:
 call Render_Offset_8x8_Run

.done:

%ifndef LAYERS_PER_LINE
 mov edi,[RO8x8_BaseDestPtr]
 inc dword [RO8x8_Current_Line]
 add edi,GfxBufferLinePitch
 dec dword [RO8x8_Lines]
 mov [RO8x8_BaseDestPtr],edi ; Point screen to next line
 jnz .next_line
%endif

 mov edx,[RO8x8_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 RO8x8_Local_Bytes
 ret

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high
%macro Plot_Lines_Offset_8x8_C4 2
%if %2 > 0
%%return:
 ret

ALIGNC
%1_check:
 pop ebx
 pop esi

%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add edi,byte 8
 dec cl
 jz %%return
%else
ALIGNC
%endif

EXPORT_C %1     ; Define label, entry point
.next_tile:
 lea eax,[esi+2]
 mov dh,[1+esi]     ; Horizontal offset change map
 push eax

 mov ebp,[RO8x8_FirstTile+RO8x8_Inner+4]
 mov eax,[OffsetChangeVMap_VOffset]
 test dh,ch         ; H-offset enabled?
 jz .have_h_offset
 mov dl,[esi]
 mov ebp,edx
 shr ebp,3
 add ebp,ebp
.have_h_offset:

 mov dh,[1+esi+eax] ; Vertical offset change map
 test dh,ch         ; V-offset enabled?
 jz .No_VChange
 mov dl,[esi+eax]
 mov eax,[RO8x8_Current_Line+RO8x8_Inner+4]
 add eax,edx

.calc_v_offset:
 and ah,1
 mov esi,[RO8x8_TMapAddress+RO8x8_Inner+4]
 jz .line_in_screen_map_top
 mov esi,[RO8x8_BMapAddress+RO8x8_Inner+4]
.line_in_screen_map_top:

 ; al contains real Y offset for next tile
 push ecx
 mov ecx,0xF8
 mov edx,7
 and ecx,eax
 and eax,byte 7
 sub edx,eax
 lea esi,[esi+ecx*8]    ; Get screen offset
 pop ecx
 jmp .have_v_offset

.LeftEdge:
 push esi

 mov ebp,[RO8x8_FirstTile+RO8x8_Inner+4]

.No_VChange:
 mov eax,[LineAddress]
 mov esi,[RO8x8_MapAddress_Current+RO8x8_Inner+4]
 mov edx,[LineAddressY]

.have_v_offset:
 add ebp,ebx
 add ebx,byte 2     ; Update X offset
 mov [RO8x8_LineAddressOffset+RO8x8_Inner+4],eax
 push ebx
 mov ebx,ebp
 and ebp,byte 31*2  ; X offset wrap
 mov [RO8x8_LineAddressOffsetY+RO8x8_Inner+8],edx
 add esi,ebp        ; Combine X and Y offsets into tile map
 and ebx,byte 32*2
 mov ebx,[RO8x8_RMapDifference+RO8x8_Inner+8]
 jz  .tile_in_screen_map_left
 add esi,ebx
.tile_in_screen_map_left:

 mov al,[esi+1]
 Check_Tile_Priority %2, %1_check

 mov ebp,[RO8x8_LineAddressOffsetY+RO8x8_Inner+8]
 test al,al         ; Check Y flip
 mov si,[esi]       ; Get tile #
 js .flip_y
 mov ebp,[RO8x8_LineAddressOffset+RO8x8_Inner+8]

.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 ebp,[palette_4bpl+edx]

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

 Plot_8_Paletted_Lines_Clip_noflip 0,C_LABEL(TileCache4)+esi*8,0,TileClip1
;Plot_8_Paletted_Lines_noflip 0,C_LABEL(TileCache4)+esi*8,0

 pop ebx
 pop esi

 add edi,byte 8
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif
 dec cl
 jnz .next_tile

 ret

ALIGNC
.xflip:
 Plot_8_Paletted_Lines_Clip_Xflip 0,C_LABEL(TileCache4)+esi*8,0,TileClip1
;Plot_8_Paletted_Lines_Xflip 0,C_LABEL(TileCache4)+esi*8,0

 pop ebx
 pop esi

 add edi,byte 8
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif
 dec cl
 jnz .next_tile

 ret
%endmacro

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high
%macro Plot_Lines_Offset_8x8_C2 2
%if %2 > 0
%%return:
 ret

ALIGNC
%1_check:
 pop ebx
 pop esi

%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add edi,byte 8
 dec cl
 jz %%return
%else
ALIGNC
%endif

EXPORT_C %1     ; Define label, entry point
.next_tile:
 lea eax,[esi+2]
 mov dh,[1+esi]     ; Offset change map
 push eax

 mov ebp,[RO8x8_FirstTile+RO8x8_Inner+4]
 mov eax,[RO8x8_Current_Line+RO8x8_Inner+4]
 test dh,ch         ; Offset enabled?
 jz .No_VChange

 test dh,dh         ; vertical offset?
 jnz .calc_v_offset

 mov dl,[esi]
 mov ebp,edx
 shr ebp,3
 add ebp,ebp
 jmp .No_VChange

.calc_v_offset:
 mov dl,[esi]
 add eax,edx

 and ah,1
 mov esi,[RO8x8_TMapAddress+RO8x8_Inner+4]
 jz .line_in_screen_map_top
 mov esi,[RO8x8_BMapAddress+RO8x8_Inner+4]
.line_in_screen_map_top:

 ; al contains real Y offset for next tile
 push ecx
 mov ecx,0xF8
 mov edx,7
 and ecx,eax
 and eax,byte 7
 sub edx,eax
 lea esi,[esi+ecx*8]    ; Get screen offset
 pop ecx
 jmp .have_v_offset

.LeftEdge:
 push esi

 mov ebp,[RO8x8_FirstTile+RO8x8_Inner+4]

.No_VChange:
 mov eax,[LineAddress]
 mov esi,[RO8x8_MapAddress_Current+RO8x8_Inner+4]
 mov edx,[LineAddressY]

.have_v_offset:
 add ebp,ebx
 add ebx,byte 2     ; Update X offset
 mov [RO8x8_LineAddressOffset+RO8x8_Inner+4],eax
 push ebx
 mov ebx,ebp
 and ebp,byte 31*2  ; X offset wrap
 mov [RO8x8_LineAddressOffsetY+RO8x8_Inner+8],edx
 add esi,ebp        ; Combine X and Y offsets into tile map
 and ebx,byte 32*2
 mov ebx,[RO8x8_RMapDifference+RO8x8_Inner+8]
 jz  .tile_in_screen_map_left
 add esi,ebx
.tile_in_screen_map_left:

 mov al,[esi+1]
 Check_Tile_Priority %2, %1_check

 mov ebp,[RO8x8_LineAddressOffsetY+RO8x8_Inner+8]
 test al,al         ; Check Y flip
 mov si,[esi]       ; Get tile #
 js .flip_y
 mov ebp,[RO8x8_LineAddressOffset+RO8x8_Inner+8]

.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 * 4 / 8 ; Clip to VRAM
 mov ebp,[palette_2bpl+edx]

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

 Plot_8_Paletted_Lines_Clip_noflip 0,C_LABEL(TileCache2)+esi*8,0,TileClip1
;Plot_8_Paletted_Lines_noflip 0,C_LABEL(TileCache2)+esi*8,0

 pop ebx
 pop esi

 add edi,byte 8
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif
 dec cl
 jnz .next_tile

 ret

ALIGNC
.xflip:
 Plot_8_Paletted_Lines_Clip_Xflip 0,C_LABEL(TileCache2)+esi*8,0,TileClip1
;Plot_8_Paletted_Lines_Xflip 0,C_LABEL(TileCache2)+esi*8,0

 pop ebx
 pop esi

 add edi,byte 8
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif
 dec cl
 jnz .next_tile

 ret
%endmacro

;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high
%macro Plot_Lines_Offset_8x8_C8 2
%if %2 > 0
%%return:
 ret

ALIGNC
%1_check:
 pop ebx
 pop esi

%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Unused],cl
%endif
 add edi,byte 8
 dec cl
 jz %%return
%else
ALIGNC
%endif

EXPORT_C %1     ; Define label, entry point
.next_tile:
 lea eax,[esi+2]
 mov dh,[1+esi]     ; Offset change map
 push eax

 mov ebp,[RO8x8_FirstTile+RO8x8_Inner+4]
 mov eax,[RO8x8_Current_Line+RO8x8_Inner+4]
 test dh,ch         ; Offset enabled?
 jz .No_VChange

 test dh,dh         ; vertical offset?
 jnz .calc_v_offset

 mov dl,[esi]
 mov ebp,edx
 shr ebp,3
 add ebp,ebp
 jmp .No_VChange

.calc_v_offset:
 mov dl,[esi]
 add eax,edx

 and ah,1
 mov esi,[RO8x8_TMapAddress+RO8x8_Inner+4]
 jz .line_in_screen_map_top
 mov esi,[RO8x8_BMapAddress+RO8x8_Inner+4]
.line_in_screen_map_top:

 ; al contains real Y offset for next tile
 push ecx
 mov ecx,0xF8
 mov edx,7
 and ecx,eax
 and eax,byte 7
 sub edx,eax
 lea esi,[esi+ecx*8]    ; Get screen offset
 pop ecx
 jmp .have_v_offset

.LeftEdge:
 push esi

 mov ebp,[RO8x8_FirstTile+RO8x8_Inner+4]

.No_VChange:
 mov eax,[LineAddress]
 mov esi,[RO8x8_MapAddress_Current+RO8x8_Inner+4]
 mov edx,[LineAddressY]

.have_v_offset:
 add ebp,ebx
 add ebx,byte 2     ; Update X offset
 mov [RO8x8_LineAddressOffset+RO8x8_Inner+4],eax
 push ebx
 mov ebx,ebp
 and ebp,byte 31*2  ; X offset wrap
 mov [RO8x8_LineAddressOffsetY+RO8x8_Inner+8],edx
 add esi,ebp        ; Combine X and Y offsets into tile map
 and ebx,byte 32*2
 mov ebx,[RO8x8_RMapDifference+RO8x8_Inner+8]
 jz  .tile_in_screen_map_left
 add esi,ebx
.tile_in_screen_map_left:

 mov al,[esi+1]
 Check_Tile_Priority %2, %1_check

 mov ebp,[RO8x8_LineAddressOffsetY+RO8x8_Inner+8]
 test al,al         ; Check Y flip
 mov si,[esi]       ; Get tile #
 js .flip_y
 mov ebp,[RO8x8_LineAddressOffset+RO8x8_Inner+8]

.flip_y:
 shl esi,3
 add esi,ebp
 mov ebp,[TilesetAddress]
 and esi,0x3FF * 8 + 7  ; Clip to tileset
 add esi,ebp

 and esi,0xFFFF / 8 ; Clip to VRAM

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

 Plot_8_Lines_Clip_noflip 0,C_LABEL(TileCache8)+esi*8,0,TileClip1
;Plot_8_Lines_noflip 0,C_LABEL(TileCache8)+esi*8,0

 pop ebx
 pop esi

 add edi,byte 8
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif
 dec cl
 jnz .next_tile

 ret

ALIGNC
.xflip:
 Plot_8_Lines_Clip_noflip 0,C_LABEL(TileCache8)+esi*8,0,TileClip1
;Plot_8_Lines_Xflip 0,C_LABEL(TileCache8)+esi*8,0

 pop ebx
 pop esi

 add edi,byte 8
%if %2 == 1 || %2 == 3
 mov [Tile_Priority_Used],cl
%endif
 dec cl
 jnz .next_tile

 ret
%endmacro

;%1 = depth
%macro Generate_Line_Plotters_Offset_8x8 1
%ifndef NO_NP_RENDER
 Plot_Lines_Offset_8x8_C%1 Plot_Lines_NP_Offset_8x8_C%1,0
%endif
 Plot_Lines_Offset_8x8_C%1 Plot_Lines_V_Offset_8x8_C%1,3
%endmacro

Generate_Line_Plotters_Offset_8x8 4
Generate_Line_Plotters_Offset_8x8 2
Generate_Line_Plotters_Offset_8x8 8

section .data
%macro Generate_Line_Plotter_Table_Offset_8x8 2
EXPORT_C Plot_Lines_%1_Offset_8x8_Table_C%2
dd C_LABEL(Plot_Lines_%1_Offset_8x8_C%2).LeftEdge
dd C_LABEL(Plot_Lines_%1_Offset_8x8_C%2)
%endmacro

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

Generate_Line_Plotter_Table_Offset_8x8 V,4
Generate_Line_Plotter_Table_Offset_8x8 V,2
Generate_Line_Plotter_Table_Offset_8x8 V,8

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

⌨️ 快捷键说明

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