?login_element?

Subversion Repositories NedoOS

Rev

Rev 731 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. filterhandler_vol
  2.         ld a,e
  3.         sub 1+15 ;"f" (1="0", 2="1"...)
  4.         ld e,a ;vol "f" = +0, "g" = +1...
  5. filtervolume
  6. ;ix=from=to
  7. ;e=volume shift (+-15)
  8.         ld a,(ix+chn.volume)
  9.         add a,e
  10.         jp po,filtervolumeq ;no signed overflow
  11.         rla
  12.         sbc a,a ;a=0 for negative overflow, a=255 for positive overflow
  13.         xor 0x80 ;a=-128 for negative overflow, a=127 for positive overflow
  14. filtervolumeq        
  15.         ld (ix+chn.volume),a
  16.         ret
  17.  
  18. filterhandler_noise
  19. ;TODO
  20.         ret
  21. filternoise
  22. ;ix=from=to
  23. ;e=noise shift (+-15)
  24.         ld a,(ix+chn.noisefrq)
  25.         add a,e
  26.         jp po,filternoiseq ;no signed overflow
  27.         rla
  28.         sbc a,a ;a=0 for negative overflow, a=255 for positive overflow
  29.         xor 0x80 ;a=-128 for negative overflow, a=127 for positive overflow
  30. filternoiseq
  31.         ld (ix+chn.noisefrq),a
  32.         ret
  33.  
  34. filterhandler_echo
  35. ;TODO
  36.         ret
  37.  
  38. filterhandler_vib
  39. ;TODO
  40.         ret
  41. filtertone
  42. ;ix=from=to
  43. ;de=tone shift (+-4095)
  44.         ld a,(ix+chn.tonefrq)
  45.         add a,e
  46.         ld e,a
  47.         ld a,(ix+chn.tonefrq+1)
  48.         adc a,d
  49.         ld d,a
  50.         jp p,$+6
  51.          ld de,0
  52.         ld (ix+chn.tonefrq),e
  53.         ld (ix+chn.tonefrq+1),d
  54.         ret
  55.  
  56. filterhandler_env
  57. ;TODO
  58. filterenv
  59. ;ix=from=to
  60. ;de=env shift
  61.         ld a,(ix+chn.envfrq)
  62.         add a,e
  63.         ld e,a
  64.         ld a,(ix+chn.envfrq+1)
  65.         adc a,d
  66.         ld d,a
  67.         jp p,$+6
  68.          ld de,0
  69.         ld (ix+chn.envfrq),e
  70.         ld (ix+chn.envfrq+1),d
  71.         ret
  72.  
  73. mixchn
  74. ;iy=from1=to
  75. ;ix=from2
  76. ;в release должен быть понижен приоритет канала
  77. ;если в from1 есть огибающая, то игнорируем from1, если его KEEPME <= чем у from2
  78. ;т.к. огибающую должен перекрывать тональник!!!
  79.         ;bit MASKBIT_E,(iy+chn.masks)
  80.         ;jr nz,mixchn_keep2
  81. ;если в from1 есть шум, то игнорируем from2, если его KEEPME <= чем у from1
  82.         ;bit MASKBIT_N,(iy+chn.masks)
  83.         ;jr nz,mixchn_keep1
  84. ;если в from2 дырка, то берём from1
  85.         bit MASKBIT_HOLE,(ix+chn.masks)
  86.         ret nz;jr nz,mixchn_keep1_ok
  87. ;если в from1 дырка, то берём from2
  88.         bit MASKBIT_HOLE,(iy+chn.masks)
  89.         jr nz,mixchn_keep2_ok
  90. ;берём самый громкий по тональнику
  91. ;TODO низкие ноты не считать громкими
  92.         ld a,(ix+chn.volume)
  93.          bit MASKBIT_E,(ix+chn.masks)
  94.          jr z,$+4
  95.          ld a,12 ;E играет на уровне 11, C на уровне 13, T-E играет громко!!! TODO
  96.         add a,(ix+chn.keepme)
  97.         add a,0x80
  98.         ld e,a
  99.         ld a,(iy+chn.volume)
  100.          bit MASKBIT_E,(iy+chn.masks)
  101.          jr z,$+4
  102.          ld a,12 ;E играет на уровне 11, C на уровне 13, T-E играет громко!!! TODO
  103.         add a,(iy+chn.keepme)
  104.         add a,0x80
  105.         cp e
  106.         jr c,mixchn_keep2_ok
  107. mixchn_keep1
  108.         ;ld a,(iy+chn.keepme)
  109.         ;cp (ix+chn.keepme)
  110.         ;ret nc ;при равенстве keepme оставляем from1
  111.         ;jr c,mixchn_keep2_ok
  112.         bit MASKBIT_OUTERENV,(ix+chn.masks)
  113.         jr nz,mixchn_keep2outerenv
  114.         ret
  115. mixchn_keep2
  116.         ;ld a,(ix+chn.keepme)
  117.         ;cp (iy+chn.keepme)
  118.         ;jr c,mixchn_keep1 ;при равенстве keepme оставляем from2
  119.         bit MASKBIT_OUTERENV,(ix+chn.masks)
  120.         jr nz,mixchn_keep1outerenv
  121. mixchn_keep2_ok
  122.         push ix
  123.         pop hl
  124.         push iy
  125.         pop de
  126.         ld bc,chn.note_in;chn
  127.         ldir
  128.         ret
  129. mixchn_keep1outerenv
  130.         ld a,(ix+chn.envfrq)
  131.         ld (iy+chn.envfrq),a
  132.         ld a,(ix+chn.envfrq+1)
  133.         ld (iy+chn.envfrq+1),a
  134.         ret
  135. mixchn_keep2outerenv
  136.         push ix
  137.         pop hl
  138.         push iy
  139.         pop de
  140.         ld bc,chn.note_in;chn
  141.         ldir
  142.         ld a,(iy+chn.envfrq)
  143.         ld (ix+chn.envfrq),a
  144.         ld a,(iy+chn.envfrq+1)
  145.         ld (ix+chn.envfrq+1),a
  146.         ret
  147.  
  148. ;надо в дырке такое поведение:
  149. ;       ||
  150. ;      |||        
  151. ;|||||||||____
  152. ;т.е. в дырке ставим громкость 0 (а не маску !T!N)
  153. rendchip
  154. ;ix=fromA
  155. ;hl=fromB
  156. ;de=fromC
  157. ;iy=chip
  158.         push de ;fromC
  159.         push hl ;fromB
  160.         ld bc,0x00ff ;b=ретриггеры A,B,C ;c=masks: все выключены
  161.         ld d,b ;текущий приоритет шума
  162.         ld e,b ;текущий приоритет огибающей
  163.         ld h,(iy+chip.envtype) ;бывший тип огибающей
  164.         res retrigenvbit,h
  165.         ld l,h
  166.  
  167.         xor a
  168.         bit MASKBIT_HOLE,(ix+chn.masks)
  169.         jr nz,rendchip_Anoenv
  170.         ld a,(ix+chn.volume)
  171.         cp 16
  172.         jr c,$+7
  173.          rla
  174.          sbc a,a
  175.          cpl
  176.          and 15
  177.         bit MASKBIT_E,(ix+chn.masks)
  178.         jr z,rendchip_Anoenv
  179.         ld e,(ix+chn.keepme) ;текущий приоритет огибающей
  180.         ld a,(ix+chn.envfrq)
  181.         ld (iy+chip.envfrq),a
  182.         ld a,(ix+chn.envfrq+1)
  183.         ld (iy+chip.envfrq+1),a
  184.         ld l,(ix+chn.envtype) ;текущий тип огибающей
  185.         ld a,16
  186. rendchip_Anoenv
  187.         ld (iy+chip.Avolume),a
  188.         bit MASKBIT_T,(ix+chn.masks)
  189.         jr z,rendchip_Anotone
  190.         dec c ;res 0,c
  191.         ld a,(ix+chn.tonefrq+1)
  192.         cp 4096/256
  193.         jr c,$+4
  194.          ld a,-1 ;overflow
  195.         ld (iy+chip.Atonefrq+1),a
  196.         jr nc,$+5 ;overflow
  197.          ld a,(ix+chn.tonefrq)
  198.         ld (iy+chip.Atonefrq),a
  199.         bit MASKBIT_RETRIGTONE,(ix+chn.masks)
  200.         jr z,$+3
  201.         inc b ;set 0,b сумма ретриггеров
  202. rendchip_Anotone
  203.         bit MASKBIT_N,(ix+chn.masks)
  204.         jr z,rendchip_Anonoise
  205.         res 3,c
  206.         ld d,(ix+chn.keepme) ;текущий приоритет шума
  207.         ld a,(ix+chn.noisefrq)
  208.         cp 32
  209.         jr c,$+5;7
  210.          rla
  211.          sbc a,a
  212.          cpl
  213.          ;and 31
  214.         ld (iy+chip.noisefrq),a
  215. rendchip_Anonoise
  216.  
  217.         pop ix ;fromB
  218.         xor a
  219.         bit MASKBIT_HOLE,(ix+chn.masks)
  220.         jr nz,rendchip_Bnoenv
  221.         ld a,(ix+chn.volume)
  222.         cp 16
  223.         jr c,$+7
  224.          rla
  225.          sbc a,a
  226.          cpl
  227.          and 15
  228.         bit MASKBIT_E,(ix+chn.masks)
  229.         jr z,rendchip_Bnoenv
  230.         ld a,(ix+chn.keepme)
  231.         cp e ;текущий приоритет огибающей
  232.         jr c,rendchip_Buseenv
  233.         ld e,a
  234.         ld a,(ix+chn.envfrq)
  235.         ld (iy+chip.envfrq),a
  236.         ld a,(ix+chn.envfrq+1)
  237.         ld (iy+chip.envfrq+1),a
  238.         ld l,(ix+chn.envtype) ;текущий тип огибающей
  239. rendchip_Buseenv
  240.         ld a,16
  241. rendchip_Bnoenv
  242.         ld (iy+chip.Bvolume),a
  243.         bit MASKBIT_T,(ix+chn.masks)
  244.         jr z,rendchip_Bnotone
  245.         res 1,c
  246.         ld a,(ix+chn.tonefrq+1)
  247.         cp 4096/256
  248.         jr c,$+4
  249.          ld a,-1 ;overflow
  250.         ld (iy+chip.Btonefrq+1),a
  251.         jr nc,$+5 ;overflow
  252.          ld a,(ix+chn.tonefrq)
  253.         ld (iy+chip.Btonefrq),a
  254.         bit MASKBIT_RETRIGTONE,(ix+chn.masks)
  255.         jr z,$+4
  256.          set 1,b ;сумма ретриггеров
  257. rendchip_Bnotone
  258.         bit MASKBIT_N,(ix+chn.masks)
  259.         jr z,rendchip_Bnonoise
  260.         res 4,c
  261.         ld a,(ix+chn.keepme)
  262.         cp d ;текущий приоритет шума
  263.         jr c,rendchip_Bnonoise
  264.         ld d,a
  265.         ld a,(ix+chn.noisefrq)
  266.         cp 32
  267.         jr c,$+5;7
  268.          rla
  269.          sbc a,a
  270.          cpl
  271.          ;and 31
  272.         ld (iy+chip.noisefrq),a
  273. rendchip_Bnonoise
  274.        
  275.         pop ix ;fromC
  276.         xor a
  277.         bit MASKBIT_HOLE,(ix+chn.masks)
  278.         jr nz,rendchip_Cnoenv
  279.         ld a,(ix+chn.volume)
  280.         cp 16
  281.         jr c,$+7
  282.          rla
  283.          sbc a,a
  284.          cpl
  285.          and 15
  286.         bit MASKBIT_E,(ix+chn.masks)
  287.         jr z,rendchip_Cnoenv
  288.         ld a,(ix+chn.keepme)
  289.         cp e ;текущий приоритет огибающей
  290.         jr c,rendchip_Cuseenv
  291.         ;ld e,a
  292.         ld a,(ix+chn.envfrq)
  293.         ld (iy+chip.envfrq),a
  294.         ld a,(ix+chn.envfrq+1)
  295.         ld (iy+chip.envfrq+1),a
  296.         ld l,(ix+chn.envtype) ;текущий тип огибающей
  297. rendchip_Cuseenv
  298.         ld a,16
  299. rendchip_Cnoenv
  300.         ld (iy+chip.Cvolume),a
  301.         bit MASKBIT_T,(ix+chn.masks)
  302.         jr z,rendchip_Cnotone
  303.         res 2,c
  304.         ld a,(ix+chn.tonefrq+1)
  305.         cp 4096/256
  306.         jr c,$+4
  307.          ld a,-1 ;overflow
  308.         ld (iy+chip.Ctonefrq+1),a
  309.         jr nc,$+5 ;overflow
  310.          ld a,(ix+chn.tonefrq)
  311.         ld (iy+chip.Ctonefrq),a
  312.         bit MASKBIT_RETRIGTONE,(ix+chn.masks)
  313.         jr z,$+4
  314.          set 2,b ;сумма ретриггеров
  315. rendchip_Cnotone
  316.         bit MASKBIT_N,(ix+chn.masks)
  317.         jr z,rendchip_Cnonoise
  318.         res 5,c
  319.         ld a,(ix+chn.keepme)
  320.         cp d ;текущий приоритет шума
  321.         jr c,rendchip_Cnonoise
  322.         ;ld d,a
  323.         ld a,(ix+chn.noisefrq)
  324.         cp 32
  325.         jr c,$+5;7
  326.          rla
  327.          sbc a,a
  328.          cpl
  329.          ;and 31
  330.         ld (iy+chip.noisefrq),a
  331. rendchip_Cnonoise
  332.  
  333.         ld (iy+chip.retriggers),b
  334.         ld (iy+chip.masks),c
  335.         ld a,l
  336.         cp h ;несовпадение в том числе при retrigenvbit (в h он сброшен)
  337.         jr z,$+4
  338.          set retrigenvbit,a
  339.         ld (iy+chip.envtype),a ;текущий тип огибающей
  340.         ret
  341.  
  342. outchip
  343. ;hl=chip (байт флагов ретриггера (ABC) + 13 байт данных AY)
  344.         xor a
  345.         LD C,0xfd
  346.         LD E,0xBF
  347.         bit 0,(hl)
  348.         jr z,outchip_noretrigA
  349.         ld d,0
  350.         ld b,0xff
  351.         out (c),d
  352.         ld b,e
  353.         out (c),a
  354.         inc d
  355.         ld b,0xff
  356.         out (c),d
  357.         ld b,e
  358.         out (c),a
  359. outchip_noretrigA
  360.         bit 1,(hl)
  361.         jr z,outchip_noretrigB
  362.         ld d,2
  363.         ld b,0xff
  364.         out (c),d
  365.         ld b,e
  366.         out (c),a
  367.         inc d
  368.         ld b,0xff
  369.         out (c),d
  370.         ld b,e
  371.         out (c),a
  372. outchip_noretrigB
  373.         bit 2,(hl)
  374.         jr z,outchip_noretrigC
  375.         ld d,4
  376.         ld b,0xff
  377.         out (c),d
  378.         ld b,e
  379.         out (c),a
  380.         inc d
  381.         ld b,0xff
  382.         out (c),d
  383.         ld b,e
  384.         out (c),a
  385. outchip_noretrigC
  386.         inc hl
  387.         ;xor a
  388.         ld d,0xff
  389.        dup 12
  390.         ld b,d;0xff
  391.         OUT (C),a
  392.         LD B,E
  393.         OUTI
  394.         inc a
  395.        edup
  396.         ld b,d;0xff
  397.         OUT (C),a
  398.         LD B,E
  399.         OUTI
  400.         bit retrigenvbit,(hl)
  401.         ret z ;no env retrigger
  402.         inc a
  403.         ld b,d;0xff
  404.         OUT (C),a
  405.         LD B,E
  406.         OUTI
  407.         ret
  408.  
  409. setchip1
  410.         ld a,0xff
  411.         jr setchip_a
  412. setchip0
  413.         ld a,0xfe
  414. setchip_a
  415.         ld bc,0xfffd
  416.         out (c),a
  417.         ret
  418.        
  419. ;Sample:
  420. ;256 masks (T,N,E,hole,outerenv,retrigtone, semitoneshiftpresent,tonefrqshiftpresent), одна из комбинаций означает loop (например, -1)
  421. noisefrqpresent=1
  422. envtypepresent=2
  423. semitoneshiftpresent=6
  424. tonefrqshiftpresent=7
  425. ;+-96 semitone shift (в потоке при наличии semitoneshiftpresent)
  426. ;+-96 env semitone shift (fair tone ratio guaranteed for 1:1, 3:4, 1:2, 1:4, 3:1, 5:2, 2:1, 3:2 + 4:1) (в потоке при наличии E)
  427. ;8*2 envtype + retrigenv (в потоке при наличии E)
  428. ;16 volume (в потоке при отсутствии E)
  429. ;+-4095 tonefrq shift (в потоке при наличии tonefrqshiftpresent)
  430. ;32 noisefrq (в потоке при наличии N)
  431. ;>1 >256 loop addrshift
  432.  
  433. playsample
  434.         ld l,(ix+chn.smpcuraddr)
  435.         ld h,(ix+chn.smpcuraddr+1)
  436. ;playsample_go
  437. ;ix=chn
  438. ;в любом случае полностью определяет текущие значения полей chn:
  439. ;masks   BYTE ;T,N,E,hole,outerenv,retrigtone, semitoneshiftpresent,tonefrqshiftpresent (должен быть первым байтом строки в потоке)
  440. ;envtype BYTE (в потоке при наличии E, значения 8..15 (15 как 4, 9 как 1) + retrigenv) ;или volume  BYTE ;volume = 0..15 (в потоке при отсутствии E)
  441. ;noisefrq BYTE ;noise = 0..31 (в потоке при наличии N)
  442.     ;keepme  BYTE ;priority for keep on top (bigger is more priority)
  443.     ;envfrq  WORD
  444.     ;tonefrq WORD
  445.         ld b,(hl) ;masks
  446.         inc hl
  447.         ld (ix+chn.masks),b ;masks   BYTE ;T,N,E,hole,outerenv,retrigtone, semitoneshiftpresent,tonefrqshiftpresent (должен быть первым байтом строки в потоке)
  448.         ld a,(ix+chn.note_in)
  449.  
  450.         ;bit semitoneshiftpresent,b
  451.         ;jr z,playsample_nosemitoneshift
  452.         add a,(hl)
  453.         inc hl
  454.         jp po,playsample_nosemitoneshift ;no signed overflow
  455.         rla
  456.         sbc a,a ;a=0 for negative overflow, a=255 for positive overflow
  457.         xor 0x80 ;a=-128 for negative overflow, a=127 for positive overflow
  458. playsample_nosemitoneshift
  459.  
  460.         bit envtypepresent,b
  461.         jr z,playsample_noenvsemitoneshift
  462.         add a,(hl) ;envsemitoneshift
  463.         ld e,a
  464.         ld d,tfrq/256
  465. ;cout env frq (use frq table)
  466.         ld a,(de)
  467.         ld c,a
  468.         inc d
  469.         ld a,(de)
  470.         ;ld d,a
  471.         ld (ix+chn.envfrq),c
  472.         ld (ix+chn.envfrq+1),a;d
  473. ;count tone frq (TODO use ratio)
  474. ;временная затычка - частота тона по частотной таблице без envsemitoneshift
  475.         ld a,e
  476.         sub (hl)
  477.         ld e,a
  478.         ld a,(de)
  479.         ld c,a
  480.         dec d
  481.         ld a,(de)
  482.         ld e,a
  483.         ld d,c
  484.         ;ld a,(hl) ;envsemitoneshift
  485.  
  486.         inc hl
  487.         ld a,(hl)
  488.         inc hl
  489.         ld (ix+chn.envtype),a ;envtype BYTE (в потоке при наличии E, значения 8..15 (15 как 4, 9 как 1) + retrigenvbit) ;тип огибающей без E не используется
  490.         jr playsample_noenvsemitoneshiftq
  491. playsample_noenvsemitoneshift
  492. ;count tone frq (use frq table)
  493.         ld e,a
  494.         ld d,tfrq/256
  495.         ld a,(de)
  496.         ld c,a
  497.         inc d
  498.         ld a,(de)
  499.         ld d,a
  500.         ld e,c ;de=tonefrq
  501.        
  502.          inc hl ;skip envsemitoneshift
  503.         ld a,(hl)
  504.         inc hl
  505.          add a,(ix+chn.volume_in)
  506.         ld (ix+chn.volume),a ;volume  BYTE ;volume = 0..15 ;громкость при E не используется
  507. playsample_noenvsemitoneshiftq
  508.  
  509.         ;bit tonefrqshiftpresent,b
  510.         ;jr z,playsample_notonefrqshift
  511.         ld a,(hl)
  512.         add a,e
  513.         ld e,a
  514.         inc hl
  515.         ld a,(hl)
  516.         adc a,d
  517.         ld d,a ;correct tone frq
  518.         inc hl
  519. ;playsample_notonefrqshift
  520.        
  521.         ;bit noisefrqpresent,b
  522.         ;jr z,playsample_nonoisefrq
  523.         ld a,(hl)
  524.         inc hl
  525.         ld (ix+chn.noisefrq),a ;noisefrq BYTE ;noise = 0..31 (в потоке при наличии N) ;noisefrq без N не используется
  526. ;playsample_nonoisefrq
  527.         ld a,(ix+chn.keepme_in)
  528.         ld (ix+chn.keepme),a ;keepme  BYTE ;priority for keep on top (bigger is more priority)
  529.  
  530. ;out: hl=next line in sample
  531.         ld a,(hl)
  532.         inc a
  533.         jr nz,playsample_noloop
  534.         inc hl
  535.         ld c,(hl)
  536.         inc hl
  537.         ld b,(hl)
  538.         add hl,bc
  539. playsample_noloop
  540.         ld (ix+chn.smpcuraddr),l
  541.         ld (ix+chn.smpcuraddr+1),h
  542.  
  543. ;накапливать глисс и прибавить его к tonefrq (в будущем считать глисс и пр. параметры от времени?)
  544.         ld a,(ix+chn.curgliss)
  545.         add a,(ix+chn.glissspeed_in)
  546.         ld (ix+chn.curgliss),a
  547.         ld l,a
  548.         ld a,(ix+chn.curgliss+1)
  549.         adc a,(ix+chn.glissspeed_in+1)
  550.         ld (ix+chn.curgliss+1),a
  551.         ld h,a
  552.         sra h
  553.         rr l
  554.         sra h
  555.         rr l
  556.         sra h
  557.         rr l ;+-12.3
  558.         add hl,de
  559.         ld (ix+chn.tonefrq),l
  560.         ld (ix+chn.tonefrq+1),h
  561.         ret
  562.  
  563. shutay
  564.         call setchip0
  565.         call shut1ay
  566.         call setchip1
  567. shut1ay
  568.         ld de,0x0e00
  569. shutay0
  570.         dec d
  571.         ld bc,0xfffd
  572.         out (c),d
  573.         ld b,0xbf
  574.         out (c),e
  575.         jr nz,shutay0
  576.         ret
  577.