News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Trouble playing a sound with the PSG

Started by awergh, 09:48, 28 January 18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

awergh

So I finally decided that it was time to be a little more adventurous and write some assembly language.  :)


Now I'm trying to play with sound and the PSG so what I want to do is play middle C.
Also the intent is to do it as straightforward as possible even though there is duplication in the code.
Once I have a functional example I can do something better.


Before I turned off the firmware nothing happened at all so I assume I have to do that.


However following that I just get noise instead of my expected note as if I'd done the following:
SOUND 1,476,100


I suspect there is something that I have overlooked but I cannot see it.





.area _DATA


.area _CODE

.globl cpct_disableFirmware_asm     ;; disables the firmware

_main::
    ;;im sure its necessary
    call cpct_disableFirmware_asm

    ;; set channel A to max volume
    ld  b,  #0xF4           ;; send register number to the PSG
    ld  c,  #8              ;; 8 is channel A volume
    out (c),c
   
    ld  b,  #0xF6           ;; Tell PSG a register number is going to be sent
    ld  c,  #0b11000000     ;; 11000000 means a register is going to be set
    out (c),c

    ld  b,  #0xF6           ;; now the PSG is set to inactive
    ld  c,  #0              ;; inactive = 0
    out (c),c

    ld  b,  #0xF4           ;; set value to the PSG (volume register)
    ld  c,  #15             ;; max volume
    out (c),c

    ld  b,  #0xF6           ;; tell the PSG the selected register (#8) is going
    ld  c,  #0b10000000     ;; to be written to (write = 10000000)
    out (c),c

    ld  b,  #0xF6           ;; return PSG to inactive
    ld  c,  #0              ;; inactive = 0
    out (c),c



    ;;hopefully write a sound to channel A (00 is low, 01 is high) - LOW
    ld  b,  #0xF4           ;; send register number to PSG
    ld  c,  #0              ;; 0 is channel A low frequency
    out (c),c

    ld  b,  #0xF6           ;; tell psg a register number is going to be set
    ld  c,  #0b11000000
    out (c),c

    ld  b,  #0xF6           ;; psg set to inactive
    ld  c,  #0
    out (c),c

    ld  b,  #0xF4           ;; set value to the PSG (low)
    ld  c,  #0xDE           ;; DE of 0x01DE
    out (c),c

    ld  b,  #0xF6           ;; tell the psg to select the register (which would be #0)
    ld  c,  #0b10000000     ;; so this is going to be written to
    out (c),c

    ld  b,  #0xF6           ;; psg to inactive
    ld  c,  #0
    out (c),c


;;hopefully write a sound to channel A (00 is low, 01 is high) - HIGH
    ld  b,  #0xF4           ;; send register number to PSG
    ld  c,  #1              ;; 1 is channel A high frequency
    out (c),c

    ld  b,  #0xF6           ;; tell psg a register number is going to be set
    ld  c,  #0b11000000
    out (c),c

    ld  b,  #0xF6           ;; psg set to inactive
    ld  c,  #0
    out (c),c

    ld  b,  #0xF4           ;; set value to the PSG (high)
    ld  c,  #0x01           ;; 01 of 0x01DE
    out (c),c

    ld  b,  #0xF6           ;; tell the psg to select the register (which would be #1)
    ld  c,  #0b10000000     ;; so this is going to be written to
    out (c),c

    ld  b,  #0xF6           ;; psg to inactive
    ld  c,  #0
    out (c),c


    ;;mixer control to turn on port A
    ld  b,  #0xF4           ;; send register number to the PSG
    ld  c,  #7              ;; 7 is mixer control
    out (c),c

    ld  b,  #0xF6           ;; tell psg a register is going to be set
    ld  c,  #0b11000000
    out (c),c

    ld  b,  #0xF6           ;; psg to inactive
    ld  c,  #0
    out (c),c

    ld  b,  #0xF6           ;; set value to the psg (mixer register)
    ld  c,  #0b00111110     ;; only turning on Port A
    out (c),c

    ld  b,  #0xF6           ;; tell the psg the selected register (mixer register) is going to be written to
    ld  c,  #0b10000000
    out (c),c

    ld  b,  #0xF6           ;; psg to inactive
    ld  c,  #0
    out (c),c


forever:
    jp forever              ;; Infinite loop



arnoldemu

This line is wrong:


ld  b,  #0xF6           ;; set value to the psg (mixer register)
    ld  c,  #0b00111110     ;; only turning on Port A
    out (c),c


Should be:


ld  b,  #0xF4           ;; set value to the psg (mixer register)
    ld  c,  #0b00111110     ;; only turning on Port A
    out (c),c


I would also advise sending silence before you write your sounds.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

awergh

Thankyou  ;D  I thought it might be something simple that.


Yes you are probably right about sending silence, I just wanted to start with a sound so that I could tell that it was working.
With that said I should probably have noticed that WinAPE has a registers window so that I can see what is happening.  :)

awergh

Quote from: arnoldemu on 11:48, 28 January 18
I would also advise sending silence before you write your sounds.


So on the question of silence which is the ideal way to do that (for channel A)?

       
  • Send 00 to registers 0 and 1
  • Set the volume to 0
  • Set the mixer control to turn off the channel?

Powered by SMFPacks Menu Editor Mod