Mercurial > repos > blastem
comparison m68k_util.c @ 1983:a7b753e260a2 mame_interp
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 09 May 2020 23:39:44 -0700 |
parents | 8494fe8d6b65 |
children | 414eb8c34198 |
comparison
equal
deleted
inserted
replaced
1937:cafde1255ad3 | 1983:a7b753e260a2 |
---|---|
1 #include <string.h> | |
2 | |
3 void m68k_read_8(m68k_context *context) | |
4 { | |
5 context->cycles += 4 * context->opts->gen.clock_divider; | |
6 context->scratch1 = read_byte(context->scratch1, context->mem_pointers, &context->opts->gen, context); | |
7 } | |
8 | |
9 void m68k_read_16(m68k_context *context) | |
10 { | |
11 context->cycles += 4 * context->opts->gen.clock_divider; | |
12 context->scratch1 = read_word(context->scratch1, context->mem_pointers, &context->opts->gen, context); | |
13 } | |
14 | |
15 void m68k_write_8(m68k_context *context) | |
16 { | |
17 context->cycles += 4 * context->opts->gen.clock_divider; | |
18 write_byte(context->scratch2, context->scratch1, context->mem_pointers, &context->opts->gen, context); | |
19 } | |
20 | |
21 void m68k_write_16(m68k_context *context) | |
22 { | |
23 context->cycles += 4 * context->opts->gen.clock_divider; | |
24 write_word(context->scratch2, context->scratch1, context->mem_pointers, &context->opts->gen, context); | |
25 } | |
26 | |
27 void m68k_sync_cycle(m68k_context *context, uint32_t target_cycle) | |
28 { | |
29 //TODO: interrupt stuff | |
30 context->sync_cycle = target_cycle; | |
31 } | |
32 | |
33 void init_m68k_opts(m68k_options *opts, memmap_chunk * memmap, uint32_t num_chunks, uint32_t clock_divider) | |
34 { | |
35 memset(opts, 0, sizeof(*opts)); | |
36 opts->gen.memmap = memmap; | |
37 opts->gen.memmap_chunks = num_chunks; | |
38 opts->gen.address_mask = 0xFFFFFF; | |
39 opts->gen.byte_swap = 1; | |
40 opts->gen.max_address = 0x1000000; | |
41 opts->gen.bus_cycles = 4; | |
42 opts->gen.clock_divider = clock_divider; | |
43 } | |
44 | |
45 m68k_context *init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler) | |
46 { | |
47 m68k_context *context = calloc(1, sizeof(m68k_context)); | |
48 context->opts = opts; | |
49 context->reset_handler = reset_handler; | |
50 context->int_cycle = 0xFFFFFFFFU; | |
51 return context; | |
52 } | |
53 | |
54 void m68k_reset(m68k_context *context) | |
55 { | |
56 //read initial SP | |
57 context->scratch1 = 0; | |
58 m68k_read_16(context); | |
59 context->aregs[7] = context->scratch1 << 16; | |
60 context->scratch1 = 2; | |
61 m68k_read_16(context); | |
62 context->aregs[7] |= context->scratch1; | |
63 | |
64 //read initial PC | |
65 context->scratch1 = 4; | |
66 m68k_read_16(context); | |
67 context->pc = context->scratch1 << 16; | |
68 context->scratch1 = 6; | |
69 m68k_read_16(context); | |
70 context->pc |= context->scratch1; | |
71 | |
72 context->scratch1 = context->pc; | |
73 m68k_read_16(context); | |
74 context->prefetch = context->scratch1; | |
75 context->pc += 2; | |
76 | |
77 context->status = 0x27; | |
78 } | |
79 | |
80 void m68k_print_regs(m68k_context *context) | |
81 { | |
82 printf("XNZVC\n%d%d%d%d%d\n", context->xflag != 0, context->nflag != 0, context->zflag != 0, context->vflag != 0, context->cflag != 0); | |
83 for (int i = 0; i < 8; i++) { | |
84 printf("d%d: %X\n", i, context->dregs[i]); | |
85 } | |
86 for (int i = 0; i < 8; i++) { | |
87 printf("a%d: %X\n", i, context->aregs[i]); | |
88 } | |
89 } |