annotate jaguar.c @ 1094:1dba006bad47

Get Jaguar disassembler more or less working. Dump gpu program to file when GPU GO bit is set
author Michael Pavone <pavone@retrodev.com>
date Mon, 31 Oct 2016 09:23:25 -0700
parents f338c950fcef
children faa3a4617f62
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"
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "jaguar.h"
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #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
8 #include "debug.h"
1085
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
9 #include "config.h"
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
10 #include "render.h"
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 //BIOS Area Memory map
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 // 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
14 // 10 04 00 - 10 08 00 : CLUT
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 // 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
16 // 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
17 // 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
18 // 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
19 // 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
20 // 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
21 // 11 40 00 - 11 40 04 : Joystick Interface
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 // 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
23 // 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
24 // 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
25
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 int headless = 1;
1085
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
27 tern_node * config;
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
28
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
29 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
30 {
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 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
34 {
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 void handle_joydown(int joystick, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
38 {
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 void handle_joyup(int joystick, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
42 {
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 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
46 {
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 void handle_mousedown(int mouse, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
50 {
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 void handle_mouseup(int mouse, int button)
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
54 {
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 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
58 {
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
59 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 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
63 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 //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
65 //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
66 if (address < 0x100000 || address >= 0x120000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 //Boot ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 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
69 return;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 if (address < 0x103000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 if (address < 0x101000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 if (address < 0x100400) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 //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
75 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
76 {
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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84 //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
85 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
86
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
87 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
88 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
89 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
90 system->memcon_written = 1;
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
91 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
92 switch (system->memcon1 >> 3 & 3)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
93 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
94 case 0:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
95 system->rom_cycles = 10;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
96 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
97 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
98 system->rom_cycles = 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
99 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
100 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
101 system->rom_cycles = 6;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
102 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
103 case 3:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
104 system->rom_cycles = 5;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
105 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
106 }
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
107 //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
108 }
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 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
110 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
111 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
112 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
113 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
114 default:
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
115 jag_video_reg_write(system->video, address, value);
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
116 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
117 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 } else if (address < 0x100800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 //CLUT
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 address = address >> 1 & 255;
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
121 system->video->clut[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 //Line buffer A
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
126 system->video->line_buffer_a[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 } else if (address < 0x101800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 //Line buffer B
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
133 system->video->line_buffer_b[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 } else if (address < 0x102100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 //Write Line Buffer
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
139 system->video->write_line_buffer[address] = value;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 //GPU/Blitter registers
1092
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
143 if (address < 0x102200) {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
144 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
145 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
146 FILE *f = fopen("gpu.bin", "wb");
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
147 fwrite(system->gpu_local, 1, sizeof(system->gpu_local), 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
148 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
149 }
1092
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
150 } else {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
151 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
152 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 } else if (address < 0x11A100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 if (address < 0x110000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 //GPU Local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 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
158 uint32_t value32 = value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 system->gpu_local[offset] &= 0xFFFF0000;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 system->gpu_local[offset] &= 0x0000FFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 value32 = value32 << 16;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 system->gpu_local[offset] |= value32;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 } else if (address < 0x114000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 //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
168 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
169 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 //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
171 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
172 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 } else if (address < 0x11B000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 //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
175 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
176 } else if (address < 0x11D000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 //DSP local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 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
179 uint32_t value32 = value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 system->dsp_local[offset] &= 0xFFFF0000;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 system->dsp_local[offset] &= 0x0000FFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 value32 = value32 << 16;
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 system->gpu_local[offset] |= value32;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 //Wave table ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 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
190 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 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
194 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 if (address < 0x100000 || address >= 0x120000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 //Boot ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 address = address >> 1 & ((system->bios_size >> 1) - 1);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 return system->bios[address];
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 if (address < 0x103000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 if (address < 0x101000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 if (address < 0x100400) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 //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
204 fprintf(stderr, "Unhandled read from video mode/memory control registers - %X\n", address);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 } else if (address < 0x100800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 //CLUT
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 address = address >> 1 & 255;
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
208 return system->video->clut[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 //Line buffer A
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
213 return system->video->line_buffer_a[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 } else if (address < 0x101800) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 //Line buffer B
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
220 return system->video->line_buffer_b[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 } else if (address < 0x102100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 //Write Line Buffer
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
224 address = address >> 1 & 0x3FF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 if (address < LINEBUFFER_WORDS) {
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
226 return system->video->write_line_buffer[address];
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 //GPU/Blitter registers
1092
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
230 if (address < 0x102200) {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
231 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
232 } else {
f338c950fcef Slightly more detailed logging of unhandled register writes
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
233 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
234 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 } else if (address < 0x11A100) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 if (address < 0x110000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 //GPU Local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 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
240 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 return system->gpu_local[offset];
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 return system->gpu_local[offset] >> 16;
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 } else if (address < 0x114000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 //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
247 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
248 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 //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
250 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
251 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 } else if (address < 0x11B000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 //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
254 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
255 } else if (address < 0x11D000) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 //DSP local RAM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 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
258 if (address & 2) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 return system->dsp_local[offset];
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 return system->dsp_local[offset] >> 16;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
263 } else {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
264 //Wave table ROM
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 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
266 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 return 0xFFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
270 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
271 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
272 address &= 0x1FFFFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
273 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
274 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
275 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
276 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
277 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
278 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
279
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
280 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
281 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
282 address &= 0x1FFFFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
283 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
284 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
285 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
286 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
287 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
288
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
289 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
290 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
291 if (!system->memcon_written) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
292 //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
293 //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
294 //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
295 //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
296 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
297 return rom0_read_64(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
298 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
299 uint16_t *src;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
300 if (system->memcon1 & 1) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
301 if (address < 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
302 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
303 //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
304 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
305 } else if (address < 0xE00000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
306 //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
307 *cycles += 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
308 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
309 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
310 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
311 return rom0_read_64(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
312 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
313 } else if (address > 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
314 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
315 //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
316 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
317 } else if (address > 0x200000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
318 //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
319 *cycles += 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
320 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
321 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
322 *cycles += 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
323 return rom0_read_64(address, system);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
324 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
325 uint64_t high = src[0];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
326 uint64_t highmid = src[1];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
327 uint64_t lowmid = src[2];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
328 uint64_t low = src[3];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
329 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
330 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
331
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
332 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
333 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
334 if (!system->memcon_written) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
335 //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
336 //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
337 //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
338 //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
339 rom0_write_64(address, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
340 return 2;
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 uint16_t *dst;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
343 uint32_t cycles;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
344 if (system->memcon1 & 1) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
345 if (address < 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
346 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
347 //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
348 cycles = 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
349 } else if (address < 0xE00000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
350 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
351 //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
352 cycles = 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
353 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
354 rom0_write_64(address, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
355 return 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
356 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
357 } else if (address > 0x800000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
358 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
359 //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
360 cycles = 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
361 } else if (address > 0x200000) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
362 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
363 //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
364 cycles = 2 * (system->rom_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
365 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
366 rom0_write_64(address, system, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
367 return 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
368 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
369 dst[0] = val >> 48;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
370 dst[1] = val >> 32;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
371 dst[2] = val >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
372 dst[3] = val;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
373 return cycles;
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
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
376 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
377 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
378 jaguar_context *system = context->system;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
379 jag_video_run(system->video, context->current_cycle);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
380 if (context->current_cycle > 0x10000000) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
381 context->current_cycle -= 0x10000000;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
382 system->video->cycles -= 0x10000000;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
383 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
384 return context;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
385 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
386
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
387
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
388 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
389 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
390 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 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
392 return context;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
393 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
394
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 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
396 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
397 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
398 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
399 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
400
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
401 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
402 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
403 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
404 //seems unlikely these areas support byte access
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
405 uint16_t value16 = value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
406 value16 |= value16 << 8;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
407 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
408 return context;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
409 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
410
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
411 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
412 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
413 sync_components(context, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
414 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
415 if (address & 1) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
416 return value;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
417 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
418 return value >> 8;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
419 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
420
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
421 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
422 {
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
423 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
424 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
425 }
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
426
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
427 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
428 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
429 jaguar_context *system = calloc(1, sizeof(jaguar_context));
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
430 system->bios = bios;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
431 system->bios_size = bios_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
432 system->cart = cart;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
433 system->cart_size = cart_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
434
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
435 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
436 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
437 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
438 jag_m68k_map[index].start = start;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
439 jag_m68k_map[index].end = start + 0x200000;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
440 jag_m68k_map[index].mask = index ? 0x1FFFFF : 0xFFFFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
441 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
442 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
443 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
444 jag_m68k_map[index].buffer = bios;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
445 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
446 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
447 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
448 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
449 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
450 m68k_options *opts = malloc(sizeof(m68k_options));
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
451 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
452 system->m68k = init_68k_context(opts, handle_m68k_reset);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
453 system->m68k->system = system;
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents: 1085
diff changeset
454 system->video = jag_video_init();
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
455 system->video->system = system;
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
456 return system;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
457 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
458
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
459 //modified copy of the version in blastem.c
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
460 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
461 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
462 FILE * f = fopen(filename, "rb");
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
463 if (!f) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
464 return 0;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
465 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
466 fseek(f, 0, SEEK_END);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
467 long filesize = ftell(f);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
468 fseek(f, 0, SEEK_SET);
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 *size = nearest_pow2(filesize);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
471 uint16_t *cart = malloc(*size);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
472 if (filesize != fread(cart, 1, filesize, f)) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
473 fatal_error("Error reading from %s\n", filename);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
474 }
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
475 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
476 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
477 {
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
478 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
479 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
480 }
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
481 while (filesize < *size)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
482 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
483 cart[filesize / 2] = 0xFFFF;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
484 filesize += 2;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
485 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
486 fclose(f);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
487 return cart;
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
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
490 //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
491 int main(int argc, char **argv)
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
492 {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
493 if (argc < 3) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
494 fputs("Usage: blastjag BIOS ROM\n", stderr);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
495 return 1;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
496 }
1085
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
497 set_exe_str(argv[0]);
bc86eaf6699d Fix some unresolved symbols when linking blastjag
Michael Pavone <pavone@retrodev.com>
parents: 1083
diff changeset
498 config = load_config(argv[0]);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
499 uint32_t bios_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
500 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
501 if (!bios_size) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
502 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
503 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
504 uint32_t cart_size;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
505 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
506 if (!bios_size) {
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
507 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
508 }
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
509 jaguar_context *system = init_jaguar(bios, bios_size, cart, cart_size);
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
510 render_init(640, 480, "BlastJag", 60, 0);
1080
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
511 m68k_reset(system->m68k);
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
512 return 0;
382614130914 Some initial work on Atari Jaguar emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
513 }