Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!europa.eng.gtefsd.com!library.ucla.edu!news.mic.ucla.edu!unixg.ubc.ca!acs.ucalgary.ca!sbdocker From: sbdocker@acs.ucalgary.ca (Sean Brendan Dockery) Subject: Re: IIe Auxiliary Memory and the Apple IIgs Message-ID: Date: Sat, 30 Oct 1993 21:45:51 GMT References: <2ac1h7$rl5@crcnis1.unl.edu> Organization: Griffin Software Development Lines: 272 In article dempson@swell.actrix.gen.nz (David Empson) writes: | In article <2ac1h7$rl5@crcnis1.unl.edu> gberigan@cse.unl.edu (Greg | Berigan) writes: | | > How does one go about accessing Bank $01 (the second 64K found in 128K | > Apple II's) without using 65c816 instructions? I take it IIe methods | > will work fine on a IIgs, and involves telling the computer that we're | > going to be treating aux memory as if it were main memory. | > | > My goal is to find a way to save the contents of aux memory to a disk | > without clobbering main memory. Is this possible, or would the method | > of switching the memory be undone by the save command? Assume ProDOS. There is no possible way that this could be done by the "SAVE" command under BASIC. It is possible to write your own command that you could add on to the BASIC.SYSTEM external command chain. | You might be able to use this technique to save the auxiliary memory | hi-res screen ($2000-$3FFF) by enabling double hi-res mode with | 80STORE active, then select page 2 and save $2000-$3FFF from main memory. Keep It Simple, Stupid. (Disclaimer: I'm not calling you stupid, Dave--it is just a cliche to promote maintaining a simple model. :-) Why not copy the whole bank in three steps? The first stage would involve copying the auxilliary zero page, the second would be copying the whole 48K, and the last would muck around with the language card soft switches. I wouldn't bother trying to deal with text or hi-res page 1x. | ProDOS-8 cannot access other areas of auxiliary memory, because you | would have to switch the main 48k bank, and you'd lose the ProDOS | global page in the process. See below response regarding this method. | You certainly can't save the auxiliary language card space! And why not? I imagine that it could be done in a fairly straight forward manner (assuming that you know how to manipulate the language card soft switches.) | A better method would be to temporarily save parts of main memory | elsewhere (allocate a handle and copy a chunk of bank zero into it), | then copy the bank one area into bank zero and save it. Finally, | restore the original contents of the bank zero area. This is fine if you are using an Apple IIGS, but as the original author stated, he would rather it be without the use of the 65816. If you plan on using 6502, it would be better to allocate a 2K (completely arbitrary on my part) file buffer which would serve as a repository for bytes read from auxilliary memory. The routine that would read auxilliary memory would have to reside on the zero page, but that is a minor obstacle. | This method is likely to cause problems if you're trying to do it | behind the back of someone else's program, especially if it uses | interrupts. So, you simply must disable interrupts during the time that you are mucking around with the softswitches and reading. This should disable interrupts for about a maximum of 15 cycles. Here is a little pseudo-code of what it might be appropriate to do. main routine open file read aux zero page memory write it to file read bulk 48K of aux memory write it to file read language card memory write it to file close file go bye-bye Here is some 6502 code to handle most of the process. I thought that I might as well post it as it might be a learning experience to some. The code is rather messy (as I am doing it off the top of my head,) but I think (hope) that it is legible. I have not included the code to read the language card for the fact that I am uncomfortable working with the language card soft switches as I have had little experience in the past. Also missing are the main routine to co-ordinate everything and routines to open and close the file. By the way, why would you want a binary image of the language card RAM (and above.) You're not trying to disassble ProDOS, are you? :-) --- careful with d'em scissors --- careful with d'em scissors --- BufPtr = $06 FileBufPtr = $08 ChrGet = $B1 PRODOS = $BF00 ; entry to ProDOS MLI CLR80COL = $C000 ; disable 80-column firmware paging SET80COL = $C001 ; re-enable 80-column firmware paging MAINRD = $C002 ; switch in bank 0 RAM CARDRD = $C003 ; switch in bank 1 (Aux) RAM CLRAUXZP = $C008 ; disable bank 1 (Aux) ZP and stack SETAUXZP = $C009 ; enable bank 1 (Aux) ZP and stack *------------------------ ReadZP = * sta SETAUXZP ; enable aux zp and stack ldx #$00 :loop0 lda $0000,x ; move zero page sta FileBufStart,x inx bne :loop0 :loop1 lda $0100,x ; move stack sta FileBufStart+$100,x inx bne :loop1 sta CLRAUXZP ; enable main zp and stack lda #$02 ; 0.5K for writing sta WrLen+1 jsr PRODOS ; write what we have read dfb $CB da WriteParms bcs ERROR rts ; we are done. *------------------------ Read48K = * lda #$00 ; initialize read pointer to $0200 sta BufPtr lda #$02 sta BufPtr+1 jsr SwapRoutine ; put our read routine in ZP :init lda #FileBufStart ; initialize the file pointer (again) sta FileBufPtr lda #/FileBufStart sta FileBufPtr+1 :read jsr ReadAuxChar ; get char from AUX mem inc BufPtr ; increment our "read" pointer bne :skip1 inc BufPtr+1 :skip1 sta (FileBufPtr) ; put char in file buffer inc FileBufPtr ; next position, please. bne :skip2 inc FileBufPtr+1 :skip2 sec ; our file buffer is 2K (arbitrary) lda FileBufPtr ; make sure we haven't exceeded it. sbc #/FileBufStart cmp #$08 blt :skip3 ; continue reading until full sta WrLen+1 ; 2K for writing (.A contains $08) jsr PRODOS ; write the 2K buffer to the file dfb $CB da WriteParms bcs ERROR ; write your own handler. :-) :skip3 lda BufPtr+1 cmp #$D0 ; in the language card area? blt :init ; nope, not yet. jsr SwapRoutine ; put ZP back into original form sec ; make sure we have correct write count lda FileBufPtr+1 sbc #/FileBufStart sta WrLen+1 jsr PRODOS ; write remaing characters dfb $CB da WriteParms bcs ERROR rts ; we are done. *------------------------ * this routine gets moves to the bank 0 zero page so it can * still be executable when we switch in the aux 48k ram for * reading (under normal circumstances, it would normally crash * horribly.) myChrGet = * sta CARDRD ; read enable AUX RAM lda (BufPtr) ; read a character sta MAINRD ; read enable MAIN RAM rts ; we should be a happy camper! *------------------------ ReadAuxChar = * php ; better safe than sorry sei sta CLR80COL ; 80-column page mapping off jsr ChrGet ; get char from AUX memory sta SET80COL ; (assume that it was on) plp rts *------------------------ SwapRoutine = * ldx #$09 ; swap 9 byte routine with ZP image :loop lda myChrGet,x pha lda ChrGet,x sta myChrGet,x pla sta ChrGet,x dex bpl :loop rts *------------------------ WriteParms = * dfb 4 ; number of parms (4) ds 1 ; file reference number da FileBufStart ; start of data buffer WrLen dw $0000 ; write X number of chars to file ds 2 ; don't care about transfer count. ;-) ds \ ; merlin directive to fill to page boundary *------------------------ * this should now reside on a page boundary FileBufStart = * ds 256 ; reserve 1K ds 256 ds 256 ds 256 ds 256 ; and a 2nd K as well ds 256 ds 256 ds 256 --- careful with d'em scissors --- careful with d'em scissors --- | dempson@swell.actrix.gen.nz I hope someone will make use of this "blurb." :-) -- Sean Dockery dockery@griffin.cuc.ab.ca sbdocker@acs.ucalgary.ca Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!europa.eng.gtefsd.com!library.ucla.edu!news.mic.ucla.edu!unixg.ubc.ca!acs.ucalgary.ca!sbdocker From: sbdocker@acs.ucalgary.ca (Sean Brendan Dockery) Subject: Correction to Re: IIe Auxiliary Memory and the Apple IIgs Message-ID: Date: Sat, 30 Oct 1993 21:54:09 GMT References: <2ac1h7$rl5@crcnis1.unl.edu> Organization: Griffin Software Development Lines: 25 I have a small error in the code which I posted. If you do not correct it, it is extremely likely that the code will crash. In article I wrote: | SwapRoutine = * | ldx #$09 ; swap 9 byte routine with ZP image The previous line should read 'ldx #$08' not 'ldx #$09'. The routine swaps 9 bytes (0..8) not 10 (0..9). :-) | :loop lda myChrGet,x | pha | lda ChrGet,x | sta myChrGet,x | pla | sta ChrGet,x | dex | bpl :loop | rts -- Sean Dockery dockery@griffin.cuc.ab.ca sbdocker@acs.ucalgary.ca