Subversion Repositories NedoOS

Rev

Rev 2423 | 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-byte 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.         pop hl
  161.         ld d,l : ld e,0x02
  162.         call opnawritefm2
  163.         ld d,h : ld e,0x03
  164.         call opnawritefm2
  165.         ld de,0xff04
  166.         call opnawritefm2
  167.         ld de,0xff05
  168.         call opnawritefm2
  169.         ld de,0xff0c
  170.         call opnawritefm2
  171.         ld de,0xff0d
  172.         call opnawritefm2
  173. ;start uploading the data
  174.         ld bc,OPNA2_DAT
  175.         ld hl,(memorystreamcurrentaddr)
  176.         exx
  177.         ld bc,OPNA2_REG
  178.         in f,(c)
  179.         jp m,$-2
  180.         ld a,0x08
  181.         out (c),a
  182. .uploadloop
  183.         in f,(c)
  184.         jp m,$-2
  185.         exx
  186.         memory_stream_read_byte a
  187.         out (c),a
  188.         exx
  189.         dec e
  190.         jr nz,.uploadloop
  191.         dec hl
  192.         ld a,h
  193.         or l
  194.         jr nz,.uploadloop
  195.         exx
  196.         ld (memorystreamcurrentaddr),hl
  197.         ld de,0x0100
  198.         call opnawritefm2
  199.         jp turnturboon
  200.  
  201. opnasettimer
  202. ;a = rate in hz
  203. ;output: zf=1 if timer is set, zf=0 otherwise
  204. ;TODO: why the timers are behaving as if master clock is 4Mhz?
  205.         cp 14
  206.         ret c
  207.         push af
  208.         call settimerstep
  209.         ld hl,opnawaittimer
  210.         ld (waittimercallback),hl
  211.         pop af
  212.         ld de,0x000f
  213.         ld hl,0x4240
  214.         exx
  215.         ld c,a
  216.         ld b,0
  217.         cp 56
  218.         jr c,.usetimerb
  219.         ld de,18
  220.         call uintmul16
  221.         exx
  222.         call uintdiv32
  223.         xor a
  224.         sub l
  225.         ld l,a
  226.         sbc a,h
  227.         sub l
  228. ;high 8 bits
  229.         ld d,l
  230.         rrca : rr d
  231.         rrca : rr d
  232.         ld e,0x24
  233.         call opnawritefm1
  234. ;low 2 bits
  235.         ld d,l
  236.         inc e
  237.         call opnawritefm1
  238.         ld de,0x1527
  239.         call opnawritefm1
  240.         xor a
  241.         ret
  242. .usetimerb
  243.         ld de,288
  244.         call uintmul16
  245.         exx
  246.         call uintdiv32
  247.         xor a
  248.         sub l
  249.         ld d,a
  250.         ld e,0x26
  251.         call opnawritefm1
  252.         ld de,0x2a27
  253.         call opnawritefm1
  254.         xor a
  255.         ret
  256.  
  257. opnawaittimer
  258.         ld bc,OPNA1_REG
  259.         in a,(c)
  260.         and 3
  261.         jr z,$-4
  262.         ld de,0x8010
  263.         jp opnawritefm2
  264.