Subversion Repositories NedoOS

Rev

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