mvbg

VM_MUSIC_MUTE

VM_MUSIC_MUTE is a GBVM instruction used to control the mute state of individual music channels on the Game Boy’s audio hardware.

Purpose: The Game Boy has four independent audio channels (two pulse waves, one wave, and one noise channel) that are typically used to play music and sound effects. VM_MUSIC_MUTE allows for fine-grained control over which of these channels are audible. This is essential for:

This instruction takes a MASK that acts as a bitmask, where each of the four lower bits corresponds to one of the Game Boy’s four audio channels. A 1 in a bit position means the channel is not muted (audible), and a 0 means it is muted.

Syntax:

VM_MUSIC_MUTE MASK

Usage Example: Muting Music Channels During Dialogue

Imagine you have background music playing, but when a dialogue box appears, you want to mute the melody channel (Channel 1) and the bass channel (Channel 2) to make the dialogue clearer, while keeping the percussion (Channel 4) and a subtle pad (Channel 3) playing.

; In your script, when a dialogue box appears:

; Define mute masks for specific channels
.CHANNEL_1_BIT:
  .R_INT8 0b1000 ; Bit for Channel 1 (most significant of the 4 bits)
.CHANNEL_2_BIT:
  .R_INT8 0b0100 ; Bit for Channel 2
.CHANNEL_3_BIT:
  .R_INT8 0b0010 ; Bit for Channel 3
.CHANNEL_4_BIT:
  .R_INT8 0b0001 ; Bit for Channel 4 (least significant of the 4 bits)

; Mute mask to keep Channel 3 and 4 unmuted (0b0011)
; This means Channel 1 and 2 will be muted.
DIALOGUE_MUTE_MASK:
  .R_INT8 0b0011

; Mute mask to unmute all channels (0b1111)
UNMUTE_ALL_MASK:
  .R_INT8 0b1111

START_DIALOGUE:
  ; Mute channels 1 and 2, keep 3 and 4 playing
  VM_MUSIC_MUTE DIALOGUE_MUTE_MASK

  VM_LOAD_TEXT TEXT_DIALOGUE
  VM_DISPLAY_TEXT
  VM_INPUT_WAIT .INPUT_A

  ; Unmute all channels after dialogue ends
  VM_MUSIC_MUTE UNMUTE_ALL_MASK

  VM_RET

TEXT_DIALOGUE:
  .TEXT "Can you hear me now?"
  .TEXT_END

In this example, VM_MUSIC_MUTE DIALOGUE_MUTE_MASK changes the audio mix, making the music less intrusive during dialogue. After the dialogue, VM_MUSIC_MUTE UNMUTE_ALL_MASK restores the full music mix. This provides a dynamic and immersive audio experience, ensuring important game elements (like dialogue) are clearly heard.

Analogy to Game Boy Development: This is a direct interface with the Game Boy’s APU (Audio Processing Unit) registers. In modern audio production, it’s analogous to adjusting the faders on individual tracks in a digital audio workstation (DAW) or using a mixer to control the volume of different instruments. It provides fine-grained control over the game’s soundscape, allowing for dynamic and responsive audio cues.