@@ -44,7 +44,7 @@
static const size_t MEM_SZ = 16 * 1024 * 1024;

static Sh4 cpu;
static BiosFile *bios;
static BiosFile bios;
static struct Memory mem;

static volatile bool is_running;
@@ -85,8 +85,8 @@ void dreamcast_init(char const *bios_path, char const *flash_path) {
memory_init(&mem, MEM_SZ);
if (flash_path)
flash_mem_load(flash_path);
bios = new BiosFile(bios_path);
memory_map_init(bios, &mem);
bios_file_init(&bios, bios_path);
memory_map_init(&bios, &mem);
sh4_init(&cpu);
spg_init();

@@ -119,10 +119,10 @@ void dreamcast_init_direct(char const *path_ip_bin,
if (flash_path)
flash_mem_load(flash_path);
if (bios_path)
bios = new BiosFile(bios_path);
bios_file_init(&bios, bios_path);
else
bios = new BiosFile();
memory_map_init(bios, &mem);
bios_file_init_empty(&bios);
memory_map_init(&bios, &mem);

file_ip_bin.seekg(0, file_ip_bin.end);
size_t len_ip_bin = file_ip_bin.tellg();
@@ -186,7 +186,7 @@ void dreamcast_cleanup() {
#endif

sh4_cleanup(&cpu);
delete bios;
bios_file_cleanup(&bios);
memory_cleanup(&mem);
}

@@ -25,7 +25,7 @@

#include <boost/asio.hpp>

#include "BiosFile.hpp"
#include "BiosFile.h"
#include "memory.h"
#include "hw/sh4/sh4.hpp"
#include "dc_sched.hpp"
@@ -66,7 +66,7 @@ int memory_map_read(void *buf, size_t addr, size_t len) {
if ((addr + (len - 1)) > ADDR_BIOS_LAST) {
goto boundary_cross;
}
return bios->read(buf, addr - ADDR_BIOS_FIRST, len);
return bios_file_read(bios, buf, addr - ADDR_BIOS_FIRST, len);
} else if (addr >= ADDR_FLASH_FIRST && addr <= ADDR_FLASH_LAST) {
if ((addr + (len - 1) > ADDR_FLASH_LAST) ||
(addr < ADDR_FLASH_FIRST)) {
@@ -23,7 +23,7 @@
#ifndef MEMORYMAP_HPP_
#define MEMORYMAP_HPP_

#include "BiosFile.hpp"
#include "BiosFile.h"
#include "memory.h"
#include "mem_areas.h"

@@ -124,3 +124,4 @@ DEF_ERROR_STRING_ATTR(feature)
DEF_ERROR_STRING_ATTR(param_name)
DEF_ERROR_U32_ATTR(address)
DEF_ERROR_INT_ATTR(length)
DEF_ERROR_INT_ATTR(errno_val)
@@ -42,6 +42,12 @@ enum error_type {

/* memory access failed because the address was out-of-bounds */
ERROR_MEM_OUT_OF_BOUNDS,

/* unable to allocate memory */
ERROR_FAILED_ALLOC,

/* error on some file operation */
ERROR_FILE_IO
};

enum error_attr_type {
@@ -147,6 +153,8 @@ ERROR_U32_ATTR(address);

ERROR_INT_ATTR(length);

ERROR_INT_ATTR(errno_val);

#define RAISE_ERROR(tp) \
do { \
error_set_line(__LINE__); \
@@ -23,6 +23,8 @@
#include <fstream>
#include <iostream>

#include "BaseException.hpp"

#include "flash_memory.hpp"

static uint8_t flash_mem[FLASH_MEM_SZ];
@@ -25,6 +25,7 @@
#include <boost/cstdint.hpp>

#include "MemoryMap.hpp"
#include "BaseException.hpp"

#include "aica_rtc.hpp"

@@ -30,6 +30,7 @@
#include "hw/pvr2/pvr2_core_reg.hpp"
#include "hw/pvr2/pvr2_tex_mem.hpp"
#include "opengl_backend.hpp"
#include "BaseException.hpp"

#include "framebuffer.hpp"

@@ -30,11 +30,33 @@
#include "BaseException.hpp"
#include "memory.h"
#include "RandGenerator.hpp"
#include "BiosFile.hpp"
#include "BiosFile.h"
#include "MemoryMap.hpp"

typedef RandGenerator<uint32_t> RandGen32;

/*
* loads a program into the given address. the InputIterator's
* indirect method (overload*) should return a data_tp.
*/
static void bios_load_binary(BiosFile *bios, addr32_t where,
Sh4Prog::ByteList::const_iterator start,
Sh4Prog::ByteList::const_iterator end) {
size_t bytes_written = 0;

bios_file_clear(bios);

for (Sh4Prog::ByteList::const_iterator it = start; it != end; it++) {
uint8_t tmp = *it;

if (bytes_written + sizeof(uint8_t) >= bios->dat_len)
BOOST_THROW_EXCEPTION(InvalidParamError());

memcpy(bios->dat + bytes_written, &tmp, sizeof(tmp));
bytes_written += sizeof(tmp);
}
}

/*
* sh4 program for unsigned division of a 32-bit dividend by a 16-bit divisor
*
@@ -311,7 +333,7 @@ run_div_test(addr32_t run_until, struct div_test_state *state,

test_prog.add_txt(std::string(prog_asm));
const Sh4Prog::ByteList& inst = test_prog.get_prog();
state->bios.load_binary<uint8_t>(0, inst.begin(), inst.end());
bios_load_binary(&state->bios, 0, inst.begin(), inst.end());

sh4_on_hard_reset(&state->sh4);
sh4_enter(&state->sh4);
@@ -428,7 +450,7 @@ unsigned_div_test_64_32(struct div_test *test, struct div_test_state *state) {

test_prog.add_txt(std::string(div_unsigned_64_32));
const Sh4Prog::ByteList& inst = test_prog.get_prog();
state->bios.load_binary<uint8_t>(0, inst.begin(), inst.end());
bios_load_binary(&state->bios, 0, inst.begin(), inst.end());

sh4_on_hard_reset(&state->sh4);
sh4_enter(&state->sh4);
@@ -466,9 +488,10 @@ int main(int argc, char **argv) {
seed = atoi(optarg);
}

try {
struct div_test_state test_state;
struct div_test_state test_state;
bios_file_init_empty(&test_state.bios);

try {
memory_init(&test_state.mem, 16 * 1024 * 1024);
memory_map_init(&test_state.bios, &test_state.mem);
sh4_init(&test_state.sh4);
@@ -497,5 +520,7 @@ int main(int argc, char **argv) {
std::cout << std::dec << n_tests << " run -- " << n_success <<
" successes." << std::endl;

bios_file_cleanup(&test_state.bios);

return (n_tests == n_success) ? 0 : 1;
}

Large diffs are not rendered by default.

@@ -34,9 +34,31 @@
#include "tool/sh4asm/sh4asm.hpp"
#include "BaseException.hpp"
#include "memory.h"
#include "BiosFile.hpp"
#include "BiosFile.h"
#include "MemoryMap.hpp"

/*
* loads a program into the given address. the InputIterator's
* indirect method (overload*) should return a data_tp.
*/
static void bios_load_binary(BiosFile *bios, addr32_t where,
Sh4Prog::ByteList::const_iterator start,
Sh4Prog::ByteList::const_iterator end) {
size_t bytes_written = 0;

bios_file_clear(bios);

for (Sh4Prog::ByteList::const_iterator it = start; it != end; it++) {
uint8_t tmp = *it;

if (bytes_written + sizeof(uint8_t) >= bios->dat_len)
BOOST_THROW_EXCEPTION(InvalidParamError());

memcpy(bios->dat + bytes_written, &tmp, sizeof(tmp));
bytes_written += sizeof(tmp);
}
}

char const prog_asm[] =
/*
* the interrupt vector will be at 0x0c000600 (VBR == 0x0c000000)
@@ -193,20 +215,21 @@ char const prog_asm[] =
"";

int main(int argc, char **argv) {
BiosFile bios;
try {
Sh4Prog test_prog;
BiosFile bios;
struct Memory mem;
Sh4 sh4;
int ret_code = 0;

bios_file_init_empty(&bios);
memory_init(&mem, 16 * 1024 * 1024);
memory_map_init(&bios, &mem);
sh4_init(&sh4);

test_prog.add_txt(std::string(prog_asm));
const Sh4Prog::ByteList& inst = test_prog.get_prog();
bios.load_binary<uint8_t>(0, inst.begin(), inst.end());
bios_load_binary(&bios, 0, inst.begin(), inst.end());

sh4_run_until(&sh4, 0x0c000100);

@@ -256,11 +279,13 @@ int main(int argc, char **argv) {
else
std::cout << "TEST SUCCESS" << std::endl;

bios_file_cleanup(&bios);
sh4_cleanup(&sh4);

return ret_code;
} catch (BaseException& exc) {
std::cerr << boost::diagnostic_information(exc);
bios_file_cleanup(&bios);
}

return 1;