News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

sudoku avatar creator

Started by sudoku, April 30, 2024, 08:05:44 AM

Previous topic - Next topic

sudoku

#30
@ sinsi:
It's not really a game per se, but my avatar creator - hence the thread title.
Yes it is tiny. 127x127... avatar sized (the sudoku board, anyway)

This project is still under development (and may still contain some unnoticed errors)
Thanks for your feedback. Do you have any other suggestions?

As far as replacing an invalid digit, don't make mistakes and you won't have to replace any invalid digits. :tongue: there is no undo function (will be, maybe in the near future)

You can always cheat and look at my avatar. :biggrin: until I change it, that is...

It's not perfect, but it works for what I need it to do. :smiley:
:cool:

learn64bit

.zip files in #26 and #22 are same

sudoku

#32
Quote from: learn64bit on May 02, 2024, 10:20:06 PM.zip files in #26 and #22 are same
Yes. But no longer.
From now on, instead of keeping previous versions attached within their respective posts, I have decided to only have the latest version attached to post #1
When I make a post announcing some change to the program, that new version will be attached to post #1, and any prior versions removed.
:cool:

sudoku

I have been thinking....

Since I am developing this little toy concurrently with the continuing development  of my sudoku GUI, why not do them within the same program... some of the code is already shared between them.

The avatar creation stuff would be done in a separate DC and not visible in the sudoku GUI. It seems that it should be 'doable'... I will run some tests later this evening (my time, it's noon here right now)...

The sudoku GUI btw, will not be posted until it is finished for those who might be interested. Please be patient. :azn:
:cool:

sudoku

#34
Found an erroneous piece of code when trying to capture a portion of the client area starting at another position other than 0, 0 in the "DCbmptoFile" procedure.
It kept on capturing with results that I did not expect.
First, I had mislabeled the calculated height and width as 'xx' and 'yy'. Now changed those to ww and hh respectively.
xx and yy are now the origin x and y.
Next, I had forgotten to address the source DC's origin during BitBlt (was hard coded at 0, 0)

original code:
        mov ecx, lprct
    assume ecx:ptr RECT  ;; set bitmap height & width from lprct (passed argument)
    mov eax, [ecx].right
    sub eax, [ecx].left
    mov xx, eax
    mov eax, [ecx].bottom
    sub eax, [ecx].top
    mov yy, eax
    assume ecx:nothing
   
    invoke CreateCompatibleBitmap, hDC, xx, yy
    mov hBmp, eax
    invoke SelectObject, tempDC, hBmp
    mov hOld, eax
    invoke BitBlt, tempDC, 0, 0, xx, yy, hDC, 0, 0, SRCCOPY
   
Which worked fine, as long as the origin was "0, 0" as in the lil_sudoku program.

Fixed the error, to have the origin anywhere within the client area:
        mov ecx, lprct
        assume ecx:ptr RECT  ;; set bitmap height & width from lprct (passed argument)
        mov edx, [ecx].left
        mov xx, edx
        mov eax, [ecx].right
        sub eax, edx
        mov ww, eax
        mov edx, [ecx].top
        mov yy, edx
        mov eax, [ecx].bottom
        sub eax, edx
        mov hh, eax
        assume ecx:nothing
        invoke CreateCompatibleBitmap, hDC, ww, hh
        mov hBmp, eax
        invoke SelectObject, tempDC, hBmp
        mov hOld, eax
        invoke BitBlt, tempDC, 0, 0, ww, hh, hDC, xx, yy, SRCCOPY

:smiley:

The full procedure: (demo using it is attached below)  :wink2:
;; converted to 32 bit by zedd151, from a 64 bit screen capture tool by Vortex.
;; modified by sudoku.

    DCbmptoFile proc hDC:dword, lprct:dword, lpOut:dword  ;; lpout is the output file name for the bitmap.
    local hBmp:dword, hOld:dword, tempDC:dword, ww:dword, hh:dword, xx:dword, yy:dword
    local hFile:dword, BmpSize:dword, SizeofDIB:dword, BWritten:dword, Bits:dword, pMem:dword
    local bm:BITMAP, BmpFileHdr:BITMAPFILEHEADER, BmpInfoHdr:BITMAPINFOHEADER
        push esi
        push edi
        push ebx
        push edx
        push ecx
        xor eax, eax
        lea edi, bm
        mov ecx, sizeof BITMAP
        rep stosb
        xor eax, eax
        lea edi, BmpFileHdr
        mov ecx, sizeof BITMAPFILEHEADER
        rep stosb
        xor eax, eax
        lea edi, BmpInfoHdr
        mov ecx, sizeof BITMAPINFOHEADER
        rep stosb
        lea edi, bm
        invoke CreateCompatibleDC, hDC
        mov tempDC, eax
        mov ecx, lprct
        assume ecx:ptr RECT  ;; set bitmap origin (xx, yy), height & width (hh, ww) from lprct (passed argument)
        mov edx, [ecx].left
        mov xx, edx
        mov eax, [ecx].right
        sub eax, edx
        mov ww, eax
        mov edx, [ecx].top
        mov yy, edx
        mov eax, [ecx].bottom
        sub eax, edx
        mov hh, eax
        assume ecx:nothing
        invoke CreateCompatibleBitmap, hDC, ww, hh
        mov hBmp, eax
        invoke SelectObject, tempDC, hBmp
        mov hOld, eax
        invoke BitBlt, tempDC, 0, 0, ww, hh, hDC, xx, yy, SRCCOPY
        invoke GetObject, hBmp, sizeof(BITMAP), edi
        mov BITMAP.bmBitsPixel[edi], 24
        xor edx, edx
        movzx eax, BITMAP.bmPlanes[edi]
        mul BITMAP.bmBitsPixel[edi]
        mov Bits, eax
        lea ecx, BmpInfoHdr
        mov BITMAPINFOHEADER.biSize[ecx], sizeof(BITMAPINFOHEADER)
        mov eax, ww
        mov BITMAPINFOHEADER.biWidth[ecx],eax
        mov eax, hh
        mov BITMAPINFOHEADER.biHeight[ecx],eax
        mov ax,BITMAP.bmPlanes[edi]
        mov BITMAPINFOHEADER.biPlanes[ecx],ax
        mov ax,BITMAP.bmBitsPixel[edi]
        mov BITMAPINFOHEADER.biBitCount[ecx],ax
        mov BITMAPINFOHEADER.biCompression[ecx], BI_RGB
        xor eax, eax
        mov BITMAPINFOHEADER.biSizeImage[ecx], eax
        mov BITMAPINFOHEADER.biXPelsPerMeter[ecx], eax
        mov BITMAPINFOHEADER.biYPelsPerMeter[ecx], eax
        mov BITMAPINFOHEADER.biClrUsed[ecx], eax
        mov BITMAPINFOHEADER.biClrImportant[ecx], eax
        xor edx, edx
        mov eax, BITMAP.bmWidth[ecx]
        mul Bits
        add eax, 31
        and eax, -32
        shr eax, 3
        mul BITMAP.bmHeight[ecx]
        mov BmpSize, eax
        invoke VirtualAlloc, 0, eax, MEM_COMMIT, PAGE_READWRITE
        mov pMem, eax
        invoke GetDIBits, tempDC, hBmp, 0, dword PTR BITMAP.bmHeight[edi], pMem, ADDR BmpInfoHdr, DIB_RGB_COLORS
        xor eax,eax
        invoke CreateFile, lpOut, GENERIC_WRITE, eax, eax, CREATE_ALWAYS, eax, eax
        mov hFile, eax
        mov eax, BmpSize
        add eax, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
        mov SizeofDIB, eax
        lea edx, BmpFileHdr
        mov BITMAPFILEHEADER.bfOffBits[edx], sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
        mov eax, SizeofDIB
        mov BITMAPFILEHEADER.bfSize[edx], eax
        mov BITMAPFILEHEADER.bfReserved1[edx], 0
        mov BITMAPFILEHEADER.bfReserved2[edx], 0
        mov BITMAPFILEHEADER.bfType[edx], 'MB'
        lea esi, BWritten
        invoke WriteFile, hFile, ADDR BmpFileHdr, sizeof(BITMAPFILEHEADER), esi, 0
        invoke WriteFile,hFile, ADDR BmpInfoHdr, sizeof(BITMAPINFOHEADER), esi, 0
        invoke WriteFile, hFile, pMem, BmpSize, esi, 0
        push eax
        invoke CloseHandle, hFile
        invoke VirtualFree, pMem, 0, MEM_RELEASE
        invoke SelectObject, tempDC, hOld
        invoke DeleteObject, hBmp
        invoke DeleteDC, tempDC
        pop eax ;; returns TRUE if file written, else returns FALSE
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    DCbmptoFile endp
    where hDC is the DC of the captured client area. lprct is the pointer to rectange captured, lpout is pointer to the output file name for the bitmap. Also now taking better care to preserve the registers. :tongue:

Will update the zip file in post #1 shortly  (done... look for lil_sudoku_3d.zip in post #1)
The effect of the changes not noticed here in this program, as the source DC origin here is (0, 0)

Demo for the 'repaired' DCbmptoFile attached BELOW...
:cool:

sudoku

As in my last couple of posts, I am working on 'big_sudoku' (will be renamed prior to going 'public')..  It will incorporate a smaller (avatar sized 127x127) board within the GUI. The game will be played on the normal sized' sudoku board, and the smaller board will echo what is taking place in the main board (user can choose whether to show and use the smaller board or not). The screen captures on the smaller board will be automatic as soon as a value is entered (on the main board), if the small board is enabled. My current avatar was created with the help of this setup (yes, in its partially finished state). Much easier to work with the larger cells and of course font. :biggrin:

More details will follow in the coming days. Hopefully it will be completed (and bug free?) by the end of summer, time permitting.
:cool:

sudoku

Progess is slow, but I am making progress. I have devised a way to have the small (127x127) board and the Main sudoku board on the same DC, with the small (127x127) being invisible to the user - this simplifies matters a bit. (By not having to use multiple DC's) Now working on the core code now that the DC stuff is out of the way...
:cool: