?login_element?

Subversion Repositories NedoOS

Rev

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

  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. ;out: zf=1 if this player can handle the file and the sound hardware is available, zf=0 otherwise
  18. isgsdisabled=$+1
  19.         jr nosupportedfiles
  20.         call ismodfile
  21.         jr nz,checkmid
  22.         ld hl,0
  23.         ld (MUSICTITLEADDR),hl
  24.         ld hl,musicprogress+1
  25.         ld (MUSICPROGRESSADDR),hl
  26.         jp initprogress
  27. nosupportedfiles
  28.         or 1
  29.         ret
  30. checkmid
  31. vsversion=$+1
  32.         ld a,255
  33.         ld l,'m'
  34.         ld h,b
  35.         sub hl,bc
  36.         jr nz,checkogg
  37.         ld hl,'id'
  38.         sub hl,de
  39.         jr nz,checkogg
  40.         cp SS_VER_VS1003
  41.         jr z,initmidvars
  42.         cp SS_VER_VS1033
  43.         jr z,initmidvars
  44.         cp SS_VER_VS1053
  45.         jr z,initmidvars
  46.         cp SS_VER_VS1103
  47.         ret nz
  48. initmidvars
  49.         ld (filechunkcounter),hl
  50.         ld (MUSICTITLEADDR),hl
  51.         ld (MUSICPROGRESSADDR),hl
  52.         jp initprogress
  53. checkogg
  54.         ld l,'o'
  55.         ld h,b
  56.         sub hl,bc
  57.         jr nz,checkaac
  58.         ld hl,'gg'
  59.         sub hl,de
  60.         jr nz,checkaac
  61.         cp SS_VER_VS1053
  62.         jr z,initmp3vars
  63.         cp SS_VER_VS1063
  64.         jr z,initmp3vars
  65.         ret    
  66. checkaac
  67.         ld l,'a'
  68.         ld h,b
  69.         sub hl,bc
  70.         jr nz,checkmp3
  71.         ld hl,'ac'
  72.         sub hl,de
  73.         jr nz,checkmp3
  74.         cp SS_VER_VS1033
  75.         jr z,initmp3vars
  76.         cp SS_VER_VS1053
  77.         jr z,initmp3vars
  78.         cp SS_VER_VS1063
  79.         jr z,initmp3vars
  80.         ret
  81. checkmp3
  82.         ld l,'m'
  83.         ld h,b
  84.         sub hl,bc
  85.         ret nz
  86.         ld hl,'p3'
  87.         sub hl,de
  88.         ret nz
  89.         and ~SS_VER_MASK
  90.         ret nz
  91. initmp3vars
  92.         ld (filechunkcounter),hl
  93.         ld (MUSICTITLEADDR),hl
  94.         ld hl,musicprogress+1
  95.         ld (MUSICPROGRESSADDR),hl
  96.         jp initprogress
  97.  
  98. ismodfile
  99. ;cde = file extension
  100. ;out: zf=1 if .mod, zf=0 otherwise
  101.         ld a,'m'
  102.         cp c
  103.         ret nz
  104.         ld a,'o'
  105.         cp d
  106.         ret nz
  107.         ld a,'d'
  108.         cp e
  109.         ret
  110.  
  111. playerinit
  112. ;hl = shared pages
  113. ;a = player page
  114. ;out: zf=1 if init is successful, hl=init message
  115.         ld a,(hl)
  116.         ld (page8000),a
  117.         inc hl
  118.         ld a,(hl)
  119.         ld (pageC000),a
  120.  
  121. ;       call gssoftreset
  122. ;b==0 if no reply from GS
  123. ;       dec b
  124. ;       inc b
  125. ;       call z,gshardreset
  126.         call gshardreset
  127. ;b==0 if no reply from GS
  128.         ld a,b
  129.         cp 1
  130.         ld hl,nodevicestr
  131.         ret c
  132.  
  133. ;get chip id
  134.         call gsstartcode
  135.         SC CMDGETCHIPID
  136.         WC
  137.         WN
  138.         GD
  139.         ld (vsversion),a
  140.         call gscodereset
  141.  
  142.         ld a,(vsversion)
  143.         cp SS_VER_VS1103+1
  144.         ld hl,gsinitok
  145.         jr nc,.gsonly
  146.         rrca
  147.         rrca
  148.         add a,idtostr%256
  149.         ld l,a
  150.         adc a,idtostr/256
  151.         sub l
  152.         ld h,a
  153.         ld de,chipidstr
  154.         ld bc,4
  155.         ldir
  156.         ld hl,ngsinitokstr
  157. .gsonly
  158.         xor a
  159.         ld (isgsdisabled),a
  160.         ret
  161.  
  162. playerdeinit
  163.         ret
  164.  
  165. musicload
  166. ;cde = file extension
  167. ;hl = input file name
  168. ;out: zf=1 if the file is ready for playing, zf=0 otherwise
  169.         call ismodfile
  170.         ld a,1
  171.         jr z,$+3
  172.         dec a
  173.         ld (isplayingmodfile),a
  174.  
  175.         ex de,hl
  176.         call openstream_file
  177.         or a
  178.         ret nz
  179.  
  180. page8000=$+1
  181.         ld a,0
  182.         SETPG8000
  183. pageC000=$+1
  184.         ld a,0
  185.         SETPGC000
  186.  
  187.         ld a,(isplayingmodfile)
  188.         or a
  189.         jr nz,loadmod
  190.  
  191.         ld a,(filehandle)
  192.         ld b,a
  193.         OS_GETFILESIZE
  194.         ld a,e
  195.         call setprogressdelta
  196.  
  197.         call gsstartcode
  198.  
  199.         ld hl,firstpaddingframedata
  200.         ld (paddingframedataptr),hl
  201.         ld hl,0
  202.         ld (paddingframecount),hl
  203.         ld (bufferdataleft),hl
  204.  
  205.         xor a
  206.         ret
  207.  
  208. TITLELENGTH = 64
  209. MODHEADERSIZE = 1084
  210.  
  211. loadmod
  212.         ld hl,MODHEADERSIZE
  213.         ld de,BUFADDR
  214.         call readstream_file
  215. ;init progress
  216.         call getmodtype
  217.         ld a,(BUFADDR+950)
  218.         jr z,$+5
  219.         ld a,(BUFADDR+470)
  220.         call setprogressdelta
  221. ;set title
  222.         ld hl,titlestr
  223.         ld (MUSICTITLEADDR),hl
  224.         ld de,BUFADDR
  225.         ld b,TITLELENGTH+1
  226. .copytitleloop
  227.         ld a,(de)
  228.         ld (hl),a
  229.         inc de
  230.         inc hl
  231.         dec b
  232.         or a
  233.         jr nz,.copytitleloop
  234.         dec hl
  235. .filltitleloop
  236.         ld (hl),' '
  237.         inc hl
  238.         djnz .filltitleloop
  239.         ld (hl),0
  240. ;load module
  241.         SC 0x30
  242.         WC
  243. ;open stream
  244.         SC 0xD1
  245.         WC
  246. ;upload file
  247.         ld hl,BUFADDR
  248.         ld bc,MODHEADERSIZE
  249. .uploadloop
  250.         ld a,(hl)
  251.         out (GSDAT),a
  252.         WD
  253.         inc hl
  254.         dec bc
  255.         ld a,b
  256.         or c
  257.         jr nz,.uploadloop
  258.         ld hl,BUFSIZE
  259.         ld de,BUFADDR
  260.         push de
  261.         call readstream_file
  262.         ex (sp),hl
  263.         pop bc
  264.         ld a,b
  265.         or c
  266.         jr nz,.uploadloop
  267.         call closestream_file
  268. ;close stream
  269.         SC 0xD2
  270.         WC
  271. ;play module
  272.         ld a,1
  273.         out (GSDAT),a
  274.         SC 0x31
  275.         WC
  276.         xor a
  277.         ld (currentposition),a
  278.         ret
  279.  
  280. musicunload
  281.         ld a,(isplayingmodfile)
  282.         or a
  283.         jr nz,unloadmod
  284.  
  285.         call closestream_file
  286.         jp gscodereset
  287.  
  288. unloadmod
  289.         SC 0xf3
  290.         WC
  291.         ret
  292.  
  293. musicplay
  294. ;out: zf=0 if still playing, zf=1 otherwise
  295. isplayingmodfile=$+1
  296.         ld a,0
  297.         or a
  298.         jr nz,playmod
  299.  
  300. bufferreadptr=$+1
  301.         ld hl,0
  302. bufferdataleft=$+1
  303.         ld bc,0
  304.         ld a,c
  305.         or b
  306.         jr nz,checkifcanupload
  307. readfilechunk
  308.         ld hl,(paddingframecount)
  309.         ld de,150
  310.         sub hl,de
  311.         sbc a
  312.         ret z
  313.         call readdata
  314.         ld hl,BUFADDR
  315.         ex de,hl
  316.         sub hl,de
  317.         ld b,l
  318.         dec hl
  319.         inc h
  320.         ld c,h
  321.         ex de,hl
  322.         jr checkifcanupload
  323.  
  324. uploaddataloop
  325.         ld a,(hl)
  326.         out (GSDAT),a
  327.         WD
  328.         inc hl
  329.         djnz uploaddataloop
  330.         dec c
  331.         jr z,readfilechunk          ;done uploading current chunk
  332.         bit 0,c
  333.         jr z,uploaddataloop         ;poll GS once per 512 bytes
  334. checkifcanupload
  335.         SC CMDGETFREEBUFFERSPACE
  336.         WC
  337.         WN
  338.         GD
  339.         cp 6
  340.         jr nc,uploaddataloop        ;keep uploading until we have less than 1024 free buffer space
  341.  
  342.         ld (bufferreadptr),hl
  343.         ld (bufferdataleft),bc
  344.  
  345.         YIELD
  346.  
  347.         or 1
  348.         ret
  349.  
  350. playmod
  351.         YIELD
  352.         YIELD
  353.         YIELD
  354.         YIELD
  355. ;update progress
  356.         SC 0x60
  357.         WC
  358.         WN
  359.         GD
  360.         push af
  361.         call updateprogress
  362.         pop af
  363. ;check if the position is increasing monotonically
  364.         ld hl,currentposition
  365.         cp (hl)
  366.         ld (hl),a
  367.         ccf
  368.         sbc a
  369.         ret
  370.  
  371. readdata
  372. ;out: de = past-the-end data pointer
  373.         ld hl,(paddingframecount)
  374.         ld a,l
  375.         or h
  376.         ld hl,BUFSIZE
  377.         ld de,BUFADDR
  378.         jr nz,writepadding
  379.         call readstream_file
  380.         ld bc,hl
  381.         ld hl,BUFADDR
  382.         add hl,bc
  383.         ex de,hl
  384.         ld hl,BUFSIZE
  385.         sub hl,bc
  386.         jr nz,writepadding
  387. ;update progress
  388.         ld hl,(filechunkcounter)
  389.         ld de,BUFSIZE>>8 ;256 bytes chunks
  390.         add hl,de
  391.         ld (filechunkcounter),hl
  392.         ld a,h
  393.         call updateprogress
  394.         ld de,(BUFADDR+BUFSIZE)%65536
  395.         ret
  396.  
  397. writepadding
  398.         ld bc,paddingframedata_end-paddingframedata
  399.         sub hl,bc
  400.         ret c
  401.         push hl
  402. paddingframedataptr=$+1
  403.         ld hl,0
  404.         ldir
  405.         ld hl,paddingframedata
  406.         ld (paddingframedataptr),hl
  407. paddingframecount=$+1
  408.         ld hl,0
  409.         inc hl
  410.         ld (paddingframecount),hl
  411.         pop hl
  412.         jr writepadding
  413.  
  414. gshardreset
  415. ;out: b!=0 if got reply from GS, b==0 otherwise
  416.         ld a,C_GRST
  417.         out (GSCTR),a               ;hw reset
  418.         YIELD
  419.         YIELD
  420.         YIELD
  421. gssoftreset
  422.         SC 0xf3                     ;GS reset
  423.         ld b,50                     ;max spins
  424. wcloop
  425.         push bc
  426.         YIELD
  427.         pop bc
  428.         dec b
  429.         ret z
  430.         in a,(GSCOM)
  431.         rrca
  432.         jr c,wcloop
  433.         ret
  434.  
  435. gsstartcode
  436.         ld bc,GSDAT
  437.         ld de,gscode_end-gscode
  438.         ld hl,GSPROGSTART
  439.         out (c),e
  440.         SC 0x14
  441.         WC
  442.         out (c),d
  443.         WD
  444.         out (c),l
  445.         WD
  446.         out (c),h
  447.         WD
  448. ;start upload
  449.         ld hl,gscode
  450. .uploadloop
  451.         outi
  452.         WD
  453.         dec de
  454.         ld a,d
  455.         or e
  456.         jr nz,.uploadloop
  457. ;launch the code
  458.         ld hl,GSPROGSTART
  459.         out (c),l
  460.         SC 0x13
  461.         WC
  462.         out (c),h
  463.         WD
  464. ;the code is starting
  465.         YIELD
  466.         YIELD
  467.         YIELD
  468.         ret
  469.  
  470. getmodtype
  471. ;https://github.com/psbhlw/gs-firmware/blob/6c783a56147511b43d197e4079e993c2b94b4f12/firmware/src/PLAY.a80#L27
  472. ;out: zf=0 for SoundTracker 4/15 file, zf=1 otherwise
  473.         LD A,(BUFADDR+1080)
  474.         CP "M"
  475.         JR Z,TTY1
  476.         CP "4"
  477.         JR Z,TTY1
  478.         CP "F"
  479.         JR Z,TTY1
  480.         ret
  481. TTY1    LD A,(BUFADDR+1081)
  482.         CP "."
  483.         JR Z,TTY2
  484.         CP "L"
  485.         JR Z,TTY2
  486.         CP "!"
  487.         JR Z,TTY2
  488.         CP "C"
  489.         JR Z,TTY2
  490.         ret
  491. TTY2    LD A,(BUFADDR+1082)
  492.         CP "K"
  493.         ret z
  494.         CP "T"
  495.         ret z
  496.         CP "H"
  497.         ret
  498.  
  499. gscodereset
  500.         SC CMDRESET
  501.         WC
  502.         ret
  503.  
  504. firstpaddingframedata
  505.         db 0xFF,0xFB,0x90,0x64,0x00,0x0F,0xF0,0x00,0x00
  506.         db 0x69,0x00,0x00,0x00,0x08,0x00,0x00,0x0D,0x20
  507.         db 0x00,0x00,0x01,0x00,0x00,0x01,0xA4,0x00,0x00
  508.         db 0x00,0x20,0x00,0x00,0x34,0x80,0x00,0x00,0x04
  509.         ds 381,0x55
  510. firstpaddingframedata_end
  511.  
  512. paddingframedata
  513.         db 0xFF,0xFB,0x90,0x64,0x40,0x8F,0xF0,0x00,0x00
  514.         db 0x69,0x00,0x00,0x00,0x08,0x00,0x00,0x0D,0x20
  515.         db 0x00,0x00,0x01,0x00,0x00,0x01,0xA4,0x00,0x00
  516.         db 0x00,0x20,0x00,0x00,0x34,0x80,0x00,0x00,0x04
  517.         ds 381,0x55
  518. paddingframedata_end
  519.  
  520. gscode
  521.         incbin "gscode.bin"
  522. gscode_end
  523.  
  524.         include "../_sdk/file.asm"
  525.         include "progress.asm"
  526.  
  527. SS_VER_VS1001 = 0x00
  528. SS_VER_VS1011 = 0x10
  529. SS_VER_VS1002 = 0x20
  530. SS_VER_VS1003 = 0x30
  531. SS_VER_VS1053 = 0x40
  532. SS_VER_VS8053 = 0x40
  533. SS_VER_VS1033 = 0x50
  534. SS_VER_VS1063 = 0x60
  535. SS_VER_VS1103 = 0x70
  536.  
  537. idtostr
  538.         db "1001"
  539.         db "1011"
  540.         db "1002"
  541.         db "1003"
  542.         db "1053"
  543.         db "1033"
  544.         db "1063"
  545. ngsinitokstr
  546.         db "NeoGS with VS"
  547. chipidstr
  548.         db "????\r\n",0
  549. gsinitok
  550.         db "GS\r\n",0
  551. nodevicestr
  552.         db "no device!\r\n",0
  553. playernamestr
  554.         db "GS/NeoGS",0
  555. end
  556.  
  557. currentposition
  558.         ds 1
  559. filechunkcounter
  560.         ds 2
  561. titlestr
  562.         ds TITLELENGTH+1
  563.  
  564.         savebin "mp3.bin",begin,end-begin
  565.