Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Begin SIO
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Apr 3, 2013
1 parent 0e0414a commit f62eeb2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
1 change: 1 addition & 0 deletions console.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script src="js/video/software.js"></script>
<script src="js/irq.js"></script>
<script src="js/keypad.js"></script>
<script src="js/sio.js"></script>
<script src="js/savedata.js"></script>
<script src="js/gpio.js"></script>
<script src="js/gba.js"></script>
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="js/video/software.js"></script>
<script src="js/irq.js"></script>
<script src="js/keypad.js"></script>
<script src="js/sio.js"></script>
<script src="js/savedata.js"></script>
<script src="js/gpio.js"></script>
<script src="js/gba.js"></script>
Expand Down
5 changes: 5 additions & 0 deletions js/gba.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function GameBoyAdvance() {
this.audio = new GameBoyAdvanceAudio();
this.video = new GameBoyAdvanceVideo();
this.keypad = new GameBoyAdvanceKeypad();
this.sio = new GameBoyAdvanceSIO();

// TODO: simplify this graph
this.cpu.mmu = this.mmu;
Expand All @@ -36,6 +37,7 @@ function GameBoyAdvance() {
this.io.audio = this.audio;
this.io.video = this.video;
this.io.keypad = this.keypad;
this.io.sio = this.sio;
this.io.core = this;

this.audio.cpu = this.cpu;
Expand All @@ -46,6 +48,8 @@ function GameBoyAdvance() {

this.keypad.core = this;

this.sio.core = this;

this.keypad.registerHandlers();
this.doStep = this.waitFrame;
this.paused = false;
Expand Down Expand Up @@ -131,6 +135,7 @@ GameBoyAdvance.prototype.reset = function() {
this.io.clear();
this.audio.clear();
this.video.clear();
this.sio.clear();

this.mmu.mmap(this.mmu.REGION_IO, this.io);
this.mmu.mmap(this.mmu.REGION_PALETTE_RAM, this.video.renderPath.palette);
Expand Down
28 changes: 10 additions & 18 deletions js/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ function GameBoyAdvanceIO() {
this.TM3CNT_HI = 0x10E;

// SIO (note: some of these are repeated)
this.SIODATA32 = 0x120;
this.SIODATA32_LO = 0x120;
this.SIOMULTI0 = 0x120;
this.SIODATA32_HI = 0x122;
this.SIOMULTI1 = 0x122;
this.SIOMULTI2 = 0x124;
this.SIOMULTI3 = 0x126;
Expand Down Expand Up @@ -139,14 +140,7 @@ function GameBoyAdvanceIO() {
this.DEFAULT_SOUNDBIAS = 0x200;
this.DEFAULT_BGPA = 1;
this.DEFAULT_BGPD = 1;
};

GameBoyAdvanceIO.prototype.setCPU = function(cpu) {
this.cpu = cpu;
};

GameBoyAdvanceIO.prototype.setVideo = function(video) {
this.video = video;
this.DEFAULT_RCNT = 0x8000;
};

GameBoyAdvanceIO.prototype.clear = function() {
Expand All @@ -158,6 +152,7 @@ GameBoyAdvanceIO.prototype.clear = function() {
this.registers[this.BG2PD >> 1] = this.DEFAULT_BGPD;
this.registers[this.BG3PA >> 1] = this.DEFAULT_BGPA;
this.registers[this.BG3PD >> 1] = this.DEFAULT_BGPD;
this.registers[this.RCNT >> 1] = this.RCNT;
};

GameBoyAdvanceIO.prototype.freeze = function() {
Expand Down Expand Up @@ -232,6 +227,8 @@ GameBoyAdvanceIO.prototype.loadU16 = function(offset) {
case this.DMA1CNT_HI:
case this.DMA2CNT_HI:
case this.DMA3CNT_HI:
case this.RCNT:
case this.SIOCNT:
case this.WAITCNT:
case this.IE:
case this.IF:
Expand Down Expand Up @@ -274,13 +271,6 @@ GameBoyAdvanceIO.prototype.loadU16 = function(offset) {
case this.TM3CNT_LO:
return this.cpu.irq.timerRead(3);

case this.RCNT:
this.core.STUB('Reading from unimplemented RCNT');
return 0x8000;
case this.SIOCNT:
this.core.STUB('Reading from unimplemented SIOCNT');
return 0;

case this.KEYINPUT:
return this.keypad.currentDown;
case this.KEYCNT:
Expand Down Expand Up @@ -722,10 +712,12 @@ GameBoyAdvanceIO.prototype.store16 = function(offset, value) {
this.STUB_REG('SIO', offset);
break;
case this.RCNT:
this.STUB_REG('RCNT', offset);
this.sio.setMode(((value >> 12) & 0xC) | ((this.registers[this.SIOCNT >> 1] >> 12) & 0x3));
this.sio.writeRCNT(value);
break;
case this.SIOCNT:
this.STUB_REG('SIOCNT', offset);
this.sio.setMode(((value >> 12) & 0x3) | ((this.registers[this.RCNT >> 1] >> 12) & 0xC));
this.sio.writeSIOCNT(value);
break;
case this.JOYCNT:
case this.JOYSTAT:
Expand Down
54 changes: 54 additions & 0 deletions js/sio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function GameBoyAdvanceSIO() {
this.SIO_NORMAL_8 = 0;
this.SIO_NORMAL_32 = 1;
this.SIO_MULTI = 2;
this.SIO_UART = 3;
this.SIO_GPIO = 8;
this.SIO_JOYBUS = 12;
}

GameBoyAdvanceSIO.prototype.clear = function() {
this.mode = this.SIO_GPIO;
};

GameBoyAdvanceSIO.prototype.setMode = function(mode) {
if (mode & 0x8) {
mode &= 0xC;
} else {
mode &= 0x3;
}
this.mode = mode;

this.core.INFO('Setting SIO mode to ' + hex(mode, 1));
};

GameBoyAdvanceSIO.prototype.writeRCNT = function(value) {
if (mode != this.SIO_GPIO) {
return;
}

this.core.STUB('General purpose serial not supported');
};

GameBoyAdvanceSIO.prototype.writeSIOCNT = function(value) {
switch (this.mode) {
case this.SIO_NORMAL_8:
this.core.STUB('8-bit transfer unsupported');
break;
case this.SIO_NORMAL_32:
this.core.STUB('32-bit transfer unsupported');
break;
case this.SIO_MULTI:
this.core.STUB('Multiplayer unsupported');
break;
case this.SIO_UART:
this.core.STUB('UART unsupported');
break;
case this.SIO_GPIO:
// Nothing to do
break;
case this.SIO_JOYBUS:
this.core.STUB('JOY BUS unsupported');
break;
}
};

0 comments on commit f62eeb2

Please sign in to comment.