Skip to content

Commit

Permalink
Merge pull request #1146 from ajcasado/master
Browse files Browse the repository at this point in the history
Several improvements on floppy loader, snapshot loader, mass storage disk image creation and dosread utils.
  • Loading branch information
EtchedPixels authored Feb 1, 2025
2 parents cd480a3 + fd78a0a commit 99c4384
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 103 deletions.
32 changes: 17 additions & 15 deletions Applications/util/dosread.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static char drive[] = "/dev/dosX";
static char drive2[] = "/dev/fdX";
#define DRIVE_NR (sizeof (drive) - 2)
static char buffer[MAX_CLUSTER_SIZE], *device = drive, path[128];
static long data_start;
static long data_start,root_address, fat_start;
static long mark; /* offset of directory entry to be written */
static unsigned short total_clusters, cluster_size, root_entries, sub_entries;
static unsigned long fat_size;
Expand Down Expand Up @@ -284,8 +284,8 @@ void determine(void)
fprintf (stderr, "%s: fats != 2\n", cmnd);
++errcount;
}
if (reservsec != 1) {
fprintf (stderr, "%s: reserved != 1\n", cmnd);
if (reservsec < 1) {
fprintf (stderr, "%s: reserved < 1\n", cmnd);
++errcount;
}
if (errcount != 0) {
Expand All @@ -301,10 +301,12 @@ void determine(void)
/* first 2 entries in FAT aren't used */
cluster_size = bytepers * boot.secpclus;
fat_size = (unsigned long) secpfat * (unsigned long) bytepers;
data_start = (long) bytepers + (long) boot.fats * fat_size
data_start = (long) (bytepers * reservsec) + (long) boot.fats * fat_size
+ (long) dirents *32L;
root_entries = dirents;
sub_entries = boot.secpclus * bytepers / 32;
fat_start = (long)(bytepers * reservsec); /* After bootsector + reserved */
root_address = (fat_start + 2L * fat_size);
if (total_clusters > 4096) fat_16 = 1;

/* Further safety checking */
Expand All @@ -319,8 +321,8 @@ void determine(void)
}
#endif

disk_io(READ, FAT_START, &fat_info, 1);
disk_io(READ, FAT_START + fat_size, &fat_check, 1);
disk_io(READ, fat_start, &fat_info, 1);
disk_io(READ, fat_start + fat_size, &fat_check, 1);
if (fat_check != fat_info) {
fprintf (stderr, "%s: Disk type in FAT copy differs from disk type in FAT original.\n", cmnd);
++errcount;
Expand Down Expand Up @@ -411,7 +413,7 @@ int main(int argc, char *argv[])
determine();

#ifdef CACHE_ROOT
disk_io(READ, ROOTADDR, root,
disk_io(READ, root_address, root,
root_entries > MAX_ROOT_ENTRIES ?
DIR_SIZE * MAX_ROOT_ENTRIES :
DIR_SIZE * root_entries);
Expand Down Expand Up @@ -557,15 +559,15 @@ DIRECTORY *directory(DIRECTORY *dir, int entries, int function, char *pathname)
}
#ifndef CACHE_ROOT
else {
disk_io(READ, ROOTADDR, buffer, root_entries * DIR_SIZE);
disk_io(READ, root_address, buffer, root_entries * DIR_SIZE);
dir_ptr = (void *)buffer;
cl_no = dir_ptr->d_cluster;
}
#endif
for (i = 0; i < entries; i++, dir_ptr++) {
type = dir_ptr->d_name[0] & 0x0FF;
if (!mem)
mark = ROOTADDR + (long) i *(long) DIR_SIZE;
mark = root_address + (long) i *(long) DIR_SIZE;
else
mark = clus_add(last) + (long) i *(long) DIR_SIZE;
if (function == ENTRY) {
Expand Down Expand Up @@ -1058,7 +1060,7 @@ void read_fat (unsigned int cl_no)
unsigned char *rp;
unsigned short i;

disk_io (READ, FAT_START + fat_low * 3 / 2, raw_fat, rawfat_size);
disk_io (READ, fat_start + fat_low * 3 / 2, raw_fat, rawfat_size);
for (rp = raw_fat, cp = cooked_fat, i = 0;
i < cache_size;
rp += 3, i += 2) {
Expand All @@ -1075,7 +1077,7 @@ void read_fat (unsigned int cl_no)
assert (sizeof (short) == 2);
assert (CHAR_BIT == 8); /* just in case */

disk_io (READ, FAT_START + fat_low * 2, (void *)cooked_fat, cache_size * 2);
disk_io (READ, fat_start + fat_low * 2, (void *)cooked_fat, cache_size * 2);
if (big_endian) {
unsigned short *cp;
unsigned char *rp;
Expand Down Expand Up @@ -1107,8 +1109,8 @@ void flush_fat(void)
*(rp + 1) = *cp >> 8;
}
}
disk_io (WRITE, FAT_START + fat_low * 2, (void *)cooked_fat, cache_size * 2);
disk_io (WRITE, FAT_START + fat_size + fat_low * 2, (void *)cooked_fat, cache_size * 2);
disk_io (WRITE, fat_start + fat_low * 2, (void *)cooked_fat, cache_size * 2);
disk_io (WRITE, fat_start+ fat_size + fat_low * 2, (void *)cooked_fat, cache_size * 2);
} else {
unsigned short *cp;
unsigned char *rp;
Expand All @@ -1122,8 +1124,8 @@ void flush_fat(void)
((*(cp + 1) & 0x00f) << 4);
*(rp + 2) = ((*(cp + 1) & 0xff0) >> 4);
}
disk_io (WRITE, FAT_START + fat_low * 3 / 2, raw_fat, rawfat_size);
disk_io (WRITE, FAT_START + fat_size + fat_low * 3 / 2, raw_fat, rawfat_size);
disk_io (WRITE, fat_start + fat_low * 3 / 2, raw_fat, rawfat_size);
disk_io (WRITE, fat_start+ fat_size + fat_low * 3 / 2, raw_fat, rawfat_size);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/dev/cpc/cpckeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint8_t shiftkeyboard[10][8] = {
{KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_F9, KEY_F6, KEY_F3,KEY_ENTER, KEY_F11},
{KEY_LEFT ,KEY_PASTE , KEY_F7, KEY_F8, KEY_F5, KEY_F1, KEY_F2, KEY_F10},
{KEY_DEL, '{', 13, '}', KEY_F4, 0/*SHIFT*/, '`', 0/*CONTROL*/ },
{KEY_POUND, '=', '|', 'P', '+', '*', '?', '>'},
{'~', '=', '|', 'P', '+', '*', '?', '>'},
{'_', ')', 'O', 'I', 'L', 'K', 'M', '<'},
{'(', 39/*'*/, 'U', 'Y', 'H', 'J', 'N', ' '},
{'&', '%', 'R', 'T', 'G', 'F', 'B', 'V'},
Expand Down
33 changes: 21 additions & 12 deletions Kernel/platform/platform-cpc6128/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,42 @@ clean:
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
# 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

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

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

# 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
mkfs.fat -F 16 -r 128 -v $(IMAGES)/FAT16.img #we could mount this now as loop device and put stuff on it before adding to the disk image

# Add the file systems
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
dd if=$(IMAGES)/FAT16.img of=$(IMAGES)/disk.img bs=512 seek=92160 conv=notrunc

# Make a 720k floppy with minimal root filesystem
(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

3 changes: 2 additions & 1 deletion Kernel/platform/platform-cpc6128/cpc6128.s
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ _plt_monitor:
_plt_reboot:
di
;halt ;we are debugging why we end here
ld bc, #0x7f89 ;this would set the firmware ready for boot into firmware with (out (c),c ; rst0)
ld bc, #0x7f89 ;this would set the firmware ready for boot into firmware with (out (c),c ; rst0)
;work with the 6128 firmware, fails with the 464 & the 664 firmware, need to investigate.
out (c), c
rst 0 ; back into our booter

Expand Down
81 changes: 19 additions & 62 deletions Kernel/platform/platform-cpc6128/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@

.area _DISCARD

;code to copy font from firmware rom to its ram place
copyfont:
;di interrupts should be off when mapping roms
ld bc, #0x7faa ;RMR ->UROM disable LROM enable
out (c),c
ld hl, #0x3800 ;Firmware (LROM) character bitmaps
ld de, #(_fontdata_8x8)
ld bc, #0x800
ldir
ld bc, #0x7fae ;RMR ->UROM disable LROM disable
out (c),c
ret
copyfont_end:


.area _COMMONMEM

Expand Down Expand Up @@ -85,18 +99,17 @@ _start:


di
ld sp, #kstack_top
ld bc,#0x7fc1 ;select the correct map (kernel map) in case of snapshot loading.
out (c),c ;this should be set in the snapshot file. FIXME

ld sp, #kstack_top
;
; move the common memory where it belongs
ld hl, #s__DATA
ld de, #s__COMMONMEM
ld bc, #l__COMMONMEM
ldir

; then the font
; ld de, #s__FONT
; ld bc, #l__FONT
; ldir

; then the discard (backwards as will overlap)
ld de, #s__DISCARD
Expand All @@ -121,49 +134,8 @@ _start:
ld (hl), #0
ldir

;We are loading from a .sna with first 64k filled with fuzix.bin starting at 0x100
;copy bank 3 to bank 7 in C7 mode (7 at 0x4000), zero bank 3 (vmem) and switch to C1 (kernel map)
;when a proper loader is done this should be managed there
call copyfont

ld bc,#0x7fc7
out (c),c

ld hl, #0xc000
ld de, #0x4000
ld bc, #0x4000
ldir

ld bc,#0x7f00
out (c),c
ld a,#0x44
out (c),a ; blue paper
ld bc,#0x7f01
out (c),c
ld a,#0x4b
out (c),a ; white ink

ld hl, #0xc000
ld de, #0xc001
ld bc, #0x3fff
ld (hl), #0
ldir

ld bc,#0x7fc1
out (c),c

ld hl,#copyfont
ld de,#0xF000
ld bc,#(copyfont_end-copyfont)
ldir

call #0xF000

ld hl,#0xF000
ld de,#0xF001
ld bc,#(copyfont_end-copyfont-1)
ld (hl),#0
ldir

; Configure memory map
call init_early

Expand All @@ -178,21 +150,6 @@ _start:
stop: halt
jr stop

;code to copy font
copyfont: ;;this wil be in the loader
di
ld bc, #0x7faa ;RMR ->UROM disable LROM enable
out (c),c
ld hl, #0x3800 ;Firmware (LROM) character bitmaps
ld de, #(_fontdata_8x8)
ld bc, #0x800
ldir
ld bc, #0x7fae ;RMR ->UROM disable LROM disable
out (c),c
ret
copyfont_end:


.area _BUFFERS
;
; Buffers (we use asm to set this up as we need them in a special segment
Expand Down
55 changes: 45 additions & 10 deletions Kernel/platform/platform-cpc6128/loader.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@
.area BOOT (ABS)
.org #0xfdff

;;ROM's & interrupts off
;;ROM's & interrupts off & mode 2

di
ld b, #0x7f
ld c,#0b10101101
ld c,#0b10101110
out (c),c
;;from default boot org to the needed one

ld bc,#0x7fc1 ;select the kernel map
out (c),c

;; hide screen

ld bc,#0x7f10
out (c),c
ld a,#0x54 ;black
out (c),a
ld bc,#0x7f00
out (c),c
;ld a,#0x44 ;blue
out (c),a
ld bc,#0x7f01
out (c),c
;ld a,#0x4b ;bright white
out (c),a

;;from default boot org to the needed one.
ld hl,#0x100
ld de,#0xfdff
ld bc,#512
Expand All @@ -22,11 +41,11 @@ jp start

start:
;;clean room
ld hl,#0
ld de ,#1
ld (#0),hl
ld bc,#0xfdfe
ldir
;ld hl,#0
;ld de ,#1
;ld (#0),hl
;ld bc,#0xfdfe
;ldir
;;patch interrupt vector
LD HL,#0XC9FB
LD (#0X0038),HL
Expand Down Expand Up @@ -103,7 +122,9 @@ ld de,#0x100
ld (#data_ptr),de

;; number of complete sectors to read for our data
;; 30 sectors, 512 bytes per sector. Total data to read is 30*512 = 15360 bytes.
;; 126 sectors, 512 bytes per sector. Total data to read is 126*512 = 64512 bytes. Fuzix binary is smaller.
;; We can load
;;
ld a,#126
ld (#sector_count),a

Expand Down Expand Up @@ -242,9 +263,18 @@ ld hl,(#data_ptr)
ld bc,#512
add hl,bc
ld (#data_ptr),hl

;; update sector id (loops #0x41-#0x49).
ld a,(#sector)

ex af,af'
ld bc,#0x7f10
out (c),c
ld a,r
and #0x5F
or #0x40
out (c),a
ex af,af'

inc a
ld (#sector),a
cp #0x4a ;; #0x49+1 (last sector id on the track+1)
Expand All @@ -256,6 +286,11 @@ ld a,(#track)
inc a
ld (#track),a

ld bc,#0x7f10
out (c),c
add #0x4a
out (c),a

ld a,#0x41 ;; #0x41 = first sector id on the track
ld (#sector),a
jp read_sectors_new_track
Expand Down
Loading

0 comments on commit 99c4384

Please sign in to comment.