?login_element?

Subversion Repositories NedoOS

Rev

Rev 1763 | Rev 1992 | 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.         sub 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 ix,step_buffer
  37.         call opl4initwave
  38.         ret z
  39.         ld a,255
  40.         ld (mwmsupported),a ;writes 255 disabling the extension
  41.         ret
  42.  
  43. playerdeinit
  44.         ret
  45.  
  46. musicload
  47. ;cde = file extension
  48. ;hl = input file name
  49. ;out: zf=1 if the file is ready for playing, zf=0 otherwise
  50. ;
  51. ;First try loading wavekit with the same filename as input file.
  52. ;This allows overriding wavekit specified in MWM header without
  53. ;having the file edited.
  54.         ld (filenameaddr),hl
  55.         ld c,'.'
  56.         call findlastchar ;out: de = after last dot or start
  57.         ld hl,2
  58.         add hl,de
  59.         ld (hl),'k'
  60. filenameaddr=$+1
  61.         ld de,0
  62.         push hl
  63.         call openstream_file
  64.         pop hl
  65.         ld (hl),'m'
  66.         or a
  67.         jr z,loadmwkdata
  68. ;didn't find wavekit, so now have to load and parse module header
  69.         ld de,(filenameaddr)
  70.         call openstream_file
  71.         or a
  72.         ret nz
  73.         ld a,(songdata_bank1)
  74.         SETPG8000
  75.         ld de,0x8000
  76.         ld hl,284
  77.         call readstream_file
  78.         call closestream_file
  79. ;check if this is a valid MWM file
  80.         ld de,0x8000
  81.         ld a,8 ;file type 8 = wave user song
  82.         call check_header
  83.         ret nz
  84. ;check if wavekit is needed
  85.         ld hl,0x8114
  86.         ld de,mwknone
  87.         ld b,8
  88.         call chk_headerlus
  89.         jr z,loadmwm
  90. ;build filename
  91.         ld hl,(filenameaddr)
  92.         ld de,0x8000
  93.         call strcopy_hltode
  94.         ld hl,0x8000
  95.         ld c,'/'
  96.         call findlastchar ;out: de = after last slash or start
  97.         ld hl,0x8114
  98.         ld b,8
  99. filenamecopyloop
  100.         ld a,(hl)
  101.         cp ' '
  102.         jr z,donefilenamecopy
  103.         ld (de),a
  104.         inc hl
  105.         inc de
  106.         djnz filenamecopyloop
  107. donefilenamecopy
  108.         ex de,hl
  109.         ld (hl),'.'
  110.         inc hl
  111.         ld (hl),'m'
  112.         inc hl
  113.         ld (hl),'w'
  114.         inc hl
  115.         ld (hl),'k'
  116.         inc hl
  117.         ld (hl),0
  118. ;load wavekit
  119.         ld de,0x8000
  120.         call openstream_file
  121.         or a
  122.         ret nz
  123. loadmwkdata
  124.         call mwkload
  125.         push af
  126.         call closestream_file
  127.         pop af
  128.         ret nz
  129. loadmwm
  130.         ld de,(filenameaddr)
  131.         call openstream_file
  132.         or a
  133.         ret nz
  134.         call mwmload
  135.         ret nz
  136.         call closestream_file
  137.  
  138.         call start_music
  139.  
  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.         ret
  170.  
  171. musicunload
  172.         jp stop_music
  173.  
  174. musicplay
  175. ;out: zf=0 if still playing, zf=1 otherwise
  176.         ld a,(play_busy)
  177.         or a
  178.         ret z
  179.         in a,(MOON_STAT)
  180.         rlca
  181.         jr nc,$-3
  182.         call play_int
  183. ;update progress
  184. lastplaypos=$+1
  185.         ld b,0
  186.         ld a,(play_pos)
  187.         ld (lastplaypos),a
  188.         sub b
  189.         jr z,playposunchanged
  190.         jr nc,loopwasnotencountered
  191.         ld hl,xleng
  192.         add a,(hl)
  193.         ld hl,xloop
  194.         sub (hl)
  195.         ld hl,loopcounter
  196.         inc (hl)
  197. loopwasnotencountered
  198. playposacc=$+1
  199.         ld hl,0
  200.         ld c,a
  201.         ld b,0
  202.         add hl,bc
  203.         ld (playposacc),hl
  204.         ld a,l
  205.         srl h
  206.         rra
  207.         call updateprogress
  208. playposunchanged
  209.         ld a,(play_busy)
  210.         or a
  211.         ret z
  212. loopcounter=$+1
  213.         ld a,0
  214.         cp 2 ;repeat the loop once
  215.         sbc a,a
  216.         ret
  217.  
  218. strcopy_hltode
  219.         ld a,(hl)
  220.         ld (de),a
  221.         or a
  222.         ret z
  223.         inc hl
  224.         inc de
  225.         jr strcopy_hltode
  226.  
  227. ;c = character
  228. ;hl = poi to filename in string
  229. ;out: de = after last dot or start
  230. findlastchar
  231.         ld d,h
  232.         ld e,l ;de = after last char
  233. findlastchar0
  234.         ld a,(hl)
  235.         inc hl
  236.         or a
  237.         ret z
  238.         cp c
  239.         jr nz,findlastchar0
  240.         jr findlastchar
  241.  
  242. load_file
  243.         push de
  244.         push ix
  245.         call readstream_file
  246.         pop ix
  247.         pop de
  248.         ret
  249.  
  250. selbank_FE
  251.         SETPG8000
  252.         ret
  253.  
  254.         include "../_sdk/file.asm"
  255.         include "common/opl4utils.asm"
  256.         include "mbwave/basic.asm"
  257.         include "progress.asm"
  258.  
  259. mwknone
  260.         db "NONE    "
  261. playernamestr
  262.         db "Moonblaster Wave Replayer",0
  263. end
  264.  
  265.         savebin "mwm.bin",begin,end-begin
  266.