zx128: custom banking added
authorAlexander Tsidaev <a.tsidaev@gmail.com>
Sun, 23 Nov 2014 21:51:05 +0000 (02:51 +0500)
committerAlexander Tsidaev <a.tsidaev@gmail.com>
Sun, 23 Nov 2014 23:02:47 +0000 (04:02 +0500)
Kernel/platform-zx128/Makefile
Kernel/platform-zx128/bankzx128.c [new file with mode: 0644]
Kernel/platform-zx128/config.h
Kernel/platform-zx128/uzi.lnk

index c6c9291..f003850 100644 (file)
@@ -1,13 +1,15 @@
-
 CSRCS = devtty.c
 CSRCS += devices.c main.c
 
+CSRCS2 = bankzx128.c
+
 ASRCS = crt0.s zx128.s zxvideo.s
 ASRCS += tricks.s commonmem.s
 
 COBJS = $(CSRCS:.c=.rel)
+COBJS2  = $(CSRCS2:.c=.rel)
 AOBJS = $(ASRCS:.s=.rel)
-OBJS  = $(COBJS) $(AOBJS)
+OBJS  = $(COBJS) $(COBJS2) $(AOBJS)
 
 JUNK = $(CSRCS:.c=.lst) $(CSRCS:.c=.asm) $(CSRCS:.c=.sym) $(ASRCS:.s=.lst) $(ASRCS:.s=.sym) $(CSRCS:.c=.rst) $(ASRCS:.s=.rst)
 
@@ -16,6 +18,9 @@ all:  $(OBJS)
 $(COBJS): %.rel: %.c
        $(CROSS_CC) $(CROSS_CCOPTS) -c $<
 
+$(COBJS2): %.rel: %.c
+       $(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG2) -c $<
+
 $(AOBJS): %.rel: %.s
        $(CROSS_AS) $(ASOPTS) $<
 
diff --git a/Kernel/platform-zx128/bankzx128.c b/Kernel/platform-zx128/bankzx128.c
new file mode 100644 (file)
index 0000000..d31b6b8
--- /dev/null
@@ -0,0 +1,53 @@
+#include <kernel.h>
+#include <timer.h>
+#include <kdata.h>
+#include <printf.h>
+
+/* This is copied version of bankfixed.c
+   The only difference is pagemap_realloc function.
+   Since we have PROGBASE at 0xC000, pagemap_realloc
+   returned ENOMEM even when 0 bytes were requested */
+
+/* Kernel is 0, apps 1,2,3 etc */
+static unsigned char pfree[MAX_MAPS];
+static unsigned char pfptr = 0;
+static unsigned char pfmax;
+
+void pagemap_add(uint8_t page)
+{
+       pfree[pfptr++] = page;
+       pfmax = pfptr;
+}
+
+void pagemap_free(ptptr p)
+{
+       if (p->p_page == 0)
+               panic("free0");
+       pfree[pfptr++] = p->p_page;
+}
+
+int pagemap_alloc(ptptr p)
+{
+#ifdef SWAP_DEV
+       if (pfptr == 0) {
+               swapneeded(p, 1);
+       }
+#endif
+       if (pfptr == 0)
+               return ENOMEM;
+       p->p_page = pfree[--pfptr];
+       return 0;
+}
+
+/* Realloc is trivial - we can't do anything useful */
+int pagemap_realloc(uint16_t size)
+{
+       if (size - PROGBASE >= MAP_SIZE)
+               return ENOMEM;
+       return 0;
+}
+
+uint16_t pagemap_mem_used(void)
+{
+       return (pfmax - pfptr) * (MAP_SIZE >> 10);
+}
index b31f3b5..cfd0cbf 100644 (file)
 #define CONFIG_FONT8X8
 #define CONFIG_FONT8X8SMALL
 
-/* We have 1 bank at C000 with 6 possible pages to map, but I'm not sure
-   if CONFIG_BANK_FIXED is our choice. */
+/* We have 1 bank at C000 with 6 possible pages to map.
+   Our choise should be CONFIG_BANK_FIXED, but we are. 
+   using custom implementation of it */
+
+#undef CONFIG_BANK_FIXED
 
-/* Fixed banking */
-#define CONFIG_BANK_FIXED
 /* 6 16K banks, 1 is for kernel needs */
 #define MAX_MAPS       5
 #define MAP_SIZE       0x4000U
index fb55a5e..7085013 100644 (file)
@@ -8,7 +8,6 @@ platform-zx128/commonmem.rel
 platform-zx128/zx128.rel
 platform-zx128/zxvideo.rel
 platform-zx128/main.rel
-platform-zx128/devfd.rel
 start.rel
 version.rel
 lowlevel-z80.rel
@@ -31,7 +30,7 @@ tty.rel
 vt.rel
 font8x8.rel
 mm.rel
-bankfixed.rel
+platform-zx128/bankzx128.rel
 swap.rel
 devsys.rel
 platform-zx128/devtty.rel