; BANKWALK.ASM -- a reversible mapping experiment for a fresh 512 KB Disk BASIC.
; Before running, verify MMU enabled, task 0, block 2 = $3A in the debugger.
; Begin at the BASIC prompt with no unsaved program or active devices.
bank2       equ     $ffa2           ; task 0, logical $4000-$5fff
window      equ     $4123           ; offset $0123 into block 2
            org     $3f00           ; code and scratch live in block 1
start       pshs    cc,a            ; preserve incoming flags and A
            orcc    #$50            ; hold IRQ and FIRQ until restored
            lda     bank2
            anda    #$3f            ; 512 KB supplies six bank bits
            sta     oldbank,pcr
            lda     #1
            sta     bank2           ; window now sees physical $02123
            lda     window
            sta     oldbyte,pcr     ; keep the byte even on a fresh machine
            lda     #$a5
            sta     window
inspect     lda     oldbyte,pcr     ; pause BEFORE this instruction
            sta     window          ; put the borrowed byte back
            lda     oldbank,pcr
            sta     bank2           ; restore the original translation
restored    puls    cc,a,pc         ; flags restored, return to BASIC

oldbank     fcb     0
oldbyte     fcb     0
            end     start
