home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / cdrom / scsi-gui10.lha / scsi-gui.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1995-02-03  |  17.0 KB  |  602 lines

  1. /* SCSIUTIL ANSI GUI V1.0 */
  2.  
  3. parse arg prefsfile
  4.  
  5. if prefsfile='?' then do
  6.   say 'Usage: rx scsi-gui [<prefs-file>]'
  7.   exit
  8. end
  9.  
  10. if arg()=0 then prefsfile = 's:scsi-gui.prefs'
  11.  
  12. if ~show('l','rexxreqtools.library') then do
  13.   if ~addlib('rexxreqtools.library',0,-30,37) then do
  14.     say 'Need rexxreqtools.library V37'
  15.     exit
  16.   end
  17. end
  18.  
  19. if ~show('l','rexxsupport.library') then do
  20.   if ~addlib('rexxsupport.library',0,-30,34) then do
  21.     exit
  22.   end
  23. end
  24.  
  25. address command
  26. rttags = 'rt_reqpos=reqpos_pointer'
  27. eztitle = 'Oh my god!'
  28. channel.0 = 'Right '
  29. channel.1 = 'Left  '
  30. channel.2 = 'Stereo'
  31.  
  32. if ~loadprefs() then signal ende
  33.  
  34. edge = '1H'
  35. spos = '1H'
  36. bpos = '1H'
  37. lrpos = '4H'
  38. stpos = '9H'
  39. bitpos = '7H'
  40. trpos = '37H'
  41. kbpos = '33H'
  42. sfpos = '12H'
  43. white = ''
  44. nv = ''
  45. cr = '0a'x
  46. cr2 = cr||cr
  47. clr = d2c(12)
  48. tempfile = 't:scsi.temp'
  49.  
  50. call getfontheight
  51. wid = width*48          /* 46 characters wide, plus 2 safety */
  52. hei = theight + height*17  /* title height plus 17 lines */
  53.  
  54. if ~open('wd','RAW:'windowx'/'windowy'/'wid'/'hei'/SCSIUtil ANSI GUI V1.0 - ESC to quit/NOSIZE/SCREEN 'ps,'W') then do
  55.   say nv'Cannot open output window'
  56.   exit
  57. end
  58.  
  59. active = 0    /* 0=Sectors, 1=Blocks */
  60. posi = 1      /* Minutes */
  61. num = 1       /* Track nummer */
  62. maxtracks = 0
  63. maxsectors = 100*60*75-1
  64. chan.0 = 'R'  /*              */
  65. chan.1 = 'L'  /* für SCSIUtil */
  66. chan.2 = 'S'  /*              */
  67.  
  68. call main     /* Fensteraufbau */
  69.  
  70. delta.1 = 75*60
  71. delta.4 = 75
  72. delta.7 = 1
  73.  
  74. c = 0
  75. do until c=27 /* wird NACH jeder Iteration ausgewertet */
  76.  
  77.   select
  78.  
  79.   /*=======================================*/
  80.   /*                                       */
  81.   /*  Wert vergrößern                      */
  82.   /*                                       */
  83.   /*=======================================*/
  84.   when c=43 then do
  85.     if active=0 then do
  86.       if sectors<maxsectors-(delta.posi-1)-blocks then do
  87.         sectors = sectors + delta.posi
  88.         call outcalc_s
  89.       end
  90.     end
  91.     else
  92.     if active=1 then do
  93.       if blocks<maxsectors-(delta.posi-1)-sectors then do
  94.         blocks = blocks + delta.posi
  95.         call outcalc_b
  96.       end
  97.     end
  98.   end /* + */
  99.  
  100.   /*=======================================*/
  101.   /*                                       */
  102.   /*  Wert verringern                      */
  103.   /*                                       */
  104.   /*=======================================*/
  105.   when c=45 then do
  106.     if active=0 then do
  107.       if sectors>delta.posi-1 then do
  108.         sectors = sectors - delta.posi
  109.         call outcalc_s
  110.       end
  111.     end
  112.     else
  113.     if active=1 then do
  114.       if blocks>delta.posi-1 then do
  115.         blocks = blocks - delta.posi
  116.         call outcalc_b
  117.       end
  118.     end
  119.   end /* - */
  120.  
  121.   /*=======================================*/
  122.   /*                                       */
  123.   /*  Track eingeben                       */
  124.   /*                                       */
  125.   /*=======================================*/
  126.   when c=48 then do
  127.     newnum = rtgetlong(num,,'Track number',,rttags)
  128.     if newnum~='' then do
  129.       if newnum<=maxtracks & newnum>0 then do
  130.         num = newnum
  131.         sectors = track.num
  132.         if sectors+blocks>=maxsectors then blocks = maxsectors-sectors
  133.         call outcalc_s
  134.         call outcalc_b
  135.       end
  136.     end
  137.   end /* 0 */
  138.  
  139.   /*=======================================*/
  140.   /*                                       */
  141.   /*  Prefs speichern                      */
  142.   /*                                       */
  143.   /*=======================================*/
  144.   when c=112 then do
  145.     if ~open('pr',prefsfile,'W') then do
  146.       call rtezrequest('Cannot save prefs!','_Oh boy',eztitle,rttags)
  147.     end
  148.     else do
  149.       call writeln('pr','Device 'device)
  150.       call writeln('pr','Unit 'unit)
  151.       call writeln('pr','Pubscreen 'ps)
  152.       call writeln('pr','Samplepath 'spath)
  153.       call writeln('pr','Samplefile 'sfile)
  154.       call writeln('pr','Bits 'bits)
  155.       call writeln('pr','Offset 'sectors)
  156.       call writeln('pr','Length 'blocks)
  157.       call writeln('pr','Channel 'channel.lr)
  158.       call writeln('pr','WindowX 'windowx)
  159.       call writeln('pr','WindowY 'windowy)
  160.       call close('pr')
  161.     end
  162.   end /* p */
  163.  
  164.   /*=======================================*/
  165.   /*                                       */
  166.   /*  Bits togglen                         */
  167.   /*                                       */
  168.   /*=======================================*/
  169.   when c=98 then do
  170.     bits = 24 - bits
  171.     call writech('wd',bitpos||white||right(bits,2)||edge)
  172.     changed = 1
  173.     if bits=8 & lr=2 then do
  174.       lr = 0
  175.       call writech('wd',lrpos||white||channel.lr||edge)
  176.     end
  177.     call outcalc_kb
  178.   end /* b */
  179.  
  180.   /*=======================================*/
  181.   /*                                       */
  182.   /*  Refresh                              */
  183.   /*                                       */
  184.   /*=======================================*/
  185. /*
  186.   when c=114 then do
  187.     call main
  188.   end /* r */
  189. */
  190.  
  191.   when c=155 then do
  192.     c = c2d(readch('wd',1))
  193.  
  194.     select
  195.  
  196.     /*=======================================*/
  197.     /*                                       */
  198.     /*  Cursor UP/DOWN                       */
  199.     /*                                       */
  200.     /*=======================================*/
  201.     when c=66 | c=65 then do
  202.       oldposi = posi
  203.       posi = 0
  204.       if active=0 then call outcalc_s
  205.                   else call outcalc_b
  206.       call writech('wd',nv||out)
  207.       active = 1 - active
  208.       posi = oldposi
  209.       if active=0 then call outcalc_s
  210.                   else call outcalc_b
  211.     end /* cursor up/down */
  212.  
  213.     /*=======================================*/
  214.     /*                                       */
  215.     /*  Cursor RIGHT                         */
  216.     /*                                       */
  217.     /*=======================================*/
  218.     when c=67 then do
  219.       posi = posi + 3
  220.       if posi>7 then do
  221.         if active=0 then call outcalc_s
  222.                     else call outcalc_b
  223.         call writech('wd',nv||out)
  224.         posi = 1
  225.         active = 1 - active
  226.       end
  227.       if active=0 then call outcalc_s
  228.                   else call outcalc_b
  229.     end /* cursor right */
  230.  
  231.     /*=======================================*/
  232.     /*                                       */
  233.     /*  Cursor LEFT                          */
  234.     /*                                       */
  235.     /*=======================================*/
  236.     when c=68 then do
  237.       posi = posi - 3
  238.       if posi<1 then do
  239.         if active=0 then call outcalc_s
  240.                     else call outcalc_b
  241.         call writech('wd',nv||out)
  242.         posi = 7
  243.         active = 1 - active
  244.       end
  245.       if active=0 then call outcalc_s
  246.                   else call outcalc_b
  247.     end /* cursor left */
  248.  
  249.     /*=======================================*/
  250.     /*                                       */
  251.     /*  CD gewechselt                        */
  252.     /*                                       */
  253.     /*=======================================*/
  254.     when c=63 then do
  255.       c = c2d(readch('wd',1))
  256.       if c=126 then call cdchange
  257.     end /* help */
  258.  
  259.     otherwise
  260.     end /* select */
  261.  
  262.   end /* c=155 */
  263.  
  264.   /*=======================================*/
  265.   /*                                       */
  266.   /*  Samplen und abspielen                */
  267.   /*                                       */
  268.   /*=======================================*/
  269.   when c=32 then do
  270.     if maxtracks>0 then do
  271.       if blocks>0 then do
  272.         if changed then do
  273.           if exists(spath||sfile) then do
  274.             call writech('wd',stpos||white'Deleting file'edge)
  275.             'delete >nil: "'spath||sfile'"'
  276.           end
  277.           call writech('wd',stpos||white'Sampling...'edge)
  278.           changed = 0
  279.           if bits=16 then do
  280.             'scsiutil -d'device' 'unit' -d'chan.lr' 'sectors' 'blocks' 0 >"'spath||sfile'"'
  281.           end
  282.           else do
  283.             'scsiutil -d'device' 'unit' -D'chan.lr' 'sectors' 'blocks' >"'spath||sfile'"'
  284.           end
  285.         end /* changed */
  286.         if exists(spath||sfile) then do
  287.           if word(statef(spath||sfile),2)=0 then do
  288.             'delete >nil: "'spath||sfile'"'
  289.           end
  290.           else do
  291.             call writech('wd',stpos||white'Playing...'edge)
  292.             if lr<2 then do /* left oder right */
  293.               if bits=16 then do
  294.                 'play16 raw bits=16 intel freq=44100 "'spath||sfile'" >nil:'
  295.               end
  296.               else do
  297.                 'play16 raw bits=8 freq=44100 "'spath||sfile'" >nil:'
  298.               end
  299.             end
  300.             else do /* sterero */
  301.               if bits=16 then do
  302.                 'play16 raw bits=16 intel tracks=2 freq=44100 "'spath||sfile'" >nil:'
  303.               end
  304.               else do
  305.                 'play16 raw bits=8 tracks=2 freq=44100 "'spath||sfile'" >nil:'
  306.               end
  307.             end /* sterero */
  308.             call writech('wd',stpos||white'OK'edge)
  309.           end /* sfile nichtleer */
  310.         end /* sfile existiert */
  311.       end /* blocks ok */
  312.       else do
  313.         call writech('wd',stpos||white'Length too short'edge)
  314.       end /* blocks nicht ok */
  315.     end /* maxtracks ok */
  316.     else do
  317.       call writech('wd',stpos||white'Please change CD'edge)
  318.     end /* maxtracks nicht ok */
  319.   end /* space */
  320.  
  321.   /*=======================================*/
  322.   /*                                       */
  323.   /*  Left/Right/Stereo channel            */
  324.   /*                                       */
  325.   /*=======================================*/
  326.   when c=9 then do
  327.     lr = lr + 1
  328.     if bits=8 & lr=2 then lr = 0
  329.     if lr>2 then lr = 0
  330.     call writech('wd',lrpos||white||channel.lr||edge)
  331.     call outcalc_kb
  332.     changed = 1
  333.   end /* tab */
  334.  
  335.   /*=======================================*/
  336.   /*                                       */
  337.   /*  Select Destination                   */
  338.   /*                                       */
  339.   /*=======================================*/
  340.   when c=100 then do
  341.     jn = 0
  342.     do while jn=0
  343.       newname = rtfilerequest(,sfile,'Sample Destination',,rttags||' rtfi_buffer=true rtfi_initialpath="'spath'"')
  344.       if newname~='' & right(newname,1)~=':' & right(newname,1)~='/' then do
  345.         ind = lastpos('/',newname)
  346.         if ind>0 then do
  347.           sfile = substr(newname,ind+1)
  348.           spath = left(newname,ind)
  349.         end
  350.         else do
  351.           ind = lastpos(':',newname)
  352.           if ind>0 then do
  353.             sfile = substr(newname,ind+1)
  354.             spath = left(newname,ind)
  355.           end
  356.           else do
  357.             sfile = newname
  358.             spath = ''
  359.           end
  360.         end
  361.         if exists(spath||sfile) then do
  362.           jn = rtezrequest('This file already exists!'cr'Can I kick it?','_Yeah!|Wo_n''t you!',eztitle,rttags||' rtez_flags=ezreqf_centertext')
  363.         end
  364.         else jn = 1
  365.         if jn>0 then call writech('wd',sfpos||white||left(sfile,17)||edge)
  366.       end /* ok */
  367.       else jn = 1
  368.     end /* do while */
  369.   end /* d */
  370.  
  371.   otherwise
  372.   end /* select */
  373.  
  374.   c = c2d(readch('wd',1))
  375. end
  376.  
  377. ende:
  378. call close('wd')
  379. call rtfreefilebuffer()
  380. exit
  381.  
  382.  
  383. colour:
  384. if posi=1 then out = white||insert(nv,out,9)
  385. else
  386. if posi=4 then out = nv||insert(white,insert(nv,out,12),10)
  387. else
  388. if posi=7 then out = nv||insert(white,out,13)
  389. else out = nv||out
  390. return
  391.  
  392. outcalc_b:
  393. out3 = blocks//75
  394. out1 = blocks%(75*60)
  395. out2 = (blocks-out3-out1*75*60)%75
  396. out = bpos||right(out1,2,'0')':'right(out2,2,'0')':'right(out3,2,'0')
  397. if active=1 then call colour
  398.             else out = nv||out
  399. call writech('wd',out||edge)
  400. call outcalc_kb
  401. changed = 1
  402. return
  403.  
  404. outcalc_kb:
  405. if lr=2 then kb = 588*4*blocks%1024
  406.         else if bits=16 then kb = 588*2*blocks%1024
  407.                         else kb = 588*blocks%1024
  408. out = kbpos||white||right(kb,6)
  409. call writech('wd',out||edge)
  410. return
  411.  
  412. outcalc_s:
  413. out3 = sectors//75
  414. out1 = sectors%(75*60)
  415. out2 = (sectors-out3-out1*75*60)%75
  416. out = spos||right(out1,2,'0')':'right(out2,2,'0')':'right(out3,2,'0')
  417. if active=0 then call colour
  418.             else out = nv||out
  419. call writech('wd',out||edge)
  420. changed = 1
  421. return
  422.  
  423. /*=======================================*/
  424. /*                                       */
  425. /*  CD Wechsel                           */
  426. /*                                       */
  427. /*=======================================*/
  428. cdchange:
  429. call writech('wd',stpos||white'Reading capacity'edge)
  430. 'scsiutil -d'device' 'unit' -c >'tempfile
  431. if open('tmp',tempfile,'R') then do
  432.   line = readln('tmp')
  433.   call close('tmp')
  434.   'delete >nil: 'tempfile
  435. end
  436. else line = ''
  437.  
  438. if ~abbrev(line,'Max Sec =') then do
  439.   call writech('wd',stpos||white'Something is wrong with CD!')
  440.   maxtracks = 0
  441.   maxsectors = 100*60*75-1
  442. end
  443. else do
  444.  
  445.   parse var line t1 t2 t3 maxsectors .
  446.  
  447.   call writech('wd',stpos||white'Reading tracks'edge)
  448.   'scsiutil -d'device' 'unit' -t >'tempfile
  449.   if open('tmp',tempfile,'R') then do
  450.     call readln('tmp')
  451.     call readln('tmp')
  452.     do i=1 until eof('tmp')
  453.       track.i = readln('tmp')
  454.       if ~eof('tmp') then track.i = word(track.i,words(track.i))
  455.     end
  456.     maxtracks = i-2
  457.     call close('tmp')
  458.     'delete >nil: 'tempfile
  459.   end
  460.   else maxtracks = 0
  461.  
  462.   changed = 1
  463.   call writech('wd',stpos||white'OK')
  464.  
  465. end
  466.  
  467. call writech('wd',trpos||white||right(maxtracks,2)||edge)
  468.  
  469. if sectors+blocks>maxsectors then do
  470.   if sectors<maxsectors then blocks = maxsectors - sectors
  471.   else do
  472.     if blocks>maxsectors then blocks = 0
  473.     sectors = maxsectors - blocks
  474.   end
  475.   call outcalc_s
  476.   call outcalc_b
  477. end
  478.  
  479. return
  480.  
  481.  
  482. /*=======================================*/
  483. /*                                       */
  484. /*  Prefs laden                          */
  485. /*                                       */
  486. /*=======================================*/
  487. loadprefs:
  488. device = ''
  489. unit = ''
  490. ps = 'Workbench'
  491. spath = ''
  492. sfile = 'Sample.dump'
  493. bits = 16
  494. sectors = 0   /* start  */
  495. blocks = 0    /* length */
  496. lr = 0        /* links (1) oder rechts (0) oder stereo (2) */
  497. windowx = 100
  498. windowy = 80
  499.  
  500. if open('pr',prefsfile,'R') then do
  501.   do until eof('pr')
  502.     line = readln('pr')
  503.     keyword = upper(word(line,1))
  504.     data = delword(line,1,1)
  505.     select
  506.       when keyword='DEVICE' then device = data
  507.       when keyword='UNIT' then unit = data
  508.       when keyword='PUBSCREEN' then ps = data
  509.       when keyword='SAMPLEPATH' then spath = data
  510.       when keyword='SAMPLEFILE' then sfile = data
  511.       when keyword='BITS' then bits = data
  512.       when keyword='OFFSET' then sectors = data
  513.       when keyword='LENGTH' then blocks = data
  514.       when keyword='WINDOWX' then windowx = data
  515.       when keyword='WINDOWY' then windowy = data
  516.       when keyword='CHANNEL' then do
  517.         do i=0 to 2
  518.           if channel.i=data then lr = i
  519.         end
  520.       end
  521.     otherwise
  522.     end
  523.   end
  524.   call close('pr')
  525.   rttags = rttags||' rt_pubscrname="'ps'"'
  526. end
  527. else call rtezrequest('Prefs unloadable!','_What the hell',eztitle,rttags)
  528.  
  529. if device='' then do
  530.   device = rtgetstring('scsi3.device',,'Please enter the CDROM device',,rttags)
  531.   if device='' then return 0
  532. end
  533. if unit='' then do
  534.   unit = rtgetlong(3,,'CDRom Unit',,rttags)
  535.   if unit='' then return 0
  536. end
  537.  
  538. return 1
  539.  
  540. /*=======================================*/
  541. /*                                       */
  542. /*  Fensterinhalt aufbauen               */
  543. /*                                       */
  544. /*=======================================*/
  545. main:
  546. call writech('wd',clr||nv||cr)
  547. call writech('wd','         .--------,'cr)
  548. call writech('wd','  Offset |'white'00'nv':00:00| (Mins:Secs:Blocks)'cr)
  549. call writech('wd','         `--------'' (Cursor keys to move, +/-)'cr)
  550. call writech('wd','         .--------,             ,------,'cr)
  551. call writech('wd','  Length |00:00:00|    Channel: |'white||channel.lr||nv'| (TAB)'cr)
  552. call writech('wd','         `--------''             `------'''cr)
  553. call writech('wd','                                   .--,'cr)
  554. call writech('wd',white'SPACE 'nv'sample and listen       Bits |'white||right(bits,2)||nv'| (B)'cr)
  555. call writech('wd',white'HELP  'nv'recognize diskchange         `--''  'cr)
  556. call writech('wd',white'D     'nv'file='white||left(sfile,17)||nv' CD has 'white||right(maxtracks,2)||nv' Tracks'cr)
  557. call writech('wd',white'P     'nv'save preferences'cr)
  558. call writech('wd',white'0     'nv'select Track      Size is 'white'     0'nv' kB'cr)
  559. call writech('wd',cr'Status: 'white'OK'cr)
  560.  
  561. call outcalc_s
  562. call outcalc_b
  563. return
  564.  
  565. /*=======================================*/
  566. /*                                       */
  567. /*  Breite und Höhe des Systemfonts      */
  568. /*                                       */
  569. /*=======================================*/
  570. getfontheight:
  571. fontfile = 'env:sys/font.prefs'
  572. if open('fo',fontfile,'R') then do
  573.   font = readch('fo',word(statef(fontfile),2))
  574.   call close('fo')
  575.  
  576. /* System font */
  577.   font = substr(font,index(font,'FONT')+4)
  578.   font = substr(font,index(font,'FONT')+4)
  579.   height = c2d(substr(font,29,2))
  580.  
  581. /* Screen/Window title font */
  582.   tfont = substr(font,index(font,'FONT')+4)
  583.   theight = c2d(substr(tfont,29,2))
  584.  
  585. /* Font laden -> Offset $72 = fixed width */
  586.   font = substr(font,33)
  587.   font = left(font,index(font,d2c(0))-1-5)
  588.   if open('fo','FONTS:'font'/'height,'R') then do
  589.     width = c2d(right(readch('fo',116),2))
  590.     call close('fo')
  591.   end
  592.   else if height=9 then width = 10 /* koennte ja auch topaz-9 sein */
  593.                    else width = 8  /* topaz-8 oder was anderes */
  594. end
  595. else do /* keine font.prefs gefunden */
  596.   theight = 8
  597.   height = 8
  598.   width = 8
  599. end
  600. return
  601.  
  602.