X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FDraw2.c;h=ec82e44e768de69a634fd8a52adcf52322ebceff;hb=d95259bdaaf911218656d8a74b096ff7306034f6;hp=b8fa76ad178bd6128c3cb3155e86dc1552d6da29;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/Draw2.c b/Pico/Draw2.c index b8fa76a..ec82e44 100644 --- a/Pico/Draw2.c +++ b/Pico/Draw2.c @@ -1,6 +1,6 @@ // This is part of Pico Library -// (c) Copyright 2006 notaz, All rights reserved. +// (c) Copyright 2007, Grazvydas "notaz" Ignotas // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -10,10 +10,6 @@ #include "PicoInt.h" -#include -#ifndef __GNUC__ -#pragma warning (disable:4706) // Disable assignment within conditional -#endif // port_config.h include must define these 2 defines: // #define START_ROW 1 // which row of tiles to start rendering at? @@ -24,12 +20,17 @@ #define USE_CACHE +// note: this is not implemented in ARM asm +#if defined(DRAW2_OVERRIDE_LINE_WIDTH) +#define LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH +#else +#define LINE_WIDTH 328 +#endif -extern unsigned char *framebuff; // in format (8+320)x(8+224+8) (eights for borders) int currpri = 0; -static int HighCacheA[41*(TILE_ROWS+1)+1+1]; // caches for high layers -static int HighCacheB[41*(TILE_ROWS+1)+1+1]; +static int HighCache2A[41*(TILE_ROWS+1)+1+1]; // caches for high layers +static int HighCache2B[41*(TILE_ROWS+1)+1+1]; unsigned short *PicoCramHigh=Pico.cram; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now) void (*PicoPrepareCram)()=0; // prepares PicoCramHigh for renderer to use @@ -50,7 +51,7 @@ static int TileXnormYnorm(unsigned char *pd,int addr,unsigned char pal) unsigned int pack=0; unsigned int t=0, blank = 1; int i; - for(i=8; i; i--, addr+=2, pd += 320+8) { + for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) { pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels if(!pack) continue; @@ -73,7 +74,7 @@ static int TileXflipYnorm(unsigned char *pd,int addr,unsigned char pal) unsigned int pack=0; unsigned int t=0, blank = 1; int i; - for(i=8; i; i--, addr+=2, pd += 320+8) { + for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) { pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels if(!pack) continue; @@ -96,7 +97,7 @@ static int TileXnormYflip(unsigned char *pd,int addr,unsigned char pal) int i; addr+=14; - for(i=8; i; i--, addr-=2, pd += 320+8) { + for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) { pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels if(!pack) continue; @@ -120,7 +121,7 @@ static int TileXflipYflip(unsigned char *pd,int addr,unsigned char pal) int i; addr+=14; - for(i=8; i; i--, addr-=2, pd += 320+8) { + for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) { pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels if(!pack) continue; @@ -143,7 +144,7 @@ static void DrawWindowFull(int start, int end, int prio) { struct PicoVideo *pvid=&Pico.video; int nametab, nametab_step, trow, tilex, blank=-1, code; - unsigned char *scrpos = framebuff; + unsigned char *scrpos = PicoDraw2FB; int tile_start, tile_end; // in cells // parse ranges @@ -169,8 +170,8 @@ static void DrawWindowFull(int start, int end, int prio) code=Pico.vram[nametab+tile_start]; if ((code>>15) != prio) return; // hack: just assume that whole window uses same priority - scrpos+=8*328+8; - scrpos+=8*328*(start-START_ROW); + scrpos+=8*LINE_WIDTH+8; + scrpos+=8*LINE_WIDTH*(start-START_ROW); // do a window until we reach planestart row for(trow = start; trow < end; trow++, nametab+=nametab_step) { // current tile row @@ -198,7 +199,7 @@ static void DrawWindowFull(int start, int end, int prio) if(zero) blank=code; // We know this tile is blank now } - scrpos += 328*8; + scrpos += LINE_WIDTH*8; } } @@ -235,20 +236,20 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend) height=(width>>4)&3; width&=3; xmask=(1<1) ymask =0x1f; + ymask=(height<<5)|0x1f; // Y Mask in tiles + if(width == 1) ymask&=0x3f; + else if(width>1) ymask =0x1f; // Find name table: if (plane==0) nametab=(pvid->reg[2]&0x38)<< 9; // A else nametab=(pvid->reg[4]&0x07)<<12; // B - scrpos = framebuff; - scrpos+=8*328*(planestart-START_ROW); + scrpos = PicoDraw2FB; + scrpos+=8*LINE_WIDTH*(planestart-START_ROW); // Get vertical scroll value: vscroll=Pico.vsram[plane]&0x1ff; - scrpos+=(8-(vscroll&7))*328; + scrpos+=(8-(vscroll&7))*LINE_WIDTH; if(vscroll&7) planeend++; // we have vertically clipped tiles due to vscroll, so we need 1 more row *hcache++ = 8-(vscroll&7); // push y-offset to tilecache @@ -307,7 +308,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend) if(zero) blank=code; // We know this tile is blank now } - scrpos += 328*8; + scrpos += LINE_WIDTH*8; } *hcache = 0; // terminate cache @@ -321,10 +322,10 @@ static void DrawTilesFromCacheF(int *hc) // unsigned short *pal; unsigned char pal; short blank=-1; // The tile we know is blank - unsigned char *scrpos = framebuff, *pd = 0; + unsigned char *scrpos = PicoDraw2FB, *pd = 0; // *hcache++ = code|(dx<<16)|(trow<<27); // cache it - scrpos+=(*hc++)*328 - START_ROW*328*8; + scrpos+=(*hc++)*LINE_WIDTH - START_ROW*LINE_WIDTH*8; while((code=*hc++)) { if((short)code == blank) continue; @@ -332,7 +333,7 @@ static void DrawTilesFromCacheF(int *hc) // y pos if(((unsigned)code>>27) != prevy) { prevy = (unsigned)code>>27; - pd = scrpos + prevy*328*8; + pd = scrpos + prevy*LINE_WIDTH*8; } // Get tile address/2: @@ -384,8 +385,8 @@ static void DrawSpriteFull(unsigned int *sprite) // goto first vertically visible tile while(sy <= START_ROW*8) { sy+=8; tile+=tdeltay; height--; } - scrpos = framebuff; - scrpos+=(sy-START_ROW*8)*328; + scrpos = PicoDraw2FB; + scrpos+=(sy-START_ROW*8)*LINE_WIDTH; for (; height > 0; height--, sy+=8, tile+=tdeltay) { @@ -407,7 +408,7 @@ static void DrawSpriteFull(unsigned int *sprite) } } - scrpos+=8*328; + scrpos+=8*LINE_WIDTH; } } #endif @@ -484,8 +485,7 @@ static void DrawAllSpritesFull(int prio, int maxwidth) #ifndef _ASM_DRAW_C static void BackFillFull(int reg7) { - unsigned int back, i; - unsigned int *p=(unsigned int *)framebuff; + unsigned int back; // Start with a background color: // back=PicoCramHigh[reg7&0x3f]; @@ -493,12 +493,7 @@ static void BackFillFull(int reg7) back|=back<<8; back|=back<<16; - for(i = (8+320)*(8+(END_ROW-START_ROW)*8)/16; i; i--) { - *p++ = back; // do 16 pixels per iteration - *p++ = back; - *p++ = back; - *p++ = back; - } + memset32((int *)PicoDraw2FB, back, LINE_WIDTH*(8+(END_ROW-START_ROW)*8)/4); } #endif @@ -563,17 +558,17 @@ static void DrawDisplayFull() if(hvwin==1) { winend|=maxcolc<<16; planeend|=maxcolc<<16; } currpri = 0; - DrawLayerFull(1, HighCacheB, START_ROW, (maxcolc<<16)|END_ROW); + DrawLayerFull(1, HighCache2B, START_ROW, (maxcolc<<16)|END_ROW); switch(hvwin) { case 4: // fullscreen window DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 0); - HighCacheA[1] = 0; + HighCache2A[1] = 0; break; case 3: // we have plane A and both v and h windows - DrawLayerFull(0, HighCacheA, planestart, planeend); + 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 break; @@ -581,20 +576,20 @@ static void DrawDisplayFull() case 2: case 1: // both window and plane A visible, window is vertical XOR horizontal - DrawLayerFull(0, HighCacheA, planestart, planeend); + DrawLayerFull(0, HighCache2A, planestart, planeend); DrawWindowFull(winstart, winend, 0); break; default: // fullscreen plane A - DrawLayerFull(0, HighCacheA, START_ROW, (maxcolc<<16)|END_ROW); + DrawLayerFull(0, HighCache2A, START_ROW, (maxcolc<<16)|END_ROW); break; } DrawAllSpritesFull(0, maxw); #ifdef USE_CACHE - if(HighCacheB[1]) DrawTilesFromCacheF(HighCacheB); - if(HighCacheA[1]) DrawTilesFromCacheF(HighCacheA); + if(HighCache2B[1]) DrawTilesFromCacheF(HighCache2B); + if(HighCache2A[1]) DrawTilesFromCacheF(HighCache2A); switch(hvwin) { case 4: // fullscreen window @@ -621,7 +616,7 @@ static void DrawDisplayFull() } -void PicoFrameFull() +PICO_INTERNAL void PicoFrameFull() { // prepare cram? if(PicoPrepareCram) PicoPrepareCram();