386f5371 |
1 | /* FCE Ultra - NES/Famicom Emulator\r |
2 | *\r |
3 | * Copyright notice for this file:\r |
4 | * Copyright (C) 2007 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 |
43725da7 |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
386f5371 |
19 | */\r |
20 | \r |
21 | #include "mapinc.h"\r |
22 | \r |
23 | static uint8 reg[4], IRQa;\r |
24 | static int16 IRQCount, IRQPause;\r |
25 | \r |
26 | static int16 Count = 0x0000;\r |
27 | \r |
28 | static SFORMAT StateRegs[]=\r |
29 | {\r |
30 | {reg, 4, "REGS"},\r |
31 | {&IRQa, 1, "IRQA"},\r |
32 | {&IRQCount, 2, "IRQC"},\r |
33 | {0}\r |
34 | };\r |
35 | \r |
36 | static void Sync(void)\r |
37 | {\r |
38 | setprg32(0x8000,0);\r |
39 | setchr8(0);\r |
40 | }\r |
41 | \r |
42 | //#define Count 0x1800\r |
43 | #define Pause 0x010\r |
44 | \r |
45 | static DECLFW(UNL3DBlockWrite)\r |
46 | {\r |
47 | switch(A)\r |
48 | {\r |
49 | //4800 32\r |
50 | //4900 37\r |
51 | //4a00 01\r |
52 | //4e00 18\r |
53 | case 0x4800: reg[0]=V; break;\r |
54 | case 0x4900: reg[1]=V; break;\r |
55 | case 0x4a00: reg[2]=V; break;\r |
56 | case 0x4e00: reg[3]=V; IRQCount=Count; IRQPause=Pause; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break;\r |
57 | } \r |
58 | }\r |
59 | \r |
60 | static void UNL3DBlockPower(void)\r |
61 | {\r |
62 | Sync();\r |
63 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
64 | SetWriteHandler(0x4800,0x4E00,UNL3DBlockWrite);\r |
65 | }\r |
66 | \r |
67 | static void UNL3DBlockReset(void)\r |
68 | {\r |
69 | Count+=0x10;\r |
70 | FCEU_printf("Count=%04x\n",Count);\r |
71 | }\r |
72 | \r |
43725da7 |
73 | static void FP_FASTAPASS(1) UNL3DBlockIRQHook(int a)\r |
386f5371 |
74 | {\r |
75 | if(IRQa)\r |
76 | {\r |
77 | if(IRQCount>0)\r |
78 | {\r |
79 | IRQCount-=a;\r |
80 | }\r |
81 | else\r |
82 | {\r |
83 | if(IRQPause>0)\r |
84 | {\r |
85 | IRQPause-=a;\r |
86 | X6502_IRQBegin(FCEU_IQEXT);\r |
87 | }\r |
88 | else\r |
89 | {\r |
90 | IRQCount=Count; \r |
91 | IRQPause=Pause;\r |
92 | X6502_IRQEnd(FCEU_IQEXT);\r |
93 | }\r |
94 | }\r |
95 | }\r |
96 | }\r |
97 | \r |
98 | static void StateRestore(int version)\r |
99 | {\r |
100 | Sync();\r |
101 | }\r |
102 | \r |
103 | void UNL3DBlock_Init(CartInfo *info)\r |
104 | {\r |
105 | info->Power=UNL3DBlockPower;\r |
106 | info->Reset=UNL3DBlockReset;\r |
107 | MapIRQHook=UNL3DBlockIRQHook;\r |
108 | GameStateRestore=StateRestore;\r |
109 | AddExState(&StateRegs, ~0, 0, 0);\r |
110 | }\r |