?login_element?

Subversion Repositories NedoOS

Rev

Rev 2009 | Go to most recent revision | 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: 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.         ret
  159.  
  160. musicunload
  161.         ld a,(isplayingmodfile)
  162.         or a
  163.         jp nz,modunload
  164.         jp s3munload
  165.  
  166. musicplay
  167. ;out: zf=0 if still playing, zf=1 otherwise
  168.         ld a,(isplayingmodfile)
  169.         or a
  170.         jr nz,.playmod
  171.         call s3mplay
  172.         ld a,(s3mplayer.patterntableindex)
  173.         call updateprogress
  174.         ld a,(s3mplayer.patterntableindex)
  175.         jr .finalize
  176. .playmod
  177.         call modplay
  178.         ld a,(modplayer.patterntableindex)
  179.         call updateprogress
  180.         ld a,(modplayer.patterntableindex)
  181. .finalize
  182. ;check if the position is increasing monotonically
  183.         ld hl,currentposition
  184.         cp (hl)
  185.         ld (hl),a
  186.         ccf
  187.         sbc a
  188.         ret
  189.  
  190.         include "../_sdk/file.asm"
  191.         include "common/memorystream.asm"
  192.         include "common/opl4.asm"
  193.         include "common/muldiv.asm"
  194.         include "moonmod/mod.asm"
  195.         include "moonmod/s3m.asm"
  196.         include "progress.asm"
  197.  
  198. playernamestr
  199.         db "MoonSound S3M/MOD Player",0
  200. outofmemorystr
  201.         db "Out of memory!",0
  202. initokstr
  203.         db "OK\r\n",0
  204. nodevicestr
  205.         db "no device!\r\n",0
  206.  
  207. tempmemorystart = $
  208. periodlookup
  209.         incbin "moonmod/periodlookup.bin"
  210. periodlookup_end
  211. end
  212.  
  213. titlestr equ tempmemorystart
  214. currentposition equ titlestr+TITLELENGTH+1
  215. modfilebufferpage equ currentposition+1
  216. isplayingmodfile equ modfilebufferpage+1
  217. modtempmemory equ isplayingmodfile+1
  218.  
  219.         org modtempmemory
  220. modinfo MODINFO
  221. modwaveheaderbuffer = $
  222. modplayer MODPLAYER
  223.  
  224.         assert $ <= PLAYEREND ;ensure everything is within the player page
  225.  
  226.         org modtempmemory
  227. s3minfo S3MINFO
  228. s3mwaveheaderbuffer = $
  229. s3mplayer S3MPLAYER
  230.  
  231.         assert $ <= PLAYEREND ;ensure everything is within the player page
  232.  
  233.         org MODHEADERADDR
  234. modheader MODHEADER
  235.  
  236.         org S3MHEADERADDR
  237. s3mheader S3MHEADER
  238.  
  239.         assert MODWAVEHEADERBUFFERSIZE <= PLAYEREND-modwaveheaderbuffer
  240.         assert S3MWAVEHEADERBUFFERSIZE <= PLAYEREND-s3mwaveheaderbuffer
  241.  
  242.         savebin "moonmod.bin",begin,end-begin
  243.