[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Read full 8-bit character from serial port?
Jorge Chamorro Bieling <bieling@terra.es> wrote:
> Ron Kneusel <oneelkruns@hotmail.com> wrote:
>
> > I'm using an Apple IIgs to read/write characters while debugging a
> > program on my PC. I can send a full 8-bit character easily enough but
> > my attempts to read a full 8-bit character have failed so far. The
> > high-bit is always set no matter what.
> >
> > I've tried using IN#2 and the monitor routine at $FD0C. I've also
> > tried using the SSC routine at $C205 with the same result. For output
> > I'm using PR#2 and $FDED which seems to send a full 8-bit character.
> >
> > So, any ideas on how to read a full 8-bit character from assembly?
>
>
> SCC_A_CMD EQU $C039 //scc CHANNEL A
> SCC_A_DATA EQU $C03B
> SCC_B_CMD EQU $C038 //scc CHANNEL B
> SCC_B_DATA EQU $C03A
>
> LDA SCC_A_CMD //DUMMY READ TO RESET 8530 POINTER TO 0
> // AND TO MAKE SURE THAT WE ACCESS REGISTER 0
> //IN THE NEXT LINE'S LDA SCC_A_DATA
>
> WAIT_RX LDA SCC_A_DATA //READ 8530 READ REGISTER 0
> AND #$01 //BIT 0 MEANS RX CHAR AVAILABLE
> BEQ WAIT_RX
>
> // THERE'S A CHAR IN THE 8530 RX BUFFER
> LDA #$01 // SET THE POINTER TO 8530 RR1
> STA SCC_A_CMD
> LDA SCC_A_DATA // READ THE 8530 READ REGISTER 1
> AND #$70 // D4=PARITY ERR, D5=RX BUFFER OVERFLOW
> BEQ ITS_OK // D6=FRAMING ERR
> JMP THERE_WAS_AN_RX_ERROR
>
> // THE RX BUFFER IS THE READ REGISTER 8
> ITS_OK LDA #$08 // WE WANT TO READ THE 8530 RR8
> STA SCC_A_CMD // SET 8530 'POINTER' TO REGISTER 8
> LDA SCC_A_DATA // READ 8530'S READ REGISTER 8
> JSR STORE // STORE THE RX CHAR SOMEWHERE
> JMP WAIT_RX
>
> I don't know which scc channel (A or B) is mapped to which
> slot/connector. Experiment by replacing SCC_A with SCC_B.
SCC_A is slot 2 (modem port), if I remember right. (All manuals boxed up
at the moment.)
The above code is not compatible with any interrupt-driven code using
either port of the SCC (e.g. AppleTalk or the standard serial firmware).
To be on the safe side, you should disable interrupts around modal
operations such as selecting an SCC register (e.g. PHP/SEI before each
STA SCC_A_CMD, and PLP after the corresponding LDA SCC_A_DATA).
It should also be noted that direct access to the SCC doesn't give you
any buffering, so you have to poll it often enough to avoid losing
receive characters. If the standard firmware is active and has buffering
enabled, it has an interrupt handler to receive characters, so this code
might not work at all (the buffer will get the character as soon as it
arrives).
> There's no SCC setup here, and you should first set it up (the 8530) by
> other means. For example via an IN#2 or whatever.
Initializing the SCC is rather complex, so leaving it to the firmware is
a good idea.
> Once the 8530 is setup, I think this should work. It has not been tested,
> though.
I haven't done any direct SCC programming for a while but it looks about
right, given the SCC is already initialized.
> The 8530 has 16 write registers and 16 read registers.
> You tell the 8530 which register you'd like to access by first writing
> to SCC_A_CMD a 'pointer' to the register: write a 1 to access register
> one, a 2 to access register 2, etc.
> The register contents can then be read at the address SCC_A_DATA.
>
> It's a good idea to start by reading SCC_A_CMD, because this resets the
> pointer to register 0 and this way you avoid writing accidentally where
> you shouldn't.
>
> Good luck !
--
David Empson
dempson@actrix.gen.nz