Path: news1.icaen!news.uiowa.edu!chi-news.cic.net!199.60.229.3!newsfeed.direct.ca!news.uoregon.edu!cie-2.uoregon.edu!nparker From: nparker@cie-2.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2.programmer Subject: Re: Where is ML address for GOTO and other Applesoft commands? Date: 22 Jun 1997 09:43:00 GMT Organization: University of Oregon Campus Information Exchange Lines: 89 Message-ID: <5ois34$p4i@pith.uoregon.edu> References: <5oebp4$5fi$1@mentor.telis.org> NNTP-Posting-Host: cie-2.uoregon.edu NNTP-Posting-User: nparker In article <5oebp4$5fi$1@mentor.telis.org> user writes: >I'm writing a program to intercept the input of a text game that I wrote. > >There is no ONE place to put a GOSUB in basic to see if the player wants >to save or load a game. > >The save and load routines, however, are already written in Applesoft. > >This is why I am writing an assembly language program to intercept input. > If the open apple key is down, and the s or l keys are pressed, the >machine language program saves the line number of the current statement >executing, and then issues a "GOTO 8000" to Applesoft. Line 8000 is where >the save routine is, and the program would branch to GOTO 8500 for save. > >What is the APPLESOFT machine language address that handles GOTO? > >What variables do you have to set or initialize before calling this >routine? > >Would this be a good approach? Perhaps the AL program could issue a break >to the basic program. The open apple key would be checked, keyboard >compared to L and S, GOTO's and load or save executed (in basic), and then >AL send "CONT" command to APPLESOFT? This all sounds like a lot more work than is really necessary. Are you sure you can't just sprinkle, say, "GOSUB 63000" liberally throughout your program, and then have 63000 KB = PEEK (49152) - 128: IF KB < 0 THEN RETURN 63010 POKE 49168,0:KB = KB - 32 * (KB > 96): IF PEEK (49249) > 127 AND (KB = 76 OR KB = 83) THEN 8000 63020 RETURN ? Remember that if you use machine language, it'll have to work exactly the same way--i.e. you'll have to sprinkle "CALL 768" liberally through your BASIC code, and have your machine language do pretty much the same thing as the above subroutine. (Actually, there is a way to avoid sprinkling CALLs everywhere...you can patch directly into BASIC's new statement fetcher, but that's a whole new can of worms, best left for another post.) If you insist on using machine language, BASIC's GOTO handler is at $D93E. You probably don't want to use this directly, though...it immediately starts trying to parse a line number from the BASIC program text. If BASIC's next-token pointer (TXTPTR, at $B8 and $B9) isn't pointing to the first digit of a line number (and it almost certainly won't be...it'll be pointing to whatever came immediately after your CALL command), you'll crash with ?SYNTAX ERROR. Fortunately there's a later entry point to the same subroutine that doesn't suffer from this drawback. Just put your line number in $50 (low byte) and $51 (high byte) and JMP $D941. This causes BASIC to resume executing at the given line number, if it exists (otherwise you get ?UNDEF'D STATEMENT ERROR). For example, here's the above subroutine translated to machine language: LINNUM EQU $50 KBD EQU $C000 KBDSTRB EQU $C010 BUTN0 EQU $C061 GOTO EQU $D93E LDA KBD ;Check keyboard BMI L1 ;Got key? RET RTS ;If not, return L1 BIT KBDSTRB ;Else clear keyboard BIT BUTN0 ;Open-apple key (or button 0) down? BPL RET ;If not, return CMP #$D0 ;Is key lowercase? BCC L2 SBC #$20 ;If so, upshift L2 CMP #$CC ;Is it "L"? BEQ DOGOTO ;If so, GOTO 8000 CMP #$D3 ;Is it "S"? BNE RET ;If not, return DOGOTO LDA #<8000 ;Put "8000" (decimal) into LINNUM STA LINNUM LDA #>8000 STA LINNUM+1 JMP GOTO+3 ;GOTO 8000 - Neil Parker -- Neil Parker, nparker@{cie-2,cie}.uoregon.edu, http://cie-2.uoregon.edu/~nparker "Bad move, Neil!" -- The Tick Unsolicited commercial e-mail to my address will be discarded unread.