Solved

DirectDraw inline assembly fill_screen()

Posted on 1997-05-18
7
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RIA: CancelEdit() doesn't change entity back to Unchanged status 5 43
Event ID 10010 3 77
Slow process to read Excel 15 148
Where did System.Data.Objects go? 2 59
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.  …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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