a2_assembly_language by Unknown
Author:Unknown
Language: eng
Format: epub
108
Using Sound in Your Programs / 109
publication called Apple Assembly Line. Those programs, and some of the explanatory text, come from the February 1981 issue of Apple Assembly Line.
The speaker hardware in the Apple is very simple. A flip-flop, which is a device that repeatedly alternates between two states (e.g. ON and OFF), controls the current that is supplied to the coil of the speaker. The flip-flop is connected in such a way, that it reverses the flow of current through the speaker's coil. This is important, because the direction of the current flow determines whether the cone of the speaker is pulled in or out. If we "toggle" the flip-flop and cause it to continuously reverse the flow of current through the speaker, we can cause the speaker to produce audible sound. The rate at which we toggle, determines the frequency of the sound. And, by changing the toggling of the speaker dynamically, it is possible to produce some very complex sounds. The toggling of the speaker is accomplished by accessing location $C030 with any of the load, store or BIT instructions.
How to generate a simple tone
To generate a simple tone, it is only necessary to toggle the speaker at a rate that is low enough so that it falls within the range of 20 to 20,000 Hertz (cycles per second), which is the range of signals that the human ear can detect. The program SIMPLE TONE ROUTINE generates a tone burst of 128 cycles (this is equal to 256 half-cycles). Each half cycle here consists of 1288 Apple clock pulses. Since the internal Apple clock frequency is about 1 MHz, the frequency of sound that is produced is about 338 Hz.
The program starts out by setting the Y-register, which is used as a half-cycle counter, to zero (line 1210). In line 1220, the X-register, which is used as a delay counter, is also set to zero. The sound producing section of code starts with LOOP 1 online 1230, where the speaker is toggled. After toggling the speaker, the program waits, while LOOP2 is executed (lines 1240 and 1250). LOOP2 is only used to produce a time delay, which will be equal to the amount of time it takes to decrement the X-register to zero. After the delay, the Y-register is decremented (line 1260) and the speaker is toggled once more (line 1270). This continues until 256 half-cycles (128 cycles) are completed.
Figuring out the frequency
At this point, you might be curious how the frequency is figured out. This is done by determining the time taken up by each half cycle, doubling it and then taking its inverse. Let's go through a sample calculation.
To start with, we have to add up all of the 6502 cycles for each instruction in the sound producing loop (lines 1230 to 1270). To avoid confusion between the 6502 cycles and the cycles of the sound producing loop, each half cycle will be referred to as a pulse. Thus, there are two pulses per sound producing cycle (Hz).
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Zero to IPO: Over $1 Trillion of Actionable Advice from the World's Most Successful Entrepreneurs by Frederic Kerrest(3980)
Harry Potter and the Goblet Of Fire by J.K. Rowling(3592)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3509)
Never by Ken Follett(3500)
Ogilvy on Advertising by David Ogilvy(3309)
Shadow of Night by Deborah Harkness(3161)
The Man Who Died Twice by Richard Osman(2787)
Book of Life by Deborah Harkness(2705)
My Brilliant Friend by Elena Ferrante(2683)
How Proust Can Change Your Life by Alain De Botton(2596)
0041152001443424520 .pdf by Unknown(2578)
Will by Will Smith(2554)
The Tipping Point by Malcolm Gladwell(2537)
How to Pay Zero Taxes, 2018 by Jeff A. Schnepper(2472)
Purple Hibiscus by Chimamanda Ngozi Adichie(2437)
Hooked: A Dark, Contemporary Romance (Never After Series) by Emily McIntire(2405)
Rationality by Steven Pinker(2134)
Borders by unknow(2103)
Daughter of Smoke and Bone by Laini Taylor(2065)
