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
24 .import _close, pushax, popax, popa
25 .importzp ptr1, tmp2, tmp3
27 .export _rs232_init, _rs232_params, _rs232_done, _rs232_get
28 .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
31 .include "../common/errno.inc"
35 rdev: .byte "R:", ATEOL, 0
41 recv_buf: .res RECVBUF_SZ
43 cm_run: .res 1 ; concurrent mode running?
51 ;----------------------------------------------------------------------------
53 ; unsigned char __fastcall__ rs232_init (char hacked);
54 ; /* Initialize the serial port. The parameter is ignored in the Atari version.
55 ; * return 0/-1 for OK/Error
62 beq iocbok ; we found one
64 lda #<EMFILE ; "too many open files"
66 seterr: jsr __seterrno
72 tay ; move iocb # into Y
74 sta tmp3 ; name length + 1
79 bcs doopen ; C set: open needed / device not already open
82 jsr _rs232_done ;** shut down if started @@@TODO check this out!!
97 lda #$0D ; mode in+out+concurrent
101 sta ICBLL,x ; zap buf len
114 cioerr: jsr fddecusage ; decrement usage counter of fd as open failed
117 .endproc ; _rs232_init
120 ;----------------------------------------------------------------------------
122 ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
124 ; Set communication parameters.
126 ; params contains baud rate, stop bits and word size
127 ; parity contains parity
129 ; 850 manual documents restrictions on the baud rate (not > 300), when not
130 ; using 8 bit word size. So only 8 bit is currently tested.
133 ; shouldn't this come from a "rs232.inc" ??
134 ErrNotInitialized = $01
142 bne work ; work only if initialized
143 lda #ErrNotInitialized
147 jsr fdtoiocb ; get iocb index into X
148 bmi inverr ; shouldn't happen
151 ; set handshake lines
153 lda #34 ; xio 34, set cts, dtr etc
155 lda #192+48+3 ; DTR on, RTS on, XMT on
166 ; set baud rate, word size, stop bits and ready monitoring
168 lda #36 ; xio 36, baud rate
170 jsr popa ; get parameter
172 ;ICAX2 = 0, monitor nothing
176 ; set translation and parity
178 lda #38 ; xio 38, translation and parity
181 ora #32 ; no translation
190 inverr: jmp __inviocb
192 .endproc ;_rs232_params
194 cioerr: jmp __do_oserror
197 ;----------------------------------------------------------------------------
199 ; unsigned char __fastcall__ rs232_done (void);
200 ; /* Close the port, deinstall the interrupt hander. You MUST call this function
201 ; * before terminating the program, otherwise the machine may crash later. If
202 ; * in doubt, install an exit handler using atexit(). The function will do
203 ; * nothing, if it was already called.
231 ;----------------------------------------------------------------------------
233 ; unsigned char __fastcall__ rs232_get (char* B);
234 ; /* Get a character from the serial port. If no characters are available, the
235 ; * function will return RS_ERR_NO_DATA, so this is not a fatal error.
243 bne work ; work only if initialized
244 lda #ErrNotInitialized
248 stx ptr1+1 ; store pointer to received char
254 lda cm_run ; concurrent mode already running?
256 jsr ena_cm ; turn on concurrent mode
258 go: ; check whether there is any input available
260 lda #STATIS ; status request, returns bytes pending
263 bmi cioerr ; @@@ error handling
265 lda DVSTAT+1 ; get byte count pending
267 beq nix_da ; no input waiting...
269 ; input is available: get it!
271 lda #GETCHR ; get raw bytes
272 sta ICCOM,x ; in command code
279 bmi cioerr ; @@@ error handling
282 sta (ptr1,x) ; return received byte
289 nix_da: lda #ErrNoData
296 ;----------------------------------------------------------------------------
298 ; unsigned char __fastcall__ rs232_put (char B);
299 ; /* Send a character via the serial port. There is a transmit buffer, but
300 ; * transmitting is not done via interrupt. The function returns
301 ; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
309 bne work ; work only if initialized
310 lda #ErrNotInitialized
318 lda cm_run ; concurrent mode already running?
320 jsr ena_cm ; turn on concurrent mode
322 ; @@@TODO: check output buffer overflow
323 go: lda #PUTCHR ; put raw bytes
324 sta ICCOM,x ; in command code
330 pla ; get the char back
339 ;----------------------------------------------------------------------------
341 ; unsigned char __fastcall__ rs232_pause (void);
342 ; /* Assert flow control and disable interrupts. */
348 ;----------------------------------------------------------------------------
350 ; unsigned char __fastcall__ rs232_unpause (void);
351 ; /* Re-enable interrupts and release flow control */
357 ;----------------------------------------------------------------------------
359 ; unsigned char __fastcall__ rs232_status (unsigned char* status,
360 ; unsigned char* errors);
361 ; /* Return the serial port status. */
371 ; enable concurrent rs232 mode
372 ; gets iocb index in X
373 ; all registers destroyed
377 lda #40 ; XIO 40, start concurrent IO
379 sta cm_run ; indicate concurrent mode is running
391 lda #$0D ; value from 850 man, p62. must be 0D?,
392 sta ICAX1,x ; or any non-zero?