My firts exampler C

Page 2/2
1 |

By aceki

Master (147)

aceki's picture

04-01-2018, 18:49

Wolverine_nl wrote:

Just something I have found in my old archive, maybe usefull, it is made for MSX-C v1.2
The code it crude, so it can be corrected on all fronts probably, but it works.
Mind, these functions are meant to be before the main() and in the main you can call them in a While loop (game loop).
Some declarations you have to make, it are snippets of functions just for the idea:

#define XMAX (TINY) 240 /* boundries screen movement player */
#define YMAX (TINY) 180 /* boundries screen movement player */
#define XMIN (TINY) 1 /* boundries screen movement player */
#define YMIN (TINY) 12 /* boundries screen movement player */
#define logop (TINY) 0
#define jport (TINY) 0
int px; /* player axis */
int py; /* player axis */
int min;
int max;


/* Player Sprite info */
VOID pl_sprite()
{
	sprite((TINY)11,plspra); 
	sprite((TINY)12,plsprb); 
	
	colspr((TINY)11,plclra); 
	colspr((TINY)12,plclrb); 
}

--
/* 			Player put sprite 			 */
/* ========================================= */	
VOID put_pl_sprite(px,py)
int px;
int py;
{
	pl_sprite();			
			putspr((TINY)11,px,py,logop,(TINY)11);
			putspr((TINY)12,px,py,logop,(TINY)12);
							
}

/* boundaries axis */
VOID in_range()
{
if (px > XMAX) 
	{px = XMAX;}
if (py > YMAX) 
		{py = YMAX;}
if (py < YMIN) 
		{py = YMIN;}
if (px < XMIN) 
		{px = XMIN;}
}

/* Player Controls */
VOID ctrl_pl_sprite()
{
min = 0; 
max = 16; 
for(min = 0;min < max; min++); 
			if (gtstck(jport) == 1) /* forward */
			{py = (py-1);} 
			else if (gtstck(jport) == 2) /* forward-right */
			{px = (px+1); py = (py-1); }
			else if (gtstck(jport) == 3) /* right */
			{px = (px+1); }
			else if (gtstck(jport) == 4) /* down-right */
			{px = (px+1);py=(py+1); }
			else if (gtstck(jport) == 5) /* down */
			{py = (py+1); }
			else if (gtstck(jport) == 6) /* down-left */
			{px = (px-1); py=(py+1);}
			else if (gtstck(jport) == 7) /* left */
			{px = (px-1); }
			else if (gtstck(jport) == 8) /* forward-left */
			{px = (px-1);py=(py-1);}
			put_pl_sprite(px,py);
			return(0);
}

Excelent!! thank yoy for you help!

By Mumbly

Resident (49)

Mumbly's picture

04-01-2018, 20:21

Thanks to share this, I never developped anything in c on msx (always in assembly)
Is it possible to make asm inline like in turbo c?

By Wolverine_nl

Paragon (1046)

Wolverine_nl's picture

04-01-2018, 21:01

No problem!
@Mumbly
In both ascii msx c and sdcc compilers you can use asm, both handle it differently though.
I dont have enough experience with it, but i think i read that sdcc compiler is better with inline asm, some other devs used it that way.

By Jin

Resident (37)

Jin's picture

22-05-2018, 21:08

Hello everyone

I have tryied these examples but without success, (some commands seems to be missing)

even when i include .h files these examples keep showing error messages.

can someone share these examples in file version?

Page 2/2
1 |