home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / util / voiceshell-1.21.lha / VoiceShell / Source / VSConv.S < prev   
Encoding:
Text File  |  1994-03-13  |  10.2 KB  |  626 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1994        *
  4. *                        *
  5. *          Tomi Blinnikka        *
  6. *                        *
  7. *    Don't try to understand the code    *
  8. *                        *
  9. * Version 1.00    15/08/1993            *
  10. *           -20/09/1993            *
  11. * BUGS:                        *
  12. *                        *
  13. * Not finished and probably never will be.    *
  14. *                        *
  15. *************************************************
  16.  
  17.     INCLUDE    "JMPLibs.i"
  18.     INCLUDE    "libraries/dos.i"
  19.  
  20.     INCLUDE    "XREF:2.0.xref"
  21.     INCLUDE    "XREF:exec.xref"
  22.     INCLUDE    "XREF:dos.xref"
  23.  
  24.     INCLUDE    "libraries/voice.i"
  25.  
  26. PROGVERSION:    macro
  27.         dc.b    "1.00 (03.03.94)"
  28.         endm
  29.  
  30. TRUE:        EQU    1
  31. FALSE:        EQU    0
  32.  
  33.  
  34. ;VSFileVersion    'VS02'
  35.  
  36. GADLENG1VS02:    EQU    16
  37. GADLENG2VS02:    EQU    64
  38. GADLENGTHVS02:    EQU    (GADLENG1VS02+GADLENG2VS02)
  39.  
  40. ;VSFileVersion    'VS03'
  41.  
  42. VocabSIZE:    EQU    60
  43. GADLENG1:    EQU    16
  44. GADLENG2:    EQU    256
  45. GADLENGTH:    EQU    (GADLENG1+GADLENG2)
  46. VSMB_Size:    EQU    VocabSIZE*304
  47.  
  48. VS02Length:    EQU    23040
  49. VS03Length:    EQU    34560
  50.  
  51. VSHEADER_SIZE:    EQU    4
  52.  
  53. ;VCLI version 7.0
  54.  
  55. VCLIVocabSIZE:    EQU    48
  56. VCLIMB_Size:    EQU    VCLIVocabSIZE*304
  57.  
  58. NullBufSize1:    EQU    GADLENG2-GADLENG2VS02
  59. NullBufSize2:    EQU    (VocabSIZE*304)-(VCLIVocabSIZE*304)
  60.  
  61.         section    VSConv,CODE
  62.  
  63.         openlib    Dos,NoDos
  64.  
  65.         lea.l    CLTemplate1,a0
  66.         move.l    a0,d1
  67.         lea.l    CLArray1,a0
  68.         move.l    a0,d2
  69.         clr.l    d3
  70.         lib    Dos,ReadArgs
  71.         move.l    d0,RDArgs1
  72.         beq    NoRDArgs
  73.  
  74.         lib    Dos,Output
  75.         move.l    d0,_stdout
  76.  
  77.         lib    Dos,Input
  78.         move.l    d0,_stdin
  79.  
  80.         lea.l    FromFileText1,a0
  81.         bsr    Printer
  82.         move.l    SourceFile,a0
  83.         bsr    Printer
  84.         lea.l    CRLFText1,a0
  85.         bsr    Printer
  86.  
  87.         lea.l    DestText1,a0
  88.         bsr    Printer
  89.         move.l    DestFile,a0
  90.         bsr    Printer
  91.         lea.l    CRLFText1,a0
  92.         bsr    Printer
  93.  
  94.         move.l    SourceFile,d1
  95.         move.l    #MODE_OLDFILE,d2
  96.         lib    Dos,Open
  97.         move.l    d0,Source
  98.         beq    NoRDArgs
  99.  
  100.         move.l    DestFile,d1
  101.         move.l    #MODE_OLDFILE,d2
  102.         lib    Dos,Open
  103.         move.l    d0,Destination
  104.         beq    OpenDest2
  105.  
  106. OpenDest1:    lea.l    FExistsText1,a0
  107.         bsr    Printer
  108.  
  109.         bsr    GetYesNo
  110.         tst.l    d0
  111.         beq    OpenDest1
  112.  
  113.         cmp.l    #1,d0            ;Yes, replace
  114.         beq    OpenDest3
  115.  
  116.         cmp.l    #2,d0
  117.         bne    ShutDown        ;Error!
  118.  
  119.         tst.l    Destination        ;Don't open twice!
  120.         bne    ShutDown        ;Error!
  121.  
  122. OpenDest2:    move.l    DestFile,d1
  123.         move.l    #MODE_NEWFILE,d2
  124.         lib    Dos,Open
  125.         move.l    d0,Destination
  126.         beq    NoRDArgs
  127.  
  128. OpenDest3:    lea.l    CRLFText1,a0
  129.         bsr    Printer
  130.  
  131.         move.l    Source,d1
  132.         bsr    GetFileLength
  133.  
  134.         cmp.l    #VS02Length,d0
  135.         beq    DoVS02
  136.  
  137.         cmp.l    #VS03Length,d0
  138.         beq    DoVS03
  139.  
  140.         bra    DoVCLI
  141.  
  142. DoVS02:        lea.l    ConvText1,a0
  143.         bsr    Printer
  144.         lea.l    ConvText3,a0
  145.         bsr    Printer
  146.  
  147.         move.l    #VSMB_Size,d0
  148.         bsr    CopyMapBuffer
  149.         cmp.l    #-1,d0
  150.         beq    NoRDArgs
  151.  
  152.         move.l    #VocabSIZE,d6
  153.  
  154. DoVS02.1:    bsr    CopyGL02Bytes
  155.         cmp.l    #-1,d0
  156.         beq    NoRDArgs
  157.  
  158.         move.l    Destination,d1
  159.         move.l    #192,d3
  160.         bsr    WriteNulls
  161.  
  162.         sub.l    #1,d6
  163.         bne    DoVS02.1
  164.  
  165.         bra    ShutDown
  166.  
  167. DoVS03:        lea.l    NewestText1,a0
  168.         bsr    Printer
  169.         bra    ShutDown
  170.  
  171. DoVCLI:        move.l    Source,d1
  172.         bsr    GetHeader
  173.         cmp.l    #-1,d0
  174.         beq    NoRDArgs
  175.  
  176.         lea.l    VCLI70ID,a0
  177.         lea.l    Buffer1,a1
  178.         bsr    CmpStrings
  179.         tst.l    d0
  180.         bne    DoVCLI1.1
  181.  
  182.         lea.l    Buffer1,a0    ;DEBUG
  183.         bsr    Printer        ;DEBUG
  184.  
  185.         lea.l    UnknownText1,a0
  186.         bsr    Printer
  187.         bra    ShutDown
  188.  
  189. DoVCLI1.1:    lea.l    ConvText2,a0
  190.         bsr    Printer
  191.         lea.l    ConvText4,a0
  192.         bsr    Printer
  193.  
  194. ;Seek 12 bytes from the start, to beginning of MapBuffer,
  195. ;in source (VCLI file)
  196.  
  197.         move.l    Source,d1
  198.         move.l    #12,d2
  199.         move.l    #-1,d3
  200.         lib    Dos,Seek
  201.  
  202. ;Copy VCLI MapBuffer to Destination (VoiceShell)
  203.  
  204.         move.l    #VCLIMB_Size,d0
  205.         bsr    CopyMapBuffer
  206.         cmp.l    #-1,d0
  207.         beq    NoRDArgs
  208.  
  209.  
  210. ;Write (VocabSize*304) - (VCLIVocabSize*304) amount of NULL to Destination
  211.  
  212.         lea.l    NullBuffer2,a0
  213.         move.l    Destination,d1
  214.         move.l    a0,d2
  215.         move.l    #NullBufSize2,d3
  216.         lib    Dos,Write
  217.         cmp.l    #NullBufSize2,d0
  218.         bne    NoRDArgs
  219.  
  220. ;Copy strings from Source (VCLI) to Destination (VoiceShell) with steps of
  221. ;GADLENG1. Read in 16 bytes chunks, written in GADLENG1 chunks, 
  222. ;VCLIVocabSize times. Skip GADLENG2 in between.
  223.  
  224.         lea.l    Buffer3,a0
  225.         move.l    Source,d1
  226.         move.l    a0,d2
  227.         move.l    #16*48,d3
  228.         lib    Dos,Read
  229.  
  230. ;Done here (IE. NOT DONE!!!). Do rest here!
  231. ;
  232.  
  233. ;Seek to first CLI Command string in Destination (VoiceShell)
  234. ;
  235.         move.l    Destination,d1
  236.         move.l    #(VocabSIZE*304)+GADLENG1,d2
  237.         move.l    #-1,d3
  238.         lib    Dos,Seek
  239.  
  240. ;Copy strings from Source (VCLI) to Destination (VoiceShell) with steps of
  241. ;GADLENG2. Read in 128 bytes chunks, written in GADLENG2 chunks, 
  242. ;VCLIVocabSize times. Skip GADLENG1 in between.
  243.  
  244.         lea.l    Buffer3,a0
  245.         move.l    Source,d1
  246.         move.l    a0,d2
  247.         move.l    #128*48,d3
  248.         lib    Dos,Read
  249.  
  250. ;Done here (IE. NOT DONE!!!). Do rest here!
  251. ;
  252.  
  253.         lea.l    SorryText1,a0        ;DEBUG
  254.         bsr    Printer            ;DEBUG
  255.  
  256.         bra    ShutDown
  257.  
  258. GetYesNo:    move.l    _stdin,d1
  259.         move.l    #TRUE,d2
  260.         lib    Dos,SetMode
  261.  
  262.         move.l    _stdin,d1
  263.         lib    Dos,Flush
  264.  
  265.         move.l    _stdin,d1
  266.         lib    Dos,FGetC
  267.         cmp.l    #-1,d0
  268.         bne    GetYesNo2
  269.         lea.l    ErrorText1,a0
  270.         bsr    Printer
  271.         bra    GetYesNo_OUT
  272.  
  273. GetYesNo2:    cmp.l    #'y',d0
  274.         beq    GetYesNo3
  275.         cmp.l    #'Y',d0
  276.         beq    GetYesNo3
  277.         cmp.l    #'n',d0
  278.         beq    GetYesNo4
  279.         cmp.l    #'N',d0
  280.         beq    GetYesNo4
  281.         cmp.l    #13,d0
  282.         beq    GetYesNo4        ;Return
  283.         cmp.l    #10,d0
  284.         beq    GetYesNo4        ;Return
  285.         clr.l    d0
  286.         bra    GetYesNo_OUT
  287. GetYesNo3:    lea.l    YesText1,a0
  288.         bsr    Printer
  289.         move.l    #1,d0
  290.         bra    GetYesNo_OUT
  291. GetYesNo4:    lea.l    NoText1,a0
  292.         bsr    Printer
  293.         move.l    #2,d0
  294. ;        bra    GetYesNo_OUT        ;Careful!
  295. GetYesNo_OUT:    move.l    _stdin,d1
  296.         move.l    #FALSE,d2
  297.         lib    Dos,SetMode
  298.         rts
  299.  
  300. ;GetFileLength gets the length of a file and returns to the start of file
  301. ;
  302. ;Input    d1 = File
  303. ;
  304. ;Result    d0 = Length
  305. ;
  306.  
  307. GetFileLength:    move.l    d1,d3
  308.         bsr    SeekStart
  309.         move.l    d3,d1
  310.         bsr    SeekEnd
  311.         push    d0
  312.         move.l    d3,d1
  313.         bsr    SeekStart
  314.         pull    d0
  315.         rts
  316.  
  317.  
  318. ;Seek to end of file
  319. ;
  320. ;Input    d1 = File
  321. ;
  322. ;Result    d0 = Length
  323. ;
  324.  
  325. SeekEnd:    push    d2-d3
  326.         move.l    d1,d6
  327.         move.l    #00,d2
  328.         move.l    #01,d3
  329.         lib    Dos,Seek
  330.         move.l    d6,d1
  331.         lib    Dos,Seek
  332.         pull    d2-d3
  333.         rts
  334.  
  335. ;Seek to start of file
  336. ;
  337. ;Input    d1 = File
  338. ;
  339. ;Result    d0 = Length
  340. ;
  341.  
  342. SeekStart:    push    d2-d3
  343.         move.l    #0,d2
  344.         move.l    #-1,d3
  345.         lib    Dos,Seek
  346.         pull    d2-d3
  347.         rts
  348.  
  349. ;GetHeader reads 12 bytes into Buffer1 and seeks to start of file
  350. ;
  351. ;Input    d1 = File
  352.  
  353. GetHeader:    move.l    d1,d4
  354.  
  355.         bsr    SeekStart
  356.  
  357.         move.l    d4,d1
  358.         lea.l    Buffer1,a0
  359.         move.l    a0,d2
  360.         move.l    #12,d3
  361.         lib    Dos,Read
  362.         cmp.l    #12,d0
  363.         bne    GetHeader_ERR1
  364.  
  365.         move.l    d4,d1
  366.         bsr    SeekStart
  367.         rts
  368.  
  369. GetHeader_ERR1:    move.l    #-1,d0
  370.         rts
  371.  
  372. ;CopyMapBuffer reads d0 bytes into MapBuffer from start of file
  373. ;
  374. ;Input    d0 = Length
  375.  
  376. CopyMapBuffer:    push    d0
  377.         move.l    Source,d1
  378.         bsr    SeekStart
  379.  
  380.         move.l    Destination,d1
  381.         bsr    SeekStart
  382.  
  383.         move.l    Source,d1
  384.         lea.l    MapBuffer,a0
  385.         move.l    a0,d2
  386.         pull    d3
  387.         lib    Dos,Read
  388.         cmp.l    d3,d0
  389.         bne    CopyMB_ERR1
  390.  
  391.         move.l    Destination,d1
  392.         lib    Dos,Write
  393.         cmp.l    d3,d0
  394.         bne    CopyMB_ERR1
  395.         rts
  396.  
  397. CopyMB_ERR1:    move.l    #-1,d0
  398.         rts
  399.  
  400. ;CopyGL02Bytes copies GADLENG2VS02 bytes from Source to Destination
  401. ;
  402.  
  403. CopyGL02Bytes:    move.l    Source,d1        ;Read GADLENGTHVS02 bytes
  404.         lea.l    Buffer2,a0
  405.         move.l    a0,d2
  406.         move.l    #GADLENGTHVS02,d3
  407.         lib    Dos,Read
  408.         cmp.l    #GADLENGTHVS02,d0
  409.         bne    CopyGL02_ERR1
  410.  
  411.         move.l    Destination,d1        ;Write GADLENGTHVS02 bytes
  412.         lib    Dos,Write
  413.         cmp.l    #GADLENGTHVS02,d0
  414.         bne    CopyGL02_ERR1
  415.         rts
  416.  
  417. CopyGL02_ERR1:    move.l    #-1,d0
  418.         rts
  419.  
  420. ;WriteNulls writes 192 NULLs to Destination
  421. ;
  422.  
  423. WriteNulls:    move.l    Destination,d1
  424.         lea.l    NullBuffer,a0
  425.         move.l    a0,d2
  426.         move.l    #NullBufSize1,d3
  427.         lib    Dos,Write
  428.         cmp.l    #NullBufSize1,d0
  429.         bne    WriteNull_ERR1
  430.         rts
  431.  
  432. WriteNull_ERR1:    move.l    #-1,d0
  433.         rts
  434.  
  435. CloseFiles:    move.l    Source,d1
  436.         beq    CloseFiles2
  437.         lib    Dos,Close
  438.  
  439. CloseFiles2:    move.l    Destination,d1
  440.         beq    CloseFiles3
  441.         lib    Dos,Close
  442. CloseFiles3:    rts
  443.  
  444. ;Compares two strings.
  445. ;
  446. ;Input    a0 = String 1
  447. ;    a1 = String 2
  448. ;
  449. ;Result    d0 = 0 if not same
  450. ;
  451. ;BUGS
  452. ;
  453. ;String 1 has to have NULL at end!
  454. ;
  455.  
  456. CmpStrings:    bsr    GetLength
  457.         move.l    d0,d4        ;length of string1 to d4
  458.         push    a0
  459.         move.l    a1,a0
  460.         bsr    GetLength
  461.         pull    a0
  462.         cmp.l    d4,d0        ;length of string2 in d3
  463.         bne    CmpStrings1.1
  464. CmpStrings1:    tst.b    (a0)
  465.         beq    CmpStrings2
  466.         cmp.b    (a0)+,(a1)+
  467.         beq    CmpStrings1
  468. CmpStrings1.1:    clr.l    d0
  469.         rts
  470. CmpStrings2:    move.l    #-1,d0
  471.         rts
  472.  
  473. ;Get length of text in given address
  474. ;
  475. ;Input a0 = Address of null terminated text string
  476. ;
  477. ;Result d0 = Length
  478.  
  479. GetLength:    push    a0
  480.         clr.l    d0
  481.         cmp.l    #$00,a0        ;fixes enforcer hit
  482.         beq    GetLength_OUT
  483. GetLength2:    add.l    #1,d0
  484.         tst.b    (a0)+
  485.         bne    GetLength2
  486.         sub.l    #1,d0        ;don't include NULL
  487. GetLength_OUT:    pull    a0
  488.         rts
  489.  
  490. ShutDown:    move.l    RDArgs1,d1
  491.         beq    ShutDown9000
  492.         lib    Dos,FreeArgs
  493.  
  494. ShutDown9000:    bsr    CloseFiles
  495.  
  496. ShutDown1000:    closlib    Dos
  497.         move.l    #RETURN_OK,d0
  498.         rts
  499.  
  500. NoDos:        move.l    #RETURN_FAIL,d0
  501.         rts
  502.  
  503. NoRDArgs:    lib    Dos,IoErr
  504.         move.l    d0,d1
  505.         clr.l    d2
  506.         lib    Dos,PrintFault
  507.         bra    ShutDown
  508.  
  509. Printer:    printa    a0
  510.         rts
  511.  
  512.  
  513. ;Library stuff
  514.  
  515.         libnames
  516.  
  517. ;Reservations
  518.  
  519. _stdin:        dc.l    0
  520. _stdout:        dc.l    0
  521. RDArgs1:    dc.l    0
  522. Source:        dc.l    0
  523. Destination:    dc.l    0
  524.  
  525.  
  526. ;Options
  527.  
  528. CLArray1:
  529. SourceFile:    dc.l    0
  530. DestFile:    dc.l    0
  531.  
  532. ;Strings, errors etc.
  533.  
  534. FExistsText1:    dc.b    13,10,"File already exists! Replace? (y/N) ",0
  535. UnknownText1:    dc.b    "Unknown file type!",13,10,0
  536. NewestText1:    dc.b    13,10,"This is the newest version of the datafile ",13,10
  537.         dc.b    "for VoiceShell that this program recognizes.",13,10,13,10
  538.         dc.b    "ERROR: Can't convert to anything!",13,10,0
  539. ErrorText1:    dc.b    "Error!",13,10,0
  540.  
  541. ;Strings, others
  542.  
  543. CLTemplate1:    dc.b    "FROM/A,TO/A",0
  544. VSConvVersion:    dc.b    "$VER: VoiceShell Conversion Utility "
  545.         PROGVERSION
  546.         dc.b    " (c) Copyright Tomi Blinnikka 1993",0
  547.  
  548. FromFileText1:    dc.b    13,10,"Source file : ",0
  549. DestText1:    dc.b    "Destination : ",0
  550.  
  551. ConvText1:    dc.b    "Converting VoiceShell: ",0
  552. ConvText2:    dc.b    "Converting VCLI: ",0
  553. ConvText3:    dc.b    "1.07 - 1.11 to 1.12.",13,10,0
  554. ConvText4:    dc.b    "VCLI 7.0 to VoiceShell 1.12.",13,10,0
  555.  
  556. SorryText1:    dc.b    "Sorry, forgot to write this part of the program...",13,10,0
  557.  
  558. YesText1:    dc.b    "Yes",13,10,0
  559. NoText1:    dc.b    "No",13,10,0
  560. CRLFText1:    dc.b    13,10,0
  561.  
  562.  
  563. ;File headers
  564.  
  565. VSVersion02:    dc.b    'VS02',0        ;For prefs only!
  566. VSVersion03:    dc.b    'VS03',0        ;For prefs only!
  567. VCLI70ID:    dc.b    "VCLI7.0 DATA",0
  568.  
  569.         ds.w    0
  570.  
  571.  
  572. ;Other stuff, part II
  573.  
  574.         Section VS,BSS
  575.  
  576. DATA_START:
  577.  
  578. MapBuffer:    ds.b    (VocabSIZE*304)        ;60 words
  579.  
  580. CmdList:    ds.b    (VocabSIZE*GADLENGTH)
  581.  
  582. DATA_END:    ds.l    1
  583.  
  584. DataSize:    EQU    (DATA_END-DATA_START)
  585.  
  586.  
  587. Buffer1:    ds.b    16
  588. Buffer2:    ds.b    GADLENG2VS02
  589. Buffer3:    ds.b    128*48            ;VCLI strings/cmds
  590.  
  591. NullBuffer:    ds.b    NullBufSize1
  592. NullBuffer2:    ds.b    NullBufSize2
  593.  
  594.  
  595.         end
  596.  
  597. ;Read configuration bytes from Source (VCLI)
  598.  
  599. ;    Byte 1
  600. ;
  601. ;    Sampler ID =    0 for PerfecSound3
  602. ;            1 for Sound Master
  603. ;            2 for Generic
  604. ;            3 for DSS8
  605. ;    Byte2
  606. ;
  607. ;        Sampler Gain = 0 to 16 for DSS8
  608.  
  609.         lea.l    Buffer1,a0
  610.  
  611.         move.b    a0,d0
  612.         btst.b    d0
  613.         beq    DoVCLI1.XX
  614.         move.b    #TIMER_B,
  615.         bra    DoVCLI1.XX+1
  616. DoVCLI1.XX:    move.b    #TIMER_A,
  617.  
  618. DoVCLI1.XX+1:    add.l    #1,a0
  619.         move.b    (a0),PrefsSampType
  620.  
  621.         add.l    #1,a0
  622.  
  623.         move.b    (a0),PrefsGain
  624.  
  625.         rts
  626.