Mercurial > repos > blastem
comparison romdb.c @ 779:ba38e36559b0
EEPROM writes now seem to work for NFL Quarterback Club 96
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 20 Jul 2015 22:22:49 -0700 |
parents | 79b10b421d3c |
children | fa2c03fcbb88 |
comparison
equal
deleted
inserted
replaced
778:6e1711d56633 | 779:ba38e36559b0 |
---|---|
97 state->state = I2C_ADDRESS_ACK; | 97 state->state = I2C_ADDRESS_ACK; |
98 break; | 98 break; |
99 case I2C_WRITE: | 99 case I2C_WRITE: |
100 state->buffer[state->address] = state->latch; | 100 state->buffer[state->address] = state->latch; |
101 state->state = I2C_WRITE_ACK; | 101 state->state = I2C_WRITE_ACK; |
102 state->address++; | |
103 //TODO: page mask | |
104 state->address &= state->size-1; | |
105 break; | 102 break; |
106 } | 103 } |
107 } | 104 } |
108 break; | 105 break; |
109 case I2C_DEVICE_ACK: | 106 case I2C_DEVICE_ACK: |
110 if (state->latch & 1) { | 107 if (state->latch & 1) { |
111 state->state = I2C_READ; | 108 state->state = I2C_READ; |
112 state->counter = 8; | 109 state->counter = 8; |
113 state->latch = state->buffer[state->address]; | 110 state->latch = state->buffer[state->address]; |
114 state->address++; | |
115 //TODO: page mask | |
116 state->address &= state->size-1; | |
117 } else { | 111 } else { |
118 if (state->size < 256) { | 112 if (state->size < 256) { |
119 state->address = state->latch >> 1; | 113 state->address = state->latch >> 1; |
120 state->state = I2C_WRITE; | 114 state->state = I2C_WRITE; |
121 } else if (state->size < 8192) { | 115 } else if (state->size < 4096) { |
122 state->address = state->latch << 8; | 116 state->address = (state->latch & 0xE) << 7; |
123 state->state = I2C_ADDRESS; | 117 state->state = I2C_ADDRESS; |
124 } else { | 118 } else { |
125 state->state = I2C_ADDRESS_HI; | 119 state->state = I2C_ADDRESS_HI; |
126 } | 120 } |
127 state->counter = 8; | 121 state->counter = 8; |
131 state->state = I2C_ADDRESS; | 125 state->state = I2C_ADDRESS; |
132 state->counter = 8; | 126 state->counter = 8; |
133 break; | 127 break; |
134 case I2C_ADDRESS_ACK: | 128 case I2C_ADDRESS_ACK: |
135 state->state = I2C_WRITE; | 129 state->state = I2C_WRITE; |
130 state->address &= state->size-1; | |
131 printf("EEPROM address is %X\n", state->address); | |
136 state->counter = 8; | 132 state->counter = 8; |
137 break; | 133 break; |
138 case I2C_READ: | 134 case I2C_READ: |
139 state->counter--; | 135 state->counter--; |
140 if (!state->counter) { | 136 if (!state->counter) { |
142 } | 138 } |
143 break; | 139 break; |
144 case I2C_READ_ACK: | 140 case I2C_READ_ACK: |
145 state->state = I2C_READ; | 141 state->state = I2C_READ; |
146 state->counter = 8; | 142 state->counter = 8; |
143 state->address++; | |
144 //TODO: page mask | |
145 state->address &= state->size-1; | |
147 break; | 146 break; |
148 case I2C_WRITE_ACK: | 147 case I2C_WRITE_ACK: |
149 state->state = I2C_WRITE; | 148 state->state = I2C_WRITE; |
150 state->counter = 8; | 149 state->counter = 8; |
150 state->address++; | |
151 //TODO: page mask | |
152 state->address &= state->size-1; | |
151 break; | 153 break; |
152 } | 154 } |
153 } else if (~val & state->scl) { | 155 } else if (~val & state->scl) { |
154 //high to low transition | 156 //high to low transition |
155 switch (state->state & 0x7F) | 157 switch (state->state & 0x7F) |
347 expanded = value << 8; | 349 expanded = value << 8; |
348 mask = 0xFF00; | 350 mask = 0xFF00; |
349 } | 351 } |
350 printf("EEPROM byte write: %X - %X (using mask %X and expanded val %X)\n", address, value, mask, expanded); | 352 printf("EEPROM byte write: %X - %X (using mask %X and expanded val %X)\n", address, value, mask, expanded); |
351 if (map->scl_mask & mask) { | 353 if (map->scl_mask & mask) { |
352 printf("scl: %d, state: %s\n", (expanded & map->scl_mask) != 0, i2c_states[gen->eeprom.state]); | |
353 set_scl(&gen->eeprom, (expanded & map->scl_mask) != 0); | 354 set_scl(&gen->eeprom, (expanded & map->scl_mask) != 0); |
355 printf("scl: %d, state: %s, counter: %d, latch: %X\n", (expanded & map->scl_mask) != 0, i2c_states[gen->eeprom.state], gen->eeprom.counter, gen->eeprom.latch); | |
354 } | 356 } |
355 if (map->sda_write_mask & mask) { | 357 if (map->sda_write_mask & mask) { |
356 printf("sda: %d\n", (expanded & map->sda_write_mask) != 0); | 358 printf("sda: %d\n", (expanded & map->sda_write_mask) != 0); |
357 set_host_sda(&gen->eeprom, (expanded & map->sda_write_mask) != 0); | 359 set_host_sda(&gen->eeprom, (expanded & map->sda_write_mask) != 0); |
358 } | 360 } |