C to C# Conversion

  • Thread starter Thread starter aaron.radich
  • Start date Start date
A

aaron.radich

Can someone help me convert the following C declarations to C#:

#define GP_RGB24(r,g,b) (((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|
((((b>>3))&0x1f)<<1))
#define CDG_Pixel(x,y) CDG_screenBuffer[(240 * (x)) + (240 - (y))]

The CDG_screenBuffer was defined as:

extern unsigned char CDG_screenBuffer[76800];

I've converted that to:

char[] CDG_screenBuffer = new char[76800];

Aaron
 
Can someone help me convert the following C declarations to C#:

#define GP_RGB24(r,g,b) (((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|
((((b>>3))&0x1f)<<1))
#define CDG_Pixel(x,y) CDG_screenBuffer[(240 * (x)) + (240 - (y))]

The CDG_screenBuffer was defined as:

extern unsigned char CDG_screenBuffer[76800];

I've converted that to:

char[] CDG_screenBuffer = new char[76800];

C char -> C# byte

And it should be possible to convert the two macros to
methods with the code almost as is.

Arne
 
Arne said:
Can someone help me convert the following C declarations to C#:

#define GP_RGB24(r,g,b) (((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|
((((b>>3))&0x1f)<<1))
#define CDG_Pixel(x,y) CDG_screenBuffer[(240 * (x)) + (240 - (y))]

The CDG_screenBuffer was defined as:

extern unsigned char CDG_screenBuffer[76800];

I've converted that to:

char[] CDG_screenBuffer = new char[76800];

C char -> C# byte

And it should be possible to convert the two macros to
methods with the code almost as is.

Or it would be, if C# allowed returning references. But it doesn't, so for
example

CDG_Pixel(1,2) = 0x00FF00FF;

won't work after the conversion.

An indexer could be used but the syntax would still need to change at every
use (from parentheses to brackets).
 
Ben said:
Arne said:
Can someone help me convert the following C declarations to C#:

#define GP_RGB24(r,g,b) (((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|
((((b>>3))&0x1f)<<1))
#define CDG_Pixel(x,y) CDG_screenBuffer[(240 * (x)) + (240 - (y))]

The CDG_screenBuffer was defined as:

extern unsigned char CDG_screenBuffer[76800];

I've converted that to:

char[] CDG_screenBuffer = new char[76800];
C char -> C# byte

And it should be possible to convert the two macros to
methods with the code almost as is.

Or it would be, if C# allowed returning references. But it doesn't, so for
example

CDG_Pixel(1,2) = 0x00FF00FF;

won't work after the conversion.

An indexer could be used but the syntax would still need to change at every
use (from parentheses to brackets).

Oops.

Yes - for LHS a little bit morr work is needed.

Arne
 
Back
Top