From cf07a88d6eaa0e7719c498ef838ef175512a2bc4 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 8 Oct 2017 22:33:04 +0300 Subject: [PATCH] fix cell scroll drawing --- pico/draw.c | 6 +++++- pico/draw2_arm.S | 14 +++++++++++--- pico/draw_arm.S | 31 ++++++++++++++++++++++--------- pico/pico_int.h | 7 +++---- pico/pico_int_o32.h | 2 ++ tools/mkoffsets.c | 5 +++++ 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/pico/draw.c b/pico/draw.c index 6408f20..bb051b6 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -261,7 +261,11 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) // Draw tiles across screen: tilex=(-ts->hscroll)>>3; dx=((ts->hscroll-1)&7)+1; - if(dx != 8) cell--; // have hscroll, start with negative cell + if (ts->hscroll & 0x0f) { + int adj = ((ts->hscroll ^ dx) >> 3) & 1; + cell -= adj + 1; + ts->cells -= adj; + } cell+=cellskip; tilex+=cellskip; dx+=cellskip<<3; diff --git a/pico/draw2_arm.S b/pico/draw2_arm.S index 1575653..6b110b3 100644 --- a/pico/draw2_arm.S +++ b/pico/draw2_arm.S @@ -73,8 +73,17 @@ BackFillFull: @ -------- some macros -------- +@ helpers +.macro add_c24 d s c + add \d, \s, #(\c & 0x00ff00) +.if \c & 0x0000ff + add \d, \d, #(\c & 0x0000ff) +.endif +.if \c & 0xff0000 + add \d, \d, #(\c & 0xff0000) +.endif +.endm -@ helper @ TileLineSinglecol (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: pixels8_old .macro TileLineSinglecol notsinglecol=0 and r2, r2, #0xf @ #0x0000000f @@ -411,8 +420,7 @@ DrawLayerFull: mla r11, r4, r7, r11 @ scrpos+=8*328*(planestart-START_ROW); @ Get vertical scroll value: - add r7, r10, #0x012000 - add r7, r7, #0x000180 @ r7=Pico.vsram (Pico+0x22180) + add_c24 r7, r10, (OFS_PMEM_vsram-OFS_PMEM_vram) ldr r7, [r7] tst r0, r0 moveq r7, r7, lsl #22 diff --git a/pico/draw_arm.S b/pico/draw_arm.S index d53e04b..29af1c1 100644 --- a/pico/draw_arm.S +++ b/pico/draw_arm.S @@ -19,7 +19,17 @@ .equ PDRAW_PLANE_HI_PRIO, (1<<6) .equ PDRAW_SHHI_DONE, (1<<7) -@ helper +@ helpers +.macro add_c24 d s c + add \d, \s, #(\c & 0x00ff00) +.if \c & 0x0000ff + add \d, \d, #(\c & 0x0000ff) +.endif +.if \c & 0xff0000 + add \d, \d, #(\c & 0xff0000) +.endif +.endm + .macro TilePixel pat lsrr offs .if !\lsrr ands r4, \pat, r2 @@ -344,8 +354,7 @@ DrawLayer: bne .DrawStrip_vsscroll @ Get vertical scroll value: - add r7, lr, #0x012000 - add r7, r7, #0x000180 @ r7=PicoMem.vsram (PicoMem+0x22180) + add_c24 r7, lr, (OFS_PMEM_vsram-OFS_PMEM_vram) ldr r7, [r7] tst r8, #2 @@ -522,17 +531,22 @@ DrawLayer: add r7, r1, #1 @ r7=dx=((ts->hscroll-1)&7)+1 mov r10,r9, lsl #16 + orr r10,r10, #0xff000000 @ will be adjusted on entering loop tst r0, #1 orrne r10,r10, #0x8000 + tst r3, #0x0f @ hscroll & 0x0f? + beq 0f + eor r3, r3, r7 + sub r10,r10, #1<<24 @ cell-- // start from negative for hscroll + tst r3, #0x08 + subne r10,r10, #1<<16 @ cells-- + subne r10,r10, #1<<24 @ cell-- // even more negative +0: tst r9, #1<<31 mov r3, #0 - orr r10,r10, #0xff000000 @ will be adjusted on entering loop orrne r10,r10, #1<<23 @ r10=(cell[31:24]|sh[23]|hi_not_empty[22]|cells_max[21:16]|plane[15]|ty[14:0]) movne r3, #0x40 @ default to shadowed pal on sh mode - cmp r7, #8 - subne r10,r10, #0x01000000 @ have hscroll, start with negative cell - and r9, r9, #0xff00 add r8, r8, r9, lsr #8 @ tilex+=cellskip add r7, r7, r9, lsr #5 @ dx+=cellskip<<3; @@ -556,8 +570,7 @@ DrawLayer: ble .dsloop_vs_exit @ calc offset and read tileline code to r7, also calc ty - add r7, lr, #0x012000 - add r7, r7, #0x000180 @ r7=PicoMem.vsram (PicoMem+0x22180) + add_c24 r7, lr, (OFS_PMEM_vsram-OFS_PMEM_vram) add r7, r7, r10,asr #23 @ vsram + ((cell&~1)<<1) bic r7, r7, #3 tst r10,#0x8000 @ plane1? diff --git a/pico/pico_int.h b/pico/pico_int.h index 848da5d..369bb5d 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -356,7 +356,6 @@ struct PicoEState unsigned short HighPal[0x100]; }; -// some assembly stuff still depends on these, do not touch! struct PicoMem { unsigned char ram[0x10000]; // 0x00000 scratch ram @@ -366,9 +365,9 @@ struct PicoMem }; unsigned char zram[0x2000]; // 0x20000 Z80 ram unsigned char ioports[0x10]; // XXX: fix asm and mv - unsigned char pad[0xf0]; // unused - unsigned short cram[0x40]; // 0x22100 - unsigned short vsram[0x40]; // 0x22180 + unsigned short cram[0x40]; // 0x22010 + unsigned char pad[0x70]; // 0x22050 DrawStripVSRam reads 0 from here + unsigned short vsram[0x40]; // 0x22100 }; // sram diff --git a/pico/pico_int_o32.h b/pico/pico_int_o32.h index 720a5ee..ca3004f 100644 --- a/pico/pico_int_o32.h +++ b/pico/pico_int_o32.h @@ -24,3 +24,5 @@ #define OFS_EST_PicoOpt 0x20 #define OFS_EST_Draw2FB 0x24 #define OFS_EST_HighPal 0x28 +#define OFS_PMEM_vram 0x10000 +#define OFS_PMEM_vsram 0x22100 diff --git a/tools/mkoffsets.c b/tools/mkoffsets.c index b371cf4..7e57383 100644 --- a/tools/mkoffsets.c +++ b/tools/mkoffsets.c @@ -18,6 +18,9 @@ #define DUMP_EST(f, field) \ DUMP(f, "OFS_EST_", struct PicoEState, field) +#define DUMP_PMEM(f, field) \ + DUMP(f, "OFS_PMEM_", struct PicoMem, field) + extern struct Pico p; int main(int argc, char *argv[]) @@ -58,6 +61,8 @@ int main(int argc, char *argv[]) DUMP_EST(f, PicoOpt); DUMP_EST(f, Draw2FB); DUMP_EST(f, HighPal); + DUMP_PMEM(f, vram); + DUMP_PMEM(f, vsram); fclose(f); return 0; -- 2.39.2