Subversion Repositories NedoOS

Rev

Rev 2376 | Blame | Compare with Previous | Last modification | View Log | Download

  1. ;Define OPN_ENABLE_FM to enable FM DACs
  2.  
  3. OPN_REG = 0xfffd
  4. OPN_DAT = 0xbffd
  5.  
  6.         macro opn_write_fm_reg chip_n
  7. ;e = register
  8. ;d = value
  9.         ld bc,OPN_REG
  10.         ifdef OPN_ENABLE_FM
  11.         ld a,chip_n+%11111000
  12.         else
  13.         ld a,chip_n+%11111100
  14.         endif
  15.         out (c),a
  16.         nop
  17.         nop
  18.         in f,(c)
  19.         jp m,$-4
  20.         out (c),e
  21.         nop
  22.         nop
  23.         in f,(c)
  24.         jp m,$-4
  25.         ld bc,OPN_DAT
  26.         out (c),d
  27.         endm
  28.  
  29. opnwriteall
  30. ;e = register
  31. ;d = value
  32.         call opnwritefm2
  33. opnwritefm1
  34. ;e = register
  35. ;d = value
  36.         opn_write_fm_reg 0
  37.         ret
  38.  
  39. opnwritefm2
  40. ;e = register
  41. ;d = value
  42.         opn_write_fm_reg 1
  43.         ret
  44.  
  45.         macro opn_write_regs incr,incd
  46. ;e = base register
  47. ;d = value
  48. ;l = count
  49. .loop   call opnwriteall
  50.         IF incr
  51.         inc e
  52.         ENDIF
  53.         IF incd
  54.         inc d
  55.         ENDIF
  56.         dec l
  57.         jr nz,.loop
  58.         endm
  59.  
  60. opninit
  61.         ld l,0x83
  62.         ld de,0x0030
  63.         opn_write_regs 1,0
  64. ;configure prescaler
  65.         ld de,0x002f
  66.         call opnwriteall
  67.         ld de,0x002d
  68.         jp opnwriteall
  69.  
  70. opnstoptimers
  71.         ld de,0x3027
  72.         call opnwriteall
  73.         ld de,0x0027
  74.         jp opnwriteall
  75.  
  76. opnmute
  77.         call opnstoptimers
  78. ;mute SSG
  79.         ld l,3
  80.         ld de,0x0008
  81.         opn_write_regs 1,0
  82.         ld l,14
  83.         ld de,0x0000
  84.         opn_write_regs 1,0
  85. ;max release rate
  86.         ld l,0x10
  87.         ld de,0x0f80
  88.         opn_write_regs 1,0
  89. ;min total level
  90.         ld l,0x10
  91.         ld de,0x7f40
  92.         opn_write_regs 1,0
  93. ;key off
  94.         ld l,3
  95.         ld de,0x0028
  96.         opn_write_regs 0,1
  97. ;default tfm state
  98.         ld bc,OPN_REG
  99.         ld a,%11111111
  100.         out (c),a
  101.         ret
  102.