+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((data & 0xffff) << 8) | (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0100 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
+ NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP
+}
+
+static inline void inline_write_32(unsigned int address, unsigned int value) {
+ inline_write_16(address, value >> 16);
+ inline_write_16(address + 2, value);
+}
+
+static inline unsigned int inline_read_16(unsigned int address) {
+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0200 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ *(gpio + 7) = (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_RD;
+
+ while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
+ unsigned int value = *(gpio + 13);
+
+ *(gpio + 10) = 0xffffec;
+
+ return (value >> 8) & 0xffff;
+}
+
+static inline unsigned int inline_read_8(unsigned int address) {
+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0300 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ *(gpio + 7) = (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_RD;
+
+ while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
+ unsigned int value = *(gpio + 13);
+
+ *(gpio + 10) = 0xffffec;
+
+ value = (value >> 8) & 0xffff;
+
+ if ((address & 1) == 0)
+ return (value >> 8) & 0xff; // EVEN, A0=0,UDS
+ else
+ return value & 0xff; // ODD , A0=1,LDS
+}
+
+static inline unsigned int inline_read_32(unsigned int address) {
+ unsigned int a = inline_read_16(address);
+ unsigned int b = inline_read_16(address + 2);
+ return (a << 16) | b;
+}
+
+static inline uint32_t ps_read(uint8_t type, uint32_t addr) {
+ switch (type) {
+ case OP_TYPE_BYTE:
+ return inline_read_8(addr);
+ case OP_TYPE_WORD:
+ return inline_read_16(addr);
+ case OP_TYPE_LONGWORD:
+ return inline_read_32(addr);
+ }
+ // This shouldn't actually happen.
+ return 0;
+}
+
+static inline void ps_write(uint8_t type, uint32_t addr, uint32_t val) {
+ switch (type) {
+ case OP_TYPE_BYTE:
+ inline_write_8(addr, val);
+ return;
+ case OP_TYPE_WORD:
+ inline_write_16(addr, val);
+ return;
+ case OP_TYPE_LONGWORD:
+ inline_write_32(addr, val);
+ return;
+ }
+ // This shouldn't actually happen.
+ return;
+}
+
+static inline int32_t platform_read_check(uint8_t type, uint32_t addr, uint32_t *res) {
+ switch (cfg->platform->id) {
+ case PLATFORM_AMIGA:
+ switch (addr) {
+ case CIAAPRA:
+ if (mouse_hook_enabled && (mouse_buttons & 0x01)) {
+ rres = (uint32_t)ps_read(type, addr);
+ *res = (rres ^ 0x40);
+ return 1;
+ }
+ return 0;
+ break;
+ case CIAAICR:
+ if (kb_hook_enabled) {
+ rres = (uint32_t)ps_read(type, addr);
+ if (get_num_kb_queued() && (!send_keypress || send_keypress == 1)) {
+ rres |= 0x08;
+ if (!send_keypress)
+ send_keypress = 1;
+ }
+ if (send_keypress == 2) {
+ send_keypress = 0;
+ }
+ *res = rres;
+ return 1;
+ }
+ return 0;
+ break;
+ case CIAADAT:
+ if (kb_hook_enabled) {
+ rres = (uint32_t)ps_read(type, addr);
+ uint8_t c = 0, t = 0;
+ pop_queued_key(&c, &t);
+ t ^= 0x01;
+ rres = ((c << 1) | t) ^ 0xFF;
+ send_keypress = 2;
+ *res = rres;
+ return 1;
+ }
+ return 0;
+ break;
+ case JOY0DAT:
+ if (mouse_hook_enabled) {
+ unsigned short result = (mouse_dy << 8) | (mouse_dx);
+ *res = (unsigned int)result;
+ return 1;
+ }
+ return 0;
+ break;
+ case POTGOR:
+ if (mouse_hook_enabled) {
+ unsigned short result = (unsigned short)ps_read(type, addr);
+ // bit 1 rmb, bit 2 mmb
+ if (mouse_buttons & 0x06) {
+ *res = (unsigned int)((result ^ ((mouse_buttons & 0x02) << 9)) // move rmb to bit 10
+ & (result ^ ((mouse_buttons & 0x04) << 6))); // move mmb to bit 8
+ return 1;
+ }
+ *res = (unsigned int)(result & 0xfffd);
+ return 1;
+ }
+ return 0;
+ break;
+ default:
+ break;