Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

do not know where is the bug

A community discussion post from the original code:zIRON forum.

Replies

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , when putting ';' i got that error

[2,13]: Expected program but found ; in [sprite.zir] Code: plugin off;

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

lol... still incorrect

Code: plugin off;

replace "plugin" with "plugins"

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

oh , sorry.

have an other problem with my code , i am afraid to post it because it is long.

can i post it here or send to you in zip file?

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

posting is fine :)

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , i divided my source code into 4 files.

the main one is here 'sprite.zir'

plugins off;

program WIN32GUI 'Sprite';

#include 'user32.zir';
#include 'kernel32.zir';
#include 'messages.zir';
#include 'colors.zir';
#include 'console.zir';
#include 'strings.zir';

#include 'FPScalc.zir';
#include 'Dx9.zir';
#include 'Win.zir';

Dword HWin = CreateWin(1024,768);

IDirect3DDevice9 Dx9device = InitDx9(HWin,1024,768);

edi = Dx9device;
push esi;
esi = 0xFF000000;

// Set up message loop
dword quit;
while (quit <> WM_QUIT) 
{ 
  
    edi.clear(0, nil, 3, esi, 1.0, 0);
	edi.BeginScene;
	FPScalc();
    edi.EndScene;
	edi.Present(nil, nil, 0, nil);
	add esi, 0x512
	
	SetWindowText(HWin,@StringFPS);
	
	quit = DoEvent(); 
}

edi as nothing;
pop esi

ExitProcess(0);

'Dx9.zir' file is

#include 'directx/direct3d9.zir';

const D3DPRESENT_INTERVAL_IMMEDIATE  =  0x80000000;
const D3DADAPTER_DEFAULT = 0;
const D3D_OK = 0;

type bool = boolean;

function InitDx9(Dword Wnd,Width,Height;bool pVsync = true,pFullscreen = false)
{
   uses edi;
   D3DPRESENT_PARAMETERS presParams;
   D3DDISPLAYMODE mDisplayMode;
   IDirect3DDevice9 dx_device;
   
   IDirect3D9 dx_object = Direct3DCreate9(D3D_SDK_VERSION);
   Edi = dx_object as IDirect3D9;
   // Windowed
	if (!pFullscreen)
	{
		Edi.GetAdapterDisplayMode (D3DADAPTER_DEFAULT, @mDisplayMode);
		if (eax != D3D_OK)
		 {
		     print('error');
		 }
    else
	// Full screen
	{
		mDisplayMode.Width = Width;
		mDisplayMode.Height = Height;
		mDisplayMode.RefreshRate = 0; 
		mDisplayMode.Format = D3DFMT_A8R8G8B8;
	}
   
   m_strFill(@presParams, sizeof presParams, 0);
   // Windowed
	if (!pFullscreen)
	{ 
	   presParams.Windowed           = true;
	   presParams.BackBufferWidth    = Width;
       presParams.BackBufferHeight   = Height;
	}
	else
	// Full screen
	{
	   presParams.Windowed           = false;
	   presParams.BackBufferWidth    = mDisplayMode.Width;
       presParams.BackBufferHeight   = mDisplayMode.Height;
	}
   presParams.hDeviceWindow          = Wnd;   
   presParams.BackBufferCount        = 1;
   presParams.BackBufferFormat       = mDisplayMode.Format;
   presParams.SwapEffect             = D3DSWAPEFFECT_DISCARD;
   presParams.AutoDepthStencilFormat = D3DFMT_D16;
   presParams.EnableAutoDepthStencil = True;
   presParams.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
   
   DWORD mQualityLevels;
   D3DCAPS9 pCaps;
   Edi = dx_object as IDirect3D9;
   Edi.GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, @pCaps);
   Edi.CheckDeviceMultiSampleType(pCaps.AdapterOrdinal,pCaps.DeviceType,mDisplayMode.Format,presParams.Windowed,D3DMULTISAMPLE_2_SAMPLES,@mQualityLevels);
   presParams.MultiSampleType        = D3DMULTISAMPLE_2_SAMPLES;
   presParams.MultiSampleQuality     = mQualityLevels; 
   
   Eax = Edi.CreateDevice(0, D3DDEVTYPE_HAL, Wnd, 64, @presParams, @dx_device);
  
   return dx_device;
}

'Win.zir' file is

const SM_CXSCREEN = 0;
const SM_CYSCREEN = 1;

function abs(int32 val)
{
  eax = val;
  if(eax:int < 0)
   {
     neg eax;
   }
} 
//////////////////////////////


function WindowProc(Dword hWnd, uMsg, wParam, lParam)
{
	if (uMsg == WM_DESTROY) {
		PostQuitMessage(0);
	 }
    
    DefWindowProc(hWnd, uMsg, wParam, lParam);
}


//
function CreateWin(dword Width,Height)
{
  const className = 'ZMainFRM';
  tagWndClassA wndClass;
  Dword hInstance = GetModuleHandleA(nil);  
  Dword hWin;

  m_strFill(@wndClass, sizeof tagWndClassA, 0);

  wndClass.hbrBackground = COLOR_BACKGROUND;
  wndClass.hInstance     = hInstance;
  wndClass.lpszClassName = className; 
  wndClass.lpfnWndProc   = @WindowProc;
    
  if (RegisterClassA(@wndClass) == 0) {
    eax = GetLastError();  
    print('RegisterClassA error: ',eax:int,'\r\n');
  }
  hWin = CreateWindowExA(0, className, 'window Demo', WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, Width,Height, 0, 0, hInstance, nil);
  
  if (hWin == null) {
    eax = GetLastError();
    print('CreateWindowExA error: ',eax:int,'\r\n');
  }
  
  // center our window before shoing it
  GetSystemMetrics (SM_CXSCREEN);
  eax -= Width;
  if(eax < 0) 
   {
     neg eax;
   }
  eax >> 1; 
  int32 mCenterX =  eax;
  GetSystemMetrics (SM_CYSCREEN);
  eax -= Height;
  if(eax < 0) 
   {
     neg eax;
   }
  eax >> 1; 
  int32 mCenterY = eax;
  SetWindowPos (hWin, 0, mCenterX, mCenterY, Width,Height, 0 );
  
  ShowWindow(hWin, SW_SHOWNORMAL);
  
  return hWin;
}


//variables

function DoEvent()
{
  tagMsg msg;
  if (PeekMessage(@msg, 0, 0, 0, 1))
	 {
		TranslateMessage(@msg);
		DispatchMessage(@msg);
	 }	
  return msg.message;	 
}

'FPScalc.zir' file is

char* fpsview='FPS %d';
byte  StringFPS[255];
dword FPS;
dword LastTime;

procedure FPScalc()
{
	FPS++;
	Edx = GetTickCount();
	Eax -= LastTime;
	if(Eax => 1000)
	 {
		LastTime = Edx;
		wsprintf(@StringFPS,fpsview,FPS);
		FPS=0;
	 }
}

then when compiling it i get that error

[29,32]: Expected identifier but found Width in [Win.zir] Code: function CreateWin(dword Width,Height)

any help please?

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I couldn't quite read your code so i've rewrote some of it and re-tabbed, anyways got it compiling and working:

sprite.zir:

plugins off;

program WIN32CUI 'Sprite';

#include 'messages.zir';
#include 'colors.zir';
#include 'ch.zir';
#include 'Win.zir';
#include 'FPScalc.zir';
#include 'Dx9.zir';

Dword HWin = CreateWin(1024,768);

IDirect3DDevice9 Dx9device = InitDx9(HWin,1024,768);

edi = Dx9device as IDirect3DDevice9;

// Set up message loop
eax = 0;
while (eax <> WM_QUIT) { 
  
	edi.clear(0, nil, 3, 0xFF000000, 1.0, 0);
	edi.BeginScene;
	FPScalc();
	edi.EndScene;
	edi.Present(nil, nil, 0, nil);
  
	SetWindowText(HWin,@StringFPS);
  
	eax = DoEvent(); 
}

ExitProcess(0);

Dx9.zir: [b]note there is still 1 problem in this function but i will let you solve it, tomorrow if you did not i will take another look

#include 'directx/direct3d9.zir';

const D3DPRESENT_INTERVAL_IMMEDIATE  =  0x80000000;
const D3DADAPTER_DEFAULT = 0;
const D3D_OK = 0;

type bool = boolean;

function InitDx9(Dword Wnd,Width,Height;bool pVsync = true,pFullscreen = false) {
	uses edi;

	D3DPRESENT_PARAMETERS presParams;
	D3DDISPLAYMODE mDisplayMode;
	IDirect3DDevice9 dx_device;
   
	m_strFill(@mDisplayMode, sizeof mDisplayMode, 0);   
	m_strFill(@presParams, sizeof presParams, 0);

	IDirect3D9 dx_object = Direct3DCreate9(D3D_SDK_VERSION);
   
	Edi = dx_object as IDirect3D9;
	
	if (!pFullscreen) {
		eax = edi.GetAdapterDisplayMode (D3DADAPTER_DEFAULT, @mDisplayMode);
		if (eax != D3D_OK) {
			print('error\r\n');
		}
	} else {
		//fullscreen
		mDisplayMode.Width = Width;
		mDisplayMode.Height = Height;
		mDisplayMode.RefreshRate = 0; 
		mDisplayMode.Format = D3DFMT_A8R8G8B8;		
	}
	
	if (!pFullscreen) { 
		// Windowed
		presParams.Windowed           = true;
		presParams.BackBufferWidth    = Width;
		presParams.BackBufferHeight   = Height;
	} else {
		// Full screen	
		presParams.Windowed           = false;
		presParams.BackBufferWidth    = mDisplayMode.Width;
		presParams.BackBufferHeight   = mDisplayMode.Height;
	}	
	
	presParams.hDeviceWindow          = Wnd;   
	presParams.BackBufferCount        = 1;
	presParams.BackBufferFormat       = mDisplayMode.Format;
	presParams.SwapEffect             = D3DSWAPEFFECT_DISCARD;
	presParams.AutoDepthStencilFormat = D3DFMT_D24X8; //D3DFMT_D16;
	presParams.EnableAutoDepthStencil = True;
	presParams.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;	
	
	/* the following code crashes app >>>>
	
	DWORD mQualityLevels;
	D3DCAPS9 pCaps;

	eax = edi.GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, @pCaps);
	edi.CheckDeviceMultiSampleType(pCaps.AdapterOrdinal,pCaps.DeviceType,mDisplayMode.Format,presParams.Windowed,D3DMULTISAMPLE_2_SAMPLES,@mQualityLevels);
	presParams.MultiSampleType        = D3DMULTISAMPLE_2_SAMPLES;
	presParams.MultiSampleQuality     = mQualityLevels; 	
	*/
	
	Eax = Edi.CreateDevice(0, D3DDEVTYPE_HAL, Wnd, 64, @presParams, @dx_device);
  
	return dx_device;
}

FPScalc.zir:

char* fpsview='FPS %d';
byte  StringFPS[255];
dword FPS;
dword LastTime;

procedure FPScalc()
{
  FPS++;
  Edx = GetTickCount();
  Eax -= LastTime;
  if(Eax => 1000)
   {
    LastTime = Edx;
    wsprintf(@StringFPS,fpsview,FPS);
    FPS=0;
   }
}

Win.zir:

const SM_CXSCREEN = 0;
const SM_CYSCREEN = 1;

function abs(int32 val) {
	if (val < 0) {
		eax = val;  
		neg eax;
	}
} 
//////////////////////////////


function WindowProc(Dword hWnd, uMsg, wParam, lParam)
{
  if (uMsg == WM_DESTROY) {
    PostQuitMessage(0);
   }
    
    DefWindowProc(hWnd, uMsg, wParam, lParam);
}


//
function CreateWin(DWord width, height) {
	uses edi;
	const className = 'ZMainFRM';
	tagWndClassA wndClass;
	Dword hInstance = GetModuleHandleA(nil);  

	m_strFill(@wndClass, sizeof tagWndClassA, 0);

	wndClass.hbrBackground = COLOR_BACKGROUND;
	wndClass.hInstance = hInstance;
	wndClass.lpszClassName = className; 
	wndClass.lpfnWndProc = @WindowProc;
    
	if (RegisterClassA(@wndClass) == 0) {
		eax = GetLastError();  
		print('RegisterClassA error: ',eax:int,'\r\n');
	}
	edi = CreateWindowExA(0, className, 'window Demo', WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, 0, 0, hInstance, nil);
  
	if (edi == null) {
		eax = GetLastError();
		print('CreateWindowExA error: ',eax:int,'\r\n');
	}
	ShowWindow(edi, SW_SHOWNORMAL);
	
	return edi;
}
/*
function CreateWin(dword Width,Height)
{
  const className = 'ZMainFRM';
  tagWndClassA wndClass;
  Dword hInstance = GetModuleHandleA(nil);  
  Dword hWin;

  m_strFill(@wndClass, sizeof tagWndClassA, 0);

  wndClass.hbrBackground = COLOR_BACKGROUND;
  wndClass.hInstance     = hInstance;
  wndClass.lpszClassName = className; 
  wndClass.lpfnWndProc   = @WindowProc;
    
  if (RegisterClassA(@wndClass) == 0) {
    eax = GetLastError();  
    print('RegisterClassA error: ',eax:int,'\r\n');
  }
  hWin = CreateWindowExA(0, className, 'window Demo', WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, Width,Height, 0, 0, hInstance, nil);
  
  if (hWin == null) {
    eax = GetLastError();
    print('CreateWindowExA error: ',eax:int,'\r\n');
  }
  
  // center our window before shoing it
  GetSystemMetrics (SM_CXSCREEN);
  eax -= Width;
  if(eax < 0) 
   {
     neg eax;
   }
  eax >> 1; 
  int32 mCenterX =  eax;
  GetSystemMetrics (SM_CYSCREEN);
  eax -= Height;
  if(eax < 0) 
   {
     neg eax;
   }
  eax >> 1; 
  int32 mCenterY = eax;
  SetWindowPos (hWin, 0, mCenterX, mCenterY, Width,Height, 0 );
  
  ShowWindow(hWin, SW_SHOWNORMAL);
  
  return hWin;
}*/


//variables

function DoEvent()
{
  tagMsg msg;
  if (PeekMessage(@msg, 0, 0, 0, 1))
   {
    TranslateMessage(@msg);
    DispatchMessage(@msg);
   }  
  return msg.message;   
}

now i will go to bath, good night :)

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok your modification solve the error.

but what was the problem there , i want to know to avoid that in the future.


http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

The problem was in InitDx9 function

  if (!pFullscreen)
  {
    Edi.GetAdapterDisplayMode (D3DADAPTER_DEFAULT, @mDisplayMode);
    if (eax != D3D_OK)
     {
         print('error');
     }
    else
  // Full screen
  {
    mDisplayMode.Width = Width;
    mDisplayMode.Height = Height;
    mDisplayMode.RefreshRate = 0; 
    mDisplayMode.Format = D3DFMT_A8R8G8B8;
  }

here you were missing 1 }, but actually there was no syntax error because the code was folded into the main procedure which caused a problem :)