diff --git a/Makefile b/Makefile index 79b1bd0..08baa96 100644 --- a/Makefile +++ b/Makefile @@ -9,15 +9,25 @@ CC = $(BASE)-gcc LD = $(CC) STRIP = $(BASE)-strip +INCLUDE = -I./ +INCLUDE = -I./support/minimig + PRJ = MiSTer SRC = $(wildcard *.c) SRC2 = $(wildcard *.cpp) +MINIMIG_SRC = $(wildcard ./support/minimig/*.cpp) +SHARPMZ_SRC = $(wildcard ./support/sharpmz/*.cpp) +ARCHIE_SRC = $(wildcard ./support/archie/*.cpp) +ST_SRC = $(wildcard ./support/st/*.cpp) +X86_SRC = $(wildcard ./support/x86/*.cpp) -OBJ = $(SRC:.c=.o) $(SRC2:.cpp=.o) -DEP = $(SRC:.c=.d) $(SRC2:.cpp=.d) +VPATH = ./:./support/minimig:./support/sharpmz:./support/archie:./support/st:./support/x86 -CFLAGS = $(DFLAGS) -c -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DVDATE=\"`date +"%y%m%d"`\" -LFLAGS = -lc -lstdc++ -lrt +OBJ = $(SRC:.c=.o) $(SRC2:.cpp=.o) $(MINIMIG_SRC:.cpp=.o) $(SHARPMZ_SRC:.cpp=.o) $(ARCHIE_SRC:.cpp=.o) $(ST_SRC:.cpp=.o) $(X86_SRC:.cpp=.o) +DEP = $(SRC:.c=.d) $(SRC2:.cpp=.d) $(MINIMIG_SRC:.cpp=.d) $(SHARPMZ_SRC:.cpp=.d) $(ARCHIE_SRC:.cpp=.d) $(ST_SRC:.cpp=.d) $(X86_SRC:.cpp=.d) + +CFLAGS = $(DFLAGS) -c -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DVDATE=\"`date +"%y%m%d"`\" +LFLAGS = -lc -lstdc++ -lrt $(PRJ): $(OBJ) @$(info $@) @@ -29,6 +39,12 @@ clean: rm -f *.d *.o *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ) rm -rf obj .vs DTAR* x64 +cleanall: + rm -rf *.d *.o *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ) + rm -rf obj .vs DTAR* x64 + find . -name '*.o' -delete + find . -name '*.d' -delete + %.o: %.c @$(info $<) @$(CC) $(CFLAGS) -std=gnu99 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' diff --git a/menu.cpp b/menu.cpp index 42267da..31d3f34 100644 --- a/menu.cpp +++ b/menu.cpp @@ -38,24 +38,18 @@ along with this program. If not, see . #include "string.h" #include "file_io.h" #include "osd.h" -#include "minimig_fdd.h" -#include "minimig_hdd.h" #include "hardware.h" -#include "minimig_config.h" #include "menu.h" #include "user_io.h" -#include "st_tos.h" #include "debug.h" -#include "minimig_boot.h" -#include "archie.h" -#include "sharpmz.h" #include "fpga_io.h" #include #include "cfg.h" #include "input.h" -#include "x86.h" #include "battery.h" +#include "support.h" + /*menu states*/ enum MENU { diff --git a/osd.cpp b/osd.cpp index 8a99ad3..86c5597 100644 --- a/osd.cpp +++ b/osd.cpp @@ -45,7 +45,8 @@ as rotated copies of the first 128 entries. -- AMR #include "logo.h" #include "user_io.h" #include "hardware.h" -#include "minimig_config.h" + +#include "support.h" static int osd_size = 8; diff --git a/support.h b/support.h new file mode 100644 index 0000000..a0373ad --- /dev/null +++ b/support.h @@ -0,0 +1,18 @@ +// Minimig support +#include "support/minimig/minimig_config.h" +#include "support/minimig/minimig_boot.h" +#include "support/minimig/minimig_fdd.h" +#include "support/minimig/minimig_hdd.h" + +// SharpMz support +#include "support/sharpmz/sharpmz.h" + +// Archie support +#include "support/archie/archie.h" + +// ST (Atari) support +#include "support/st/st_ikbd.h" +#include "support/st/st_tos.h" + +// X86 support +#include "support/x86/x86.h" \ No newline at end of file diff --git a/archie.cpp b/support/archie/archie.cpp similarity index 99% rename from archie.cpp rename to support/archie/archie.cpp index bf206d2..3da5c6e 100644 --- a/archie.cpp +++ b/support/archie/archie.cpp @@ -1,11 +1,11 @@ #include "stdio.h" #include "string.h" -#include "hardware.h" -#include "fpga_io.h" -#include "menu.h" +#include "../../hardware.h" +#include "../../fpga_io.h" +#include "../../menu.h" #include "archie.h" -#include "debug.h" -#include "user_io.h" +#include "../../debug.h" +#include "../../user_io.h" #define MAX_FLOPPY 4 @@ -97,7 +97,7 @@ void archie_set_ar(char i) { if (i) config.system_ctrl |= 1; else config.system_ctrl &= ~1; - user_io_8bit_set_status((i ? -1 : 0), 2); + user_io_8bit_set_status((i ? -1 : 0), 2); } char archie_get_ar() @@ -108,7 +108,7 @@ char archie_get_ar() void archie_set_amix(char i) { config.system_ctrl = (config.system_ctrl & ~0b110) | ((i & 3)<<1); - user_io_8bit_set_status(config.system_ctrl << 1, 0b1100); + user_io_8bit_set_status(config.system_ctrl << 1, 0b1100); } char archie_get_amix() diff --git a/archie.h b/support/archie/archie.h similarity index 95% rename from archie.h rename to support/archie/archie.h index 72fd748..ef599fb 100644 --- a/archie.h +++ b/support/archie/archie.h @@ -1,7 +1,7 @@ #ifndef ARCHIE_H #define ARCHIE_H -#include "file_io.h" +#include "../../file_io.h" void archie_init(void); void archie_poll(void); diff --git a/minimig_boot.cpp b/support/minimig/minimig_boot.cpp similarity index 99% rename from minimig_boot.cpp rename to support/minimig/minimig_boot.cpp index 9c1cd73..5b7f3fb 100644 --- a/minimig_boot.cpp +++ b/support/minimig/minimig_boot.cpp @@ -6,13 +6,13 @@ #include "string.h" #include "stdio.h" #include "minimig_boot.h" -#include "hardware.h" -#include "osd.h" -#include "spi.h" -#include "file_io.h" +#include "../../hardware.h" +#include "../../osd.h" +#include "../../spi.h" +#include "../../file_io.h" #include "minimig_config.h" #include "minimig_fdd.h" -#include "cfg.h" +#include "../../cfg.h" static uint8_t buffer[1024]; diff --git a/minimig_boot.h b/support/minimig/minimig_boot.h similarity index 100% rename from minimig_boot.h rename to support/minimig/minimig_boot.h diff --git a/minimig_config.cpp b/support/minimig/minimig_config.cpp similarity index 98% rename from minimig_config.cpp rename to support/minimig/minimig_config.cpp index d6ac839..8751b1a 100644 --- a/minimig_config.cpp +++ b/support/minimig/minimig_config.cpp @@ -3,19 +3,19 @@ #include #include #include -#include -#include +#include +#include -#include "hardware.h" +#include "../../hardware.h" #include "minimig_boot.h" -#include "file_io.h" -#include "osd.h" +#include "../../file_io.h" +#include "../../osd.h" #include "minimig_fdd.h" #include "minimig_hdd.h" -#include "menu.h" +#include "../../menu.h" #include "minimig_config.h" -#include "user_io.h" -#include "input.h" +#include "../../user_io.h" +#include "../../input.h" typedef struct { @@ -237,30 +237,30 @@ static char UploadActionReplay() static char* GetConfigurationName(int num) { static char path[128]; - sprintf(path, "%s/%s", getRootDir(), CONFIG_DIR); + sprintf(path, "%s/%s", getRootDir(), CONFIG_DIR); - DIR *d; - struct dirent *dir; - d = opendir(path); - if (d) - { - if(num) sprintf(path, "minimig%d", num); - else sprintf(path, "minimig.cfg", num); - - while ((dir = readdir(d)) != NULL) - { - int len = strlen(dir->d_name); - if (len>10 && !strncasecmp(dir->d_name, path, strlen(path)) && !strcasecmp(dir->d_name+len-4, ".cfg")) - { - closedir(d); - strcpy(path, dir->d_name); - return path; - } - } - closedir(d); - } - - return NULL; + DIR *d; + struct dirent *dir; + d = opendir(path); + if (d) + { + if(num) sprintf(path, "minimig%d", num); + else sprintf(path, "minimig.cfg", num); + + while ((dir = readdir(d)) != NULL) + { + int len = strlen(dir->d_name); + if (len>10 && !strncasecmp(dir->d_name, path, strlen(path)) && !strcasecmp(dir->d_name+len-4, ".cfg")) + { + closedir(d); + strcpy(path, dir->d_name); + return path; + } + } + closedir(d); + } + + return NULL; } unsigned char SaveConfiguration(int num) @@ -324,8 +324,8 @@ static void ApplyConfiguration(char reloadkickstart) printf("Secondary Slave HDD is %s.\n", config.hardfile[3].enabled ? "enabled" : "disabled"); } - rstval = SPI_CPU_HLT; - spi_osd_cmd8(OSD_CMD_RST, rstval); + rstval = SPI_CPU_HLT; + spi_osd_cmd8(OSD_CMD_RST, rstval); spi_osd_cmd8(OSD_CMD_HDD, (config.enable_ide ? 1 : 0) | (OpenHardfile(0) ? 2 : 0) | (OpenHardfile(1) ? 4 : 0) | (OpenHardfile(2) ? 8 : 0) | (OpenHardfile(3) ? 16 : 0)); ConfigMemory(config.memory); @@ -340,7 +340,7 @@ static void ApplyConfiguration(char reloadkickstart) { printf("Reloading kickstart ...\n"); rstval |= (SPI_RST_CPU | SPI_CPU_HLT); - spi_osd_cmd8(OSD_CMD_RST, rstval); + spi_osd_cmd8(OSD_CMD_RST, rstval); if (!UploadKickstart(config.kickstart)) { strcpy(config.kickstart, "Amiga/KICK.ROM"); @@ -356,21 +356,21 @@ static void ApplyConfiguration(char reloadkickstart) } } rstval |= (SPI_RST_USR | SPI_RST_CPU); - spi_osd_cmd8(OSD_CMD_RST, rstval); + spi_osd_cmd8(OSD_CMD_RST, rstval); } else { printf("Resetting ...\n"); rstval |= (SPI_RST_USR | SPI_RST_CPU); - spi_osd_cmd8(OSD_CMD_RST, rstval); + spi_osd_cmd8(OSD_CMD_RST, rstval); } - rstval = 0; - spi_osd_cmd8(OSD_CMD_RST, rstval); + rstval = 0; + spi_osd_cmd8(OSD_CMD_RST, rstval); ConfigVideo(config.filter.hires, config.filter.lores, config.scanlines); ConfigAudio(config.audio); - ConfigAutofire(config.autofire, 0xC); + ConfigAutofire(config.autofire, 0xC); } unsigned char LoadConfiguration(int num) @@ -461,12 +461,12 @@ unsigned char LoadConfiguration(int num) updatekickstart = true; BootPrintEx(">>> No config found. Using defaults. <<<"); } - - for (int i = 0; i < 4; i++) - { - df[i].status = 0; - FileClose(&df[i].file); - } + + for (int i = 0; i < 4; i++) + { + df[i].status = 0; + FileClose(&df[i].file); + } // print config to boot screen char cfg_str[256]; @@ -494,17 +494,17 @@ unsigned char LoadConfiguration(int num) return(result); } -void MinimigReset() -{ - ApplyConfiguration(0); - user_io_rtc_reset(); -} - -void SetKickstart(char *name) -{ +void MinimigReset() +{ + ApplyConfiguration(0); + user_io_rtc_reset(); +} + +void SetKickstart(char *name) +{ int len = strlen(name); if (len > (sizeof(config.kickstart) - 1)) len = sizeof(config.kickstart) - 1; - memcpy(config.kickstart, name, len); - config.kickstart[len] = 0; - force_reload_kickstart = 1; -} + memcpy(config.kickstart, name, len); + config.kickstart[len] = 0; + force_reload_kickstart = 1; +} diff --git a/minimig_config.h b/support/minimig/minimig_config.h similarity index 97% rename from minimig_config.h rename to support/minimig/minimig_config.h index b94d187..d71d504 100644 --- a/minimig_config.h +++ b/support/minimig/minimig_config.h @@ -2,7 +2,7 @@ #ifndef __MINIMIG_CONFIG_H__ #define __MINIMIG_CONFIG_H__ -#include "file_io.h" +#include "../../file_io.h" typedef struct { @@ -48,6 +48,6 @@ unsigned char SaveConfiguration(int num); const char* GetConfigDisplayName(int num); void MinimigReset(); -void SetKickstart(char *name); +void SetKickstart(char *name); #endif diff --git a/minimig_fdd.cpp b/support/minimig/minimig_fdd.cpp similarity index 99% rename from minimig_fdd.cpp rename to support/minimig/minimig_fdd.cpp index 65a4298..22f0f08 100644 --- a/minimig_fdd.cpp +++ b/support/minimig/minimig_fdd.cpp @@ -25,13 +25,13 @@ along with this program. If not, see . #include #include -#include "hardware.h" -#include "file_io.h" +#include "../../hardware.h" +#include "../../file_io.h" #include "minimig_fdd.h" #include "minimig_config.h" -#include "debug.h" -#include "fpga_io.h" -#include "menu.h" +#include "../../debug.h" +#include "../../fpga_io.h" +#include "../../menu.h" unsigned char drives = 0; // number of active drives reported by FPGA (may change only during reset) adfTYPE *pdfx; // drive select pointer @@ -39,7 +39,7 @@ adfTYPE df[4] = { 0 }; // drive information structure static uint8_t sector_buffer[512]; -unsigned char Error; +unsigned char Error; #define TRACK_SIZE 12668 #define HEADER_SIZE 0x40 @@ -631,42 +631,42 @@ void HandleFDD(unsigned char c1, unsigned char c2) } } -// insert floppy image pointed to to by global into -void InsertFloppy(adfTYPE *drive, char* path) -{ - int writable = FileCanWrite(path); - - if (!FileOpenEx(&drive->file, path, writable ? O_RDWR | O_SYNC : O_RDONLY)) - { - return; - } - - unsigned char i, j; - unsigned long tracks; - - // calculate number of tracks in the ADF image file - tracks = drive->file.size / (512 * 11); - if (tracks > MAX_TRACKS) - { - menu_debugf("UNSUPPORTED ADF SIZE!!! Too many tracks: %lu\n", tracks); - tracks = MAX_TRACKS; - } - drive->tracks = (unsigned char)tracks; - - strcpy(drive->name, path); - - // initialize the rest of drive struct - drive->status = DSK_INSERTED; - if (writable) // read-only attribute - drive->status |= DSK_WRITABLE; - - drive->sector_offset = 0; - drive->track = 0; - drive->track_prev = -1; - - menu_debugf("Inserting floppy: \"%s\"\n", path); - menu_debugf("file writable: %d\n", writable); - menu_debugf("file size: %lu (%lu KB)\n", drive->file.size, drive->file.size >> 10); - menu_debugf("drive tracks: %u\n", drive->tracks); - menu_debugf("drive status: 0x%02X\n", drive->status); -} +// insert floppy image pointed to to by global into +void InsertFloppy(adfTYPE *drive, char* path) +{ + int writable = FileCanWrite(path); + + if (!FileOpenEx(&drive->file, path, writable ? O_RDWR | O_SYNC : O_RDONLY)) + { + return; + } + + unsigned char i, j; + unsigned long tracks; + + // calculate number of tracks in the ADF image file + tracks = drive->file.size / (512 * 11); + if (tracks > MAX_TRACKS) + { + menu_debugf("UNSUPPORTED ADF SIZE!!! Too many tracks: %lu\n", tracks); + tracks = MAX_TRACKS; + } + drive->tracks = (unsigned char)tracks; + + strcpy(drive->name, path); + + // initialize the rest of drive struct + drive->status = DSK_INSERTED; + if (writable) // read-only attribute + drive->status |= DSK_WRITABLE; + + drive->sector_offset = 0; + drive->track = 0; + drive->track_prev = -1; + + menu_debugf("Inserting floppy: \"%s\"\n", path); + menu_debugf("file writable: %d\n", writable); + menu_debugf("file size: %lu (%lu KB)\n", drive->file.size, drive->file.size >> 10); + menu_debugf("drive tracks: %u\n", drive->tracks); + menu_debugf("drive status: 0x%02X\n", drive->status); +} diff --git a/minimig_fdd.h b/support/minimig/minimig_fdd.h similarity index 96% rename from minimig_fdd.h rename to support/minimig/minimig_fdd.h index da9883b..1adce51 100644 --- a/minimig_fdd.h +++ b/support/minimig/minimig_fdd.h @@ -1,7 +1,7 @@ #ifndef __MINIMIG_FDD_H__ #define __MINIMIG_FDD_H__ -#include "file_io.h" +#include "../../file_io.h" // floppy disk interface defs #define CMD_RDTRK 0x01 @@ -24,8 +24,8 @@ typedef struct char name[1024]; /*floppy name*/ } adfTYPE; -extern unsigned char drives; -extern adfTYPE df[4]; +extern unsigned char drives; +extern adfTYPE df[4]; void UpdateDriveStatus(void); void HandleFDD(unsigned char c1, unsigned char c2); diff --git a/minimig_hdd.cpp b/support/minimig/minimig_hdd.cpp similarity index 99% rename from minimig_hdd.cpp rename to support/minimig/minimig_hdd.cpp index d6ca154..004dfdd 100644 --- a/minimig_hdd.cpp +++ b/support/minimig/minimig_hdd.cpp @@ -25,13 +25,13 @@ along with this program. If not, see . #include #include -#include "hardware.h" -#include "file_io.h" +#include "../../hardware.h" +#include "../../file_io.h" #include "minimig_hdd.h" -#include "menu.h" +#include "../../menu.h" #include "minimig_config.h" -#include "debug.h" -#include "fpga_io.h" +#include "../../debug.h" +#include "../../fpga_io.h" #define CMD_IDECMD 0x04 #define CMD_IDEDAT 0x08 @@ -86,32 +86,32 @@ static uint8_t sector_buffer[512]; static void CalcGeometry(hdfTYPE *hdf) { - uint32_t head, cyl, spt; - uint32_t sptt[] = { 63, 127, 255, 0 }; - uint32_t total = hdf->file.size / 512; - for (int i = 0; sptt[i] != 0; i++) - { - spt = sptt[i]; - for (head = 4; head <= 16; head++) - { - cyl = total / (head * spt); - if (total <= 1024 * 1024) - { - if (cyl <= 1023) break; - } - else - { - if (cyl < 16383) break; - if (cyl < 32767 && head >= 5) break; - if (cyl <= 65536) break; - } - } - if (head <= 16) break; - } - - hdf->cylinders = cyl; - hdf->heads = (uint16_t)head; - hdf->sectors = (uint16_t)spt; + uint32_t head, cyl, spt; + uint32_t sptt[] = { 63, 127, 255, 0 }; + uint32_t total = hdf->file.size / 512; + for (int i = 0; sptt[i] != 0; i++) + { + spt = sptt[i]; + for (head = 4; head <= 16; head++) + { + cyl = total / (head * spt); + if (total <= 1024 * 1024) + { + if (cyl <= 1023) break; + } + else + { + if (cyl < 16383) break; + if (cyl < 32767 && head >= 5) break; + if (cyl <= 65536) break; + } + } + if (head <= 16) break; + } + + hdf->cylinders = cyl; + hdf->heads = (uint16_t)head; + hdf->sectors = (uint16_t)spt; } static void GetRDBGeometry(hdfTYPE *hdf) @@ -133,7 +133,7 @@ static void GetRDBGeometry(hdfTYPE *hdf) printf(" DANGEROUS: Cannot translate to legal CHS values. Re-calculate the CHS.\n"); CalcGeometry(hdf); - } + } } static void SetHardfileGeometry(hdfTYPE *hdf, int isHDF) @@ -765,4 +765,4 @@ int checkHDF(const char* name, struct RigidDiskBlock **rdb) return 1; // non-HDF file } return 0; -} +} \ No newline at end of file diff --git a/minimig_hdd.h b/support/minimig/minimig_hdd.h similarity index 100% rename from minimig_hdd.h rename to support/minimig/minimig_hdd.h diff --git a/minimig_hdd_internal.h b/support/minimig/minimig_hdd_internal.h similarity index 100% rename from minimig_hdd_internal.h rename to support/minimig/minimig_hdd_internal.h diff --git a/sharpmz.cpp b/support/sharpmz/sharpmz.cpp similarity index 99% rename from sharpmz.cpp rename to support/sharpmz/sharpmz.cpp index 6930b31..c6bd362 100644 --- a/sharpmz.cpp +++ b/support/sharpmz/sharpmz.cpp @@ -33,13 +33,13 @@ #include "malloc.h" #include #include -#include "hardware.h" -#include "fpga_io.h" +#include "../../hardware.h" +#include "../../fpga_io.h" #include "sharpmz.h" -#include "osd.h" -#include "menu.h" -#include "debug.h" -#include "user_io.h" +#include "../../osd.h" +#include "../../menu.h" +#include "../../debug.h" +#include "../../user_io.h" #define sharpmz_debugf(a, ...) //#define sharpmz_debugf(a, ...) printf("\033[1;31mSHARPMZ: " a "\033[0m\n", ##__VA_ARGS__) diff --git a/sharpmz.h b/support/sharpmz/sharpmz.h similarity index 99% rename from sharpmz.h rename to support/sharpmz/sharpmz.h index 21dfa66..b7e1cf1 100644 --- a/sharpmz.h +++ b/support/sharpmz/sharpmz.h @@ -31,7 +31,7 @@ #ifndef SHARPMZ_H #define SHARPMZ_H -#include "file_io.h" +#include "../../file_io.h" // Defaults. // diff --git a/st_ikbd.cpp b/support/st/st_ikbd.cpp similarity index 99% rename from st_ikbd.cpp rename to support/st/st_ikbd.cpp index ab44543..2ad1f68 100644 --- a/st_ikbd.cpp +++ b/support/st/st_ikbd.cpp @@ -27,10 +27,10 @@ M1 tank platoon/A_385 fixed #include #include -#include "user_io.h" -#include "spi.h" +#include "../../user_io.h" +#include "../../spi.h" #include "st_ikbd.h" -#include "debug.h" +#include "../../debug.h" #define IKBD_AUTO_MS 20 diff --git a/st_ikbd.h b/support/st/st_ikbd.h similarity index 100% rename from st_ikbd.h rename to support/st/st_ikbd.h diff --git a/st_tos.cpp b/support/st/st_tos.cpp similarity index 95% rename from st_tos.cpp rename to support/st/st_tos.cpp index d8c9206..c0c5ea4 100644 --- a/st_tos.cpp +++ b/support/st/st_tos.cpp @@ -2,14 +2,14 @@ #include #include -#include "hardware.h" -#include "menu.h" +#include "../../hardware.h" +#include "../../menu.h" #include "st_tos.h" -#include "file_io.h" -#include "debug.h" -#include "user_io.h" +#include "../../file_io.h" +#include "../../debug.h" +#include "../../user_io.h" #include "st_ikbd.h" -#include "fpga_io.h" +#include "../../fpga_io.h" #define CONFIG_FILENAME "MIST.CFG" diff --git a/st_tos.h b/support/st/st_tos.h similarity index 99% rename from st_tos.h rename to support/st/st_tos.h index 21691b2..58b0323 100644 --- a/st_tos.h +++ b/support/st/st_tos.h @@ -1,7 +1,7 @@ #ifndef __ST_TOS_H__ #define __ST_TOS_H__ -#include "file_io.h" +#include "../../file_io.h" // FPGA spi cmommands #define MIST_INVALID 0x00 diff --git a/x86.cpp b/support/x86/x86.cpp similarity index 99% rename from x86.cpp rename to support/x86/x86.cpp index afbd7dd..aabb4a3 100644 --- a/x86.cpp +++ b/support/x86/x86.cpp @@ -24,18 +24,18 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -#include "spi.h" -#include "user_io.h" -#include "file_io.h" -#include "fpga_io.h" +#include "../../spi.h" +#include "../../user_io.h" +#include "../../file_io.h" +#include "../../fpga_io.h" #define ALT_CPU_CPU_FREQ 90000000u @@ -62,52 +62,52 @@ typedef struct static x86_config config; -static uint8_t dma_sdio(int status) -{ - uint8_t res; - EnableFpga(); - spi8(UIO_DMA_SDIO); - res = spi_w((uint16_t)status); - DisableFpga(); - return res; -} - -static uint32_t dma_get(uint32_t address) -{ - EnableFpga(); - spi8(UIO_DMA_READ); - spi32w(address); - uint32_t res = spi32w(0); - DisableFpga(); - return res; -} - -static void dma_set(uint32_t address, uint32_t data) -{ - EnableFpga(); - spi8(UIO_DMA_WRITE); - spi32w(address); - spi32w(data); - DisableFpga(); -} - -static void dma_sendbuf(uint32_t address, uint32_t length, uint32_t *data) -{ - EnableFpga(); - spi8(UIO_DMA_WRITE); - spi32w(address); - while (length--) spi32w(*data++); - DisableFpga(); -} +static uint8_t dma_sdio(int status) +{ + uint8_t res; + EnableFpga(); + spi8(UIO_DMA_SDIO); + res = spi_w((uint16_t)status); + DisableFpga(); + return res; +} -static void dma_rcvbuf(uint32_t address, uint32_t length, uint32_t *data) -{ - EnableFpga(); - spi8(UIO_DMA_READ); - spi32w(address); - while (length--) *data++ = spi32w(0); - DisableFpga(); -} +static uint32_t dma_get(uint32_t address) +{ + EnableFpga(); + spi8(UIO_DMA_READ); + spi32w(address); + uint32_t res = spi32w(0); + DisableFpga(); + return res; +} + +static void dma_set(uint32_t address, uint32_t data) +{ + EnableFpga(); + spi8(UIO_DMA_WRITE); + spi32w(address); + spi32w(data); + DisableFpga(); +} + +static void dma_sendbuf(uint32_t address, uint32_t length, uint32_t *data) +{ + EnableFpga(); + spi8(UIO_DMA_WRITE); + spi32w(address); + while (length--) spi32w(*data++); + DisableFpga(); +} + +static void dma_rcvbuf(uint32_t address, uint32_t length, uint32_t *data) +{ + EnableFpga(); + spi8(UIO_DMA_READ); + spi32w(address); + while (length--) *data++ = spi32w(0); + DisableFpga(); +} static int load_bios(const char* name, uint8_t index) { @@ -178,30 +178,30 @@ static __inline fileTYPE *get_image(uint32_t type) return &fdd_image1; } -static int img_mount(uint32_t type, char *name) -{ - FileClose(get_image(type)); - - int writable = FileCanWrite(name); - int ret = FileOpenEx(get_image(type), name, writable ? (O_RDWR | O_SYNC) : O_RDONLY); - if (!ret) - { - get_image(type)->size = 0; - printf("Failed to open file %s\n", name); - return 0; - } - - printf("Mount %s as %s\n", name, writable ? "read-write" : "read-only"); - return 1; -} +static int img_mount(uint32_t type, char *name) +{ + FileClose(get_image(type)); -static int img_read(uint32_t type, uint32_t lba, void *buf, uint32_t len) + int writable = FileCanWrite(name); + int ret = FileOpenEx(get_image(type), name, writable ? (O_RDWR | O_SYNC) : O_RDONLY); + if (!ret) + { + get_image(type)->size = 0; + printf("Failed to open file %s\n", name); + return 0; + } + + printf("Mount %s as %s\n", name, writable ? "read-write" : "read-only"); + return 1; +} + +static int img_read(uint32_t type, uint32_t lba, void *buf, uint32_t len) { if (!FileSeekLBA(get_image(type), lba)) return 0; return FileReadAdv(get_image(type), buf, len); } -static int img_write(uint32_t type, uint32_t lba, void *buf, uint32_t len) +static int img_write(uint32_t type, uint32_t lba, void *buf, uint32_t len) { if (!FileSeekLBA(get_image(type), lba)) return 0; return FileWriteAdv(get_image(type), buf, len); @@ -488,14 +488,14 @@ static int hdd_set(uint32_t num) return hdd[num].present; } -static uint8_t bin2bcd(unsigned val) -{ - return ((val / 10) << 4) + (val % 10); +static uint8_t bin2bcd(unsigned val) +{ + return ((val / 10) << 4) + (val % 10); } void x86_init() { - user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET); + user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET); load_bios("ao486/boot0.rom", 0); load_bios("ao486/boot1.rom", 1); @@ -532,7 +532,7 @@ void x86_init() //-------------------------------------------------------------------------- floppy fdd_set(config.fdd_name); - + //-------------------------------------------------------------------------- hdd hdd_set(0); @@ -551,8 +551,8 @@ void x86_init() unsigned char translate_mode = 1; //LBA translate_mode = (translate_mode << 6) | (translate_mode << 4) | (translate_mode << 2) | translate_mode; - time_t t = time(NULL); - struct tm tm = *localtime(&t); + time_t t = time(NULL); + struct tm tm = *localtime(&t); //rtc contents 0-127 uint32_t tmp[128] = { @@ -650,8 +650,8 @@ void x86_init() cmos[0x2F] = sum & 0xFF; for(unsigned int i=0; itag, "colourisation")) - { - in_border = 0; - in_color = 0; - in_bright = 0; - in_entry = 0; - in_line = 0; - in_paper = 0; - in_ink = 0; - } - - if (!strcasecmp(node->tag, "border")) in_border = 1; - if (!strcasecmp(node->tag, "colour")) in_color = 1; - if (!strcasecmp(node->tag, "bright")) in_bright = 1; - - if (!strcasecmp(node->tag, "entry")) - { - int ncode = -1; - int ncnt = -1; - for (int i = 0; i < node->n_attributes; i++) - { - if (!strcasecmp(node->attributes[i].name, "code")) ncode = atoi(node->attributes[i].value); - if (!strcasecmp(node->attributes[i].name, "quantity")) ncnt = atoi(node->attributes[i].value); - } - - in_entry = 0; - if (ncode >= 0 && ncode <= 127) - { - start = ncode; - if (ncnt < 1) ncnt = 1; - end = start + ncnt; - if (end > 128) end = 128; - memset(tmp, 0, sizeof(tmp)); - in_entry = 1; - } - } - - if (!strcasecmp(node->tag, "line")) - { - int nline = -1; - for (int i = 0; i < node->n_attributes; i++) - { - if (!strcasecmp(node->attributes[i].name, "index")) nline = atoi(node->attributes[i].value); - } - - in_line = 0; - if (nline >= 0 && nline <= 7) - { - line = nline; - if (in_entry) tmp[line] = 0; - in_line = 1; - } - } - - if (!strcasecmp(node->tag, "paper")) in_paper = 1; - if (!strcasecmp(node->tag, "ink")) in_ink = 1; - break; - - case XML_EVENT_END_NODE: - if (!strcasecmp(node->tag, "border")) in_border = 0; - if (!strcasecmp(node->tag, "colour")) in_color = 0; - if (!strcasecmp(node->tag, "bright")) in_bright = 0; - if (!strcasecmp(node->tag, "line")) in_line = 0; - if (!strcasecmp(node->tag, "paper")) in_paper = 0; - if (!strcasecmp(node->tag, "ink")) in_ink = 0; - if (!strcasecmp(node->tag, "entry")) - { - if (in_entry) - { - for (int i = start; i < end; i++) memcpy(&col_attr[i * 8], tmp, 8); - } - in_entry = 0; - } - break; - - case XML_EVENT_TEXT: - if (in_border && in_color) col_attr[1024] = (char)((col_attr[1024] & 8) | (atoi(text) & 7)); - if (in_border && in_bright) col_attr[1024] = (char)((col_attr[1024] & 7) | ((atoi(text) & 1) << 3)); - - if (in_entry && in_line && in_ink && in_color) tmp[line] = (char)((tmp[line] & 0xF8) | (atoi(text) & 7)); - if (in_entry && in_line && in_ink && in_bright) tmp[line] = (char)((tmp[line] & 0xF7) | ((atoi(text) & 1) << 3)); - if (in_entry && in_line && in_paper && in_color) tmp[line] = (char)((tmp[line] & 0x8F) | ((atoi(text) & 7) << 4)); - if (in_entry && in_line && in_paper && in_bright) tmp[line] = (char)((tmp[line] & 0x7F) | ((atoi(text) & 1) << 7)); - break; - - case XML_EVENT_ERROR: - printf("XML parse: %s: ERROR %d\n", text, n); - break; - default: - break; - } - - return true; -} +static unsigned char col_attr[1025]; +static int col_parse(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const int n, SAX_Data* sd) +{ + static int in_border = 0; + static int in_color = 0; + static int in_bright = 0; + static int in_entry = 0; + static int in_line = 0; + static int in_paper = 0; + static int in_ink = 0; + static int end = 0; + static int start = 0; + static int line = 0; + + static char tmp[8]; + + switch (evt) + { + case XML_EVENT_START_NODE: + if (!strcasecmp(node->tag, "colourisation")) + { + in_border = 0; + in_color = 0; + in_bright = 0; + in_entry = 0; + in_line = 0; + in_paper = 0; + in_ink = 0; + } + + if (!strcasecmp(node->tag, "border")) in_border = 1; + if (!strcasecmp(node->tag, "colour")) in_color = 1; + if (!strcasecmp(node->tag, "bright")) in_bright = 1; + + if (!strcasecmp(node->tag, "entry")) + { + int ncode = -1; + int ncnt = -1; + for (int i = 0; i < node->n_attributes; i++) + { + if (!strcasecmp(node->attributes[i].name, "code")) ncode = atoi(node->attributes[i].value); + if (!strcasecmp(node->attributes[i].name, "quantity")) ncnt = atoi(node->attributes[i].value); + } + + in_entry = 0; + if (ncode >= 0 && ncode <= 127) + { + start = ncode; + if (ncnt < 1) ncnt = 1; + end = start + ncnt; + if (end > 128) end = 128; + memset(tmp, 0, sizeof(tmp)); + in_entry = 1; + } + } + + if (!strcasecmp(node->tag, "line")) + { + int nline = -1; + for (int i = 0; i < node->n_attributes; i++) + { + if (!strcasecmp(node->attributes[i].name, "index")) nline = atoi(node->attributes[i].value); + } + + in_line = 0; + if (nline >= 0 && nline <= 7) + { + line = nline; + if (in_entry) tmp[line] = 0; + in_line = 1; + } + } + + if (!strcasecmp(node->tag, "paper")) in_paper = 1; + if (!strcasecmp(node->tag, "ink")) in_ink = 1; + break; + + case XML_EVENT_END_NODE: + if (!strcasecmp(node->tag, "border")) in_border = 0; + if (!strcasecmp(node->tag, "colour")) in_color = 0; + if (!strcasecmp(node->tag, "bright")) in_bright = 0; + if (!strcasecmp(node->tag, "line")) in_line = 0; + if (!strcasecmp(node->tag, "paper")) in_paper = 0; + if (!strcasecmp(node->tag, "ink")) in_ink = 0; + if (!strcasecmp(node->tag, "entry")) + { + if (in_entry) + { + for (int i = start; i < end; i++) memcpy(&col_attr[i * 8], tmp, 8); + } + in_entry = 0; + } + break; + + case XML_EVENT_TEXT: + if (in_border && in_color) col_attr[1024] = (char)((col_attr[1024] & 8) | (atoi(text) & 7)); + if (in_border && in_bright) col_attr[1024] = (char)((col_attr[1024] & 7) | ((atoi(text) & 1) << 3)); + + if (in_entry && in_line && in_ink && in_color) tmp[line] = (char)((tmp[line] & 0xF8) | (atoi(text) & 7)); + if (in_entry && in_line && in_ink && in_bright) tmp[line] = (char)((tmp[line] & 0xF7) | ((atoi(text) & 1) << 3)); + if (in_entry && in_line && in_paper && in_color) tmp[line] = (char)((tmp[line] & 0x8F) | ((atoi(text) & 7) << 4)); + if (in_entry && in_line && in_paper && in_bright) tmp[line] = (char)((tmp[line] & 0x7F) | ((atoi(text) & 1) << 7)); + break; + + case XML_EVENT_ERROR: + printf("XML parse: %s: ERROR %d\n", text, n); + break; + default: + break; + } + + return true; +} static const unsigned char defchars[512] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, - 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, - 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, - 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0xAA, 0x55, 0xAA, 0x55, - 0xAA, 0x55, 0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1C, 0x22, 0x78, 0x20, 0x20, 0x7E, 0x00, 0x00, 0x08, 0x3E, 0x28, 0x3E, 0x0A, 0x3E, 0x08, - 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x3C, 0x42, 0x04, 0x08, 0x00, 0x08, 0x00, - 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x04, 0x00, 0x00, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00, - 0x00, 0x00, 0x10, 0x08, 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x08, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, 0x00, - 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, - 0x00, 0x3C, 0x46, 0x4A, 0x52, 0x62, 0x3C, 0x00, 0x00, 0x18, 0x28, 0x08, 0x08, 0x08, 0x3E, 0x00, - 0x00, 0x3C, 0x42, 0x02, 0x3C, 0x40, 0x7E, 0x00, 0x00, 0x3C, 0x42, 0x0C, 0x02, 0x42, 0x3C, 0x00, - 0x00, 0x08, 0x18, 0x28, 0x48, 0x7E, 0x08, 0x00, 0x00, 0x7E, 0x40, 0x7C, 0x02, 0x42, 0x3C, 0x00, - 0x00, 0x3C, 0x40, 0x7C, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x7E, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00, - 0x00, 0x3C, 0x42, 0x3C, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x3E, 0x02, 0x3C, 0x00, - 0x00, 0x3C, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x00, 0x00, 0x7C, 0x42, 0x7C, 0x42, 0x42, 0x7C, 0x00, - 0x00, 0x3C, 0x42, 0x40, 0x40, 0x42, 0x3C, 0x00, 0x00, 0x78, 0x44, 0x42, 0x42, 0x44, 0x78, 0x00, - 0x00, 0x7E, 0x40, 0x7C, 0x40, 0x40, 0x7E, 0x00, 0x00, 0x7E, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x00, - 0x00, 0x3C, 0x42, 0x40, 0x4E, 0x42, 0x3C, 0x00, 0x00, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x00, - 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00, 0x02, 0x02, 0x02, 0x42, 0x42, 0x3C, 0x00, - 0x00, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00, - 0x00, 0x42, 0x66, 0x5A, 0x42, 0x42, 0x42, 0x00, 0x00, 0x42, 0x62, 0x52, 0x4A, 0x46, 0x42, 0x00, - 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x7C, 0x40, 0x40, 0x00, - 0x00, 0x3C, 0x42, 0x42, 0x52, 0x4A, 0x3C, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x7C, 0x44, 0x42, 0x00, - 0x00, 0x3C, 0x40, 0x3C, 0x02, 0x42, 0x3C, 0x00, 0x00, 0xFE, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, - 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, - 0x00, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x24, 0x00, 0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00, - 0x00, 0x82, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00, 0x00, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x7E, 0x00 -}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, + 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0xAA, 0x55, 0xAA, 0x55, + 0xAA, 0x55, 0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1C, 0x22, 0x78, 0x20, 0x20, 0x7E, 0x00, 0x00, 0x08, 0x3E, 0x28, 0x3E, 0x0A, 0x3E, 0x08, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x3C, 0x42, 0x04, 0x08, 0x00, 0x08, 0x00, + 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x04, 0x00, 0x00, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00, + 0x00, 0x00, 0x10, 0x08, 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x08, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, 0x00, + 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, + 0x00, 0x3C, 0x46, 0x4A, 0x52, 0x62, 0x3C, 0x00, 0x00, 0x18, 0x28, 0x08, 0x08, 0x08, 0x3E, 0x00, + 0x00, 0x3C, 0x42, 0x02, 0x3C, 0x40, 0x7E, 0x00, 0x00, 0x3C, 0x42, 0x0C, 0x02, 0x42, 0x3C, 0x00, + 0x00, 0x08, 0x18, 0x28, 0x48, 0x7E, 0x08, 0x00, 0x00, 0x7E, 0x40, 0x7C, 0x02, 0x42, 0x3C, 0x00, + 0x00, 0x3C, 0x40, 0x7C, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x7E, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00, + 0x00, 0x3C, 0x42, 0x3C, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x3E, 0x02, 0x3C, 0x00, + 0x00, 0x3C, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x00, 0x00, 0x7C, 0x42, 0x7C, 0x42, 0x42, 0x7C, 0x00, + 0x00, 0x3C, 0x42, 0x40, 0x40, 0x42, 0x3C, 0x00, 0x00, 0x78, 0x44, 0x42, 0x42, 0x44, 0x78, 0x00, + 0x00, 0x7E, 0x40, 0x7C, 0x40, 0x40, 0x7E, 0x00, 0x00, 0x7E, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x00, + 0x00, 0x3C, 0x42, 0x40, 0x4E, 0x42, 0x3C, 0x00, 0x00, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x00, + 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00, 0x02, 0x02, 0x02, 0x42, 0x42, 0x3C, 0x00, + 0x00, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00, + 0x00, 0x42, 0x66, 0x5A, 0x42, 0x42, 0x42, 0x00, 0x00, 0x42, 0x62, 0x52, 0x4A, 0x46, 0x42, 0x00, + 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x7C, 0x40, 0x40, 0x00, + 0x00, 0x3C, 0x42, 0x42, 0x52, 0x4A, 0x3C, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x7C, 0x44, 0x42, 0x00, + 0x00, 0x3C, 0x40, 0x3C, 0x02, 0x42, 0x3C, 0x00, 0x00, 0xFE, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, + 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, + 0x00, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x24, 0x00, 0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00, + 0x00, 0x82, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00, 0x00, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x7E, 0x00 +}; -static int chr_parse(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const int n, SAX_Data* sd) -{ - static int in_entry = 0; - static int in_line = 0; - static int code = 0; - static int line = 0; - - switch (evt) - { - case XML_EVENT_START_NODE: - if (!strcasecmp(node->tag, "definition")) - { - in_entry = 0; - in_line = 0; - code = 0; - line = 0; - } - - if (!strcasecmp(node->tag, "entry")) - { - int ncode = -1; - for (int i = 0; i < node->n_attributes; i++) - { - if (!strcasecmp(node->attributes[i].name, "code")) ncode = atoi(node->attributes[i].value); - } - - in_entry = 0; - if (ncode >= 0 && ncode <= 63) - { - code = ncode; - in_entry = 1; - } - - if (ncode >= 128 && ncode <= 191) - { - code = ncode - 64; - in_entry = 1; - } - } - - if (!strcasecmp(node->tag, "line")) - { - int nline = -1; - for (int i = 0; i < node->n_attributes; i++) - { - if (!strcasecmp(node->attributes[i].name, "index")) nline = atoi(node->attributes[i].value); - } - - in_line = 0; - if (nline >= 0 && nline <= 7) - { - line = nline; - in_line = 1; - } - } - break; - - case XML_EVENT_END_NODE: - if (!strcasecmp(node->tag, "line")) in_line = 0; - if (!strcasecmp(node->tag, "entry")) in_entry = 0; - break; - - case XML_EVENT_TEXT: - if (in_entry && in_line) - { - unsigned char tmp = 0; - if (strlen(text) >= 8) - { - for (int i = 0; i < 8; i++) tmp = (tmp << 1) | ((text[i] == '1') ? 1 : 0); - if (code >= 64) tmp = ~tmp; - } - col_attr[code * 8 + line] = tmp; - in_line = 0; - } - break; - - case XML_EVENT_ERROR: - printf("XML parse: %s: ERROR %d\n", text, n); - break; - default: - break; - } - - return true; +static int chr_parse(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const int n, SAX_Data* sd) +{ + static int in_entry = 0; + static int in_line = 0; + static int code = 0; + static int line = 0; + + switch (evt) + { + case XML_EVENT_START_NODE: + if (!strcasecmp(node->tag, "definition")) + { + in_entry = 0; + in_line = 0; + code = 0; + line = 0; + } + + if (!strcasecmp(node->tag, "entry")) + { + int ncode = -1; + for (int i = 0; i < node->n_attributes; i++) + { + if (!strcasecmp(node->attributes[i].name, "code")) ncode = atoi(node->attributes[i].value); + } + + in_entry = 0; + if (ncode >= 0 && ncode <= 63) + { + code = ncode; + in_entry = 1; + } + + if (ncode >= 128 && ncode <= 191) + { + code = ncode - 64; + in_entry = 1; + } + } + + if (!strcasecmp(node->tag, "line")) + { + int nline = -1; + for (int i = 0; i < node->n_attributes; i++) + { + if (!strcasecmp(node->attributes[i].name, "index")) nline = atoi(node->attributes[i].value); + } + + in_line = 0; + if (nline >= 0 && nline <= 7) + { + line = nline; + in_line = 1; + } + } + break; + + case XML_EVENT_END_NODE: + if (!strcasecmp(node->tag, "line")) in_line = 0; + if (!strcasecmp(node->tag, "entry")) in_entry = 0; + break; + + case XML_EVENT_TEXT: + if (in_entry && in_line) + { + unsigned char tmp = 0; + if (strlen(text) >= 8) + { + for (int i = 0; i < 8; i++) tmp = (tmp << 1) | ((text[i] == '1') ? 1 : 0); + if (code >= 64) tmp = ~tmp; + } + col_attr[code * 8 + line] = tmp; + in_line = 0; + } + break; + + case XML_EVENT_ERROR: + printf("XML parse: %s: ERROR %d\n", text, n); + break; + default: + break; + } + + return true; } static void send_pcolchr(const char* name, unsigned char index, int type) { static char full_path[1024]; - - sprintf(full_path, "%s/%s", getRootDir(), name); + + sprintf(full_path, "%s/%s", getRootDir(), name); char *p = strrchr(full_path, '.'); if (!p) p = full_path + strlen(full_path); strcpy(p, type ? ".chr" : ".col"); - - if (type) - { - memcpy(col_attr, defchars, sizeof(defchars)); - memcpy(col_attr+sizeof(defchars), defchars, sizeof(defchars)); - } - else memset(col_attr, 0, sizeof(col_attr)); + + if (type) + { + memcpy(col_attr, defchars, sizeof(defchars)); + memcpy(col_attr+sizeof(defchars), defchars, sizeof(defchars)); + } + else memset(col_attr, 0, sizeof(col_attr)); - SAX_Callbacks sax; - SAX_Callbacks_init(&sax); - sax.all_event = type ? chr_parse : col_parse; - if (XMLDoc_parse_file_SAX(full_path, &sax, 0)) - { - printf("Send additional file %s\n", full_path); + SAX_Callbacks sax; + SAX_Callbacks_init(&sax); + sax.all_event = type ? chr_parse : col_parse; + if (XMLDoc_parse_file_SAX(full_path, &sax, 0)) + { + printf("Send additional file %s\n", full_path); //hexdump(col_attr, sizeof(col_attr)); @@ -1196,7 +1189,7 @@ static void send_pcolchr(const char* name, unsigned char index, int type) spi8(UIO_FILE_TX); spi8(0x00); DisableFpga(); - } + } } int user_io_file_tx(const char* name, unsigned char index, char opensave, char mute, char composite) @@ -1211,12 +1204,12 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m if (composite) { if (!FileReadSec(&f, buf)) return 0; - if (memcmp(buf, "MiSTer", 6)) return 0; - - uint32_t off = 16 + *(uint32_t*)(((uint8_t*)buf) + 12); - bytes2send -= off; - - FileSeek(&f, off, SEEK_SET); + if (memcmp(buf, "MiSTer", 6)) return 0; + + uint32_t off = 16 + *(uint32_t*)(((uint8_t*)buf) + 12); + bytes2send -= off; + + FileSeek(&f, off, SEEK_SET); } /* transmit the entire file using one transfer */ @@ -1587,19 +1580,19 @@ void user_io_poll() */ static u_int8_t last_status_change = 0; - char stchg = spi_uio_cmd_cont(UIO_GET_STATUS); - if ((stchg & 0xF0) == 0xA0 && last_status_change != (stchg & 0xF)) - { - last_status_change = (stchg & 0xF); - uint32_t st = spi32w(0); - DisableIO(); + char stchg = spi_uio_cmd_cont(UIO_GET_STATUS); + if ((stchg & 0xF0) == 0xA0 && last_status_change != (stchg & 0xF)) + { + last_status_change = (stchg & 0xF); + uint32_t st = spi32w(0); + DisableIO(); user_io_8bit_set_status(st, ~UIO_STATUS_RESET); //printf("** new status from core: %08X\n", st); - } - else - { - DisableIO(); - } + } + else + { + DisableIO(); + } // sd card emulation if (is_x86_core())