Author Topic: how can we play sound in assembly using i/o ports only?  (Read 1941 times)

0 Members and 1 Guest are viewing this topic.

Offline nitrofurano

  • CPC664
  • ***
  • Posts: 61
  • Liked: 13
  • Likes Given: 46
hi!
i'm trying to play sound on cpc in assembly using i/o ports only, and getting no success at all... :S


i tried:


Code: [Select]

    ld bc,$f782
    out (c),c
    ld bc,$f407
    out (c),c
    ld bc,$f638
    out (c),c
    ld bc,$f400
    out (c),c
    ld bc,$f6FE
    out (c),c
    ld bc,$f408
    out (c),c
    ld bc,$f60F
    out (c),c


and


Code: [Select]

    ld b,$F4
    out (c),c
    ld bc,$F607
    out (c),c
    ld bc,$F600
    out (c),c
    ld b,$F4
    out (c),c
    ld bc,$F638
    out (c),c
    ld bc,$F600
    out (c),c
    ld b,$F4
    out (c),c
    ld bc,$F600
    out (c),c
    ld bc,$F600
    out (c),c
    ld b,$F4
    out (c),c
    ld bc,$F6FE
    out (c),c
    ld bc,$F600
    out (c),c
    ld b,$F4
    out (c),c
    ld bc,$F608
    out (c),c
    ld bc,$F600
    out (c),c
    ld b,$F4
    out (c),c
    ld bc,$F60F
    out (c),c
    ld bc,$F600
    out (c),c

any idea? and thanks in advance!

(btw, please don’t suggest me to use firmware routines, sound queues, etc. - i really just want to use i/o ports directly only - i’m all focused on multitargeting/multiplatform development (trying to cover all z80-based machines that uses ay-3-891x), since if i could access ay-3-891x directly on ZX-Spectrum and MSX, it seems totally nonsense for me if i couldn’t do the same on CPC )



Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2277
  • Likes Given: 3478
Re: how can we play sound in assembly using i/o ports only?
« Reply #1 on: 14:17, 25 March 16 »
Code: [Select]
    ld bc,$F407 ;;<< register
    out (c),c
ld bc,&f6c0 ;;<<<<<< select register
out (c),c ;; <<<<<<<
    ld bc,$F600
    out (c),c ;; << back to inactive
    ld bc,$F438 ;; << data
    out (c),c
ld bc,&f680 ;; << write data to register
out (c),c
    ld bc,$F600
    out (c),c

Note the F6c0, f680 for select register and write register. Data goes to f4 not f6.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2277
  • Likes Given: 3478
Re: how can we play sound in assembly using i/o ports only?
« Reply #2 on: 14:18, 25 March 16 »
Code: [Select]
    ld bc,$F407 ;;<< register
    out (c),c
ld bc,&f6c0 ;;<<<<<< select register
out (c),c ;; <<<<<<<
    ld bc,$F600
    out (c),c ;; << back to inactive
    ld bc,$F438 ;; << data
    out (c),c
ld bc,&f680 ;; << write data to register
out (c),c
    ld bc,$F600
    out (c),c

Note the F6c0, f680 for select register and write register. Data goes to f4 not f6.

This writes 38 to register 07. Repeat the same pattern for all registers you want to write.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline nitrofurano

  • CPC664
  • ***
  • Posts: 61
  • Liked: 13
  • Likes Given: 46
Re: how can we play sound in assembly using i/o ports only?
« Reply #3 on: 14:39, 25 March 16 »
working excellently! thanks, @arnoldemu ! :)

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2277
  • Likes Given: 3478
Re: how can we play sound in assembly using i/o ports only?
« Reply #4 on: 14:43, 25 March 16 »
working excellently! thanks, @arnoldemu ! :)
you're welcome :)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline nitrofurano

  • CPC664
  • ***
  • Posts: 61
  • Liked: 13
  • Likes Given: 46
Re: how can we play sound in assembly using i/o ports only?
« Reply #5 on: 15:19, 25 March 16 »
thanks! and here is the bonus on the feedback, my very humble code made on ZX-Basic Compiler seems to play embedded .vgm files (almost) fine! :) (the bug is from my side, that i couldn’t figure out exactly what is happening, might be something getting misinterpreted from the code i made) - the idea is to, later, convert files from VortexTracker into something similar to .vgm (perhaps a more optimized file, since .vgm is usually relatively huge because redundant data), and play there in similar way (humbly saying, might be quite useful for game development, at least for me! :) )

Offline nitrofurano

  • CPC664
  • ***
  • Posts: 61
  • Liked: 13
  • Likes Given: 46
Re: how can we play sound in assembly using i/o ports only?
« Reply #6 on: 23:39, 25 March 16 »
btw, it’s interesting that ay-3-891x runs in a lower frequency on CPC than on ZX-Spectrum and MSX - for the 440hz (A-4 in germanic notation), it seems that on the 12bit (frequency values between 0 and 4095) frequency area used in the 6 first registers, it’s 142 on CPC, and 254 on ZX-Spectrum and MSX - is there any documentation or frequency table describing/confirming that?

Offline jsa

  • CPC464
  • **
  • Posts: 14
  • Country: fi
  • Hmmmm?
  • Liked: 1
  • Likes Given: 1
Re: how can we play sound in assembly using i/o ports only?
« Reply #7 on: 23:27, 31 March 16 »

If I recall right these things are clocked bit differently in all of those.

In MSX AY frequency is ~1.79 MHz contrary to Amstrad 1MHz. -> 142*1.79 = 254.18.
On ZX AY frequency is 1.77 so values should differ between ZX and MSX as well.








Online Bryce

  • The Hardware Guy.
  • Supporter
  • 6128 Plus
  • *
  • Posts: 11.960
  • Country: wf
  • It's not broken, it just hasn't been fixed yet.
    • index.php?action=treasury
  • Liked: 4350
  • Likes Given: 456
Re: how can we play sound in assembly using i/o ports only?
« Reply #8 on: 00:19, 01 April 16 »
The pitch difference between 1.77MHz and 1.79MHz AYs would be less 5Hz. Would you really notice a difference between 440Hz and 444Hz if you didn't have them playing at the same time in front of you?

Bryce.

Offline jsa

  • CPC464
  • **
  • Posts: 14
  • Country: fi
  • Hmmmm?
  • Liked: 1
  • Likes Given: 1
Re: how can we play sound in assembly using i/o ports only?
« Reply #9 on: 10:25, 03 April 16 »
I would not notice. But someone with "golden ears" might.  ;D . But then again why analyze music with "scope".



Offline trabitboy

  • Supporter
  • CPC664
  • *
  • Posts: 90
  • Country: be
  • Liked: 50
  • Likes Given: 74
Re: how can we play sound in assembly using i/o ports only?
« Reply #10 on: 10:50, 06 April 16 »
working excellently! thanks, @arnoldemu ! :)

Hi !
I'm trying direct AY access too, and couldn't help but see the source of your test is included :o )
It doesn't seem to be winape syntax, is it pasmo?

edit: my bad, just understood by looking at the .sh
instructive :)
« Last Edit: 11:52, 06 April 16 by trabitboy »