?login_element?

Subversion Repositories NedoOS

Rev

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