;* *
;* *
;* *
-;*(C) 2003 Ullrich von Bassewitz *
-;* Römerstrasse 52 *
-;* D-70794 Filderstadt *
-;*EMail: uz@cc65.org *
+;* (C) 2003-2012, Ullrich von Bassewitz *
+;* Roemerstrasse 52 *
+;* D-70794 Filderstadt *
+;* EMail: uz@cc65.org *
;* *
;* *
;*This software is provided 'as-is', without any expressed or implied *
;------------------------------------------------------------------------------
; Error codes
-SER_ERR_OK = $00 ; Not an error - relax
-SER_ERR_NO_DRIVER = $01 ; No driver available
-SER_ERR_CANNOT_LOAD = $02 ; Error loading driver
-SER_ERR_INV_DRIVER = $03 ; Invalid driver
-SER_ERR_NO_DEVICE = $04 ; Device (hardware) not found
-SER_ERR_BAUD_UNAVAIL = $05 ; Baud rate not available
-SER_ERR_NO_DATA = $06 ; Nothing to read
-SER_ERR_OVERFLOW = $07 ; No room in send buffer
-SER_ERR_INIT_FAILED = $08 ; Initialization failed
-SER_ERR_INV_IOCTL = $09 ; IOCTL not supported
+.enum
+ SER_ERR_OK ; Not an error - relax
+ SER_ERR_NO_DRIVER ; No driver available
+ SER_ERR_CANNOT_LOAD ; Error loading driver
+ SER_ERR_INV_DRIVER ; Invalid driver
+ SER_ERR_NO_DEVICE ; Device (hardware) not found
+ SER_ERR_BAUD_UNAVAIL ; Baud rate not available
+ SER_ERR_NO_DATA ; Nothing to read
+ SER_ERR_OVERFLOW ; No room in send buffer
+ SER_ERR_INIT_FAILED ; Initialization failed
+ SER_ERR_INV_IOCTL ; IOCTL not supported
+ SER_ERR_INSTALLED ; A driver is already installed
+ SER_ERR_COUNT ; Special: Number of error codes
+.endenum
/* */
/* */
/* */
-/* (C) 2003-2011, Ullrich von Bassewitz */
+/* (C) 2003-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
#define SER_ERR_OVERFLOW 0x07 /* No room in send buffer */
#define SER_ERR_INIT_FAILED 0x08 /* Initialization failed */
#define SER_ERR_INV_IOCTL 0x09 /* IOCTL not supported */
+#define SER_ERR_INSTALLED 0x0A /* A driver is already installed */
/* Struct containing parameters for the serial port */
struct ser_params {
.proc _ser_load_driver
-; Save name on the C stack. We will need it later as parameter passed to open()
+; Check if we do already have a driver loaded. This is an error. Do not
+; touch A/X because they contain the file name.
- jsr pushax
-
-; Check if we do already have a driver loaded. If so, remove it.
-
- lda _ser_drv
- ora _ser_drv+1
+ ldy _ser_drv
+ bne @L0
+ ldy _ser_drv+1
beq @L1
- jsr _ser_uninstall
+@L0: lda #SER_ERR_INSTALLED
+ bne @L4
-; Open the file. The name parameter is already on stack and will get removed
-; by open().
+; Push the name onto the C stack and open the file. The parameter will get
+; removed by open().
; ctrl.callerdata = open (name, O_RDONLY);
-@L1: lda #<O_RDONLY
+@L1: jsr pushax
+ lda #<O_RDONLY
jsr pusha0
ldy #4 ; Argument size
jsr _open
; Open or mod_load failed. Return an error code.
@L3: lda #<SER_ERR_CANNOT_LOAD
- ldx #>SER_ERR_CANNOT_LOAD
+@L4: ldx #0
rts
.endproc