overdraw eliminated in AS mode
[picodrive.git] / Pico / Draw.s
index f310253..c620c74 100644 (file)
 .extern Pico\r
 .extern PicoOpt\r
 .extern HighCol\r
-.extern Scanline\r
+.extern DrawScanline\r
 .extern HighSprZ\r
 .extern rendstatus\r
+.extern HighPreSpr\r
 .extern DrawLineDest\r
 .extern DrawStripInterlace\r
 .extern HighCacheS_ptr\r
 \r
+.equ PDRAW_SPRITES_MOVED, (1<<0)\r
+.equ PDRAW_WND_DIFF_PRIO, (1<<1)\r
+.equ PDRAW_ACC_SPRITES,   (1<<2)\r
+.equ PDRAW_DIRTY_SPRITES, (1<<4)\r
+.equ PDRAW_PLANE_HI_PRIO, (1<<6)\r
+.equ PDRAW_SHHI_DONE,     (1<<7)\r
+.equ MAX_LINE_SPRITES,    30\r
 \r
 @ helper\r
 .macro TilePixel pat lsrr offs\r
@@ -316,7 +324,7 @@ DrawLayer:
     ldreqb  r12, [r11, #2]\r
     ldrneb  r12, [r11, #4]\r
 \r
-    ldr     r2, =Scanline         @ trying to make good use of pipeline here\r
+    ldr     r2, =DrawScanline     @ trying to make good use of pipeline here\r
     ldr     lr, =(Pico+0x10000)   @ lr=Pico.vram\r
 \r
     moveq   r12, r12, lsl #10\r
@@ -330,7 +338,7 @@ DrawLayer:
     mov     r4, r8, lsr #8        @ pvid->reg[13]\r
     mov     r4, r4, lsl #10       @ htab=pvid->reg[13]<<9; (halfwords)\r
     tst     r7, #2\r
-    addne   r4, r4, r2, lsl #2    @ htab+=Scanline<<1; // Offset by line\r
+    addne   r4, r4, r2, lsl #2    @ htab+=DrawScanline<<1; // Offset by line\r
     tst     r7, #1\r
     biceq   r4, r4, #0x1f         @ htab&=~0xf; // Offset by tile\r
     add     r4, r4, r0, lsl #1    @ htab+=plane\r
@@ -499,7 +507,7 @@ DrawLayer:
     mov     r0, #0\r
     ldreq   r2, [r1]\r
     str     r0, [r6]    @ terminate the cache list\r
-    orreq   r2, r2, #0x40 @ had a layer with all hi-prio tiles\r
+    orreq   r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles\r
     streq   r2, [r1]\r
 \r
     ldmfd   sp!, {r4-r11,lr}\r
@@ -513,7 +521,7 @@ DrawLayer:
     bic     r8, r8, #0x3fc00000\r
     orr     r8, r8, r5, lsl #25   @ r8=(xmask[31:25]|had_output[24]|tilex[21:0])\r
 \r
-    ldr     r4, =Scanline\r
+    ldr     r4, =DrawScanline\r
     orr     r5, r1, r10, lsl #24\r
     ldr     r4, [r4]\r
     sub     r1, r3, #1\r
@@ -674,7 +682,7 @@ DrawLayer:
     mov     r0, #0\r
     ldreq   r2, [r1]\r
     str     r0, [r6]    @ terminate the cache list\r
-    orreq   r2, r2, #0x40 @ had a layer with all hi-prio tiles\r
+    orreq   r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles\r
     streq   r2, [r1]\r
 \r
     ldmfd   sp!, {r4-r11,lr}\r
@@ -690,7 +698,7 @@ DrawLayer:
     movne   r7, r7, lsl #5\r
 \r
     @ Find the line in the name table\r
-    add     r2, r7, r2, lsl #22    @ r2=(vscroll+(Scanline<<1))<<21 (11 bits);\r
+    add     r2, r7, r2, lsl #22    @ r2=(vscroll+(DrawScanline<<1))<<21 (11 bits);\r
     orr     r1, r1, #0x80000000\r
     and     r2, r2, r1, ror #10    @ &((ymask<<1)|1)<<21;\r
     mov     r2, r2, lsr #21\r
@@ -908,12 +916,12 @@ DrawTilesFromCache:
 .dtfc_check_rendflags:\r
     ldr     r1, =rendstatus\r
     ldr     r2, [r1]\r
-    tst     r2, #0xc0\r
+    tst     r2, #(PDRAW_PLANE_HI_PRIO|PDRAW_SHHI_DONE)\r
     beq     .dtfc_loop\r
     bic     r8, r8, #1      @ sh/hi mode off\r
-    tst     r2, #0x80\r
+    tst     r2, #PDRAW_SHHI_DONE\r
     bne     .dtfc_loop      @ already processed\r
-    orr     r2, r2, #0x80\r
+    orr     r2, r2, #PDRAW_SHHI_DONE\r
     str     r2, [r1]\r
 \r
     add     r1, r11,#8\r
@@ -939,12 +947,26 @@ DrawTilesFromCache:
 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
 \r
 \r
-.global DrawSpritesFromCache @ int *hc, int maxwidth, int prio, int sh\r
+.global DrawSpritesSHi @ int prio_unused, int sh\r
+\r
+DrawSpritesSHi:\r
+    ldr     r3, =DrawScanline\r
+    ldr     r2, =HighLnSpr\r
+    ldr     r12,[r3]\r
+    mov     r3, #(MAX_LINE_SPRITES+2)\r
+    mla     r2, r12, r3, r2\r
+    ldr     r3, [r2]\r
+    ands    r3, r3, #0x7f\r
+    bxeq    lr\r
 \r
-DrawSpritesFromCache:\r
     stmfd   sp!, {r4-r11,lr}\r
+    mov     r12,#0xff\r
+    strb    r12,[r2,#1]     @ set end marker\r
+    add     r10,r2, #2\r
+    add     r10,r10,r3      @ r10=HighLnSpr end\r
+\r
+    str     r1, [sp, #-4]   @ no calls after this point\r
 \r
-    @ cache some stuff to avoid mem access\r
 .if OVERRIDE_HIGHCOL\r
     ldr     r11,=HighCol\r
     mov     r12,#0xf\r
@@ -954,150 +976,231 @@ DrawSpritesFromCache:
     mov     r12,#0xf\r
 .endif\r
     ldr     lr, =(Pico+0x10000) @ lr=Pico.vram\r
-    mov     r6, r3, lsl #31\r
-    orr     r6, r6, #1<<30\r
 \r
-    mov     r10, r0\r
 \r
-.dsfc_loop:\r
-    ldr     r9, [r10], #4    @ read code\r
-    bic     r6, r6, #7       @ using pipeline\r
-    tst     r9, r9\r
-    ldmeqfd sp!, {r4-r11,pc}\r
+DrawSpriteSHi:\r
+    @ draw next sprite\r
+    ldrb    r0, [r10,#-1]!\r
+    ldr     r1, =HighPreSpr\r
+    ldr     r8, [sp, #-4]\r
+    cmp     r0, #0xff\r
+    ldmeqfd sp!, {r4-r11,pc} @ end of list\r
+    and     r0, r0, #0x7f\r
+    add     r0, r1, r0, lsl #3\r
 \r
-    mov     r4, r9, lsl #28\r
-    orr     r6, r6, r4, lsr #30\r
-    add     r6, r6, #1       @ r6=s1cc???? ... ?????www (s=shadow/hilight, cc=pal, w=width)\r
+    ldr     r9, [r0, #4]    @ sprite[1]\r
+    mov     r2, r9, asr #16 @ r2=sx\r
 \r
-    and     r5, r9, #3\r
-    add     r5, r5, #1       @ r5=delta\r
-    tst     r9, #0x10000\r
-    rsbne   r5, r5, #0       @ Flip X\r
-    mov     r5, r5, lsl #4\r
+    mov     r9, r9, lsl #16\r
+    mov     r3, r9, lsr #31 @ priority\r
+    mov     r9, r9, lsr #16\r
+    orr     r9, r9, r8, lsl #31 @ r9=code|sh[31]\r
+    and     r4, r9, #0x6000\r
+    orr     r9, r9, r4, lsl #16\r
+    orr     r9, r9, #0x10000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)\r
+    cmp     r12,r9, lsr #28 @ sh/hi with pal3?\r
+    cmpne   r3, #1          @ if not, is hi prio\r
+    bne     DrawSpriteSHi   @ non-operator low sprite, already drawn\r
 \r
-    mov     r2, r9, lsr #17\r
-    mov     r8, r2, lsl #1   @ tile=((unsigned int)code>>17)<<1;\r
+    ldr     r3, [r0]        @ sprite[0]\r
+    ldr     r7, =DrawScanline\r
+    mov     r6, r3, lsr #28\r
+    sub     r6, r6, #1      @ r6=width-1 (inc later)\r
+    mov     r5, r3, lsr #24\r
+    and     r5, r5, #7      @ r5=height\r
 \r
-    and     r3, r9, #0x30    @ r3=pal=(code&0x30);\r
+    mov     r0, r3, lsl #16 @ r4=sy<<16 (tmp)\r
 \r
-    bic     r6, r6, #3<<28\r
-    orr     r6, r6, r3, lsl #24\r
+    ldr     r7, [r7]\r
+    sub     r7, r7, r0, asr #16 @ r7=row=DrawScanline-sy\r
 \r
-    mov     r0, r9, lsl #16\r
-    mov     r0, r0, asr #22  @ sx=(code<<16)>>22\r
-    adds    r0, r0, #0       @ set ZV\r
-    b       .dsfc_inloop_enter\r
+    tst     r9, #0x1000\r
+    movne   r0, r5, lsl #3\r
+    subne   r0, r0, #1\r
+    subne   r7, r0, r7      @ if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
 \r
-@ scratch: r4, r7\r
-.dsfc_inloop:\r
-    sub     r6, r6, #1\r
-    tst     r6, #7\r
-    beq     .dsfc_loop\r
-    adds    r0, r0, #8\r
-    add     r8, r8, r5\r
-\r
-.dsfc_inloop_enter:\r
-    ble     .dsfc_inloop\r
+    add     r8, r9, r7, lsr #3 @ tile+=row>>3; // Tile number increases going down\r
+    tst     r9, #0x0800\r
+    mlane   r8, r5, r6, r8  @ if (code&0x0800) { tile+=delta*(width-1);\r
+    rsbne   r5, r5, #0      @ delta=-delta; } // r5=delta now\r
+\r
+    mov     r8, r8, lsl #21\r
+    mov     r8, r8, lsr #17\r
+    and     r7, r7, #7\r
+    add     r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address\r
+\r
+    mov     r5, r5, lsl #4     @ delta<<=4; // Delta of address\r
+\r
+    orrs    r3, r9, r9, lsl #4\r
+    mov     r3, r4, lsr #9     @ r3=pal=((code>>9)&0x30);\r
+\r
+    add     r6, r6, #1         @ inc now\r
+    adds    r0, r2, #0         @ mov sx to r0 and set ZV flags\r
+    b       .dsprShi_loop_enter\r
+\r
+.dsprShi_loop:\r
+    subs    r6, r6, #1         @ width--\r
+    beq     DrawSpriteSHi\r
+    adds    r0, r0, #8         @ sx+=8\r
+    add     r8, r8, r5         @ tile+=delta\r
+\r
+.dsprShi_loop_enter:\r
+    ble     .dsprShi_loop     @ sx <= 0\r
     cmp     r0, #328\r
-    bge     .dsfc_loop\r
+    bge     DrawSpriteSHi\r
 \r
     mov     r8, r8, lsl #17\r
-    mov     r8, r8, lsr #17   @ tile&=0x7fff; // Clip tile address\r
+    mov     r8, r8, lsr #17    @ tile&=0x7fff; // Clip tile address\r
 \r
-    ldr     r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(Pico.vram+tile); // Get 8 pixels\r
-    add     r1, r11, r0       @ r1=pdest\r
+    ldr     r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
+    add     r1, r11, r0        @ r1=pdest\r
     tst     r2, r2\r
-    beq     .dsfc_inloop\r
+    beq     .dsprShi_loop\r
 \r
-    cmp     r12, r6, lsr #28\r
-    beq     .dsfc_shadow\r
+    cmp     r12, r9, lsr #28\r
+    beq     .dsprShi_shadow\r
 \r
     cmp     r2, r2, ror #4\r
-    beq     .dsfc_SingleColor @ tileline singlecolor \r
+    beq     .dsprShi_SingleColor @ tileline singlecolor \r
 \r
-    tst     r9, #0x10000\r
-    bne     .dsfc_TileFlip\r
+    tst     r9, #0x0800\r
+    bne     .dsprShi_TileFlip\r
 \r
-    @ TileFlip (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
-.dsfc_TileNorm:\r
+    @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
+@ scratch: r4, r7\r
+.dsprShi_TileNorm:\r
     TileNorm r12\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_TileFlip:\r
+.dsprShi_TileFlip:\r
     TileFlip r12\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_SingleColor:\r
-    tst     r0, #1              @ not aligned?\r
+.dsprShi_SingleColor:\r
     and     r4, r2, #0xf\r
     orr     r4, r3, r4\r
     orr     r4, r4, r4, lsl #8\r
+    tst     r0, #1              @ not aligned?\r
     strneb  r4, [r1], #1\r
     streqh  r4, [r1], #2\r
     strh    r4, [r1], #2\r
     strh    r4, [r1], #2\r
     strh    r4, [r1], #2\r
     strneb  r4, [r1], #1\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_shadow:\r
-    tst     r9, #0x80000000\r
-    beq     .dsfc_shadow_lowpri\r
+.dsprShi_shadow:\r
+    tst     r9, #0x8000\r
+    beq     .dsprShi_shadow_lowpri\r
 \r
     cmp     r2, r2, ror #4\r
-    beq     .dsfc_singlec_sh\r
+    beq     .dsprShi_singlec_sh\r
 \r
-    tst     r9, #0x10000\r
-    bne     .dsfc_TileFlip_sh\r
+    tst     r9, #0x0800\r
+    bne     .dsprShi_TileFlip_sh\r
 \r
     @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern\r
-.dsfc_TileNorm_sh:\r
+.dsprShi_TileNorm_sh:\r
     TileNormSh\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_TileFlip_sh:\r
+.dsprShi_TileFlip_sh:\r
     TileFlipSh\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_singlec_sh:\r
+.dsprShi_singlec_sh:\r
     cmp     r2, #0xe0000000\r
-    bcc     .dsfc_SingleColor   @ normal singlecolor tileline (carry inverted in ARM)\r
+    bcc     .dsprShi_SingleColor   @ normal singlecolor tileline (carry inverted in ARM)\r
     tst     r2, #0x10000000\r
-    bne     .dsfc_sh_sh\r
+    bne     .dsprShi_sh_sh\r
     TileSingleHi\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_sh_sh:\r
+.dsprShi_sh_sh:\r
     TileSingleSh\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_shadow_lowpri:\r
-    tst     r9, #0x10000\r
-    bne     .dsfc_TileFlip_sh_lp\r
+.dsprShi_shadow_lowpri:\r
+    tst     r9, #0x800\r
+    bne     .dsprShi_TileFlip_sh_lp\r
 \r
-.dsfc_TileNorm_sh_lp:\r
+.dsprShi_TileNorm_sh_lp:\r
     TileNormSh_onlyop_lp\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
-.dsfc_TileFlip_sh_lp:\r
+.dsprShi_TileFlip_sh_lp:\r
     TileFlipSh_onlyop_lp\r
-    b       .dsfc_inloop\r
+    b       .dsprShi_loop\r
 \r
 .pool\r
 \r
 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
 \r
-@ + 0  :    hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size\r
-@ + 4  :    xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
+.global DrawAllSprites @ int prio, int sh\r
+\r
+DrawAllSprites:\r
+    ldr     r3, =rendstatus\r
+    orr     r1, r1, r0, lsl #1\r
+    ldr     r12,[r3]\r
+    tst     r12,#(PDRAW_ACC_SPRITES|PDRAW_SPRITES_MOVED)\r
+    beq     das_no_prep\r
+    stmfd   sp!, {r1,lr}\r
+    and     r0, r12,#PDRAW_DIRTY_SPRITES\r
+    bic     r12,r12,#(PDRAW_ACC_SPRITES|PDRAW_SPRITES_MOVED)\r
+    str     r12,[r3]\r
+    bl      PrepareSprites\r
+    ldmfd   sp!, {r1,lr}\r
+\r
+das_no_prep:\r
+    ldr     r3, =DrawScanline\r
+    ldr     r2, =HighLnSpr\r
+    ldr     r12,[r3]\r
+    mov     r3, #(MAX_LINE_SPRITES+2)\r
+    mla     r2, r12, r3, r2\r
+    ldr     r3, [r2]\r
+    ands    r3, r3, #0x7f\r
+    bxeq    lr\r
+\r
+    @ time to do some real work\r
+    stmfd   sp!, {r4-r11,lr}\r
+    mov     r12,#0xff\r
+    strb    r12,[r2,#1]     @ set end marker\r
+    add     r10,r2, #2\r
+    add     r10,r10,r3      @ r10=HighLnSpr end\r
+\r
+    str     r1, [sp, #-4]   @ no calls after this point\r
+\r
+.if OVERRIDE_HIGHCOL\r
+    ldr     r11,=HighCol\r
+    mov     r12,#0xf\r
+    ldr     r11,[r11]\r
+.else\r
+    ldr     r11,=HighCol\r
+    mov     r12,#0xf\r
+.endif\r
+    ldr     lr, =(Pico+0x10000) @ lr=Pico.vram\r
 \r
-.global DrawSprite @ unsigned int *sprite, int sh, int acc_sprites\r
+@ + 0  :    hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: horiz. size\r
+@ + 4  :    xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
 \r
-DrawSprite:\r
-    stmfd   sp!, {r4-r9,r11,lr}\r
+DrawSprite: @ was: unsigned int *sprite, int sh, int acc_sprites\r
+    @ draw next sprite\r
+    ldrb    r0, [r10,#-1]!\r
+    ldr     r1, =HighPreSpr\r
+    ldr     r8, [sp, #-4]\r
+    mov     r2, r0, lsr #7\r
+    cmp     r0, #0xff\r
+    ldmeqfd sp!, {r4-r11,pc} @ end of list\r
+    cmp     r2, r8, lsr #1\r
+    bne     DrawSprite      @ wrong priority\r
+    and     r0, r0, #0x7f\r
+    add     r0, r1, r0, lsl #3\r
+\r
+@    stmfd   sp!, {r4-r9,r11,lr}\r
+@    orr     r8, r2, r1, lsl #4\r
 \r
-    orr     r8, r2, r1, lsl #4\r
     ldr     r3, [r0]        @ sprite[0]\r
-    ldr     r7, =Scanline\r
+    ldr     r7, =DrawScanline\r
     mov     r6, r3, lsr #28\r
     sub     r6, r6, #1      @ r6=width-1 (inc later)\r
     mov     r5, r3, lsr #24\r
@@ -1107,12 +1210,12 @@ DrawSprite:
 \r
     ldr     r7, [r7]\r
     ldr     r9, [r0, #4]\r
-    sub     r7, r7, r4, asr #16 @ r7=row=Scanline-sy\r
+    sub     r7, r7, r4, asr #16 @ r7=row=DrawScanline-sy\r
 \r
     mov     r2, r9, asr #16 @ r2=sx\r
     mov     r9, r9, lsl #16\r
     mov     r9, r9, lsr #16\r
-    orr     r9, r9, r8, lsl #27 @ r9=code|sh[31]|as[27]\r
+    orr     r9, r9, r8, lsl #31 @ r9=code|sh[31]\r
 \r
     tst     r9, #0x1000\r
     movne   r4, r5, lsl #3\r
@@ -1129,33 +1232,15 @@ DrawSprite:
     and     r7, r7, #7\r
     add     r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address\r
 \r
-    tst     r9, #0x8000\r
-    tsteq   r9, #(1<<27)\r
-    bne     .dspr_cache       @ if(code&0x8000) || as\r
-    tst     r6, #0x4000\r
-    tstne   r6, #0x2000\r
-    tstne   r9, #(1<<31)\r
-    bne     .dspr_cache       @ (sh && pal == 0x30)\r
-\r
 .dspr_continue:\r
     @ cache some stuff to avoid mem access\r
-.if OVERRIDE_HIGHCOL\r
-    ldr     r11,=HighCol\r
-    mov     r12,#0xf\r
-    ldr     r11,[r11]\r
-.else\r
-    ldr     r11,=HighCol\r
-    mov     r12,#0xf\r
-.endif\r
-    ldr     lr, =(Pico+0x10000) @ lr=Pico.vram\r
-\r
     mov     r5, r5, lsl #4     @ delta<<=4; // Delta of address\r
     and     r4, r9, #0x6000\r
     orr     r9, r9, r4, lsl #16\r
-    orrs    r9, r9, #0x10000000 @ r9=scc1 a??? ... <code> (s=shadow/hilight, cc=pal, a=acc_spr)\r
+    orrs    r9, r9, #0x10000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)\r
 \r
     mov     r3, r4, lsr #9     @ r3=pal=((code>>9)&0x30);\r
-    orrmi   r3, r3, #0x40      @ shadow by default\r
+    orrmi   r3, r3, #0x40      @ for sh/hi\r
 \r
     add     r6, r6, #1         @ inc now\r
     adds    r0, r2, #0         @ mov sx to r0 and set ZV flags\r
@@ -1163,14 +1248,14 @@ DrawSprite:
 \r
 .dspr_loop:\r
     subs    r6, r6, #1         @ width--\r
-    ldmeqfd sp!, {r4-r9,r11,pc}@ return\r
+    beq     DrawSprite\r
     adds    r0, r0, #8         @ sx+=8\r
     add     r8, r8, r5         @ tile+=delta\r
 \r
 .dspr_loop_enter:\r
     ble     .dspr_loop         @ sx <= 0\r
     cmp     r0, #328\r
-    ldmgefd sp!, {r4-r9,r11,pc}@ return\r
+    bge     DrawSprite\r
 \r
     mov     r8, r8, lsl #17\r
     mov     r8, r8, lsr #17    @ tile&=0x7fff; // Clip tile address\r
@@ -1233,31 +1318,6 @@ DrawSprite:
     b       .dspr_loop\r
 \r
 \r
-.dspr_cache:\r
-    @ *HighCacheS_ptr++ = ((code&0x8000)<<16)|(tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|pal|((sprite[0]>>16)&0xf);\r
-    ldr     r1, =HighCacheS_ptr\r
-    mov     r4, r8, lsl #16     @ tile\r
-    tst     r9, #0x0800\r
-    orrne   r4, r4, #0x10000    @ code&0x0800\r
-    mov     r0, r2, lsl #22\r
-    orr     r4, r4, r0, lsr #16 @ (sx<<6)&0x0000ffc0\r
-    and     r0, r9, #0x6000\r
-    orr     r4, r4, r0, lsr #9  @ (code>>9)&0x30\r
-    mov     r3, r3, lsl #12\r
-    orr     r4, r4, r3, lsr #28 @ (sprite[0]>>24)&0xf\r
-\r
-    ldr     r0, [r1]\r
-    tst     r9, #0x8000\r
-    orrne   r4, r4, #0x80000000 @ prio\r
-\r
-    str     r4, [r0], #4\r
-    str     r0, [r1]\r
-\r
-    and     r0, r9, #(1<<27)    @ as\r
-    teqne   r0,     #(1<<27)    @ (code&0x8000) && !as\r
-    ldmnefd sp!, {r4-r9,r11,pc}\r
-    b       .dspr_continue      @ draw anyway if accurate sprites enabled\r
-\r
 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
 \r
 .global DrawWindow @ int tstart, int tend, int prio, int sh // int *hcache\r
@@ -1266,7 +1326,7 @@ DrawWindow:
     stmfd   sp!, {r4-r11,lr}\r
 \r
     ldr     r11, =(Pico+0x22228)  @ Pico.video\r
-    ldr     r10, =Scanline\r
+    ldr     r10, =DrawScanline\r
     ldrb    r12, [r11, #3]        @ pvid->reg[3]\r
 \r
     ldr     r10, [r10]\r
@@ -1291,11 +1351,12 @@ DrawWindow:
     @ fetch the first code now\r
     ldrh    r7, [lr, r12]\r
 \r
-    ands    r6, r6, #2            @ we care about bit 1 only\r
+    ands    r6, r6, #PDRAW_WND_DIFF_PRIO\r
     orr     r6, r6, r2\r
 \r
-    teqne   r2, r7, lsr #15       @ do prio bits differ?\r
-    ldmnefd sp!, {r4-r11,pc}      @ yes, assume that whole window uses same priority\r
+    eoreq   r8, r2, r7, lsr #15   @ do prio bits differ?\r
+    cmpeq   r8, #1\r
+    ldmeqfd sp!, {r4-r11,pc}      @ yes, assume that whole window uses same priority\r
 \r
     orr     r6, r6, r3, lsl #8    @ shadow mode\r
 \r
@@ -1507,7 +1568,7 @@ FinalizeLineBGR444:
     eors    r6, r6, #1          @ sh is 0\r
     ldr     r12,[r12]\r
     mov     lr, #0xff\r
-    tstne   r12,#(1<<2)         @ and PDRAW_ACC_SPRITES\r
+    tstne   r12,#PDRAW_ACC_SPRITES\r
 \r
 .if OVERRIDE_HIGHCOL\r
     ldr     r1, =HighCol\r
@@ -1676,7 +1737,7 @@ FinalizeLineRGB555:
     eors    r6, r6, #1          @ sh is 0\r
     ldr     r12,[r12]\r
     mov     lr, #0xff\r
-    tstne   r12,#(1<<2)         @ and PDRAW_ACC_SPRITES\r
+    tstne   r12,#PDRAW_ACC_SPRITES\r
     movne   lr, #0x3f\r
 \r
 .if OVERRIDE_HIGHCOL\r