1 /*
2  * libtilemcore - Graphing calculator emulation library
3  *
4  * Copyright (C) 2001 Solignac Julien
5  * Copyright (C) 2004-2009 Benjamin Moody
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25 
26 #include <stdio.h>
27 #include <tilem.h>
28 
29 #include "x2.h"
30 
31 #include <stdlib.h>
32 
x2_z80_wrmem(TilemCalc * calc,dword A,byte v)33 void x2_z80_wrmem(TilemCalc* calc, dword A, byte v)
34 {
35 	dword pa = 0x4000 * calc->mempagemap[(A)>>14] + (A & 0x3FFF);
36 
37 	if (pa >= 0x28000)
38 		abort();
39 
40 	if (pa >= 0x20000) {
41 		*(calc->mem + pa) = v;
42 	}
43 }
44 
45 
x2_z80_rdmem(TilemCalc * calc,dword A)46 byte x2_z80_rdmem(TilemCalc* calc, dword A)
47 {
48 	dword pa = 0x4000 * calc->mempagemap[(A)>>14] + (A & 0x3FFF);
49 	return (*(calc->mem + pa));
50 }
51 
x2_mem_ltop(TilemCalc * calc,dword A)52 dword x2_mem_ltop(TilemCalc* calc, dword A)
53 {
54 	byte page = calc->mempagemap[A >> 14];
55 	return ((page << 14) | (A & 0x3fff));
56 }
57 
x2_mem_ptol(TilemCalc * calc,dword A)58 dword x2_mem_ptol(TilemCalc* calc, dword A)
59 {
60 	byte page = A >> 14;
61 	int i;
62 
63 	for (i = 0; i < 4; i++) {
64 		if (calc->mempagemap[i] == page) {
65 			return ((i << 14) | (A & 0x3fff));
66 		}
67 	}
68 
69 	return (0xffffffff);
70 }
71