Path: blob/master/libsnes/bsnes/snes/chip/icd2/mmio/mmio.cpp
2 views
#ifdef ICD2_CPP12//convert linear pixel data { 0x00, 0x55, 0xaa, 0xff } to 2bpp planar tiledata3void ICD2::render(const uint16 *source) {4memset(lcd.output, 0x00, 320 * sizeof(uint16));56for(unsigned y = 0; y < 8; y++) {7for(unsigned x = 0; x < 160; x++) {8unsigned pixel = *source++;9unsigned addr = y * 2 + (x / 8 * 16);10lcd.output[addr + 0] |= ((pixel & 1) >> 0) << (7 - (x & 7));11lcd.output[addr + 1] |= ((pixel & 2) >> 1) << (7 - (x & 7));12}13}14}1516uint8 ICD2::read(unsigned addr) {17addr &= 0xffff;1819//LY counter20if(addr == 0x6000) {21r6000_ly = GameBoy::lcd.status.ly;22r6000_row = lcd.row;23return r6000_ly;24}2526//command ready port27if(addr == 0x6002) {28bool data = packetsize > 0;29if(data) {30for(unsigned i = 0; i < 16; i++) r7000[i] = packet[0][i];31packetsize--;32for(unsigned i = 0; i < packetsize; i++) packet[i] = packet[i + 1];33}34return data;35}3637//ICD2 revision38if(addr == 0x600f) {39return 0x21;40}4142//command port43if((addr & 0xfff0) == 0x7000) {44return r7000[addr & 15];45}4647//VRAM port48if(addr == 0x7800) {49uint8 data = lcd.output[r7800];50r7800 = (r7800 + 1) % 320;51return data;52}5354return 0x00;55}5657void ICD2::write(unsigned addr, uint8 data) {58addr &= 0xffff;5960//VRAM port61if(addr == 0x6001) {62r6001 = data;63r7800 = 0;6465unsigned offset = (r6000_row - (4 - (r6001 - (r6000_ly & 3)))) & 3;66render(lcd.buffer + offset * 160 * 8);6768return;69}7071//control port72//d7: 0 = halt, 1 = reset73//d5,d4: 0 = 1-player, 1 = 2-player, 2 = 4-player, 3 = ???74//d1,d0: 0 = frequency divider (clock rate adjust)75if(addr == 0x6003) {76if((r6003 & 0x80) == 0x00 && (data & 0x80) == 0x80) {77reset();78}79switch(data & 3) {80case 0: frequency = cpu.frequency / 4; break; //fast (glitchy, even on real hardware)81case 1: frequency = cpu.frequency / 5; break; //normal82case 2: frequency = cpu.frequency / 7; break; //slow83case 3: frequency = cpu.frequency / 9; break; //very slow84}85r6003 = data;86return;87}8889if(addr == 0x6004) { r6004 = data; return; } //joypad 190if(addr == 0x6005) { r6005 = data; return; } //joypad 291if(addr == 0x6006) { r6006 = data; return; } //joypad 392if(addr == 0x6007) { r6007 = data; return; } //joypad 493}9495#endif969798