News:

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

Main Menu

"Hello masm32", not a BOT, new member

Started by LordAdef, January 22, 2017, 09:42:24 AM

Previous topic - Next topic

hutch--

 :biggrin:

You know the magic MASM rule, its not a bug, its a feature you need to understand. Unless Intel have sneaked an undocumented capacity that nobody knew about,multiple index's don't have a matching opcode so they don't fly. RE : MASM error checking, it is more often than not unintelligible nonsense, its a tool written for people who know NOT to try and invent opcodes of their own. If they do they get garbage on the screen.

MASM has always had the answer to fast reliable code, write it with no errors and it will run properly, if not go back and learn how to write code with no errors.  :P

LordAdef

Quotelea rdx, [rcx+rdx+rsi+r8+r9+r10+r11+r12+10]      ; eight register addressing!

ok, I'm working and couldn't follow the last page well... Does this aberration actually works?

nidud

#182
deleted

jj2007

Quote from: LordAdef on April 28, 2017, 09:01:13 AMDoes this aberration actually work?

Yes and no:  int 3
  lea rdx, [rcx+rdx+rsi+r8+r9+r10+r11+r12+10]      ; eight register addressing!


x64dbg:00000001400011E5 | CC                       | int3                               |
00000001400011E6 | 4B 8D 54 1C 0A           | lea rdx, qword ptr ds:[r12+r11+A]  |


So ML64 uses the last two registers r12, r11 for the encoding (hex A=dec 10). It "works" if these two registers contain meaningful values. But of course, a good assembler must throw an "invalid opcode" error. It's a fat Micros**t bug, nothing else.

LordAdef

Guys, what do you think?

I´m tweaking the engine and like your opinion. I made some tests using a Double Buffer, instead of doing straight to HDC:

(all in WM_PAINT)
1. Main_Current: I´m printing everything to HDC
2. Main_MapDoubleBuffer: Using a Double Buffer where I only paint the bk map. The rest is still going straight to HDC (It´s the middle groung between the 2 others)
3. Main_All_in_DoubleBuffer: Everything is built in the Back Buffer.

All 3 options attached. Asm file compatible with ml, although my resources are not being joined (I don´t know why, pure ignorance of mine really)

There is a trade here:
-> Main_Current is faster, but flickers
-> All_in_DoubleBuffer is the fastest of the two using double buffer (curiously). Although I´m slower, the feel is more solid, since the image is less flickery.

Would you trade the speed of #1 for visual stability of #3? I inclined to do it.

My benchmarks:
QuoteEverything straight to HDC:
6458 us 6505 us 6544 us 6686 us 6454 us 6362 us 6433 us 6392 us 6306 us 6448 us 6390 us 6447 us 6544 us 6481 us 6899

ONly BK map is sent to Back Buffer, the rest is straight to HDC
7638 us 7766 us 7531 us 7544 us 7531 us 7581 us 7583 us 7596 us 7799 us 7729 us 7787 us 7711 us 7894 us 7698 us 7545

All to Back Buffer
7208 us 7151 us 7344 us 7215 us 7248 us 7112 us 7238 us 7384 us 7279 us 7258 us 7339 us 7165 us 7266 us 7265 us 7285

Cheers Alex

jj2007

I've downloaded all three, and can't find any difference in speed. And all three flicker, not much but equally ::)
This is on Win7-64 and a Core i5 cpu.

LordAdef

Quote from: jj2007 on April 29, 2017, 06:17:23 PM
I've downloaded all three, and can't find any difference in speed. And all three flicker, not much but equally ::)
This is on Win7-64 and a Core i5 cpu.

Any suggestion JJ?

jj2007

   .IF uMsg==WM_CREATE
            invoke pIniFonts, hdc
            mCreateDC


Suggestion: Put all that stuff into the same file, it would be much easier to find it and understand what it does (select the word, hit F3).

More concretely: hdc is a local variable, i.e. it may contain anything. What are you passing to pIniFonts?

LordAdef

Quote from: jj2007 on April 30, 2017, 01:57:13 AM
   .IF uMsg==WM_CREATE
            invoke pIniFonts, hdc
            mCreateDC


Suggestion: Put all that stuff into the same file, it would be much easier to find it and understand what it does (select the word, hit F3).

More concretely: hdc is a local variable, i.e. it may contain anything. What are you passing to pIniFonts?

Ok, checking it out in 10 minutes.
Concerning the paint engine, do you think implementing a new test with the "scroll" Windows function would give me a better flickerless result? A quick test has shown me it may be the case, although the logic imposes some difficulties

jj2007

ScrollWindow must use BitBlt internally, I doubt that it can be much faster.

I am too busy (and too tired) to look into the double buffering, Alex - but if it's done correctly, it should not flicker at all. For comparison, try sizing the Gdi+ example in File/New Masm source; the only item that flickers is the yellow box in the lower right...

Re pIniFonts:
004023A8        ³.  50                      push eax                               ; ÚhObject
004023A9        ³.  FF75 08                 push dword ptr [ebp+8]                 ; ³hDC => [Arg1]
004023AC        ³.  E8 E7010000             call <jmp.&gdi32.SelectObject>         ; ÀGDI32.SelectObject


Returns 0, invalid handle.

LordAdef

I understand JJ, no worries.

Double buffering is not flickering for me. For scrolling, I even think it gets a worse result than compared to double buffering. the three exes in the zip.




LordAdef

QuotepIniFonts proc hdc:DWORD
            ;----------------------------------------- MAP FONT -----------------------------------------------------------------------------------------------------------
            invoke CreateFont,12,0,0,0,400,0,0,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
                                           DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT, chr$("Courier New") ;ADDR FontName1 ;Lucida Console
            mov Font1, eax
            invoke SelectObject, hdc, eax
            mov OldFont, eax
           
            ;---------------------------------------- MAN FONT -----------------------------------------------------------------------------------------------------------
            invoke CreateFont,18,0,0,0,400,0,0,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
                                           DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,  chr$("Arial")
            mov Font2, eax
           
            ;---------------------------------------- LABEL FONT --------------------------------------------------------------------------------------------------------
            invoke CreateFont,52,0,0,0,400,0,0,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
                                           DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT, chr$("Arial Black")
            mov Font3, eax
           
            ;---------------------------------------- LABEL FONT 2 -----------------------------------------------------------------------------------------------------
            invoke CreateFont,28,0,0,0,400,0,0,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
                                           DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT, chr$("Arial")
            mov Font4, eax
           
            ;---------------------------------------- TEST FONT -----------------------------------------------------------------------------------------------------
            invoke CreateFont,12,0,0,0,400,0,0,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
                                           DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT, chr$("MapTst")
            mov Font5, eax

     ret
pIniFonts endp

I´m only using hdc to retrieve the default font, and restore it back when I´m done.
            invoke SelectObject, hdc, eax
            mov OldFont, eax

I made it as a proc but it was previously sitting in there.

jj2007

Quote from: LordAdef on April 30, 2017, 05:52:34 AM
I´m only using hdc to retrieve the default font, and restore it back when I´m done.
            invoke SelectObject, hdc, eax
            int 3
            mov OldFont, eax

If Olly is installed as \Masm32\OllyDbg\ollydbg.exe, hit F6 and have a look at eax and the error message.

Otherwise,
- activate MasmBasic.inc
- OxPT_Susy (disactivates the option, console will be default)
- fonts.asm, line 7:
            invoke SelectObject, hdc, eax
ifdef MbBufferGet
fdeb 4, "SelObj", eax, hdc, $Err$()
endif
            mov OldFont, eax

LordAdef

A quick help, please...


I need to iterate through an array of structures. [ebx*Bullet ] wont do it, but [2*Bullet] does. Pre compile thing? How do I do this?
   xor ecx, ecx
   @@:
   mov edi, offset man.bullets[ecx*Bullet].active
   .IF   dword Ptr [edi] == 1
      printf (" Bullet %d is active\n", dword Ptr [edi])
   .ENDIF
   inc ecx
   cmp ecx, 100
   jnz @B

QuoteBullet STRUCT
           active   dd      ?
               speed   dd     ?
               x      dd      ?
               y      dd      ?               
        Bullet ENDS

        Player STRUCT
           align 4
               x          dd ?
               y          dd ?
             sprite   dd   ?
               frmx   dd   ?
               frmy   dd   ?
               bullets   Bullet   100 dup (<>)  <==== These guys HERE
               kState   dd   ?   
        Player ENDS

QuoteIf Olly is installed as \Masm32\OllyDbg\ollydbg.exe, hit F6 and have a look at eax and the error message.
Thanks, I´ll have a look

Siekmanski

Hi Alex,

Maybe ebx/ecx is trashed by the function "printf" ?

try this,

mov edi,offset Player.bullets
mov esi,0
find_active_bullets:
.if dword ptr[edi].Bullet.active == 1
    printf (" Bullet %d is active\n", esi)
.endif
add edi,sizeof Bullet
inc    esi
cmp    esi, 100
jne find_active_bullets


little hint: you can align the struct to 4 like this,
Player STRUCT 4
Creative coders use backward thinking techniques as a strategy.