changeset 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 6e1711d56633
children fa2c03fcbb88
files romdb.c
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/romdb.c	Mon Jul 20 21:58:31 2015 -0700
+++ b/romdb.c	Mon Jul 20 22:22:49 2015 -0700
@@ -99,9 +99,6 @@
 				case I2C_WRITE:
 					state->buffer[state->address] = state->latch;
 					state->state = I2C_WRITE_ACK;
-					state->address++;
-					//TODO: page mask
-					state->address &= state->size-1;
 					break;
 				}
 			}
@@ -111,15 +108,12 @@
 				state->state = I2C_READ;
 				state->counter = 8;
 				state->latch = state->buffer[state->address];
-				state->address++;
-				//TODO: page mask
-				state->address &= state->size-1;
 			} else {
 				if (state->size < 256) {
 					state->address = state->latch >> 1;
 					state->state = I2C_WRITE;
-				} else if (state->size < 8192) {
-					state->address = state->latch << 8;
+				} else if (state->size < 4096) {
+					state->address = (state->latch & 0xE) << 7;
 					state->state = I2C_ADDRESS;
 				} else {
 					state->state = I2C_ADDRESS_HI;
@@ -133,6 +127,8 @@
 			break;
 		case I2C_ADDRESS_ACK:
 			state->state = I2C_WRITE;
+			state->address &= state->size-1;
+			printf("EEPROM address is %X\n", state->address);
 			state->counter = 8;
 			break;
 		case I2C_READ:
@@ -144,10 +140,16 @@
 		case I2C_READ_ACK:
 			state->state = I2C_READ;
 			state->counter = 8;
+			state->address++;
+			//TODO: page mask
+			state->address &= state->size-1;
 			break;
 		case I2C_WRITE_ACK:
 			state->state = I2C_WRITE;
 			state->counter = 8;
+			state->address++;
+			//TODO: page mask
+			state->address &= state->size-1;
 			break;
 		}
 	} else if (~val & state->scl) {
@@ -349,8 +351,8 @@
 	}
 	printf("EEPROM byte write: %X - %X (using mask %X and expanded val %X)\n", address, value, mask, expanded);
 	if (map->scl_mask & mask) {
-		printf("scl: %d, state: %s\n", (expanded & map->scl_mask) != 0, i2c_states[gen->eeprom.state]);
 		set_scl(&gen->eeprom, (expanded & map->scl_mask) != 0);
+		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);
 	}
 	if (map->sda_write_mask & mask) {
 		printf("sda: %d\n", (expanded & map->sda_write_mask) != 0);