?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ; Moonblaster Wave Replayer
  2. ; https://www.teambomba.net/mbwave.html
  3. ; https://www.teambomba.net/download/WAVEDRV.LZH
  4. ;
  5. ; You need to add implementation of the following functions and macro to compile:
  6. ; selbank_FE
  7. ; load_file
  8. ; opl4_wait
  9. ;
  10. ;**************************************************************************
  11. ;*                                                                        *
  12. ;*      MoonBlaster for MoonSound Wave BASIC driver                       *
  13. ;*                                                                        *
  14. ;* Author :R. Schrijvers & M. Delorme                                     *
  15. ;* Versiom:1.14 - Plays MBWAVE 0.92 until MBWAVE 1.14 songs               *
  16. ;* Date   :10/10/98 (DDMMYY)                                              *
  17. ;*                                                                        *
  18. ;* Comments:                                                              *
  19. ;* ML-programmers should have no trouble ripping the replayer from this   *
  20. ;* source. Therefore, no seperate ML-source will be released.             *
  21. ;**************************************************************************
  22.  
  23. ;--- Defines ---
  24.  
  25. RAMHEADERS      equ     1       ; don't change ROM headers
  26.         ; When this is switched OFF the
  27.         ; replayer will be faster, but only do
  28.         ; this when you really need the speed!
  29.         ; It will affect the sound quality.
  30.  
  31. WVIO    equ     MOON_WREG       ; wave I/O base port
  32. FMIO    equ     MOON_BASE       ; FM ports
  33. PTW_SIZE        equ     20      ; size of Wave playtable line
  34. WAVCHNS equ     24
  35.  
  36.         macro   add_hl_a        ; add A to HL
  37.         add     a,l     ; notice: A is modified!
  38.         jr      nc,$+3
  39.         inc     h
  40.         ld      l,a
  41.         endm
  42.  
  43.         macro   add_de_a        ; add A to DE
  44.         add     a,e     ; notice: A is modified!
  45.         jr      nc,$+3
  46.         inc     d
  47.         ld      e,a
  48.         endm
  49.  
  50.         macro   ld_bc bv, cv
  51.         ld      bc, 256 * bv + cv
  52.         endm
  53.  
  54.         macro   opl4_wait_keep_af
  55.         ex      af,af'
  56.         opl4_wait
  57.         ex      af,af'
  58.         endm
  59.  
  60. ;--- Load MWM file ---
  61.  
  62. ; Note: The routine below is a bit complex because it supports
  63. ; songs > 16K. However, if you know that your song will always be < 16K you
  64. ; can simplify it a lot:
  65. ; - read the header and trash it!
  66. ; - read the rest of the file
  67. ; - modify the play_nextpos routine so that 3 is added to the pattern address
  68. mwmload:
  69.         ld      hl,songdata_bank1       ; select first song bank
  70.         ld      (load_bank),hl
  71.         ld      a,(hl)
  72.         call    selbank_FE
  73.  
  74.         ld      hl,6
  75.         ld      de,(songdata_adres)
  76.         call    load_file       ; read header
  77.         ld      a,8     ; file type 8 = wave user song
  78.         call    check_header
  79.         ret     nz
  80.  
  81.         ld      hl,278
  82.         ld      de,(songdata_adres)     ; read settings
  83.         call    load_file
  84.         ld      a,(de)
  85.         add     hl,de
  86.         ex      de,hl
  87.         inc     a
  88.         ld      l,a
  89.         ld      h,0
  90.         call    load_file       ; read positions
  91.         call    check_pats
  92.         add     hl,de
  93.         ex      de,hl
  94.         add     a,a
  95.         ld      l,a
  96.         ld      h,0
  97.         call    load_file       ; read pattern addresses
  98.         add     hl,de
  99.         ld      (load_adres),hl
  100.  
  101. mbload_lp:
  102.         ld      de,load_buffer
  103.         ld      hl,3
  104.         call    load_file
  105.         ld      a,(load_buffer + 2)
  106.         or      a
  107.         jr      z,mbload2
  108.         ld      de,(load_adres)
  109.         ld      hl,(load_buffer)
  110.         call    load_file
  111.         ld      de,08000h
  112.         ld      (load_adres),de
  113.         ld      hl,(load_bank)
  114.         inc     hl
  115.         ld      a,(hl)
  116.         ld      (load_bank),hl
  117.         call    selbank_FE
  118.         jr      mbload_lp
  119.  
  120. mbload2:
  121.         call    load_xlfo_data
  122.  
  123.         xor     a
  124.         ret
  125.  
  126. ;--- load xlfo data ---
  127.  
  128. load_xlfo_data:
  129.         ld      de,xlfo_data
  130.         ld      hl,4
  131.         call    load_file       ; hl stays 4 after this
  132.         ld      b,4
  133.         ld      hl,xlfo_label
  134.         call    chk_headerlus
  135.         ret     nz
  136.         ld      de,xls_tabel
  137.         ld      hl,18
  138.         jp      load_file
  139.  
  140. xlfo_label:     db      "XLFO"
  141. xlfo_data:      ds      4
  142. load_buffer:    ds      3
  143.  
  144. ;--- Load MWK file ---
  145. ; Note: This will clear the first song bank!!
  146.  
  147. mwkload:
  148.         ld      hl,songdata_bank1
  149.         ld      (load_bank),hl  ; select first bank as buffer
  150.         ld      a,(hl)
  151.         call    selbank_FE
  152.  
  153.         ld      hl,6
  154.         ld      de,(songdata_adres)
  155.         call    load_file       ; read header
  156.         ld      a,13    ; file type 13 = user wavekit
  157.         call    check_header
  158.         ret     nz
  159.  
  160.         call    init_opl4
  161.  
  162.         call    load_mwkdata    ; load tone and wave data
  163.         call    load_mwktones   ; load tones
  164.  
  165.         xor     a
  166.         ret
  167.  
  168. ;--- Load tone info bytes and wave tables ---
  169. ; In: wavekit file is open
  170. ; Out: tones_data: contains tone info bytes
  171. ;       waves: contains wave tables
  172.  
  173. load_mwkdata:   ld      hl,4 + 64
  174.         ld      de,08000h
  175.         call    load_file       ; load tone info bytes
  176.         ld      hl,08000h + 4
  177.         ld      de,tones_data
  178.         ld      bc,64
  179.         ldir
  180.         ld      a,(08000h + 3)  ; #waves
  181.         ld      b,a
  182.         ld      hl,0
  183.         ld      de,25
  184. mwkload_lp1:    add     hl,de
  185.         djnz    mwkload_lp1
  186.         push    hl
  187.         ld      de,08000h
  188.         call    load_file       ; load wave tables
  189.         pop     bc
  190.         ld      hl,08000h
  191.         ld      de,waves
  192.         ldir
  193.         ret
  194.  
  195.  
  196. ;--- Load all tones ---
  197. ; In: tones_data is filled with tone info bytes
  198. ;      wavekit file is open
  199. ; Out: sample headers and data is set in sample RAM
  200.  
  201. load_mwktones:  ld      de,0    ; tone header start at 200000h
  202.         ld      ix,sample_address
  203.         ld      (ix + 0),d      ; reg 'DE' is filles with 0
  204.         ld      (ix + 1),3
  205.         ld      (ix + 2),20h    ; sample start at 200300h
  206.         ld      hl,tones_data
  207.         ld      b,64
  208. load_mwktonesl: push    bc
  209.         push    hl
  210.         bit     0,(hl)
  211.         call    nz,load_mwktone
  212.         ex      de,hl
  213.         ld      de,12
  214.         add     hl,de
  215.         ex      de,hl
  216.         pop     hl
  217.         inc     hl
  218.         pop     bc
  219.         djnz    load_mwktonesl
  220.  
  221.         ld      c,2
  222.         ld      a,10000b
  223.         jp      opl4_out_wave   ; disable SRAM access mode
  224.  
  225.  
  226. ;--- Load one tone ---
  227. ; In: tones_data is filled with tone info bytes
  228. ;      wavekit file is open
  229. ;      IX = pointer to current sample address
  230. ;      HL = pointer to tone info byte
  231. ;      DE = pointer to tone header SRAM address
  232. ; Out: sample header and data is set in sample RAM
  233. ;       contents of IX is increased by sample size
  234.  
  235. load_mwktone:   push    de
  236.         push    hl
  237.         ld      de,08000h + 1
  238.         ld      hl,11 + 2
  239.         call    load_file
  240.         pop     hl
  241.         push    hl
  242.         ld      a,(hl)
  243.         bit     5,a
  244.         jp      nz,loadRomTone
  245.  
  246.         ld      hl,(08000h + 1)
  247.         ld      a,(ix + 0)      ; add relative start address
  248.         add     a,l
  249.         ld      (08000h + 2),a
  250.         ld      a,(ix + 1)
  251.         add     a,h
  252.         ld      (08000h + 1),a
  253.         pop     hl
  254.         push    af
  255.         ld      a,(hl)  ; include sample type bits
  256.         and     11000000b
  257.         or      (ix + 2)
  258.         ld      (08000h),a
  259.         pop     af
  260.         jr      nc,load_mwktone2        ; Carry from add a,h?
  261.         ld      hl,08000h
  262.         inc     (hl)
  263.  
  264. load_mwktone2:  pop     hl
  265.         push    hl
  266.         ld      e,020h
  267.         call    set_opl4_wrt    ; set write to address for header
  268.         ld      hl,08000h
  269.         ld      de,12
  270.         call    ramtosram       ; move header to Sample RAM
  271.  
  272.         ld      l,(ix + 0)      ; current sample RAM address
  273.         ld      h,(ix + 1)
  274.         ld      e,(ix + 2)
  275.         call    set_opl4_wrt
  276.  
  277.         ld      hl,(08000h + 1 + 11)    ; sample size
  278.         push    hl
  279.  
  280.         ld      (sample_size),hl
  281. load_mwktonelp: ld      de,04000h
  282.         ld      hl,(sample_size)
  283.         or      a
  284.         sbc     hl,de
  285.         ld      (sample_size),hl
  286.         jr      c,load_mwktone3 ; < 4000h
  287.         ld      a,l
  288.         or      h
  289.         jr      z,load_mwktone3 ; == 4000h
  290.  
  291.         ld      de,08000h       ; buffer address
  292.         ld      hl,04000h
  293.         call    load_file       ; load 04000h bytes
  294.         ex      de,hl
  295.         call    ramtosram       ; and put them in SRAM
  296.         jr      load_mwktonelp
  297. load_mwktone3   add     hl,de
  298.         ld      de,08000h       ; buffer address
  299.         call    load_file       ; load last bytes
  300.         ex      de,hl
  301.         call    ramtosram       ; and put them in SRAM
  302.  
  303.         pop     hl
  304.         ld      a,(ix + 0)
  305.         add     a,l
  306.         ld      (ix + 0),a
  307.         ld      a,(ix + 1)
  308.         adc     a,h
  309.         ld      (ix + 1),a
  310.         jr      nc,load_mwktone4
  311.         inc     (ix + 2)
  312. load_mwktone4:  pop     de
  313.         ret
  314.  
  315. sample_address: ds      3,0
  316. sample_size:    dw      0
  317.  
  318. loadRomTone:
  319.         pop     hl
  320.         and     a,%11000000
  321.         ld      hl,(08000h + 1 + 11)    ; sample size
  322.         or      a,h
  323.         ld      hl,#8000
  324.         ld      (hl),a
  325.         ld      de,(#8001)
  326.         inc     hl
  327.         ld      (hl),d
  328.         inc     hl
  329.         ld      (hl),e
  330.         pop     hl
  331.         push    hl
  332.         ld      e,020h
  333.         call    set_opl4_wrt    ; set write to address for header
  334.         ld      hl,08000h
  335.         ld      de,12
  336.         call    ramtosram       ; move header to Sample RAM
  337.         jr      load_mwktone4
  338.  
  339.  
  340. ;--- put samples in SRAM ---
  341. ; In: HL = RAM address DE = length
  342.  
  343. ramtosram:
  344.         push    hl
  345.         push    de
  346.         opl4_wait
  347.         ld      a,6
  348.         out     (WVIO),a
  349. ramtosram_lp:
  350.         opl4_wait
  351.         ld      a,(hl)
  352.         out     (WVIO + 1),a
  353.         inc     hl
  354.         dec     de
  355.         ld      a,d
  356.         or      e
  357.         jr      nz,ramtosram_lp
  358.         pop     de
  359.         pop     hl
  360.         ret
  361.  
  362. ;------------------------------------
  363. ;--- Set OPL4 for SRAM read/write ---
  364. ;------------------------------------
  365. ; In: EHL = SRAM address
  366.  
  367. set_opl4_wrt:
  368.         ld      c,2     ; enable SRAM access
  369.         ld      a,10001b
  370.         call    opl4_out_wave
  371.         inc     c
  372.         ld      a,e
  373.         and     111111b
  374.         call    opl4_out_wave
  375.         inc     c
  376.         ld      a,h
  377.         call    opl4_out_wave
  378.         inc     c
  379.         ld      a,l
  380.         jp      opl4_out_wave
  381.  
  382. ;--- check header ---
  383. ; In: A = file type
  384. ; Out: Z for Ok, NZ for error
  385.  
  386. check_header:   ld      (header_txt + 5),a
  387.         ld      hl,header_txt
  388.         ld      b,6
  389. chk_headerlus:  ld      a,(de)
  390.         cp      (hl)
  391.         ret     nz
  392.         inc     hl
  393.         inc     de
  394.         djnz    chk_headerlus
  395.         ret
  396.  
  397. ;--- search highest pattern ---
  398. ; In: L = #positions, DE = pointer to patterns
  399. ; Out: A = highest pattern
  400.  
  401. check_pats:     push    hl
  402.         push    de
  403.         ld      b,l
  404.         ex      de,hl
  405.         xor     a
  406. check_patslp:   cp      (hl)
  407.         jr      nc,check_pats2
  408.         ld      a,(hl)
  409. check_pats2:    inc     hl
  410.         djnz    check_patslp
  411.         inc     a
  412.         pop     de
  413.         pop     hl
  414.         ret
  415.  
  416. load_adres:     dw      0
  417. load_bank:      dw      0
  418.  
  419. header_txt:     db      "MBMS",010h,8
  420.  
  421.  
  422. ;-------------------------------- PLAYROUTINE --------------------------------
  423.  
  424. ; start_music = start music
  425. ; stop_music = stop music
  426. ; cont_music = continues music after pause
  427. ; halt_music = halts/pauses music
  428.  
  429. play_busy       db      0 ; 0 = not playing, 255 = playing
  430. songdata_bank1  ds      3
  431. songdata_adres  dw      08000h ; address of song data
  432. play_pos        db      0 ; current position
  433. play_step       db      0 ; current step
  434. status          ds      3 ; status bytes (0 = off)
  435. step_buffer     ds      25 ; decrunched step, played next int
  436.  
  437. ;--------------------
  438. ;--- Start music ---
  439. ;--------------------
  440. ; In : -
  441. ; Out: -
  442. ; Mod: all
  443.  
  444. start_music:
  445.         ld      a,(play_busy)
  446.         or      a
  447.         ret     nz      ; already playing?
  448.  
  449.         ld      hl,0
  450.         ld      (status),hl
  451.         ld      (status+1),hl   ; clear status bytes
  452.  
  453.         ld      a,0ffh
  454.         ld      (play_busy),a   ; set busy playing
  455.  
  456.         ld      (play_pos),a
  457.         ld      a,15
  458.         ld      (play_step),a   ; set step and position
  459.  
  460.         ld      a,(songdata_bank1)
  461.         call    selbank_FE
  462.  
  463.         ld      hl,(songdata_adres)
  464.         ld      de,xleng
  465.         ld      bc,220
  466.         ldir            ; copy song settings
  467.         ld      de,58
  468.         add     hl,de   ; skip name/wavekit
  469.         ld      (pos_address),hl
  470.         ld      a,(xleng)
  471.         inc     a
  472.         ld      e,a
  473.         add     hl,de
  474.         ld      (pat_address),hl
  475.  
  476.         call    init_opl4       ; initialise OPL4
  477.         call    init_voices     ; set start voices
  478.         ld      a,(xtempo)
  479.         ld      (play_speed),a  ; set tempo
  480.         ld      a,(play_speed)
  481.         sub     3
  482.         ld      (play_timercnt),a       ; initialise timer (tempo)
  483.         xor     a
  484.         ld      (play_tspval),a ; transpose off
  485.  
  486. start_mus_cnt:
  487.         opl4_wait
  488.         ld      a,2
  489.         out     (FMIO),a
  490.         ld      a,(xhzequal)
  491.         or      a
  492.         jr      z,Speed60Hz
  493.         cp      1
  494.         jr      nz,Speedxhz
  495.         ld      a,248
  496.         jr      Speedxhz
  497. Speed60Hz:
  498.         ld      a,208
  499. Speedxhz:
  500.         neg
  501.         opl4_wait_keep_af
  502.         out     (FMIO+1),a
  503.         opl4_wait
  504.         ld      a,4
  505.         out     (FMIO),a
  506.         opl4_wait
  507.         ld      a,0100001b
  508.         out     (FMIO+1),a
  509.         ret
  510.  
  511. ;--- initialise OPL4 registers ---
  512.  
  513. init_opl4:
  514.         opl4_wait
  515.         ld      a,5
  516.         out     (FMIO+2),a
  517.         opl4_wait
  518.         ld      a,3
  519.         out     (FMIO+3),a
  520.  
  521.         ld      c,2
  522.         ld      a,10000b
  523.         jp      opl4_out_wave   ; init Wave ROM stuff
  524.  
  525.  
  526. ;----------------------------
  527. ;--- Stel Start Voices in ---
  528. ;----------------------------
  529.  
  530. init_voices:
  531.         ld      b,WAVCHNS       ; # wave channels
  532.         ld      iy,play_table_wav
  533.         ld      ix,xbegwav
  534.         ld      de,PTW_SIZE
  535. init_wavesl:
  536.         push    de
  537.         push    bc
  538.         ld      a,(ix - 72)     ; xdetune!
  539.         add     a,a
  540.         ld      (iy + 5),a      ; detune!
  541.         ld      (iy + 12),0     ; Reverb off
  542.         ld      a,(ix + 0)      ; wave/patchnr
  543.         push    af
  544.         call    play_wwavevt2
  545.         pop     af
  546.         ld      hl,xwavvols - 1
  547.         add_hl_a
  548.         ld      a,(hl)  ; volume
  549.         ld      (iy + 15),a
  550.         call    play_wchgvol2
  551.         ld      a,(ix - 98)     ; stereo preset
  552.         call    play_wchgste2
  553.         inc     ix
  554.         pop     bc
  555.         pop     de
  556.         add     iy,de
  557.         djnz    init_wavesl
  558.         ret
  559.  
  560.  
  561.  
  562. ;-----------------------
  563. ;--- Continue muziek ---
  564. ;-----------------------
  565. ; In : -
  566. ; Out: -
  567. ; Mod: all
  568.  
  569. cont_music:
  570.         ld      a,(play_busy)   ; already playing?
  571.         or      a
  572.         ret     nz
  573.         dec     a
  574.         ld      (play_busy),a
  575.         jp      start_mus_cnt
  576.  
  577.  
  578. ;--------------------
  579. ;--- Stop muziek ----
  580. ;--------------------
  581. ; In : -
  582. ; Out: -
  583. ; Mod: all
  584.  
  585. stop_music:
  586.  
  587. ;------------------
  588. ;--- Halt music ---
  589. ;------------------
  590.  
  591. halt_music:
  592.         ld      a,(play_busy)   ; already stopped?
  593.         or      a
  594.         ret     z
  595.  
  596.         opl4_wait
  597.         ld      a,4
  598.         out     (FMIO),a
  599.         opl4_wait
  600.         ld      a,128
  601.         out     (FMIO+1),a      ; Reset Opl4 flags to prevent a crash
  602.         opl4_wait
  603.         xor     a
  604.         out     (FMIO+1),a      ; Stop timers
  605.         ld      (play_busy),a
  606.  
  607.         ld      b,WAVCHNS       ; # wave channels
  608.         ld      iy,play_table_wav
  609.         ld      de,PTW_SIZE
  610. halt_musicl3:
  611.         call    play_woffevt
  612.         call    play_chgdmp
  613.         add     iy,de
  614.         djnz    halt_musicl3
  615.  
  616.         ret
  617.  
  618. ;-------------------------------
  619. ;--- Music interrupt routine ---
  620. ;-------------------------------
  621.  
  622. play_int:
  623.         opl4_wait
  624.         ld      a,4
  625.         out     (FMIO),a
  626.         opl4_wait
  627.         ld      a,10000001b
  628.         out     (FMIO+1),a      ; reset opl4 IRQ
  629.  
  630. play_int3:
  631.         call    play_pitch      ; pitch-bend/modulation handler
  632.  
  633.         ld      a,(play_speed)  ; speed
  634.         ld      hl,play_timercnt
  635.         inc     (hl)
  636.         cp      (hl)
  637.         jp      nz,play_int_sec ; almost there?
  638.         ld      (hl),0
  639.  
  640.         ld      a,(songdata_bank)
  641.         call    selbank_FE
  642.  
  643.         call    play_wtones     ; select tones in advance
  644.  
  645.         ld      hl,step_buffer  ; songdata-adres
  646.         ld      iy,play_table_wav
  647.         ld      b,WAVCHNS       ; # Wave channels!
  648.         ld      de,PTW_SIZE
  649. play_int_wlus:
  650.         ld      a,(hl)
  651.         or      a
  652.         jr      z,play_int_wend2        ; empty
  653.  
  654.         ex      af,af'
  655.         ld      a,b
  656.         exx
  657.         ld      b,a
  658.         ex      af,af'
  659.  
  660.         ld      de,play_int_wend
  661.         push    de
  662.  
  663.         cp      97
  664.         jp      c,play_wonevt   ; wave on
  665.         jp      z,play_woffevt  ; wave off
  666.         cp      146
  667.         jp      c,play_wwavevt  ; wave
  668.         cp      178
  669.         jp      c,play_wchgvol  ; volume
  670.         cp      193
  671.         jp      c,play_wchgste  ; stereo
  672.         cp      212
  673.         jp      c,play_wlnk     ; link
  674.         cp      231
  675.         jp      c,play_wchgpit  ; pitch bending
  676.         cp      238
  677.         jp      c,play_wchgdet  ; detune
  678.         cp      241
  679.         jp      c,play_wchgmod  ; modulation
  680.         jp      z,play_chgpsr   ; pseudo reverb on
  681.         cp      243
  682.         jp      c,play_chgdmp   ; damp
  683.         jp      z,play_chglfo   ; LFO
  684.         cp      245
  685.         jp      c,play_chgpso   ; pseudo reverb off
  686.         cp      255
  687.         jp      c,play_chgxls   ; eXtra Lfo Settings
  688.  
  689. play_int_wend:
  690.         exx
  691. play_int_wend2:
  692.         add     iy,de
  693.         inc     hl
  694.         djnz    play_int_wlus
  695.  
  696.         ld      a,(hl)  ; command line
  697.         or      a
  698.         jr      z,play_cmdcnt
  699.  
  700.         ld      ix,play_cmdcnt
  701.  
  702.         cp      24
  703.         jp      c,play_chgtmp   ; change tempo
  704.         jp      z,play_endop    ; end of pattern
  705.         cp      28
  706.         jr      c,play_cmdcnt   ; status
  707.         cp      76 + 1
  708.         jp      c,play_chgtrs   ; transpose
  709.         cp      211
  710.         jp      c,play_chgbasefr        ; base frequency
  711.  
  712. play_cmdcnt:
  713. play_int_fin:
  714.         ret
  715.  
  716. ;-----------------------------------------------
  717. ;--- Interrupt routine BEFORE play-interrupt ---
  718. ;-----------------------------------------------
  719.  
  720. play_int_sec:   dec     a
  721.         cp      (hl)
  722.         jp      z,play_int_secit
  723.         dec     a
  724.         cp      (hl)
  725.         jp      nz,play_int_fin
  726.  
  727. play_int_3rd:
  728.         ld      a,(play_step)   ; increase current step
  729.         inc     a
  730.         and     01111b
  731.         ld      (play_step),a
  732.         ld      hl,(songdata_ptr)
  733.         call    z,play_nextpos  ; step 0 => new position
  734.  
  735.         ld      a,(songdata_bank)
  736.         call    selbank_FE
  737.  
  738. ;--- decrunch one step ---
  739.  
  740.         ld      de,step_buffer
  741. decr_step_lp:
  742.         ld      a,(hl)
  743.         inc     hl
  744.         cp      0ffh    ; 0FFh => completely empty
  745.         jp      nz,decr_step_2
  746.         exx
  747.         ld      hl,step_buffer
  748.         ld      de,step_buffer + 1
  749.         ld      bc,25 - 1
  750.         ld      (hl),b
  751.         ldir
  752.         exx
  753.         jp      decr_step_end
  754.  
  755. decr_step_2:
  756.         ld      (de),a  ; 1st byte uncrunched
  757.         inc     de
  758.         push    hl
  759.         inc     hl
  760.         inc     hl
  761.         inc     hl
  762.         exx
  763.         pop     hl
  764.         ld      b,3     ; decrunch 3 * 8 bytes
  765. decr_step_lp1:
  766.         ld      a,(hl)
  767.         exx
  768.         ld      b,8     ; decrunch 8 bytes
  769.         ld      c,a
  770. decr_step_lp2:
  771.         xor     a
  772.         rlc     c
  773.         jr      nc,decr_step_3  ; no carry? then empty event
  774.         ld      a,(hl)
  775.         inc     hl
  776. decr_step_3:
  777.         ld      (de),a
  778.         inc     de
  779.         djnz    decr_step_lp2
  780.         exx
  781.         inc     hl
  782.         djnz    decr_step_lp1
  783.         exx
  784. decr_step_end:
  785.         ld      (songdata_ptr),hl
  786.  
  787. ;--- Calculate freq. & note nr of wave to play ---
  788.         ld      iy,play_table_wav
  789.         ld      hl,step_buffer  ; third interrupt
  790.         ld_bc   (WAVCHNS/2),96  ; Wave channels
  791.         jr      play_int_seclp
  792.  
  793. play_int_secit:
  794.         ld      b,WAVCHNS
  795.         ld      hl,step_buffer
  796.         ld      iy,play_table_wav
  797.         ld      de,PTW_SIZE
  798. play_int_secl2:
  799.         ld      a,(hl)
  800.         dec     a
  801.         cp      96
  802.         jr      nc,play_int_secpb
  803.         ld      (iy + 2),0
  804. play_int_secpb:
  805.         inc     hl
  806.         add     iy,de
  807.         djnz    play_int_secl2
  808.  
  809.         ld      iy,play_table_wav + (WAVCHNS/2) * PTW_SIZE
  810.         ld      hl,step_buffer + WAVCHNS / 2    ; second interrupt
  811.         ld_bc   (WAVCHNS/2),96  ; Wave channels
  812.         jr      play_int_seclp
  813.  
  814.  
  815. play_int_seclp:
  816.         ld      de,PTW_SIZE
  817. play_int_secwl:
  818.         ld      a,(hl)
  819.         dec     a
  820.         cp      c       ; 96
  821.         jp      c,calc_wave     ; JP to and fro for extra speed
  822. play_int_secwe:
  823.         add     iy,de
  824.         inc     hl
  825.         djnz    play_int_secwl
  826.         jp      play_int_fin
  827.  
  828. ;--- calc wave stuff ---
  829.  
  830. calc_wave:
  831.         exx
  832.         ld      d,a
  833.  
  834.         ld      hl,patch_table  ; dit stuk verandert A niet!
  835.         ld      b,0
  836.         ld      c,(iy + 10)
  837.         ld      a,c
  838.         cp      175
  839.         jp      z,calc_drm      ; gm drum patch
  840.         cp      176
  841.         jp      nc,calc_own     ; own wave
  842.  
  843. calc_drm_cnt:   ld      a,d
  844.         add     hl,bc
  845.         add     hl,bc
  846.         ld      e,(hl)
  847.         inc     hl
  848.         ld      d,(hl)  ; pointer to patch
  849.         ex      de,hl
  850.         ld      e,(hl)
  851.         inc     hl
  852.         ld      c,(hl)
  853.         inc     hl
  854.         ld      b,(hl)
  855.         inc     hl
  856.         ld      (iy + 13),c     ; pointer to header bytes
  857.         ld      (iy + 14),b
  858.         ; search right patch part
  859.  
  860.         bit     0,e     ; transpose
  861.         jr      z,keyb_wonwav7
  862.         ld      b,a
  863.         ld      a,(play_tspval)
  864.         add     a,b
  865. keyb_wonwav7:   ld      b,0
  866.         ld      de,3 + 2
  867. calc_wave_lp:   cp      (hl)
  868.         jr      c,calc_wave_2
  869.         ld      b,(hl)
  870.         add     hl,de
  871.         cp      (hl)    ; 4 * the same, saves 30 T-states!
  872.         jr      c,calc_wave_2   ; (Anything for some extra speed)
  873.         ld      b,(hl)
  874.         add     hl,de
  875.         cp      (hl)
  876.         jr      c,calc_wave_2
  877.         ld      b,(hl)
  878.         add     hl,de
  879.         cp      (hl)
  880.         jr      c,calc_wave_2
  881.         ld      b,(hl)
  882.         add     hl,de
  883.         jp      calc_wave_lp
  884. calc_wave_2:    ld      d,a     ; save note...
  885.         inc     hl
  886.         ld      a,(hl)  ; low byte tone
  887.         ld      (iy + 7),a
  888.  
  889.         inc     hl
  890.         ld      a,(hl)
  891.         and     1       ; also resets carry!
  892.         ld      (iy + 6),a      ; high byte tone
  893.  
  894.         ld      a,(hl)  ; tone-note
  895.         rra             ; note that carry was set 0 earlier!!
  896.         add     a,d
  897.         sub     b
  898.         ld      (iy + 0),a      ; last note
  899.  
  900.         inc     hl
  901.         ld      e,(hl)
  902.         inc     hl
  903.         ld      d,(hl)
  904.         ld      (iy + 17),d     ; pointer to freqtab
  905.         ld      (iy + 16),e
  906.  
  907.         ld      hl,tabdiv12
  908.         ld      c,a
  909.         ld      b,0
  910.         add     hl,bc
  911.         add     hl,bc
  912.         ld      c,(hl)
  913.         inc     hl
  914.         ld      a,(hl)
  915.         ex      de,hl
  916.  
  917.         add_hl_a        ; right ptr to freq
  918.  
  919.         ld      e,(hl)
  920.         inc     hl
  921.         ld      d,(hl)  ; DE = freq
  922.  
  923.         sla     e       ; freq fine
  924.         ld      a,d
  925.         rla             ; freq rotated 1 left
  926.         add     a,c     ; octave
  927.  
  928.         ld      d,a     ; high byte freq
  929.  
  930.         ld      h,b     ; LD H,0!
  931. calc_drmcnt2:   ld      l,(iy + 5)
  932.         bit     7,l
  933.         jr      z,calc_wave_6
  934.         dec     h
  935.         add     hl,hl   ; detune...
  936. calc_wave_7:    add     hl,de
  937.         res     3,h
  938.         ld      (iy + 8),l      ; freq fine
  939.         ld      (iy + 9),h
  940.         exx             ; Yes! Finally, finished...
  941.         jp      play_int_secwe
  942. calc_wave_6:    ex      de,hl
  943.         add     hl,de   ; detune...
  944.         ld      d,1000b
  945.         jr      calc_wave_7
  946.  
  947.  
  948.  
  949. ;--- Calc GM drums ---
  950.  
  951. calc_drm:       ld      a,d
  952.         cp      36
  953.         jp      c,calc_drm_cnt  ; < 36 => first drum handled as patch
  954.         cp      85 + 5 + 1
  955.         jp      c,calc_drm2
  956.         ld      a,84 + 4 + 1    ; > 89 => 89
  957. calc_drm2:
  958.         ld      hl,gmdrm_c4
  959.         sub     36
  960.         ld      b,a
  961.         add     a,a
  962.         add     a,a
  963.         ld      e,a
  964.         ld      d,0
  965.         add     hl,de
  966.         ld      e,b
  967.         add     hl,de
  968.         ld      a,(hl)
  969.         ld      (iy + 7),a
  970.         ld      (iy + 6),0
  971.         inc     hl
  972.         ld      e,(hl)
  973.         inc     hl
  974.         ld      d,(hl)
  975.         inc     hl
  976.         ld      a,(hl)
  977.         ld      (iy + 13),a
  978.         inc     hl
  979.         ld      a,(hl)
  980.         ld      (iy + 14),a
  981.         ld      h,0
  982.         jp      calc_drmcnt2
  983.  
  984. calc_own:
  985.         sub     176
  986.         ld      c,a
  987.         add     a,a
  988.         add     a,a
  989.         add     a,a
  990.         ld      l,a
  991.         ld      h,0
  992.         add     hl,hl
  993.         add_hl_a        ; * 24
  994.         ld      a,c
  995.         add_hl_a        ; * 25
  996.         ld      bc,waves
  997.         add     hl,bc   ; pointer to patch
  998.  
  999.         ld      e,(hl)  ; transpose
  1000.         inc     hl
  1001.         ; zoek juiste patch-deel
  1002.         ld      a,d
  1003.         bit     0,e     ; transpose
  1004.         jr      z,calc_own2
  1005.         ld      a,(play_tspval)
  1006.         add     a,d
  1007.  
  1008. calc_own2:      ld      d,0
  1009.         ld      bc,3
  1010. calc_own_lp:    cp      (hl)
  1011.         jr      c,calc_own_2
  1012.         ld      d,(hl)
  1013.         add     hl,bc
  1014.         jp      calc_own_lp
  1015. calc_own_2:     ld      b,a     ; save note...
  1016.         inc     hl
  1017.         ld      a,(hl)  ; low byte tone
  1018.         ld      e,a
  1019.         add     a,128   ; tone 384 and above
  1020.         ld      (iy + 7),a
  1021.         ld      (iy + 6),1      ; RAM wave is altijd > 256
  1022.         inc     hl
  1023.  
  1024.         ld      a,(hl)  ; tone-note
  1025.         add     a,b
  1026.         sub     d
  1027.         ld      (iy + 0),a      ; last note
  1028.         push    af
  1029.  
  1030.         ld      (iy + 14),0     ; no header
  1031.  
  1032.         ld      hl,tones_data
  1033.         ld      d,0
  1034.         add     hl,de
  1035.         ld      a,(hl)
  1036.         and     110b
  1037.         ld      hl,frqtab_amiga
  1038.         jr      z,calc_own3
  1039.         ld      hl,frqtab_441khz
  1040.         cp      2
  1041.         jr      z,calc_own3
  1042.         ld      hl,frqtab_turbo
  1043. calc_own3:      pop     af
  1044.         ld      (iy + 16),l
  1045.         ld      (iy + 17),h
  1046.  
  1047.         ld      e,a     ; D is still 0
  1048.         add     hl,de
  1049.         add     hl,de
  1050.         ld      e,(hl)
  1051.         inc     hl
  1052.         ld      d,(hl)
  1053.         ld      h,0
  1054.         jp      calc_drmcnt2
  1055.  
  1056.  
  1057. ;---------------------------
  1058. ;--- WAVE Event routines ---
  1059. ;---------------------------
  1060.  
  1061. play_wtones:    ld      hl,step_buffer  ; songdata address
  1062.         ld      b,WAVCHNS       ; # channels
  1063.         ld      iy,play_table_wav
  1064.         ld      de,PTW_SIZE
  1065. play_wtonesl:   ld      a,(hl)
  1066.         dec     a
  1067.         cp      96
  1068.         jp      nc,play_wtonese
  1069.  
  1070.         opl4_wait
  1071.         ld      a,068h - 1
  1072.         add     a,b     ; calc. register
  1073.         out     (WVIO),a
  1074.         opl4_wait
  1075.         xor     a
  1076.         out     (WVIO+1),a      ; off
  1077.  
  1078.         opl4_wait
  1079.         ld      a,050h - 1
  1080.         add     a,b     ; calc. register
  1081.         out     (WVIO),a
  1082.         ld      c,a
  1083.         opl4_wait
  1084.         ld      a,11111111b
  1085.         out     (WVIO+1),a      ; volume 0!
  1086.  
  1087.         opl4_wait
  1088.         ld      a,20h - 1
  1089.         add     a,b
  1090.         out     (WVIO),a
  1091.         ld      a,(iy + 8)
  1092.         ld      (iy + 18),a
  1093.         or      (iy + 6)
  1094.         opl4_wait_keep_af
  1095.         out     (WVIO+1),a      ; freq + tone
  1096.  
  1097.         opl4_wait
  1098.         ld      a,8 - 1
  1099.         add     a,b
  1100.         out     (WVIO),a
  1101.         opl4_wait
  1102.         ld      a,(iy + 7)
  1103.         out     (WVIO+1),a      ; tone
  1104.  
  1105.         opl4_wait
  1106.         ld      a,38h - 1
  1107.         add     a,b
  1108.         out     (WVIO),a
  1109.         ld      a,(iy + 9)
  1110.         ld      (iy + 19),a
  1111.         or      (iy + 12)       ; pseude reverb
  1112.         opl4_wait_keep_af
  1113.         out     (WVIO+1),a      ; freq
  1114.  
  1115. play_wtonese:
  1116.         inc     hl
  1117.         add     iy,de
  1118.         djnz    play_wtonesl
  1119.         ret
  1120.  
  1121.  
  1122. ;--- Play ON-event ---
  1123.  
  1124. play_wonevt:
  1125.         dec     b
  1126.         ld      l,(iy + 13)
  1127.         ld      h,(iy + 14)
  1128.         ld      a,h
  1129.         or      a       ; Check only on high byte of pointer
  1130.         jr      z,play_wonevtlp2        ; own voice, no header...
  1131.  
  1132.         IF      RAMHEADERS=1
  1133.         opl4_wait
  1134.         ld      a,80h
  1135.         add     a,b
  1136.         out     (WVIO),a
  1137.         opl4_wait
  1138.         ld      a,(hl)
  1139.         out     (WVIO+1),a
  1140.         inc     hl
  1141.  
  1142. play_wvwait:
  1143.         in      a,(MOON_STAT)   ; wait till Wave Load ready
  1144.         and     $03
  1145.         jr      nz,play_wvwait
  1146.  
  1147. play_wonevtlp:
  1148.         ld      a,(hl)
  1149.         cp      0ffh
  1150.         jr      z,play_wonevtlp2
  1151.         add     a,b
  1152.         opl4_wait_keep_af
  1153.         out     (WVIO),a
  1154.         inc     hl
  1155.         opl4_wait
  1156.         ld      a,(hl)
  1157.         out     (WVIO+1),a      ; header byte
  1158.         inc     hl
  1159.         jp      play_wonevtlp
  1160.         ENDIF
  1161.  
  1162. play_wonevtlp2:
  1163.         opl4_wait
  1164.         ld      a,050h  ; set volume back to normal
  1165.         add     a,b
  1166.         out     (WVIO),a
  1167.         ld      a,(iy + 15)
  1168.         or      1       ; level direct
  1169.         opl4_wait_keep_af
  1170.         out     (WVIO+1),a
  1171.  
  1172.         opl4_wait
  1173.         ld      a,068h
  1174.         add     a,b
  1175.         out     (WVIO),a
  1176.         ld      a,10000000b
  1177.         or      (iy + 11)       ; pan pot
  1178.         opl4_wait_keep_af
  1179.         out     (WVIO+1),a      ; key on
  1180.         ret
  1181.  
  1182.  
  1183. ;--- Play OFF event ---
  1184.  
  1185. play_woffevt:
  1186.         opl4_wait
  1187.         ld      a,068h - 1
  1188.         add     a,b     ; calc. register
  1189.         out     (WVIO),a
  1190.         ld      (iy+2),0        ; pb/mod off
  1191.         opl4_wait
  1192.         in      a,(WVIO + 1)
  1193.         and     1111111b
  1194.         opl4_wait_keep_af
  1195.         out     (WVIO + 1),a
  1196.         ret
  1197.  
  1198.  
  1199. ;--- Play Wave event ---
  1200.  
  1201. play_wwavevt:   sub     98 - 1
  1202. play_wwavevt2:  ld      (iy + 2),0      ; pb off
  1203.         ld      c,a
  1204.         ld      hl,xwavnrs - 1
  1205.         add_hl_a
  1206.         ld      a,(hl)
  1207.         ld      (iy + 10),a
  1208.         ld      a,c
  1209.         ld      hl,xwavvols - 1
  1210.         add_hl_a
  1211.         ld      a,(iy + 15)
  1212.         and     1
  1213.         ld      d,a
  1214.         ld      a,(hl)
  1215.         add     a,a
  1216.         add     a,a
  1217.         or      d
  1218.         ld      (iy + 15),a
  1219.         ret
  1220.  
  1221. play_wavevtfd:  ld      a,(hl)
  1222.         add     a,a
  1223.         add     a,a
  1224.         or      d
  1225.         cp      (iy + 15)
  1226.         ret     c
  1227.         ld      (iy + 15),a
  1228.         ret
  1229.  
  1230.  
  1231. ;--- Play volume event ---
  1232.  
  1233. play_wchgvol:   sub     146
  1234.         xor     31
  1235.         add     a,a
  1236. play_wchgvol2:  add     a,a     ; * 4, OPL4 can handle 0-127
  1237.         add     a,a
  1238.         ld      c,a
  1239.  
  1240. play_wchgvolfd:
  1241.         opl4_wait
  1242.         ld      a,050h - 1
  1243.         add     a,b
  1244.         out     (WVIO),a
  1245.         ld      a,(iy + 15)     ; level direct
  1246.         and     1
  1247.         or      c
  1248.         ld      (iy + 15),a
  1249.         opl4_wait_keep_af
  1250.         out     (WVIO+1),a
  1251.         ret
  1252.  
  1253. ;--- Link note ---
  1254.  
  1255. play_wlnk:      ld      (iy + 2),0
  1256.         push    bc
  1257.         sub     202
  1258.         add     a,(iy + 0)
  1259.         ld      (iy + 0),a
  1260.  
  1261.         bit     0,(iy + 6)
  1262.         jr      z,play_wlnk2
  1263.         bit     7,(iy + 7)
  1264.         jr      nz,play_wlnk3
  1265.  
  1266. play_wlnk2:     ld      hl,tabdiv12
  1267.         ld      c,a
  1268.         ld      b,0
  1269.         add     hl,bc
  1270.         add     hl,bc
  1271.         ld      c,(hl)
  1272.         inc     hl
  1273.         ld      a,(hl)
  1274.         ld      l,(iy + 16)
  1275.         ld      h,(iy + 17)
  1276.         add_hl_a        ; ptr to freq
  1277.  
  1278.         ld      e,(hl)
  1279.         inc     hl
  1280.         ld      d,(hl)
  1281.         ex      de,hl   ; HL = freq
  1282.  
  1283.         add     hl,hl
  1284.         ld      a,h
  1285.         add     a,c
  1286.         ld      h,a
  1287. play_wlnk_7:    ld      d,0
  1288.         ld      e,(iy + 5)
  1289.         bit     7,e
  1290.         jr      z,play_wlnk_6
  1291.         dec     d
  1292. play_wlnk_6:    add     hl,de   ; detune...
  1293.         add     hl,de
  1294.  
  1295.         ld      (iy + 18),l     ; freq fine
  1296.         ld      (iy + 19),h
  1297.  
  1298.         pop     bc
  1299.         opl4_wait
  1300.         ld      a,20h - 1
  1301.         add     a,b
  1302.         out     (WVIO),a
  1303.         ld      a,l
  1304.         or      (iy + 6)
  1305.         opl4_wait_keep_af
  1306.         out     (WVIO+1),a      ; freq + tone
  1307.  
  1308.         opl4_wait
  1309.         ld      a,38h - 1
  1310.         add     a,b
  1311.         out     (WVIO),a
  1312.         ld      a,h
  1313.         or      (iy + 12)
  1314.         opl4_wait_keep_af
  1315.         out     (WVIO+1),a      ; freq
  1316.         ret
  1317.  
  1318. play_wlnk3:     ld      l,(iy + 16)     ; link own wave
  1319.         ld      h,(iy + 17)
  1320.         ld      e,a
  1321.         ld      d,0
  1322.         add     hl,de
  1323.         add     hl,de
  1324.         ld      e,(hl)
  1325.         inc     hl
  1326.         ld      d,(hl)
  1327.         ex      de,hl   ; freq
  1328.         jp      play_wlnk_7
  1329.  
  1330.  
  1331. ;--- Play stereo event ---
  1332.  
  1333. play_wchgste:   sub     178 + 7
  1334. play_wchgste2:  and     1111b
  1335.         ld      d,a
  1336.         ld      a,(iy+11)
  1337.         and     11110000b
  1338.         or      d
  1339.         ld      (iy+11),a
  1340.         opl4_wait
  1341.         ld      a,68h - 1
  1342.         add     a,b
  1343.         out     (WVIO),a
  1344.         ld      (iy + 2),0
  1345.         opl4_wait
  1346.         in      a,(WVIO + 1)
  1347.         and     11110000b
  1348.         or      d
  1349.         opl4_wait_keep_af
  1350.         out     (WVIO + 1),a
  1351.         ret
  1352.  
  1353. ;--- Pitch bending ---
  1354.  
  1355. play_wchgpit:   sub     221
  1356.         ld      (iy+2),1        ; Pitch bending on
  1357.         add     a,a
  1358.         add     a,a
  1359.         ld      (iy+3),a        ; Set pitch bend speed
  1360.         rlca            ; bit 7,a
  1361.         jr      c,play_wchgpit2
  1362.         ld      (iy+4),0
  1363.         ret
  1364.  
  1365. play_wchgpit2:  ld      (iy+4),0ffh
  1366.         ret
  1367.  
  1368.  
  1369. ;--- Modulation event ---
  1370.  
  1371. play_wchgmod:   sub     238 - 2
  1372.         ld      (iy + 2),a
  1373.         add     a,a
  1374.         add     a,a
  1375.         add     a,a
  1376.         add     a,a
  1377.         ld      hl,xmodtab - 2 * 16
  1378.         add_hl_a
  1379.         ld      (iy + 3),l
  1380.         ld      (iy + 4),h
  1381.         ret
  1382.  
  1383. ;--- Set detune ---
  1384.  
  1385. play_wchgdet:   sub     234
  1386.         add     a,a
  1387.         add     a,a     ; * 4
  1388.         ld      (iy + 5),a
  1389.         ret
  1390.  
  1391. ;--- Damp ---
  1392.  
  1393. play_chgdmp:
  1394.         opl4_wait
  1395.         ld      a,068h - 1
  1396.         add     a,b     ; calc. register
  1397.         out     (WVIO),a
  1398.         ld      (iy+2),0        ; pb/mod off
  1399.         opl4_wait
  1400.         in      a,(WVIO+1)
  1401.         or      1000000b
  1402.         opl4_wait_keep_af
  1403.         out     (WVIO + 1),a
  1404.         ret
  1405.  
  1406. ;--- Pseudo reverb on ---
  1407.  
  1408. play_chgpsr:    set     3,(iy+12)
  1409.         ret
  1410.  
  1411. ;--- Pseudo reverb off ---
  1412.  
  1413. play_chgpso:    res     3,(iy+12)
  1414.         ret
  1415.  
  1416. ;--- LFO ---
  1417.  
  1418. play_chglfo:
  1419.         opl4_wait
  1420.         ld      a,068h - 1
  1421.         add     a,b     ; calc. register
  1422.         out     (WVIO),a
  1423.         opl4_wait
  1424.         in      a,(WVIO+1)
  1425.         xor     100000b
  1426.         opl4_wait_keep_af
  1427.         out     (WVIO+1),a
  1428.         ret
  1429.  
  1430. ;--- eXtra Lfo Settings
  1431.  
  1432. play_chgxls:
  1433.         sub     246
  1434.         add     a,a
  1435.         ld      hl,xls_tabel
  1436.         add_hl_a
  1437.  
  1438.         opl4_wait
  1439.         ld      a,068h - 1
  1440.         add     a,b     ; calc. register
  1441.         out     (WVIO),a
  1442.         ld      d,a     ; Save calculation for later
  1443.         opl4_wait
  1444.         in      a,(WVIO+1)
  1445.         ld      c,a
  1446.         set     5,a
  1447.         opl4_wait_keep_af
  1448.         out     (WVIO+1),a
  1449.  
  1450.         opl4_wait
  1451.         ld      a,080h - 1
  1452.         add     a,b     ; calc. register
  1453.         out     (WVIO),a
  1454.         opl4_wait
  1455.         ld      a,(hl)
  1456.         out     (WVIO+1),a
  1457.         inc     hl
  1458.  
  1459.         opl4_wait
  1460.         ld      a,0E0h - 1
  1461.         add     a,b     ; calc. register
  1462.         out     (WVIO),a
  1463.         opl4_wait
  1464.         ld      a,(hl)
  1465.         out     (WVIO+1),a
  1466.         opl4_wait
  1467.         ld      a,d     ; Reg d = #68
  1468.         out     (WVIO),a
  1469.         opl4_wait
  1470.         ld      a,c     ; Reg c = contents reg #68
  1471.         res     5,a
  1472.         out     (WVIO+1),a
  1473.         ret
  1474.  
  1475. xls_tabel:
  1476.         db      49,0
  1477.         db      50,0
  1478.         db      51,0
  1479.         db      52,0
  1480.         db      53,0
  1481.         db      54,0
  1482.         db      55,0
  1483.         db      58,5
  1484.         db      03,0
  1485.  
  1486. ;--------------------------
  1487. ;--- CMD Event routines ---
  1488. ;--------------------------
  1489.  
  1490. ;-- change tempo --
  1491.  
  1492. play_chgtmp:    cpl
  1493.         add     a,25 +1
  1494.         ld      (play_speed),a
  1495.         jp      (ix)
  1496.  
  1497. ;-- change base frequency --
  1498.  
  1499. play_chgbasefr:
  1500.         ld      c,a
  1501.         opl4_wait
  1502.         ld      a,2
  1503.         out     (FMIO),a
  1504.         opl4_wait
  1505.         ld      a,c
  1506.         sub     77
  1507.         out     (FMIO+1),a
  1508.         neg
  1509.         ld      (xhzequal),a
  1510.         jp      (ix)
  1511.  
  1512.  
  1513. ;-- end of pattern --
  1514.  
  1515. play_endop:     ld      a,15
  1516.         ld      (play_step),a
  1517.         jp      (ix)
  1518.  
  1519. ;--- set transpose ---
  1520.  
  1521. play_chgtrs:    sub     52
  1522.         ld      (play_tspval),a
  1523.         jp      (ix)
  1524.  
  1525.  
  1526.  
  1527. ;---------------------------
  1528. ;--- Go to next position ---
  1529. ;---------------------------
  1530.  
  1531. play_nextpos:   ld      a,(songdata_bank1)
  1532.         call    selbank_FE      ; this bank contains pattern addresses
  1533.  
  1534.         ld      a,(xleng)
  1535.         inc     a
  1536.         ld      b,a
  1537.         ld      a,(play_pos)
  1538.         inc     a
  1539.         cp      b
  1540.         jp      c,play_nextpos2
  1541.         ld      a,(xloop)
  1542.         cp      255
  1543.         call    z,play_nextstop ; stop song, want loop OFF
  1544.  
  1545. play_nextpos2:
  1546.         ld      (play_pos),a
  1547.         ld      hl,(pos_address)
  1548.         add_hl_a
  1549.         ld      a,(hl)
  1550.         ld      (current_pat),a
  1551.         add     a,a
  1552.         ld      hl,(pat_address)
  1553.         add_hl_a
  1554.         ld      e,(hl)
  1555.         inc     hl
  1556.         ld      d,(hl)
  1557.         ex      de,hl
  1558.         ld      a,h
  1559.         rlca
  1560.         rlca
  1561.         and     011b
  1562.         ld      de,songdata_bank1
  1563.         add_de_a
  1564.         ld      a,(de)
  1565.         ld      (songdata_bank),a
  1566.         ld      a,h
  1567.         and     00111111b
  1568.         ld      h,a
  1569.         ld      de,(songdata_adres)
  1570.         add     hl,de
  1571.         ret
  1572. play_nextstop:
  1573.         call    stop_music
  1574.         xor     a
  1575.         ret
  1576.  
  1577. ;--------------------------------
  1578. ;--- Pitch interrupt routines ---
  1579. ;--------------------------------
  1580.  
  1581. ;----- pitch bending/modulation -----
  1582.  
  1583. play_pitch:
  1584.         ld      iy,play_table_wav
  1585.         ld      de,PTW_SIZE
  1586.         ld      hl,play_pitchwvl2
  1587.         ld      b,WAVCHNS       ; wave channels
  1588. play_pitchwlus:
  1589.         ld      a,(iy+2)
  1590.         or      a
  1591.         jp      nz,play_pitch_wdo
  1592. play_pitchwvl2:
  1593.         add     iy,de
  1594.         djnz    play_pitchwlus
  1595.         ret
  1596.  
  1597.  
  1598.  
  1599. ;--- pitch bending ---
  1600.  
  1601. play_pitch_wdo: exx
  1602.  
  1603.         ld      c,a
  1604.  
  1605.         ld      l,(iy + 3)      ; pitch bend speed
  1606.         ld      h,(iy + 4)
  1607.         dec     c
  1608.         jp      nz,play_mod_wdo ; modulation
  1609.         ex      de,hl
  1610. play_pitch_wd4:
  1611.         ld      h,(iy + 19)
  1612.         ld      l,(iy + 18)
  1613.         add     hl,de   ; sliding
  1614.         bit     3,h
  1615.         jr      z,play_pitch_wd5
  1616.         bit     7,d
  1617.         jr      nz,play_pitch_wd6
  1618.         ld      a,h
  1619.         add     a,1000b
  1620.         ld      h,a
  1621.         jr      play_pitch_wd5
  1622. play_pitch_wd6:
  1623.         res     3,h
  1624. play_pitch_wd5:
  1625.         ld      (iy + 18),l     ; freq fine
  1626.         ld      (iy + 19),h
  1627.         opl4_wait
  1628.         ld      a,(iy + 1)
  1629.         ld      c,a
  1630.         out     (WVIO),a
  1631.         ld      a,l
  1632.         or      (iy + 6)
  1633.         opl4_wait_keep_af
  1634.         out     (WVIO+1),a      ; freq + tone
  1635.  
  1636.         opl4_wait
  1637.         ld      a,c
  1638.         add     a,24
  1639.         out     (WVIO),a
  1640.         opl4_wait
  1641.         ld      a,h
  1642.         out     (WVIO+1),a      ; freq
  1643.         exx
  1644.         jp      (hl)
  1645.  
  1646.  
  1647. ;---- modulation ----
  1648.  
  1649. play_mod_wdo:
  1650.         ld      d,0
  1651.         ld      a,(hl)
  1652.         add     a,a
  1653.         add     a,a
  1654.         ld      e,a
  1655.         jr      nc,play_mod_wdo3
  1656.         dec     d
  1657. play_mod_wdo3:
  1658.         inc     hl
  1659.         ld      a,(hl)
  1660.         cp      10
  1661.         jp      nz,play_mod_wdo2
  1662.         ld      a,c
  1663.  
  1664.         ld      hl,xmodtab - 16
  1665.         add     a,a
  1666.         add     a,a
  1667.         add     a,a
  1668.         add     a,a
  1669.         add_hl_a
  1670. play_mod_wdo2:
  1671.         ld      (iy + 3),l
  1672.         ld      (iy + 4),h
  1673.         jp      play_pitch_wd4
  1674.  
  1675.  
  1676. ;----------------
  1677. ;--- OPL4 out ---
  1678. ;----------------
  1679.  
  1680. opl4_out_wave:
  1681.         ex      af,af'
  1682.         opl4_wait
  1683.         ld      a,c
  1684.         out     (WVIO),a
  1685.         opl4_wait
  1686.         ex      af,af'
  1687.         out     (WVIO+1),a
  1688.         ret
  1689.  
  1690.  
  1691. ;--- smart table: --
  1692.  
  1693. ;    - last note played                 01: + 0
  1694. ;    - frequency register               01: + 1
  1695. ;    - pitch bending on/off             01: + 2
  1696. ;    - pitch bend speed                 02: + 3
  1697. ;    - detune value                     01: + 5
  1698. ;    - tone nr for next interrupt       02: + 6
  1699. ;    - freq for next interrupt          02: + 8
  1700. ;    - current patch                    01  + 10
  1701. ;    - current stereo setting           01  + 11
  1702. ;    - pseudo reverb                    01  + 12
  1703. ;    - Pointer to header bytes          02  + 13
  1704. ;    - Volume                           01  + 15
  1705. ;    - Pointer to used freq table       01  + 16
  1706. ;    - Current pitch freq.              02  + 18
  1707. ;                               --
  1708. ;    Total:                             20
  1709.  
  1710. play_table_wav:
  1711.         db      0,037h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch1
  1712.         db      0,036h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch2
  1713.         db      0,035h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch3
  1714.         db      0,034h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch4
  1715.         db      0,033h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch5
  1716.         db      0,032h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch6
  1717.         db      0,031h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch7
  1718.         db      0,030h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch8
  1719.         db      0,02fh,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch9
  1720.         db      0,02eh,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch10
  1721.         db      0,02dh,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch11
  1722.         db      0,02ch,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch12
  1723.         db      0,02bh,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch13
  1724.         db      0,02ah,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch14
  1725.         db      0,029h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch15
  1726.         db      0,028h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch16
  1727.         db      0,027h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch17
  1728.         db      0,026h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch18
  1729.         db      0,025h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch19
  1730.         db      0,024h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch20
  1731.         db      0,023h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch21
  1732.         db      0,022h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch22
  1733.         db      0,021h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch23
  1734.         db      0,020h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0      ; ch24
  1735.  
  1736.  
  1737. songdata_bank:  db      0
  1738. play_speed:     db      0       ; current play speed
  1739. play_tspval:    db      0       ; current transpose
  1740. play_timercnt:  db      0       ; tempo counter
  1741. current_pat:    db      0
  1742.  
  1743.  
  1744. xleng   ds      1       ; Song length
  1745. xloop   ds      1       ; Loop position
  1746. xwvstpr ds      24      ; Stereo settings Wave
  1747. xtempo  ds      1       ; Tempo
  1748. xhzequal        ds      1       ; Base frequency
  1749. xdetune ds      24      ; Detune settings
  1750. xmodtab ds      3*16    ; Modulation tables
  1751. xbegwav ds      24      ; Start waves
  1752. xwavnrs ds      48      ; Wave numbers
  1753. xwavvols        ds      48      ; Wave volumes
  1754.  
  1755. pat_address:    dw      0
  1756. pos_address:    dw      0
  1757. songdata_ptr:   dw      0
  1758.  
  1759. tabdiv12:
  1760.         db      -5*16,0,-5*16,2*1,-5*16,2*2,-5*16,2*3,-5*16,2*4,-5*16,2*5
  1761.         db      -5*16,2*6,-5*16,2*7,-5*16,2*8,-5*16,2*9,-5*16,2*10,-5*16,2*11
  1762.         db      -4*16,0,-4*16,2*1,-4*16,2*2,-4*16,2*3,-4*16,2*4,-4*16,2*5
  1763.         db      -4*16,2*6,-4*16,2*7,-4*16,2*8,-4*16,2*9,-4*16,2*10,-4*16,2*11
  1764.         db      -3*16,0,-3*16,2*1,-3*16,2*2,-3*16,2*3,-3*16,2*4,-3*16,2*5
  1765.         db      -3*16,2*6,-3*16,2*7,-3*16,2*8,-3*16,2*9,-3*16,2*10,-3*16,2*11
  1766.         db      -2*16,0,-2*16,2*1,-2*16,2*2,-2*16,2*3,-2*16,2*4,-2*16,2*5
  1767.         db      -2*16,2*6,-2*16,2*7,-2*16,2*8,-2*16,2*9,-2*16,2*10,-2*16,2*11
  1768.         db      -1*16,0,-1*16,2*1,-1*16,2*2,-1*16,2*3,-1*16,2*4,-1*16,2*5
  1769.         db      -1*16,2*6,-1*16,2*7,-1*16,2*8,-1*16,2*9,-1*16,2*10,-1*16,2*11
  1770.         db      0*16,0,0*16,2*1,0*16,2*2,0*16,2*3,0*16,2*4,0*16,2*5
  1771.         db      0*16,2*6,0*16,2*7,0*16,2*8,0*16,2*9,0*16,2*10,0*16,2*11
  1772.         db      1*16,0,1*16,2*1,1*16,2*2,1*16,2*3,1*16,2*4,1*16,2*5
  1773.         db      1*16,2*6,1*16,2*7,1*16,2*8,1*16,2*9,1*16,2*10,1*16,2*11
  1774.         db      2*16,0,2*16,2*1,2*16,2*2,2*16,2*3,2*16,2*4,2*16,2*5
  1775.         db      2*16,2*6,2*16,2*7,2*16,2*8,2*16,2*9,2*16,2*10,2*16,2*11
  1776.         db      3*16,0,3*16,2*1,3*16,2*2,3*16,2*3,3*16,2*4,3*16,2*5
  1777.         db      3*16,2*6,3*16,2*7,3*16,2*8,3*16,2*9,3*16,2*10,3*16,2*11
  1778.         db      4*16,0,4*16,2*1,4*16,2*2,4*16,2*3,4*16,2*4,4*16,2*5
  1779.         db      4*16,2*6,4*16,2*7,4*16,2*8,4*16,2*9,4*16,2*10,4*16,2*11
  1780.         db      5*16,0,5*16,2*1,5*16,2*2,5*16,2*3,5*16,2*4,5*16,2*5
  1781.         db      5*16,2*6,5*16,2*7,5*16,2*8,5*16,2*9,5*16,2*10,5*16,2*11
  1782.         db      6*16,0,6*16,2*1,6*16,2*2,6*16,2*3,6*16,2*4,6*16,2*5
  1783.         db      6*16,2*6,6*16,2*7,6*16,2*8,6*16,2*9,6*16,2*10,6*16,2*11
  1784.         db      7*16,0,7*16,2*1,7*16,2*2,7*16,2*3,7*16,2*4,7*16,2*5
  1785.         db      7*16,2*6,7*16,2*7,7*16,2*8,7*16,2*9,7*16,2*10,7*16,2*11
  1786.         db      8*16,0,8*16,2*1,8*16,2*2,8*16,2*3,8*16,2*4,8*16,2*5
  1787.         db      8*16,2*6,8*16,2*7,8*16,2*8,8*16,2*9,8*16,2*10,8*16,2*11
  1788.         db      9*16,0,9*16,2*1,9*16,2*2,9*16,2*3,9*16,2*4,9*16,2*5
  1789.         db      9*16,2*6,9*16,2*7,9*16,2*8,9*16,2*9,9*16,2*10,9*16,2*11
  1790.         db      10*16,0,10*16,2*1,10*16,2*2,10*16,2*3,10*16,2*4,10*16,2*5
  1791.         db      10*16,2*6,10*16,2*7,10*16,2*8,10*16,2*9,10*16,2*10,10*16,2*11
  1792.  
  1793. ;--- freq. table for 44.1 kHz
  1794.  
  1795. frqtab_441khz:  dw      (-4 * 2048 + 0) * 2
  1796.         dw      (-4 * 2048 + 61) * 2
  1797.         dw      (-4 * 2048 + 125) * 2
  1798.         dw      (-4 * 2048 + 194) * 2
  1799.         dw      (-4 * 2048 + 266) * 2
  1800.         dw      (-4 * 2048 + 343) * 2
  1801.         dw      (-4 * 2048 + 424) * 2
  1802.         dw      (-4 * 2048 + 510) * 2
  1803.         dw      (-4 * 2048 + 601) * 2
  1804.         dw      (-4 * 2048 + 698) * 2
  1805.         dw      (-4 * 2048 + 801) * 2
  1806.         dw      (-4 * 2048 + 909) * 2
  1807.         dw      (-3 * 2048 + 0) * 2
  1808.         dw      (-3 * 2048 + 61) * 2
  1809.         dw      (-3 * 2048 + 125) * 2
  1810.         dw      (-3 * 2048 + 194) * 2
  1811.         dw      (-3 * 2048 + 266) * 2
  1812.         dw      (-3 * 2048 + 343) * 2
  1813.         dw      (-3 * 2048 + 424) * 2
  1814.         dw      (-3 * 2048 + 510) * 2
  1815.         dw      (-3 * 2048 + 601) * 2
  1816.         dw      (-3 * 2048 + 698) * 2
  1817.         dw      (-3 * 2048 + 801) * 2
  1818.         dw      (-3 * 2048 + 909) * 2
  1819.         dw      (-2 * 2048 + 0) * 2
  1820.         dw      (-2 * 2048 + 61) * 2
  1821.         dw      (-2 * 2048 + 125) * 2
  1822.         dw      (-2 * 2048 + 194) * 2
  1823.         dw      (-2 * 2048 + 266) * 2
  1824.         dw      (-2 * 2048 + 343) * 2
  1825.         dw      (-2 * 2048 + 424) * 2
  1826.         dw      (-2 * 2048 + 510) * 2
  1827.         dw      (-2 * 2048 + 601) * 2
  1828.         dw      (-2 * 2048 + 698) * 2
  1829.         dw      (-2 * 2048 + 801) * 2
  1830.         dw      (-2 * 2048 + 909) * 2
  1831.         dw      (-1 * 2048 + 0) * 2
  1832.         dw      (-1 * 2048 + 61) * 2
  1833.         dw      (-1 * 2048 + 125) * 2
  1834.         dw      (-1 * 2048 + 194) * 2
  1835.         dw      (-1 * 2048 + 266) * 2
  1836.         dw      (-1 * 2048 + 343) * 2
  1837.         dw      (-1 * 2048 + 424) * 2
  1838.         dw      (-1 * 2048 + 510) * 2
  1839.         dw      (-1 * 2048 + 601) * 2
  1840.         dw      (-1 * 2048 + 698) * 2
  1841.         dw      (-1 * 2048 + 801) * 2
  1842.         dw      (-1 * 2048 + 909) * 2
  1843.         dw      (-0 * 2048 + 0) * 2
  1844.         dw      (-0 * 2048 + 61) * 2
  1845.         dw      (-0 * 2048 + 125) * 2
  1846.         dw      (-0 * 2048 + 194) * 2
  1847.         dw      (-0 * 2048 + 266) * 2
  1848.         dw      (-0 * 2048 + 343) * 2
  1849.         dw      (-0 * 2048 + 424) * 2
  1850.         dw      (-0 * 2048 + 510) * 2
  1851.         dw      (-0 * 2048 + 601) * 2
  1852.         dw      (-0 * 2048 + 698) * 2
  1853.         dw      (-0 * 2048 + 801) * 2
  1854.         dw      (-0 * 2048 + 909) * 2
  1855.         dw      (+1 * 2048 + 0) * 2
  1856.         dw      (+1 * 2048 + 61) * 2
  1857.         dw      (+1 * 2048 + 125) * 2
  1858.         dw      (+1 * 2048 + 194) * 2
  1859.         dw      (+1 * 2048 + 266) * 2
  1860.         dw      (+1 * 2048 + 343) * 2
  1861.         dw      (+1 * 2048 + 424) * 2
  1862.         dw      (+1 * 2048 + 510) * 2
  1863.         dw      (+1 * 2048 + 601) * 2
  1864.         dw      (+1 * 2048 + 698) * 2
  1865.         dw      (+1 * 2048 + 801) * 2
  1866.         dw      (+1 * 2048 + 909) * 2
  1867.         dw      (+2 * 2048 + 0) * 2
  1868.         dw      (+2 * 2048 + 61) * 2
  1869.         dw      (+2 * 2048 + 125) * 2
  1870.         dw      (+2 * 2048 + 194) * 2
  1871.         dw      (+2 * 2048 + 266) * 2
  1872.         dw      (+2 * 2048 + 343) * 2
  1873.         dw      (+2 * 2048 + 424) * 2
  1874.         dw      (+2 * 2048 + 510) * 2
  1875.         dw      (+2 * 2048 + 601) * 2
  1876.         dw      (+2 * 2048 + 698) * 2
  1877.         dw      (+2 * 2048 + 801) * 2
  1878.         dw      (+2 * 2048 + 909) * 2
  1879.         dw      (+3 * 2048 + 0) * 2
  1880.         dw      (+3 * 2048 + 61) * 2
  1881.         dw      (+3 * 2048 + 125) * 2
  1882.         dw      (+3 * 2048 + 194) * 2
  1883.         dw      (+3 * 2048 + 266) * 2
  1884.         dw      (+3 * 2048 + 343) * 2
  1885.         dw      (+3 * 2048 + 424) * 2
  1886.         dw      (+3 * 2048 + 510) * 2
  1887.         dw      (+3 * 2048 + 601) * 2
  1888.         dw      (+3 * 2048 + 698) * 2
  1889.         dw      (+3 * 2048 + 801) * 2
  1890.         dw      (+3 * 2048 + 909) * 2
  1891.         dw      (+4 * 2048 + 0) * 2
  1892.         dw      (+4 * 2048 + 61) * 2
  1893.         dw      (+4 * 2048 + 125) * 2
  1894.         dw      (+4 * 2048 + 194) * 2
  1895.         dw      (+4 * 2048 + 266) * 2
  1896.         dw      (+4 * 2048 + 343) * 2
  1897.         dw      (+4 * 2048 + 424) * 2
  1898.         dw      (+4 * 2048 + 510) * 2
  1899.         dw      (+4 * 2048 + 601) * 2
  1900.         dw      (+4 * 2048 + 698) * 2
  1901.         dw      (+4 * 2048 + 801) * 2
  1902.         dw      (+4 * 2048 + 909) * 2
  1903.         dw      (+5 * 2048 + 0) * 2
  1904.         dw      (+5 * 2048 + 61) * 2
  1905.         dw      (+5 * 2048 + 125) * 2
  1906.         dw      (+5 * 2048 + 194) * 2
  1907.         dw      (+5 * 2048 + 266) * 2
  1908.         dw      (+5 * 2048 + 343) * 2
  1909.         dw      (+5 * 2048 + 424) * 2
  1910.         dw      (+5 * 2048 + 510) * 2
  1911.         dw      (+5 * 2048 + 601) * 2
  1912.         dw      (+5 * 2048 + 698) * 2
  1913.         dw      (+5 * 2048 + 801) * 2
  1914.         dw      (+5 * 2048 + 909) * 2
  1915.  
  1916. ;--- freq table for Amiga ---
  1917.  
  1918. frqtab_amiga:
  1919.  
  1920.         dw      (-5 * 2048 + 529) * 2
  1921.         dw      (-5 * 2048 + 621) * 2
  1922.         dw      (-5 * 2048 + 721) * 2
  1923.         dw      (-5 * 2048 + 823) * 2
  1924.         dw      (-5 * 2048 + 937) * 2
  1925.         dw      (-4 * 2048 + 14) * 2
  1926.         dw      (-4 * 2048 + 76) * 2
  1927.         dw      (-4 * 2048 + 142) * 2
  1928.         dw      (-4 * 2048 + 211) * 2
  1929.         dw      (-4 * 2048 + 284) * 2
  1930.         dw      (-4 * 2048 + 361) * 2
  1931.         dw      (-4 * 2048 + 447) * 2
  1932.  
  1933.         dw      (-4 * 2048 + 529) * 2
  1934.         dw      (-4 * 2048 + 621) * 2
  1935.         dw      (-4 * 2048 + 721) * 2
  1936.         dw      (-4 * 2048 + 823) * 2
  1937.         dw      (-4 * 2048 + 937) * 2
  1938.         dw      (-3 * 2048 + 14) * 2
  1939.         dw      (-3 * 2048 + 76) * 2
  1940.         dw      (-3 * 2048 + 142) * 2
  1941.         dw      (-3 * 2048 + 211) * 2
  1942.         dw      (-3 * 2048 + 284) * 2
  1943.         dw      (-3 * 2048 + 361) * 2
  1944.         dw      (-3 * 2048 + 447) * 2
  1945.  
  1946.         dw      (-3 * 2048 + 529) * 2
  1947.         dw      (-3 * 2048 + 621) * 2
  1948.         dw      (-3 * 2048 + 721) * 2
  1949.         dw      (-3 * 2048 + 823) * 2
  1950.         dw      (-3 * 2048 + 937) * 2
  1951.         dw      (-2 * 2048 + 14) * 2
  1952.         dw      (-2 * 2048 + 76) * 2
  1953.         dw      (-2 * 2048 + 142) * 2
  1954.         dw      (-2 * 2048 + 211) * 2
  1955.         dw      (-2 * 2048 + 284) * 2
  1956.         dw      (-2 * 2048 + 361) * 2
  1957.         dw      (-2 * 2048 + 447) * 2
  1958.  
  1959.         dw      (-2 * 2048 + 529) * 2
  1960.         dw      (-2 * 2048 + 621) * 2
  1961.         dw      (-2 * 2048 + 721) * 2
  1962.         dw      (-2 * 2048 + 823) * 2
  1963.         dw      (-2 * 2048 + 937) * 2
  1964.         dw      (-1 * 2048 + 14) * 2
  1965.         dw      (-1 * 2048 + 76) * 2
  1966.         dw      (-1 * 2048 + 142) * 2
  1967.         dw      (-1 * 2048 + 211) * 2
  1968.         dw      (-1 * 2048 + 284) * 2
  1969.         dw      (-1 * 2048 + 361) * 2
  1970.         dw      (-1 * 2048 + 447) * 2
  1971.  
  1972.         dw      (-1 * 2048 + 529) * 2
  1973.         dw      (-1 * 2048 + 621) * 2
  1974.         dw      (-1 * 2048 + 721) * 2
  1975.         dw      (-1 * 2048 + 823) * 2
  1976.         dw      (-1 * 2048 + 937) * 2
  1977.         dw      (-0 * 2048 + 14) * 2
  1978.         dw      (-0 * 2048 + 76) * 2
  1979.         dw      (-0 * 2048 + 142) * 2
  1980.         dw      (-0 * 2048 + 211) * 2
  1981.         dw      (-0 * 2048 + 284) * 2
  1982.         dw      (-0 * 2048 + 361) * 2
  1983.         dw      (-0 * 2048 + 447) * 2
  1984.  
  1985.         dw      (-0 * 2048 + 529) * 2
  1986.         dw      (-0 * 2048 + 621) * 2
  1987.         dw      (-0 * 2048 + 721) * 2
  1988.         dw      (-0 * 2048 + 823) * 2
  1989.         dw      (-0 * 2048 + 937) * 2
  1990.         dw      (+1 * 2048 + 14) * 2
  1991.         dw      (+1 * 2048 + 76) * 2
  1992.         dw      (+1 * 2048 + 142) * 2
  1993.         dw      (+1 * 2048 + 211) * 2
  1994.         dw      (+1 * 2048 + 284) * 2
  1995.         dw      (+1 * 2048 + 361) * 2
  1996.         dw      (+1 * 2048 + 447) * 2
  1997.  
  1998.         dw      (+1 * 2048 + 529) * 2
  1999.         dw      (+1 * 2048 + 621) * 2
  2000.         dw      (+1 * 2048 + 721) * 2
  2001.         dw      (+1 * 2048 + 823) * 2
  2002.         dw      (+1 * 2048 + 937) * 2
  2003.         dw      (+2 * 2048 + 14) * 2
  2004.         dw      (+2 * 2048 + 76) * 2
  2005.         dw      (+2 * 2048 + 142) * 2
  2006.         dw      (+2 * 2048 + 211) * 2
  2007.         dw      (+2 * 2048 + 284) * 2
  2008.         dw      (+2 * 2048 + 361) * 2
  2009.         dw      (+2 * 2048 + 447) * 2
  2010.  
  2011.         dw      (+2 * 2048 + 529) * 2
  2012.         dw      (+2 * 2048 + 621) * 2
  2013.         dw      (+2 * 2048 + 721) * 2
  2014.         dw      (+2 * 2048 + 823) * 2
  2015.         dw      (+2 * 2048 + 937) * 2
  2016.         dw      (+3 * 2048 + 14) * 2
  2017.         dw      (+3 * 2048 + 76) * 2
  2018.         dw      (+3 * 2048 + 142) * 2
  2019.         dw      (+3 * 2048 + 211) * 2
  2020.         dw      (+3 * 2048 + 284) * 2
  2021.         dw      (+3 * 2048 + 361) * 2
  2022.         dw      (+3 * 2048 + 447) * 2
  2023.  
  2024.  
  2025. ;--- freq table for Turbo-R ---
  2026.  
  2027. frqtab_turbo:
  2028.         dw      (-5 * 2048 + 439) * 2
  2029.         dw      (-5 * 2048 + 526) * 2
  2030.         dw      (-5 * 2048 + 618) * 2
  2031.         dw      (-5 * 2048 + 716) * 2
  2032.         dw      (-5 * 2048 + 819) * 2
  2033.         dw      (-5 * 2048 + 929) * 2
  2034.         dw      (-4 * 2048 + 10) * 2
  2035.         dw      (-4 * 2048 + 72) * 2
  2036.         dw      (-4 * 2048 + 137) * 2
  2037.         dw      (-4 * 2048 + 206) * 2
  2038.         dw      (-4 * 2048 + 279) * 2
  2039.         dw      (-4 * 2048 + 357) * 2
  2040.  
  2041.         dw      (-4 * 2048 + 439) * 2
  2042.         dw      (-4 * 2048 + 526) * 2
  2043.         dw      (-4 * 2048 + 618) * 2
  2044.         dw      (-4 * 2048 + 716) * 2
  2045.         dw      (-4 * 2048 + 819) * 2
  2046.         dw      (-4 * 2048 + 929) * 2
  2047.         dw      (-3 * 2048 + 10) * 2
  2048.         dw      (-3 * 2048 + 72) * 2
  2049.         dw      (-3 * 2048 + 137) * 2
  2050.         dw      (-3 * 2048 + 206) * 2
  2051.         dw      (-3 * 2048 + 279) * 2
  2052.         dw      (-3 * 2048 + 357) * 2
  2053.  
  2054.         dw      (-3 * 2048 + 439) * 2
  2055.         dw      (-3 * 2048 + 526) * 2
  2056.         dw      (-3 * 2048 + 618) * 2
  2057.         dw      (-3 * 2048 + 716) * 2
  2058.         dw      (-3 * 2048 + 819) * 2
  2059.         dw      (-3 * 2048 + 929) * 2
  2060.         dw      (-2 * 2048 + 10) * 2
  2061.         dw      (-2 * 2048 + 72) * 2
  2062.         dw      (-2 * 2048 + 137) * 2
  2063.         dw      (-2 * 2048 + 206) * 2
  2064.         dw      (-2 * 2048 + 279) * 2
  2065.         dw      (-2 * 2048 + 357) * 2
  2066.  
  2067.         dw      (-2 * 2048 + 439) * 2
  2068.         dw      (-2 * 2048 + 526) * 2
  2069.         dw      (-2 * 2048 + 618) * 2
  2070.         dw      (-2 * 2048 + 716) * 2
  2071.         dw      (-2 * 2048 + 819) * 2
  2072.         dw      (-2 * 2048 + 929) * 2
  2073.         dw      (-1 * 2048 + 10) * 2
  2074.         dw      (-1 * 2048 + 72) * 2
  2075.         dw      (-1 * 2048 + 137) * 2
  2076.         dw      (-1 * 2048 + 206) * 2
  2077.         dw      (-1 * 2048 + 279) * 2
  2078.         dw      (-1 * 2048 + 357) * 2
  2079.  
  2080.         dw      (-1 * 2048 + 439) * 2
  2081.         dw      (-1 * 2048 + 526) * 2
  2082.         dw      (-1 * 2048 + 618) * 2
  2083.         dw      (-1 * 2048 + 716) * 2
  2084.         dw      (-1 * 2048 + 819) * 2
  2085.         dw      (-1 * 2048 + 929) * 2
  2086.         dw      (-0 * 2048 + 10) * 2
  2087.         dw      (-0 * 2048 + 72) * 2
  2088.         dw      (-0 * 2048 + 137) * 2
  2089.         dw      (-0 * 2048 + 206) * 2
  2090.         dw      (-0 * 2048 + 279) * 2
  2091.         dw      (-0 * 2048 + 357) * 2
  2092.  
  2093.         dw      (-0 * 2048 + 439) * 2
  2094.         dw      (-0 * 2048 + 526) * 2
  2095.         dw      (-0 * 2048 + 618) * 2
  2096.         dw      (-0 * 2048 + 716) * 2
  2097.         dw      (-0 * 2048 + 819) * 2
  2098.         dw      (-0 * 2048 + 929) * 2
  2099.         dw      (+1 * 2048 + 10) * 2
  2100.         dw      (+1 * 2048 + 72) * 2
  2101.         dw      (+1 * 2048 + 137) * 2
  2102.         dw      (+1 * 2048 + 206) * 2
  2103.         dw      (+1 * 2048 + 279) * 2
  2104.         dw      (+1 * 2048 + 357) * 2
  2105.  
  2106.         dw      (+1 * 2048 + 439) * 2
  2107.         dw      (+1 * 2048 + 526) * 2
  2108.         dw      (+1 * 2048 + 618) * 2
  2109.         dw      (+1 * 2048 + 716) * 2
  2110.         dw      (+1 * 2048 + 819) * 2
  2111.         dw      (+1 * 2048 + 929) * 2
  2112.         dw      (+2 * 2048 + 10) * 2
  2113.         dw      (+2 * 2048 + 72) * 2
  2114.         dw      (+2 * 2048 + 137) * 2
  2115.         dw      (+2 * 2048 + 206) * 2
  2116.         dw      (+2 * 2048 + 279) * 2
  2117.         dw      (+2 * 2048 + 357) * 2
  2118.  
  2119. waves:  ds      48 * 25
  2120. tones_data:     ds      64
  2121.  
  2122.         include "patches.asm"
  2123.