?login_element?

Subversion Repositories NedoOS

Rev

Rev 2033 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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