Update to bsnes v060r06 release.

Completely rewrote the syntax for all XML parsing, took over five
hours of nonstop work, holy fuck.

Sadly the expanded syntax greatly increases the parser complexity, the
SNES::Cartridge class is twice as big now, XML parsing for all special
chips takes up 20KB of space.

Example:
    void Cartridge::xml_parse_sdd1(xml_element *root) {
    has_sdd1 = true;

    foreach_element(node, root) {
    if(node->name == "mcu") {
    foreach_element(leaf, node) {
    if(leaf->name == "map") {
    Mapping m((Memory&)sdd1);
    foreach_attribute(attr, leaf) {
    if(attr->name == "address") xml_parse_address(m, attr->content);
    }
    mapping.add(m);
    }
    }
    } else if(node->name == "mmio") {
    foreach_element(leaf, node) {
    if(leaf->name == "map") {
    Mapping m((MMIO&)sdd1);
    foreach_attribute(attr, leaf) {
    if(attr->name == "address") xml_parse_address(m, attr->content);
    }
    mapping.add(m);
    }
    }
    }
    }
    }


Of course, C++ doesn't have foreach(), that'd be too goddamned
convenient, right? So behold the spawn of satan himself:

    #define concat_(x, y) x ## y
    #define concat(x, y) concat_(x, y)

    #define foreach_element(iter, object) \
    unsigned concat(counter, __LINE__) = 0; \
    xml_element* iter; \
    while(concat(counter, __LINE__) < object->element.size() \
    && (iter = object->element[concat(counter, __LINE__)++]) != 0)

    #define foreach_attribute(iter, object) \
    unsigned concat(counter, __LINE__) = 0; \
    xml_attribute* iter; \
    while(concat(counter, __LINE__) < object->attribute.size() \
    && (iter = object->attribute[concat(counter, __LINE__)++]) != 0)

[No archive available]
This commit is contained in:
byuu 2010-02-27 10:04:33 +00:00
parent 768e9b589d
commit e1c8757a10

Diff Content Not Available