| 
   Learn Multi platform 8086 Assembly
          Programming... For World Domination!
 
 Platform Specific Lessons
 
      
        
          |  
  | Lesson
                P11 - Sound on the Wonderswan The wonderswan has pretty powerful sound for a handheld!... With 4
            channels capable of playing digital sound samples, we can create
            some decent digital music!
 
 Lets make a noise!
 
 |  |  WSW_JoypadSprite.asm
 | 
 
 |  |    The WonderSwan sound hardware
 
      
        
          | The sound processor uses wave samples at the address defined by
            port 08Fh. Each channel uses 16
            bytes (32 4 bit samples) If we define the base as being 0D00h
              (by writing 34h to port 08Fh) the following addresses will define
            the samples used by the sound processor: | 
              
                
                  | Channel | Address |  
                  | 1 | 0D00h |  
                  | 2 | 0D10h |  
                  | 3 | 0D20h |  
                  | 4 | 0D30h |  |    
        
        
          
            | Port | Direction | Function | Bits | Details |  
            | 080h | RW | REG_SND_CH1_PITCH
                L | LLLLLLLL | Pitch
                (Higher number=Higher pitch) |  
            | 081h | RW | REG_SND_CH1_PITCH
                H | -----HHH | 
 |  
            | 082h | RW | REG_SND_CH2_PITCH
                L | LLLLLLLL | Pitch
                (Higher number=Higher pitch) |  
            | 083h | RW | REG_SND_CH2_PITCH
                H | -----HHH | 
 |  
            | 084h | RW | REG_SND_CH3_PITCH
                L | LLLLLLLL | Pitch
                (Higher number=Higher pitch) |  
            | 085h | RW | REG_SND_CH3_PITCH
                H | -----HHH | 
 |  
            | 086h | RW | REG_SND_CH4_PITCH
                L | LLLLLLLL | Pitch
                (Higher number=Higher pitch) |  
            | 087h | RW | REG_SND_CH4_PITCH
                H | -----HHH | 
 |  
            | 088h | RW | REG_SND_CH1_VOL | LLLLRRRR | L=Left
                R=Right (15=loud) |  
            | 089h | RW | REG_SND_CH2_VOL | LLLLRRRR | L=Left
                R=Right (15=loud) |  
            | 08Ah | RW | REG_SND_CH3_VOL | LLLLRRRR | L=Left
                R=Right (15=loud) |  
            | 08Bh | RW | REG_SND_CH4_VOL | LLLLRRRR | L=Left
                R=Right (15=loud) |  
            | 08Ch | RW | REG_SND_SWEEP_VALUE | SSSSSSSS | 
 |  
            | 08Dh | RW | REG_SND_SWEEP_TIME | ---TTTTT | 
 |  
            | 08Eh | RW | REG_SND_NOISE | ---ERMMM | E=Enable /
                R=Reset / M=Mode |  
            | 08Fh | RW | REG_SND_WAVE_BASE | AAAAAAAA | Wave
                address >>6 (34h= 0D00h) |  
            | 090h | RW | REG_SND_CTRL | NSV-4321 | N= ch4
                Noise / S= ch3 Sweep / V= ch2 Voice / M=Channel Modes / 4321 -
                Channel enable |  
            | 091h | RW | REG_SND_OUTPUT | 
 | 
 |  
            | 092h | R | REG_SND_RANDOM
                L | 
 | 
 |  
            | 093h | R | REG_SND_RANDOM
                H | 
 | 
 |  
            | 094h | RW | REG_SND_VOICE_CTRL | 
 | 
 |  
            | 095h | RW | REG_SND_HYPERVOICE | 
 | 
 |  
            | 096h | RW | REG_SND_9697
                L | 
 | 
 |  
            | 097h | RW | REG_SND_9697
                H | 
 | 
 |  
            | 098h | RW | REG_SND_9899
                L | 
 | 
 |  
            | 099h | RW | REG_SND_9899
                H | 
 | 
 |  
            | 09Ah | R | REG_SND_9A | 
 | 
 |  
            | 09Bh | R | REG_SND_9B | 
 | 
 |  
            | 09Ch | R | REG_SND_9C | 
 | 
 |  
            | 09Dh | R | REG_SND_9D | 
 | 
 |  
            | 09Eh | R | REG_SND_9E | 
 | 
 |    Introducing ChibiSound!
      
      
        
          
            | Since the earliest of my tutorials,
              I've handled sound with a simple sound driver knows as
              'ChibiSound' 
 This takes an 8 bit byte value from 0-255, and make a sound of
              selectable pitch, with noise or half volume in a similar way on
              all our systems!
 This was created for Grime Z80, and allows common sound code to
              give similar effects on all the systems!
 
 All we do is load the AL register with a value, and call
              ChibiSound!
 
 Of course, this won't be enough to make music (please wait for
              ChibiSound Pro - yes really!) but it will give us some simple SFX,
              and make it easy to compare doing simple tasks on our various
              systems!
 
 | 
                
                  in all cases, smaller numbers are higher pitch, so 10h is higher
              than 11h
                    | AL Value | Effect |  
                    | 00h | Sound Off |  
                    | 01h-3Fh | Quiet tone |  
                    | 40h-7Fh | Loud tone |  
                    | 80h-BFh | Quiet Noise |  
                    | C0h-FFh | Loud Noise |  |  
 Writing ChibiSound    
      
        
          
            | Before we can make a sound we need to do two things! 
 First we need to set the base memory address of our sound samples
              0D00h, we write 34h to port 08Fh to set the memory address.
 
 Next we need to create a wave - We write 16 bytes, one nibble per
              sample.... We make a square wave by writing a sequence of 0 and F
              bytes
 
 We need to make noise in some cases, so we use Channel 4 in all
              cases in this example
 
 |  |  
            | First we check if AL=0, if it is, we need to turn off the sound. 
 We silence the channels by setting bit 3 to zero of port 090h
 
 |   |  
            | Next we set the volume, we only have 1 bit setting our volume in
              the parameter - bit 6. 
 we set the bits of port 08Bh  to set the volume - 15 is the
              maximum - 0 is the minimum volume
 
 |   |  
            | We need to set the pitch. The Wonderswan uses a 11 bit
              frequency. 
 We set the pitch using ports 086h (L) and 087h (H)... we only have
              6 pitch bits in our chibisound parameter, so we need to bitshift!
 |   |  
            | If bit 7 of our chibisound parameter is 1, we need to set the
              noise to on! 
 We need to set the Noise on  with bit 7 of port 090h (we also
              set channel 4 on with bit 3).
 
 We also need to set the noise to ON, and configure it with port
              08Eh
 
 |   |  
            | If noise is off, we just need to set bit 3 of port 090h to 1 to
              enable the channel without noise. 
 |  |  
 
      
        
          
            | Sound channels 2,3 and 4 on
                the Wonderswan all have different capabilities, but at a basic
                level they all play digital samples with frequency synthesis. |  |  
 
 
 
 
 
 |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Buy my Assembly programming book
 on Amazon in Print or Kindle!
 
 
  
 
  
 
  
 Available worldwide!
 Search 'ChibiAkumas' on
 your local Amazon website!
 Click here for more info!
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 |