?login_element?

Subversion Repositories NedoOS

Rev

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

  1. WAVEHEADERBUFFERSIZE = MOONRAMWAVETABLESIZE*MOONWAVEHEADERSIZE
  2.  
  3. opl4writemusiconlyfm1
  4. ;skips writes to control registers
  5. ;e = register
  6. ;d = value
  7.         ld a,e
  8.         cp 0x20
  9.         jp nc,opl4writefm1
  10.         cp 0x08
  11.         ret nz
  12.         jp opl4writefm1
  13.  
  14. opl4writemusiconlyfm2
  15. ;skips writes to control registers
  16. ;e = register
  17. ;d = value
  18.         ld a,e
  19.         cp 5
  20.         ret z
  21.         jp opl4writefm2
  22.  
  23. opl4writewavemusiconly
  24. ;skips writes to control registers and handles ROM dumps
  25. ;e = register
  26. ;d = value
  27.         ld a,e
  28.         cp 0x38
  29.         jp nc,opl4writewave
  30.         cp 0x08
  31.         ret c
  32.         cp 0x20
  33.         jr c,writewavetableindexlo
  34. ;force wave table index into 384--511 range if ROM data is loaded
  35. isromloaded=$+1
  36.         ld a,0
  37.         or d
  38.         ld d,a
  39.         jp opl4writewave
  40. writewavetableindexlo
  41.         ld a,(isromloaded)
  42.         rrca
  43.         or d
  44.         ld d,a
  45.         call opl4writewave
  46. ;wait for the header to load
  47.         in a,(MOON_STAT)
  48.         and 3
  49.         jr nz,$-4
  50.         ret
  51.  
  52. vgmopl4init
  53.         xor a
  54.         ld (isromloaded),a
  55.         ld hl,MOONSOUNDROMSIZE%65536
  56.         ld (opl4loadramdatablockheader.romsize0),hl
  57.         ld a,MOONSOUNDROMSIZE/65536
  58.         ld (opl4loadramdatablockheader.romsize2),a
  59.         jp opl4init
  60.  
  61. sub24x16
  62. ;dhl = minuend
  63. ;bc = subtrahend
  64. ;out: cf=1 if negative result, zf=1 if zero
  65.         sub hl,bc
  66.         jr c,.carry
  67.         ret nz
  68.         ld a,d
  69.         or a
  70.         ret
  71. .carry
  72.         ld a,d
  73.         sbc a,0
  74.         ld d,a
  75.         ret nz
  76.         ld a,l
  77.         or h
  78.         ret
  79.  
  80. opl4loadromdatablockheader
  81. ;dhl = header+data size
  82. ;out: zf=1 if no data to load, dhl = data block size, dhl' = start address
  83.         exx
  84.         call memorystreamread4 ;adbc = total rom size
  85.         ld (opl4loadramdatablockheader.romsize0),bc
  86.         ld a,d
  87.         add 0x20 ;place in RAM
  88.         ld (opl4loadramdatablockheader.romsize2),a
  89.         call memorystreamread4 ;adbc = start address
  90.         ld hl,bc
  91.         set 5,d ;place in RAM
  92.         exx
  93.         ld bc,8
  94.         jr sub24x16
  95.  
  96. opl4loadramdatablockheader
  97. ;dhl = header+data size
  98. ;out: zf=1 if no data to load, dhl = data block size, dhl' = start address
  99.         exx
  100.         call memorystreamread4 ;adbc = total ram size
  101.         call memorystreamread4 ;adbc = start address
  102. .romsize0=$+1
  103.         ld hl,0
  104.         add hl,bc
  105. .romsize2=$+1
  106.         ld a,0
  107.         adc a,d
  108.         and 0x3f
  109.         ld d,a
  110.         exx
  111.         ld bc,8
  112.         jr sub24x16
  113.  
  114. setup24bitscounterloop
  115. ;dhl = counter
  116. ;out: b = inner loop counter, de = outer loop counter
  117.         ld e,l
  118.         ld bc,1
  119.         sub hl,bc
  120.         jr nc,$+3
  121.         dec d
  122.         ld b,e
  123.         ld e,h
  124.         inc de
  125.         ret
  126.  
  127. opl4loadsample
  128. ;dhl = sample start address
  129. ;dhl' = sample size
  130.         ld b,d
  131.         ld de,0x0305
  132.         call opl4writefm2
  133.         ld d,b
  134.         call opl4setmemoryaddress
  135.         ld de,0x1102
  136.         call opl4writewave
  137.         opl4_wait
  138.         ld a,6
  139.         out (MOON_WREG),a
  140.         exx
  141.         call setup24bitscounterloop
  142.         ld hl,(memorystreamcurrentaddr)
  143. .loop
  144.         memory_stream_read_byte c
  145.         opl4_wait
  146.         ld a,c
  147.         out (MOON_WDAT),a
  148.         djnz .loop
  149.         dec de
  150.         ld a,e
  151.         or d
  152.         jr nz,.loop
  153.         ld (memorystreamcurrentaddr),hl
  154.         ld de,0x1002
  155.         jp opl4writewave
  156.  
  157. opl4loadramdatablock
  158. ;dhl = data+header size
  159.         call opl4loadramdatablockheader
  160.         ret z
  161.         exx
  162.         jr opl4loadsample
  163.  
  164. opl4loadromdatablock
  165. ;dhl = data+header size
  166.         call opl4loadromdatablockheader
  167.         ret z
  168.         exx
  169.         push de
  170.         call opl4loadsample
  171.         pop af
  172. ;check if the address is within the first 64K of RAM
  173.         cp 0x21
  174.         ret nc
  175. ;patch all 128 headers that LSI can read from RAM
  176.         ld a,1
  177.         ld (isromloaded),a
  178.         ld hl,MOONSOUNDROMSIZE%65536
  179.         ld d,MOONSOUNDROMSIZE/65536
  180.         ld bc,WAVEHEADERBUFFERSIZE
  181.         ld ix,waveheaderbuffer
  182.         call opl4readmemory
  183.         ld hl,waveheaderbuffer
  184.         ld de,MOONWAVEHEADERSIZE
  185.         ld b,MOONRAMWAVETABLESIZE
  186. .loop
  187.         set 5,(hl) ;set base address in RAM area
  188.         add hl,de
  189.         djnz .loop
  190.         ld hl,MOONSOUNDROMSIZE%65536
  191.         ld d,MOONSOUNDROMSIZE/65536
  192.         ld bc,WAVEHEADERBUFFERSIZE
  193.         ld ix,waveheaderbuffer
  194.         jp opl4writememory
  195.  
  196. opl4inittimer60hz
  197.         ld de,0x2f02
  198.         call opl4writefm1
  199.         ld de,0x2104
  200.         jp opl4writefm1
  201.  
  202. opl4waittimer60hz
  203.         in a,(MOON_STAT)
  204.         rla
  205.         jr nc,opl4waittimer60hz
  206.         ld de,0x8104
  207.         jp opl4writefm1
  208.