ZX Beep

Descripción del contenido de la página

Procedimiento para QL S*BASIC que emula el comando beep del BASIC de ZX Spectrum.

Etiquetas:

NOTA: en 2017-09-20 ZX Beep fue integrado en la biblioteca Sbira. Esta página ya no será actualizada, y más adelante será redirigida.


ZX Beep es un procedimiento para S*BASIC que emula el funcionamiento del comando beep del BASIC de ZX Spectrum. Lo escribí para usarlo en el proyecto Ritimba, pero puede ser útil en cualquier otra conversión de Sinclair BASIC a S*BASIC.

El funcionamiento del comando beep de SuperBASIC siempre ha sido un misterio. Incluso el manual original de QL tiene errores en la descripción de algún parámetro, que después se han reproducido en los manuales de SBASIC.

Con un poco de paciencia, obtuve la información necesaria buscando entre muchos programas y documentos disponibles en la admirable sede de Dilwyn Jones sobre QL.

Código fuente

En el formato SBim:

rem 'zx_beep' procedure for S*BASIC
rem that simulates the ZX Spectrum's 'beep' command

rem Version 0.4.0+20170918

' Author: Marcos Cruz (programandala.net), 2017

' ==============================================================
' License

' You may do whatever you want with this work, so long as you
' retain all copyright, authorship and credit notices and this
' license in all redistributed copies and derived works.
' There is no warranty.

' ==============================================================
' Credit

' The required information was found in the following
' files, from Dilwyn Jones' website:
'
' - <http://www.dilwyn.me.uk/docs/articles/beeps.pdf>, anonymous.
'
' - <http://www.dilwyn.me.uk/sound/music.zip>, by Dilwin Jones.
'
' - <http://www.dilwyn.me.uk/sound/playscale.zip>, by Mark Swift
'   (1993) and Simon N. Goodwin (1994).

' ==============================================================
' Usage example

' ----
' merge zx_beep_bas
' init_zx_beep
' let zx_beep_tempo=2.1:rem Default. Adjust to your machine.
' zx_beep seconds,pitch
' ----

' Where "seconds" and "pitch" are the parameters
' accepted by ZX Spectrum's 'beep' command (not their
' whole ranges, though).

' ==============================================================

defproc zx_beep(duration,tone%)

  loc pitch%

  repeat zx_beep_busy:\
    if not beeping:\
      exit zx_beep_busy

  let pitch%=tone%+zx_beep_middle_c_offset%

  if pitch%>=0 and pitch%<=zx_beep_last_pitch%:\
      beep zx_beep_tempo*duration*1000000/72,ql_pitch%(pitch%)

enddef

defproc init_zx_beep

  loc i,middle_c_pitch%

  let zx_beep_tempo=2.1
    ' The greater, the longer notes.
    ' Configure to your machine.

  let middle_c_pitch%=33

  restore @zx_beep_data

  zx_beep_last_pitch%=0

  rep count_data
    read i
    if i=-1:\
      exit count_data
    let zx_beep_last_pitch%=zx_beep_last_pitch%+1
  endrep count_data

  dim ql_pitch%(zx_beep_last_pitch%)

  restore @zx_beep_data

  for i=0 to zx_beep_last_pitch%
    read ql_pitch%(i)
    if ql_pitch%(i)=middle_c_pitch%:\
      let zx_beep_middle_c_offset%=i
  endfor i

enddef

' ==============================================================
' Data

'    Hz approx = 11447/(10.6+pitch)
' pitch approx = 11447/Hz-10.6

label @zx_beep_data

'    QL pitch  Hz       Note
'    --------  ------   ----
data 000     ' 987.80 ' B
data 001     ' 932.30 ' A#
data 002     ' 880.00 ' A
data 003     ' 830.60 ' G#
data 004     ' 784.00 ' G
data 005     ' 740.00 ' F#
data 006     ' 698.50 ' F
data 007     ' 659.30 ' E
data 008     ' 622.30 ' D#
data 009     ' 587.30 ' D
data 010     ' 554.40 ' C#
data 011     ' 523.30 ' C
data 012     ' 493.90 ' B
data 014     ' 466.10 ' A#
data 015     ' 440.00 ' A 
data 017     ' 415.30 ' G#
data 019     ' 391.99 ' G 
data 020     ' 369.99 ' F#
data 022     ' 349.22 ' F 
data 024     ' 329.62 ' E 
data 026     ' 311.12 ' D#
data 028     ' 293.66 ' D 
data 031     ' 277.18 ' C#
data 033     ' 261.62 ' C (middle C)
data 036     ' 246.94 ' B 
data 039     ' 233.08 ' A#
data 041     ' 220.00 ' A 
data 045     ' 207.65 ' G#
data 048     ' 195.99 ' G 
data 051     ' 184.99 ' F#
data 055     ' 174.61 ' F 
data 059     ' 164.81 ' E 
data 063     ' 155.56 ' D#
data 067     ' 146.83 ' D 
data 072     ' 138.59 ' C#
data 077     ' 130.81 ' C 
data 082     ' 123.47 ' B 
data 088     ' 116.54 ' A#
data 093     ' 110.00 ' A 
data 100     ' 103.82 ' G#
data 106     ' 097.99 ' G 
data 113     ' 092.49 ' F#
data 121     ' 087.30 ' F 
data 128     ' 082.40 ' E 
data 137     ' 077.78 ' D#
data 145     ' 073.41 ' D 
data 155     ' 069.29 ' C#
data 164     ' 065.40 ' C 
data 175     ' 061.73 ' B 
data 186     ' 058.27 ' A#
data 198     ' 055.00 ' A 
data 210     ' 051.91 ' G#
data 223     ' 048.99 ' G 
data 237     ' 046.24 ' F#
data 252     ' 043.65 ' F 

data -1 ' end of data

' vim: filetype=sbim

Convertido automáticamente al formato final, legible por S*BASIC:

1 rem 'zx_beep' procedure for S*BASIC
2 rem that simulates the ZX Spectrum's 'beep' command
3 rem Version 0.4.0+201709181828
4 defproc zx_beep(duration,tone%)
5 loc pitch%
6 repeat zx_beep_busy:if not beeping:exit zx_beep_busy
7 let pitch%=tone%+zx_beep_middle_c_offset%
8 if pitch%>=0 and pitch%<=zx_beep_last_pitch%:beep zx_beep_tempo*duration*1000000/72,ql_pitch%(pitch%)
9 enddef
10 defproc init_zx_beep
11 loc i,middle_c_pitch%
12 let zx_beep_tempo=2.1
13 let middle_c_pitch%=33
14 restore 28
15 zx_beep_last_pitch%=0
16 rep count_data
17 read i
18 if i=-1:exit count_data
19 let zx_beep_last_pitch%=zx_beep_last_pitch%+1
20 endrep count_data
21 dim ql_pitch%(zx_beep_last_pitch%)
22 restore 28
23 for i=0 to zx_beep_last_pitch%
24 read ql_pitch%(i)
25 if ql_pitch%(i)=middle_c_pitch%:let zx_beep_middle_c_offset%=i
26 endfor i
27 enddef
28 data 000
29 data 001
30 data 002
31 data 003
32 data 004
33 data 005
34 data 006
35 data 007
36 data 008
37 data 009
38 data 010
39 data 011
40 data 012
41 data 014
42 data 015
43 data 017
44 data 019
45 data 020
46 data 022
47 data 024
48 data 026
49 data 028
50 data 031
51 data 033
52 data 036
53 data 039
54 data 041
55 data 045
56 data 048
57 data 051
58 data 055
59 data 059
60 data 063
61 data 067
62 data 072
63 data 077
64 data 082
65 data 088
66 data 093
67 data 100
68 data 106
69 data 113
70 data 121
71 data 128
72 data 137
73 data 145
74 data 155
75 data 164
76 data 175
77 data 186
78 data 198
79 data 210
80 data 223
81 data 237
82 data 252
83 data -1


Descargas

Páginas relacionadas

Sbira
[Proyecto:] Biblioteca para SBASIC.

Enlaces externos relacionados