Many fixes/improvements to CD image handling:

- Fix memory leak when changing images (file handle not freed)
- Longer max file length limit (127 chars)
- Better errors when USB not present
- Fix polling of CD status register when listing images
- Add ability to load image by name
- Many weird edge cases with image loading state fixed
This commit is contained in:
Ian Scott committed 2025-06-21 23:46:50 -06:00
1 parent d9d0007d25
commit 02ba99b6aa
13 files changed
+170 -157

No files matched your search

+75 -59
View File
@@ -27,7 +27,7 @@
#include "../common/picogus.h"
static void banner(void) {
printf("PicoGUSinit v3.5.0 (c) 2025 Ian Scott - licensed under the GNU GPL v2\n");
printf("PicoGUSinit v3.6.0 (c) 2025 Ian Scott - licensed under the GNU GPL v2\n");
}
@@ -140,6 +140,7 @@ static void err_pigus(void) {
static void err_protocol(uint8_t expected, uint8_t got) {
fprintf(stderr, "ERROR: PicoGUS card using protocol %u, needs %u\n", got, expected);
fprintf(stderr, "Please run the latest PicoGUS firmware and pgusinit.exe versions together!\n");
fprintf(stderr, "To flash new firmware, run pgusinit /flash picogus.uf2\n");
}
@@ -242,29 +243,34 @@ static bool wait_for_read(const uint8_t value) {
}
static cdrom_image_status_t wait_for_cd_status(void) {
outp(CONTROL_PORT, 0xCC); // Knock on the door...
outp(CONTROL_PORT, MODE_CDSTATUS); // Select CD image status register
cdrom_image_status_t cd_status;
for (uint16_t i = 0; i < 256; ++i) {
delay(100);
cd_status = (cdrom_image_status_t)inp(DATA_PORT_HIGH);
if (cd_status != CD_STATUS_BUSY) {
break;
}
}
return cd_status;
}
static bool print_cdimage_list(void) {
outp(CONTROL_PORT, 0xCC); // Knock on the door...
outp(CONTROL_PORT, MODE_CDLOAD); // Get currently loaded index
uint8_t current_index = inp(DATA_PORT_HIGH);
printf("Listing CD images on USB drive:\n");
outp(CONTROL_PORT, MODE_CDLIST); // Select CD image list register
delay(10);
outp(CONTROL_PORT, MODE_CDSTATUS); // Select CD image status register
bool ready = false;
for (uint16_t i = 0; i < 65535; ++i) {
int8_t cd_status = inp(DATA_PORT_HIGH);
if (cd_status == CD_STATUS_ERROR) {
printf("Error getting CD image list: ");
print_string(MODE_CDERROR);
return false;
} else if (cd_status == 2) {
ready = true;
break;
}
}
if (!ready) {
cdrom_image_status_t cd_status = wait_for_cd_status();
if (cd_status == CD_STATUS_BUSY) {
printf("Timeout getting CD image list\n");
return false;
} else if (cd_status == CD_STATUS_ERROR) {
printf("Error getting CD image list: ");
print_string(MODE_CDERROR);
return false;
}
outp(CONTROL_PORT, MODE_CDLIST); // Select CD image list register
char b[256], c, *p = b;
@@ -287,32 +293,40 @@ static bool print_cdimage_list(void) {
}
static void print_cdimage_current(void) {
outp(CONTROL_PORT, 0xCC); // Knock on the door...
outp(CONTROL_PORT, MODE_CDSTATUS); // Select CD image status register
uint8_t cd_status;
for (uint16_t i = 0; i < 65535; ++i) {
cd_status = inp(DATA_PORT_HIGH);
if (cd_status != CD_STATUS_BUSY) {
break;
}
}
if (cd_status == CD_STATUS_BUSY) {
printf("Timeout loading CD image.\n");
return;
} else if ((int8_t)cd_status == CD_STATUS_ERROR) {
printf("Error loading CD image: ");
print_string(MODE_CDERROR);
return;
}
static int print_cdimage_current(void) {
outp(CONTROL_PORT, MODE_CDLOAD); // Get currently loaded index
uint8_t current_index = inp(DATA_PORT_HIGH);
if (!current_index) {
printf("No CD image loaded.\n");
return;
return 97;
}
printf("CD image loaded: ");
print_string(MODE_CDNAME);
return 0;
}
static int wait_for_cd_load(void) {
cdrom_image_status_t cd_status = wait_for_cd_status();
if (cd_status == CD_STATUS_BUSY) {
printf("Timeout loading CD image.\n");
return 99;
} else if ((int8_t)cd_status == CD_STATUS_ERROR) {
printf("Error loading CD image: ");
print_string(MODE_CDERROR);
return 98;
}
return print_cdimage_current();
}
static void print_cdemu_status(void) {
outp(CONTROL_PORT, MODE_CDAUTOADV); // Select joystick enable register
uint8_t tmp_uint8 = inp(DATA_PORT_HIGH);
outp(CONTROL_PORT, MODE_CDPORT); // Select port register
uint16_t tmp_uint16 = inpw(DATA_PORT_LOW); // Get port
printf("CD-ROM emulation on port %x, image auto-advance %s\n", tmp_uint16, tmp_uint8 ? "enabled" : "disabled");
print_cdimage_current();
}
@@ -493,6 +507,7 @@ static void send_string(uint8_t mode, char* str, int16_t max_len)
outp(DATA_PORT_HIGH, 0);
}
#define process_bool_opt(option) \
if (i + 1 >= argc) { \
usage(mode, false); \
@@ -522,9 +537,7 @@ int main(int argc, char* argv[]) {
uint8_t enable_joystick = 0;
uint8_t wtvol;
char fw_filename[256] = {0};
char wifi_ssid[33] = {0};
char wifi_pass[64] = {0};
bool nopass = false;
bool wifichg = false;
card_mode_t mode;
char mode_name[8] = {0};
int fw_num = 8;
@@ -549,12 +562,11 @@ int main(int argc, char* argv[]) {
usage(INVALID_MODE, false);
return 255;
}
e = sscanf(argv[++i], "%255s", fw_filename);
if (e != 1) {
if (strlen(argv[++i]) > 255) {
usage(INVALID_MODE, false);
return 5;
}
return write_firmware(fw_filename);
return write_firmware(argv[i]);
}
++i;
}
@@ -762,25 +774,25 @@ int main(int argc, char* argv[]) {
usage(mode, false);
return 255;
}
e = sscanf(argv[++i], "%32s", wifi_ssid);
if (e != 1) {
if (strlen(argv[++i]) > 32) {
usage(mode, false);
return 4;
}
send_string(MODE_WIFISSID, wifi_ssid, 32);
wifichg = true;
send_string(MODE_WIFISSID, argv[i], 32);
} else if (stricmp(argv[i], "/wifipass") == 0) {
if (i + 1 >= argc) {
usage(mode, false);
return 255;
}
e = sscanf(argv[++i], "%63s", wifi_pass);
if (e != 1) {
if (strlen(argv[++i]) > 63) {
usage(mode, false);
return 4;
}
send_string(MODE_WIFIPASS, wifi_pass, 63);
wifichg = true;
send_string(MODE_WIFIPASS, argv[i], 63);
} else if (stricmp(argv[i], "/wifinopass") == 0) {
nopass = true;
wifichg = true;
send_string(MODE_WIFIPASS, "", 1);
// CD-ROM options /////////////////////////////////////////////////////////////////
} else if (stricmp(argv[i], "/cdport") == 0) {
@@ -804,8 +816,18 @@ int main(int argc, char* argv[]) {
}
outp(CONTROL_PORT, MODE_CDLOAD); // Select CD image load register
outp(DATA_PORT_HIGH, tmp_uint8);
print_cdimage_current();
return 0;
return wait_for_cd_load();
} else if (stricmp(argv[i], "/cdloadname") == 0) {
if (i + 1 >= argc) {
usage(mode, false);
return 255;
}
if (strlen(argv[++i]) > 127) {
usage(mode, false);
return 5;
}
send_string(MODE_CDNAME, argv[i], 127);
return wait_for_cd_load();
} else if (stricmp(argv[i], "/cdauto") == 0) {
process_bool_opt(tmp_uint8);
outp(CONTROL_PORT, MODE_CDAUTOADV); // Select CD image autoadvance register
@@ -838,7 +860,7 @@ int main(int argc, char* argv[]) {
return reboot_to_firmware(fw_num, permanent);
}
if (wifi_ssid[0] || wifi_pass[0] || nopass) {
if (wifichg) {
outp(CONTROL_PORT, MODE_WIFIAPPLY);
outp(DATA_PORT_HIGH, 0);
}
@@ -920,10 +942,7 @@ int main(int argc, char* argv[]) {
break;
case USB_MODE:
printf("Running in USB mode\n", tmp_uint16);
print_cdimage_current();
outp(CONTROL_PORT, MODE_CDAUTOADV); // Select joystick enable register
tmp_uint8 = inp(DATA_PORT_HIGH);
printf("CD image auto-advance on USB reinsert %s\n", tmp_uint8 ? "enabled" : "disabled");
print_cdemu_status();
break;
case PSG_MODE:
outp(CONTROL_PORT, MODE_TANDYPORT); // Select port register
@@ -950,10 +969,7 @@ int main(int argc, char* argv[]) {
} else {
printf("(AdLib port disabled)\n");
}
print_cdimage_current();
outp(CONTROL_PORT, MODE_CDAUTOADV); // Select joystick enable register
tmp_uint8 = inp(DATA_PORT_HIGH);
printf("CD image auto-advance on USB reinsert %s\n", tmp_uint8 ? "enabled" : "disabled");
print_cdemu_status();
break;
case NE2000_MODE:
outp(CONTROL_PORT, MODE_NE2KPORT); // Select port register
+1 -2
View File
@@ -19,7 +19,7 @@ set(PICO_COPY_TO_RAM 1)
include(pico_sdk_import.cmake)
project(picogus
VERSION "3.0.1"
VERSION "3.1.0"
LANGUAGES C CXX ASM
)
@@ -123,7 +123,6 @@ function(config_target TARGET_NAME MULTIFW)
target_sources(${TARGET_NAME} PRIVATE
mke/mke.c
cdrom/msc_app.c
audio_fifo.c
)
target_compile_definitions(${TARGET_NAME} PRIVATE CDROM=1)
target_sources(${TARGET_NAME} PRIVATE
+4 -2
View File
@@ -162,9 +162,12 @@ void cdrom_tasks(cdrom_t *dev) {
if (dev->image_path[0]) {
printf("Opening %s...",dev->image_path);
if (cdrom_image_open(dev,dev->image_path)) {
dev->image_command = CD_COMMAND_NONE;
dev->image_status = CD_STATUS_ERROR;
cdman_clear_image();
break;
} else {
cdman_set_image_index(dev);
}
printf("Done.\n");
dev->disk_loaded = 1;
@@ -179,9 +182,8 @@ void cdrom_tasks(cdrom_t *dev) {
void cdrom_fifo_init(cdrom_fifo_t *fifo,uint16_t size) {
fifo->data = malloc(size);
fifo->data = calloc(1, size);
if(!fifo->data) fatal("Unable to allocate fifo");
memset(fifo->data,0,size);
fifo->size = size;
}
+1 -1
View File
@@ -170,7 +170,7 @@ typedef struct cdrom {
char **image_list;
int image_count;
char image_path[256];
char image_path[128];
uint32_t sound_on;
uint32_t cdrom_capacity;
+1 -1
View File
@@ -9,7 +9,7 @@ void cdrom_errorstr_set(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsnprintf(_error, 256, fmt, ap);
printf("setting cdrom error: %s\n", _error);
/* printf("setting cdrom error: %s\n", _error); */
va_end(ap);
}
+6 -16
View File
@@ -161,15 +161,6 @@ image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf)
static int
image_is_track_pre(cdrom_t *dev, uint32_t lba)
{
cd_img_t *img = (cd_img_t *) dev->image;
int track;
/* GetTrack requires LBA. */
track = cdi_get_track(img, lba);
if (track != -1)
return cdi_get_audio_track_pre(img, track);
return 0;
}
@@ -231,7 +222,7 @@ image_exit(cdrom_t *dev)
cdi_close(img);
dev->image = NULL;
}
printf("wiped ops in image exit\n");
// printf("wiped ops in image exit\n");
dev->ops = NULL;
}
@@ -250,7 +241,7 @@ static int
image_open_abort(cdrom_t *dev)
{
cdrom_image_close(dev);
printf("wipes ops in image open abort");
// printf("wipes ops in image open abort");
dev->ops = NULL;
dev->host_drive = 0;
dev->image_path[0] = 0;
@@ -267,17 +258,16 @@ cdrom_image_open(cdrom_t *dev, const char *fn)
if (fn != dev->image_path)
strcpy(dev->image_path, fn);
putchar('a');
// putchar('a');
/* Create new instance of the CDROM_Image class. */
img = (cd_img_t *) malloc(sizeof(cd_img_t));
img = (cd_img_t *) calloc(1, sizeof(cd_img_t));
/* This guarantees that if ops is not NULL, then
neither is the image pointer. */
if (!img)
return image_open_abort(dev);
putchar('b');
memset(img, 0, sizeof(cd_img_t));
// putchar('b');
dev->image = img;
/* Open the image. */
@@ -298,7 +288,7 @@ cdrom_image_open(cdrom_t *dev, const char *fn)
cdrom_image_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL);
/* Attach this handler to the drive. */
printf("Set Ops in Open\n");
// printf("Set Ops in Open\n");
dev->ops = &cdrom_image_ops;
return 0;
+25 -55
View File
@@ -72,9 +72,8 @@ static inline void frames_to_msf(uint32_t total_frames, uint8_t *pM, uint8_t *pS
*pF = (uint8_t)total_frames;
}
#define MAX_LINE_LENGTH 512
#define MAX_FILENAME_LENGTH 256
#define CROSS_LEN 512
#define MAX_LINE_LENGTH 256
#define MAX_FILENAME_LENGTH 127
static char temp_keyword[64];
@@ -177,10 +176,12 @@ bin_close(void *priv)
if (tf->fp != NULL) {
//fclose(tf->fp);
f_close(tf->fp);
free(tf->fp);
tf->fp = NULL;
}
memset(tf->fn, 0x00, sizeof(tf->fn));
tf->fn[0] = 0;
/* memset(tf->fn, 0x00, sizeof(tf->fn)); */
free(priv);
}
@@ -274,7 +275,7 @@ cdi_clear_tracks(cd_img_t *cdi)
}
/* Now free the array. */
free(cdi->tracks);
free(cdi->tracks); /// maybe not
cdi->tracks = NULL;
/* Mark that there's no tracks. */
@@ -297,8 +298,10 @@ cdi_set_device(cd_img_t *cdi, const char *path)
return cdi_load_cue(cdi, path);
} else if (strncasecmp(path + (len - 4), ".iso", 4) == 0) {
return cdi_load_iso(cdi, path);
} else {
cdrom_errorstr_set("File '%s' not a cue or iso", path);
return 0;
}
return 0;
}
void
@@ -317,17 +320,6 @@ cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_
*lead_out = cdi->tracks[*end].start;
}
int
cdi_get_audio_track_pre(cd_img_t *cdi, int track)
{
const track_t *trk = &cdi->tracks[track - 1];
if ((track < 1) || (track > cdi->tracks_num))
return 0;
return trk->pre;
}
/* This replaces both Info and EndInfo, they are specified by a variable. */
int
cdi_get_audio_track_info(cd_img_t *cdi, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr)
@@ -748,7 +740,7 @@ cdi_cue_get_keyword(char **dest, char **line)
static uint32_t
cdi_cue_get_number(char **line)
{
char temp[128];
char temp[11];
uint32_t num;
if (!cdi_cue_get_buffer(temp, line, 0))
@@ -765,7 +757,7 @@ static int
/* cdi_cue_get_frame(uint64_t *frames, char **line) */
cdi_cue_get_frame(uint32_t *frames, char **line)
{
char temp[128];
char temp[9];
int min;
int sec;
int fr;
@@ -784,26 +776,6 @@ cdi_cue_get_frame(uint32_t *frames, char **line)
return 1;
}
static int
cdi_cue_get_flags(track_t *cur, char **line)
{
char temp[128];
char temp2[128] = {0};
int success;
success = cdi_cue_get_buffer(temp, line, 0);
if (!success)
return 0;
success = sscanf(temp, "%s", temp2) == 1;
if (!success)
return 0;
cur->pre = (strstr(temp2, "PRE") != NULL);
return 1;
}
static int
/* cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, uint64_t *total_pregap, uint64_t cur_pregap) */
cdi_add_track(cd_img_t *cdi, track_t *cur, uint32_t *shift, uint32_t prestart, uint32_t *total_pregap, uint32_t cur_pregap)
@@ -908,12 +880,14 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
cdi->tracks = NULL;
cdi->tracks_num = 0;
putchar('a');
// putchar('a');
/* fp = (FIL *) malloc(sizeof(FIL)); */
FRESULT result = f_open(&fp, cuefile, FA_READ);
cdrom_image_backend_log("result: %u\n", result);
if (result != FR_OK)
if (result != FR_OK) {
cdrom_errorstr_set("No file '%s' on USB", cuefile);
return 0;
}
FSIZE_t len = f_size(&fp);
cdrom_image_backend_log("file size: %u", len);
@@ -981,8 +955,6 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
trk.form = 0;
trk.mode2 = 0;
trk.pre = 0;
if (!strcmp(type, "AUDIO")) {
trk.sector_size = RAW_SECTOR_SIZE;
trk.attr = AUDIO_TRACK;
@@ -1060,36 +1032,36 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
break;
}
} else if (!strcmp(command, "FILE")) {
putchar('1');
// putchar('1');
if (can_add_track) {
success = cdi_add_track(cdi, &trk, &shift, prestart, &total_pregap, cur_pregap);
} else {
success = 1;
}
if (!success) {
putchar('x');
// putchar('x');
break;
}
can_add_track = 0;
putchar('2');
// putchar('2');
memset(ansi, 0, MAX_FILENAME_LENGTH * sizeof(char));
memset(filename, 0, MAX_FILENAME_LENGTH * sizeof(char));
putchar('3');
// putchar('3');
success = cdi_cue_get_buffer(ansi, &line, 0);
if (!success)
break;
putchar('4');
// putchar('4');
success = cdi_cue_get_keyword(&type, &line);
if (!success)
break;
putchar('5');
// putchar('5');
trk.file = NULL;
error = 1;
putchar('6');
// putchar('6');
if (!strcmp(type, "BINARY")) {
strncpy(filename,ansi,MAX_FILENAME_LENGTH);
trk.file = track_file_init(filename, &error);
@@ -1097,7 +1069,7 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
error = 0;
}
}
putchar('7');
// putchar('7');
if (error) {
switch (error) {
case 1:
@@ -1118,9 +1090,7 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
}
} else if (!strcmp(command, "PREGAP"))
success = cdi_cue_get_frame(&cur_pregap, &line);
else if (!strcmp(command, "FLAGS"))
success = cdi_cue_get_flags(&trk, &line);
else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || !strcmp(command, "POSTGAP") || !strcmp(command, "REM") || !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || !strcmp(command, "")) {
else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || !strcmp(command, "POSTGAP") || !strcmp(command, "REM") || !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || !strcmp(command, "FLAGS") || !strcmp(command, "")) {
/* Ignored commands. */
success = 1;
} else {
@@ -1128,7 +1098,7 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
success = 0;
}
putchar('z');
// putchar('z');
if (!success)
break;
}
+2 -4
View File
@@ -57,7 +57,7 @@ typedef struct SMSF {
uint8_t fr;
} TMSF;
#define SZ_TBL 64
#define SZ_TBL 32
/* Track file struct. */
typedef struct track_file_t {
@@ -66,7 +66,7 @@ typedef struct track_file_t {
uint32_t (*get_length)(void *priv);
void (*close)(void *priv);
char fn[260];
char fn[128];
FIL *fp;
void *priv;
// fast seek cluster link map table
@@ -80,7 +80,6 @@ typedef struct track_t {
int sector_size;
int mode2;
int form;
int pre;
int pad;
// uint64_t start;
uint32_t start;
@@ -101,7 +100,6 @@ extern void cdi_close(cd_img_t *cdi);
extern int cdi_set_device(cd_img_t *cdi, const char *path);
extern void cdi_get_audio_tracks(cd_img_t *cdi, int *st_track, int *end, TMSF *lead_out);
extern void cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_out);
extern int cdi_get_audio_track_pre(cd_img_t *cdi, int track);
extern int cdi_get_audio_track_info(cd_img_t *cdi, int end, int track, int *track_num, TMSF *start, uint8_t *attr);
extern int cdi_get_audio_track_info_lba(cd_img_t *cdi, int end, int track, int *track_num, uint32_t *start, uint8_t *attr);
extern int cdi_get_track(cd_img_t *cdi, uint32_t sector);
+31 -6
View File
@@ -10,9 +10,9 @@
#include "cdrom_error_msg.h"
// Maximum number of files to list
#define MAX_FILES 100
#define MAX_FILES 25
// Maximum filename length
#define MAX_FILENAME_LEN 64
#define MAX_FILENAME_LEN 127
// Structure to hold filename and allow sorting
typedef char FileEntry[MAX_FILENAME_LEN];
@@ -83,8 +83,8 @@ char** cdman_list_images(int *fileCount) {
// Check if it has valid extension
if (isCDImage(fno.fname)) {
strncpy(entries[count], fno.fname, MAX_FILENAME_LEN - 1);
entries[count][MAX_FILENAME_LEN - 1] = '\0';
strcpy(entries[count], fno.fname);
/* entries[count][MAX_FILENAME_LEN - 1] = '\0'; */
count++;
}
}
@@ -113,7 +113,7 @@ char** cdman_list_images(int *fileCount) {
fileList[i] = (char *)malloc(len);
if (fileList[i]) {
strcpy(fileList[i], entries[i]);
printf("%s\n", fileList[i]);
/* printf("%s\n", fileList[i]); */
} else {
// Clean up on allocation failure
for (int j = 0; j < i; j++) {
@@ -161,17 +161,42 @@ void cdman_load_image_index(cdrom_t *dev, int imageIndex) {
} else {
int imageCount;
char** images = cdman_list_images(&imageCount);
if (!images) {
dev->image_command = CD_COMMAND_NONE;
dev->image_status = CD_STATUS_ERROR;
return;
}
if (imageIndex > imageCount) {
// Wrap around index for autoadvance
imageIndex = 1;
}
strcpy(dev->image_path, images[imageIndex - 1]);
dev->image_command = CD_COMMAND_IMAGE_LOAD;
cdman_list_images_free(images, imageCount);
dev->image_command = CD_COMMAND_IMAGE_LOAD;
}
current_index = last_loaded_index = imageIndex;
}
void cdman_set_image_index(cdrom_t *dev) {
int imageCount;
char** images = cdman_list_images(&imageCount);
if (!images) {
dev->image_command = CD_COMMAND_NONE;
dev->image_status = CD_STATUS_ERROR;
return;
}
current_index = 0;
for (int i = 0; i < imageCount; ++i) {
if (strncasecmp(dev->image_path, images[i], MAX_FILENAME_LEN) == 0) {
current_index = last_loaded_index = i + 1;
// Copy back the canonical name to image_path with proper case
strcpy(dev->image_path, images[i]);
break;
}
}
cdman_list_images_free(images, imageCount);
}
void cdman_unload_image(cdrom_t *dev) {
dev->image_path[0] = 0;
+1
View File
@@ -11,6 +11,7 @@ void cdman_list_images_free(char **fileList, int fileCount);
uint8_t cdman_current_image_index(void);
void cdman_load_image_index(cdrom_t *dev, int imageIndex);
void cdman_set_image_index(cdrom_t *dev);
void cdman_unload_image(cdrom_t *dev);
void cdman_clear_image(void);
void cdman_reload_image(cdrom_t *dev);
+6 -6
View File
@@ -56,18 +56,18 @@ static bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const
msc_csw_t const* csw = cb_data->csw;
if (csw->status != 0) {
printf("Inquiry failed\r\n");
// printf("Inquiry failed\r\n");
return false;
}
// Print out Vendor ID, Product ID and Rev
printf("%.8s %.16s rev %.4s\r\n", scsi_resp.inquiry.vendor_id, scsi_resp.inquiry.product_id, scsi_resp.inquiry.product_rev);
// printf("%.8s %.16s rev %.4s\r\n", scsi_resp.inquiry.vendor_id, scsi_resp.inquiry.product_id, scsi_resp.inquiry.product_rev);
// Get capacity of device
uint32_t const block_count = tuh_msc_get_block_count(dev_addr, cbw->lun);
uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun);
printf("Disk Size: %" PRIu32 " MB\r\n", block_count / ((1024*1024)/block_size));
// printf("Disk Size: %" PRIu32 " MB\r\n", block_count / ((1024*1024)/block_size));
// printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size);
// For simplicity: we only mount 1 device
@@ -89,10 +89,10 @@ static bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const
//------------- IMPLEMENTATION -------------//
void tuh_msc_mount_cb(uint8_t dev_addr)
{
printf("A MassStorage device is mounted\r\n");
// printf("A MassStorage device is mounted\r\n");
if (mounted_dev) {
// Only handle a single drive
printf("Only a single USB drive is supported\n");
// printf("Only a single USB drive is supported\n");
return;
}
mounted_dev = dev_addr; // may not actually be mounted, but does indicate the drive is inserted
@@ -103,7 +103,7 @@ void tuh_msc_mount_cb(uint8_t dev_addr)
void tuh_msc_umount_cb(uint8_t dev_addr)
{
(void)dev_addr;
printf("A MassStorage device is unmounted\r\n");
// printf("A MassStorage device is unmounted\r\n");
mounted_dev = 0;
f_unmount("");
+1 -1
View File
@@ -114,7 +114,7 @@
#define FF_USE_LFN 1
#define FF_MAX_LFN 255
#define FF_MAX_LFN 127
/* The FF_USE_LFN switches the support for LFN (long file name).
/
/ 0: Disable LFN. FF_MAX_LFN has no effect.
+16 -4
View File
@@ -219,12 +219,12 @@ __force_inline void select_picogus(uint8_t value) {
break;
case MODE_CDLIST:
#ifdef CDROM
if (cdrom.image_status != CD_STATUS_READY) {
if (cdrom.image_status == CD_STATUS_IDLE) {
cdrom.image_status = CD_STATUS_BUSY;
cdrom.image_command = CD_COMMAND_IMAGE_LIST;
puts("cdimages start");
// puts("cdimages start");
}
puts("cdimages read");
// puts("cdimages read");
cur_read = 0;
cur_read_idx = 0;
#endif
@@ -234,6 +234,7 @@ __force_inline void select_picogus(uint8_t value) {
case MODE_CDAUTOADV:
break;
case MODE_CDNAME:
cur_write = 0;
case MODE_CDERROR:
cur_read = 0;
break;
@@ -393,6 +394,17 @@ __force_inline void write_picogus_high(uint8_t value) {
cdrom.image_status = CD_STATUS_BUSY;
cdrom.image_command = CD_COMMAND_IMAGE_LOAD_INDEX;
break;
case MODE_CDNAME:
if (!cur_write) {
memset(cdrom.image_path, 0, sizeof(cdrom.image_path));
}
cdrom.image_path[cur_write++] = value;
if (!value) {
cur_write = 0;
cdrom.image_status = CD_STATUS_BUSY;
cdrom.image_command = CD_COMMAND_IMAGE_LOAD;
}
break;
#endif
case MODE_CDAUTOADV: // enable auto advance of CD image on USB reinsert
settings.CD.autoAdvance = value;
@@ -520,7 +532,7 @@ __force_inline uint8_t read_picogus_high(void) {
return settings.CD.basePort == 0xFFFF ? 0 : (settings.CD.basePort >> 8);
#ifdef CDROM
case MODE_CDSTATUS:
printf("cdstatus %x\n", cdrom.image_status);
// printf("cdstatus %x\n", cdrom.image_status);
return cdrom.image_status;
case MODE_CDLIST:
if (cur_read_idx == cdrom.image_count) { // If end of the images