Mercurial > repos > blastem
annotate nor.c @ 1466:f2ee46d08b01
Push correct PC onto stack on divide by zero for pc-relative case
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 13 Sep 2017 21:13:11 -0700 |
parents | d94855080529 |
children | 1f745318f10a |
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> |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 enum { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 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
|
7 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
|
8 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
|
9 }; |
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 enum { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 }; |
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 //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
|
18 //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
|
19 #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
|
20 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 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
|
22 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 state->bus_flags = 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
|
34 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 void nor_run(nor_state *state, 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
|
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 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
|
39 return; |
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 (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
|
42 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
|
43 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
|
44 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
|
45 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 memset(state->page_buffer, 0xFF, state->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
|
47 } |
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 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 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
|
51 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 if ( |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 ((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
|
57 (!(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
|
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 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
|
60 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 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
|
62 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
|
63 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 nor_run(state, 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
|
66 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
|
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 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
|
69 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
|
70 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 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
|
72 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
|
73 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 //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
|
80 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
|
81 default: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 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
|
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 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 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
|
86 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 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
|
89 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 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
|
92 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 } |
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 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
|
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 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
|
101 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 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
|
107 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 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
|
109 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 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
|
111 //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
|
112 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
|
113 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 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
|
118 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 if ( |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 ((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
|
124 (!(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
|
125 ) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 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
|
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 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
|
129 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
|
130 } |
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 nor_run(state, 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
|
133 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
|
134 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 case 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
|
136 if (value == 0xAA && (address & (state->size - 1)) == 0x5555) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 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
|
138 } else { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 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
|
140 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
|
141 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 case 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
|
144 if (value == 0x55 && (address & (state->size - 1)) == 0x2AAA) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 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
|
146 } else { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 nor_write_byte(state, 0x5555, 0xAA, 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
|
148 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
|
149 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
|
150 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 case 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
|
153 if ((address & (state->size - 1)) == 0x5555) { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 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
|
155 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
|
156 { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 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
|
158 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
|
159 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 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
|
161 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
|
162 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 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
|
164 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
|
165 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 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
|
167 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
|
168 break; |
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 } else { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 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
|
172 { |
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 0x80: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 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
|
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 0x90: |
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_PRODUCTID; |
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 0xA0: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 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
|
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 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
|
183 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
|
184 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 default: |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 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
|
187 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 } else { |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 nor_write_byte(state, 0x5555, 0xAA, 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
|
191 nor_write_byte(state, 0x2AAA, 0x55, 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
|
192 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
|
193 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 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
|
195 break; |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 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
|
198 } |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 |
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 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
|
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 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
|
203 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
|
204 } |