Subversion Repositories NedoOS

Rev

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