annotate m68k_util.c @ 2283:6f6f21d0c396

Fix missing address masks on some VRAM reads
author Michael Pavone <pavone@retrodev.com>
date Mon, 09 Jan 2023 00:15:26 -0800
parents 8494fe8d6b65
children 414eb8c34198
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 //TODO: interrupt stuff
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 context->sync_cycle = target_cycle;
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
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 void init_m68k_opts(m68k_options *opts, memmap_chunk * memmap, uint32_t num_chunks, uint32_t clock_divider)
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 memset(opts, 0, sizeof(*opts));
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 opts->gen.memmap = memmap;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 opts->gen.memmap_chunks = num_chunks;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 opts->gen.address_mask = 0xFFFFFF;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 opts->gen.byte_swap = 1;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 opts->gen.max_address = 0x1000000;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 opts->gen.bus_cycles = 4;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 opts->gen.clock_divider = clock_divider;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 }
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 m68k_context *init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler)
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 m68k_context *context = calloc(1, sizeof(m68k_context));
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 context->opts = opts;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 context->reset_handler = reset_handler;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 context->int_cycle = 0xFFFFFFFFU;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 return context;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 }
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 void m68k_reset(m68k_context *context)
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 //read initial SP
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 context->scratch1 = 0;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 m68k_read_16(context);
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 context->aregs[7] = context->scratch1 << 16;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 context->scratch1 = 2;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 m68k_read_16(context);
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 context->aregs[7] |= context->scratch1;
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 PC
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 context->scratch1 = 4;
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->pc = context->scratch1 << 16;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 context->scratch1 = 6;
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->pc |= 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 context->scratch1 = context->pc;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 m68k_read_16(context);
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 context->prefetch = context->scratch1;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 context->pc += 2;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 context->status = 0x27;
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 }
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 void m68k_print_regs(m68k_context *context)
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
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);
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 for (int i = 0; i < 8; i++) {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 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
85 }
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 for (int i = 0; i < 8; i++) {
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 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
88 }
8494fe8d6b65 Add missing file from new 68K core
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }