Beispiel #1
0
        // register for save states

        /*-------------------------------------------------
        *   register_save - register for save states
        *  -------------------------------------------------*/
        public void register_save()
        {
            assert(m_save_order.empty());
            assert(m_save_data == null);

            // make space for the data
            m_save_order.clear();
            m_save_order.reserve(m_itemtable.size());
            m_save_data = new s32 [m_itemtable.size()];  //m_save_data = std::make_unique<s32 []>(m_itemtable.size());

            // sort existing outputs by name and register for save
            foreach (var item in m_itemtable)
            {
                m_save_order.emplace_back(item.second());
            }
            m_save_order.Sort((l, r) => { return(string.Compare(l.name(), r.name())); });  //std::sort(m_save_order.begin(), m_save_order.end(), [] (auto const &l, auto const &r) { return l.get().name() < r.get().name(); });

            // register the reserved space for saving
            //throw new emu_unimplemented();
#if false
            machine().save().save_pointer(nullptr, "output", nullptr, 0, NAME(m_save_data), m_itemtable.size());
#endif

            if (OUTPUT_VERBOSE)
            {
                osd_printf_verbose("Registered {0} outputs for save states\n", m_itemtable.size());
            }
        }
Beispiel #2
0
        //PCOPYASSIGNMOVE(ptokenizer, delete)

        //virtual ~ptokenizer() = default;

        //using token_type = detail::token_type;
        //using token_id_t = detail::token_id_t;
        //using token_t = detail::token_t;
        //using token_store = detail::token_store;

        // tokenizer stuff follows ...

        public ptokenizer_token_id_t register_token(string token)
        {
            ptokenizer_token_id_t ret = new ptokenizer_token_id_t(m_tokens.size(), token);

            m_tokens.emplace(token, ret);
            return(ret);
        }
Beispiel #3
0
        public static void load_translation(random_read file)
        {
            MemoryU8   translation_data_buffer;                                                                                                        //std::unique_ptr<std::uint32_t []> translation_data;
            PointerU32 translation_data;                                                                                                               //std::unique_ptr<std::uint32_t []> translation_data;

            std.unordered_map <string, std.pair <string, uint32_t> > translation_map = new std.unordered_map <string, std.pair <string, uint32_t> >(); //std::unordered_map<std::string_view, std::pair<char const *, std::uint32_t> > translation_map;

            uint64_t size = 0;

            if (file.length(out size) || (20 > size))
            {
                osd_printf_error("Error reading translation file: {0}-byte file is too small to contain translation data\n", size);
                return;
            }

            translation_data_buffer = new MemoryU8((int)size + 3, true);  //translation_data.reset(new (std::nothrow) std::uint32_t [(size + 3) / 4]);
            translation_data        = new PointerU32(f_translation_data);
            if (translation_data == null)
            {
                osd_printf_error("Failed to allocate {0} bytes to load translation data file\n", size);
                return;
            }

            size_t read;

            file.read(translation_data, size, out read);
            if (read != size)
            {
                osd_printf_error("Error reading translation file: requested {0} bytes but got {1} bytes\n", size, read);
                translation_data = null;  //translation_data.reset();
                return;
            }

            if ((translation_data[0] != MO_MAGIC) && (translation_data[0] != MO_MAGIC_REVERSED))
            {
                osd_printf_error("Error reading translation file: unrecognized magic number {0}\n", translation_data[0]); //0x%08X
                translation_data = null;                                                                                  //translation_data.reset();
                return;
            }

            var fetch_word = new Func <size_t, uint32_t>(
                (size_t offset) =>     //[reversed = translation_data[0] == MO_MAGIC_REVERSED, words = translation_data.get()] (size_t offset)
            {
                var reversed = translation_data[0] == MO_MAGIC_REVERSED;
                var words    = translation_data;

                return(reversed ? swapendian_int32(words[offset]) : words[offset]);
            });

            // FIXME: check major/minor version number

            if ((fetch_word(3) % 4) != 0 || (fetch_word(4) % 4) != 0)
            {
                osd_printf_error("Error reading translation file: table offsets {0} and {1} are not word-aligned\n", fetch_word(3), fetch_word(4));
                translation_data = null;  //translation_data.reset();
                return;
            }

            uint32_t number_of_strings        = fetch_word(2);
            uint32_t original_table_offset    = fetch_word(3) >> 2;
            uint32_t translation_table_offset = fetch_word(4) >> 2;

            if ((4 * (original_table_offset + ((uint64_t)number_of_strings * 2))) > size)
            {
                osd_printf_error("Error reading translation file: {0}-entry original string table at offset {1} extends past end of {2}-byte file\n", number_of_strings, fetch_word(3), size);
                translation_data = null;  //translation_data.reset();
                return;
            }

            if ((4 * (translation_table_offset + ((uint64_t)number_of_strings * 2))) > size)
            {
                osd_printf_error("Error reading translation file: {0}-entry translated string table at offset {1} extends past end of {2}-byte file\n", number_of_strings, fetch_word(4), size);
                translation_data = null;  //translation_data.reset();
                return;
            }

            osd_printf_verbose("Reading translation file: {0} strings, original table at word offset {1}, translated table at word offset {2}\n", number_of_strings, original_table_offset, translation_table_offset);

            PointerU8 data = new PointerU8(translation_data);  //char const *const data = reinterpret_cast<char const *>(translation_data.get());

            for (uint32_t i = 1; number_of_strings > i; ++i)
            {
                uint32_t original_length = fetch_word(original_table_offset + (2 * i));
                uint32_t original_offset = fetch_word(original_table_offset + (2 * i) + 1);
                if ((original_length + original_offset) >= size)
                {
                    osd_printf_error("Error reading translation file: {0}-byte original string {1} at offset {2} extends past end of {3}-byte file\n", original_length, i, original_offset, size);
                    continue;
                }

                if (data[original_length + original_offset] != 0)
                {
                    osd_printf_error("Error reading translation file: {0}-byte original string {1} at offset {2} is not correctly NUL-terminated\n", original_length, i, original_offset);
                    continue;
                }

                uint32_t translation_length = fetch_word(translation_table_offset + (2 * i));
                uint32_t translation_offset = fetch_word(translation_table_offset + (2 * i) + 1);
                if ((translation_length + translation_offset) >= size)
                {
                    osd_printf_error("Error reading translation file: {0}-byte translated string {1} at offset {2} extends past end of {3}-byte file\n", translation_length, i, translation_offset, size);
                    continue;
                }

                if (data[translation_length + translation_offset] != 0)
                {
                    osd_printf_error("Error reading translation file: {0}-byte translated string {1} at offset {2} is not correctly NUL-terminated\n", translation_length, i, translation_offset);
                    continue;
                }

                string original    = data.ToString((int)original_offset, int.MaxValue);                                 //std::string_view const original(&data[original_offset], original_length);
                string translation = data.ToString((int)translation_offset, int.MaxValue);                              //char const *const translation(&data[translation_offset]);
                var    ins         = translation_map.emplace(original, std.make_pair(translation, translation_length)); //auto const ins = translation_map.emplace(original, std::make_pair(translation, translation_length));
                if (!ins)
                {
                    osd_printf_warning(
                        "Loading translation file: translation {0} '{1}'='{2}' conflicts with previous translation '{3}'='{4}'\n",
                        i,
                        original,
                        translation,
                        null,      //ins.first->first,
                        null);     //ins.first->second.first);
                }
            }

            osd_printf_verbose("Loaded {0} translated string from file\n", translation_map.size());
            f_translation_data = translation_data;
            f_translation_map  = translation_map;
        }