merge mapper code from FCEUX
[fceu.git] / boards / bonza.c
index 5e572f1..a618f90 100644 (file)
  *\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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
  */\r
 \r
 #include "mapinc.h"\r
 \r
+#define CARD_EXTERNAL_INSERED 0x80\r
+\r
 static uint8 prg_reg;\r
 static uint8 chr_reg;\r
-\r
-static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt;\r
-static uint16 sim0data;\r
-static uint8 sim0array[128] =\r
-{\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
-  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA,\r
-};\r
-\r
 static SFORMAT StateRegs[]=\r
 {\r
   {&prg_reg, 1, "PREG"},\r
@@ -44,6 +31,58 @@ static SFORMAT StateRegs[]=
   {0}\r
 };\r
 \r
+/*\r
+\r
+_GET_CHALLENGE:      .BYTE   0,$B4,  0,  0,$62\r
+\r
+_SELECT_FILE_1_0200: .BYTE   0,$A4,  1,  0,  2,  2,  0\r
+_SELECT_FILE_2_0201: .BYTE   0,$A4,  2,  0,  2,  2,  1\r
+_SELECT_FILE_2_0203: .BYTE   0,$A4,  2,  0,  2,  2,  3\r
+_SELECT_FILE_2_0204: .BYTE   0,$A4,  2,  0,  2,  2,  4\r
+_SELECT_FILE_2_0205: .BYTE   0,$A4,  2,  0,  2,  2,  5\r
+_SELECT_FILE_2_3F04: .BYTE   0,$A4,  2,  0,  2,$3F,  4\r
+_SELECT_FILE_2_4F00: .BYTE   0,$A4,  2,  0,  2,$4F,  0\r
+\r
+_READ_BINARY_5:      .BYTE   0,$B0,$85,  0,  2\r
+_READ_BINARY_6:      .BYTE   0,$B0,$86,  0,  4\r
+_READ_BINARY_6_0:    .BYTE   0,$B0,$86,  0,$18\r
+_READ_BINARY_0:      .BYTE   0,$B0,  0,  2,  3\r
+_READ_BINARY_0_0:    .BYTE   0,$B0,  0,  0,  4\r
+_READ_BINARY_0_1:    .BYTE   0,$B0,  0,  0, $C\r
+_READ_BINARY_0_2:    .BYTE   0,$B0,  0,  0,$10\r
+\r
+_UPDATE_BINARY:      .BYTE   0,$D6,  0,  0,  4\r
+_UPDATE_BINARY_0:    .BYTE   0,$D6,  0,  0,$10\r
+\r
+_GET_RESPONSE:       .BYTE $80,$C0,  2,$A1,  8\r
+_GET_RESPONSE_0:     .BYTE   0,$C0,  0,  0,  2\r
+_GET_RESPONSE_1:     .BYTE   0,$C0,  0,  0,  6\r
+_GET_RESPONSE_2:     .BYTE   0,$C0,  0,  0,  8\r
+_GET_RESPONSE_3:     .BYTE   0,$C0,  0,  0, $C\r
+_GET_RESPONSE_4:     .BYTE   0,$C0,  0,  0,$10\r
+\r
+byte_8C0B:           .BYTE $80,$30,  0,  2, $A,  0,  1\r
+byte_8C48:           .BYTE $80,$32,  0,  1,  4\r
+byte_8C89:           .BYTE $80,$34,  0,  0,  8,  0,  0\r
+byte_8D01:           .BYTE $80,$36,  0,  0, $C\r
+byte_8CA7:           .BYTE $80,$38,  0,  2,  4\r
+byte_8BEC:           .BYTE $80,$3A,  0,  3,  0\r
+\r
+byte_89A0:           .BYTE   0,$48,  0,  0,  6\r
+byte_8808:           .BYTE   0,$54,  0,  0,$1C\r
+byte_89BF:           .BYTE   0,$58,  0,  0,$1C\r
+\r
+_MANAGE_CHANNEL:     .BYTE   0,$70,  0,  0,  8\r
+byte_8CE5:           .BYTE   0,$74,  0,  0,$12\r
+byte_8C29:           .BYTE   0,$76,  0,  0,  8\r
+byte_8CC6:           .BYTE   0,$78,  0,  0,$12\r
+*/\r
+\r
+static uint8 sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE,\r
+                                 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53,\r
+                                 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10,\r
+                                 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; \r
+\r
 static void Sync(void)\r
 {\r
   setprg32(0x8000, prg_reg);\r
@@ -57,7 +96,6 @@ static void StateRestore(int version)
 \r
 static DECLFW(M216WriteHi)\r
 {\r
-// FCEU_printf("%04x:%04x\n",A,V);\r
   prg_reg=A&1;\r
   chr_reg=(A&0x0E)>>1;\r
   Sync();\r
@@ -65,58 +103,13 @@ static DECLFW(M216WriteHi)
 \r
 static DECLFW(M216Write5000)\r
 {\r
-// FCEU_printf("WRITE: %04x:%04x\n",A,V);\r
-  sim0reg=V;\r
-  if(!sim0reg)\r
-  {\r
-    sim0bit=sim0byte=sim0parity=0;\r
-    sim0data=sim0array[0];\r
-    sim0bcnt=0x80;\r
-  }\r
-  else if(sim0reg&0x20)\r
-  {\r
-    sim0bcnt=0x20;\r
-  }\r
+//  FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt);\r
 }\r
 \r
 static DECLFR(M216Read5000)\r
 {\r
-  if(sim0reg&0x60)\r
-  {\r
-    sim0reg=(sim0reg^(sim0reg<<1))&0x40;\r
-    return sim0reg;\r
-  }\r
-  else\r
-  {\r
-    uint8 sim0out=0;\r
-    if(sim0bit<8)\r
-    {\r
-//       sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1;\r
-      sim0out=(sim0data&1)<<6;\r
-      sim0data>>=1;\r
-      sim0bit++;\r
-      sim0parity+=sim0data;\r
-    }\r
-    else if(sim0bit==8)\r
-    {\r
-      sim0bit++;\r
-      sim0out=sim0parity&1;\r
-    }\r
-    else if(sim0bit==9)\r
-    {\r
-      if(sim0byte==sim0bcnt)\r
-        sim0out=0x60;\r
-      else\r
-      {\r
-        sim0bit=0;\r
-        sim0byte++;\r
-        sim0data=sim0array[sim0byte];\r
-        sim0out=0;\r
-      }\r
-    }\r
-//    FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte);\r
-    return sim0out;\r
-  }\r
+//    FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit);\r
+    return 0;\r
 }\r
 \r
 static void Power(void)\r