mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-04-18 08:36:07 +00:00
Handle Ultimate2-style IDX files for C64 TAP files
This commit is contained in:
2
Makefile
2
Makefile
@@ -11,7 +11,7 @@ TODAY = `date +"%m/%d/%y"`
|
||||
|
||||
PRJ = firmware
|
||||
SRC = hw/AT91SAM/Cstartup_SAM7.c hw/AT91SAM/hardware.c hw/AT91SAM/spi.c hw/AT91SAM/mmc.c hw/AT91SAM/at91sam_usb.c hw/AT91SAM/usbdev.c
|
||||
SRC += fdd.c firmware.c fpga.c hdd.c main.c menu.c menu-minimig.c menu-8bit.c osd.c state.c syscalls.c user_io.c settings.c data_io.c boot.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c cue_parser.c mist_cfg.c archie.c pcecd.c neocd.c snes.c zx_col.c arc_file.c font.c utils.c
|
||||
SRC += fdd.c firmware.c fpga.c hdd.c main.c menu.c menu-minimig.c menu-8bit.c osd.c state.c syscalls.c user_io.c settings.c data_io.c boot.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c cue_parser.c mist_cfg.c archie.c pcecd.c neocd.c snes.c zx_col.c arc_file.c c64files.c font.c utils.c
|
||||
SRC += usb/usb.c usb/max3421e.c usb/usb-max3421e.c usb/usbdebug.c usb/hub.c usb/hid.c usb/hidparser.c usb/xboxusb.c usb/timer.c usb/asix.c usb/pl2303.c usb/usbrtc.c usb/storage.c usb/joymapping.c usb/joystick.c
|
||||
SRC += fat_compat.c
|
||||
SRC += FatFs/diskio.c FatFs/ff.c FatFs/ffunicode.c
|
||||
|
||||
@@ -12,7 +12,7 @@ TODAY = `date +"%m/%d/%y"`
|
||||
PRJ = firmware
|
||||
SRC = hw/ATSAMV71/cstartup.c hw/ATSAMV71/hardware.c hw/ATSAMV71/spi.c hw/ATSAMV71/qspi.c hw/ATSAMV71/mmc.c hw/ATSAMV71/usbdev.c hw/ATSAMV71/eth.c hw/ATSAMV71/irq/nvic.c
|
||||
SRC += hw/ATSAMV71/network/intmath.c hw/ATSAMV71/network/gmac.c hw/ATSAMV71/network/gmacd.c hw/ATSAMV71/network/phy.c hw/ATSAMV71/network/ethd.c
|
||||
SRC += fdd.c firmware.c fpga.c hdd.c main.c menu.c menu-minimig.c menu-8bit.c osd.c state.c syscalls.c user_io.c settings.c data_io.c boot.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c cue_parser.c mist_cfg.c archie.c pcecd.c neocd.c psx.c snes.c zx_col.c arc_file.c font.c utils.c
|
||||
SRC += fdd.c firmware.c fpga.c hdd.c main.c menu.c menu-minimig.c menu-8bit.c osd.c state.c syscalls.c user_io.c settings.c data_io.c boot.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c cue_parser.c mist_cfg.c archie.c pcecd.c neocd.c psx.c snes.c zx_col.c arc_file.c c64files.c font.c utils.c
|
||||
SRC += sxmlc/sxmlc.c
|
||||
SRC += it6613/HDMI_TX.c it6613/it6613_drv.c it6613/it6613_sys.c it6613/EDID.c it6613/hdmitx_mist.c
|
||||
SRC += usb/usbdebug.c usb/hub.c usb/xboxusb.c usb/hid.c usb/hidparser.c usb/timer.c usb/asix.c usb/pl2303.c usb/usbrtc.c usb/joymapping.c usb/joystick.c usb/storage.c
|
||||
|
||||
211
c64files.c
Normal file
211
c64files.c
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
This file is part of MiST-firmware
|
||||
|
||||
MiST-firmware is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
MiST-firmware is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "c64files.h"
|
||||
#include "fat_compat.h"
|
||||
#include "data_io.h"
|
||||
#include "menu.h"
|
||||
#include "osd.h"
|
||||
|
||||
#define IDX_EOT 4 // End-Of-Transmission
|
||||
|
||||
#define CHAR_IS_LINEEND(c) (((c) == '\n'))
|
||||
#define CHAR_IS_COMMENT(c) (((c) == ';'))
|
||||
#define CHAR_IS_QUOTE(c) (((c) == '"'))
|
||||
#define CHAR_IS_SPACE(c) (((c) == ' ') || ((c) == '\t'))
|
||||
|
||||
#define IDX_LINE_SIZE 128
|
||||
|
||||
static FIL idxfile;
|
||||
static FIL tapfile;
|
||||
static int idx_pt = 0;
|
||||
static int lastidx = -1;
|
||||
static char idxline[IDX_LINE_SIZE];
|
||||
static int f_index;
|
||||
|
||||
static char c64_idx_getch()
|
||||
{
|
||||
UINT br;
|
||||
|
||||
if (!(idx_pt&0x1ff)) {
|
||||
// reload buffer
|
||||
f_read(&idxfile, sector_buffer, 512, &br);
|
||||
//hexdump(sector_buffer, 512, 0);
|
||||
}
|
||||
|
||||
if (idx_pt >= f_size(&idxfile)) return 0;
|
||||
else return sector_buffer[(idx_pt++)&0x1ff];
|
||||
}
|
||||
|
||||
static int c64_idx_getline(char* line, int *offset)
|
||||
{
|
||||
char c;
|
||||
char ignore=0;
|
||||
char literal=0;
|
||||
char leadingspace = 0;
|
||||
int i=0;
|
||||
*offset = 0;
|
||||
|
||||
while(1) {
|
||||
c = c64_idx_getch();
|
||||
if ((!c) || CHAR_IS_LINEEND(c)) break;
|
||||
if (!CHAR_IS_SPACE(c) && *offset) leadingspace = 0;
|
||||
if (CHAR_IS_QUOTE(c) && !ignore) literal ^= 1;
|
||||
else if (CHAR_IS_COMMENT(c) && !ignore && !literal) ignore++;
|
||||
else if ((literal || !ignore ) && i<(IDX_LINE_SIZE-1) && !leadingspace) line[i++] = c;
|
||||
if (*offset == 0 && CHAR_IS_SPACE(c)) {
|
||||
line[i] = 0;
|
||||
*offset = strtoll(line, NULL, 0);
|
||||
i = 0;
|
||||
if (*offset) leadingspace = 1;
|
||||
}
|
||||
}
|
||||
line[i] = '\0';
|
||||
iprintf("line: %s, offset: %d\n", line, *offset);
|
||||
return c==0 ? IDX_EOT : literal ? 1 : 0;
|
||||
}
|
||||
|
||||
static char *c64_idxitem(int idx, int *offset)
|
||||
{
|
||||
if (idx <= lastidx) {
|
||||
idx_pt = 0;
|
||||
f_rewind(&idxfile);
|
||||
lastidx = -1;
|
||||
}
|
||||
while (1) {
|
||||
int r = c64_idx_getline(idxline, offset);
|
||||
if (idxline[0]) lastidx++;
|
||||
if (r == IDX_EOT || idx == lastidx) break;
|
||||
}
|
||||
return idxline;
|
||||
}
|
||||
|
||||
static char c64_idx_getmenupage(uint8_t idx, char action, menu_page_t *page)
|
||||
{
|
||||
if (action == MENU_PAGE_EXIT) {
|
||||
f_close(&idxfile);
|
||||
f_close(&tapfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
page->title = "C64IDX";
|
||||
page->flags = 0;
|
||||
page->timer = 0;
|
||||
page->stdexit = MENU_STD_EXIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char c64_idx_getmenuitem(uint8_t idx, char action, menu_item_t *item)
|
||||
{
|
||||
int offset;
|
||||
char *str;
|
||||
if (action == MENU_ACT_GET) {
|
||||
str = c64_idxitem(idx, &offset);
|
||||
item->item = str;
|
||||
item->active = (str[0] != 0);
|
||||
return (str[0] != 0);
|
||||
} else if (action == MENU_ACT_SEL) {
|
||||
str = c64_idxitem(idx, &offset);
|
||||
iprintf("C64: load TAP segment \"%s\" at offset %08x\n", str, offset);
|
||||
f_close(&idxfile);
|
||||
|
||||
UINT br;
|
||||
UINT c;
|
||||
FRESULT res;
|
||||
char *p;
|
||||
// Send header
|
||||
DISKLED_ON
|
||||
res = f_read(&tapfile, sector_buffer, 20, &br);
|
||||
DISKLED_OFF
|
||||
if (res != FR_OK) {
|
||||
f_close(&tapfile);
|
||||
CloseMenu();
|
||||
return 1;
|
||||
}
|
||||
data_io_file_tx_prepare(&tapfile, f_index, "TAP");
|
||||
EnableFpga();
|
||||
SPI(DIO_FILE_TX_DAT);
|
||||
spi_write(sector_buffer, 20);
|
||||
DisableFpga();
|
||||
// Send data
|
||||
if (f_lseek(&tapfile, offset) == FR_OK) {
|
||||
while(1) {
|
||||
DISKLED_ON
|
||||
res = f_read(&tapfile, sector_buffer, SECTOR_BUFFER_SIZE, &br);
|
||||
DISKLED_OFF
|
||||
if (res == FR_OK) {
|
||||
EnableFpga();
|
||||
SPI(DIO_FILE_TX_DAT);
|
||||
spi_write(sector_buffer, br);
|
||||
DisableFpga();
|
||||
}
|
||||
if (res != FR_OK || br != SECTOR_BUFFER_SIZE) break;
|
||||
}
|
||||
}
|
||||
data_io_file_tx_done();
|
||||
f_close(&tapfile);
|
||||
CloseMenu();
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void c64_handleidx(FIL *file, int index, const char *name, const char *ext)
|
||||
{
|
||||
iprintf("C64: open IDX %s\n", name);
|
||||
|
||||
f_rewind(file);
|
||||
idxfile = *file;
|
||||
idx_pt = 0;
|
||||
lastidx = -1;
|
||||
f_index = index;
|
||||
|
||||
const char *fileExt = 0;
|
||||
int len = strlen(name);
|
||||
while(len > 2) {
|
||||
if (name[len-2] == '.') {
|
||||
fileExt = &name[len-1];
|
||||
break;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
if (fileExt) {
|
||||
char tap[len+3];
|
||||
memcpy(tap, name, len-1);
|
||||
strcpy(&tap[len-1], "TAP");
|
||||
if(f_open(&tapfile, tap, FA_READ) != FR_OK) {
|
||||
f_close(&idxfile);
|
||||
ErrorMessage("Unable to open the\ncorresponding TAP file!", 0);
|
||||
return;
|
||||
}
|
||||
SetupMenu(&c64_idx_getmenupage, &c64_idx_getmenuitem, NULL);
|
||||
} else {
|
||||
f_close(&idxfile);
|
||||
CloseMenu();
|
||||
}
|
||||
}
|
||||
|
||||
static data_io_processor_t c64_idxfile = {"IDX", &c64_handleidx};
|
||||
|
||||
|
||||
void c64files_init()
|
||||
{
|
||||
data_io_add_processor(&c64_idxfile);
|
||||
}
|
||||
23
c64files.h
Normal file
23
c64files.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
This file is part of MiST-firmware
|
||||
|
||||
MiST-firmware is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
MiST-firmware is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef C64_FILES_H
|
||||
#define C64_FILES_H
|
||||
|
||||
void c64files_init();
|
||||
|
||||
#endif // C64_FILES_H
|
||||
@@ -187,16 +187,17 @@ char data_io_add_processor(data_io_processor_t *processor) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void data_io_file_tx_processor(FIL *file, char index, const char *ext, const char *processor_id) {
|
||||
void data_io_file_tx_processor(FIL *file, char index, const char *ext, const char *name, const char *processor_id) {
|
||||
iprintf("data_io_file_tx_processor idx: %d ext: %s\n", index, ext);
|
||||
data_io_processor_t *processor;
|
||||
data_io_file_tx_prepare(file, index, ext);
|
||||
if (processor_id && (processor = data_io_get_processor(processor_id))) {
|
||||
processor->file_tx_send(file);
|
||||
processor->file_tx_send(file, index, name, ext);
|
||||
} else {
|
||||
iprintf("Processor for %s not found. Defaulting to normal upload\n", processor_id);
|
||||
data_io_file_tx_prepare(file, index, ext);
|
||||
data_io_file_tx_send(file);
|
||||
data_io_file_tx_done();
|
||||
}
|
||||
data_io_file_tx_done();
|
||||
}
|
||||
|
||||
// send 'fill' byte 'len' times
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
typedef struct {
|
||||
char id[4];
|
||||
void (*file_tx_send)(FIL *file);
|
||||
void (*file_tx_send)(FIL *file, int index, const char* name, const char* ext);
|
||||
} data_io_processor_t;
|
||||
|
||||
void data_io_init();
|
||||
@@ -30,7 +30,7 @@ void data_io_file_tx_start();
|
||||
void data_io_file_tx_done();
|
||||
void data_io_fill_tx(unsigned char, unsigned int, char);
|
||||
void data_io_file_tx(FIL*, char, const char*);
|
||||
void data_io_file_tx_processor(FIL*, char, const char*, const char*);
|
||||
void data_io_file_tx_processor(FIL*, char, const char*, const char*, const char*);
|
||||
void data_io_file_rx(FIL*, char, unsigned int);
|
||||
|
||||
// called when a rom entry is found in the mist.ini
|
||||
|
||||
2
main.c
2
main.c
@@ -51,6 +51,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "menu.h"
|
||||
#include "user_io.h"
|
||||
#include "data_io.h"
|
||||
#include "c64files.h"
|
||||
#include "arc_file.h"
|
||||
#include "font.h"
|
||||
#include "tos.h"
|
||||
@@ -142,6 +143,7 @@ int main(void)
|
||||
DISKLED_ON;
|
||||
|
||||
data_io_init();
|
||||
c64files_init();
|
||||
Timer_Init();
|
||||
|
||||
USART_Init(115200);
|
||||
|
||||
@@ -147,15 +147,15 @@ static char RomFileSelected(uint8_t idx, const char *SelectedName) {
|
||||
data_io_file_tx_done();
|
||||
}
|
||||
} else if (romtype == ROM_PROCESSED) {
|
||||
data_io_file_tx_processor(&file, ext_idx << 6 | selected_drive_slot, GetExtension(SelectedName), data_processor_id);
|
||||
data_io_file_tx_processor(&file, ext_idx << 6 | selected_drive_slot, GetExtension(SelectedName), SelectedName, data_processor_id);
|
||||
} else {
|
||||
if (romtype == ROM_SNES) ext_idx = snes_getromtype(&file);
|
||||
data_io_file_tx(&file, ext_idx << 6 | selected_drive_slot, GetExtension(SelectedName));
|
||||
}
|
||||
f_close(&file);
|
||||
if (romtype != ROM_PROCESSED) f_close(&file);
|
||||
}
|
||||
// close menu afterwards
|
||||
CloseMenu();
|
||||
// close menu afterwards (but allow custom processor to have its own menu)
|
||||
if (romtype != ROM_PROCESSED) CloseMenu();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user