0

I have this working code in order to play PCM sound (.WAV) using 'Direct Mode' in DOS: ASM code plays .WAV in DOS

It works perfectly (including timing, etc.).

However I'd like to improve this code so meanwhile I play the .WAV file, I'd like to display an animation in 320*200 video mode. I'd like to change memory pages as well, something like this:

        mov     al,0x13
        int     0x10

    MAIN:    
        mov ax,08000h
        mov     es,ax
        push    cs
        pop     ds


        ;[put animation code here: e.g. one frame of a rotating cube at a time]


        push    es    ; then change the video memory page and clear the screen
        pop     ds
        mov ax, 0a000h
        mov es,ax

        mov     cx,32001
        xor     si,si
        mov     di,si
        rep     movsw

        mov     ah,0x11
        int     0x16
        jz      near MAIN    ; and jump back to MAIN

So how to merge the two codes? How to play a .WAV file in DOS and display an animation simultaneously? It would be also cool, if displayed frames and played 'music chunks' could be synchronized in a way that if you have a slower machine and if you can display e.g. just 5 frames/second then you should hear 5 'chunks of music'/second. In other words: less frames/second -> sloooower music. Or vica versa: skipping frames if the animation is too slow. The above mentioned code that plays the .WAV file has a waiting loop, probably we could put the animation code here, but both codes use ES register and stuff, so they cannot be easily merged. How to solve the register collision?

Fract
  • 323
  • 1
  • 6
  • 22
  • 2
    The wav code clearly has a waiting loop. You can insert your frame drawing there. It will then automatically synchronize with the sound. Caveat: your code should be fast enough to fit between samples of course. Otherwise you will need to break it up into parts. – Jester Jan 07 '22 at 23:25
  • 2
    Jester's comment means: You cannot use the method that is used in the code on GitHub to play sound at the same time as displaying an animation. However, you may also use DMA and interrupts to play sound. And this can be done at the same time an animation is displayed. However, you will need a lot of programming knowledge to work with DMA and interrupts... – Martin Rosenau Jan 08 '22 at 07:12
  • 1
    Do you mean you want the same PCM samples to be played back at a lower sample rate on slower machines, so as well as slower, they're lower pitch? – Peter Cordes Jan 08 '22 at 09:11

0 Answers0