00001 #ifndef _DRAWMETHODS_H
00002 #define _DRAWMETHODS_H
00003
00004 #include "goomconfig.h"
00005
00006 #define DRAWMETHOD_NORMAL(adr,col) {*(adr) = (col);}
00007
00008 #ifdef MMX
00009 #include "mmx.h"
00010
00011 #define DRAWMETHOD_PLUS(_out,_backbuf,_col) \
00012 {\
00013 movd_m2r (_backbuf, mm0); \
00014 paddusb_m2r (_col, mm0); \
00015 movd_r2m (mm0, _out); \
00016 }
00017
00018 #else
00019 #define DRAWMETHOD_PLUS(_out,_backbuf,_col) \
00020 {\
00021 int tra=0,i=0;\
00022 unsigned char *bra = (unsigned char*)&(_backbuf);\
00023 unsigned char *dra = (unsigned char*)&(_out);\
00024 unsigned char *cra = (unsigned char*)&(_col);\
00025 for (;i<4;i++) {\
00026 tra = *cra;\
00027 tra += *bra;\
00028 if (tra>255) tra=255;\
00029 *dra = tra;\
00030 ++dra;++cra;++bra;\
00031 }\
00032 }
00033 #endif
00034
00035 #define DRAWMETHOD_OR(adr,col) {*(adr)|=(col);}
00036
00037 #ifdef MMX
00038 #define DRAWMETHOD_DONE() {__asm__ __volatile__ ("emms");}
00039 #else
00040 #define DRAWMETHOD_DONE() {}
00041 #endif
00042
00043 #ifndef DRAWMETHOD
00044 #define DRAWMETHOD DRAWMETHOD_PLUS(*p,*p,col)
00045
00046 static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny) {
00047 int x, y, dx, dy, yy, xx;
00048 int *p;
00049
00050
00051 if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx))
00052 return;
00053
00054 dx = x2 - x1;
00055 dy = y2 - y1;
00056 if (x1 > x2) {
00057 int tmp;
00058
00059 tmp = x1;
00060 x1 = x2;
00061 x2 = tmp;
00062 tmp = y1;
00063 y1 = y2;
00064 y2 = tmp;
00065 dx = x2 - x1;
00066 dy = y2 - y1;
00067 }
00068
00069
00070 if (dx == 0) {
00071 if (y1 < y2) {
00072 p = &(data[(screenx * y1) + x1]);
00073 for (y = y1; y <= y2; y++) {
00074 DRAWMETHOD;
00075 p += screenx;
00076 }
00077 }
00078 else {
00079 p = &(data[(screenx * y2) + x1]);
00080 for (y = y2; y <= y1; y++) {
00081 DRAWMETHOD;
00082 p += screenx;
00083 }
00084 }
00085 return;
00086 }
00087
00088 if (dy == 0) {
00089 if (x1 < x2) {
00090 p = &(data[(screenx * y1) + x1]);
00091 for (x = x1; x <= x2; x++) {
00092 DRAWMETHOD;
00093 p++;
00094 }
00095 return;
00096 }
00097 else {
00098 p = &(data[(screenx * y1) + x2]);
00099 for (x = x2; x <= x1; x++) {
00100 DRAWMETHOD;
00101 p++;
00102 }
00103 return;
00104 }
00105 }
00106
00107
00108
00109 if (y2 > y1) {
00110
00111 if (dy > dx) {
00112 dx = ((dx << 16) / dy);
00113 x = x1 << 16;
00114 for (y = y1; y <= y2; y++) {
00115 xx = x >> 16;
00116 p = &(data[(screenx * y) + xx]);
00117 DRAWMETHOD;
00118 if (xx < (screenx - 1)) {
00119 p++;
00120 }
00121 x += dx;
00122 }
00123 return;
00124 }
00125
00126 else {
00127 dy = ((dy << 16) / dx);
00128 y = y1 << 16;
00129 for (x = x1; x <= x2; x++) {
00130 yy = y >> 16;
00131 p = &(data[(screenx * yy) + x]);
00132 DRAWMETHOD;
00133 if (yy < (screeny - 1)) {
00134 p += screeny;
00135 }
00136 y += dy;
00137 }
00138 }
00139 }
00140
00141
00142
00143 else {
00144
00145 if (-dy > dx) {
00146 dx = ((dx << 16) / -dy);
00147 x = (x1 + 1) << 16;
00148 for (y = y1; y >= y2; y--) {
00149 xx = x >> 16;
00150 p = &(data[(screenx * y) + xx]);
00151 DRAWMETHOD;
00152 if (xx < (screenx - 1)) {
00153 p--;
00154 }
00155 x += dx;
00156 }
00157 return;
00158 }
00159
00160 else {
00161 dy = ((dy << 16) / dx);
00162 y = y1 << 16;
00163 for (x = x1; x <= x2; x++) {
00164 yy = y >> 16;
00165 p = &(data[(screenx * yy) + x]);
00166 DRAWMETHOD;
00167 if (yy < (screeny - 1)) {
00168 p += screeny;
00169 }
00170 y += dy;
00171 }
00172 return;
00173 }
00174 }
00175 }
00176 #endif
00177
00178 #endif