Subversion Repositories NedoOS

Rev

Rev 2423 | 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 playerwindowui
  10.  
  11. isfilesupported
  12. ;cde = file extension
  13. ;out: zf=1 if this player can handle the file and the sound hardware is available, zf=0 otherwise
  14.         ld a,'m'
  15.         cp c
  16.         ret nz
  17.         ld hl,'id'
  18.         sbc hl,de
  19.         ret
  20.  
  21. cleanupvars
  22. ;out: zf=0 so this function can be used as error handler
  23.         or 255
  24.         jp initprogress
  25.  
  26. playerinit
  27. ;ix = GPSETTINGS
  28. ;a = player page
  29. ;out: zf=1 if init is successful, hl=init message
  30.         ld (.settingsaddr),ix
  31.         ld a,(ix+GPSETTINGS.moonsoundstatus)
  32.         cp 2
  33.         ld hl,nodevicestr
  34.         ret nz
  35. ;init additional tables
  36.         OS_NEWPAGE
  37.         or a
  38.         ld hl,outofmemorystr
  39.         ret nz
  40.         ld a,e
  41.         push af
  42.         SETPGC000
  43. ;move additional tables to its own page
  44.         ld hl,opl4tables
  45.         ld de,0xc000
  46.         ld bc,opl4tables_end-opl4tables
  47.         ldir
  48. ;start initing vars after the table was copied
  49.         pop af
  50.         ld (opl4tablespage),a
  51. .settingsaddr=$+2
  52.         ld ix,0
  53.         call ismidienabled
  54.         ld hl,playerdisabledstr
  55.         ret nz
  56.         call cleanupvars
  57.         xor a
  58.         ld hl,initokstr
  59.         ret
  60.  
  61. ismidienabled
  62. ;output: zf=1 if this player is enabled, zf=0 otherwise
  63.         ld de,(ix+GPSETTINGS.mididevice)
  64.         ld a,d
  65.         or e
  66.         ret z
  67.         ld a,(de)
  68.         cp '0'
  69.         ret z
  70.         cp '1'
  71.         ret
  72.        
  73. playerdeinit
  74. opl4tablespage=$+1
  75.         ld e,0
  76.         OS_DELPAGE
  77.         ret    
  78.        
  79. musicload
  80. ;cde = file extension
  81. ;hl = input file name
  82. ;out: hl = device mask, zf=1 if the file is ready for playing, zf=0 otherwise
  83.         call midloadfile
  84.         ld hl,DEVICE_MOONSOUND_MASK
  85.         ret z
  86.         call memorystreamfree
  87.         jp cleanupvars ;sets zf=0
  88.  
  89. musicunload
  90.         call cleanupvars
  91.         jp midunload
  92.  
  93. musicplay
  94. ;out: zf=0 if still playing, zf=1 otherwise
  95.         jp midplay
  96.        
  97.        
  98. MAX_NR_OF_TRACKS = 64
  99. NR_OF_MIDI_CHANNELS = 16
  100. NR_OF_WAVE_CHANNELS = 24
  101.  
  102.  
  103. TITLELENGTH = 64
  104. MEMORYSTREAMMAXPAGES = 210
  105. MEMORYSTREAMERRORMASK = 255
  106.  
  107. DRUM_CHANNEL = 9
  108.  
  109. DEFAULT_QNOTE_DURATION_MCS = 500000
  110. VSYNC_MCS = 1000000/VSYNC_FREQ
  111.  
  112.  
  113.  
  114.  
  115.  
  116.        
  117.         include "../_sdk/file.asm"
  118.         include "common/opl4.asm"
  119.         include "moonmid/midi_def.asm"
  120.         include "moonmid/opl.asm"
  121.         include "moonmid/moonsound.asm"
  122.        
  123.        
  124.         include "common/memorystream.asm"
  125.         include "common/muldiv.asm"
  126.         include "moonmid/muldiv.asm"
  127.         include "moonmid/mnmid.asm"
  128.         include "progress.asm" 
  129.        
  130.        
  131.        
  132.        
  133.        
  134.        
  135. midloadfile
  136. ;hl = input file name
  137. ;out: zf=1 if loaded, zf=0 otherwise
  138.         ex de,hl
  139.         call memorystreamloadfile
  140.         ret nz
  141.         call memorystreamstart
  142.  
  143. ;init midi file
  144.         ld b,midheadersigsize
  145.         ld de,midheadersig
  146.         call midchecksignature
  147.         ret nz
  148.  
  149.         memory_stream_read_2 c,a
  150. /*file type*/
  151.         ;c a - midi file  format ; 0x0000,0x0001,0x0002
  152.         cp 3
  153.         ret nc
  154.         ld (g_header.file_format),a
  155.  
  156. /*tracks count*/
  157.         memory_stream_read_2 c,a
  158.         ld (g_header.number_of_tracks),a
  159.  
  160.         add a,-MAX_NR_OF_TRACKS-1
  161.         sbc a,a
  162.         ret nz
  163.  
  164.         memory_stream_read_2 b,c
  165.         ld a,c
  166.         ld (g_header.ticks_per_qnote),a
  167.         ld a,b
  168.         ld (g_header.ticks_per_qnote+1),a
  169.         ld de,VSYNC_MCS
  170.         call uintmul16
  171.         add hl,hl : rl de
  172.         add hl,hl : rl de
  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. playerwindowui
  217.         PROGRESSIVEPLAYERWINDOWTEMPLATE 0,musicprogress+1
  218.  
  219. tempmemorystart = $
  220. opl4tables
  221.         DISP 0xc000
  222.         include "moonmid/yrw801imap_robo.asm"
  223.         ENT    
  224. opl4tables_end
  225. end
  226.  
  227.         savebin "moonmid.bin",begin,end-begin
  228.  
  229.  
  230.                                         org tempmemorystart
  231. newtareastart                                  
  232. free_voice:             ds 2
  233. oldest_voice:           ds 2
  234. g_ticks_per_update  ds 4,0
  235. g_MIDI_counter          ds 4,0
  236. g_volume_boost          ds 1,16
  237. n_on_voices         ds 1,0  
  238. n_on_data           ds 8,0   ; dw wave_data, dw voice_data
  239. n_on_data_ptr       ds 2
  240. g_header                        MIDI_HEADER
  241.                                         align 256
  242. midi_ch_table:          ds NR_OF_MIDI_CHANNELS*2,0
  243. newtareaend
  244.  
  245.  
  246.  
  247.  
  248. ;       display "moonmid load = ",/d,end-begin," bytes"
  249. ;       display "moonmid work = ",/d,newtareaend-begin," bytes"
  250. ;       display "sample table = ",/d,opl4tables_end-opl4tables," bytes"
  251.