Skip to content

Commit

Permalink
Parse ZX81 Chroma interface COL and CHR files
Browse files Browse the repository at this point in the history
...using sxmlc as the XML parser
  • Loading branch information
gyurco committed Nov 2, 2024
1 parent eb571c5 commit 180c34f
Show file tree
Hide file tree
Showing 12 changed files with 4,257 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 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
Expand Down
5 changes: 3 additions & 2 deletions Makefile.SAMV71
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ 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 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 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
SRC += usb/usb.c usb/max3421e.c usb/usb-max3421e.c
Expand All @@ -30,7 +31,7 @@ LIBDIR =
# Commandline options for each tool.
# for ESA11 add -DEMIST
DFLAGS = -I. -Iarch -Icmsis -Iusb -Ihw/ATSAMV71 -D_GNU_SOURCE -DMIST -DCONFIG_HAVE_NVIC -DCONFIG_HAVE_ETH -DCONFIG_HAVE_GMAC -DCONFIG_HAVE_GMAC_QUEUES -DGMAC_QUEUE_COUNT=6 -DCONFIG_ARCH_ARM -DCONFIG_ARCH_ARMV7M -DCONFIG_CHIP_SAMV71 -DCONFIG_PACKAGE_100PIN
DFLAGS += -DFW_ID=\"SIDIUPG\" -DSZ_TBL=2048 -DDEFAULT_CORE_NAME=\"SIDI128.RBF\" -DFATFS_NO_TINY -DSD_NO_DIRECT_MODE -DJOY_DB9_MD -DHAVE_QSPI -DHAVE_HDMI -DHAVE_PSX -DUSB_STORAGE
DFLAGS += -DFW_ID=\"SIDIUPG\" -DSZ_TBL=2048 -DDEFAULT_CORE_NAME=\"SIDI128.RBF\" -DFATFS_NO_TINY -DSD_NO_DIRECT_MODE -DJOY_DB9_MD -DHAVE_QSPI -DHAVE_HDMI -DHAVE_PSX -DHAVE_XML -DUSB_STORAGE
#DFLAGS += -DPROTOTYPE
CFLAGS = $(DFLAGS) -march=armv7-m -mtune=cortex-m7 -mthumb -ffunction-sections -fsigned-char -c -O2 --std=gnu99 -DVDATE=\"`date +"%y%m%d"`\"
CFLAGS += $(CFLAGS-$@)
Expand Down
2 changes: 1 addition & 1 deletion data_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void data_io_file_tx_done(void) {
// TRANSMIT FILE TO FPGA //
///////////////////////////

static void data_io_file_tx_prepare(FIL *file, char index, const char *ext) {
void data_io_file_tx_prepare(FIL *file, char index, const char *ext) {
char e[3];
iprintf("Preparing transmission for index %d\n", index);

Expand Down
1 change: 1 addition & 0 deletions data_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define DIO_FILE_RX 0x57
#define DIO_FILE_RX_DAT 0x58

void data_io_file_tx_prepare(FIL *file, char index, const char *ext);
void data_io_set_index(char index);
void data_io_file_tx_start();
void data_io_file_tx_done();
Expand Down
40 changes: 32 additions & 8 deletions menu-8bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "fat_compat.h"
#include "cue_parser.h"
#include "snes.h"
#include "zx_col.h"

extern char s[FF_LFN_BUF + 1];

Expand All @@ -39,9 +40,10 @@ extern char fs_pFileExt[13];
//////////////////////////
/////// 8-bit menu ///////
//////////////////////////
static unsigned char selected_drive_slot;
static unsigned char isSnesROM;
typedef enum _RomType {ROM_NORMAL, ROM_SNES, ROM_ZXCOL, ROM_ZXCHR} RomType;

static unsigned char selected_drive_slot;
static RomType romtype;

static void substrcpy(char *d, char *s, char idx) {
char p = 0;
Expand Down Expand Up @@ -118,11 +120,31 @@ static unsigned long long getStatusMask(char *opt) {

static char RomFileSelected(uint8_t idx, const char *SelectedName) {
FIL file;
char snes_romtype;
char ext_idx = user_io_ext_idx(SelectedName, fs_pFileExt);

// this assumes that further file entries only exist if the first one also exists
if (f_open(&file, SelectedName, FA_READ) == FR_OK) {
if (isSnesROM) snes_romtype = snes_getromtype(&file);
data_io_file_tx(&file, (isSnesROM ? snes_romtype : user_io_ext_idx(SelectedName, fs_pFileExt))<<6 | selected_drive_slot, GetExtension(SelectedName));
if (romtype == ROM_ZXCOL || romtype == ROM_ZXCHR) {
if (romtype == ROM_ZXCOL && !zx_col_load(&file, sector_buffer)) {
ErrorMessage("\n Error parsing COL file!\n", 0);
f_close(&file);
return 0;
} else if (romtype == ROM_ZXCHR && !zx_chr_load(&file, sector_buffer)) {
ErrorMessage("\n Error parsing CHR file!\n", 0);
f_close(&file);
return 0;
} else {
data_io_file_tx_prepare(&file, ext_idx << 6 | selected_drive_slot, GetExtension(SelectedName));
EnableFpga();
SPI(DIO_FILE_TX_DAT);
spi_write(sector_buffer, 1024+(romtype == ROM_ZXCOL ? 1 : 0));
DisableFpga();
data_io_file_tx_done();
}
} 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);
}
// close menu afterwards
Expand Down Expand Up @@ -196,7 +218,7 @@ static char GetMenuItem_8bit(uint8_t idx, char action, menu_item_t *item) {
strncpy(ext, p, 13);
while(strlen(ext) < 3) strcat(ext, " ");
selected_drive_slot = 1;
isSnesROM = 0;
romtype = ROM_NORMAL;
SelectFileNG(ext, SCAN_DIR | SCAN_LFN, RomFileSelected, 1);
} else if (action == MENU_ACT_GET) {
//menumask = 1;
Expand Down Expand Up @@ -249,8 +271,10 @@ static char GetMenuItem_8bit(uint8_t idx, char action, menu_item_t *item) {
iscue = 1;
}
if (p[1]>='0' && p[1]<='9') selected_drive_slot = p[1]-'0';
isSnesROM = 0;
if (p[1] && p[1] != ',' && p[2] && p[2] != ',' && !strncmp(&p[2], "SNES", 4)) isSnesROM = 1; // F1SNES
romtype = ROM_NORMAL;
if (p[1] && p[1] != ',' && p[2] && p[2] != ',' && !strncmp(&p[2], "SNES", 4)) romtype = ROM_SNES; // F1SNES
if (p[1] && p[1] != ',' && p[2] && p[2] != ',' && !strncmp(&p[2], "ZXCOL", 5)) romtype = ROM_ZXCOL; // F2ZXCOL
if (p[1] && p[1] != ',' && p[2] && p[2] != ',' && !strncmp(&p[2], "ZXCHR", 5)) romtype = ROM_ZXCHR; // F3ZXCHR
substrcpy(ext, p, 1);
while(strlen(ext) < 3) strcat(ext, " ");
SelectFileNG(ext, SCAN_DIR | SCAN_LFN, (p[0] == 'F')?RomFileSelected:iscue?CueFileSelected:ImageFileSelected, 1);
Expand Down
161 changes: 161 additions & 0 deletions sxmlc/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
*** v4.5.4 - Corrected memory leak if text contained HTML-escaped characters (thanks @hakker_de!).

*** v4.5.3 - Corrected write on NULL for not-XML files (thanks @bladchan!).
- Added NULL check when reading BOM.

*** v4.5.2 - Corrected buffer overrun on unhtml() (thanks @gvollant!).
- Changed true/false to uppercase (MS Visual Studio).
- Added some first) specifics for MS Visual Studio complaints.

*** v4.5.1 - Added missing free() in XMLSearch_free() (thanks @yogibe4r!).

*** v4.5.0 - HTML decoding on node text.
- Corrected uninitialized BOM size in XMLDOC_init().

*** v4.4.0 - Added UTF-8 support (many thanks to Todd Osborne!).

*** v4.3.4 - Test for i_root validity in macro XMLDoc_root.

*** v4.3.3 - Added Sourceforge#12 by Alexander Goomenyuk (expose data source context to user).
- Added search unitest.

*** v4.3.2 - Fixed GitHub#11 by Dami�n M. Gonz�lez (missing free() on XMLNode_set_text()).
- Doxygen documentation update.
- Correction of CHECK_NODE macro that returned false on valid nodes!

*** v4.3.1 - Correction on XMLNode_get_index().
- Doxygen documentation.

*** v4.3.0 - Added Github#9: "Support for XMLNode_add_sibling()".
- Documentation update.
- Rudimentary unit testing.

*** v4.2.7 - Fixed #20 by Richard Minner (SXMLC_VERSION not updated), #21, #22 by George Makarov (sx_f* consistency).

*** v4.2.6 - Fixed #17, #18, #19 by Andreas Neustifter (infinite loop and compilation messages).

*** v4.2.5 - Some compilation messages corrections by cosminginerica.

*** v4.2.4 - Correction on reading non-quoted attribute values, now returns proper TAG_SELF to SAX callbacks.
- Added XMLNode_get_attribute_count().

*** v4.2.3 - Some corrections by Cliff Baumann.

*** v4.2.2 - Corrected uninitialized alloc (thanks Harry Sintonen) and memory leak (thanks Cliff Baumann).

*** v4.2.1 - Better handling of XML escapable characters.
- str2html() can allocate output buffer is NULL is given.

*** v4.2.0 - Many bug corrections (memory-related, error checks, consistency. Many many thanks to Harry Sintonen!!!)

*** v4.1.2 - Fixed problem in char casting during line read(Thanks to Nicholai Benalal!).

*** v4.1.1 - Fixed single attribute search init from XPath(Thanks to Nicholai Benalal!).

*** v4.1.0 - Thanks to Olgierd Stankiewicz!
- Added support for sparse text in nodes.
- Added attribute separator for XML print.
- Corrected missing +1 in attribute value char allocation.
- Changed constant name 'MAX_PATH' to 'SXMLC_MAX_PATH' to prevent potential conflicts with OS includes.

*** v4.0.10 - Corrected backslash were not allowed in values (Thanks to J�rg Singendonk ([email protected])!).
- Corrected root node was not set when it is a "self-contained" node.

*** v4.0.9 - Corrected SAX callbacks return value not taken into account (Thanks to Logan ([email protected])!).

*** v4.0.8 - Corrected potential bad free during initialization of search from XPath (Cnacu6o to Sergey ([email protected])!).
- Set search attribute value to NULL when no '=' is given.
- Removed #include "sxmlutils.h" not needed anymore.

*** v4.0.7 - Corrected possible segfault during initialization of search from XPath (Cnacu6o to Sergey ([email protected])!).

*** v4.0.6 - Merged sxmlutils.c into sxmlc.c.
- Corrected test when re-opening the file as text could be used before being NULL-tested.

*** v4.0.5 - Corrected bug #6: XMLNode_equal was not testing attribute value (thanks to Carmel (@lablabla))
- Finished code reformatting

*** v4.0.4 - Corrected #end instead of #endif

*** v4.0.3 - Updated license to BSD
- Corrected bug #4: mis-initialization in XML search struct (thanks to Carmel (@lablabla))
- Corrected bug #5: infinite loop in sx_strdup with DBG_MEM defined (thanks to Carmel (@lablabla))
- Reformatted code (unfinished)

*** v4.0.2 - Updated license to LGPL v2.1 (mistakenly LGPL v3)

*** v4.0.1 - Corrections/Suggestions given by Pete (@bothap)
- Corrected coredump when memory not initialised after malloc when init_value happens to contain XML_INIT_DONE.
- Corrected memory leak in DOM parser when 'dom->current->text' alrady contained text.
- Renamed 'utils.*' to 'sxmlutils.*'.
- Removed automatic freeing of 'XMLNode' and 'XMLDoc' (documented in 'datastruct.html').
- Enclosed BOM zeroing into '#ifdef SXMLC_UNICODE' in 'XMLNode_init'.
- Added functions 'XMLNode_get_attribute*' to retrieve an attribute value based on its name.

*** v4.0.0
- Unicode handling through SXMLC_UNICODE define (Use -DSXMLC_UNICODE when compiling).
- Use 'sx_*' functions to manipulate strings, and C2SX() macro around constant strings and characters to provide portable code for Unicode/non-Unicode compilation.
- Added 'NULC' and 'CEOF' constants as nul and EOF characters, according to SXMLC_UNICODE define.
- Removed parameter 'protect' in function 'strip_spaces' (forced to backslash).

*** v3.5.1
- Minor corrections in comments.
- 'XMLDoc_parse_file' is now a macro.
- 'XMLNode_print' takes less parameters (no more 'depth') and can be used in thread (no more static variables). Sub-functions were added.
- New function 'XMLNode_print_header' which print only the "header" part (i.e. no text or children).
- Correction in HowTo

*** v3.5.0
- Corrected memory leak in 'XMLDoc_free' when children nodes pointers were not freed
- Corrected CDATA tag end (!)
- Added macros to ease memory debugging (define DBG_MEM constant)
- Added parameters to 'XMLNode_remove_child' and 'XMLDoc_remove_node' to allow for freeing child/node pointer itself
- Function 'XML_parse_1string' returns 'TAG_ERROR' on error, instead of 'TAG_NONE'
- Check is made on tag name consistency in "DOM node end callback"
- Function 'DOMXMLDoc_doc_end' is used as "DOM node end callback" (!)
- New functions 'XMLNode_get_children_count', 'XMLNode_dup' (allocate and copy)
- Added XML_DEFAULT_QUOTE to tell which quote " or ' should be used when printing a node
- New macro 'isquote'

*** v3.4.0
- Modifications to get splint talk just a little bit less! ;) (functions now return values, etc.)
- #defines are replaced by enums.
- User-defined tags can be released and accessed.
- Added an 'examples' folder.
- Added AUTHOR and CHANGELOG files.
- Changed method 'XMLNode_set_comment' into more generic 'XMLNode_set_type'.

*** v3.3.1
- Added 'XMLDoc_remove_node' that didn't exist!
- Added an option to 'XML*_print' to prevent printing "pretty-print" separators.
- 'XMLDoc_print' no longer prints a new line as the first line (a.k.a "UGLY HACK").

*** v3.3.0
- Corrected problem on child nodes association.
- Added parser for buffer, not only files (changed prototype of "read_line_alloc").
- Added SAX callbacks for document start and end.
- Added an error handler for SAX.
- Changed the parameter on SAX callbacks to get access to line number and data source name.
- Tests are made on proper initialization of XMLDoc and XMLNode structures.
- Added generation of XPath description for a node.
- New file "htmlstrip.c" as an example on how to use sxmlc to parse an HTML document.

*** v3.2.0
- Include DOCTYPE tag.
- Unified DOM parse to use SAX callbacks.
- Added an "all-in-one" callback for SAX parser.
- Added support of user-defined tags.
- Added 'extern "C" {' to .h files.
- Added "const" specifier in function arguments when possible.
- Changed values from 'TAG_*' constants.
- Corrected XMLNode_copy to copy the 'active' attribute as well.
- Use standard function "strdup" instead of own "strcpy_alloc".
- Added a check for uninitialized XMLDoc.
- Made the 'XML_parse_1string' function available to call (non static) .
- Node text, attributes name and value are unescaped.

*** v3.1.0
- Handling of XPath-like queries.
- Added new utility functions (major one being the split).
- Regexp function can be overloaded.
- Attribute value handles test for difference, not only equality.
23 changes: 23 additions & 0 deletions sxmlc/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2014, matthieu-labas
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 6 additions & 0 deletions sxmlc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sxmlc
=====

Simple, lightweight XML parser in C.

Documentation on http://sxmlc.sourceforge.net/
Loading

0 comments on commit 180c34f

Please sign in to comment.