Subversion Repositories NedoOS

Rev

Rev 1712 | 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. vsversion=$+1
  18.         ld a,255
  19.         ld l,'m'
  20.         ld h,b
  21.         sub hl,bc
  22.         jr nz,checkogg
  23.         ld hl,'id'
  24.         sub hl,de
  25.         jr nz,checkogg
  26.         cp SS_VER_VS1003
  27.         ret z
  28.         cp SS_VER_VS1033
  29.         ret z
  30.         cp SS_VER_VS1053
  31.         ret z
  32.         cp SS_VER_VS1103
  33.         ret
  34. checkogg
  35.         ld l,'o'
  36.         ld h,b
  37.         sub hl,bc
  38.         jr nz,checkaac
  39.         ld hl,'gg'
  40.         sub hl,de
  41.         jr nz,checkaac
  42.         cp SS_VER_VS1053
  43.         ret z
  44.         cp SS_VER_VS1063
  45.         ret    
  46. checkaac
  47.         ld l,'a'
  48.         ld h,b
  49.         sub hl,bc
  50.         jr nz,checkmp3
  51.         ld hl,'ac'
  52.         sub hl,de
  53.         jr nz,checkmp3
  54.         cp SS_VER_VS1033
  55.         ret z
  56.         cp SS_VER_VS1053
  57.         ret z
  58.         cp SS_VER_VS1063
  59.         ret
  60. checkmp3
  61.         ld l,'m'
  62.         ld h,b
  63.         sub hl,bc
  64.         ret nz
  65.         ld hl,'p3'
  66.         sub hl,de
  67.         ret nz
  68.         and ~SS_VER_MASK
  69.         ret
  70.  
  71. playerinit
  72. ;hl = shared pages
  73. ;a = player page
  74.         ld a,(hl)
  75.         ld (page8000),a
  76.         inc hl
  77.         ld a,(hl)
  78.         ld (pageC000),a
  79.  
  80. ;       call gssoftreset
  81. ;b==0 if no reply from GS
  82. ;       dec b
  83. ;       inc b
  84. ;       call z,gshardreset
  85.         call gshardreset
  86. ;b==0 if no reply from GS
  87.         ld a,b
  88.         cp 1
  89.         ret c
  90.  
  91.         ld bc,GSDAT
  92.         ld de,gscode_end-gscode
  93.         ld hl,GSPROGSTART
  94.         out (c),e
  95.         SC 0x14
  96.         WC
  97.         out (c),d
  98.         WD
  99.         out (c),l
  100.         WD
  101.         out (c),h
  102.         WD
  103. ;start upload
  104.         ld hl,gscode
  105. uploadcodeloop
  106.         outi
  107.         WD
  108.         dec de
  109.         ld a,d
  110.         or e
  111.         jr nz,uploadcodeloop
  112. ;launch the code
  113.         ld hl,GSPROGSTART
  114.         out (c),l
  115.         SC 0x13
  116.         WC
  117.         out (c),h
  118.         WD
  119. ;the code is starting
  120.         YIELD
  121.         YIELD
  122.         YIELD
  123. ;get chip id
  124.         SC CMDGETCHIPID
  125.         WC
  126.         WN
  127.         GD
  128.         ld (vsversion),a
  129.  
  130.         xor a
  131.         ret
  132.  
  133. playerdeinit
  134.         ld a,(vsversion)
  135.         inc a
  136.         ret z
  137.         SC CMDRESTART
  138.         ret
  139.  
  140. musicload
  141. ;de = input file name
  142.         call openstream_file
  143.         or a
  144.         ret nz
  145.  
  146. page8000=$+1
  147.         ld a,0
  148.         SETPG8000
  149. pageC000=$+1
  150.         ld a,0
  151.         SETPGC000
  152.  
  153.         ld hl,firstpaddingframedata
  154.         ld (paddingframedataptr),hl
  155.         ld hl,0
  156.         ld (paddingframecount),hl
  157.         ld (bufferdataleft),hl
  158.  
  159.         xor a
  160.         ret
  161.  
  162. musicunload
  163.         call closestream_file
  164.  
  165.         SC CMDRESTARTSTREAM
  166.         WC
  167.         ret
  168.  
  169. musicplay
  170. ;out: zf=0 if still playing, zf=1 otherwise
  171. bufferreadptr=$+1
  172.         ld hl,0
  173. bufferdataleft=$+1
  174.         ld bc,0
  175.         ld a,c
  176.         or b
  177.         jr nz,checkifcanupload
  178. readfilechunk
  179.         ld hl,(paddingframecount)
  180.         ld de,150
  181.         sub hl,de
  182.         sbc a
  183.         ret z
  184.         call readdata
  185.         ld hl,BUFADDR
  186.         ex de,hl
  187.         sub hl,de
  188.         ld b,l
  189.         dec hl
  190.         inc h
  191.         ld c,h
  192.         ex de,hl
  193.         jr checkifcanupload
  194.  
  195. uploaddataloop
  196.         ld a,(hl)
  197.         out (GSDAT),a
  198.         WD
  199.         inc hl
  200.         djnz uploaddataloop
  201.         dec c
  202.         jr z,readfilechunk            ;done uploading current chunk
  203.         bit 0,c
  204.         jr z,uploaddataloop          ;poll GS once per 512 bytes
  205. checkifcanupload
  206.         SC CMDGETFREEBUFFERSPACE
  207.         WC
  208.         WN
  209.         GD
  210.         cp 6
  211.         jr nc,uploaddataloop        ;keep uploading until we have less than 1024 free buffer space
  212.  
  213.         ld (bufferreadptr),hl
  214.         ld (bufferdataleft),bc
  215.  
  216.         YIELD
  217.  
  218.         or 1
  219.         ret
  220.  
  221. readdata
  222. ;out: de = past-the-end data pointer
  223.         ld hl,(paddingframecount)
  224.         ld a,l
  225.         or h
  226.         ld hl,BUFSIZE
  227.         ld de,BUFADDR
  228.         jr nz,writepadding
  229.         call readstream_file
  230.         ld bc,hl
  231.         ld hl,BUFADDR
  232.         add hl,bc
  233.         ex de,hl
  234.         ld hl,BUFSIZE
  235.         sub hl,bc
  236.         ret z
  237. writepadding
  238.         ld bc,paddingframedata_end-paddingframedata
  239.         sub hl,bc
  240.         ret c
  241.         push hl
  242. paddingframedataptr=$+1
  243.         ld hl,0
  244.         ldir
  245.         ld hl,paddingframedata
  246.         ld (paddingframedataptr),hl
  247. paddingframecount=$+1
  248.         ld hl,0
  249.         inc hl
  250.         ld (paddingframecount),hl
  251.         pop hl
  252.         jr writepadding
  253.  
  254. gshardreset
  255. ;out: b!=0 if got reply from GS, b==0 otherwise
  256.         ld a,C_GRST
  257.         out (GSCTR),a              ;hw reset
  258.         YIELD
  259.         YIELD
  260.         YIELD
  261. gssoftreset
  262.         SC 0xf3                  ;GS reset
  263.         ld b,0x30                      ;max spins
  264. wcloop
  265.         push bc
  266.         YIELD
  267.         pop bc
  268.         dec b
  269.         ret z
  270.         in a,(GSCOM)
  271.         rrca
  272.         jr c,wcloop
  273.         ret
  274.        
  275. firstpaddingframedata
  276.         db 0xFF,0xFB,0x90,0x64,0x00,0x0F,0xF0,0x00,0x00
  277.         db 0x69,0x00,0x00,0x00,0x08,0x00,0x00,0x0D,0x20
  278.         db 0x00,0x00,0x01,0x00,0x00,0x01,0xA4,0x00,0x00
  279.         db 0x00,0x20,0x00,0x00,0x34,0x80,0x00,0x00,0x04
  280.         ds 381,0x55
  281. firstpaddingframedata_end
  282.  
  283. paddingframedata
  284.         db 0xFF,0xFB,0x90,0x64,0x40,0x8F,0xF0,0x00,0x00
  285.         db 0x69,0x00,0x00,0x00,0x08,0x00,0x00,0x0D,0x20
  286.         db 0x00,0x00,0x01,0x00,0x00,0x01,0xA4,0x00,0x00
  287.         db 0x00,0x20,0x00,0x00,0x34,0x80,0x00,0x00,0x04
  288.         ds 381,0x55
  289. paddingframedata_end
  290.  
  291. gscode
  292.         incbin "gscode.bin"
  293. gscode_end
  294.  
  295.         include "../_sdk/file.asm"
  296. end
  297.  
  298.         savebin "mp3.bin",begin,end-begin
  299.