summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaxwell Beck <max@rastertail.net>2024-12-28 16:54:26 -0600
committerMaxwell Beck <max@rastertail.net>2024-12-28 16:54:26 -0600
commiteb05dd5e283d962ca52f80e89cb775ec8a92c46b (patch)
tree100da2093a68a2ecec0b953727efccf9c0952591
parentd20a72c10d707f4f85ea848b7bfd0929ff4e1a97 (diff)
Only read drive data while spinning
-rw-r--r--src/drive.c154
1 files changed, 78 insertions, 76 deletions
diff --git a/src/drive.c b/src/drive.c
index e74b64d..8eb1bfd 100644
--- a/src/drive.c
+++ b/src/drive.c
@@ -110,85 +110,87 @@ bool drive_cycle(drive_t *drive, uint8_t cycles, bool advance) {
 
 				drive->gcr_bits = 10;
 				*/
-				if (drive->gap_remain > 0) {
-					drive->gap_remain--;
-					drive->gcr_word = 0x55;
-					drive->gcr_bits = 8;
-				} else if (drive->sync_remain > 0) {
-					drive->sync_remain--;
-					drive->gcr_word = 0x3ff;
-					drive->gcr_bits = 10;
-				} else if (drive->header_remain > 0) {
-					drive->header_remain--;
-					uint8_t track_plus_one = drive->track + 1;
-					uint8_t checksum = drive->sector ^ track_plus_one;
-					switch (drive->header_remain) {
-					case 7:
-						drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0x8];
-						break;
-					case 6:
-						drive->gcr_word = (GCR_CONV[(checksum & 0xf0) >> 4] << 5) | GCR_CONV[checksum & 0x0f];
-						break;
-					case 5:
-						drive->gcr_word = (GCR_CONV[(drive->sector & 0xf0) >> 4] << 5) | GCR_CONV[drive->sector & 0x0f];
-						break;
-					case 4:
-						drive->gcr_word = (GCR_CONV[(track_plus_one & 0xf0) >> 4] << 5) | GCR_CONV[track_plus_one & 0x0f];
-						break;
-					case 3:
-					case 2:
-						drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0x0];
-						break;
-					case 1:
-					case 0:
-						drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0xf];
-						break;
-					}
-					if (drive->header_remain == 0) {
-						drive->gap_remain = 9;
-						drive->sync_remain = 4;
-						drive->data_remain = 260;
-						drive->data_checksum = 0;
-					}
-					drive->gcr_bits = 10;
-				} else if (drive->data_remain > 0) {
-					drive->data_remain--;
-					switch (drive->data_remain) {
-					case 259:
-						drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0x7];
-						break;
-					case 2:
-						drive->gcr_word = (GCR_CONV[(drive->data_checksum & 0xf0) >> 4] << 5) | GCR_CONV[drive->data_checksum & 0x0f];
-						break;
-					case 1:
-					case 0:
-						drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0xf];
-						break;
-					default:
-						{
-							uint8_t b = drive->image[drive->image_ptr + (drive->sector << 8) + drive->byte];
-							drive->gcr_word = (GCR_CONV[(b & 0xf0) >> 4] << 5) | GCR_CONV[b & 0x0f];
-							drive->data_checksum ^= b;
-
-							uint8_t byte_next = drive->byte + 1;
-							uint8_t sector_next = drive->sector;
-							if (byte_next == 0) {
-								sector_next += 1;
-							}
-							if (sector_next >= SECTORS_PER_TRACK[drive->track]) {
-								sector_next = 0;
+				if (drive->spinning) {
+					if (drive->gap_remain > 0) {
+						drive->gap_remain--;
+						drive->gcr_word = 0x55;
+						drive->gcr_bits = 8;
+					} else if (drive->sync_remain > 0) {
+						drive->sync_remain--;
+						drive->gcr_word = 0x3ff;
+						drive->gcr_bits = 10;
+					} else if (drive->header_remain > 0) {
+						drive->header_remain--;
+						uint8_t track_plus_one = drive->track + 1;
+						uint8_t checksum = drive->sector ^ track_plus_one;
+						switch (drive->header_remain) {
+						case 7:
+							drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0x8];
+							break;
+						case 6:
+							drive->gcr_word = (GCR_CONV[(checksum & 0xf0) >> 4] << 5) | GCR_CONV[checksum & 0x0f];
+							break;
+						case 5:
+							drive->gcr_word = (GCR_CONV[(drive->sector & 0xf0) >> 4] << 5) | GCR_CONV[drive->sector & 0x0f];
+							break;
+						case 4:
+							drive->gcr_word = (GCR_CONV[(track_plus_one & 0xf0) >> 4] << 5) | GCR_CONV[track_plus_one & 0x0f];
+							break;
+						case 3:
+						case 2:
+							drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0x0];
+							break;
+						case 1:
+						case 0:
+							drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0xf];
+							break;
+						}
+						if (drive->header_remain == 0) {
+							drive->gap_remain = 9;
+							drive->sync_remain = 4;
+							drive->data_remain = 260;
+							drive->data_checksum = 0;
+						}
+						drive->gcr_bits = 10;
+					} else if (drive->data_remain > 0) {
+						drive->data_remain--;
+						switch (drive->data_remain) {
+						case 259:
+							drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0x7];
+							break;
+						case 2:
+							drive->gcr_word = (GCR_CONV[(drive->data_checksum & 0xf0) >> 4] << 5) | GCR_CONV[drive->data_checksum & 0x0f];
+							break;
+						case 1:
+						case 0:
+							drive->gcr_word = (GCR_CONV[0x0] << 5) | GCR_CONV[0xf];
+							break;
+						default:
+							{
+								uint8_t b = drive->image[drive->image_ptr + (drive->sector << 8) + drive->byte];
+								drive->gcr_word = (GCR_CONV[(b & 0xf0) >> 4] << 5) | GCR_CONV[b & 0x0f];
+								drive->data_checksum ^= b;	
+
+								uint8_t byte_next = drive->byte + 1;
+								uint8_t sector_next = drive->sector;
+								if (byte_next == 0) {
+									sector_next += 1;
+								}
+								if (sector_next >= SECTORS_PER_TRACK[drive->track]) {
+									sector_next = 0;
+								}
+								drive->byte = byte_next;
+								drive->sector = sector_next;
 							}
-							drive->byte = byte_next;
-							drive->sector = sector_next;
+							break;
 						}
-						break;
-					}
-					if (drive->data_remain == 0) {
-						drive->gap_remain = 10;
-						drive->sync_remain = 4;
-						drive->header_remain = 8;
+						if (drive->data_remain == 0) {
+							drive->gap_remain = 10;
+							drive->sync_remain = 4;
+							drive->header_remain = 8;
+						}
+						drive->gcr_bits = 10;
 					}
-					drive->gcr_bits = 10;
 				}
 			}