I'm trying an alternative method for restoring the system after taking the hardware. Instead of peeking in graphics library to get the current view and copper list I am just leaving all of this up to the RemakeDisplay call.
The code below restores the system perfectly almost every time, and in fact I can also leave the restoration of DMACON out because I've seen that this is done via RemakeDisplay. However occasionally it happens that the view is not restored and I end up in AmigaOS with no changes whatsoever to the display related HW registers. Does anyone know why this happens?
dmacon = $96
dmaconr = $2
intena = $9a
intenar = $1c
OpenLibrary = -552
CloseLibrary = -414
LoadView = -222
WaitTOF = -270
RemakeDisplay = -384
move.l 4.w, a6
lea graphicslib, a1
moveq #33, d0
jsr OpenLibrary(a6)
move.l d0, a6
move.l d0, -(sp)
sub.l a1, a1
jsr LoadView(a6)
jsr WaitTOF(a6)
lea $dff000, a6
move.w dmaconr(a6), d0
move.w intenar(a6), d1
move.w #$7ff, dmacon(a6)
move.w #$7fff, intena(a6)
movem.w d0-d1, -(sp)
move.l #copperlist, cop1lch(a6)
move.w d0, copjmp1(a6)
move.w #%1000001010000000, dmacon(a6)
wait
btst #6, $bfe001
bne.s wait
move.w #$7ff, dmacon(a6)
move.w #$7fff, intena(a6)
movem.w (sp)+, d0-d1
or.w #$8040, d0
or.w #$c000, d1
move.w d0, dmacon(a6)
move.w d1, intena(a6)
move.l 4.w, a6
lea intuitionlib, a1
moveq #33, d0
jsr OpenLibrary(a6)
move.l d0, a6
jsr RemakeDisplay(a6)
move.l a6, a1
move.l 4.w, a6
jsr CloseLibrary(a6)
move.l (sp)+, a1
jsr CloseLibrary(a6)
moveq #0, d0
rts
intuitionlib
dc.b "intuition.library", 0
graphicslib
dc.b "graphics.library", 0
section dat, data_c
copperlist
dc.l $8001ff00, $01800800
dc.l $9001ff00, $01800080
dc.l $a001ff00, $01800008
dc.l $b001ff00, $01800000
dc.l -2