nuclear@22: ; vim:set ft=nasm: nuclear@22: segment code use32 nuclear@22: nuclear@22: ; void swap_buffers_asm(void *dest, void *src, int xsz, int ysz, int bpp) nuclear@22: ; dest -> eax nuclear@22: ; src -> edx nuclear@22: ; xsz -> ebx nuclear@22: ; ysz -> ecx nuclear@22: ; bpp -> [ebp + 8] (after pushing ebp) nuclear@22: global swap_buffers_asm_ nuclear@22: swap_buffers_asm_: nuclear@22: push ebp nuclear@22: mov ebp, esp nuclear@22: nuclear@22: mov edi, eax ; let's hold dest ptr in edi, frees up eax nuclear@22: mov esi, edx ; let's hold src ptr in esi, frees up edx nuclear@22: ; calculate pixel count -> ecx, frees up ebx nuclear@22: mov eax, ebx nuclear@22: mul ecx nuclear@22: mov ecx, eax ; now ecx = xsz * ysz nuclear@22: nuclear@22: mov eax, [ebp + 8] ; eax <- bpp nuclear@22: cmp eax, 32 nuclear@22: je .bpp32 nuclear@22: cmp eax, 24 nuclear@22: je .bpp24 nuclear@22: cmp eax, 16 nuclear@22: je .bpp16 nuclear@22: ; invalid bpp, ignore nuclear@22: jmp .done nuclear@22: nuclear@22: .bpp32: ; 32bit block transfer, no conversion nuclear@22: rep movsd ; esi, edi, and ecx already loaded, just go... nuclear@22: jmp .done nuclear@22: nuclear@22: .bpp24: ; 32bpp -> 24bpp conversion (LSB-first), 1 byte overrun! nuclear@22: movsd ; transfer a full 32bit chunk and inc esi,edi by 4 nuclear@22: dec edi ; backtrack dest one byte after last transfer nuclear@22: dec ecx nuclear@22: jnz .bpp24 nuclear@22: jmp .done nuclear@22: nuclear@22: .bpp16: ; fuck 16bpp for now (TODO) nuclear@22: .done: nuclear@22: pop ebp nuclear@22: ret