Subversion Repositories NedoOS

Rev

Rev 2420 | 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.         org PLAYERSTART
  8.  
  9. begin   PLAYERHEADER playerwindowui
  10.  
  11. TITLELENGTH = 64
  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
  22.  
  23. cleanupvars
  24. ;out: zf=0 so this function can be used as error handler
  25.         xor a
  26.         ld (titlestr),a
  27.         inc a
  28.         jp initprogress
  29.  
  30. playerinit
  31. ;ix = GPSETTINGS
  32. ;a = player page
  33. ;out: zf=1 if init is successful, hl=init message
  34.         ld a,(ix+GPSETTINGS.sharedpages+0) : ld (songdata_bank1+0),a
  35.         ld a,(ix+GPSETTINGS.sharedpages+1) : ld (songdata_bank1+1),a
  36.         ld a,(ix+GPSETTINGS.sharedpages+2) : ld (songdata_bank1+2),a
  37.         call cleanupvars
  38.         ld a,(ix+GPSETTINGS.moonsoundstatus)
  39.         cp 2
  40.         ld hl,initokstr
  41.         ret z
  42.         ld hl,nodevicestr
  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.         jp nz,cleanupvars
  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.         jp nz,cleanupvars
  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.         jp nz,cleanupvars
  127. loadmwkdata
  128.         call mwkload
  129.         push af
  130.         call closestream_file
  131.         pop af
  132.         jp nz,cleanupvars
  133. loadmwm
  134.         ld hl,moduleerrorstr
  135.         ld (ERRORSTRINGADDR),hl
  136.         ld de,(filenameaddr)
  137.         call openstream_file
  138.         or a
  139.         jp nz,cleanupvars
  140.         call mwmload
  141.         jp nz,cleanupvars
  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. ;set title
  163.         ld hl,0x80dc
  164.         ld de,titlestr
  165.         ld bc,50
  166.         ldir
  167.         ld b,TITLELENGTH-50
  168.         ld a,' '
  169. .filltitleloop
  170.         ld (de),a
  171.         inc de
  172.         djnz .filltitleloop
  173.         xor a
  174.         ld (de),a
  175. ;init progress vars
  176.         ld (lastplaypos),a
  177.         ld (loopcounter),a
  178.         ld hl,0
  179.         ld (playposacc),hl
  180.         ld (ERRORSTRINGADDR),hl
  181.         ld hl,DEVICE_MOONSOUND_MASK
  182.         ret
  183.  
  184. musicunload
  185.         call cleanupvars
  186.         jp stop_music
  187.  
  188. musicplay
  189. ;out: zf=0 if still playing, zf=1 otherwise
  190.         ld a,(play_busy)
  191.         or a
  192.         ret z
  193.         in a,(MOON_STAT)
  194.         rlca
  195.         jr nc,$-3
  196.         call play_int
  197. ;update progress
  198. lastplaypos=$+1
  199.         ld b,0
  200.         ld a,(play_pos)
  201.         ld (lastplaypos),a
  202.         sub b
  203.         jr z,playposunchanged
  204.         jr nc,loopwasnotencountered
  205.         ld hl,xleng
  206.         add a,(hl)
  207.         ld hl,xloop
  208.         sub (hl)
  209.         ld hl,loopcounter
  210.         inc (hl)
  211. loopwasnotencountered
  212. playposacc=$+1
  213.         ld hl,0
  214.         ld c,a
  215.         ld b,0
  216.         add hl,bc
  217.         ld (playposacc),hl
  218.         ld a,l
  219.         srl h
  220.         rra
  221.         call updateprogress
  222. playposunchanged
  223.         ld a,(play_busy)
  224.         or a
  225.         ret z
  226. loopcounter=$+1
  227.         ld a,0
  228.         cp 2 ;repeat the loop once
  229.         sbc a,a
  230.         ret
  231.  
  232. strcopy_hltode
  233.         ld a,(hl)
  234.         ld (de),a
  235.         or a
  236.         ret z
  237.         inc hl
  238.         inc de
  239.         jr strcopy_hltode
  240.  
  241. ;c = character
  242. ;hl = poi to filename in string
  243. ;out: de = after last dot or start
  244. findlastchar
  245.         ld d,h
  246.         ld e,l ;de = after last char
  247. findlastchar0
  248.         ld a,(hl)
  249.         inc hl
  250.         or a
  251.         ret z
  252.         cp c
  253.         jr nz,findlastchar0
  254.         jr findlastchar
  255.  
  256. load_file
  257.         push de
  258.         push ix
  259.         call readstream_file
  260.         pop ix
  261.         pop de
  262.         ret
  263.  
  264. selbank_FE
  265.         SETPG8000
  266.         ret
  267.  
  268.         include "../_sdk/file.asm"
  269.         include "common/opl4.asm"
  270.         include "mbwave/basic.asm"
  271.         include "progress.asm"
  272.  
  273. initokstr
  274.         db "OK\r\n",0
  275. nodevicestr
  276.         db "no device!\r\n",0
  277. mwknone
  278.         db "NONE    "
  279. playernamestr
  280.         db "MBWave",0
  281. wavekiterrorstr
  282.         db "Unable to load wavekit!",0
  283. moduleerrorstr
  284.         db "Failed to load the module!",0
  285. playerwindowui
  286.         PROGRESSIVEPLAYERWINDOWTEMPLATE titlestr,musicprogress+1
  287. end
  288.  
  289. titlestr
  290.         ds TITLELENGTH+1
  291.  
  292.         savebin "mwm.bin",begin,end-begin
  293.  
  294.         assert $ <= PLAYEREND ;ensure everything is within the player page
  295.