1use core::ptr::addr_of_mut;
50
51use psx_gpu::prim::FillRect;
52use psx_gpu::Gpu;
53use psx_hw::gpu::gp1;
54use psx_hw::mdec::{DECODE_15BPP, DECODE_24BPP};
55use psx_io::periph::{Cd, GpuDma, MdecDma};
56use psx_pack::cd::{SectorReader, SECTOR_WORDS};
57use psx_rt::{interrupts, Peripherals};
58use psx_spu::CdVolume;
59use psx_vram::VramRect;
60
61use crate::mdec::Mdec;
62use crate::stream::{Chunk, FrameAssembler, CHUNK_PAYLOAD_BYTES, MAX_CHUNKS};
63use crate::{bitstream, mdec};
64
65#[derive(Copy, Clone, Debug)]
67pub struct Movie {
68 pub lba: u32,
70 pub frames: u32,
72 pub width: u16,
74 pub height: u16,
76 pub max_chunks: u16,
78 pub rle_words: usize,
81 pub xa: Option<(u8, u8)>,
83}
84
85pub const DEFAULT_BUFFERS: [(u16, u16); 3] = [(0, 0), (0, 256), (512, 0)];
88
89#[derive(Copy, Clone, Debug, PartialEq, Eq)]
91pub enum Depth {
92 Rgb15,
95 Rgb24,
100}
101
102#[derive(Copy, Clone, Debug)]
104pub struct Config {
105 pub depth: Depth,
107 pub buffers: [(u16, u16); 3],
111 pub screen_width: u16,
113 pub screen_height: u16,
115 pub latency_vblanks: u32,
118 pub stall_vblanks: u32,
120}
121
122#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
124pub enum Stop {
125 #[default]
127 End,
128 Skipped,
130 Stall,
132 CdError,
134 Wedged,
136 Setup,
138}
139
140#[derive(Copy, Clone, Debug, Default)]
142pub struct Outcome {
143 pub stop: Stop,
145 pub shown: u32,
147 pub skipped: u32,
149 pub late: u32,
151 pub worst_late_vblanks: u32,
153 pub dropped: u32,
156 pub decode_errors: u32,
158 pub last_frame: u32,
160 pub vblanks: u32,
162 pub kcyc_vlc: u32,
165 pub kcyc_mdec: u32,
167 pub kcyc_wait: u32,
169}
170
171pub const WEDGE_ERRORS: u32 = 8;
173const SLOTS: usize = 3;
175const CHUNK_WORDS: usize = CHUNK_PAYLOAD_BYTES / 4;
177const DECODE_TIMEOUT_VBLANKS: u32 = 30;
180const PUMP_MACROBLOCKS: u32 = 2;
182const MODE_XA: u8 = 0x80 | 0x40 | 0x08;
184const MODE_DATA: u8 = 0x80;
186const FOREIGN_SECTORS: u32 = 32;
189const GP1_DISPLAY_MODE: u32 = 0x0800_0000;
191const DISPLAY_24BIT: u32 = 1 << 4;
192
193fn display_mode() -> u32 {
195 let stat = psx_io::gpu::status().bits();
196 ((stat >> 17) & 3)
197 | ((stat >> 19) & 1) << 2
198 | ((stat >> 20) & 1) << 3
199 | ((stat >> 21) & 1) << 4
200 | ((stat >> 22) & 1) << 5
201 | ((stat >> 16) & 1) << 6
202 | ((stat >> 14) & 1) << 7
203}
204
205const BUFFERS: usize = 3;
209
210fn slot_words(m: &Movie) -> usize {
211 m.max_chunks as usize * CHUNK_WORDS
212}
213
214fn rle_words(m: &Movie) -> usize {
217 m.rle_words.div_ceil(mdec::DMA_BLOCK_WORDS) * mdec::DMA_BLOCK_WORDS
218}
219
220fn halfwords_x2(depth: Depth) -> u16 {
222 match depth {
223 Depth::Rgb15 => 2,
224 Depth::Rgb24 => 3,
225 }
226}
227
228fn column_words(m: &Movie, depth: Depth) -> usize {
230 4 * halfwords_x2(depth) as usize * m.height as usize
231}
232
233fn frame_words(m: &Movie, depth: Depth) -> usize {
235 (m.width as usize / 16) * column_words(m, depth)
236}
237
238pub fn memory_words(movie: &Movie, depth: Depth) -> usize {
240 SLOTS * slot_words(movie) + 2 * rle_words(movie) + 2 * frame_words(movie, depth)
241}
242
243const PHASE_VLC: usize = 0;
245const PHASE_MDEC: usize = 1;
246const PHASE_WAIT: usize = 2;
247
248struct Clock {
249 phase: usize,
250 last: u16,
251 acc: [u32; 3],
252}
253
254impl Clock {
255 fn switch(&mut self, next: usize) {
256 let now = psx_io::timers::counter(psx_io::timers::Timer::Timer2);
257 self.acc[self.phase] += now.wrapping_sub(self.last) as u32;
258 self.last = now;
259 self.phase = next;
260 }
261}
262
263#[derive(Copy, Clone)]
266struct Buffers {
267 slots: *mut u32,
268 slot_words: usize,
269 rle: *mut u32,
270 rle_words: usize,
271 frames: *mut u32,
272 column_words: usize,
273 frame_words: usize,
274}
275
276impl Buffers {
277 fn slot(&self, i: usize) -> &'static mut [u8] {
278 unsafe {
281 core::slice::from_raw_parts_mut(
282 self.slots.add(i * self.slot_words) as *mut u8,
283 self.slot_words * 4,
284 )
285 }
286 }
287 fn rle(&self, i: usize) -> &'static mut [u32] {
288 unsafe { core::slice::from_raw_parts_mut(self.rle.add(i * self.rle_words), self.rle_words) }
291 }
292 fn rle16(&self, i: usize) -> &'static mut [u16] {
293 let words = self.rle(i);
294 unsafe { core::slice::from_raw_parts_mut(words.as_mut_ptr() as *mut u16, words.len() * 2) }
296 }
297 fn frame(&self, i: usize) -> *mut u32 {
298 unsafe { self.frames.add(i * self.frame_words) }
300 }
301 fn column(&self, frame: usize, c: u16) -> *mut u32 {
302 unsafe { self.frame(frame).add(c as usize * self.column_words) }
304 }
305}
306
307static mut READER: Option<SectorReader> = None;
308static mut MDEC: Option<Mdec> = None;
309static mut SECTOR: [u32; SECTOR_WORDS] = [0; SECTOR_WORDS];
310
311fn install_devices(cd: Cd, mdec: MdecDma) {
313 unsafe {
315 *addr_of_mut!(READER) = Some(SectorReader::with_cd(cd));
316 *addr_of_mut!(MDEC) = Some(Mdec::new(mdec));
317 }
318}
319
320fn reader() -> &'static mut SectorReader {
321 unsafe { (*addr_of_mut!(READER)).as_mut().expect("reader installed") }
324}
325
326fn mdec() -> &'static mut Mdec {
327 unsafe { (*addr_of_mut!(MDEC)).as_mut().expect("mdec installed") }
329}
330
331fn read_one(lba: u32) -> Option<&'static [u8]> {
333 let r = reader();
334 unsafe {
336 if !r.start_read(lba) {
337 return None;
338 }
339 let ok = r.read_sector(&mut *addr_of_mut!(SECTOR));
340 r.stop();
341 if !ok {
342 return None;
343 }
344 Some(core::slice::from_raw_parts(
345 addr_of_mut!(SECTOR) as *const u8,
346 SECTOR_WORDS * 4,
347 ))
348 }
349}
350
351pub fn find_root_file(name: &str) -> Option<(u32, u32)> {
354 let devices = unsafe { Peripherals::steal() };
357 install_devices(devices.cd, devices.mdec_dma);
358 if !reader().prepare() {
359 return None;
360 }
361 let (root, _) = crate::iso::root_directory(read_one(crate::iso::PVD_LBA)?)?;
362 crate::iso::find_in_directory(read_one(root)?, name)
363}
364
365struct Stream {
367 buf: Buffers,
368 last_frame: u32,
369 frames: u32,
370 done: bool,
371 cd_error: bool,
372 started: bool,
373 foreign: u32,
375 filling: usize,
376 ready: Option<(usize, u32, u32)>,
379 decoding: Option<usize>,
380 asm: FrameAssembler,
381 skipped: u32,
382 last_sector_vblank: u32,
383}
384
385impl Stream {
386 fn pump(&mut self) {
387 while !self.done {
388 let got = unsafe { reader().try_read_sector(&mut *addr_of_mut!(SECTOR)) };
390 match got {
391 Ok(true) => {}
392 Ok(false) => return,
393 Err(()) => {
394 self.cd_error = true;
395 self.done = true;
396 return;
397 }
398 }
399 let now = interrupts::vblank_count();
400 self.last_sector_vblank = now;
401 let sector = unsafe {
403 core::slice::from_raw_parts(addr_of_mut!(SECTOR) as *const u8, SECTOR_WORDS * 4)
404 };
405 if Chunk::parse(sector).is_none() {
406 self.foreign += 1;
410 if self.started && self.foreign > FOREIGN_SECTORS {
411 self.done = true;
412 }
413 continue;
414 }
415 self.foreign = 0;
416 self.started = true;
417 if let Some(frame) = self.asm.add(sector, self.buf.slot(self.filling)) {
418 self.last_frame = frame.number;
419 if frame.number >= self.frames {
420 self.done = true;
421 }
422 let done = self.filling;
423 let next = match self.ready.replace((done, frame.size, now)) {
424 Some((stale, _, _)) => {
425 self.skipped += 1;
426 stale
427 }
428 None => (0..SLOTS)
429 .find(|&s| s != done && Some(s) != self.decoding)
430 .unwrap_or(done),
431 };
432 self.filling = next;
433 }
434 }
435 }
436}
437
438struct Columns {
441 x: u16,
443 step: u16,
444 y: u16,
445 count: u16,
446 next: u16,
447 frame: usize,
449 uploading: bool,
451 started: u32,
452}
453
454impl Columns {
455 fn start(x: u16, step: u16, y: u16, count: u16, frame: usize) -> Self {
456 Columns {
457 x,
458 step,
459 y,
460 count,
461 next: 0,
462 frame,
463 uploading: false,
464 started: interrupts::vblank_count(),
465 }
466 }
467
468 fn service(&mut self, dma: &mut GpuDma, buf: &Buffers, height: u16) -> bool {
470 if self.uploading && psx_vram::dma_copy_to_vram_done() {
471 self.uploading = false;
472 }
473 if !self.uploading && self.next < self.count {
474 let c = self.next;
475 let rect = VramRect::new(self.x + c * self.step, self.y, self.step, height);
476 let src = buf.column(self.frame, c);
477 if unsafe { psx_vram::dma_copy_to_vram_start(dma, rect, src) } {
482 self.uploading = true;
483 } else {
484 let words = unsafe { core::slice::from_raw_parts(src, buf.column_words) };
486 psx_vram::upload_words(rect, words);
487 }
488 self.next += 1;
489 }
490 self.next == self.count && !self.uploading
491 }
492}
493
494struct Player {
495 dma: GpuDma,
498 st: Stream,
499 buf: Buffers,
500 movie: Movie,
501 x: u16,
503 step: u16,
504 y_offset: u16,
505 latency: u32,
506 origins: [(u16, u16); BUFFERS],
508 front: usize,
510 decoding: Option<(usize, usize, u32)>,
512 mdec_frame: usize,
514 mdec_started: u32,
515 to_upload: Option<(usize, usize, u32)>,
518 upload: Option<(usize, usize, u32)>,
520 cols: Columns,
521 waiting: [Option<(usize, u32)>; 2],
524 queued: Option<usize>,
526 pending: Option<(usize, usize, u32)>,
529 shown: u32,
530 late: u32,
531 worst_late: u32,
532 errors: u32,
533 in_a_row: u32,
534 wedged: bool,
535 clock: Clock,
536}
537
538impl Player {
539 fn idle_phase(&self) -> usize {
540 if self.decoding.is_some() {
541 PHASE_MDEC
542 } else {
543 PHASE_WAIT
544 }
545 }
546
547 fn free_buffer(&self) -> Option<usize> {
550 (0..BUFFERS).find(|&b| {
551 b != self.front
552 && self.queued != Some(b)
553 && self.decoding.map(|d| d.1) != Some(b)
554 && self.to_upload.map(|d| d.1) != Some(b)
555 && self.upload.map(|d| d.1) != Some(b)
556 && self.waiting.iter().all(|w| w.map(|w| w.0) != Some(b))
557 })
558 }
559
560 fn free_frame(&self) -> Option<usize> {
563 (0..2).find(|&f| {
564 (self.decoding.is_none() || self.mdec_frame != f)
565 && self.to_upload.map(|u| u.0) != Some(f)
566 && self.upload.map(|u| u.0) != Some(f)
567 })
568 }
569
570 fn drained(&self) -> bool {
572 self.decoding.is_none()
573 && self.to_upload.is_none()
574 && self.upload.is_none()
575 && self.pending.is_none()
576 && self.waiting[0].is_none()
577 && self.queued.is_none()
578 }
579
580 fn tick(&mut self) {
583 self.clock.switch(self.clock.phase);
586 self.st.pump();
587 if let Some(b) = self.queued {
588 if !interrupts::is_display_control_queued() {
589 self.front = b;
590 self.queued = None;
591 self.shown += 1;
592 }
593 }
594 if let Some((_, b, due)) = self.decoding {
595 if mdec().column_done() {
597 self.decoding = None;
598 if mdec().decode_finish() {
599 self.in_a_row = 0;
600 self.to_upload = Some((self.mdec_frame, b, due));
601 } else {
602 self.decode_failed();
603 }
604 } else if interrupts::vblank_count().wrapping_sub(self.mdec_started)
605 > DECODE_TIMEOUT_VBLANKS
606 {
607 mdec().abort_decode();
608 self.decoding = None;
609 self.decode_failed();
610 }
611 }
612 if self.upload.is_none() {
613 if let Some((f, b, due)) = self.to_upload.take() {
614 let (x, y) = self.origins[b];
615 self.cols = Columns::start(
616 x + self.x,
617 self.step,
618 y + self.y_offset,
619 self.movie.width / 16,
620 f,
621 );
622 self.upload = Some((f, b, due));
623 }
624 }
625 if let Some((_, b, due)) = self.upload {
626 if self
627 .cols
628 .service(&mut self.dma, &self.buf, self.movie.height)
629 {
630 self.upload = None;
631 let slot = if self.waiting[0].is_none() { 0 } else { 1 };
632 self.waiting[slot] = Some((b, due));
633 } else if interrupts::vblank_count().wrapping_sub(self.cols.started)
634 > DECODE_TIMEOUT_VBLANKS
635 {
636 psx_io::dma::abort(psx_io::dma::Channel::Gpu);
637 psx_io::gpu::write_display_control(gp1::RESET_CMD_BUFFER);
640 self.cols.uploading = false;
641 self.upload = None;
642 self.decode_failed();
643 }
644 }
645 if self.queued.is_none() {
646 if let Some((b, due)) = self.waiting[0] {
647 let now = interrupts::vblank_count();
648 let edge = now.wrapping_add(1);
649 let behind = self.waiting[1].is_some()
653 || (self.pending.is_some() && self.st.ready.is_some());
654 let gp0_free = !self.cols.uploading && psx_vram::dma_copy_to_vram_done();
656 if gp0_free && (behind || edge.wrapping_sub(due) as i32 >= 0) {
657 let gpu = Gpu::from_dma_mut(&mut self.dma);
661 gpu.arm_draw_done();
662 gpu.signal_draw_done();
663 let (x, y) = self.origins[b];
664 interrupts::queue_display_control_at_vblank(gp1::display_start(
665 x as u32, y as u32,
666 ));
667 let late = edge.wrapping_sub(due) as i32;
668 if late > 0 {
669 self.late += 1;
670 self.worst_late = self.worst_late.max(late as u32);
671 }
672 self.queued = Some(b);
673 self.waiting = [self.waiting[1], None];
674 }
675 }
676 }
677 }
678
679 fn decode_failed(&mut self) {
680 self.errors += 1;
681 self.in_a_row += 1;
682 if self.in_a_row >= WEDGE_ERRORS {
683 self.wedged = true;
684 }
685 let _ = setup_mdec();
686 }
687}
688
689fn setup_mdec() -> bool {
690 mdec().reset() && mdec().load_tables().is_some_and(|t| t.enable_writes != 0)
691}
692
693fn clear_buffers(dma: &mut GpuDma, config: &Config) {
696 let gpu = Gpu::from_dma_mut(dma);
697 gpu.wait_idle();
699 let line = config.screen_width * halfwords_x2(config.depth) / 2;
700 for &(x, y) in &config.buffers {
701 gpu.draw(&FillRect::new(
702 (x, y),
703 (line, config.screen_height),
704 (0, 0, 0),
705 ));
706 }
707 gpu.wait_idle();
708}
709
710fn leave_display(dma: &mut GpuDma, config: &Config, mode: u32) {
713 if config.depth == Depth::Rgb24 {
714 clear_buffers(dma, config);
715 psx_io::gpu::write_display_control(GP1_DISPLAY_MODE | mode);
716 }
717}
718
719fn setup_failed() -> Outcome {
720 Outcome {
721 stop: Stop::Setup,
722 ..Outcome::default()
723 }
724}
725
726pub fn play(
734 movie: &Movie,
735 config: &Config,
736 memory: &mut [u32],
737 poll: &mut dyn FnMut() -> bool,
738) -> Outcome {
739 if memory.len() < memory_words(movie, config.depth)
740 || movie.width == 0
741 || movie.height == 0
742 || !movie.width.is_multiple_of(16)
743 || !movie.height.is_multiple_of(16)
744 || movie.width > config.screen_width
745 || movie.height > config.screen_height
746 || movie.max_chunks == 0
747 || movie.max_chunks > MAX_CHUNKS
748 {
749 return setup_failed();
750 }
751 let base = memory.as_mut_ptr();
752 let sw = slot_words(movie);
753 let rw = rle_words(movie);
754 let buf = Buffers {
755 slots: base,
756 slot_words: sw,
757 rle: unsafe { base.add(SLOTS * sw) },
759 rle_words: rw,
760 frames: unsafe { base.add(SLOTS * sw + 2 * rw) },
762 column_words: column_words(movie, config.depth),
763 frame_words: frame_words(movie, config.depth),
764 };
765
766 let devices = unsafe { Peripherals::steal() };
769 install_devices(devices.cd, devices.mdec_dma);
770 let mut dma = devices.gpu_dma;
771
772 let r = reader();
773 let ready = {
776 match movie.xa {
777 Some((file, channel)) => {
778 r.prepare_mode(MODE_XA) && r.unmute() && r.set_filter(file, channel)
779 }
780 None => r.prepare_mode(MODE_DATA),
781 }
782 };
783 if !ready || !setup_mdec() {
784 return setup_failed();
785 }
786 if movie.xa.is_some() {
787 reader().cd_mut().set_audio_mixer(0x80, 0, 0x80, 0);
788 psx_spu::set_cd_volume(CdVolume::MAX, CdVolume::MAX);
789 psx_spu::enable_cd_audio(true);
790 }
791
792 let x2 = halfwords_x2(config.depth);
795 let _ = interrupts::take_queued_display_control();
796 clear_buffers(&mut dma, config);
797 let (x0, y0) = config.buffers[0];
798 psx_io::gpu::write_display_control(gp1::display_start(x0 as u32, y0 as u32));
799 let mode = display_mode();
800 if config.depth == Depth::Rgb24 {
801 psx_io::gpu::write_display_control(GP1_DISPLAY_MODE | mode | DISPLAY_24BIT);
802 }
803
804 if !r.start_read(movie.lba) {
806 leave_display(&mut dma, config, mode);
807 return setup_failed();
808 }
809
810 psx_io::timers::set_mode(psx_io::timers::Timer::Timer2, 0x0200);
811 let start = interrupts::vblank_count();
812 let mut p = Player {
813 dma,
814 st: Stream {
815 buf,
816 last_frame: 0,
817 frames: movie.frames,
818 done: false,
819 cd_error: false,
820 started: false,
821 foreign: 0,
822 filling: 0,
823 ready: None,
824 decoding: None,
825 asm: FrameAssembler::new(),
826 skipped: 0,
827 last_sector_vblank: start,
828 },
829 buf,
830 movie: *movie,
831 x: (config.screen_width - movie.width) / 2 * x2 / 2,
832 step: 8 * x2,
833 y_offset: (config.screen_height - movie.height) / 2,
834 latency: config.latency_vblanks,
835 origins: config.buffers,
836 front: 0,
837 decoding: None,
838 mdec_frame: 0,
839 mdec_started: 0,
840 to_upload: None,
841 upload: None,
842 cols: Columns::start(0, 0, 0, 0, 0),
843 waiting: [None, None],
844 queued: None,
845 pending: None,
846 shown: 0,
847 late: 0,
848 worst_late: 0,
849 errors: 0,
850 in_a_row: 0,
851 wedged: false,
852 clock: Clock {
853 phase: PHASE_WAIT,
854 last: psx_io::timers::counter(psx_io::timers::Timer::Timer2),
855 acc: [0; 3],
856 },
857 };
858 let mut polled = start;
859 let mut skipped = false;
860 let rows = movie.height as u32 / 16;
861 let macroblocks = movie.width as u32 / 16 * rows;
862 loop {
863 p.tick();
864 if p.wedged {
865 break;
866 }
867 let now = interrupts::vblank_count();
868 if now != polled {
869 polled = now;
870 if poll() {
871 skipped = true;
872 break;
873 }
874 }
875 if p.pending.is_none() {
877 if let Some((slot, bytes, arrived)) = p.st.ready.take() {
878 p.clock.switch(PHASE_VLC);
879 p.st.decoding = Some(slot);
880 let rle = match p.decoding {
881 Some((r, _, _)) => 1 - r,
882 None => 0,
883 };
884 let frame_bytes = &p.buf.slot(slot)[..(bytes as usize).min(p.buf.slot_words * 4)];
885 let out = p.buf.rle16(rle);
886 let decoded = bitstream::decode_frame(
887 frame_bytes,
888 out,
889 macroblocks,
890 PUMP_MACROBLOCKS,
891 &mut || p.tick(),
892 );
893 p.st.decoding = None;
894 match decoded {
895 Ok(words) => p.pending = Some((rle, words, arrived.wrapping_add(p.latency))),
896 Err(_) => p.errors += 1,
897 }
898 let phase = p.idle_phase();
899 p.clock.switch(phase);
900 continue;
901 }
902 }
903 if p.decoding.is_none() && p.pending.is_some() {
904 if let (Some(b), Some(f)) = (p.free_buffer(), p.free_frame()) {
905 let Some((rle, words, due)) = p.pending.take() else {
906 continue;
907 };
908 p.clock.switch(PHASE_MDEC);
909 let depth = match config.depth {
910 Depth::Rgb15 => DECODE_15BPP,
911 Depth::Rgb24 => DECODE_24BPP,
912 };
913 if unsafe { mdec().decode_start(p.buf.rle(rle), words, depth) }.is_err() {
916 p.errors += 1;
919 continue;
920 }
921 if unsafe { mdec().read_column_start(p.buf.frame(f), p.buf.frame_words) } {
925 p.mdec_frame = f;
926 p.mdec_started = interrupts::vblank_count();
927 p.decoding = Some((rle, b, due));
928 } else {
929 mdec().abort_decode();
932 p.decode_failed();
933 }
934 continue;
935 }
936 }
937 let idle = now.wrapping_sub(p.st.last_sector_vblank);
938 if p.drained() && p.st.ready.is_none() && (p.st.done || idle > config.stall_vblanks) {
939 break;
940 }
941 let phase = p.idle_phase();
942 p.clock.switch(phase);
943 }
944 let _ = interrupts::take_queued_display_control();
946 mdec().abort_decode();
947 psx_io::dma::abort(psx_io::dma::Channel::Gpu);
948 if p.cols.uploading {
949 psx_io::gpu::write_display_control(gp1::RESET_CMD_BUFFER);
952 }
953 reader().stop();
955 if movie.xa.is_some() {
956 psx_spu::set_cd_volume(CdVolume(0), CdVolume(0));
957 }
958 if config.depth == Depth::Rgb24 {
959 leave_display(&mut p.dma, config, mode);
960 }
961 let stop = if skipped {
962 Stop::Skipped
963 } else if p.wedged {
964 Stop::Wedged
965 } else if p.st.cd_error {
966 Stop::CdError
967 } else if p.st.done {
968 Stop::End
969 } else {
970 Stop::Stall
971 };
972 let per = (p.shown + p.st.skipped).max(1);
973 let kcyc = |phase: usize| p.clock.acc[phase] / per * 8 / 1000;
974 Outcome {
975 stop,
976 shown: p.shown,
977 skipped: p.st.skipped,
978 late: p.late,
979 worst_late_vblanks: p.worst_late,
980 dropped: p.st.asm.dropped,
981 decode_errors: p.errors,
982 last_frame: p.st.last_frame,
983 vblanks: interrupts::vblank_count().wrapping_sub(start),
984 kcyc_vlc: kcyc(PHASE_VLC),
985 kcyc_mdec: kcyc(PHASE_MDEC),
986 kcyc_wait: kcyc(PHASE_WAIT),
987 }
988}