merge mappers from FCEU-mm
[fceu.git] / boards / transformer.c
CommitLineData
43725da7 1/* FCE Ultra - NES/Famicom Emulator\r
2 *\r
3 * Copyright notice for this file:\r
4 * Copyright (C) 2009 CaH4e3\r
5 *\r
6 * This program is free software; you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation; either version 2 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * This program is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with this program; if not, write to the Free Software\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
19 */\r
20\r
21#include "mapinc.h"\r
22\r
23static uint8 *WRAM=NULL;\r
24static uint32 WRAMSIZE;\r
25\r
26char *GetKeyboard(void);\r
27\r
28static char *TransformerKeys, oldkeys[256];\r
29static int TransformerCycleCount, TransformerChar = 0;\r
30\r
31static void FP_FASTAPASS(1) TransformerIRQHook(int a)\r
32{\r
33 TransformerCycleCount+=a;\r
34 if(TransformerCycleCount >= 1000)\r
35 {\r
36 uint32 i;\r
37 TransformerCycleCount -= 1000;\r
38 TransformerKeys = GetKeyboard();\r
39 \r
40 for(i=0; i<256; i++) {\r
41 if(oldkeys[i] != TransformerKeys[i]) {\r
42 if(oldkeys[i] == 0)\r
43 TransformerChar = i;\r
44 else\r
45 TransformerChar = i | 0x80;\r
46 X6502_IRQBegin(FCEU_IQEXT);\r
47 memcpy((void *)&oldkeys[0], (void *)TransformerKeys, 256);\r
48 break;\r
49 }\r
50 }\r
51 }\r
52}\r
53\r
54static DECLFR(TransformerRead)\r
55{\r
56 uint8 ret = 0;\r
57 switch(A&3) {\r
58 case 0: ret = TransformerChar & 15; break;\r
59 case 1: ret = (TransformerChar >> 4); break;\r
60 case 2: break;\r
61 case 4: break;\r
62 }\r
63 X6502_IRQEnd(FCEU_IQEXT);\r
64 return ret;\r
65}\r
66\r
67static void TransformerPower(void)\r
68{\r
69 setprg8r(0x10,0x6000,0);\r
70 setprg16(0x8000,0);\r
71 setprg16(0xC000,~0);\r
72 setchr8(0);\r
73\r
74 SetReadHandler(0x5000,0x5004,TransformerRead);\r
75 SetReadHandler(0x6000,0x7FFF,CartBR);\r
76 SetWriteHandler(0x6000,0x7FFF,CartBW);\r
77 SetReadHandler(0x8000,0xFFFF,CartBR);\r
78\r
79 MapIRQHook=TransformerIRQHook;\r
80}\r
81\r
82static void TransformerClose(void)\r
83{\r
84 if(WRAM)\r
85 FCEU_gfree(WRAM);\r
86 WRAM=NULL;\r
87}\r
88\r
89void Transformer_Init(CartInfo *info)\r
90{\r
91 info->Power=TransformerPower;\r
92 info->Close=TransformerClose;\r
93\r
94 WRAMSIZE=8192;\r
95 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
96 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
97 if(info->battery)\r
98 {\r
99 info->SaveGame[0]=WRAM;\r
100 info->SaveGameLen[0]=WRAMSIZE;\r
101 }\r
102 AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
103}\r