Subversion Repositories NedoOS

Rev

Rev 2286 | Blame | Compare with Previous | Last modification | View Log | Download

  1. ; S3M and MOD player for MoonSound
  2.  
  3.         DEVICE ZXSPECTRUM128
  4.         include "../_sdk/sys_h.asm"
  5.         include "playerdefs.asm"
  6.  
  7. TITLELENGTH = 64
  8. MEMORYSTREAMMAXPAGES = 20
  9. MEMORYSTREAMERRORMASK = 0
  10.  
  11.         org PLAYERSTART
  12.  
  13. begin   PLAYERHEADER
  14.  
  15. isfilesupported
  16. ;cde = file extension
  17. ;out: zf=1 if this player can handle the file and the sound hardware is available, zf=0 otherwise
  18.         call ismodfile
  19.         jr z,initplayvars
  20. .checks3m
  21.         ld a,'s'
  22.         cp c
  23.         ret nz
  24.         ld hl,'3m'
  25.         sbc hl,de
  26.         ret nz
  27. initplayvars
  28.         ld hl,0
  29.         ld (MUSICTITLEADDR),hl
  30.         ld hl,musicprogress+1
  31.         ld (MUSICPROGRESSADDR),hl
  32.         jp initprogress
  33.  
  34. playerinit
  35. ;hl,ix = GPSETTINGS
  36. ;a = player page
  37. ;out: zf=1 if init is successful, hl=init message
  38.         ld (.settingsaddr),hl
  39.         ld a,(ix+GPSETTINGS.moonsoundstatus)
  40.         cp 2
  41.         ld hl,nodevicestr
  42.         ret nz
  43. ;init period lookup
  44.         OS_NEWPAGE
  45.         or a
  46.         ld hl,outofmemorystr
  47.         ret nz
  48.         ld a,e
  49.         push af
  50.         SETPGC000
  51. ;move period lookup table to its own page
  52.         ld hl,periodlookup
  53.         ld de,0xc000
  54.         ld bc,periodlookup_end-periodlookup
  55.         ldir
  56. ;start initing vars after the table was copied
  57.         pop af
  58.         ld (modperiodlookuppage),a
  59. .settingsaddr=$+2
  60.         ld ix,0
  61.         ld a,(ix)
  62.         ld (modfilebufferpage),a
  63.         call setdefaultpanning
  64.         call checkmididevicesettings
  65.         ld hl,initokstr
  66.         xor a
  67.         ret
  68.  
  69. checkmididevicesettings
  70. ;output: zf=1 if this player is enabled, zf=0 otherwise
  71.         ld de,(ix+GPSETTINGS.moddevice)
  72.         ld a,d
  73.         or e
  74.         ret z
  75.         ld a,(de)
  76.         cp '0'
  77.         ret z
  78.         cp '1'
  79.         ret z
  80.         ld hl,isfilesupported.checks3m
  81.         ld (ISFILESUPPORTEDPROCADDR),hl
  82.         ret
  83.  
  84. setdefaultpanning
  85. ;ix = GPSETTINGS
  86.         ld de,(ix+GPSETTINGS.moonmoddefaultpanning)
  87.         ld a,d
  88.         or e
  89.         ret z
  90.         ld b,4
  91.         ld hl,moddefaultpanning
  92. .setpanningloop
  93.         ld a,(de)
  94.         sub 'A'
  95.         jr nc,$+4
  96.         add a,'A'-'0'-10
  97.         add a,10
  98.         and 15
  99.         ld (hl),a
  100.         inc hl
  101.         inc de
  102.         djnz .setpanningloop
  103.         ret
  104.  
  105. playerdeinit
  106. modperiodlookuppage=$+1
  107.         ld e,0
  108.         OS_DELPAGE
  109.         ret
  110.  
  111. ismodfile
  112. ;cde = file extension
  113. ;out: zf=1 if .mod, zf=0 otherwise
  114.         ld a,'m'
  115.         cp c
  116.         ret nz
  117.         ld a,'o'
  118.         cp d
  119.         ret nz
  120.         ld a,'d'
  121.         cp e
  122.         ret
  123.  
  124. musicload
  125. ;cde = file extension
  126. ;hl = input file name
  127. ;out: hl = device mask, zf=1 if the file is ready for playing, zf=0 otherwise
  128.         call ismodfile
  129.         ex de,hl
  130.         jr nz,.loads3m
  131.         call modload
  132.         ret nz
  133.         ld a,255
  134.         ld (isplayingmodfile),a
  135.         ld a,(modinfo.songlength)
  136.         jr .finalize
  137. .loads3m
  138.         call s3mload
  139.         ret nz
  140.         xor a
  141.         ld (isplayingmodfile),a
  142.         ld a,(s3mheader.ordernum)
  143. .finalize
  144.         call setprogressdelta
  145.         ld de,MODHEADERADDR
  146.         ld a,(de)
  147.         or a
  148.         jr z,.notitle
  149.         ld hl,titlestr
  150.         ld (MUSICTITLEADDR),hl
  151.         ld b,TITLELENGTH+1
  152. .copytitleloop
  153.         ld a,(de)
  154.         ld (hl),a
  155.         inc de
  156.         inc hl
  157.         dec b
  158.         or a
  159.         jr nz,.copytitleloop
  160.         dec hl
  161. .filltitleloop
  162.         ld (hl),' '
  163.         inc hl
  164.         djnz .filltitleloop
  165.         ld (hl),0
  166. .notitle
  167.         xor a
  168.         ld (currentposition),a
  169.         ld hl,DEVICE_MOONSOUND_MASK
  170.         ret
  171.  
  172. musicunload
  173.         ld a,(isplayingmodfile)
  174.         or a
  175.         jp nz,modunload
  176.         jp s3munload
  177.  
  178. musicplay
  179. ;out: zf=0 if still playing, zf=1 otherwise
  180.         ld a,(isplayingmodfile)
  181.         or a
  182.         jr nz,.playmod
  183.         call s3mplay
  184.         ld a,(s3mplayer.patterntableindex)
  185.         call updateprogress
  186.         ld a,(s3mplayer.patterntableindex)
  187.         jr .finalize
  188. .playmod
  189.         call modplay
  190.         ld a,(modplayer.patterntableindex)
  191.         call updateprogress
  192.         ld a,(modplayer.patterntableindex)
  193. .finalize
  194. ;check if the position is increasing monotonically
  195.         ld hl,currentposition
  196.         cp (hl)
  197.         ld (hl),a
  198.         ccf
  199.         sbc a
  200.         ret
  201.  
  202.         include "../_sdk/file.asm"
  203.         include "common/memorystream.asm"
  204.         include "common/opl4.asm"
  205.         include "common/muldiv.asm"
  206.         include "moonmod/mod.asm"
  207.         include "moonmod/s3m.asm"
  208.         include "progress.asm"
  209.  
  210. playernamestr
  211.         db "MoonSound S3M/MOD",0
  212. outofmemorystr
  213.         db "Out of memory!",0
  214. initokstr
  215.         db "OK\r\n",0
  216. nodevicestr
  217.         db "no device!\r\n",0
  218.  
  219. tempmemorystart = $
  220. periodlookup
  221.         incbin "moonmod/periodlookup.bin"
  222. periodlookup_end
  223. end
  224.  
  225. titlestr equ tempmemorystart
  226. currentposition equ titlestr+TITLELENGTH+1
  227. modfilebufferpage equ currentposition+1
  228. isplayingmodfile equ modfilebufferpage+1
  229. modtempmemory equ isplayingmodfile+1
  230.  
  231.         org modtempmemory
  232. modinfo MODINFO
  233. modwaveheaderbuffer = $
  234. modplayer MODPLAYER
  235.  
  236.         assert $ <= PLAYEREND ;ensure everything is within the player page
  237.  
  238.         org modtempmemory
  239. s3minfo S3MINFO
  240. s3mwaveheaderbuffer = $
  241. s3mplayer S3MPLAYER
  242.  
  243.         assert $ <= PLAYEREND ;ensure everything is within the player page
  244.  
  245.         org MODHEADERADDR
  246. modheader MODHEADER
  247.  
  248.         org S3MHEADERADDR
  249. s3mheader S3MHEADER
  250.  
  251.         assert MODWAVEHEADERBUFFERSIZE <= PLAYEREND-modwaveheaderbuffer
  252.         assert S3MWAVEHEADERBUFFERSIZE <= PLAYEREND-s3mwaveheaderbuffer
  253.  
  254.         savebin "moonmod.bin",begin,end-begin
  255.