Tried to lighten up some code, imported some Caphics code

This commit is contained in:
Thomas Touhey 2016-05-29 02:59:52 +02:00
parent 152a98bd6d
commit d8eb346f40
31 changed files with 265 additions and 776 deletions

View File

@ -29,14 +29,7 @@ SRC = ML_vram_address \
ML_circle ML_filled_circle ML_ellipse ML_ellipse_in_rect \
ML_filled_ellipse ML_filled_ellipse_in_rect \
ML_horizontal_scroll ML_vertical_scroll \
\
ML_bmp_or ML_bmp_and ML_bmp_xor \
ML_bmp_or_cl ML_bmp_and_cl ML_bmp_xor_cl \
ML_bmp_8_or ML_bmp_8_and ML_bmp_8_xor \
ML_bmp_8_or_cl ML_bmp_8_and_cl ML_bmp_8_xor_cl \
ML_bmp_16_or ML_bmp_16_and ML_bmp_16_xor \
ML_bmp_16_or_cl ML_bmp_16_and_cl ML_bmp_16_xor_cl \
\
ML_bmp \
ML_background
# INCLUDE FILES

View File

@ -14,6 +14,10 @@
extern "C" {
# endif
/*
** Constants
*/
# define ML_SCREEN_WIDTH 128
# define ML_SCREEN_HEIGHT 64
@ -21,6 +25,10 @@ extern "C" {
# define ML_CONTRAST_NORMAL 168
# define ML_CONTRAST_MAX 190
/*
** Custom types
*/
typedef enum {
ML_TRANSPARENT = -1,
ML_WHITE,
@ -57,7 +65,8 @@ void ML_line(int x1, int y1, int x2, int y2, ML_Color color);
void ML_horizontal_line(int y, int x1, int x2, ML_Color color);
void ML_vertical_line(int x, int y1, int y2, ML_Color color);
void ML_rectangle(int x1, int y1, int x2, int y2, int border_width, ML_Color border_color, ML_Color fill_color);
void ML_rectangle(int x1, int y1, int x2, int y2, int border_width,
ML_Color border_color, ML_Color fill_color);
void ML_polygon(const int *x, const int *y, int nb_vertices, ML_Color color);
void ML_filled_polygon(const int *x, const int *y, int nb_vertices, ML_Color color);
@ -73,30 +82,61 @@ void ML_filled_ellipse_in_rect(int x1, int y1, int x2, int y2, ML_Color color);
void ML_horizontal_scroll(int scroll);
void ML_vertical_scroll(int scroll);
void ML_bmp_or(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_and(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_xor(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_or_cl(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_and_cl(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_xor_cl(const unsigned char *bmp, int x, int y, int width, int height);
# define ML_bmp_or(B, X, Y, W, H) \
ML_bmp((B), (X), (Y), (W), (H), ML_MOR)
# define ML_bmp_and(B, X, Y, W, H) \
ML_bmp((B), (X), (Y), (W), (H), ML_MAND)
# define ML_bmp_xor(B, X, Y, W, H) \
ML_bmp((B), (X), (Y), (W), (H), ML_MXOR)
# define ML_bmp_or_cl(B, X, Y, W, H) \
ML_bmp((B), (X), (Y), (W), (H), ML_MOR)
# define ML_bmp_and_cl(B, X, Y, W, H) \
ML_bmp((B), (X), (Y), (W), (H), ML_MAND)
# define ML_bmp_xor_cl(B, X, Y, W, H) \
ML_bmp((B), (X), (Y), (W), (H), ML_MXOR)
void ML_bmp_8_or(const unsigned char *bmp, int x, int y);
void ML_bmp_8_and(const unsigned char *bmp, int x, int y);
void ML_bmp_8_xor(const unsigned char *bmp, int x, int y);
void ML_bmp_8_or_cl(const unsigned char *bmp, int x, int y);
void ML_bmp_8_and_cl(const unsigned char *bmp, int x, int y);
void ML_bmp_8_xor_cl(const unsigned char *bmp, int x, int y);
void ML_bmp(const void *bmp, int x, int y, int width, int height, ML_Mode mode);
void ML_bmp_16_or(const unsigned short *bmp, int x, int y);
void ML_bmp_16_and(const unsigned short *bmp, int x, int y);
void ML_bmp_16_xor(const unsigned short *bmp, int x, int y);
void ML_bmp_16_or_cl(const unsigned short *bmp, int x, int y);
void ML_bmp_16_and_cl(const unsigned short *bmp, int x, int y);
void ML_bmp_16_xor_cl(const unsigned short *bmp, int x, int y);
# define ML_bmp_8_or(B, X, Y) \
ML_bmp_8((B), (X), (Y), ML_MOR)
# define ML_bmp_8_and(B, X, Y) \
ML_bmp_8((B), (X), (Y), ML_MAND)
# define ML_bmp_8_xor(B, X, Y) \
ML_bmp_8((B), (X), (Y), ML_MXOR)
# define ML_bmp_8_or_cl(B, X, Y) \
ML_bmp_8((B), (X), (Y), ML_MOR)
# define ML_bmp_8_and_cl(B, X, Y) \
ML_bmp_8((B), (X), (Y), ML_MAND)
# define ML_bmp_8_xor_cl(B, X, Y) \
ML_bmp_8((B), (X), (Y), ML_MXOR)
#define ML_background_or(B) ML_background((B), ML_OR)
#define ML_background_and(B) ML_background((B), ML_AND)
#define ML_background_xor(B) ML_background((B), ML_XOR)
# define ML_bmp_8(B, X, Y, M) \
ML_bmp((B), (X), (Y), 8, 8, (M))
//void ML_bmp_8(const unsigned char *bmp, int x, int y, ML_Mode mode);
# define ML_bmp_16_or(B, X, Y) \
ML_bmp_16((B), (X), (Y), ML_MOR)
# define ML_bmp_16_and(B, X, Y) \
ML_bmp_16((B), (X), (Y), ML_MAND)
# define ML_bmp_16_xor(B, X, Y) \
ML_bmp_16((B), (X), (Y), ML_MXOR)
# define ML_bmp_16_or_cl(B, X, Y) \
ML_bmp_16((B), (X), (Y), ML_MOR)
# define ML_bmp_16_and_cl(B, X, Y) \
ML_bmp_16((B), (X), (Y), ML_MAND)
# define ML_bmp_16_xor_cl(B, X, Y) \
ML_bmp_16((B), (X), (Y), ML_MXOR)
# define ML_bmp_16(B, X, Y, M) \
ML_bmp((B), (X), (Y), 16, 16, (M))
//void ML_bmp_16(const unsigned char *bmp, int x, int y, ML_Mode mode);
# define ML_background_or(B) \
ML_background((B), ML_MOR)
# define ML_background_and(B) \
ML_background((B), ML_MAND)
# define ML_background_xor(B) \
ML_background((B), ML_MXOR)
void ML_background(const void *bmp, ML_Mode mode);
# ifdef __cplusplus

View File

@ -13,8 +13,9 @@
# include <stddef.h>
# include <monochrome.h>
# define sgn(x) (x < 0 ? -1 : 1)
# define rnd(x) ((int)x + 0.5)
# define abs(X) ((X) > 0 ? (X) : -(X))
# define sgn(X) ((X) < 0 ? -1 : 1)
# define rnd(X) ((int)(X) + 0.5)
/*
** STDLIB Prototypes
@ -23,4 +24,11 @@
void *malloc(size_t size);
void free(void *ptr);
/*
** VRAM Utilities
*/
# define ML_vram_xy(X, Y) \
(ML_vram_address() + ((Y) << 4) + ((X) >> 3))
#endif

View File

@ -18,7 +18,7 @@
void ML_background(const void *bmp, ML_Mode mode)
{
unsigned int *v = ML_vram_adress();
unsigned int *v = ML_vram_address();
const unsigned int *b = bmp;
int w = 0;

95
src/ML_bmp.c Normal file
View File

@ -0,0 +1,95 @@
/* ************************************************************************** */
/* _____ _ */
/* ML_bmp.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project : libmonochrome | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/05/29 01:55:54 |___/ */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
static void ML_bmp_line(unsigned char *vram, const unsigned char *b,
int width, int offset, ML_Mode mode);
static inline void ML_bmp_byte(unsigned char *v, int b, int offset, int width,
ML_Mode mode);
void ML_bmp(const void *bmp, int x, int y, int width, int height, ML_Mode mode)
{
/* FIXME: no support for non-clipping blit. */
/* Oh, and yeah : most of this code is adapted from Caphics.
Clipping is, of course, on by default, and this function is not
optimized for when its disabled. */
if (x < width + 1 || x >= 128 || y < height + 1 || y >= 64)
return ;
// check clipping for retrocompatibility ?
int ls = (width >> 3) + ((width & 7) != 0); // line size
const unsigned char *b = (const unsigned char*)bmp;
// pass first lines
if (y < 0) {
b += -y * ls;
height += y;
y = 0;
}
if (height > 64 - y)
height = 64 - y;
// pass first pixels if x < 0
int offset = 0;
if (x < 0) {
b += -x >> 3;
width += x & 8;
x = 0;
}
if (width > 128 - x)
width = 128 - x;
// go to first interesting byte of vram
char *vram = ML_vram_xy(x, y);
// then draw
while (height--) {
ML_bmp_line((unsigned char*)vram, b, width, offset, mode);
vram += 8, bmp += ls;
}
}
static void ML_bmp_line(unsigned char *vram, const unsigned char *b,
int width, int offset, ML_Mode mode)
{
while (1) {
ML_bmp_byte(vram, *b, offset, width, mode);
if (width < 8)
break ;
vram++, b++;
width -= 8;
}
}
static inline void ML_bmp_byte(unsigned char *v, int b, int offset, int width,
ML_Mode mode)
{
if (width < 8) b &= 255 << (8 - width);
switch (mode) {
case ML_MAND:
*v &= ~(b >> offset);
if (width > 8 - offset)
*(++v) &= ~(b << (8 - offset));
break;
case ML_MOR:
*v |= b >> offset;
if (width > 8 - offset)
*(++v) |= b << (8 - offset);
break;
case ML_MXOR:
*v ^= b >> offset;
if (width > 8 - offset)
*(++v) ^= b << (8 - offset);
break;
}
}

View File

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_16_and.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_16_and(const unsigned short *bmp, int x, int y)
{
unsigned long line;
char i, shift, begin=0, end=16, *screen, *p=(char*)&line+1;
if(!bmp || x<0 || x>112 || y<-15 || y>63) return;
if(y < 0) begin = -y;
if(y > 48) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = ~((unsigned short)~bmp[i]<<shift);
screen[0] &= *p;
screen[1] &= *(p+1);
if(shift!=8) screen[2] &= *(p+2);
screen += 16;
}
}

View File

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_16_and_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_16_and_cl(const unsigned short *bmp, int x, int y)
{
unsigned long line;
char i, shift, begin=0, end=16, bool1=1, bool2=1, bool3=1, *screen, *p=(char*)&line+1;
if(!bmp || x<-15 || x>127 || y<-15 || y>63) return;
if(y < 0) begin = -y;
if(y > 48) end = 64-y;
shift = 8-(x&7);
if(x < 0) bool1 = 0;
if(x<-8 || x>119) bool2 = 0;
if(x>111 || shift==8) bool3 = 0;
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = ~((unsigned short)~bmp[i]<<shift);
if(bool1) screen[0] &= *p;
if(bool2) screen[1] &= *(p+1);
if(bool3) screen[2] &= *(p+2);
screen += 16;
}
}

View File

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_16_or.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_16_or(const unsigned short *bmp, int x, int y)
{
unsigned long line;
char i, shift, begin=0, end=16, *screen, *p=(char*)&line+1;
if(!bmp || x<0 || x>112 || y<-15 || y>63) return;
if(y < 0) begin = -y;
if(y > 48) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
screen[0] |= *p;
screen[1] |= *(p+1);
if(shift!=8) screen[2] |= *(p+2);
screen += 16;
}
}

View File

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_16_or_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_16_or_cl(const unsigned short *bmp, int x, int y)
{
unsigned long line;
char i, shift, begin=0, end=16, bool1=1, bool2=1, bool3=1, *screen, *p=(char*)&line+1;
if(!bmp || x<-15 || x>127 || y<-15 || y>63) return;
if(y < 0) begin = -y;
if(y > 48) end = 64-y;
shift = 8-(x&7);
if(x < 0) bool1 = 0;
if(x<-8 || x>119) bool2 = 0;
if(x>111 || shift==8) bool3 = 0;
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
if(bool1) screen[0] |= *p;
if(bool2) screen[1] |= *(p+1);
if(bool3) screen[2] |= *(p+2);
screen += 16;
}
}

View File

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_16_xor.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_16_xor(const unsigned short *bmp, int x, int y)
{
unsigned long line;
char i, shift, begin=0, end=16, *screen, *p=(char*)&line+1;
if(!bmp || x<0 || x>112 || y<-15 || y>63) return;
if(y < 0) begin = -y;
if(y > 48) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
screen[0] ^= *p;
screen[1] ^= *(p+1);
if(shift!=8) screen[2] ^= *(p+2);
screen += 16;
}
}

View File

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_16_xor_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_16_xor_cl(const unsigned short *bmp, int x, int y)
{
unsigned long line;
char i, shift, begin=0, end=16, bool1=1, bool2=1, bool3=1, *screen, *p=(char*)&line+1;
if(!bmp || x<-15 || x>127 || y<-15 || y>63) return;
if(y < 0) begin = -y;
if(y > 48) end = 64-y;
shift = 8-(x&7);
if(x < 0) bool1 = 0;
if(x<-8 || x>119) bool2 = 0;
if(x>111 || shift==8) bool3 = 0;
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
if(bool1) screen[0] ^= *p;
if(bool2) screen[1] ^= *(p+1);
if(bool3) screen[2] ^= *(p+2);
screen += 16;
}
}

View File

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_8_and.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_8_and(const unsigned char *bmp, int x, int y)
{
unsigned short line;
char i, shift, begin=0, end=8, *screen, *p=(char*)&line;
if(!bmp || x<0 || x>120 || y<-7 || y>63) return;
if(y < 0) begin = -y;
if(y > 56) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = ~((unsigned char)~bmp[i]<<shift);
screen[0] &= *p;
if(shift!=8) screen[1] &= *(p+1);
screen += 16;
}
}

View File

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_8_and_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_8_and_cl(const unsigned char *bmp, int x, int y)
{
unsigned short line;
char i, shift, begin=0, end=8, bool1=1, bool2=1, *screen, *p=(char*)&line;
if(!bmp || x<-7 || x>127 || y<-7 || y>63) return;
if(y < 0) begin = -y;
if(y > 56) end = 64-y;
shift = 8-(x&7);
if(x < 0) bool1 = 0;
if(x>120 || shift==8) bool2 = 0;
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = ~((unsigned char)~bmp[i]<<shift);
if(bool1) screen[0] &= *p;
if(bool2) screen[1] &= *(p+1);
screen += 16;
}
}

View File

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_8_or.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_8_or(const unsigned char *bmp, int x, int y)
{
unsigned short line;
char i, shift, begin=0, end=8, *screen, *p=(char*)&line;
if(!bmp || x<0 || x>120 || y<-7 || y>63) return;
if(y < 0) begin = -y;
if(y > 56) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
screen[0] |= *p;
if(shift!=8) screen[1] |= *(p+1);
screen += 16;
}
}

View File

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_8_or_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_8_or_cl(const unsigned char *bmp, int x, int y)
{
unsigned short line;
char i, shift, begin=0, end=8, bool1=1, bool2=1, *screen, *p=(char*)&line;
if(!bmp || x<-7 || x>127 || y<-7 || y>63) return;
if(y < 0) begin = -y;
if(y > 56) end = 64-y;
shift = 8-(x&7);
if(x < 0) bool1 = 0;
if(x>120 || shift==8) bool2 = 0;
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
if(bool1) screen[0] |= *p;
if(bool2) screen[1] |= *(p+1);
screen += 16;
}
}

View File

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_8_xor.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_8_xor(const unsigned char *bmp, int x, int y)
{
unsigned short line;
char i, shift, begin=0, end=8, *screen, *p=(char*)&line;
if(!bmp || x<0 || x>120 || y<-7 || y>63) return;
if(y < 0) begin = -y;
if(y > 56) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
screen[0] ^= *p;
if(shift<8) screen[1] ^= *(p+1);
screen += 16;
}
}

View File

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_8_xor_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_8_xor_cl(const unsigned char *bmp, int x, int y)
{
unsigned short line;
char i, shift, begin=0, end=8, bool1=1, bool2=1, *screen, *p=(char*)&line;
if(!bmp || x<-7 || x>127 || y<-7 || y>63) return;
if(y < 0) begin = -y;
if(y > 56) end = 64-y;
shift = 8-(x&7);
if(x < 0) bool1 = 0;
if(x>120 || shift==8) bool2 = 0;
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
line = bmp[i]<<shift;
if(bool1) screen[0] ^= *p;
if(bool2) screen[1] ^= *(p+1);
screen += 16;
}
}

View File

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_and.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_and(const unsigned char *bmp, int x, int y, int width, int height)
{
unsigned short line;
char shift, *screen, *p=(char*)&line;
int i, j, begin=0, end=height, real_width=(width-1>>3<<3)+8;
if(!bmp || x<0 || x>128-width || y<1-height || y>63 || width<1 || height<1) return;
if(y < 0) begin = -y;
if(y+height > 64) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
for(j=0 ; j<width-1>>3 ; j++)
{
line = ~((unsigned char)~bmp[i*(real_width>>3)+j]<<shift);
screen[j] &= *p;
if(shift!=8) screen[j+1] &= *(p+1);
}
line = ~((unsigned char)~(bmp[i*(real_width>>3)+j] | (unsigned char)-1>>8-(width&7))<<shift);
screen[j] &= *p;
if(shift!=8 && x+real_width<129) screen[j+1] &= *(p+1);
screen += 16;
}
}

View File

@ -1,59 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_and_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_and_cl(const unsigned char *bmp, int x, int y, int width, int height)
{
unsigned short line;
char shift, *screen, *p;
int i, j, real_width, begin_x, end_x, begin_y, end_y;
char bool1=1, bool2=1, bool3;
if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return;
p = (char*)&line;
real_width = (width-1>>3<<3)+8;
if(y < 0) begin_y = -y;
else begin_y = 0;
if(y+height > 64) end_y = 64-y;
else end_y = height;
shift = 8-(x&7);
if(x<0)
{
begin_x = -x>>3;
if(shift != 8) bool1 = 0;
} else begin_x = 0;
if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0;
else end_x = real_width-1>>3;
bool3 = (end_x == real_width-1>>3);
screen = ML_vram_adress()+(y+begin_y<<4)+(x>>3);
for(i=begin_y ; i<end_y ; i++)
{
if(begin_x < end_x)
{
line = ~((unsigned char)~bmp[i*(real_width>>3)+begin_x]<<shift);
if(bool1) screen[begin_x] &= *p;
if(shift!=8) screen[begin_x+1] &= *(p+1);
for(j=begin_x+1 ; j<end_x ; j++)
{
line = ~((unsigned char)~bmp[i*(real_width>>3)+j]<<shift);
screen[j] &= *p;
if(shift!=8) screen[j+1] &= *(p+1);
}
}
line = (unsigned char)~bmp[i*(real_width>>3)+end_x];
if(bool3) line &= -1<<real_width-width;
line = ~(line << shift);
if(begin_x < end_x || bool1) screen[end_x] &= *p;
if(bool2) screen[end_x+1] &= *(p+1);
screen += 16;
}
}

View File

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_or.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_or(const unsigned char *bmp, int x, int y, int width, int height)
{
unsigned short line;
char shift, *screen, *p=(char*)&line;
int i, j, begin=0, end=height, real_width=(width-1>>3<<3)+8;
if(!bmp || x<0 || x>128-width || y<1-height || y>63 || width<1 || height<1) return;
if(y < 0) begin = -y;
if(y+height > 64) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
for(j=0 ; j<width-1>>3 ; j++)
{
line = bmp[i*(real_width>>3)+j]<<shift;
screen[j] |= *p;
if(shift!=8) screen[j+1] |= *(p+1);
}
line = (bmp[i*(real_width>>3)+j] & -1<<(real_width-width))<<shift;
screen[j] |= *p;
if(shift!=8 && x+real_width<129) screen[j+1] |= *(p+1);
screen += 16;
}
}

View File

@ -1,58 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_or_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_or_cl(const unsigned char *bmp, int x, int y, int width, int height)
{
unsigned short line;
char shift, *screen, *p;
int i, j, real_width, begin_x, end_x, begin_y, end_y;
char bool1=1, bool2=1, bool3;
if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return;
p = (char*)&line;
real_width = (width-1>>3<<3)+8;
if(y < 0) begin_y = -y;
else begin_y = 0;
if(y+height > 64) end_y = 64-y;
else end_y = height;
shift = 8-(x&7);
if(x<0)
{
begin_x = -x>>3;
if(shift != 8) bool1 = 0;
} else begin_x = 0;
if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0;
else end_x = real_width-1>>3;
bool3 = (end_x == real_width-1>>3);
screen = ML_vram_adress()+(y+begin_y<<4)+(x>>3);
for(i=begin_y ; i<end_y ; i++)
{
if(begin_x < end_x)
{
line = bmp[i*(real_width>>3)+begin_x] << shift;
if(bool1) screen[begin_x] |= *p;
if(shift!=8) screen[begin_x+1] |= *(p+1);
for(j=begin_x+1 ; j<end_x ; j++)
{
line = bmp[i*(real_width>>3)+j] << shift;
screen[j] |= *p;
if(shift!=8) screen[j+1] |= *(p+1);
}
}
line = bmp[i*(real_width>>3)+end_x];
if(bool3) line &= -1<<real_width-width;
line <<= shift;
if(begin_x < end_x || bool1) screen[end_x] |= *p;
if(bool2) screen[end_x+1] |= *(p+1);
screen += 16;
}
}

View File

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_xor.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_xor(const unsigned char *bmp, int x, int y, int width, int height)
{
unsigned short line;
char shift, *screen, *p=(char*)&line;
int i, j, begin=0, end=height, real_width=(width-1>>3<<3)+8;
if(!bmp || x<0 || x>128-width || y<1-height || y>63 || width<1 || height<1) return;
if(y < 0) begin = -y;
if(y+height > 64) end = 64-y;
shift = 8-(x&7);
screen = ML_vram_adress()+(y+begin<<4)+(x>>3);
for(i=begin ; i<end ; i++)
{
for(j=0 ; j<width-1>>3 ; j++)
{
line = bmp[i*(real_width>>3)+j]<<shift;
screen[j] ^= *p;
if(shift!=8) screen[j+1] ^= *(p+1);
}
line = (bmp[i*(real_width>>3)+j] & -1<<(real_width-width))<<shift;
screen[j] ^= *p;
if(shift!=8 && x+real_width<129) screen[j+1] ^= *(p+1);
screen += 16;
}
}

View File

@ -1,58 +0,0 @@
/* ************************************************************************** */
/* */
/* ML_bmp_xor_cl.c */
/* | Project : libmonochrome */
/* */
/* By: Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> */
/* Last updated: 2011/11/22 */
/* */
/* ************************************************************************** */
#include <monochrome/internals.h>
void ML_bmp_xor_cl(const unsigned char *bmp, int x, int y, int width, int height)
{
unsigned short line;
char shift, *screen, *p;
int i, j, real_width, begin_x, end_x, begin_y, end_y;
char bool1=1, bool2=1, bool3;
if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return;
p = (char*)&line;
real_width = (width-1>>3<<3)+8;
if(y < 0) begin_y = -y;
else begin_y = 0;
if(y+height > 64) end_y = 64-y;
else end_y = height;
shift = 8-(x&7);
if(x<0)
{
begin_x = -x>>3;
if(shift != 8) bool1 = 0;
} else begin_x = 0;
if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0;
else end_x = real_width-1>>3;
bool3 = (end_x == real_width-1>>3);
screen = ML_vram_adress()+(y+begin_y<<4)+(x>>3);
for(i=begin_y ; i<end_y ; i++)
{
if(begin_x < end_x)
{
line = bmp[i*(real_width>>3)+begin_x] << shift;
if(bool1) screen[begin_x] ^= *p;
if(shift!=8) screen[begin_x+1] ^= *(p+1);
for(j=begin_x+1 ; j<end_x ; j++)
{
line = bmp[i*(real_width>>3)+j] << shift;
screen[j] ^= *p;
if(shift!=8) screen[j+1] ^= *(p+1);
}
}
line = bmp[i*(real_width>>3)+end_x];
if(bool3) line &= -1<<real_width-width;
line <<= shift;
if(begin_x < end_x || bool1) screen[end_x] ^= *p;
if(bool2) screen[end_x+1] ^= *(p+1);
screen += 16;
}
}

View File

@ -12,15 +12,7 @@
void ML_clear_vram()
{
int i, end, *pointer_long, vram;
char *pointer_byte;
vram = (int)ML_vram_adress();
end = 4-vram&3;
pointer_byte = (char*)vram;
for(i=0 ; i<end ; i++) pointer_byte[i] = 0;
pointer_long = (int*) (vram+end);
for(i=0 ; i<255 ; i++) pointer_long[i] = 0;
pointer_byte += 1020+end;
end = vram&3;
for(i=0 ; i<end ; i++) pointer_byte[i] = 0;
int *vram = ML_vram_address();
for (int i = 0; i < 256; i++)
*vram = 0;
}

View File

@ -12,16 +12,17 @@
void ML_display_vram()
{
char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000, *vram;
int i, j;
vram = ML_vram_adress();
for(i=0 ; i<64 ; i++)
{
volatile char *LCD_register_selector = (volatile char*)0xB4000000;
volatile char *LCD_data_register = (volatile char*)0xB4010000;
char *vram = ML_vram_address();
for (int i = 0; i < 64; i++) {
*LCD_register_selector = 4;
*LCD_data_register = i|192;
*LCD_data_register = i | 192;
*LCD_register_selector = 4;
*LCD_data_register = 0;
*LCD_register_selector = 7;
for(j=0 ; j<16 ; j++) *LCD_data_register = *vram++;
for (int j = 0; j < 16; j++)
*LCD_data_register = *vram++;
}
}

View File

@ -12,66 +12,70 @@
void ML_horizontal_line(int y, int x1, int x2, ML_Color color)
{
int i;
if (y & ~63 || (x1 < 0 && x2 < 0) || (x1 > 127 && x2 > 127))
return;
int i;
char checker;
char* vram = ML_vram_adress();
if(y&~63 || (x1<0 && x2<0) || (x1>127 && x2>127)) return;
if(x1 > x2)
{
i = x1;
x1 = x2;
x2 = i;
}
if(x1 < 0) x1 = 0;
if(x2 > 127) x2 = 127;
switch(color)
{
case ML_BLACK:
if(x1>>3 != x2>>3)
{
vram[(y<<4)+(x1>>3)] |= 255 >> (x1&7);
vram[(y<<4)+(x2>>3)] |= 255 << 7-(x2&7);
for(i=(x1>>3)+1 ; i<x2>>3 ; i++)
vram[(y<<4) + i] = 255;
}
else vram[(y<<4)+(x1>>3)] |= (255>>(x1%8 + 7-x2%8))<<(7-(x2&7));
char* vram = ML_vram_address();
if (x1 > x2) {
i = x1;
x1 = x2;
x2 = i;
}
if (x1 < 0)
x1 = 0;
if (x2 > 127)
x2 = 127;
switch (color) {
case ML_BLACK:
if (x1 >> 3 != x2 >> 3) {
vram[(y << 4) + (x1 >> 3)] |= 255 >> (x1 & 7);
vram[(y << 4) + (x2 >> 3)] |= 255 << (7 - (x2 & 7));
for (i = (x1 >> 3) + 1 ; i < x2 >> 3; i++)
vram[(y << 4) + i] = 255;
} else
vram[(y << 4) + (x1 >> 3)] |= (255 >> (x1 % 8 + 7 - x2 % 8))
<< (7 - (x2 & 7));
break;
case ML_WHITE:
if(x1>>3 != x2>>3)
{
vram[(y<<4)+(x1>>3)] &= 255 << 8-(x1&7);
vram[(y<<4)+(x2>>3)] &= 255 >> 1+(x2&7);
for(i=(x1>>3)+1 ; i<x2>>3 ; i++)
vram[(y<<4) + i] = 0;
}
else vram[(y<<4)+(x1>>3)] &= (255<<8-(x1&7)) | (255>>1+(x2&7));
if (x1 >> 3 != x2 >> 3) {
vram[(y << 4) + (x1 >> 3)] &= 255 << (8 - (x1 & 7));
vram[(y << 4) + (x2 >> 3)] &= 255 >> (1 + (x2 & 7));
for (i = (x1 >> 3) + 1; i < x2 >> 3; i++)
vram[(y << 4) + i] = 0;
} else
vram[(y << 4) + (x1 >> 3)] &= (255 << (8 - (x1 & 7)))
| (255 >> (1 + (x2 & 7)));
break;
case ML_XOR:
if(x1>>3 != x2>>3)
{
vram[(y<<4)+(x1>>3)] ^= 255 >> (x1&7);
vram[(y<<4)+(x2>>3)] ^= 255 << 7-(x2&7);
for(i=(x1>>3)+1 ; i<(x2>>3) ; i++)
vram[(y<<4) + i] ^= 255;
}
else vram[(y<<4)+(x1>>3)] ^= (255>>((x1&7) + 7-(x2&7)))<<(7-(x2&7));
if (x1 >> 3 != x2 >> 3) {
vram[(y << 4) + (x1 >> 3)] ^= 255 >> (x1 & 7);
vram[(y << 4) + (x2 >> 3)] ^= 255 << (7 - (x2 & 7));
for (i = (x1 >> 3) + 1; i < (x2 >> 3); i++)
vram[(y << 4) + i] ^= 255;
} else
vram[(y << 4) + (x1 >> 3)] ^= (255 >> ((x1 & 7) + 7 - (x2 & 7)))
<< (7 - (x2 & 7));
break;
case ML_CHECKER:
checker = (y&1 ? 85 : 170);
if(x1>>3 != x2>>3)
{
vram[(y<<4)+(x1>>3)] &= 255 << 8-(x1&7);
vram[(y<<4)+(x2>>3)] &= 255 >> 1+(x2&7);
vram[(y<<4)+(x1>>3)] |= checker & 255>>(x1&7);
vram[(y<<4)+(x2>>3)] |= checker & 255<<7-(x2&7);
for(i=(x1>>3)+1 ; i<x2>>3 ; i++)
vram[(y<<4) + i] = checker;
}
else
{
vram[(y<<4)+(x1>>3)] &= (255<<8-(x1&7)) | (255>>1+(x2&7));
vram[(y<<4)+(x1>>3)] |= checker & (255>>(x1%8 + 7-x2%8))<<(7-(x2&7));
checker = (y & 1 ? 85 : 170);
if (x1 >> 3 != x2 >> 3) {
vram[(y << 4) + (x1 >> 3)] &= 255 << (8 - (x1 & 7));
vram[(y << 4) + (x2 >> 3)] &= 255 >> (1 + (x2 & 7));
vram[(y << 4) + (x1 >> 3)] |= checker & 255 >> (x1 & 7);
vram[(y << 4) + (x2 >> 3)] |= checker & 255 << (7 - (x2 & 7));
for (i = (x1 >> 3) + 1; i < x2 >> 3; i++)
vram[(y << 4) + i] = checker;
} else {
vram[(y << 4) + (x1 >> 3)] &= (255 << (8 - (x1 & 7)))
| (255 >> (1 + (x2 & 7)));
vram[(y << 4) + (x1 >> 3)] |= checker
& (255 >> (x1 % 8 + 7 - x2 % 8)) << (7 - (x2 & 7));
}
break;
}
default:
break;
}
}

View File

@ -16,7 +16,7 @@ void ML_horizontal_scroll(int scroll)
char line[16], shift, *vram;
unsigned char next;
unsigned short word;
vram = ML_vram_adress();
vram = ML_vram_address();
scroll %= 128;
shift = 8-(scroll&7);
for(i=0 ; i<64 ; i++)

View File

@ -12,22 +12,29 @@
void ML_pixel(int x, int y, ML_Color color)
{
char* vram = ML_vram_adress();
if(x&~127 || y&~63) return;
switch(color)
if (x & ~127 || y & ~63)
return;
char *vram = ML_vram_xy(x, y);
int bit = 128 >> (x & 7);
switch (color)
{
case ML_BLACK:
vram[(y<<4)+(x>>3)] |= 128>>(x&7);
*vram |= bit;
break;
case ML_WHITE:
vram[(y<<4)+(x>>3)] &= ~(128>>(x&7));
*vram &= ~bit;
break;
case ML_XOR:
vram[(y<<4)+(x>>3)] ^= 128>>(x&7);
*vram ^= bit;
break;
case ML_CHECKER:
if(y&1^x&1) vram[(y<<4)+(x>>3)] &= ~(128>>(x&7));
else vram[(y<<4)+(x>>3)] |= 128>>(x&7);
if ((y & 1) ^ (x & 1))
*vram &= ~bit;
else
*vram |= bit;
break;
default:
break;
}
}

View File

@ -12,10 +12,10 @@
ML_Color ML_pixel_test(int x, int y)
{
char *vram, byte;
if(x&~127 || y&~63) return ML_TRANSPARENT;
vram = ML_vram_adress();
byte = 1<<(7-(x&7));
return (vram[(y<<4)+(x>>3)] & byte ? ML_BLACK : ML_WHITE);
if (x & ~127 || y & ~63)
return ML_TRANSPARENT;
char *vram = ML_vram_xy(x, y);
int byte = 128 >> (x & 7);
return (*vram & byte ? ML_BLACK : ML_WHITE);
}

View File

@ -13,7 +13,7 @@
void ML_vertical_line(int x, int y1, int y2, ML_Color color)
{
int i, j;
char checker, byte, *vram = ML_vram_adress();
char checker, byte, *vram = ML_vram_address();
if(x&~127 || (y1<0 && y2<0) || (y1>63 && y2>63)) return;
if(y1 > y2)
{
@ -26,7 +26,7 @@ void ML_vertical_line(int x, int y1, int y2, ML_Color color)
i = (y1<<4)+(x>>3);
j = (y2<<4)+(x>>3);
switch(color)
switch (color)
{
case ML_BLACK:
byte = 128>>(x&7);
@ -45,7 +45,7 @@ void ML_vertical_line(int x, int y1, int y2, ML_Color color)
break;
case ML_CHECKER:
byte = 128>>(x&7);
checker = y1&1^x&1;
checker = (y1 & 1) ^ (x & 1);
for( ; i<=j ; i+=16)
{
if(checker) vram[i] &= ~byte;
@ -53,5 +53,7 @@ void ML_vertical_line(int x, int y1, int y2, ML_Color color)
checker = !checker;
}
break;
default:
break;
}
}

View File

@ -13,7 +13,7 @@
void ML_vertical_scroll(int scroll)
{
int i, j;
char column[64], *vram = ML_vram_adress();
char column[64], *vram = ML_vram_address();
scroll %= 64;
for(i=0 ; i<16 ; i++)
{