Subversion Repositories NedoOS

Rev

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

  1. ; SMF player for ZXM-MoonSound (OPL4)
  2.  
  3.         DEVICE ZXSPECTRUM128
  4.         include "../_sdk/sys_h.asm"
  5.         include "playerdefs.asm"
  6.        
  7.         org PLAYERSTART
  8.  
  9. begin   PLAYERHEADER
  10. isfilesupported
  11. ;cde = file extension
  12. ;out: zf=1 if this player can handle the file and the sound hardware is available, zf=0 otherwise
  13.         call ismidfile
  14.         ret nz
  15.         ld hl,0
  16.         ld (MUSICTITLEADDR),hl
  17.         ld hl,musicprogress+1
  18.         ld (MUSICPROGRESSADDR),hl
  19.         jp initprogress
  20.        
  21. ismidfile
  22. ;cde = file extension
  23. ;out: zf=1 if .mod, zf=0 otherwise
  24.         ld a,'m'
  25.         cp c
  26.         ret nz
  27.         ld a,'i'
  28.         cp d
  29.         ret nz
  30.         ld a,'d'
  31.         cp e
  32.         ret
  33.        
  34. playerinit
  35. ;hl,ix = GPSETTINGS
  36. ;a = player page
  37. ;out: zf=1 if init is successful, hl=init message
  38.         ld (.settingsaddr),hl
  39.         ld a,(ix+GPSETTINGS.moonsoundstatus)
  40.         cp 2
  41.         ld hl,nodevicestr
  42.         ret nz
  43. ;init additional tables
  44.         OS_NEWPAGE
  45.         or a
  46.         ld hl,outofmemorystr
  47.         ret nz
  48.         ld a,e
  49.         push af
  50.         SETPGC000
  51. ;move additional tables to its own page
  52.         ld hl,opl4tables
  53.         ld de,0xc000
  54.         ld bc,opl4tables_end-opl4tables
  55.         ldir
  56. ;start initing vars after the table was copied
  57.         pop af
  58.         ld (opl4tablespage),a
  59. .settingsaddr=$+2
  60.         ld ix,0
  61.         call ismidienabled
  62.         ld hl,playerdisabledstr
  63.         ret nz
  64.         ld hl,initokstr
  65.         ret
  66.  
  67. ismidienabled
  68. ;output: zf=1 if this player is enabled, zf=0 otherwise
  69.         ld de,(ix+GPSETTINGS.mididevice)
  70.         ld a,d
  71.         or e
  72.         ret z
  73.         ld a,(de)
  74.         cp '0'
  75.         ret z
  76.         cp '1'
  77.         ret
  78.        
  79. playerdeinit
  80. opl4tablespage=$+1
  81.         ld e,0
  82.         OS_DELPAGE
  83.         ret    
  84.        
  85. musicload:     
  86.         call midloadfile
  87.         xor a
  88.         ld hl,DEVICE_MOONSOUND_MASK
  89.         ret
  90.  
  91. musicunload
  92.         jp midunload   
  93.        
  94. musicplay
  95. ;out: zf=0 if still playing, zf=1 otherwise
  96.         jp midplay
  97.        
  98.        
  99. MAX_NR_OF_TRACKS = 64
  100. NR_OF_MIDI_CHANNELS = 16
  101. NR_OF_WAVE_CHANNELS = 24
  102.  
  103.  
  104. TITLELENGTH = 64
  105. MEMORYSTREAMMAXPAGES = 210
  106. MEMORYSTREAMERRORMASK = 255
  107.  
  108. DRUM_CHANNEL = 9
  109.  
  110. DEFAULT_QNOTE_DURATION_MCS = 500000
  111. VSYNC_FREQ = 46 ;49 ;46
  112. VSYNC_MCS = 1000000/VSYNC_FREQ
  113.  
  114.  
  115.  
  116.  
  117.  
  118.        
  119.         include "../_sdk/file.asm"
  120.         include "common/opl4.asm"
  121.         include "moonmid/midi_def.asm"
  122.         include "moonmid/opl.asm"
  123.         include "moonmid/moonsound.asm"
  124.        
  125.        
  126.         include "common/memorystream.asm"
  127.         include "common/muldiv.asm"
  128.         include "moonmid/muldiv.asm"
  129.         include "moonmid/mnmid.asm"
  130.         include "progress.asm" 
  131.        
  132.        
  133.        
  134.        
  135.        
  136.        
  137. midloadfile
  138. ;hl = input file name
  139. ;out: zf=1 if loaded, zf=0 otherwise
  140.         ex de,hl
  141.         call memorystreamloadfile
  142.         ret nz
  143.         call memorystreamstart
  144.  
  145. ;init midi file
  146.         ld b,midheadersigsize
  147.         ld de,midheadersig
  148.         call midchecksignature
  149.         ret nz
  150.  
  151.         memory_stream_read_2 c,a
  152. /*file type*/
  153.         ;c a - midi file  format ; 0x0000,0x0001,0x0002
  154.         cp 3
  155.         ret nc
  156.         ld (g_header.file_format),a
  157.  
  158. /*tracks count*/
  159.         memory_stream_read_2 c,a
  160.         ld (g_header.number_of_tracks),a
  161.  
  162.         add a,-MAX_NR_OF_TRACKS-1
  163.         sbc a,a
  164.         ret nz
  165.  
  166.         memory_stream_read_2 b,c
  167.         ld a,c
  168.         ld (g_header.ticks_per_qnote),a
  169.         ld a,b
  170.         ld (g_header.ticks_per_qnote+1),a
  171.         ld de,VSYNC_MCS
  172.         call uintmul16
  173.         add hl,hl : rl de
  174.         add hl,hl : rl de
  175.         ld (g_header.ticksperqnoteXupdatelen+0),hl
  176.         ld (g_header.ticksperqnoteXupdatelen+2),de
  177.  
  178.         ld a,16
  179.         ld (g_volume_boost),a
  180.        
  181.         ld a,SNDRV_MIDI_MODE_GM
  182.         ld (g_header.midi_mode),a
  183.        
  184.         ld a,127
  185.         ld (g_header.gs_master_volume),a
  186.        
  187.         call midloadtracks
  188.         jp nz,memorystreamfree ;sets zf=0
  189.         call rewind
  190.        
  191.         call midsetprogressdelta
  192.         call rewind
  193.        
  194.         call set_refresh
  195. ;       call opl4_reset
  196.         call opl4init
  197.     jp generate_tables 
  198.        
  199. midunload
  200.         call opl4_reset
  201.         call opl4mute
  202.         jp memorystreamfree
  203. ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  204.         include "moonmid/pitch_table.asm"
  205.        
  206. playernamestr
  207.         db "MoonSound MIDI",0
  208. outofmemorystr
  209.         db "Out of memory!",0
  210. initokstr
  211.         db "OK\r\n",0
  212. nodevicestr
  213.         db "no device!\r\n",0
  214. playerdisabledstr
  215.         db "disabled!\r\n",0
  216.  
  217. tempmemorystart = $
  218. opl4tables
  219.         DISP 0xc000
  220.         include "moonmid/yrw801imap_robo.asm"
  221.         ENT    
  222. opl4tables_end
  223. end
  224.  
  225.         savebin "moonmid.bin",begin,end-begin
  226.  
  227.  
  228.                                         org tempmemorystart
  229. newtareastart                                  
  230. free_voice:             ds 2
  231. oldest_voice:           ds 2
  232. g_ticks_per_update  ds 4,0
  233. g_MIDI_counter          ds 4,0
  234. g_volume_boost          ds 1,16
  235. n_on_voices         ds 1,0  
  236. n_on_data           ds 8,0   ; dw wave_data, dw voice_data
  237. n_on_data_ptr       ds 2
  238. g_header                        MIDI_HEADER
  239.                                         align 256
  240. midi_ch_table:          ds NR_OF_MIDI_CHANNELS*2,0
  241. newtareaend
  242.  
  243.  
  244.  
  245.  
  246. ;       display "moonmid load = ",/d,end-begin," bytes"
  247. ;       display "moonmid work = ",/d,newtareaend-begin," bytes"
  248. ;       display "sample table = ",/d,opl4tables_end-opl4tables," bytes"