msx2: save map_table before switching pages
authorgeijoenr <enric.geijo@gmail.com>
Tue, 30 May 2017 17:59:48 +0000 (19:59 +0200)
committergeijoenr <geijoenr@gmail.com>
Mon, 5 Jun 2017 18:23:50 +0000 (20:23 +0200)
If an interrupt happens between setting the mapper register
and the update of map_table, map_save will take the wrong
input for restoring the mapping when returning from the interrupt.
By saving the map_table at the beginning we ensure that no matter
when the interrupt happens, map_restore sets the right pages.

This prevents some random hangs when doing lots of usermem operations.

Kernel/platform-msx2/msx2.s

index c360e0a..c130814 100644 (file)
@@ -187,22 +187,25 @@ map_kernel:
 
 map_process_2:
            push de
+            push bc
            push af
            ld de, #map_table   ; Write only so cache in RAM
-           ld a, (hl)
-           ld (de), a
-           out (0xFC), a       ; Low 16K
-           inc hl
-           inc de
-           ld a, (hl)  
-           out (0xFD), a       ; Next 16K
-           ld (de), a
-           inc hl
-           inc de
-           ld a, (hl)          ; Next 16K. Leave the common for the task
-           out (0xFE), a       ; switcher
-           ld (de), a
+            ld (de), a
+            ld bc, #4
+            ldir
+            dec hl
+            dec hl
+            dec hl
+            dec hl
+            ld c, #0xFC
+            ld b, #4
+            outi
+            inc c
+            outi
+            inc c
+            outi
            pop af
+            pop bc
            pop de
             ret
 ;
@@ -218,7 +221,8 @@ map_restore:
 ;
 ;      Save the current mapping.
 ;
-map_save:   push hl
+map_save:
+            push hl
            ld hl, (map_table)
            ld (map_savearea), hl
            ld hl, (map_table + 2)