News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

why does this give me an error ?

Started by hfheatherfox07, January 31, 2013, 08:22:19 PM

Previous topic - Next topic

hfheatherfox07


This fails ->    .if x >= 0 && x < ScreenWidth && y >= 0 && y < ScreenHeight

I found this: see next post
dibEngine(converted to assembly)


I can not post the link here , but one of the posters there ( that I know uses this a lot )posted this :

In the PutPixel procedure you'll need to put a check when the pixel is outside the canvas to not plot it. This can make the application crash because you're writting to memory outside the screen buffer:

SPixel PROC x:DWORD, y:DWORD, colour:DWORD
   pushad
   mov   edi, [canvas_buffer]
   .if x >= 0 && x < ScreenWidth && y >= 0 && y < ScreenHeight
      mov eax,y
      imul eax,ScreenWidth
      add eax,x
      shl eax,2
      add edi,eax
      mov eax,colour
      mov dword ptr [edi],eax
   .endif
   popad
   ret
SPixel endp


Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Here is a copy of the Original Post ( rather than linking that site )

Original Post:

Based off Wiccaan's dibEngine written for C++, just converted into assembly.

Still in beta.

Usage:

In a new project, with your other includes:
include dibEngine.inc

After creating your window:

invoke CreateWindowEx,0,addr lpclassname,addr lpwindowname,80000000h,100,100,400,300,0,0,esi,0      ;sample window
            mov hwnd,eax
            invoke dib_SetHwnd,hwnd
            invoke dib_InitCanvas,400,300


Your lovely pallette is now all set for dib'ing. Now in either your main program loop(message processing), a WM_TIMER case, or, if the image is static, before the main game loop, you can make a series of calls to drawing functions - the current build includes dib_PutPixel, and dib_DrawButton:


            invoke dib_PutPixel,100,100,0,0,255              ;x,y,r,g,b
            invoke dib_DrawButton,200,200,offset lpclassname,0   ;x,y,text,bHover


Now in WM_PAINT:

invoke dib_UpdateCanvas

That's it! All you need to draw static pixels and buttons.;p

Just kidding, more support is on the way, but just wanted to release working code to show that I'm still alive.

A special thanks to Wiccaan, STN, and KSBunker, aswell as shoutouts to pandas and DeltronZero.

Attached is an example program, and the main dibEngine.inc file.

Demonstration of button-drawing:
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

.if x >= 0 && x < ScreenWidth && y >= 0 && y < ScreenHeight

you are trying to compare one memory operand with another memory operand
the simplest way to fix this is to get "x" and "y" into registers
    mov eax,y
    mov ecx,x
    .if (ecx>=0) && (ecx<ScreenWidth) && (eax>=0) && (eax<ScreenHeight)
        imul eax,ScreenWidth
        add eax,ecx
;
;

you could probably put ScreenWidth in EDX prior to the ".if" to create more efficient code

hfheatherfox07

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Well the original atachment works well
I have no idea why that poster recommended changing the set pixel proc to include a check
Now it does not draw pixels lol

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

this can be simplified
    mov eax,y
    mov ecx,x
    mov edx,ScreenWidth
    .if (ecx<edx) && (eax<ScreenHeight)
        imul eax,edx
        add eax,ecx
;
;


but i doubt that would stop it from drawing pixels
verify that ScreenWidth and ScreenHeight are set to valid values

hfheatherfox07

I made those changes , but it won't draw ?
lol that one pixel is gone , and so is the button colour
Did you get it to work?
When I invoked the proc I invoked with 2 less variables and used a hex value for the colour instead of 3
The (r,b,g)

:(
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

this seems to work
dib_PutPixel proc x:DWORD, y:DWORD, r:BYTE, g:BYTE, b:BYTE
                mov   ecx,x
                mov   ebx,ScreenWidth
mov   eax,y
                .if (ecx<ebx)&&(eax<ScreenHeight)
    imul  eax,ebx
    movzx ebx,byte ptr g
                    add   eax,ecx
    mov   bh,r
    shl   ebx,8
                    mov   ecx,lpCanvasBuffer
    mov   bl,b
    mov   [ecx+eax*4],ebx
                .endif
ret
dib_PutPixel endp

EDX has to be preserved for some reason and EBX doesn't (i guess)

hfheatherfox07

So you need to have r,b,g ......
Maybe that guy was messing with people ? ( I have seen some of the example he does no source)
I thought the change would be good if you can eliminate those and use hex colour

P.S
Is there an app that gives you an image's pixel coordinates + r,b,g for each pixel?

This guy does multi colour letters all plotted ????
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

no - you can use RGB
you will have to change the PROTO
and - you will have to change everyplace this function is used to pass an RGB

dib_PutPixel proc x:DWORD, y:DWORD, crRGB:COLORREF
                mov   ecx,x
                mov   ebx,ScreenWidth
mov   eax,y
                .if (ecx<ebx)&&(eax<ScreenHeight)
    imul  eax,ebx
                    add   eax,ecx
                    mov   ebx,crRGB
                    mov   ecx,lpCanvasBuffer
    mov   [ecx+eax*4],ebx
                .endif
ret
dib_PutPixel endp


if you have the colors as individual bytes in memory, you can use the RGB macro
otherwise, you can assign them as EQUates or something
COLORREF = 65536*Red + 256*Green + Blue
where Red, Green, and Blue are 0 to 255

MichaelW

Quote
COLORREF = 65536*Red + 256*Green + Blue

That reverses the order of the color components relative to the GDI RGB macro:

#define RGB(r,g,b)          ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))



#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void main()
{
  BYTE r=1,g=2,b=3;
  COLORREF rgb1, rgb2;
  rgb1 = RGB(r,g,b);
  rgb2 = 65536*r + 256*g + b;
  printf("%Xh\n%Xh\n", rgb1, rgb2);
  getch();
}


30201h
10203h


But duplicates the RGB component order for GDI+:

enum
    {
        AlphaShift  = 24,
        RedShift    = 16,
        GreenShift  = 8,
        BlueShift   = 0
    };

    // Assemble A, R, G, B values into a 32-bit integer
   
    static ARGB MakeARGB(IN BYTE a,
                         IN BYTE r,
                         IN BYTE g,
                         IN BYTE b)
    {
        return (((ARGB) (b) <<  BlueShift) |
                ((ARGB) (g) << GreenShift) |
                ((ARGB) (r) <<   RedShift) |
                ((ARGB) (a) << AlphaShift));
    }







Well Microsoft, here's another nice mess you've gotten us into.

dedndave

right, Michael - my mistake
those are RGBQUAD's, not COLORREF's
(well - modified versions of RGBQUAD's - lol)

hfheatherfox07

Quote from: dedndave on February 01, 2013, 08:25:09 AM
no - you can use RGB
you will have to change the PROTO
and - you will have to change everyplace this function is used to pass an RGB

I meant the poster does not use r,g,b
His proto has colour : DWORD
So I assume he invokes set pixel with colour hex

What I said was that we can not use that, or can we?
That is what I tried with your first proc and it did not work....

This example is neat but I do not anticipate using it much
Unless there is an app that converts images to pixel coordinates
It would take for ever to plot image

There is a C example were I downloaded this but I don't get how they made it work
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

@MichaelW
I was actually looking on the net Today for a batch file to compile C

Do you know how? If so and you have time can you attach the above code with batch file to compile ?

I use batch files for masm all the time with notepad2 to edit and compile ,
Never found a C example

Thank you!


And sorry for asking
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

i would imagine you can use a command-line exe to compile with most C compilers
for microsoft, i think it's CL.EXE - you should be able to get the switches with /?
or look for it on MSDN