1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +00:00

New extended memory API

git-svn-id: svn://svn.cc65.org/cc65/trunk@1678 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-11-29 14:46:56 +00:00
parent 5de8af4f8f
commit 4c4e5def21
11 changed files with 456 additions and 0 deletions

44
asminc/em-error.inc Normal file
View File

@ -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

88
asminc/em-kernel.inc Normal file
View File

@ -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

33
libsrc/em/Makefile Normal file
View File

@ -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)

107
libsrc/em/em-kernel.s Normal file
View File

@ -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

11
libsrc/em/em_copyfrom.s Normal file
View File

@ -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

11
libsrc/em/em_copyto.s Normal file
View File

@ -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

89
libsrc/em/em_load.c Normal file
View File

@ -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;
}

13
libsrc/em/em_map.s Normal file
View File

@ -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

17
libsrc/em/em_mapclean.s Normal file
View File

@ -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

11
libsrc/em/em_pagecount.s Normal file
View File

@ -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

32
libsrc/em/em_unload.s Normal file
View File

@ -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