--- /dev/null
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ * Copyright (C) 2009 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+char *GetKeyboard(void);\r
+\r
+static char *TransformerKeys, oldkeys[256];\r
+static int TransformerCycleCount, TransformerChar = 0;\r
+\r
+static void FP_FASTAPASS(1) TransformerIRQHook(int a)\r
+{\r
+ TransformerCycleCount+=a;\r
+ if(TransformerCycleCount >= 1000)\r
+ {\r
+ uint32 i;\r
+ TransformerCycleCount -= 1000;\r
+ TransformerKeys = GetKeyboard();\r
+ \r
+ for(i=0; i<256; i++) {\r
+ if(oldkeys[i] != TransformerKeys[i]) {\r
+ if(oldkeys[i] == 0)\r
+ TransformerChar = i;\r
+ else\r
+ TransformerChar = i | 0x80;\r
+ X6502_IRQBegin(FCEU_IQEXT);\r
+ memcpy((void *)&oldkeys[0], (void *)TransformerKeys, 256);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+static DECLFR(TransformerRead)\r
+{\r
+ uint8 ret = 0;\r
+ switch(A&3) {\r
+ case 0: ret = TransformerChar & 15; break;\r
+ case 1: ret = (TransformerChar >> 4); break;\r
+ case 2: break;\r
+ case 4: break;\r
+ }\r
+ X6502_IRQEnd(FCEU_IQEXT);\r
+ return ret;\r
+}\r
+\r
+static void TransformerPower(void)\r
+{\r
+ setprg8r(0x10,0x6000,0);\r
+ setprg16(0x8000,0);\r
+ setprg16(0xC000,~0);\r
+ setchr8(0);\r
+\r
+ SetReadHandler(0x5000,0x5004,TransformerRead);\r
+ SetReadHandler(0x6000,0x7FFF,CartBR);\r
+ SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+\r
+ MapIRQHook=TransformerIRQHook;\r
+}\r
+\r
+static void TransformerClose(void)\r
+{\r
+ if(WRAM)\r
+ FCEU_gfree(WRAM);\r
+ WRAM=NULL;\r
+}\r
+\r
+void Transformer_Init(CartInfo *info)\r
+{\r
+ info->Power=TransformerPower;\r
+ info->Close=TransformerClose;\r
+\r
+ WRAMSIZE=8192;\r
+ WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+ SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+ if(info->battery)\r
+ {\r
+ info->SaveGame[0]=WRAM;\r
+ info->SaveGameLen[0]=WRAMSIZE;\r
+ }\r
+ AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+}\r