Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!sdcsvax!sdcc6!ix742 From: ix742@sdcc6.UUCP (James Hayes) Newsgroups: net.micro.apple Subject: Re: ROM to RAM (really DOS vs. CHARGET) Message-ID: <2620@sdcc6.UUCP> Date: Mon, 19-May-86 03:23:23 EDT Article-I.D.: sdcc6.2620 Posted: Mon May 19 03:23:23 1986 Date-Received: Fri, 23-May-86 05:47:15 EDT References: <3440@reed.UUCP> <203@neoucom.UUCP> Reply-To: ix742@sdcc6.UUCP (James Hayes) Distribution: net Organization: UC San Diego EE/CS Department. Lines: 90 wtm@neoucom.UUCP (Bill Mayhew) writes in article <203@neoucom.UUCP>: > ..... DOS links into >BASIC's "charget" routine. To save time, dos ingores everything >until it detectes a carriage return followed by control-D in the >input stream, it then parses the line until the next return comes >up. Charget is a short subrountine that is stored in page zero, >beginning at $39 (I think, but check the "Applesoft Programmer's >reference manual" to be sure.) Nope. DOS never looks at CHARGET. DOS looks at the KEYboard INput (KEYIN) vector. This lies at $38/$39 (Low/High) and contains the address of the routine that reads from the keyboard. KEYIN is used to monitor what you type. I.e. "CATALOG". DOS also looks out Character OUT (COUT $36/$37) for the routine to listen to the output of BASIC, etc.. It looks for commands like "OPEN", "CLOSE", "CATALOG" that are preceded by ^D{command}. This is how BASIC works with DOS. The Applesoft CHARGET routine also lies in page 1 but is used for an entirely different purpose. When BASIC wants the next character in the program, it calls CHARGET. This is just a memory fetch routine. Once the fetch has completed, the address of the fetch is incremented. You can modify CHARGET to filter commands in basic. I.e 10 !UNDO(3,4):PRINT "HELLO" The !UNDO command doesn't belong to BASIC. If you modify CHARGET, you can intercept the command when you see the initial !. I beleive PRODOS modifies CHARGET to look for HGR, HGR2, LOMEM, HIMEM and the like, so it can modify it's on memory map. But note that BASIC stores it's own commands in a one byte TOKEN. So modifying what HOME does (for example) is as easy as looking for one byte. I can't remember the charget address off hand, but I beleive it lives near $10-$20. > Note that the documentation about using the keyboard and >console vectors in the Apple Programmer's reference is incorrect. >DOS is very tenacious about giving up control. If either the input >or output vector is attatched to DOS, it will reinstall the other >vector you've taken over as soon as you do an I/O, thus >disconnecting your subroutine. > I've found the best way to take over control from DOS is >to attack DOS itself. If I remember right, you can steal contol >back by planting you vector in dos somewhere around $AA65. >Disassemble DOS, and look for the vector that points to the input >routine in the monitor ROM. I've used this approach to add >a keyclick subroutine. A slightly more portable way to do this is the following: Set up the addresses of the input/output hooks to point to your routines, and then ask DOS to connect them for you. This is done by calling the DOS reconnect vector at $3EA. This will automatically modify DOS's internal vectors for you. This is more reliable, for different DOS versions might have different internal vectors. $3EA will always set them properly. A sample keyclick program: $300 LDY #CLICK STY $38 ; Store it in the KEYIN vector STX $39 JMP $3EA ; Ask DOS to reconnect * CLICK BIT $C000 ; Wait for key BPL CLICK ; Keep looping BIT $C030 ; Twitch speaker LDA #20 JSR $FCA8 ; Delay BIT $C030 ; Twitch speaker again. LDA $C000 ; Read the key struck BIT $C010 ; Clear the key struck RTS ; Return Note: This DOES NOT disconnect DOS. DOS will still monitor the I/O looking for it's comands. This is very handy... I hope I haven't created more confusion than I've gotten rid of... -- Jim Hayes, UCSD EE/CS Department. ARPA: hayes@UCSD.EDU UUCP: {ihnp4, gatech, ucbvax, decvax, etc.}!sdcsvax!hayes "There are two ways to dislike poetry; one way is to dislike it, the other is to read Pope." -- Oscar Wilde