Posts: 442
Threads: 107
Joined: Feb 2005
is it possible to make a pixel drawing function in asm? if so, anybody got an example.... this has been oddly interesting to me here leately
i'm also looking for documents that talk about graphics, and assembly... if anybody has any good linx
url=http://www.random-seed.net] [/url]
Posts: 140
Threads: 13
Joined: Apr 2005
Quote:is it possible to make a pixel drawing function in asm? if so, anybody got an example.... this has been oddly interesting to me here leately
i'm also looking for documents that talk about graphics, and assembly... if anybody has any good linx
no link but you must mov values (x,y,color) in registers and calc (mul add) the pixel position in videomemory.
look this short example and compare it's speed
i'm shure you will do more gfx in assemler.
let me know if you need more infos or help.
Joshy
Code: option explicit
'asm.bas
#define scr_w 1024
#define scr_h 768
sub set_clip32(byval memory as integer ptr,byval x as integer,byval y as integer,byval c as integer)
if (x<0) or (x>(scr_w-1)) then exit sub
if (y<0) or (y>(scr_h-1)) then exit sub
x=x shl 2:y=y shl 2
asm
mov dword ptr edi,[memory] ' videoadr
mov eax,scr_w
mul dword ptr [y] ' adr = y * 4 * scr_W
add eax,dword ptr [x] ' adr = y * 4 * scr_w + x * 4
mov ebx,dword ptr [c]
mov [edi+eax],ebx ' poke videoadr + y * 4 * scr_w + x * 4,color
end asm
end sub
sub set_32(byval memory as integer ptr,byval x as integer,byval y as integer,byval c as integer)
x=x shl 2:y=y shl 2
asm
mov dword ptr edi,[memory]
mov eax,scr_w
mul dword ptr [y]
add eax,dword ptr [x]
mov ebx,dword ptr [c]
mov [edi+eax],ebx
end asm
end sub
'!!! only with screenwidth=1024 !!!
sub set_fast32(byval memory as integer ptr,byval x as integer,byval y as integer,byval c as integer)
asm
mov eax, dword ptr [y]
shl eax, 10 ' = y * 1024
add eax, dword ptr [x] ' = y * 1024 + x
shl eax, 2 ' = (Y * 1024 + x) * 4
add eax, dword ptr [memory]
mov ebx, dword ptr [c]
mov dword ptr [eax],ebx
end asm
end sub
sub pset_32(byval x as integer,byval y as integer,byval c as integer)
pset (x,y),c
end sub
screenres scr_w,scr_h,32
dim as integer ptr videomemory
dim as integer i,x,y
dim as double stime,etime,pset_32time,set_clip32time,set_32time,set_fast32time
screenlock:videomemory=screenptr
stime=timer
for i=1 to 100
for y=0 to scr_h-1
for x=0 to scr_w-1
set_clip32 videomemory,x,y,rgb(255,0,0)
next
next
next
etime=timer
set_clip32time=etime-stime
screenunlock
screenlock:videomemory=screenptr
stime=timer
for i=1 to 100
for y=0 to scr_h-1
for x=0 to scr_w-1
set_32 videomemory,x,y,rgb(0,255,0)
next
next
next
etime=timer
set_32time=etime-stime
screenunlock
screenlock:videomemory=screenptr
stime=timer
for i=1 to 100
for y=0 to scr_h-1
for x=0 to scr_w-1
set_fast32 videomemory,x,y,rgb(0,0,255)
next
next
next
etime=timer
set_fast32time=etime-stime
screenunlock
screenlock
stime=timer
for i=1 to 100
for y=0 to scr_h-1
for x=0 to scr_w-1
pset_32 x,y,rgb(255,255,255)
next
next
next
etime=timer
pset_32time=etime-stime
screenunlock
print "set_clip32 ="; set_clip32time
print "set_32 ="; set_32time
print "set_fast32 ="; set_fast32time
print "pset(x,y) ="; pset_32time
sleep
end
sorry about my english
Posts: 442
Threads: 107
Joined: Feb 2005
thnx! i'll let ya know if i have any questions
url=http://www.random-seed.net] [/url]
Posts: 357
Threads: 118
Joined: Oct 2004
I have a question. Suppose I wanted to use set_fast32 add screenres 320,200. It's been a really long time since I've used asm. This is what I did:
Quote:sub set_fast32(byval x as integer,byval y as integer,byval c as integer)
y = y * 320
asm
mov eax, dword ptr [y]
add eax, dword ptr [x]
shl eax, 2
add eax, dword ptr [buffer]
add eax, 4 'double buffering requires this too
mov ebx, dword ptr [c]
mov dword ptr [eax],ebx
end asm
end sub
It's a quick fix, but I would prefer to have shl 8 + shl 6 in there, but I just can't remember how to do it.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Posts: 320
Threads: 9
Joined: Dec 2004
Code: sub set_fast32(byval x as integer, byval y as integer, byval c as integer)
asm
mov eax, dword ptr [y]
mov ebx, eax
' multiply y by 320
shl eax, 6
shl ebx, 8
add eax, ebx
' add x
add eax, dword ptr [x]
' add the buffer offset and the size of the surface info
add eax, dword ptr [buffer]
add eax, 4
' copy the colour in
mov ebx, dword ptr [c]
mov dword ptr [eax], ebx
end asm
end sub
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Posts: 357
Threads: 118
Joined: Oct 2004
thanks, i need one more piece of help.
Quote:function point32 (x as integer, y as integer, byval memory as integer ptr) as integer
asm
mov eax, dword ptr [y]
mov ebx, eax
' multiply y by 320
shl eax, 6
shl ebx, 8
add eax, ebx
' add x
add eax, dword ptr [x]
' add the buffer offset and the size of the surface info
add eax, dword ptr [memory]
add eax, 4
'return
'deref eax
mov [function], eax
end asm
END function
return the pointer to the place in memory when there colour is. How do I deference it?
I tried turning the function to return a pointer and use *, but that caused it to crash. I thought asm had a deref function, but I must be mistaking.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Posts: 140
Threads: 13
Joined: Apr 2005
First of all 32 means 32 bit per color=4 bytes
the formular are adr=y*320*4 + x*4
Code: mov eax, dword ptr [y]
mov ebx, eax
' multiply y by 1280=(320*4)
shl eax, 10 '*1024
shl ebx, 8 '* 256
add eax, ebx
same for x
Code: ' add x*4
mov ebx, dword ptr [x]
shl ebx,2 '*4
add eax,ebx
and if you will get an pointer you must declare it too and x,y are values not addresses use byval. Code: function point32 (byval x as integer,byval y as integer, byval memory as integer ptr) as integer ptr
Joshy
Code: function point32 (byval x as integer,byval y as integer, byval memory as integer ptr) as integer ptr
asm
mov eax, dword ptr [y]
mov ebx, eax
' multiply y by 320*4
shl eax, 10 '*1024
shl ebx, 8 '* 256
add eax, ebx
' add x*4
mov ebx, dword ptr [x]
shl ebx,2
add eax,ebx
' add the buffer offset and the size of the surface info
mov ebx,dword ptr [memory]
add eax,ebx
add eax, 4
'return
'deref eax
mov [function], eax
end asm
END function
dim memory as integer ptr
dim col as integer
screenres 320,200,32
screenlock
memory = screenptr
pset(99,99),&H123456
memory=point32(99,99,memory)
memory-=1 ' 4 bytes !!!
col=*memory
screenunlock
? "color on (99,99)=";hex(col)
sleep
sorry about my english
Posts: 484
Threads: 14
Joined: Apr 2005
DJ peters, i tried your example, and on my machine it seems to go to a black screen and do nothing, locked in a loop maybe? any ideas?
EVEN MEN OF STEEL RUST.
Posts: 357
Threads: 118
Joined: Oct 2004
There isn't supposed to be anything there. The only pixel that was coloured is (99,99). Thanks for clearing it up for me, these routines are sooo fast.
There is no way to dereference using asm and have the function return an integer? I have a feeling that I will forget a * somewhere and spend hours pulling my hair out over it.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Posts: 484
Threads: 14
Joined: Apr 2005
thats bizarre. i tried it again , and this time it worked
i got
set_clip 4.1
set 32 3.9
setfast32 1.5
pset 12.9
EVEN MEN OF STEEL RUST.
|