2 ; Ullrich von Bassewitz, 2012-07-22
4 ; unsigned char __fastcall__ em_load_driver (const char* name)
5 ; /* Load an extended memory driver and return an error code */
8 .include "em-kernel.inc"
9 .include "em-error.inc"
10 .include "modload.inc"
22 ;----------------------------------------------------------------------------
33 ;----------------------------------------------------------------------------
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 #EM_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.
89 ; Res = em_install (ctrl.module);
91 lda ctrl + MOD_CTRL::MODULE
92 ldx ctrl + MOD_CTRL::MODULE+1
95 ; If em_install was successful, we're done
100 ; The driver didn't install correctly. Remove it from memory and return the
103 pha ; Save the error code
106 jsr _mod_free ; Free the driver memory
107 jsr em_clear_ptr ; Clear em_drv
108 pla ; Restore the error code
109 ldx #0 ; We must return an int
112 ; Open or mod_load failed. Return an error code.
114 @L3: lda #<EM_ERR_CANNOT_LOAD