Subversion Repositories NedoOS

Rev

Rev 2408 | Blame | Compare with Previous | Last modification | View Log | Download

  1. ; One-time initialization code, not retained after startup is complete.
  2.  
  3.         include "common/opl4.asm"
  4.         include "common/opn.asm"
  5.         include "common/opm.asm"
  6.         include "common/opna.asm"
  7.  
  8. startup
  9.         ld de,DEFAULTCOLOR
  10.         OS_SETCOLOR
  11.         OS_GETMAINPAGES ;out: d,e,h,l=pages in 0000,4000,8000,c000, c=flags, b=id
  12.         ld (gpsettings.sharedpages),hl
  13.         ld a,e
  14.         ld (gpsettings.sharedpages+2),a
  15.         ld d,b
  16.         call closeexistingplayer
  17.         ld de,currentfolder
  18.         OS_GETPATH
  19.         ld hl,(currentfolder+2)
  20.         ld a,l
  21.         xor '/'
  22.         or h
  23.         jr nz,$+5
  24.         ld (currentfolder+2),a
  25.         OS_SETSYSDRV
  26.         call loadandparsesettings
  27.         call checkinifile
  28.         call runsetup
  29.         call detectcpuspeed
  30.         call detectmoonsound
  31.         call detecttfm
  32.         call detectopm
  33.         jp detectopna
  34.  
  35. runsetup
  36.         ld a,(runplayersetup)
  37.         or a
  38.         ret z
  39. ;player setup
  40.         ld hl,(gpsettings.mididevice)
  41.         ld de,midioptions
  42.         ld b,midioptioncount
  43.         ld a,(hl)
  44.         and 15
  45.         call updateradiobuttons
  46.         ld hl,(gpsettings.moddevice)
  47.         ld de,modoptions
  48.         ld b,modoptioncount
  49.         ld a,(hl)
  50.         and 15
  51.         call updateradiobuttons
  52.         ld hl,(bomgemoonsettings)
  53.         ld de,bomgemoonoption
  54.         ld a,(hl)
  55.         and 1
  56.         call updatecheckbox
  57.         call redrawplayersetupui
  58.         ld hl,playersetupmsgtable
  59.         ld (currentmsgtable),hl
  60.         call playloop
  61.         ld de,DEFAULTCOLOR
  62.         OS_SETCOLOR
  63.         ld e,7
  64.         OS_CLS
  65.         ret
  66.  
  67. checkinifile
  68.         ld hl,(inifileversionsettings)
  69.         ld a,l
  70.         or h
  71.         jr z,.isoutdated
  72.         ld a,(hl)
  73.         cp '1'
  74.         ret z
  75. .isoutdated
  76.         ld hl,builtininifile
  77.         ld de,inifilebuffer
  78.         ld bc,builtininifilesize
  79.         ld (inifilesize),bc
  80.         ldir
  81.         xor a
  82.         ld (de),a
  83.         call parsesettings
  84.         ld a,1
  85.         ld (runplayersetup),a
  86.         ret
  87.  
  88. playersetupmsgtable
  89.         db (playersetupmsghandlers_end-playersetupmsghandlers_start)/3
  90. playersetupmsghandlers_start
  91.         db key_redraw    : dw redrawplayersetupui
  92.         db key_esc       : dw exitplayersetup
  93.         db key_up        : dw goprevoption
  94.         db key_down      : dw gonextoption
  95.         db key_enter     : dw setoption
  96.         db ' '           : dw setoption
  97.         db key_tab       : dw gonextfast
  98. playersetupmsghandlers_end
  99.  
  100. playersetupoptions
  101. midioptions
  102.         dw midioption1str : dw midioptionhandler : dw defaultdevicedescstr
  103.         dw midioption2str : dw midioptionhandler : dw moonsounddescstr
  104.         dw midioption3str : dw midioptionhandler : dw midioption3descstr
  105.         dw midioption4str : dw midioptionhandler : dw midioption4descstr
  106.         dw midioption5str : dw midioptionhandler : dw midioption5descstr
  107.         dw midioption6str : dw midioptionhandler : dw midioption6descstr
  108. midioptioncount=($-midioptions)/6
  109. modoptions
  110.         dw modoption1str : dw modoptionhandler : dw defaultdevicedescstr
  111.         dw modoption2str : dw modoptionhandler : dw moonsounddescstr
  112.         dw modoption3str : dw modoptionhandler : dw modoption3descstr
  113. modoptioncount=($-modoptions)/6
  114. bomgemoonoption
  115.         dw bomgemoonoptionstr : dw bomgemoonhandler : dw bomgemoonoptiondescstr
  116. playersetupoptioncount=($-playersetupoptions)/6
  117.  
  118. midioption1str db 4,5,"[X] Auto Select Device        ",0
  119. midioption2str db 5,5,"[ ] MoonSound (OPL4)          ",0
  120. midioption3str db 6,5,"[ ] NeoGS (VS10x3 Synth)      ",0
  121. midioption4str db 7,5,"[ ] UART AY1 (Multisound Old) ",0
  122. midioption5str db 8,5,"[ ] UART AY2 (Multisound New) ",0
  123. midioption6str db 9,5,"[ ] UART YM2608               ",0
  124. modoption1str db 5,47,"[X] Auto Select Device  ",0
  125. modoption2str db 6,47,"[ ] MoonSound (OPL4)    ",0
  126. modoption3str db 7,47,"[ ] GeneralSound        ",0
  127. bomgemoonoptionstr db 14,21,"[ ] OPL3-only Device (BomgeMoon)  ",0
  128. settingsheaderstr
  129.         db "Player Settings",0
  130. setuphotkeysstr
  131.         db "ESC=Save&Continue  Space=Toggle  Up/Down=Nagivate",0
  132. mididevicestr
  133.         db "MIDI Device...",0
  134. moddevicestr
  135.         db "MOD Device...",0
  136. miscoptionstr
  137.         db "Misc...",0
  138.  
  139. moonsounddescstr db "Проигрывать через MoonSound.",0
  140. defaultdevicedescstr db "Разрешает плееру использовать любое доступное устройство.",0
  141. midioption3descstr db "Используйте если у вас обновлённая версия NeoGS c декодером VLSI VS10x3.",0
  142. midioption4descstr db "Используйте если у вас MultiSound с прошивкой первой версии.",0
  143. midioption5descstr db "Используйте если у вас MultiSound с последней ревизией прошивки.",0
  144. midioption6descstr db "MIDI UART подключен через IOA YM2608.",0
  145. modoption3descstr db "Проигрывать через прошивку GeneralSound/NeoGS.",0
  146. bomgemoonoptiondescstr db "Используйте если у вас нет MoonSound, но есть карта с OPL3 чипом.",0
  147.  
  148. activeoption db 0
  149. inifileversionsettings dw 0
  150. inifilesize dw 0
  151.  
  152. exitplayersetup
  153.         pop hl
  154.         ld de,settingsfilename
  155.         call openstream_file
  156.         or a
  157.         jr z,.openedfile
  158.         ld de,settingsfilename
  159.         OS_CREATEHANDLE
  160.         or a
  161.         ret nz
  162.         ld a,b
  163.         ld (filehandle),a
  164. .openedfile
  165.         ld a,(filehandle)
  166.         ld b,a
  167.         ld de,inifilebuffer
  168.         ld hl,(inifilesize)
  169.         OS_WRITEHANDLE
  170.         jp closestream_file
  171.  
  172. updatecheckbox
  173. ;hl = ini address
  174. ;de = option struct
  175. ;a = 0-1 value
  176.         dec a
  177.         ld c,a
  178.         ld b,1
  179.         ld a,'1'
  180.         jr updateradiobuttons.updateoptions
  181.  
  182. updateradiobuttons
  183. ;hl = ini address
  184. ;de = option structs
  185. ;b = option count
  186. ;a = active option
  187.         ld c,a
  188.         ld a,'0'
  189. .updateoptions
  190.         ld (.basedigit),a
  191.         ld a,h
  192.         or l
  193.         ret z
  194.         ld a,c
  195. .basedigit=$+1
  196.         add a,'0'
  197.         ld (hl),a
  198.         ex de,hl
  199.         inc c
  200. .loop   ld e,(hl)
  201.         inc hl
  202.         ld d,(hl)
  203.         inc de
  204.         inc de
  205.         inc de
  206.         dec c
  207.         ld a,'X'
  208.         jr z,$+4
  209.         ld a,' '
  210.         ld (de),a
  211.         ld de,5
  212.         add hl,de
  213.         djnz .loop
  214.         ret
  215.  
  216. midioptionhandler
  217.         ld hl,(gpsettings.mididevice)
  218.         ld de,midioptions
  219.         ld b,midioptioncount
  220.         ld a,(activeoption)
  221.         sub (midioptions - playersetupoptions)/6
  222.         call updateradiobuttons
  223.         jp drawsetupoptions
  224.  
  225. modoptionhandler
  226.         ld hl,(gpsettings.moddevice)
  227.         ld de,modoptions
  228.         ld b,modoptioncount
  229.         ld a,(activeoption)
  230.         sub (modoptions - playersetupoptions)/6
  231.         call updateradiobuttons
  232.         jp drawsetupoptions
  233.  
  234. bomgemoonhandler
  235.         ld hl,(bomgemoonsettings)
  236.         ld de,bomgemoonoption
  237.         ld a,(hl)
  238.         cpl
  239.         and 1
  240.         call updatecheckbox
  241.         jp drawsetupoptions
  242.  
  243. getactiveoptionaddr
  244. ;hl=base addr
  245. ;output: hl=active option addr
  246.         ld a,(activeoption)
  247.         add a,a
  248.         ld e,a
  249.         add a,a
  250.         add a,e
  251.         ld e,a
  252.         ld d,0
  253.         add hl,de
  254.         ret
  255.  
  256. setoption
  257.         ld hl,playersetupoptions+2
  258.         call getactiveoptionaddr
  259.         ld e,(hl)
  260.         inc hl
  261.         ld d,(hl)
  262.         ex de,hl
  263.         jp (hl)
  264.  
  265. goprevoption
  266.         ld a,(activeoption)
  267.         dec a
  268.         jp p,$+5
  269.         ld a,playersetupoptioncount-1
  270.         ld (activeoption),a
  271.         jp drawsetupoptions
  272.  
  273. gonextoption
  274.         ld a,(activeoption)
  275.         inc a
  276.         cp playersetupoptioncount
  277.         jr c,$+3
  278.         xor a
  279.         ld (activeoption),a
  280.         jp drawsetupoptions
  281.  
  282. gonextfast
  283.         ld a,(activeoption)
  284.         add a,3
  285.         cp playersetupoptioncount
  286.         jr c,$+3
  287.         xor a
  288.         ld (activeoption),a
  289.         jp drawsetupoptions
  290.  
  291. optiondescbuffer equ playlistpanel
  292.  
  293. redrawplayersetupui
  294.         ld e,7
  295.         OS_CLS
  296.         ld de,DEFAULTCOLOR
  297.         OS_SETCOLOR
  298.         ld de,0x00020
  299.         OS_SETXY
  300.         ld hl,settingsheaderstr
  301.         call print_hl
  302.         ld de,0x180f
  303.         OS_SETXY
  304.         ld hl,setuphotkeysstr
  305.         call print_hl
  306.         ld de,PANELCOLOR
  307.         OS_SETCOLOR
  308.         ld de,0x0304
  309.         ld bc,0x1e06
  310.         call drawwindow
  311.         ld de,0x0306
  312.         OS_SETXY
  313.         ld hl,mididevicestr
  314.         call print_hl
  315.         ld de,0x042e
  316.         ld bc,0x1803
  317.         call drawwindow
  318.         ld de,0x0430
  319.         OS_SETXY
  320.         ld hl,moddevicestr
  321.         call print_hl
  322.         ld de,0x0d14
  323.         ld bc,0x2201
  324.         call drawwindow
  325.         ld de,0x0d16
  326.         OS_SETXY
  327.         ld hl,miscoptionstr
  328.         call print_hl
  329. drawsetupoptions
  330.         ld hl,playersetupoptions
  331.         ld b,playersetupoptioncount
  332.         ld c,0
  333. .optionsloop
  334.         push bc
  335.         ld a,(activeoption)
  336.         cp c
  337.         ld de,CURSORCOLOR
  338.         jr z,$+5
  339.         ld de,PANELFILECOLOR
  340.         push hl
  341.         OS_SETCOLOR
  342.         pop hl
  343.         ld e,(hl)
  344.         inc hl
  345.         ld d,(hl)
  346.         push hl
  347.         ex de,hl
  348.         ld d,(hl)
  349.         inc hl
  350.         ld e,(hl)
  351.         inc hl
  352.         push hl
  353.         OS_SETXY
  354.         pop hl
  355.         call print_hl
  356.         pop hl
  357.         ld de,5
  358.         add hl,de
  359.         pop bc
  360.         inc c
  361.         djnz .optionsloop
  362. ;print desc
  363.         ld de,DEFAULTCOLOR
  364.         OS_SETCOLOR
  365.         ld de,0x1600
  366.         OS_SETXY
  367.         ld hl,playersetupoptions+4
  368.         call getactiveoptionaddr
  369.         ld e,(hl)
  370.         inc hl
  371.         ld d,(hl)
  372.         push de
  373.         ex de,hl
  374.         ld c,0
  375.         call findlastchar
  376.         ld a,l
  377.         sub e
  378.         dec a
  379.         ld c,a
  380.         ld a,80
  381.         sub c
  382.         rra
  383.         ld b,a
  384.         ld de,optiondescbuffer
  385.         ld a,' '
  386. .fillloop1
  387.         ld (de),a
  388.         inc de
  389.         djnz .fillloop1
  390.         pop hl
  391.         ldir
  392.         ld a,(optiondescbuffer+80)%256
  393.         sub e
  394.         ld b,a
  395.         ld a,' '
  396. .fillloop2
  397.         ld (de),a
  398.         inc de
  399.         djnz .fillloop2
  400.         xor a
  401.         ld (de),a
  402.         ld hl,optiondescbuffer
  403.         call print_hl
  404.         ret
  405.  
  406. loadandparsesettings
  407.         ld de,settingsfilename
  408.         call openstream_file
  409.         or a
  410.         ret nz
  411.         ld de,inifilebuffer
  412.         ld hl,0x4000
  413.         call readstream_file
  414.         ld (inifilesize),hl
  415.         ld de,inifilebuffer
  416.         add hl,de
  417.         ld (hl),0
  418.         call closestream_file
  419. parsesettings
  420.         ld de,inifilebuffer
  421. .parseloop
  422.         ld bc,'='*256
  423.         call findnextchar
  424.         or a
  425.         ret z
  426.         cp b
  427.         jr nz,.parseloop
  428.         ld b,settingsvarcount
  429.         ld hl,settingsvars
  430. .varsearchloop
  431.         ld a,(hl)
  432.         inc hl
  433.         cp c
  434.         jr z,.foundvar
  435.         inc hl
  436.         inc hl
  437.         djnz .varsearchloop
  438.         jr .nextvar
  439. .foundvar
  440.         ld a,(hl)
  441.         inc hl
  442.         ld h,(hl)
  443.         ld l,a
  444.         ld (hl),e
  445.         inc hl
  446.         ld (hl),d
  447. .nextvar
  448.         ld b,0
  449.         call findnextchar
  450.         or a
  451.         jr nz,.parseloop
  452.         ret
  453.  
  454. settingsfilename
  455.         db "gp/gp.ini",0
  456.  
  457. settingsvars
  458.         db 0x19 : dw gpsettings.usemp3
  459.         db 0x14 : dw gpsettings.usemwm
  460.         db 0x74 : dw gpsettings.usept3
  461.         db 0x1F : dw gpsettings.usevgm
  462.         db 0x26 : dw gpsettings.usemoonmod
  463.         db 0x7F : dw gpsettings.moonmoddefaultpanning
  464.         db 0x7A : dw gpsettings.midiuartdelayoverride
  465.         db 0x61 : dw bomgemoonsettings
  466.         db 0x20 : dw gpsettings.usemoonmid
  467.         db 0x11 : dw gpsettings.mididevice
  468.         db 0x7E : dw gpsettings.moddevice
  469.         db 0x32 : dw inifileversionsettings
  470. settingsvarcount=($-settingsvars)/3
  471.  
  472. findnextchar
  473. ;de = ptr
  474. ;b = character to search
  475. ;c = LRC
  476. ;output: de = ptr past character, c = updated LRC
  477.         ld a,(de)
  478.         inc de
  479.         or a
  480.         ret z
  481.         cp "\n"
  482.         ret z
  483.         cp b
  484.         ret z
  485.         xor c
  486.         ld c,a
  487.         jr findnextchar
  488.  
  489. detectcpuspeed
  490.         ld hl,detectingcpustr
  491.         call print_hl
  492.         call swapinterrupthandler ;avoid OS while benchmarking
  493.         halt
  494.         ld hl,0
  495.         ld e,0
  496.         xor a
  497.         ld (.spincount),a
  498.         ld a,33
  499.         halt
  500. ;--> 42 t-states loop start
  501. .loop   inc e
  502.         jp nz,$+4
  503.         inc hl
  504.         nop
  505. .spincount=$+1
  506.         ld bc,0
  507.         cp c
  508.         jp nc,.loop
  509. ;<-- loop end
  510.         push de
  511.         push hl
  512.         call swapinterrupthandler ;restore OS handler
  513.         pop hl
  514.         pop de
  515. ;hl = hle / 32
  516.         sla e : adc hl,hl
  517.         sla e : adc hl,hl
  518.         sla e : adc hl,hl
  519.         ld (gpsettings.framelength),hl
  520.         ex de,hl
  521.         ld hl,-MIN_FRAME_LENGTH_FPGA
  522.         add hl,de
  523.         ld hl,cpufpgastr
  524.         jp c,print_hl
  525.         ld hl,-MIN_FRAME_LENGTH_ZXEVO
  526.         add hl,de
  527.         ld hl,cpuevostr
  528.         jp c,print_hl
  529.         ld hl,cpuatmstr
  530.         jp print_hl
  531.  
  532. swapinterrupthandler
  533.         di
  534.         ld hl,.store
  535.         ld de,0x38
  536.         ld b,3
  537. .loop   ld a,(de)
  538.         ld c,(hl)
  539.         ld (hl),a
  540.         ld a,c
  541.         ld (de),a
  542.         inc hl
  543.         inc de
  544.         djnz .loop
  545.         ei
  546.         ret
  547. .store  jp lightweightinterrupthandler
  548.  
  549. lightweightinterrupthandler
  550.         push af
  551.         ld a,(detectcpuspeed.spincount)
  552.         inc a
  553.         ld (detectcpuspeed.spincount),a
  554.         pop af
  555.         ei
  556.         ret
  557.  
  558. isbomgemoon
  559. ;output: zf=0 is BomgeMoon flag is set
  560.         ld hl,(bomgemoonsettings)
  561.         ld a,l
  562.         or h
  563.         ret z
  564.         ld a,(hl)
  565.         cp '0'
  566.         ret
  567.  
  568. detectmoonsound
  569.         ld hl,detectingmoonsoundstr
  570.         call print_hl
  571.         call ismoonsoundpresent
  572.         ld hl,notfoundstr
  573.         jp nz,print_hl
  574.         call opl4init
  575.         call isbomgemoon
  576.         jr z,.detectwaveports
  577.         ld hl,devicebomgemoon
  578.         ld (devicelist.moonsoundstraddr),hl
  579.         ld a,1
  580.         ld (gpsettings.moonsoundstatus),a
  581.         ld hl,bomgemoonstr
  582.         jp print_hl
  583. .detectwaveports
  584.         ld bc,9
  585.         ld d,0
  586.         ld hl,0x1200
  587.         ld ix,playlistpanel
  588.         call opl4readmemory
  589.         ld b,9
  590.         ld de,rom001200
  591.         ld hl,gpsettings.moonsoundstatus
  592. .cmploop
  593.         ld a,(de)
  594.         cp (ix)
  595.         jr nz,.waveportsfailed
  596.         inc de
  597.         inc ix
  598.         djnz .cmploop
  599.         ld (hl),2
  600.         ld hl,foundstr
  601.         jp print_hl
  602. .waveportsfailed
  603.         ld (hl),1
  604.         ld hl,firmwareerrorstr
  605.         call print_hl
  606.         ld hl,pressanykeystr
  607.         call print_hl
  608.         YIELDGETKEYLOOP
  609.         ret
  610.  
  611. detecttfm
  612.         ld hl,detectingtfmstr
  613.         call print_hl
  614.         call turnturbooff
  615.         call istfmpresent_notimer
  616.         push af
  617.         call turnturboon
  618.         pop af
  619.         ld hl,notfoundstr
  620.         jp nz,print_hl
  621.         ld a,1
  622.         ld (gpsettings.tfmstatus),a
  623.         ld hl,foundstr
  624.         jp print_hl
  625.  
  626. trywritingopm
  627.         dec a
  628.         jr nz,$-1
  629.         ld bc,OPM0_REG
  630.         out (c),e
  631.         ld bc,OPM1_REG
  632.         out (c),e
  633.         dec a
  634.         jr nz,$-1
  635.         ld bc,OPM0_DAT
  636.         out (c),d
  637.         ld bc,OPM1_DAT
  638.         out (c),d
  639.         ret
  640.  
  641. detectopm
  642.         ld hl,detectingopmstr
  643.         call print_hl
  644. ;check for non-zero as an early exit condition
  645.         ld bc,OPM0_DAT
  646.         in a,(c)
  647.         or a
  648.         ld hl,notfoundstr
  649.         jp nz,print_hl
  650. ;start timer
  651.         ld de,0xff12
  652.         call trywritingopm
  653.         ld de,0x2a14
  654.         call trywritingopm
  655. ;wait for the timer to finish
  656.         YIELD
  657.         YIELD
  658. ;check the timer flags
  659.         ld bc,OPM0_DAT
  660.         in a,(c)
  661.         cp 2
  662.         ld hl,notfoundstr
  663.         jp nz,print_hl
  664.         ld bc,OPM1_DAT
  665.         in a,(c)
  666.         cp 2
  667.         ld hl,founddualchipstr
  668.         jr z,.hasdualopm
  669.         call opmdisablechip1
  670.         ld hl,foundstr
  671.         ld a,1
  672. .hasdualopm
  673.         ld (gpsettings.opmstatus),a
  674.         call print_hl
  675.         jp opmstoptimers
  676.  
  677. trywritingopna1
  678.         dec a
  679.         jr nz,$-1
  680.         ld bc,OPNA1_REG
  681.         out (c),e
  682.         dec a
  683.         jr nz,$-1
  684.         ld bc,OPNA1_DAT
  685.         out (c),d
  686.         ret
  687.  
  688. detectopna
  689.         ld hl,detectingopnastr
  690.         call print_hl
  691. ;check for non-zero as an early exit condition
  692.         ld bc,OPNA1_REG
  693.         in a,(c)
  694.         or a
  695.         ld hl,notfoundstr
  696.         jp nz,print_hl
  697.         ld de,0xff26
  698.         call trywritingopna1
  699.         ld de,0x2a27
  700.         call trywritingopna1
  701. ;wait for the timer to finish
  702.         YIELD
  703.         YIELD
  704. ;check the timer flags
  705.         ld bc,OPNA1_REG
  706.         in a,(c)
  707.         cp 2
  708.         ld hl,notfoundstr
  709.         jp nz,print_hl
  710.         ld a,1
  711.         ld (gpsettings.opnastatus),a
  712.         ld de,0x3027
  713.         call trywritingopna1
  714.         ld de,0x0027
  715.         call trywritingopna1
  716.         ld hl,foundstr
  717.         jp print_hl
  718.  
  719. trywritingmoonsoundfm1
  720.         djnz $
  721.         ld a,e
  722.         out (MOON_REG1),a
  723.         djnz $
  724.         ld a,d
  725.         out (MOON_DAT1),a
  726.         ret
  727.  
  728. ismoonsoundpresent
  729. ;out: zf=1 if Moonsound is present, zf=0 if not
  730.         switch_to_pcm_ports_c2_c3
  731. ;check for 255 as an early exit condition
  732.         in a,(MOON_STAT)
  733.         add a,1
  734.         sbc a,a
  735.         ret nz
  736. ;read the status second time, now expect all bits clear
  737.         in a,(MOON_STAT)
  738.         or a
  739.         ret nz
  740. ;start timer
  741.         ld de,0xff03
  742.         call trywritingmoonsoundfm1
  743.         ld de,0x4204
  744.         call trywritingmoonsoundfm1
  745.         ld d,0x80
  746.         call trywritingmoonsoundfm1
  747. ;wait for the timer to finish
  748.         YIELD
  749.         YIELD
  750. ;check the timer flags
  751.         in a,(MOON_STAT)
  752.         cp 0xa0
  753.         ret nz
  754. ;there must be MoonSound in this system
  755.         call opl4stoptimers
  756.         xor a
  757.         ret
  758.  
  759. trywritingtfm1
  760.         dec a
  761.         jr nz,$-1
  762.         ld bc,OPN_REG
  763.         out (c),e
  764.         dec a
  765.         jr nz,$-1
  766.         ld bc,OPN_DAT
  767.         out (c),d
  768.         ret
  769.  
  770. istfmpresent_notimer
  771.         ld bc,OPN_REG
  772.         ld a,%11111100
  773.         out (c),a
  774.         ld de,0xff00
  775.         call trywritingtfm1
  776.         YIELD
  777.         YIELD
  778.         ld bc,OPN_REG
  779.         in a,(c)
  780.         and 128
  781.         ret
  782.  
  783. closeexistingplayer
  784. ;d = current pid
  785.         ld e,1
  786. .searchloop
  787.         ld a,e
  788.         cp d
  789.         jr z,.nextprocess
  790.         push de
  791.         OS_GETAPPMAINPAGES ;d,e,h,l=pages in 0000,4000,8000,c000
  792.         or a
  793.         ld a,d
  794.         pop de
  795.         jr nz,.nextprocess
  796.         push de
  797.         SETPGC000
  798.         ld hl,0xc000+COMMANDLINE
  799.         ld de,fullpathbuffer
  800.         ld bc,COMMANDLINE_sz
  801.         ldir
  802.         ld hl,fullpathbuffer
  803.         call skipword_hl
  804.         ld (hl),0
  805.         ld hl,fullpathbuffer
  806.         ld c,'/'
  807.         call findlastchar ;out: de = after last slash or start
  808.         call isplayer
  809.         pop de
  810.         jr z,.foundplayer
  811. .nextprocess
  812.         inc e
  813.         ld a,e
  814.         inc a
  815.         jr nz,.searchloop
  816.         ret
  817. .foundplayer
  818.         xor a
  819.         ld (0xc000+COMMANDLINE),a
  820.         push de
  821.         ld hl,closingplayerstr
  822.         call print_hl
  823.         pop de
  824. .waitloop
  825.         push de
  826.         YIELD
  827.         YIELD
  828.         YIELD
  829.         YIELD
  830.         OS_GETAPPMAINPAGES
  831.         pop de
  832.         or a
  833.         jr z,.waitloop
  834.         ret
  835.  
  836. isplayer
  837. ;de = command line file name
  838. ;out: zf=1 if gp, zf=0 otherwise
  839.         ld a,(de)
  840.         call tolower
  841.         cp 'g'
  842.         ret nz
  843.         inc de
  844.         ld a,(de)
  845.         call tolower
  846.         cp 'p'
  847.         ret nz
  848.         inc de
  849.         ld a,(de)
  850.         or a
  851.         ret z
  852.         cp '.'
  853.         ret
  854.  
  855. closingplayerstr
  856.         db "Closing old player instance...\r\n",0
  857. detectingmoonsoundstr
  858.         db "Detecting MoonSound...",0
  859. detectingtfmstr
  860.         db "Detecting TurboSound FM...",0
  861. detectingopmstr
  862.         db "Detecting YM2151...",0
  863. detectingopnastr
  864.         db "Detecting YM2608...",0
  865. notfoundstr
  866.         db "no device!\r\n",0
  867. foundstr
  868.         db "found!\r\n",0
  869. bomgemoonstr
  870.         db "OPL3\r\n",0
  871. founddualchipstr
  872.         db "2x\r\n",0
  873. detectingcpustr
  874.         db "Running on...",0
  875. cpufpgastr
  876.         db "FPGA\r\n",0
  877. cpuevostr
  878.         db "ZX Evolution\r\n",0
  879. cpuatmstr
  880.         db "ATM\r\n",0
  881. rom001200
  882.         db "Copyright"
  883. firmwareerrorstr
  884.         db "firmware problem!\r\nPlease update ZXM-MoonSound firmware to revision 1.01\r\n"
  885.         db "https://www.dropbox.com/s/1e0b2197emrhzos/zxm_moonsound01_frm0101.zip\r\n"
  886.         db "Or set BomgeMoon=1 in bin\\gp\\gp.ini to skip OPL4 ports detection.",0
  887.  
  888. builtininifile
  889.         incbin "gp.ini"
  890. builtininifilesize=$-builtininifile
  891.