]> git.sur5r.net Git - cc65/commitdiff
New extended memory API
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 29 Nov 2002 14:46:56 +0000 (14:46 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 29 Nov 2002 14:46:56 +0000 (14:46 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1678 b7a2c559-68d2-44c3-8de9-860c34a00d81

asminc/em-error.inc [new file with mode: 0644]
asminc/em-kernel.inc [new file with mode: 0644]
libsrc/em/Makefile [new file with mode: 0644]
libsrc/em/em-kernel.s [new file with mode: 0644]
libsrc/em/em_copyfrom.s [new file with mode: 0644]
libsrc/em/em_copyto.s [new file with mode: 0644]
libsrc/em/em_load.c [new file with mode: 0644]
libsrc/em/em_map.s [new file with mode: 0644]
libsrc/em/em_mapclean.s [new file with mode: 0644]
libsrc/em/em_pagecount.s [new file with mode: 0644]
libsrc/em/em_unload.s [new file with mode: 0644]

diff --git a/asminc/em-error.inc b/asminc/em-error.inc
new file mode 100644 (file)
index 0000000..4cf89fe
--- /dev/null
@@ -0,0 +1,44 @@
+;/*****************************************************************************/
+;/*                                                                           */
+;/*                               em-error.inc                                */
+;/*                                                                           */
+;/*                              EM error codes                               */
+;/*                                                                           */
+;/*                                                                           */
+;/*                                                                           */
+;/* (C) 2002      Ullrich von Bassewitz                                       */
+;/*               Wacholderweg 14                                             */
+;/*               D-70597 Stuttgart                                           */
+;/* EMail:        uz@musoftware.de                                            */
+;/*                                                                           */
+;/*                                                                           */
+;/* This software is provided 'as-is', without any expressed or implied       */
+;/* warranty.  In no event will the authors be held liable for any damages    */
+;/* arising from the use of this software.                                    */
+;/*                                                                           */
+;/* Permission is granted to anyone to use this software for any purpose,     */
+;/* including commercial applications, and to alter it and redistribute it    */
+;/* freely, subject to the following restrictions:                            */
+;/*                                                                           */
+;/* 1. The origin of this software must not be misrepresented; you must not   */
+;/*    claim that you wrote the original software. If you use this software   */
+;/*    in a product, an acknowledgment in the product documentation would be  */
+;/*    appreciated but is not required.                                       */
+;/* 2. Altered source versions must be plainly marked as such, and must not   */
+;/*    be misrepresented as being the original software.                      */
+;/* 3. This notice may not be removed or altered from any source              */
+;/*    distribution.                                                          */
+;/*                                                                           */
+;/*****************************************************************************/
+
+
+
+; Error codes
+EM_ERR_OK               = 0       ; No error
+EM_ERR_NO_DRIVER        = 1       ; No driver available
+EM_ERR_CANNOT_LOAD      = 2       ; Error loading driver
+EM_ERR_INV_DRIVER       = 3       ; Invalid driver
+EM_ERR_NO_DEVICE        = 4       ; Device (hardware) not found
+
+
+
diff --git a/asminc/em-kernel.inc b/asminc/em-kernel.inc
new file mode 100644 (file)
index 0000000..35d6b61
--- /dev/null
@@ -0,0 +1,88 @@
+;/*****************************************************************************/
+;/*                                                                           */
+;/*                              em-kernel.inc                                */
+;/*                                                                           */
+;/*                           EM kernel interface                             */
+;/*                                                                           */
+;/*                                                                           */
+;/*                                                                           */
+;/* (C) 2002      Ullrich von Bassewitz                                       */
+;/*               Wacholderweg 14                                             */
+;/*               D-70597 Stuttgart                                           */
+;/* EMail:        uz@musoftware.de                                            */
+;/*                                                                           */
+;/*                                                                           */
+;/* This software is provided 'as-is', without any expressed or implied       */
+;/* warranty.  In no event will the authors be held liable for any damages    */
+;/* arising from the use of this software.                                    */
+;/*                                                                           */
+;/* Permission is granted to anyone to use this software for any purpose,     */
+;/* including commercial applications, and to alter it and redistribute it    */
+;/* freely, subject to the following restrictions:                            */
+;/*                                                                           */
+;/* 1. The origin of this software must not be misrepresented; you must not   */
+;/*    claim that you wrote the original software. If you use this software   */
+;/*    in a product, an acknowledgment in the product documentation would be  */
+;/*    appreciated but is not required.                                       */
+;/* 2. Altered source versions must be plainly marked as such, and must not   */
+;/*    be misrepresented as being the original software.                      */
+;/* 3. This notice may not be removed or altered from any source              */
+;/*    distribution.                                                          */
+;/*                                                                           */
+;/*****************************************************************************/
+
+
+
+;------------------------------------------------------------------------------
+; Driver header stuff
+
+EMD_HDR_ID              = 0                     ; 0x65, 0x6d, 0x64 ("emd")
+EMD_HDR_VERSION         = 3                     ; Interface version
+
+EMD_HDR_JUMPTAB         = 4
+EMD_HDR_INSTALL         = EMD_HDR_JUMPTAB+0     ; INSTALL routine
+EMD_HDR_DEINSTALL       = EMD_HDR_JUMPTAB+2     ; DEINSTALL routine
+EMD_HDR_PAGECOUNT       = EMD_HDR_JUMPTAB+4     ; PAGECOUNT routine
+EMD_HDR_MAP             = EMD_HDR_JUMPTAB+6     ; MAP routine
+EMD_HDR_MAPCLEAN        = EMD_HDR_JUMPTAB+8     ; MAPCLEAN routine
+EMD_HDR_COPYFROM        = EMD_HDR_JUMPTAB+10    ; COPYFROM routine
+EMD_HDR_COPYTO          = EMD_HDR_JUMPTAB+12    ; COPYTO routine
+
+EMD_HDR_JUMPCOUNT       = 7                     ; Number of jump vectors
+
+;------------------------------------------------------------------------------
+; Offsets into the em_copy structure
+
+EM_COPY_PAGE            = 0
+EM_COPY_OFFS            = 2
+EM_COPY_BUF             = 3
+EM_COPY_COUNT           = 5
+
+;------------------------------------------------------------------------------
+; Variables
+
+               .global _em_drv                         ; Pointer to driver
+
+;------------------------------------------------------------------------------
+; Driver entry points
+
+        .global emd_install
+        .global emd_deinstall
+        .global emd_pagecount
+        .global emd_map
+        .global emd_mapclean
+       .global emd_copyfrom
+        .global emd_copyto
+
+;------------------------------------------------------------------------------
+; ASM functions
+
+       .global _em_install
+       .global _em_deinstall
+       .global _em_pagecount
+       .global _em_map
+       .global _em_mapclean
+       .global _em_copyfrom
+       .global _em_copyto
+
+
diff --git a/libsrc/em/Makefile b/libsrc/em/Makefile
new file mode 100644 (file)
index 0000000..85efe2a
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# Makefile for the extended memory library
+#
+
+.SUFFIXES: .o .s .c
+
+%.o:           %.c
+       @$(CC) $(CFLAGS) $<
+       @$(AS) -g -o $@ $(AFLAGS) $(*).s
+
+%.o:   %.s
+       @$(AS) -g -o $@ $(AFLAGS) $<
+
+C_OBJS =        em_load.o
+
+S_OBJS =               em-kernel.o     \
+               em_copyto.o     \
+               em_copyfrom.o   \
+               em_map.o        \
+               em_mapclean.o   \
+               em_pagecount.o  \
+               em_unload.o     \
+
+
+all:   $(C_OBJS) $(S_OBJS)
+
+clean:
+       @rm -f *~
+       @rm -f $(C_OBJS:.o=.s)
+       @rm -f $(C_OBJS)
+       @rm -f $(S_OBJS)
+
+
diff --git a/libsrc/em/em-kernel.s b/libsrc/em/em-kernel.s
new file mode 100644 (file)
index 0000000..d7d29ce
--- /dev/null
@@ -0,0 +1,107 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; Common functions of the extended memory API.
+;
+
+        .export         _em_install, _em_deinstall
+
+        .import         return0
+        .importzp       ptr1
+
+        .include        "em-kernel.inc"
+        .include        "em-error.inc"
+
+
+;----------------------------------------------------------------------------
+; Variables
+
+
+.bss
+_em_drv:        .res    2                      ; Pointer to driver
+
+; Jump table for the driver functions.
+.data
+emd_vectors:
+emd_install:           jmp     $0000
+emd_deinstall:         jmp     $0000
+emd_pagecount:  jmp     $0000
+emd_map:        jmp     $0000
+emd_mapclean:   jmp     $0000
+emd_copyfrom:  jmp     $0000
+emd_copyto:     jmp     $0000
+
+; Driver header signature
+.rodata
+emd_sig:        .byte   $65, $6d, $64, $00      ; "emd", version
+emd_sig_len     = * - emd_sig
+
+
+;----------------------------------------------------------------------------
+; unsigned char __fastcall__ em_install (void* driver);
+; /* Install the driver once it is loaded */
+
+
+_em_install:
+               sta     _em_drv
+       sta     ptr1
+       stx     _em_drv+1
+       stx     ptr1+1
+
+; Check the driver signature
+
+        ldy     #emd_sig_len-1
+@L0:    lda     (ptr1),y
+        cmp     emd_sig,y
+        bne     inv_drv
+        dey
+        bpl     @L0
+
+; Copy the jump vectors
+
+        ldy     #EMD_HDR_JUMPTAB
+        ldx     #0
+@L1:    inx                             ; Skip the JMP opcode
+        jsr     copy                    ; Copy one byte
+        jsr     copy                    ; Copy one byte
+        cpx     #(EMD_HDR_JUMPCOUNT*3)
+        bne     @L1
+
+        jmp     emd_install             ; Call driver install routine
+
+; Driver signature invalid
+
+inv_drv:
+        lda     #EM_ERR_INV_DRIVER
+        ldx     #0
+        rts
+
+; Copy one byte from the jump vectors
+
+copy:   lda     (ptr1),y
+        iny
+set:    sta     emd_vectors,x
+        inx
+        rts
+
+;----------------------------------------------------------------------------
+; void __fastcall__ em_deinstall (void);
+; /* Deinstall the driver before unloading it */
+
+_em_deinstall:
+        jsr     emd_deinstall           ; Call driver routine
+
+; Point all jump vectors to return0
+
+        ldx     #0
+@L1:    inx                             ; Skip JMP opcode
+        lda     #<return0
+        jsr     set
+        lda     #>return0
+        jsr     set
+        cpx     #(EMD_HDR_JUMPCOUNT*3)
+        bne     @L1
+
+        rts
+
+
diff --git a/libsrc/em/em_copyfrom.s b/libsrc/em/em_copyfrom.s
new file mode 100644 (file)
index 0000000..47bf1e6
--- /dev/null
@@ -0,0 +1,11 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; void __fastcall__ em_copyfrom (const struct em_copy* copy_data);
+; /* Copy from extended into linear memory */
+
+
+        .include        "em-kernel.inc"
+
+               _em_copyfrom    = emd_copyfrom          ; Use driver entry
+
diff --git a/libsrc/em/em_copyto.s b/libsrc/em/em_copyto.s
new file mode 100644 (file)
index 0000000..da2664c
--- /dev/null
@@ -0,0 +1,11 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; void __fastcall__ em_copyto (const struct em_copy* copy_data);
+; /* Copy from linear into extended memory */
+
+
+        .include        "em-kernel.inc"
+
+       _em_copyto      = emd_copyto            ; Use driver entry
+
diff --git a/libsrc/em/em_load.c b/libsrc/em/em_load.c
new file mode 100644 (file)
index 0000000..7eb6a69
--- /dev/null
@@ -0,0 +1,89 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                em_load.c                                  */
+/*                                                                           */
+/*                       Loader module for EM drivers                        */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2002      Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <string.h>
+#include <fcntl.h>
+#include <modload.h>
+#include <em.h>
+#include <em/em-kernel.h>
+
+
+
+unsigned char __fastcall__ em_load (unsigned char driver)
+/* Load the extended memory driver and return an error code. */
+{
+    return EM_ERR_NO_DRIVER;
+}
+
+
+
+unsigned char __fastcall__ em_load_driver (const char* name)
+/* Load an extended memory driver and return an error code */
+{
+    static struct mod_ctrl ctrl = {
+        read            /* Read from disk */
+    };
+    unsigned char Res;
+
+    /* Check if we do already have a driver loaded. If so, remove it. */
+    if (em_drv != 0) {
+        em_deinstall ();
+    }
+
+    /* Now open the file */
+    ctrl.callerdata = open (name, O_RDONLY);
+    if (ctrl.callerdata >= 0) {
+
+        /* Load the module */
+        Res = mod_load (&ctrl);
+
+        /* Close the input file */
+        close (ctrl.callerdata);
+
+        /* Check the return code */
+        if (Res == MLOAD_OK) {
+
+            /* Check the driver signature, install the driver */
+            return em_install (ctrl.module);
+
+        }
+    }
+
+    /* Error loading the driver */
+    return EM_ERR_CANNOT_LOAD;
+}
+
+
+
diff --git a/libsrc/em/em_map.s b/libsrc/em/em_map.s
new file mode 100644 (file)
index 0000000..760103d
--- /dev/null
@@ -0,0 +1,13 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; void* __fastcall__ em_map (unsigned page);
+; /* Unmap the current page from memory and map a new one. The function returns
+;  * a pointer to the location of the page in memory.
+;  */
+
+
+        .include        "em-kernel.inc"
+
+               _em_map         = emd_map               ; Use driver entry
+
diff --git a/libsrc/em/em_mapclean.s b/libsrc/em/em_mapclean.s
new file mode 100644 (file)
index 0000000..ead21e1
--- /dev/null
@@ -0,0 +1,17 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; void* __fastcall__ em_mapclean (unsigned page);
+; /* Unmap the current page from memory and map a new one. The function returns
+;  * a pointer to the location of the page in memory. This function differs from
+;  * em_map_page() in that it will discard the contents of the currently mapped
+;  * page, assuming that the page has not been modified or that the modifications
+;  * are no longer needed, if this leads to better performance. NOTE: This does
+;  * NOT mean that the contents of currently mapped page are always discarded!
+;  */
+
+
+        .include        "em-kernel.inc"
+
+               _em_mapclean    = emd_mapclean         ; Use driver entry
+
diff --git a/libsrc/em/em_pagecount.s b/libsrc/em/em_pagecount.s
new file mode 100644 (file)
index 0000000..298b2a7
--- /dev/null
@@ -0,0 +1,11 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; unsigned em_pagecount (void);
+; /* Return the total number of 256 byte pages available in extended memory. */
+
+
+        .include        "em-kernel.inc"
+
+               _em_pagecount   = emd_pagecount                 ; Use driver entry
+
diff --git a/libsrc/em/em_unload.s b/libsrc/em/em_unload.s
new file mode 100644 (file)
index 0000000..d9cb53a
--- /dev/null
@@ -0,0 +1,32 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; unsigned char __fastcall__ em_unload (void);
+; /* Unload the currently loaded driver. */
+
+
+        .include        "em-kernel.inc"
+        .include        "em-error.inc"
+        .include        "modload.inc"
+
+       .import         return0
+
+
+_em_unload:
+       lda     _em_drv
+       ora     _em_drv+1
+               beq     no_driver               ; No driver
+
+       jsr     _em_deinstall           ; Deinstall the driver
+
+        lda     _em_drv
+        ldx     _em_drv+1
+        jsr     _mod_free               ; Free the driver
+
+       jmp     return0
+
+no_driver:
+       tax                             ; X = 0
+       lda     #EM_ERR_NO_DRIVER
+       rts
+