void DrawWindow(int tstart, int tend, int prio, int sh);\r
void BackFill(int reg7, int sh);\r
void DrawSprite(int *sprite, int **hc, int sh);\r
-void DrawTilesFromCache(int *hc, int sh);\r
+void DrawTilesFromCache(int *hc, int sh, int rlim);\r
void DrawSpritesFromCache(int *hc, int sh);\r
void DrawLayer(int plane, int *hcache, int maxcells, int sh);\r
void FinalizeLineBGR444(int sh);\r
\r
// --------------------------------------------\r
\r
-static void DrawTilesFromCache(int *hc, int sh)\r
+static void DrawTilesFromCache(int *hc, int sh, int rlim)\r
{\r
int code, addr, dx;\r
int pal;\r
\r
if (sh)\r
{\r
- while((code=*hc++)) {\r
+ while ((code=*hc++)) {\r
unsigned char *zb;\r
// Get tile address/2:\r
addr=(code&0x7ff)<<4;\r
if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;\r
\r
pal=((code>>9)&0x30);\r
+ if (rlim-dx < 0) goto last_cut_tile;\r
\r
if (code&0x0800) TileFlip(dx,addr,pal);\r
else TileNorm(dx,addr,pal);\r
else\r
{\r
short blank=-1; // The tile we know is blank\r
- while((code=*hc++)) {\r
+ while ((code=*hc++)) {\r
int zero;\r
if((short)code == blank) continue;\r
// Get tile address/2:\r
dx=(code>>16)&0x1ff;\r
\r
pal=((code>>9)&0x30);\r
+ if (rlim-dx < 0) goto last_cut_tile;\r
\r
if (code&0x0800) zero=TileFlip(dx,addr,pal);\r
else zero=TileNorm(dx,addr,pal);\r
\r
- if(zero) blank=(short)code;\r
+ if (zero) blank=(short)code;\r
+ }\r
+ }\r
+ return;\r
+\r
+last_cut_tile:\r
+ {\r
+ unsigned int t, pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
+ unsigned char *pd = HighCol+dx;\r
+ if (!pack) return;\r
+ if (code&0x0800)\r
+ {\r
+ switch (rlim-dx+8)\r
+ {\r
+ case 7: t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8)); // "break" is left out intentionally\r
+ case 6: t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));\r
+ case 5: t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));\r
+ case 4: t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));\r
+ case 3: t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));\r
+ case 2: t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));\r
+ case 1: t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));\r
+ default: break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ switch (rlim-dx+8)\r
+ {\r
+ case 7: t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));\r
+ case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));\r
+ case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));\r
+ case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));\r
+ case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));\r
+ case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));\r
+ case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));\r
+ default: break;\r
+ }\r
}\r
}\r
}\r
if (win&0x80) { if (Scanline>=edge) hvwind=1; }\r
else { if (Scanline< edge) hvwind=1; }\r
\r
- if(!hvwind) { // we might have a vertical window here\r
+ if (!hvwind) { // we might have a vertical window here\r
win=pvid->reg[0x11];\r
edge=win&0x1f;\r
- if(win&0x80) {\r
- if(!edge) hvwind=1;\r
+ if (win&0x80) {\r
+ if (!edge) hvwind=1;\r
else if(edge < (maxcells>>1)) hvwind=2;\r
} else {\r
- if(!edge);\r
+ if (!edge);\r
else if(edge < (maxcells>>1)) hvwind=2;\r
else hvwind=1;\r
}\r
}\r
\r
DrawLayer(1, HighCacheB, maxcells, sh);\r
- if(hvwind == 1)\r
+ if (hvwind == 1)\r
DrawWindow(0, maxcells>>1, 0, sh); // HighCacheAW\r
- else if(hvwind == 2) {\r
+ else if (hvwind == 2) {\r
// ahh, we have vertical window\r
DrawLayer(0, HighCacheA, (win&0x80) ? edge<<1 : maxcells, sh);\r
DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh); // HighCacheW\r
DrawLayer(0, HighCacheA, maxcells, sh);\r
DrawAllSprites(HighCacheS, maxw, 0, sh);\r
\r
- if(HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh);\r
- if(hvwind == 1)\r
+ if (HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, 328);\r
+ if (hvwind == 1)\r
DrawWindow(0, maxcells>>1, 1, sh);\r
- else if(hvwind == 2) {\r
- if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh);\r
+ else if (hvwind == 2) {\r
+ if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : 0);\r
DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh);\r
} else\r
- if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh);\r
+ if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, 328);\r
DrawAllSprites(HighCacheS, maxw, 1, sh);\r
\r
#if 0\r
streqb r4, [r1,#\offs]\r
.endm\r
\r
-@ TileNorm (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: register with helper pattern 0xf, touches r3 high bits\r
+@ TileNormShHP (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: register with helper pattern 0xf, touches r3 high bits\r
.macro TileNormShHP\r
TilePixelShHP 12, 0 @ #0x0000f000\r
TilePixelShHP 8, 1 @ #0x00000f00\r
TilePixelShHP 16, 7 @ #0x000f0000\r
.endm\r
\r
-@ TileFlip (r1=pdest, r2=pixels8, r3=pal) r4: scratch, pat: register with helper pattern 0xf\r
+@ TileFlipShHP (r1=pdest, r2=pixels8, r3=pal) r4: scratch, pat: register with helper pattern 0xf\r
.macro TileFlipShHP\r
TilePixelShHP 16, 0 @ #0x000f0000\r
TilePixelShHP 20, 1 @ #0x00f00000\r
beq .DrawStrip_SingleColor @ tileline singlecolor \r
\r
tst r9, #0x0800\r
- beq .DrawStrip_TileNorm\r
+ bne .DrawStrip_TileFlip\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern\r
- TileFlip r0\r
- b .dsloop\r
-\r
.DrawStrip_TileNorm:\r
TileNorm r0\r
b .dsloop\r
\r
+.DrawStrip_TileFlip:\r
+ TileFlip r0\r
+ b .dsloop\r
+\r
.DrawStrip_SingleColor:\r
and r4, r2, #0xf\r
orr r4, r3, r4\r
beq .DrawStrip_vs_SingleColor @ tileline singlecolor \r
\r
tst r9, #0x0800\r
- beq .DrawStrip_vs_TileNorm\r
+ bne .DrawStrip_vs_TileFlip\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern\r
- TileFlip r0\r
- b .dsloop_vs\r
-\r
.DrawStrip_vs_TileNorm:\r
TileNorm r0\r
b .dsloop_vs\r
\r
+.DrawStrip_vs_TileFlip:\r
+ TileFlip r0\r
+ b .dsloop_vs\r
+\r
.DrawStrip_vs_SingleColor:\r
and r4, r2, #0xf\r
orr r4, r3, r4\r
@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
\r
\r
-.global DrawTilesFromCache @ int *hc, int sh\r
+.global DrawTilesFromCache @ int *hc, int sh, int rlim\r
\r
DrawTilesFromCache:\r
stmfd sp!, {r4-r8,r11,lr}\r
mov r12,#0xf\r
\r
mvn r5, #0 @ r5=prevcode=-1\r
- movs r8, r1\r
+ ands r8, r1, #1\r
+ orr r8, r8, r2, lsl #1\r
bne .dtfc_check_rendflags\r
\r
@ scratch: r4, r7\r
ldr r6, [r0], #4 @ read code\r
movs r1, r6, lsr #16 @ r1=dx;\r
ldmeqfd sp!, {r4-r8,r11,pc} @ dx is never zero, this must be a terminator, return\r
- bic r1, r1, #0xfe00\r
- add r1, r11, r1 @ r1=pdest\r
+ bic r4, r1, #0xfe00\r
+ add r1, r11, r4 @ r1=pdest\r
\r
mov r7, r6, lsl #16\r
cmp r5, r7, lsr #16\r
ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
\r
.dtfc_samecode:\r
- tst r8, r8\r
+ rsbs r4, r4, r8, lsr #1\r
+ bmi .dtfc_cut_tile\r
+\r
+ tst r8, #1\r
bne .dtfc_shadow\r
\r
tst r2, r2\r
beq .dtfc_SingleColor @ tileline singlecolor \r
\r
tst r5, #0x0800\r
- beq .dtfc_TileNorm\r
+ bne .dtfc_TileFlip\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
- TileFlip r12\r
- b .dtfc_loop\r
-\r
.dtfc_TileNorm:\r
TileNorm r12\r
b .dtfc_loop\r
\r
+.dtfc_TileFlip:\r
+ TileFlip r12\r
+ b .dtfc_loop\r
+\r
.dtfc_SingleColor:\r
and r4, r2, #0xf\r
orr r4, r3, r4\r
beq .dtfc_SingleColor @ tileline singlecolor \r
\r
tst r5, #0x0800\r
- beq .dtfc_TileNormShHP\r
+ bne .dtfc_TileFlipShHP\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
- TileFlipShHP\r
- b .dtfc_loop\r
-\r
.dtfc_TileNormShHP:\r
TileNormShHP\r
b .dtfc_loop\r
\r
+.dtfc_TileFlipShHP:\r
+ TileFlipShHP\r
+ b .dtfc_loop\r
+\r
.dtfc_shadow_blank:\r
ldrb r4, [r1] @ 1ci\r
ldrb r12,[r1,#1]\r
mov r12, #0xf\r
b .dtfc_loop\r
\r
+.dtfc_cut_tile:\r
+ add r4, r4, #7 @ 0-6\r
+ mov r4, r4, lsl #2\r
+ mov r12,#0xf<<28\r
+ mov r12,r12,asr r4\r
+ mov r2, r2, ror #16\r
+ tst r5, #0x0800 @ flipped?\r
+ mvnne r12,r12\r
+ and r2, r2, r12\r
+ mov r2, r2, ror #16\r
+ mov r12,#0xf\r
+ tst r8, #1\r
+ bne .dtfc_shadow\r
+ tst r2, r2\r
+ beq .dtfc_loop\r
+ tst r5, #0x0800\r
+ beq .dtfc_TileNorm\r
+ b .dtfc_TileFlip\r
+\r
@ check if we have detected layer covered with hi-prio tiles:\r
.dtfc_check_rendflags:\r
ldr r1, =rendstatus\r
ldr r2, [r1]\r
tst r2, #0xc0\r
beq .dtfc_loop\r
- mov r8, #0 @ sh/hi mode off\r
+ bic r8, r8, #1 @ sh/hi mode off\r
tst r2, #0x80\r
bne .dtfc_loop @ already processed\r
orr r2, r2, #0x80\r
beq .dsfc_SingleColor @ tileline singlecolor \r
\r
tst r9, #0x10000\r
- beq .dsfc_TileNorm\r
+ bne .dsfc_TileFlip\r
\r
@ TileFlip (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
- TileFlip r12\r
- b .dsfc_inloop\r
-\r
.dsfc_TileNorm:\r
TileNorm r12\r
b .dsfc_inloop\r
\r
+.dsfc_TileFlip:\r
+ TileFlip r12\r
+ b .dsfc_inloop\r
+\r
.dsfc_SingleColor:\r
tst r0, #1 @ not aligned?\r
and r4, r2, #0xf\r
beq .dsfc_singlec_sh\r
\r
tst r9, #0x10000\r
- beq .dsfc_TileNorm_sh\r
+ bne .dsfc_TileFlip_sh\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
- TileFlipSh\r
- b .dsfc_inloop\r
-\r
.dsfc_TileNorm_sh:\r
TileNormSh\r
b .dsfc_inloop\r
\r
+.dsfc_TileFlip_sh:\r
+ TileFlipSh\r
+ b .dsfc_inloop\r
+\r
.dsfc_singlec_sh:\r
cmp r2, #0xe0000000\r
bcc .dsfc_SingleColor @ normal singlecolor tileline (carry inverted in ARM)\r
beq .dspr_SingleColor @ tileline singlecolor \r
\r
tst r9, #0x0800\r
- beq .dspr_TileNorm\r
+ bne .dspr_TileFlip\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
- TileFlip r12\r
- b .dspr_loop\r
-\r
@ scratch: r4, r7\r
.dspr_TileNorm:\r
TileNorm r12\r
b .dspr_loop\r
\r
+.dspr_TileFlip:\r
+ TileFlip r12\r
+ b .dspr_loop\r
+\r
.dspr_SingleColor:\r
and r4, r2, #0xf\r
orr r4, r3, r4\r
beq .dspr_singlec_sh\r
\r
tst r9, #0x0800\r
- beq .dspr_TileNorm_sh\r
+ bne .dspr_TileFlip_sh\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
- TileFlipSh\r
- b .dspr_loop\r
-\r
.dspr_TileNorm_sh:\r
TileNormSh\r
b .dspr_loop\r
\r
+.dspr_TileFlip_sh:\r
+ TileFlipSh\r
+ b .dspr_loop\r
+\r
.dspr_singlec_sh:\r
cmp r2, #0xe0000000\r
bcc .dspr_SingleColor @ normal tileline\r
beq .dw_SingleColor @ tileline singlecolor \r
\r
tst r9, #0x0800\r
- beq .dw_TileNorm\r
+ bne .dw_TileFlip\r
\r
@ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern\r
- TileFlip r0\r
- b .dwloop\r
-\r
.dw_TileNorm:\r
TileNorm r0\r
b .dwloop\r
\r
+.dw_TileFlip:\r
+ TileFlip r0\r
+ b .dwloop\r
+\r
.dw_SingleColor:\r
and r4, r0, r2 @ #0x0000000f\r
orr r4, r3, r4\r