Subversion Repositories NedoOS

Rev

Rev 1637 | Rev 1755 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1.         DEVICE ZXSPECTRUM128
  2.         include "../_sdk/sys_h.asm"
  3.         include "ngsdec/gscodedefs.asm"
  4.         include "ngsdec/gsports.asm"
  5.         include "ngsdec/vs10xx.asm"
  6.         include "playerdefs.asm"
  7.  
  8. BUFADDR = 0x8000
  9. BUFSIZE = 0x8000
  10.  
  11.         org PLAYERSTART
  12.  
  13. begin   PLAYERHEADER
  14.  
  15. isfilesupported
  16. ;cde = file extension
  17. isgsdisabled=$+1
  18.         jr nosupportedfiles
  19.         call ismodfile
  20.         ret z
  21. vsversion=$+1
  22.         ld a,255
  23.         ld l,'m'
  24.         ld h,b
  25.         sub hl,bc
  26.         jr nz,checkogg
  27.         ld hl,'id'
  28.         sub hl,de
  29.         jr nz,checkogg
  30.         cp SS_VER_VS1003
  31.         ret z
  32.         cp SS_VER_VS1033
  33.         ret z
  34.         cp SS_VER_VS1053
  35.         ret z
  36.         cp SS_VER_VS1103
  37.         ret
  38. checkogg
  39.         ld l,'o'
  40.         ld h,b
  41.         sub hl,bc
  42.         jr nz,checkaac
  43.         ld hl,'gg'
  44.         sub hl,de
  45.         jr nz,checkaac
  46.         cp SS_VER_VS1053
  47.         ret z
  48.         cp SS_VER_VS1063
  49.         ret    
  50. checkaac
  51.         ld l,'a'
  52.         ld h,b
  53.         sub hl,bc
  54.         jr nz,checkmp3
  55.         ld hl,'ac'
  56.         sub hl,de
  57.         jr nz,checkmp3
  58.         cp SS_VER_VS1033
  59.         ret z
  60.         cp SS_VER_VS1053
  61.         ret z
  62.         cp SS_VER_VS1063
  63.         ret
  64. checkmp3
  65.         ld l,'m'
  66.         ld h,b
  67.         sub hl,bc
  68.         ret nz
  69.         ld hl,'p3'
  70.         sub hl,de
  71.         ret nz
  72.         and ~SS_VER_MASK
  73.         ret
  74. nosupportedfiles
  75.         or 1
  76.         ret
  77.  
  78. ismodfile
  79. ;cde = file extension
  80. ;out: zf=1 if .mod, zf=0 otherwise
  81.         ld a,'m'
  82.         cp c
  83.         ret nz
  84.         ld a,'o'
  85.         cp d
  86.         ret nz
  87.         ld a,'d'
  88.         cp e
  89.         ret
  90.  
  91. playerinit
  92. ;hl = shared pages
  93. ;a = player page
  94.         ld a,(hl)
  95.         ld (page8000),a
  96.         inc hl
  97.         ld a,(hl)
  98.         ld (pageC000),a
  99.  
  100. ;       call gssoftreset
  101. ;b==0 if no reply from GS
  102. ;       dec b
  103. ;       inc b
  104. ;       call z,gshardreset
  105.         call gshardreset
  106. ;b==0 if no reply from GS
  107.         ld a,b
  108.         cp 1
  109.         ret c
  110.  
  111. ;get chip id
  112.         call gsstartcode
  113.         SC CMDGETCHIPID
  114.         WC
  115.         WN
  116.         GD
  117.         ld (vsversion),a
  118.         call gscodereset
  119.  
  120.         xor a
  121.         ld (isgsdisabled),a
  122.         ret
  123.  
  124. playerdeinit
  125.         ret
  126.  
  127. musicload
  128. ;cde = file extension
  129. ;hl = input file name
  130.         call ismodfile
  131.         ld a,1
  132.         jr z,$+3
  133.         dec a
  134.         ld (isplayingmodfile),a
  135.  
  136.         ex de,hl
  137.         call openstream_file
  138.         or a
  139.         ret nz
  140.  
  141. page8000=$+1
  142.         ld a,0
  143.         SETPG8000
  144. pageC000=$+1
  145.         ld a,0
  146.         SETPGC000
  147.  
  148.         ld a,(isplayingmodfile)
  149.         or a
  150.         jr nz,loadmod
  151.  
  152.         call gsstartcode
  153.  
  154.         ld hl,firstpaddingframedata
  155.         ld (paddingframedataptr),hl
  156.         ld hl,0
  157.         ld (paddingframecount),hl
  158.         ld (bufferdataleft),hl
  159.  
  160.         xor a
  161.         ret
  162.  
  163. loadmod
  164. ;load module
  165.         SC 0x30
  166.         WC
  167. ;open stream
  168.         SC 0xD1
  169.         WC
  170. .loadchunk
  171.         ld hl,BUFSIZE
  172.         ld de,BUFADDR
  173.         push de
  174.         call readstream_file
  175.         ex (sp),hl
  176.         pop bc
  177.         ld a,b
  178.         or c
  179.         jr z,.doneloading
  180. .uploadloop
  181.         ld a,(hl)
  182.         out (GSDAT),a
  183.         WD
  184.         inc hl
  185.         dec bc
  186.         ld a,b
  187.         or c
  188.         jr nz,.uploadloop
  189.         jr .loadchunk
  190.  
  191. .doneloading
  192.         call closestream_file
  193. ;close stream
  194.         SC 0xD2
  195.         WC
  196. ;play module
  197.         ld a,1
  198.         out (GSDAT),a
  199.         SC 0x31
  200.         WC
  201.  
  202.         xor a
  203.         ld (patternindex),a
  204.         ret
  205.  
  206. musicunload
  207.         ld a,(isplayingmodfile)
  208.         or a
  209.         jr nz,unloadmod
  210.  
  211.         call closestream_file
  212.         jp gscodereset
  213.  
  214. unloadmod
  215.         SC 0xf3
  216.         WC
  217.         ret
  218.  
  219. musicplay
  220. ;out: zf=0 if still playing, zf=1 otherwise
  221. isplayingmodfile=$+1
  222.         ld a,0
  223.         or a
  224.         jr nz,playmod
  225.  
  226. bufferreadptr=$+1
  227.         ld hl,0
  228. bufferdataleft=$+1
  229.         ld bc,0
  230.         ld a,c
  231.         or b
  232.         jr nz,checkifcanupload
  233. readfilechunk
  234.         ld hl,(paddingframecount)
  235.         ld de,150
  236.         sub hl,de
  237.         sbc a
  238.         ret z
  239.         call readdata
  240.         ld hl,BUFADDR
  241.         ex de,hl
  242.         sub hl,de
  243.         ld b,l
  244.         dec hl
  245.         inc h
  246.         ld c,h
  247.         ex de,hl
  248.         jr checkifcanupload
  249.  
  250. uploaddataloop
  251.         ld a,(hl)
  252.         out (GSDAT),a
  253.         WD
  254.         inc hl
  255.         djnz uploaddataloop
  256.         dec c
  257.         jr z,readfilechunk          ;done uploading current chunk
  258.         bit 0,c
  259.         jr z,uploaddataloop         ;poll GS once per 512 bytes
  260. checkifcanupload
  261.         SC CMDGETFREEBUFFERSPACE
  262.         WC
  263.         WN
  264.         GD
  265.         cp 6
  266.         jr nc,uploaddataloop        ;keep uploading until we have less than 1024 free buffer space
  267.  
  268.         ld (bufferreadptr),hl
  269.         ld (bufferdataleft),bc
  270.  
  271.         YIELD
  272.  
  273.         or 1
  274.         ret
  275.  
  276. playmod
  277.         YIELD
  278. ;read pattern index
  279.         SC 0x60
  280.         WC
  281.         WN
  282.         GD
  283. ;check if the index is increasing monotonically
  284.         ld hl,patternindex
  285.         cp (hl)
  286.         ld (hl),a
  287.         ccf
  288.         sbc a
  289.         ret
  290.  
  291. readdata
  292. ;out: de = past-the-end data pointer
  293.         ld hl,(paddingframecount)
  294.         ld a,l
  295.         or h
  296.         ld hl,BUFSIZE
  297.         ld de,BUFADDR
  298.         jr nz,writepadding
  299.         call readstream_file
  300.         ld bc,hl
  301.         ld hl,BUFADDR
  302.         add hl,bc
  303.         ex de,hl
  304.         ld hl,BUFSIZE
  305.         sub hl,bc
  306.         ret z
  307. writepadding
  308.         ld bc,paddingframedata_end-paddingframedata
  309.         sub hl,bc
  310.         ret c
  311.         push hl
  312. paddingframedataptr=$+1
  313.         ld hl,0
  314.         ldir
  315.         ld hl,paddingframedata
  316.         ld (paddingframedataptr),hl
  317. paddingframecount=$+1
  318.         ld hl,0
  319.         inc hl
  320.         ld (paddingframecount),hl
  321.         pop hl
  322.         jr writepadding
  323.  
  324. gshardreset
  325. ;out: b!=0 if got reply from GS, b==0 otherwise
  326.         ld a,C_GRST
  327.         out (GSCTR),a               ;hw reset
  328.         YIELD
  329.         YIELD
  330.         YIELD
  331. gssoftreset
  332.         SC 0xf3                     ;GS reset
  333.         ld b,50                     ;max spins
  334. wcloop
  335.         push bc
  336.         YIELD
  337.         pop bc
  338.         dec b
  339.         ret z
  340.         in a,(GSCOM)
  341.         rrca
  342.         jr c,wcloop
  343.         ret
  344.  
  345. gsstartcode
  346.         ld bc,GSDAT
  347.         ld de,gscode_end-gscode
  348.         ld hl,GSPROGSTART
  349.         out (c),e
  350.         SC 0x14
  351.         WC
  352.         out (c),d
  353.         WD
  354.         out (c),l
  355.         WD
  356.         out (c),h
  357.         WD
  358. ;start upload
  359.         ld hl,gscode
  360. .uploadloop
  361.         outi
  362.         WD
  363.         dec de
  364.         ld a,d
  365.         or e
  366.         jr nz,.uploadloop
  367. ;launch the code
  368.         ld hl,GSPROGSTART
  369.         out (c),l
  370.         SC 0x13
  371.         WC
  372.         out (c),h
  373.         WD
  374. ;the code is starting
  375.         YIELD
  376.         YIELD
  377.         YIELD
  378.         ret
  379.  
  380. gscodereset
  381.         SC CMDRESET
  382.         WC
  383.         ret
  384.  
  385. firstpaddingframedata
  386.         db 0xFF,0xFB,0x90,0x64,0x00,0x0F,0xF0,0x00,0x00
  387.         db 0x69,0x00,0x00,0x00,0x08,0x00,0x00,0x0D,0x20
  388.         db 0x00,0x00,0x01,0x00,0x00,0x01,0xA4,0x00,0x00
  389.         db 0x00,0x20,0x00,0x00,0x34,0x80,0x00,0x00,0x04
  390.         ds 381,0x55
  391. firstpaddingframedata_end
  392.  
  393. paddingframedata
  394.         db 0xFF,0xFB,0x90,0x64,0x40,0x8F,0xF0,0x00,0x00
  395.         db 0x69,0x00,0x00,0x00,0x08,0x00,0x00,0x0D,0x20
  396.         db 0x00,0x00,0x01,0x00,0x00,0x01,0xA4,0x00,0x00
  397.         db 0x00,0x20,0x00,0x00,0x34,0x80,0x00,0x00,0x04
  398.         ds 381,0x55
  399. paddingframedata_end
  400.  
  401. gscode
  402.         incbin "gscode.bin"
  403. gscode_end
  404.  
  405.         include "../_sdk/file.asm"
  406.  
  407. playernamestr
  408.         db "GS/NGS",0
  409. end
  410.  
  411. patternindex
  412.         db 0
  413.  
  414.         savebin "mp3.bin",begin,end-begin
  415.