2 ; Christian Groessler, Dec-2001
4 ; RS232 routines using the R: device (currently tested with an 850 only)
6 ; unsigned char __fastcall__ rs232_init (char hacked);
7 ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
8 ; unsigned char __fastcall__ rs232_done (void);
9 ; unsigned char __fastcall__ rs232_get (char* B);
10 ; unsigned char __fastcall__ rs232_put (char B);
11 ; unsigned char __fastcall__ rs232_pause (void); [TODO]
12 ; unsigned char __fastcall__ rs232_unpause (void); [TODO]
13 ; unsigned char __fastcall__ rs232_status (unsigned char* status,
14 ; unsigned char* errors); [TODO]
18 .import __seterrno, __do_oserror, __oserror
23 .import _close, pushax, popax
24 .importzp ptr1, tmp2, tmp3
26 .export _rs232_init, _rs232_params, _rs232_done, _rs232_get
27 .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
30 .include "../common/errno.inc"
34 rdev: .byte "R:", ATEOL, 0
41 recv_buf: .res RECVBUF_SZ
42 cm_run: .res 1 ; concurrent mode running?
50 ;----------------------------------------------------------------------------
52 ; unsigned char __fastcall__ rs232_init (char hacked);
53 ; /* Initialize the serial port. The parameter is ignored in the Atari version.
54 ; * return 0/-1 for OK/Error
61 beq iocbok ; we found one
63 lda #<EMFILE ; "too many open files"
65 seterr: jsr __seterrno
71 tay ; move iocb # into Y
73 sta tmp3 ; name length + 1
78 bcs doopen ; C set: open needed / device not already open
81 jsr _rs232_done ;** shut down if started @@@TODO check this out!!
96 lda #$0D ; mode in+out+concurrent
100 sta ICBLL,x ; zap buf len
113 cioerr: jsr fddecusage ; decrement usage counter of fd as open failed
116 .endproc ; _rs232_init
119 ;----------------------------------------------------------------------------
121 ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
122 ; /* Set the port parameters. Use a combination of the #defined values above. */
124 ; Set communication parameters.
126 ; @@@ C64 values @@@ fixit
127 ; baud rates stops word | parity
128 ; --------------------- ----- ----- | ---------
129 ; $00=50 $08=9600 $00=1 $00=8 | $00=none
130 ; $01=110 $09=19200 $80=2 $20=7 | $20=odd
131 ; $02=134.5 $0a=38400 $40=6 | $60=even
132 ; $03=300 $0b=57600 $60=5 | $A0=mark
133 ; $04=600 $0c=115200 | $E0=space
134 ; $05=1200 $0d=230400
135 ; $06=2400 $0e=future
136 ; $07=4800 $0f=future
139 ; we don't support word sizes != 8 (will never)
140 ; ignore parity for now, always none
141 ; ignore baud rate for now, always 9600
143 ; shouldn't this come from a "rs232.inc" ??
144 ErrNotInitialized = $01
151 bne work ; work only if initialized
152 lda #ErrNotInitialized
156 jsr fdtoiocb ; get iocb index into X
160 ; set handshake lines
162 lda #34 ; xio 34, set cts, dtr etc
164 lda #192+48+3 ; DTR on, RTS on, XMT on
174 ; set baud rate, word size, stop bits and ready monitoring
176 lda #36 ; xio 36, baud rate
180 ;ICAX2 = 0, monitor nothing
183 ; set translation and parity
185 lda #38 ; xio 38, translation and parity
187 lda #32 ; no translation, no parity
195 .endproc ;_rs232_params
198 ;----------------------------------------------------------------------------
200 ; unsigned char __fastcall__ rs232_done (void);
201 ; /* Close the port, deinstall the interrupt hander. You MUST call this function
202 ; * before terminating the program, otherwise the machine may crash later. If
203 ; * in doubt, install an exit handler using atexit(). The function will do
204 ; * nothing, if it was already called.
236 ;----------------------------------------------------------------------------
238 ; unsigned char __fastcall__ rs232_get (char* B);
239 ; /* Get a character from the serial port. If no characters are available, the
240 ; * function will return RS_ERR_NO_DATA, so this is not a fatal error.
250 bne work ; work only if initialized
251 lda #ErrNotInitialized
255 stx ptr1+1 ; store pointer to received char
261 lda cm_run ; concurrent mode already running?
263 jsr ena_cm ; turn on concurrent mode
265 go: ; check whether there is any input available
267 lda #STATIS ; status request, returns bytes pending
270 ; bmi cioerr ; @@@ error handling
272 lda DVSTAT+1 ; get byte count pending
274 beq nix_da ; no input waiting...
291 ; input is available: get it!
293 lda #GETCHR ; get raw bytes
294 sta ICCOM,x ; in command code
301 ; bmi cioerr ; @@@ error handling
304 sta (ptr1,x) ; return received byte
311 nix_da: lda #ErrNoData
318 ;----------------------------------------------------------------------------
320 ; unsigned char __fastcall__ rs232_put (char B);
321 ; /* Send a character via the serial port. There is a transmit buffer, but
322 ; * transmitting is not done via interrupt. The function returns
323 ; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
331 bne work ; work only if initialized
332 lda #ErrNotInitialized
340 lda cm_run ; concurrent mode already running?
342 jsr ena_cm ; turn on concurrent mode
344 ; @@@TODO: check output buffer overflow
345 go: lda #PUTCHR ; put raw bytes
346 sta ICCOM,x ; in command code
352 pla ; get the char back
361 ;----------------------------------------------------------------------------
363 ; unsigned char __fastcall__ rs232_pause (void);
364 ; /* Assert flow control and disable interrupts. */
370 ;----------------------------------------------------------------------------
372 ; unsigned char __fastcall__ rs232_unpause (void);
373 ; /* Re-enable interrupts and release flow control */
379 ;----------------------------------------------------------------------------
381 ; unsigned char __fastcall__ rs232_status (unsigned char* status,
382 ; unsigned char* errors);
383 ; /* Return the serial port status. */
393 ; enable concurrent rs232 mode
394 ; gets iocb index in X
395 ; all registers destroyed
399 lda #40 ; XIO 40, start concurrent IO
401 sta cm_run ; indicate concurrent mode is running
413 lda #$0D ; value from 850 man, p62. must be 0D?,
414 sta ICAX1,x ; or any non-zero?