view src/xs_backend.c @ 983:04dde987c0aa

Some translation updates.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 31 Mar 2013 11:43:01 +0300
parents 6f53d0405d58
children
line wrap: on
line source

/*
   XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)

   Backend handling

   Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
   (C) Copyright 1999-2012 Tecnic Software productions (TNSP)

   This program 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 2 of the License, or
   (at your option) any later version.

   This program 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, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "xs_backend.h"
#include "xs_config.h"

/* List of emulator engines
 */
#ifdef HAVE_SIDPLAY1
#  include "xs_sidplay1.h"
#endif
#ifdef HAVE_SIDPLAY2
#  include "xs_sidplay2.h"
#endif
#ifdef HAVE_SIDPLAYFP
#  include "xs_sidplayfp.h"
#endif


static XSEngine xs_enginelist[] =
{
#ifdef HAVE_SIDPLAY1
    {
        XS_ENG_SIDPLAY1,
        xs_sidplay1_probe,
        xs_sidplay1_init, xs_sidplay1_close,
        xs_sidplay1_initsong, xs_sidplay1_fillbuffer,
        xs_sidplay1_load, xs_sidplay1_delete,
        xs_sidplay1_getinfo, xs_sidplay1_updateinfo,
        NULL
    },
#endif
#ifdef HAVE_SIDPLAY2
    {
        XS_ENG_SIDPLAY2,
        xs_sidplay2_probe,
        xs_sidplay2_init, xs_sidplay2_close,
        xs_sidplay2_initsong, xs_sidplay2_fillbuffer,
        xs_sidplay2_load, xs_sidplay2_delete,
        xs_sidplay2_getinfo, xs_sidplay2_updateinfo,
        xs_sidplay2_flush
    },
#endif
#ifdef HAVE_SIDPLAYFP
    {
        XS_ENG_SIDPLAYFP,
        xs_sidplayfp_probe,
        xs_sidplayfp_init, xs_sidplayfp_close,
        xs_sidplayfp_initsong, xs_sidplayfp_fillbuffer,
        xs_sidplayfp_load, xs_sidplayfp_delete,
        xs_sidplayfp_getinfo, xs_sidplayfp_updateinfo,
        xs_sidplayfp_flush
    },
#endif
};

static const gint xs_nenginelist = sizeof(xs_enginelist) / sizeof(xs_enginelist[0]);


const XSROMImageData xs_rom_images[XS_C64_ROM_IMAGES] =
{
    { "Kernal",        "kernal",  8192 },
    { "Basic v2.0",    "basic",   8192 },
    { "Character ROM", "chargen", 4096 },
};


gboolean xs_init_emu_backend(XSEngineState *state, gint *preferred)
{
    gint engine;
    gboolean initialized = FALSE;

    XSDEBUG("trying emulator engine #%i...\n", *preferred);

    for (engine = 0; engine < xs_nenginelist && !initialized; engine++)
    {
        if (xs_enginelist[engine].plrIdent == *preferred &&
            xs_enginelist[engine].plrInit(state))
        {
            initialized = TRUE;
            state->engine = &xs_enginelist[engine];
        }
    }

    XSDEBUG("init#1: %s, %i\n", initialized ? "OK" : "FAILED", *preferred);
    return initialized;
}


gboolean xs_load_rom_image(gint index, guint8 **data)
{
    const XSROMImageData *rom = &xs_rom_images[index];
    size_t size = 0;

    XSDEBUG("Trying ROM '%s' from '%s%s', %d bytes.\n",
        rom->name, xs_cfg.romPath, rom->filename, rom->size);

    if (!xs_fload_buffer_path(xs_cfg.romPath, rom->filename,
        data, &size, rom->size, TRUE))
    {
        xs_error("Failed to load required %s ROM image '%s%s'.\n",
            rom->name, xs_cfg.romPath, rom->filename);
        return FALSE;
    }

    if (size < rom->size)
    {
        xs_error("ROM image %s '%s%s' size does not match: %d != %d\n",
            rom->name, xs_cfg.romPath, rom->filename,
            size, rom->size);
        return FALSE;
    }

    return TRUE;
}


void xs_free_rom_images(guint8 **roms)
{
    gint i;
    for (i = 0; i < XS_C64_ROM_IMAGES; i++)
    {
        g_free(roms[i]);
        roms[i] = NULL;
    }
}


gboolean xs_load_rom_images(guint8 **roms)
{
    gint i;

    XSDEBUG("Loading C64 ROM images ...\n");

    xs_free_rom_images(roms);

    for (i = 0; i < XS_C64_ROM_IMAGES; i++)
    {
        if (!xs_load_rom_image(i, &roms[i]))
        {
            xs_free_rom_images(roms);
            return FALSE;
        }
    }

    return TRUE;
}