Implement PAD registers

This commit is contained in:
Lycoder
2023-06-15 11:04:59 -03:00
parent 4e7015318d
commit b257359036
2 changed files with 47 additions and 7 deletions
+45 -7
View File
@@ -17,9 +17,13 @@ void psx_pad_init(psx_pad_t* pad) {
}
uint32_t psx_pad_read32(psx_pad_t* pad, uint32_t offset) {
log_fatal("PAD read32 %u", offset);
if (offset == 0x4) return 0x00000005;
switch (offset) {
case 0: return 0x00;
case 4: return 0x03;
case 8: return pad->mode;
case 10: return pad->ctrl;
case 14: return pad->baud;
}
log_warn("Unhandled 32-bit PAD read at offset %08x", offset);
@@ -27,8 +31,13 @@ uint32_t psx_pad_read32(psx_pad_t* pad, uint32_t offset) {
}
uint16_t psx_pad_read16(psx_pad_t* pad, uint32_t offset) {
log_fatal("PAD read16 %u", offset);
if (offset == 0x4) return 0x00000005;
switch (offset) {
case 0: return 0x00;
case 4: return 0x03;
case 8: return pad->mode;
case 10: return pad->ctrl;
case 14: return pad->baud;
}
log_warn("Unhandled 16-bit PAD read at offset %08x", offset);
@@ -36,8 +45,13 @@ uint16_t psx_pad_read16(psx_pad_t* pad, uint32_t offset) {
}
uint8_t psx_pad_read8(psx_pad_t* pad, uint32_t offset) {
log_fatal("PAD read8 %u", offset);
if (offset == 0x4) return 0x00000005;
switch (offset) {
case 0: return 0x00;
case 4: return 0x03;
case 8: return pad->mode;
case 10: return pad->ctrl;
case 14: return pad->baud;
}
log_warn("Unhandled 8-bit PAD read at offset %08x", offset);
@@ -45,14 +59,38 @@ uint8_t psx_pad_read8(psx_pad_t* pad, uint32_t offset) {
}
void psx_pad_write32(psx_pad_t* pad, uint32_t offset, uint32_t value) {
switch (offset) {
case 0: break;
case 4: break;
case 8: pad->mode = value & 0xffff; return;
case 10: pad->ctrl = value & 0xffff; return;
case 14: pad->baud = value & 0xffff; return;
}
log_warn("Unhandled 32-bit PAD write at offset %08x (%08x)", offset, value);
}
void psx_pad_write16(psx_pad_t* pad, uint32_t offset, uint16_t value) {
switch (offset) {
case 0: break;
case 4: break;
case 8: pad->mode = value; return;
case 10: pad->ctrl = value; return;
case 14: pad->baud = value; return;
}
log_warn("Unhandled 16-bit PAD write at offset %08x (%04x)", offset, value);
}
void psx_pad_write8(psx_pad_t* pad, uint32_t offset, uint8_t value) {
switch (offset) {
case 0: break;
case 4: break;
case 8: pad->mode = value; return;
case 10: pad->ctrl = value; return;
case 14: pad->baud = value; return;
}
log_warn("Unhandled 8-bit PAD write at offset %08x (%02x)", offset, value);
}
+2
View File
@@ -9,6 +9,8 @@
typedef struct {
uint32_t io_base, io_size;
uint16_t mode, ctrl, baud;
} psx_pad_t;
psx_pad_t* psx_pad_create();