From f5abe554edde6793bfe267c1e1678c1056ae2675 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 17 Feb 2026 01:31:04 +0200 Subject: [PATCH] Document and clarify image blit routines in `vidput.inc` and `tvidput.inc`: added detailed comments for `xvidput` and `xtvidput`, including stack effects, parameters, examples, and memory layouts. --- emulator/tvidput.inc | 313 ++++++++++++++++++++++------------------- emulator/vidput.inc | 323 ++++++++++++++++++++++++------------------- 2 files changed, 350 insertions(+), 286 deletions(-) diff --git a/emulator/tvidput.inc b/emulator/tvidput.inc index 3c52a25..5398c9e 100644 --- a/emulator/tvidput.inc +++ b/emulator/tvidput.inc @@ -1,140 +1,173 @@ -; part of virtual processor, emulator for FIFTH - - -xtvidput: -mov ebx, edi ; read data from stack, and save it to variables -mov eax, [es:ebx] -mov [cory], eax -add ebx, 4 -mov eax, [es:ebx] -mov [corx], eax - -add ebx, 4 -mov eax, [es:ebx] -add eax, [xms_addr] -mov ecx, [es:eax] -mov [img2x], ecx -add eax, 4 -mov ecx, [es:eax] -mov [img2y], ecx -add eax, 4 -mov [img2a], eax - -add ebx, 4 -mov eax, [es:ebx] -add eax, [xms_addr] -mov ecx, [es:eax] -mov [img1x], ecx -add eax, 4 -mov ecx, [es:eax] -mov [img1y], ecx -add eax, 4 -mov [img1a], eax - -add ebx, 4 -mov edi, ebx - -cmp dword [cory] , 0 ; calculate Y start -jl tvidl1 -mov dword [starty], 0 -jmp tvidl2 -tvidl1: -mov eax, [cory] -neg eax -mov [starty], eax -tvidl2: - -cmp dword [corx] , 0 ; calculate X start -jl tvidl3 -mov dword [startx], 0 -jmp tvidl4 -tvidl3: -mov eax, [corx] -neg eax -mov [startx], eax -tvidl4: - -mov eax, [cory] ; calculate Y end -add eax, [img1y] -cmp eax, [img2y] -jg tvidl5 -mov eax, [img1y] -mov [endy], eax -jmp tvidl6 -tvidl5: -mov eax, [img2y] -sub eax, [cory] -mov [endy], eax -tvidl6: - -mov eax, [corx] ; calculate X end -add eax, [img1x] -cmp eax, [img2x] -jg tvidl7 -mov eax, [img1x] -mov [endx], eax -jmp tvidl8 -tvidl7: -mov eax, [img2x] -sub eax, [corx] -mov [endx], eax -tvidl8: - -mov eax, [endy] ; calculate Y length -sub eax, [starty] -cmp eax, 0 -jle emu -mov [lengthy], eax - -mov eax, [endx] ; calculate X length -sub eax, [startx] -cmp eax, 0 -jle emu -mov [lengthx], eax - -mov eax, [starty] ; calculate img1 start address -mov ebx, [img1x] -sub edx, edx -mul ebx -add eax, [img1a] -add eax, [startx] -mov [img1start], eax - -mov eax, [cory] ; calculate img2 start address -add eax, [starty] -mov ebx, [img2x] -sub edx, edx -mul ebx -add eax, [img2a] -add eax, [corx] -add eax, [startx] -mov [img2start], eax - -tvidl9: -mov ebx, [img1start] -mov ecx, [lengthx] -mov edx, [img2start] - -tmemmove: ; ebx - from, edx - to, ecx - amount -cmp ecx, 0 -je tl11 -mov al, [es:ebx] -cmp al, 255 -je tl12 -mov [es:edx], al -tl12: -inc ebx -inc edx -dec ecx -jmp tmemmove -tl11: - -mov eax, [img1x] -add [img1start], eax -mov eax, [img2x] -add [img2start], eax -dec dword [lengthy] -cmp [lengthy], 0 -jg tvidl9 - -jmp emu +; Blit image with transparency support +; +; Stack Effect: addr1 addr2 x y -- +; +; Copies a portion of image1 to image2 at the specified (x, y) +; coordinates with transparency support. Pixels in image1 with value +; 255 (0xFF) are treated as transparent and are not copied to the +; destination. +; +; Parameters: +; - addr1: Address of the source image structure (width, height, data) +; - addr2: Address of the destination image structure +; - x: X-coordinate in destination where to start copying +; - y: Y-coordinate in destination where to start copying +; +; Image Structure Format: +; - Offset 0: Image width (32-bit) +; - Offset 4: Image height (32-bit) +; - Offset 8: Base address of image data (32-bit pointer) +; +; Example: +; 0x1000 ; Source image structure +; 0x2000 ; Destination image structure +; 50 ; x +; 50 ; y +; tvidput +; +; Memory layout before execution: +; [es:edi] = y +; [es:edi+4] = x +; [es:edi+8] = addr2 +; [es:edi+12] = addr1 +; +; Memory layout after execution: +; Destination image updated with source image data (transparent pixels skipped) + +xtvidput: +mov ebx, edi ; read data from stack, and save it to variables +mov eax, [es:ebx] +mov [cory], eax +add ebx, 4 +mov eax, [es:ebx] +mov [corx], eax + +add ebx, 4 +mov eax, [es:ebx] +add eax, [xms_addr] +mov ecx, [es:eax] +mov [img2x], ecx +add eax, 4 +mov ecx, [es:eax] +mov [img2y], ecx +add eax, 4 +mov [img2a], eax + +add ebx, 4 +mov eax, [es:ebx] +add eax, [xms_addr] +mov ecx, [es:eax] +mov [img1x], ecx +add eax, 4 +mov ecx, [es:eax] +mov [img1y], ecx +add eax, 4 +mov [img1a], eax + +add ebx, 4 +mov edi, ebx + +cmp dword [cory] , 0 ; calculate Y start +jl tvidl1 +mov dword [starty], 0 +jmp tvidl2 +tvidl1: +mov eax, [cory] +neg eax +mov [starty], eax +tvidl2: + +cmp dword [corx] , 0 ; calculate X start +jl tvidl3 +mov dword [startx], 0 +jmp tvidl4 +tvidl3: +mov eax, [corx] +neg eax +mov [startx], eax +tvidl4: + +mov eax, [cory] ; calculate Y end +add eax, [img1y] +cmp eax, [img2y] +jg tvidl5 +mov eax, [img1y] +mov [endy], eax +jmp tvidl6 +tvidl5: +mov eax, [img2y] +sub eax, [cory] +mov [endy], eax +tvidl6: + +mov eax, [corx] ; calculate X end +add eax, [img1x] +cmp eax, [img2x] +jg tvidl7 +mov eax, [img1x] +mov [endx], eax +jmp tvidl8 +tvidl7: +mov eax, [img2x] +sub eax, [corx] +mov [endx], eax +tvidl8: + +mov eax, [endy] ; calculate Y length +sub eax, [starty] +cmp eax, 0 +jle emu +mov [lengthy], eax + +mov eax, [endx] ; calculate X length +sub eax, [startx] +cmp eax, 0 +jle emu +mov [lengthx], eax + +mov eax, [starty] ; calculate img1 start address +mov ebx, [img1x] +sub edx, edx +mul ebx +add eax, [img1a] +add eax, [startx] +mov [img1start], eax + +mov eax, [cory] ; calculate img2 start address +add eax, [starty] +mov ebx, [img2x] +sub edx, edx +mul ebx +add eax, [img2a] +add eax, [corx] +add eax, [startx] +mov [img2start], eax + +tvidl9: +mov ebx, [img1start] +mov ecx, [lengthx] +mov edx, [img2start] + +tmemmove: ; ebx - from, edx - to, ecx - amount +cmp ecx, 0 +je tl11 +mov al, [es:ebx] +cmp al, 255 +je tl12 +mov [es:edx], al +tl12: +inc ebx +inc edx +dec ecx +jmp tmemmove +tl11: + +mov eax, [img1x] +add [img1start], eax +mov eax, [img2x] +add [img2start], eax +dec dword [lengthy] +cmp [lengthy], 0 +jg tvidl9 + +jmp emu diff --git a/emulator/vidput.inc b/emulator/vidput.inc index 7e7e793..091f87a 100644 --- a/emulator/vidput.inc +++ b/emulator/vidput.inc @@ -1,146 +1,177 @@ -; part of virtual processor, emulator for FIFTH - - -xvidput: -mov ebx, edi ; read data from stack, and save it to variables -mov eax, [es:ebx] -mov [cory], eax -add ebx, 4 -mov eax, [es:ebx] -mov [corx], eax - -add ebx, 4 -mov eax, [es:ebx] -add eax, [xms_addr] -mov ecx, [es:eax] -mov [img2x], ecx -add eax, 4 -mov ecx, [es:eax] -mov [img2y], ecx -add eax, 4 -mov [img2a], eax - -add ebx, 4 -mov eax, [es:ebx] -add eax, [xms_addr] -mov ecx, [es:eax] -mov [img1x], ecx -add eax, 4 -mov ecx, [es:eax] -mov [img1y], ecx -add eax, 4 -mov [img1a], eax - -add ebx, 4 -mov edi, ebx - -cmp dword [cory] , 0 ; calculate Y start -jl vidl1 -mov dword [starty], 0 -jmp vidl2 -vidl1: -mov eax, [cory] -neg eax -mov [starty], eax -vidl2: - -cmp dword [corx] , 0 ; calculate X start -jl vidl3 -mov dword [startx], 0 -jmp vidl4 -vidl3: -mov eax, [corx] -neg eax -mov [startx], eax -vidl4: - -mov eax, [cory] ; calculate Y end -add eax, [img1y] -cmp eax, [img2y] -jg vidl5 -mov eax, [img1y] -mov [endy], eax -jmp vidl6 -vidl5: -mov eax, [img2y] -sub eax, [cory] -mov [endy], eax -vidl6: - -mov eax, [corx] ; calculate X end -add eax, [img1x] -cmp eax, [img2x] -jg vidl7 -mov eax, [img1x] -mov [endx], eax -jmp vidl8 -vidl7: -mov eax, [img2x] -sub eax, [corx] -mov [endx], eax -vidl8: - -mov eax, [endy] ; calculate Y length -sub eax, [starty] -cmp eax, 0 -jle emu -mov [lengthy], eax - -mov eax, [endx] ; calculate X length -sub eax, [startx] -cmp eax, 0 -jle emu -mov [lengthx], eax - -mov eax, [starty] ; calculate img1 start address -mov ebx, [img1x] -sub edx, edx -mul ebx -add eax, [img1a] -add eax, [startx] -mov [img1start], eax - -mov eax, [cory] ; calculate img2 start address -add eax, [starty] -mov ebx, [img2x] -sub edx, edx -mul ebx -add eax, [img2a] -add eax, [corx] -add eax, [startx] -mov [img2start], eax - -vidl9: -mov ebx, [img1start] -mov ecx, [lengthx] -mov edx, [img2start] -call memmove - -mov eax, [img1x] -add [img1start], eax -mov eax, [img2x] -add [img2start], eax -dec dword [lengthy] -cmp [lengthy], 0 -jg vidl9 - -jmp emu - -cory dd 0 -corx dd 0 -img2x dd 0 -img2y dd 0 -img2a dd 0 -img1x dd 0 -img1y dd 0 -img1a dd 0 - -starty dd 0 -startx dd 0 -endy dd 0 -endx dd 0 -lengthx dd 0 -lengthy dd 0 - -img1start dd 0 -img2start dd 0 +; Blit image without transparency +; +; Stack Effect: addr1 addr2 x y -- +; +; Copies a portion of image1 to image2 at the specified (x, y) +; coordinates with clipping. Every pixel is copied regardless of value. +; +; Parameters: +; - addr1: Address of the source image structure (width, height, data) +; - addr2: Address of the destination image structure +; - x: X-coordinate in destination where to start copying +; - y: Y-coordinate in destination where to start copying +; +; Image Structure Format: +; - Offset 0: Image width (32-bit) +; - Offset 4: Image height (32-bit) +; - Offset 8: Base address of image data (32-bit pointer) +; +; Example: +; 0x1000 ; Source image structure +; 0x2000 ; Destination image structure +; 50 ; x +; 50 ; y +; vidput +; +; Memory layout before execution: +; [es:edi] = y +; [es:edi+4] = x +; [es:edi+8] = addr2 +; [es:edi+12] = addr1 +; +; Memory layout after execution: +; Destination image updated with source image data + +xvidput: +mov ebx, edi ; read data from stack, and save it to variables +mov eax, [es:ebx] +mov [cory], eax +add ebx, 4 +mov eax, [es:ebx] +mov [corx], eax + +add ebx, 4 +mov eax, [es:ebx] +add eax, [xms_addr] +mov ecx, [es:eax] +mov [img2x], ecx +add eax, 4 +mov ecx, [es:eax] +mov [img2y], ecx +add eax, 4 +mov [img2a], eax + +add ebx, 4 +mov eax, [es:ebx] +add eax, [xms_addr] +mov ecx, [es:eax] +mov [img1x], ecx +add eax, 4 +mov ecx, [es:eax] +mov [img1y], ecx +add eax, 4 +mov [img1a], eax + +add ebx, 4 +mov edi, ebx + +cmp dword [cory] , 0 ; calculate Y start +jl vidl1 +mov dword [starty], 0 +jmp vidl2 +vidl1: +mov eax, [cory] +neg eax +mov [starty], eax +vidl2: + +cmp dword [corx] , 0 ; calculate X start +jl vidl3 +mov dword [startx], 0 +jmp vidl4 +vidl3: +mov eax, [corx] +neg eax +mov [startx], eax +vidl4: + +mov eax, [cory] ; calculate Y end +add eax, [img1y] +cmp eax, [img2y] +jg vidl5 +mov eax, [img1y] +mov [endy], eax +jmp vidl6 +vidl5: +mov eax, [img2y] +sub eax, [cory] +mov [endy], eax +vidl6: + +mov eax, [corx] ; calculate X end +add eax, [img1x] +cmp eax, [img2x] +jg vidl7 +mov eax, [img1x] +mov [endx], eax +jmp vidl8 +vidl7: +mov eax, [img2x] +sub eax, [corx] +mov [endx], eax +vidl8: + +mov eax, [endy] ; calculate Y length +sub eax, [starty] +cmp eax, 0 +jle emu +mov [lengthy], eax + +mov eax, [endx] ; calculate X length +sub eax, [startx] +cmp eax, 0 +jle emu +mov [lengthx], eax + +mov eax, [starty] ; calculate img1 start address +mov ebx, [img1x] +sub edx, edx +mul ebx +add eax, [img1a] +add eax, [startx] +mov [img1start], eax + +mov eax, [cory] ; calculate img2 start address +add eax, [starty] +mov ebx, [img2x] +sub edx, edx +mul ebx +add eax, [img2a] +add eax, [corx] +add eax, [startx] +mov [img2start], eax + +vidl9: +mov ebx, [img1start] +mov ecx, [lengthx] +mov edx, [img2start] +call memmove + +mov eax, [img1x] +add [img1start], eax +mov eax, [img2x] +add [img2start], eax +dec dword [lengthy] +cmp [lengthy], 0 +jg vidl9 + +jmp emu + +cory dd 0 +corx dd 0 +img2x dd 0 +img2y dd 0 +img2a dd 0 +img1x dd 0 +img1y dd 0 +img1a dd 0 + +starty dd 0 +startx dd 0 +endy dd 0 +endx dd 0 +lengthx dd 0 +lengthy dd 0 + +img1start dd 0 +img2start dd 0 -- 2.20.1