Hi folks!

I dunno if anyone's thought of this before, but over Xmas I came up with a
nifty way of using the break button safely. With a program sitting over
the ROM in section A, I was using the following code to return basic: 

        ORG 62h
back    OUT (251),A     ; Ensure XMEM bit is disabled
        OUT (250),A     ; Page ROM into section A.
nmi     LD  A,31
        JR  back

Now, this works fine, but the stream of nmis that gets sent by the button 
usually fills up the nmi handler stack, which is nicely placed above the 
page allocation table, thus corrupting it and making lots of nasty things 
happen later on.

So, I decided to alter the code to pause for a bit before returning to 
basic, and junking any return addresses generated by subsequent nmis, 
avoiding any stack overflow:

        ORG 62h
back    OUT (251),A
        OUT (250),A
nmi     POP HL          ; junk return address
        LD  BC,1000h
loop    DJNZ loop
        DEC C
        JR  NZ,loop
        LD  A,31
        JR  back

Hope this helps someone.

                    \\///
                    (o o)
+----------------ooO-(_)-Ooo----------------+
|  Steve Taylor          [EMAIL PROTECTED]  |
|  Pembroke College                         |
|  Cambridge CB2 1RF                        |
+-------------------------------------------+

Reply via email to