Newsgroups: comp.sys.apple2.programmer
Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!usc!howland.reston.ans.net!cs.utexas.edu!utnut!torn!fonorola!alpha.vaxxine.com!mhackett
From: mhackett@vaxxine.com (Michael Hackett)
Subject: Re: Resetting Stack Ptr under CDA
Message-ID: <D2zDnw.B8D@vaxxine.com>
Organization: Some Assembly Required
X-Newsreader: MacSOUP 1.0d4
References: <3fn8j5$lmh@gap.cco.caltech.edu> <3fno2e$64h@gap.cco.caltech.edu>
Date: Wed, 25 Jan 1995 21:43:35 GMT
Lines: 44

In article <3fno2e$64h@gap.cco.caltech.edu>, nathan@cco.caltech.edu
(Nathan Mates) wrote:

> - Even if you move the stack ptr out of page 01, the system thinks
> it's perfectly OK to stomp all over page 01. I finally had to
> backup and restore page 01 around my code before it could exit correctly.

I think this has something to do with the "emulation stack pointer"
which will be used when an interrupt routine is invoked.  See GS TN #88
("The Page One Stack in a 16-Bit World"), by one Mr. Tangent.  Here is
some code from Splat! to implement the procedure described in the note:


EMULSTACK  gequ  $010100        ; LSB of emulation mode (page 1) stack
AUXSTACK   gequ  $010101        ; LSB of page 1 stack when in auxiliary
;                               ;   memory (ie. bank 1)
ALTZP      gequ  $e0c016        ; MSb is 1 if auxiliary-memory stack
;                               ;   and zero page are selected

         tsc                    ; copy stack ptr. to accumulator
         short m
         xba                    ; check MSB of stack pointer
         cmp   #1               ; is stack on page 1?
         bne   notOne           ; no -> nothing extra to do
         ldx   #0               ; on page 1 -> assume in memory memory
         lda   >ALTZP           ; check "in main or aux. memory?" switch
         bpl   saveEmul         ; bit 7 clear -> in main memory
         inx                    ; no, in aux. memory -> save value in
;                               ;   alternate location
saveEmul xba                    ; save LSB of SP in system location
         sta   >EMULSTACK,x     ; (x=0 for main stack/ZP; x=1 for aux.)
notOne   long  m

; at this point, you should save the old stack pointer and switch to
;   your stack space, and restore the old SP when done


Feel free to critique/correct my code, but I think it is correct.  (Does
it meet with your approval, Dave?)  Use it as you wish.  Hope it helps
straighten out your problem.

========================================================================
Michael Hackett       Internet: mhackett@vaxxine.com    GEnie: M.HACKETT
Some Assembly Required    Voice: (905) 687-1729      BBS: (905) 687-9987
