1 /*
2  * libtilemcore - Graphing calculator emulation library
3  *
4  * Copyright (C) 2001 Solignac Julien
5  * Copyright (C) 2004-2011 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 "x4.h"
30 
x4_reset(TilemCalc * calc)31 void x4_reset(TilemCalc* calc)
32 {
33 	calc->hwregs[PORT3] = 0x0B;
34 	calc->hwregs[PORT4] = 0x07;
35 	calc->hwregs[PORT6] = 0x3F;
36 	calc->hwregs[PORT7] = 0x3F;
37 
38 	calc->mempagemap[0] = 0x00;
39 	calc->mempagemap[1] = 0x3E;
40 	calc->mempagemap[2] = 0x3F;
41 	calc->mempagemap[3] = 0x3F;
42 
43 	calc->z80.r.pc.d = 0x8000;
44 
45 	calc->hwregs[PORT8] = 0x80;
46 
47 	calc->hwregs[PORT20] = 0;
48 	calc->hwregs[PORT21] = 0;
49 	calc->hwregs[PORT22] = 0x08;
50 	calc->hwregs[PORT23] = 0x29;
51 	calc->hwregs[PORT25] = 0x10;
52 	calc->hwregs[PORT26] = 0x20;
53 	calc->hwregs[PORT27] = 0;
54 	calc->hwregs[PORT28] = 0;
55 	calc->hwregs[PORT29] = 0x14;
56 	calc->hwregs[PORT2A] = 0x27;
57 	calc->hwregs[PORT2B] = 0x2F;
58 	calc->hwregs[PORT2C] = 0x3B;
59 	calc->hwregs[PORT2D] = 0x01;
60 	calc->hwregs[PORT2E] = 0x44;
61 	calc->hwregs[PORT2F] = 0x4A;
62 
63 	calc->hwregs[FLASH_READ_DELAY] = 0;
64 	calc->hwregs[FLASH_WRITE_DELAY] = 0;
65 	calc->hwregs[FLASH_EXEC_DELAY] = 0;
66 	calc->hwregs[RAM_READ_DELAY] = 0;
67 	calc->hwregs[RAM_WRITE_DELAY] = 0;
68 	calc->hwregs[RAM_EXEC_DELAY] = 0;
69 	calc->hwregs[LCD_PORT_DELAY] = 5;
70 	calc->hwregs[NO_EXEC_RAM_MASK] = 0x7C00;
71 	calc->hwregs[NO_EXEC_RAM_LOWER] = 0x4000;
72 	calc->hwregs[NO_EXEC_RAM_UPPER] = 0x8000;
73 
74 	calc->hwregs[PROTECTSTATE] = 0;
75 
76 	tilem_z80_set_speed(calc, 6000);
77 
78 	tilem_z80_set_timer(calc, TIMER_INT1, 1600, 9277, 1);
79 	tilem_z80_set_timer(calc, TIMER_INT2A, 1300, 9277, 1);
80 	tilem_z80_set_timer(calc, TIMER_INT2B, 1000, 9277, 1);
81 }
82 
x4_stateloaded(TilemCalc * calc,int savtype TILEM_ATTR_UNUSED)83 void x4_stateloaded(TilemCalc* calc, int savtype TILEM_ATTR_UNUSED)
84 {
85 	tilem_calc_fix_certificate(calc, calc->mem + (0x3E * 0x4000L),
86 	                           0x29, 0x0c, 0x1e50);
87 }
88