2 ; Christian Groessler, Dec-2001
3 ; converted to driver interface Dec-2013
5 ; RS232 routines using the R: device (currently tested with an 850 only)
8 .include "zeropage.inc"
9 .include "ser-kernel.inc"
10 .include "ser-error.inc"
14 ; ------------------------------------------------------------------------
15 ; Header. Includes jump table
21 .byte $73, $65, $72 ; "ser"
22 .byte SER_API_VERSION ; Serial API version number
43 rdev: .byte "R:", ATEOL, 0
44 bauds: .byte 1 ; SER_BAUD_45_5
47 .byte 5 ; SER_BAUD_110
48 .byte 6 ; SER_BAUD_134_5
49 .byte 7 ; SER_BAUD_150
50 .byte 8 ; SER_BAUD_300
51 .byte 9 ; SER_BAUD_600
52 .byte 10 ; SER_BAUD_1200
53 .byte 11 ; SER_BAUD_1800
54 .byte 12 ; SER_BAUD_2400
55 .byte 0 ; SER_BAUD_3600
56 .byte 13 ; SER_BAUD_4800
57 .byte 0 ; SER_BAUD_7200
58 .byte 14 ; SER_BAUD_9600
59 .byte 0 ; SER_BAUD_19200
60 .byte 0 ; SER_BAUD_38400
61 .byte 0 ; SER_BAUD_57600
62 .byte 0 ; SER_BAUD_115200
63 .byte 0 ; SER_BAUD_230400
64 .byte 0 ; SER_BAUD_31250
65 .byte 0 ; SER_BAUD_62500
66 .byte 3 ; SER_BAUD_56_875
73 num_databits = * - databits
75 .byte 0 ; SER_PAR_NONE
76 .byte 4+1 ; SER_PAR_ODD
77 .byte 2+8 ; SER_PAR_EVEN
78 ;.byte 0 ; SER_PAR_MARK
79 ;.byte 0 ; SER_PAR_SPACE
80 num_parities = * - parities
86 recv_buf: .res RECVBUF_SZ
88 cm_run: .res 1 ; concurrent mode running?
94 ; jump table into main program, initialized from libref
132 lda #<SER_ERR_BAUD_UNAVAIL
133 ldx #>SER_ERR_BAUD_UNAVAIL
138 ;----------------------------------------------------------------------------
139 ; SER_OPEN: A pointer to a ser_params structure is passed in ptr1.
140 ; Must return an SER_ERR_xx code in a/x.
146 ; set line parameters
149 jsr my_fdtoiocb ; get iocb index into X
150 bmi openerr ; shouldn't happen
153 ; set baud rate, word size, stop bits and ready monitoring
156 ldy #SER_PARAMS::BAUDRATE
166 ldy #SER_PARAMS::DATABITS
176 ldy #SER_PARAMS::STOPBITS
184 lda #36 ; xio 36, baud rate
187 ;ICAX2 = 0, monitor nothing
196 ; check if the handshake setting is valid
197 ldy #SER_PARAMS::HANDSHAKE
199 cmp #SER_HS_HW ; this is all we support
202 ; set handshake lines
203 lda #34 ; xio 34, set cts, dtr etc
205 lda #192+48+3 ; DTR on, RTS on, XMT on
210 ; set translation and parity
211 ldy #SER_PARAMS::PARITY
218 ora #32 ; no translation
221 lda #38 ; xio 38, translation and parity
230 inverr: jmp my___inviocb
233 ; @@@ need to close IOCB here
234 jsr my_fddecusage ; decrement usage counter of fd as open failed
238 lda #SER_ERR_INIT_FAILED
241 ;---- open the device
247 tay ; move iocb # into Y
249 sta tmp3 ; name length + 1
254 bcs @doopen ; C set: open needed / device not already open
257 jsr SER_CLOSE ;** shut down if started @@@TODO check this out!!
272 lda #$0D ; mode in+out+concurrent
276 sta ICBLL,x ; zap buf len
281 lda tmp2 ; get fd (from newfd)
288 ;----------------------------------------------------------------------------
289 ; CLOSE: Close the port, disable interrupts and flush the buffer. Called
290 ; without parameters. Must return an error code in a/x.
292 ;----------------------------------------------------------------------------
293 ; SER_UNINSTALL routine. Is called before the driver is removed from memory.
294 ; Must return an SER_ERR_xx code in a/x.
310 @done: lda #<SER_ERR_OK
314 ;----------------------------------------------------------------------------
315 ; SER_GET: Will fetch a character from the receive buffer and store it into the
316 ; variable pointer to by ptr1. If no data is available, SER_ERR_NO_DATA is
323 beq ni_err ; work only if initialized
329 lda cm_run ; concurrent mode already running?
331 jsr ena_cm ; turn on concurrent mode
333 @go: ; check whether there is any input available
335 lda #STATIS ; status request, returns bytes pending
340 lda DVSTAT+1 ; get byte count pending
342 beq @nix_da ; no input waiting...
344 ; input is available: get it!
346 lda #GETCHR ; get raw bytes
347 sta ICCOM,x ; in command code
353 jsr my_CIOV ; go get it
357 sta (ptr1,x) ; return received byte
361 @nix_da:lda #SER_ERR_NO_DATA
366 lda #SER_ERR_OVERFLOW ; there is no large selection of serial error codes... :-/
370 ni_err: lda #SER_ERR_NOT_OPEN
374 ;----------------------------------------------------------------------------
375 ; SER_PUT: Output character in A.
376 ; Must return an error code in a/x.
382 beq ni_err ; work only if initialized
384 pha ; remember char to write
390 lda cm_run ; concurrent mode already running?
392 jsr ena_cm ; turn on concurrent mode
394 ; @@@TODO: check output buffer overflow
395 @go: lda #PUTCHR ; put raw bytes
396 sta ICCOM,x ; in command code
402 pla ; get the char back
403 jsr my_CIOV ; go do it
409 ;----------------------------------------------------------------------------
410 ; SER_STATUS: Return the status in the variable pointed to by ptr1.
411 ; Must return an error code in a/x.
415 ; fall through to SER_IOCTL
417 ;----------------------------------------------------------------------------
418 ; SER_IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
419 ; specific data in ptr1, and the ioctl code in A.
420 ; Must return an error code in a/x.
424 lda #<SER_ERR_INV_IOCTL ; We don't support ioclts for now
425 ldx #>SER_ERR_INV_IOCTL
428 ;----------------------------------------------------------------------------
429 ; SER_IRQ: Not used on the Atari
434 ;----------------------------------------------------------------------------
435 ; SER_INSTALL routine. Is called after the driver is loaded into memory. If
436 ; possible, check if the hardware is present.
437 ; Must return an SER_ERR_xx code in a/x.
440 ; check if R: device is installed
442 search: lda HATABS,y ; get device name
451 ; R: device not found, return error
453 lda #<SER_ERR_NO_DEVICE
457 ; R: device found, initialize jump table into main program
498 sta my_findfreeiocb+1
501 sta my_findfreeiocb+2
505 sta my___do_oserror+1
508 sta my___do_oserror+2
556 ; enable concurrent rs232 mode
557 ; gets iocb index in X
558 ; all registers destroyed
562 lda #40 ; XIO 40, start concurrent IO
564 sta cm_run ; indicate concurrent mode is running
576 lda #$0D ; value from 850 man, p62. must be $0D?,
577 sta ICAX1,x ; or any non-zero?