#ifdef SGI # include "../../blend/psx.h" # include "fbmm.h" #else # include "../ton/psxutil.h" # include "../ton/psxgraph.h" # include "fbmm.h" #endif struct FrameBufferAlloc fbA[MAXFBA]; int fbAcnt = -1; int fb_free(int bf_ptr) { if (fbA[bf_ptr].iu == FB_CLEAR){ printf("Double free fp_ptr (%i %s)\n", bf_ptr, fbA[bf_ptr].name); return(-1); } fbA[bf_ptr].iu = FB_CLEAR; return(0); } int fb_free_all(short permission) { int i; for (i=0; i 15) { name[14] = 0; } fbA[i].sx = orgx; fbA[i].sy = orgy; fbA[i].ex = orgx + sizx-1; fbA[i].ey = orgy + sizy-1; fbA[i].iu = FB_ADD; strcpy(fbA[i].name, name); fbAcnt = i; return(i); } int does_it_fit(int sx, int sy, int ex, int ey) { int i, fsx, fsy, fex, fey, bits =0; for (i=0; i=fsx) && (ex <=fex) && (sy >=fsy) && (ey <=fey) ) return(15); if ( (sx >=fsx) && (sx < fex) ){ if ( (sy >=fsy) && (sy <=fey) ) return( 9); if ( (ey >=fsy) && (ey <=fey) ) return(12); if ( (sy < fsy) && (ey >=fey) ) return( 8); } if ( (ex >=fsx) && (ex <=fex) ){ if ( (sy >=fsy) && (sy <=fey) ) return( 3); if ( (ey >=fsy) && (ey <=fey) ) return( 6); if ( (sy < fsy) && (ey > fey) ) return( 2); } if ( (sx fex) ) { if ( (sy >=fsy) && (sy <=fey) ) return( 1); if ( (ey >=fsy) && (ey <=fey) ) return( 4); } } } return(0); } int fit_it(orgx,orgy, sx,sy, dx,dy, sdy, sizx,sizy, fbn) int *orgx,*orgy; int sx,sy, dx,dy, sdy, sizx,sizy, fbn; { int x, y, h, ex, ey, sh, eh, dh, bits; ex = -1; if (sx == 0) { ex = 1024; }else{ sx -= sizx; } ey = -1; if (sy == 0) { ey = 512; }else{ sy -= sizy; } dx *= 64; dy *= 256; for(y = sy; y != ey; y += dy){ sh = y; eh = y + sizy; if (sdy == -1) { sh = y + sizy; eh = y; } for (x = sx; x != ex; x += dx){ for (h = sh; h != eh; h+=sdy){ bits = does_it_fit(x, h, x+sizx-1, h+sizy-1); if (bits == 0) { *orgx = x; *orgy = h; fbA[fbn].sx = x; fbA[fbn].sy = h; fbA[fbn].ex = x + sizx-1; fbA[fbn].ey = h + sizy-1; fbA[fbn].iu = FB_ALLOC; return(1); /* OK */ } } } } return(0); /* ERROR */ } int fb_alloc(int *orgx, int *orgy, int sizx, int sizy, char *name) { int i, c, bits; int xb, yb; int sx, sy, ex, ey; int searchtype; if (fbAcnt == -1){ /* FirstTime so Init */ for (i=0; i 256) return(-3); searchtype = 0; /* Garbage */ if (sizy == 1) searchtype = 1; /* Palette */ if (sizy == 256) searchtype = 2; /* PictureBlock */ while (fbA[i].iu != FB_CLEAR) { i++; if (i == MAXFBA) i = 0; if (i == c) return(-2); } if (strlen(name) > 15) name[14] = 0; fbAcnt = i; sizx = ((sizx + 63) / 64); sizx = sizx * 64; switch(searchtype){ case 0: /* if( fit_it(&orgx, &orgy, 1024, 512, -1,-1, -1, sizx, sizy, i)) { strcpy(fbA[i].name, name); return(i); } break; */ case 1: /* if( fit_it(&orgx, &orgy, 1024, 256, 1,-1, 1, sizx, sizy, i)) { strcpy(fbA[i].name, name); return(i); } break; */ case 2: if( fit_it(&orgx, &orgy, 0, 0, 1, 1, 1, sizx, sizy, i)) { strcpy(fbA[i].name, name); return(i); } break; } return(-1); } void dev_print_fba_block() { int i; for (i=0; i