main
trans.c
1/*
2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5*/
6#include "68kinst.h"
7#include "m68k_core.h"
8#include "mem.h"
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13int headless = 1;
14void render_errorbox(char * title, char * buf)
15{
16}
17
18void render_infobox(char * title, char * buf)
19{
20}
21
22m68k_context * sync_components(m68k_context * context, uint32_t address)
23{
24 if (context->current_cycle > 0x80000000) {
25 context->current_cycle -= 0x80000000;
26 }
27 if (context->status & M68K_STATUS_TRACE || context->trace_pending) {
28 context->target_cycle = context->current_cycle;
29 }
30 return context;
31}
32
33m68k_context *reset_handler(m68k_context *context)
34{
35 m68k_print_regs(context);
36 exit(0);
37 //unreachable
38 return context;
39}
40
41int main(int argc, char ** argv)
42{
43 long filesize;
44 unsigned short *filebuf;
45 char disbuf[1024];
46 unsigned short * cur;
47 m68k_options opts;
48 FILE * f = fopen(argv[1], "rb");
49 fseek(f, 0, SEEK_END);
50 filesize = ftell(f);
51 fseek(f, 0, SEEK_SET);
52 filebuf = malloc(0x400000);
53 memset(filebuf, 0, 0x400000);
54 fread(filebuf, 2, filesize/2 > 0x200000 ? 0x200000 : filesize/2, f);
55 fclose(f);
56 for(cur = filebuf; cur - filebuf < (filesize/2); ++cur)
57 {
58 *cur = (*cur >> 8) | (*cur << 8);
59 }
60 memmap_chunk memmap[2];
61 memset(memmap, 0, sizeof(memmap_chunk)*2);
62 memmap[0].end = 0x400000;
63 memmap[0].mask = 0xFFFFFF;
64 memmap[0].flags = MMAP_READ;
65 memmap[0].buffer = filebuf;
66
67 memmap[1].start = 0xE00000;
68 memmap[1].end = 0x1000000;
69 memmap[1].mask = 0xFFFF;
70 memmap[1].flags = MMAP_READ | MMAP_WRITE | MMAP_CODE;
71 memmap[1].buffer = malloc(64 * 1024);
72 memset(memmap[1].buffer, 0, 64 * 1024);
73 init_m68k_opts(&opts, memmap, 2, 1);
74 m68k_context * context = init_68k_context(&opts, reset_handler);
75 context->mem_pointers[0] = memmap[0].buffer;
76 context->mem_pointers[1] = memmap[1].buffer;
77 context->target_cycle = context->sync_cycle = 0x80000000;
78 uint32_t address;
79 address = filebuf[2] << 16 | filebuf[3];
80 translate_m68k_stream(address, context);
81 m68k_reset(context);
82 return 0;
83}
84