Skip to content

Commit

Permalink
Merge pull request #1138 from ajcasado/master
Browse files Browse the repository at this point in the history
Add platform for Amstrad CPC with standard memory expansion used as ram disk for swap
  • Loading branch information
EtchedPixels authored Jan 22, 2025
2 parents e7a4d54 + 79a61f0 commit 7863335
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 82 deletions.
10 changes: 5 additions & 5 deletions Kernel/platform/platform-cpc6128/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CSRCS = devtty.c devices.c main.c
CSRCS = devtty.c devices.c main.c devrd.c rd_cpcsme.c
CDSRCS = discard.c
DSRCS = ../../dev/tinyide.c ../../dev/tinydisk.c ../../dev/devfdc765.c ../../dev/tinysd.c ../../dev/ch375.c
DDSRCS = ../../dev/tinyide_discard.c ../../dev/tinydisk_discard.c ../../dev/tinysd_discard.c
DSRCS = ../../dev/tinyide.c ../../dev/tinydisk.c ../../dev/devfdc765.c ../../dev/ch375.c
DDSRCS = ../../dev/tinyide_discard.c ../../dev/tinydisk_discard.c
DZSRCS = ../../dev/cpc/cpcide.c ../../dev/cpc/cpckeyboard.c ../../dev/cpc/devinput.c ../../dev/cpc/albireo.c
DDZSRCS =
ASRCS = crt0.s cpc6128.s cpcvideo.s fdc765.s
ASRCS += tricks.s commonmem.s
ASRCS = crt0.s cpc6128.s cpcvideo.s fdc765.s
ASRCS += tricks.s commonmem.s
NSRCS =

COBJS = $(CSRCS:.c=.rel)
Expand Down
10 changes: 8 additions & 2 deletions Kernel/platform/platform-cpc6128/README
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Amstrad CPC6128


## Mmeory Model
## Memory Model

The CPC6128 supported memory maps:

Expand All @@ -23,7 +23,13 @@ In the CPC6128:
| Kernel | 0 / 1 / 2 | Common 7 (map C1)
| Video | 0 / 3 / 2 | Common 7 (map C3)

The use of standard memory expansions as swap space has been implemented. With this memory map, the ability to have multiple tasks simultaneously in RAM has not been implemented. This is because the expanded memory can only be mapped in 16k blocks starting at address 0x4000, which removes the common area from the map (this mapping is used to implement the RAM disk for swap while executing code in the non-common code area). Alternatively, it can be mapped in 64k blocks, replacing the entire memory space without any common area to rely on. See this references:
https://www.cpcwiki.eu/index.php/Gate_Array#Register_MMR_.28RAM_memory_mapping.29
https://www.cpcwiki.eu/index.php/Standard_Memory_Expansions

This latter 64k block mapping approach, which involves switching between 64k blocks, is being considered for another port inspired by the memory usage in the Cromemco port.

Two standard memory expansion sizes are supported: 512k and 1024k. To build the port with either of these options, simply define the macros EXTENDED_RAM_512 or EXTENDED_RAM_1024 depending on the desired size in the file config.h. If neither is defined, the build will default to supporting a swap partition on any of the supported disk types.

## STATUS

Expand Down Expand Up @@ -54,7 +60,7 @@ Support more hardware: M4 Board (storage, network and RTC), Ulifac/Usifac, netwo

Fix lots of bugs.

Switch to a thunked memory model based on C2 Map to use the standard and extended RAM expansions up to 4MiB, the Cromemco port could be a model to this solution. As ther is no real common as we are switching the whole 64k space, the common data area has to be updated in all the used banks, but this can give aprox. 60K for kernel and user and hold a lot of processes in memory with a big RAM expansion. If this proves to be too hard, a RAM disk for swapping can be a way to use the RAM expansions.
Switch to a thunked memory model based on C2 Map to use the standard and extended RAM expansions up to 4MiB, the Cromemco port could be a model to this solution. As there is no real common as we are switching the whole 64k space, the common data area has to be updated in all the used banks, but this can give aprox. 60K for kernel and user and hold a lot of processes in memory with a big RAM expansion.

Look for speed optimization opportunities.

Expand Down
35 changes: 24 additions & 11 deletions Kernel/platform/platform-cpc6128/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#define UDATA_BLKS 1
#define UDATA_SIZE 0x200
#define CONFIG_DYNAMIC_BUFPOOL
#define CONFIG_DYNAMIC_SWAP
#define MAXTICKS 20 /* Has to be high because we are swap only */

#define MAXTICKS 60 /* Has to be high because we are swap only */

#undef CONFIG_KMOD

Expand Down Expand Up @@ -70,8 +70,24 @@
#define SWAPBASE 0x0000
#define SWAPTOP 0xC000UL
#define SWAP_SIZE 0x61 /* 48K + udata */
#define MAX_SWAPS 16
#define SWAPDEV (swap_dev) /* Device for swapping (dynamic). */
#define EXTENDED_RAM_1024
#ifdef EXTENDED_RAM_1024
#define MAX_SWAPS 19 /*See platform devrd.c*/
#define PTABSIZE 19
#define TOTAL_SWAP_BLOCKS (1088-128) * 2
#endif
#ifdef EXTENDED_RAM_512
#define MAX_SWAPS 8 /*See platform devrd.c*/
#define PTABSIZE 8
#define TOTAL_SWAP_BLOCKS (576-128) * 2
#endif
#if defined EXTENDED_RAM_512 || defined EXTENDED_RAM_1024
#define SWAPDEV 0x800 /* Device for swapping - RAM disk on standard memory expansion. */
#else
#define CONFIG_DYNAMIC_SWAP
#define SWAPDEV (swap_dev) /* Device for swapping (dynamic). */
#define MAX_SWAPS 16
#endif

/* We swap by hitting the user map */
#define swap_map(x) ((uint8_t *)(x))
Expand All @@ -83,15 +99,12 @@
#define CONFIG_TINYIDE_SDCCPIO
#define CONFIG_TINYIDE_8BIT
#define IDE_IS_8BIT(x) 1
/* SD support */
/* #define TD_SD_NUM 2 */
/* #define CONFIG_TD_SD */
/* Emulator for this platform needs bug workarounds */
/* #undef CONFIG_TD_SD_EMUBUG */
/*#undef SD_SPI_CALLTYPE __z88dk_fastcall */

#define BOOTDEVICENAMES "hd#,fd"

#define CONFIG_SMALL

/* #define DEBUG */




25 changes: 14 additions & 11 deletions Kernel/platform/platform-cpc6128/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include <vt.h>
#include <tinydisk.h>
#include <tinyide.h>
#include <tinysd.h>
/*#include <tinysd.h>*/
#include <devtty.h>
#include <devfdc765.h>
#include <netdev.h>
/*#include <netdev.h>*/
#include <devrd.h>

struct devsw dev_tab[] = /* The device driver switch table */
{
Expand All @@ -24,23 +25,25 @@ struct devsw dev_tab[] = /* The device driver switch table */
/* 4: /dev/mem etc System devices (one offs) */
{ no_open, no_close, sys_read, sys_write, sys_ioctl },
/* 5: Pack to 7 with nxio if adding private devices and start at 8 */
#ifdef CONFIG_NET
{ nxio_open, no_close, no_rdwr, no_rdwr, no_ioctl },
{ nxio_open, no_close, no_rdwr, no_rdwr, no_ioctl },
{ nxio_open, no_close, no_rdwr, no_rdwr, no_ioctl },
{ nxio_open, no_close, no_rdwr, no_rdwr, no_ioctl },
#endif
#if defined EXTENDED_RAM_512 || defined EXTENDED_RAM_1024
/* 5: unused */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 6: unused */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 7: unused */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 8: Standard memory expansions RAM swap */
{ rd_open, no_close, rd_read, rd_write, no_ioctl },
#endif
};




bool validdev(uint16_t dev)
{
/* This is a bit uglier than needed but the right hand side is
a constant this way */
if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1)
return false;
return false;
else
return true;
}
Expand Down
51 changes: 0 additions & 51 deletions Kernel/platform/platform-cpc6128/devinput.c

This file was deleted.

2 changes: 0 additions & 2 deletions Kernel/platform/platform-cpc6128/devinput.h

This file was deleted.

83 changes: 83 additions & 0 deletions Kernel/platform/platform-cpc6128/devrd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* CPC standard RAM bank memory expansions ramdisc driver, based on platform zxdiv48.
*/

#include <kernel.h>
#include <kdata.h>
#include <printf.h>

#if defined EXTENDED_RAM_512 || defined EXTENDED_RAM_1024
#include <devrd.h>


static int rd_transfer(uint8_t is_read, uint8_t rawflag)
{
nblock = udata.u_nblock;
block = udata.u_block;
rd_dptr = udata.u_dptr;
rd_wr = is_read;
uint16_t swap_bank_long;
uint8_t ct = 0;

#ifdef DEBUG
kprintf("u_dptr %p Block %u u_nblock %u rd_wr %u\n",udata.u_dptr, udata.u_block, udata.u_nblock, rd_wr);
#endif

/* It's a disk but only for swapping (and rd_io isn't general purpose) */
if (((block + nblock) > (TOTAL_SWAP_BLOCKS - 1)) || (rawflag == 1)) {
udata.u_error = EIO;
kprintf("dev_rd_EIO");
return -1;
}

/* udata could change under us so keep variables privately */
while (ct < nblock) {
swap_bank_long = (block >> 5);
swap_bank_long = swap_bank_long + 196 + (((swap_bank_long + 8) / 4) * 4); /*Convert bank number to Register MMR value
*See https://www.cpcwiki.eu/index.php/Gate_Array#Register_MMR_.28RAM_memory_mapping.29*/
if (swap_bank_long > 255){
rd_swap_bank = swap_bank_long - 64;
rd_swap_mem_port_h = 0x7e;
}
else{
rd_swap_bank = swap_bank_long;
rd_swap_mem_port_h = 0x7f;
}
rd_proc_bank = ((uint16_t)rd_dptr / 0x4000) + 0xc4;
rd_swap_bank_addr = ((block & 31) << BLKSHIFT) + 0x4000;
rd_proc_bank_addr = ((uint16_t)rd_dptr & 0x3fff) + 0x4000;

#ifdef DEBUG
if (nblock == 1)
kprintf("swap_bank %p swap_addr %p proc_bank %p proc_addr %p count %u\n", rd_swap_bank, rd_swap_bank_addr, rd_proc_bank, rd_proc_bank_addr, ct);
#endif
rd_io();
block++;
rd_dptr += BLKSIZE;
ct++;
}
return ct << BLKSHIFT; /*Total bytes transferred*/
}

int rd_open(uint8_t minor, uint16_t flag)
{
flag;
if(minor != 0) {
udata.u_error = ENODEV;
return -1;
}
return 0;
}

int rd_read(uint8_t minor, uint8_t rawflag, uint8_t flag)
{
flag;minor;
return rd_transfer(true, rawflag);
}

int rd_write(uint8_t minor, uint8_t rawflag, uint8_t flag)
{
flag;minor;
return rd_transfer(false, rawflag);
}
#endif
20 changes: 20 additions & 0 deletions Kernel/platform/platform-cpc6128/devrd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
*
* CPC standard RAM bank memory expansions ramdisc driver
*/

int rd_open(uint8_t minor, uint16_t flags);
int rd_read(uint8_t minor, uint8_t rawflag, uint8_t flag);
int rd_write(uint8_t minor, uint8_t rawflag, uint8_t flag);

extern uint8_t rd_wr;
extern uint8_t rd_swap_bank;
extern uint8_t rd_swap_mem_port_h;
extern uint8_t rd_proc_bank;
extern uint8_t *rd_dptr;
extern uint16_t rd_swap_bank_addr;
extern uint16_t rd_proc_bank_addr;
extern uint16_t nblock;
extern blkno_t block;

void rd_io(void);
5 changes: 5 additions & 0 deletions Kernel/platform/platform-cpc6128/discard.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ uint8_t plt_param(char *p)
/* Nothing to do for the map of init */
void map_init(void)
{
#if defined EXTENDED_RAM_512 || defined EXTENDED_RAM_1024
uint_fast8_t i;
for (i = 0; i < MAX_SWAPS; i++)
swapmap_init(i);
#endif
}

void plt_copyright(void)
Expand Down
2 changes: 2 additions & 0 deletions Kernel/platform/platform-cpc6128/fuzix.lnk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
platform/platform-cpc6128/crt0.rel
platform/platform-cpc6128/commonmem.rel
platform/platform-cpc6128/cpc6128.rel
platform/platform-cpc6128/rd_cpcsme.rel
platform/platform-cpc6128/cpcvideo.rel
platform/platform-cpc6128/main.rel
platform/platform-cpc6128/discard.rel
Expand Down Expand Up @@ -54,4 +55,5 @@ platform/platform-cpc6128/devfdc765.rel
platform/platform-cpc6128/fdc765.rel
platform/platform-cpc6128/ch375.rel
platform/platform-cpc6128/albireo.rel
platform/platform-cpc6128/devrd.rel
-e
Loading

0 comments on commit 7863335

Please sign in to comment.