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.
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
;
;
; 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)