1/*****************************************************************************\
2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3 This file is licensed under the Snes9x License.
4 For further information, consult the LICENSE file in the root directory.
5\*****************************************************************************/
6
7#include "snes9x.h"
8#include "memmap.h"
9#include "seta.h"
10
11static uint8 board[9][9]; // shougi playboard
12static int line = 0; // line counter
13
14
15uint8 S9xGetST011 (uint32 Address)
16{
17 uint8 t;
18 uint16 address = (uint16) Address & 0xFFFF;
19
20 line++;
21
22 // status check
23 if (address == 0x01)
24 t = 0xFF;
25 else
26 t = Memory.SRAM[address]; // read directly from s-ram
27
28#ifdef DEBUGGER
29 if (address < 0x150)
30 printf("ST011 R: %06X %02X\n", Address, t);
31#endif
32
33 return (t);
34}
35
36void S9xSetST011 (uint32 Address, uint8 Byte)
37{
38 static bool reset = false;
39 uint16 address = (uint16) Address & 0xFFFF;
40
41 line++;
42
43 if (!reset)
44 {
45 // bootup values
46 ST011.waiting4command = true;
47 reset = true;
48 }
49
50#ifdef DEBUGGER
51 if (address < 0x150)
52 printf("ST011 W: %06X %02X\n", Address, Byte);
53#endif
54
55 Memory.SRAM[address] = Byte;
56
57 // op commands/data goes through this address
58 if (address == 0x00)
59 {
60 // check for new commands
61 if (ST011.waiting4command)
62 {
63 ST011.waiting4command = false;
64 ST011.command = Byte;
65 ST011.in_index = 0;
66 ST011.out_index = 0;
67
68 switch (ST011.command)
69 {
70 case 0x01: ST011.in_count = 12 * 10 + 8; break;
71 case 0x02: ST011.in_count = 4; break;
72 case 0x04: ST011.in_count = 0; break;
73 case 0x05: ST011.in_count = 0; break;
74 case 0x06: ST011.in_count = 0; break;
75 case 0x07: ST011.in_count = 0; break;
76 case 0x0E: ST011.in_count = 0; break;
77 default: ST011.waiting4command = true; break;
78 }
79 }
80 else
81 {
82 ST011.parameters[ST011.in_index] = Byte;
83 ST011.in_index++;
84 }
85 }
86
87 if (ST011.in_count == ST011.in_index)
88 {
89 // actually execute the command
90 ST011.waiting4command = true;
91 ST011.out_index = 0;
92
93 switch (ST011.command)
94 {
95 // unknown: download playboard
96 case 0x01:
97 // 9x9 board data: top to bottom, left to right
98 // Values represent piece types and ownership
99 for (int lcv = 0; lcv < 9; lcv++)
100 memcpy(board[lcv], ST011.parameters + lcv * 10, 9 * 1);
101 break;
102
103 // unknown
104 case 0x02:
105 break;
106
107 // unknown
108 case 0x04:
109 // outputs
110 Memory.SRAM[0x12C] = 0x00;
111 //Memory.SRAM[0x12D] = 0x00;
112 Memory.SRAM[0x12E] = 0x00;
113 break;
114
115 // unknown
116 case 0x05:
117 // outputs
118 Memory.SRAM[0x12C] = 0x00;
119 //Memory.SRAM[0x12D] = 0x00;
120 Memory.SRAM[0x12E] = 0x00;
121 break;
122
123 // unknown
124 case 0x06:
125 break;
126
127 case 0x07:
128 break;
129
130 // unknown
131 case 0x0E:
132 // outputs
133 Memory.SRAM[0x12C] = 0x00;
134 Memory.SRAM[0x12D] = 0x00;
135 break;
136 }
137 }
138}
139