Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/chip/icd2/mmio/mmio.cpp
2 views
1
#ifdef ICD2_CPP
2
3
//convert linear pixel data { 0x00, 0x55, 0xaa, 0xff } to 2bpp planar tiledata
4
void ICD2::render(const uint16 *source) {
5
memset(lcd.output, 0x00, 320 * sizeof(uint16));
6
7
for(unsigned y = 0; y < 8; y++) {
8
for(unsigned x = 0; x < 160; x++) {
9
unsigned pixel = *source++;
10
unsigned addr = y * 2 + (x / 8 * 16);
11
lcd.output[addr + 0] |= ((pixel & 1) >> 0) << (7 - (x & 7));
12
lcd.output[addr + 1] |= ((pixel & 2) >> 1) << (7 - (x & 7));
13
}
14
}
15
}
16
17
uint8 ICD2::read(unsigned addr) {
18
addr &= 0xffff;
19
20
//LY counter
21
if(addr == 0x6000) {
22
r6000_ly = GameBoy::lcd.status.ly;
23
r6000_row = lcd.row;
24
return r6000_ly;
25
}
26
27
//command ready port
28
if(addr == 0x6002) {
29
bool data = packetsize > 0;
30
if(data) {
31
for(unsigned i = 0; i < 16; i++) r7000[i] = packet[0][i];
32
packetsize--;
33
for(unsigned i = 0; i < packetsize; i++) packet[i] = packet[i + 1];
34
}
35
return data;
36
}
37
38
//ICD2 revision
39
if(addr == 0x600f) {
40
return 0x21;
41
}
42
43
//command port
44
if((addr & 0xfff0) == 0x7000) {
45
return r7000[addr & 15];
46
}
47
48
//VRAM port
49
if(addr == 0x7800) {
50
uint8 data = lcd.output[r7800];
51
r7800 = (r7800 + 1) % 320;
52
return data;
53
}
54
55
return 0x00;
56
}
57
58
void ICD2::write(unsigned addr, uint8 data) {
59
addr &= 0xffff;
60
61
//VRAM port
62
if(addr == 0x6001) {
63
r6001 = data;
64
r7800 = 0;
65
66
unsigned offset = (r6000_row - (4 - (r6001 - (r6000_ly & 3)))) & 3;
67
render(lcd.buffer + offset * 160 * 8);
68
69
return;
70
}
71
72
//control port
73
//d7: 0 = halt, 1 = reset
74
//d5,d4: 0 = 1-player, 1 = 2-player, 2 = 4-player, 3 = ???
75
//d1,d0: 0 = frequency divider (clock rate adjust)
76
if(addr == 0x6003) {
77
if((r6003 & 0x80) == 0x00 && (data & 0x80) == 0x80) {
78
reset();
79
}
80
switch(data & 3) {
81
case 0: frequency = cpu.frequency / 4; break; //fast (glitchy, even on real hardware)
82
case 1: frequency = cpu.frequency / 5; break; //normal
83
case 2: frequency = cpu.frequency / 7; break; //slow
84
case 3: frequency = cpu.frequency / 9; break; //very slow
85
}
86
r6003 = data;
87
return;
88
}
89
90
if(addr == 0x6004) { r6004 = data; return; } //joypad 1
91
if(addr == 0x6005) { r6005 = data; return; } //joypad 2
92
if(addr == 0x6006) { r6006 = data; return; } //joypad 3
93
if(addr == 0x6007) { r6007 = data; return; } //joypad 4
94
}
95
96
#endif
97
98