[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Input/output on the Apple ][



In article <1h07vtu.8hm9sg17inxicN%dempson@actrix.gen.nz>,
David Empson <dempson@actrix.gen.nz> wrote:
><sam124@operamail.com> wrote:
>
>> I would like to do single character output using data stored in the
>> 6502's accumulator.  I would also like to do single character input,
>> with and without echoing.
>
>The standard routine to output a character is COUT, which is at $FDED.
>This allows for redirection of output to a slot using the PR#n command,
>capture by DOS 3.3 or ProDOS's BASIC.SYSTEM (e.g. output to text files),
>etc.  A simple JSR $FDED will output a character in the accumulator,
>typically to the screen.  The X and Y registers are preserved.
>
>If you want to always output to the screen (bypassing redirection with
>PR#n etc.) you can call COUT1 ($FDF0) directly, but this can cause
>compatibility problems with 80-column display mode on some machines.
>
>Note that the screen output routines expect characters passed to COUT to
>have the high order bit set, e.g. "A" is $C1, not $41.
>
>The screen output routines take care of the text output window,
>scrolling, etc.
>
>For keyboard input, you can do it at two levels:
>
>(a) Direct hardware input.
>(b) Call an appropriate monitor routine.
>
>For direct hardware input, your code sits in a loop polling the keyboard
>input register, which is at location $C000.  When a key is pressed, the
>high order bit of this location is set, and the lower order 7 bits are
>the ASCII value of the key.  You then need to reset the keyboard latch
>by reading or writing location $C010, otherwise the keypress will remain
>pending.  Typical code is as follows:
>
>WAITKEY  LDA $C000
>         BPL WAITKEY
>         STA $C010
>         RTS
>
>This method won't display any kind of cursor and cannot be redirected
>from another source (e.g. a slot or text file input).  If you want to
>echo the character to the screen, call COUT after your WAITKEY routine
>has returned a character, but check for control characters before
>blindly outputting anything, e.g. by comparing with $A0 (space with high
>order bit set) and avoiding echo of anything less than that.

You do want to echo some control characters though.  For instance CR....

>The standard monitor routine for reading a single character is RDKEY,
>location $FD0C.  This can be redirected to input from slots (IN#n) or
>DOS/ProDOS file input.  If the standard screen input routine is used, it
>will display a blinking cursor while waiting for input, but is otherwise
>functionally equivalent to the WAITKEY loop above.  (This is the
>equivalent of the GET statement in BASIC.)  You have to call COUT to
>echo the character.
>
>If you don't want to allow redirection from other inputs but do want a
>cursor, you can call the KEYIN routine ($FD1B) directly.  It is
>otherwise equivalent to RDKEY.
>
>If you want to read a whole line of input, with echoing and editing
>(same input routine used by Integer BASIC, Applesoft BASIC, the monitor,
>mini-assembler and DOS 3.3 and ProDOS's BASIC.SYSTEM), call GETLN, which
>is $FD6A.  You need to set up a prompt character first by storing it in
>location $33.  The input line is stored in the buffer at $200-$2FF, with
>a carriage return ($8D) as the last character.  The length of the line
>is also returned in the X register.
>
>[I had to look up GETLN's address - the rest of the details were from
>memory, but I haven't used any of this stuff for more than ten years!]
>
>-- 
>David Empson
>dempson@actrix.gen.nz


-- 
----------------------------------------------------------------
Paul Schlyter,  Grev Turegatan 40,  SE-114 38 Stockholm,  SWEDEN
e-mail:  pausch at stockholm dot bostream dot se
WWW:     http://stjarnhimlen.se/