Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DirectDraw inline assembly fill_screen()

Posted on 1997-05-18
7
Medium Priority
?
374 Views
Last Modified: 2013-12-03
i am having a lot of fun with DirectDraw at the moment, but i'm trying to do some inline assembly coding that essentially involves direct screen writes, which thankfully, we can now do because of DirectX.  it's about time!

so, anyway, the following code works just fine to fill the screen with "color" on a 640x480x8 resolution direct draw primary surface.

      video_buffer = (unsigned char far *)ddsd.lpSurface;
      memset(video_buffer, color, 640*480*2);
      video_buffer[640*430+200] = 123;

this code fills the screen with "color" and plots the point 640*430+200 in the color 123 (some sort of green color :)

because i am interested in speed and not elegance, i tried to code this same function in inline assembly and that code looks like this:

// fill the video buffer using inline assembly - it's fast!
_asm
{
   les di,video_buffer          ; point es:di to video buffer
   mov al,BYTE PTR color        ; move the color into al
   mov ah,al                    ; replicate color into ah
   mov cx,640*480               ; number of words to fill
   rep stosw                    ; move the color into the video buffer fast!
}

the application gets to this code and nothing happens.  unfortunately, it also causes the program to quit.  since i am grabbing the entire screen (DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) i cannot debug the program. sufice it to say that the fill function is entered, and if i don't use the inline assembly code, everything works as it's supposed to work.  if i try to use my inline assembly instead of memset, it does not work and the application dies.

help?  are there many of you using DirectDraw?  nebulous question :)

thanks much.

scribs
scribs@noshame-press.org
setting children free world-wide!!
no shame press
p.o. box 40039
san francisco, ca 94140-0039
415.641.4175
rape crisis hotline (24hr): 800.796.7363/pin: 1099608
0
Comment
Question by:scribbles
  • 4
  • 3
7 Comments
 

Author Comment

by:scribbles
ID: 1397466
Edited text of question
0
 

Author Comment

by:scribbles
ID: 1397467
Edited text of question
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1397468
Since you are using DirectX, your program must be 32-bit. So, video_buffer is a 32-bit pointer. But it seems that your assembly code is 16-bit. di is a 16-bit register. Replace it with 32-bit assembly code (use edi, ecx,...).

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:scribbles
ID: 1397469
thanks chensu.  i was wondering if maybe you could tell me where i can learn more about 32-bit assembly code.  for the time-being, however, is it good enough to just stick the 'e' in front of all the registers?  is that the naming convention for 32-bit registers?  and are there any exceptions to that convention?

thanks again.  that was quite a helpful answer!

scribs
0
 

Author Comment

by:scribbles
ID: 1397470
i tried modifying the code to the following:

les edi,video_buffer
mov eal,BYTE PTR color
mov eah,eal
mov ecx,640*480
rep stosw

and i get the following errors:

mov eah,eal      ; error C2415: improper operand type
mov ecx,640*480  ; error C2415: improper operand type

----
it's been a long time since i've coded assembly.  i lost my reference manual, and anyway, that was for the 486 processor.  do i need to change my compiler settings to have a /G1 or /G2 switch for extended instructions on later models of the processor?

anyway, thanks for the help.  i'm sort of understanding but again, it's been a while.

scribs

0
 
LVL 23

Expert Comment

by:chensu
ID: 1397471
I used to program in Intel 80x86 assembly language. But I haven't done it for so long time. I can't find a reference manual. You can get it from Intel. As far as I remember, you can also get some example code from some Microsoft samples (muldiv32.c contains some 32-bit inline assembly code).

0
 
LVL 23

Expert Comment

by:chensu
ID: 1397472
I found some information on the inline assembly language. Please see the documentations that comes with Visual C++ or MSDN CDs:
Visual C++ Books/C/C++/Programming Techniques/Using the Inline Assembler/.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question