Skip to content

Commit

Permalink
Merge pull request #1162 from ajcasado/master
Browse files Browse the repository at this point in the history
Added support for the USIFAC serial port, experiments with network access using SLIP, various bug fixes, and optimizations.
  • Loading branch information
EtchedPixels authored Feb 23, 2025
2 parents ef4f5f6 + 619337a commit 0c11361
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 132 deletions.
3 changes: 2 additions & 1 deletion Applications/netd/Makefile.z80
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include $(FUZIX_ROOT)/Target/rules.z80

CFLAGS += -DNETD_LITTLE_ENDIAN

SRCS = netd.c uip.c uiplib.c timer.c clock-arch.c uip_arp.c telnet.c lwwire.c
SRCS = netd.c uip.c uiplib.c timer.c clock-arch.c uip_arp.c telnet.c lwwire.c slip.c
SRCS += echoping.c dig.c gethostbyname.c httpd.c ping.c ntpdate.c
SRCS += htget.c tinyirc.c linein.c ifconfig.c

Expand All @@ -14,6 +14,7 @@ all: $(APPS)


netd: $(OBJS)
$(LINKER) $(LINKER_OPT) -o netd-slip $(CRT0) netd.o uip.o uiplib.o timer.o clock-arch.o uip_arp.o slip.o $(LINKER_TAIL)
$(LINKER) $(LINKER_OPT) -o netd-lwwire $(CRT0) netd.o uip.o uiplib.o timer.o clock-arch.o uip_arp.o lwwire.o $(LINKER_TAIL)
$(LINKER) $(LINKER_OPT) -o telnet $(CRT0) telnet.o gethostbyname.o $(LINKER_TAIL)
$(LINKER) $(LINKER_OPT) -o echoping $(CRT0) echoping.o $(LINKER_TAIL)
Expand Down
4 changes: 2 additions & 2 deletions Applications/util/less.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define BUFLEN 512 /* Size of the line buffer */

int ttyfd; /* The fd for the terminal */
int rows = 25, cols = 80; /* The default size of the terminal */
unsigned short rows = 25, cols = 80; /* The default size of the terminal */
int is_stdin = 0; /* Is input from standard input? */

/* We keep track of line offsets from the input file */
Expand Down Expand Up @@ -115,7 +115,7 @@ void set_cbreak() {
error("Cannot tcsetattr\n");

/* Ensure we reset the terminal when we exit */
atexit(reset_terminal);
atexit((void*)reset_terminal);
}

/* Get the terminal's size */
Expand Down
4 changes: 4 additions & 0 deletions Kernel/dev/ch375.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <printf.h>
#include "ch375.h"

#if defined CONFIG_CH375

static uint8_t ch_ver;
static uint8_t ch_rd = 0x28;
static uint8_t ch_wd = 0x2B;
Expand Down Expand Up @@ -161,3 +163,5 @@ uint_fast8_t ch375_probe(void)
ch_dev = td_register(0, ch375_xfer, td_ioctl_none, 1);
return 1;
}

#endif
4 changes: 4 additions & 0 deletions Kernel/dev/cpc/albireo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/* We have to provide slightly custom methods here because of the banked
kernel */

#ifdef CONFIG_ALBIREO
COMMON_MEMORY

void ch375_rblock(uint8_t *p) __naked
Expand Down Expand Up @@ -375,3 +377,5 @@ void ch375_wblock(uint8_t *p) __naked
ret
__endasm;
}

#endif
2 changes: 2 additions & 0 deletions Kernel/dev/cpc/cpcide.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/* We have to provide slightly custom methods here because of the banked
kernel */
#ifdef CONFIG_TD_IDE
COMMON_MEMORY

void devide_read_data(uint8_t *p) __naked
Expand Down Expand Up @@ -242,3 +243,4 @@ dowrite1: ; transfer 512 bytes
ret
__endasm;
}
#endif
55 changes: 43 additions & 12 deletions Kernel/dev/cpc/video.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
;
; amstrad cpc vt primitives
;
.globl _int_disabled

; exported symbols
.globl cpc_plot_char
.globl cpc_scroll_down
Expand All @@ -15,6 +17,7 @@
.globl _curattr
.globl _vtattr


videopos: ;get x->d, y->e => set de address for top byte of char
ld l,e
ld h,#0
Expand Down Expand Up @@ -59,7 +62,9 @@ cpc_plot_char:
add hl,hl
ld bc, #_fontdata_8x8
add hl, bc ; hl points to first byte of char data

di
ld bc, #0x7faa ;RMR ->UROM disable LROM enable
out (c),c
ld b,#7
ld a,(hl)
ld (de),a
Expand All @@ -71,10 +76,17 @@ plot_char_line:
ld a,(hl)
ld (de),a
djnz plot_char_line


ld bc, #0x7fae ;RMR ->UROM disable LROM disable
out (c),c
ex af,af'
ld a,(_int_disabled)
or a
jr nz,cont_no_int_char
ei
; We do underline for now - not clear italic or bold are useful
; with the font we have.
cont_no_int_char:
ex af,af'
ld bc,(_vtattr) ; c is vt attributes
bit 1,c ; underline ?
jr nz, last_ul
Expand Down Expand Up @@ -210,11 +222,30 @@ cpc_cursor_on:
pop de
push de
push hl
ld (cursorpos), de
call videopos
ld a,d
add a,#0x38
ld d,a
ld d,a
add a,#0x80 ;here start a workaround to avoid the behaviour of C3 map on cpc 664 & 464 reading rom instead of ram data at 0x4000
ld l,e
ld h,a
;push bc
di
ld bc,#0x7fc0
out (c),c
ld a,(hl)
ld c,#0xc3
out (c),c
ld (saved_cursor_byte),a
ld a,(_int_disabled)
or a
jr nz,cont_no_int_cursor
ei
cont_no_int_cursor:
;pop bc
;pop hl
;push hl ;here ends the wotkaround, on a 6128 ld a,(de) does the same
ld (cursorpos), de
ld a,#0xFF
ld (de),a

Expand All @@ -227,12 +258,10 @@ _cursor_off:
.endif
cpc_cursor_disable:
cpc_cursor_off:
ld de, (cursorpos)
call videopos
ld a,d
add a,#0x38
ld d,a
xor a
VIDEO_MAP

ld de, (cursorpos)
ld a,(saved_cursor_byte)
ld (de),a

VIDEO_UNMAP
Expand Down Expand Up @@ -283,7 +312,9 @@ write_ay_reg: ; E = register, D = data from https://cpctech.cpc-live.com/source/
.area _DATA

cursorpos:
.dw 0
.dw 0
saved_cursor_byte:
.db 0
scroll_offset:
.dw 0
CRTC_offset:
Expand Down
17 changes: 8 additions & 9 deletions Kernel/platform/platform-cpc6128/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DZSRCS = ../../dev/cpc/cpcide.c ../../dev/cpc/cpckeyboard.c ../../dev/cpc/devinp
DDZSRCS =
ASRCS = crt0.s cpc6128.s cpcvideo.s fdc765.s
ASRCS += tricks.s commonmem.s
NSRCS =
NSRCS = ../../dev/net/net_native.c

COBJS = $(CSRCS:.c=.rel)
CDOBJS = $(CDSRCS:.c=.rel)
Expand Down Expand Up @@ -57,28 +57,27 @@ image:
# Create a snapshot file with fuzix code at right places and set execution at 0x100
dd if=../../fuzix.bin of=bank012.bin bs=48896 count=1
dd if=../../fuzix.bin of=bank7.bin bs=1 skip=48896
createSnapshot $(IMAGES)/6128.sna -l bank012.bin 0x100 -l bank7.bin 0x1c000 -s Z80_PC 0x100
createSnapshot $(IMAGES)/6128.sna -l bank012.bin 0x100 -l bank7.bin 0x1c000 -s Z80_PC 0x100 -s GA_RAMCFG 0xc1

#Assemble loader
sdasz80 -l -o loader.s
sdldz80 -i loader.rel
hex2bin loader.ihx
# Make a system disk raw image to work from with loader at cpm boot sector followed by fuzix.bin
dd if=/dev/zero of=padding.bin bs=512 count=360
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
dd if=/dev/zero of=disk.raw bs=512 count=360
dd if=loader.bin of=disk.raw seek=0 bs=512 conv=notrunc
dd if=../../fuzix.bin of=disk.raw bs=512 seek=1 conv=notrunc
# And generate a 40 track cpc system disk dsk file from it
../../tools/raw2dskcpc disk.raw fuzix.dsk 40 1 64
cp fuzix.dsk $(IMAGES)/fuzix.dsk
../../tools/raw2dskcpc disk.raw $(IMAGES)/fuzix.dsk 40 1 64


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

diskimage:
# Make a blank disk image and partition it P1->32M,FUZIX P2->8M,FUZIX P3->4M,FUZIX.SWAP P4->(64-(32+8+4+1(reserved)))M,FAT16
dd if=/dev/zero of=$(IMAGES)/disk.img bs=512 count=131072
echo 'label: dos' | sfdisk $(IMAGES)/disk.img
echo -e 'size=32M, id=7e\n size=8M, id=7e\n size=4M, id=7f\n size=+, id=4\n' | sfdisk $(IMAGES)/disk.img
sfdisk $(IMAGES)/disk.img < diskimage.sfdisk

# Make a FAT16 filesystem for partition P4 so we can play with dos utils (dosread, etc.), root directory entries are limited by available RAM
dd if=/dev/zero of=$(IMAGES)/FAT16.img bs=512 count=38912
Expand Down
51 changes: 41 additions & 10 deletions Kernel/platform/platform-cpc6128/README
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,50 @@ 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:
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.
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

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

Added support for the USIFAC serial port. If CONFIG_USIFAC_SERIAL is defined in config.h, the tty2 device is added. To use the console on this device,
modify the following line in /etc/inittab:
02:3:off:getty /dev/tty2
to:
02:3:respawn:getty /dev/tty2
This has been tested with Putty conecting the usifac to a linux box using a USB-Serial converter and works wery well. By default the usifac is set at
115200 baud with no flow control.

If CONFIG_USIFAC_SLIP is defined, the tty2 device can no longer be used as the system console. You must change tty4 to tty2 in slip.c and start the
network driver by running netd-slip&. However, mainly as this platform relies solely on swap for multitasking, this functionality is practically
useless except for basic operations like ping as while the netd-slip driver is active, the console becomes extremely slow. Also, among other issues,
name resolution does not work and ipconfig provides incorrect information. Tested connecting the usifac to a ESP-01 module with this firmware:
https://github.com/martin-ger/esp_slip_router
This driver uses /etc/netrc and /etc/resolv.conf files for network interface configuration

## TODO

Expand All @@ -56,19 +78,28 @@ 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...
Support more hardware: M4 Board (storage, network and RTC), Ulifac/Usifac storage, networking with wifi module plugged in the usifac, sdcard in the
Albireo.

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

## 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
Install cpctools: https://github.com/cpcsdk/cpctools
install hex2bin: https://github.com/algodesigner/hex2bin

make TARGET=cpc6128 diskimage

.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.
To run on emulator use ACE-DL emulator and use disk.img as image for the x-mass IDE interface emulation.


36 changes: 26 additions & 10 deletions Kernel/platform/platform-cpc6128/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@

#undef CONFIG_KMOD

#undef CONFIG_NET
#undef CONFIG_NET_NATIVE
/*Usifac compatible serial device*/
#define CONFIG_USIFAC_SERIAL
#undef CONFIG_USIFAC_SLIP
#if defined CONFIG_USIFAC_SLIP
#define CONFIG_NET
#define CONFIG_NET_NATIVE
#else
#undef CONFIG_NET
#undef CONFIG_NET_NATIVE
#endif
#undef CONFIG_NET_WIZNET
#undef CONFIG_NET_W5100

Expand All @@ -51,8 +59,7 @@
#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 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 */
Expand All @@ -61,7 +68,8 @@
#define CMDLINE NULL /* Location of root dev name */

/* Device parameters */
#define NUM_DEV_TTY 1
#define NUM_DEV_TTY 2
#define TTY_INIT_BAUD B115200 /*USIFAC*/

#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#define NBUFS 5 /* Number of block buffers */
Expand All @@ -77,8 +85,8 @@
#define TOTAL_SWAP_BLOCKS (1088-128) * 2
#endif
#ifdef EXTENDED_RAM_512
#define MAX_SWAPS 8 /*See platform devrd.c*/
#define PTABSIZE 8
#define MAX_SWAPS 9 /*See platform devrd.c*/
#define PTABSIZE 9
#define TOTAL_SWAP_BLOCKS (576-128) * 2
#endif
#if defined EXTENDED_RAM_512 || defined EXTENDED_RAM_1024
Expand All @@ -96,9 +104,17 @@
#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
#ifdef CONFIG_TD_IDE
#define CONFIG_TINYIDE_SDCCPIO
#define CONFIG_TINYIDE_8BIT
#define IDE_IS_8BIT(x) 1
#endif
/* Albireo ch376 USB storage support*/
#define CONFIG_ALBIREO
#ifdef CONFIG_ALBIREO
#define CONFIG_CH375
#endif


#define BOOTDEVICENAMES "hd#,fd"

Expand Down
Loading

0 comments on commit 0c11361

Please sign in to comment.