Mercurial > repos > blastem
annotate trans.c @ 505:b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 06 Jan 2014 22:54:05 -0800 |
parents | 140af5509ce7 |
children | 8e395210f50f |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
440
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
440
diff
changeset
|
2 Copyright 2013 Michael Pavone |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
440
diff
changeset
|
3 This file is part of BlastEm. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
440
diff
changeset
|
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. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
440
diff
changeset
|
5 */ |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "68kinst.h" |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "m68k_to_x86.h" |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "mem.h" |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <stdio.h> |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <stdlib.h> |
440 | 11 #include <string.h> |
12 | |
13 m68k_context * sync_components(m68k_context * context, uint32_t address) | |
14 { | |
15 if (context->current_cycle > 0x80000000) { | |
16 context->current_cycle -= 0x80000000; | |
17 } | |
18 return context; | |
19 } | |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 int main(int argc, char ** argv) |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 { |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 long filesize; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 unsigned short *filebuf; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 char disbuf[1024]; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 unsigned short * cur; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 x86_68k_options opts; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 m68k_context context; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 FILE * f = fopen(argv[1], "rb"); |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 fseek(f, 0, SEEK_END); |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 filesize = ftell(f); |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 fseek(f, 0, SEEK_SET); |
440 | 33 filebuf = malloc(filesize > 0x400000 ? filesize : 0x400000); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 fread(filebuf, 2, filesize/2, f); |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 fclose(f); |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 for(cur = filebuf; cur - filebuf < (filesize/2); ++cur) |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 *cur = (*cur >> 8) | (*cur << 8); |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
440 | 40 memmap_chunk memmap[2]; |
41 memset(memmap, 0, sizeof(memmap_chunk)*2); | |
42 memmap[0].end = 0x400000; | |
43 memmap[0].mask = 0xFFFFFF; | |
44 memmap[0].flags = MMAP_READ; | |
45 memmap[0].buffer = filebuf; | |
46 | |
47 memmap[1].start = 0xE00000; | |
48 memmap[1].end = 0x1000000; | |
49 memmap[1].mask = 0xFFFF; | |
50 memmap[1].flags = MMAP_READ | MMAP_WRITE | MMAP_CODE; | |
51 memmap[1].buffer = malloc(64 * 1024); | |
52 init_x86_68k_opts(&opts, memmap, 2); | |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 init_68k_context(&context, opts.native_code_map, &opts); |
440 | 54 context.mem_pointers[0] = memmap[0].buffer; |
55 context.mem_pointers[1] = memmap[1].buffer; | |
56 context.target_cycle = context.sync_cycle = 0x80000000; | |
212
e657a99b5abf
Fixed up trans for changes to translate_m68k_stream, but still need to deal with missing callbacks.
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
57 uint32_t address; |
e657a99b5abf
Fixed up trans for changes to translate_m68k_stream, but still need to deal with missing callbacks.
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
58 address = filebuf[2] << 16 | filebuf[3]; |
e657a99b5abf
Fixed up trans for changes to translate_m68k_stream, but still need to deal with missing callbacks.
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
59 translate_m68k_stream(address, &context); |
19
4717146a7606
Initial support for M68k reset vector, rather than starting at an arbitrary address
Mike Pavone <pavone@retrodev.com>
parents:
18
diff
changeset
|
60 m68k_reset(&context); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 return 0; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 } |
440 | 63 |