Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!jarthur!nntp-server.caltech.edu!toddpw From: toddpw@nntp-server.caltech.edu (Todd P. Whitesel) Newsgroups: comp.sys.apple2 Subject: Re: FTA Modulae Keywords: Animation Message-ID: <1991Apr19.223632.9413@nntp-server.caltech.edu> Date: 19 Apr 91 22:36:32 GMT References: <47417@ut-emx.uucp> <109615@tut.cis.ohio-state.edu> <47484@ut-emx.uucp> <110011@tut.cis.ohio-state.edu> Organization: California Institute of Technology, Pasadena Lines: 90 meekins@tortoise.cis.ohio-state.edu (Tim Meekins) writes: >And for today's installment of Hacking With Tim: >"Mapping the Stack and Direct Page for Sneaky Tricks" which just so happens to be the title of today's installment of Todd Fixes Your Code.... >map something on bank 0 to bank 1 or $E1? Well, we use a trick that goes back >to the //e architecture (I think). That's right. They wanted more than 64K to be available, and decided to do truly evil bank-switching -- an entire extra memory space. The Double-res video buffers occupied the same memory areas, but went out to the screen twice as fast, with the first half of each 1 microsecond video cell coming from the 'auxiliary' 64K and the second half from the 'main' 64K. It was a truly spiffy hack, but by this time chip technnology had progressed to the point where it shouldn't have been necessary (especially not for Apple). Memory quirks in the // series make great hacking legends but are not good for practical programming -- except in this case... >are a set of soft swicthes that can be set to determine which bank is being >used. IN ADDITION, a soft switch was added to allow the Zero Page to be used >on either bank. So, on a IIgs, we can access this switch (ALTZP) to move >the DP/S to bank $00 or bank $01. In the code I'm showing below, I'll be >using the STATEREG ($C068) to modify ALTZP. You can also use SETSTDZP ($C008) >and SETZLTZP ($C009). Aighh!! This is totally wrong. The memory mapping switches that were available were: 80STORE, for accessing the auxiliary video buffers ONLY RAMRD, for memory reads from $200-$BFFF RAMWRT, for memory writes from $200-$BFFF ALTZP, for bank-switching $0-$1FF AND $D000-$FFFF simultaneously STATEREG does work, you just need to set RAMWRT instead of ALTZP. In fact, your bitmask of $30 below is the correct one for setting both RAMRD and RAMWRT. >So, in a typical routine, I'd use the following code "header": > phd ;Save the direct page > lda >$E1C068 > ora #$0030 ;Set ALTZP > sta >$E1C068 > tsx ;Save the stack in X register Nitpick note- C069 is reserved, so you should be using 8 bit access. There's no guarantee it will be a RMW register if it is ever defined. >Now all we need to do is point to the SHR area to "modify" > lda #$2000+160-2 > tcs > lda #$2000+160 > tcd That should be -1 but otherwise ok >now to scroll line 1 to line 0 [correct pei's deleted] >and now we can clean everything up: > lda >$E1C068 > and #$FFCF > sta >$E1C068 > txs > pld This is fine. One last problem: >Also, mapping the DP/S can sometimes cause some funny things to happen >to certain resources, so, if you want to make Todd happy, add a SEI/CLI >pair and turn off interrupts before running this code. Tim, you are not making me happy. You ARE AVOIDING PISSING ME OFF BECAUSE APPLETALK CRASHES YOUR DEMO. You should ALWAYS put a php/sei, plp pair around code that changes the bank-switched memory state like this or points the stack at data instead of stack stuff. If you do not then anybody with AppleTalk Installed will not be able to run your programs, and any interrupts (like sound or VBL) that occur while you are drawing to the screen will use your remapped stack as a tiny temporary buffer. Tim is lucky to have survived so long programming things this way. Todd Whitesel toddpw @ tybalt.caltech.edu P.S. At least he gets them done, though. I finally have a more or less free weekend, so LHG watchers take heart.