In article <20040927221306.23043.00001311@mb-m12.aol.com>, mjmahon@aol.com (Michael J. Mahon) wrote: > Has anyone used the KBIN and COUT hooks on the Apple //e > to provide input characters and to intercept output characters? > > I'm planning to do this for a "remote Apple" program, and I can find > very little information on exactly what I need to do and what liberties > I can take. > > Are there any eloquent examples of using these hooks available? > > Thanks, > > -michael > > Check out parallel computing for 8-bit Apples on my > Home page: http://members.aol.com/MJMahon/ The best example is the monitor itself or any firmware card. The actual zero page vectors are CSWL/H ($36/37) and KSWL/H ($38/39). Tracing from the reset routine, you'll see that SETVID initializes CSW to make COUT point to COUT1, and SETKBD initializes KSW to make $FD18 point to KEYIN. The INPRT () and OUTPRT () monitor commands replace these vectors with firmware entry points; DOS and ProDOS replace the vectors to trap control-D, which signals a command. This is the difference between 'PR#3' in Basic versus 'PRINT CHR$(4);"PR#3"' in DOS: the former disconnects DOS from the output stream, while the latter doesn't. In DOS 3.3, you can just replace the zero page vector(s) with your routine(s) and JSR $A851 to notify DOS of the change. Have your output handler exit via JMP $COUT1. Have your input handler do JSR KEYIN to collect a keyress then exit via RTS. I've never done this in ProDOS. -- John ---- jmatthews at wright dot edu www dot wright dot edu/~john.matthews/ In article <20040928003116.05268.00000975@mb-m23.aol.com>, mjmahon@aol.com (Michael J. Mahon) wrote: > John B. Matthews replied: > > >In article <20040927221306.23043.00001311@mb-m12.aol.com>, > > mjmahon@aol.com (Michael J. Mahon) wrote: > > > >> Has anyone used the KBIN and COUT hooks on the Apple //e > >> to provide input characters and to intercept output characters? > >> > >> I'm planning to do this for a "remote Apple" program, and I can find > >> very little information on exactly what I need to do and what liberties > >> I can take. > >> > >> Are there any eloquent examples of using these hooks available? > >> > >> Thanks, > >> > >> -michael > >> > >> Check out parallel computing for 8-bit Apples on my > >> Home page: http://members.aol.com/MJMahon/ > > > >The best example is the monitor itself or any firmware card. The > >actual zero page vectors are CSWL/H ($36/37) and KSWL/H ($38/39). > >Tracing from the reset routine, you'll see that SETVID initializes > >CSW to make COUT point to COUT1, and SETKBD initializes KSW to make > >$FD18 point to KEYIN. > > > >The INPRT () and OUTPRT () > >monitor commands replace these vectors with firmware entry points; > >DOS and ProDOS replace the vectors to trap control-D, which signals > >a command. This is the difference between 'PR#3' in Basic versus > >'PRINT CHR$(4);"PR#3"' in DOS: the former disconnects DOS from the > >output stream, while the latter doesn't. > > > >In DOS 3.3, you can just replace the zero page vector(s) with your > >routine(s) and JSR $A851 to notify DOS of the change. Have your > >output handler exit via JMP $COUT1. Have your input handler do JSR > >KEYIN to collect a keyress then exit via RTS. > > > >I've never done this in ProDOS. > > Actually, I'm interested in doing it on a bare machine. ;-) > > I understand how the hooks work and how to set them. What I'd > like to see is some lucid example of actually using them to do > useful work. Excellent! Before the AutoStart ROM, I wrote a utility to make listings easier to single-step and add new editing commands. As an example, here's the code I made CSW point to: dosbas equ $9DBF kbd equ $C000 kclr equ $C010 keyin equ $FD1B cout1 equ $FDF0 monz equ $FF69 ... slist cmp #$8D ; CR? bne cont ; no, continue bit kbd ; key pressed? bpl cont ; no, continue bit kclr ; yes, clear the strobe pha ; save this CR rdkb lda kbd bpl rdkb ; wait for another keypress cmp #$A0 ; SP? single-step beq rest ; yes, don't clear strobe bit kclr ; any other key continues cmp #$9B ; ESC? beq bas ; exit to Basic rest pla ; get CR back cont jmp cout1 bas jmp dosbas Here's a KSW routine to make control-z drop into the monitor: mykey jsr keyin cmp #$9A ; control-z? beq mon rts mon jmp monz > I plan to feed input to a slave machine from the message server, as > if it were typed on the slave, and have the slave's output captured > by a COUT hook that buffers it and sends it to another message > server queue. The intent is to allow a master machine to control > a slave machine interactively, by serving as its keyboard and display. > > When I look at the monitor listing, I see a mesh of interacting > assumptions about the value of Y, the setup of BASL, etc., and > I'd like to know _exactly_ what assumptions I can make when > writing the KEYIN and COUT routines. Without an OS or user in the way, you can do anything! Seriously, everything is just like RESET left it. How are you going to bootstrap the code? EPROM? > -michael -- John ---- jmatthews at wright dot edu www dot wright dot edu/~john.matthews/