Mercurial > repos > blastem
annotate m68k_util.c @ 2577:5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 07 Feb 2025 08:57:24 -0800 |
parents | d44fe974fb85 |
children | 939b818df589 |
rev | line source |
---|---|
1951
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 void m68k_read_8(m68k_context *context) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 context->cycles += 4 * context->opts->gen.clock_divider; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 context->scratch1 = read_byte(context->scratch1, context->mem_pointers, &context->opts->gen, context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 void m68k_read_16(m68k_context *context) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 context->cycles += 4 * context->opts->gen.clock_divider; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 context->scratch1 = read_word(context->scratch1, context->mem_pointers, &context->opts->gen, context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 void m68k_write_8(m68k_context *context) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 context->cycles += 4 * context->opts->gen.clock_divider; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 write_byte(context->scratch2, context->scratch1, context->mem_pointers, &context->opts->gen, context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 void m68k_write_16(m68k_context *context) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 context->cycles += 4 * context->opts->gen.clock_divider; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 write_word(context->scratch2, context->scratch1, context->mem_pointers, &context->opts->gen, context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 void m68k_sync_cycle(m68k_context *context, uint32_t target_cycle) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 { |
2577
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
29 context->sync_cycle = target_cycle; //why? |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
30 context->sync_components(context, 0); |
1951
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 |
2577
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
33 static sync_fun *sync_comp_tmp; |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
34 static int_ack_fun int_ack_tmp; |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
35 void init_m68k_opts(m68k_options *opts, memmap_chunk * memmap, uint32_t num_chunks, uint32_t clock_divider, sync_fun *sync_components, int_ack_fun int_ack) |
1951
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 memset(opts, 0, sizeof(*opts)); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 opts->gen.memmap = memmap; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 opts->gen.memmap_chunks = num_chunks; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 opts->gen.address_mask = 0xFFFFFF; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 opts->gen.byte_swap = 1; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 opts->gen.max_address = 0x1000000; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 opts->gen.bus_cycles = 4; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 opts->gen.clock_divider = clock_divider; |
2577
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
45 sync_comp_tmp = sync_components; |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
46 int_ack_tmp = int_ack; |
1951
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 |
2577
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
49 m68k_context *init_68k_context(m68k_options * opts, m68k_reset_handler *reset_handler) |
1951
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 m68k_context *context = calloc(1, sizeof(m68k_context)); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 context->opts = opts; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 context->reset_handler = reset_handler; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 context->int_cycle = 0xFFFFFFFFU; |
2577
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
55 context->sync_components = sync_comp_tmp; |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
56 sync_comp_tmp = NULL; |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
57 context->int_ack_handler = int_ack_tmp; |
5f725429d08f
WIP changes to new CPU core for rotate instructions and to get interrupts more functional
Michael Pavone <pavone@retrodev.com>
parents:
2500
diff
changeset
|
58 int_ack_tmp = NULL; |
1951
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 return context; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 void m68k_reset(m68k_context *context) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 //read initial SP |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 context->scratch1 = 0; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 m68k_read_16(context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 context->aregs[7] = context->scratch1 << 16; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 context->scratch1 = 2; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 m68k_read_16(context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 context->aregs[7] |= context->scratch1; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 //read initial PC |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 context->scratch1 = 4; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 m68k_read_16(context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 context->pc = context->scratch1 << 16; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 context->scratch1 = 6; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 m68k_read_16(context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 context->pc |= context->scratch1; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 context->scratch1 = context->pc; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 m68k_read_16(context); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 context->prefetch = context->scratch1; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 context->pc += 2; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 context->status = 0x27; |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 void m68k_print_regs(m68k_context *context) |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 printf("XNZVC\n%d%d%d%d%d\n", context->xflag != 0, context->nflag != 0, context->zflag != 0, context->vflag != 0, context->cflag != 0); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 for (int i = 0; i < 8; i++) { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 printf("d%d: %X\n", i, context->dregs[i]); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 for (int i = 0; i < 8; i++) { |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 printf("a%d: %X\n", i, context->aregs[i]); |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 } |
8494fe8d6b65
Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
2499
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
98 |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
99 void m68k_serialize(m68k_context *context, uint32_t pc, serialize_buffer *buf) |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
100 { |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
101 //TODO: implement me |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
102 } |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
103 |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
104 void m68k_deserialize(deserialize_buffer *buf, void *vcontext) |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
105 { |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
106 //TODO: implement me |
d74d3998482c
Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2447
diff
changeset
|
107 } |
2500
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
108 |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
109 void start_68k_context(m68k_context *context, uint32_t pc) |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
110 { |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
111 context->scratch1 = context->pc = pc; |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
112 m68k_read_16(context); |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
113 context->prefetch = context->scratch1; |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
114 context->pc += 2; |
d44fe974fb85
Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
2499
diff
changeset
|
115 } |