BEEP VAL

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
alban lusitanae
Drutt
Posts: 28
Joined: Fri Jun 28, 2019 1:49 pm
Location: Portugal
Contact:

BEEP VAL

Post by alban lusitanae »

Hi to all

Been seeing in some test programs the usage of BEEP VAL "xyz" in more or less the same way the Poke Usr Data is normally used,
you do BEEP VAL and then between brackets insert a continuous string.

I have not found any good sources around this (guess it was another thing only know if you took a course at the time or bought some specialty magazines)?

Best regards
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BEEP VAL

Post by 1024MAK »

BEEP needs two parameters, the tone value and the duration.
VAL is a function that evaluates a string and returns (when possible) a number. VAL can be used to reduce the memory usage of a program. This may confuse you. ZX Spectrum BASIC hides a floating point version of any numerical constant (number) in a program. A numerical constant in the program is followed by its binary form, using the character 'CHR$ 14' followed by five bytes for the number itself. So the number 2 actually takes up 7 bytes!

However, I think you may be thinking of:
SOUND “abc”
SOUND requires a string expression, the letters in the string are the musical notes.

SOUND is only available on the 128K machines which have a dedicated sound chip (AY).

BEEP uses the ULA / gate array and is available on all ZX Spectrum models.

For more information read this section of the manual.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: BEEP VAL

Post by AndyC »

It's PLAY not SOUND, but otherwise 1024MAK has hit the nail on the head. It's usually about saving space.
User avatar
alban lusitanae
Drutt
Posts: 28
Joined: Fri Jun 28, 2019 1:49 pm
Location: Portugal
Contact:

Re: BEEP VAL

Post by alban lusitanae »

Oh i kmow PLAY and I know i cannot use it except in 128k. Saving space is great because i tend to just keep creating things and run out of memory. I just need to know how i can string the two variables of beep in it. I ll check it out and revert if i cant figure out the code. Many thx.
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BEEP VAL

Post by 1024MAK »

1024MAK wrote: Mon Jul 15, 2019 6:29 pm BEEP needs two parameters, the tone value and the duration.
VAL is a function that evaluates a string and returns (when possible) a number. VAL can be used to reduce the memory usage of a program. This may confuse you. ZX Spectrum BASIC hides a floating point version of any numerical constant (number) in a program. A numerical constant in the program is followed by its binary form, using the character 'CHR$ 14' followed by five bytes for the number itself. So the number 2 actually takes up 7 bytes!

However, I think you may be thinking of:
PLAY “abc”
PLAY requires a string expression, the letters in the string are the musical notes.

PLAY is only available on the 128K machines which have a dedicated sound chip (AY).

BEEP uses the ULA / gate array and is available on all ZX Spectrum models.

For more information read this section of the manual.

Mark
NOTE: above quotation edited to change SOUND (which is wrong!) to PLAY (which is correct).

Yes, working nights must have screwed with my head! :lol:
It is PLAY not SOUND. I must have been thinking about another computers BASIC at the time :oops:

Can you tell that I am tone deaf :lol:

Mark

PS If a friendly moderator or administrator feels like sorting out my mess, please feel free to do so... :mrgreen:
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BEEP VAL

Post by 1024MAK »

alban lusitanae wrote: Tue Jul 16, 2019 6:59 am Oh i kmow PLAY and I know i cannot use it except in 128k. Saving space is great because i tend to just keep creating things and run out of memory. I just need to know how i can string the two variables of beep in it. I ll check it out and revert if i cant figure out the code. Many thx.
Try:
BEEP VAL “.2”,VAL “1”

Or

BEEP VAL “.2”,PI

Where PI is the function on the M key...

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: BEEP VAL

Post by Einar Saukas »

1024MAK wrote: Tue Jul 16, 2019 8:44 amIt is PLAY not SOUND. I must have been thinking about another computers BASIC at the time :oops:
The BEEP command is called SOUND in the Sinclair BASIC of Brazilian clone TK90X.

And the PLAY command is called SOUND in the Sinclair BASIC of Timex models.
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

1024MAK wrote: Mon Jul 15, 2019 6:29 pm BEEP uses the ULA / gate array and is available on all ZX Spectrum models.
I wondered, why, if the Z80 has to produce the sound anyway and execution of BASIC had to been stopped for that purpose, the didn't they use pwm. Maybe this would not have worked to well for higher frequencies, but still.
Last edited by 1bvl109 on Tue Jul 16, 2019 7:04 pm, edited 1 time in total.
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: BEEP VAL

Post by Seven.FFF »

In his (highly recommended) ULA reverse-engineering book, Chris Smith documents that the sound generation shares the same circuit as the tape output, and surmises it was done that way for efficiency (needing less logic gates in the ULA, which means more room to fit other functionality in).
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

Seven.FFF wrote: Tue Jul 16, 2019 5:47 pm... the sound generation shares the same circuit as the tape output, and surmises it was done that way for efficiency (needing less logic gates in the ULA, which means more room to fit other functionality in).
SOUNDS reasonable.
But wouldn't it have been possible, to send, say 4 or 5 bits out through a https://en.wikipedia.org/wiki/Resistor_ladder ?
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BEEP VAL

Post by 1024MAK »

You’re forgetting that Sinclair wanted cheap and simple...

Why provide extra hardware when the CPU can bit-bash a single bit (pin) controlled by software?

At the time, software solutions were cheap compared to hardware. The RS232 serial port on the Interface 1 is the same. As are the network ports. Even the RS232 serial port on the 128K toastrack uses the Z80 bit bashing the I/O pins.

Back to the sound generation. Of course, given more silicon “real estate”, an auto presetable counter could have been used.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: BEEP VAL

Post by AndyC »

1bvl109 wrote: Tue Jul 16, 2019 5:39 pm
1024MAK wrote: Mon Jul 15, 2019 6:29 pm BEEP uses the ULA / gate array and is available on all ZX Spectrum models.
I wondered, why, if the Z80 has to produce the sound anyway and execution of BASIC had to been stopped for that purpose, the didn't they use pwm. Maybe this would not have worked to well for higher frequencies, but still.
If audio quality had been seen as important, they would have stuck an actual sound chip in it. The simple ability to make some noise at low a cost as possible met their own low bar.
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

1024MAK wrote: Tue Jul 16, 2019 11:09 pm You’re forgetting that Sinclair wanted cheap and simple...
Well I don't know, how much space the ULA actually offered, but some things seem to be caused more by rushed-to-the-market then by we-can-t'afford-the-hardware.
1024MAK wrote: Tue Jul 16, 2019 11:09 pm Why provide extra hardware when the CPU can bit-bash a single bit (pin) controlled by software?
All you would need is a latch for 3 to 4 bits more. Now I'm no expert in chip design, but a gated SR-latch https://en.wikipedia.org/wiki/Flip-flop ... d_SR_latch uses 4 NAND-gates, each using 2 transistors and 1 resistor https://en.wikipedia.org/wiki/NAND_gate
A n-R-2R ladder uses 2*n resistors. There they really not able to afford that? I tend to rather disbelieve this, because it fits to well. Maybe they really could not afford the hardware for 3 to 4 more bits, but every bit would have helped.

I remember games with speech synthesizing, Ghostbusters anyone? It was not that great. By combining pwm with a DAC, i.e. doing sounddithering you should be able to achieve a much better quality for lower frequencies. For higher you can't hear the harmonics anyway. Possibly because the human ear was also developed by thrifty Sinclair. Evolution should have invested in the Apple version.
1024MAK wrote: Tue Jul 16, 2019 11:09 pm At the time, software solutions were cheap compared to hardware.
I'm trying to follow that spirit as close as possible. The workload here is still on the Z80, especially if you want to do dithering. It might not even be possible for that reason.
1024MAK wrote: Tue Jul 16, 2019 11:09 pm Back to the sound generation. Of course, given more silicon “real estate”, an auto presetable counter could have been used.
Sure. Trying to save CPU-power would be the other way to go.
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

AndyC wrote: Wed Jul 17, 2019 8:49 am If audio quality had been seen as important, they would have stuck an actual sound chip in it. The simple ability to make some noise at low a cost as possible met their own low bar.
But concerning pwm the investment would be only in software. What I'm saying is, they are not squeezing the max out of the lemon of cheapness.
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

1bvl109 wrote: Tue Jul 16, 2019 5:39 pm I wondered, why, if the Z80 has to produce the sound anyway and execution of BASIC had to been stopped for that purpose, the didn't they use pwm.
Umm sorry. This should of course read ... why didn't they use pwm.
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: BEEP VAL

Post by ZXDunny »

1bvl109 wrote: Thu Jul 18, 2019 1:07 pm Well I don't know, how much space the ULA actually offered, but some things seem to be caused more by rushed-to-the-market then by we-can-t'afford-the-hardware.
I don't think you quite "get" what Sinclair did, and how they operated back then. It wasn't a case of "rush to market" at all. It was "can we do this cheaper? And what level of capability can we get away with?" which explains how the beeper came to be. After the ZX81, any sound at all was a welcome addition.

It was the same for colour. Adding 16 colours, but as cheap as possible, corners cut with BRIGHT and FLASH to save costs and reduce memory footprint.
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

ZXDunny wrote: Thu Jul 18, 2019 2:20 pm It was "can we do this cheaper? And what level of capability can we get away with?" which explains how the beeper came to be.
"... what level of capability can we get away with?" is exactly what I'm talking about. You could have impressive sound for cheap. No external alteration, only some more gates in the ULA needed. This could increase the number of costumers we appeal to. Why not take it?

Leaving the ULA alone, you could have not so impressive, but still more flexible sound for a ROM routine and a system variable using pwm.

On the other hand, the speaker was surely nice to have but required more hardware and seemed superfluous if you had some recorder or radio, those amplifier you could use.
ZXDunny wrote: Thu Jul 18, 2019 2:20 pmAfter the ZX81, any sound at all was a welcome addition.
Sure. I bought an AY-3-8912 board. It had the additional advantage of providing a Kempston Joystick on the spectrum, if you knew how to solder the 9-Pin D-Sub. However personally I found it to be inferior to an 8255 PIO WITH R-2R even if using only one of the three bytes. Of course you needed quite some help from the CPU, but it was great for things like a drum machine.

100 CLEAR 32767
110 FOR I=0 TO 1023
120 POKE 32768+I,127+127*RND*EXP(-I/300)*SGN(RND()-0.5)
130 NEXT I

IIRC writing this 1k to the DAC produced some nice "hammering-on-metal plates"-sound.

First I used a commercial 8bit DAC by Ferranti, but it was precise only up to 4 bits. Never knew what I did wrong. R-2R worked like cake. I didn't even need 1% precision resistors, because higher tolerance actually were better than described on the can.

I was told 8255 were already discontinued for more intelligent PIOs, but got back into production with the rise of the PC. Anyway they were dirt cheap already when the ZX81 came out.
ZXDunny wrote: Thu Jul 18, 2019 2:20 pmIt was the same for colour. Adding 16 colours, but as cheap as possible, corners cut with BRIGHT and FLASH to save costs and reduce memory footprint.
I suspect that FLASH was there to transfer cursor-flashing to hardware. I would have prefered a second bright bit. One for foreground, one for background. And gray instead of bright black, which sounds like positive zero.
Ok, it enabled the nice Manic Miner intro screen trick, but how many programmers would actually miss it?

Also: https://en.wikipedia.org/wiki/Timex_Sinclair_2068 managed 2 colours per 1 byte instead of 2 per 8. In 1983. The memory footprint of the screen was 12K, so it even could have been done with a 16K. I never understood, why the 128k didn't make us of this. The ULA was already there. Couldn't they reach an agreement with Timex?

And I would have preferred a second Z80A instead of an AY-3-8910, making it the first dual core home-computer in history. I would have been mesmerized. Anyone else? Count of hands please. https://www.youtube.com/watch?v=bu55q_3YtOY
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: BEEP VAL

Post by AndyC »

1bvl109 wrote: Thu Jul 18, 2019 6:11 pm
ZXDunny wrote: Thu Jul 18, 2019 2:20 pm It was "can we do this cheaper? And what level of capability can we get away with?" which explains how the beeper came to be.
"... what level of capability can we get away with?" is exactly what I'm talking about. You could have impressive sound for cheap. No external alteration, only some more gates in the ULA needed. This could increase the number of costumers we appeal to. Why not take it?

Leaving the ULA alone, you could have not so impressive, but still more flexible sound for a ROM routine and a system variable using pwm.
Even a software solution costs in terms of programmer time and, potentially, ROM space. Sinclair were so cheap and on such a tight schedule they didn't even get all the Interface 1 code into the ROM as they had originally planned. The Spectrum didn't need impressive graphics or sound, it just needed to be a viable step up from the ZX81. They had been producing a new model on a yearly basis, they could always do things better in the "ZX83" - the Speccy was never envisioned as staying around even half as long as it did.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: BEEP VAL

Post by ZXDunny »

1bvl109 wrote: Thu Jul 18, 2019 6:11 pm I was told 8255 were already discontinued for more intelligent PIOs, but got back into production with the rise of the PC. Anyway they were dirt cheap already when the ZX81 came out.
But it would have pushed up costs. Adding any extra hardware would have pushed up manufacturing costs. So it was never going to happen. This was a computer done as cheap as possible but still, as has been pointed out, a recognisably better ZX81.

And besides, Sinclair didn't add anything. We can't go back and change it so there's no real point to this.
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

AndyC wrote: Thu Jul 18, 2019 6:29 pm Even a software solution costs in terms of programmer time and, potentially, ROM space.
Of course.
Same for the ULA modification. Even if there is space, you have to do the work, to fill it.
AndyC wrote: Thu Jul 18, 2019 6:29 pmSinclair were so cheap and on such a tight schedule ...
"Tight schedule" elsewhere known as "rushing to the market". I don't criticise that as such, it isn't necessary a bad thing. Of course there are limits. Companies have failed, because the market was sucked dry by an inferior product which was readily available. I'm only referring to what an improvement would cost compared to the benefits, from a purely technical perspective without regard for the success of the whole project.
AndyC wrote: Thu Jul 18, 2019 6:29 pm... they didn't even get all the Interface 1 code into the ROM as they had originally planned.
Interesting. I never header about this. What ROM are we refering here to?
AndyC wrote: Thu Jul 18, 2019 6:29 pmThe Spectrum didn't need impressive graphics or sound, it just needed to be a viable step up from the ZX81.
Sure, I somewhat greater step wouldn't have hurt though.
AndyC wrote: Thu Jul 18, 2019 6:29 pmThey had been producing a new model on a yearly basis, they could always do things better in the "ZX83" - the Speccy was never envisioned as staying around even half as long as it did.
Fair enough. However I'm not satisfied with the 128k either.

My theory is that the ZXs should appeal to hackers. And to gamers, i.e hackers who do games. So hackers it is. They like things which are transparent, pushed to the limit and extendable.
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: BEEP VAL

Post by ZXDunny »

"ok, we need to make an upgraded ZX81. What can we get for the same cost as the '81 cost when it was launched?"

"We can add colour. We could use full or empty RGB channels to get 8 colours, and probably a halfbright by setting an extra bit."

"No interesting colours like the commodores then?"

"Not if you don't want to spend any money."

"Ok, that'll do then. We'll call it a 'Spectrum' and they'll love it. What else?"

"We could get a full 64k of RAM?"

"With a 16k ROM?"

"No, that would cost more, we'd need some sort of paging"

"Bugger that, let's launch it as 48k. It's still more than 1kb. And we could launch two models, and charge more. What else?"

"Sound?"

"Can we do sound? What's the minimum we could go for?"

"A piezo buzzer that we can toggle on and off. We could add it to the graphics chip. But there are better chips out there for sound."

"f*** 'em. A buzzer will be plenty good enough, it's not like anyone will make music with it, this is a glorified calculator like the last one.
Hmm. That graphics chip. What else can we cram in there?"

"Tape loading? We could use it to listen to the tape. Oh, and we could use it to read the keyboard too."

"Do it. Just keep the cost at a minimum. We're not going to make any money if this thing costs £300."
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: BEEP VAL

Post by AndyC »

1bvl109 wrote: Thu Jul 18, 2019 6:55 pm
AndyC wrote: Thu Jul 18, 2019 6:29 pm... they didn't even get all the Interface 1 code into the ROM as they had originally planned.
Interesting. I never header about this. What ROM are we refering here to?
The BASIC ROM, it was originally supposed to contain all the microdrive code, but it wasn't ready it time and so got dropped for a slightly hacky solution in the Interface 1
1bvl109 wrote: Thu Jul 18, 2019 6:55 pm
AndyC wrote: Thu Jul 18, 2019 6:29 pmThey had been producing a new model on a yearly basis, they could always do things better in the "ZX83" - the Speccy was never envisioned as staying around even half as long as it did.
Fair enough. However I'm not satisfied with the 128k either.
The.128 design wasn't really a Sinclair thing, it was a Spanish spin off (Investronica?) that stemmed from rules at the time which applied additional taxes on computers with less than 64K (they were seen as entertainment items). They threw in a few extras to make it a bit more appealing, but it was a quick and dirty upgrade. Not quite as cheap a solution as Amstrad, who made a CPC472 by just soldering and unconnected 8K of RAM inside a standard 464 to solve the same problem!
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: BEEP VAL

Post by Seven.FFF »

ZXDunny wrote: Thu Jul 18, 2019 7:34 pm "Tape loading? We could use it to listen to the tape. Oh, and we could use it to read the keyboard too."
Expanding on my earlier observation that the ULA beeper circuit is the same circuit that outputs the tape MIC signal... it's almost certainly similar to the ZX81 tape circuit too. It's not like Altwasser invented it from scratch for the Spectrum.

I'm veering into conjecture here, but he already had the ZX81 circuit, was aware of it's reliability issues, fixed those in a minimum viable way, then bingo, free buzzer feature too! Job done, with the absolute minimum of work.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: BEEP VAL

Post by Seven.FFF »

1bvl109 wrote: Thu Jul 18, 2019 6:55 pm My theory is that the ZXs should appeal to hackers. And to gamers, i.e hackers who do games. So hackers it is. They like things which are transparent, pushed to the limit and extendable.
That may be what we'd all like to be true, but the reality is different. Many of the decisions they made make it much harder for hackers, and edge connector hardware designers :)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
1bvl109
Dizzy
Posts: 98
Joined: Tue Jun 04, 2019 9:00 pm

Re: BEEP VAL

Post by 1bvl109 »

ZXDunny wrote: Thu Jul 18, 2019 6:37 pm But it would have pushed up costs. Adding any extra hardware would have pushed up manufacturing costs.
As would have better software.

So, don't add it, just make the machine flexible enough to be able to add it later. Then sell it. Maybe you need a few lines more on the edge connector. And here's your ULA+ for a nice steep price. How about a 128/256/1024 RAM pack?

Alternatively just bring out an early successor which can do this. Going incompatible where you need to. We have lots of revisions of the board already.
ZXDunny wrote: Thu Jul 18, 2019 6:37 pmSo it was never going to happen. This was a computer done as cheap as possible but still, as has been pointed out, a recognisably better ZX81.
You have to pay for recognizable better however.
ZXDunny wrote: Thu Jul 18, 2019 6:37 pm And besides, Sinclair didn't add anything. We can't go back and change it so there's no real point to this.
I don't mean, repeat don't mean to bugger the old man. He had to organize a company. I never did such a thing. I have some basic understand of electronics 40 years ago. This is it.

Of course hope goes on forever and maybe somebody somewhere is sitting down with a Z80e thinking what would be needed to make a cheap as dirt successor.
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken
Post Reply