From 7ab3ede933ca2307b948cd6a218d1f49a4a8aa72 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 23 Jul 2012 06:18:58 +0000 Subject: [PATCH] Forgot to add the new module that contains em_load_driver. git-svn-id: svn://svn.cc65.org/cc65/trunk@5795 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/em/em_load.s | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 libsrc/em/em_load.s diff --git a/libsrc/em/em_load.s b/libsrc/em/em_load.s new file mode 100644 index 000000000..1e4a364e2 --- /dev/null +++ b/libsrc/em/em_load.s @@ -0,0 +1,120 @@ +; +; Ullrich von Bassewitz, 2012-07-22 +; +; unsigned char __fastcall__ em_load_driver (const char* name) +; /* Load an extended memory driver and return an error code */ + + + .include "em-kernel.inc" + .include "em-error.inc" + .include "modload.inc" + .include "fcntl.inc" + + .import pushax + .import pusha0 + .import incsp2 + .import _open + .import _read + .import _close + + + +;---------------------------------------------------------------------------- +; Variables + +.data + +ctrl: .addr _read + .res 2 ; CALLERDATA + .res 2 ; MODULE + .res 2 ; MODULE_SIZE + .res 2 ; MODULE_ID + +;---------------------------------------------------------------------------- +; Code + +.code + +.proc _em_load_driver + +; Check if we do already have a driver loaded. This is an error. Do not +; touch A/X because they contain the file name. + + ldy _em_drv + bne @L0 + ldy _em_drv+1 + beq @L1 +@L0: lda #EM_ERR_INSTALLED + bne @L4 + +; 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: jsr pushax + lda #= 0) { + + txa + bmi @L3 + +; /* Load the module */ +; Res = mod_load (&ctrl); + + lda #ctrl + jsr _mod_load + pha + +; /* Close the input file */ +; close (ctrl.callerdata); + + lda ctrl + MOD_CTRL::CALLERDATA + ldx ctrl + MOD_CTRL::CALLERDATA+1 + jsr _close + +; /* Check the return code */ +; if (Res == MLOAD_OK) { + + pla + bne @L3 + +; Check the driver signature, install the driver. +; Res = em_install (ctrl.module); + + lda ctrl + MOD_CTRL::MODULE + ldx ctrl + MOD_CTRL::MODULE+1 + jsr _em_install + +; If em_install was successful, we're done + + tax + beq @L2 + +; The driver didn't install correctly. Remove it from memory and return the +; error code. + + pha ; Save the error code + lda _em_drv + ldx _em_drv+1 + jsr _mod_free ; Free the driver memory + jsr em_clear_ptr ; Clear em_drv + pla ; Restore the error code + ldx #0 ; We must return an int +@L2: rts ; Done + +; Open or mod_load failed. Return an error code. + +@L3: lda #