home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / VoiceShell / VSConv.S < prev    next >
Text File  |  1993-12-21  |  10KB  |  624 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1993        *
  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. *************************************************
  14.  
  15.     INCLUDE    "JMPLibs.i"
  16.     INCLUDE    "libraries/dos.i"
  17.  
  18.     INCLUDE    "XREF:2.0.xref"
  19.     INCLUDE    "XREF:exec.xref"
  20.     INCLUDE    "XREF:dos.xref"
  21.  
  22.     INCLUDE    "libraries/voice.i"
  23.  
  24. PROGVERSION:    macro
  25.         dc.b    "1.00 (20.09.93)"
  26.         endm
  27.  
  28. TRUE:        EQU    1
  29. FALSE:        EQU    0
  30.  
  31.  
  32. ;VSFileVersion    'VS02'
  33.  
  34. GADLENG1VS02:    EQU    16
  35. GADLENG2VS02:    EQU    64
  36. GADLENGTHVS02:    EQU    (GADLENG1VS02+GADLENG2VS02)
  37.  
  38. ;VSFileVersion    'VS03'
  39.  
  40. VocabSIZE:    EQU    60
  41. GADLENG1:    EQU    16
  42. GADLENG2:    EQU    256
  43. GADLENGTH:    EQU    (GADLENG1+GADLENG2)
  44. VSMB_Size:    EQU    VocabSIZE*304
  45.  
  46. VS02Length:    EQU    23040
  47. VS03Length:    EQU    34560
  48.  
  49. VSHEADER_SIZE:    EQU    4
  50.  
  51. ;VCLI version 7.0
  52.  
  53. VCLIVocabSIZE:    EQU    48
  54. VCLIMB_Size:    EQU    VCLIVocabSIZE*304
  55.  
  56. NullBufSize1:    EQU    GADLENG2-GADLENG2VS02
  57. NullBufSize2:    EQU    (VocabSIZE*304)-(VCLIVocabSIZE*304)
  58.  
  59.         section    VSConv,CODE
  60.  
  61.         openlib    Dos,NoDos
  62.  
  63.         lea.l    CLTemplate1,a0
  64.         move.l    a0,d1
  65.         lea.l    CLArray1,a0
  66.         move.l    a0,d2
  67.         clr.l    d3
  68.         lib    Dos,ReadArgs
  69.         move.l    d0,RDArgs1
  70.         beq    NoRDArgs
  71.  
  72.         lib    Dos,Output
  73.         move.l    d0,_stdout
  74.  
  75.         lib    Dos,Input
  76.         move.l    d0,_stdin
  77.  
  78.         lea.l    FromFileText1,a0
  79.         bsr    Printer
  80.         move.l    SourceFile,a0
  81.         bsr    Printer
  82.         lea.l    CRLFText1,a0
  83.         bsr    Printer
  84.  
  85.         lea.l    DestText1,a0
  86.         bsr    Printer
  87.         move.l    DestFile,a0
  88.         bsr    Printer
  89.         lea.l    CRLFText1,a0
  90.         bsr    Printer
  91.  
  92.         move.l    SourceFile,d1
  93.         move.l    #MODE_OLDFILE,d2
  94.         lib    Dos,Open
  95.         move.l    d0,Source
  96.         beq    NoRDArgs
  97.  
  98.         move.l    DestFile,d1
  99.         move.l    #MODE_OLDFILE,d2
  100.         lib    Dos,Open
  101.         move.l    d0,Destination
  102.         beq    OpenDest2
  103.  
  104. OpenDest1:    lea.l    FExistsText1,a0
  105.         bsr    Printer
  106.  
  107.         bsr    GetYesNo
  108.         tst.l    d0
  109.         beq    OpenDest1
  110.  
  111.         cmp.l    #1,d0            ;Yes, replace
  112.         beq    OpenDest3
  113.  
  114.         cmp.l    #2,d0
  115.         bne    ShutDown        ;Error!
  116.  
  117.         tst.l    Destination        ;Don't open twice!
  118.         bne    ShutDown        ;Error!
  119.  
  120. OpenDest2:    move.l    DestFile,d1
  121.         move.l    #MODE_NEWFILE,d2
  122.         lib    Dos,Open
  123.         move.l    d0,Destination
  124.         beq    NoRDArgs
  125.  
  126. OpenDest3:    lea.l    CRLFText1,a0
  127.         bsr    Printer
  128.  
  129.         move.l    Source,d1
  130.         bsr    GetFileLength
  131.  
  132.         cmp.l    #VS02Length,d0
  133.         beq    DoVS02
  134.  
  135.         cmp.l    #VS03Length,d0
  136.         beq    DoVS03
  137.  
  138.         bra    DoVCLI
  139.  
  140. DoVS02:        lea.l    ConvText1,a0
  141.         bsr    Printer
  142.         lea.l    ConvText3,a0
  143.         bsr    Printer
  144.  
  145.         move.l    #VSMB_Size,d0
  146.         bsr    CopyMapBuffer
  147.         cmp.l    #-1,d0
  148.         beq    NoRDArgs
  149.  
  150.         move.l    #VocabSIZE,d6
  151.  
  152. DoVS02.1:    bsr    CopyGL02Bytes
  153.         cmp.l    #-1,d0
  154.         beq    NoRDArgs
  155.  
  156.         move.l    Destination,d1
  157.         move.l    #192,d3
  158.         bsr    WriteNulls
  159.  
  160.         sub.l    #1,d6
  161.         bne    DoVS02.1
  162.  
  163.         bra    ShutDown
  164.  
  165. DoVS03:        lea.l    NewestText1,a0
  166.         bsr    Printer
  167.         bra    ShutDown
  168.  
  169. DoVCLI:        move.l    Source,d1
  170.         bsr    GetHeader
  171.         cmp.l    #-1,d0
  172.         beq    NoRDArgs
  173.  
  174.         lea.l    VCLI70ID,a0
  175.         lea.l    Buffer1,a1
  176.         bsr    CmpStrings
  177.         tst.l    d0
  178.         bne    DoVCLI1.1
  179.  
  180.         lea.l    Buffer1,a0    ;DEBUG
  181.         bsr    Printer        ;DEBUG
  182.  
  183.         lea.l    UnknownText1,a0
  184.         bsr    Printer
  185.         bra    ShutDown
  186.  
  187. DoVCLI1.1:    lea.l    ConvText2,a0
  188.         bsr    Printer
  189.         lea.l    ConvText4,a0
  190.         bsr    Printer
  191.  
  192. ;Seek 12 bytes from the start, to beginning of MapBuffer,
  193. ;in source (VCLI file)
  194.  
  195.         move.l    Source,d1
  196.         move.l    #12,d2
  197.         move.l    #-1,d3
  198.         lib    Dos,Seek
  199.  
  200. ;Copy VCLI MapBuffer to Destination (VoiceShell)
  201.  
  202.         move.l    #VCLIMB_Size,d0
  203.         bsr    CopyMapBuffer
  204.         cmp.l    #-1,d0
  205.         beq    NoRDArgs
  206.  
  207.  
  208. ;Write (VocabSize*304) - (VCLIVocabSize*304) amount of NULL to Destination
  209.  
  210.         lea.l    NullBuffer2,a0
  211.         move.l    Destination,d1
  212.         move.l    a0,d2
  213.         move.l    #NullBufSize2,d3
  214.         lib    Dos,Write
  215.         cmp.l    #NullBufSize2,d0
  216.         bne    NoRDArgs
  217.  
  218. ;Copy strings from Source (VCLI) to Destination (VoiceShell) with steps of
  219. ;GADLENG1. Read in 16 bytes chunks, written in GADLENG1 chunks, 
  220. ;VCLIVocabSize times. Skip GADLENG2 in between.
  221.  
  222.         lea.l    Buffer3,a0
  223.         move.l    Source,d1
  224.         move.l    a0,d2
  225.         move.l    #16*48,d3
  226.         lib    Dos,Read
  227.  
  228. ;Done here (IE. NOT DONE!!!). Do rest here!
  229. ;
  230.  
  231. ;Seek to first CLI Command string in Destination (VoiceShell)
  232. ;
  233.         move.l    Destination,d1
  234.         move.l    #(VocabSIZE*304)+GADLENG1,d2
  235.         move.l    #-1,d3
  236.         lib    Dos,Seek
  237.  
  238. ;Copy strings from Source (VCLI) to Destination (VoiceShell) with steps of
  239. ;GADLENG2. Read in 128 bytes chunks, written in GADLENG2 chunks, 
  240. ;VCLIVocabSize times. Skip GADLENG1 in between.
  241.  
  242.         lea.l    Buffer3,a0
  243.         move.l    Source,d1
  244.         move.l    a0,d2
  245.         move.l    #128*48,d3
  246.         lib    Dos,Read
  247.  
  248. ;Done here (IE. NOT DONE!!!). Do rest here!
  249. ;
  250.  
  251.         lea.l    SorryText1,a0        ;DEBUG
  252.         bsr    Printer            ;DEBUG
  253.  
  254.         bra    ShutDown
  255.  
  256. GetYesNo:    move.l    _stdin,d1
  257.         move.l    #TRUE,d2
  258.         lib    Dos,SetMode
  259.  
  260.         move.l    _stdin,d1
  261.         lib    Dos,Flush
  262.  
  263.         move.l    _stdin,d1
  264.         lib    Dos,FGetC
  265.         cmp.l    #-1,d0
  266.         bne    GetYesNo2
  267.         lea.l    ErrorText1,a0
  268.         bsr    Printer
  269.         bra    GetYesNo_OUT
  270.  
  271. GetYesNo2:    cmp.l    #'y',d0
  272.         beq    GetYesNo3
  273.         cmp.l    #'Y',d0
  274.         beq    GetYesNo3
  275.         cmp.l    #'n',d0
  276.         beq    GetYesNo4
  277.         cmp.l    #'N',d0
  278.         beq    GetYesNo4
  279.         cmp.l    #13,d0
  280.         beq    GetYesNo4        ;Return
  281.         cmp.l    #10,d0
  282.         beq    GetYesNo4        ;Return
  283.         clr.l    d0
  284.         bra    GetYesNo_OUT
  285. GetYesNo3:    lea.l    YesText1,a0
  286.         bsr    Printer
  287.         move.l    #1,d0
  288.         bra    GetYesNo_OUT
  289. GetYesNo4:    lea.l    NoText1,a0
  290.         bsr    Printer
  291.         move.l    #2,d0
  292. ;        bra    GetYesNo_OUT        ;Careful!
  293. GetYesNo_OUT:    move.l    _stdin,d1
  294.         move.l    #FALSE,d2
  295.         lib    Dos,SetMode
  296.         rts
  297.  
  298. ;GetFileLength gets the length of a file and returns to the start of file
  299. ;
  300. ;Input    d1 = File
  301. ;
  302. ;Result    d0 = Length
  303. ;
  304.  
  305. GetFileLength:    move.l    d1,d3
  306.         bsr    SeekStart
  307.         move.l    d3,d1
  308.         bsr    SeekEnd
  309.         push    d0
  310.         move.l    d3,d1
  311.         bsr    SeekStart
  312.         pull    d0
  313.         rts
  314.  
  315.  
  316. ;Seek to end of file
  317. ;
  318. ;Input    d1 = File
  319. ;
  320. ;Result    d0 = Length
  321. ;
  322.  
  323. SeekEnd:    push    d2-d3
  324.         move.l    d1,d6
  325.         move.l    #00,d2
  326.         move.l    #01,d3
  327.         lib    Dos,Seek
  328.         move.l    d6,d1
  329.         lib    Dos,Seek
  330.         pull    d2-d3
  331.         rts
  332.  
  333. ;Seek to start of file
  334. ;
  335. ;Input    d1 = File
  336. ;
  337. ;Result    d0 = Length
  338. ;
  339.  
  340. SeekStart:    push    d2-d3
  341.         move.l    #0,d2
  342.         move.l    #-1,d3
  343.         lib    Dos,Seek
  344.         pull    d2-d3
  345.         rts
  346.  
  347. ;GetHeader reads 12 bytes into Buffer1 and seeks to start of file
  348. ;
  349. ;Input    d1 = File
  350.  
  351. GetHeader:    move.l    d1,d4
  352.  
  353.         bsr    SeekStart
  354.  
  355.         move.l    d4,d1
  356.         lea.l    Buffer1,a0
  357.         move.l    a0,d2
  358.         move.l    #12,d3
  359.         lib    Dos,Read
  360.         cmp.l    #12,d0
  361.         bne    GetHeader_ERR1
  362.  
  363.         move.l    d4,d1
  364.         bsr    SeekStart
  365.         rts
  366.  
  367. GetHeader_ERR1:    move.l    #-1,d0
  368.         rts
  369.  
  370. ;CopyMapBuffer reads d0 bytes into MapBuffer from start of file
  371. ;
  372. ;Input    d0 = Length
  373.  
  374. CopyMapBuffer:    push    d0
  375.         move.l    Source,d1
  376.         bsr    SeekStart
  377.  
  378.         move.l    Destination,d1
  379.         bsr    SeekStart
  380.  
  381.         move.l    Source,d1
  382.         lea.l    MapBuffer,a0
  383.         move.l    a0,d2
  384.         pull    d3
  385.         lib    Dos,Read
  386.         cmp.l    d3,d0
  387.         bne    CopyMB_ERR1
  388.  
  389.         move.l    Destination,d1
  390.         lib    Dos,Write
  391.         cmp.l    d3,d0
  392.         bne    CopyMB_ERR1
  393.         rts
  394.  
  395. CopyMB_ERR1:    move.l    #-1,d0
  396.         rts
  397.  
  398. ;CopyGL02Bytes copies GADLENG2VS02 bytes from Source to Destination
  399. ;
  400.  
  401. CopyGL02Bytes:    move.l    Source,d1        ;Read GADLENGTHVS02 bytes
  402.         lea.l    Buffer2,a0
  403.         move.l    a0,d2
  404.         move.l    #GADLENGTHVS02,d3
  405.         lib    Dos,Read
  406.         cmp.l    #GADLENGTHVS02,d0
  407.         bne    CopyGL02_ERR1
  408.  
  409.         move.l    Destination,d1        ;Write GADLENGTHVS02 bytes
  410.         lib    Dos,Write
  411.         cmp.l    #GADLENGTHVS02,d0
  412.         bne    CopyGL02_ERR1
  413.         rts
  414.  
  415. CopyGL02_ERR1:    move.l    #-1,d0
  416.         rts
  417.  
  418. ;WriteNulls writes 192 NULLs to Destination
  419. ;
  420.  
  421. WriteNulls:    move.l    Destination,d1
  422.         lea.l    NullBuffer,a0
  423.         move.l    a0,d2
  424.         move.l    #NullBufSize1,d3
  425.         lib    Dos,Write
  426.         cmp.l    #NullBufSize1,d0
  427.         bne    WriteNull_ERR1
  428.         rts
  429.  
  430. WriteNull_ERR1:    move.l    #-1,d0
  431.         rts
  432.  
  433. CloseFiles:    move.l    Source,d1
  434.         beq    CloseFiles2
  435.         lib    Dos,Close
  436.  
  437. CloseFiles2:    move.l    Destination,d1
  438.         beq    CloseFiles3
  439.         lib    Dos,Close
  440. CloseFiles3:    rts
  441.  
  442. ;Compares two strings.
  443. ;
  444. ;Input    a0 = String 1
  445. ;    a1 = String 2
  446. ;
  447. ;Result    d0 = 0 if not same
  448. ;
  449. ;BUGS
  450. ;
  451. ;String 1 has to have NULL at end!
  452. ;
  453.  
  454. CmpStrings:    bsr    GetLength
  455.         move.l    d0,d4        ;length of string1 to d4
  456.         push    a0
  457.         move.l    a1,a0
  458.         bsr    GetLength
  459.         pull    a0
  460.         cmp.l    d4,d0        ;length of string2 in d3
  461.         bne    CmpStrings1.1
  462. CmpStrings1:    tst.b    (a0)
  463.         beq    CmpStrings2
  464.         cmp.b    (a0)+,(a1)+
  465.         beq    CmpStrings1
  466. CmpStrings1.1:    clr.l    d0
  467.         rts
  468. CmpStrings2:    move.l    #-1,d0
  469.         rts
  470.  
  471. ;Get length of text in given address
  472. ;
  473. ;Input a0 = Address of null terminated text string
  474. ;
  475. ;Result d0 = Length
  476.  
  477. GetLength:    push    a0
  478.         clr.l    d0
  479.         cmp.l    #$00,a0        ;fixes enforcer hit
  480.         beq    GetLength_OUT
  481. GetLength2:    add.l    #1,d0
  482.         tst.b    (a0)+
  483.         bne    GetLength2
  484.         sub.l    #1,d0        ;don't include NULL
  485. GetLength_OUT:    pull    a0
  486.         rts
  487.  
  488. ShutDown:    move.l    RDArgs1,d1
  489.         beq    ShutDown9000
  490.         lib    Dos,FreeArgs
  491.  
  492. ShutDown9000:    bsr    CloseFiles
  493.  
  494. ShutDown1000:    closlib    Dos
  495.         move.l    #RETURN_OK,d0
  496.         rts
  497.  
  498. NoDos:        move.l    #RETURN_FAIL,d0
  499.         rts
  500.  
  501. NoRDArgs:    lib    Dos,