Solved

DirectDraw inline assembly fill_screen()

Posted on 1997-05-18
7
354 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 50 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mixed results 10 79
mixing C++ & C# in Vis Studio 2013 7 141
Alternative to visual sourcesafe 2 114
Authentication of Web Services 3 49
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now