30 Commits

Author SHA1 Message Date
Andre Zeps
7f3be52193 FMV: Fixed regression of GOP Timecode
- Issue was introduced with 594bae844
- Fixes division by zero with Addams Family Disc 2 when
  opening playback controls
2026-05-02 19:07:03 +02:00
Andre Zeps
090ec12ea8 FMV: Fix missing last frame
Fix required for
https://github.com/Slamy/CDi_FMVTest/tree/main/fmv_event_timing
2026-02-22 14:12:37 +01:00
Andre Zeps
ec0ff3b771 FMA: Fixed regression with timing of buffer underflow IRQ
Fixes regression by 7e3d995781
2026-02-22 14:12:37 +01:00
Andre Zeps
112d467b92 FMV: Altered timing of DTS register
- Slightly improves stability of MPEG pause and continue
  with "Lost Ride"
  Still not 100% there...
2026-02-22 14:12:37 +01:00
Andre Zeps
594bae844e FMV: Fixed timing of frame events and parameters
- Decoupled SEQ event from GOP event.
  Now behaves like real VMPEG hardware
- Fixes Lost Ride gameplay after vehicle charge intro
- Fixes timing accuracy of temp ref and time code
  Measurable with mv_status()
2026-02-22 14:12:37 +01:00
Andre Zeps
176e9b6403 FMV: Add support for mid stream sequence parameter change
- Fixes graphical issues after vehicle charge intro
  in "Lost Ride"
2026-02-22 14:12:37 +01:00
Andre Zeps
0393f32cd0 FMV: Patch pl_mpeg for prediction of skipped macroblocks after the slices
- Fixes glitches on macroblock level at the bottom right
2026-02-22 14:12:37 +01:00
Andre Zeps
47addf7da0 FMA: Fixed MPEG Audio Frame Header Register
- Replaced stub with actual data from stream
- Fixes value of MAS_Head as returned by ma_status()
  - Stereo and Mono are correctly detected by VCD bridge
2026-02-22 14:12:37 +01:00
Andre Zeps
7e3d995781 FMA: Fixed timing of buffer underflow IRQ
- Fixes ma_hostplay() and ma_loop() combo of "The Lost Ride"
  to play the railroad ambient sound

Game is still not playable
2026-01-30 21:41:08 +01:00
Andre Zeps
957ab71ae2 FMV: Added experimental slow motion and single step
- Added slow motion mode
- Added support for single step
- Fixes playback control problems with "Imagination in Motion - A New Era in 3D Chill Out Video"

This commit introduces technical debt
- The stepping mechanism is not fully understood
- Slow motion seems to desync audio and video when resuming normal playback

With the current state, the playback speed is still dictated
by the MPEG decoder. It might be possible, that this is wrong.
2026-01-16 19:02:03 +01:00
Andre Zeps
df9e95abf4 FMV: Extended headroom for framebuffers
- Fixes data corruption when output
  buffer is full with 26 frames

I was able to prove that 30 framebuffers
are not enough when allowing 26 of them
to be queued for viewing.
There is a certain distance between
allocation and actually offering the framebuffer
to the queue of ready frames.
It can reach up to 5 frames, it seems.
This is probably the result of B and P frames?
2026-01-12 18:11:44 +01:00
Andre Zeps
77c4a85d30 FMV: Allow up to 25 frames in picture FIFO
- Fixes long videos with even smaller frame size
- Fixes even more videos in "Les Guignols de l’Info"

This is the change of b8e3bac amplified.
The failing video this time is at seek position 0xB278800.
The previous one failing was 208x128, this one is
even smaller with 160x112.

It reaches a FIFO level of 21 until playback is started
even on real hardware.
2026-01-07 20:23:28 +01:00
Andre Zeps
b8e3baca21 FMV: Allow up to 17 frames in picture FIFO
- Fixes long videos with small frame size
- Fixes videos in "Les Guignols de l’Info"

A user has mentioned that "Les Guignols de l’Info" sometimes has problems with videos.

After analysis of "/cd/rtf/application.rtf" from said disc,
starting at byte position 0x11DEA000, it turns out that the
pictures in FIFO (0x0E040A4) can go up to 17 even on real hardware.
This has never happened before and I've assumed that 8 is the maximum.

This is an issue because DecodTS of fdrvs1 calculates the DTS of the next picture with
the formula GEN_DEC_TIM1 (0x0E040A0) - GEN_PINF (0x0E040A4) * GEN_PICT_RATE (0x0E040A8).
This means that GEN_DEC_TIM1 is constantly increasing but GEN_PINF was limited to 8
before. This resulted in having the next picture to show getting more and more out of reach
of V_SCR.

On real hardware, the FIFO reaches 14 until playback starts.
2026-01-04 11:23:43 +01:00
Andre Zeps
f855ffc493 FMV: Fixed some meta data returned by MV_Status
- Fixed temporal ref and both frame rate registers
- Effect on commerical titles unknown
2025-12-28 15:49:43 +01:00
Andre Zeps
3fff0f0e41 FMV: Fix for pl_mpeg parsing single frame videos
This library is not suited for playback of short MPEG files and
pauses in stream delivery at the same time.
If the stream has not enough data, frame generation is aborted.
So one would assume to just always wait until enough data
is there to decode. But that is trap, because short MPEG files
are never decoded on time.

This fix does 2 things
- If enough data for one frame to decode is available, communicate
  at least 1 frame in the FIFO to the driver even so it is not yet
  fully commited by pl_mpeg.
- Don't wait for data as soon as the driver has
  instructed VMPEG to decode and play. I would guess that the buffer is
  filled enough at that point to not underflow.
- Since my guess was wrong as underflows can still occur,
  to abort the wait, the output buffer must be empty too.

There is also another fix here. The worker descriptor must now
be manually committed to increment the command counter.
Since waiting for data can now be aborted, it is possible
that a requested buffer for a worker descriptor needs to be thrown away,
which resulted into a wrong increment and an assertion failure ont the worker side.
2025-12-28 15:49:43 +01:00
Andre Zeps
da3bfd7467 FMV: Added 3rd MPEG macroblock worker core
- Increases computing power for pixel operations
- Fixes freeze at timecode 04:32 of
  "Star Trek VI - Terre Inconnue (France) (Disc 1)"
  during the shock wave scene
2025-12-21 22:02:28 +01:00
Andre Zeps
e543fdaa0e FMV: Fix last missing macroblock
- Very small frame sizes (e.g. 16x128) don't work without this
2025-12-19 14:56:53 +01:00
Andre Zeps
768996504e FMV: Fixed framebuffer jump when sequence header was found
- Was noticable with Top Gun when scanning
- Fixes regression from 120a2d74e since the sequence
  header cache can now be invalidated
2025-12-18 13:30:33 +01:00
Andre Zeps
fd43dbad1d FMV: Added another huffman table to hardware decoding unit
- Reduces CPU load of decoder core
- Fixes playback of "Secret of Nimh (VCD)"
- Fixes freeze in the early minutes of
  "Star Trek VI - Terre Inconnue (France) (Disc 1)"
2025-12-18 13:30:33 +01:00
Andre Zeps
f7b4e9db49 FMV: Removed the pixel aspect ratio conversion to reduce memory footprint
The CD-i has no support for this header field.
Instead - at least with VMPEG -, one of two pixel clocks
can be configured via a register at 0x0E01000
2025-12-15 22:37:24 +01:00
Andre Zeps
1c41f27f51 MCD212: Improved accuracy of display active bit
- Seems to have no effect at all but is more cycle accurate.
- Also uses less FPGA resources
2025-11-23 21:10:11 +01:00
Andre Zeps
120a2d74e2 FMV: Discard SEQ HDR cache when a new header is in reach
There is no evidence yet for an indication by VMPEG driver code,
that the sequence header cache needs to be discarded.
The FMV bitstream decoder firmware will now check whether a header
exists during the startup of the decoding process.
If one exists, the cache is not used.

- Fixes regression between CDi_dvc_rc2 and CDi_dvc_rc3
  caused by using a cached but wrong SEQ HDR
2025-11-23 20:40:21 +01:00
Andre Zeps
4501cdc6df FMV: Fixed order of memory writes in decoder
- Ensures that the "first I frame of GOP" info is correctly communicated
2025-11-13 19:45:25 +01:00
Andre Zeps
ad65b8a5f3 Altered linker and startup scripts
in an attempt to fix memory errors after resets.
The error is no longer occuring

- .bss segment erase no longer overwrites first word of .noinit
- .data segment no longer overwritten by itself

Also added an endurance test which scans through the video
and tries to encourage this issue
2025-11-13 19:45:25 +01:00
Andre Zeps
b724f4ab4f FMV: Increased stability of decoding process resume
- Frame buffer indexes kept between resets
  - Avoids display of not committed buffers
- Discard frames until first I frame
  - Avoids corrupted graphics during scanning
- Sequence header configuration protected from restart
  - Configuration validity stored outside of soft core

- Fixes continuing playback of "Coneheads" which
  only has one SEQ header at the start of whole stream

- Fixes scanning through Top Gun
2025-11-10 16:50:36 +01:00
Andre Zeps
572d480084 FMV: Adaptive frame rate based on frame buffer level
Doing this might not be the correct approach.
It hopefully doesn't hurt but protects the decoder from being
paused for too long
2025-11-02 13:11:42 +01:00
Andre Zeps
46510d4a2a FMV: Avoid overflow of FMV Picture FIFO
Decoder is paused when YUV Display FIFO is full
2025-11-02 13:11:41 +01:00
Andre Zeps
142207fcca FMV: Increased accuracy of video IRQs
- Added EOI - ISO 11172 End Code detection in demuxer
- Added EOS - Sequence End Code detection in decoder firmware
- SEQ, GOP and PIC no longer generated by bitstream decoder
- PIC now aligned to vblank before a new picture is shown
- SEQ and GOP now aligned to PIC when its the first I frame of a GOP
- LPD now aligned to PIC when it was the last picture
- BUF - Buffer underflow now detected by firmware
- Added pictures in FIFO register (00E040A4)
- Added DTS register (00E040A0)
- Added VDI register for DTS updates (0E0408C)
- FMV Playback start no longer decided by demuxer but by VMPEG ROM
- Added pixel width calculation for later use

- Fixes hang at the end of the Space Ace Intro

Names of events to according
https://github.com/TwBurn/cdi-docs/blob/main/mv_cbnd.md#mv_trigger-define-mpeg-video-events-to-signal
2025-11-02 13:11:41 +01:00
Andre Zeps
f54e5da706 FMA: Re-enable underflow handling
Fixed occurence of UNF event
2025-11-02 13:11:41 +01:00
Andre Zeps
3698b47f60 Add source code of MPEG decoder firmware
Removes dependence to https://github.com/Slamy/fpga_soft_mpeg
to ease change management.

Matching git hashes from said repo:
Audio 2fd79f6ff5445baaa5634f66cd0ef83643db4704
Video 8d0abb4b85d0626d35263aa5facc387123e36f2a

Expected md5sums with this commit

0489b54f46a11e1ded36e4a2d51d0e9f  ./rtl/mpeg/fma/firmware.mem
8673facd20983f1dfa4c4d301a374338  ./rtl/mpeg/fmv/firmware2.mem
c16c0dfde857b47c6fe251d4e8deb5ab  ./rtl/mpeg/fmv/firmware.mem
2025-10-30 19:13:56 +01:00