?login_element?

Subversion Repositories NedoOS

Rev

Rev 1818 | Rev 1993 | 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 "playerdefs.asm"
  4.  
  5. NUM_PLAYERS = 5
  6. SFN_SIZE = 13
  7. FILE_DATA_SIZE = 52 ;keep in sync with getfiledataoffset
  8. FILE_DISPLAY_INFO_OFFSET = 0
  9. FILE_DISPLAY_INFO_SIZE = 38
  10. FILE_NAME_OFFSET = FILE_DISPLAY_INFO_OFFSET+FILE_DISPLAY_INFO_SIZE
  11. FILE_NAME_SIZE = SFN_SIZE
  12. FILE_ATTRIB_OFFSET = FILE_NAME_OFFSET+FILE_NAME_SIZE
  13. FILE_ATTRIB_SIZE = 1
  14. BROWSER_FILE_COUNT=177
  15. PLAYLIST_FILE_COUNT=40
  16. PANELCOLOR = 0x4f
  17. CURSORCOLOR = 0x28
  18. PANELFILECOLOR = 0x0f
  19. PANELDIRCOLOR = 0x4f
  20. PANELDRIVECOLOR = 0x4b
  21. FILE_LINE_COUNT = 22
  22. FILES_WINDOW_X = 0
  23. FILE_ATTRIB_MUSIC = 255
  24. FILE_ATTRIB_PARENT_DIR = 0
  25. FILE_ATTRIB_DRIVE = 1
  26. FILE_ATTRIB_FOLDER = 2
  27. PLAYLIST_VERSION = 1
  28.  
  29.         org PROGSTART
  30.  
  31. mainbegin
  32.         ld sp,0x4000
  33.         OS_HIDEFROMPARENT
  34.         ld e,6 ;textmode
  35.         OS_SETGFX
  36.         ld e,7
  37.         OS_CLS
  38.  
  39.         OS_GETMAINPAGES ;out: d,e,h,l=pages in 0000,4000,8000,c000, c=flags, b=id
  40.         ld (gpsettings.sharedpages),hl
  41.         ld a,e
  42.         ld (gpsettings.sharedpages+2),a
  43.         ld d,b
  44.         call closeexistingplayer
  45.  
  46.         ld de,currentfolder
  47.         OS_GETPATH
  48.         ld hl,(currentfolder+2)
  49.         ld a,l
  50.         xor '/'
  51.         or h
  52.         jr nz,$+5
  53.         ld (currentfolder+2),a
  54.  
  55.         OS_SETSYSDRV
  56.         call loadsettings
  57.         call loadplayers
  58.         jp nz,printerrorandexit
  59.  
  60.         ld ix,browserpanel
  61.         call clearpanel
  62.         ld ix,playlistpanel
  63.         call clearpanel
  64.         or 255 ;set zf=0
  65.         call setcurrentpanel
  66.  
  67.         ld de,defaultplaylistfilename
  68.         call loadplaylist
  69.  
  70.         ld hl,COMMANDLINE
  71.         call skipword_hl
  72.         call skipspaces_hl
  73.         ld a,(hl)
  74.         or a
  75.         call nz,setcurrentfolder
  76.         push hl
  77.         call changetocurrentfolder
  78.         pop de
  79.         ld hl,chdirfailedstr
  80.         jp nz,printerrorandexit
  81.         push de
  82.         call createfileslist
  83.         pop de
  84.         ld a,(de)
  85.         or a
  86.         call nz,findfile
  87.         ld (browserpanel.currentfileindex),a
  88.         push af
  89.         call drawui
  90.         pop af
  91.         call c,startplaying
  92.  
  93. playloop
  94. isplaying=$+1
  95.         ld a,0
  96.         or a
  97.         jr z,checkmsgs
  98.         call musicplay
  99.         call z,playnextfile
  100.         call updateprogressbar
  101.  
  102. checkmsgs
  103.         ld a,(COMMANDLINE)
  104.         or a
  105.         ld a,key_esc
  106.         jr z,closeplayer
  107.         OS_GETKEY
  108.         call tolower
  109. closeplayer
  110.         ld hl,playloop
  111.         push hl
  112. currentmsgtable=$+1
  113.         ld hl,mainmsgtable
  114.         ld de,3
  115.         ld b,(hl)
  116.         inc hl
  117. checkmsgloop
  118.         cp (hl)
  119.         jr z,processmsg
  120.         add hl,de
  121.         djnz checkmsgloop
  122.         ret
  123.  
  124. processmsg
  125.         inc hl
  126.         ld e,(hl)
  127.         inc hl
  128.         ld d,(hl)
  129.         ex de,hl
  130.         jp (hl)
  131.  
  132. printerrorandexit
  133.         call print_hl
  134.         ld hl,pressanykeystr
  135.         call print_hl
  136.         YIELDGETKEYLOOP
  137.         QUIT
  138.  
  139. mainmsgtable
  140.         db (mainmsghandlers_end-mainmsghandlers_start)/3
  141. mainmsghandlers_start
  142.         db 0             : dw nokey
  143.         db key_redraw    : dw redraw
  144.         db key_up        : dw goprevfile
  145.         db key_down      : dw gonextfile
  146.         db key_enter     : dw startplaying
  147.         db key_esc       : dw exitplayer
  148.         db ' '           : dw addtoplaylist
  149.         db key_tab       : dw switchpanels
  150.         db key_backspace : dw clearplaylist
  151.         db key_home      : dw gotop
  152.         db key_end       : dw golastfile
  153.         db key_left      : dw gopageup
  154.         db key_right     : dw gopagedown
  155.         db key_pgup      : dw gopageup
  156.         db key_pgdown    : dw gopagedown
  157.         db 's'           : dw onhotkeyS
  158. mainmsghandlers_end
  159.  
  160. playmsgtable
  161.         db (playmsghandlers_end-playmsghandlers_start)/3
  162. playmsghandlers_start
  163.         db key_redraw    : dw redraw
  164.         db ' '           : dw playnextfile
  165.         db key_esc       : dw stopplaying
  166. playmsghandlers_end
  167.  
  168. nokey
  169.         YIELD
  170.         ret
  171.  
  172. gotop
  173.         ld ix,(currentpaneladdr)
  174.         xor a
  175.         ld (ix+PANEL.currentfileindex),a
  176.         ld (ix+PANEL.firstfiletoshow),a
  177.         jp drawcurrentpanelfilelist
  178.  
  179. clearplaylist
  180.         ld ix,playlistpanel
  181.         call clearpanel
  182.         jp drawplaylistwindow
  183.  
  184. playnextfile
  185.         ld ix,(currentpaneladdr)
  186.         call setnextfileindex
  187.         jp c,startplaying
  188.         xor a
  189.         ld (ix+PANEL.currentfileindex),a
  190.         ld (ix+PANEL.firstfiletoshow),a
  191.         ld hl,(currentpaneladdr)
  192.         ld de,PANEL.fileslist+FILE_ATTRIB_OFFSET
  193.         add hl,de
  194.         ld e,FILE_DATA_SIZE
  195. .wraploop
  196.         ld a,(hl)
  197.         cp FILE_ATTRIB_MUSIC
  198.         jp z,startplaying
  199.         add hl,de
  200.         inc (ix+PANEL.currentfileindex)
  201.         jr .wraploop
  202.  
  203. switchpanels
  204.         ld a,(browserpanel.isinactive)
  205.         or a
  206. setcurrentpanel
  207.         ld a,255
  208.         ld (browserpanel.isinactive),a
  209.         ld (playlistpanel.isinactive),a
  210.         call nz,getbrowserpanelparams
  211.         call z,getplaylistpanelparams
  212.         ld (currentpaneladdr),ix
  213.         ld (currentpanelpos),de
  214.         ld (ix+PANEL.isinactive),0
  215.         call drawbrowserfileslist
  216.         jp drawplaylistfileslist
  217.  
  218. addtoplaylist
  219.         ld a,(browserpanel.isinactive)
  220.         or a
  221.         jr nz,removefromplaylist
  222.         ld hl,currentfolder
  223.         ld de,fullpathbuffer
  224.         call strcopy_hltode
  225.         ld a,'/'
  226.         ld (de),a
  227.         inc de
  228.         push de
  229.         ld a,(browserpanel.currentfileindex)
  230.         call getfiledataoffset
  231.         ld de,browserpanel.fileslist+FILE_ATTRIB_OFFSET
  232.         add hl,de
  233.         ld a,(hl)
  234.         ld de,FILE_NAME_OFFSET-FILE_ATTRIB_OFFSET
  235.         add hl,de
  236.         pop de
  237.         cp FILE_ATTRIB_MUSIC
  238.         ret nz
  239.         call strcopy_hltode
  240.         ld hl,fullpathbuffer+FILE_DATA_SIZE-2
  241.         sub hl,de
  242.         ret c
  243.         jr z,skippadding
  244.         ld bc,hl
  245.         ld hl,de
  246.         inc de
  247.         ldir
  248.         dec de
  249. skippadding
  250.         inc de
  251.         ld a,255
  252.         ld (de),a
  253.         ld hl,playlistpanel.filecount
  254.         ld a,(hl)
  255.         cp PLAYLIST_FILE_COUNT
  256.         ret nc
  257.         inc (hl)
  258.         call getfiledataoffset
  259.         ld de,playlistpanel.fileslist
  260.         add hl,de
  261.         ex de,hl
  262.         ld hl,fullpathbuffer
  263.         ld bc,FILE_DATA_SIZE
  264.         ldir
  265.         jp drawplaylistfileslist
  266.  
  267. removefromplaylist
  268.         ld a,(playlistpanel.filecount)
  269.         or a
  270.         ret z
  271.         dec a
  272.         jp z,clearplaylist
  273.         ld (playlistpanel.filecount),a
  274.         ld b,a
  275.         ld a,(playlistpanel.currentfileindex)
  276.         cp b
  277.         jr nz,.movetail
  278.         dec a
  279.         ld (playlistpanel.currentfileindex),a
  280.         jp drawplaylistwindow
  281. .movetail
  282.         call getfiledataoffset
  283.         ld de,playlistpanel.fileslist
  284.         add hl,de
  285.         ex de,hl
  286.         ld hl,playlistpanel.fileslist+FILE_DATA_SIZE*(PLAYLIST_FILE_COUNT-1)
  287.         sub hl,de
  288.         ld bc,hl
  289.         ld hl,FILE_DATA_SIZE
  290.         add hl,de
  291.         ldir
  292.         jp drawplaylistwindow
  293.  
  294. exitplayer
  295.         pop hl
  296.         call stopplaying
  297.         ld hl,playerpages
  298.         ld a,(playercount)
  299.         ld b,a
  300. playerdeinitloop
  301.         push bc
  302.         push hl
  303.         ld a,(hl)
  304.         SETPG4000
  305.         call playerdeinit
  306.         pop hl
  307.         pop bc
  308.         inc hl
  309.         djnz playerdeinitloop
  310. ;save playlist
  311.         ld a,255
  312.         ld (playlistpanel.isinactive),a
  313.         OS_SETSYSDRV
  314.         ld de,defaultplaylistfilename
  315.         call saveplaylist
  316.         QUIT
  317.  
  318. saveplaylist
  319. ;de = filename
  320.         push de
  321.         call openstream_file
  322.         pop de
  323.         or a
  324.         jr z,.openedfile
  325.         OS_CREATEHANDLE
  326.         or a
  327.         ret nz
  328.         ld a,b
  329.         ld (filehandle),a
  330. .openedfile
  331.         ld a,(filehandle)
  332.         ld b,a
  333.         ld de,playlistdatastart
  334.         ld hl,playlistdatasize
  335.         OS_WRITEHANDLE
  336.         call closestream_file
  337.         xor a
  338.         ret
  339.  
  340. onhotkeyS
  341.         ld de,playlistfilename
  342.         call saveplaylist
  343.         ld de,playlistfilename
  344.         jp createfilelistandchangesel
  345.  
  346. startplaying
  347.         call stopplaying
  348.         ld ix,(currentpaneladdr)
  349.         ld a,(ix+PANEL.filecount)
  350.         or a
  351.         ret z
  352.         ld a,(ix+PANEL.currentfileindex)
  353.         call getfiledataoffset
  354.         ld a,ixl
  355.         add PANEL.fileslist+FILE_ATTRIB_OFFSET
  356.         ld e,a
  357.         adc a,ixh
  358.         sub e
  359.         ld d,a
  360.         add hl,de
  361.         ld a,(hl)
  362.         cp FILE_ATTRIB_PARENT_DIR
  363.         jp z,changetoparentdir
  364.         cp FILE_ATTRIB_FOLDER
  365.         jp z,changetofolder
  366.         cp FILE_ATTRIB_DRIVE
  367.         jr z,changedrive
  368.         cp FILE_ATTRIB_MUSIC
  369.         ret nz
  370.         ld a,(browserpanel.isinactive)
  371.         or a
  372.         ld de,FILE_NAME_OFFSET-FILE_ATTRIB_OFFSET
  373.         jr z,$+5
  374.         ld de,FILE_DISPLAY_INFO_OFFSET-FILE_ATTRIB_OFFSET
  375.         add hl,de
  376.         ld (.filename),hl
  377.         call getfileextension
  378.         ld (.filext2),de
  379.         ld (.filext1),bc
  380.         call isfileplaylist
  381.         jp z,.loadplaylist
  382.         call findsupportedplayer
  383.         ret nz
  384.         call drawplayerwindow
  385. .filext1=$+1
  386.         ld bc,0
  387. .filext2=$+1
  388.         ld de,0
  389. .filename=$+1
  390.         ld hl,0
  391.         call musicload
  392.         jp nz,drawui
  393.         ld hl,playmsgtable
  394.         ld (currentmsgtable),hl
  395.         ld a,1
  396.         ld (isplaying),a
  397.         call drawsongtitle
  398.         jp drawprogress
  399. .loadplaylist
  400.         ld de,(.filename)
  401.         call loadplaylist
  402.         call drawplaylistwindow
  403.         xor a
  404.         call setcurrentpanel
  405.         jp startplaying
  406.  
  407. changedrive
  408.         ld de,FILE_NAME_OFFSET-FILE_ATTRIB_OFFSET
  409.         add hl,de
  410.         push hl
  411.         ld de,(currentfolder)
  412.         push de
  413.         ld de,currentfolder
  414.         ldi
  415.         ldi
  416.         call changetocurrentfolder
  417.         pop hl
  418.         pop de
  419.         jp z,createfilelistandchangesel
  420.         ld (currentfolder),hl
  421.         ret
  422.  
  423. changetoparentdir
  424.         ld hl,currentfolder
  425.         ld c,'/'
  426.         call findlastchar ;out: de = after last slash or start
  427.         push de
  428.         dec de
  429.         xor a
  430.         ld (de),a
  431.         call changetocurrentfolder
  432.         pop de
  433.         jp createfilelistandchangesel
  434.  
  435. createfilelistandchangesel
  436. ;de = selection filename
  437.         push de
  438.         call createfileslist
  439.         pop de
  440.         call findfile
  441.         ld (browserpanel.currentfileindex),a
  442.         sub FILE_LINE_COUNT-1
  443.         jp c,drawbrowserwindow
  444.         ld hl,browserpanel.firstfiletoshow
  445.         cp (hl)
  446.         jp c,drawbrowserwindow
  447.         ld (hl),a
  448.         jp drawbrowserwindow
  449.  
  450. changetofolder
  451.         ld de,FILE_NAME_OFFSET-FILE_ATTRIB_OFFSET
  452.         add hl,de
  453.         ld de,currentfolder-1
  454. .findzeroloop
  455.         inc de
  456.         ld a,(de)
  457.         or a
  458.         jr nz,.findzeroloop
  459.         ld a,'/'
  460.         ld (de),a
  461.         inc de
  462.         call strcopy_hltode
  463.         call changetocurrentfolder
  464.         call createfileslist
  465.         xor a
  466.         ld (browserpanel.currentfileindex),a
  467.         jp drawbrowserwindow
  468.  
  469. stopplaying
  470.         ld a,(isplaying)
  471.         or a
  472.         ret z
  473.         call musicunload
  474.         ld hl,mainmsgtable
  475.         ld (currentmsgtable),hl
  476.         xor a
  477.         ld (isplaying),a
  478.         jp drawui
  479.  
  480. setnextfileindex
  481. ;ix = current panel
  482. ;out: cf=0 if at the end of file list, c1=1 otherwise
  483.         ld a,(ix+PANEL.currentfileindex)
  484.         inc a
  485.         cp (ix+PANEL.filecount)
  486.         ret nc
  487.         ld (ix+PANEL.currentfileindex),a
  488.         sub FILE_LINE_COUNT-1
  489.         ret c
  490.         cp (ix+PANEL.firstfiletoshow)
  491.         ret c
  492.         ld (ix+PANEL.firstfiletoshow),a
  493.         scf
  494.         ret
  495.  
  496. golastfile
  497.         ld ix,(currentpaneladdr)
  498.         call setnextfileindex
  499.         jr c,$-3
  500.         jp drawcurrentpanelfilelist
  501.  
  502. gopagedown     
  503.         ld ix,(currentpaneladdr)
  504.         ld b,FILE_LINE_COUNT
  505.         call setnextfileindex
  506.         djnz $-3
  507.         jp drawcurrentpanelfilelist
  508.  
  509. gonextfile
  510.         ld ix,(currentpaneladdr)
  511.         call setnextfileindex
  512.         ret nc
  513.         jp drawcurrentpanelfilelist
  514.  
  515. setprevfileindex
  516. ;ix = current panel
  517.         ld a,(ix+PANEL.currentfileindex)
  518.         or a
  519.         ret z
  520.         dec a
  521.         ld (ix+PANEL.currentfileindex),a
  522.         cp (ix+PANEL.firstfiletoshow)
  523.         ret nc
  524.         ld (ix+PANEL.firstfiletoshow),a
  525.         ret
  526.  
  527. goprevfile
  528.         ld ix,(currentpaneladdr)
  529.         call setprevfileindex
  530.         jp drawcurrentpanelfilelist
  531.  
  532. gopageup
  533.         ld ix,(currentpaneladdr)
  534.         ld b,FILE_LINE_COUNT
  535.         call setprevfileindex
  536.         djnz $-3
  537.         jp drawcurrentpanelfilelist
  538.  
  539. loadplaylist
  540. ;de = filename
  541.         call openstream_file
  542.         or a
  543.         jr nz,initemptyplaylist
  544.         ld de,playlistdatastart
  545.         ld hl,playlistdatasize
  546.         call readstream_file
  547.         call closestream_file
  548.         ld de,PLAYLIST_VERSION
  549.         ld hl,(playlistpanelversion)
  550.         sub hl,de
  551.         ret z
  552. initemptyplaylist
  553.         ld hl,PLAYLIST_VERSION
  554.         ld (playlistpanelversion),hl
  555.         ld ix,playlistpanel
  556.         jr clearpanel
  557.  
  558. clearpanel
  559. ;ix = panel
  560.         xor a
  561.         ld (ix+PANEL.filecount),a
  562.         ld (ix+PANEL.currentfileindex),a
  563.         ld (ix+PANEL.firstfiletoshow),a
  564.         ret
  565.  
  566. changetocurrentfolder
  567. ;out: zf=1 if succeeded, zf=0 otherwise
  568.         ld hl,(currentfolder+2)
  569.         push hl
  570.         ld a,l
  571.         or a
  572.         jr nz,$+8
  573.         ld hl,'/'
  574.         ld (currentfolder+2),hl
  575.         ld de,currentfolder
  576.         OS_CHDIR
  577.         pop hl
  578.         ld (currentfolder+2),hl
  579.         or a
  580.         ret
  581.  
  582. setcurrentfolder
  583. ;out: hl = file name only
  584.         push hl
  585.         ld c,'/'
  586.         call findlastchar ;out: de = after last slash or start
  587.         pop bc
  588.         ld hl,de
  589.         sub hl,bc
  590.         ex hl,de
  591.         ret z
  592. ;copy file path
  593.         ld hl,bc
  594.         ld bc,de
  595.         ld de,currentfolder
  596.         ldir
  597.         dec de
  598.         xor a
  599.         ld (de),a
  600.         ret
  601.  
  602. findfile
  603. ;de = file name
  604. ;out: a = file index, cf=1 if file was found
  605.         ld a,(browserpanel.filecount)
  606.         or a
  607.         ret z
  608.         ld b,a
  609.         ld c,0
  610.         ld hl,browserpanel.fileslist+FILE_NAME_OFFSET
  611. .searchloop
  612.         push bc
  613.         push de
  614.         push hl
  615.         call stricmp
  616.         pop hl
  617.         ld de,FILE_DATA_SIZE
  618.         add hl,de
  619.         pop de
  620.         pop bc
  621.         scf
  622.         ld a,c
  623.         ret z
  624.         inc c
  625.         djnz .searchloop
  626.         xor a
  627.         ret
  628.  
  629. stricmp
  630. ;hl = string1 addr
  631. ;de = string2 addr
  632. ;out: zf=1 if equal
  633.         ld a,(hl)
  634.         call tolower
  635.         ld c,a
  636.         ld a,(de)
  637.         call tolower
  638.         ld b,a
  639.         or c
  640.         ret z
  641.         ld a,b
  642.         cp c
  643.         ret nz
  644.         cp 1
  645.         ret c
  646.         inc hl
  647.         inc de
  648.         jr stricmp
  649.  
  650. getmusicprogress
  651. ;out: zf=0 and a=progress if progress is available, zf=1 and a=255 otherwise
  652.         ld hl,(MUSICPROGRESSADDR)
  653.         ld a,l
  654.         or h
  655.         ld a,255
  656.         ret z
  657.         ld a,(hl)
  658.         ret
  659.  
  660. drawplayerwindow
  661.         ld de,PANELCOLOR
  662.         OS_SETCOLOR
  663.         call getmusicprogress
  664.         ld (musicprogress),a
  665.         ld de,8*256+6
  666.         ld bc,66*256+4
  667.         ld a,8
  668.         jr nz,$+10
  669.         ld de,8*256+12
  670.         ld bc,54*256+3
  671.         ld a,14
  672.         ld (playerwindowtitlepos),a
  673.         ld (songtitlepos),a
  674.         call drawwindow
  675.         ld de,CURSORCOLOR
  676.         OS_SETCOLOR
  677. playerwindowtitlepos=$+1
  678.         ld de,8*256+0
  679.         OS_SETXY
  680.         ld hl,playingstr
  681.         call print_hl
  682.         call drawsongtitle
  683.         ld a,(isplaying)
  684.         or a
  685.         call nz,drawprogress
  686.         ret
  687.  
  688. drawsongtitle
  689.         ld de,PANELDIRCOLOR
  690.         OS_SETCOLOR
  691. songtitlepos=$+1
  692.         ld de,10*256+0
  693.         OS_SETXY
  694.         ld hl,(MUSICTITLEADDR)
  695.         ld a,l
  696.         or h
  697.         jp nz,print_hl
  698.         ld ix,(currentpaneladdr)
  699.         ld a,(ix+PANEL.currentfileindex)
  700.         call getfiledataoffset
  701.         ld a,ixl
  702.         add PANEL.fileslist+FILE_DISPLAY_INFO_OFFSET
  703.         ld e,a
  704.         adc a,ixh
  705.         sub e
  706.         ld d,a
  707.         add hl,de
  708.         jp print_hl
  709.  
  710. drawprogress
  711.         ld a,(musicprogress)
  712.         cp 255
  713.         ret z
  714.         ld de,11*256+8
  715.         OS_SETXY
  716.         ld a,(musicprogress)
  717.         ld c,a
  718.         or a
  719.         jr z,.drawremaining
  720.         ld b,a
  721. .drawdoneloop
  722.         push bc
  723.         ld a,178
  724.         PRCHAR
  725.         pop bc
  726.         djnz .drawdoneloop
  727. .drawremaining
  728.         ld a,64
  729.         sub c
  730.         ret z
  731.         ld b,a
  732. .drawremainingloop
  733.         push bc
  734.         ld a,176
  735.         PRCHAR
  736.         pop bc
  737.         djnz .drawremainingloop
  738.         ret
  739.  
  740. updateprogressbar
  741.         call getmusicprogress
  742.         ret z
  743.         ld d,a
  744.         ld hl,musicprogress
  745.         ld e,(hl)
  746.         sub e
  747.         ret z
  748.         ld (hl),d
  749.         push af
  750.         ld hl,11*256+8
  751.         ld d,0
  752.         add hl,de
  753.         ex de,hl
  754.         OS_SETXY
  755.         pop bc
  756. .drawloop
  757.         push bc
  758.         ld a,178
  759.         PRCHAR
  760.         pop bc
  761.         djnz .drawloop
  762.         ret
  763.  
  764. drawwindowline
  765. ;d = left char
  766. ;e = right char
  767. ;c = middle char
  768. ;b = middle char count
  769.         ld a,d
  770.         push de
  771.         push bc
  772.         PRCHAR
  773.         pop bc
  774. .drawloop
  775.         push bc
  776.         ld a,c
  777.         PRCHAR
  778.         pop bc
  779.         djnz .drawloop
  780.         pop de
  781.         ld a,e
  782.         PRCHAR
  783.         ret
  784.  
  785. drawwindow
  786. ;e = left coord
  787. ;d = top coord
  788. ;b = client area width
  789. ;c = client area height
  790. ;top line
  791.         push de
  792.         push bc
  793.         OS_SETXY
  794.         pop bc
  795.         push bc
  796.         ld de,0xc9bb
  797.         ld c,0xcd
  798.         call drawwindowline
  799.         pop bc
  800.         pop de
  801.         inc d
  802. ;client area
  803. .drawloop
  804.         push de
  805.         push bc
  806.         OS_SETXY
  807.         pop bc
  808.         push bc
  809.         ld de,0xbaba
  810.         ld c,0x20
  811.         call drawwindowline
  812.         pop bc
  813.         pop de
  814.         inc d
  815.         dec c
  816.         jr nz,.drawloop
  817. ;bottom line
  818.         push bc
  819.         OS_SETXY
  820.         pop bc
  821.         ld de,0xc8bc
  822.         ld c,0xcd
  823.         jp drawwindowline
  824.  
  825. getfiledataoffset
  826. ;a = index
  827. ;out: hl = index * FILE_DATA_SIZE
  828.         ld l,a
  829.         ld h,0
  830.         ld de,hl
  831.         add hl,hl
  832.         add hl,hl
  833.         ex de,hl
  834.         add hl,de
  835.         ex de,hl
  836.         add hl,hl
  837.         add hl,de
  838.         add hl,hl
  839.         add hl,hl
  840.         ret
  841.  
  842. getfileinfocolor
  843. ;c = file index
  844. ;hl = file data address
  845. currentfileindex=$+1
  846.         ld a,0
  847.         cp c
  848.         ld de,CURSORCOLOR
  849.         ret z
  850.         ld a,(ix+FILE_ATTRIB_OFFSET-FILE_DISPLAY_INFO_OFFSET)
  851.         cp FILE_ATTRIB_MUSIC
  852.         ld de,PANELFILECOLOR
  853.         ret z
  854.         cp FILE_ATTRIB_DRIVE
  855.         ld de,PANELDRIVECOLOR
  856.         ret z
  857. ;FILE_ATTRIB_PARENT_DIR or FILE_ATTRIB_FOLDER
  858.         ld de,PANELDIRCOLOR
  859.         ret
  860.  
  861. printfilesinfos
  862. ;ix = struct PANEL
  863. ;e = left coord
  864. ;d = top coord
  865. ;b = line count
  866. ;c = first file index
  867.         ld a,(ix+PANEL.currentfileindex)
  868.         or (ix+PANEL.isinactive)
  869.         ld (currentfileindex),a
  870.         ld a,(ix+PANEL.filecount)
  871.         ld (.currentfilecount),a
  872.         push de
  873.         ld a,c
  874.         call getfiledataoffset
  875.         ld de,ix
  876.         add hl,de
  877.         ld de,FILE_DISPLAY_INFO_OFFSET+PANEL.fileslist
  878.         add hl,de
  879.         pop de
  880. .filesloop
  881.         ld a,c
  882. .currentfilecount=$+1
  883.         cp 0
  884.         ret nc
  885.         push de
  886.         push hl
  887.         push bc
  888.         OS_SETXY
  889.         pop bc
  890.         pop ix
  891.         push bc
  892.         push ix
  893.         call getfileinfocolor
  894.         OS_SETCOLOR
  895.         pop hl
  896.         pop bc
  897.         push bc
  898.         ld b,FILE_DISPLAY_INFO_SIZE
  899. .printdisplaystringloop
  900.         push bc
  901.         push hl
  902.         ld a,(hl)
  903.         or a
  904.         jr nz,$+4
  905.         ld a,' '
  906.         PRCHAR
  907.         pop hl
  908.         pop bc
  909.         inc hl
  910.         djnz .printdisplaystringloop
  911.         ld de,FILE_DATA_SIZE-FILE_DISPLAY_INFO_SIZE
  912.         add hl,de
  913.         pop bc
  914.         pop de
  915.         inc c
  916.         inc d
  917.         djnz .filesloop
  918.         ret
  919.  
  920. getbrowserpanelparams
  921.         ld ix,browserpanel
  922.         ld de,256+1+FILES_WINDOW_X
  923.         ret
  924.  
  925. drawbrowserfileslist
  926.         call getbrowserpanelparams
  927.         ld b,FILE_LINE_COUNT
  928.         ld c,(ix+PANEL.firstfiletoshow)
  929.         jp printfilesinfos
  930.  
  931. getplaylistpanelparams
  932.         ld ix,playlistpanel
  933.         ld de,256+FILE_DISPLAY_INFO_SIZE+3+FILES_WINDOW_X
  934.         ret
  935.  
  936. drawplaylistfileslist
  937.         call getplaylistpanelparams
  938.         ld b,FILE_LINE_COUNT
  939.         ld c,(ix+PANEL.firstfiletoshow)
  940.         jp printfilesinfos
  941.  
  942. drawcurrentpanelfilelist
  943. currentpaneladdr=$+2
  944.         ld ix,0
  945. currentpanelpos=$+1
  946.         ld de,0
  947.         ld b,FILE_LINE_COUNT
  948.         ld c,(ix+PANEL.firstfiletoshow)
  949.         jp printfilesinfos
  950.  
  951. drawbrowserwindow
  952.         ld de,PANELCOLOR
  953.         OS_SETCOLOR
  954.         ld de,FILES_WINDOW_X
  955.         ld bc,FILE_DISPLAY_INFO_SIZE*256+FILE_LINE_COUNT
  956.         call drawwindow
  957.         ld de,CURSORCOLOR
  958.         OS_SETCOLOR
  959.         ld de,FILES_WINDOW_X+2
  960.         OS_SETXY
  961.         ld hl,currentfolder
  962.         call print_hl
  963.         jp drawbrowserfileslist
  964.  
  965. drawplaylistwindow
  966.         ld de,PANELCOLOR
  967.         OS_SETCOLOR
  968.         ld de,FILES_WINDOW_X+FILE_DISPLAY_INFO_SIZE+2
  969.         ld bc,FILE_DISPLAY_INFO_SIZE*256+FILE_LINE_COUNT
  970.         call drawwindow
  971.         ld de,CURSORCOLOR
  972.         OS_SETCOLOR
  973.         ld de,FILES_WINDOW_X+FILE_DISPLAY_INFO_SIZE+4
  974.         OS_SETXY
  975.         ld hl,playliststr
  976.         call print_hl
  977.         jr drawplaylistfileslist
  978.  
  979. redraw
  980.         ld e,7
  981.         OS_CLS
  982. drawui
  983.         call drawbrowserwindow
  984.         call drawplaylistwindow
  985.         ld de,0x7
  986.         OS_SETCOLOR
  987.         ld de,24*256+3
  988.         OS_SETXY
  989.         ld hl,hotkeystr
  990.         call print_hl
  991.         ld a,(isplaying)
  992.         or a
  993.         ret z
  994.         jp drawplayerwindow
  995.  
  996. skipword_hl
  997.         ld a,(hl)
  998.         or a
  999.         ret z
  1000.         cp ' '
  1001.         ret z
  1002.         inc hl
  1003.         jr skipword_hl
  1004.  
  1005. skipspaces_hl
  1006.         ld a,(hl)
  1007.         cp ' '
  1008.         ret nz
  1009.         inc hl
  1010.         jr skipspaces_hl
  1011.  
  1012. print_hl
  1013.         ld a,(hl)
  1014.         or a
  1015.         ret z
  1016.         push hl
  1017.         PRCHAR
  1018.         pop hl
  1019.         inc hl
  1020.         jp print_hl
  1021.  
  1022. strcopy_hltode
  1023.         ld a,(hl)
  1024.         ld (de),a
  1025.         or a
  1026.         ret z
  1027.         inc hl
  1028.         inc de
  1029.         jr strcopy_hltode
  1030.  
  1031. ;c = character
  1032. ;hl = poi to filename in string
  1033. ;out: de = after last char or start
  1034. findlastchar
  1035.         ld d,h
  1036.         ld e,l ;de = after last char
  1037. findlastchar0
  1038.         ld a,(hl)
  1039.         inc hl
  1040.         or a
  1041.         ret z
  1042.         cp c
  1043.         jr nz,findlastchar0
  1044.         jr findlastchar
  1045.  
  1046. tolower
  1047.         cp 'A'
  1048.         ret c
  1049.         cp 'Z'+1
  1050.         ret nc
  1051.         add 32
  1052.         ret
  1053.  
  1054. pressanykeystr
  1055.         db "!\r\nPress any key to exit...\r\n",0
  1056. playersfilename
  1057.         db "gp/gp.plr",0
  1058. settingsfilename
  1059.         db "gp/gp.ini",0
  1060. defaultplaylistfilename
  1061.         db "gp/"
  1062. playlistfilename
  1063.         db "playlist.gpl",0
  1064. invalidplayerfilestr
  1065.         db "Corrupted gp/gp.plr file",0
  1066. noplayersloadedstr
  1067.         db "Unable to load any players",0
  1068. playersloaderrorstr
  1069.         db "Failed to load gp/gp.plr from OS folder",0
  1070. chdirfailedstr
  1071.         db "Unable to change directory",0
  1072. playliststr
  1073.         db "Playlist",0
  1074. playingstr
  1075.         db "Playing...",0
  1076. closingplayerstr
  1077.         db "Closing old player instance...\r\n",0
  1078. emptystr
  1079.         db 0
  1080. initializing1str
  1081.         db "Initializing ",0
  1082. initializing2str
  1083.         db "...",0
  1084. hotkeystr
  1085.         db "Arrows=Navigate  Enter=Play  Tab=Panel  Space=Add/Remove  S=Save Playlist",0
  1086. drivedata
  1087.         db "E: - IDE Master p.1                   E:",0,0,0,0,0,0,0,0,0,0,0,FILE_ATTRIB_DRIVE
  1088.         db "F: - IDE Master p.2                   F:",0,0,0,0,0,0,0,0,0,0,0,FILE_ATTRIB_DRIVE
  1089.         db "M: - SD Z-controller                  M:",0,0,0,0,0,0,0,0,0,0,0,FILE_ATTRIB_DRIVE
  1090.         db "O: - USB ZX-NetUsb                    O:",0,0,0,0,0,0,0,0,0,0,0,FILE_ATTRIB_DRIVE
  1091. drivedataend
  1092.  
  1093. loadplayer
  1094. ;de = code size
  1095. ;hl = settings variable addr
  1096.         ld (.codesize),de
  1097.         ld a,h
  1098.         or l
  1099.         ld a,'1' ;default for Use<Player> variable is 1
  1100.         jr z,$+3
  1101.         ld a,(hl)
  1102.         ld (.settingsvalue),a
  1103.         OS_NEWPAGE
  1104.         or a
  1105.         ret nz
  1106.         ld a,e
  1107.         ld (.playerpage),a
  1108.         SETPG4000
  1109.         ld de,0x4000
  1110. .codesize=$+1
  1111.         ld hl,0
  1112.         call readstream_file
  1113. .settingsvalue=$+1
  1114.         ld a,0
  1115.         cp '0'
  1116.         jr z,.cleanup
  1117.         ld hl,initializing1str
  1118.         call print_hl
  1119.         ld hl,(PLAYERNAMESTRADDR)
  1120.         call print_hl
  1121.         ld hl,initializing2str
  1122.         call print_hl
  1123.         ld hl,gpsettings
  1124.         ld a,(.playerpage)
  1125.         call playerinit
  1126.         push af
  1127.         call print_hl
  1128.         pop af
  1129.         jr nz,.cleanup
  1130.         ld hl,playercount
  1131.         ld e,(hl)
  1132.         inc (hl)
  1133.         ld d,0
  1134.         ld hl,playerpages
  1135.         add hl,de
  1136. .playerpage=$+1
  1137.         ld (hl),0
  1138.         ret
  1139. .cleanup
  1140.         ld a,(.playerpage)
  1141.         ld e,a
  1142.         OS_DELPAGE
  1143.         ret
  1144.  
  1145. loadplayers
  1146. ;output: zf=1 if success, zf=0 and hl=error message if failed
  1147.         ld de,playersfilename
  1148.         call openstream_file
  1149.         or a
  1150.         ld hl,playersloaderrorstr
  1151.         ret nz
  1152. ;check if the file matches this build
  1153.         ld a,(filehandle)
  1154.         ld b,a
  1155.         OS_GETFILESIZE
  1156.         ld de,plrend-plrbegin
  1157.         sub hl,de
  1158.         ld hl,invalidplayerfilestr
  1159.         ret nz
  1160. ;load players from file
  1161.         xor a
  1162.         ld (playercount),a
  1163.         ld de,modend-modstart : ld hl,(gpsettings.usemoonmod) : call loadplayer
  1164.         ld de,mwmend-mwmstart : ld hl,(gpsettings.usemwm) : call loadplayer
  1165.         ld de,pt3end-pt3start : ld hl,(gpsettings.usept3) : call loadplayer
  1166.         ld de,mp3end-mp3start : ld hl,(gpsettings.usemp3) : call loadplayer
  1167.         ld de,vgmend-vgmstart : ld hl,(gpsettings.usevgm) : call loadplayer
  1168.         call closestream_file
  1169.         ld a,(playercount)
  1170.         dec a
  1171.         ld hl,noplayersloadedstr
  1172.         ret m
  1173.         xor a
  1174.         ret
  1175.  
  1176. loadsettings
  1177.         ld de,settingsfilename
  1178.         call openstream_file
  1179.         or a
  1180.         ret nz
  1181.         ld de,browserpanel
  1182.         ld hl,0x4000
  1183.         call readstream_file
  1184.         ld de,browserpanel
  1185.         add hl,de
  1186.         ld (hl),0
  1187.         call closestream_file
  1188.         ld de,browserpanel
  1189. .parseloop
  1190.         ld bc,'='*256
  1191.         call findnextchar
  1192.         or a
  1193.         ret z
  1194.         cp b
  1195.         jr nz,.parseloop
  1196.         ld b,settingsvarcount
  1197.         ld hl,settingsvars
  1198. .varsearchloop
  1199.         ld a,(hl)
  1200.         inc hl
  1201.         cp c
  1202.         jr z,.foundvar
  1203.         inc hl
  1204.         inc hl
  1205.         djnz .varsearchloop
  1206.         jr .nextvar
  1207. .foundvar
  1208.         ld a,(hl)
  1209.         inc hl
  1210.         ld h,(hl)
  1211.         ld l,a
  1212.         ld (hl),e
  1213.         inc hl
  1214.         ld (hl),d
  1215. .nextvar
  1216.         ld b,0
  1217.         call findnextchar
  1218.         or a
  1219.         jr nz,.parseloop
  1220.         ret
  1221.  
  1222. findnextchar
  1223. ;de = ptr
  1224. ;b = character to search
  1225. ;c = LRC
  1226. ;output: de = ptr past character, c = updated LRC
  1227.         ld a,(de)
  1228.         inc de
  1229.         or a
  1230.         ret z
  1231.         cp "\n"
  1232.         ret z
  1233.         cp b
  1234.         ret z
  1235.         xor c
  1236.         ld c,a
  1237.         jr findnextchar
  1238.  
  1239. gpsettings GPSETTINGS
  1240.  
  1241. settingsvars
  1242.         db 0x19 : dw gpsettings.usemp3
  1243.         db 0x14 : dw gpsettings.usemwm
  1244.         db 0x74 : dw gpsettings.usept3
  1245.         db 0x1F : dw gpsettings.usevgm
  1246.         db 0x26 : dw gpsettings.usemoonmod
  1247.         db 0x7F : dw gpsettings.moonmoddefaultpanning
  1248. settingsvarcount=($-settingsvars)/3
  1249.  
  1250. getfileextension
  1251. ;hl = file name
  1252. ;out: cde = file extension
  1253.         ld c,'.'
  1254.         call findlastchar ;out: de = after last dot or start
  1255.         ex de,hl
  1256.         ld a,(hl)
  1257.         call tolower
  1258.         ld c,a
  1259.         inc hl
  1260.         ld a,(hl)
  1261.         call tolower
  1262.         ld d,a
  1263.         inc hl
  1264.         ld a,(hl)
  1265.         call tolower
  1266.         ld e,a
  1267.         ret
  1268.  
  1269. isfileplaylist
  1270. ;cde = file extension
  1271. ;out: zf=1 if playlist, zf=0 otherwise
  1272.         ld a,c
  1273.         cp 'g'
  1274.         ret nz
  1275.         ld a,d
  1276.         cp 'p'
  1277.         ret nz
  1278.         ld a,e
  1279.         cp 'l'
  1280.         ret
  1281.  
  1282. findsupportedplayer
  1283. ;cde = file extension
  1284.         ld hl,playerpages
  1285.         ld a,(playercount)
  1286.         ld b,a
  1287. .findplayerloop
  1288.         push hl
  1289.         push bc
  1290.         ld a,(hl)
  1291.         SETPG4000
  1292.         pop bc
  1293.         call isfilesupported
  1294.         pop hl
  1295.         ret z
  1296.         inc hl
  1297.         djnz .findplayerloop
  1298.         dec b ;set zf=0
  1299.         ret
  1300.  
  1301. createfileslist
  1302.         ld de,emptystr
  1303.         OS_OPENDIR
  1304.  
  1305.         ld a,(gpsettings.sharedpages)
  1306.         SETPG8000
  1307.         ld a,(gpsettings.sharedpages+1)
  1308.         SETPGC000
  1309.  
  1310.         xor a
  1311.         ld (browserpanel.currentfileindex),a
  1312.         ld (browserpanel.firstfiletoshow),a
  1313.  
  1314.         ld hl,currentfolder+2
  1315.         cp (hl)
  1316.         ld hl,0x8000
  1317.         jr nz,.startloop
  1318.         ex de,hl
  1319.         ld hl,drivedata
  1320.         ld bc,drivedataend-drivedata
  1321.         ldir
  1322.         ex de,hl
  1323.         ld a,(drivedataend-drivedata)/FILE_DATA_SIZE
  1324. .startloop
  1325.         ld (browserpanel.filecount),a
  1326. .fileenumloop
  1327.         ld (.filedataaddr),hl
  1328. .skiptonextfile
  1329.         ld de,filinfo
  1330.         OS_READDIR
  1331.         or a
  1332.         jp nz,.sortfiles
  1333. ;skip '.' folder
  1334.         ld hl,(filinfo+FILINFO_FNAME)
  1335.         ld a,l
  1336.         xor '.'
  1337.         or h
  1338.         jr z,.skiptonextfile
  1339. ;skip findsupportedplayer for folders
  1340.         ld a,(filinfo+FILINFO_FATTRIB)
  1341.         and FATTRIB_DIR
  1342.         jr nz,.foundfileordir
  1343.         ld hl,filinfo+FILINFO_FNAME
  1344.         call getfileextension
  1345.         call isfileplaylist
  1346.         jr z,.foundfileordir
  1347.         call findsupportedplayer
  1348.         jr nz,.skiptonextfile
  1349. ;we've got either a playable file or a folder
  1350. .foundfileordir
  1351. .filedataaddr=$+1
  1352.         ld de,0
  1353.         ld hl,FILE_NAME_OFFSET
  1354.         add hl,de
  1355.         ex de,hl
  1356.         ld hl,filinfo+FILINFO_FNAME
  1357.         ld bc,9*256+SFN_SIZE
  1358. .copysfnloop
  1359.         ld a,(hl)
  1360.         cp '.'
  1361.         jr z,.foundsfnext
  1362.         or a
  1363.         jr z,.sfntailloop
  1364.         call tolower
  1365.         ld (de),a
  1366.         inc hl
  1367.         inc de
  1368.         dec c
  1369.         dec b
  1370.         jr .copysfnloop
  1371. ;this is a folder, pad it to SFN_SIZE with zeros
  1372. .sfntailloop
  1373.         ld (de),a
  1374.         inc de
  1375.         dec c
  1376.         jr nz,.sfntailloop
  1377.         jr .donesfncopy
  1378. ;format SFN as 8.3 fixed-position array padding with '*' if necessary
  1379. ;this is needed for sorting
  1380. .foundsfnext
  1381.         ld a,'*'
  1382. .sfntailloop1
  1383.         ld (de),a
  1384.         inc de
  1385.         djnz .sfntailloop1
  1386.         dec de
  1387. ;copy dot, extension, zero terminator
  1388.         ld b,5
  1389. .sfntailloop2
  1390.         ld a,(hl)
  1391.         call tolower
  1392.         ld (de),a
  1393.         inc hl
  1394.         inc de
  1395.         djnz .sfntailloop2
  1396. .donesfncopy
  1397. ;fill display name
  1398.         ld hl,FILE_DISPLAY_INFO_OFFSET-FILE_NAME_OFFSET-SFN_SIZE
  1399.         add hl,de
  1400.         ex de,hl
  1401.         ld hl,filinfo+FILINFO_LNAME
  1402.         ld a,(hl)
  1403.         or a
  1404.         jr nz,$+5
  1405.         ld hl,filinfo+FILINFO_FNAME
  1406.         ld bc,(FILE_DISPLAY_INFO_SIZE-1)*256+255
  1407. .copylfnloop
  1408.         ldi
  1409.         dec b
  1410.         jr z,.lfncopydone
  1411.         ld a,(hl)
  1412.         or a
  1413.         jr nz,.copylfnloop
  1414. .filltailloop
  1415.         ld (de),a
  1416.         inc de
  1417.         djnz .filltailloop
  1418. .lfncopydone
  1419.         xor a
  1420.         ld (de),a
  1421. ;set atrribute data
  1422.         call getfileattrib
  1423.         ld hl,FILE_ATTRIB_OFFSET-FILE_DISPLAY_INFO_OFFSET-FILE_DISPLAY_INFO_SIZE+1
  1424.         add hl,de
  1425.         ld (hl),a
  1426.         ld de,FILE_DATA_SIZE-FILE_ATTRIB_OFFSET
  1427.         add hl,de
  1428. ;check if we have space for more files
  1429.         ld a,(browserpanel.filecount)
  1430.         inc a
  1431.         ld (browserpanel.filecount),a
  1432.         cp BROWSER_FILE_COUNT
  1433.         jp c,.fileenumloop
  1434. .sortfiles
  1435.         ld a,(browserpanel.filecount)
  1436.         or a
  1437.         ret z
  1438.         ld c,a
  1439.         ld b,0
  1440.         ld a,12
  1441.         ld ix,fileextsortkeyoffsets
  1442.         ld hl,0x8000
  1443.         ld de,FILE_DATA_SIZE
  1444.         ld iy,browserpanel.fileslist
  1445.         call radixsort
  1446. ;remove '*' padding restoring SFN to original null-terminated string form
  1447.         ld a,(browserpanel.filecount)
  1448.         ld b,a
  1449.         ld hl,browserpanel.fileslist+FILE_NAME_OFFSET
  1450. .removepaddingnextfile
  1451.         ld de,hl
  1452.         push hl
  1453. .removepaddingloop
  1454.         ld a,(hl)
  1455.         inc hl
  1456.         cp '*'
  1457.         jr z,.removepaddingloop
  1458.         ld (de),a
  1459.         inc de
  1460.         or a
  1461.         jr nz,.removepaddingloop
  1462.         pop hl
  1463.         ld de,FILE_DATA_SIZE
  1464.         add hl,de
  1465.         djnz .removepaddingnextfile
  1466.         ret
  1467.  
  1468. getfileattrib
  1469. ;out: a = attribute value
  1470.         ld a,(filinfo+FILINFO_FATTRIB)
  1471.         and FATTRIB_DIR
  1472.         ld a,FILE_ATTRIB_MUSIC
  1473.         ret z
  1474.         ld hl,(filinfo+FILINFO_FNAME)
  1475.         ld bc,'..'
  1476.         sub hl,bc
  1477.         ld a,FILE_ATTRIB_PARENT_DIR
  1478.         ret z
  1479.         ld a,FILE_ATTRIB_FOLDER
  1480.         ret
  1481.  
  1482. fileextsortkeyoffsets
  1483.         dw FILE_NAME_OFFSET+7, FILE_NAME_OFFSET+6, FILE_NAME_OFFSET+5
  1484.         dw FILE_NAME_OFFSET+4, FILE_NAME_OFFSET+3, FILE_NAME_OFFSET+2
  1485.         dw FILE_NAME_OFFSET+1, FILE_NAME_OFFSET+0
  1486.         dw FILE_NAME_OFFSET+11, FILE_NAME_OFFSET+10, FILE_NAME_OFFSET+9
  1487.         dw FILE_ATTRIB_OFFSET
  1488.  
  1489.         macro jumpindirect addr
  1490.         push hl
  1491.         ld hl,(addr)
  1492.         ex (sp),hl
  1493.         ret
  1494.         endm
  1495.  
  1496. playerinit      jumpindirect PLAYERINITPROCADDR
  1497. playerdeinit    jumpindirect PLAYERDEINITPROCADDR
  1498. musicload       jumpindirect MUSICLOADPROCADDR
  1499. musicunload     jumpindirect MUSICUNLOADPROCADDR
  1500. musicplay       jumpindirect MUSICPLAYPROCADDR
  1501. isfilesupported jumpindirect ISFILESUPPORTEDPROCADDR
  1502.  
  1503.         include "../_sdk/file.asm"
  1504.         include "common/radixsort.asm"
  1505.  
  1506. closeexistingplayer
  1507. ;d = current pid
  1508.         ld e,1
  1509. .searchloop
  1510.         ld a,e
  1511.         cp d
  1512.         jr z,.nextprocess
  1513.         push de
  1514.         OS_GETAPPMAINPAGES ;d,e,h,l=pages in 0000,4000,8000,c000
  1515.         or a
  1516.         ld a,d
  1517.         pop de
  1518.         jr nz,.nextprocess
  1519.         push de
  1520.         SETPGC000
  1521.         ld hl,0xc000+COMMANDLINE
  1522.         ld de,0x8000
  1523.         ld bc,COMMANDLINE_sz
  1524.         ldir
  1525.         ld hl,0x8000
  1526.         call skipword_hl
  1527.         ld (hl),0
  1528.         ld hl,0x8000
  1529.         ld c,'/'
  1530.         call findlastchar ;out: de = after last slash or start
  1531.         call isplayer
  1532.         pop de
  1533.         jr z,.foundplayer
  1534. .nextprocess
  1535.         inc e
  1536.         ld a,e
  1537.         inc a
  1538.         jr nz,.searchloop
  1539.         ret
  1540. .foundplayer
  1541.         xor a
  1542.         ld (0xc000+COMMANDLINE),a
  1543.         push de
  1544.         ld hl,closingplayerstr
  1545.         call print_hl
  1546.         pop de
  1547. .waitloop
  1548.         push de
  1549.         YIELD
  1550.         YIELD
  1551.         YIELD
  1552.         YIELD
  1553.         OS_GETAPPMAINPAGES
  1554.         pop de
  1555.         or a
  1556.         jr z,.waitloop
  1557.         ret
  1558.  
  1559. isplayer
  1560. ;de = command line file name
  1561. ;out: zf=1 if gp, zf=0 otherwise
  1562.         ld a,(de)
  1563.         call tolower
  1564.         cp 'g'
  1565.         ret nz
  1566.         inc de
  1567.         ld a,(de)
  1568.         call tolower
  1569.         cp 'p'
  1570.         ret nz
  1571.         inc de
  1572.         ld a,(de)
  1573.         or a
  1574.         ret z
  1575.         cp '.'
  1576.         ret
  1577. mainend
  1578.  
  1579. playerpages
  1580.         ds NUM_PLAYERS
  1581. filinfo
  1582.         ds FILINFO_sz
  1583. currentfolder
  1584.         ds MAXPATH_sz
  1585. fullpathbuffer
  1586.         ds MAXPATH_sz
  1587.  
  1588.         struct PANEL
  1589. filecount ds 1
  1590. currentfileindex ds 1
  1591. firstfiletoshow ds 1
  1592. isinactive ds 1
  1593. fileslist ds FILE_DATA_SIZE
  1594.         ends
  1595.  
  1596. browserpanel PANEL
  1597.         ds FILE_DATA_SIZE*(BROWSER_FILE_COUNT-1)
  1598.  
  1599. playlistdatastart=$
  1600. playlistpanelversion ds 2
  1601. playlistpanel PANEL
  1602.         ds FILE_DATA_SIZE*(PLAYLIST_FILE_COUNT-1)
  1603. playlistdatasize=$-playlistdatastart
  1604.  
  1605. musicprogress ds 1
  1606. playercount ds 1
  1607.  
  1608. page0dataend = $
  1609.  
  1610.         assert page0dataend <= 0x3d00 ;reserve 768 bytes for stack
  1611.  
  1612.         savebin "gp.com",mainbegin,mainend-mainbegin
  1613.  
  1614.         org 0x0000
  1615.  
  1616. plrbegin
  1617. modstart
  1618.         incbin "moonmod.bin"
  1619. modend
  1620. mwmstart
  1621.         incbin "mwm.bin"
  1622. mwmend
  1623. pt3start
  1624.         incbin "pt3.bin"
  1625. pt3end
  1626. mp3start
  1627.         incbin "mp3.bin"
  1628. mp3end
  1629. vgmstart
  1630.         incbin "vgm.bin"
  1631. vgmend
  1632. plrend
  1633.  
  1634.         savebin "gp.plr",plrbegin,plrend-plrbegin
  1635.