1 #include "burnint.h"
2 #include "tlcs90_intf.h"
3 
4 static UINT8 (*read)(UINT32) = NULL;
5 static void (*write)(UINT32, UINT8) = NULL;
6 static UINT8 (*readio)(UINT16) = NULL;
7 static void (*writeio)(UINT16, UINT8) = NULL;
8 
9 static UINT8 *mem[2][0x1000]; // only read/fetch & write
10 
11 extern void t90_internal_registers_w(UINT16 offset, UINT8 data);
12 extern UINT8 t90_internal_registers_r(UINT16 offset);
13 INT32 tlcs90_init(INT32 clock);
14 
15 cpu_core_config tlcs90Config =
16 {
17 	tlcs90Open,
18 	tlcs90Close,
19 	tlcs90CheatRead,
20 	tlcs90WriteROM,
21 	tlcs90GetActive,
22 	tlcs90TotalCycles,
23 	tlcs90NewFrame,
24 	tlcs90Run,
25 	tlcs90RunEnd,
26 	tlcs90Reset,
27 	0x100000,
28 	0
29 };
30 
tlcs90_program_read_byte(UINT32 address)31 UINT8 tlcs90_program_read_byte(UINT32 address)
32 {
33 	address &= 0xfffff;
34 
35 	// internal registers!!!!!!!!!!!!!!!!!
36 	if (address >= 0xffc0 && address <= 0xffef) {
37 		return t90_internal_registers_r(address & 0x3f);
38 	}
39 
40 	if (mem[0][(address / 0x100)] != NULL) {
41 		return mem[0][(address / 0x100)][address & 0xff];
42 	}
43 
44 	if (read) {
45 		return read(address);
46 	}
47 
48 	return 0;
49 }
50 
tlcs90_program_write_byte(UINT32 address,UINT8 data)51 void tlcs90_program_write_byte(UINT32 address, UINT8 data)
52 {
53 	address &= 0xfffff;
54 
55 	// internal registers!!!!!!!!!!!!!!!!!
56 	if (address >= 0xffc0 && address <= 0xffef) {
57 		t90_internal_registers_w(address & 0x3f, data);
58 		return;
59 	}
60 
61 	if (mem[1][(address / 0x100)] != NULL) {
62 		mem[1][(address / 0x100)][address & 0xff] = data;
63 		return;
64 	}
65 
66 	if (write) {
67 		write(address, data);
68 		return;
69 	}
70 }
71 
tlcs90_io_read_byte(UINT16 port)72 UINT8 tlcs90_io_read_byte(UINT16 port)
73 {
74 	port &= 0xffff;
75 
76 //	bprintf (0, _T("Read Port: %4.4x\n"), port);
77 
78 	if (readio) {
79 		return readio(port);
80 	}
81 
82 	return 0;
83 }
84 
tlcs90_io_write_byte(UINT16 port,UINT8 data)85 void tlcs90_io_write_byte(UINT16 port, UINT8 data)
86 {
87 	port &= 0xffff;
88 
89 //	bprintf (0, _T("Write Port: %4.4x %2.2x\n"), port, data);
90 
91 	if (writeio) {
92 		return writeio(port, data);
93 	}
94 }
95 
96 
tlcs90SetReadHandler(UINT8 (* pread)(UINT32))97 void tlcs90SetReadHandler(UINT8 (*pread)(UINT32))
98 {
99 	read = pread;
100 }
101 
tlcs90SetWriteHandler(void (* pwrite)(UINT32,UINT8))102 void tlcs90SetWriteHandler(void (*pwrite)(UINT32, UINT8))
103 {
104 	write = pwrite;
105 }
106 
tlcs90SetReadPortHandler(UINT8 (* pread)(UINT16))107 void tlcs90SetReadPortHandler(UINT8 (*pread)(UINT16))
108 {
109 	readio = pread;
110 }
111 
tlcs90SetWritePortHandler(void (* pwrite)(UINT16,UINT8))112 void tlcs90SetWritePortHandler(void (*pwrite)(UINT16, UINT8))
113 {
114 	writeio = pwrite;
115 }
116 
tlcs90MapMemory(UINT8 * ptr,UINT32 start,UINT32 end,INT32 flags)117 void tlcs90MapMemory(UINT8 *ptr, UINT32 start, UINT32 end, INT32 flags)
118 {
119 	start &= 0xfffff;
120 	end &= 0xfffff;
121 
122 	for (UINT32 i = start / 0x100; i < (end / 0x100) + 1; i++)
123 	{
124 		if (flags & (1 << 0)) mem[0][i] = ptr + ((i * 0x100) - start);
125 		if (flags & (1 << 1)) mem[1][i] = ptr + ((i * 0x100) - start);
126 	}
127 }
128 
tlcs90CheatRead(UINT32 address)129 UINT8 tlcs90CheatRead(UINT32 address)
130 {
131 	return tlcs90_program_read_byte(address);
132 }
133 
tlcs90WriteROM(UINT32 address,UINT8 data)134 void tlcs90WriteROM(UINT32 address, UINT8 data)
135 {
136 	if (mem[0][(address / 0x100)] != NULL) {
137 		mem[0][(address / 0x100)][address & 0xff] = data;
138 	}
139 
140 	if (mem[1][(address / 0x100)] != NULL) {
141 		mem[1][(address / 0x100)][address & 0xff] = data;
142 	}
143 }
144 
tlcs90GetActive()145 INT32 tlcs90GetActive()
146 {
147 	return 0; // only one for now
148 }
149 
tlcs90Open(INT32)150 void tlcs90Open(INT32)
151 {
152 	// only one cpu for now
153 }
154 
tlcs90Close()155 void tlcs90Close()
156 {
157 
158 }
159 
tlcs90Init(INT32,INT32 clock)160 INT32 tlcs90Init(INT32, INT32 clock)
161 {
162 	memset (mem, 0, 2 * 0x1000 * sizeof(UINT8 *));
163 
164 	read = NULL;
165 	write = NULL;
166 	readio = NULL;
167 	writeio = NULL;
168 
169 	CpuCheatRegister(0, &tlcs90Config);
170 
171 	return tlcs90_init(clock);
172 }
173 
tlcs90Exit()174 INT32 tlcs90Exit()
175 {
176 	memset (mem, 0, 2 * 0x1000 * sizeof(UINT8 *));
177 	read = NULL;
178 	write = NULL;
179 	readio = NULL;
180 	writeio = NULL;
181 
182 	return 0;
183 }
184 
185 
186