Solved

DirectDraw inline assembly fill_screen()

Posted on 1997-05-18
7
352 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

19 Experts available now in Live!

Get 1:1 Help Now