Subversion Repositories NedoOS

Rev

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

  1. ; MoonBlaster Wave modules player
  2.  
  3.         DEVICE ZXSPECTRUM128
  4.         include "../_sdk/sys_h.asm"
  5.         include "playerdefs.asm"
  6.  
  7. MUSICTITLE = 0x80dc
  8.  
  9.         org PLAYERSTART
  10.  
  11. begin   PLAYERHEADER
  12.  
  13. isfilesupported
  14. ;cde = file extension
  15. ;out: zf=1 if this player can handle the file and the sound hardware is available, zf=0 otherwise
  16.         ld a,c
  17.         cp 'm'
  18.         ret nz
  19.         ld hl,'wm'
  20.         sbc hl,de
  21.         ret nz
  22. ;prepare local variables
  23.         ld (MUSICTITLEADDR),hl
  24.         ld hl,musicprogress+1
  25.         ld (MUSICPROGRESSADDR),hl
  26.         jp initprogress
  27.  
  28. playerinit
  29. ;hl,ix = GPSETTINGS
  30. ;a = player page
  31. ;out: zf=1 if init is successful, hl=init message
  32.         ld de,songdata_bank1
  33.         ld bc,3
  34.         ldir
  35.         ld a,(ix+GPSETTINGS.moonsoundstatus)
  36.         cp 2
  37.         ld hl,initokstr
  38.         ret z
  39.         ld hl,nodevicestr
  40.         ret
  41.  
  42. playerdeinit
  43.         ret
  44.  
  45. musicload
  46. ;cde = file extension
  47. ;hl = input file name
  48. ;out: hl = device mask, zf=1 if the file is ready for playing, zf=0 otherwise
  49. ;
  50. ;First try loading wavekit with the same filename as input file.
  51. ;This allows overriding wavekit specified in MWM header without
  52. ;having the file edited.
  53.         ld de,wavekiterrorstr
  54.         ld (ERRORSTRINGADDR),de
  55.         ld (filenameaddr),hl
  56.         ld c,'.'
  57.         call findlastchar ;out: de = after last dot or start
  58.         ld hl,2
  59.         add hl,de
  60.         ld (hl),'k'
  61. filenameaddr=$+1
  62.         ld de,0
  63.         push hl
  64.         call openstream_file
  65.         pop hl
  66.         ld (hl),'m'
  67.         or a
  68.         jr z,loadmwkdata
  69. ;didn't find wavekit, so now have to load and parse module header
  70.         ld de,(filenameaddr)
  71.         call openstream_file
  72.         or a
  73.         ret nz
  74.         ld a,(songdata_bank1)
  75.         SETPG8000
  76.         ld de,0x8000
  77.         ld hl,284
  78.         call readstream_file
  79.         call closestream_file
  80. ;check if this is a valid MWM file
  81.         ld de,0x8000
  82.         ld a,8 ;file type 8 = wave user song
  83.         call check_header
  84.         ret nz
  85. ;check if wavekit is needed
  86.         ld hl,0x8114
  87.         ld de,mwknone
  88.         ld b,8
  89.         call chk_headerlus
  90.         jr z,loadmwm
  91. ;build filename
  92.         ld hl,(filenameaddr)
  93.         ld de,0x8000
  94.         call strcopy_hltode
  95.         ld hl,0x8000
  96.         ld c,'/'
  97.         call findlastchar ;out: de = after last slash or start
  98.         ld hl,0x8114
  99.         ld b,8
  100. filenamecopyloop
  101.         ld a,(hl)
  102.         cp ' '
  103.         jr z,donefilenamecopy
  104.         ld (de),a
  105.         inc hl
  106.         inc de
  107.         djnz filenamecopyloop
  108. donefilenamecopy
  109.         ex de,hl
  110.         ld (hl),'.'
  111.         inc hl
  112.         ld (hl),'m'
  113.         inc hl
  114.         ld (hl),'w'
  115.         inc hl
  116.         ld (hl),'k'
  117.         inc hl
  118.         ld (hl),0
  119. ;load wavekit
  120.         ld de,0x8000
  121.         call openstream_file
  122.         or a
  123.         ret nz
  124. loadmwkdata
  125.         call mwkload
  126.         push af
  127.         call closestream_file
  128.         pop af
  129.         ret nz
  130. loadmwm
  131.         ld hl,moduleerrorstr
  132.         ld (ERRORSTRINGADDR),hl
  133.         ld de,(filenameaddr)
  134.         call openstream_file
  135.         or a
  136.         ret nz
  137.         call mwmload
  138.         ret nz
  139.         call closestream_file
  140.         call start_music
  141. ;set music length
  142.         ld a,(xloop)
  143.         ld c,a
  144.         ld b,0
  145.         cp 255
  146.         ld a,(xleng)
  147.         jr nc,noloopinmusic
  148. ;the loop is played one additional time
  149.         ld l,a
  150.         ld h,b
  151.         add hl,hl
  152.         sbc hl,bc
  153.         ld a,l
  154.         srl h
  155. noloopinmusic
  156.         rra
  157.         adc a,b
  158.         call setprogressdelta
  159. ;make title avaialable
  160.         ld hl,MUSICTITLE
  161.         ld (MUSICTITLEADDR),hl
  162. ;null terminate string
  163.         xor a
  164.         ld (MUSICTITLE+50),a
  165. ;init progress vars
  166.         ld (lastplaypos),a
  167.         ld (loopcounter),a
  168.         ld hl,0
  169.         ld (playposacc),hl
  170.         ld (ERRORSTRINGADDR),hl
  171.         ld hl,DEVICE_MOONSOUND_MASK
  172.         ret
  173.  
  174. musicunload
  175.         jp stop_music
  176.  
  177. musicplay
  178. ;out: zf=0 if still playing, zf=1 otherwise
  179.         ld a,(play_busy)
  180.         or a
  181.         ret z
  182.         in a,(MOON_STAT)
  183.         rlca
  184.         jr nc,$-3
  185.         call play_int
  186. ;update progress
  187. lastplaypos=$+1
  188.         ld b,0
  189.         ld a,(play_pos)
  190.         ld (lastplaypos),a
  191.         sub b
  192.         jr z,playposunchanged
  193.         jr nc,loopwasnotencountered
  194.         ld hl,xleng
  195.         add a,(hl)
  196.         ld hl,xloop
  197.         sub (hl)
  198.         ld hl,loopcounter
  199.         inc (hl)
  200. loopwasnotencountered
  201. playposacc=$+1
  202.         ld hl,0
  203.         ld c,a
  204.         ld b,0
  205.         add hl,bc
  206.         ld (playposacc),hl
  207.         ld a,l
  208.         srl h
  209.         rra
  210.         call updateprogress
  211. playposunchanged
  212.         ld a,(play_busy)
  213.         or a
  214.         ret z
  215. loopcounter=$+1
  216.         ld a,0
  217.         cp 2 ;repeat the loop once
  218.         sbc a,a
  219.         ret
  220.  
  221. strcopy_hltode
  222.         ld a,(hl)
  223.         ld (de),a
  224.         or a
  225.         ret z
  226.         inc hl
  227.         inc de
  228.         jr strcopy_hltode
  229.  
  230. ;c = character
  231. ;hl = poi to filename in string
  232. ;out: de = after last dot or start
  233. findlastchar
  234.         ld d,h
  235.         ld e,l ;de = after last char
  236. findlastchar0
  237.         ld a,(hl)
  238.         inc hl
  239.         or a
  240.         ret z
  241.         cp c
  242.         jr nz,findlastchar0
  243.         jr findlastchar
  244.  
  245. load_file
  246.         push de
  247.         push ix
  248.         call readstream_file
  249.         pop ix
  250.         pop de
  251.         ret
  252.  
  253. selbank_FE
  254.         SETPG8000
  255.         ret
  256.  
  257.         include "../_sdk/file.asm"
  258.         include "common/opl4.asm"
  259.         include "mbwave/basic.asm"
  260.         include "progress.asm"
  261.  
  262. initokstr
  263.         db "OK\r\n",0
  264. nodevicestr
  265.         db "no device!\r\n",0
  266. mwknone
  267.         db "NONE    "
  268. playernamestr
  269.         db "MBWave",0
  270. wavekiterrorstr
  271.         db "Unable to load wavekit!",0
  272. moduleerrorstr
  273.         db "Failed to load the module!",0
  274. end
  275.  
  276.         savebin "mwm.bin",begin,end-begin
  277.