From d8eb346f40f621710fda5b4066f29e21cc8d8130 Mon Sep 17 00:00:00 2001 From: Thomas Touhey Date: Sun, 29 May 2016 02:59:52 +0200 Subject: [PATCH] Tried to lighten up some code, imported some Caphics code --- Makefile.vars | 9 +-- include/monochrome.h | 84 ++++++++++++++++++------- include/monochrome/internals.h | 12 +++- src/ML_background.c | 2 +- src/ML_bmp.c | 95 ++++++++++++++++++++++++++++ src/ML_bmp_16_and.c | 30 --------- src/ML_bmp_16_and_cl.c | 33 ---------- src/ML_bmp_16_or.c | 30 --------- src/ML_bmp_16_or_cl.c | 33 ---------- src/ML_bmp_16_xor.c | 30 --------- src/ML_bmp_16_xor_cl.c | 33 ---------- src/ML_bmp_8_and.c | 29 --------- src/ML_bmp_8_and_cl.c | 31 ---------- src/ML_bmp_8_or.c | 30 --------- src/ML_bmp_8_or_cl.c | 31 ---------- src/ML_bmp_8_xor.c | 29 --------- src/ML_bmp_8_xor_cl.c | 31 ---------- src/ML_bmp_and.c | 36 ----------- src/ML_bmp_and_cl.c | 59 ------------------ src/ML_bmp_or.c | 36 ----------- src/ML_bmp_or_cl.c | 58 ----------------- src/ML_bmp_xor.c | 36 ----------- src/ML_bmp_xor_cl.c | 58 ----------------- src/ML_clear_vram.c | 14 +---- src/ML_display_vram.c | 15 ++--- src/ML_horizontal_line.c | 110 +++++++++++++++++---------------- src/ML_horizontal_scroll.c | 2 +- src/ML_pixel.c | 23 ++++--- src/ML_pixel_test.c | 12 ++-- src/ML_vertical_line.c | 8 ++- src/ML_vertical_scroll.c | 2 +- 31 files changed, 265 insertions(+), 776 deletions(-) create mode 100644 src/ML_bmp.c delete mode 100644 src/ML_bmp_16_and.c delete mode 100644 src/ML_bmp_16_and_cl.c delete mode 100644 src/ML_bmp_16_or.c delete mode 100644 src/ML_bmp_16_or_cl.c delete mode 100644 src/ML_bmp_16_xor.c delete mode 100644 src/ML_bmp_16_xor_cl.c delete mode 100644 src/ML_bmp_8_and.c delete mode 100644 src/ML_bmp_8_and_cl.c delete mode 100644 src/ML_bmp_8_or.c delete mode 100644 src/ML_bmp_8_or_cl.c delete mode 100644 src/ML_bmp_8_xor.c delete mode 100644 src/ML_bmp_8_xor_cl.c delete mode 100644 src/ML_bmp_and.c delete mode 100644 src/ML_bmp_and_cl.c delete mode 100644 src/ML_bmp_or.c delete mode 100644 src/ML_bmp_or_cl.c delete mode 100644 src/ML_bmp_xor.c delete mode 100644 src/ML_bmp_xor_cl.c diff --git a/Makefile.vars b/Makefile.vars index 6b2033e..6d501af 100644 --- a/Makefile.vars +++ b/Makefile.vars @@ -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 diff --git a/include/monochrome.h b/include/monochrome.h index a1df810..936e56d 100644 --- a/include/monochrome.h +++ b/include/monochrome.h @@ -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 diff --git a/include/monochrome/internals.h b/include/monochrome/internals.h index 38da805..aaa4c33 100644 --- a/include/monochrome/internals.h +++ b/include/monochrome/internals.h @@ -13,8 +13,9 @@ # include # include -# 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 diff --git a/src/ML_background.c b/src/ML_background.c index a6f0beb..d449cf3 100644 --- a/src/ML_background.c +++ b/src/ML_background.c @@ -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; diff --git a/src/ML_bmp.c b/src/ML_bmp.c new file mode 100644 index 0000000..8a2bca6 --- /dev/null +++ b/src/ML_bmp.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* _____ _ */ +/* ML_bmp.c |_ _|__ _ _| |__ ___ _ _ */ +/* | Project : libmonochrome | |/ _ \| | | | '_ \ / _ \ | | | */ +/* | | (_) | |_| | | | | __/ |_| | */ +/* By: thomas |_|\___/ \__,_|_| |_|\___|\__, |.fr */ +/* Last updated: 2016/05/29 01:55:54 |___/ */ +/* */ +/* ************************************************************************** */ + +#include + +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; + } +} diff --git a/src/ML_bmp_16_and.c b/src/ML_bmp_16_and.c deleted file mode 100644 index 37f29d1..0000000 --- a/src/ML_bmp_16_and.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ML_bmp_16_and.c */ -/* | Project : libmonochrome */ -/* */ -/* By: Pierre "PierrotLL" Le Gall */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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 */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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>3 ; j++) - { - line = ~((unsigned char)~bmp[i*(real_width>>3)+j]<>3)+j] | (unsigned char)-1>>8-(width&7))< */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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>3)+begin_x]<>3)+j]<>3)+end_x]; - if(bool3) line &= -1< */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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>3 ; j++) - { - line = bmp[i*(real_width>>3)+j]<>3)+j] & -1<<(real_width-width))< */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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>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>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< */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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>3 ; j++) - { - line = bmp[i*(real_width>>3)+j]<>3)+j] & -1<<(real_width-width))< */ -/* Last updated: 2011/11/22 */ -/* */ -/* ************************************************************************** */ - -#include - -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>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>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< 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>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>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>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; + } } diff --git a/src/ML_horizontal_scroll.c b/src/ML_horizontal_scroll.c index 060521e..e7c4847 100644 --- a/src/ML_horizontal_scroll.c +++ b/src/ML_horizontal_scroll.c @@ -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++) diff --git a/src/ML_pixel.c b/src/ML_pixel.c index 9cea53e..eedacfa 100644 --- a/src/ML_pixel.c +++ b/src/ML_pixel.c @@ -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; } } diff --git a/src/ML_pixel_test.c b/src/ML_pixel_test.c index 784c9da..fbc82fb 100644 --- a/src/ML_pixel_test.c +++ b/src/ML_pixel_test.c @@ -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); } diff --git a/src/ML_vertical_line.c b/src/ML_vertical_line.c index a7faa96..4b7abac 100644 --- a/src/ML_vertical_line.c +++ b/src/ML_vertical_line.c @@ -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; } } diff --git a/src/ML_vertical_scroll.c b/src/ML_vertical_scroll.c index 4f37ed3..34ada86 100644 --- a/src/ML_vertical_scroll.c +++ b/src/ML_vertical_scroll.c @@ -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++) {