Annotation of hatari/src/psg.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari
                      3: 
                      4:   Programmable Sound Generator (YM-2149) - PSG
1.1.1.3 ! root        5: 
        !             6:   ChangeLog:
        !             7: 
        !             8:   9 Aug 2003  Matthias Arndt <[email protected]>
        !             9:        - added hook for printer dispatcher to PSG Port B (Reg 15)
        !            10:        - added flag to decide if last write did go to IOB
        !            11: 
        !            12:   10 Aug 2003
        !            13:     - corrected bug in printer dispatcher: STROBE is Bit5 counted from 0 (32 instead of 16)
1.1       root       14: */
                     15: 
                     16: #include "main.h"
1.1.1.3 ! root       17: #include "configuration.h"
1.1       root       18: #include "memAlloc.h"
                     19: #include "memorySnapShot.h"
                     20: #include "sound.h"
1.1.1.3 ! root       21: #include "psg.h"
        !            22: 
        !            23: /* printer.h  because Printer I/O goes through PSG Register 15 */
        !            24: #include "printer.h"
1.1       root       25: 
                     26: unsigned char PSGRegisterSelect = 0;                  /* 0xff8800 (read/write) */
                     27: unsigned char PSGRegisters[16] = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 };  /* Register in PSG, see PSG_REG_xxxx */
                     28: 
1.1.1.3 ! root       29: /* boolean flag: did the last write to the PSG go to IOB? */
        !            30: BOOL bPSG_LastWriteToIOB;
1.1       root       31: 
                     32: /*-----------------------------------------------------------------------*/
                     33: /*
                     34:   Reset variables used in PSG
                     35: */
                     36: void PSG_Reset(void)
                     37: {
                     38:   PSGRegisterSelect = 0;
                     39:   Memory_Clear(PSGRegisters,sizeof(unsigned char)*16);
1.1.1.3 ! root       40:   bPSG_LastWriteToIOB=FALSE;
1.1       root       41: }
                     42: 
1.1.1.2   root       43: 
                     44: /*-----------------------------------------------------------------------*/
1.1       root       45: /*
                     46:   Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
                     47: */
                     48: void PSG_MemorySnapShot_Capture(BOOL bSave)
                     49: {
1.1.1.2   root       50:   /* Save/Restore details */
1.1       root       51:   MemorySnapShot_Store(&PSGRegisterSelect,sizeof(PSGRegisterSelect));
                     52:   MemorySnapShot_Store(PSGRegisters,sizeof(PSGRegisters));
                     53: }
                     54: 
1.1.1.2   root       55: 
                     56: /*-----------------------------------------------------------------------*/
1.1       root       57: /*
                     58:   Write byte to 0xff88000, this is used as a selector for when we read/write to address 0xff8802
                     59: */
                     60: void PSG_WriteSelectRegister(unsigned short v)
                     61: {
                     62:  PSGRegisterSelect = v & 0x0f;              /* Store register to select (value in bits 0-3) */
                     63: }
                     64: 
1.1.1.2   root       65: 
                     66: /*-----------------------------------------------------------------------*/
1.1       root       67: /*
                     68:   Read byte from 0xff8800, returns to PSG data
                     69: */
                     70: unsigned short PSG_ReadSelectRegister(void)
                     71: {
1.1.1.2   root       72:  /* Read data last selected by register */
1.1       root       73:  return PSGRegisters[PSGRegisterSelect];    /* Return value from PSGRegisters[] */
                     74: }
                     75: 
1.1.1.2   root       76: 
                     77: /*-----------------------------------------------------------------------*/
1.1       root       78: /*
                     79:   Write byte to 0xff8802, stores according to PSG select register(write 0xff8800)
                     80: */
                     81: void PSG_WriteDataRegister(unsigned short bl)
                     82: {
                     83:  Sound_Update();                            /* Create samples up until this point with current values */
                     84:  PSGRegisters[PSGRegisterSelect]=bl;        /* Write value to PSGRegisters[] */
                     85:  if( PSGRegisterSelect==13 )                /* Whenever 'write' to register 13, cause envelope to reset */
                     86:   {
                     87:    bEnvelopeFreqFlag = TRUE;
                     88:    bWriteEnvelopeFreq = TRUE;
                     89:   }
1.1.1.3 ! root       90: 
        !            91:  /* Matthias Arndt <[email protected]>    9 Aug 2003
        !            92:   * FIXME: This is only a prelimary dirty hack!
        !            93:   * Port B (Printer port) - writing here needs to be dispatched to the printer
        !            94:   * STROBE (Port A bit5) does a short LOW and back to HIGH when the char is valid
        !            95:   * To print you need to write the character byte to IOB and you need to toggle STROBE
        !            96:   * (like EmuTOS does)....therefor we print when STROBE gets low and last write access to
        !            97:   * the PSG was to IOB
        !            98:   */
        !            99:  if(ConfigureParams.Printer.bEnablePrinting) /* Printer dispatching only when printing is activated */
        !           100:   {
        !           101:        if( PSGRegisterSelect==PSG_REG_IO_PORTA )
        !           102:         {
        !           103:        /* is STROBE LOW?  */
        !           104:        if((PSGRegisters[PSG_REG_IO_PORTA]&32)==0)
        !           105:                  /* did the last write go to IOB? then we want to print something... */
        !           106:              if(bPSG_LastWriteToIOB==TRUE)
        !           107:                        Printer_TransferByteTo(((unsigned char) PSGRegisters[PSG_REG_IO_PORTB] & 0xff));
        !           108: 
        !           109:                bPSG_LastWriteToIOB=FALSE;
        !           110:         }
        !           111:        else
        !           112:                if( PSGRegisterSelect==PSG_REG_IO_PORTB )
        !           113:                  {
        !           114:                bPSG_LastWriteToIOB=TRUE;
        !           115:                  }
        !           116:        else
        !           117:          bPSG_LastWriteToIOB=FALSE;
        !           118:   }
        !           119: 
1.1       root      120:  /* Check registers 8,9 and 10 which are 'amplitude' for each channel and store if wrote to(to check for sample playback) */
                    121:  if( PSGRegisterSelect==8 )
                    122:    bWriteChannelAAmp=TRUE;
                    123:  else if( PSGRegisterSelect==9 )
                    124:    bWriteChannelBAmp=TRUE;
                    125:  else if( PSGRegisterSelect==10 )
                    126:    bWriteChannelCAmp=TRUE;
                    127: }
                    128: 
1.1.1.2   root      129: 
                    130: /*-----------------------------------------------------------------------*/
1.1       root      131: /*
                    132:   Read byte from 0xff8802, returns 0xff
                    133: */
                    134: unsigned short PSG_ReadDataRegister(void)
                    135: {
                    136:  return 0xff;
                    137: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.