www.pudn.com > sn068s.zip > BG16.NI
%define R16x16_Local_Bytes 24 %define R16x16_Plotter_LeftEdge esp+20 %define R16x16_Plotter esp+16 %define R16x16_BG_Table esp+12 %define R16x16_Current_Line esp+8 %define R16x16_BaseDestPtr esp+4 %define R16x16_Lines esp %macro Render_16x16 1 ALIGNC EXPORT_C Render_16x16_C%1 %if %1 == 2 mov ecx,[M0_Color+edx] mov [Palette_Base],ecx %endif %ifndef NO_NP_RENDER mov ecx,_Plot_Lines_Unclipped_NP_16x16_C%1 test al,al mov eax,_Plot_Lines_Unclipped_NP_16x16_C%1.LeftEdge jnz .have_plotter %endif %ifndef NO_PLOTTER_PER_PRIORITY cmp byte [Tile_priority_bit],0 mov ecx,_Plot_Lines_Unclipped_H_16x16_C%1 mov eax,_Plot_Lines_Unclipped_H_16x16_C%1.LeftEdge jz .have_plotter mov ecx,_Plot_Lines_Unclipped_L_16x16_C%1 mov eax,_Plot_Lines_Unclipped_L_16x16_C%1.LeftEdge %else mov ecx,_Plot_Lines_Unclipped_V_16x16_C%1 mov eax,_Plot_Lines_Unclipped_V_16x16_C%1.LeftEdge %endif .have_plotter: jmp short Render_16x16_Base %endmacro Render_16x16 2 Render_16x16 4 Render_16x16 8 ALIGNC Render_16x16_Base: push eax push ecx push edx push ebx push edi push ebp .next_line: mov edx,[R16x16_BG_Table] mov eax,[R16x16_Current_Line] call Sort_Screen_Height_Mosaic mov eax,[R16x16_Current_Line] Get_Current_Line SORT_TILES_16_TALL ; This sets up the screen vert 2! mov edi,[R16x16_BaseDestPtr] mov eax,[SetAddress+edx] add edi,[_SNES_Screen8] mov [TilesetAddress],eax push ebx mov ah,[TileCount2+edx] push edx push eax mov ecx,[VLMapAddress+edx] mov eax,[FirstPixel+edx] add ebx,ecx sub edi,eax cmp al,8 mov ch,[TileCount1+edx] jb .no_clipped_left_edge_tile inc ch call dword [R16x16_Plotter_LeftEdge+12] jmp short .left_run_completed .no_clipped_left_edge_tile: call dword [R16x16_Plotter+12] .left_run_completed: pop ecx pop edx pop ebx test ch,ch jz .no_second_set add ebx,[VRMapAddress+edx] call dword [R16x16_Plotter] .no_second_set: %ifndef LAYERS_PER_LINE mov edi,[R16x16_BaseDestPtr] inc dword [R16x16_Current_Line] add edi,GfxBufferLinePitch dec dword [R16x16_Lines] mov [R16x16_BaseDestPtr],edi ; Point screen to next line jnz near .next_line %endif mov edx,[R16x16_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 R16x16_Local_Bytes ret ;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high %macro Plot_Lines_Unclipped_16x16_C2 2 %if %2 > 0 %%return: ret ALIGNC %1_check: %if %2 == 1 || %2 == 3 mov [Tile_Priority_Unused],ch %endif add ebx,byte 2 ; Update screen pointer add edi,byte 16 sub ch,2 jbe %%return %endif EXPORT_C %1 ; Define label, entry point %%next_tile: mov al,[ebx+1] Check_Tile_Priority %2, %1_check 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 dl,al add esi,ebp and edx,byte 7*4 ; Get palette add ebx,byte 2 ; Update screen pointer mov ebp,[Palette_Base] mov edx,[palette_2bpl+edx] or ebp,edx ; Adjust palette for mode 0 mov edx,[TilesetAddress] add al,al ; Get X flip (now in MSB) push esi js near %%xflip and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 4 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_noflip 1,_TileCache2+esi*8,0 pop esi dec ch jz near %%no_more add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,[TilesetAddress] and esi,0xFFFF * 4 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_noflip 1,_TileCache2+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 dec ch jnz near %%next_tile %%no_more: ret ALIGNC %%xflip: add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 4 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_Xflip 1,_TileCache2+esi*8,0 pop esi dec ch jz near %%xflip_no_more and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,[TilesetAddress] and esi,0xFFFF * 4 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_Xflip 1,_TileCache2+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 dec ch jnz near %%next_tile %%xflip_no_more: ret .LeftEdge: mov al,[ebx+1] Check_Tile_Priority %2, near %1_check mov ebp,[LineAddressY] test al,al ; Check Y flip mov si,[ebx] ; Get tile # js %%leftedge_flip_y mov ebp,[LineAddress] %%leftedge_flip_y: shl esi,3 mov dl,al add esi,ebp and edx,byte 7*4 ; Get palette add ebx,byte 2 ; Update screen pointer mov ebp,[Palette_Base] mov edx,[palette_2bpl+edx] or ebp,edx ; Adjust palette for mode 0 mov edx,[TilesetAddress] add al,al ; Get X flip (now in MSB) js near %%leftedge_xflip add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 4 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_noflip 1,_TileCache2+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 sub ch,2 ja near %%next_tile ret ALIGNC %%leftedge_xflip: and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 4 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_Xflip 1,_TileCache2+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 sub ch,2 ja near %%next_tile ret %endmacro ;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high %macro Plot_Lines_Unclipped_16x16_C4 2 %if %2 > 0 %%return: ret ALIGNC %1_check: %if %2 == 1 || %2 == 3 mov [Tile_Priority_Unused],ch %endif add ebx,byte 2 ; Update screen pointer add edi,byte 16 sub ch,2 jbe %%return %endif EXPORT_C %1 ; Define label, entry point %%next_tile: mov al,[ebx+1] Check_Tile_Priority %2, %1_check 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 dl,al add esi,ebp add ebx,byte 2 ; Update screen pointer and edx,byte 7*4 ; Get palette mov ebp,[palette_4bpl+edx] add al,al ; Get X flip (now in MSB) mov edx,[TilesetAddress] push esi js near %%xflip and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 2 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_noflip 1,_TileCache4+esi*8,0 pop esi dec ch jz near %%no_more add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,[TilesetAddress] and esi,0xFFFF * 2 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_noflip 1,_TileCache4+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 dec ch jnz near %%next_tile %%no_more: ret ALIGNC %%xflip: add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 2 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_Xflip 1,_TileCache4+esi*8,0 pop esi dec ch jz near %%xflip_no_more and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,[TilesetAddress] and esi,0xFFFF * 2 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_Xflip 1,_TileCache4+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 dec ch jnz near %%next_tile %%xflip_no_more: ret .LeftEdge: mov al,[ebx+1] Check_Tile_Priority %2, near %1_check mov ebp,[LineAddressY] test al,al ; Check Y flip mov si,[ebx] ; Get tile # js %%leftedge_flip_y mov ebp,[LineAddress] %%leftedge_flip_y: shl esi,3 mov dl,al add esi,ebp add ebx,byte 2 ; Update screen pointer and edx,byte 7*4 ; Get palette mov ebp,[palette_4bpl+edx] add al,al ; Get X flip (now in MSB) mov edx,[TilesetAddress] js near %%leftedge_xflip add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 2 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_noflip 1,_TileCache4+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 sub ch,2 ja near %%next_tile ret ALIGNC %%leftedge_xflip: and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF * 2 / 8 ; Clip to VRAM Plot_8_Paletted_Lines_Xflip 1,_TileCache4+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 sub ch,2 ja near %%next_tile ret %endmacro ;%1 = label, %2 = priority - 0 = none, 1 = low, 2 = high %macro Plot_Lines_Unclipped_16x16_C8 2 %if %2 > 0 %%return: ret ALIGNC %1_check: %if %2 == 1 || %2 == 3 mov [Tile_Priority_Unused],ch %endif add ebx,byte 2 ; Update screen pointer add edi,byte 16 sub ch,2 jbe %%return %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 test al,al ; Check Y flip mov ebp,[LineAddressY] js %%flip_y mov ebp,[LineAddress] %%flip_y: add esi,ebp add al,al ; Get X flip (now in MSB) mov edx,[TilesetAddress] push esi js near %%xflip and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF / 8 ; Clip to VRAM Plot_8_Lines_noflip 1,_TileCache8+esi*8,0 pop esi dec ch jz near %%no_more add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,[TilesetAddress] and esi,0xFFFF / 8 ; Clip to VRAM Plot_8_Lines_noflip 1,_TileCache8+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 dec ch jnz near %%next_tile %%no_more: ret ALIGNC %%xflip: add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF / 8 ; Clip to VRAM Plot_8_Lines_Xflip 1,_TileCache8+esi*8,0 pop esi dec ch jz near %%xflip_no_more and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,[TilesetAddress] and esi,0xFFFF / 8 ; Clip to VRAM Plot_8_Lines_Xflip 1,_TileCache8+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 dec ch jnz near %%next_tile %%xflip_no_more: ret .LeftEdge: mov al,[ebx+1] Check_Tile_Priority %2, near %1_check mov si,[ebx] ; Get tile # add ebx,byte 2 ; Update screen pointer shl esi,3 test al,al ; Check Y flip mov ebp,[LineAddressY] js %%leftedge_flip_y mov ebp,[LineAddress] %%leftedge_flip_y: add esi,ebp add al,al ; Get X flip (now in MSB) mov edx,[TilesetAddress] js near %%leftedge_xflip add esi,byte 8 and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF / 8 ; Clip to VRAM Plot_8_Lines_noflip 1,_TileCache8+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 sub ch,2 ja near %%next_tile ret ALIGNC %%leftedge_xflip: and esi,0x3FF * 8 + 7 ; Clip to tileset add esi,edx and esi,0xFFFF / 8 ; Clip to VRAM Plot_8_Lines_Xflip 1,_TileCache8+esi*8,8 %if %2 == 1 || %2 == 3 mov [Tile_Priority_Used],ch %endif add edi,byte 16 sub ch,2 ja near %%next_tile ret %endmacro %ifndef NO_NP_RENDER Plot_Lines_Unclipped_16x16_C2 Plot_Lines_Unclipped_NP_16x16_C2,0 %endif %ifndef NO_PLOTTER_PER_PRIORITY Plot_Lines_Unclipped_16x16_C2 Plot_Lines_Unclipped_L_16x16_C2,1 Plot_Lines_Unclipped_16x16_C2 Plot_Lines_Unclipped_H_16x16_C2,2 %else Plot_Lines_Unclipped_16x16_C2 Plot_Lines_Unclipped_V_16x16_C2,3 %endif %ifndef NO_NP_RENDER Plot_Lines_Unclipped_16x16_C4 Plot_Lines_Unclipped_NP_16x16_C4,0 %endif %ifndef NO_PLOTTER_PER_PRIORITY Plot_Lines_Unclipped_16x16_C4 Plot_Lines_Unclipped_L_16x16_C4,1 Plot_Lines_Unclipped_16x16_C4 Plot_Lines_Unclipped_H_16x16_C4,2 %else Plot_Lines_Unclipped_16x16_C4 Plot_Lines_Unclipped_V_16x16_C4,3 %endif %ifndef NO_NP_RENDER Plot_Lines_Unclipped_16x16_C8 Plot_Lines_Unclipped_NP_16x16_C8,0 %endif %ifndef NO_PLOTTER_PER_PRIORITY Plot_Lines_Unclipped_16x16_C8 Plot_Lines_Unclipped_L_16x16_C8,1 Plot_Lines_Unclipped_16x16_C8 Plot_Lines_Unclipped_H_16x16_C8,2 %else Plot_Lines_Unclipped_16x16_C8 Plot_Lines_Unclipped_V_16x16_C8,3 %endif