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

Re: P8/6502 question



In article <3oao6s$ae0@acme.freenet.columbus.oh.us>
dalloff@freenet.columbus.oh.us (Dave Althoff) writes:
>[...munch, crunch, chomp, yum yum...]          Under DOS 3.3, I can open a
>file using Applesoft, then issue a READ instruction, then my 6502 program
>can collect characters from the file by calling RDCHAR (which calls
>the DOS character input routine pointed to by KSW).  Does this work in P8,
>or do I have to locate and read the buffer manually?

It ought to work in P8.  Keep in mind, though, that DOS 3.3 give you the
characters from the file with the high bit set, and ProDOS gives you the high
bits clear.

>Also, (I know, I COULD look this up...but this is faster and easier!) once
>I read a string into the input buffer ($200), how can I transfer it into
>an Applesoft string from 6502?  In other words, how can I find Q1$ and
>assign the data in the buffer to it.  If it helps, I'm limiting the input
>string to 81 characters.

Here's an input-anything subroutine that might help:

              INPUTTKN  EQU $84            ;INPUT token
              FORPNT    EQU $85            ;ptr for COPYTEMP
              CHRGET    EQU $B1            ;get next byte from pgm text
	      IN        EQU $0200          ;input buffer
	      INLIN     EQU $D52C          ;get line of input, mask hi bit
	      COPYTEMP  EQU $DA9A          ;make temp str descr permanent
	      CHKSTR    EQU $DD6C          ;make sure var is str
              PTRGET    EQU $DFE3          ;get var from pgm text
              ERRDIR    EQU $E306          ;give ?ILLEGAL DIRECT ERROR
	      STRLIT    EQU $E3E7          ;save str & build temp descr
			ORG $0300
0300:C9 84              CMP #INPUTTKN      ;is next token INPUT?
0302:D0 1E              BNE EXIT           ;if not, quit
0304:20 06 E3           JSR ERRDIR         ;make sure prog is running
0307:20 B1 00           JSR CHRGET         ;gobble INPUT token
030A:20 E3 DF           JSR PTRGET         ;get var name
030D:20 6C DD           JSR CHKSTR         ;make sure it's a string
0310:85 85              STA FORPNT         ;save pointer to var for COPYTEMP
0312:84 86              STY FORPNT+1
0314:20 2C D5           JSR INLIN          ;get line of input
0317:A0 02              LDY #>IN
0319:A9 00              LDA #<IN
031B:AA                 TAX
031C:20 E9 E3           JSR STRLIT+2       ;copy str to safe place
031F:20 9A DA           JSR COPYTEMP       ;save descriptor in var
0322:60       EXIT      RTS

To use this routine, point the ampersand vector at its first byte ($300 in
the above listing, but it's relocatable, so you can put it anywhere).
Then, in your program, you can put this:

     &  INPUT A$

to get a line of input into A$.

But what if you already have a line of input in the input buffer, and you
just want to save it in a string?  Simple--just NOP out the three bytes of
the JSR INLIN instruction.  Or better yet, replace it with a JSR to a
subroutine that gets your line of text from the disk and filters it as
desired.  (Just make sure that your JSR INLIN replacement clears the high
bit of every character, and leaves a $00 byte at the end of the input
line.)

               - Neil Parker
--
Neil Parker, nparker@{cie-2,cie}.uoregon.edu, http://cie-2.uoregon.edu/~nparker

                     "Bad move, Neil!"  -- The Tick