Mercurial > repos > blastem
annotate nor.c @ 2208:3809a0bd680e
Fix a couple of Z80 debugger issues
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 27 Aug 2022 22:02:09 -0700 |
parents | 1f745318f10a |
children | d74d3998482c |
rev | line source |
---|---|
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include "genesis.h" |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <string.h> |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
4 #include "util.h" |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 enum { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 NOR_NORMAL, |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 NOR_PRODUCTID, |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 NOR_BOOTBLOCK |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 }; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 enum { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 NOR_CMD_IDLE, |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 NOR_CMD_AA, |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 NOR_CMD_55 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 }; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 //Technically this value shoudl be slightly different between NTSC and PAL |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 //as it's defined as 200 micro-seconds, not in clock cycles |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #define NOR_WRITE_PAUSE 10690 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 void nor_flash_init(nor_state *state, uint8_t *buffer, uint32_t size, uint32_t page_size, uint16_t product_id, uint8_t bus_flags) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 state->buffer = buffer; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 state->page_buffer = malloc(page_size); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 memset(state->page_buffer, 0xFF, page_size); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 state->size = size; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 state->page_size = page_size; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 state->product_id = product_id; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 state->last_write_cycle = 0xFFFFFFFF; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 state->mode = NOR_NORMAL; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 state->cmd_state = NOR_CMD_IDLE; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 state->alt_cmd = 0; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 state->bus_flags = bus_flags; |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
35 state->cmd_address1 = 0x5555; |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
36 state->cmd_address2 = 0x2AAA; |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
39 void nor_run(nor_state *state, m68k_context *m68k, uint32_t cycle) |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 if (state->last_write_cycle == 0xFFFFFFFF) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 return; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 if (cycle - state->last_write_cycle >= NOR_WRITE_PAUSE) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 state->last_write_cycle = 0xFFFFFFFF; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 for (uint32_t i = 0; i < state->page_size; i++) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 state->buffer[state->current_page + i] = state->page_buffer[i]; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 memset(state->page_buffer, 0xFF, state->page_size); |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
50 if (state->bus_flags == RAM_FLAG_BOTH) { |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
51 //TODO: add base address of NOR device to start and end addresses |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
52 m68k_invalidate_code_range(m68k, state->current_page, state->current_page + state->page_size); |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
53 } |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 uint8_t nor_flash_read_b(uint32_t address, void *vcontext) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 m68k_context *m68k = vcontext; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 genesis_context *gen = m68k->system; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 nor_state *state = &gen->nor; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 if ( |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 ((address & 1) && state->bus_flags == RAM_FLAG_EVEN) || |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 (!(address & 1) && state->bus_flags == RAM_FLAG_ODD) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 ) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 return 0xFF; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 if (state->bus_flags != RAM_FLAG_BOTH) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 address = address >> 1; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
72 nor_run(state, m68k, m68k->current_cycle); |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 switch (state->mode) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 case NOR_NORMAL: |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
76 if (state->bus_flags == RAM_FLAG_BOTH) { |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
77 address ^= 1; |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
78 } |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 return state->buffer[address & (state->size-1)]; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 case NOR_PRODUCTID: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 switch (address & (state->size - 1)) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 case 0: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 return state->product_id >> 8; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 case 1: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 return state->product_id; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 case 2: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 //TODO: Implement boot block protection |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 return 0xFE; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 default: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 return 0xFE; |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
93 } //HERE |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 case NOR_BOOTBLOCK: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 return 0xFF; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 uint16_t nor_flash_read_w(uint32_t address, void *context) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 uint16_t value = nor_flash_read_b(address, context) << 8; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 value |= nor_flash_read_b(address+1, context); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 return value; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 void nor_write_byte(nor_state *state, uint32_t address, uint8_t value, uint32_t cycle) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 switch(state->mode) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 case NOR_NORMAL: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 if (state->last_write_cycle != 0xFFFFFFFF) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 state->current_page = address & (state->size - 1) & ~(state->page_size - 1); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
116 if (state->bus_flags == RAM_FLAG_BOTH) { |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
117 address ^= 1; |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
118 } |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 state->page_buffer[address & (state->page_size - 1)] = value; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 case NOR_PRODUCTID: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 case NOR_BOOTBLOCK: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 //TODO: Implement boot block protection |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 state->mode = NOR_NORMAL; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 void *nor_flash_write_b(uint32_t address, void *vcontext, uint8_t value) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 m68k_context *m68k = vcontext; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 genesis_context *gen = m68k->system; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 nor_state *state = &gen->nor; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 if ( |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 ((address & 1) && state->bus_flags == RAM_FLAG_EVEN) || |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 (!(address & 1) && state->bus_flags == RAM_FLAG_ODD) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 ) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 return vcontext; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 if (state->bus_flags != RAM_FLAG_BOTH) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 address = address >> 1; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
145 nor_run(state, m68k, m68k->current_cycle); |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 switch (state->cmd_state) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 case NOR_CMD_IDLE: |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
149 if (value == 0xAA && (address & (state->size - 1)) == state->cmd_address1) { |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 state->cmd_state = NOR_CMD_AA; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } else { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 nor_write_byte(state, address, value, m68k->current_cycle); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 state->cmd_state = NOR_CMD_IDLE; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 case NOR_CMD_AA: |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
157 if (value == 0x55 && (address & (state->size - 1)) == state->cmd_address2) { |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 state->cmd_state = NOR_CMD_55; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } else { |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
160 nor_write_byte(state, state->cmd_address1, 0xAA, m68k->current_cycle); |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 nor_write_byte(state, address, value, m68k->current_cycle); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 state->cmd_state = NOR_CMD_IDLE; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 case NOR_CMD_55: |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
166 if ((address & (state->size - 1)) == state->cmd_address1) { |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 if (state->alt_cmd) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 switch(value) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 case 0x10: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 puts("UNIMPLEMENTED: NOR flash erase"); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 case 0x20: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 puts("UNIMPLEMENTED: NOR flash disable protection"); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 case 0x40: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 state->mode = NOR_BOOTBLOCK; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 case 0x60: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 state->mode = NOR_PRODUCTID; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 } else { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 switch(value) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 case 0x80: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 state->alt_cmd = 1; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 case 0x90: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 state->mode = NOR_PRODUCTID; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 case 0xA0: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 puts("UNIMPLEMENTED: NOR flash enable protection"); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 case 0xF0: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 state->mode = NOR_NORMAL; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 default: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 printf("Unrecognized unshifted NOR flash command %X\n", value); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 } else { |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
203 nor_write_byte(state, state->cmd_address1, 0xAA, m68k->current_cycle); |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1414
diff
changeset
|
204 nor_write_byte(state, state->cmd_address2, 0x55, m68k->current_cycle); |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 nor_write_byte(state, address, value, m68k->current_cycle); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 state->cmd_state = NOR_CMD_IDLE; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 return vcontext; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 void *nor_flash_write_w(uint32_t address, void *vcontext, uint16_t value) |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 nor_flash_write_b(address, vcontext, value >> 8); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 return nor_flash_write_b(address + 1, vcontext, value); |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 } |