| 1 | /*\r |
| 2 | * PicoDrive\r |
| 3 | * (C) notaz, 2006-2009\r |
| 4 | *\r |
| 5 | * This work is licensed under the terms of MAME license.\r |
| 6 | * See COPYING file in the top-level directory.\r |
| 7 | */\r |
| 8 | \r |
| 9 | .equ SRR_MAPPED, (1 << 0)\r |
| 10 | .equ SRR_READONLY, (1 << 1)\r |
| 11 | .equ SRF_EEPROM, (1 << 1)\r |
| 12 | .equ POPT_EN_32X, (1 << 20)\r |
| 13 | \r |
| 14 | .text\r |
| 15 | .align 4\r |
| 16 | \r |
| 17 | .global PicoRead8_sram\r |
| 18 | .global PicoRead8_io\r |
| 19 | .global PicoRead16_sram\r |
| 20 | .global PicoRead16_io\r |
| 21 | .global PicoWrite8_io\r |
| 22 | .global PicoWrite16_io\r |
| 23 | \r |
| 24 | PicoRead8_sram: @ u32 a, u32 d\r |
| 25 | ldr r2, =(SRam)\r |
| 26 | ldr r3, =(Pico+0x22200)\r |
| 27 | ldr r1, [r2, #8] @ SRam.end\r |
| 28 | cmp r0, r1\r |
| 29 | bgt m_read8_nosram\r |
| 30 | ldr r1, [r2, #4] @ SRam.start\r |
| 31 | cmp r0, r1\r |
| 32 | blt m_read8_nosram\r |
| 33 | ldrb r1, [r3, #0x11] @ Pico.m.sram_reg\r |
| 34 | tst r1, #SRR_MAPPED\r |
| 35 | beq m_read8_nosram\r |
| 36 | ldr r1, [r2, #0x0c]\r |
| 37 | tst r1, #SRF_EEPROM\r |
| 38 | bne m_read8_eeprom\r |
| 39 | ldr r1, [r2, #4] @ SRam.start\r |
| 40 | ldr r2, [r2] @ SRam.data\r |
| 41 | sub r0, r0, r1\r |
| 42 | add r0, r0, r2\r |
| 43 | ldrb r0, [r0]\r |
| 44 | bx lr\r |
| 45 | \r |
| 46 | m_read8_nosram:\r |
| 47 | ldr r1, [r3, #4] @ romsize\r |
| 48 | cmp r0, r1\r |
| 49 | movgt r0, #0\r |
| 50 | bxgt lr @ bad location\r |
| 51 | @ XXX: banking unfriendly\r |
| 52 | ldr r1, [r3]\r |
| 53 | eor r0, r0, #1\r |
| 54 | ldrb r0, [r1, r0]\r |
| 55 | bx lr\r |
| 56 | \r |
| 57 | m_read8_eeprom:\r |
| 58 | stmfd sp!,{r0,lr}\r |
| 59 | bl EEPROM_read\r |
| 60 | ldmfd sp!,{r1,lr}\r |
| 61 | tst r1, #1\r |
| 62 | moveq r0, r0, lsr #8\r |
| 63 | bx lr\r |
| 64 | \r |
| 65 | \r |
| 66 | PicoRead8_io: @ u32 a, u32 d\r |
| 67 | bic r2, r0, #0x001f @ most commonly we get i/o port read,\r |
| 68 | cmp r2, #0xa10000 @ so check for it first\r |
| 69 | beq io_ports_read\r |
| 70 | \r |
| 71 | m_read8_not_io:\r |
| 72 | and r2, r0, #0xfc00\r |
| 73 | cmp r2, #0x1000\r |
| 74 | bne m_read8_not_brq\r |
| 75 | \r |
| 76 | ldr r3, =(Pico+0x22200)\r |
| 77 | mov r1, r0\r |
| 78 | ldr r0, [r3, #8] @ Pico.m.rotate\r |
| 79 | add r0, r0, #1\r |
| 80 | strb r0, [r3, #8]\r |
| 81 | eor r0, r0, r0, lsl #6\r |
| 82 | \r |
| 83 | tst r1, #1\r |
| 84 | bxne lr @ odd addr -> open bus\r |
| 85 | bic r0, r0, #1 @ bit0 defined in this area\r |
| 86 | and r2, r1, #0xff00\r |
| 87 | cmp r2, #0x1100\r |
| 88 | bxne lr @ not busreq\r |
| 89 | \r |
| 90 | ldrb r1, [r3, #(8+0x01)] @ Pico.m.z80Run\r |
| 91 | ldrb r2, [r3, #(8+0x0f)] @ Pico.m.z80_reset\r |
| 92 | orr r0, r0, r1\r |
| 93 | orr r0, r0, r2\r |
| 94 | bx lr\r |
| 95 | \r |
| 96 | m_read8_not_brq:\r |
| 97 | ldr r2, =PicoOpt\r |
| 98 | ldr r2, [r2]\r |
| 99 | tst r2, #POPT_EN_32X\r |
| 100 | bne PicoRead8_32x\r |
| 101 | mov r0, #0\r |
| 102 | bx lr\r |
| 103 | \r |
| 104 | @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r |
| 105 | \r |
| 106 | PicoRead16_sram: @ u32 a, u32 d\r |
| 107 | ldr r2, =(SRam)\r |
| 108 | ldr r3, =(Pico+0x22200)\r |
| 109 | ldr r1, [r2, #8] @ SRam.end\r |
| 110 | cmp r0, r1\r |
| 111 | bgt m_read16_nosram\r |
| 112 | ldr r1, [r2, #4] @ SRam.start\r |
| 113 | cmp r0, r1\r |
| 114 | blt m_read16_nosram\r |
| 115 | ldrb r1, [r3, #0x11] @ Pico.m.sram_reg\r |
| 116 | tst r1, #SRR_MAPPED\r |
| 117 | beq m_read16_nosram\r |
| 118 | ldr r1, [r2, #0x0c]\r |
| 119 | tst r1, #SRF_EEPROM\r |
| 120 | bne EEPROM_read\r |
| 121 | ldr r1, [r2, #4] @ SRam.start\r |
| 122 | ldr r2, [r2] @ SRam.data\r |
| 123 | sub r0, r0, r1\r |
| 124 | add r0, r0, r2\r |
| 125 | ldrb r1, [r0], #1\r |
| 126 | ldrb r0, [r0]\r |
| 127 | orr r0, r0, r1, lsl #8\r |
| 128 | bx lr\r |
| 129 | \r |
| 130 | m_read16_nosram:\r |
| 131 | ldr r1, [r3, #4] @ romsize\r |
| 132 | cmp r0, r1\r |
| 133 | movgt r0, #0\r |
| 134 | bxgt lr @ bad location\r |
| 135 | @ XXX: banking unfriendly\r |
| 136 | ldr r1, [r3]\r |
| 137 | ldrh r0, [r1, r0]\r |
| 138 | bx lr\r |
| 139 | \r |
| 140 | \r |
| 141 | PicoRead16_io: @ u32 a, u32 d\r |
| 142 | bic r2, r0, #0x001f @ most commonly we get i/o port read,\r |
| 143 | cmp r2, #0xa10000 @ so check for it first\r |
| 144 | bne m_read16_not_io\r |
| 145 | stmfd sp!,{lr}\r |
| 146 | bl io_ports_read @ same as read8\r |
| 147 | orr r0, r0, r0, lsl #8 @ only has bytes mirrored\r |
| 148 | ldmfd sp!,{pc}\r |
| 149 | \r |
| 150 | m_read16_not_io:\r |
| 151 | and r2, r0, #0xfc00\r |
| 152 | cmp r2, #0x1000\r |
| 153 | bne m_read16_not_brq\r |
| 154 | \r |
| 155 | ldr r3, =(Pico+0x22200)\r |
| 156 | and r2, r0, #0xff00\r |
| 157 | ldr r0, [r3, #8] @ Pico.m.rotate\r |
| 158 | add r0, r0, #1\r |
| 159 | strb r0, [r3, #8]\r |
| 160 | eor r0, r0, r0, lsl #5\r |
| 161 | eor r0, r0, r0, lsl #8\r |
| 162 | bic r0, r0, #0x100 @ bit8 defined in this area\r |
| 163 | cmp r2, #0x1100\r |
| 164 | bxne lr @ not busreq\r |
| 165 | \r |
| 166 | ldrb r1, [r3, #(8+0x01)] @ Pico.m.z80Run\r |
| 167 | ldrb r2, [r3, #(8+0x0f)] @ Pico.m.z80_reset\r |
| 168 | orr r0, r0, r1, lsl #8\r |
| 169 | orr r0, r0, r2, lsl #8\r |
| 170 | bx lr\r |
| 171 | \r |
| 172 | m_read16_not_brq:\r |
| 173 | ldr r2, =PicoOpt\r |
| 174 | ldr r2, [r2]\r |
| 175 | tst r2, #POPT_EN_32X\r |
| 176 | bne PicoRead16_32x\r |
| 177 | mov r0, #0\r |
| 178 | bx lr\r |
| 179 | \r |
| 180 | @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r |
| 181 | \r |
| 182 | PicoWrite8_io: @ u32 a, u32 d\r |
| 183 | bic r2, r0, #0x1e @ most commonly we get i/o port write,\r |
| 184 | eor r2, r2, #0xa10000 @ so check for it first\r |
| 185 | eors r2, r2, #1\r |
| 186 | beq io_ports_write\r |
| 187 | \r |
| 188 | m_write8_not_io:\r |
| 189 | tst r0, #1\r |
| 190 | bne m_write8_not_z80ctl @ even addrs only\r |
| 191 | and r2, r0, #0xff00\r |
| 192 | cmp r2, #0x1100\r |
| 193 | moveq r0, r1\r |
| 194 | beq ctl_write_z80busreq\r |
| 195 | cmp r2, #0x1200\r |
| 196 | moveq r0, r1\r |
| 197 | beq ctl_write_z80reset\r |
| 198 | \r |
| 199 | m_write8_not_z80ctl:\r |
| 200 | @ unlikely\r |
| 201 | eor r2, r0, #0xa10000\r |
| 202 | eor r2, r2, #0x003000\r |
| 203 | eors r2, r2, #0x0000f1\r |
| 204 | bne m_write8_not_sreg\r |
| 205 | ldr r3, =(Pico+0x22200)\r |
| 206 | ldrb r2, [r3, #(8+9)] @ Pico.m.sram_reg\r |
| 207 | and r1, r1, #(SRR_MAPPED|SRR_READONLY)\r |
| 208 | bic r2, r2, #(SRR_MAPPED|SRR_READONLY)\r |
| 209 | orr r2, r2, r1\r |
| 210 | strb r2, [r3, #(8+9)]\r |
| 211 | bx lr\r |
| 212 | \r |
| 213 | m_write8_not_sreg:\r |
| 214 | ldr r2, =PicoOpt\r |
| 215 | ldr r2, [r2]\r |
| 216 | tst r2, #POPT_EN_32X\r |
| 217 | bne PicoWrite8_32x\r |
| 218 | bx lr\r |
| 219 | \r |
| 220 | @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r |
| 221 | \r |
| 222 | PicoWrite16_io: @ u32 a, u32 d\r |
| 223 | bic r2, r0, #0x1f @ most commonly we get i/o port write,\r |
| 224 | cmp r2, #0xa10000 @ so check for it first\r |
| 225 | beq io_ports_write\r |
| 226 | \r |
| 227 | m_write16_not_io:\r |
| 228 | and r2, r0, #0xff00\r |
| 229 | cmp r2, #0x1100\r |
| 230 | moveq r0, r1, lsr #8\r |
| 231 | beq ctl_write_z80busreq\r |
| 232 | cmp r2, #0x1200\r |
| 233 | moveq r0, r1, lsr #8\r |
| 234 | beq ctl_write_z80reset\r |
| 235 | \r |
| 236 | m_write16_not_z80ctl:\r |
| 237 | @ unlikely\r |
| 238 | eor r2, r0, #0xa10000\r |
| 239 | eor r2, r2, #0x003000\r |
| 240 | eors r2, r2, #0x0000f0\r |
| 241 | bne m_write16_not_sreg\r |
| 242 | ldr r3, =(Pico+0x22200)\r |
| 243 | ldrb r2, [r3, #(8+9)] @ Pico.m.sram_reg\r |
| 244 | and r1, r1, #(SRR_MAPPED|SRR_READONLY)\r |
| 245 | bic r2, r2, #(SRR_MAPPED|SRR_READONLY)\r |
| 246 | orr r2, r2, r1\r |
| 247 | strb r2, [r3, #(8+9)]\r |
| 248 | bx lr\r |
| 249 | \r |
| 250 | m_write16_not_sreg:\r |
| 251 | ldr r2, =PicoOpt\r |
| 252 | ldr r2, [r2]\r |
| 253 | tst r2, #POPT_EN_32X\r |
| 254 | bne PicoWrite16_32x\r |
| 255 | bx lr\r |
| 256 | \r |
| 257 | .pool\r |
| 258 | \r |
| 259 | @ vim:filetype=armasm\r |