Solved

DirectDraw inline assembly fill_screen()

Posted on 1997-05-18
7
365 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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
Windows Standards for file storage. 3 39
Question to Pivot table 1 75
Licensing Sharepoint 2016 for developers 11 100
"Video DataSource is Offline or not responding"  - why? 1 171
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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