annotate jaguar.c @ 1386:d0008f2620cc

Force J region for Japanese version of Light Crusader
author Michael Pavone <pavone@retrodev.com>
date Wed, 31 May 2017 21:34:59 -0700
parents b45d1f64060e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdint.h>
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdio.h>
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <stddef.h>
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <stdlib.h>
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "m68k_core.h"
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
6 #include "68kinst.h"
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "jaguar.h"
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "util.h"
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
9 #include "debug.h"
1085
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
10 #include "config.h"
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
11 #include "render.h"
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 //BIOS Area Memory map
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 // 10 00 00 - 10 04 00 : Video mode/ Memory control registers
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 // 10 04 00 - 10 08 00 : CLUT
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 // 10 08 00 - 10 10 00 : Line buffer A
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 // 10 10 00 - 10 18 00 : Line buffer B
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 // 10 18 00 - 10 20 00 : Write Line buffer
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 // 10 21 00 - 10 30 00 : GPU/blitter registers
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 // 10 30 00 - 10 40 00 : GPU Local RAM (mirrored every 1K?)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 // 11 00 00 - 11 00 40 : Timer/Clock registers
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 // 11 40 00 - 11 40 04 : Joystick Interface
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 // 11 A1 00 - 11 A1 52 : DSP/DAC/I2S Registers
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 // 11 B0 00 - 11 D0 00 : DSP Local RAM (8KB)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 // 11 D0 00 - 11 E0 00 : Wave table ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 int headless = 1;
1085
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
28 tern_node * config;
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
29
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
30 void handle_keydown(int keycode, uint8_t scancode)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
31 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
32 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
33
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
34 void handle_keyup(int keycode, uint8_t scancode)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
35 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
36 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
37
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
38 void handle_joydown(int joystick, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
39 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
40 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
41
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
42 void handle_joyup(int joystick, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
43 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
44 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
45
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
46 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
47 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
48 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
49
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
50 void handle_mousedown(int mouse, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
51 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
52 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
53
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
54 void handle_mouseup(int mouse, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
55 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
56 }
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
57
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
58 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
59 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
60 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
62 void jag_update_m68k_int(jaguar_context *system)
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
63 {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
64 m68k_context *m68k = system->m68k;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
65 if (m68k->sync_cycle - m68k->current_cycle > system->max_cycles) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
66 m68k->sync_cycle = m68k->current_cycle + system->max_cycles;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
67 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
68 //TODO: Support other interrupt sources
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
69 if (!system->cpu_int_control || (m68k->status & 0x7)) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
70 m68k->int_cycle = CYCLE_NEVER;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
71 } else if(system->cpu_int_control & system->video->cpu_int_pending) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
72 m68k->int_cycle = m68k->current_cycle;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
73 //supposedly all interrupts on the jaguar are "level 0" autovector interrupts
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
74 //which I assume means they're abusing the "spurious interrupt" vector
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
75 m68k->int_num = VECTOR_USER0 - VECTOR_SPURIOUS_INTERRUPT;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
76 } else {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
77 m68k->int_cycle = jag_next_vid_interrupt(system->video);
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
78 m68k->int_num = VECTOR_USER0 - VECTOR_SPURIOUS_INTERRUPT;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
79 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
80
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
81 if (m68k->int_cycle > m68k->current_cycle && m68k->int_pending == INT_PENDING_SR_CHANGE) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
82 m68k->int_pending = INT_PENDING_NONE;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
83 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
84
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
85 m68k->target_cycle = m68k->int_cycle < m68k->sync_cycle ? m68k->int_cycle : m68k->sync_cycle;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
86 if (m68k->should_return) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
87 m68k->target_cycle = m68k->current_cycle;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
88 } else if (m68k->target_cycle < m68k->current_cycle) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
89 //Changes to SR can result in an interrupt cycle that's in the past
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
90 //This can cause issues with the implementation of STOP though
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
91 m68k->target_cycle = m68k->current_cycle;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
92 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
93 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 void rom0_write_16(uint32_t address, jaguar_context *system, uint16_t value)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 //TODO: Use write_latch and write_pending to turn two 16-bit writes into a 32-bit one
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 //Documentation heavily suggests that writes to most registers should be 32-bits wide
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 if (address < 0x100000 || address >= 0x120000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 //Boot ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 fprintf(stderr, "Invalid write to Boot ROM - %X:%X\n", address, value);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 return;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 if (address < 0x103000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 if (address < 0x101000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 if (address < 0x100400) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 //Video mode / Memory control registers
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
108 switch(address & 0x3FE)
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
109 {
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
110 case 0:
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
111 if (((value ^ system->memcon1) & 1) || !system->memcon_written) {
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
112 uint16_t **mem_pointers = system->m68k->mem_pointers;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
113 int rom = value & 1 ? 4 : 1;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
114 int ram0 = value & 1 ? 0 : 6;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
115 int ram1 = value & 1 ? 2 : 4;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
116 mem_pointers[ram0] = mem_pointers[ram0 + 1] = system->dram;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
117 //these are probably open bus, but mirror DRAM for now
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
118 mem_pointers[ram1] = mem_pointers[ram1 + 1] = system->dram;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
119
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
120 mem_pointers[rom] = system->cart;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
121 mem_pointers[rom + 1] = system->cart + ((0x200000 & (system->cart_size-1)) >> 1);
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
122 mem_pointers[rom + 2] = system->cart + ((0x400000 & (system->cart_size-1)) >> 1);
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
123 system->memcon_written = 1;
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
124 printf("MEMCON1 write - ROMHI: %d\n", value & 1);
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
125 switch (system->memcon1 >> 3 & 3)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
126 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
127 case 0:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
128 system->rom_cycles = 10;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
129 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
130 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
131 system->rom_cycles = 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
132 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
133 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
134 system->rom_cycles = 6;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
135 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
136 case 3:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
137 system->rom_cycles = 5;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
138 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
139 }
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
140 //TODO: invalidate code cache
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
141 }
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
142 system->memcon1 = value;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
143 break;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
144 case 2:
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
145 system->memcon2 = value;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
146 break;
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
147 case 0xE0:
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
148 system->cpu_int_control = value & 0x1F;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
149 system->video->cpu_int_pending &= ~(value >> 8);
1100
653558f6fa7a Fix Jaguar video interrupt cycle calculation
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
150 printf("INT1 write: %X @ %d - int_pending: %X, int_control: %X\n", value, system->m68k->current_cycle, system->video->cpu_int_pending, system->cpu_int_control);
653558f6fa7a Fix Jaguar video interrupt cycle calculation
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
151 jag_update_m68k_int(system);
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
152 //TODO: apply mask to int pending fields on other components once they are implemented
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
153 break;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
154 case 0xE2:
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
155 //no real handling of bus conflicts presently, so this doesn't really need to do anything yet
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
156 printf("INT2 write: %X\n", value);
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
157 break;
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
158 default:
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
159 jag_video_reg_write(system->video, address, value);
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
160 jag_update_m68k_int(system);
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
161 break;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
162 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 } else if (address < 0x100800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 //CLUT
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 address = address >> 1 & 255;
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
166 system->video->clut[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 //Line buffer A
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
171 system->video->line_buffer_a[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 } else if (address < 0x101800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 //Line buffer B
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
178 system->video->line_buffer_b[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 } else if (address < 0x102100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 //Write Line Buffer
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
184 system->video->write_line_buffer[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 //GPU/Blitter registers
1092
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
188 if (address < 0x102200) {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
189 fprintf(stderr, "Unhandled write to GPU registers %X: %X\n", address, value);
1094
1dba006bad47 Get Jaguar disassembler more or less working. Dump gpu program to file when GPU GO bit is set
Michael Pavone <pavone@retrodev.com>
parents: 1092
diff changeset
190 if (address == 0x102116 && (value & 1)) {
1dba006bad47 Get Jaguar disassembler more or less working. Dump gpu program to file when GPU GO bit is set
Michael Pavone <pavone@retrodev.com>
parents: 1092
diff changeset
191 FILE *f = fopen("gpu.bin", "wb");
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
192 uint8_t buf[4];
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
193 for (int i = 0; i < GPU_RAM_BYTES/sizeof(uint32_t); i++)
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
194 {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
195 buf[0] = system->gpu_local[i] >> 24;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
196 buf[1] = system->gpu_local[i] >> 16;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
197 buf[2] = system->gpu_local[i] >> 8;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
198 buf[3] = system->gpu_local[i];
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
199 fwrite(buf, 1, sizeof(buf), f);
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
200 }
1094
1dba006bad47 Get Jaguar disassembler more or less working. Dump gpu program to file when GPU GO bit is set
Michael Pavone <pavone@retrodev.com>
parents: 1092
diff changeset
201 fclose(f);
1dba006bad47 Get Jaguar disassembler more or less working. Dump gpu program to file when GPU GO bit is set
Michael Pavone <pavone@retrodev.com>
parents: 1092
diff changeset
202 }
1092
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
203 } else {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
204 fprintf(stderr, "Unhandled write to Blitter registers %X: %X\n", address, value);
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
205 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 } else if (address < 0x11A100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 if (address < 0x110000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 //GPU Local RAM
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
210 uint32_t offset = address >> 2 & (GPU_RAM_BYTES / sizeof(uint32_t) - 1);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 uint32_t value32 = value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 system->gpu_local[offset] &= 0xFFFF0000;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 system->gpu_local[offset] &= 0x0000FFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 value32 = value32 << 16;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 system->gpu_local[offset] |= value32;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 } else if (address < 0x114000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 //timer clock registers
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
221 fprintf(stderr, "Unhandled write to timer/clock registers - %X:%X\n", address, value);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 //joystick interface
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
224 fprintf(stderr, "Unhandled write to joystick interface - %X:%X\n", address, value);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 } else if (address < 0x11B000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 //DSP/DAC/I2S Registers
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
228 fprintf(stderr, "Unhandled write to DSP/DAC/I2S registers - %X:%X\n", address, value);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 } else if (address < 0x11D000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 //DSP local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 uint32_t offset = address >> 2 & (DSP_RAM_BYTES / sizeof(uint32_t) - 1);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 uint32_t value32 = value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 system->dsp_local[offset] &= 0xFFFF0000;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 system->dsp_local[offset] &= 0x0000FFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 value32 = value32 << 16;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 system->gpu_local[offset] |= value32;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 //Wave table ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 fprintf(stderr, "Invalid write to wave table ROM - %X:%X\n", address, value);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 uint16_t rom0_read_16(uint32_t address, jaguar_context *system)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 if (address < 0x100000 || address >= 0x120000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 //Boot ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 address = address >> 1 & ((system->bios_size >> 1) - 1);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 return system->bios[address];
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 if (address < 0x103000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 if (address < 0x101000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 if (address < 0x100400) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 //Video mode / Memory control registers
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
257 switch (address & 0x3FE)
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
258 {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
259 case 0xE0:
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
260 puts("INT1 read");
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
261 //TODO: Bitwise or with cpu_int_pending fields from other components once implemented
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
262 return system->video->cpu_int_pending;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
263 break;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
264 default:
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
265 fprintf(stderr, "Unhandled read from video mode/memory control registers - %X\n", address);
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
266 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 } else if (address < 0x100800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 //CLUT
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 address = address >> 1 & 255;
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
270 return system->video->clut[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
272 //Line buffer A
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
275 return system->video->line_buffer_a[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
276 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
277 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
278 } else if (address < 0x101800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
279 //Line buffer B
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
280 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
282 return system->video->line_buffer_b[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
283 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
284 } else if (address < 0x102100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
285 //Write Line Buffer
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
286 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
287 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
288 return system->video->write_line_buffer[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 //GPU/Blitter registers
1092
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
292 if (address < 0x102200) {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
293 fprintf(stderr, "Unhandled read from GPU registers %X\n", address);
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
294 } else {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
295 fprintf(stderr, "Unhandled read from Blitter registers %X\n", address);
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
296 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
297 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
298 } else if (address < 0x11A100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
299 if (address < 0x110000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
300 //GPU Local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
301 uint32_t offset = address >> 2 & (GPU_RAM_BYTES / sizeof(uint32_t) - 1);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
302 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
303 return system->gpu_local[offset];
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
304 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
305 return system->gpu_local[offset] >> 16;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
306 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
307 } else if (address < 0x114000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
308 //timer clock registers
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
309 fprintf(stderr, "Unhandled read from timer/clock registers - %X\n", address);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
310 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
311 //joystick interface
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
312 fprintf(stderr, "Unhandled read from joystick interface - %X\n", address);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
313 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
314 } else if (address < 0x11B000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
315 //DSP/DAC/I2S Registers
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
316 fprintf(stderr, "Unhandled read from DSP/DAC/I2S registers - %X\n", address);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
317 } else if (address < 0x11D000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
318 //DSP local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
319 uint32_t offset = address >> 2 & (DSP_RAM_BYTES / sizeof(uint32_t) - 1);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
320 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
321 return system->dsp_local[offset];
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
322 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
323 return system->dsp_local[offset] >> 16;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
324 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
325 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
326 //Wave table ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
327 fprintf(stderr, "Unhandled read from wave table ROM - %X\n", address);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
328 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
329 return 0xFFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
330 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
331
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
332 uint64_t rom0_read_64(uint32_t address, jaguar_context *system)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
333 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
334 address &= 0x1FFFFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
335 uint64_t high = rom0_read_16(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
336 uint64_t highmid = rom0_read_16(address+2, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
337 uint64_t lowmid = rom0_read_16(address+4, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
338 uint64_t low = rom0_read_16(address+6, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
339 return high << 48 | highmid << 32 | lowmid << 16 | low;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
340 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
341
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
342 void rom0_write_64(uint32_t address, jaguar_context *system, uint64_t val)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
343 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
344 address &= 0x1FFFFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
345 rom0_write_16(address, system, val >> 48);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
346 rom0_write_16(address+2, system, val >> 32);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
347 rom0_write_16(address+4, system, val >> 16);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
348 rom0_write_16(address+6, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
349 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
350
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
351 uint64_t jag_read_phrase(jaguar_context *system, uint32_t address, uint32_t *cycles)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
352 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
353 if (!system->memcon_written) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
354 //unsure of timing, but presumably at least 2 32-bit reads
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
355 //which presumably take a minimum of 1 cycle
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
356 //reality probably depends on the exact area read
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
357 //docs seem to imply some areas only 16-bits wide whereas others are 32-bit
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
358 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
359 return rom0_read_64(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
360 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
361 uint16_t *src;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
362 if (system->memcon1 & 1) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
363 if (address < 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
364 src = system->dram + (address >> 1 & (DRAM_WORDS - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
365 //DRAM is 64-bits wide, but sounds like an access is still at least two cycles
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
366 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
367 } else if (address < 0xE00000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
368 //cart is slow and only 32-bits wide
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
369 *cycles += 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
370 src = system->cart + (address >> 1 & (system->cart_size - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
371 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
372 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
373 return rom0_read_64(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
374 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
375 } else if (address > 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
376 src = system->dram + (address >> 1 & (DRAM_WORDS - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
377 //DRAM is 64-bits wide, but sounds like an access is still at least two cycles
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
378 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
379 } else if (address > 0x200000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
380 //cart is slow and only 32-bits wide
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
381 *cycles += 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
382 src = system->cart + (address >> 1 & (system->cart_size - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
383 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
384 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
385 return rom0_read_64(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
386 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
387 uint64_t high = src[0];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
388 uint64_t highmid = src[1];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
389 uint64_t lowmid = src[2];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
390 uint64_t low = src[3];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
391 return high << 48 | highmid << 32 | lowmid << 16 | low;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
392 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
393
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
394 uint32_t jag_write_phrase(jaguar_context *system, uint32_t address, uint64_t val)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
395 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
396 if (!system->memcon_written) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
397 //unsure of timing, but presumably at least 2 32-bit reads
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
398 //which presumably take a minimum of 1 cycle
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
399 //reality probably depends on the exact area read
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
400 //docs seem to imply some areas only 16-bits wide whereas others are 32-bit
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
401 rom0_write_64(address, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
402 return 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
403 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
404 uint16_t *dst;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
405 uint32_t cycles;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
406 if (system->memcon1 & 1) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
407 if (address < 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
408 dst = system->dram + (address >> 1 & (DRAM_WORDS - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
409 //DRAM is 64-bits wide, but sounds like an access is still at least two cycles
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
410 cycles = 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
411 } else if (address < 0xE00000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
412 dst = system->cart + (address >> 1 & (system->cart_size - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
413 //cart is slow and only 32-bits wide
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
414 cycles = 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
415 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
416 rom0_write_64(address, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
417 return 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
418 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
419 } else if (address > 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
420 dst = system->dram + (address >> 1 & (DRAM_WORDS - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
421 //DRAM is 64-bits wide, but sounds like an access is still at least two cycles
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
422 cycles = 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
423 } else if (address > 0x200000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
424 dst = system->cart + (address >> 1 & (system->cart_size - 1));
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
425 //cart is slow and only 32-bits wide
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
426 cycles = 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
427 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
428 rom0_write_64(address, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
429 return 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
430 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
431 dst[0] = val >> 48;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
432 dst[1] = val >> 32;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
433 dst[2] = val >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
434 dst[3] = val;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
435 return cycles;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
436 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
437
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
438 m68k_context * sync_components(m68k_context * context, uint32_t address)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
439 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
440 jaguar_context *system = context->system;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
441 jag_video_run(system->video, context->current_cycle);
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
442 jag_update_m68k_int(system);
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
443 if (context->current_cycle > 0x10000000) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
444 context->current_cycle -= 0x10000000;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
445 system->video->cycles -= 0x10000000;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
446 }
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
447 if (context->int_ack) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
448 context->int_ack = 0;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
449 //hack until 68K core more properly supports non-autovector interrupts
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
450 context->status |= 1;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
451 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
452 jag_update_m68k_int(system);
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
453 return context;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
454 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
455
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
456
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
457 void *rom0_write_m68k(uint32_t address, void *context, uint16_t value)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
458 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
459 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
460 rom0_write_16(address, ((m68k_context *)context)->system, value);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
461 return context;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
462 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
463
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
464 uint16_t rom0_read_m68k(uint32_t address, void *context)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
465 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
466 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
467 return rom0_read_16(address, ((m68k_context *)context)->system);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
468 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
469
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
470 void *rom0_write_m68k_b(uint32_t address, void *context, uint8_t value)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
471 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
472 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
473 //seems unlikely these areas support byte access
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
474 uint16_t value16 = value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
475 value16 |= value16 << 8;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
476 rom0_write_16(address, ((m68k_context *)context)->system, value16);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
477 return context;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
478 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
479
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
480 uint8_t rom0_read_m68k_b(uint32_t address, void *context)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
481 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
482 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
483 uint16_t value = rom0_read_16(address, ((m68k_context *)context)->system);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
484 if (address & 1) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
485 return value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
486 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
487 return value >> 8;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
488 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
489
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
490 m68k_context *handle_m68k_reset(m68k_context *context)
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
491 {
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
492 puts("M68K executed RESET");
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
493 return context;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
494 }
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
495
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
496 jaguar_context *init_jaguar(uint16_t *bios, uint32_t bios_size, uint16_t *cart, uint32_t cart_size)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
497 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
498 jaguar_context *system = calloc(1, sizeof(jaguar_context));
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
499 system->bios = bios;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
500 system->bios_size = bios_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
501 system->cart = cart;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
502 system->cart_size = cart_size;
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
503 //TODO: Figure out a better default for this and make it configurable
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
504 system->max_cycles = 3000;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
505
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
506 memmap_chunk *jag_m68k_map = calloc(8, sizeof(memmap_chunk));
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
507 for (uint32_t start = 0, index=0; index < 8; index++, start += 0x200000)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
508 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
509 jag_m68k_map[index].start = start;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
510 jag_m68k_map[index].end = start + 0x200000;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
511 jag_m68k_map[index].mask = index ? 0x1FFFFF : 0xFFFFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
512 jag_m68k_map[index].aux_mask = bios_size - 1;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
513 jag_m68k_map[index].ptr_index = index;
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
514 jag_m68k_map[index].flags = MMAP_READ | MMAP_WRITE | MMAP_PTR_IDX | MMAP_FUNC_NULL | MMAP_AUX_BUFF | MMAP_CODE;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
515 jag_m68k_map[index].buffer = bios;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
516 jag_m68k_map[index].read_16 = rom0_read_m68k;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
517 jag_m68k_map[index].read_8 = rom0_read_m68k_b;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
518 jag_m68k_map[index].write_16 = rom0_write_m68k;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
519 jag_m68k_map[index].write_8 = rom0_write_m68k_b;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
520 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
521 m68k_options *opts = malloc(sizeof(m68k_options));
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
522 init_m68k_opts(opts, jag_m68k_map, 8, 2);
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
523 system->m68k = init_68k_context(opts, handle_m68k_reset);
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1094
diff changeset
524 system->m68k->sync_cycle = system->max_cycles;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
525 system->m68k->system = system;
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
526 system->video = jag_video_init();
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
527 system->video->system = system;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
528 return system;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
529 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
530
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
531 //modified copy of the version in blastem.c
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
532 uint16_t *load_rom(char * filename, uint32_t *size)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
533 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
534 FILE * f = fopen(filename, "rb");
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
535 if (!f) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
536 return 0;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
537 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
538 fseek(f, 0, SEEK_END);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
539 long filesize = ftell(f);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
540 fseek(f, 0, SEEK_SET);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
541
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
542 *size = nearest_pow2(filesize);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
543 uint16_t *cart = malloc(*size);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
544 if (filesize != fread(cart, 1, filesize, f)) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
545 fatal_error("Error reading from %s\n", filename);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
546 }
1083
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
547 filesize = (filesize + 1) & ~1L;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
548 for (long i = 0; i < filesize; i+=2)
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
549 {
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
550 long index = i >> 1;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
551 cart[index] = cart[index] >> 8 | cart[index] << 8;
f6e998227300 Byteswap ROMs in jaguar ROM loader. Handle switching memory map from writes to memcon1. Fix some typos in error messages
Michael Pavone <pavone@retrodev.com>
parents: 1080
diff changeset
552 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
553 while (filesize < *size)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
554 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
555 cart[filesize / 2] = 0xFFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
556 filesize += 2;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
557 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
558 fclose(f);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
559 return cart;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
560 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
561
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
562 //temporary main function until I clean up blastem.c
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
563 int main(int argc, char **argv)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
564 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
565 if (argc < 3) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
566 fputs("Usage: blastjag BIOS ROM\n", stderr);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
567 return 1;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
568 }
1085
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
569 set_exe_str(argv[0]);
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
570 config = load_config(argv[0]);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
571 uint32_t bios_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
572 uint16_t *bios = load_rom(argv[1], &bios_size);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
573 if (!bios_size) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
574 fatal_error("Failed to read BIOS from %s\n", argv[1]);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
575 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
576 uint32_t cart_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
577 uint16_t *cart = load_rom(argv[2], &cart_size);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
578 if (!bios_size) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
579 fatal_error("Failed to read cart from %s\n", argv[2]);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
580 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
581 jaguar_context *system = init_jaguar(bios, bios_size, cart, cart_size);
1114
b45d1f64060e Fix blastjag target
Michael Pavone <pavone@retrodev.com>
parents: 1100
diff changeset
582 render_init(640, 480, "BlastJag", 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
583 m68k_reset(system->m68k);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
584 return 0;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
585 }