title: Is it possible to play PCM sound (.WAV) using 'Direct Mode' in DOS and display animation simultaneously?
body: <p>I have this working code in order to play PCM sound (.WAV) using 'Direct Mode' in DOS:
  <a href="https://github.com/leonardo-ono/Assembly8086SBHardwareLevelDspProgrammingTest/blob/master/playpcm_complete.asm" rel="nofollow noreferrer">ASM code plays .WAV in DOS</a></p>
  <p>It works perfectly (including timing, etc.).</p>
  <p>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:</p>
  <pre><code>        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
  </code></pre>
  <p>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 -&gt; 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?</p>