Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change
Quote from: zedd151 on Today at 03:17:22 AMI wanted to eliminate the .rc file altogether, but in memory dialogs seem more trouble than they are worth. (without using macros to do it)Thinking about this some more, you could create memory dialog templates without using macros, using a function or two.
#include "\masm32\include\resource.h"
#define IDR_MENU 10000
#define IDM_ABOUT 10
#define IDM_MNMIZE 20
#define IDM_EXIT 30
MYDIALOG DIALOGEX DISCARDABLE 20, 10, 186, 100, 18481280
STYLE DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
CAPTION "Dialog box"
FONT 12, "System", 700, 0, 1
{
CONTROL "&About", 110, "Button", WS_TABSTOP, 116, 8, 50, 20, 0, 1234049503
CONTROL "&Minimize",120, "Button", WS_TABSTOP, 116, 36, 50, 20, 0, 1234049503
CONTROL "&Exit",130, "Button", WS_TABSTOP, 116, 64, 50, 20
CONTROL " Masm Dialog Box", 4000, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 16, 8, 72, 20
}
IDR_MENU MENU
{
POPUP "&File"
{
MENUITEM "&About", IDM_ABOUT
MENUITEM "&Minimize", IDM_MNMIZE
MENUITEM "&Exit", IDM_EXIT
}
}
.data
include Dialog.inc
include Menu.inc
invoke GetModuleHandle,0
xor ecx,ecx
invoke DialogBoxIndirectParam,eax,ADDR Dialog,\
ecx,ADDR DlgProc,ecx
invoke ExitProcess,eax
DlgProc PROC USES ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.IF uMsg==WM_INITDIALOG
invoke LoadMenuIndirect,ADDR Menu
invoke SetMenu,hWnd,eax
Quote from: NoCforMe on Today at 05:44:27 AMA dialog is a window.Of course.
Quote from: zedd151 on Today at 12:18:55 AMAny controls can then be added the usual way using CreateWindowEx (as if we were working with a 'window')A dialog is a window.
include \masm32\include\masm32rt.inc
DlgProc proto :dword, :dword, :dword, :dword
randb proto :dword
set_board proto
scramble proto :dword, :dword, :dword, :dword, :dword
painting proto :dword
cwidth equ 512 ; desired client area width
cheight equ 512 ; desired clien area height
vpad equ 16 ; vertical padding for DrawText
hpad equ -1 ; horizontal padding for DrawText
reps equ 800 ; number of times the initial game board is randomly scrambled
.data?
align 16
board label byte
a1 db ?
a2 db ?
a3 db ?
a4 db ?
b1 db ?
b2 db ?
b3 db ?
b4 db ?
c1 db ?
c2 db ?
c3 db ?
c4 db ?
d1 db ?
d2 db ?
d3 db ?
d4 db ?
hInstance dd ?
hFont1 dd ?
GrayPen dd ?
WhitePen dd ?
GrayBrush dd ?
.const
gover db "Game Over!", 0
finito db "Finished!", 0
align 16
x1 dd 0 ; board x coordinates
x2 dd 128
x3 dd 256
x4 dd 384
y1 dd 0 ; board y coordinates
y2 dd 128
y3 dd 256
y4 dd 384
.code
;; revised version of dwtoa from masm32.lib - returns string length
dwtoa_revised proc dwValue:DWORD, lpBuffer:DWORD
push ebx
push esi
push edi
mov eax, dwValue
mov edi, [lpBuffer]
test eax,eax
jnz sign
zero:
mov word ptr [edi],30h
jmp dtaexit
sign:
jns pos
mov byte ptr [edi],'-'
neg eax
add edi, 1
pos:
mov ecx, 3435973837
mov esi, edi
.while (eax > 0)
mov ebx,eax
mul ecx
shr edx, 3
mov eax,edx
lea edx,[edx*4+edx]
add edx,edx
sub ebx,edx
add bl,'0'
mov [edi],bl
add edi, 1
.endw
mov byte ptr [edi], 0
mov eax, edi
sub eax, lpBuffer
push eax
.while (esi < edi)
sub edi, 1
mov al, [esi]
mov ah, [edi]
mov [edi], al
mov [esi], ah
add esi, 1
.endw
pop eax ;; string length returned in eax
dtaexit:
pop edi
pop esi
pop ebx
ret
dwtoa_revised endp
;; draws the game pieces
drawcell proc mDC:dword, x:dword, y:dword, lptext:dword, count:dword
local rcta1:RECT
push esi
push edi
push ebx
push edx
push ecx
mov eax, x
mov rcta1.left, eax
add eax, 128
mov rcta1.right, eax
mov eax, y
mov rcta1.top, eax
add eax, 128
mov rcta1.bottom, eax
invoke FillRect, mDC, addr rcta1, GrayBrush
mov esi, x
add esi, 0
mov edi, y
add edi, 126
invoke SelectObject, mDC, WhitePen
invoke MoveToEx, mDC, esi, edi, 0
sub edi, 126
invoke LineTo, mDC, esi, edi
add esi, 126
invoke LineTo, mDC, esi, edi
mov esi, x
add esi, 1
mov edi, y
add edi, 127
invoke SelectObject, mDC, GrayPen
invoke MoveToEx, mDC, esi, edi, 0
add esi, 126
invoke LineTo, mDC, esi, edi
sub edi, 126
invoke LineTo, mDC, esi, 1
invoke SelectObject, mDC, hFont1
mov eax, x
add eax, hpad
mov rcta1.left, eax
add eax, 128
mov rcta1.right, eax
mov eax, y
add eax, vpad
mov rcta1.top, eax
add eax, 128
mov rcta1.bottom, eax
xor edx, edx
mov dl, a1
invoke SetBkMode, mDC, TRANSPARENT
invoke DrawText, mDC, lptext, count, addr rcta1, DT_CENTER or DT_VCENTER
pop ecx
pop edx
pop ebx
pop edi
pop esi
ret
drawcell endp
;; draw the game pieces in a loop
painting proc hDC:dword
local rcta1:RECT, numstring[8]:byte, cnt:dword, xx:dword, yy:dword
lea edi, board
lea esi, y1
mov yy, 0
top1:
lea ebx, x1
mov xx, 0
@@:
movzx edx, byte ptr [edi]
.if edx > 0
invoke dwtoa_revised, edx, addr numstring
mov cnt, eax
mov ecx, [ebx]
mov edx, [esi]
invoke drawcell, hDC, [ebx], [esi], addr numstring, cnt
.endif
inc edi
add ebx, 4
inc xx
cmp xx, 4
jnz @b
add esi, 4
inc yy
cmp yy, 4
jnz top1
ret
painting endp
start proc
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, 100, 0, addr DlgProc, 0
invoke ExitProcess, eax
start endp
DlgProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
local hDC:dword, ps:PAINTSTRUCT, rct:RECT, hBrush:dword, hBrush_old:dword
local mDC:dword, hBmp:dword, hBmp_old:dword, tmp1:dword
local x:dword, y:dword, wwid:dword, whgt:dword, cwid:dword, chgt:dword
.if uMsg == WM_INITDIALOG
invoke GetWindowRect, hWin, addr rct
mov eax, rct.right
sub eax, rct.left
mov wwid, eax
mov eax, rct.bottom
sub eax, rct.top
mov whgt, eax
invoke GetClientRect, hWin, addr rct
mov eax, rct.right
sub eax, rct.left
mov cwid, eax
mov eax, rct.bottom
sub eax, rct.top
mov chgt, eax
mov eax, cwidth
sub eax, cwid
add wwid, eax
mov eax, cheight
sub eax, chgt
add whgt, eax
invoke SystemParametersInfoA, SPI_GETWORKAREA, 0, addr rct, 0
mov eax, rct.right
sub eax, wwid
sar eax, 1
mov x, eax
mov eax, rct.bottom
sub eax, whgt
sar eax, 1
mov y, eax
invoke MoveWindow, hWin, x, y, wwid, whgt, TRUE
fn RetFontHandle, "Tahoma", 90, 400
mov hFont1, eax
invoke CreatePen, PS_SOLID, 1, 003F3F73h
mov GrayPen, eax
invoke GetStockObject, WHITE_PEN
mov WhitePen, eax
invoke GetStockObject, LTGRAY_BRUSH
mov GrayBrush, eax
invoke set_board
invoke InvalidateRect, hWin, 0, 0
.elseif uMsg == WM_KEYUP
.if wParam == VK_LEFT
.if a1 == 0
mov al, a2
mov a1, al
mov a2, 0
.elseif a2 == 0
mov al, a3
mov a2, al
mov a3, 0
.elseif a3 == 0
mov al, a4
mov a3, al
mov a4, 0
.elseif b1 == 0
mov al, b2
mov b1, al
mov b2, 0
.elseif b2 == 0
mov al, b3
mov b2, al
mov b3, 0
.elseif b3 == 0
mov al, b4
mov b3, al
mov b4, 0
.elseif c1 == 0
mov al, c2
mov c1, al
mov c2, 0
.elseif c2 == 0
mov al, c3
mov c2, al
mov c3, 0
.elseif c3 == 0
mov al, c4
mov c3, al
mov c4, 0
.elseif d1 == 0
mov al, d2
mov d1, al
mov d2, 0
.elseif d2 == 0
mov al, d3
mov d2, al
mov d3, 0
.elseif d3 == 0
mov al, d4
mov d3, al
mov d4, 0
.endif
invoke InvalidateRect, hWin, 0, 0
.elseif wParam == VK_UP
.if a1 == 0
mov al, b1
mov a1, al
mov b1, 0
.elseif a2 == 0
mov al, b2
mov a2, al
mov b2, 0
.elseif a3 == 0
mov al, b3
mov a3, al
mov b3, 0
.elseif a4 == 0
mov al, b4
mov a4, al
mov b4, 0
.elseif b1 == 0
mov al, c1
mov b1, al
mov c1, 0
.elseif b2 == 0
mov al, c2
mov b2, al
mov c2, 0
.elseif b3 == 0
mov al, c3
mov b3, al
mov c3, 0
.elseif b4 == 0
mov al, c4
mov b4, al
mov c4, 0
.elseif c1 == 0
mov al, d1
mov c1, al
mov d1, 0
.elseif c2 == 0
mov al, d2
mov c2, al
mov d2, 0
.elseif c3 == 0
mov al, d3
mov c3, al
mov d3, 0
.elseif c4 == 0
mov al, d4
mov c4, al
mov d4, 0
.endif
invoke InvalidateRect, hWin, 0, 0
.elseif wParam == VK_RIGHT
.if a2 == 0
mov al, a1
mov a2, al
mov a1, 0
.elseif a3 == 0
mov al, a2
mov a3, al
mov a2, 0
.elseif a4 == 0
mov al, a3
mov a4, al
mov a3, 0
.elseif b2 == 0
mov al, b1
mov b2, al
mov b1, 0
.elseif b3 == 0
mov al, b2
mov b3, al
mov b2, 0
.elseif b4 == 0
mov al, b3
mov b4, al
mov b3, 0
.elseif c2 == 0
mov al, c1
mov c2, al
mov c1, 0
.elseif c3 == 0
mov al, c2
mov c3, al
mov c2, 0
.elseif c4 == 0
mov al, c3
mov c4, al
mov c3, 0
.elseif d2 == 0
mov al, d1
mov d2, al
mov d1, 0
.elseif d3 == 0
mov al, d2
mov d3, al
mov d2, 0
.elseif d4 == 0
mov al, d3
mov d4, al
mov d3, 0
.endif
invoke InvalidateRect, hWin, 0, 0
.elseif wParam == VK_DOWN
.if b1 == 0
mov al, a1
mov b1, al
mov a1, 0
.elseif b2 == 0
mov al, a2
mov b2, al
mov a2, 0
.elseif b3 == 0
mov al, a3
mov b3, al
mov a3, 0
.elseif b4 == 0
mov al, a4
mov b4, al
mov a4, 0
.elseif c1 == 0
mov al, b1
mov c1, al
mov b1, 0
.elseif c2 == 0
mov al, b2
mov c2, al
mov b2, 0
.elseif c3 == 0
mov al, b3
mov c3, al
mov b3, 0
.elseif c4 == 0
mov al, b4
mov c4, al
mov b4, 0
.elseif d1 == 0
mov al, c1
mov d1, al
mov c1, 0
.elseif d2 == 0
mov al, c2
mov d2, al
mov c2, 0
.elseif d3 == 0
mov al, c3
mov d3, al
mov c3, 0
.elseif d4 == 0
mov al, c4
mov d4, al
mov c4, 0
.endif
.endif
invoke InvalidateRect, hWin, 0, 0
;; check for winning condition
.if a1 == 1 && a2 == 2 && a3 == 3 && a4 == 4
.if b1 == 5 && b2 == 6 && b3 == 7 && b4 == 8
.if c1 == 9 && c2 == 10 && c3 == 11 && c4 == 12
.if d1 == 13 && d2 == 14 && d3 == 15 && d4 == 0
;; if winner, display messagebox
fn MessageBox, 0, addr gover, addr finito, 0
;; if winner, reset board
invoke set_board
invoke InvalidateRect, hWin, 0, 0
xor eax, eax
ret
.endif
.endif
.endif
.endif
.elseif uMsg == WM_PAINT
invoke BeginPaint, hWin, addr ps
mov hDC, eax
invoke GetClientRect, hWin, addr rct
invoke CreateCompatibleDC, hDC
mov mDC, eax
invoke CreateCompatibleBitmap, hDC, rct.right, rct.bottom
mov hBmp, eax
invoke SelectObject, mDC, hBmp
mov hBmp_old, eax
invoke CreateSolidBrush, 003F3F3Fh
mov hBrush, eax
invoke FillRect, mDC, addr rct, hBrush
invoke painting, mDC ; paint the game pieces
invoke BitBlt, hDC, 0, 0, rct.right, rct.bottom, mDC, 0, 0, SRCCOPY
invoke SelectObject, mDC, hBmp_old
invoke DeleteObject, hBmp
invoke DeleteObject, hBrush
invoke DeleteDC, mDC
invoke EndPaint, hWin, addr ps
.elseif uMsg == WM_CLOSE
invoke EndDialog, hWin, 0
.endif
xor eax, eax
ret
DlgProc endp
;; prng based on nrandom in masm32.lib
randb proc base:dword
.data?
randseed dd ?
.code
push esi
push edi
push ebx
push edx
push ecx
invoke GetTickCount
add randseed, eax
mov eax, randseed
xor edx, edx
mov ecx, 127773
div ecx
mov ecx, eax
mov eax, 16807
mul edx
mov edx, ecx
mov ecx, eax
mov eax, 2836
mul edx
sub ecx, eax
xor edx, edx
mov eax, ecx
mov randseed, ecx
div base
mov eax, edx
pop ecx
pop edx
pop ebx
pop edi
pop esi
ret
randb endp
;; scrambles the game board somewhat randomly 1 iteration
scramble proc dst:dword, Below:dword, Right:dword, Above:dword, Left:dword
push esi
push edi
push ebx
push edx
push ecx
mov ecx, dst
mov edx, Below
mov ebx, Right
mov esi, Above
mov edi, Left
invoke randb, 4
.if byte ptr [ecx] == 0 && eax == 0
mov al, byte ptr [edx]
mov byte ptr [ecx], al
mov byte ptr [edx], 0
.elseif byte ptr [ecx] == 0 && eax == 1
mov al, byte ptr [ebx]
mov byte ptr [ecx], al
mov byte ptr [ebx], 0
.elseif byte ptr [ecx] == 0 && eax == 2
mov al, byte ptr [esi]
mov byte ptr [ecx], al
mov byte ptr [esi], 0
.elseif byte ptr [ecx] == 0 && eax == 3
mov al, byte ptr [edi]
mov byte ptr [ecx], al
mov byte ptr [edi], 0
.endif
pop ecx
pop edx
pop ebx
pop edi
pop esi
ret
scramble endp
;; scrambles the game board somewhat randomly for 'reps' number of iterations
set_board proc
local ctr1:dword
mov ctr1, 0
mov a1, 1
mov a2, 2
mov a3, 3
mov a4, 4
mov b1, 5
mov b2, 6
mov b3, 7
mov b4, 8
mov c1, 9
mov c2, 10
mov c3, 11
mov c4, 12
mov d1, 13
mov d2, 14
mov d3, 15
mov d4, 0
top:
inc ctr1
invoke scramble, addr a1, addr b1, addr a2, addr a1, addr a1
invoke scramble, addr a2, addr b2, addr a3, addr a2, addr a1
invoke scramble, addr a3, addr b3, addr a4, addr a3, addr a2
invoke scramble, addr a4, addr b4, addr a4, addr a4, addr a3
invoke scramble, addr b1, addr c1, addr b2, addr a1, addr b1
invoke scramble, addr b2, addr c2, addr b3, addr a2, addr b1
invoke scramble, addr b3, addr c3, addr b4, addr a3, addr b2
invoke scramble, addr b4, addr c4, addr b4, addr a4, addr b3
invoke scramble, addr c1, addr d1, addr c2, addr b1, addr c1
invoke scramble, addr c2, addr d2, addr c3, addr b2, addr c1
invoke scramble, addr c3, addr d3, addr c4, addr b3, addr c2
invoke scramble, addr c4, addr d4, addr c4, addr b4, addr c3
invoke scramble, addr d1, addr d1, addr d2, addr c1, addr d1
invoke scramble, addr d2, addr d2, addr d3, addr c2, addr d1
invoke scramble, addr d3, addr d3, addr d4, addr c3, addr d2
invoke scramble, addr d4, addr d4, addr d4, addr c4, addr d3
cmp ctr1, reps
jl top
ret
set_board endp
end
Quote from: jj2007 on Today at 02:50:45 AMI prefer event-driven programming with "real" windowsI usually do use real windows too. But I have been working with dialog boxes recently, and am converting some old code, switching from using windows to dialog boxes, and eliminating butmaps. I wanted to eliminate the .rc file altogether, but in memory dialogs seem more trouble than they are worth. (without using macros to do it)
Quote from: jack on Today at 03:06:22 AMI had forgotten to zero out the sum for the second test, so it just kept adding, it's fixed now if you want to download the binary
multiply n times d 100000000 times in a loop
a sum of the product is kept and printed out
in order to prevent gcc from eliminating the loop
and thereby making the timing meaningless
n = 340282366920938463447387429234553266722
d = 18446744073709551615
product = 45370982256125128475310893311622766046
sum of product = 113427455641665582386530236262442737152
assembler version
elapsed time seconds 0.338004100020044
n = 340282366920938463447387429234553266722
d = 18446744073709551615
product = 45370982256125128475310893311622766046
sum of product = 113427455641665582386530236262442737152
high level version
elapsed time seconds 0.0723988000536337
press return to end
Quote from: zedd151 on Today at 02:58:19 AMBut wait, something is amiss.I had forgotten to zero out the sum for the second test, so it just kept adding, it's fixed now if you want to download the binary
'sum of product = 226854911283331164773060472524885474304' - for the high level version in my test?
and 'sum of product = 113427455641665582386530236262442737152' - for the high level version in your test.