X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=picodrive.git;a=blobdiff_plain;f=pico%2Fdraw2.c;h=db155fa27fa0c0d758af0f459578c24b3bd9f761;hp=58139d930705390ce90062b32140e966d66d11d4;hb=e0bcb7a90d06b295b1ca989b6ad70412912cca5b;hpb=cff531af94bd9c9c89ae162e80f48ddc26a4e504 diff --git a/pico/draw2.c b/pico/draw2.c index 58139d9..db155fa 100644 --- a/pico/draw2.c +++ b/pico/draw2.c @@ -8,15 +8,11 @@ #include "pico_int.h" -// port_config.h include must define these 2 defines: -// #define START_ROW 1 // which row of tiles to start rendering at? -// #define END_ROW 27 // ..end -// one row means 8 pixels. If above example was used, (27-1)*8=208 lines would be rendered. +#define START_ROW 0 // which row of tiles to start rendering at? +#define END_ROW 28 // ..end #define TILE_ROWS END_ROW-START_ROW -#define USE_CACHE - // note: this is not implemented in ARM asm #if defined(DRAW2_OVERRIDE_LINE_WIDTH) #define LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH @@ -24,6 +20,8 @@ #define LINE_WIDTH 328 #endif +static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; + static int HighCache2A[41*(TILE_ROWS+1)+1+1]; // caches for high layers static int HighCache2B[41*(TILE_ROWS+1)+1+1]; @@ -33,11 +31,12 @@ void (*PicoPrepareCram)()=0; // prepares PicoCramHigh for renderer to // stuff available in asm: #ifdef _ASM_DRAW_C -void BackFillFull(int reg7); -void DrawLayerFull(int plane, int *hcache, int planestart, int planeend); -void DrawTilesFromCacheF(int *hc); -void DrawWindowFull(int start, int end, int prio); -void DrawSpriteFull(unsigned int *sprite); +void BackFillFull(void *dst, int reg7); +void DrawLayerFull(int plane, int *hcache, int planestart, int planeend, + struct PicoEState *est); +void DrawTilesFromCacheF(int *hc, struct PicoEState *est); +void DrawWindowFull(int start, int end, int prio, struct PicoEState *est); +void DrawSpriteFull(unsigned int *sprite, struct PicoEState *est); #else @@ -135,11 +134,11 @@ static int TileXflipYflip(unsigned char *pd,int addr,unsigned char pal) // start: (tile_start<<16)|row_start, end: [same] -static void DrawWindowFull(int start, int end, int prio) +static void DrawWindowFull(int start, int end, int prio, struct PicoEState *est) { struct PicoVideo *pvid=&Pico.video; int nametab, nametab_step, trow, tilex, blank=-1, code; - unsigned char *scrpos = PicoDraw2FB; + unsigned char *scrpos = est->Draw2FB; int tile_start, tile_end; // in cells // parse ranges @@ -199,7 +198,8 @@ static void DrawWindowFull(int start, int end, int prio) } -static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend) +static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend, + struct PicoEState *est) { struct PicoVideo *pvid=&Pico.video; static char shift[4]={5,6,6,7}; // 32,64 or 128 sized tilemaps @@ -239,7 +239,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend) if (plane==0) nametab=(pvid->reg[2]&0x38)<< 9; // A else nametab=(pvid->reg[4]&0x07)<<12; // B - scrpos = PicoDraw2FB; + scrpos = est->Draw2FB; scrpos+=8*LINE_WIDTH*(planestart-START_ROW); // Get vertical scroll value: @@ -306,14 +306,14 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend) } -static void DrawTilesFromCacheF(int *hc) +static void DrawTilesFromCacheF(int *hc, struct PicoEState *est) { int code, addr, zero = 0; unsigned int prevy=0xFFFFFFFF; // unsigned short *pal; unsigned char pal; short blank=-1; // The tile we know is blank - unsigned char *scrpos = PicoDraw2FB, *pd = 0; + unsigned char *scrpos = est->Draw2FB, *pd = 0; // *hcache++ = code|(dx<<16)|(trow<<27); // cache it scrpos+=(*hc++)*LINE_WIDTH - START_ROW*LINE_WIDTH*8; @@ -345,7 +345,7 @@ static void DrawTilesFromCacheF(int *hc) // sx and sy are coords of virtual screen with 8pix borders on top and on left -static void DrawSpriteFull(unsigned int *sprite) +static void DrawSpriteFull(unsigned int *sprite, struct PicoEState *est) { int width=0,height=0; // unsigned short *pal=NULL; @@ -376,7 +376,7 @@ static void DrawSpriteFull(unsigned int *sprite) // goto first vertically visible tile while(sy <= START_ROW*8) { sy+=8; tile+=tdeltay; height--; } - scrpos = PicoDraw2FB; + scrpos = est->Draw2FB; scrpos+=(sy-START_ROW*8)*LINE_WIDTH; for (; height > 0; height--, sy+=8, tile+=tdeltay) @@ -467,29 +467,29 @@ static void DrawAllSpritesFull(int prio, int maxwidth) } // Go through sprites backwards: - for (i-- ;i>=0; i--) + for (i--; i >= 0; i--) { - DrawSpriteFull(sprites[i]); + DrawSpriteFull(sprites[i], &Pico.est); } } #ifndef _ASM_DRAW_C -static void BackFillFull(int reg7) +static void BackFillFull(void *dst, int reg7) { unsigned int back; // Start with a background color: -// back=PicoCramHigh[reg7&0x3f]; back=reg7&0x3f; back|=back<<8; back|=back<<16; - memset32((int *)PicoDraw2FB, back, LINE_WIDTH*(8+(END_ROW-START_ROW)*8)/4); + memset32(dst, back, LINE_WIDTH*(8+(END_ROW-START_ROW)*8)/4); } #endif static void DrawDisplayFull(void) { + struct PicoEState *est = &Pico.est; struct PicoVideo *pvid=&Pico.video; int win, edge=0, hvwin=0; // LSb->MSb: hwin&plane, vwin&plane, full int planestart=START_ROW, planeend=END_ROW; // plane A start/end when window shares display with plane A (in tile rows or columns) @@ -551,59 +551,59 @@ static void DrawDisplayFull(void) if (hvwin==1) { winend|=maxcolc<<16; planeend|=maxcolc<<16; } HighCache2A[1] = HighCache2B[1] = 0; - if (PicoDrawMask & PDRAW_LAYERB_ON) - DrawLayerFull(1, HighCache2B, START_ROW, (maxcolc<<16)|END_ROW); - if (PicoDrawMask & PDRAW_LAYERA_ON) switch (hvwin) + if (!(pvid->debug_p & PVD_KILL_B)) + DrawLayerFull(1, HighCache2B, START_ROW, (maxcolc<<16)|END_ROW, est); + if (!(pvid->debug_p & PVD_KILL_A)) switch (hvwin) { case 4: // fullscreen window - DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 0); + DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 0, est); break; case 3: // we have plane A and both v and h windows - DrawLayerFull(0, HighCache2A, planestart, planeend); - DrawWindowFull( winstart&~0xff0000, (winend&~0xff0000)|(maxcolc<<16), 0); // h - DrawWindowFull((winstart&~0xff)|START_ROW, (winend&~0xff)|END_ROW, 0); // v + DrawLayerFull(0, HighCache2A, planestart, planeend, est); + DrawWindowFull( winstart&~0xff0000, (winend&~0xff0000)|(maxcolc<<16), 0, est); // h + DrawWindowFull((winstart&~0xff)|START_ROW, (winend&~0xff)|END_ROW, 0, est); // v break; case 2: case 1: // both window and plane A visible, window is vertical XOR horizontal - DrawLayerFull(0, HighCache2A, planestart, planeend); - DrawWindowFull(winstart, winend, 0); + DrawLayerFull(0, HighCache2A, planestart, planeend, est); + DrawWindowFull(winstart, winend, 0, est); break; default: // fullscreen plane A - DrawLayerFull(0, HighCache2A, START_ROW, (maxcolc<<16)|END_ROW); + DrawLayerFull(0, HighCache2A, START_ROW, (maxcolc<<16)|END_ROW, est); break; } - if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) + if (!(pvid->debug_p & PVD_KILL_S_LO)) DrawAllSpritesFull(0, maxw); - if (HighCache2B[1]) DrawTilesFromCacheF(HighCache2B); - if (HighCache2A[1]) DrawTilesFromCacheF(HighCache2A); - if (PicoDrawMask & PDRAW_LAYERA_ON) switch (hvwin) + if (HighCache2B[1]) DrawTilesFromCacheF(HighCache2B, est); + if (HighCache2A[1]) DrawTilesFromCacheF(HighCache2A, est); + if (!(pvid->debug_p & PVD_KILL_A)) switch (hvwin) { case 4: // fullscreen window - DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 1); + DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 1, est); break; case 3: // we have plane A and both v and h windows - DrawWindowFull( winstart&~0xff0000, (winend&~0xff0000)|(maxcolc<<16), 1); // h - DrawWindowFull((winstart&~0xff)|START_ROW, (winend&~0xff)|END_ROW, 1); // v + DrawWindowFull( winstart&~0xff0000, (winend&~0xff0000)|(maxcolc<<16), 1, est); // h + DrawWindowFull((winstart&~0xff)|START_ROW, (winend&~0xff)|END_ROW, 1, est); // v break; case 2: case 1: // both window and plane A visible, window is vertical XOR horizontal - DrawWindowFull(winstart, winend, 1); + DrawWindowFull(winstart, winend, 1, est); break; } - if (PicoDrawMask & PDRAW_SPRITES_HI_ON) + if (!(pvid->debug_p & PVD_KILL_S_HI)) DrawAllSpritesFull(1, maxw); } @@ -616,10 +616,14 @@ PICO_INTERNAL void PicoFrameFull() if (PicoPrepareCram) PicoPrepareCram(); // Draw screen: - BackFillFull(Pico.video.reg[7]); + BackFillFull(Pico.est.Draw2FB, Pico.video.reg[7]); if (Pico.video.reg[1] & 0x40) DrawDisplayFull(); pprof_end(draw); } +void PicoDraw2Init(void) +{ + Pico.est.Draw2FB = PicoDraw2FB_; +}