From fa41d47e1f998312d6f27a7463cc5664e0f7d376 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 9 Jan 2023 19:41:02 -0800 Subject: [PATCH] make the smpc intback interrupt do something --- main.c | 22 +++++++++++++++++++++- smpc.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 402a745..8d36ec0 100644 --- a/main.c +++ b/main.c @@ -44,7 +44,7 @@ void oci_int(void) smpc.reg.IREG0 = INTBACK__IREG0__STATUS_DISABLE; smpc.reg.IREG1 = ( INTBACK__IREG1__PERIPHERAL_DATA_ENABLE - | INTBACK__IREG1__PORT2_15BYTE + | INTBACK__IREG1__PORT2_0BYTE | INTBACK__IREG1__PORT1_15BYTE ); smpc.reg.IREG2 = INTBACK__IREG2__MAGIC; @@ -60,6 +60,26 @@ void smpc_int(void) { scu.reg.IST &= ~(IST__SMPC); + if (smpc.reg.SR & SR__PDL) { + // to get all controller data, one should check SR__NPE and send CONTINUE + // requests as needed + + // assuming SR__PDL is set and SR__P1MD is not 0-byte-mode: + // smpc.reg.OREG0 (port 1 status) + // smpc.reg.OREG1 (peripheral 1 data[0] {type,size}) + // smpc.reg.OREG2 (peripheral 1 data[1]) + + if ((smpc.reg.OREG2 & DIGITAL__1__C) == 0) { + // if C is pressed, swap the color palette + vdp2.cram.u16[1] = (0x31 << 10); // blue + vdp2.cram.u16[2] = (0x31 << 5); // green + } else { + // if C is not pressed, restore the original palette + vdp2.cram.u16[1] = (0x31 << 5); // green + vdp2.cram.u16[2] = (0x31 << 10); // blue + } + } + smpc.reg.IREG0 = INTBACK__IREG0__BREAK; } diff --git a/smpc.h b/smpc.h index 6bdf86d..e80105f 100644 --- a/smpc.h +++ b/smpc.h @@ -180,3 +180,37 @@ enum intback_ireg_bit { INTBACK__IREG2__MAGIC = (0xF0), }; + +enum sr_bit { + SR__PDL = (1 << 6), + SR__NPE = (1 << 5), + SR__RESB = (1 << 4), + SR__P2MD1 = (1 << 3), + SR__P2MD0 = (1 << 2), + SR__P1MD1 = (1 << 1), + SR__P1MD0 = (1 << 0), +#define SR__P2MD__15BYTE(sr) (((sr & 0b00001100)) == (0b00 << 2)) +#define SR__P2MD__255BYTE(sr) (((sr & 0b00001100)) == (0b01 << 2)) +#define SR__P2MD__0BYTE(sr) (((sr & 0b00001100)) == (0b11 << 2)) + +#define SR__P1MD__15BYTE(sr) (((sr & 0b00000011)) == (0b00 << 0)) +#define SR__P1MD__255BYTE(sr) (((sr & 0b00000011)) == (0b01 << 0)) +#define SR__P1MD__0BYTE(sr) (((sr & 0b00000011)) == (0b11 << 0)) +}; + +enum digital_bit { + DIGITAL__1__RIGHT = (1 << 7), + DIGITAL__1__LEFT = (1 << 6), + DIGITAL__1__DOWN = (1 << 5), + DIGITAL__1__UP = (1 << 4), + DIGITAL__1__START = (1 << 3), + DIGITAL__1__A = (1 << 2), + DIGITAL__1__C = (1 << 1), + DIGITAL__1__B = (1 << 0), + + DIGITAL__2__R = (1 << 7), + DIGITAL__2__X = (1 << 6), + DIGITAL__2__Y = (1 << 5), + DIGITAL__2__Z = (1 << 4), + DIGITAL__2__L = (1 << 3), +};