Sign in to follow this  
nick22891

Inline assembly pixel manipulation.

Recommended Posts

Can someone direct me to a tutorial where i can learn the basics of graphics manipulation with inline assembly? I want to write an emulator and was told i would need to run the graphics with assembly code to make it fast enough. P.S. I am using Dev C++. Don't even bother telling me to switch compilers.

Share this post


Link to post
Share on other sites
Quote:
Original post by nick22891
Can someone direct me to a tutorial where i can learn the basics of graphics manipulation with inline assembly? I want to write an emulator and was told i would need to run the graphics with assembly code to make it fast enough.
You were told wrong. There's two ways you'll be able to write better assembly than the compiler:
1. Have been writing assembly for many, many years and have at least equal knowledge of assembly as the compiler writers.
2. Have advance knowledge of some optimisations that can be performed, for instance using prefetch or SSE instructions. Although the performance benifit you'll get from that is almost certainly going to be negligible.

Overall, don't worry about it. Write your emulator in C/C++ and then optimise parts as needed. If you're writing an emulator, you're probably emulating something a fair bit slower than the machine running the emulator anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
2. Have advance knowledge of some optimisations that can be performed, for instance using prefetch or SSE instructions. Although the performance benifit you'll get from that is almost certainly going to be negligible.
And you're still going to have much better results using SSE intrinsics than you are with inline assembly.

It's quite difficult to even write a working emulator, let alone write one that is fast. Make one that works first, and then move from there. And yes, you'll have to use a library, whether it's SDL, D3D, OGL, or something else.

Share this post


Link to post
Share on other sites
Quote:
Original post by nick22891
But how will i deal with the graphics rendering? i dont like libraries. DO i have to use them?
Unless you're writing your own OS, you're already using libraries. For raw graphics output, DirectDraw is probably the fastest you'll get since it can basically give you a large array that represents the screen (Locking a surface).

Even using assembly (inline or otherwise) you can't just magically write to video memory.

Share this post


Link to post
Share on other sites
Quote:

i dont like libraries. DO i have to use them?

Yes, you have to use them.

And you don't really dislike libraries, because if you did, you wouldn't be using them. Which means you'd be doing lots of really unpleasant stuff by hand, including replacing all of the stuff that the C runtime and various supporting OS libraries are doing for you. I find that people who proclaim they "don't like using libraries" are shocked to discover exactly how many libraries and supporting tools they depend on just to get to the point where main() is called.

On a similar note, a good programmer knows the value of tools and the cost of reinventing the wheel for trivialities. Pushing pixels on the screen is one of those cases where you use a library, because the alternative is man-years of effort for something that is, at best, as decent as the default facilities available to you. In short; not worth it.

Note that you could pretend to manually muck around with pixels by writing a DOS application (a real DOS application, not a console-mode application) and running that under the DOS VM. But that would require switching compilers; Dev-C++ (which is, incidentally, an IDE, not a compiler) does not ship with a DOS compiler (as far as I know, at least, MinGW only produces Win32 applications).

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Note that you could pretend to manually muck around with pixels by writing a DOS application (a real DOS application, not a console-mode application) and running that under the DOS VM. But that would require switching compilers; Dev-C++ (which is, incidentally, an IDE, not a compiler) does not ship with a DOS compiler (as far as I know, at least, MinGW only produces Win32 applications).


That is correct, you would have to replace MinGW with DJGPP.

Share this post


Link to post
Share on other sites
I just checked out the link to the page the guy posted and im convinced that libraries are the way to go. I thought they were too complicated but now i see how simple they are by comparison.

Share this post


Link to post
Share on other sites
Quote:
Original post by nick22891
But how will i deal with the graphics rendering? i dont like libraries. DO i have to use them?


"But how will I deal with the drawing? I don't like ball-point pens. Do I have to use them (or will a quill and crushed berries work fine)?"

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
Enjoy, welcome to ~20 years ago. Sometimes giving people exactly what they ask for is the best way for them to find out they didn't really wanted it in the first place.


Quote:
# Scramble (C or C++, you decide!)

Quote:
Copyright 1997-2001


Are you trying to kill me? ;_;

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
Enjoy, welcome to ~20 years ago. Sometimes giving people exactly what they ask for is the best way for them to find out they didn't really wanted it in the first place.


Ironically, if you were to use advice posted there, the resulting assembly-based code would almost certainly be slower than simply writing it in plain C or C++, and compiling it on modern compiler.

Even using state of the art assembly there would result in sub-optimal run-time due to lack of extended instructions, or OS primitives available today.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this