ZX Forum #04
19 ноября 1997 |
|
world of sound Spectrum - Chapter 3: How is the sound device (BEEP'ra and methods of sound production).
3. How is the sound Unfortunately, the ZX-Spectrum to control the sound allotted only one bit. This bit D4 port 254 (# FE). But despite this, the programmers manage to create very beautiful melodies and effects. When this bit is set, the speaker (amplifier) is energized, and its membrane is located in one position. When he is cleared, the dynamics of the voltage No, and the membrane is in a different position. Thus, if you change the state of this bit with a fairly high frequency, the membrane will vibrate and you hear a sound. Use this method can even be of BASIC: 10 FOR A = 1 TO 300: OUT 254,23 20 OUT 254,7: NEXT A And as easy on the assembler, but this case will prohibit the interruption, if You want to get high-quality sound: 1415. 10 DI; ban interrupt 20 LD BC, 2560; BC = length 30 LD A, 7; A = Border color 40 BEGIN XOR 16; inverting bits D4 50 OUT (254), A; output to port A 254 60 LD D, 100; D = delay (frequency) 70 PAUSE DEC D; D = D-1 80 JR NZ, PAUSE; if D <> 0 then loop 90 DEC BC; BC = BC-1 100 LD D, A; preservation A 110 LD A, B; BC = 120 OR C; 0? 130 LD A, D; A recovery 140 JR NZ, BEGIN; if BC <> 0 then loop 150 EI; permission to interrupt 160 RET; return to BASIC 2 You've probably noticed that in these programs to the drop port is not 16 and 0, would be consistent set and reset bits D4, and 23 and 7. The fact that this port The speaker controls the border and even the color output on a tape recorder. Acquainted with its ability to close: Bits D0 ... D2 determine the color of the border: 000 (0) - Black 100 (4) - Green 001 (1) - Blue 101 (5) - blue 010 (2) - red 110 (6) - yellow 011 (3) - Purple 111 (7) - white Bit D3 control the output on tape. Bit D4 controls the sound. Bits D5 ... D7 not used. When you enter a byte from a port bit D6 controls the tape input. I think now it is clear where it came from numbers 23 and 7: to set and reset bits D4 is necessary to consistently bring in port value of 16 and 0. But it must retain color border is 7 (white). Consequently, the first value will be 16 +7 = 23, and the second - 0 +7 = 7. In fact, You can set any color border. Moreover, we can create new different color effects. It's enough when inverting the sound bits use a different color border. You've probably noticed that in the above program in assembly language prohibits interruption. I think we should clarify this. The fact is that the ZX-Spectrum is designed so that every fiftieth of a second routine is called ROM, which is located at address 56 (# 38). And if you want a quality (not popping) sound, then it must be disabled, and that achieved by the prohibition of interrupt (command DI). When you return to the BASIC interrupt need to re-authorize (command EI).
Other articles:
Similar articles:
В этот день... 21 November