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]
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
65 tay ; move iocb # into Y
67 sta tmp3 ; name length + 1
72 bcs doopen ; C set: open needed / device not already open
75 jsr _rs232_done ;** shut down if started @@@TODO check this out!!
90 lda #$0D ; mode in+out+concurrent
94 sta ICBLL,x ; zap buf len
106 cioerr1:jsr fddecusage ; decrement usage counter of fd as open failed
110 lda #RS_ERR_INIT_FAILED
113 .endproc ; _rs232_init
116 ;----------------------------------------------------------------------------
118 ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
120 ; Set communication parameters.
122 ; params contains baud rate, stop bits and word size
123 ; parity contains parity
125 ; 850 manual documents restrictions on the baud rate (not > 300), when not
126 ; using 8 bit word size. So only 8 bit is currently tested.
134 bne work ; work only if initialized
135 lda #RS_ERR_NOT_INITIALIZED
139 jsr fdtoiocb ; get iocb index into X
140 bmi inverr ; shouldn't happen
143 ; set handshake lines
145 lda #34 ; xio 34, set cts, dtr etc
147 lda #192+48+3 ; DTR on, RTS on, XMT on
158 ; set baud rate, word size, stop bits and ready monitoring
160 lda #36 ; xio 36, baud rate
162 jsr popa ; get parameter
164 ;ICAX2 = 0, monitor nothing
168 ; set translation and parity
170 lda #38 ; xio 38, translation and parity
173 ora #32 ; no translation
182 inverr: jmp __inviocb
184 .endproc ;_rs232_params
186 cioerr: jmp __do_oserror
189 ;----------------------------------------------------------------------------
191 ; unsigned char __fastcall__ rs232_done (void);
192 ; /* Close the port, deinstall the interrupt hander. You MUST call this function
193 ; * before terminating the program, otherwise the machine may crash later. If
194 ; * in doubt, install an exit handler using atexit(). The function will do
195 ; * nothing, if it was already called.
223 ;----------------------------------------------------------------------------
225 ; unsigned char __fastcall__ rs232_get (char* B);
226 ; /* Get a character from the serial port. If no characters are available, the
227 ; * function will return RS_ERR_NO_DATA, so this is not a fatal error.
235 bne work ; work only if initialized
236 lda #RS_ERR_NOT_INITIALIZED
240 stx ptr1+1 ; store pointer to received char
246 lda cm_run ; concurrent mode already running?
248 jsr ena_cm ; turn on concurrent mode
250 go: ; check whether there is any input available
252 lda #STATIS ; status request, returns bytes pending
255 bmi cioerr ; @@@ error handling
257 lda DVSTAT+1 ; get byte count pending
259 beq nix_da ; no input waiting...
261 ; input is available: get it!
263 lda #GETCHR ; get raw bytes
264 sta ICCOM,x ; in command code
271 bmi cioerr ; @@@ error handling
274 sta (ptr1,x) ; return received byte
281 nix_da: lda #RS_ERR_NO_DATA
288 ;----------------------------------------------------------------------------
290 ; unsigned char __fastcall__ rs232_put (char B);
291 ; /* Send a character via the serial port. There is a transmit buffer, but
292 ; * transmitting is not done via interrupt. The function returns
293 ; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
301 bne work ; work only if initialized
302 lda #RS_ERR_NOT_INITIALIZED
310 lda cm_run ; concurrent mode already running?
312 jsr ena_cm ; turn on concurrent mode
314 ; @@@TODO: check output buffer overflow
315 go: lda #PUTCHR ; put raw bytes
316 sta ICCOM,x ; in command code
322 pla ; get the char back
331 ;----------------------------------------------------------------------------
333 ; unsigned char __fastcall__ rs232_pause (void);
334 ; /* Assert flow control and disable interrupts. */
340 ;----------------------------------------------------------------------------
342 ; unsigned char __fastcall__ rs232_unpause (void);
343 ; /* Re-enable interrupts and release flow control */
349 ;----------------------------------------------------------------------------
351 ; unsigned char __fastcall__ rs232_status (unsigned char* status,
352 ; unsigned char* errors);
353 ; /* Return the serial port status. */
363 ; enable concurrent rs232 mode
364 ; gets iocb index in X
365 ; all registers destroyed
369 lda #40 ; XIO 40, start concurrent IO
371 sta cm_run ; indicate concurrent mode is running
383 lda #$0D ; value from 850 man, p62. must be 0D?,
384 sta ICAX1,x ; or any non-zero?