//waitbjoy : wait the pression of a joystick button (or emulate in keyboard) int waitbjoy(int joy,int jbutton){ if (jbutton==0) while(bjoy(joy)==0){ if (autotimer()!=0)return -1; } else while(bjoy(joy)!=jbutton){ if (autotimer()!=0)return -1; } return 0; }
//bar(x,y,x1,y1) : write a fill rettangle int bar(int x,int y,int x1,int y1) { SDL_Rect d; int tmp; if (x1<x){ tmp=x1; x1=x; x=tmp; } if (y1<y){ tmp=y1; y1=y; y=tmp; } d.x=x; d.y=y; d.w=x1-x+1; d.h=y1-y+1; SDL_FillRect (SDLscreen[c_screen], &d,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b)); if (autotimer()!=0)return -1; return 0; }
//box(x,y,x1,y1) : write a empty rettangle int box(int x,int y,int x1,int y1) { int tmp; if (SDL_MUSTLOCK(SDLscreen[c_screen])) SDL_LockSurface(SDLscreen[c_screen]); if (x1<x){ tmp=x1; x1=x; x=tmp; } if (y1<y){ tmp=y1; y1=y; y=tmp; } draw_box(SDLscreen[c_screen],x,y,x1,y1,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b)); if (SDL_MUSTLOCK(SDLscreen[c_screen])) SDL_UnlockSurface(SDLscreen[c_screen]); if (autotimer()!=0)return -1; return 0; }
//pastebob(x,y,n) : copy on screen image n at x,y performing clip int pastebob(int x,int y,int n) { SDL_Rect s; SDL_Rect d; if (n<0 || n>NUM_IMAGES){ error_description="SDLengine error - pasteBob: invalid image number "; error_type=1; SDLerr(stderr, "SDLengine error - pasteBob: %d is an invalid image number", n); return -1; } if (SDLimageCC[n]!=NULL){ s.x=0; s.y=0; s.w=SDLimageCC[n]->w; s.h=SDLimageCC[n]->h; d.x=x-SDL_hsx[n]; d.y=y-SDL_hsy[n]; d.w=SDLimageCC[n]->w; d.h=SDLimageCC[n]->h; SDL_BlitSurface(SDLimageCC[n], &s, SDLscreen[c_screen], &d ); } else { error_description="SDLengine error - pasteBob: specified image slot is empty "; error_type=1; SDLerr(stderr, "SDLengine error - pasteBob: image slot %d is empty", n); return -1; } if (autotimer()!=0)return -1; return 0; }
//blt(n,sx,sy,sw,sh,dx,dy) : copy a part of graphics slot in screen int blt(int n,int sx,int sy,int sw,int sh,int dx,int dy) { SDL_Rect s; SDL_Rect d; s.x=sx; s.y=sy; s.w=sw; s.h=sh; d.x=dx; d.y=dy; d.w=sw; d.h=sh; if (n<0 || n>NUM_IMAGES)return -1; if (SDLimage[n]!=NULL){ SDL_BlitSurface( SDLimage[n], &s ,SDLscreen[c_screen], &d); } else { error_description="SDLengine error - blt: specified image slot is empty "; error_type=1; SDLerr(stderr, "SDLengine error - blt: image slot %d is empty", n); return-1; } if (autotimer()!=0)return -1; return 0; }
//waitTime(t) : wait t milliseconds int waitTime(int t) { Uint32 ticks; ticks=SDL_GetTicks()+t; while(ticks>SDL_GetTicks()){ SDL_Delay(5); getevent(); if (stopkey()==-1)return -1; if (autotimer()!=0)return -1; } return 0; }
//fillellipse(x,y,rx,ry) : write a fill ellipse int fillellipse(int x,int y,int rx,int ry) { if (SDL_MUSTLOCK(SDLscreen[c_screen])) SDL_LockSurface(SDLscreen[c_screen]); draw_fillellipse(SDLscreen[c_screen],x,y,rx,ry,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b)); if (SDL_MUSTLOCK(SDLscreen[c_screen])) SDL_UnlockSurface(SDLscreen[c_screen]); if (autotimer()!=0)return -1; return 0; }
//line(x,y,x1,y1) : write a line int line(int x,int y,int x1,int y1) { if (SDL_MUSTLOCK(SDLscreen[c_screen]) ) SDL_LockSurface(SDLscreen[c_screen]); draw_line(SDLscreen[c_screen],x,y,x1,y1,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b)); if (SDL_MUSTLOCK(SDLscreen[c_screen]) ) SDL_UnlockSurface(SDLscreen[c_screen]); if (autotimer()!=0)return -1; return 0; }
//dot(x,y) : write x,y point with a current color int dot(int x,int y) { if (SDL_MUSTLOCK(SDLscreen[c_screen]) ) SDL_LockSurface(SDLscreen[c_screen]); putpixel( SDLscreen[c_screen], x, y,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b)); if (SDL_MUSTLOCK(SDLscreen[c_screen]) ) SDL_UnlockSurface(SDLscreen[c_screen]); if (autotimer()!=0)return -1; return 0; }
//bjoy : return joystick buttons pressed in boolean expression int bjoy(int index) { int ret,i,a; if (index>=SDL_NumJoysticks())return emulate_bjoy(index); ret=0; a=1; SDL_JoystickUpdate(); for(i=0;i<SDL_JoystickNumButtons(SDLjoy[index]);i++){ if(SDL_JoystickGetButton(SDLjoy[index],i))ret+=a; a*=2; } if (autotimer()!=0)return -1; return ret; }
//joy : return joystick boolean coordinate int joy(int index) { int ret,tmp; if (index>=SDL_NumJoysticks())return -1; SDL_JoystickUpdate(); ret=0; if (SDLjoy[index] && SDL_JoystickNumAxes(SDLjoy[index])>=2 ){ tmp= SDL_JoystickGetAxis(SDLjoy[index],0); if (tmp<0) ret+=1; if (tmp>0) ret+=2; tmp= SDL_JoystickGetAxis(SDLjoy[index],1); if (tmp<0) ret+=4; if (tmp>0) ret+=8; } if (SDLjoy[index] && SDL_JoystickNumHats(SDLjoy[index])>0 ){ ret+=SDL_JoystickGetHat(SDLjoy[index],0); } if (autotimer()!=0)return -1; return ret; }
//triangle(xa,ya,xb,yb,xc,yc) : draw a filled triangle int triangle(int x1,int y1,int x2,int y2,int x3,int y3) { int c,x,y; int dx,dy; double sl; //* dx = x2 - x1; // change in x dy = y2 - y1; // change in y sl = (double)dy / dx; if (abs(dx) >= abs(dy)) { // draw left/right - right/left c = (x1 <= x2) ? 1 : -1; for (x = x1; x != x2 + c; x += c) { y = y1 + (int)( (x - x1) * sl + 0.5 ); if (y>=0) line(x,y,x3,y3); } } else { // draw top/bottom - bottom/top c = (y1 <= y2) ? 1 : -1; for (y = y1; y != y2 + c; y += c) { x =(int) x1 + (int)( (y - y1) / sl + 0.5 ); line(x,y,x3,y3); } } dx = x3 - x2; // change in x dy = y3 - y2; // change in y sl = (double)dy / dx; if (abs(dx) >= abs(dy)) { // draw left/right - right/left c = (x2 <= x3) ? 1 : -1; for (x = x2; x != x3 + c; x += c) { y = y2 + (int)( (x - x2) * sl + 0.5 ); if (y>=0) line(x,y,x1,y1); } } else { // draw top/bottom - bottom/top c = (y2 <= y3) ? 1 : -1; for (y = y2; y != y3 + c; y += c) { x =(int) x2 + (int)( (y - y2) / sl + 0.5 ); line(x,y,x1,y1); } } dx = x1 - x3; // change in x dy = y1 - y3; // change in y sl = (double)dy / dx; if (abs(dx) >= abs(dy)) { // draw left/right - right/left c = (x3 <= x1) ? 1 : -1; for (x = x3; x != x1 + c; x += c) { y = y3 + (int)( (x - x3) * sl + 0.5 ); if (y>=0) line(x,y,x2,y2); } } else { // draw top/bottom - bottom/top c = (y3 <= y1) ? 1 : -1; for (y = y3; y != y1 + c; y += c) { x =(int) x3 + (int)( (y - y3) / sl + 0.5 ); line(x,y,x2,y2); } } //*/ if (autotimer()!=0)return -1; return 0; }
//paint(x,y) : fill a close area int paint(int x,int y) { char *paintmap; int xstart,ystart; int src_col,col; char pm; if (SDL_MUSTLOCK(SDLscreen[c_screen])) SDL_LockSurface(SDLscreen[c_screen]); paintmap= malloc(screenwidth()*screenheight()); xstart=x; ystart=y; src_col=getpixel(SDLscreen[c_screen],x,y);//point(x,y); putpixel(SDLscreen[c_screen],x,y,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b));//dot(x,y); col=getpixel(SDLscreen[c_screen],x,y);//point(x,y); pm=2; if (col==src_col)return -1; while(0==0) { //if (point(x,y)==src_col) { if (getpixel(SDLscreen[c_screen],x,y)== src_col) { putpixel(SDLscreen[c_screen],x,y,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b));//dot(x,y); paintmap[y*screenwidth()+x]=pm; } //if (point(x+1,y)==src_col && (x+1) < screenwidth()) { if (getpixel(SDLscreen[c_screen],x+1,y)==src_col && (x+1) < screenwidth()) { x=x+1; pm=1; } //else if (point(x-1,y)==src_col && (x-1) > 0 ) { else if (getpixel(SDLscreen[c_screen],x-1,y)==src_col && (x-1) >= 0 ) { x=x-1; pm=2; } //else if (point(x,y+1)==src_col && (y+1) < screenheight()) { else if (getpixel(SDLscreen[c_screen],x,y+1)==src_col && (y+1) < screenheight()) { y=y+1; pm=3; } //else if (point(x,y-1)==src_col && (y-1) > 0) { else if (getpixel(SDLscreen[c_screen],x,y-1)==src_col && (y-1) >= 0) { y=y-1; pm=4; } else { if (x==xstart && y==ystart)break; if (paintmap[y*screenwidth()+x]==1) x=x-1; else if (paintmap[y*screenwidth()+x]==2) x=x+1; else if (paintmap[y*screenwidth()+x]==3) y=y-1; else if (paintmap[y*screenwidth()+x]==4) y=y+1; } } free(paintmap); if (SDL_MUSTLOCK(SDLscreen[c_screen]) ) SDL_UnlockSurface(SDLscreen[c_screen]); if (autotimer()!=0)return -1; return 0; }
//dot_ex(x,y,c) : write x,y point with a c color int dot_ex(int x,int y,int c) { ink(c); if (autotimer()!=0)return -1; return dot(x,y); }
//emulate_bjoy : return emulate joystick buttons in keyboard keys int emulate_bjoy(int index) { Uint8 *keystate; if (autotimer()!=0)return -1; getevent(); keystate = SDL_GetKeyState(NULL); int ret,a; ret=0; a=1; if(keystate[273] || keystate[264])ret+=a; //gp2x_north cursup or keypad 8 a*=2; if((keystate[273] && keystate[276]) || keystate[263])ret+=a; //gp2x_northwest cursup+cursleft or keypad 7 a*=2; if(keystate[276] || keystate[260])ret+=a; //gp2x_west cursleft or keypad 4 a*=2; if((keystate[274] && keystate[276]) || keystate[257])ret+=a; //gp2x_southwest cursdown+cursleft or keypad 1 a*=2; if(keystate[274] || keystate[258])ret+=a; //gp2x_south cursdown or keypad 2 a*=2; if((keystate[274] && keystate[275]) || keystate[259])ret+=a; //gp2x_southeast cursdown+cursright or keypad 3 a*=2; if(keystate[275] || keystate[262])ret+=a; //gp2x_east cursright or keypad 6 a*=2; if((keystate[273] && keystate[275]) || keystate[265])ret+=a; //gp2x_northeast cursup+cursright or keypad 9 a*=2; if(keystate[13])ret+=a; //gp2x_start enter a*=2; if(keystate[32])ret+=a; //gp2x_select space a*=2; if(keystate[304])ret+=a; //gp2x_topleft left shift a*=2; if(keystate[303])ret+=a; //gp2x_topright right shift a*=2; if(keystate[97])ret+=a; //gp2x_a a a*=2; if(keystate[115])ret+=a; //gp2x_b s a*=2; if(keystate[100])ret+=a; //gp2x_x d a*=2; if(keystate[102])ret+=a; //gp2x_y f a*=2; if(keystate[280])ret+=a; //gp2x_volup pageup a*=2; if(keystate[281])ret+=a; //gp2x_voldown pagedown a*=2; if(keystate[261])ret+=a; //gp2x_center keypad 5 a*=2; //printf( "emulate joy=%d\n",ret); //DEBUG!!! return ret; }