Skip to content

Commit

Permalink
Polishing cassette dump utility
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Jul 31, 2024
1 parent 8dbe871 commit 4c5fa1a
Show file tree
Hide file tree
Showing 17 changed files with 671 additions and 392 deletions.
Binary file modified programs/casdump/CASDUMP.PRG
Binary file not shown.
1 change: 1 addition & 0 deletions programs/casdump/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cassettedump-slot1: main.c fat32.c memory.c terminal.c sdcard.c sdcard.asm util.
fat32.c main.c memory.c terminal.c terminal_ext.c \
util.c sdcard.c sdcard.asm ram.asm util.asm tape.asm \
-startup=1 \
-pragma-define:SLOT1=0 \
-pragma-define:CRT_ORG_CODE=0x1000 \
-pragma-define:CRT_ORG_DATA=0x6100 \
-pragma-define:REGISTER_SP=0x9FFF \
Expand Down
2 changes: 1 addition & 1 deletion programs/casdump/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if [[ "$OSTYPE" == "msys" ]]; then
winpty docker run -v `pwd | sed 's/\//\/\//g'`://src/ -it z88dk/z88dk make
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
docker run -v `pwd`:/src/ -it z88dk/z88dk make
python3 ../../scripts/signprg.py CASSETTEDUMP.PRG
python3 ../../scripts/signprg.py CASDUMP.PRG
else
echo "Unknown operating system"
fi
9 changes: 6 additions & 3 deletions programs/casdump/fat32.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ uint8_t _fptr_entry_id = 0; // entry index
uint32_t read_mbr(void) {
// read the first sector of the SD card
read_sector(0x00000000);

// grab the start address of the first partition
return ram_read_uint32_t(SDCACHE0 + 0x1C6);

if(ram_read_uint16_t(SDCACHE0 + 510) != 0xAA55) {
return 0;
} else {
return ram_read_uint32_t(SDCACHE0 + 0x1C6);
}
}

/**
Expand Down
98 changes: 84 additions & 14 deletions programs/casdump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "terminal_ext.h"
#include "tape.h"

#define MODE_AUTOMATIC 0
#define MODE_MANUAL 1

// set printf io
#pragma printf "%i %X %lX %c %s %lu %u"

Expand All @@ -43,6 +46,8 @@ void copy_current_tapeblock(void);
// pre-allocate a big read buffer
static uint8_t cassette_buffer[0x400];
static char filename[11];
uint8_t wait = 1;
uint8_t mode = MODE_AUTOMATIC;

int main(void) {
// initialize environment
Expand Down Expand Up @@ -70,9 +75,32 @@ int main(void) {

for(;;) {
// whether to proceed to next cassette
print_recall("Start reading tape? (Y/N)");
if(wait_for_key_fixed(33) == 0) {
break;
print("Select operation:");
print(" (M)anual (A)utomatic (Q)uit");
print_recall(" Enter command...");
wait = 1;
while(wait == 1) {
wait_for_key();
switch(keymem[0x00]) {
case 34: // A
mode = MODE_AUTOMATIC;
wait = 0;
print("Automatic mode set");
break;
case 30: // M
mode = MODE_MANUAL;
wait = 0;
print("Manual mode set");
break;
case 3: // Q
return 0;
break;
default:
print("Invalid option");
print_recall("Enter command...");
wait = 1;
break;
}
}

// rewind the tape
Expand Down Expand Up @@ -107,11 +135,42 @@ int main(void) {
sprintf(termbuffer, "Found: %c%.16s %.3s%c%i%c%i", COL_YELLOW, description,
ext,COL_CYAN,totalblocks,COL_MAGENTA,length);
terminal_printtermbuffer();
print_recall("Copy program to sd-card? (Y/N)");

// check if user presses YES key
uint8_t store_continue = wait_for_key_fixed(33);
uint8_t store_continue = 1;
uint8_t continue_copying = YES;
if(mode == MODE_MANUAL) {
print_recall("Copy program to sd-card? (Y/N) Abort (A)");
wait = 1;
while(wait == 1) {
wait_for_key();
switch(keymem[0x00]) {
case 33: // Y
wait = 0;
continue_copying = YES;
store_continue = 1;
break;
case 25: // N
wait = 0;
store_continue = 0;
print("Skipping program.");
break;
case 34: // A
wait = 0;
continue_copying = NO;
print("Aborting copying.");
break;
default:
print("Invalid option");
print_recall("Copy program to sd-card? (Y/N) Abort (A)");
wait = 1;
break;
}
}
}

if(continue_copying == NO) {
break;
}

if(store_continue == 1) {
// grab total blocks and start copying first block
Expand Down Expand Up @@ -168,7 +227,7 @@ int main(void) {
}
copy_current_tapeblock();
}
sprintf(termbuffer, "%c%s >%c%.8s.%.3s", COL_GREEN, description, COL_YELLOW, filename, &filename[8]);
sprintf(termbuffer, "%c%.16s%.3s%c>%c%.8s.%.3s", COL_GREEN, description, ext, COL_WHITE, COL_YELLOW, filename, &filename[8]);
terminal_printtermbuffer();
} else {
// skip all blocks
Expand All @@ -186,8 +245,6 @@ int main(void) {
print("copying from tape to SD-card.");
print("");
}

return 0;
}

void init(void) {
Expand All @@ -209,19 +266,32 @@ void init(void) {
// turn LEDs off
z80_outp(PORT_LED_IO, 0x00);

// mount sd card
// mount sd card for SLOT1 cartridge, else assume that the
// card is already mounted
#ifdef SLOT1
print_recall("Initializing SD card..");
if(init_sdcard() != 0) {
print_error("Cannot connect to SD-CARD.");
for(;;){}
}
#endif

// mount first partition
uint32_t lba0 = read_mbr();
read_partition(lba0);

// sd card successfully mounted
print("Partition 1 mounted");
if(lba0 == 0) {
print_error("Invalid signature");
sprintf(termbuffer, "Signature read: %04X", ram_read_uint16_t(SDCACHE0 + 510));
terminal_printtermbuffer();
#ifndef SLOT1
print("Press any key to return to launcher");
wait_for_key();
#else
for(;;){}
#endif
} else {
read_partition(lba0);
print("Partition 1 mounted");
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void (*__operations[])(void) = {
void command_ls(void) {
if(check_mounted() == 1) { return; }

read_folder(_current_folder_cluster, -1, 0);
read_folder(-1, 0);
}

/**
Expand All @@ -76,7 +76,7 @@ void command_ls(void) {
void command_lscas(void) {
if(check_mounted() == 1) { return; }

read_folder(_current_folder_cluster, -1, 1);
read_folder(-1, 1);
}

/**
Expand All @@ -87,7 +87,7 @@ void command_cd(void) {

int id = atoi(&__lastinput[2]);

uint32_t clus = read_folder(_current_folder_cluster, id, 0);
uint32_t clus = read_folder(id, 0);
if(clus != _root_dir_first_cluster) {
if(_current_attrib & (1 << 4)) {
if(clus == 0) { // if zero, this is the root directory
Expand Down Expand Up @@ -117,7 +117,7 @@ void command_fileinfo(void) {
sprintf(termbuffer, "Filesize: %lu bytes", _filesize_current_file);
terminal_printtermbuffer();
print("Clusters:");
for(uint8_t i=0; i<LINKEDLIST_SIZE; i++) {
for(uint8_t i=0; i<F_LL_SIZE; i++) {
uint32_t cluster_id = _linkedlist[i];

if(cluster_id == 0 || cluster_id == 0xFFFFFFFF) {
Expand Down Expand Up @@ -237,7 +237,7 @@ void command_hexdump(void) {
}

// read the first sector of the file
read_sector(get_sector_addr(_linkedlist[0], 0));
read_sector(calculate_sector_address(_linkedlist[0], 0));

sprintf(termbuffer, "Filename: %s.%s", _basename, _ext);
terminal_printtermbuffer();
Expand Down Expand Up @@ -390,7 +390,7 @@ uint8_t read_file_metadata(int16_t file_id) {
return 1;
}

uint32_t cluster = read_folder(_current_folder_cluster, file_id, 0);
uint32_t cluster = read_folder(file_id, 0);
if(cluster == _root_dir_first_cluster) {
print_error("Could not find file");
return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void copy_ram_rom(uint16_t ram_src, uint16_t nbytes, uint8_t verbose) {
uint8_t j = 0;

do {
sst39sf_write_byte(rom_addr++, ram_read_byte(ram_src++));
sst39sf_write_byte(rom_addr++, ram_read_uint8_t(ram_src++));
} while (j++ != 255);

if(verbose == 1) {
Expand All @@ -54,7 +54,7 @@ void copy_ram_rom(uint16_t ram_src, uint16_t nbytes, uint8_t verbose) {
}

for(uint8_t j=0; j<remaining; j++) {
sst39sf_write_byte(rom_addr++, ram_read_byte(ram_src++));
sst39sf_write_byte(rom_addr++, ram_read_uint8_t(ram_src++));
}

if(verbose == 1) {
Expand Down
Loading

0 comments on commit 4c5fa1a

Please sign in to comment.