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
36 rdev: .byte "R:", ATEOL, 0
42 recv_buf: .res RECVBUF_SZ
44 cm_run: .res 1 ; concurrent mode running?
52 ;----------------------------------------------------------------------------
54 ; unsigned char __fastcall__ rs232_init (char hacked);
55 ; /* Initialize the serial port. The parameter is ignored in the Atari version.
56 ; * return 0/-1 for OK/Error
63 beq iocbok ; we found one
65 lda #<EMFILE ; "too many open files"
67 seterr: jsr __seterrno
73 tay ; move iocb # into Y
75 sta tmp3 ; name length + 1
80 bcs doopen ; C set: open needed / device not already open
83 jsr _rs232_done ;** shut down if started @@@TODO check this out!!
98 lda #$0D ; mode in+out+concurrent
102 sta ICBLL,x ; zap buf len
115 cioerr: jsr fddecusage ; decrement usage counter of fd as open failed
118 .endproc ; _rs232_init
121 ;----------------------------------------------------------------------------
123 ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
125 ; Set communication parameters.
127 ; params contains baud rate, stop bits and word size
128 ; parity contains parity
130 ; 850 manual documents restrictions on the baud rate (not > 300), when not
131 ; using 8 bit word size. So only 8 bit is currently tested.
139 bne work ; work only if initialized
140 lda #RS_ERR_NOT_INITIALIZED
144 jsr fdtoiocb ; get iocb index into X
145 bmi inverr ; shouldn't happen
148 ; set handshake lines
150 lda #34 ; xio 34, set cts, dtr etc
152 lda #192+48+3 ; DTR on, RTS on, XMT on
163 ; set baud rate, word size, stop bits and ready monitoring
165 lda #36 ; xio 36, baud rate
167 jsr popa ; get parameter
169 ;ICAX2 = 0, monitor nothing
173 ; set translation and parity
175 lda #38 ; xio 38, translation and parity
178 ora #32 ; no translation
187 inverr: jmp __inviocb
189 .endproc ;_rs232_params
191 cioerr: jmp __do_oserror
194 ;----------------------------------------------------------------------------
196 ; unsigned char __fastcall__ rs232_done (void);
197 ; /* Close the port, deinstall the interrupt hander. You MUST call this function
198 ; * before terminating the program, otherwise the machine may crash later. If
199 ; * in doubt, install an exit handler using atexit(). The function will do
200 ; * nothing, if it was already called.
228 ;----------------------------------------------------------------------------
230 ; unsigned char __fastcall__ rs232_get (char* B);
231 ; /* Get a character from the serial port. If no characters are available, the
232 ; * function will return RS_ERR_NO_DATA, so this is not a fatal error.
240 bne work ; work only if initialized
241 lda #RS_ERR_NOT_INITIALIZED
245 stx ptr1+1 ; store pointer to received char
251 lda cm_run ; concurrent mode already running?
253 jsr ena_cm ; turn on concurrent mode
255 go: ; check whether there is any input available
257 lda #STATIS ; status request, returns bytes pending
260 bmi cioerr ; @@@ error handling
262 lda DVSTAT+1 ; get byte count pending
264 beq nix_da ; no input waiting...
266 ; input is available: get it!
268 lda #GETCHR ; get raw bytes
269 sta ICCOM,x ; in command code
276 bmi cioerr ; @@@ error handling
279 sta (ptr1,x) ; return received byte
286 nix_da: lda #RS_ERR_NO_DATA
293 ;----------------------------------------------------------------------------
295 ; unsigned char __fastcall__ rs232_put (char B);
296 ; /* Send a character via the serial port. There is a transmit buffer, but
297 ; * transmitting is not done via interrupt. The function returns
298 ; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
306 bne work ; work only if initialized
307 lda #RS_ERR_NOT_INITIALIZED
315 lda cm_run ; concurrent mode already running?
317 jsr ena_cm ; turn on concurrent mode
319 ; @@@TODO: check output buffer overflow
320 go: lda #PUTCHR ; put raw bytes
321 sta ICCOM,x ; in command code
327 pla ; get the char back
336 ;----------------------------------------------------------------------------
338 ; unsigned char __fastcall__ rs232_pause (void);
339 ; /* Assert flow control and disable interrupts. */
345 ;----------------------------------------------------------------------------
347 ; unsigned char __fastcall__ rs232_unpause (void);
348 ; /* Re-enable interrupts and release flow control */
354 ;----------------------------------------------------------------------------
356 ; unsigned char __fastcall__ rs232_status (unsigned char* status,
357 ; unsigned char* errors);
358 ; /* Return the serial port status. */
368 ; enable concurrent rs232 mode
369 ; gets iocb index in X
370 ; all registers destroyed
374 lda #40 ; XIO 40, start concurrent IO
376 sta cm_run ; indicate concurrent mode is running
388 lda #$0D ; value from 850 man, p62. must be 0D?,
389 sta ICAX1,x ; or any non-zero?