'The example demonstrates use DDRAW with FPU
'
'I have not carried out optimization of a code - this is a crude code
'This code has reminded me about old kind DOS
'DisplayMode is 320x200x32 ~ &FFFFFFFF
'
'DDRAW.INC You can take in - http://ryme.future.easyspace.com/
'
'I have made change of a movement ON a vertical.
'You has an opportunity TO make it also ON a horizontal.
' --------------------------- V.Shulakov ---------------------------
#COMPILE EXE
#OPTION VERSION4
#DIM ALL
#INCLUDE "WIN32API.INC"
#INCLUDE "DDRAW.INC"
%NULL_PAINT = &h00000000
%BLUE_PAINT = &h000099ff
%YELL_PAINT = &h00ffff00
DECLARE SUB NEXTFLAG()
GLOBAL ddsd AS DDSURFACEDESC
GLOBAL fk AS SINGLE '
GLOBAL lpDDSPrimary AS LONG
GLOBAL ddscaps AS DDSCAPS
GLOBAL LPDD AS DWORD
GLOBAL DDWIDTH AS LONG
GLOBAL DDHEIGHT AS LONG
'__________________________________ START ___________________________________
'
FUNCTION WINMAIN (BYVAL hInst AS LONG, _
BYVAL hPrevInst AS LONG, _
CmdLine AS ASCIIZ PTR, _
BYVAL CmdShow AS LONG) EXPORT AS LONG
LOCAL Msg AS tagMsg
LOCAL wndclass AS WndClassEx
GLOBAL hWnd AS LONG
LOCAL szClassName AS ASCIIZ * 80
LOCAL szDisplayName AS ASCIIZ * 80
LOCAL TMP AS LONG
GLOBAL GPTR AS LONG
DIM G(1:200,1:90) AS GLOBAL LONG
GPTR = VARPTR(G(1,1))
ddwidth = 320
ddheight = 200
fk = 0.031
szClassName = "DDraw FPU Demo"
szDisplayName = szClassName
wndclass.cbSize = SIZEOF(WndClass)
wndclass.style = %CS_HREDRAW OR %CS_VREDRAW
wndclass.lpfnWndProc = CODEPTR( WndProc )
wndclass.cbClsExtra = 0
wndclass.cbWndExtra = 0
wndclass.hInstance = hinst
wndclass.hIcon = 0
wndclass.hCursor = 0
wndclass.hbrBackground = GetStockObject( %white_BRUSH )
wndclass.lpszMenuName = %NULL
wndclass.lpszClassName = VARPTR( szClassName )
wndclass.hIconSm = 0
RegisterClassEx wndclass
HWND=CreateWindowEx(0,szClassName,_
szDisplayName,_
%WS_POPUP,_
0, 0, ddwidth, ddheight,_
BYVAL %NULL, BYVAL %NULL,_
hInst, BYVAL %NULL)
ShowWindow hWnd, %SW_SHOWNORMAL
SetFocus hWnd
ShowCursor 0
'_________________________________________________________________
'
IF %DD_OK<>DDDirectDrawCreate(BYVAL %NULL,lpDD,BYVAL %NULL) THEN
! JMP FATAL
END IF
IF %DD_OK<>DDSetCooperativeLevel(lpDD, hWnd, _
%DDSCL_EXCLUSIVE OR %DDSCL_FULLSCREEN) THEN
! JMP FATAL
END IF
IF %DD_OK<>DDSetDisplayMode( lpDD, ddwidth, ddheight, 32) THEN
! JMP FATAL
END IF
ddsd.dwSize=SIZEOF(DDSD)
ddsd.dwFlags=%DDSD_CAPS
ddsd.ddsCaps.dwCaps=%DDSCAPS_PRIMARYSURFACE
IF %DD_OK<>DDCreateSurface(lpDD, ddsd, lpDDSPrimary) THEN
! JMP FATAL
END IF
'_________________________________________________________________
'
WHILE -1
IF 0<>PeekMessage(msg, BYVAL %NULL, 0, 0, %PM_REMOVE) THEN
IF msg.message = %WM_QUIT THEN
PostQuitMessage msg.wParam
EXIT LOOP
ELSE
TranslateMessage msg
DispatchMessage msg
END IF
ELSE
IF GetFocus = hWnd THEN
ddsd.dwSize= SIZEOF(DDSD) '(DDSURFACEDESC)
ddsd.dwFlags=%DDSD_PITCH
WHILE -1
TMP=DDSLock(lpDDSPrimary, BYVAL %NULL, ddsd, %DDLOCK_WAIT, BYVAL %NULL)
IF TMP = %DD_OK THEN
EXIT LOOP
ELSEIF TMP = %DDERR_SURFACELOST THEN
DDSRestore lpDDSPrimary
END IF
WEND
DDWaitForVerticalBlank lpDD, %DDWAITVB_BLOCKBEGIN, BYVAL %NULL
STATIC L AS LONG
IF L=0 THEN
! call NEXTframe
! mov L,1
ELSE
! call NEXTFLAG
END IF
DDSUNLOCK lpDDSPrimary, ddsd.lpSurface
ELSE
! mov L,0
END IF
END IF
WEND
FATAL: '*************************************************************
IF lpDD <> %NULL THEN
IF lpDDSPrimary <> %NULL THEN
DDIRelease lpDDSPrimary
lpDDSPrimary = %NULL
END IF
DDIRelease lpDD
lpDD = %NULL
END IF
FUNCTION= msg.wParam
END FUNCTION
'_____________________________________________________________________________________
' Window Proc
'_____________________________________________________________________________________
'
FUNCTION WndProc (BYVAL hWin AS LONG, BYVAL uMsg AS LONG, _
BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
IF uMsg = %WM_KEYDOWN THEN
IF wParam = %VK_ESCAPE THEN
PostQuitMessage 0
FUNCTION=0
EXIT FUNCTION
END IF
ELSEIF uMsg = %WM_DESTROY THEN
PostQuitMessage 0
FUNCTION=0
EXIT FUNCTION
END IF
FUNCTION = DefWindowProc(hWin, uMsg, wParam, lParam)
END FUNCTION
'____________________________________________________________
'
SUB nextFrame
#REGISTER NONE
LOCAL col AS LONG
LOCAL j AS LONG
LOCAL i AS LONG
! PUSHAD
! mov eax,ddsd[36]
! mov esi,eax ; ' htmp=ddsd.lpSurface
! mov col,201
! xor edx,edx
mf0:
! inc edx
! dec col
! mov eax,esi
! mov edi,eax
! xor ecx,ecx
mf1:
! inc ecx
! mov eax,230
! sub eax,col
! mov ebx,edi
! mov [ebx],eax ; ' BLUE
! INC edi
! mov eax,230
! sub eax,col
! mov ebx,edi
! mov [ebx],eax ; ' GREEN
! INC edi
! mov ebx,edi
! xor eax,eax
! mov [ebx],eax ; ' RED
! INC edi
! mov ebx,edi
! xor eax,eax
! mov [ebx],eax ; ' REZiNTEN -----
! INC edi
! cmp ecx,320
! jne mf1 ;--------------------->
! mov eax,ddsd[16]
! add esi,eax ; ' htmp=htmp+ddsd.Union1.lPitch
! cmp edx,200
! jne mf0 ;--------------------->
! mov J,0
mfr2: 'for j
! mov I,0
mfr1: 'for i
! cmp J,11
! jl ML1
! cmp J,80
! jg ML1
! cmp I,11
! jl ML1
! cmp I,190
! jg ML1
! cmp J,46
! jl ML2
! jmp ML3
ML1:
! mov eax,J
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov esi,%NULL_PAINT
! mov [edx],esi
! jmp ML0
ML2:
! mov eax,j
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov esi,%BLUE_PAINT
! mov [edx],esi
! jmp ML0
ML3:
! mov eax,j
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov esi,%YELL_PAINT
! mov [edx],esi
ML0:
! inc I
! cmp I,200
! jl mfr1
! inc J
! cmp J,90
! jl mfr2
! POPAD
END SUB
'_________________________________________________________
'
SUB NEXTFLAG
#REGISTER NONE
LOCAL i AS LONG 'for i~
LOCAL J AS LONG 'for j~
STATIC K AS SINGLE 'FPU tmp
STATIC J1 AS SINGLE 'FPU tmp
STATIC H AS LONG
STATIC H1 AS LONG
LOCAL col AS LONG 'COLOR--
LOCAL ftmp AS LONG 'FPU tmp
LOCAL fi AS LONG 'FPU tmp
! PUSHAD
! mov eax,ddsd[16] ;ddsd.Union1.lPitch
! mov ebx,45
! mul ebx
! add eax,ddsd[36] ;ddsd.lpSurface
! mov esi,eax ;htmp
! mov FI,10
! mov I,0
mfrp1: 'for i 200
! inc I
! fld K
! fadd FK
! fst K
! fcos
! fimul FI
! fist H
! fst J1
! mov ftmp,4
! fimul ftmp
! fist H1
! add H1,40
! fninit
! mov eax,ddsd[16]
! mul H
! mov ebx,eax
! mov eax,I
! shl eax,2
! add eax,240
! add eax,esi
! add eax,ebx
! mov edi,eax
! mov COL,201
! mov J,0
mfrp2: 'for j 90
! inc J
! INC H
! DEC COL
! mov eax,J
! dec eax
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! dec ebx
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov eax,[edx]
! cmp eax,0 ;cmp<>0
! jz m_null
! mov al,[edx]
! cmp al,0
! jz mb1
! sub al,H1
mb1:
! mov [edi],al
! mov al,[edx+1]
! cmp al,0
! jz mb2
! sub al,H1
mb2:
! mov [edi+1],al
! mov al,[edx+2]
! cmp al,0
! jz mb3
! sub al,H1
mb3:
! mov [edi+2],al
! mov al,[edx+3]
! cmp al,0
! jz mb4
! sub al,H1
mb4:
! mov [edi+3],al
! jmp m_finish
m_null: 'frame colored fill
! mov al,H
! add al,74
! mov [edi],al ; 'BLUE 155 << 177 >--
! mov [edi+1],al ; 'GREEN
! xor al,al
! mov [edi+2],al ; 'RED
! mov [edi+3],al ; 'INTENS
m_finish:
! mov eax,ddsd[16]
! add edi,eax
! cmp J,90
! jl mfrp2 ;--------------------->
! cmp I,200
! jl mfrp1 ;--------------------->
! POPAD
END SUB
'___________________________________________________________________
'
' end end end end end end end end end end end end end end end end
'___________________________________________________________________
'
------------------
'
'I have not carried out optimization of a code - this is a crude code
'This code has reminded me about old kind DOS
'DisplayMode is 320x200x32 ~ &FFFFFFFF
'
'DDRAW.INC You can take in - http://ryme.future.easyspace.com/
'
'I have made change of a movement ON a vertical.
'You has an opportunity TO make it also ON a horizontal.
' --------------------------- V.Shulakov ---------------------------
#COMPILE EXE
#OPTION VERSION4
#DIM ALL
#INCLUDE "WIN32API.INC"
#INCLUDE "DDRAW.INC"
%NULL_PAINT = &h00000000
%BLUE_PAINT = &h000099ff
%YELL_PAINT = &h00ffff00
DECLARE SUB NEXTFLAG()
GLOBAL ddsd AS DDSURFACEDESC
GLOBAL fk AS SINGLE '
GLOBAL lpDDSPrimary AS LONG
GLOBAL ddscaps AS DDSCAPS
GLOBAL LPDD AS DWORD
GLOBAL DDWIDTH AS LONG
GLOBAL DDHEIGHT AS LONG
'__________________________________ START ___________________________________
'
FUNCTION WINMAIN (BYVAL hInst AS LONG, _
BYVAL hPrevInst AS LONG, _
CmdLine AS ASCIIZ PTR, _
BYVAL CmdShow AS LONG) EXPORT AS LONG
LOCAL Msg AS tagMsg
LOCAL wndclass AS WndClassEx
GLOBAL hWnd AS LONG
LOCAL szClassName AS ASCIIZ * 80
LOCAL szDisplayName AS ASCIIZ * 80
LOCAL TMP AS LONG
GLOBAL GPTR AS LONG
DIM G(1:200,1:90) AS GLOBAL LONG
GPTR = VARPTR(G(1,1))
ddwidth = 320
ddheight = 200
fk = 0.031
szClassName = "DDraw FPU Demo"
szDisplayName = szClassName
wndclass.cbSize = SIZEOF(WndClass)
wndclass.style = %CS_HREDRAW OR %CS_VREDRAW
wndclass.lpfnWndProc = CODEPTR( WndProc )
wndclass.cbClsExtra = 0
wndclass.cbWndExtra = 0
wndclass.hInstance = hinst
wndclass.hIcon = 0
wndclass.hCursor = 0
wndclass.hbrBackground = GetStockObject( %white_BRUSH )
wndclass.lpszMenuName = %NULL
wndclass.lpszClassName = VARPTR( szClassName )
wndclass.hIconSm = 0
RegisterClassEx wndclass
HWND=CreateWindowEx(0,szClassName,_
szDisplayName,_
%WS_POPUP,_
0, 0, ddwidth, ddheight,_
BYVAL %NULL, BYVAL %NULL,_
hInst, BYVAL %NULL)
ShowWindow hWnd, %SW_SHOWNORMAL
SetFocus hWnd
ShowCursor 0
'_________________________________________________________________
'
IF %DD_OK<>DDDirectDrawCreate(BYVAL %NULL,lpDD,BYVAL %NULL) THEN
! JMP FATAL
END IF
IF %DD_OK<>DDSetCooperativeLevel(lpDD, hWnd, _
%DDSCL_EXCLUSIVE OR %DDSCL_FULLSCREEN) THEN
! JMP FATAL
END IF
IF %DD_OK<>DDSetDisplayMode( lpDD, ddwidth, ddheight, 32) THEN
! JMP FATAL
END IF
ddsd.dwSize=SIZEOF(DDSD)
ddsd.dwFlags=%DDSD_CAPS
ddsd.ddsCaps.dwCaps=%DDSCAPS_PRIMARYSURFACE
IF %DD_OK<>DDCreateSurface(lpDD, ddsd, lpDDSPrimary) THEN
! JMP FATAL
END IF
'_________________________________________________________________
'
WHILE -1
IF 0<>PeekMessage(msg, BYVAL %NULL, 0, 0, %PM_REMOVE) THEN
IF msg.message = %WM_QUIT THEN
PostQuitMessage msg.wParam
EXIT LOOP
ELSE
TranslateMessage msg
DispatchMessage msg
END IF
ELSE
IF GetFocus = hWnd THEN
ddsd.dwSize= SIZEOF(DDSD) '(DDSURFACEDESC)
ddsd.dwFlags=%DDSD_PITCH
WHILE -1
TMP=DDSLock(lpDDSPrimary, BYVAL %NULL, ddsd, %DDLOCK_WAIT, BYVAL %NULL)
IF TMP = %DD_OK THEN
EXIT LOOP
ELSEIF TMP = %DDERR_SURFACELOST THEN
DDSRestore lpDDSPrimary
END IF
WEND
DDWaitForVerticalBlank lpDD, %DDWAITVB_BLOCKBEGIN, BYVAL %NULL
STATIC L AS LONG
IF L=0 THEN
! call NEXTframe
! mov L,1
ELSE
! call NEXTFLAG
END IF
DDSUNLOCK lpDDSPrimary, ddsd.lpSurface
ELSE
! mov L,0
END IF
END IF
WEND
FATAL: '*************************************************************
IF lpDD <> %NULL THEN
IF lpDDSPrimary <> %NULL THEN
DDIRelease lpDDSPrimary
lpDDSPrimary = %NULL
END IF
DDIRelease lpDD
lpDD = %NULL
END IF
FUNCTION= msg.wParam
END FUNCTION
'_____________________________________________________________________________________
' Window Proc
'_____________________________________________________________________________________
'
FUNCTION WndProc (BYVAL hWin AS LONG, BYVAL uMsg AS LONG, _
BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
IF uMsg = %WM_KEYDOWN THEN
IF wParam = %VK_ESCAPE THEN
PostQuitMessage 0
FUNCTION=0
EXIT FUNCTION
END IF
ELSEIF uMsg = %WM_DESTROY THEN
PostQuitMessage 0
FUNCTION=0
EXIT FUNCTION
END IF
FUNCTION = DefWindowProc(hWin, uMsg, wParam, lParam)
END FUNCTION
'____________________________________________________________
'
SUB nextFrame
#REGISTER NONE
LOCAL col AS LONG
LOCAL j AS LONG
LOCAL i AS LONG
! PUSHAD
! mov eax,ddsd[36]
! mov esi,eax ; ' htmp=ddsd.lpSurface
! mov col,201
! xor edx,edx
mf0:
! inc edx
! dec col
! mov eax,esi
! mov edi,eax
! xor ecx,ecx
mf1:
! inc ecx
! mov eax,230
! sub eax,col
! mov ebx,edi
! mov [ebx],eax ; ' BLUE
! INC edi
! mov eax,230
! sub eax,col
! mov ebx,edi
! mov [ebx],eax ; ' GREEN
! INC edi
! mov ebx,edi
! xor eax,eax
! mov [ebx],eax ; ' RED
! INC edi
! mov ebx,edi
! xor eax,eax
! mov [ebx],eax ; ' REZiNTEN -----
! INC edi
! cmp ecx,320
! jne mf1 ;--------------------->
! mov eax,ddsd[16]
! add esi,eax ; ' htmp=htmp+ddsd.Union1.lPitch
! cmp edx,200
! jne mf0 ;--------------------->
! mov J,0
mfr2: 'for j
! mov I,0
mfr1: 'for i
! cmp J,11
! jl ML1
! cmp J,80
! jg ML1
! cmp I,11
! jl ML1
! cmp I,190
! jg ML1
! cmp J,46
! jl ML2
! jmp ML3
ML1:
! mov eax,J
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov esi,%NULL_PAINT
! mov [edx],esi
! jmp ML0
ML2:
! mov eax,j
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov esi,%BLUE_PAINT
! mov [edx],esi
! jmp ML0
ML3:
! mov eax,j
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov esi,%YELL_PAINT
! mov [edx],esi
ML0:
! inc I
! cmp I,200
! jl mfr1
! inc J
! cmp J,90
! jl mfr2
! POPAD
END SUB
'_________________________________________________________
'
SUB NEXTFLAG
#REGISTER NONE
LOCAL i AS LONG 'for i~
LOCAL J AS LONG 'for j~
STATIC K AS SINGLE 'FPU tmp
STATIC J1 AS SINGLE 'FPU tmp
STATIC H AS LONG
STATIC H1 AS LONG
LOCAL col AS LONG 'COLOR--
LOCAL ftmp AS LONG 'FPU tmp
LOCAL fi AS LONG 'FPU tmp
! PUSHAD
! mov eax,ddsd[16] ;ddsd.Union1.lPitch
! mov ebx,45
! mul ebx
! add eax,ddsd[36] ;ddsd.lpSurface
! mov esi,eax ;htmp
! mov FI,10
! mov I,0
mfrp1: 'for i 200
! inc I
! fld K
! fadd FK
! fst K
! fcos
! fimul FI
! fist H
! fst J1
! mov ftmp,4
! fimul ftmp
! fist H1
! add H1,40
! fninit
! mov eax,ddsd[16]
! mul H
! mov ebx,eax
! mov eax,I
! shl eax,2
! add eax,240
! add eax,esi
! add eax,ebx
! mov edi,eax
! mov COL,201
! mov J,0
mfrp2: 'for j 90
! inc J
! INC H
! DEC COL
! mov eax,J
! dec eax
! mov ebx,800
! mul ebx
! mov edx,eax
! mov ebx,I
! dec ebx
! shl ebx,2
! add edx,ebx
! add edx,GPTR
! mov eax,[edx]
! cmp eax,0 ;cmp<>0
! jz m_null
! mov al,[edx]
! cmp al,0
! jz mb1
! sub al,H1
mb1:
! mov [edi],al
! mov al,[edx+1]
! cmp al,0
! jz mb2
! sub al,H1
mb2:
! mov [edi+1],al
! mov al,[edx+2]
! cmp al,0
! jz mb3
! sub al,H1
mb3:
! mov [edi+2],al
! mov al,[edx+3]
! cmp al,0
! jz mb4
! sub al,H1
mb4:
! mov [edi+3],al
! jmp m_finish
m_null: 'frame colored fill
! mov al,H
! add al,74
! mov [edi],al ; 'BLUE 155 << 177 >--
! mov [edi+1],al ; 'GREEN
! xor al,al
! mov [edi+2],al ; 'RED
! mov [edi+3],al ; 'INTENS
m_finish:
! mov eax,ddsd[16]
! add edi,eax
! cmp J,90
! jl mfrp2 ;--------------------->
! cmp I,200
! jl mfrp1 ;--------------------->
! POPAD
END SUB
'___________________________________________________________________
'
' end end end end end end end end end end end end end end end end
'___________________________________________________________________
'
------------------
Comment