Can't beat this:
; void drawline(int x1:eax, int x2:ecx, int y1:edx, int colour:edi);
; void put_pixel(int x:esi, int y:eax, int colour:edi)/P(ecx,edx,ebx,esi,edi);
drawline:
mov esi, eax ; esi = x1
sub ecx, eax ; ecx = x2 - x1
sub ebx, edx ; ebx = y2 - y1
push edx
shl ebx, 16 ; ebx = (y2 - y1) <<16
xchg eax, ebx ; eax = (y2 - y1) <<16, ebx = x1
cdq ; edx:eax = (y2 - y1) <<16
div ecx ; eax = ((y2 - y1) <<16) / (x2 - x1) = m
pop edx
inc ecx ; ecx = x2 - x1 + 1
shl edx, 16 ; edx = f = y1 << 16
xchg eax, ebx ; ebx = m
; eax : g
; ecx : x2 - x1 + 1
; edx : f
; ebx : m
; esi : x
lineloop:
mov eax, edx
add eax, 32768
call put_pixel
inc esi
add edx, ebx
loop lineloop
ret
Another thing I noticed when writing the above code is that his rounding is wrong: to get the standard half+up rounding, 3276
8, i.e. 1/2, needs to be added. Otherwise it's an off-by-1 rounding error.
>>14
Benchmark this... if you can.