Author Topic: Simple Games - Research and Development  (Read 13678 times)

daydreamer

  • Member
  • *****
  • Posts: 2399
  • my kind of REAL10 Blonde
Re: Simple Games - Research and Development
« Reply #120 on: September 17, 2022, 06:57:14 PM »
Wellll, I don't know about you, but I would use text instead of bitmaps to draw all that stuff. And instead of having so many different static controls, just divide your main sudoku cells into virtual compartments (what is it, 9 per cell?) by just computing where to put the text. I think that would be a whole lot simpler.
if you can get away with small text from textout its companions
    mov eax,rv(SetTextColor,hDC,00ff0000h)
    mov eax,rv(SetBkColor,hDC,65535)
SetBkMode(hdc, TRANSPARENT) ; or use OPAQUE
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Simple Games - Research and Development
« Reply #121 on: September 17, 2022, 07:39:13 PM »
GetClientRect apparently does not take the menu height into account

That would surprise me. Do you have code where that happens?

Hint #2: SystemParametersInfo() is your friend.

Especially, SystemParametersInfo(SPI_GETWORKINGAREA) is your friend for getting the "client rect" of the desktop window (I put it in quotes because technically speaking the taskbar sits inside the client rect).

Pseudocode:

Code: [Select]
  invoke SystemParametersInfo, SPI_GETWORKAREA, 0, addr rc_, 0
  Print Str$("sys w=%i", rc_.right), Str$(", h=%i\n", rc_.bottom)
  invoke GetDesktopWindow
  lea edx, rc_
  invoke GetClientRect, eax, edx
  Print Str$("gtc w=%i", rc_.right), Str$(", h=%i\n", rc_.bottom)

Code: [Select]
sys w=1366, h=740
gtc w=1366, h=768

zedd151

  • Member
  • *****
  • Posts: 1968
Re: Simple Games - Research and Development
« Reply #122 on: September 17, 2022, 11:40:37 PM »
GetClientRect apparently does not take the menu height into account
That would surprise me. Do you have code where that happens?
:rolleyes:  Would I post that otherwise?


two exe's one with menu one without.
« Last Edit: September 19, 2022, 08:40:13 AM by swordfish »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: [SOLVED] height of menu...
« Reply #123 on: September 17, 2022, 11:55:52 PM »

       Solved using  GetSystemMetrics, SM_CYMENU. Thanks for that tip, NoCforMe. I had forgotten that it was exactly the place to look for this type of information...


Code: [Select]
        ; This source code written by swordfish @ masm32.com
        include \masm32\include\masm32rt.inc
   
        RegWindow       proto :dword
        WinMain         proto :dword, :dword
        WndProc         proto :dword, :dword, :dword, :dword
        CenterMain      proto :dword, :dword, :dword
        LoadBitmaps     proto :dword, :dword
        Cell            proto :dword, :dword, :dword, :dword, :dword, :dword
        MakeGrid        proto :dword, :dword, :dword, :dword, :dword
        CandGrid        proto :dword, :dword, :dword, :dword, :dword
        SmallCell       proto :dword, :dword, :dword, :dword, :dword, :dword
        CandCells       proto :dword, :dword, :dword, :dword
        AllCandidates   proto :dword, :dword, :dword, :dword
       
        ws              equ WS_BORDER or WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU
        bs              equ WS_VISIBLE or WS_CHILD or SS_NOTIFY or SS_BITMAP
        bks             equ WS_VISIBLE or WS_CHILD or SS_BITMAP
    .const
        wclass          db "GAMECLASS", 0
        sclass          db "STATIC", 0
        about           db "sudoku 2022", 0
        dname           db "sudoku", 0
       
        stcc            dd sclass
        wwc             dd wclass
        nam             dd dname
       
        x1              dd 4
        x2              dd 70
        x3              dd 136
        x4              dd 204
        x5              dd 270
        x6              dd 336
        x7              dd 404
        x8              dd 470
        x9              dd 536
        y1              dd 4
        y2              dd 70
        y3              dd 136
        y4              dd 204
        y5              dd 270
        y6              dd 336
        y7              dd 404
        y8              dd 470
        y9              dd 536
        cx1             dd 1
        cx2             dd 22
        cx3             dd 43
        cy1             dd 1
        cy2             dd 22
        cy3             dd 43
       
    .data?
        include handles.inc
    .data
        wwidth          dd 1024
        wheight         dd 768
        hi              dd 0
        hWnd            dd 0
        prevsel         dd 0
        selected        dd -1
        stringy         db 4 dup (0)
    .code
    start:
        invoke GetModuleHandle, 0
        mov hi, eax
        invoke RegWindow, wwc
        invoke WinMain, wwc, nam
        invoke ExitProcess, eax
       
    WinMain proc cn:dword, dn:dword
    local msg:MSG, Wtx:dword, Wty:dword
        invoke CreateWindowEx, 0, cn, dn, ws, 0, 0, 1111, 768, 0, 0, hi, 0
        mov hWnd, eax
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
 
        invoke LoadMenu, hi, 600
        invoke SetMenu, hWnd, eax
       
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;       
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd
      StartLoop:
        invoke GetMessage, addr msg, 0, 0, 0
        cmp eax, 0
        je ExitLoop
        invoke TranslateMessage, addr msg
        invoke DispatchMessage, addr msg
        jmp StartLoop
      ExitLoop:
        return msg.wParam
    WinMain endp


    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
    local hndl:dword
      .if uMsg == WM_CREATE
        invoke CenterMain, hWin, wwidth, wheight
        invoke LoadBitmaps, addr hWh0, 400
        invoke MakeGrid, hWin, addr h201, addr x1, addr y1, 201
        invoke CandGrid, hWin, addr hFrame01, addr x1, addr y1, 301
        invoke AllCandidates, addr hFrame01, addr hCand01_1, addr cx1, addr cy1
      .elseif uMsg == WM_CHAR
      .elseif uMsg == WM_COMMAND
        .if wParam == 1000
          invoke SendMessage, hWin, WM_SYSCOMMAND, SC_CLOSE, 0
        .elseif wParam == 1900
          fn MessageBox, hWin, addr about, addr dname, MB_OK
        .elseif wParam == 201
          fn MessageBox, hWin, addr about, addr dname, MB_OK
        .elseif wParam == 1202
          fn MessageBox, hWin, addr about, addr dname, MB_OK
        .endif
      .elseif uMsg == WM_CLOSE
      .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage, 0
        return 0
      .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp
   
    RegWindow proc cn:dword
    local wc:WNDCLASSEX, icn:dword
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        mov wc.cbClsExtra, 0
        mov wc.cbWndExtra, 0
        mrm wc.hInstance, hi
        mov wc.hbrBackground, COLOR_BTNFACE+6
        mov wc.lpszMenuName, 0
        mrm wc.lpszClassName, cn
        invoke LoadIcon, hi, 500
        mov wc.hIcon, eax
        mov icn, eax
        invoke LoadCursor, 0, IDC_ARROW
        mov wc.hCursor, eax
        mrm wc.hIconSm, icn
        invoke RegisterClassEx, addr wc
        ret
    RegWindow endp
   
    CenterMain proc hWin:dword, wd:dword, ht:dword
    local rct:RECT, h:dword, w:dword, x:dword, y:dword
      @@: ; dynamically adjusting width of the window for proper client rect size
        invoke MoveWindow, hWin, x, y, wd, ht, 0
        invoke GetClientRect, hWin, addr rct
        mov eax, rct.right
        sub eax, rct.left
      .if eax > 872 ; desired client rect width
        dec wd
        jmp @b
      .elseif eax < 872
        inc wd
        jmp @b
      .endif
      @@: ; dynamically adjusting height of the window for proper client rect size
        invoke MoveWindow, hWin, x, y, wd, ht, 0
        invoke GetClientRect, hWin, addr rct
        mov eax, rct.bottom
        sub eax, rct.top
      .if eax > 604 ; desired client rect height
        dec ht
        jmp @b
      .elseif eax < 604
        inc ht
        jmp @b
      .endif
        invoke GetSystemMetrics, SM_CYMENU
        add ht, eax
        invoke SystemParametersInfoA, SPI_GETWORKAREA, 0, addr rct, 0
        mov eax, rct.right
        sub eax, wd
        sar eax, 1
        mov x, eax
        mov eax, rct.bottom
        sub eax, ht
        sar eax, 1
        mov y, eax
        invoke MoveWindow, hWin, x, y, wd, ht, TRUE
        ret
    CenterMain endp
   
    LoadBitmaps proc lpHandle:dword, id:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        xor ebx, ebx
        mov esi, lpHandle
        mov edi, id
      top:
        lea eax, [edi+ebx]
        invoke LoadBitmap, hi, eax
        mov [esi+ebx*4], eax
        inc ebx
        cmp ebx, 51
        jnz top
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    LoadBitmaps endp


    Cell proc hWin:dword, bnx:dword, bsx:dword, x:dword, y:dword, id:dword
    local hndl:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        invoke CreateWindowEx, 0, bnx, 0, bsx, x, y, 64, 64, hWin, id, hi, 0
        mov hndl, eax
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hWh0
        mov eax, hndl
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    Cell endp
   
    MakeGrid proc hWin:dword, lphndl:dword, lpx:dword, lpy:dword, id:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        invoke CreateWindowEx, 0, stcc, 0, bs, 0, 0, 604, 604, hWin, 0, hi, 0
        mov hBack, eax
        invoke SendMessage, hBack, STM_SETIMAGE, IMAGE_BITMAP, hBackBmp
        mov edx, lpx
        mov edi, lphndl
        xor esi, esi
      ttop:
        xor ebx, ebx
        mov ecx, lpy
      top:
        invoke Cell, hWin, stcc, bs, dword ptr [ecx], dword ptr [edx], id
        mov dword ptr [edi+ebx*4], eax
        add ecx, 4
        inc id
        inc ebx
        cmp ebx, 9
        jnz top
        inc esi
        add edx, 4
        add edi, 36
        cmp esi, 9
        jnz ttop
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    MakeGrid endp
   
    CandGrid proc hWin:dword, lphndl:dword, lpx:dword, lpy:dword, id:dword
    local hndl:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov edx, lpx
        mov edi, lphndl
        xor esi, esi
      ttop:
        xor ebx, ebx
        mov ecx, lpy
      top:
        invoke Cell, hWin, stcc, bs, dword ptr [ecx], dword ptr [edx], id
        mov dword ptr [edi+ebx*4], eax
        add ecx, 4
        inc id
        inc ebx
        cmp ebx, 9
        jnz top
        inc esi
        add edx, 4
        add edi, 36
        cmp esi, 9
        jnz ttop
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    CandGrid endp
   
    SmallCell proc hWin:dword, bnx:dword, bsx:dword, x:dword, y:dword, nmbr:dword
    local hndl:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        invoke CreateWindowEx, 0, bnx, 0, bsx, x, y, 20, 20, hWin, 0, hi, 0
        mov hndl, eax
      .if     nmbr == 1
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand1
      .elseif nmbr == 2
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand2
      .elseif nmbr == 3
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand3
      .elseif nmbr == 4
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand4
      .elseif nmbr == 5
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand5
      .elseif nmbr == 6
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand6
      .elseif nmbr == 7
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand7
      .elseif nmbr == 8
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand8
      .elseif nmbr == 9
        invoke SendMessage, hndl, STM_SETIMAGE, IMAGE_BITMAP, hCand9
      .endif
        mov eax, hndl
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    SmallCell endp
   
    CandCells proc hWin:dword, lphndl:dword, lpx:dword, lpy:dword
    local nmbr:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov nmbr, 1
        mov edx, lpx
        mov edi, lphndl
        xor esi, esi
      ttop:
        xor ebx, ebx
        mov ecx, lpy
      top:
        invoke SmallCell, hWin, stcc, bs, dword ptr [ecx], dword ptr [edx], nmbr
        mov dword ptr [edi+ebx*4], eax
        add ecx, 4
        inc nmbr
        inc ebx
        cmp ebx, 3
        jnz top
        inc esi
        add edx, 4
        add edi, 12
        cmp esi, 3
        jnz ttop
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    CandCells endp
   
    AllCandidates proc lpParent:dword, lpChild:dword, lpX:dword, lpY:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        xor ebx, ebx
        mov esi, lpParent
        mov edi, lpChild
      @@:
        mov ecx, [esi+ebx*4]
        invoke CandCells, ecx, edi, lpX, lpY
        add edi, 36
        inc ebx
        cmp ebx, 81
        jnz @b
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    AllCandidates endp


    end start
« Last Edit: September 19, 2022, 08:40:45 AM by swordfish »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: ... Sudoku R & D ...
« Reply #124 on: September 18, 2022, 07:42:13 AM »
Added the rest of the controls to the GUI.  :biggrin: 
Upon clicking the controls a MessageBox pops up displaying the control ID and Parent Handle.
This was used for checking that The ID's are set correctly.


Now it's time to make these controls Do Something!  Thats where the fun begins...  :greensml:
Have to fix the flickery effect when hiding/showing the candidates still, though.  :toothy:
« Last Edit: September 19, 2022, 08:41:01 AM by swordfish »
Regards, zedd.
:tongue:

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: ... Sudoku R & D ...
« Reply #125 on: September 18, 2022, 10:05:46 AM »
Have to fix the flickery effect when hiding/showing the candidates still, though.  :toothy:

Changing to drawing text instead of bitmaps would cure that. You're doing a little too much GDI stuff here ...

How 'bout this as away to go? Assuming you're putting (up to) 9 characters in each cell, set up a scheme like this for drawing text (image below). Instead of creating 9 separate controls, just use the "cell" as a container (it can be a separate control, or it can just be part of one big control/container). You only need 6 numbers to place the characters:

Code: [Select]
$x0 EQU #
$x1 EQU #
$x2 EQU #
$y0 EQU #
$y1 EQU #
$y2 EQU #

(you'll fill in the actual #s)

Then just use these xs and ys to position your text with DrawText() or whatever. Easy peasy.

And if each cell is a separate entity, then you only need one set of numbers for the whole shebang, since the numbers will be relative offsets from each cell.
« Last Edit: September 18, 2022, 06:41:05 PM by NoCforMe »

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: ... Sudoku R & D ...
« Reply #126 on: September 18, 2022, 06:13:15 PM »
Then just use these xs and ys to position your text with DrawText() or whatever. Easy peasy.

For such short text, TextOut is easier peasier :cool:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: ...
« Reply #127 on: September 18, 2022, 09:55:22 PM »
NoCforMe, jj2006…
When either of you decide to make your own sudoku game, you can choose any method that either of you like.  :biggrin:   To each their own. Easy to Pleasy that way.  :tongue:





I have resolved the issue ...  :cool:  apparently bulk hiding or showing xxx amount of controls in one fell swoop was too much, I made my own soluce ...

... and am currently working on the other functions ...

I'm working off a checklist of sorts, finishing each step before moving on to the next.
« Last Edit: September 18, 2022, 11:04:43 PM by swordfish »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: ...
« Reply #128 on: September 19, 2022, 04:29:27 AM »
... apparently bulk hiding or showing xxx amount of controls in one fell swoop was too much, I made my own soluce ...
Well, that all went over like a lead balloon. No, you don't get to see that code  :mrgreen:
So, now I try yet another approach which so far looks promising...  :badgrin: 


Now, in WM_PAINT upon testing a few flags and depending on those flags, will execute a different code flow. No comments please from the peanut gallery:tongue:  I am right now streamlining that code so it's neither cumbersome nor makes the WM_PAINT code cluttered.


Called from within WM_PAINT handler:
Code: [Select]
    DrawChar proc hDC:dword, lpChar:dword, xc:dword, yc:dword, wd:dword, ht:dword
    local rct:RECT, hMemDC:dword, hOld:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov eax, xc
        mov rct.left, eax
        add eax, wd
        mov rct.right, eax
        mov eax, yc
        mov rct.top, eax
        add eax, ht
        mov rct.bottom, eax
        invoke FillRect, hDC, addr rct, hBlue
        add rct.top, 7 ;; need padding to properly vertical center for DrawText. DT_VCENTER not v centering
        invoke SelectObject, hDC, CellFont
        invoke SetBkMode, hDC, TRANSPARENT
        invoke SetTextColor, hDC, 0077BBFFh
        mov esi, len(lpChar)
        invoke DrawText, hDC, lpChar, esi, addr rct, DT_CENTER or DT_VCENTER
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    DrawChar endp
Will add a couple more args so not using globals or hard coded colorref here for the colors. Text length always 1. Don't need to get length  :rolleyes:  a whoops on my part.
« Last Edit: September 22, 2022, 10:57:44 AM by swordfish »
Regards, zedd.
:tongue:

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: ...
« Reply #129 on: September 19, 2022, 07:16:43 AM »
Now, in WM_PAINT upon testing a few flags and depending on those flags, will execute a different code flow. No comments please from the peanut gallery:tongue:

What, did I say anything?

No, seriously, nothing wrong at all with setting a few flags in WM_PAINT. I do it all the time. After all, you're focusing all your painting and drawing on that one place in your code, so of course you're going to have to dance around a bit.

zedd151

  • Member
  • *****
  • Posts: 1968
Re: Simple Games - Research and Development
« Reply #130 on: September 19, 2022, 07:58:58 AM »
Reworking the code using a slightly altered DrawChar procedure than shown above, now called "DrawCell". It has a single extra argument for whether the cell should be selected (blue background) or highlighted (orange background) the text color will remain black in either case including default case. Only changed text color for the demo that is shown above.


Once I get the painting functions finished I can then work on the other controls code, and getting mouse clicks of course.
Code: [Select]
        ; This source code written by swordfish @ masm32.com
        include \masm32\include\masm32rt.inc
   
        RegWindow   proto :dword, :dword
        WinMain     proto :dword, :dword, :dword
        WndProc     proto :dword, :dword, :dword, :dword
        CenterMain  proto :dword, :dword, :dword
        DrawBitmap  proto :dword, :dword, :dword, :dword, :dword, :dword
        DrawCells   proto :dword, :dword, :dword, :dword
   
     
        wwidth      equ 1026
        wheight     equ 768
        ws          equ WS_BORDER or WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU
        menuid      equ 600
        iconid      equ 500
        hilite      equ 1
        select      equ 2
    .data?
        hWnd        dd ?
        hInstance   dd ?
        hBlue       dd ?
        hOrange     dd ?
        CellFont    dd ?
        hBackBmp    dd ?


    .data
        align 16
        board label byte
                    db 1, 2, 3, 4, 5, 6, 7, 8, 9
                    db 4, 5, 6, 7, 8, 9, 1, 2, 3
                    db 7, 8, 9, 1, 2, 3, 4, 5, 6
                    db 2, 3, 4, 5, 6, 7, 8, 9, 1
                    db 5, 6, 7, 8, 9, 1, 2, 3, 4
                    db 8, 9, 1, 2, 3, 4, 5, 6, 7
                    db 3, 4, 5, 6, 7, 8, 9, 1, 2
                    db 6, 7, 8, 9, 1, 2, 3, 4, 5
                    db 9, 1, 2, 3, 4, 5, 6, 7, 8
        str1        db "1", 0
        str2        db "2", 0
        str3        db "3", 0
        str4        db "4", 0
        str5        db "5", 0
        str6        db "6", 0
        str7        db "7", 0
        str8        db "8", 0
        str9        db "9", 0
    .const
        x1              dd 4
        x2              dd 70
        x3              dd 136
        x4              dd 204
        x5              dd 270
        x6              dd 336
        x7              dd 404
        x8              dd 470
        x9              dd 536
        y1              dd 4
        y2              dd 70
        y3              dd 136
        y4              dd 204
        y5              dd 270
        y6              dd 336
        y7              dd 404
        y8              dd 470
        y9              dd 536
       
        dname       db "sudoku", 0
        wclass      db "SUDOKUCLASS", 0
        about       db "sudoku v1.0 by swordfish 2022", 0
       
    .code
   
    start:
        invoke GetModuleHandle, 0
        mov hInstance, eax
        invoke RegWindow, hInstance, addr wclass
        invoke WinMain, hInstance, addr wclass, addr dname
        invoke ExitProcess, eax
       
    WinMain proc hi:dword, cn:dword, dn:dword
    local msg:MSG, Wtx:dword, Wty:dword
        invoke CreateWindowEx, 0, cn, dn, ws, 0, 0, 0, 0, 0, 0, hi, 0
        mov hWnd, eax
        invoke LoadMenu, hi, menuid
        invoke SetMenu, hWnd, eax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd
      StartLoop:
        invoke GetMessage, addr msg, 0, 0, 0
        cmp eax, 0
        je ExitLoop
        invoke TranslateMessage, addr msg
        invoke DispatchMessage, addr msg
        jmp StartLoop
      ExitLoop:
        return msg.wParam
    WinMain endp
   
    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
    local hDC:dword, ps:PAINTSTRUCT, hMemDC:dword, hOld:dword
      .if uMsg == WM_CREATE
        invoke CenterMain, hWin, wwidth, wheight
        invoke LoadBitmap, hInstance, 450
        mov hBackBmp, eax
        invoke CreateSolidBrush, 0077BBFFh
        mov hOrange, eax
        invoke CreateSolidBrush, 00FFBB77h
        mov hBlue, eax
        fn RetFontHandle, "simhei", 48, 100
        mov CellFont, eax
      .elseif uMsg == WM_COMMAND
        .if wParam == 86
          invoke SendMessage, hWin, WM_SYSCOMMAND, SC_CLOSE, 0
        .elseif wParam == 99
          fn MessageBox, hWin, addr about, addr dname, MB_OK
        .endif
      .elseif uMsg == WM_PAINT
        invoke BeginPaint, hWin, addr ps
        mov hDC, eax
        invoke DrawBitmap, hDC, hBackBmp, 0, 0, 872, 604    ;; background
        invoke DrawCells, hDC, addr board, addr x1, addr y1 ;; cells
        invoke EndPaint, hWin,addr ps
      .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage, 0
        return 0
      .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp
   
    RegWindow proc hi:dword, cn:dword
    local wc:WNDCLASSEX, icn:dword
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        mov wc.cbClsExtra, 0
        mov wc.cbWndExtra, 0
        mrm wc.hInstance, hi
        mov wc.hbrBackground, COLOR_BTNFACE+6
        mov wc.lpszMenuName, 0
        mrm wc.lpszClassName, cn
        invoke LoadIcon, hi, iconid
        mov wc.hIcon, eax
        mov icn, eax
        invoke LoadCursor, 0, IDC_ARROW
        mov wc.hCursor, eax
        mrm wc.hIconSm, icn
        invoke RegisterClassEx, addr wc
        ret
    RegWindow endp
   
    CenterMain proc hWin:dword, wd:dword, ht:dword
    local rct:RECT, h:dword, w:dword, x:dword, y:dword
      @@: ; dynamically adjusting width of the window for proper client rect size
        invoke MoveWindow, hWin, x, y, wd, ht, 0
        invoke GetClientRect, hWin, addr rct
        mov eax, rct.right
        sub eax, rct.left
      .if eax > 872 ; desired client rect width
        dec wd
        jmp @b
      .elseif eax < 872
        inc wd
        jmp @b
      .endif
      @@: ; dynamically adjusting height of the window for proper client rect size
        invoke MoveWindow, hWin, x, y, wd, ht, 0
        invoke GetClientRect, hWin, addr rct
        mov eax, rct.bottom
        sub eax, rct.top
      .if eax > 604 ; desired client rect height
        dec ht
        jmp @b
      .elseif eax < 604
        inc ht
        jmp @b
      .endif
        invoke GetSystemMetrics, SM_CYMENU
        add ht, eax
        invoke SystemParametersInfoA, SPI_GETWORKAREA, 0, addr rct, 0
        mov eax, rct.right
        sub eax, wd
        sar eax, 1
        mov x, eax
        mov eax, rct.bottom
        sub eax, ht
        sar eax, 1
        mov y, eax
        invoke MoveWindow, hWin, x, y, wd, ht, TRUE
        ret
    CenterMain endp


    DrawBitmap proc hDC:dword, hBmp:dword, xc:dword, yc:dword, wd:dword, ht:dword
    local hOld:dword, hMemDC:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        invoke CreateCompatibleDC, NULL
        mov hMemDC, eax                         
        invoke SelectObject, hMemDC, hBmp       ; select object to blit to hMemDC
        mov hOld, eax
        invoke BitBlt, hDC, xc, yc, wd, ht, hMemDC, 0, 0, SRCCOPY  ; blit hMemDC to hDC
        invoke SelectObject, hMemDC, hOld       ; select object for deletion
        invoke DeleteObject, hMemDC             ; delete oject here
        invoke DeleteDC, hMemDC
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    DrawBitmap endp
   
    DrawCell proc hDC:dword, txt:dword, x:dword, y:dword, hi:dword
    local rct:RECT, hMemDC:dword, hOld:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov eax, x
        mov rct.left, eax
        add eax, 64
        mov rct.right, eax
        mov eax, y
        mov rct.top, eax
        add eax, 64
        mov rct.bottom, eax
      .if hi == hilite
        invoke FillRect, hDC, addr rct, hBlue
      .elseif hi == select
        invoke FillRect, hDC, addr rct, hOrange
      .endif
        add rct.top, 7 ;; need padding to properly vertical center
        invoke SelectObject, hDC, CellFont
        invoke SetBkMode, hDC, TRANSPARENT
        invoke DrawText, hDC, txt, 1, addr rct, DT_CENTER or DT_VCENTER
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    DrawCell endp
   
    DrawCells proc hDC:dword, lpBoard:dword, lpx:dword, lpy:dword
        push ebx
        push esi
        push edi
        push edx
        push ecx
        mov edx, lpx
        mov esi, lpBoard
        xor ebx, ebx
      ttop:
        xor edi, edi
        mov ecx, lpy
      top:
      .if byte ptr [esi+edi] == 1
        invoke DrawCell, hDC, addr str1, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 2
        invoke DrawCell, hDC, addr str2, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 3
        invoke DrawCell, hDC, addr str3, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 4
        invoke DrawCell, hDC, addr str4, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 5
        invoke DrawCell, hDC, addr str5, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 6
        invoke DrawCell, hDC, addr str6, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 7
        invoke DrawCell, hDC, addr str7, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 8
        invoke DrawCell, hDC, addr str8, dword ptr [ecx], dword ptr [edx], 0
      .elseif byte ptr [esi+edi] == 9
        invoke DrawCell, hDC, addr str9, dword ptr [ecx], dword ptr [edx], 0
      .endif
        add ecx, 4
        inc edi
        cmp edi, 9
        jnz top
        add esi, 9
        inc ebx
        add edx, 4
        cmp ebx, 9
        jnz ttop
        pop ecx
        pop edx
        pop edi
        pop esi
        pop ebx
        ret
    DrawCells endp
   
    end start
As of now, only reading and displaying the game board.
« Last Edit: September 22, 2022, 10:55:39 AM by swordfish »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: Simple Games - Research and Development
« Reply #131 on: September 19, 2022, 08:56:37 AM »


Now to get rid of the last bitmap... using FillRect to do the deed.
In order to remove the background image have done the following:
Code: [Select]
    GridBkgd proc hDC:dword ;; draws black background for grid
    local rct:RECT
        mov rct.left, 0
        mov rct.top, 0
        mov rct.right, 604
        mov rct.bottom, 604
        invoke FillRect, hDC, addr rct, hBlack
        ret
    GridBkgd endp


    ;; draws cell background color and cell value, if any
   
    DrawCell proc hDC:dword, txt:dword, x:dword, y:dword, bk:dword
    local rct:RECT, hMemDC:dword, hOld:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov eax, x
        mov rct.left, eax
        add eax, 64
        mov rct.right, eax
        mov eax, y
        mov rct.top, eax
        add eax, 64
        mov rct.bottom, eax
      .if bk == hilite                         ;; if back color = highlight
        invoke FillRect, hDC, addr rct, hBlue
      .elseif bk == select                  ;; if back color = selected
        invoke FillRect, hDC, addr rct, hOrange
      .else                                       ;; else default white background
        invoke FillRect, hDC, addr rct, hWhite
      .endif
        cmp txt, 0
        jz @f
        add rct.top, 7 ;; need padding to properly vertical center
        invoke SelectObject, hDC, CellFont
        invoke SetBkMode, hDC, TRANSPARENT
        invoke DrawText, hDC, txt, 1, addr rct, DT_CENTER or DT_VCENTER
      @@:
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    DrawCell endp
Will do similar for the other 'button controls' as well
   
« Last Edit: September 22, 2022, 10:55:21 AM by swordfish »
Regards, zedd.
:tongue:

zedd151

  • Member
  • *****
  • Posts: 1968
Re: sudoku mouse test
« Reply #132 on: September 19, 2022, 02:11:59 PM »

Test of mouse coordinates to cell index


Code: [Select]
    GetSelectedCell proc lParam
    push esi
    push edi
    push ebx
    push edx
    push ecx
    movzx ecx, word ptr [lParam]
    xor ebx, ebx ;; ebx == column index
    lea esi, x1
  @@:
    mov eax, [esi+ebx*4]  ;; eax == cell.x
    mov edi, eax
    add edi, 64           ;; edi == cell.x + cell.width
  .if ecx >= eax && ecx <= edi 
    jmp @f
  .endif
    inc ebx
    cmp ebx, 9
    jnz @b
    mov eax, -1 ;; if mouse click is outside of grid
    ret
  @@:
    mov edx, lParam
    shr edx, 16
    xor ecx, ecx ;; ecx == row index
    lea esi, x1
  @@:
    mov eax, [esi+ecx*4]  ;; eax == cell.y
    mov edi, eax
    add edi, 64           ;; edi == cell.y + cell.height
  .if edx >= eax && edx <= edi
    jmp @f
  .endif
    inc ecx
    cmp ecx, 9
    jnz @b
    mov eax, -1 ;; if mouse click is outside of grid
    ret
  @@:
    mov eax, 9
    mul ecx
    add eax, ebx
    inc eax     ;; increase to return 1-based cell index
    pop ecx
    pop edx
    pop ebx
    pop edi
    pop esi
    ret
GetSelectedCell endp
« Last Edit: September 22, 2022, 01:36:53 PM by swordfish »
Regards, zedd.
:tongue:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Simple Games - Research and Development
« Reply #133 on: September 19, 2022, 05:33:52 PM »
Code: [Select]
  .if ecx >= eax && ecx <= edi
    jmp @f
  .endif
    inc ebx
    cmp ebx, 9
    jnz @b
    mov eax, -1 ;; if mouse click is outside of grid
    ret
  @@:
    mov edx, lParam

Code: [Select]
   .if ecx < eax || ecx > edi
  inc ebx
  cmp ebx, 9
  jnz @b
  mov eax, -1 ;; if mouse click is outside of grid
  ret
    .endif
    mov edx, lParam   

This creates an unnecessary extra jmp:

 .if ...
    jmp @f
  .endif

I know, it's a matter of taste, and style - but it sticks out ;-)

zedd151

  • Member
  • *****
  • Posts: 1968
Re: 16 bit DOS mode sudoku?
« Reply #134 on: September 20, 2022, 04:30:25 AM »

Just kidding about the post title :tongue:  Sorry for the click bait.  :mrgreen:
@jj, that's ok jj. I just slapped that code together for testing purposes. In the final version I *should* have a more elegant solution for that piece of code.  :cool:  As of now trying to get a paint buffer going and making it reliable. So far, so good. I am contemplating using static controls, if only for the mouse click events generated. Each static could have a pre-made RECT structure associated with it, so only need to blit that portion of the screen and would be convenient with a struct ready for the purpose.  :biggrin:   But then I think if I do that, 'why not just write the char and set bk color on the static'? Then why not use bmps.  It's a vicious circle of thoughts. And so on and so forth. Just kidding. I'm going to continue with the current code to see how far I can get it without any issues.  :tongue:


Or I could say "**** it!", and make a 32 bit console mode sudoku.  :badgrin:
Regards, zedd.
:tongue: