From dcff1d07745c9f20d9687f5239a4ca21efa7c0e1 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 22 Jul 2012 19:54:04 +0000 Subject: [PATCH] An already loaded driver is an error in ser_load_driver, because the library cannot know if it was dynamically loaded or statically linked. git-svn-id: svn://svn.cc65.org/cc65/trunk@5794 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- asminc/ser-error.inc | 32 ++++++++++++++++++-------------- include/serial.h | 3 ++- libsrc/serial/ser_load.s | 24 ++++++++++++------------ 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/asminc/ser-error.inc b/asminc/ser-error.inc index e6057a641..f1592876b 100644 --- a/asminc/ser-error.inc +++ b/asminc/ser-error.inc @@ -6,10 +6,10 @@ ;* * ;* * ;* * -;*(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 * @@ -36,15 +36,19 @@ ;------------------------------------------------------------------------------ ; 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 diff --git a/include/serial.h b/include/serial.h index 04b5144a2..b5601170e 100644 --- a/include/serial.h +++ b/include/serial.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2003-2011, Ullrich von Bassewitz */ +/* (C) 2003-2012, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -110,6 +110,7 @@ #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 { diff --git a/libsrc/serial/ser_load.s b/libsrc/serial/ser_load.s index d711a74b1..069327d7f 100644 --- a/libsrc/serial/ser_load.s +++ b/libsrc/serial/ser_load.s @@ -37,22 +37,22 @@ ctrl: .addr _read .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 #SER_ERR_CANNOT_LOAD +@L4: ldx #0 rts .endproc