(enfin sauf le /2)
C'est la meme histoire avec
- Code: Select all
for (i=0; i320*240; i++)
{
buf-pixel[i] = 0xFF;
}
for (i=0; i320*240; i++)
{
buf-pixel[i] = 0xFF;
}
void bufSetData (buffer *buf, uint8_t data, int x, int y) //put a number in the buffer. buf is the buffer, data the number, x y the coords.
{
if (x/2 == 1)
buf[y*160+x/2] = buf[y*160+x/2]/16 + data;
else
buf[y*160+x/2] = buf[y*160+x/2]%16 + data*16;
}
/// ////////////////////// ///
/// BUFFER.H ///
/// a simple buffer system ///
/// by Chockosta ///
/// ////////////////////// ///
#ifndef _BUFFER_H_
#define _BUFFER_H_
typedef uint8_t buffer;
buffer* bufCreate (); //allocate a buffer
void bufDelete (buffer *buf); //free a buffer
void bufSetData (buffer *buf, uint8_t data, int x, int y); //put a number in the buffer (may not be used by a human being)
uint8_t bufGetData (buffer *buf, int x, int y); //returns a number which is in the buffer (may not be used by a human being)
void bufSetPixel (buffer *buf, int x, int y, int color); //set a pixel
int bufGetPixel (buffer *buf, int x, int y); //returns a pixel's color
void bufDisplay (buffer *buf); //displays the buffer
void bufClear (buffer *buf); //clears the buffer
void bufCopy (buffer *buf, buffer *buf2); //copy the buffer to another buffer
inline void screenSetPixel (int x, int y, int color); //set a pixel.
#endif
#include os.h
#include "buffer.h"
buffer* bufCreate () //allocate a buffer
{
uint8_t *ptr = malloc (38400 * sizeof(uint8_t));
return ptr;
}
void bufDelete (buffer *buf) //free a buffer
{
free (buf);
}
void bufSetData (buffer *buf, uint8_t data, int x, int y) //put a number in the buffer
{
if (x%2 == 1)
buf[y*160+x/2] = buf[y*160+x/2]/16*16 + data;
else
buf[y*160+x/2] = buf[y*160+x/2]%16 + data*16;
}
uint8_t bufGetData (buffer *buf, int x, int y)
{
if (x%2 == 1)
return buf[y*160+x/2]%16;
else
return buf[y*160+x/2]/16;
}
void bufSetPixel (buffer *buf, int x, int y, int color) //set a pixel
{
if (x=0 x320 y=0 y240 color=0 color16)
bufSetData (buf, color, x, y);
}
int bufGetPixel (buffer *buf, int x, int y) //returns a pixel's color
{
if (x=0 x320 y=0 y240)
return bufGetData (buf, x, y);
else
return 0;
}
void bufDisplay (buffer *buf) //displays the buffer
{
int i, j;
for (i=0; i320; i++)
{
for (j=0; j240; j++)
{
screenSetPixel (i, j, bufGetData(buf, i,j));
}
}
}
void bufClear (buffer *buf) //clears the buffer
{
memset (buf, 0xFF, 38400 * sizeof(uint8_t));
}
void bufCopy (buffer *buf, buffer *buf2) //copy the buffer to another buffer
{
int i;
for (i=0; i38400; i++)
{
buf2[i] = buf[i];
}
}
inline void screenSetPixel(int x, int y, int color)
{
unsigned char* p = (unsigned char*)(SCREEN_BASE_ADDRESS + ((x 1) + (y 7) + (y 5)));
*p = (x 1) ? ((*p 0xF0) | color) : ((*p 0x0F) | (color 4));
}
Return to Native: Ndless, Linux, ...
Users browsing this forum: ClaudeBot [spider] and 10 guests