Digisound via PSG

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Arne
Atari Super Hero
Atari Super Hero
Posts: 507
Joined: Thu Nov 01, 2007 10:01 am

Digisound via PSG

Postby Arne » Sun May 12, 2019 10:08 am

Hi Folks,

trying to implement a Digisound function in ASM/Pure C for the PSG.
I searched the forum and found this http://www.atari-forum.com/viewtopic.php?f=16&t=16152&p=141914 thread.
unseenmenace attached a ZIP with a small ASM routine that I am trying to implement. By now I just got noise
emitting from the speakers. :-(
So the code from unseenmenace looks like this:

Code: Select all

    section text

sample_length   dc.l    sample_end-sample

player   movem.l d0-d1/a6,-(sp)
      move.l  usp,a6      ; Get pointer to current sample
      moveq.l #0,d0
      move.b  (a6)+,d0   ; Get sample byte
      lsl.w   #3,d0      ; *8
      subq.l  #1,position   ; Decrement counter
      bne.s   .play
      lea.l   sample,a6   ; Loop sample if it we reached the end
      move.l  sample_length(pc),position
.play   move.l  a6,usp      ; Store address to the next sample
      lea.l   $ffff8800.w,a6   ; YM2149
      movem.l .da_table(pc,d0.l),d0/d1
      movep.l d0,(a6)      ; Output volume data to YM-register,
      move.l  d1,(a6)      ; this is how the DA is emulated
      movem.l (sp)+,d0-d1/a6
      rte

.da_table   include 'da_table.s'


First 8 Byte of da_table look like this:

Code: Select all

 dc.w $80e,$90d,$a0c,$0 (..)


I converted a WAV on the PC with Goldwave to a 9600Hz/Mono/RAW file (i.e. no header)
And I'm using STEEM 3.9.2 for my trials. Tested it on a MSTE once and it gave the same result.
As far as I understand the $08/$09/$0A of the upper byte in each word of da_table set the register
to 8/9/10 (volume control of the PSG) and next byte sets the volume.
I set up TimerA for 9600Hz, i.e.

Code: Select all

Xbtimer(0, 0x05, 0x04, player); /* Div64, Count to 4: 2457600Hz/64/4 = 9600   */


From http://www.stcarchiv.de/stc1987/12/timer-und-interrupts I learned that the
Timer-IRQ shall be serviced by clearing bit #5 in ISRA.
So I added a

Code: Select all

      bclr   #5,$FFFA0F

in front of

Code: Select all

      movem.l (sp)+,d0-d1/a6
      rte


Questions
  • What is "usp" in the code? Can't be UserStackPointer. I assume it is the position of the byte to be output i.e. used as index into da_table?
  • That movem.l .da_table(pc,d0.l),d0/d1 should fill D0 <- $080E090D and D1 <- $0A0C0000 if D0 was 0 before
    Then I do not understand the purpose of the next movep.l.
    This should poke the D0 content into the PSG like this:
    $FF8800 <- $08
    $FF8802 <- $0E
    $FF8804 <- $09
    $FF8806 <- $0D

    But control/Data regs of the PSG are located on $FF8800/$FF8802 only
  • And what purpose serves the next move.l?
    D1 should be poked into PSG like this:
    $FF8800 <- $0A
    $FF8801 <- $0C
    $FF8802 <- $00
    $FF8803 <- $00
  • Is there any additional MFP/PSG init stuff to do?
And the final question: did anybody ever use the function given by unseenmenace successfully?

Thanx, Arne
Image

arf
Captain Atari
Captain Atari
Posts: 202
Joined: Thu May 17, 2012 9:56 pm
Location: Germany

Re: Digisound via PSG

Postby arf » Sun May 12, 2019 1:06 pm

Arne wrote:Hi Folks,

trying to implement a Digisound function in ASM/Pure C for the PSG.


You may have a look at GEMJing (source available, PSG parts by Jörg Hahne in SAMROUTS.S).

czietz
Hardware Guru
Hardware Guru
Posts: 964
Joined: Tue May 24, 2016 6:47 pm

Re: Digisound via PSG

Postby czietz » Sun May 12, 2019 1:29 pm

Some remarks (without having tried unseenmenace's code): On an ST/STE the address for the PSG is not fully decoded, which is why it is possible to access its registers at $FF8804 and $FF8806 as well. The second MOVE.L probably should be a MOVEP.L. USP is the user stack pointer. The coder used it as spare register to keep track of the current sample. This means that your main program must not modify the user stack pointer, of course, otherwise garbage will be played. Probably the code assumes that the main program also runs in supervisor mode and therefore the USP is not used at all.

User avatar
Arne
Atari Super Hero
Atari Super Hero
Posts: 507
Joined: Thu Nov 01, 2007 10:01 am

Re: Digisound via PSG

Postby Arne » Sun May 12, 2019 1:47 pm

Thanks, I will have a thorough look into the SAMROUT sources as they look clean and neat.

About the USP: I always thought that only one SP (USP or SSP) is accessible by the programmer 8O
Anyway: I expected some address wrap-around in hardware and the move.l should really be a movep. Changed that but to no avail. That's why I asked if anyone ever successfully implemented that code snippet.
Instead of the USP I use a dc.l 1 for storage.
Image

User avatar
FedePede04
Atari God
Atari God
Posts: 1211
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Digisound via PSG

Postby FedePede04 » Sun May 12, 2019 2:53 pm

one of the problem is, you have to send the volume date over 3 round.
$ff8800 is the register of the sound chip
$ff8802 is the data you want to load the register with.

so if you want to set volume in channel A you need first to set 8 in $FF8800
and next you want to set a volume from 0-15 in $ff8802

so the data have to be pack in a order where you have first the channel in the upper byte and the data in lower byte.

what movep does is if you movep.w FF8800 it move the first byte in FF8800 and the second byte in FF8802... (not going to be use here but if you send it to FF8801 the next would byte be send to FF8803)

so your data stream have to look something like

Code: Select all

Channal, Data, Channal Data, Channal   Data
     8   0-15      9   0-15      10   0-15
ect.


so your loop is wrong depend on you conversions list it should be more like this

Code: Select all

      lea.l   $ffff8800.w,a6   ; YM2149
      movem.w .da_table(pc,d0.l),d0-d2
      movep.w d0,(a6)      ; Output volume data Channel A
      movep.w d1,(a6)      ; Output volume data Channel B
      movep.w d2,(a6)      ; Output volume data Channel C

Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
Arne
Atari Super Hero
Atari Super Hero
Posts: 507
Joined: Thu Nov 01, 2007 10:01 am

Re: Digisound via PSG

Postby Arne » Sun May 12, 2019 5:20 pm

FedePede04 wrote:so your loop is wrong depend on you conversions list it should be more like this


Not "my" loop. So I was not mistaken that the published code cannot run.
Anyway, thanks to arf and the GEMJing sources I've been able to make the code run. Bad noisy quality anyway :(
Thought it would be better.
Image

User avatar
FedePede04
Atari God
Atari God
Posts: 1211
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Digisound via PSG

Postby FedePede04 » Sun May 12, 2019 5:23 pm

Arne wrote:
FedePede04 wrote:so your loop is wrong depend on you conversions list it should be more like this


Not "my" loop. So I was not mistaken that the published code cannot run.
Anyway, thanks to arf and the GEMJing sources I've been able to make the code run. Bad noisy quality anyway :(
Thought it would be better.

try turn of the mixer so no sound is set to on

Code: Select all

move.b   #7,$ff8800
Move.b   #255,$ff8802


btw if you turn of the tone in the mixer, the gate of the pulse is always high, i can still play samples, but the internal pulse does not interfere with you samples, and if the freq in A,B or C is set to a really high freq it will produces a high pitch
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
Arne
Atari Super Hero
Atari Super Hero
Posts: 507
Joined: Thu Nov 01, 2007 10:01 am

Re: Digisound via PSG

Postby Arne » Sun May 12, 2019 5:48 pm

FedePede04 wrote:try turn of the mixer so no sound is set to on


Thanks, already did that as it is done in the GEMJing sources, too.
Checked my demo on a MSTE with SM124 and I have to say that the sound via the SM124 own speaker sounds better than via the speakers I have attached to my PC when playing the same demo via STEEM. Anyway: I'm happy now. Thanks guys. :D
Image

User avatar
FedePede04
Atari God
Atari God
Posts: 1211
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Digisound via PSG

Postby FedePede04 » Sun May 12, 2019 5:58 pm

Arne wrote:
FedePede04 wrote:try turn of the mixer so no sound is set to on


Thanks, already did that as it is done in the GEMJing sources, too.
Checked my demo on a MSTE with SM124 and I have to say that the sound via the SM124 own speaker sounds better than via the speakers I have attached to my PC when playing the same demo via STEEM. Anyway: I'm happy now. Thanks guys. :D


ok when the only thing i can think of,
is maybe the sample is a sign sample, try to convert the sample to a non sign sample. if it already a non sign sample, when try to make it a sign sample, that can also give a lot of noise.....
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 1 guest