Skip to content

Commit

Permalink
Add platform for Amstrad CPC with standard memory expansion used as r…
Browse files Browse the repository at this point in the history
…am disk for swap
  • Loading branch information
ajcasado committed Jan 15, 2025
1 parent 957ca3e commit cd56063
Show file tree
Hide file tree
Showing 29 changed files with 2,693 additions and 0 deletions.
86 changes: 86 additions & 0 deletions Kernel/platform/platform-cpc6128-SME/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
CSRCS = devtty.c devices.c main.c devrd.c
CDSRCS = 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 rd_cpcsme.s
ASRCS += tricks.s commonmem.s
NSRCS =

COBJS = $(CSRCS:.c=.rel)
CDOBJS = $(CDSRCS:.c=.rel)
AOBJS = $(ASRCS:.s=.rel)
DOBJS = $(patsubst ../../dev/%.c,%.rel, $(DSRCS))
DDOBJS = $(patsubst ../../dev/%.c,%.rel, $(DDSRCS))
DZOBJS = $(patsubst ../../dev/cpc/%.c,%.rel, $(DZSRCS))
DDZOBJS = $(patsubst ../../dev/cpc/%.c,%.rel, $(DDZSRCS))
NOBJS = $(patsubst ../../dev/net/%.c,%.rel, $(NSRCS))
OBJS = $(COBJS) $(CDOBJS) $(AOBJS) $(DOBJS) $(DDOBJS) $(DZOBJS) $(DDZOBJS) $(NOBJS)

CROSS_CCOPTS += -I../../dev/ -I../../dev/cpc/ -I../../dev/net

CROSS_CC_SEG3 = --codeseg CODE3

all: $(OBJS)

$(COBJS): %.rel: %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG3) -c $<

$(CDOBJS): %.rel: %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

$(DOBJS): %.rel: ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG3) -c $<

$(DDOBJS): %.rel: ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

$(DZOBJS): %.rel: ../../dev/cpc/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG3) -c $<

$(DDZOBJS): %.rel: ../../dev/cpc/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

$(NOBJS): %.rel: ../../dev/net/%.c
$(CROSS_CC) $(CROSS_CCOPTS) -c $<

$(AOBJS): %.rel: %.s
$(CROSS_AS) $(ASOPTS) $<

clean:
rm -f $(OBJS) *.lst *.asm *.sym *.rst *.rel core *~
rm -f loader.tmp loader.ihx loader.lst loader.bin padding.bin disk.raw
rm -rf fuzix.dsk

image:
# Copy snapshot file template, transfer fuzix code to 0x100 and set execution at 0x100
cp $(FUZIX_ROOT)/Standalone/filesystem-src/6128.sna $(IMAGES)/
createSnapshot $(IMAGES)/6128.sna --loadFileData ../../fuzix.bin 256
printf '\x01' | dd of=$(IMAGES)/6128.sna bs=1 seek=24 conv=notrunc
sdasz80 -l -o loader.s
sdldz80 -i loader.rel
hex2bin loader.ihx

dd if=/dev/zero of=padding.bin bs=512 count=360
# Make a disk image to work from
dd if=loader.bin of=padding.bin seek=0 bs=512 conv=notrunc
dd if=../../fuzix.bin of=padding.bin bs=512 seek=1 conv=notrunc
cat padding.bin >disk.raw
# And generate a 40 track cpc system disk from it
../../tools/raw2dskcpc disk.raw fuzix.dsk 40 1 64
cp fuzix.dsk $(IMAGES)/fuzix.dsk

IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)

diskimage:
# Make a blank disk image with partition
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.64M of=$(IMAGES)/disk.img bs=64M conv=sync
# Add the file system
dd if=$(IMAGES)/filesys.img of=$(IMAGES)/disk.img bs=512 seek=2048 conv=notrunc
dd if=$(IMAGES)/filesys8.img of=$(IMAGES)/disk.img bs=512 seek=67584 conv=notrunc
# Make an emulator image of it
cat $(FUZIX_ROOT)/Standalone/filesystem-src/hdfheader $(IMAGES)/disk.img > $(IMAGES)/emu-ide.hdf
(cd $(FUZIX_ROOT)/Standalone/filesystem-src; ./build-mini-filesystem $(ENDIANFLAG) $(FUZIX_ROOT)/Images/$(TARGET)/root.raw 64 1440)
../../tools/raw2dskcpc $(FUZIX_ROOT)/Images/$(TARGET)/root.raw $(FUZIX_ROOT)/Images/$(TARGET)/root.dsk 80 2 0

22 changes: 22 additions & 0 deletions Kernel/platform/platform-cpc6128-SME/Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Amstrad CPC6128


## Mmeory Model

This port is based on the zx+3 port, taking advantage of Alan Cox's suggestion to take advantage of the fact that the memory maps C1, C2 and C3 correspond to the maps used in the zx+3 port.

In the zx+3:
| User | 0 / 1 / 2 | Common 3
| Kernel | 4 / 5 / 6 | Common 3
| Video | 4 / 7 / 6 | Common 3

In the CPC6128:
| User | 4 / 5 / 6 | Common 7 (map C2)
| Kernel | 0 / 1 / 2 | Common 7 (map C1)
| Video | 0 / 3 / 2 | Common 7 (map c3)

## TODO

Lots of bugs.
Trying to mount the flopy hangs the machine, and may do nasty things to the floppy and the drive, don't try on a real machine!!
Fix memory size reporting 64 v 48K.
68 changes: 68 additions & 0 deletions Kernel/platform/platform-cpc6128-SME/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Amstrad CPC6128


## Mmeory Model

The CPC6128 supported memory maps:

-MAP- C0 C1 C2 C3 C4 C5 C6 C7
0000-3FFF RAM_0 RAM_0 RAM_4 RAM_0 RAM_0 RAM_0 RAM_0 RAM_0
4000-7FFF RAM_1 RAM_1 RAM_5 RAM_3 RAM_4 RAM_5 RAM_6 RAM_7
8000-BFFF RAM_2 RAM_2 RAM_6 RAM_2 RAM_2 RAM_2 RAM_2 RAM_2
C000-FFFF RAM_3 RAM_7 RAM_7 RAM_7 RAM_3 RAM_3 RAM_3 RAM_3

This port is based on the zx+3 port, following Alan Cox's suggestion to take advantage of the fact that memory maps C1, C2 and C3 correspond to the maps used in the zx+3 port.

In the zx+3:
| User | 0 / 1 / 2 | Common 3
| Kernel | 4 / 5 / 6 | Common 3
| Video | 4 / 7 / 6 | Common 3

In the CPC6128:
| User | 4 / 5 / 6 | Common 7 (map C2)
| Kernel | 0 / 1 / 2 | Common 7 (map C1)
| Video | 0 / 3 / 2 | Common 7 (map C3)



## STATUS

Video mode 2 is used. The video driver configures the CRTC in 64x32 characters to do easy hardware scroll and use the whole video memory bank.

The floppy driver seems to work. /dev/fd0 is drive A and /dev/fd1 is drive B. fd0 is hard coded to one side and fd1 to double side. A minimal system root disk image is generated to boot from fd1. Format is 9 sectors per track with sector ID from 1 to 9.

The IDE driver that is supposed to work with the symbiface and xmass fails to initialize. FIXED, tested with ACE-DL emulator x-mass suport.

The USB mass storage of the Albiero works using the ch375 driver used in other platforms. It should be easy to get it working with the Usifac/Ulifac.

There isn't a proper loader, for now a snapshot is generated. FIXED, dsk floppy boot image generated.

To test it burn disk.img on a spare usb pendrive and put it on the albireo. Load an run the snapshot or burn the dsk in a floppy and start FUZIX with |cpm.


## TODO

Fix fdc driver. DONE
Fix IDE driver. DONE
Sometimes the top byte of the characters isn't drawn. FIXED
Vertical scroll shows the bottom line of the screen in the top of the screen. FIXED
Fix memory size reporting 64 v 48K (inherited from zx+3).
do_beep() doesn't seem to work. FIXED
Write a proper loader. DONE.
Configurable screen, at least add 80x25, maybe also change the video mode and routines to manage 6x8 fonts.
Support more hardware: M4 Board (storage, network and RTC), Ulifac/Usifac, networking with wifi module plugged in the usifac, sdcard in the Albireo, try slip with the serial port of the usifac...

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.

Look for speed optimization opportunities.

## BUILD & RUN

make diskimage with cpc6128 target in base Makefile
.sna snapshot, .dsk Floppy image, and mass storage filesystem images are generated in Images folder. Tu boot from floppy use |cpm command from basic prompt

To run on emulator use ACE-DL emulator and use disk.img as image for the x-mass IDE interface emulation.


9 changes: 9 additions & 0 deletions Kernel/platform/platform-cpc6128-SME/commonmem.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;
; Multiple app sizes and the fact the kernel and apps share the same banks
; means we need to put this somewhere low
;
.module commonmem
.area _COMMONMEM

.include "../../cpu-z80/std-commonmem.s"

104 changes: 104 additions & 0 deletions Kernel/platform/platform-cpc6128-SME/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#define CONFIG_LARGE_IO_DIRECT(x) 1 /* We support direct to user I/O */

#define CONFIG_FDC765
/* Enable to make ^Z dump the inode table for debug */
#undef CONFIG_IDUMP
/* Enable to make ^A drop back into the monitor */
#undef CONFIG_MONITOR
/* Profil syscall support (not yet complete) */
#define CONFIG_PROFIL
/* Multiple processes in memory at once */
#define CONFIG_MULTI
/* CP/M emulation */
#undef CONFIG_CPM_EMU

/* Input layer support */
#define CONFIG_INPUT
#define CONFIG_INPUT_GRABMAX 3
/* Video terminal, not a serial tty */
#define CONFIG_VT
/* Keyboard contains non-ascii symbols */
#define CONFIG_UNIKEY

/* Swap based one process in RAM */
#define CONFIG_SWAP_ONLY
#define CONFIG_PARENT_FIRST
#define CONFIG_SPLIT_UDATA
#define UDATA_BLKS 1
#define UDATA_SIZE 0x200
#define CONFIG_DYNAMIC_BUFPOOL
#undef CONFIG_DYNAMIC_SWAP
#define MAXTICKS 60 /* Has to be high because we are swap only */

#undef CONFIG_KMOD

#undef CONFIG_NET
#undef CONFIG_NET_NATIVE
#undef CONFIG_NET_WIZNET
#undef CONFIG_NET_W5100

/* Custom banking */

/* Banks as reported to user space */
#define CONFIG_BANKS 1

/* Vt definitions */
#define VT_WIDTH 64
#define VT_HEIGHT 32
#define VT_RIGHT 63
#define VT_BOTTOM 31

#define TICKSPERSEC 300 /* Ticks per second */
#define PROGBASE 0x0000 /* also data base */
#define PROGLOAD 0x0100 /* also data base */
#define PROGTOP 0xC000 /* Top of program, below C000 for simplicity
to get going */

#define BOOT_TTY (513) /* Set this to default device for stdio, stderr */
/* In this case, the default is the first TTY device */

/* We need a tidier way to do this from the loader */
#define CMDLINE NULL /* Location of root dev name */

/* Device parameters */
#define NUM_DEV_TTY 1

#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#define NBUFS 5 /* Number of block buffers */
#define NMOUNTS 4 /* Number of mounts at a time */

#define SWAPBASE 0x0000
#define SWAPTOP 0xC000UL
#define SWAP_SIZE 0x61 /* 48K + udata */
#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 9 /*See platform devrd.c*/
#define PTABSIZE 9
#define TOTAL_SWAP_BLOCKS (576-128) * 2
#endif
#define SWAPDEV 0x800 /* Device for swapping - RAM disk on standard memory expansion. */

/* We swap by hitting the user map */
#define swap_map(x) ((uint8_t *)(x))

#define CONFIG_TD
#define CONFIG_TD_NUM 2
/* IDE/CF support */
#define CONFIG_TD_IDE
#define CONFIG_TINYIDE_SDCCPIO
#define CONFIG_TINYIDE_8BIT
#define IDE_IS_8BIT(x) 1

#define BOOTDEVICENAMES "hd#,fd"

#define CONFIG_SMALL





Loading

0 comments on commit cd56063

Please sign in to comment.