]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
imported winuaesrc1400b6.zip
authorToni Wilen <twilen@winuae.net>
Sun, 11 Feb 2007 13:25:28 +0000 (15:25 +0200)
committerToni Wilen <twilen@winuae.net>
Mon, 22 Feb 2010 19:31:41 +0000 (21:31 +0200)
24 files changed:
cfgfile.c
cia.c
compemu_fpp.c
compemu_raw_x86.c
compemu_support.c
custom.c
disk.c
expansion.c
filesys.c
fpp.c
include/compemu.h
include/serial.h
memory.c
newcpu.c
od-win32/dxwrap.c
od-win32/mman.c
od-win32/parser.c
od-win32/picasso96_win.c
od-win32/picasso96_win.h
od-win32/win32.c
od-win32/win32.h
od-win32/win32gfx.c
od-win32/winuaechangelog.txt
uaeserial.c

index a7120a0f76259ad4a26cf81d4f700a896a5d828e..28641b43af7e40d9422d87850aa10af09d78d2c3 100755 (executable)
--- a/cfgfile.c
+++ b/cfgfile.c
@@ -146,7 +146,8 @@ static const char *cartsmode[] = { "none", "hrtmon", 0 };
 static const char *idemode[] = { "none", "a600/a1200", "a4000", 0 };
 static const char *rtctype[] = { "none", "MSM6242B", "RP5C01A", 0 };
 static const char *ciaatodmode[] = { "vblank", "50hz", "60hz", 0 };
-static const char *cscompa[] = { "-", "Generic", "CDTV", "CD32", "A500", "A500+", "A600", "A1000", "A1200", "A2000", "A4000" };
+static const char *ksmirrortype[] = { "none", "e0", "a8+e0", 0 };
+static const char *cscompa[] = { "-", "Generic", "CDTV", "CD32", "A500", "A500+", "A600", "A1000", "A1200", "A2000", "A4000", 0 };
 
 static const char *obsolete[] = {
     "accuracy", "gfx_opengl", "gfx_32bit_blits", "32bit_blits",
@@ -470,7 +471,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
     cfgfile_write (f, "ciaatod=%s\n", ciaatodmode[p->cs_ciaatod]);
     cfgfile_write (f, "rtc=%s\n", rtctype[p->cs_rtc]);
     //cfgfile_write (f, "chipset_rtc_adjust=%d\n", p->cs_rtc_adjust);
-    cfgfile_write (f, "ksmirror=%s\n", p->cs_ksmirror ? "true" : "false");
+    cfgfile_write (f, "ksmirror=%s\n", ksmirrortype[p->cs_ksmirror]);
     cfgfile_write (f, "cd32cd=%s\n", p->cs_cd32cd ? "true" : "false");
     cfgfile_write (f, "cd32c2p=%s\n", p->cs_cd32c2p ? "true" : "false");
     cfgfile_write (f, "cd32nvram=%s\n", p->cs_cd32nvram ? "true" : "false");
@@ -1104,7 +1105,6 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, char *option, char *valu
 
     if (cfgfile_yesno (option, value, "immediate_blits", &p->immediate_blits)
 
-       || cfgfile_yesno (option, value, "ksmirror", &p->cs_ksmirror)
        || cfgfile_yesno (option, value, "cd32cd", &p->cs_cd32cd)
        || cfgfile_yesno (option, value, "cd32c2p", &p->cs_cd32c2p)
        || cfgfile_yesno (option, value, "cd32nvram", &p->cs_cd32nvram)
@@ -1162,6 +1162,7 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, char *option, char *valu
     if (cfgfile_strval (option, value, "comp_trustbyte", &p->comptrustbyte, compmode, 0)
        || cfgfile_strval (option, value, "chipset_compatible", &p->cs_compatible, cscompa, 0)
        || cfgfile_strval (option, value, "rtc", &p->cs_rtc, rtctype, 0)
+       || cfgfile_strval (option, value, "ksmirror", &p->cs_ksmirror, ksmirrortype, 0)
        || cfgfile_strval (option, value, "ciaatod", &p->cs_ciaatod, ciaatodmode, 0)
        || cfgfile_strval (option, value, "ide", &p->cs_ide, idemode, 0)
        || cfgfile_strval (option, value, "comp_trustword", &p->comptrustword, compmode, 0)
@@ -2732,7 +2733,7 @@ static void buildin_default_prefs (struct uae_prefs *p)
     p->cs_cdtvcd = p->cs_cdtvram = p->cs_cdtvcard = 0;
     p->cs_ide = 0;
     p->cs_pcmcia = 0;
-    p->cs_ksmirror = 0;
+    p->cs_ksmirror = 1;
     p->cs_ciaatod = 0;
     p->cs_df0idhw = 1;
 
@@ -3099,7 +3100,7 @@ int build_in_chipset_prefs (struct uae_prefs *p)
     p->cs_agnusrev = -1;
     p->cs_mbdmac = -1;
     p->cs_pcmcia = 0;
-    p->cs_ksmirror = 0;
+    p->cs_ksmirror = 1;
     p->cs_ciaatod = 0;
     p->cs_df0idhw = 1;
 
@@ -3111,35 +3112,36 @@ int build_in_chipset_prefs (struct uae_prefs *p)
            p->cs_ide = -1;
            p->cs_mbdmac = 1;
            p->cs_ramseyrev = 0x0f;
-           p->cs_ksmirror = 1;
        break;
        case  2: // CDTV
            p->cs_rtc = 1;
            p->cs_cdtvcd = p->cs_cdtvram = 1;
            p->cs_df0idhw = 0;
+           p->cs_ksmirror = 0;
        break;
        case  3: // CD32
            p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 1;
+           p->cs_ksmirror = 0;
        break;
        case  4: // A500
            p->cs_df0idhw = 0;
        break;
        case  5: // A500+
-           p->cs_ksmirror = 1;
        break;
        case  6: // A600
-           p->cs_ksmirror = 1;
            p->cs_ide = 1;
            p->cs_pcmcia = 1;
        break;
        case  7: // A1000
            p->cs_a1000ram = 1;
            p->cs_ciaatod = p->ntscmode ? 2 : 1;
+           p->cs_ksmirror = 0;
+           p->cs_rtc = 0;
        break;
        case  8: // A1200
            p->cs_ide = 1;
            p->cs_pcmcia = 1;
-           p->cs_ksmirror = 1;
+           p->cs_ksmirror = 2;
        break;
        case  9: // A2000
            p->cs_rtc = 1;
@@ -3166,7 +3168,6 @@ int build_in_chipset_prefs (struct uae_prefs *p)
            p->cs_ramseyrev = 0x0f;
            p->cs_ide = 2;
            p->cs_mbdmac = 1;
-           p->cs_ksmirror = 1;
        break;
        case 13: // A4000T
            p->cs_rtc = 2;
@@ -3174,7 +3175,6 @@ int build_in_chipset_prefs (struct uae_prefs *p)
            p->cs_ramseyrev = 0x0f;
            p->cs_ide = 2;
            p->cs_mbdmac = 1;
-           p->cs_ksmirror = 1;
        break;
     }
     return 1;
diff --git a/cia.c b/cia.c
index 2dde7b5ea3b8f6f10dd1b83d32c6dec5f9c2c0d7..53361c1178eba2f1bb690012c5cfa85965195f0e 100755 (executable)
--- a/cia.c
+++ b/cia.c
@@ -1260,8 +1260,12 @@ uae_u32 REGPARAM2 clock_bget (uaecptr addr)
 #endif
     ct = localtime (&t);
     addr &= 0x3f;
-    if ((addr & 3) != 3)
-       return 0;
+    if ((addr & 3) == 2 || (addr & 3) == 0) {
+       int v = 0;
+       if (currprefs.cpu_level == 0 && currprefs.cpu_compatible)
+           v = regs.irc >> 8;
+       return v;
+    }
     addr >>= 2;
     if (currprefs.cs_rtc == 1) { /* MSM6242B */
        switch (addr) {
index a237a04e73ba8bc2d82be45326457a563d206037..2e1a6b972b96a55266e7fe3c397a2653a4f8f412 100755 (executable)
@@ -49,6 +49,16 @@ static const uae_u16 x86_fpucw[]={
 static const int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 };
 static const int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 };
 
+static const struct {
+       double b[2];
+       double w[2];
+       double l[2];
+} clamp_bounds = {
+       { -128.0, 127.0 },
+       { -32768.0, 32767.0 },
+       { -2147483648.0, 2147483647.0 }
+};
+
 /* return the required floating point precision or -1 for failure, 0=E, 1=S, 2=D */
 STATIC_INLINE int comp_fp_get (uae_u32 opcode, uae_u16 extra, int treg)
 {
@@ -260,11 +270,11 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
      case 0: /* Dn */
        switch (size) {
         case 0: /* FMOVE.L FPx, Dn */
-#if USE_X86_FPUCW
+#if USE_X86_FPUCW && 0
            if (!(regs.fpcr & 0xf0)) { /* if extended round to nearest */
                mov_l_ri(S1,0x10); /* use extended round to zero mode */
                fldcw_m_indexed(S1,(uae_u32)x86_fpucw);
-               fmovi_mr((uae_u32)temp_fp,sreg);
+               fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.l);
                mov_l_rm(reg,(uae_u32)temp_fp);
                mov_l_rm(S1,(uae_u32)&regs.fpcr);
                and_l_ri(S1,0xf0); /* restore control word */
@@ -272,7 +282,7 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
                return 0;
            }
 #endif
-           fmovi_mr((uae_u32)temp_fp,sreg);
+           fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.l);
            mov_l_rm(reg,(uae_u32)temp_fp);
            return 0;
         case 1: /* FMOVE.S FPx, Dn */
@@ -280,11 +290,11 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
            mov_l_rm(reg,(uae_u32)temp_fp);
            return 0;
         case 4: /* FMOVE.W FPx, Dn */
-#if USE_X86_FPUCW
+#if USE_X86_FPUCW && 0
            if (!(regs.fpcr & 0xf0)) { /* if extended round to nearest */
                mov_l_ri(S1,0x10); /* use extended round to zero mode */
                fldcw_m_indexed(S1,(uae_u32)x86_fpucw);
-               fmovi_mr((uae_u32)temp_fp,sreg);
+               fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.w);
                mov_w_rm(reg,(uae_u32)temp_fp);
                mov_l_rm(S1,(uae_u32)&regs.fpcr);
                and_l_ri(S1,0xf0); /* restore control word */
@@ -292,15 +302,15 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
                return 0;
            }
 #endif
-           fmovi_mr((uae_u32)temp_fp,sreg);
+           fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.w);
            mov_w_rm(reg,(uae_u32)temp_fp);
            return 0;
         case 6: /* FMOVE.B FPx, Dn */
-#if USE_X86_FPUCW
+#if USE_X86_FPUCW && 0
            if (!(regs.fpcr & 0xf0)) { /* if extended round to nearest */
                mov_l_ri(S1,0x10); /* use extended round to zero mode */
                fldcw_m_indexed(S1,(uae_u32)x86_fpucw);
-               fmovi_mr((uae_u32)temp_fp,sreg);
+               fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.b);
                mov_b_rm(reg,(uae_u32)temp_fp);
                mov_l_rm(S1,(uae_u32)&regs.fpcr);
                and_l_ri(S1,0xf0); /* restore control word */
@@ -308,7 +318,7 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
                return 0;
            }
 #endif
-           fmovi_mr((uae_u32)temp_fp,sreg);
+           fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.b);
            mov_b_rm(reg,(uae_u32)temp_fp);
            return 0;
         default:
@@ -361,7 +371,7 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
     }
     switch (size) {
      case 0: /* Long */
-       fmovi_mr((uae_u32)temp_fp,sreg);
+       fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.l);
        mov_l_rm(S2,(uae_u32)temp_fp);
        writelong_clobber(S1,S2,S3);
        return 0;
@@ -382,7 +392,7 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
        writelong_clobber(S1,S2,S3);
        return 0;
      case 4: /* Word */
-       fmovi_mr((uae_u32)temp_fp,sreg);
+       fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.w);
        mov_l_rm(S2,(uae_u32)temp_fp);
        writeword_clobber(S1,S2,S3);
        return 0;
@@ -395,7 +405,7 @@ STATIC_INLINE int comp_fp_put (uae_u32 opcode, uae_u16 extra)
        writelong_clobber(S1,S2,S3);
        return 0;
      case 6: /* Byte */
-       fmovi_mr((uae_u32)temp_fp,sreg);
+       fmovi_mrb((uae_u32)temp_fp,sreg, clamp_bounds.b);
        mov_l_rm(S2,(uae_u32)temp_fp);
        writebyte(S1,S2,S3);
        return 0;
@@ -1063,7 +1073,7 @@ void comp_fpp_opp (uae_u32 opcode, uae_u16 extra)
                break;
            case 0x03: /* FINTRZ */
 #if USE_X86_FPUCW /* if we have control over the CW, we can do this */
-               if ((regs.fpcr & 0xf0) == 0x10) /* maybe unsafe, because this test is done */
+               if (0 && (regs.fpcr & 0xf0) == 0x10) /* maybe unsafe, because this test is done */
                    frndint_rr(dreg,sreg); /* during the JIT compilation and not at runtime */
                else {
                    mov_l_ri(S1,0x10); /* extended round to zero */
index e1a5a6b9e2b1074e3ce76dfc89d917e664fac294..f82d09e9d91e981453183b1f6914629cfae1b157 100755 (executable)
@@ -2703,14 +2703,49 @@ LOWFUNC(NONE,READ,2,raw_fmovi_rm,(FW r, MEMR m))
 }
 LENDFUNC(NONE,READ,2,raw_fmovi_rm,(FW r, MEMR m))
 
-LOWFUNC(NONE,WRITE,2,raw_fmovi_mr,(MEMW m, FR r))
+LOWFUNC(NONE,WRITE,3,raw_fmovi_mrb,(MEMW m, FR r, double *bounds))
 {
-    make_tos(r);
+    /* Clamp value to the given range and convert to integer.
+       ideally, the clamping should be done using two FCMOVs, but
+       this requires two free fp registers, and we can only be sure
+       of having one. Using a jump for the lower bound and an FCMOV
+       for the upper bound, we can do it with one scratch register.
+     */
+
+    int rs;
+    usereg(r);
+    rs = stackpos(r)+1;
+
+    /* Lower bound onto stack */
+    emit_byte(0xdd);
+    emit_byte(0x05);
+    emit_long((uae_u32)&bounds[0]); /* fld double from lower */
+
+    /* Clamp to lower */
     emit_byte(0xdb);
-    emit_byte(0x15);
+    emit_byte(0xf0+rs); /* fcomi lower,r */
+    emit_byte(0x73);
+    emit_byte(12);      /* jae to writeback */
+
+    /* Upper bound onto stack */
+    emit_byte(0xdd);
+    emit_byte(0xd8);   /* fstp st(0) */
+    emit_byte(0xdd);
+    emit_byte(0x05);
+    emit_long((uae_u32)&bounds[1]); /* fld double from upper */
+
+    /* Clamp to upper */
+    emit_byte(0xdb);
+    emit_byte(0xf0+rs); /* fcomi upper,r */
+    emit_byte(0xdb);
+    emit_byte(0xd0+rs); /* fcmovnbe upper,r */
+
+    /* Store to destination */
+    emit_byte(0xdb);
+    emit_byte(0x1d);
     emit_long(m);
 }
-LENDFUNC(NONE,WRITE,2,raw_fmovi_mr,(MEMW m, FR r))
+LENDFUNC(NONE,WRITE,3,raw_fmovi_mrb,(MEMW m, FR r, double *bounds))
 
 LOWFUNC(NONE,READ,2,raw_fmovs_rm,(FW r, MEMR m))
 {
index 3a8f8faa8f32c85ba2c8eff6ff7188122fce43e2..e45ebbc46b4333368e2c726c1c6915cd96a8cb3d 100755 (executable)
@@ -3926,13 +3926,13 @@ MIDFUNC(2,fmovi_rm,(FW r, MEMR m))
 }
 MENDFUNC(2,fmovi_rm,(FW r, MEMR m))
 
-MIDFUNC(2,fmovi_mr,(MEMW m, FR r))
+MIDFUNC(3,fmovi_mrb,(MEMW m, FR r, double *bounds))
 {
     r=f_readreg(r);
-    raw_fmovi_mr(m,r);
+    raw_fmovi_mrb(m,r,bounds);
     f_unlock(r);
 }
-MENDFUNC(2,fmovi_mr,(MEMW m, FR r))
+MENDFUNC(3,fmovi_mrb,(MEMW m, FR r, double *bounds))
 
 MIDFUNC(2,fmovs_rm,(FW r, MEMR m))
 {
index 885f9115b428d519bf3eb02a6052c8a49b25014b..f829e8901ae9fc9282b83ae74b7a98ba04a31c7e 100755 (executable)
--- a/custom.c
+++ b/custom.c
@@ -5626,6 +5626,21 @@ void check_prefs_changed_custom (void)
     currprefs.immediate_blits = changed_prefs.immediate_blits;
     currprefs.collision_level = changed_prefs.collision_level;
 
+    currprefs.cs_ciaatod = changed_prefs.cs_ciaatod;
+    currprefs.cs_rtc = changed_prefs.cs_rtc;
+    currprefs.cs_cd32cd = changed_prefs.cs_cd32cd;
+    currprefs.cs_cd32c2p = changed_prefs.cs_cd32c2p;
+    currprefs.cs_cd32nvram = changed_prefs.cs_cd32nvram;
+    currprefs.cs_cdtvcd = changed_prefs.cs_cdtvcd;
+    currprefs.cs_ide = changed_prefs.cs_ide;
+    currprefs.cs_pcmcia = changed_prefs.cs_pcmcia;
+    currprefs.cs_fatgaryrev = changed_prefs.cs_fatgaryrev;
+    currprefs.cs_ramseyrev = changed_prefs.cs_ramseyrev;
+    currprefs.cs_agnusrev = changed_prefs.cs_agnusrev;
+    currprefs.cs_deniserev = changed_prefs.cs_deniserev;
+    currprefs.cs_mbdmac = changed_prefs.cs_mbdmac;
+    currprefs.cs_df0idhw = changed_prefs.cs_df0idhw;
+
     if (currprefs.chipset_mask != changed_prefs.chipset_mask ||
        currprefs.gfx_vsync != changed_prefs.gfx_vsync ||
        currprefs.picasso96_nocustom != changed_prefs.picasso96_nocustom ||
diff --git a/disk.c b/disk.c
index 6bdadd2830fff96c0fe005e250d4a1c00f3a546a..937771a53a79976a36d2f457c28a9231e1f053a0 100755 (executable)
--- a/disk.c
+++ b/disk.c
@@ -1124,7 +1124,7 @@ static void drive_motor (drive * drv, int off)
 #endif
        if (disk_debug_logging > 1)
            write_log (" ->motor off");
-       if (currprefs.cpu_level <= 1) {
+       if (currprefs.cpu_level <= 1 && currprefs.m68k_speed == 0) {
            drv->motordelay = 1;
            event2_newevent2(30, drv - floppy, motordelay_func);
        }
index 417befd2795c41142fc4c680828385cf927a17fc..028e3c028e08500ed26463a450b808221e292f40 100755 (executable)
@@ -909,12 +909,8 @@ static void expamem_init_z3fastmem (void)
 
 static void expamem_map_gfxcard (void)
 {
-    gfxmem_start = ((expamem_hi | (expamem_lo >> 4)) << 16);
+    gfxmem_start = (expamem_hi | (expamem_lo >> 4)) << 16;
     map_banks (&gfxmem_bank, gfxmem_start >> 16, allocated_gfxmem >> 16, 0);
-#if 0
-    if (allocated_gfxmem < 0x1000000)
-       map_banks (&gfxmem_bank, (gfxmem_start + allocated_gfxmem) >> 16, (0x1000000 - allocated_gfxmem) >> 16, 0);
-#endif
     write_log ("UAEGFX-card: mapped @$%lx, %d MB RTG RAM\n", gfxmem_start, allocated_gfxmem / 0x100000);
 }
 
index 3fe1d4e4bb49969edb29db329eaa3faa494a2d34..51d405bf65b0483f7ce78ba7af36a5feb7cf05c2 100755 (executable)
--- a/filesys.c
+++ b/filesys.c
@@ -2669,7 +2669,14 @@ static void action_set_comment (Unit * unit, dpacket packet)
 
     if (fsdb_cando (unit)) {
         commented = bstr (unit, comment);
-       commented = strlen (commented) > 0 ? my_strdup (commented) : NULL;
+       if (strlen (commented) > 0) {
+           char *p = commented;
+           commented = xmalloc (81);
+           strncpy (commented, p, 80);
+           commented[80] = 0;
+       } else {
+           commented = NULL;
+       }
     }
     TRACE (("ACTION_SET_COMMENT(0x%lx,\"%s\")\n", lock, commented));
 
diff --git a/fpp.c b/fpp.c
index 79fd0a5dfdf87a624e086635a53f5c36524d9bc4..7f76f9373cd94e124b6d3fa1579435cab0439a76 100755 (executable)
--- a/fpp.c
+++ b/fpp.c
@@ -137,12 +137,26 @@ typedef uae_s64 tointtype;
 typedef uae_s32 tointtype;
 #endif
 
-static __inline__ tointtype toint(fptype src)
+STATIC_INLINE tointtype toint(fptype src, fptype minval, fptype maxval)
 {
-  switch ((regs.fpcr >> 4) & 3) {
+    if (src < minval)
+       src = minval;
+    if (src > maxval)
+       src = maxval;
+#if defined(X86_MSVC_ASSEMBLY)
+    {
+       fptype tmp_fp;
+       __asm {
+           fld  LDPTR src
+           frndint
+           fstp LDPTR tmp_fp
+       }
+       return (tointtype)tmp_fp;
+    }
+#else /* no X86_MSVC */
+    switch ((regs.fpcr >> 4) & 3) {
     case 0: /* to nearest */
-       if (regs.fpcr & 0xf0) /* if not Extended RN */
-           return (tointtype)floor (src + 0.5);
+       return (tointtype)floor (src + 0.5);
     case 1: /* to zero */
        return (tointtype) src;
     case 2: /* down */
@@ -150,7 +164,7 @@ static __inline__ tointtype toint(fptype src)
     case 3: /* up */
        return (tointtype)ceil (src);
   }
-  return (tointtype)src; /* never reached */
+#endif
 }
 
 uae_u32 get_fpsr (void)
@@ -434,15 +448,15 @@ STATIC_INLINE int put_fp_value (struct regstruct *regs, fptype value, uae_u32 op
     case 0:
        switch (size) {
        case 6:
-           m68k_dreg (regs, reg) = (uae_u32)(((toint(value) & 0xff)
+           m68k_dreg (regs, reg) = (uae_u32)(((toint(value, -128.0, 127.0) & 0xff)
                | (m68k_dreg (regs, reg) & ~0xff)));
            break;
        case 4:
-           m68k_dreg (regs, reg) = (uae_u32)(((toint(value) & 0xffff)
+           m68k_dreg (regs, reg) = (uae_u32)(((toint(value, -32768.0, 327676.0) & 0xffff)
            | (m68k_dreg (regs, reg) & ~0xffff)));
            break;
        case 0:
-           m68k_dreg (regs, reg) = (uae_u32)toint(value);
+           m68k_dreg (regs, reg) = (uae_u32)toint(value, -2147483648.0, 2147483647.0);
            break;
        case 1:
            m68k_dreg (regs, reg) = from_single (value);
@@ -497,7 +511,7 @@ STATIC_INLINE int put_fp_value (struct regstruct *regs, fptype value, uae_u32 op
     }
     switch (size) {
     case 0:
-       put_long (ad, (uae_u32)toint(value));
+       put_long (ad, (uae_u32)toint(value, -2147483648.0, 2147483647.0));
        break;
     case 1:
        put_long (ad, from_single (value));
@@ -525,7 +539,7 @@ STATIC_INLINE int put_fp_value (struct regstruct *regs, fptype value, uae_u32 op
        }
        break;
     case 4:
-       put_word (ad, (uae_s16) toint(value));
+       put_word (ad, (uae_s16) toint(value, -32768.0, 32767.0));
        break;
     case 5:{
            uae_u32 wrd1, wrd2;
@@ -536,7 +550,7 @@ STATIC_INLINE int put_fp_value (struct regstruct *regs, fptype value, uae_u32 op
        }
        break;
     case 6:
-       put_byte (ad, (uae_s8)toint(value));
+       put_byte (ad, (uae_s8)toint(value, -128.0, 127.0));
        break;
     default:
        return 0;
index 0f12fc0e5654cc99dcbade46f1135857511b9575..53bee8eed13687bb9f1a6f972f18307cc047f9be 100755 (executable)
@@ -408,7 +408,7 @@ DECLARE(fmov_0(FW r));
 DECLARE(fmov_rm(FW r, MEMR m));
 DECLARE(fmov_mr(MEMW m, FR r));
 DECLARE(fmovi_rm(FW r, MEMR m));
-DECLARE(fmovi_mr(MEMW m, FR r));
+DECLARE(fmovi_mrb(MEMW m, FR r, double *bounds));
 DECLARE(fmovs_rm(FW r, MEMR m));
 DECLARE(fmovs_mr(MEMW m, FR r));
 DECLARE(fcuts_r(FRW r));
index d0a0f2de0bdadca045e818e370fdb02270bb44dd..5ea7e41dd9db781fe48e0920858c1fc5730ab157 100755 (executable)
@@ -36,7 +36,7 @@ extern void uaeser_close (void*);
 extern int uaeser_read (void*, uae_u8 *data, uae_u32 len);
 extern int uaeser_write (void*, uae_u8 *data, uae_u32 len);
 extern int uaeser_query (void*, uae_u16 *status, uae_u32 *pending);
-extern int uaeser_setparams (void*, int baud, int rbuffer, int bits, int sbits, int rtscts, int parity);
+extern int uaeser_setparams (void*, int baud, int rbuffer, int bits, int sbits, int rtscts, int parity, uae_u32 xonxoff);
 extern int uaeser_break (void*, int brklen);
 extern void uaeser_signal (void*, int source);
 extern void uaeser_trigger (void*);
index bde6fea80f21d5c420ea93056f23cff7c051117f..c6a6bf6e579505679e42cab4aeb9ca575e3aace4 100755 (executable)
--- a/memory.c
+++ b/memory.c
@@ -656,6 +656,13 @@ static void dummylog(int rw, uaecptr addr, int size, uae_u32 val, int ins)
     /* extended rom */
     if (addr >= 0xf00000 && addr <= 0xf7ffff)
        return;
+    /* motherbord ram */
+    if (addr >= 0x08000000 && addr <= 0x08000007)
+       return;
+    if (addr >= 0x07f00000 && addr <= 0x07f00007)
+       return;
+    if (addr >= 0x07f7fff0 && addr <= 0x07ffffff)
+       return;
     if (MAX_ILG >= 0)
        illegal_count++;
     if (ins) {
@@ -1677,7 +1684,7 @@ static int read_kickstart (struct zfile *f, uae_u8 *mem, int size, int dochecksu
     }
     if (currprefs.cs_a1000ram) {
        int off = 0;
-       a1000_bootrom = xmalloc (262144);
+       a1000_bootrom = xcalloc (262144, 1);
        while (off + i < 262144) {
            memcpy (a1000_bootrom + off, kickmemory, i);
            off += i;
@@ -2218,14 +2225,17 @@ void map_overlay (int chip)
 
 void memory_reset (void)
 {
-    int custom_start, bnk;
+    int bnk;
 
     be_cnt = 0;
     currprefs.chipmem_size = changed_prefs.chipmem_size;
     currprefs.bogomem_size = changed_prefs.bogomem_size;
     currprefs.mbresmem_low_size = changed_prefs.mbresmem_low_size;
     currprefs.mbresmem_high_size = changed_prefs.mbresmem_high_size;
+    currprefs.cs_ksmirror = changed_prefs.cs_ksmirror;
+    currprefs.cs_cdtvram = changed_prefs.cs_cdtvram;
     currprefs.cs_cdtvcard = changed_prefs.cs_cdtvcard;
+    currprefs.cs_a1000ram = changed_prefs.cs_a1000ram;
 
     init_mem_banks ();
     allocate_memory ();
@@ -2285,15 +2295,18 @@ void memory_reset (void)
     if (cloanto_rom)
        currprefs.maprom = changed_prefs.maprom = 0;
 
-    custom_start = 0xC0;
-    map_banks (&custom_bank, custom_start, 0xE0 - custom_start, 0);
+    map_banks (&custom_bank, 0xC0, 0xE0 - 0xC0, 0);
     map_banks (&cia_bank, 0xA0, 32, 0);
+    if (!currprefs.cs_a1000ram)
+       map_banks (&dummy_bank, 0xD8, 6, 0); /* D80000 - DDFFFF not mapped (A1000 = custom chips) */
 
-    /* map "nothing" to 0x200000 - 0xa00000 */
+    /* map "nothing" to 0x200000 - 0x9FFFFF (0xBEFFFF if AGA) */
     bnk = allocated_chipmem >> 16;
     if (bnk < 0x20 + (currprefs.fastmem_size >> 16))
        bnk = 0x20 + (currprefs.fastmem_size >> 16);
-    map_banks (&dummy_bank, bnk, 0xA0 - bnk, 0);
+    map_banks (&dummy_bank, bnk, (currprefs.chipset_mask & CSMASK_AGA ? 0xBF : 0xA0) - bnk, 0);
+    if (currprefs.chipset_mask & CSMASK_AGA)
+       map_banks (&dummy_bank, 0xc0, 0xd8 - 0xc0, 0);
 
     if (bogomemory != 0) {
        int t = allocated_bogomem >> 16;
@@ -2370,7 +2383,10 @@ void memory_reset (void)
     
     if ((cloanto_rom || currprefs.cs_ksmirror) && !currprefs.maprom && !extendedkickmem_type)
         map_banks (&kickmem_bank, 0xE0, 8, 0);
-
+    if (currprefs.cs_ksmirror == 2) { /* unexpanded A1200 also maps ROM here.. */
+        map_banks (&kickmem_bank, 0xA8, 8, 0);
+        map_banks (&kickmem_bank, 0xB0, 8, 0);
+    }
 #ifdef ARCADIA
     if (is_arcadia_rom (currprefs.romextfile) == ARCADIA_BIOS) {
        if (strcmp (currprefs.romextfile, changed_prefs.romextfile) != 0)
index 28f59a05854b2019fae3dd5d829da3f86fd60fa4..16a27cd2cad9327c2ae94de500582f843b6f734d 100755 (executable)
--- a/newcpu.c
+++ b/newcpu.c
@@ -962,6 +962,9 @@ static void Exception_normal (int nr, struct regstruct *regs, uaecptr oldpc)
     exception_debug (nr);
     MakeSR(regs);
 
+    if (nr == 3)
+       activate_debugger();
+
     if (!regs->s) {
        regs->usp = m68k_areg(regs, 7);
        if (currprefs.cpu_level >= 2)
index 93f9cb6c776d68e95a1f281b0e8aff93e0f21aff..aafc70ddbf95c7e07545c79d6d38fc4b1287bb2f 100755 (executable)
@@ -1535,7 +1535,7 @@ DWORD DirectDraw_CurrentRefreshRate(void)
  *   1999.08.02  Brian King             Creation
  *
  */
-static int DirectDraw_BltFastStub4(LPDIRECTDRAWSURFACE7 dstsurf, DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 srcsurf, LPRECT srcrect )
+static int DirectDraw_BltFastStub4(LPDIRECTDRAWSURFACE7 dstsurf, DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 srcsurf, LPRECT srcrect)
 {
     int result = 0;
     HRESULT ddrval;
index 624e2aa3b833fdc368459bc2917a4be1def9124a..3d2c7009c53e446db8c65d4fe35fe97f78323429 100755 (executable)
@@ -234,11 +234,6 @@ void *shmat(int shmid, void *shmaddr, int shmflg)
        if(!strcmp(shmids[shmid].name,"gfx")) {
            shmaddr=natmem_offset + currprefs.z3fastmem_start + ((currprefs.z3fastmem_size + 0xffffff) & ~0xffffff);
            got = TRUE;
-#if 0
-           result=malloc(size);
-           shmids[shmid].attached=result;
-           return result;
-#endif
        }
        if(!strcmp(shmids[shmid].name,"bogo")) {
            shmaddr=natmem_offset+0x00C00000;
@@ -339,7 +334,7 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
     return result;
 }
 
-int isinf( double x )
+int isinf(double x)
 {
     const int nClass = _fpclass(x);
     int result;
index 61d7c56dd0e96385bf7402b0d2c615321bba38c8..c93a21baab22f8b93de0b713e280882b422c46ca 100755 (executable)
@@ -540,13 +540,14 @@ int uaeser_break (struct uaeserialdatawin32 *sd, int brklen)
     return 1;
 }
 
-int uaeser_setparams (struct uaeserialdatawin32 *sd, int baud, int rbuffer, int bits, int sbits, int rtscts, int parity)
+int uaeser_setparams (struct uaeserialdatawin32 *sd, int baud, int rbuffer, int bits, int sbits, int rtscts, int parity, uae_u32 xonxoff)
 {
     DCB dcb;
 
+    memset (&dcb, 0, sizeof (dcb));
     dcb.DCBlength = sizeof (DCB);
     if (!GetCommState (sd->hCom, &dcb))
-       return 0;
+       return 5;
 
     dcb.BaudRate = baud;
     dcb.ByteSize = bits;
@@ -566,8 +567,15 @@ int uaeser_setparams (struct uaeserialdatawin32 *sd, int baud, int rbuffer, int
     }   
 
     dcb.fTXContinueOnXoff = FALSE;
-    dcb.fOutX = FALSE;
-    dcb.fInX = FALSE;
+    dcb.XonChar = (xonxoff >> 8) & 0xff;
+    dcb.XoffChar = (xonxoff >> 16) & 0xff;
+    if (xonxoff & 1) {
+       dcb.fOutX = TRUE;
+       dcb.fInX = TRUE;
+    } else {
+       dcb.fOutX = FALSE;
+       dcb.fInX = FALSE;
+    }
 
     dcb.fErrorChar = FALSE;
     dcb.fNull = FALSE;
@@ -576,11 +584,12 @@ int uaeser_setparams (struct uaeserialdatawin32 *sd, int baud, int rbuffer, int
     dcb.XoffLim = 512;
     dcb.XonLim = 2048;
 
-    dcb.ByteSize = rbuffer;
-
-    if (!SetCommState (sd->hCom, &dcb))
-       return 0;
-    return 1;
+    if (!SetCommState (sd->hCom, &dcb)) {
+       write_log("uaeserial: SetCommState() failed %d\n", GetLastError());
+       return 5;
+    }
+    SetupComm (sd->hCom, rbuffer, rbuffer);
+    return 0;
 }
 
 static void startwce(struct uaeserialdatawin32 *sd, DWORD *evtmask)
@@ -1173,17 +1182,39 @@ end:
 
 int enumserialports(void)
 {
-    int port, cnt;
+    int cnt, i, j;
     char name[256];
-    COMMCONFIG cc;
     DWORD size = sizeof(COMMCONFIG);
+    char devname[1000];
 
     write_log("Serial port enumeration..\n");
-    if (os_winnt) {
+    cnt = 0;
+    if (os_winnt)
        cnt = enumserialports_2();
-    } else {
+    for (i = 0; i < 10; i++) {
+       sprintf(name, "COM%d", i);
+       if (!QueryDosDevice(name, devname, sizeof devname)) {
+           continue;
+       } else {
+           for(j = 0; j < cnt; j++) {
+               if (!strcmp(comports[j].cfgname, name))
+                   break;
+           }
+           if (j == cnt) {
+               comports[j].dev = xmalloc(100);
+               sprintf(comports[cnt].dev, "\\.\\\\%s", name);
+               comports[j].cfgname = my_strdup (name);
+               comports[j].name = my_strdup (name);
+               write_log("SERPORT: '%s' = '%s' (%s)\n", comports[j].name, comports[j].dev, devname);
+               cnt++;
+           }
+       }
+    }
+#if 0
+    {
        cnt = 0;
        for(port = 0; port < MAX_SERIAL_PORTS; port++) {
+           COMMCONFIG cc;
            sprintf(name, "COM%d", port);
            if(GetDefaultCommConfig(name, &cc, &size)) {
                if (cnt < MAX_SERIAL_PORTS) {
@@ -1197,6 +1228,7 @@ int enumserialports(void)
            }
        }
     }
+#endif
     write_log("Serial port enumeration end\n");
     return cnt;
 }
index e282fb21cb8868c1972e120815d85341e6098ec0..7bd2c80dc3776d1e040cab95de7e5eb551b0e69f 100755 (executable)
@@ -35,7 +35,6 @@
 
 #include "options.h"
 #include "threaddep/thread.h"
-#include "uae.h"
 #include "memory.h" 
 #include "custom.h"
 #include "events.h"
 int p96hack_vpos, p96hack_vpos2, p96refresh_active; 
 int have_done_picasso; /* For the JIT compiler */
 static int vsyncgfxwrite = 0; 
-static int p96syncrate,vsyncgfxcount;
-int p96hsync_counter;
-#if defined(X86_MSVC_ASSEMBLY)
-#define SWAPSPEEDUP
-#endif
-#ifdef PICASSO96
+static int p96syncrate, vsyncgfxcount;
+static int p96hsync_counter;
+
 #ifdef DEBUG // Change this to _DEBUG for debugging
 #define P96TRACING_ENABLED 1
 #define P96TRACING_LEVEL 1
@@ -68,31 +64,28 @@ int p96hsync_counter;
 #define PIXEL_LOCK    //and scrollable screens
 #define MAXFLUSHPIXEL 3200 //pixel draw in a lock
 static void flushpixels(void);
-int pixelcount,palette_changed;
+static int pixelcount, palette_changed;
 struct pixel32{
     uaecptr addr;
     uae_u32 value;
     int size;
 };
-struct pixel32 pixelbase[MAXFLUSHPIXEL+2];
+static struct pixel32 pixelbase[MAXFLUSHPIXEL + 2];
 #ifdef P96TRACING_ENABLED
 #define P96TRACE(x) do { write_log x; } while(0)
 #else
 #define P96TRACE(x)
 #endif
+#define P96TRACEX(x) do { write_log x; } while(0)
 
 #define GetBytesPerPixel(x) GetBytesPerPixel2(x,__FILE__,__LINE__)
 
 #if defined(JIT)
-static int picasso_is_special = PIC_WRITE; /* ditto */
-static int picasso_is_special_read = PIC_READ; /* ditto */
-#define P96_SM_RS special_mem |= picasso_is_special_read | picasso_is_special
-#define P96_SM_R special_mem |= picasso_is_special_read;
-#define P96_SM_S special_mem |= picasso_is_special;
+#define P96_SM_R special_mem |= PIC_READ;
+#define P96_SM_W special_mem |= PIC_WRITE;
 #else
-#define P96_SM_RS
 #define P96_SM_R
-#define P96_SM_S
+#define P96_SM_W
 #endif
 
 static uae_u32 REGPARAM2 gfxmem_lget (uaecptr) REGPARAM;
@@ -104,10 +97,6 @@ static void REGPARAM2 gfxmem_bput (uaecptr, uae_u32) REGPARAM;
 static int REGPARAM2 gfxmem_check (uaecptr addr, uae_u32 size) REGPARAM;
 static uae_u8 *REGPARAM2 gfxmem_xlate (uaecptr addr) REGPARAM;
 
-static void write_gfx_long (uaecptr addr, uae_u32 value);
-static void write_gfx_word (uaecptr addr, uae_u16 value);
-static void write_gfx_byte (uaecptr addr, uae_u8 value);
-
 static uae_u8 all_ones_bitmap, all_zeros_bitmap; /* yuk */
 
 struct picasso96_state_struct picasso96_state;
@@ -116,11 +105,11 @@ struct picasso_vidbuf_description picasso_vidinfo;
 /* These are the maximum resolutions... They are filled in by GetSupportedResolutions() */
 /* have to fill this in, otherwise problems occur on the Amiga side P96 s/w which expects
 /* data here. */
-struct ScreenResolution planar = { 320, 240 };
-struct ScreenResolution chunky = { 640, 480 };
-struct ScreenResolution hicolour = { 640, 480 };
-struct ScreenResolution truecolour = { 640, 480 };
-struct ScreenResolution alphacolour = { 640, 480 };
+static struct ScreenResolution planar = { 320, 240 };
+static struct ScreenResolution chunky = { 640, 480 };
+static struct ScreenResolution hicolour = { 640, 480 };
+static struct ScreenResolution truecolour = { 640, 480 };
+static struct ScreenResolution alphacolour = { 640, 480 };
 
 #include "win32gui.h"
 #include "resource.h"
@@ -160,44 +149,40 @@ static void checkrtglibrary(void)
 static uae_u32 p2ctab[256][2];
 static int set_gc_called = 0;
 //fastscreen
-static uaecptr oldscr=0;
+static uaecptr oldscr = 0;
 #ifdef _DEBUG
-void PICASSO96_Unlock2( char *filename, int linenum )
+static void PICASSO96_Unlock2(char *filename, int linenum)
 #else
-void PICASSO96_Unlock( void )
+static void PICASSO96_Unlock(void)
 #endif
 {
 #ifdef LOCK_UNLOCK_MADNESS
-#if defined( P96TRACING_ENABLED ) && P96TRACING_LEVEL > 1
-       // This format of output lets you double-click and jump to file/line
-       write_log( "%s(%d) : calling P96 UNLOCK with picasso_on=%d\n", filename, linenum, picasso_on );
+#if defined(P96TRACING_ENABLED) && P96TRACING_LEVEL > 1
+    // This format of output lets you double-click and jump to file/line
+    write_log("%s(%d) : calling P96 UNLOCK with picasso_on=%d\n", filename, linenum, picasso_on);
 #endif
-    if( picasso_on )
-    {
+    if(picasso_on) {
 #ifdef PIXEL_LOCK
        flushpixels();
 #endif 
        gfx_unlock_picasso ();
-
-       //picasso96_state.HostAddress = NULL;
+       picasso96_state.HostAddress = NULL;
     }
 #endif
 }
 
 #ifdef _DEBUG
-void PICASSO96_Lock2( char *filename, int linenum )
+static void PICASSO96_Lock2(char *filename, int linenum)
 #else
-void PICASSO96_Lock( void )
+static void PICASSO96_Lock(void)
 #endif
 {
 #ifdef LOCK_UNLOCK_MADNESS
-#if defined( P96TRACING_ENABLED ) && P96TRACING_LEVEL > 1
-       // This format of output lets you double-click and jump to file/line
-       write_log( "%s(%d) : calling P96 LOCK with picasso_on=%d\n", filename, linenum, picasso_on );
+#if defined(P96TRACING_ENABLED) && P96TRACING_LEVEL > 1
+    // This format of output lets you double-click and jump to file/line
+    write_log( "%s(%d) : calling P96 LOCK with picasso_on=%d\n", filename, linenum, picasso_on );
 #endif
-    if( picasso_on /*&& !picasso96_state.HostAddress*/)
-    {
-       //gfx_unlock_picasso(); // forces the proper flushing
+    if(picasso_on) {
        picasso96_state.HostAddress = gfx_lock_picasso ();
     }
 #endif
@@ -303,24 +288,23 @@ static void DumpTemplate (struct Template *tmp, unsigned long w, unsigned long h
 
 static void DumpLine( struct Line *line )
 {
-    if( line )
-    {
-       write_log( "Line->X = %d\n", line->X );
-       write_log( "Line->Y = %d\n", line->Y );
-       write_log( "Line->Length = %d\n", line->Length );
-       write_log( "Line->dX = %d\n", line->dX );
-       write_log( "Line->dY = %d\n", line->dY );
-       write_log( "Line->sDelta = %d\n", line->sDelta );
-       write_log( "Line->lDelta = %d\n", line->lDelta );
-       write_log( "Line->twoSDminusLD = %d\n", line->twoSDminusLD );
-       write_log( "Line->LinePtrn = %d\n", line->LinePtrn );
-       write_log( "Line->PatternShift = %d\n", line->PatternShift );
-       write_log( "Line->FgPen = 0x%x\n", line->FgPen );
-       write_log( "Line->BgPen = 0x%x\n", line->BgPen );
-       write_log( "Line->Horizontal = %d\n", line->Horizontal );
-       write_log( "Line->DrawMode = %d\n", line->DrawMode );
-       write_log( "Line->Xorigin = %d\n", line->Xorigin );
-       write_log( "Line->Yorigin = %d\n", line->Yorigin );
+    if(line) {
+       write_log("Line->X = %d\n", line->X);
+       write_log("Line->Y = %d\n", line->Y);
+       write_log("Line->Length = %d\n", line->Length);
+       write_log("Line->dX = %d\n", line->dX);
+       write_log("Line->dY = %d\n", line->dY);
+       write_log("Line->sDelta = %d\n", line->sDelta);
+       write_log("Line->lDelta = %d\n", line->lDelta);
+       write_log("Line->twoSDminusLD = %d\n", line->twoSDminusLD);
+       write_log("Line->LinePtrn = %d\n", line->LinePtrn);
+       write_log("Line->PatternShift = %d\n", line->PatternShift);
+       write_log("Line->FgPen = 0x%x\n", line->FgPen);
+       write_log("Line->BgPen = 0x%x\n", line->BgPen);
+       write_log("Line->Horizontal = %d\n", line->Horizontal);
+       write_log("Line->DrawMode = %d\n", line->DrawMode);
+       write_log("Line->Xorigin = %d\n", line->Xorigin);
+       write_log("Line->Yorigin = %d\n", line->Yorigin);
     }
 }
 #endif
@@ -364,13 +348,10 @@ static uae_u8 GetBytesPerPixel2(uae_u32 RGBfmt, char *file, int line)
        return 2;
     default:
        write_log ("ERROR - GetBytesPerPixel() from %s@%d was unsuccessful with 0x%x?!\n", file, line, RGBfmt);
-       if( !bFailure )
-       {
+       if(!bFailure) {
            bFailure = TRUE;
            return GetBytesPerPixel(picasso_vidinfo.rgbformat);
-       }
-       else
-       {
+       } else {
            abort();
        }
     }
@@ -430,11 +411,11 @@ static int CopyBitMapStructureA2U (uaecptr amigamemptr, struct BitMap *bm)
     bm->Depth = get_byte (amigamemptr + PSSO_BitMap_Depth);
     
     /* ARGH - why is THIS happening? */
-    if( bm->Depth > 8 )
+    if(bm->Depth > 8)
        bm->Depth = 8;
     
     for (i = 0; i < bm->Depth; i++) {
-       uaecptr plane = get_long (amigamemptr + PSSO_BitMap_Planes + i*4);
+       uaecptr plane = get_long (amigamemptr + PSSO_BitMap_Planes + i * 4);
        switch (plane) {
        case 0:
            bm->Planes[i] = &all_zeros_bitmap;
@@ -470,29 +451,28 @@ static int CopyTemplateStructureA2U (uaecptr amigamemptr, struct Template *tmpl)
     return 0;
 }
 
-static int CopyLineStructureA2U( uaecptr amigamemptr, struct Line *line )
-{
-    if( valid_address( amigamemptr, sizeof( struct Line ) ) )
-    {
-       line->X = get_word( amigamemptr + PSSO_Line_X );
-       line->Y = get_word( amigamemptr + PSSO_Line_Y );
-       line->Length = get_word( amigamemptr + PSSO_Line_Length );
-       line->dX = get_word( amigamemptr + PSSO_Line_dX );
-       line->dY = get_word( amigamemptr + PSSO_Line_dY );
-       line->lDelta = get_word( amigamemptr + PSSO_Line_lDelta );
-       line->sDelta = get_word( amigamemptr + PSSO_Line_sDelta );
-       line->twoSDminusLD = get_word( amigamemptr + PSSO_Line_twoSDminusLD );
-       line->LinePtrn = get_word( amigamemptr + PSSO_Line_LinePtrn );
-       line->PatternShift = get_word( amigamemptr + PSSO_Line_PatternShift );
-       line->FgPen = get_long( amigamemptr + PSSO_Line_FgPen );
-       line->BgPen = get_long( amigamemptr + PSSO_Line_BgPen );
-       line->Horizontal = get_word( amigamemptr + PSSO_Line_Horizontal );
-       line->DrawMode = get_byte( amigamemptr + PSSO_Line_DrawMode );
-       line->Xorigin = get_word( amigamemptr + PSSO_Line_Xorigin );
-       line->Yorigin = get_word( amigamemptr + PSSO_Line_Yorigin );
+static int CopyLineStructureA2U(uaecptr amigamemptr, struct Line *line)
+{
+    if(valid_address(amigamemptr, sizeof(struct Line))) {
+       line->X = get_word(amigamemptr + PSSO_Line_X);
+       line->Y = get_word(amigamemptr + PSSO_Line_Y);
+       line->Length = get_word(amigamemptr + PSSO_Line_Length);
+       line->dX = get_word(amigamemptr + PSSO_Line_dX);
+       line->dY = get_word(amigamemptr + PSSO_Line_dY);
+       line->lDelta = get_word(amigamemptr + PSSO_Line_lDelta);
+       line->sDelta = get_word(amigamemptr + PSSO_Line_sDelta);
+       line->twoSDminusLD = get_word(amigamemptr + PSSO_Line_twoSDminusLD);
+       line->LinePtrn = get_word(amigamemptr + PSSO_Line_LinePtrn);
+       line->PatternShift = get_word(amigamemptr + PSSO_Line_PatternShift);
+       line->FgPen = get_long(amigamemptr + PSSO_Line_FgPen);
+       line->BgPen = get_long(amigamemptr + PSSO_Line_BgPen);
+       line->Horizontal = get_word(amigamemptr + PSSO_Line_Horizontal);
+       line->DrawMode = get_byte(amigamemptr + PSSO_Line_DrawMode);
+       line->Xorigin = get_word(amigamemptr + PSSO_Line_Xorigin);
+       line->Yorigin = get_word(amigamemptr + PSSO_Line_Yorigin);
        return 1;
     }
-    write_log( "ERROR - Invalid Line structure...\n" );
+    write_log("ERROR - Invalid Line structure...\n");
     return 0;
 }
 
@@ -509,7 +489,7 @@ static void CopyLibResolutionStructureU2A (struct LibResolution *libres, uaecptr
     put_word (amigamemptr + PSSO_LibResolution_Height, libres->Height);
     put_word (amigamemptr + PSSO_LibResolution_Flags, libres->Flags);
     for (i = 0; i < MAXMODES; i++)
-       put_long (amigamemptr + PSSO_LibResolution_Modes + i*4, libres->Modes[i]);
+       put_long (amigamemptr + PSSO_LibResolution_Modes + i * 4, libres->Modes[i]);
 #if 0
     put_long (amigamemptr, libres->Node.ln_Succ);
     put_long (amigamemptr + 4, libres->Node.ln_Pred);
@@ -539,56 +519,36 @@ static void AmigaListAddTail (uaecptr l, uaecptr n)
 * filled rectangle in the frame buffer; it can be used as a memcpy source if
 * there is no OS specific function to fill the rectangle.
 */
-static void do_fillrect( uae_u8 *src, unsigned int x, unsigned int y, unsigned int width, unsigned int height, uae_u32 pen, int Bpp, RGBFTYPE rgbtype )
+static void do_fillrect(uae_u8 *src, unsigned int x, unsigned int y, unsigned int width, unsigned int height, uae_u32 pen, int Bpp, RGBFTYPE rgbtype)
 {
     uae_u8 *dst;
-   
+    int orig_width = width;
+    int orig_height = height;
+
     /* Try OS specific fillrect function here; and return if successful.  Make sure we adjust for
-    * the pen values if we're doing 8-bit display-emulation on a 16-bit or higher screen. */
+     * the pen values if we're doing 8-bit display-emulation on a 16-bit or higher screen. */
 #ifdef PIXEL_LOCK
-     flushpixels(); 
+    flushpixels(); 
 #endif
 
-    if( picasso_vidinfo.rgbformat == picasso96_state.RGBFormat )
-    {
-       if( DX_Fill( x, y, width, height, pen, rgbtype ) )
-    {
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-#endif
+    if(picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
+       if(DX_Fill(x, y, width, height, pen, rgbtype))
            return;
-               }
-    }
-    else
-    {   
-       if( DX_Fill( x, y, width, height, picasso_vidinfo.clut[src[0]], rgbtype ) )
-               {
-#ifdef LOCK_UNLOCK_MADNESS
-     //PICASSO96_Unlock();
-#endif
+    } else {   
+       if(DX_Fill(x, y, width, height, picasso_vidinfo.clut[src[0]], rgbtype))
           return;
-               } 
-
     }
-   
+
     P96TRACE(("P96_WARNING: do_fillrect() using fall-back routine!\n"));
     
-    if( y+height > picasso_vidinfo.height )
+    if(y + height > picasso_vidinfo.height)
        height = picasso_vidinfo.height - y;
-    if( x+width > picasso_vidinfo.width )
+    if(x + width > picasso_vidinfo.width)
        width = picasso_vidinfo.width - x;
 
-    DX_Invalidate (y, y + height - 1);
     if (! picasso_vidinfo.extra_mem)
-       {               
-#ifdef LOCK_UNLOCK_MADNESS
-     //PICASSO96_Unlock();
-#endif
-       pixelcount=0;
-          return;
-               } 
+       return;
     
-    width *= Bpp;
 #ifdef LOCK_UNLOCK_MADNESS
     PICASSO96_Lock();
     dst = picasso96_state.HostAddress;
@@ -598,14 +558,15 @@ static void do_fillrect( uae_u8 *src, unsigned int x, unsigned int y, unsigned i
     if (!dst)
        goto out;
     
-    dst += y*picasso_vidinfo.rowbytes + x*picasso_vidinfo.pixbytes;
+    width *= Bpp;
+    dst += y * picasso_vidinfo.rowbytes + x * picasso_vidinfo.pixbytes;
     if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) 
     {
-       if( Bpp == 1 )
+       if(Bpp == 1)
        {
            while (height-- > 0)
            {
-               memset( dst, pen, width );
+               memset(dst, pen, width);
                dst += picasso_vidinfo.rowbytes;
            } 
        }
@@ -652,8 +613,9 @@ out:;
 #ifndef        LOCK_UNLOCK_MADNESS
     gfx_unlock_picasso ();
 #else
-     PICASSO96_Unlock();
+    PICASSO96_Unlock();
 #endif
+    DX_Invalidate (x, y, orig_width, orig_height);
 }
 
 /*
@@ -663,82 +625,90 @@ out:;
 * must do it by hand using the data in the frame-buffer, calculated using
 * the RenderInfo data and our coordinates.
 */
-static void do_blit( struct RenderInfo *ri, int Bpp, 
-           unsigned int srcx, unsigned int srcy, unsigned int dstx, unsigned int dsty,
-           unsigned int width, unsigned int height, BLIT_OPCODE opcode, int can_do_blit)
+static void do_blit(struct RenderInfo *ri, int Bpp, 
+                   unsigned int srcx, unsigned int srcy,
+                   unsigned int dstx, unsigned int dsty,
+                   unsigned int width, unsigned int height,
+                   BLIT_OPCODE opcode, int can_do_blit)
 {
     uae_u8 *dstp, *srcp;
-    int orig_height = height;
+    int orig_width, orig_height;
 
-    if(picasso96_state.BigAssBitmap && can_do_blit){
-       srcx=dstx;
-       srcy=dsty;
-       can_do_blit=0;
+    if(picasso96_state.BigAssBitmap && can_do_blit) {
+       srcx = dstx;
+       srcy = dsty;
+       can_do_blit = 0;
     } //hack to use cpu rotines for scrolling in big Screens
     if (picasso96_state.XOffset < 0)
        can_do_blit = 0;
     
-    dstx=dstx-picasso96_state.XOffset;
-    dsty=dsty-picasso96_state.YOffset;
-    if((int)dstx<=0){
-       srcx=srcx-dstx;
-       dstx=0;
+    dstx = dstx - picasso96_state.XOffset;
+    dsty = dsty - picasso96_state.YOffset;
+    if((int)dstx <= 0) {
+       srcx = srcx - dstx;
+       dstx = 0;
     }
-    if((int)dsty<=0){
-       srcy=srcy-dsty;
-       dsty=0;
+    if((int)dsty <= 0) {
+       srcy = srcy - dsty;
+       dsty = 0;
     }
 
 #ifdef LOCK_UNLOCK_MADNESS
 #ifdef PIXEL_LOCK
-       flushpixels();
+    flushpixels();
 #endif
-    //PICASSO96_Lock();
 #endif
     /* Is our x/y origin on-screen? */
-    if( dsty >= picasso_vidinfo.height )
+    if(dsty >= picasso_vidinfo.height)
        return;
-    if( dstx >= picasso_vidinfo.width )
+    if(dstx >= picasso_vidinfo.width)
        return;
 
     /* Is our area in-range? */
-    if( dsty+height >= picasso_vidinfo.height )
+    if(dsty + height >= picasso_vidinfo.height)
        height = picasso_vidinfo.height - dsty;
-    if( dstx+width >= picasso_vidinfo.width )
+    if(dstx + width >= picasso_vidinfo.width)
        width = picasso_vidinfo.width - dstx;
 
-    if (can_do_blit) 
-    {
+    orig_height = height;
+    orig_width = width;
+
+    if (can_do_blit)  {
        //
        // Call OS blitting function that can do it in video memory.
        // Should return if it was successful
        //
-       if( DX_Blit( srcx, srcy, dstx, dsty, width, height, opcode ) )
+       if(DX_Blit(srcx, srcy, dstx, dsty, width, height, opcode))
            return;
+       srcx = dstx;
+       srcy = dsty;
+    }
+    if (opcode != BLIT_SRC) {
+       write_log("do_blit() opcode = %d!\n", opcode);
+       return;
     }
+
 #ifdef LOCK_UNLOCK_MADNESS
-       PICASSO96_Lock();
+    PICASSO96_Lock();
 #endif
 
-    srcp = ri->Memory + srcx*Bpp + srcy*ri->BytesPerRow;
+    srcp = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow;
 
-    DX_Invalidate (dsty, dsty + height - 1);
     if (! picasso_vidinfo.extra_mem)
-       {
+    {
     #ifdef LOCK_UNLOCK_MADNESS
-    goto out;
+       goto out;
     #else 
-    return;
+       return;
     #endif
-       }
+    }
 
 #ifdef LOCK_UNLOCK_MADNESS
     dstp = picasso96_state.HostAddress;
 #else
     dstp = gfx_lock_picasso ();
 #endif
-    if (dstp == 0)
-    {
+    if (dstp == 0) {
        write_log ("WARNING: do_blit() couldn't lock\n");
        goto out;
     }
@@ -746,9 +716,9 @@ static void do_blit( struct RenderInfo *ri, int Bpp,
     /* The areas can't overlap: the source is always in the Picasso frame buffer,
     * and the destination is a different buffer owned by the graphics code.  */
     dstp += dsty * picasso_vidinfo.rowbytes + dstx * picasso_vidinfo.pixbytes;
-    P96TRACE(("do_blit with srcp 0x%x, dstp 0x%x, dst_rowbytes %d, srcx %d, srcy %d, dstx %d, dsty %d, w %d, h %d, dst_pixbytes %d\n",
+    P96TRACE(("do_blit with srcp %p, dstp %p, dst_rowbytes %d, srcx %d, srcy %d, dstx %d, dsty %d, w %d, h %d, dst_pixbytes %d\n",
        srcp, dstp, picasso_vidinfo.rowbytes, srcx, srcy, dstx, dsty, width, height, picasso_vidinfo.pixbytes));
-    P96TRACE(("gfxmem is at 0x%x\n",gfxmemory));
+    P96TRACE(("gfxmem is at %p\n", gfxmemory));
        
     if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) 
     {
@@ -793,13 +763,13 @@ static void do_blit( struct RenderInfo *ri, int Bpp,
            dstp += picasso_vidinfo.rowbytes;
        }
     }
-    out:
+    out:;
 #ifndef LOCK_UNLOCK_MADNESS
     gfx_unlock_picasso ();
 #else
     PICASSO96_Unlock();
 #endif
-    ;
+    DX_Invalidate (dstx, dsty, orig_width, orig_height);
 }
 
 /*
@@ -807,14 +777,15 @@ static void do_blit( struct RenderInfo *ri, int Bpp,
 * so that do_blit can be used if
 * there is no OS specific function to invert the rectangle.
 */
-static void do_invertrect( struct RenderInfo *ri, int Bpp, int x, int y, int width, int height)
+static void do_invertrect(struct RenderInfo *ri, int Bpp, int x, int y, int width, int height)
 {
-   /* if( DX_InvertRect( x, y, width, height ) )
+   /* if(DX_InvertRect(x, y, width, height))
        return;*/  //deactivate in 0.8.20 
     P96TRACE(("do_invertrect falling back to do_blit!\n"));
     do_blit (ri, Bpp, x, y, x, y, width, height, BLIT_SRC, 0);
 }
 
+#if 0
 static uaecptr wgfx_linestart;
 static uaecptr wgfx_lineend;
 static uaecptr wgfx_min, wgfx_max;
@@ -825,31 +796,31 @@ static void wgfx_do_flushline (void)
     uae_u8 *src, *dstp;
 
     /* Mark these lines as "dirty" */
-    DX_Invalidate (wgfx_y, wgfx_y);
 
     if (! picasso_vidinfo.extra_mem) /* The "out" will flush the dirty lines directly */
        goto out;
     
 #ifdef LOCK_UNLOCK_MADNESS
     dstp = picasso96_state.HostAddress;
-
 #else
     dstp = gfx_lock_picasso ();
 #endif
      if (dstp == 0)
        goto out;
+
 #if P96TRACING_LEVEL > 0
     P96TRACE(("flushing %d\n", wgfx_y));
 #endif
+
     src = gfxmemory + wgfx_min;
     
-    if( picasso_vidinfo.rgbformat == picasso96_state.RGBFormat )
+    if(picasso_vidinfo.rgbformat == picasso96_state.RGBFormat)
     {
 #if P96TRACING_LEVEL > 0
        P96TRACE(("flushing type-a\n"));
 #endif
        dstp += wgfx_y * picasso_vidinfo.rowbytes + wgfx_min - wgfx_linestart;
-               memcpy (dstp, src, wgfx_max - wgfx_min);
+       memcpy (dstp, src, wgfx_max - wgfx_min);
     }
     else
     {
@@ -884,6 +855,7 @@ out:
 #ifndef LOCK_UNLOCK_MADNESS
     gfx_unlock_picasso ();
 #endif
+    DX_Invalidate (0, wgfx_y, -1, 1);
 
     wgfx_linestart = 0xFFFFFFFF;
 }
@@ -894,6 +866,7 @@ STATIC_INLINE void wgfx_flushline (void)
        return;
     wgfx_do_flushline ();
 }
+#endif
 
 static int renderinfo_is_current_screen (struct RenderInfo *ri)
 {
@@ -908,7 +881,7 @@ static int renderinfo_is_current_screen (struct RenderInfo *ri)
 /*
 * Fill a rectangle in the screen.
 */
-STATIC_INLINE void do_fillrect_frame_buffer( struct RenderInfo *ri, int X, int Y, int Width, int Height, uae_u32 Pen, int Bpp, RGBFTYPE RGBFormat )
+static void do_fillrect_frame_buffer(struct RenderInfo *ri, int X, int Y, int Width, int Height, uae_u32 Pen, int Bpp, RGBFTYPE RGBFormat)
 {
     int cols;
     uae_u8 *start, *oldstart;
@@ -916,7 +889,7 @@ STATIC_INLINE void do_fillrect_frame_buffer( struct RenderInfo *ri, int X, int Y
     int lines;
 
     /* Do our virtual frame-buffer memory.  First, we do a single line fill by hand */
-    oldstart = start = src = ri->Memory + X*Bpp + Y*ri->BytesPerRow;
+    oldstart = start = src = ri->Memory + X * Bpp + Y * ri->BytesPerRow;
     
     switch (Bpp) 
     {
@@ -951,31 +924,31 @@ STATIC_INLINE void do_fillrect_frame_buffer( struct RenderInfo *ri, int X, int Y
     src = oldstart;
     dst = src + ri->BytesPerRow;
     /* next, we do the remaining line fills via memcpy() for > 1 BPP, otherwise some more memset() calls */
-    if( Bpp > 1 )
+    if(Bpp > 1)
     {
-       for (lines = 0; lines < (Height - 1); lines++, dst += ri->BytesPerRow)
+       for (lines = 0; lines < Height - 1; lines++, dst += ri->BytesPerRow)
            memcpy (dst, src, Width * Bpp);
     }
     else
     {
-       for (lines = 0; lines < (Height - 1); lines++, dst += ri->BytesPerRow)
-           memset( dst, Pen, Width );
+       for (lines = 0; lines < Height - 1; lines++, dst += ri->BytesPerRow)
+           memset(dst, Pen, Width);
     }
 }
 
 void picasso_handle_vsync (void)
 {
-    DX_Invalidate(0,4000); //so a flushpixel is done every vsync if pixel are in buffer
+    flushpixels();
     PICASSO96_Unlock();
     if (palette_changed) {
        DX_SetPalette (0,256);
        palette_changed = 0;
     }
 
-    if (vsyncgfxwrite==1) {
+    if (vsyncgfxwrite == 1) {
        static long blitcount;
        vsyncgfxcount++;
-       if (vsyncgfxcount>1) {
+       if (vsyncgfxcount > 1) {
            if (picasso_on) {
                if (picasso96_state.RGBFormat == picasso_vidinfo.rgbformat
                    || picasso96_state.RGBFormat == RGBFB_CHUNKY) { 
@@ -1002,17 +975,18 @@ static int set_panning_called = 0;
 * 3. whenever the graphics code notifies us that the screen contents have been lost.
 */
 extern unsigned int new_beamcon0;
-void picasso_refresh ( int call_setpalette )
+void picasso_refresh (int call_setpalette)
 {
     struct RenderInfo ri;
     static int beamcon0_before, p96refresh_was;
     
-    if (! picasso_on)return;
+    if (! picasso_on)
+       return;
     {  //for higher P96 mousedraw rate
        /* HACK */
        extern uae_u16 vtotal;
        if (p96hack_vpos2) {
-           vtotal=p96hack_vpos2;
+           vtotal = p96hack_vpos2;
            beamcon0_before = new_beamcon0;
            new_beamcon0 |= 0x80;
            p96refresh_active = 1;
@@ -1027,9 +1001,9 @@ void picasso_refresh ( int call_setpalette )
                /* HACK until ntsc timing is fixed.. */
     } //end for higher P96 mousedraw rate
     have_done_picasso = 1;
-    
+
     /* Make sure that the first time we show a Picasso video mode, we don't blit any crap.
-    * We can do this by checking if we have an Address yet.  */
+     * We can do this by checking if we have an Address yet.  */
     if (picasso96_state.Address) {
        unsigned int width, height;
 
@@ -1038,18 +1012,18 @@ void picasso_refresh ( int call_setpalette )
        ri.BytesPerRow = picasso96_state.BytesPerRow;
        ri.RGBFormat = picasso96_state.RGBFormat;
 
-       if( set_panning_called )
+       if(set_panning_called)
        {
-           width = ( picasso96_state.VirtualWidth < picasso96_state.Width ) ?
+           width = (picasso96_state.VirtualWidth < picasso96_state.Width) ?
                picasso96_state.VirtualWidth : picasso96_state.Width;
-           height = ( picasso96_state.VirtualHeight < picasso96_state.Height ) ?
+           height = (picasso96_state.VirtualHeight < picasso96_state.Height) ?
                picasso96_state.VirtualHeight : picasso96_state.Height;
            // Let's put a black-border around the case where we've got a sub-screen...
-           if( !picasso96_state.BigAssBitmap )
+           if(!picasso96_state.BigAssBitmap)
            {
                if (picasso96_state.XOffset || picasso96_state.YOffset)
-                   DX_Fill( 0, 0, picasso96_state.Width, picasso96_state.Height, 0,
-                       picasso96_state.RGBFormat );
+                   DX_Fill(0, 0, picasso96_state.Width, picasso96_state.Height, 0,
+                       picasso96_state.RGBFormat);
            }
        }
        else
@@ -1069,236 +1043,11 @@ void picasso_refresh ( int call_setpalette )
 /*
 * Functions to perform an action on the frame-buffer
 */
-STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct
-RenderInfo *dstri, unsigned long srcx, unsigned long srcy,
-    unsigned long dstx, unsigned long dsty, unsigned long width, unsigned
-long height, uae_u8 mask, BLIT_OPCODE opcode )
-{
-    
-    uae_u8 *src, *dst, *tmp, *tmp2, *tmp3;
-    uae_u8 Bpp = GetBytesPerPixel(ri->RGBFormat);
-    unsigned long total_width = width * Bpp;
-    unsigned long linewidth = (total_width + 15) & ~15;
-    unsigned long lines;
-    int can_do_visible_blit = 0;
-
-    src = ri->Memory + srcx*Bpp + srcy*ri->BytesPerRow;
-    dst = dstri->Memory + dstx*Bpp + dsty*dstri->BytesPerRow;
-    if (mask != 0xFF && Bpp > 1)
-    {
-    write_log ("WARNING - BlitRect() has mask 0x%x with Bpp %d.\n", mask, Bpp);
-    }
-    
-    if (mask == 0xFF || Bpp > 1) 
-    {
-    if( opcode == BLIT_SRC )
-    {
-       /* handle normal case efficiently */
-       if (ri->Memory == dstri->Memory && dsty == srcy) 
-       {
-       unsigned long i;
-       for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
-           memmove (dst, src, total_width);
-       }
-       else if (dsty < srcy) 
-       {
-       unsigned long i;
-       for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
-           memcpy (dst, src, total_width);
-       }
-       else
-       {
-       unsigned long i;
-       src += (height-1) * ri->BytesPerRow;
-       dst += (height-1) * dstri->BytesPerRow;
-       for (i = 0; i < height; i++, src -= ri->BytesPerRow, dst -= dstri->BytesPerRow)
-           memcpy (dst, src, total_width);
-       }
-       return;
-    }
-    else
-    {
-       uae_u8 *src2 = src;
-       uae_u8 *dst2 = dst;
-       uae_u32 *src2_32 = (uae_u32*)src;
-       uae_u32 *dst2_32 = (uae_u32*)dst;
-       unsigned int y;
-       
-       for( y = 0; y < height; y++ ) /* Vertical lines */
-       {
-       uae_u8 *bound = src + total_width - 4;
-       //copy now the longs
-       for( src2_32 = src, dst2_32 = dst; src2_32 < bound; src2_32++, dst2_32++ ) /* Horizontal bytes */
-       {
-           switch( opcode )
-           {
-           case BLIT_FALSE:
-           *dst2_32 = 0;
-           break;
-           case BLIT_NOR:
-           *dst2_32 = ~(*src2_32 | *dst2_32);
-           break;
-           case BLIT_ONLYDST:
-           *dst2_32 = *dst2_32 & ~(*src2_32);
-           break;
-           case BLIT_NOTSRC:
-           *dst2_32 = ~(*src2_32);
-           break;
-           case BLIT_ONLYSRC:
-           *dst2_32 = *src2_32 & ~(*dst2_32);
-           break;
-           case BLIT_NOTDST:
-           *dst2_32 = ~(*dst2_32);
-           break;
-           case BLIT_EOR:
-           *dst2_32 = *src2_32 ^ *dst2_32;
-           break;
-           case BLIT_NAND:
-           *dst2_32 = ~(*src2_32 & *dst2_32);
-           break;
-           case BLIT_AND:
-           *dst2_32 = *src2_32 & *dst2_32;
-           break;
-           case BLIT_NEOR:
-           *dst2_32 = ~(*src2_32 ^ *dst2_32);
-           break;
-           case BLIT_DST:
-           write_log( "do_blitrect_frame_buffer shouldn't get BLIT_DST!\n");
-           break;
-           case BLIT_NOTONLYSRC:
-           *dst2_32 = ~(*src2_32) | *dst2_32;
-           break;
-           case BLIT_SRC:
-           write_log( "do_blitrect_frame_buffer shouldn't get BLIT_SRC!\n");
-           break;
-           case BLIT_NOTONLYDST:
-           *dst2_32 = ~(*dst2_32) | *src2_32;
-           break;
-           case BLIT_OR:
-           *dst2_32 = *src2_32 | *dst2_32;
-           break;
-           case BLIT_TRUE:
-           *dst2_32 = 0xFFFFFFFF;
-           break;
-           case 30: //code for swap source with dest in byte
-           {       
-               uae_u32 temp;
-               temp = *src2_32;
-               *src2_32 = *dst2_32;
-               *dst2_32 = temp;
-           }
-           break;
-           case BLIT_LAST:
-           write_log( "do_blitrect_frame_buffer shouldn't get BLIT_LAST!\n");
-           break;
-           } /* switch opcode */
-       }// for end
-       //now copy the rest few bytes
-       for( src2 = src2_32, dst2 = dst2_32; src2 < src + total_width; src2++, dst2++ ) /* Horizontal bytes */
-       {
-           switch( opcode )
-           {
-           case BLIT_FALSE:
-           *dst2 = 0;
-           break;
-           case BLIT_NOR:
-           *dst2 = ~(*src2 | *dst2);
-           break;
-           case BLIT_ONLYDST:
-           *dst2 = *dst2 & ~(*src2);
-           break;
-           case BLIT_NOTSRC:
-           *dst2 = ~(*src2);
-           break;
-           case BLIT_ONLYSRC:
-           *dst2 = *src2 & ~(*dst2);
-           break;
-           case BLIT_NOTDST:
-           *dst2 = ~(*dst2);
-           break;
-           case BLIT_EOR:
-           *dst2 = *src2 ^ *dst2;
-           break;
-           case BLIT_NAND:
-           *dst2 = ~(*src2 & *dst2);
-           break;
-           case BLIT_AND:
-           *dst2 = *src2 & *dst2;
-           break;
-           case BLIT_NEOR:
-           *dst2 = ~(*src2 ^ *dst2);
-           break;
-           case BLIT_DST:
-           write_log( "do_blitrect_frame_buffer shouldn't get BLIT_DST!\n");
-           break;
-           case BLIT_NOTONLYSRC:
-           *dst2 = ~(*src2) | *dst2;
-           break;
-           case BLIT_SRC:
-           write_log( "do_blitrect_frame_buffer shouldn't get BLIT_SRC!\n");
-           break;
-           case BLIT_NOTONLYDST:
-           *dst2 = ~(*dst2) | *src2;
-           break;
-           case BLIT_OR:
-           *dst2 = *src2 | *dst2;
-           break;
-           case BLIT_TRUE:
-           *dst2 = 0xFF;
-           break;
-           case BLIT_LAST:
-           write_log( "do_blitrect_frame_buffer shouldn't get BLIT_LAST!\n");
-           break;
-           case 30: //code for swap source with dest in long
-               {
-               uae_u8 temp;
-               temp = *src2;
-               *src2 = *dst2;
-               *dst2 = temp;
-               }
-           break;
-           } /* switch opcode */
-       } /* for width */
-       src += ri->BytesPerRow;
-       dst += dstri->BytesPerRow;
-       } /* for height */
-    }
-    return;
-       }
-
-    tmp3 = tmp2 = tmp = xmalloc (linewidth * height); /* allocate enough
-memory for the src-rect        */
-    if (!tmp)
-    return;
-
-    /* copy the src-rect into our temporary buffer space */
-    for (lines = 0; lines < height; lines++, src += ri->BytesPerRow, tmp2 +=
-linewidth) 
-    {
-    memcpy (tmp2, src, total_width);
-    }
-
-    /* copy the temporary buffer to the destination */
-    for (lines = 0; lines < height; lines++, dst += dstri->BytesPerRow, tmp
-+= linewidth) 
-    {
-    unsigned long cols;
-    for (cols = 0; cols < width; cols++) 
-    {
-       dst[cols] &= ~mask;
-       dst[cols] |= tmp[cols] & mask;
-    }
-    }
-    /* free the temp-buf */
-    free (tmp3);
-} 
-
-#if 0
-/*
-* Functions to perform an action on the frame-buffer
-*/
-STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct RenderInfo *dstri, unsigned long srcx, unsigned long srcy,
-    unsigned long dstx, unsigned long dsty, unsigned long width, unsigned long height, uae_u8 mask, BLIT_OPCODE opcode )
+static void do_blitrect_frame_buffer(struct RenderInfo *ri, struct RenderInfo *dstri,
+                                   unsigned long srcx, unsigned long srcy,
+                                   unsigned long dstx, unsigned long dsty,
+                                   unsigned long width, unsigned long height,
+                                   uae_u8 mask, BLIT_OPCODE opcode)
 {
     
     uae_u8 *src, *dst, *tmp, *tmp2, *tmp3;
@@ -1308,8 +1057,8 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
     unsigned long lines;
     int can_do_visible_blit = 0;
 
-    src = ri->Memory + srcx*Bpp + srcy*ri->BytesPerRow;
-    dst = dstri->Memory + dstx*Bpp + dsty*dstri->BytesPerRow;
+    src = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow;
+    dst = dstri->Memory + dstx * Bpp + dsty * dstri->BytesPerRow;
     if (mask != 0xFF && Bpp > 1)
     {
        write_log ("WARNING - BlitRect() has mask 0x%x with Bpp %d.\n", mask, Bpp);
@@ -1317,10 +1066,10 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
     
     if (mask == 0xFF || Bpp > 1) 
     {
-       if( opcode == BLIT_SRC )
+       if(opcode == BLIT_SRC)
        {
            /* handle normal case efficiently */
-           if (ri->Memory == dstri->Memory && dsty == srcy) 
+           if (ri->Memory == dstri->Memory && dsty == srcy)
            {
                unsigned long i;
                for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
@@ -1335,8 +1084,8 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
            else
            {
                unsigned long i;
-               src += (height-1) * ri->BytesPerRow;
-               dst += (height-1) * dstri->BytesPerRow;
+               src += (height - 1) * ri->BytesPerRow;
+               dst += (height - 1) * dstri->BytesPerRow;
                for (i = 0; i < height; i++, src -= ri->BytesPerRow, dst -= dstri->BytesPerRow)
                    memcpy (dst, src, total_width);
            }
@@ -1344,67 +1093,145 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
        }
        else
        {
-           uae_u8 *src2 = src;
-           uae_u8 *dst2 = dst;
+           uae_u8 *src2;
+           uae_u8 *dst2;
            unsigned int y;
-           
-           for( y = 0; y < height; y++ ) /* Vertical lines */
+
+           for(y = 0; y < height; y++) /* Vertical lines */
            {
-               for( src2 = src, dst2 = dst; src2 < src + total_width; src2++, dst2++ ) /* Horizontal bytes */
+               uae_u8 *bound = src + total_width - 4;
+               uae_u32 *src2_32;
+               uae_u32 *dst2_32;
+               //copy now the longs
+               for(src2_32 = (uae_u32*)src, dst2_32 = (uae_u32*)dst; src2_32 < (uae_u32*)bound; src2_32++, dst2_32++) /* Horizontal bytes */
                {
-                   switch( opcode )
+                   switch(opcode)
                    {
                    case BLIT_FALSE:
-                       *dst2 = 0;
-                       break;
+                   *dst2_32 = 0;
+                   break;
                    case BLIT_NOR:
-                       *dst2 = ~(*src2 | *dst2);
-                       break;
+                   *dst2_32 = ~(*src2_32 | *dst2_32);
+                   break;
                    case BLIT_ONLYDST:
-                       *dst2 = *dst2 & ~(*src2);
-                       break;
+                   *dst2_32 = *dst2_32 & ~(*src2_32);
+                   break;
                    case BLIT_NOTSRC:
-                       *dst2 = ~(*src2);
-                       break;
+                   *dst2_32 = ~(*src2_32);
+                   break;
                    case BLIT_ONLYSRC:
-                       *dst2 = *src2 & ~(*dst2);
-                       break;
+                   *dst2_32 = *src2_32 & ~(*dst2_32);
+                   break;
                    case BLIT_NOTDST:
-                       *dst2 = ~(*dst2);
-                       break;
+                   *dst2_32 = ~(*dst2_32);
+                   break;
                    case BLIT_EOR:
-                       *dst2 = *src2 ^ *dst2;
-                       break;
+                   *dst2_32 = *src2_32 ^ *dst2_32;
+                   break;
                    case BLIT_NAND:
-                       *dst2 = ~(*src2 & *dst2);
-                       break;
+                   *dst2_32 = ~(*src2_32 & *dst2_32);
+                   break;
                    case BLIT_AND:
-                       *dst2 = *src2 & *dst2;
-                       break;
+                   *dst2_32 = *src2_32 & *dst2_32;
+                   break;
                    case BLIT_NEOR:
-                       *dst2 = ~(*src2 ^ *dst2);
-                       break;
+                   *dst2_32 = ~(*src2_32 ^ *dst2_32);
+                   break;
                    case BLIT_DST:
-                       write_log( "do_blitrect_frame_buffer shouldn't get BLIT_DST!\n" );
-                       break;
+                   write_log( "do_blitrect_frame_buffer shouldn't get BLIT_DST!\n");
+                   break;
                    case BLIT_NOTONLYSRC:
-                       *dst2 = ~(*src2) | *dst2;
-                       break;
+                   *dst2_32 = ~(*src2_32) | *dst2_32;
+                   break;
                    case BLIT_SRC:
-                       write_log( "do_blitrect_frame_buffer shouldn't get BLIT_SRC!\n" );
-                       break;
+                   write_log( "do_blitrect_frame_buffer shouldn't get BLIT_SRC!\n");
+                   break;
                    case BLIT_NOTONLYDST:
-                       *dst2 = ~(*dst2) | *src2;
-                       break;
+                   *dst2_32 = ~(*dst2_32) | *src2_32;
+                   break;
                    case BLIT_OR:
-                       *dst2 = *src2 | *dst2;
-                       break;
+                   *dst2_32 = *src2_32 | *dst2_32;
+                   break;
                    case BLIT_TRUE:
-                       *dst2 = 0xFF;
-                       break;
+                   *dst2_32 = 0xFFFFFFFF;
+                   break;
+                   case 30: //code for swap source with dest in byte
+                   {       
+                       uae_u32 temp;
+                       temp = *src2_32;
+                       *src2_32 = *dst2_32;
+                       *dst2_32 = temp;
+                   }
+                   break;
                    case BLIT_LAST:
-                       write_log( "do_blitrect_frame_buffer shouldn't get BLIT_LAST!\n" );
-                       break;
+                   write_log( "do_blitrect_frame_buffer shouldn't get BLIT_LAST!\n");
+                   break;
+                   } /* switch opcode */
+               }// for end
+               //now copy the rest few bytes
+               for(src2 = (uae_u8*)src2_32, dst2 = (uae_u8*)dst2_32; src2 < src + total_width; src2++, dst2++) /* Horizontal bytes */
+               {
+                   switch(opcode)
+                   {
+                   case BLIT_FALSE:
+                   *dst2 = 0;
+                   break;
+                   case BLIT_NOR:
+                   *dst2 = ~(*src2 | *dst2);
+                   break;
+                   case BLIT_ONLYDST:
+                   *dst2 = *dst2 & ~(*src2);
+                   break;
+                   case BLIT_NOTSRC:
+                   *dst2 = ~(*src2);
+                   break;
+                   case BLIT_ONLYSRC:
+                   *dst2 = *src2 & ~(*dst2);
+                   break;
+                   case BLIT_NOTDST:
+                   *dst2 = ~(*dst2);
+                   break;
+                   case BLIT_EOR:
+                   *dst2 = *src2 ^ *dst2;
+                   break;
+                   case BLIT_NAND:
+                   *dst2 = ~(*src2 & *dst2);
+                   break;
+                   case BLIT_AND:
+                   *dst2 = *src2 & *dst2;
+                   break;
+                   case BLIT_NEOR:
+                   *dst2 = ~(*src2 ^ *dst2);
+                   break;
+                   case BLIT_DST:
+                   write_log("do_blitrect_frame_buffer shouldn't get BLIT_DST!\n");
+                   break;
+                   case BLIT_NOTONLYSRC:
+                   *dst2 = ~(*src2) | *dst2;
+                   break;
+                   case BLIT_SRC:
+                   write_log("do_blitrect_frame_buffer shouldn't get BLIT_SRC!\n");
+                   break;
+                   case BLIT_NOTONLYDST:
+                   *dst2 = ~(*dst2) | *src2;
+                   break;
+                   case BLIT_OR:
+                   *dst2 = *src2 | *dst2;
+                   break;
+                   case BLIT_TRUE:
+                   *dst2 = 0xFF;
+                   break;
+                   case BLIT_LAST:
+                   write_log("do_blitrect_frame_buffer shouldn't get BLIT_LAST!\n");
+                   break;
+                   case 30: //code for swap source with dest in long
+                   {
+                       uae_u8 temp;
+                       temp = *src2;
+                       *src2 = *dst2;
+                       *dst2 = temp;
+                   }
+                   break;
                    } /* switch opcode */
                } /* for width */
                src += ri->BytesPerRow;
@@ -1412,11 +1239,11 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
            } /* for height */
        }
        return;
-       }
+    }
 
     tmp3 = tmp2 = tmp = xmalloc (linewidth * height); /* allocate enough memory for the src-rect */
     if (!tmp)
-       return;
+        return;
 
     /* copy the src-rect into our temporary buffer space */
     for (lines = 0; lines < height; lines++, src += ri->BytesPerRow, tmp2 += linewidth) 
@@ -1425,7 +1252,7 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
     }
 
     /* copy the temporary buffer to the destination */
-    for (lines = 0; lines < height; lines++, dst += dstri->BytesPerRow, tmp += linewidth) 
+    for (lines = 0; lines < height; lines++, dst += dstri->BytesPerRow, tmp+= linewidth) 
     {
        unsigned long cols;
        for (cols = 0; cols < width; cols++) 
@@ -1435,9 +1262,8 @@ STATIC_INLINE void do_blitrect_frame_buffer( struct RenderInfo *ri, struct Rende
        }
     }
     /* free the temp-buf */
-    free (tmp3);
-}
-#endif
+    xfree (tmp3);
+} 
 
 /*
 DrawLine: 
@@ -1503,25 +1329,25 @@ to account for possible screen panning.
 uae_u32 picasso_SetSpritePosition (void)
 {
     uae_u32 result = 0;
-    uaecptr bi = m68k_areg( regs, 0 );
-    uae_u16 MouseX  = get_word( bi + PSSO_BoardInfo_MouseX ) - picasso96_state.XOffset;
-    uae_u16 MouseY  = get_word( bi + PSSO_BoardInfo_MouseY ) - picasso96_state.YOffset;
+    uaecptr bi = m68k_areg(regs, 0);
+    uae_u16 MouseX  = get_word(bi + PSSO_BoardInfo_MouseX) - picasso96_state.XOffset;
+    uae_u16 MouseY  = get_word(bi + PSSO_BoardInfo_MouseY) - picasso96_state.YOffset;
     
     // Keep these around, because we don't want flickering
     static uae_u16 OldMouseX = -1;
     static uae_u16 OldMouseY = -1;
 
     // Bounds check MouseX and MouseY here, because sometimes they seem to go negative...
-    if( (uae_s16)MouseX < 0 )
+    if((uae_s16)MouseX < 0)
        MouseX = 0;
-    if( (uae_s16)MouseY < 0 )
+    if((uae_s16)MouseY < 0)
        MouseY = 0;
 
-    if( ( MouseX != OldMouseX ) || ( MouseY != OldMouseY ) )
+    if((MouseX != OldMouseX) || (MouseY != OldMouseY))
     {
-       result = DX_MoveCursor( MouseX, MouseY );
+       result = DX_MoveCursor(MouseX, MouseY);
        write_log ("SetSpritePosition() - moving cursor to (%d,%d), result = %d\n", MouseX, MouseY, result);
-       if( result )
+       if(result)
        {
            OldMouseX = MouseX;
            OldMouseY = MouseY;
@@ -1838,7 +1664,7 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs)
        amigamemptr = gfxmem_start + allocated_gfxmem - 16384 + (PSSO_LibResolution_sizeof * LibResolutionStructureCount++);
        CopyLibResolutionStructureU2A (&res, amigamemptr);
 #if defined P96TRACING_ENABLED && P96TRACING_LEVEL > 1
-       DumpLibResolutionStructure( amigamemptr);
+       DumpLibResolutionStructure(amigamemptr);
 #endif
        AmigaListAddTail (AmigaBoardInfo + PSSO_BoardInfo_ResolutionsList, amigamemptr);
     }
@@ -1846,8 +1672,6 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs)
     return -1;
 }
 
-extern int x_size, y_size;
-
 /*
 * SetSwitch:
 * a0: struct BoardInfo
@@ -1868,7 +1692,7 @@ uae_u32 REGPARAM2 picasso_SetSwitch (struct regstruct *regs)
     * desired state, and wait for custom.c to call picasso_enablescreen
     * whenever it is ready to change the screen state.  */
     picasso_requested_on = flag;
-    write_log ("SetSwitch() - trying to show %s screen\n", flag ? "picasso96":"amiga");
+    write_log ("SetSwitch() - trying to show %s screen\n", flag ? "picasso96" : "amiga");
     
     /* Put old switch-state in D0 */
 
@@ -1877,7 +1701,9 @@ uae_u32 REGPARAM2 picasso_SetSwitch (struct regstruct *regs)
 
 void picasso_enablescreen (int on)
 {  
+#if 0
     wgfx_linestart = 0xFFFFFFFF;
+#endif
     picasso_refresh (1);
     write_log ("SetSwitch() from threadid %d - showing %s screen\n", GetCurrentThreadId(), on ? "picasso96": "amiga");
     checkrtglibrary();
@@ -1941,10 +1767,10 @@ uae_u32 REGPARAM2 picasso_SetDAC (struct regstruct *regs)
 }
 
 
-static void init_picasso_screen( void )
+static void init_picasso_screen(void)
 {
     if(set_panning_called) {
-       picasso96_state.Extent = picasso96_state.Address + ( picasso96_state.BytesPerRow * picasso96_state.VirtualHeight );
+       picasso96_state.Extent = picasso96_state.Address + (picasso96_state.BytesPerRow * picasso96_state.VirtualHeight);
     }
     if (set_gc_called) {
        gfx_set_picasso_modeinfo (picasso96_state.Width, picasso96_state.Height,
@@ -1986,7 +1812,7 @@ uae_u32 REGPARAM2 picasso_SetGC (struct regstruct *regs)
     picasso96_state.GC_Depth = get_byte (modeinfo + PSSO_ModeInfo_Depth);
     picasso96_state.GC_Flags = get_byte (modeinfo + PSSO_ModeInfo_Flags);
     
-    P96TRACE(("SetGC(%d,%d,%d,%d)\n", picasso96_state.Width, picasso96_state.Height, picasso96_state.GC_Depth, border ));
+    P96TRACE(("SetGC(%d,%d,%d,%d)\n", picasso96_state.Width, picasso96_state.Height, picasso96_state.GC_Depth, border));
     set_gc_called = 1;
     picasso96_state.HostAddress = NULL;
     init_picasso_screen ();
@@ -2022,26 +1848,26 @@ uae_u32 REGPARAM2 picasso_SetPanning (struct regstruct *regs)
     uae_u16 Width = m68k_dreg (regs, 0);
     uaecptr start_of_screen = m68k_areg (regs, 1);
     uaecptr bi = m68k_areg(regs, 0);
-    uaecptr bmeptr = get_long( bi + PSSO_BoardInfo_BitMapExtra );  /* Get our BoardInfo ptr's BitMapExtra ptr */
+    uaecptr bmeptr = get_long(bi + PSSO_BoardInfo_BitMapExtra);  /* Get our BoardInfo ptr's BitMapExtra ptr */
     uae_u16 bme_width, bme_height;
 
-    if(oldscr==0){
-       oldscr=start_of_screen;    
+    if(oldscr == 0) {
+       oldscr = start_of_screen;    
     }
-    if ((oldscr!=start_of_screen)){
+    if (oldscr != start_of_screen) {
        set_gc_called = 0;
-       oldscr=start_of_screen;
+       oldscr = start_of_screen;
     }
 
-    bme_width = get_word( bmeptr + PSSO_BitMapExtra_Width );
-    bme_height = get_word( bmeptr + PSSO_BitMapExtra_Height );
+    bme_width = get_word(bmeptr + PSSO_BitMapExtra_Width);
+    bme_height = get_word(bmeptr + PSSO_BitMapExtra_Height);
     
     picasso96_state.Address = start_of_screen; /* Amiga-side address */
     picasso96_state.XOffset = (uae_s16)(m68k_dreg (regs, 1) & 0xFFFF);
     picasso96_state.YOffset = (uae_s16)(m68k_dreg (regs, 2) & 0xFFFF);
     picasso96_state.VirtualWidth = bme_width;
     picasso96_state.VirtualHeight = bme_height;
-    if( ( bme_width > Width ) || ( bme_height > picasso96_state.Height ) ) // NOTE: These were != instead of > before...
+    if((bme_width > Width) || (bme_height > picasso96_state.Height)) // NOTE: These were != instead of > before...
        picasso96_state.BigAssBitmap = 1;
     else
        picasso96_state.BigAssBitmap = 0;
@@ -2085,7 +1911,7 @@ static void do_xor8 (uae_u8 *ptr, long len, uae_u32 val)
     return;
 #endif
     for (i = 0; i < len; i++, ptr++) {
-       do_put_mem_byte (ptr, (uae_u8)( do_get_mem_byte (ptr) ^ val ) );
+       do_put_mem_byte (ptr, (uae_u8)(do_get_mem_byte (ptr) ^ val));
     }
 }
 
@@ -2121,40 +1947,38 @@ uae_u32 REGPARAM2 picasso_InvertRect (struct regstruct *regs)
     unsigned long width_in_bytes;
     uae_u32 result = 0;
 
-  
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-#else 
-         wgfx_flushline ();    
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
+    wgfx_flushline ();    
 #endif
     
-    if ( CopyRenderInfoStructureA2U (renderinfo, &ri))
+    if (CopyRenderInfoStructureA2U (renderinfo, &ri))
     {
        P96TRACE(("InvertRect %dbpp 0x%lx\n", Bpp, (long)mask));
     
        if (mask != 0xFF && Bpp > 1) 
-       {
            mask = 0xFF;
-       }
 
        xorval = 0x01010101 * (mask & 0xFF);
        width_in_bytes = Bpp * Width;
-       rectstart = uae_mem = ri.Memory + Y*ri.BytesPerRow + X*Bpp;
+       rectstart = uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp;
     
        for (lines = 0; lines < Height; lines++, uae_mem += ri.BytesPerRow)
            do_xor8 (uae_mem, width_in_bytes, xorval);
     
-       if (vsyncgfxwrite==0) if (renderinfo_is_current_screen (&ri)) {
-           if (mask == 0xFF)
-               do_invertrect( &ri, Bpp, X, Y, Width, Height );
-           else
-               do_blit( &ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0);
+       if (vsyncgfxwrite == 0) {
+           if (renderinfo_is_current_screen (&ri)) {
+               if (mask == 0xFF)
+                   do_invertrect(&ri, Bpp, X, Y, Width, Height);
+               else
+                   do_blit(&ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0);
+           }
        }
        result = 1;
     }
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
+
     return result; /* 1 if supported, 0 otherwise */
 }
 
@@ -2188,17 +2012,14 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs)
     struct RenderInfo ri;
     uae_u32 result = 0;
 
-    if (Width * Height <= 2500)
-       return 0;
-    P96_SM_RS;
-
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock(); // We need this, because otherwise we're still Locked from custom.c
-#else
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
     wgfx_flushline ();
 #endif
     
-    if ( CopyRenderInfoStructureA2U (renderinfo, &ri) && Y != 0xFFFF)
+    if (CopyRenderInfoStructureA2U (renderinfo, &ri) && Y != 0xFFFF)
     {
        if (ri.RGBFormat != RGBFormat)
            write_log ("Weird Stuff!\n");
@@ -2208,69 +2029,77 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs)
        P96TRACE(("FillRect(%d, %d, %d, %d) Pen 0x%x BPP %d BPR %d Mask 0x%x\n",
            X, Y, Width, Height, Pen, Bpp, ri.BytesPerRow, Mask));
     
-       if( Bpp > 1 )
+       if(Bpp > 1)
            Mask = 0xFF;
     
        if (Mask == 0xFF) 
        {
-           if( ( Width == 1 ) || ( Height == 1 ) )
+           if((Width == 1) || (Height == 1))
            {
                int i;
                uaecptr addr;
-               if( renderinfo_is_current_screen( &ri ) )
+               if(renderinfo_is_current_screen(&ri))
                {
-                   uae_u32 diff=gfxmem_start-(uae_u32)gfxmemory;
-                   addr = ri.Memory + X*Bpp + Y*ri.BytesPerRow + diff;
-                   if( Width == 1 )
+                   uae_u32 diff = gfxmem_start - (uae_u32)gfxmemory; /* xxx this is sooo wrong.. */
+                   addr = ri.Memory + X * Bpp + Y * ri.BytesPerRow + diff;
+                   if(Width == 1)
                    {
-                       for( i = 0; i < Height; i++ )
+                       for(i = 0; i < Height; i++)
                        {
-                           if( Bpp == 4 )
-                               gfxmem_lput( addr + (i*picasso96_state.BytesPerRow ), Pen );
-                           else if( Bpp == 2 )
-                               gfxmem_wput( addr + (i*picasso96_state.BytesPerRow ), Pen );
+                           if(Bpp == 4)
+                               gfxmem_lput(addr + (i * picasso96_state.BytesPerRow), Pen);
+                           else if(Bpp == 2)
+                               gfxmem_wput(addr + (i * picasso96_state.BytesPerRow), Pen);
                            else
-                               gfxmem_bput( addr + (i*picasso96_state.BytesPerRow ), Pen );
+                               gfxmem_bput(addr + (i * picasso96_state.BytesPerRow), Pen);
                        }
                    }
-                   else if( Height == 1 )
+                   else if(Height == 1)
                    {
-                       for( i = 0; i < Width; i++ )
+                       for(i = 0; i < Width; i++)
                        {
-                           if( Bpp == 4 )
-                               gfxmem_lput( addr + (i*Bpp), Pen );
-                           else if( Bpp == 2 )
-                               gfxmem_wput( addr + (i*Bpp), Pen );
+                           if(Bpp == 4)
+                               gfxmem_lput(addr + (i * Bpp), Pen);
+                           else if(Bpp == 2)
+                               gfxmem_wput(addr + (i * Bpp), Pen);
                            else
-                               gfxmem_bput( addr + (i*Bpp), Pen );
+                               gfxmem_bput(addr + (i * Bpp), Pen);
                        }
                    }
                    return 1;
                }
            }
-
            /* Do the fill-rect in the frame-buffer */
-           do_fillrect_frame_buffer( &ri, X, Y, Width, Height, Pen, Bpp, RGBFormat ); 
+           do_fillrect_frame_buffer(&ri, X, Y, Width, Height, Pen, Bpp, RGBFormat);
            /* Now we do the on-screen display, if renderinfo points to it */
            if (renderinfo_is_current_screen (&ri))
            {
-               src = ri.Memory + X*Bpp + Y*ri.BytesPerRow;
-               X=X-picasso96_state.XOffset;
-               Y=Y-picasso96_state.YOffset;        
-               if((int)X<0){Width=Width+X;X=0;}
-               if((int)Width<1)return 1;
-               if((int)Y<0){Height=Height+Y;Y=0;}
-               if((int)Height<1)return 1;
+               src = ri.Memory + X * Bpp + Y * ri.BytesPerRow;
+               X = X - picasso96_state.XOffset;
+               Y = Y - picasso96_state.YOffset;            
+               if((int)X < 0) {
+                   Width = Width + X;
+                   X = 0;
+               }
+               if((int)Width < 1)
+                   return 1;
+               if((int)Y < 0) {
+                   Height = Height + Y;
+                   Y = 0;
+               }
+               if((int)Height < 1)
+                   return 1;
                /* Argh - why does P96Speed do this to me, with FillRect only?! */
-               if( ( X < picasso96_state.Width) &&
-                   ( Y < picasso96_state.Height) )
+               if((X < picasso96_state.Width) &&
+                   (Y < picasso96_state.Height))
                {
-                   if( X+Width > picasso96_state.Width)
+                   if(X + Width > picasso96_state.Width)
                        Width = picasso96_state.Width - X;
-                   if( Y+Height > picasso96_state.Height)
+                   if(Y + Height > picasso96_state.Height)
                        Height = picasso96_state.Height - Y;
 
-                   if (vsyncgfxwrite==0)do_fillrect( src, X, Y, Width, Height, Pen, Bpp, RGBFormat );
+                   if (vsyncgfxwrite == 0)
+                       do_fillrect(src, X, Y, Width, Height, Pen, Bpp, RGBFormat);
                }
            }
            result = 1;
@@ -2280,13 +2109,13 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs)
            /* We get here only if Mask != 0xFF */
            if (Bpp != 1) 
            {
-               write_log( "WARNING - FillRect() has unhandled mask 0x%x with Bpp %d. Using fall-back routine.\n", Mask, Bpp );
+               write_log("WARNING - FillRect() has unhandled mask 0x%x with Bpp %d. Using fall-back routine.\n", Mask, Bpp);
            }
            else
            {
                Pen &= Mask;
                Mask = ~Mask;
-               oldstart = ri.Memory + Y*ri.BytesPerRow + X*Bpp;
+               oldstart = ri.Memory + Y * ri.BytesPerRow + X * Bpp;
                {
                    uae_u8 *start = oldstart;
                    uae_u8 *end = start + Height * ri.BytesPerRow;
@@ -2297,20 +2126,18 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs)
                        for (cols = 0; cols < Width; cols++) 
                        {
                            uae_u32 tmpval = do_get_mem_byte (p + cols) & Mask;
-                           do_put_mem_byte (p + cols, (uae_u8)( Pen | tmpval ) );
+                           do_put_mem_byte (p + cols, (uae_u8)(Pen | tmpval));
                        }
                    }
                }
-               if (vsyncgfxwrite==0) if (renderinfo_is_current_screen (&ri))
-                   do_blit( &ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0);
+               if (vsyncgfxwrite == 0) {
+                   if (renderinfo_is_current_screen (&ri))
+                       do_blit(&ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0);
+               }
                result = 1;
            }
        }
     }
-
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
     return result;
 }
 
@@ -2352,7 +2179,7 @@ struct blitdata
     BLIT_OPCODE opcode;
 } blitrectdata;
 
-STATIC_INLINE int BlitRectHelper( void )
+static int BlitRectHelper(void)
 {
     struct RenderInfo *ri = blitrectdata.ri;
     struct RenderInfo *dstri = blitrectdata.dstri;
@@ -2366,13 +2193,11 @@ STATIC_INLINE int BlitRectHelper( void )
     BLIT_OPCODE opcode = blitrectdata.opcode;
     
     uae_u8 Bpp = GetBytesPerPixel(ri->RGBFormat);
-    unsigned long total_width = width * Bpp;
-    unsigned long linewidth = (total_width + 15) & ~15;
     int can_do_visible_blit = 0;
-    
-    if( opcode == BLIT_DST )
+
+    if(opcode == BLIT_DST)
     {
-       write_log( "WARNING: BlitRect() being called with opcode of BLIT_DST\n" );
+       write_log("WARNING: BlitRect() being called with opcode of BLIT_DST\n");
        return 1;
     }
     
@@ -2384,30 +2209,28 @@ STATIC_INLINE int BlitRectHelper( void )
     * If we have a destination RenderInfo, then we've been called from picasso_BlitRectNoMaskComplete()
     * and we need to put the results on the screen from the frame-buffer.
     */
-    //if (dstri->Memory == ri->Memory)
     if (dstri == NULL || dstri->Memory == ri->Memory)
     {
-       if( mask != 0xFF && Bpp > 1 ) 
-       {
+       if(mask != 0xFF && Bpp > 1) 
            mask = 0xFF;
-       }
        dstri = ri;
        can_do_visible_blit = 1;
     }
     
     /* Do our virtual frame-buffer memory first */
-    do_blitrect_frame_buffer( ri, dstri, srcx, srcy, dstx, dsty, width, height, mask, opcode );
+    do_blitrect_frame_buffer(ri, dstri, srcx, srcy, dstx, dsty, width, height, mask, opcode);
     /* Now we do the on-screen display, if renderinfo points to it */
-    if (vsyncgfxwrite==1)return 1;
-       if (renderinfo_is_current_screen (dstri))
+    if (vsyncgfxwrite == 1)
+       return 1;
+    if (renderinfo_is_current_screen (dstri))
     {
        if (mask == 0xFF || Bpp > 1) {
-           if( can_do_visible_blit )
-               do_blit( dstri, Bpp, srcx, srcy, dstx, dsty, width, height, opcode, 1 );
+           if(can_do_visible_blit)
+               do_blit(dstri, Bpp, srcx, srcy, dstx, dsty, width, height, opcode, 1);
            else
-               do_blit( dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0 );
+               do_blit(dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0);
        } else {
-           do_blit( dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0 );
+           do_blit(dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0);
        }
        P96TRACE(("Did do_blit 1 in BlitRect()\n"));
     }
@@ -2415,24 +2238,21 @@ STATIC_INLINE int BlitRectHelper( void )
     {
        P96TRACE(("Did not do_blit 1 in BlitRect()\n"));
     }
-    
+
     return 1;
 }
 
-STATIC_INLINE int BlitRect (uaecptr ri, uaecptr dstri,
+static int BlitRect (uaecptr ri, uaecptr dstri,
                unsigned long srcx, unsigned long srcy, unsigned long dstx, unsigned long dsty,
-               unsigned long width, unsigned long height, uae_u8 mask, BLIT_OPCODE opcode )
+               unsigned long width, unsigned long height, uae_u8 mask, BLIT_OPCODE opcode)
 {
     /* Set up the params */
-    CopyRenderInfoStructureA2U( ri, &blitrectdata.ri_struct );
+    CopyRenderInfoStructureA2U(ri, &blitrectdata.ri_struct);
     blitrectdata.ri = &blitrectdata.ri_struct;
-    if( dstri )
-    {
-       CopyRenderInfoStructureA2U( dstri, &blitrectdata.dstri_struct );
+    if(dstri) {
+       CopyRenderInfoStructureA2U(dstri, &blitrectdata.dstri_struct);
        blitrectdata.dstri = &blitrectdata.dstri_struct;
-    }
-    else
-    {
+    } else {
        blitrectdata.dstri = NULL;
     }
     blitrectdata.srcx = srcx;
@@ -2470,23 +2290,18 @@ uae_u32 REGPARAM2 picasso_BlitRect (struct regstruct *regs)
     unsigned long dsty = (uae_u16)m68k_dreg (regs, 3);
     unsigned long width = (uae_u16)m68k_dreg (regs, 4);
     unsigned long height = (uae_u16)m68k_dreg (regs, 5);
-    uae_u8  Mask = (uae_u8)m68k_dreg (regs, 6);
+    uae_u8 Mask = (uae_u8)m68k_dreg (regs, 6);
     uae_u32 result = 0;
 
-    P96_SM_RS;
-   
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-#else  
-    wgfx_flushline ();    
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
+    wgfx_flushline ();    
 #endif
-    
     P96TRACE(("BlitRect(%d, %d, %d, %d, %d, %d, 0x%x)\n", srcx, srcy, dstx, dsty, width, height, Mask));
-    result = BlitRect(renderinfo, (uaecptr)NULL, srcx, srcy, dstx, dsty, width, height, Mask, BLIT_SRC );
+    result = BlitRect(renderinfo, 0, srcx, srcy, dstx, dsty, width, height, Mask, BLIT_SRC);
 
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
     return result;
 }
 
@@ -2522,23 +2337,18 @@ uae_u32 REGPARAM2 picasso_BlitRectNoMaskComplete (struct regstruct *regs)
     uae_u32 RGBFmt = m68k_dreg (regs, 7);
     uae_u32 result = 0;
 
-    P96_SM_RS;
-    
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-
-#else
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
     wgfx_flushline ();   
 #endif
 
     P96TRACE(("BlitRectNoMaskComplete() op 0x%2x, xy(%4d,%4d) --> xy(%4d,%4d), wh(%4d,%4d)\n",
        OpCode, srcx, srcy, dstx, dsty, width, height));
     
-    result = BlitRect( srcri, dstri, srcx, srcy, dstx, dsty, width, height, 0xFF, OpCode );
+    result = BlitRect(srcri, dstri, srcx, srcy, dstx, dsty, width, height, 0xFF, OpCode);
 
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
     return result;
 }
 
@@ -2557,8 +2367,8 @@ STATIC_INLINE void PixelWrite2(uae_u8 *mem, int bits, uae_u32 fgpen)
 
 STATIC_INLINE void PixelWrite3(uae_u8 *mem, int bits, uae_u32 fgpen)
 {
-    do_put_mem_byte (mem + bits*3, fgpen & 0x000000FF);
-    *(uae_u16 *)(mem + bits*3+1) = (fgpen & 0x00FFFF00) >> 8;
+    do_put_mem_byte (mem + bits * 3, fgpen & 0x000000FF);
+    *(uae_u16 *)(mem + bits * 3 + 1) = (fgpen & 0x00FFFF00) >> 8;
 }
 
 STATIC_INLINE void PixelWrite4(uae_u8 *mem, int bits, uae_u32 fgpen)
@@ -2578,8 +2388,8 @@ STATIC_INLINE void PixelWrite(uae_u8 *mem, int bits, uae_u32 fgpen, uae_u8 Bpp,
        do_put_mem_word (((uae_u16 *)mem) + bits, (uae_u16)fgpen);
        break;
     case 3:
-       do_put_mem_byte (mem + bits*3, (uae_u8)fgpen);
-       *(uae_u16 *)(mem + bits*3+1) = (fgpen & 0x00FFFF00) >> 8;
+       do_put_mem_byte (mem + bits * 3, (uae_u8)fgpen);
+       *(uae_u16 *)(mem + bits * 3 + 1) = (fgpen & 0x00FFFF00) >> 8;
        break;
     case 4:
        do_put_mem_long (((uae_u32 *)mem) + bits, fgpen);
@@ -2630,19 +2440,17 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs)
     unsigned long ysize_mask;
     uae_u32 result = 0;
 
-    P96_SM_RS;
-   
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-
-#else  
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
     wgfx_flushline ();
 #endif
     
-    if( CopyRenderInfoStructureA2U (rinf, &ri) && CopyPatternStructureA2U (pinf, &pattern))
+    if(CopyRenderInfoStructureA2U (rinf, &ri) && CopyPatternStructureA2U (pinf, &pattern))
     {
        Bpp = GetBytesPerPixel(ri.RGBFormat);
-       uae_mem = ri.Memory + Y*ri.BytesPerRow + X*Bpp; /* offset with address */
+       uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset with address */
     
        if (pattern.DrawMode & INVERS)
            inversion = 1;
@@ -2650,10 +2458,10 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs)
        pattern.DrawMode &= 0x03;
        if (Mask != 0xFF) 
        {
-           if( Bpp > 1 )
+           if(Bpp > 1)
                Mask = 0xFF;
 
-           if( pattern.DrawMode == COMP)
+           if(pattern.DrawMode == COMP)
            {
                write_log ("WARNING - BlitPattern() has unhandled mask 0x%x with COMP DrawMode. Using fall-back routine.\n", Mask);
            }
@@ -2667,7 +2475,7 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs)
            result = 1;
        }
 
-       if( result )
+       if(result)
        {
            /* write_log ("BlitPattern() xy(%d,%d), wh(%d,%d) draw 0x%x, off(%d,%d), ph %d\n",
            X, Y, W, H, pattern.DrawMode, pattern.XOffset, pattern.YOffset, 1 << pattern.Size); */
@@ -2722,13 +2530,13 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs)
                                case 1:
                                    {
                                        uae_u8 *addr = uae_mem2 + bits;
-                                       do_put_mem_byte (addr, (uae_u8)( do_get_mem_byte (addr) ^ fgpen ) );
+                                       do_put_mem_byte (addr, (uae_u8)(do_get_mem_byte (addr) ^ fgpen));
                                    }
                                    break;
                                case 2:
                                    {
                                        uae_u16 *addr = ((uae_u16 *)uae_mem2) + bits;
-                                       do_put_mem_word (addr, (uae_u16)( do_get_mem_word (addr) ^ fgpen ) );
+                                       do_put_mem_word (addr, (uae_u16)( do_get_mem_word (addr) ^ fgpen));
                                    }
                                    break;
                                case 3:
@@ -2750,18 +2558,19 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs)
                    }
                }
            }
-    
-           /* If we need to update a second-buffer (extra_mem is set), then do it only if visible! */
-           if ( picasso_vidinfo.extra_mem && renderinfo_is_current_screen (&ri))
-               if (vsyncgfxwrite==0)do_blit( &ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0);
+           #ifdef PIXEL_LOCK
+           flushpixels();
+           #endif
 
+           /* If we need to update a second-buffer (extra_mem is set), then do it only if visible! */
+           if (picasso_vidinfo.extra_mem && renderinfo_is_current_screen (&ri)) {
+               if (vsyncgfxwrite==0)
+                   do_blit(&ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0);
+           }
            result = 1;
        }
     }
 
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
     return result;
 }
 
@@ -2803,17 +2612,14 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs)
     uae_u8 *tmpl_base;
     uae_u32 result = 0;
 
-//  if (W * H <= 2500)
-//     return 0;
-    P96_SM_RS;
-
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock(); // @@@ We need to unlock here, because do_blit (later) needs to lock...
-#else
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
     wgfx_flushline ();
 #endif
     
-    if ( CopyRenderInfoStructureA2U (rinf, &ri) && CopyTemplateStructureA2U (tmpl, &tmp))
+    if (CopyRenderInfoStructureA2U (rinf, &ri) && CopyTemplateStructureA2U (tmpl, &tmp))
     {
        Bpp = GetBytesPerPixel(ri.RGBFormat);
        uae_mem = ri.Memory + Y*ri.BytesPerRow + X*Bpp; /* offset into address */
@@ -2825,10 +2631,10 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs)
 
        if (Mask != 0xFF) 
        {
-           if( Bpp > 1 )
+           if(Bpp > 1)
                Mask = 0xFF;
 
-           if( tmp.DrawMode == COMP)
+           if(tmp.DrawMode == COMP)
            {
                write_log ("WARNING - BlitTemplate() has unhandled mask 0x%x with COMP DrawMode. Using fall-back routine.\n", Mask);
                flushpixels();  //only need in the windows Version
@@ -2850,18 +2656,18 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs)
            return 0;
        }
 #endif
-       if( result )
+       if(result)
        {
            P96TRACE(("BlitTemplate() xy(%d,%d), wh(%d,%d) draw 0x%x fg 0x%x bg 0x%x \n",
                X, Y, W, H, tmp.DrawMode, tmp.FgPen, tmp.BgPen));
     
            bitoffset = tmp.XOffset % 8;
     
-#if defined( P96TRACING_ENABLED        ) && ( P96TRACING_LEVEL > 0 )
+#if defined(P96TRACING_ENABLED) && (P96TRACING_LEVEL > 0)
            DumpTemplate(&tmp, W, H);
 #endif
     
-           tmpl_base = tmp.Memory + tmp.XOffset/8;
+           tmpl_base = tmp.Memory + tmp.XOffset / 8;
            
            for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow, tmpl_base += tmp.BytesPerRow) {
                unsigned long cols;
@@ -2911,13 +2717,13 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs)
                                case 1:
                                    {
                                        uae_u8 *addr = uae_mem2 + bits;
-                                       do_put_mem_byte (addr, (uae_u8)( do_get_mem_byte (addr) ^ fgpen ) );
+                                       do_put_mem_byte (addr, (uae_u8)(do_get_mem_byte (addr) ^ fgpen));
                                    }
                                    break;
                                case 2:
                                    {
                                        uae_u16 *addr = ((uae_u16 *)uae_mem2) + bits;
-                                       do_put_mem_word (addr, (uae_u16)( do_get_mem_word (addr) ^ fgpen ) );
+                                       do_put_mem_word (addr, (uae_u16)(do_get_mem_word (addr) ^ fgpen));
                                    }
                                    break;
                                case 3:
@@ -2940,16 +2746,17 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs)
                }
            }
            
+           #ifdef PIXEL_LOCK
+           flushpixels();
+           #endif
            /* If we need to update a second-buffer (extra_mem is set), then do it only if visible! */
-           if( picasso_vidinfo.extra_mem && renderinfo_is_current_screen( &ri ) )
-               if (vsyncgfxwrite==0)do_blit( &ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0 );
-           
+           if(picasso_vidinfo.extra_mem && renderinfo_is_current_screen(&ri)) {
+               if (vsyncgfxwrite == 0)
+                   do_blit(&ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0);
+           }
            result = 1;
        }
 }    
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
     return 1;
 }
 
@@ -2966,7 +2773,7 @@ uae_u32 REGPARAM2 picasso_CalculateBytesPerRow (struct regstruct *regs)
     uae_u16 width = m68k_dreg (regs, 0);
     uae_u32 type = m68k_dreg (regs, 7);
     
-    width = GetBytesPerPixel(type)*width;
+    width = GetBytesPerPixel(type) * width;
     P96TRACE(("CalculateBytesPerRow() = %d\n",width));
     
     return width;
@@ -3027,7 +2834,7 @@ static void PlanarToChunky(struct RenderInfo *ri, struct BitMap *bm,
 {
     int j;
     
-    uae_u8 *PLANAR[8], *image = ri->Memory + dstx * GetBytesPerPixel (ri->RGBFormat) + dsty*ri->BytesPerRow;
+    uae_u8 *PLANAR[8], *image = ri->Memory + dstx * GetBytesPerPixel (ri->RGBFormat) + dsty * ri->BytesPerRow;
     int Depth = bm->Depth;
     unsigned long rows, bitoffset = srcx & 7;
     long eol_offset;
@@ -3039,7 +2846,7 @@ static void PlanarToChunky(struct RenderInfo *ri, struct BitMap *bm,
     for (j = 0; j < Depth; j++) {
        uae_u8 *p = bm->Planes[j];
        if (p != &all_zeros_bitmap && p != &all_ones_bitmap)
-           p += srcx/8 + srcy*bm->BytesPerRow;
+           p += srcx / 8 + srcy * bm->BytesPerRow;
        PLANAR[j] = p;
        if ((mask & (1 << j)) == 0)
            PLANAR[j] = &all_zeros_bitmap;
@@ -3122,11 +2929,10 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (struct regstruct *regs)
     struct BitMap local_bm;
     uae_u32 result = 0;
 
-    P96_SM_RS;
-   
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-#else
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
     wgfx_flushline ();
 #endif
 
@@ -3134,7 +2940,7 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (struct regstruct *regs)
        write_log ("ERROR - BlitPlanar2Chunky() has minterm 0x%x, which I don't handle. Using fall-back routine.\n",
            minterm);
     }
-    else if( CopyRenderInfoStructureA2U (ri, &local_ri) && 
+    else if(CopyRenderInfoStructureA2U (ri, &local_ri) && 
             CopyBitMapStructureA2U (bm, &local_bm))
     {
        P96TRACE(("BlitPlanar2Chunky(%d, %d, %d, %d, %d, %d) Minterm 0x%x, Mask 0x%x, Depth %d\n",
@@ -3143,14 +2949,12 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (struct regstruct *regs)
        PlanarToChunky (&local_ri, &local_bm, srcx, srcy, dstx, dsty, width, height, mask);
        if (renderinfo_is_current_screen (&local_ri))
        {
-           if (!vsyncgfxwrite)do_blit( &local_ri, GetBytesPerPixel( local_ri.RGBFormat ), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0);
+           if (!vsyncgfxwrite)
+               do_blit(&local_ri, GetBytesPerPixel(local_ri.RGBFormat), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0);
        }
        result = 1;
     }
 
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
     return result;
 }
 
@@ -3169,14 +2973,14 @@ static void PlanarToDirect(struct RenderInfo *ri, struct BitMap *bm,
     unsigned long rows;
     long eol_offset;
     
-    if( !bpp )
+    if(!bpp)
        return;
     
     /* Set up our bm->Planes[] pointers to the right horizontal offset */
     for (j = 0; j < Depth; j++) {
        uae_u8 *p = bm->Planes[j];
        if (p != &all_zeros_bitmap && p != &all_ones_bitmap)
-           p += srcx/8 + srcy*bm->BytesPerRow;
+           p += srcx / 8 + srcy * bm->BytesPerRow;
        PLANAR[j] = p;
        if ((mask & (1 << j)) == 0)
            PLANAR[j] = &all_zeros_bitmap;
@@ -3201,12 +3005,12 @@ static void PlanarToDirect(struct RenderInfo *ri, struct BitMap *bm,
            
            switch (bpp) {
            case 2:
-               do_put_mem_word ((uae_u16 *)image2, (uae_u16)( cim->Colors[v] ) );
+               do_put_mem_word ((uae_u16 *)image2, (uae_u16)(cim->Colors[v]));
                image2 += 2;
                break;
            case 3:
-               do_put_mem_byte (image2++, (uae_u8)cim->Colors[v] );
-               do_put_mem_word ((uae_u16 *)image2, (uae_u16)( (cim->Colors[v] & 0x00FFFF00) >> 8) );
+               do_put_mem_byte (image2++, (uae_u8)cim->Colors[v]);
+               do_put_mem_word ((uae_u16 *)image2, (uae_u16)((cim->Colors[v] & 0x00FFFF00) >> 8));
                image2 += 2;
                break;
            case 4:
@@ -3279,19 +3083,19 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs)
     struct ColorIndexMapping local_cim;
     uae_u32 result = 0;
 
-    P96_SM_RS;
-    
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Unlock();
-#else
+#ifdef PIXEL_LOCK
+    flushpixels();
+#endif
+#ifndef LOCK_UNLOCK_MADNESS
     wgfx_flushline ();
 #endif
     
-    if (minterm != 0x0C) {
+    if (minterm != 0x0C)
+    {
        write_log ("WARNING - BlitPlanar2Direct() has unhandled op-code 0x%x. Using fall-back routine.\n",
            minterm);
     }
-    else if( CopyRenderInfoStructureA2U (ri, &local_ri) &&
+    else if(CopyRenderInfoStructureA2U (ri, &local_ri) &&
             CopyBitMapStructureA2U (bm, &local_bm))
     {
        Mask = 0xFF;
@@ -3299,13 +3103,16 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs)
        P96TRACE(("BlitPlanar2Direct(%d, %d, %d, %d, %d, %d) Minterm 0x%x, Mask 0x%x, Depth %d\n",
            srcx, srcy, dstx, dsty, width, height, minterm, Mask, local_bm.Depth));
        PlanarToDirect (&local_ri, &local_bm, srcx, srcy, dstx, dsty, width, height, Mask, &local_cim);
-       if (renderinfo_is_current_screen (&local_ri))
-           if (!vsyncgfxwrite)do_blit( &local_ri, GetBytesPerPixel( local_ri.RGBFormat ), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0);
+       #ifdef PIXEL_LOCK
+       flushpixels();
+       #endif
+       if (renderinfo_is_current_screen (&local_ri)) {
+           if (!vsyncgfxwrite)
+               do_blit(&local_ri, GetBytesPerPixel(local_ri.RGBFormat), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0);
+       }
        result = 1;
     }
-#ifdef LOCK_UNLOCK_MADNESS
-    //PICASSO96_Lock();
-#endif
+
     return result;
 }
 
@@ -3319,397 +3126,242 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs)
 * this is not the case.  So I provide some write-through functions (as per Mathias' orders!)
 */
 #ifdef PIXEL_LOCK
-static void flushpixels( void )
+
+struct frect
 {
-    int i,y,x,xbytes,size;
-    uae_u8 *dst, *ydestaddr;
-    uaecptr addr,xminaddr=0,xmaxaddr;
-    uae_u32 value;
-    int lock=0;
-    
-    if (pixelcount==0)return;
-    if (!picasso_on) {
- pixelcount=0;
-       return;
-    }
-          xmaxaddr=0;
-          //panoffset=picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-          //             +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
-          
-          DX_Invalidate (0,4000);
-#ifndef        _DEBUG
-          if(DirectDraw_IsLocked()==FALSE) {
-              dst = gfx_lock_picasso ();
-              lock=1;
-          } else 
-#endif
-              dst = picasso96_state.HostAddress;
-          if (!dst)goto out;
-          if( picasso_vidinfo.rgbformat != picasso96_state.RGBFormat )
-          {
-              int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat);
-              if (picasso96_state.RGBFormat != RGBFB_CHUNKY)
-              {
-                  write_log ("ERROR - flushpixels() has non RGBFB_CHUNKY mode!\n");
-                  goto out;
-              }
-              for (i=0;i<pixelcount;i++)
-              { 
-                  addr=pixelbase[i].addr;
-                  value=pixelbase[i].value;    
-                  y = addr / picasso96_state.BytesPerRow;
-                  
-                  if (! picasso_vidinfo.extra_mem)
-                      goto next2;         
-                  xbytes = addr - y * picasso96_state.BytesPerRow;
-                  //x = xbytes  / picasso96_state.BytesPerPixel;
-                  
-                  
-                  if (xbytes < picasso96_state.Width*picasso96_state.BytesPerPixel && y < picasso96_state.Height)
-                  {    
-                      if(psiz==4)
-                      {
-                          int i2;
-                          unsigned int val;
-                          uae_u8 *addr;
-                          
-                          i2=pixelbase[i].size;
-                          addr=dst + y * picasso_vidinfo.rowbytes + ((xbytes)*4);
-                          if (i2==4)
-                          {
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[((value)&0xff)];
-                              addr+=4;
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[((value>>8)&0xff)];
-                              addr+=4;
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[((value>>16)&0xff)];
-                              addr+=4;
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[((value>>24)&0xff)];
-                              goto next2;
-                          }
-                          if (i2==2)
-                          {
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[((value>>8)&0xff)];
-                              addr+=4;
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[((value)&0xff)];
-                              goto next2;
-                          }
-                          if (i2==1)
-                          {
-                              *(uae_u32 *) addr=picasso_vidinfo.clut[(value&0xff)];
-                              goto next2;
-                          }
-                          
-                      }
-                      else
-                      {
-                          int i2;
-                          unsigned int val;
-                          uae_u8 *addr;
-                          
-                          i2=pixelbase[i].size;
-                          addr=dst + y * picasso_vidinfo.rowbytes + ((xbytes)*2);
-                          if (i2==4)
-                          {
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[((value)&0xff)];
-                              addr+=2;
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[((value>>8)&0xff)];
-                              addr+=2;
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[((value>>16)&0xff)];
-                              addr+=2;
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[((value>>24)&0xff)];
-                              goto next2;
-                          }
-                          if (i2==2)
-                          {
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[((value>>8)&0xff)];
-                              addr+=2;
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[((value)&0xff)];
-                              goto next2;
-                          }
-                          if (i2==1)
-                          {
-                              *(uae_u16 *) addr=picasso_vidinfo.clut[(value&0xff)];
-                              goto next2;
-                          }
-                          
-                          
-                      }
-                  }
-                  
-next2:;}
-              goto out;  }
-          for (i=0;i<pixelcount;i++)
-          { 
-              addr=pixelbase[i].addr;
-              value=pixelbase[i].value;
-              if(addr>xminaddr && addr<xmaxaddr)
-              {
-                  if(pixelbase[i].size==4){
-#ifdef SWAPSPEEDUP
-    *(uae_u32 *)((addr-xminaddr)+ydestaddr)=value;    
-#else     
-   do_put_mem_long ((uae_u32 *)((addr-xminaddr)+ydestaddr),value);
-#endif                   
-                          goto next;
-                  }
-                  switch (pixelbase[i].size)
-                  {
-                  case 1:
-                      *(uae_u8 *)((addr-xminaddr)+ydestaddr) = value;
-                      break;
-                  case 2:
-                      do_put_mem_word ((uae_u16 *)((addr-xminaddr)+ydestaddr),value);
-                      break;   
-                  }    
-              }
-              else
-              {
-                  y = addr / picasso96_state.BytesPerRow;
-                  
-                  if (! picasso_vidinfo.extra_mem)
-                      goto next;
-                  ydestaddr=picasso_vidinfo.rowbytes*y+dst;
-                  xminaddr= y*picasso96_state.BytesPerRow;     
-                  //xmaxaddr=xminaddr+picasso96_state.BytesPerRow;
-                  xmaxaddr=xminaddr+(picasso_vidinfo.width*picasso_vidinfo.pixbytes);
-                  
-                  xbytes = addr - y * picasso96_state.BytesPerRow;
-                  //x = xbytes  / picasso96_state.BytesPerPixel;
-                  
-                  
-                  if (xbytes < picasso96_state.Width*picasso96_state.BytesPerPixel && y < picasso96_state.Height)
-                  {            
-                      switch (pixelbase[i].size)
-                      {
-                      case 1:
-                          *(uae_u8 *)(dst + y * picasso_vidinfo.rowbytes + xbytes) = value;
-                          break;
-                      case 2:
-                          do_put_mem_word ((uae_u16 *)(dst + y * picasso_vidinfo.rowbytes + xbytes), value);
-                          break;
-                      case 4:  
-#ifdef SWAPSPEEDUP
-          *(uae_u32 *)(dst + y * picasso_vidinfo.rowbytes + xbytes) = value;
-#else
-                                  do_put_mem_long ((uae_u32 *)(dst + y * picasso_vidinfo.rowbytes + xbytes), value);       
-#endif 
-                                  break;               
-                      }
-                      
-                  }
-                  else xmaxaddr=0;
-              }
-              
-next:; } 
-out:;if(lock)gfx_unlock_picasso        ();
-    pixelcount=0;
+    int top, left, right, bottom;
+    int first;
+};
+
+STATIC_INLINE init_refresh(struct frect *r)
+{
+    r->first = 1;
+    r->left = picasso96_state.Width * picasso96_state.BytesPerPixel;
+    r->top = picasso96_state.Height;
+    r->right = -1;
+    r->bottom = -1;
 }
-#endif
 
-static void write_gfx_long (uaecptr addr, uae_u32 value)
+STATIC_INLINE flush_it(struct frect *r)
 {
-    uaecptr oldaddr = addr;
-    int y;
-#ifdef LOCK_UNLOCK_MADNESS
-    int x, xbytes;
-    uae_u8 *dst;
-#ifdef PIXEL_LOCK
-            addr += gfxmem_start;
-    /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
-    if (addr > picasso96_state.Address && addr + 4 < picasso96_state.Extent)
-    {
-       addr -= picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-           +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
-       if ( pixelcount > MAXFLUSHPIXEL )
-           flushpixels();
-       pixelbase[pixelcount].addr=addr;
-       pixelbase[pixelcount].value=value;
-       pixelbase[pixelcount++].size=4;
+    if (r->right >= 0 && r->bottom >= 0) {
+       DX_Invalidate (r->left / picasso96_state.BytesPerPixel, r->top,
+           (r->right - r->left) / picasso96_state.BytesPerPixel + 1, (r->bottom - r->top) + 1);
     }
-    return;
-#endif
-#endif
+    init_refresh(r);
+}
 
-    if (!picasso_on)
-       return;
-    
-#ifndef LOCK_UNLOCK_MADNESS
-       /*
-       * Several writes to successive memory locations are a common access pattern.
-       * Try to optimize it.
-    */
-    if (addr >= wgfx_linestart && addr + 4 <= wgfx_lineend) {
-       if (addr < wgfx_min)
-           wgfx_min = addr;
-       if (addr + 4 > wgfx_max)
-           wgfx_max = addr + 4;
-       return;
-    } else
-    {
-#if P96TRACING_LEVEL > 0
-       P96TRACE(("write_gfx_long( 0x%x, 0x%x )\n", addr, value ));
-#endif
-       wgfx_flushline ();
+#define FLUSH_MIN 30
+STATIC_INLINE void flush_refresh(int x, int y, struct frect *r)
+{
+    if (x < r->left) {
+       if (!r->first && r->left - x > FLUSH_MIN) {
+           flush_it(r);
+           flush_refresh(x, y, r);
+           return;
+       }
+       r->left = x;
     }
-#endif
-
-      addr += gfxmem_start;
-    /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
-    if (addr < picasso96_state.Address || addr + 4 > picasso96_state.Extent)
-       return;
-    addr -= picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-       +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
-    y = addr / picasso96_state.BytesPerRow;
-    
-#ifdef LOCK_UNLOCK_MADNESS
-    //DX_Invalidate (y,y);    
-    if (! picasso_vidinfo.extra_mem) {
-       pixelcount=0;
-       return;
+    if (y < r->top) {
+       if (!r->first && r->top - y > FLUSH_MIN) {
+           flush_it(r);
+           flush_refresh(x, y, r);
+           return;
+       }
+       r->top = y;
     }
-    
-    xbytes = addr - y * picasso96_state.BytesPerRow;
-    //x = xbytes  / picasso96_state.BytesPerPixel;
-    
-    if (xbytes < (picasso96_state.Width*picasso96_state.BytesPerPixel) && y < picasso96_state.Height)
-    {
-       
-       dst = picasso96_state.HostAddress;
-       //dst = gfx_lock_picasso ();
-       if (dst) {
-           do_put_mem_long ((uae_u32 *)(dst + y * picasso_vidinfo.rowbytes + xbytes), value);       
-           //gfx_unlock_picasso ();
+    if (x > r->right) {
+       if (!r->first && x - r->right > FLUSH_MIN) {
+           flush_it(r);
+           flush_refresh(x, y, r);
+           return;
        }
-       else
-           write_log("error\n");
+       r->right = x;
     }
-#else
-    if (y >= picasso96_state.Height)
-       return;
-    wgfx_linestart = picasso96_state.Address - gfxmem_start + y * picasso96_state.BytesPerRow;
-    wgfx_lineend = wgfx_linestart + picasso96_state.BytesPerRow;
-    wgfx_y = y;
-    wgfx_min = oldaddr;
-    wgfx_max = oldaddr + 4;
-#endif
+    if (y > r->bottom) {
+       if (!r->first && y - r->bottom > FLUSH_MIN) {
+           flush_it(r);
+           flush_refresh(x, y, r);
+           return;
+       }
+       r->bottom = y;
+    }
+    r->first = 0;
 }
 
-static void write_gfx_word (uaecptr addr, uae_u16 value)
+static void flushpixels(void)
 {
-     uaecptr oldaddr = addr;
-    int y;
-#ifdef LOCK_UNLOCK_MADNESS
-    int x, xbytes;
+    int i;
     uae_u8 *dst;
-#ifdef PIXEL_LOCK
-    addr += gfxmem_start;
-    /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
-    if (addr > picasso96_state.Address && addr + 4 < picasso96_state.Extent)
-    {
-       addr -= picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-           +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
-       if ( pixelcount > MAXFLUSHPIXEL )
-           flushpixels();
-       pixelbase[pixelcount].addr=addr;
-       pixelbase[pixelcount].value=value;
-       pixelbase[pixelcount++].size=2;
-    }
-    return;
-#endif
-#endif
-    if (!picasso_on)
-       return;
-    
-#ifndef LOCK_UNLOCK_MADNESS
-    /*
-    * Several writes to successive memory locations are a common access pattern.
-    * Try to optimize it.
-    */
-    if (addr >= wgfx_linestart && addr + 2 <= wgfx_lineend) {
-       if (addr < wgfx_min)
-           wgfx_min = addr;
-       if (addr + 2 > wgfx_max)
-           wgfx_max = addr + 2;
-       return;
-    } else
-       wgfx_flushline ();
-#endif
+    int lock = 0;
+    int needrefresh;
+    struct frect r;
     
-    addr += gfxmem_start;
-    /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
-    if (addr < picasso96_state.Address || addr + 2 > picasso96_state.Extent)
+    if (pixelcount == 0)
        return;
-    addr -= picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-       +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
-    
-    y = addr / picasso96_state.BytesPerRow;
-    
-#ifdef LOCK_UNLOCK_MADNESS
-    //DX_Invalidate (y, y);
-    if (! picasso_vidinfo.extra_mem) {
-       pixelcount=0;
+    if (!picasso_on) {
+       pixelcount = 0;
        return;
     }
-    
-    xbytes = addr - y * picasso96_state.BytesPerRow;
-    //x = xbytes / picasso96_state.BytesPerPixel;
-    
-    if (x < (picasso96_state.Width*picasso96_state.BytesPerPixel) && y < picasso96_state.Height)
-    {
+    needrefresh = DirectDraw_GetLockableType() == secondary_surface;
+
+    if(DirectDraw_IsLocked() == FALSE) {
+       dst = gfx_lock_picasso ();
+       lock = 1;
+    } else {
        dst = picasso96_state.HostAddress;
-       
-       //dst = gfx_lock_picasso ();
-       if (dst) {
-           do_put_mem_word ((uae_u16 *)(dst + y * picasso_vidinfo.rowbytes + xbytes), value);
-           //gfx_unlock_picasso ();
+    }
+    if (!dst)
+       goto out;
+
+    init_refresh(&r);
+
+    if(picasso_vidinfo.rgbformat != picasso96_state.RGBFormat) {
+
+       int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat);
+       if (picasso96_state.RGBFormat != RGBFB_CHUNKY) {
+           write_log ("ERROR - flushpixels() has non RGBFB_CHUNKY mode!\n");
+           goto out;
+       }
+       for (i = 0; i < pixelcount; i++) { 
+           int i2 = pixelbase[i].size;
+           uaecptr addr = pixelbase[i].addr;
+           uae_u32 value = pixelbase[i].value; 
+           int y = addr / picasso96_state.BytesPerRow;
+           int xbytes = addr % picasso96_state.BytesPerRow;
+
+           if (! picasso_vidinfo.extra_mem)
+               break;
+                  
+           if (xbytes < picasso96_state.Width * picasso96_state.BytesPerPixel && y < picasso96_state.Height) { 
+               if(psiz == 4) {
+                   uae_u8 *addr;
+                          
+                   addr = dst + y * picasso_vidinfo.rowbytes + (xbytes * 4);
+                   if (i2 == 4) {
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[((value)&0xff)];
+                       addr += 4;
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[((value>>8)&0xff)];
+                       addr += 4;
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[((value>>16)&0xff)];
+                       addr += 4;
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[((value>>24)&0xff)];
+                       break;
+                   } else if (i2 == 2) {
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[((value>>8)&0xff)];
+                       addr += 4;
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[((value)&0xff)];
+                       break;
+                   } else if (i2 == 1) {
+                       *(uae_u32 *) addr = picasso_vidinfo.clut[(value&0xff)];
+                       break;
+                   }
+               } else {
+                   uae_u8 *addr;
+                          
+                   addr = dst + y * picasso_vidinfo.rowbytes + (xbytes * 2);
+                   if (i2 == 4) {
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[((value)&0xff)];
+                       addr += 2;
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[((value>>8)&0xff)];
+                       addr += 2;
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[((value>>16)&0xff)];
+                       addr += 2;
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[((value>>24)&0xff)];
+                       break;
+                   } else if (i2 == 2) {
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[((value>>8)&0xff)];
+                       addr+=2;
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[((value)&0xff)];
+                       break;
+                   } else if (i2 == 1) {
+                       *(uae_u16 *) addr = picasso_vidinfo.clut[(value&0xff)];
+                       break;
+                   }
+               }
+               if (needrefresh)
+                   flush_refresh(xbytes, y, &r);
+           }
+       }
+
+    } else {
+
+       for (i = 0;i < pixelcount; i++) { 
+           uaecptr addr = pixelbase[i].addr;
+           uae_u32 value = pixelbase[i].value;
+           int y = addr / picasso96_state.BytesPerRow;
+           int xbytes = addr % picasso96_state.BytesPerRow;
+           uae_u8 *p = dst + y * picasso_vidinfo.rowbytes + xbytes;
+    
+           if (! picasso_vidinfo.extra_mem)
+               continue;
+
+           if (xbytes < picasso96_state.Width * picasso96_state.BytesPerPixel && y < picasso96_state.Height) {         
+               switch (pixelbase[i].size)
+               {
+                   case 1:
+                   *(uae_u8 *)p = value;
+                   break;
+                   case 2:
+                   do_put_mem_word ((uae_u16 *)p, value);
+                   break;
+                   case 4:  
+    #ifdef SWAPSPEEDUP
+                   *(uae_u32 *)p = value;
+    #else
+                   do_put_mem_long ((uae_u32 *)p, value);       
+    #endif     
+                   break;
+               }
+               if (needrefresh)
+                   flush_refresh(xbytes, y, &r);
+           }
        }
     }
-#else
-    if (y >= picasso96_state.Height)
-       return;
-    wgfx_linestart = picasso96_state.Address - gfxmem_start + y * picasso96_state.BytesPerRow;
-    wgfx_lineend = wgfx_linestart + picasso96_state.BytesPerRow;
-    wgfx_y = y;
-    wgfx_min = oldaddr;
-    wgfx_max = oldaddr + 2;
-#endif
+out:;
+    if(lock)
+        gfx_unlock_picasso();
+    pixelcount = 0;
+    flush_it(&r);
 }
+#endif
 
-static void write_gfx_byte (uaecptr addr, uae_u8 value)
+static void write_gfx_x (uaecptr addr, uae_u32 value, int size)
 {
     uaecptr oldaddr = addr;
     int y;
 #ifdef LOCK_UNLOCK_MADNESS
     int x, xbytes;
     uae_u8 *dst;
+#endif
+
+    if (!picasso_on)
+       return;
+
 #ifdef PIXEL_LOCK
-        addr += gfxmem_start;
+    addr += gfxmem_start;
     /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
-    if (addr > picasso96_state.Address && addr + 4 < picasso96_state.Extent)
-    {
-       addr -= picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-           +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
-       if ( pixelcount > MAXFLUSHPIXEL )
+    if (addr >= picasso96_state.Address && addr + size < picasso96_state.Extent) {
+       addr -= picasso96_state.Address + (picasso96_state.XOffset * picasso96_state.BytesPerPixel)
+           + (picasso96_state.YOffset * picasso96_state.BytesPerRow);
+       if (pixelcount > MAXFLUSHPIXEL)
            flushpixels();
-       pixelbase[pixelcount].addr=addr;
-       pixelbase[pixelcount].value=value;
-       pixelbase[pixelcount++].size=1;
+       pixelbase[pixelcount].addr = addr;
+       pixelbase[pixelcount].value = value;
+       pixelbase[pixelcount++].size = size;
     }
     return;
 #endif
-#endif
-    if (!picasso_on)
-       return;
 #ifndef LOCK_UNLOCK_MADNESS   
-       /*
-       * Several writes to successive memory locations are a common access pattern.
-       * Try to optimize it.
-    */
-    if (addr >= wgfx_linestart && addr + 4 <= wgfx_lineend) {
+    /*
+     * Several writes to successive memory locations are a common access pattern.
+     * Try to optimize it.
+     */
+    if (addr >= wgfx_linestart && addr + size <= wgfx_lineend) {
        if (addr < wgfx_min)
            wgfx_min = addr;
-       if (addr + 1 > wgfx_max)
-           wgfx_max = addr + 1;
+       if (addr + size > wgfx_max)
+           wgfx_max = addr + size;
        return;
     } else
        wgfx_flushline ();
@@ -3717,30 +3369,37 @@ static void write_gfx_byte (uaecptr addr, uae_u8 value)
 
     addr += gfxmem_start;
     /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
-    if (addr < picasso96_state.Address || addr + 1 > picasso96_state.Extent)
+    if (addr < picasso96_state.Address || addr + size > picasso96_state.Extent)
        return;
-    addr -= picasso96_state.Address+(picasso96_state.XOffset*picasso96_state.BytesPerPixel)
-       +(picasso96_state.YOffset*picasso96_state.BytesPerRow);
+    addr -= picasso96_state.Address + (picasso96_state.XOffset * picasso96_state.BytesPerPixel)
+       + (picasso96_state.YOffset * picasso96_state.BytesPerRow);
     
     y = addr / picasso96_state.BytesPerRow;
-    
+    xbytes = addr % picasso96_state.BytesPerRow;
+    x = xbytes / picasso96_state.BytesPerPixel;
+   
 #ifdef LOCK_UNLOCK_MADNESS
-    //DX_Invalidate (y, y);
     if (! picasso_vidinfo.extra_mem) {
-       pixelcount=0;
+       pixelcount = 0;
        return;
     }
     
-    xbytes = addr - y * picasso96_state.BytesPerRow;
-    x = xbytes / picasso96_state.BytesPerPixel;
-    
-    if (x < picasso96_state.Width && y < picasso96_state.Height) 
-       {
+    if (x < picasso96_state.Width && y < picasso96_state.Height) {
        dst = picasso96_state.HostAddress;
-               
        //dst = gfx_lock_picasso ();
        if (dst) {
-           *(uae_u8 *)(dst + y * picasso_vidinfo.rowbytes + xbytes) = value;
+           switch (size)
+           {
+               case 1:
+               *(uae_u8 *)(dst + y * picasso_vidinfo.rowbytes + xbytes) = value;
+               break;
+               case 2:
+               do_put_mem_word ((uae_u16 *)(dst + y * picasso_vidinfo.rowbytes + xbytes), value);
+               break;
+               case 4:
+               do_put_mem_long ((uae_u32 *)(dst + y * picasso_vidinfo.rowbytes + xbytes), value);       
+               break;
+           }
            //gfx_unlock_picasso ();
        }
     }
@@ -3751,34 +3410,30 @@ static void write_gfx_byte (uaecptr addr, uae_u8 value)
     wgfx_lineend = wgfx_linestart + picasso96_state.BytesPerRow;
     wgfx_y = y;
     wgfx_min = oldaddr;
-    wgfx_max = oldaddr + 1;
+    wgfx_max = oldaddr + size;
 #endif
 }
 
 static uae_u32 REGPARAM2 gfxmem_lget (uaecptr addr)
 {
-    uae_u32 *m;
-
-    P96_SM_R;
+    uae_u8 *m;
     addr -= gfxmem_start & gfxmem_mask;
     addr &= gfxmem_mask;
-    m = (uae_u32 *)(gfxmemory + addr);
-    return do_get_mem_long(m);
+    m = gfxmemory + addr;
+    return do_get_mem_long((uae_u32*)m);
 }
 
 static uae_u32 REGPARAM2 gfxmem_wget (uaecptr addr)
 {
-    uae_u16 *m;
-    P96_SM_R;
+    uae_u8 *m;
     addr -= gfxmem_start & gfxmem_mask;
     addr &= gfxmem_mask;
-    m = (uae_u16 *)(gfxmemory + addr);
-    return do_get_mem_word(m);
+    m = gfxmemory + addr;
+    return do_get_mem_word((uae_u16*)m);
 }
 
 static uae_u32 REGPARAM2 gfxmem_bget (uaecptr addr)
 {
-    P96_SM_R;
     addr -= gfxmem_start & gfxmem_mask;
     addr &= gfxmem_mask;
     return gfxmemory[addr];
@@ -3786,62 +3441,53 @@ static uae_u32 REGPARAM2 gfxmem_bget (uaecptr addr)
 
 static void REGPARAM2 gfxmem_lput (uaecptr addr, uae_u32 l)
 {
-    uae_u32 *m;
+    uae_u8 *m;
 #ifdef SWAPSPEEDUP
-       __asm {         //byteswap now
+    __asm {         //byteswap now
        mov eax,l
        bswap eax
        mov l,eax
-       }
+    }
 #endif
-    P96_SM_S;
+    P96_SM_W;
     addr -= gfxmem_start & gfxmem_mask;
     addr &= gfxmem_mask;
 
-    m = (uae_u32 *)(gfxmemory + addr);
-/*                   //only write difference
-       __asm {
-       mov eax,m
-       mov eax,[eax]
-       bswap eax
-       cmp eax,l
-       jne l2
-       mov m,0
-l2:
-    }
-       if (!m) return;
-*/ 
+    m = gfxmemory + addr;
 #ifdef SWAPSPEEDUP
-      *m=l;
+    *m = l;
 #else
-        do_put_mem_long(m, l);
+    do_put_mem_long((uae_u32*)m, l);
 #endif
     /* write the long-word to our displayable memory */
-    if (vsyncgfxwrite==0)write_gfx_long(addr, l);
+    if (vsyncgfxwrite == 0)
+       write_gfx_x(addr, l, 4);
 }
 
 static void REGPARAM2 gfxmem_wput (uaecptr addr, uae_u32 w)
 {
-    uae_u16 *m;
-    P96_SM_S;
+    uae_u8 *m;
+    P96_SM_W;
     addr -= gfxmem_start & gfxmem_mask;
     addr &= gfxmem_mask;
-    m = (uae_u16 *)(gfxmemory + addr);
-    do_put_mem_word(m, (uae_u16)w);
+    m = gfxmemory + addr;
+    do_put_mem_word((uae_u16*)m, w);
     
     /* write the word to our displayable memory */
-    if (vsyncgfxwrite==0)write_gfx_word(addr, (uae_u16)w);
+    if (vsyncgfxwrite == 0)
+       write_gfx_x(addr, w, 2);
 }
 
 static void REGPARAM2 gfxmem_bput (uaecptr addr, uae_u32 b)
 {
-    P96_SM_S;
+    P96_SM_W;
     addr -= gfxmem_start & gfxmem_mask;
     addr &= gfxmem_mask;
     gfxmemory[addr] = b;
     
     /* write the byte to our displayable memory */
-    if (vsyncgfxwrite==0)write_gfx_byte(addr, (uae_u8)b);
+    if (vsyncgfxwrite == 0)
+       write_gfx_x(addr, b, 1);
 }
 
 static int REGPARAM2 gfxmem_check (uaecptr addr, uae_u32 size)
@@ -3874,7 +3520,7 @@ void InitPicasso96 (void)
     pixelcount = 0;
     palette_changed = 0;
 //fastscreen
-    oldscr=0;
+    oldscr = 0;
 //fastscreen
     memset (&picasso96_state, 0, sizeof(struct picasso96_state_struct));
     
@@ -3940,5 +3586,3 @@ uae_u8 *save_p96 (int *len, uae_u8 *dstptr)
 }
 
 #endif
-
-#endif
index d6229a02623eede94d7d27ffe4af03f05dc571de..18d3afd8de305c42dccc86406816470252a2515e 100755 (executable)
 #include "dxwrap.h"
 
 #ifdef _DEBUG
-void PICASSO96_Lock2( char *filename, int linenum );
-#define PICASSO96_Lock() PICASSO96_Lock2( __FILE__, __LINE__ )
+void PICASSO96_Lock2(char *filename, int linenum);
+#define PICASSO96_Lock() PICASSO96_Lock2(__FILE__, __LINE__)
 
-void PICASSO96_Unlock2( char *filename, int linenum );
-#define PICASSO96_Unlock() PICASSO96_Unlock2( __FILE__, __LINE__ )
+void PICASSO96_Unlock2(char *filename, int linenum);
+#define PICASSO96_Unlock() PICASSO96_Unlock2(__FILE__, __LINE__)
 #endif
 
 /* Define this if you provide the proper sprite functions */
 //#define HARDWARE_SPRITE_EMULATION
 
-//#include "newcpu.h"
-
-#define PIC_READ (S_READ|S_WRITE)
-#define PIC_WRITE (S_READ|S_WRITE)
+#define PIC_READ (S_READ)
+#define PIC_WRITE (S_WRITE)
 
 #define NOSIGNAL 0xFFFFFFFF
 
@@ -514,19 +512,15 @@ extern int uaegfx_card_found;
 extern struct picasso96_state_struct picasso96_state;
 extern uae_u16 picasso96_pixel_format;
 
-#ifdef _WIN32
-extern unsigned int timer_id;
-#endif
-
 extern int  DX_InvertRect (int X, int Y, int Width, int Height);
 extern void DX_SetPalette (int start, int count);
 extern int  DX_BitsPerCannon (void);
-extern void DX_Invalidate (int first, int last);
-extern int  DX_Flip( void );
-extern int  DX_Blit( int srcx, int srcy, int dstx, int dsty, int w, int h, BLIT_OPCODE opcode );
-extern int  DX_Fill( int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE rgbtype );
-extern uae_u32 DX_ShowCursor( uae_u32 activate );
-extern uae_u32 DX_MoveCursor( uae_u32 x, uae_u32 y );
+extern void DX_Invalidate (int, int, int, int);
+extern int  DX_Flip(void);
+extern int  DX_Blit(int srcx, int srcy, int dstx, int dsty, int w, int h, BLIT_OPCODE opcode);
+extern int  DX_Fill(int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE rgbtype);
+extern uae_u32 DX_ShowCursor(uae_u32 activate);
+extern uae_u32 DX_MoveCursor(uae_u32 x, uae_u32 y);
 extern void picasso_enablescreen (int on);
 extern void picasso_refresh (int);
 extern void picasso_handle_vsync (void);
index a8855a1cb4a23f6108d4d906502da07f38d8b38a..74a18186637d1d93d8a62bbb46efb4b4695f7fa7 100755 (executable)
@@ -830,8 +830,10 @@ static LRESULT CALLBACK AmigaWindowProc (HWND hWnd, UINT message, WPARAM wParam,
     case WM_MBUTTONDOWN:
     case WM_MBUTTONDBLCLK:
        if (currprefs.win32_middle_mouse) {
+#ifndef _DEBUG
            if (isfullscreen ())
                minimizewindow ();
+#endif
            if (mouseactive)
                setmouseactive(0);
        } else {
index 1209dd83f780971db39f99f9ffe6e3468704b12b..861522648f8ff28fe0c9f097355af0e871baf1a3 100755 (executable)
@@ -15,9 +15,9 @@
 #define GETBDM(x) (((x) - ((x / 10000) * 10000)) / 100)
 #define GETBDD(x) ((x) % 100)
 
-#define WINUAEBETA 5
+#define WINUAEBETA 6
 #define WINUAEPUBLICBETA 1
-#define WINUAEDATE MAKEBD(2007, 2, 3)
+#define WINUAEDATE MAKEBD(2007, 2, 11)
 
 #define IHF_WINDOWHIDDEN 6
 #define NORMAL_WINDOW_STYLE (WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU)
index b01a21e7bc5fc105bd29593f59913b3ed83d19e9..98a84056a933875f291cfabc636391b035a40a0a 100755 (executable)
@@ -255,9 +255,6 @@ HWND hStatusWnd = NULL;
 HINSTANCE hDDraw = NULL;
 uae_u16 picasso96_pixel_format = RGBFF_CHUNKY;
 
-/* For the DX_Invalidate() and gfx_unlock_picasso() functions */
-static int p96_double_buffer_first, p96_double_buffer_last, p96_double_buffer_needs_flushing = 0;
-
 static char scrlinebuf[4096 * 4]; /* this is too large, but let's rather play on the safe side here */
 
 static int rgbformat_bits (RGBFTYPE t)
@@ -1003,24 +1000,6 @@ uae_u8 *gfx_lock_picasso (void)
 void gfx_unlock_picasso (void)
 {
     DirectDraw_SurfaceUnlock();
-    if (p96_double_buffer_needs_flushing) {
-       /* Here, our flush_block() will deal with a offscreen-plain (back-buffer) to visible-surface (front-buffer) */
-       if (DirectDraw_GetLockableType() == secondary_surface) {
-           BOOL relock = FALSE;
-           if (DirectDraw_IsLocked()) {
-               relock = TRUE;
-               unlockscr();
-           }
-           DX_Blit (0, p96_double_buffer_first, 
-                    0, p96_double_buffer_first, 
-                    currentmode->current_width, p96_double_buffer_last - p96_double_buffer_first + 1, 
-                    BLIT_SRC);
-           if (relock) {
-               lockscr();
-           }
-       }
-       p96_double_buffer_needs_flushing = 0;
-    }
 }
 
 static void close_hwnds( void )
@@ -1422,27 +1401,33 @@ void DX_SetPalette (int start, int count)
     }
 
     /* Set our DirectX palette here */
-    if( currentmode->current_depth == 8 )
+    if(currentmode->current_depth == 8)
     {
        if (SUCCEEDED(DirectDraw_SetPalette(0))) {
-           ddrval = DirectDraw_SetPaletteEntries( start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start] ) );
+           ddrval = DirectDraw_SetPaletteEntries(start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start]));
            if (FAILED(ddrval))
                gui_message("DX_SetPalette() failed with %s/%d\n", DXError (ddrval), ddrval);
        }
     }
     else
     {
-       write_log ("ERROR - DX_SetPalette() pixbytes %d\n", currentmode->current_depth >> 3 );
+       write_log ("ERROR - DX_SetPalette() pixbytes %d\n", currentmode->current_depth >> 3);
     }
 }
 
-void DX_Invalidate (int first, int last)
+void DX_Invalidate (int x, int y, int width, int height)
 {
-    p96_double_buffer_first = first;
-    if(last >= picasso_vidinfo.height )
-       last = picasso_vidinfo.height - 1;
-    p96_double_buffer_last  = last;
-    p96_double_buffer_needs_flushing = 1;
+    if (DirectDraw_GetLockableType() == secondary_surface) {
+        BOOL relock = FALSE;
+        if (DirectDraw_IsLocked()) {
+           relock = TRUE;
+           unlockscr();
+       }
+       DX_Blit (x, y, x, y, width, height, BLIT_SRC);
+       if (relock) {
+           lockscr();
+       }
+    }
 }
 
 #endif
@@ -1452,15 +1437,15 @@ int DX_BitsPerCannon (void)
     return 8;
 }
 
-static COLORREF BuildColorRef( int color, RGBFTYPE pixelformat )
+static COLORREF BuildColorRef(int color, RGBFTYPE pixelformat)
 {
     COLORREF result;
 
     /* Do special case first */
-    if( pixelformat == RGBFB_CHUNKY )
+    if(pixelformat == RGBFB_CHUNKY)
        result = color;
     else
-       result = do_get_mem_long( &color );
+       result = do_get_mem_long(&color);
     return result;
 #if 0
     int r,g,b;
@@ -1524,6 +1509,7 @@ static COLORREF BuildColorRef( int color, RGBFTYPE pixelformat )
  */
 int DX_Fill(int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE rgbtype)
 {
+    HRESULT hr;
     int result = 0;
     RECT dstrect;
     RECT srcrect;
@@ -1542,13 +1528,20 @@ int DX_Fill(int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE r
        OffsetRect(&dstrect, amigawin_rect.left, amigawin_rect.top);
 
     /* Render our fill to the visible (primary) surface */
-    if((result = DirectDraw_Blt(primary_surface, &dstrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx)))
-    {
-       if(DirectDraw_GetLockableType() == secondary_surface)
-       {
+    hr = DirectDraw_Blt(primary_surface, &dstrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx);
+    if(SUCCEEDED(hr)) {
+       result = 1;
+       if(DirectDraw_GetLockableType() == secondary_surface) {
            /* We've colour-filled the visible, but still need to colour-fill the offscreen */
-           result = DirectDraw_Blt(secondary_surface, &srcrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx);
+           hr = DirectDraw_Blt(secondary_surface, &srcrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx);
+           if (FAILED(hr)) {
+               write_log("DX_Fill2(%dx%d %d%d): %s\n", dstx, dsty, width, height, DXError(hr));
+               result = 0;
+           }
+
        }
+    } else {
+       write_log("DX_Fill(%dx%d %d%d): %s\n", dstx, dsty, width, height, DXError(hr));
     }
     return result;
 }
@@ -1558,8 +1551,6 @@ int DX_Fill(int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE r
  * - primary is the displayed (visible) surface in VRAM, which may have an associated offscreen surface (or back-buffer)
  */
 
-static DDBLTFX fx = { sizeof(DDBLTFX) };
-
 static DWORD BLIT_OPCODE_TRANSLATION[BLIT_LAST] =
 {
     BLACKNESS,  /* BLIT_FALSE */
@@ -1585,19 +1576,21 @@ int DX_Blit(int srcx, int srcy, int dstx, int dsty, int width, int height, BLIT_
     HRESULT result;
     RECT dstrect, srcrect;
     DWORD dwROP = BLIT_OPCODE_TRANSLATION[opcode];
+    DDBLTFX fx = { 0 };
 
     if(dwROP == -1) {
        /* Unsupported blit opcode! */
        return 0;
     }
+    fx.dwSize = sizeof (fx);
     fx.dwROP = dwROP;
 
     /* Set up our source rectangle.  This NEVER needs to be adjusted for windowed display, since the
      * source is ALWAYS in an offscreen buffer, or we're in full-screen mode. */
-    SetRect(&srcrect, srcx, srcy, srcx+width, srcy+height);
+    SetRect(&srcrect, srcx, srcy, srcx + width, srcy + height);
 
     /* Set up our destination rectangle, and adjust for blit to windowed display (if necessary ) */
-    SetRect(&dstrect, dstx, dsty, dstx+width, dsty+height);
+    SetRect(&dstrect, dstx, dsty, dstx + width, dsty + height);
     
     if(!(currentmode->flags & (DM_DX_FULLSCREEN | DM_OVERLAY)))
        OffsetRect(&dstrect, amigawin_rect.left, amigawin_rect.top);
@@ -1605,37 +1598,36 @@ int DX_Blit(int srcx, int srcy, int dstx, int dsty, int width, int height, BLIT_
     /* Render our blit within the primary surface */
     result = DirectDraw_Blt(primary_surface, &dstrect, DirectDraw_GetLockableType(), &srcrect, DDBLT_WAIT | DDBLT_ROP, &fx);
     if (FAILED(result)) {
-       write_log("DX_Blit1() failed %s\n", DXError(result));
+       write_log("DX_Blit1(%d,%d,%d,%d) failed: %s\n", srcx, srcy, width, height, DXError(result));
        return 0;
     } else if(DirectDraw_GetLockableType() == secondary_surface) {
        /* We've just blitted from the offscreen to the visible, but still need to blit from offscreen to offscreen
         * NOTE: reset our destination rectangle again if its been modified above... */
        if((srcx != dstx) || (srcy != dsty)) {
-                   SetRect(&dstrect, dstx, dsty, dstx+width, dsty+height);
+           SetRect(&dstrect, dstx, dsty, dstx + width, dsty + height);
            result = DirectDraw_Blt(secondary_surface, &dstrect, secondary_surface, &srcrect, DDBLT_WAIT | DDBLT_ROP, &fx);
            if (FAILED(result)) {
-               write_log("DX_Blit2() failed %s\n", DXError(result));
+               write_log("DX_Blit2(%d,%d,%d,%d) failed: %s\n", srcx, srcy, width, height, DXError(result));
            }
        }
     }
-
     return 1;
 }
 
-void DX_WaitVerticalSync( void )
+void DX_WaitVerticalSync(void)
 {
     DirectDraw_WaitForVerticalBlank (DDWAITVB_BLOCKBEGIN);
 }
 
 #if 0
-uae_u32 DX_ShowCursor( uae_u32 activate )
+uae_u32 DX_ShowCursor(uae_u32 activate)
 {
     uae_u32 result = 0;
-    if( ShowCursor( activate ) > 0 )
+    if(ShowCursor(activate) > 0)
        result = 1;
     return result;
 }
-uae_u32 DX_MoveCursor( uae_u32 x, uae_u32 y )
+uae_u32 DX_MoveCursor(uae_u32 x, uae_u32 y)
 {
     uae_u32 result = 0;
 
@@ -1643,19 +1635,19 @@ uae_u32 DX_MoveCursor( uae_u32 x, uae_u32 y )
     if(!(currentmode->flags & DM_DX_FULLSCREEN))
     {
        RECT rect;
-       if( GetWindowRect( hAmigaWnd, &rect ) )
+       if(GetWindowRect(hAmigaWnd, &rect))
        {
            x = rect.left + x;
            y = rect.top + y;
        }
     }
-    if( SetCursorPos( x, y ) )
+    if(SetCursorPos(x, y))
        result = 1;
     return result;
 }
 #endif
 
-static void open_screen( void )
+static void open_screen(void)
 {
     close_windows ();
     open_windows();
@@ -1665,7 +1657,7 @@ static void open_screen( void )
 }
 
 #ifdef PICASSO96
-void gfx_set_picasso_state( int on )
+void gfx_set_picasso_state(int on)
 {
     if (screen_is_picasso == on)
        return;
@@ -1673,13 +1665,13 @@ void gfx_set_picasso_state( int on )
     open_screen();
 }
 
-void gfx_set_picasso_modeinfo( uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt )
+void gfx_set_picasso_modeinfo(uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt)
 {
     depth >>= 3;
-    if( ((unsigned)picasso_vidinfo.width == w ) &&
-           ( (unsigned)picasso_vidinfo.height == h ) &&
-           ( (unsigned)picasso_vidinfo.depth == depth ) &&
-           ( picasso_vidinfo.selected_rgbformat == rgbfmt) )
+    if(((unsigned)picasso_vidinfo.width == w) &&
+           ((unsigned)picasso_vidinfo.height == h) &&
+           ((unsigned)picasso_vidinfo.depth == depth) &&
+           (picasso_vidinfo.selected_rgbformat == rgbfmt))
        return;
 
     picasso_vidinfo.selected_rgbformat = rgbfmt;
@@ -1688,8 +1680,7 @@ void gfx_set_picasso_modeinfo( uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgb
     picasso_vidinfo.depth = depth;
     picasso_vidinfo.extra_mem = 1;
 
-    if( screen_is_picasso ) 
-    {
+    if(screen_is_picasso) {
        open_screen();
     }
 }
index 59eee15047b7d93b6f6e51f3702b4b46378ca99b..f8f8b778dbbdceaffd55d198d9e9831c2a85ff23 100755 (executable)
@@ -1,4 +1,34 @@
 
+Beta 6:
+
+- FPU emulation floating point to integer conversion fixed, previously
+  for example float -> byte conversion simply truncated to byte instead
+  of clamping it to -128 or 127 if original value can't fit in a byte.
+  Same problem was with words and longs. (Aske Christensen)
+- uaeserial.device compatibility fixes
+- A500 D80000-DDFFFF area is unmapped (except possible RTC at DC0000)
+  higher end models can have other MB devices here
+- A1000 is most likely the only Amiga model that has custom chips
+  mapped at D80000-DDFFFF
+- RTC access is now exactly same as in real A500 (if more compatible
+  setting enabled)
+- AGA end of fast (or chip if no fast) to BBFFFF is not mapped, same
+  with C00000 to D7FFFF. (Need more testing)
+  Mapping changes may help with some buggy programs that poke illegal
+  addresses.
+- My A1200 seems to have KS ROM mapped at 0xA80000-B7FFFF. But with
+  Blizzard 1260 installed it is replaced with 64kb "bank" of RAM from
+  card's expansion RAM.. It seems all "unmapped" areas map to
+  Blizzard's expansion RAM. Quite interesting effect.. (not emulated)
+- serial port detection update. For some reason not all serial ports
+  (at least some USB types) can't be detected by enumerating
+  GUID_CLASS_COMPORT class. (and this was supposed to be the proper
+  way to do it..)
+- do not log KS motherboard RAM probe (less useless spam when booting)
+- Picasso96 graphics corruption introduced in previous betas should
+  be fixed (also other changes, can be faster or slower in some cases,
+  also there is possibility something else broke..)
+
 Beta 5:
 
 - CD32/CDTV emulation now autodetects all CD (all drives) changes on
index df8c3f6a865537b6a217981248d757b9c99794a6..2781bd536b781d30ebcab8f9288dd996ed8b5799 100755 (executable)
@@ -198,10 +198,26 @@ static uae_u32 REGPARAM2 dev_close (TrapContext *context)
     return 0;
 }
 
+static void resetparams(struct devstruct *dev, uaecptr req)
+{
+    put_long(req + io_CtlChar, 0x00001311);
+    put_long(req + io_RBufLen, 8192);
+    put_long(req + io_ExtFlags, 0);
+    put_long(req + io_Baud, 9600);
+    put_long(req + io_BrkTime, 250000);
+    put_long(req + io_TermArray0, 0);
+    put_long(req + io_TermArray1, 0);
+    put_byte(req + io_ReadLen, 8);
+    put_byte(req + io_WriteLen, 8);
+    put_byte(req + io_StopBits, 1);
+    put_byte(req + io_SerFlags, get_byte(req + io_SerFlags) & (SERF_XDISABLED | SERF_SHARED | SERF_7WIRE));
+    put_word(req + io_Status, 0);
+}
+
 static int setparams(struct devstruct *dev, uaecptr req)
 {
     int v;
-    int rbuffer, baud, rbits, wbits, sbits, rtscts, parity;
+    int rbuffer, baud, rbits, wbits, sbits, rtscts, parity, xonxoff;
     
     rbuffer = get_long (req + io_RBufLen);
     v = get_long (req + io_ExtFlags);
@@ -215,9 +231,9 @@ static int setparams(struct devstruct *dev, uaecptr req)
        write_log ("UAESER: SERF_EOFMODE not supported\n");
        return 5;
     }
-    if (!(v & SERF_XDISABLED)) {
-       write_log ("UAESER: xOn/xOff not supported\n");
-       return 5;
+    xonxoff = (v & SERF_XDISABLED) ? 0 : 1;
+    if (xonxoff) {
+       xonxoff |= (get_long (req + io_CtlChar) << 8) & 0x00ffff00;
     }
     rtscts = (v & SERF_7WIRE) ? 1 : 0;
     parity = 0;
@@ -230,13 +246,16 @@ static int setparams(struct devstruct *dev, uaecptr req)
        write_log ("UAESER: Read=%d, Write=%d, Stop=%d, not supported\n", rbits, wbits, sbits);
        return 5;
     }
-    write_log ("%s:%d BAUD=%d BUF=%d BITS=%d+%d RTSCTS=%d PARITY=%d\n",
+    write_log ("%s:%d BAUD=%d BUF=%d BITS=%d+%d RTSCTS=%d PAR=%d XO=%06.6X\n",
        getdevname(), dev->unit, 
-       baud, rbuffer, rbits, sbits, rtscts, parity);
-    v = uaeser_setparams (dev->sysdata, baud, rbuffer, rbits, sbits, rtscts, parity);
-    if (!v)
+       baud, rbuffer, rbits, sbits, rtscts, parity, xonxoff);
+    v = uaeser_setparams (dev->sysdata, baud, rbuffer,
+       rbits, sbits, rtscts, parity, xonxoff);
+    if (v) {
        write_log("->failed\n");
-    return v;
+       return v;
+    }
+    return 0;
 }
 
 static int openfail (uaecptr ioreq, int error)
@@ -275,6 +294,7 @@ static uae_u32 REGPARAM2 dev_open (TrapContext *context)
     dev->uniq = ++uniq;
     dev->exclusive = (get_word(ioreq + io_SerFlags) & SERF_SHARED) ? 0 : 1;
     put_long (ioreq + 24, dev->uniq);
+    resetparams (dev, ioreq);
     setparams (dev, ioreq);
     if (log_uaeserial)
        write_log ("%s:%d open ioreq=%08.8X\n", getdevname(), unit, ioreq);