?login_element?

Subversion Repositories NedoOS

Rev

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