From be883f10890316f1d5f84888eaecc16e05fa9571 Mon Sep 17 00:00:00 2001
From: sparky4 <sparky4@cock.li>
Date: Fri, 18 Dec 2015 12:24:29 -0600
Subject: [PATCH] wwww

---
 16/xw/modex/demo01.c  | 149 +++++++++++++++--------------
 16/xw_/modex/demo01.c | 218 ++++++++++++++++++++++--------------------
 2 files changed, 191 insertions(+), 176 deletions(-)

diff --git a/16/xw/modex/demo01.c b/16/xw/modex/demo01.c
index a53f87a2..0c9f3b02 100755
--- a/16/xw/modex/demo01.c
+++ b/16/xw/modex/demo01.c
@@ -1,111 +1,118 @@
 /*
-		DEMO01 - Sprites, page flipping and palette rotation
-		Copyright (c) 1994 Alessandro Scotti
-*/
-uses Crt, Modex;
+ *		DEMO01 - Sprites, page flipping and palette rotation
+ *		Copyright (c) 1994 Alessandro Scotti
+ */
+#include ../../x/modex.h
 
 #DEFINE MAX_SPRITE 100
 
-type
-	/* Sprite structure */
-	TSprite = record
-		X, Y : integer;												/* Sprite coordinates */
-		DX,DY: integer;												/* Deltas for sprite movement */
-		W, H : integer;												/* Sprite width and height */
-		Image: array[ 1..16, 1..16 ] of byte;	/* Sprite image data */
-	}
-	/* RGB color structure */
-	TRgb		= record
-		R, G, B: byte;
-	}
-var
-	S			: array[ 1..MAX_SPRITE ] of TSprite;	 /* An array of sprites */
-	Palette: array[ byte ] of TRgb;							 /* Palette */
-	Page	 : word;																/* Page offset */
-	I			: word;
+typedef unsigned char byte;
+typedef unsigned short word;
+typedef unsigned long  dword;
+
+/* Sprite structure */
+typedef struct {
+	int X, Y;												/* Sprite coordinates */
+	int DX,DY;												/* Deltas for sprite movement */
+	int W, H;												/* Sprite width and height */
+	byte Image[16,16];	/* Sprite image data */
+} TSprite;
+
+/* RGB color structure */
+typedef struct {
+	byte R, G, B;
+} TRgb;
+Tsprite S[MAX_SPRITE];	 /* An array of sprites */
+TRgb Palette[ byte ];							 /* Palette */
+word Page;																/* Page offset */
+word i;
 
 /* Initializes a sprite structure */
-procedure sxInit( var S: TSprite );
-var
-	I: word;
-begin
-	S.X = Random( 320 );	/* Initialize position with random values */
-	S.Y = Random( 240 );
-	S.DX = Random( 7 )-3; /* Initialize speed with random values */
-	S.DY = Random( 7 )-3;
-	S.W = 16;						 /* Size is fixed in this program */
-	S.H = 16;
-	/* The image is a square with a hole inside */
-	FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );
-	for I=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );
+void sxInit(TSprite *S)
+{
+//word i;
+
+S->X = rand( 320 );	/* Initialize position with random values */
+S->Y = rand( 240 );
+S->DX = rand( 7 )-3; /* Initialize speed with random values */
+S->DY = rand( 7 )-3;
+S->W = 16;						 /* Size is fixed in this program */
+S->H = 16;
+/* The image is a square with a hole inside */
+FillChar( S->Image, SizeOf(S->Image), rand(15)+1 );
+	for(i=5; i<=12;i++)
+	{
+		FillChar( S->Image[ i, 5 ], 8, 0 );
+	}
 }
 
 /* Moves a sprite */
-procedure sxMove( var S: TSprite );
-begin
-	Inc( S.X, S.DX );		 /* Get new position */
-	Inc( S.Y, S.DY );
-	/* Check sprite position, change delta if needed */
-	if( S.X > 320 ) then begin
-		S.X = 320;
-		S.DX = -S.DX;
-	}
-	if( S.X < -16 ) then begin
-		S.X = -16;
-		S.DX = -S.DX;
-	}
-	if( S.Y > 240 ) then begin
-		S.Y = 240;
-		S.DY = -S.DY;
-	}
-	if( S.Y < -16 ) then begin
-		S.Y = -16;
-		S.DY = -S.DY;
-	}
-	/* Draw the sprite, note the Page offset added to the */
-	/* Y coordinate of the image */
-	mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );
+void sxMove(TSprite *S)
+{
+//Inc( S.X, S.DX );		 /* Get new position */
+//Inc( S.Y, S.DY );
+/* Check sprite position, change delta if needed */
+if( S->X > 320 ){
+	S->X = 320;
+S->DX = -S->DX;
+}
+if( S->X < -16 ){
+	S->X = -16;
+S->DX = -S->DX;
+}
+if( S->Y > 240 ){
+	S.Y = 240;
+	S->DY = -S->DY;
+}
+if( S->Y < -16 ){
+	S->Y = -16;
+	S->DY = -S->DY;
+}
+/* Draw the sprite, note the Page offset added to the */
+/* Y coordinate of the image */
+mxPutImage( S.Image, S->X, Page+S->Y, S->W, S->H, OP_TRANS );
 }
 
 void main()
 {
 	int i;
+	//TSprite S;
 	/* Initialize library */
 	mxInit();
-
+	
 	/* Enter graphics mode */
 	mxSetMode( MX_320x240 );
-
+	
 	/* Print initialization message */
 	mxSetTextColor( 15, OP_TRANS );
 	mxOutStr( 4, 4, 'Initializing...' );
-
+	
 	/* Initialize sprites */
 	for(i=1;i<=MAX_SPRITE;i++)
-		sxInit( S[i] );
-
+		sxInit( &S[i] );
+	
 	/* Draw background */
 	for(i=1;i<=192;i++)
 	{
 		mxCircle( 160, 480+120, I, I+63 );
 		mxCircle( 161, 480+120, I, I+63 );
 	}
-
+	
 	/* Compute and set palette */
 	for(i=1;i<= 192;Palette[i+63])
-        {
+	{
 		short R = 0;
 		short G = 0;
 		short B = 0;
 		if( i < 64 )
-			R = i shr 1+31
+			R = i >> 1+31;
 		else if( i < 128 )
-			G = (i-64) shr 1+31
+			G = (i-64) >> 1+31;
 		else
-			B = (i-128) shr 1+31;
+			B = (i-128) >> 1+31;
 	}
 	mxSetPalette( @Palette[64], 64, 192 );
-
+	
 	/* Main loop */
 	short Page = 240;
 	while(!kbhit())
@@ -126,8 +133,8 @@ void main()
 		mxSetPalette( @Palette[64], 64, 192 );
 		mxRotatePalette( @Palette[64], 192, 3 );
 	}
-
+	
 	mxSetMode( MX_TEXT );
 	mxTerm;
-
+	
 }
diff --git a/16/xw_/modex/demo01.c b/16/xw_/modex/demo01.c
index 0908fdf4..98086b62 100755
--- a/16/xw_/modex/demo01.c
+++ b/16/xw_/modex/demo01.c
@@ -1,125 +1,133 @@
 /*
-    DEMO01 - Sprites, page flipping and palette rotation
-    Copyright (c) 1994 Alessandro Scotti
+		DEMO01 - Sprites, page flipping and palette rotation
+		Copyright (c) 1994 Alessandro Scotti
 */
-uses Crt, Modex;
+#include ../../x/
 
 #DEFINE MAX_SPRITE 100
-type
-  (* Sprite structure *)
-  TSprite = record
-    X, Y : integer;                        (* Sprite coordinates *)
-    DX,DY: integer;                        (* Deltas for sprite movement *)
-    W, H : integer;                        (* Sprite width and height *)
-    Image: array[ 1..16, 1..16 ] of byte;  (* Sprite image data *)
-  end;
-  (* RGB color structure *)
-  TRgb    = record
-    R, G, B: byte;
-  end;
+
+/* Sprite structure */
+typedef struct {
+		int X, Y;												/* Sprite coordinates */
+		int DX,DY;												/* Deltas for sprite movement */
+		int W, H;												/* Sprite width and height */
+		unsigned char Image[16,16];	/* Sprite image data */
+} TSprite;
+
+/* RGB color structure */
+typedef struct {
+		R, G, B: byte;
+} TRgb;
 var
-  S      : array[ 1..MAX_SPRITE ] of TSprite;   (* An array of sprites *)
-  Palette: array[ byte ] of TRgb;               (* Palette *)
-  Page   : word;                                (* Page offset *)
-  I      : word;
+	S			: array[ 1..MAX_SPRITE ] of TSprite;	 /* An array of sprites */
+	Palette: array[ byte ] of TRgb;							 /* Palette */
+	Page	 : word;																/* Page offset */
+	I			: word;
 
-(* Initializes a sprite structure *)
+/* Initializes a sprite structure */
 procedure sxInit( var S: TSprite );
 var
-  I: word;
+	I: word;
 begin
-  S.X := Random( 320 );  (* Initialize position with random values *)
-  S.Y := Random( 240 );
-  S.DX := Random( 7 )-3; (* Initialize speed with random values *)
-  S.DY := Random( 7 )-3;
-  S.W := 16;             (* Size is fixed in this program *)
-  S.H := 16;
-  (* The image is a square with a hole inside *)
-  FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );
-  for I:=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );
-end;
+	S.X = Random( 320 );	/* Initialize position with random values */
+	S.Y = Random( 240 );
+	S.DX = Random( 7 )-3; /* Initialize speed with random values */
+	S.DY = Random( 7 )-3;
+	S.W = 16;						 /* Size is fixed in this program */
+	S.H = 16;
+	/* The image is a square with a hole inside */
+	FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );
+	for I=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );
+}
 
-(* Moves a sprite *)
+/* Moves a sprite */
 procedure sxMove( var S: TSprite );
 begin
-  Inc( S.X, S.DX );     (* Get new position *)
-  Inc( S.Y, S.DY );
-  (* Check sprite position, change delta if needed *)
-  if( S.X > 320 ) then begin
-    S.X := 320;
-    S.DX := -S.DX;
-  end;
-  if( S.X < -16 ) then begin
-    S.X := -16;
-    S.DX := -S.DX;
-  end;
-  if( S.Y > 240 ) then begin
-    S.Y := 240;
-    S.DY := -S.DY;
-  end;
-  if( S.Y < -16 ) then begin
-    S.Y := -16;
-    S.DY := -S.DY;
-  end;
-  (* Draw the sprite, note the Page offset added to the *)
-  (* Y coordinate of the image *)
-  mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );
-end;
+	Inc( S.X, S.DX );		 /* Get new position */
+	Inc( S.Y, S.DY );
+	/* Check sprite position, change delta if needed */
+	if( S.X > 320 ) then begin
+		S.X = 320;
+		S.DX = -S.DX;
+	}
+	if( S.X < -16 ) then begin
+		S.X = -16;
+		S.DX = -S.DX;
+	}
+	if( S.Y > 240 ) then begin
+		S.Y = 240;
+		S.DY = -S.DY;
+	}
+	if( S.Y < -16 ) then begin
+		S.Y = -16;
+		S.DY = -S.DY;
+	}
+	/* Draw the sprite, note the Page offset added to the */
+	/* Y coordinate of the image */
+	mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );
+}
 
-begin
-  (* Initialize library *)
-  mxInit;
+void main()
+{
+	int i;
+	/* Initialize library */
+	mxInit();
+
+	/* Enter graphics mode */
+	mxSetMode( MX_320x240 );
 
-  (* Enter graphics mode *)
-  mxSetMode( MX_320x240 );
+	/* Print initialization message */
+	mxSetTextColor( 15, OP_TRANS );
+	mxOutStr( 4, 4, 'Initializing...' );
 
-  (* Print initialization message *)
-  mxSetTextColor( 15, OP_TRANS );
-  mxOutStr( 4, 4, 'Initializing...' );
+	/* Initialize sprites */
+	for(i=1;i<=MAX_SPRITE;i++)
+		sxInit( S[i] );
 
-  (* Initialize sprites *)
-  for I:=1 to MAX_SPRITE do sxInit( S[I] );
+	/* Draw background */
+	for(i=1;i<=192;i++)
+	{
+		mxCircle( 160, 480+120, I, I+63 );
+		mxCircle( 161, 480+120, I, I+63 );
+	}
 
-  (* Draw background *)
-  for I:=1 to 192 do begin
-    mxCircle( 160, 480+120, I, I+63 );
-    mxCircle( 161, 480+120, I, I+63 );
-  end;
+	/* Compute and set palette */
+	for(i=1;i<= 192;Palette[i+63])
+        {
+		short R = 0;
+		short G = 0;
+		short B = 0;
+		if( i < 64 )
+			R = i shr 1+31
+		else if( i < 128 )
+			G = (i-64) shr 1+31
+		else
+			B = (i-128) shr 1+31;
+	}
+	mxSetPalette( @Palette[64], 64, 192 );
 
-  (* Compute and set palette *)
-  for I:=1 to 192 do with Palette[I+63] do begin
-    R := 0;
-    G := 0;
-    B := 0;
-    if( I < 64 ) then
-      R := I shr 1+31
-    else if( I < 128 ) then
-      G := (I-64) shr 1+31
-    else
-      B := (I-128) shr 1+31;
-  end;
-  mxSetPalette( @Palette[64], 64, 192 );
+	/* Main loop */
+	short Page = 240;
+	while(!kbhit())
+	{
+		/* Set clip region to current page */
+		mxSetClipRegion( 0, Page, 320, 240 );
+		mxSetClip( TRUE );
+		/* Restore background */
+		mxBitBlt( 0, 480, 320, 240, 0, Page );
+		/* Draw sprites */
+		for(i=1; i <= MAX_SPRITE; sxMove( S[i] ));
+		/* Print message */
+		mxOutStr( 4, Page+4, 'Some sprites moving...' );
+		/* Flip page */
+		mxStartLine( Page );
+		Page = 240-Page;
+		/* Animate palette */
+		mxSetPalette( @Palette[64], 64, 192 );
+		mxRotatePalette( @Palette[64], 192, 3 );
+	}
 
-  (* Main loop *)
-  Page := 240;
-  while( not KeyPressed ) do begin
-    (* Set clip region to current page *)
-    mxSetClipRegion( 0, Page, 320, 240 );
-    mxSetClip( TRUE );
-    (* Restore background *)
-    mxBitBlt( 0, 480, 320, 240, 0, Page );
-    (* Draw sprites *)
-    for I:=1 to MAX_SPRITE do sxMove( S[I] );
-    (* Print message *)
-    mxOutStr( 4, Page+4, 'Some sprites moving...' );
-    (* Flip page *)
-    mxStartLine( Page );
-    Page := 240-Page;
-    (* Animate palette *)
-    mxSetPalette( @Palette[64], 64, 192 );
-    mxRotatePalette( @Palette[64], 192, 3 );
-  end;
+	mxSetMode( MX_TEXT );
+	mxTerm;
 
-  mxSetMode( MX_TEXT );
-  mxTerm;
-end.
+}
-- 
2.39.5