From 8af9a8407bc9f65fc34eecfe0fbd4beb6dacdfac Mon Sep 17 00:00:00 2001
From: Chris Young <chris@unsatisfactorysoftware.co.uk>
Date: Sat, 31 Dec 2016 14:43:06 +0000
Subject: [PATCH] Don't unmap ExtMem immediately as: (a) it is upsetting the
 gif decoder (although I suspect it is caused by the OS struggling with the
 excessive remaps) (b) We are probably going to need to map it back in
 imminently for display

---
 frontends/amiga/bitmap.c | 3 ++-
 frontends/amiga/gui.c    | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/frontends/amiga/bitmap.c b/frontends/amiga/bitmap.c
index fe84a94b7..5b5d6bb1e 100644
--- a/frontends/amiga/bitmap.c
+++ b/frontends/amiga/bitmap.c
@@ -277,7 +277,8 @@ void amiga_bitmap_modified(void *bitmap)
 	struct bitmap *bm = bitmap;
 
 #ifdef __amigaos4__
-	amiga_bitmap_unmap_buffer(bm);
+		/* unmap the buffer after 0.5s - we might need it imminently */
+		ami_schedule(500, amiga_bitmap_unmap_buffer, bm);
 #endif
 
 	if(bm->nativebm) ami_rtg_freebitmap(bm->nativebm);
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index a51d8c2db..ba0a786e3 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008-2015 Chris Young <chris@unsatisfactorysoftware.co.uk>
+ * Copyright 2008-2016 Chris Young <chris@unsatisfactorysoftware.co.uk>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -616,6 +616,11 @@ static nserror ami_set_options(struct nsoption_s *defaults)
 
 	/* Some OS-specific overrides */
 #ifdef __amigaos4__
+	if(!LIB_IS_AT_LEAST((struct Library *)SysBase, 53, 89)) {
+		/* Disable ExtMem usage pre-OS4.1FEU1 */
+		nsoption_set_bool(use_extmem, false);
+	}
+
 	if(codeset == 0) codeset = 4; /* ISO-8859-1 */
 	const char *encname = (const char *)ObtainCharsetInfo(DFCS_NUMBER, codeset,
 							DFCS_MIMENAME);