?login_element?

Subversion Repositories NedoOS

Rev

Rev 1945 | Go to most recent revision | 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 = 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 de,GPSETTINGS.moonsoundstatus-3
  37.         add hl,de
  38.         ld a,(hl)
  39.         cp 2
  40.         ld hl,initokstr
  41.         ret z
  42.         ld hl,nodevicestr
  43.         ld a,255
  44.         ld (mwmsupported),a ;writes 255 disabling the extension
  45.         ret
  46.  
  47. playerdeinit
  48.         ret
  49.  
  50. musicload
  51. ;cde = file extension
  52. ;hl = input file name
  53. ;out: zf=1 if the file is ready for playing, zf=0 otherwise
  54. ;
  55. ;First try loading wavekit with the same filename as input file.
  56. ;This allows overriding wavekit specified in MWM header without
  57. ;having the file edited.
  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 de,(filenameaddr)
  135.         call openstream_file
  136.         or a
  137.         ret nz
  138.         call mwmload
  139.         ret nz
  140.         call closestream_file
  141.  
  142.         call start_music
  143.  
  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.         ret
  174.  
  175. musicunload
  176.         jp stop_music
  177.  
  178. musicplay
  179. ;out: zf=0 if still playing, zf=1 otherwise
  180.         ld a,(play_busy)
  181.         or a
  182.         ret z
  183.         in a,(MOON_STAT)
  184.         rlca
  185.         jr nc,$-3
  186.         call play_int
  187. ;update progress
  188. lastplaypos=$+1
  189.         ld b,0
  190.         ld a,(play_pos)
  191.         ld (lastplaypos),a
  192.         sub b
  193.         jr z,playposunchanged
  194.         jr nc,loopwasnotencountered
  195.         ld hl,xleng
  196.         add a,(hl)
  197.         ld hl,xloop
  198.         sub (hl)
  199.         ld hl,loopcounter
  200.         inc (hl)
  201. loopwasnotencountered
  202. playposacc=$+1
  203.         ld hl,0
  204.         ld c,a
  205.         ld b,0
  206.         add hl,bc
  207.         ld (playposacc),hl
  208.         ld a,l
  209.         srl h
  210.         rra
  211.         call updateprogress
  212. playposunchanged
  213.         ld a,(play_busy)
  214.         or a
  215.         ret z
  216. loopcounter=$+1
  217.         ld a,0
  218.         cp 2 ;repeat the loop once
  219.         sbc a,a
  220.         ret
  221.  
  222. strcopy_hltode
  223.         ld a,(hl)
  224.         ld (de),a
  225.         or a
  226.         ret z
  227.         inc hl
  228.         inc de
  229.         jr strcopy_hltode
  230.  
  231. ;c = character
  232. ;hl = poi to filename in string
  233. ;out: de = after last dot or start
  234. findlastchar
  235.         ld d,h
  236.         ld e,l ;de = after last char
  237. findlastchar0
  238.         ld a,(hl)
  239.         inc hl
  240.         or a
  241.         ret z
  242.         cp c
  243.         jr nz,findlastchar0
  244.         jr findlastchar
  245.  
  246. load_file
  247.         push de
  248.         push ix
  249.         call readstream_file
  250.         pop ix
  251.         pop de
  252.         ret
  253.  
  254. selbank_FE
  255.         SETPG8000
  256.         ret
  257.  
  258.         include "../_sdk/file.asm"
  259.         include "common/opl4.asm"
  260.         include "mbwave/basic.asm"
  261.         include "progress.asm"
  262.  
  263. initokstr
  264.         db "OK\r\n",0
  265. nodevicestr
  266.         db "no device!\r\n",0
  267. mwknone
  268.         db "NONE    "
  269. playernamestr
  270.         db "Moonblaster Wave Replayer",0
  271. end
  272.  
  273.         savebin "mwm.bin",begin,end-begin
  274.