Mercurial > repos > blastem
comparison cdd_mcu.c @ 2067:f22e04b69272 segacd
More CDC/CDD improvements
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 30 Jan 2022 11:58:17 -0800 |
parents | 02a9846668d1 |
children | c69e42444f96 |
comparison
equal
deleted
inserted
replaced
2066:a61a8a87410c | 2067:f22e04b69272 |
---|---|
59 { | 59 { |
60 sum += buffer[i]; | 60 sum += buffer[i]; |
61 } | 61 } |
62 return (~sum) & 0xF; | 62 return (~sum) & 0xF; |
63 } | 63 } |
64 #define SEEK_SPEED 2200 //made up number | 64 #define COARSE_SEEK 2200 //made up numbers |
65 #define FINE_SEEK 10 | |
65 static void handle_seek(cdd_mcu *context) | 66 static void handle_seek(cdd_mcu *context) |
66 { | 67 { |
68 //TODO: more realistic seeking behavior | |
67 if (context->seeking) { | 69 if (context->seeking) { |
68 if (context->seek_pba == context->head_pba) { | 70 if (context->seek_pba == context->head_pba) { |
69 context->seeking = 0; | 71 context->seeking = 0; |
70 } else if (context->seek_pba > context->head_pba) { | 72 } else if (context->seek_pba > context->head_pba) { |
71 context->head_pba += SEEK_SPEED; | 73 if (context->seek_pba - context->head_pba >= COARSE_SEEK) { |
72 if (context->head_pba > context->seek_pba) { | 74 context->head_pba += COARSE_SEEK; |
73 context->head_pba = context->seek_pba; | 75 } else if (context->seek_pba - context->head_pba >= FINE_SEEK) { |
76 context->head_pba += FINE_SEEK; | |
77 } else { | |
78 context->head_pba++; | |
74 } | 79 } |
75 } else { | 80 } else { |
76 if (context->head_pba >= SEEK_SPEED) { | 81 if (context->head_pba - context->seek_pba >= COARSE_SEEK) { |
77 context->head_pba -= SEEK_SPEED; | 82 context->head_pba -= COARSE_SEEK; |
83 } else if (context->head_pba >= FINE_SEEK) { | |
84 context->head_pba -= FINE_SEEK; | |
78 } else { | 85 } else { |
79 context->head_pba = 0; | 86 context->head_pba = 0; |
80 } | |
81 if (context->head_pba < context->seek_pba) { | |
82 context->head_pba = context->seek_pba; | |
83 } | 87 } |
84 } | 88 } |
85 } | 89 } |
86 } | 90 } |
87 | 91 |
350 uint32_t lba = context->cmd_buffer.b.time.min_high * 10 + context->cmd_buffer.b.time.min_low; | 354 uint32_t lba = context->cmd_buffer.b.time.min_high * 10 + context->cmd_buffer.b.time.min_low; |
351 lba *= 60; | 355 lba *= 60; |
352 lba += context->cmd_buffer.b.time.sec_high * 10 + context->cmd_buffer.b.time.sec_low; | 356 lba += context->cmd_buffer.b.time.sec_high * 10 + context->cmd_buffer.b.time.sec_low; |
353 lba *= 75; | 357 lba *= 75; |
354 lba += context->cmd_buffer.b.time.frame_high * 10 + context->cmd_buffer.b.time.frame_low; | 358 lba += context->cmd_buffer.b.time.frame_high * 10 + context->cmd_buffer.b.time.frame_low; |
355 printf("READ/SEEK cmd for lba %d, MM:SS:FF %u%u:%u%u:%u%u\n", lba, | 359 printf("CDD CMD: %s cmd for lba %d, MM:SS:FF %u%u:%u%u:%u%u\n", |
360 context->cmd_buffer.cmd_type == CMD_READ ? "READ" : "SEEK", lba, | |
356 context->cmd_buffer.b.time.min_high, context->cmd_buffer.b.time.min_low, | 361 context->cmd_buffer.b.time.min_high, context->cmd_buffer.b.time.min_low, |
357 context->cmd_buffer.b.time.sec_high, context->cmd_buffer.b.time.sec_low, | 362 context->cmd_buffer.b.time.sec_high, context->cmd_buffer.b.time.sec_low, |
358 context->cmd_buffer.b.time.frame_high, context->cmd_buffer.b.time.frame_low | 363 context->cmd_buffer.b.time.frame_high, context->cmd_buffer.b.time.frame_low |
359 ); | 364 ); |
360 if (lba >= context->media->tracks[0].fake_pregap + context->media->tracks[context->media->num_tracks - 1].end_lba) { | 365 if (lba >= context->media->tracks[0].fake_pregap + context->media->tracks[context->media->num_tracks - 1].end_lba) { |
408 context->seek_pba = 0; | 413 context->seek_pba = 0; |
409 context->requested_format = SF_TOCN; | 414 context->requested_format = SF_TOCN; |
410 break; | 415 break; |
411 } | 416 } |
412 printf("CDD CMD: REPORT REQUEST(%d), format set to %d\n", context->cmd_buffer.b.format.status_type, context->requested_format); | 417 printf("CDD CMD: REPORT REQUEST(%d), format set to %d\n", context->cmd_buffer.b.format.status_type, context->requested_format); |
418 break; | |
419 case CMD_PAUSE: | |
420 if (context->status == DS_DOOR_OPEN || context->status == DS_TRAY_MOVING || context->status == DS_DISC_LEADOUT || context->status == DS_DISC_LEADIN) { | |
421 context->error_status = DS_CMD_ERROR; | |
422 break; | |
423 } | |
424 if (context->requested_format == SF_TOCT || context->requested_format == SF_TOCN) { | |
425 context->requested_format = SF_ABSOLUTE; | |
426 } | |
427 if (!context->toc_valid) { | |
428 context->error_status = DS_CMD_ERROR; | |
429 break; | |
430 } | |
431 if (context->status == DS_STOP) { | |
432 context->seeking = 1; | |
433 context->seek_pba = LEADIN_SECTORS + context->media->tracks[0].fake_pregap + context->media->tracks[0].start_lba; | |
434 printf("CDD CMD: PAUSE, seeking to %u\n", context->seek_pba); | |
435 } else { | |
436 puts("CDD CMD: PAUSE"); | |
437 } | |
438 context->status = DS_PAUSE; | |
413 break; | 439 break; |
414 default: | 440 default: |
415 printf("CDD CMD: Unimplemented(%d)\n", context->cmd_buffer.cmd_type); | 441 printf("CDD CMD: Unimplemented(%d)\n", context->cmd_buffer.cmd_type); |
416 } | 442 } |
417 } | 443 } |