Help needed with Atom DOS NMI Handler

emulators, hardware and classic software for atom + system machines
Post Reply
User avatar
John_Newcombe
Posts: 131
Joined: Tue Nov 28, 2017 9:19 am
Contact:

Help needed with Atom DOS NMI Handler

Post by John_Newcombe »

I am trying to understand the NMI handler used within Atom DOS. I am very happy with how the code works within the handler except for one instruction.

Just before the RTI, there is an additional PLA (i.e. not matched with a previous PHA). The comment, taken from the disassembly described here, https://www.acornatom.nl/atom_handleidi ... ow2044.htm suggests it is to get the stack pointer.

The handler does one of two things depending upon whether data is present. It either calls a subroutine vectored via D5/D6 and returns with an RTS and then adds the PLA before the RTI. Or, it jumps to a routine in ZP which, when complete executes RTI but not before issuing the extra PLA. Obviously I am missing something.


Is anyone able to help me understand this?

Code: Select all

;============================================
; ENTRY NMI ROUTINE                  HARDWARE
;--------------------------------------------
LE87B       lda REG8271+0          ; Load status register
            and #$04               ; Test data ready bit
            beq LE88B              ; If set check register
            inc $00F6              ; Increment low byte save/load address
            bne LE888              ; Check overflow
            inc $00F7              ; Increment high byte save/load address
LE888:      jmp $00F2              ; Jump to zeropage routine

;--------------------------------------------
; Save register and accu before checking the result
;--------------------------------------------
LE88B:      txa                    ; 
            pha                    ; 
            tya                    ; 
            pha                    ; 
            cld                    ; 
            jsr LE899              ; Load result register
            pla                    ; 
            tay                    ; 
            pla                    ; 
            tax                    ; 
            pla                    ; Pull stack pointer ????
            rti                    ; 


;--------------------------------------------
; Interrupt request routine
;--------------------------------------------
LE899:      jmp ($00D5)            ;

The routine vectored via D5/D6

Code: Select all

;--------------------------------------------
; Interrupt request routine initialisation controller
;--------------------------------------------
LE729       jsr LE7E4              ; Read result register
            lda #$0A               ; Set number of attemps = 10
            sta $00F0
            rts


Example of the ZP Routine

Code: Select all

;============================================
; NMI LOAD ROUTINE                   HARDWARE
;--------------------------------------------
LE84F:      lda REG8271+4          ; Read data
            sta $1FFF              ; Store in memory
                                   ; address changes during NMI
            pla                    ; Pull stackpointer ????
            rti                    ; End of interrupt

User avatar
hoglet
Posts: 12665
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Help needed with Atom DOS NMI Handler

Post by hoglet »

The extra PLA is to match a PHA that the Atom Kernel NMI handler does before indirecting through the vector:

Code: Select all

  Execute NMI
  -----------

- Pushes accumulator onto stack before jumping to NMIVEC at (#200).

FFC7  48        PHA             Save accumulator onto stack
FFC8  6C 00 02  JMP (#200)      ..before jumping to NMIVEC
This restores the original accumulator value when the NMI was taken.

Dave
User avatar
John_Newcombe
Posts: 131
Joined: Tue Nov 28, 2017 9:19 am
Contact:

Re: Help needed with Atom DOS NMI Handler

Post by John_Newcombe »

I hadn't even considered that possibility. Many thanks for the prompt reply.

J
Post Reply

Return to “acorn atom and acorn system series”