src/mess/machine/at45dbxx.c
| r3905 | r3906 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | #include "at45dbxx.h" |
| 14 | | #include "deprecat.h" |
| 15 | 14 | |
| 16 | 15 | #define LOG_LEVEL 1 |
| 17 | 16 | #define _logerror(level,x) do { if (LOG_LEVEL > level) logerror x; } while (0) |
| r3905 | r3906 | |
| 126 | 125 | state_save_register_item(machine, name, NULL, 0, flash.pin.busy); |
| 127 | 126 | } |
| 128 | 127 | |
| 129 | | static UINT8 at45dbxx_read_byte( void) |
| 128 | static UINT8 at45dbxx_read_byte( running_machine *machine) |
| 130 | 129 | { |
| 131 | 130 | UINT8 data; |
| 132 | 131 | // check mode |
| r3905 | r3906 | |
| 138 | 137 | return data; |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | | static void flash_set_io( UINT8* data, UINT32 size, UINT32 pos) |
| 140 | static void flash_set_io( running_machine *machine, UINT8* data, UINT32 size, UINT32 pos) |
| 142 | 141 | { |
| 143 | 142 | flash.io.data = data; |
| 144 | 143 | flash.io.size = size; |
| 145 | 144 | flash.io.pos = pos; |
| 146 | 145 | } |
| 147 | 146 | |
| 148 | | static UINT32 flash_get_page_addr( void) |
| 147 | static UINT32 flash_get_page_addr( running_machine *machine) |
| 149 | 148 | { |
| 150 | 149 | switch (flash.devid) |
| 151 | 150 | { |
| r3905 | r3906 | |
| 156 | 155 | } |
| 157 | 156 | } |
| 158 | 157 | |
| 159 | | static UINT32 flash_get_byte_addr( void) |
| 158 | static UINT32 flash_get_byte_addr( running_machine *machine) |
| 160 | 159 | { |
| 161 | 160 | switch (flash.devid) |
| 162 | 161 | { |
| r3905 | r3906 | |
| 167 | 166 | } |
| 168 | 167 | } |
| 169 | 168 | |
| 170 | | static void at45dbxx_write_byte( UINT8 data) |
| 169 | static void at45dbxx_write_byte(running_machine *machine, UINT8 data) |
| 171 | 170 | { |
| 172 | 171 | // check mode |
| 173 | 172 | if (flash.mode != FLASH_MODE_SI) return; |
| r3905 | r3906 | |
| 190 | 189 | { |
| 191 | 190 | _logerror( 1, ("at45dbxx opcode %02X - status register read\n", opcode)); |
| 192 | 191 | flash.status = (flash.status & 0xC7) | flash.devid; // 80 = busy / 40 = compare fail |
| 193 | | flash_set_io( &flash.status, 1, 0); |
| 192 | flash_set_io( machine, &flash.status, 1, 0); |
| 194 | 193 | flash.mode = FLASH_MODE_SO; |
| 195 | 194 | flash.cmd.size = 8; |
| 196 | 195 | } |
| r3905 | r3906 | |
| 204 | 203 | { |
| 205 | 204 | UINT32 page; |
| 206 | 205 | UINT8 comp; |
| 207 | | page = flash_get_page_addr(); |
| 206 | page = flash_get_page_addr(machine); |
| 208 | 207 | _logerror( 1, ("at45dbxx opcode %02X - main memory page to buffer 1 compare [%04X]\n", opcode, page)); |
| 209 | 208 | comp = memcmp( flash.data + page * flash.page_size, flash.buffer1, flash.page_size) == 0 ? 0 : 1; |
| 210 | 209 | if (comp) flash.status |= 0x40; else flash.status &= ~0x40; |
| r3905 | r3906 | |
| 221 | 220 | if (flash.cmd.size == 8) |
| 222 | 221 | { |
| 223 | 222 | UINT32 page, byte; |
| 224 | | page = flash_get_page_addr(); |
| 225 | | byte = flash_get_byte_addr(); |
| 223 | page = flash_get_page_addr(machine); |
| 224 | byte = flash_get_byte_addr(machine); |
| 226 | 225 | _logerror( 1, ("at45dbxx opcode %02X - main memory page read [%04X/%04X]\n", opcode, page, byte)); |
| 227 | | flash_set_io( flash.data + page * flash.page_size, flash.page_size, byte); |
| 226 | flash_set_io( machine, flash.data + page * flash.page_size, flash.page_size, byte); |
| 228 | 227 | flash.mode = FLASH_MODE_SO; |
| 229 | 228 | flash.cmd.size = 8; |
| 230 | 229 | } |
| r3905 | r3906 | |
| 237 | 236 | if (flash.cmd.size == 4) |
| 238 | 237 | { |
| 239 | 238 | UINT32 page, byte; |
| 240 | | page = flash_get_page_addr(); |
| 241 | | byte = flash_get_byte_addr(); |
| 239 | page = flash_get_page_addr(machine); |
| 240 | byte = flash_get_byte_addr(machine); |
| 242 | 241 | _logerror( 1, ("at45dbxx opcode %02X - main memory page program through buffer 1 [%04X/%04X]\n",opcode, page, byte)); |
| 243 | | flash_set_io( flash.buffer1, flash.page_size, byte); |
| 242 | flash_set_io( machine, flash.buffer1, flash.page_size, byte); |
| 244 | 243 | memset( flash.buffer1, 0xFF, flash.page_size); |
| 245 | 244 | flash.mode = FLASH_MODE_SI; |
| 246 | 245 | flash.cmd.size = 8; |
| r3905 | r3906 | |
| 267 | 266 | } |
| 268 | 267 | } |
| 269 | 268 | |
| 270 | | int at45dbxx_pin_so( void) |
| 269 | int at45dbxx_pin_so( running_machine *machine) |
| 271 | 270 | { |
| 272 | 271 | if (flash.pin.cs == 0) return 0; |
| 273 | 272 | return flash.pin.so; |
| 274 | 273 | } |
| 275 | 274 | |
| 276 | | void at45dbxx_pin_si( int data) |
| 275 | void at45dbxx_pin_si(running_machine *machine, int data) |
| 277 | 276 | { |
| 278 | 277 | if (flash.pin.cs == 0) return; |
| 279 | 278 | flash.pin.si = data; |
| 280 | 279 | } |
| 281 | 280 | |
| 282 | | void at45dbxx_pin_cs( int data) |
| 281 | void at45dbxx_pin_cs(running_machine *machine, int data) |
| 283 | 282 | { |
| 284 | 283 | // check if changed |
| 285 | 284 | if (flash.pin.cs == data) return; |
| r3905 | r3906 | |
| 290 | 289 | if ((flash.cmd.size >= 4) && (flash.cmd.data[0] == FLASH_CMD_82)) |
| 291 | 290 | { |
| 292 | 291 | UINT32 page, byte; |
| 293 | | page = flash_get_page_addr(); |
| 294 | | byte = flash_get_byte_addr(); |
| 292 | page = flash_get_page_addr(machine); |
| 293 | byte = flash_get_byte_addr(machine); |
| 295 | 294 | _logerror( 1, ("at45dbxx - program data stored in buffer 1 into selected page in main memory [%04X/%04X]\n", page, byte)); |
| 296 | 295 | memcpy( flash.data + page * flash.page_size, flash.buffer1, flash.page_size); |
| 297 | 296 | } |
| 298 | 297 | // reset |
| 299 | | at45dbxx_reset(Machine); |
| 298 | at45dbxx_reset(machine); |
| 300 | 299 | } |
| 301 | 300 | // save cs |
| 302 | 301 | flash.pin.cs = data; |
| 303 | 302 | } |
| 304 | 303 | |
| 305 | | void at45dbxx_pin_sck( int data) |
| 304 | void at45dbxx_pin_sck(running_machine *machine, int data) |
| 306 | 305 | { |
| 307 | 306 | // check if changed |
| 308 | 307 | if (flash.pin.sck == data) return; |
| r3905 | r3906 | |
| 313 | 312 | if (flash.so_bits == 8) |
| 314 | 313 | { |
| 315 | 314 | flash.so_bits = 0; |
| 316 | | flash.so_byte = at45dbxx_read_byte(); |
| 315 | flash.so_byte = at45dbxx_read_byte(machine); |
| 317 | 316 | } |
| 318 | 317 | // input |
| 319 | 318 | if (flash.pin.si) flash.si_byte = flash.si_byte | (1 << flash.si_bits); |
| r3905 | r3906 | |
| 321 | 320 | if (flash.si_bits == 8) |
| 322 | 321 | { |
| 323 | 322 | flash.si_bits = 0; |
| 324 | | at45dbxx_write_byte( flash.si_byte); |
| 323 | at45dbxx_write_byte( machine, flash.si_byte); |
| 325 | 324 | flash.si_byte = 0; |
| 326 | 325 | } |
| 327 | 326 | // output (part 2) |