comparison cdd_mcu.c @ 2095:c732dcc9c61b

Better simulation of CDD pause behavior
author Michael Pavone <pavone@retrodev.com>
date Mon, 07 Feb 2022 21:31:58 -0800
parents 0db3af42dd72
children 460c93c19146
comparison
equal deleted inserted replaced
2094:ca6fc8c8dc60 2095:c732dcc9c61b
74 { 74 {
75 //TODO: more realistic seeking behavior 75 //TODO: more realistic seeking behavior
76 if (context->seeking) { 76 if (context->seeking) {
77 if (context->seek_pba == context->head_pba) { 77 if (context->seek_pba == context->head_pba) {
78 context->seeking = 0; 78 context->seeking = 0;
79 if (context->status == DS_PAUSE) {
80 context->pause_pba = context->head_pba;
81 }
79 } else if (context->seek_pba > context->head_pba) { 82 } else if (context->seek_pba > context->head_pba) {
80 if (context->seek_pba - context->head_pba >= COARSE_SEEK || context->head_pba < LEADIN_SECTORS) { 83 if (context->seek_pba - context->head_pba >= COARSE_SEEK || context->head_pba < LEADIN_SECTORS) {
81 context->head_pba += COARSE_SEEK; 84 context->head_pba += COARSE_SEEK;
82 } else if (context->seek_pba - context->head_pba >= FINE_SEEK) { 85 } else if (context->seek_pba - context->head_pba >= FINE_SEEK) {
83 context->head_pba += FINE_SEEK; 86 context->head_pba += FINE_SEEK;
127 } 130 }
128 } 131 }
129 break; 132 break;
130 case DS_PAUSE: 133 case DS_PAUSE:
131 handle_seek(context); 134 handle_seek(context);
135 if (!context->seeking) {
136 context->head_pba++;
137 if (context->head_pba > context->pause_pba + FINE_SEEK) {
138 context->head_pba = context->pause_pba - FINE_SEEK;
139 if (context->head_pba < LEADIN_SECTORS) {
140 context->head_pba = LEADIN_SECTORS;
141 }
142 }
143 }
132 if (context->head_pba >= LEADIN_SECTORS) { 144 if (context->head_pba >= LEADIN_SECTORS) {
133 uint8_t track = context->media->seek(context->media, context->head_pba - LEADIN_SECTORS); 145 uint8_t track = context->media->seek(context->media, context->head_pba - LEADIN_SECTORS);
134 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) { 146 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) {
135 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE; 147 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE;
136 } 148 }
142 context->head_pba++; 154 context->head_pba++;
143 if (context->media && context->media->type == MEDIA_CDROM && context->media->num_tracks) { 155 if (context->media && context->media->type == MEDIA_CDROM && context->media->num_tracks) {
144 if (context->head_pba > 3*(context->media->num_tracks + 2)) { 156 if (context->head_pba > 3*(context->media->num_tracks + 2)) {
145 context->toc_valid = 1; 157 context->toc_valid = 1;
146 context->seeking = 1; 158 context->seeking = 1;
147 context->seek_pba = LEADIN_SECTORS + context->media->tracks[0].start_lba; 159 context->seek_pba = LEADIN_SECTORS + context->media->tracks[0].start_lba + context->media->tracks[0].fake_pregap;
148 context->status = DS_PAUSE; 160 context->status = DS_PAUSE;
149 } 161 }
150 162
151 } else { 163 } else {
152 context->status = DS_NO_DISC; 164 context->status = DS_NO_DISC;
155 break; 167 break;
156 case DS_TRACKING: 168 case DS_TRACKING:
157 handle_seek(context); 169 handle_seek(context);
158 if (!context->seeking) { 170 if (!context->seeking) {
159 context->status = DS_PAUSE; 171 context->status = DS_PAUSE;
172 context->pause_pba = context->head_pba;
160 } 173 }
161 if (context->head_pba >= LEADIN_SECTORS) { 174 if (context->head_pba >= LEADIN_SECTORS) {
162 uint8_t track = context->media->seek(context->media, context->head_pba - LEADIN_SECTORS); 175 uint8_t track = context->media->seek(context->media, context->head_pba - LEADIN_SECTORS);
163 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) { 176 if (!context->seeking && context->media->tracks[track].type == TRACK_AUDIO) {
164 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE; 177 gate_array[GAO_CDD_CTRL] &= ~BIT_MUTE;
452 printf("CDD CMD: PAUSE, seeking to %u\n", context->seek_pba); 465 printf("CDD CMD: PAUSE, seeking to %u\n", context->seek_pba);
453 } else { 466 } else {
454 puts("CDD CMD: PAUSE"); 467 puts("CDD CMD: PAUSE");
455 } 468 }
456 context->status = DS_PAUSE; 469 context->status = DS_PAUSE;
470 if (!context->seeking) {
471 context->pause_pba = context->head_pba;
472 }
457 break; 473 break;
458 case CMD_PLAY: 474 case CMD_PLAY:
459 if (context->status == DS_DOOR_OPEN || context->status == DS_TRAY_MOVING || context->status == DS_DISC_LEADOUT || context->status == DS_DISC_LEADIN) { 475 if (context->status == DS_DOOR_OPEN || context->status == DS_TRAY_MOVING || context->status == DS_DISC_LEADOUT || context->status == DS_DISC_LEADIN) {
460 context->error_status = DS_CMD_ERROR; 476 context->error_status = DS_CMD_ERROR;
461 break; 477 break;