Subversion Repositories NedoOS

Rev

Rev 2420 | 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 0
  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.         ret z
  20. .checks3m
  21.         ld a,'s'
  22.         cp c
  23.         ret nz
  24.         ld hl,'3m'
  25.         sbc hl,de
  26.         ret
  27.  
  28. cleanupvars
  29. ;out: zf=0 so this function can be used as error handler
  30.         ld hl,playerwindowloading
  31.         ld (CUSTOMUIADDR),hl
  32.         xor a
  33.         ld (titlestr),a
  34.         ld (currentposition),a
  35.         inc a
  36.         jp initprogress
  37.  
  38. playerinit
  39. ;ix = GPSETTINGS
  40. ;a = player page
  41. ;out: zf=1 if init is successful, hl=init message
  42.         ld (.settingsaddr),ix
  43.         ld hl,(ix+GPSETTINGS.drawprogresscallback)
  44.         ld (drawsampleloadingprogress.callback),hl
  45.         ld a,(ix+GPSETTINGS.moonsoundstatus)
  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=$+2
  66.         ld ix,0
  67.         ld a,(ix)
  68.         ld (modfilebufferpage),a
  69.         call setdefaultpanning
  70.         call checkmoddevicesettings
  71.         call cleanupvars
  72.         xor a
  73.         ld hl,initokstr
  74.         ret
  75.  
  76. checkmoddevicesettings
  77. ;output: zf=1 if this player is enabled, zf=0 otherwise
  78.         ld de,(ix+GPSETTINGS.moddevice)
  79.         ld a,d
  80.         or e
  81.         ret z
  82.         ld a,(de)
  83.         cp '0'
  84.         ret z
  85.         cp '1'
  86.         ret z
  87.         ld hl,isfilesupported.checks3m
  88.         ld (ISFILESUPPORTEDPROCADDR),hl
  89.         ret
  90.  
  91. setdefaultpanning
  92. ;ix = GPSETTINGS
  93.         ld de,(ix+GPSETTINGS.moonmoddefaultpanning)
  94.         ld a,d
  95.         or e
  96.         ret z
  97.         ld b,4
  98.         ld hl,moddefaultpanning
  99. .setpanningloop
  100.         ld a,(de)
  101.         sub 'A'
  102.         jr nc,$+4
  103.         add a,'A'-'0'-10
  104.         add a,10
  105.         and 15
  106.         ld (hl),a
  107.         inc hl
  108.         inc de
  109.         djnz .setpanningloop
  110.         ret
  111.  
  112. playerdeinit
  113. modperiodlookuppage=$+1
  114.         ld e,0
  115.         OS_DELPAGE
  116.         ret
  117.  
  118. ismodfile
  119. ;cde = file extension
  120. ;out: zf=1 if .mod, zf=0 otherwise
  121.         ld a,'m'
  122.         cp c
  123.         ret nz
  124.         ld a,'o'
  125.         cp d
  126.         ret nz
  127.         ld a,'d'
  128.         cp e
  129.         ret
  130.  
  131. musicload
  132. ;cde = file extension
  133. ;hl = input file name
  134. ;out: hl = device mask, zf=1 if the file is ready for playing, zf=0 otherwise
  135.         call ismodfile
  136.         ex de,hl
  137.         jr nz,.loads3m
  138.         call modload
  139.         jp nz,cleanupvars ;sets zf=0
  140.         call modprintinfo
  141.         ld a,255
  142.         ld (isplayingmodfile),a
  143.         ld a,(modinfo.songlength)
  144.         jr .finalize
  145. .loads3m
  146.         call s3mload
  147.         jp nz,cleanupvars ;sets zf=0
  148.         call s3mprintinfo
  149.         xor a
  150.         ld (isplayingmodfile),a
  151.         ld a,(s3mheader.ordernum)
  152. .finalize
  153.         call setprogressdelta
  154.         ld de,MODHEADERADDR
  155.         ld a,(de)
  156.         or a
  157.         jr z,.notitle
  158.         ld hl,titlestr
  159.         ld b,TITLELENGTH+1
  160. .copytitleloop
  161.         ld a,(de)
  162.         ld (hl),a
  163.         inc de
  164.         inc hl
  165.         dec b
  166.         or a
  167.         jr nz,.copytitleloop
  168.         dec hl
  169. .filltitleloop
  170.         ld (hl),' '
  171.         inc hl
  172.         djnz .filltitleloop
  173.         ld (hl),0
  174. .notitle
  175.         ld hl,playerwindowui
  176.         ld (CUSTOMUIADDR),hl
  177.         xor a
  178.         ld hl,DEVICE_MOONSOUND_MASK
  179.         ret
  180.  
  181. musicunload
  182.         call cleanupvars
  183.         ld a,(isplayingmodfile)
  184.         or a
  185.         jp nz,modunload
  186.         jp s3munload
  187.  
  188. musicplay
  189. ;out: zf=0 if still playing, zf=1 otherwise
  190.         ld a,(isplayingmodfile)
  191.         or a
  192.         jr nz,.playmod
  193.         call s3mplay
  194.         ld a,(s3mplayer.patterntableindex)
  195.         call updateprogress
  196.         ld a,(s3mplayer.patterntableindex)
  197.         jr .finalize
  198. .playmod
  199.         call modplay
  200.         ld a,(modplayer.patterntableindex)
  201.         call updateprogress
  202.         ld a,(modplayer.patterntableindex)
  203. .finalize
  204. ;check if the position is increasing monotonically
  205.         ld hl,currentposition
  206.         cp (hl)
  207.         ld (hl),a
  208.         ccf
  209.         sbc a
  210.         ret
  211.  
  212.         include "../_sdk/file.asm"
  213.         include "common/memorystream.asm"
  214.         include "common/opl4.asm"
  215.         include "common/muldiv.asm"
  216.         include "moonmod/mod.asm"
  217.         include "moonmod/s3m.asm"
  218.         include "progress.asm"
  219.  
  220. atodecimalstring
  221. ;a = number
  222. ;de = string buffer
  223.         ld l,a
  224.         ld h,0
  225. hltodecimalstring
  226. ;hl = number
  227. ;de = string buffer
  228.         ld ixl,e
  229.         ld bc,-10000
  230.         inc ixl
  231.         call .writedigit
  232.         ld bc,-1000
  233.         call .writedigit
  234.         ld bc,-100
  235.         call .writedigit
  236.         ld bc,-10
  237.         call .writedigit
  238.         ld bc,-1
  239.         dec ixl ;ensure the last zero is printed
  240.         call .writedigit
  241.         xor a
  242.         ld (de),a
  243.         ret
  244. .writedigit
  245.         ld a,'0'-1
  246.         inc a
  247.         add hl,bc
  248.         jr c,$-2
  249.         sbc hl,bc
  250.         ld (de),a
  251.         inc de
  252.         cp '0'
  253.         ret nz
  254. ;remove leading zeroes
  255.         ld a,e
  256.         cp ixl
  257.         ret nz
  258.         dec de
  259.         ret
  260.  
  261. strcopy_hltode
  262.         ld a,(hl)
  263.         ld (de),a
  264.         or a
  265.         ret z
  266.         inc hl
  267.         inc de
  268.         jr strcopy_hltode
  269.  
  270. modprintinfo
  271.         ld hl,(modinfo.moduletypestr)
  272.         ld (playerwindowui.trackertext+CUSTOMUIPRINTTEXT.straddr),hl
  273.         ld de,chnumstr
  274.         ld a,(modinfo.channelcount)
  275.         call atodecimalstring
  276.         ld de,instnumstr
  277.         ld a,(modinfo.samplecount)
  278.         call atodecimalstring
  279.         ld hl,(modinfo.samplesizesinkb)
  280.         jr printsamplesize
  281.  
  282. s3mprintinfo
  283.         ld hl,st3str
  284.         ld (playerwindowui.trackertext+CUSTOMUIPRINTTEXT.straddr),hl
  285.         ld de,chnumstr
  286.         ld a,(s3minfo.chnum)
  287.         call atodecimalstring
  288.         ld de,instnumstr
  289.         ld a,(s3minfo.instnum)
  290.         call atodecimalstring
  291.         ld hl,(s3minfo.samplesizesinkb)
  292. printsamplesize
  293.         ld de,samplesizestr
  294.         call hltodecimalstring
  295.         ld hl,kbytestr
  296.         jp strcopy_hltode
  297.  
  298. drawsampleloadingprogress
  299. .callback=$+1
  300.         jp 0
  301.  
  302. trackertextstr db "Tracker: ",0
  303. st3str db "Scream Tracker 3",0
  304. chnumtextstr db "Channels: "
  305. chnumstr ds 4
  306. instnumtextstr db "Instruments: "
  307. instnumstr ds 4
  308. samplesizetextstr db "Samples: "
  309. samplesizestr ds 10
  310. kbytestr db "KB",0
  311.  
  312. playernamestr
  313.         db "MoonSound S3M/MOD",0
  314. outofmemorystr
  315.         db "Out of memory!",0
  316. initokstr
  317.         db "OK\r\n",0
  318. nodevicestr
  319.         db "no device!\r\n",0
  320. loadingtitlestr
  321.         db "Loading tracker module...",0
  322. playerwindowloading
  323.         PROGRESSIVELOADINGWINDOWTEMPLATE loadingtitlestr,musicprogress+1
  324.  
  325. playerwindowui
  326.         CUSTOMUISETCOLOR ,COLOR_PANEL
  327.         CUSTOMUIDRAWWINDOW ,6,8,66,7
  328.         CUSTOMUISETCOLOR ,15
  329.         CUSTOMUISEPARATOR ,7,13,64,196,196,196
  330.         CUSTOMUIPLAYERWINDOWTITLE ,8,8
  331.         CUSTOMUISONGTITLE ,8,10,titlestr
  332.         CUSTOMUIPLAYPROGRESS ,8,11,musicprogress+1
  333.         CUSTOMUIPLAYTIME ,67,8
  334.         CUSTOMUISETCOLOR ,COLOR_PANEL_FILE
  335.         CUSTOMUIPRINTTEXT ,9,14,trackertextstr
  336. .trackertext
  337.         CUSTOMUIPRINTTEXT ,18,14,st3str
  338.         CUSTOMUIPRINTTEXT ,8,15,chnumtextstr
  339.         CUSTOMUIPRINTTEXT ,49,14,instnumtextstr
  340.         CUSTOMUIPRINTTEXT ,53,15,samplesizetextstr
  341.         CUSTOMUIDRAWEND
  342.  
  343. tempmemorystart = $
  344. periodlookup
  345.         incbin "moonmod/periodlookup.bin"
  346. periodlookup_end
  347. end
  348.  
  349. titlestr equ tempmemorystart
  350. currentposition equ titlestr+TITLELENGTH+1
  351. modfilebufferpage equ currentposition+1
  352. isplayingmodfile equ modfilebufferpage+1
  353. modtempmemory equ isplayingmodfile+1
  354.  
  355.         org modtempmemory
  356. modinfo MODINFO
  357. modwaveheaderbuffer = $
  358. modplayer MODPLAYER
  359.  
  360.         assert $ <= PLAYEREND ;ensure everything is within the player page
  361.  
  362.         org modtempmemory
  363. s3minfo S3MINFO
  364. s3mwaveheaderbuffer = $
  365. s3mplayer S3MPLAYER
  366.  
  367.         assert $ <= PLAYEREND ;ensure everything is within the player page
  368.  
  369.         org MODHEADERADDR
  370. modheader MODHEADER
  371.  
  372.         org S3MHEADERADDR
  373. s3mheader S3MHEADER
  374.  
  375.         assert MODWAVEHEADERBUFFERSIZE <= PLAYEREND-modwaveheaderbuffer
  376.         assert S3MWAVEHEADERBUFFERSIZE <= PLAYEREND-s3mwaveheaderbuffer
  377.  
  378.         savebin "moonmod.bin",begin,end-begin
  379.