2 ; Ullrich von Bassewitz, 2006-06-05
4 ; unsigned char __fastcall__ ser_load_driver (const char* name)
5 ; /* Load a serial driver and return an error code */
8 .include "ser-kernel.inc"
9 .include "ser-error.inc"
10 .include "modload.inc"
22 ;----------------------------------------------------------------------------
33 ;----------------------------------------------------------------------------
38 .proc _ser_load_driver
40 ; Check if we do already have a driver loaded. This is an error. Do not
41 ; touch A/X because they contain the file name.
47 @L0: lda #SER_ERR_INSTALLED
50 ; Push the name onto the C stack and open the file. The parameter will get
52 ; ctrl.callerdata = open (name, O_RDONLY);
57 ldy #4 ; Argument size
59 sta ctrl + MOD_CTRL::CALLERDATA
60 stx ctrl + MOD_CTRL::CALLERDATA+1
62 ; if (ctrl.callerdata >= 0) {
67 ; /* Load the module */
68 ; Res = mod_load (&ctrl);
75 ; /* Close the input file */
76 ; close (ctrl.callerdata);
78 lda ctrl + MOD_CTRL::CALLERDATA
79 ldx ctrl + MOD_CTRL::CALLERDATA+1
82 ; /* Check the return code */
83 ; if (Res == MLOAD_OK) {
88 ; Check the driver signature, install the driver. c is already on stack and
89 ; will get removed by ser_install().
90 ; Res = ser_install (ctrl.module);
92 lda ctrl + MOD_CTRL::MODULE
93 ldx ctrl + MOD_CTRL::MODULE+1
96 ; If ser_install was successful, we're done
101 ; The driver didn't install correctly. Remove it from memory and return the
104 pha ; Save the error code
107 jsr _mod_free ; Free the driver memory
108 jsr _ser_clear_ptr ; Clear ser_drv
109 pla ; Restore the error code
110 ldx #0 ; We must return an int
113 ; Open or mod_load failed. Return an error code.
115 @L3: lda #<SER_ERR_CANNOT_LOAD