1 ; A task switcher for the Acorn Electron. 2 3 ; Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> 4 5 ; This program is free software; you can redistribute it and/or modify it under 6 ; the terms of the GNU General Public License as published by the Free Software 7 ; Foundation; either version 3 of the License, or (at your option) any later 8 ; version. 9 10 ; This program is distributed in the hope that it will be useful, but WITHOUT 11 ; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 ; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 ; details. 14 15 ; You should have received a copy of the GNU General Public License along with 16 ; this program. If not, see <http://www.gnu.org/licenses/>. 17 18 .include "macros.oph" 19 20 .org $2000 21 .text 22 23 main: 24 jsr install_handler 25 rts 26 27 ; install the interrupt handler address in IRQ1V 28 ; 29 ; affects: A 30 31 install_handler: 32 sei 33 .invoke mov16 $204, old_handler 34 .invoke store16 handler, $204 35 cli 36 rts 37 38 ; handle interrupts 39 ; 40 ; affects: (temporary stack usage) 41 42 handler: 43 pha ; A -> stack 44 txa 45 pha ; X -> stack 46 tya 47 pha ; Y -> stack 48 .invoke push16 $70 49 50 ; test PC for execution of ROM routines 51 ; these are probably not re-entrant 52 53 ; obtain the stack location of the stored PC MSB 54 tsx 55 txa 56 sta $70 57 lda #$01 ; $01xx 58 sta $71 59 60 ldy #6 ; offset of MSB (<empty>, Y, X, A, F, LSB, MSB) 61 lda ($70), y 62 63 ; reference the stack location and compute PC MSB & $80 64 and #$80 65 cmp #$80 66 67 ; exit if PC MSB & $80 != 0 68 beq exit_handler 69 70 ; increment a counter 71 .invoke add16 1, $7000 72 73 exit_handler: 74 .invoke pull16 $70 75 pla 76 tay ; stack -> Y 77 pla 78 tax ; stack -> X 79 pla ; stack -> A 80 jmp (old_handler) 81 82 old_handler: .word 0 83 84 ; vim: tabstop=4 expandtab shiftwidth=4