Skip to content

Commit 0c11361

Browse files
authored
Merge pull request #1162 from ajcasado/master
Added support for the USIFAC serial port, experiments with network access using SLIP, various bug fixes, and optimizations.
2 parents ef4f5f6 + 619337a commit 0c11361

22 files changed

+357
-132
lines changed

Applications/netd/Makefile.z80

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include $(FUZIX_ROOT)/Target/rules.z80
22

33
CFLAGS += -DNETD_LITTLE_ENDIAN
44

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

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

1515

1616
netd: $(OBJS)
17+
$(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)
1718
$(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)
1819
$(LINKER) $(LINKER_OPT) -o telnet $(CRT0) telnet.o gethostbyname.o $(LINKER_TAIL)
1920
$(LINKER) $(LINKER_OPT) -o echoping $(CRT0) echoping.o $(LINKER_TAIL)

Applications/util/less.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define BUFLEN 512 /* Size of the line buffer */
3434

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

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

117117
/* Ensure we reset the terminal when we exit */
118-
atexit(reset_terminal);
118+
atexit((void*)reset_terminal);
119119
}
120120

121121
/* Get the terminal's size */

Kernel/dev/ch375.c

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <printf.h>
2525
#include "ch375.h"
2626

27+
#if defined CONFIG_CH375
28+
2729
static uint8_t ch_ver;
2830
static uint8_t ch_rd = 0x28;
2931
static uint8_t ch_wd = 0x2B;
@@ -161,3 +163,5 @@ uint_fast8_t ch375_probe(void)
161163
ch_dev = td_register(0, ch375_xfer, td_ioctl_none, 1);
162164
return 1;
163165
}
166+
167+
#endif

Kernel/dev/cpc/albireo.c

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/* We have to provide slightly custom methods here because of the banked
99
kernel */
10+
11+
#ifdef CONFIG_ALBIREO
1012
COMMON_MEMORY
1113

1214
void ch375_rblock(uint8_t *p) __naked
@@ -375,3 +377,5 @@ void ch375_wblock(uint8_t *p) __naked
375377
ret
376378
__endasm;
377379
}
380+
381+
#endif

Kernel/dev/cpc/cpcide.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/* We have to provide slightly custom methods here because of the banked
99
kernel */
10+
#ifdef CONFIG_TD_IDE
1011
COMMON_MEMORY
1112

1213
void devide_read_data(uint8_t *p) __naked
@@ -242,3 +243,4 @@ dowrite1: ; transfer 512 bytes
242243
ret
243244
__endasm;
244245
}
246+
#endif

Kernel/dev/cpc/video.s

+43-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
;
22
; amstrad cpc vt primitives
33
;
4+
.globl _int_disabled
5+
46
; exported symbols
57
.globl cpc_plot_char
68
.globl cpc_scroll_down
@@ -15,6 +17,7 @@
1517
.globl _curattr
1618
.globl _vtattr
1719

20+
1821
videopos: ;get x->d, y->e => set de address for top byte of char
1922
ld l,e
2023
ld h,#0
@@ -59,7 +62,9 @@ cpc_plot_char:
5962
add hl,hl
6063
ld bc, #_fontdata_8x8
6164
add hl, bc ; hl points to first byte of char data
62-
65+
di
66+
ld bc, #0x7faa ;RMR ->UROM disable LROM enable
67+
out (c),c
6368
ld b,#7
6469
ld a,(hl)
6570
ld (de),a
@@ -71,10 +76,17 @@ plot_char_line:
7176
ld a,(hl)
7277
ld (de),a
7378
djnz plot_char_line
74-
75-
79+
ld bc, #0x7fae ;RMR ->UROM disable LROM disable
80+
out (c),c
81+
ex af,af'
82+
ld a,(_int_disabled)
83+
or a
84+
jr nz,cont_no_int_char
85+
ei
7686
; We do underline for now - not clear italic or bold are useful
7787
; with the font we have.
88+
cont_no_int_char:
89+
ex af,af'
7890
ld bc,(_vtattr) ; c is vt attributes
7991
bit 1,c ; underline ?
8092
jr nz, last_ul
@@ -210,11 +222,30 @@ cpc_cursor_on:
210222
pop de
211223
push de
212224
push hl
213-
ld (cursorpos), de
214225
call videopos
215226
ld a,d
216227
add a,#0x38
217-
ld d,a
228+
ld d,a
229+
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
230+
ld l,e
231+
ld h,a
232+
;push bc
233+
di
234+
ld bc,#0x7fc0
235+
out (c),c
236+
ld a,(hl)
237+
ld c,#0xc3
238+
out (c),c
239+
ld (saved_cursor_byte),a
240+
ld a,(_int_disabled)
241+
or a
242+
jr nz,cont_no_int_cursor
243+
ei
244+
cont_no_int_cursor:
245+
;pop bc
246+
;pop hl
247+
;push hl ;here ends the wotkaround, on a 6128 ld a,(de) does the same
248+
ld (cursorpos), de
218249
ld a,#0xFF
219250
ld (de),a
220251

@@ -227,12 +258,10 @@ _cursor_off:
227258
.endif
228259
cpc_cursor_disable:
229260
cpc_cursor_off:
230-
ld de, (cursorpos)
231-
call videopos
232-
ld a,d
233-
add a,#0x38
234-
ld d,a
235-
xor a
261+
VIDEO_MAP
262+
263+
ld de, (cursorpos)
264+
ld a,(saved_cursor_byte)
236265
ld (de),a
237266

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

285314
cursorpos:
286-
.dw 0
315+
.dw 0
316+
saved_cursor_byte:
317+
.db 0
287318
scroll_offset:
288319
.dw 0
289320
CRTC_offset:

Kernel/platform/platform-cpc6128/Makefile

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DZSRCS = ../../dev/cpc/cpcide.c ../../dev/cpc/cpckeyboard.c ../../dev/cpc/devinp
66
DDZSRCS =
77
ASRCS = crt0.s cpc6128.s cpcvideo.s fdc765.s
88
ASRCS += tricks.s commonmem.s
9-
NSRCS =
9+
NSRCS = ../../dev/net/net_native.c
1010

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

6262
#Assemble loader
6363
sdasz80 -l -o loader.s
6464
sdldz80 -i loader.rel
6565
hex2bin loader.ihx
6666
# Make a system disk raw image to work from with loader at cpm boot sector followed by fuzix.bin
67-
dd if=/dev/zero of=padding.bin bs=512 count=360
68-
dd if=loader.bin of=padding.bin seek=0 bs=512 conv=notrunc
69-
dd if=../../fuzix.bin of=padding.bin bs=512 seek=1 conv=notrunc
70-
cat padding.bin >disk.raw
67+
dd if=/dev/zero of=disk.raw bs=512 count=360
68+
dd if=loader.bin of=disk.raw seek=0 bs=512 conv=notrunc
69+
dd if=../../fuzix.bin of=disk.raw bs=512 seek=1 conv=notrunc
7170
# And generate a 40 track cpc system disk dsk file from it
72-
../../tools/raw2dskcpc disk.raw fuzix.dsk 40 1 64
73-
cp fuzix.dsk $(IMAGES)/fuzix.dsk
71+
../../tools/raw2dskcpc disk.raw $(IMAGES)/fuzix.dsk 40 1 64
72+
7473

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

7776
diskimage:
7877
# 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
7978
dd if=/dev/zero of=$(IMAGES)/disk.img bs=512 count=131072
8079
echo 'label: dos' | sfdisk $(IMAGES)/disk.img
81-
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
80+
sfdisk $(IMAGES)/disk.img < diskimage.sfdisk
8281

8382
# Make a FAT16 filesystem for partition P4 so we can play with dos utils (dosread, etc.), root directory entries are limited by available RAM
8483
dd if=/dev/zero of=$(IMAGES)/FAT16.img bs=512 count=38912

Kernel/platform/platform-cpc6128/README

+41-10
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,50 @@ In the CPC6128:
2323
| Kernel | 0 / 1 / 2 | Common 7 (map C1)
2424
| Video | 0 / 3 / 2 | Common 7 (map C3)
2525

26-
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:
26+
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
27+
has not been implemented.
28+
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
29+
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,
30+
replacing the entire memory space without any common area to rely on. See this references:
2731
https://www.cpcwiki.eu/index.php/Gate_Array#Register_MMR_.28RAM_memory_mapping.29
2832
https://www.cpcwiki.eu/index.php/Standard_Memory_Expansions
2933

30-
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.
31-
32-
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.
34+
This latter 64k block mapping approach, which involves switching between 64k blocks, is being considered for another port inspired by the memory usage
35+
in the Cromemco port.
36+
Two standard memory expansion sizes are supported: 512k and 1024k. To build the port with either of these options, simply define the macros
37+
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
38+
a swap partition on any of the supported disk types.
3339

3440
## STATUS
3541

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

38-
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.
44+
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
45+
root disk image is generated to boot from fd1. Format is 9 sectors per track with sector ID from 1 to 9.
3946

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

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

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

46-
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.
53+
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
54+
|cpm.
55+
56+
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,
57+
modify the following line in /etc/inittab:
58+
02:3:off:getty /dev/tty2
59+
to:
60+
02:3:respawn:getty /dev/tty2
61+
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
62+
115200 baud with no flow control.
4763

64+
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
65+
network driver by running netd-slip&. However, mainly as this platform relies solely on swap for multitasking, this functionality is practically
66+
useless except for basic operations like ping as while the netd-slip driver is active, the console becomes extremely slow. Also, among other issues,
67+
name resolution does not work and ipconfig provides incorrect information. Tested connecting the usifac to a ESP-01 module with this firmware:
68+
https://github.com/martin-ger/esp_slip_router
69+
This driver uses /etc/netrc and /etc/resolv.conf files for network interface configuration
4870

4971
## TODO
5072

@@ -56,19 +78,28 @@ Fix memory size reporting 64 v 48K (inherited from zx+3).
5678
do_beep() doesn't seem to work. FIXED
5779
Write a proper loader. DONE.
5880
Configurable screen, at least add 80x25, maybe also change the video mode and routines to manage 6x8 fonts.
59-
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...
81+
Support more hardware: M4 Board (storage, network and RTC), Ulifac/Usifac storage, networking with wifi module plugged in the usifac, sdcard in the
82+
Albireo.
6083

6184
Fix lots of bugs.
6285

63-
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.
86+
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
87+
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
88+
this can give aprox. 60K for kernel and user and hold a lot of processes in memory with a big RAM expansion.
6489

6590
Look for speed optimization opportunities.
6691

6792
## BUILD & RUN
6893

69-
make diskimage with cpc6128 target in base Makefile
70-
.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
94+
Install cpctools: https://github.com/cpcsdk/cpctools
95+
install hex2bin: https://github.com/algodesigner/hex2bin
96+
97+
make TARGET=cpc6128 diskimage
7198

99+
.sna snapshot, .dsk Floppy image, and mass storage filesystem images are generated in Images folder. Tu boot from floppy use |cpm command from basic
100+
prompt
101+
102+
To run on emulator use ACE-DL emulator and use disk.img as image for the x-mass IDE interface emulation.
72103
To run on emulator use ACE-DL emulator and use disk.img as image for the x-mass IDE interface emulation.
73104

74105

Kernel/platform/platform-cpc6128/config.h

+26-10
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@
3232

3333
#undef CONFIG_KMOD
3434

35-
#undef CONFIG_NET
36-
#undef CONFIG_NET_NATIVE
35+
/*Usifac compatible serial device*/
36+
#define CONFIG_USIFAC_SERIAL
37+
#undef CONFIG_USIFAC_SLIP
38+
#if defined CONFIG_USIFAC_SLIP
39+
#define CONFIG_NET
40+
#define CONFIG_NET_NATIVE
41+
#else
42+
#undef CONFIG_NET
43+
#undef CONFIG_NET_NATIVE
44+
#endif
3745
#undef CONFIG_NET_WIZNET
3846
#undef CONFIG_NET_W5100
3947

@@ -51,8 +59,7 @@
5159
#define TICKSPERSEC 300 /* Ticks per second */
5260
#define PROGBASE 0x0000 /* also data base */
5361
#define PROGLOAD 0x0100 /* also data base */
54-
#define PROGTOP 0xC000 /* Top of program, below C000 for simplicity
55-
to get going */
62+
#define PROGTOP 0xC000 /* Top of program, below C000 for simplicity to get going */
5663

5764
#define BOOT_TTY (513) /* Set this to default device for stdio, stderr */
5865
/* In this case, the default is the first TTY device */
@@ -61,7 +68,8 @@
6168
#define CMDLINE NULL /* Location of root dev name */
6269

6370
/* Device parameters */
64-
#define NUM_DEV_TTY 1
71+
#define NUM_DEV_TTY 2
72+
#define TTY_INIT_BAUD B115200 /*USIFAC*/
6573

6674
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
6775
#define NBUFS 5 /* Number of block buffers */
@@ -77,8 +85,8 @@
7785
#define TOTAL_SWAP_BLOCKS (1088-128) * 2
7886
#endif
7987
#ifdef EXTENDED_RAM_512
80-
#define MAX_SWAPS 8 /*See platform devrd.c*/
81-
#define PTABSIZE 8
88+
#define MAX_SWAPS 9 /*See platform devrd.c*/
89+
#define PTABSIZE 9
8290
#define TOTAL_SWAP_BLOCKS (576-128) * 2
8391
#endif
8492
#if defined EXTENDED_RAM_512 || defined EXTENDED_RAM_1024
@@ -96,9 +104,17 @@
96104
#define CONFIG_TD_NUM 2
97105
/* IDE/CF support */
98106
#define CONFIG_TD_IDE
99-
#define CONFIG_TINYIDE_SDCCPIO
100-
#define CONFIG_TINYIDE_8BIT
101-
#define IDE_IS_8BIT(x) 1
107+
#ifdef CONFIG_TD_IDE
108+
#define CONFIG_TINYIDE_SDCCPIO
109+
#define CONFIG_TINYIDE_8BIT
110+
#define IDE_IS_8BIT(x) 1
111+
#endif
112+
/* Albireo ch376 USB storage support*/
113+
#define CONFIG_ALBIREO
114+
#ifdef CONFIG_ALBIREO
115+
#define CONFIG_CH375
116+
#endif
117+
102118

103119
#define BOOTDEVICENAMES "hd#,fd"
104120

0 commit comments

Comments
 (0)