Subversion Repositories NedoOS

Rev

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

  1. opnawritemusiconlyfm1
  2. ;e = register
  3. ;d = value
  4.         ld a,e
  5.         cp 0x30
  6.         jp nc,opnawritefm1
  7.         cp 0x0e
  8.         jp c,opnawritefm1
  9.         cp 0x22
  10.         jr c,.rhythm
  11.         jp z,opnawritefm1
  12. ;block timers but no need to block the prescaler since OPNA PC-98 sound cards
  13. ;behave the same as the RE2-2608 so VGMs can adjust it as they like
  14.         cp 0x28
  15.         jp nc,opnawritefm1
  16.         ret
  17. .rhythm cp 0x1e
  18.         ret nc
  19.         cp 0x12
  20.         ret z
  21.         cp 0x10
  22.         jp nz,opnawritefm1
  23.         call opnawritefm1
  24.         dec a
  25.         jr nz,$-1
  26.         ret
  27.  
  28. opnawritemusiconlyfm2
  29. ;e = register
  30. ;d = value
  31.         ld a,e
  32.         cp 0x0c
  33.         ret z
  34.         cp 0x0d
  35.         ret z
  36.         cp 0x06
  37.         jp nc,opnawritefm2
  38.         add a,a
  39.         add a,e
  40.         ld (opnafm2commandtable+1),a
  41. opnafm2commandtable
  42.         jr $
  43.         jp opnawritectrl1 ; control 1       (00)
  44.         jp opnawritectrl2 ; control 2       (01)
  45.         jp opnawritefm2   ; start addr low  (02)
  46.         jp opnawritefm2   ; start addr high (03)
  47.         jp opnawritefm2   ; stop addr low   (04)
  48.         jp opnawritefm2   ; stop addr high  (05)
  49.  
  50. opnawritectrl1
  51.         ld a,d
  52.         and %10110001
  53.         ld d,a
  54.         jp opnawritefm2
  55.  
  56. opnawritectrl2
  57.         ld a,d
  58.         and 0x03
  59.         call z,opnasetnoconversionhandlers
  60.         call nz,opnasetconversionhandlers
  61.         ld a,d
  62.         and %11000100
  63.         ld d,a
  64.         jp opnawritefm2
  65.  
  66. opnaconvertstartlo
  67.         ld a,d
  68.         ld (opnastartaddr),a
  69. opnawriteconvertedstartaddr
  70. opnastartaddr=$+1
  71.         ld hl,0
  72.         add hl,hl
  73.         add hl,hl
  74.         add hl,hl
  75.         ld d,l
  76.         ld e,0x02
  77.         call opnawritefm2
  78.         ld d,h
  79.         inc e
  80.         jp opnawritefm2
  81.  
  82. opnaconvertstarthi
  83.         ld a,d
  84.         ld (opnastartaddr+1),a
  85.         jr opnawriteconvertedstartaddr
  86.  
  87. opnaconvertstoplo
  88.         ld a,d
  89.         ld (opnastopaddr),a
  90. opnawriteconvertedstopaddr
  91. opnastopaddr=$+1
  92.         ld hl,0
  93.         add hl,hl
  94.         add hl,hl
  95.         add hl,hl
  96.         ld d,l
  97.         ld e,0x04
  98.         call opnawritefm2
  99.         ld d,h
  100.         inc e
  101.         jp opnawritefm2
  102.  
  103. opnaconvertstophi
  104.         ld a,d
  105.         ld (opnastopaddr+1),a
  106.         jr opnawriteconvertedstopaddr
  107.  
  108. vgmopnainit
  109.         call opnainit
  110.         jr opnasetnoconversionhandlers
  111.  
  112.         macro opna_set_adpcm_register_handler reg,handler
  113.         ld hl,handler
  114.         ld (opnafm2commandtable+3+reg*3),hl
  115.         endm
  116.  
  117. opnasetnoconversionhandlers
  118.         opna_set_adpcm_register_handler 2,opnawritefm2
  119.         opna_set_adpcm_register_handler 3,opnawritefm2
  120.         opna_set_adpcm_register_handler 4,opnawritefm2
  121.         opna_set_adpcm_register_handler 5,opnawritefm2
  122.         ret
  123.  
  124. opnasetconversionhandlers
  125.         opna_set_adpcm_register_handler 2,opnaconvertstartlo
  126.         opna_set_adpcm_register_handler 3,opnaconvertstarthi
  127.         opna_set_adpcm_register_handler 4,opnaconvertstoplo
  128.         opna_set_adpcm_register_handler 5,opnaconvertstophi
  129.         ret
  130.  
  131. opnaloaddatablock
  132. ;dhl = data+header size
  133.         push de
  134.         push hl
  135.         call turnturbooff
  136.         pop hl
  137.         pop de
  138. ;continue uploading at 3.5Mhz
  139.         exx
  140.         call memorystreamread4 ;adbc = total ram size
  141.         call memorystreamread4 ;adbc = start address
  142.         exx
  143.         ld bc,8
  144.         call sub24x16
  145.         jp z,turnturboon
  146.         call setup24bitscounterloop
  147.         ex de,hl
  148.         ld e,b
  149.         exx
  150. ;address in 4-bytes blocks for 1-bit RAM mode
  151.         srl d : rr bc
  152.         srl d : rr bc
  153.         push bc
  154.         ld de,0x0100
  155.         call opnawritefm2
  156.         ld de,0x6000
  157.         call opnawritefm2
  158.         ld de,0x0001
  159.         call opnawritefm2
  160.         ld de,0x1310
  161.         call opnawritefm2
  162.         ld de,0x8010
  163.         call opnawritefm2
  164.         pop hl
  165.         ld d,l : ld e,0x02
  166.         call opnawritefm2
  167.         ld d,h : ld e,0x03
  168.         call opnawritefm2
  169.         ld de,0xff04
  170.         call opnawritefm2
  171.         ld de,0xff05
  172.         call opnawritefm2
  173.         ld de,0xff0c
  174.         call opnawritefm2
  175.         ld de,0xff0d
  176.         call opnawritefm2
  177. ;start uploading the data
  178.         ld bc,OPNA2_DAT
  179.         ld hl,(memorystreamcurrentaddr)
  180.         exx
  181.         ld bc,OPNA2_REG
  182.         in f,(c)
  183.         jp m,$-2
  184.         ld a,0x08
  185.         out (c),a
  186. .uploadloop
  187.         in f,(c)
  188.         jp m,$-2
  189.         exx
  190.         memory_stream_read_byte a
  191.         out (c),a
  192.         exx
  193.         dec e
  194.         jr nz,.uploadloop
  195.         dec hl
  196.         ld a,h
  197.         or l
  198.         jr nz,.uploadloop
  199.         exx
  200.         ld (memorystreamcurrentaddr),hl
  201.         ld de,0x8010
  202.         call opnawritefm2
  203.         ld de,0x0100
  204.         call opnawritefm2
  205.         jp turnturboon
  206.