?login_element?

Subversion Repositories NedoOS

Rev

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

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