home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / dev / asm / tbsource / questions / versions / 0.99e / qv99e.lha / QueIO.bak < prev    next >
Encoding:
Text File  |  1991-10-06  |  7.0 KB  |  455 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1991        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    DonĀ“t try to understand the code    *
  8. *                        *
  9. * Version: See info from main source code    *
  10. *                        *
  11. *************************************************
  12.  
  13. ;Includes
  14.  
  15.     INCLUDE    "JMPLibs.i"
  16.     INCLUDE    "exec.xref"
  17.     INCLUDE    "dos.xref"
  18.     INCLUDE    "intuition.xref"
  19.  
  20.     INCLUDE    "libraries/reqbase.i"
  21.     INCLUDE    "exec/types.i"
  22.  
  23. ; XDEFs
  24.  
  25.     XDEF    Load
  26.     XDEF    Save
  27.     XDEF    SaveAs
  28.  
  29. ;XREFs
  30.  
  31.     XREF    _DosBase
  32.     XREF    _IntuitionBase
  33.     XREF    SetActivation
  34.     XREF    OthActivation
  35.     XREF    OthActivation1
  36.     XREF    SleepPointer
  37.     XREF    NormalPointer
  38.     XREF    Mode
  39.     XREF    NumQ
  40.     XREF    QueCount
  41.     XREF    QueCount2
  42.     XREF    MenusOff
  43.     XREF    MenusOn
  44.     XREF    Speaker
  45.     XREF    LoadName
  46.     XREF    SaveName
  47.     XREF    FileRequester
  48.     XREF    FRPathName
  49.     XREF    QueFile
  50.     XREF    FileError
  51.     XREF    CheckFile
  52.     XREF    KillQueMem1
  53.     XREF    DesMem1
  54.     XREF    RememberKey
  55.     XREF    Find
  56.     XREF    SS_ERR_File1
  57.     XREF    SS_ERR_File2
  58.     XREF    SS_ERR_File3
  59.     XREF    SS_Done
  60.     XREF    SS_Load
  61.     XREF    SS_Load2
  62.     XREF    SS_Save
  63.     XREF    SS_SaveAs
  64.     XREF    NoMem1
  65.     XREF    Game
  66.     XREF    DoTeach
  67.     XREF    PrintTeach
  68.     XREF    Window1IDCMP
  69.     XREF    SaveQuestion
  70.     XREF    AskReplace
  71.     XREF    TwoGadRequest
  72.     XREF    Que
  73.     XREF    GetLength
  74.     XREF    Window1
  75.     XREF    MainMGad1
  76.     XREF    MainMenu
  77.  
  78. Load:        jsr    SleepPointer
  79.  
  80.         cmp.w    #$00,Mode
  81.         bne    LoadCont1
  82.         move.l    Window1,a0
  83.         lea.l    MainMGad1,a1
  84.         move.l    #-1,d0
  85.         lib    Intuition,RemoveGList
  86.  
  87. LoadCont1:    cmp.w    #$02,Mode
  88.         bne    Load0.1
  89.         move.w    NumQ,d6
  90.         clr.w    NumQ
  91.         jsr    SetActivation
  92.         move.w    d6,NumQ
  93.         jsr    OthActivation
  94.  
  95. Load0.1:    jsr    MenusOff
  96.  
  97.         lea.l    SS_Load,a0
  98.         jsr    Speaker
  99.  
  100.         lea.l    LoadName,a5
  101.         move.l    #FRQABSOLUTEXYM+FRQLOADINGM,d5
  102.         jsr    FileRequester
  103.         tst.l    d0
  104.         beq    Load_Out1
  105.  
  106.         lea.l    FRPathName,a1
  107.         move.l    a1,d1
  108.         cmp.b    #$00,(a1)
  109.         beq    Load_Out1
  110.         move.l    #MODE_OLDFILE,d2
  111.         lib    Dos,Open
  112.         move.l    d0,QueFile
  113.         bne    Load1
  114.         jsr    FileError
  115.         jmp    Load_Out1
  116.  
  117. ;reading "logic"
  118.  
  119. Load1:        jsr    CheckFile
  120.         tst.l    d0
  121.         beq    Load_Out2
  122.  
  123.         jsr    KillQueMem1
  124.  
  125.         lea.l    SS_Load2,a0
  126.         jsr    Speaker
  127.  
  128. ;Load descriptions (2 lines)
  129.  
  130.         move.l    DesMem1,d4
  131. Load1.1:    move.l    QueFile,d1
  132.         move.l    d4,d2
  133.         move.l    #1,d3
  134.         lib    Dos,Read
  135.         tst.l    d0
  136.         beq    Load5
  137.         move.l    d4,a2
  138.         add.l    #1,d4
  139.         tst.b    (a2)
  140.         bne    Load1.1
  141.  
  142.         move.l    DesMem1,d4
  143.         add.l    #LineLeng,d4
  144. Load1.2:    move.l    QueFile,d1
  145.         move.l    d4,d2
  146.         move.l    #1,d3
  147.         lib    Dos,Read
  148.         tst.l    d0
  149.         beq    Load5
  150.         move.l    d4,a2
  151.         add.l    #1,d4
  152.         tst.b    (a2)
  153.         bne    Load1.2
  154.  
  155. ;Then load the questions and answers
  156.  
  157. ;We're going to add 12 bytes to the amount of memory to be reserved
  158. ;for each question set, just in case.
  159.  
  160.         move.w    #$00,d4
  161. Load2:        lea.l    RememberKey,a0
  162.         move.l    #NextQues+12,d0
  163.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  164.         lib    Intuition,AllocRemember
  165.         tst.l    d0
  166.         bne    Load2.1
  167.         jmp    Load6
  168. Load2.1:    add.w    #1,d4
  169.         cmp.w    NumQ,d4
  170.         bne    Load2
  171.  
  172.         move.w    #$00,QueCount
  173. Load3:        move.b    #$00,d5
  174.         jsr    Find
  175. Load3.1:    move.l    QueFile,d1
  176.         move.l    a4,d2
  177.         move.l    #1,d3
  178.         lib    Dos,Read
  179.         tst.l    d0
  180.         beq    Load5
  181.         add.l    #1,a4
  182.         tst.b    -1(a4)
  183.         bne    Load3.1
  184.  
  185. ;Read two lines of questions
  186.  
  187.         cmp.b    #$01,d5
  188.         beq    Load3.2
  189.         add.b    #$01,d5
  190.         jsr    Find
  191.         add.l    #LineLeng,a4
  192.         jmp    Load3.1
  193.  
  194. ;Read 10 answers
  195.  
  196. Load3.2:    jsr    Find
  197.         add.l    #QueLeng,a4
  198.         move.w    #$00,d5
  199. Load3.3:    move.l    QueFile,d1
  200.         move.l    a4,d2
  201.         move.l    #1,d3
  202.         lib    Dos,Read
  203.         tst.l    d0
  204.         beq    Load5
  205.         add.l    #1,a4
  206.         tst.b    -1(a4)
  207.         bne    Load3.3
  208.  
  209.         cmp.w    #9,d5
  210.         beq    Load3.4
  211.         add.w    #$01,d5
  212.         jsr    Find
  213.         move.w    d5,d1
  214.         add.l    #QueLeng,a4
  215.         mulu.w    #AnsLeng,d1
  216.         add.l    d1,a4
  217.         jmp    Load3.3
  218.  
  219. Load3.4:    add.w    #$01,QueCount
  220.         move.w    QueCount,d1
  221.         cmp.w    NumQ,d1
  222.         bne    Load3
  223.  
  224. Load4:        move.l    QueFile,d1
  225.         lib    Dos,Close
  226.         move.l    #$00,QueFile
  227.         move.w    #$00,QueCount
  228.         jmp    Load_Out
  229.  
  230. Load5:        jsr    FileError
  231.         lea.l    SS_ERR_File1,a0
  232.         jsr    Speaker
  233.         jsr    KillQueMem1
  234.         move.w    #00,NumQ
  235.         jmp    Load4
  236. Load6:        jsr    NoMem1
  237.         lea.l    SS_ERR_File1,a0
  238.         jsr    Speaker
  239.         jsr    KillQueMem1
  240.         move.w    #00,NumQ
  241.         jmp    Load4
  242.  
  243. Load_Out:    lea.l    SS_Done,a0
  244.         jsr    Speaker
  245.         jsr    MenusOn
  246.         jsr    NormalPointer
  247.         cmp.w    #$02,Mode
  248.         bne    Game
  249.         jsr    SetActivation
  250.         jsr    OthActivation1
  251.         jmp    DoTeach
  252. Load_Out1:    jsr    MenusOn
  253.         jsr    NormalPointer
  254.         cmp.w    #$02,Mode
  255.         bne    GoMainMenu
  256.         jsr    SetActivation
  257.         jsr    OthActivation1
  258.         jmp    Window1IDCMP
  259. Load_Out2:    lea.l    SS_ERR_File2,a0
  260.         jsr    Speaker
  261.  
  262.         move.l    QueFile,d1
  263.         lib    Dos,Close
  264.         move.l    #$00,QueFile
  265.         jsr    MenusOn
  266.         jsr    NormalPointer
  267.         move.w    #$00,NumQ
  268.         cmp.w    #$02,Mode
  269.         bne    GoMainMenu
  270.         jsr    SetActivation
  271.         jsr    OthActivation1
  272.         jmp    Window1IDCMP
  273.  
  274. GoMainMenu:    jsr    MainMenu
  275.         jmp    Window1IDCMP
  276.  
  277. SaveAs:        jsr    SleepPointer
  278.         jsr    SaveQuestion
  279.  
  280.         cmp.w    #$02,Mode
  281.         bne    SaveAs0.1
  282.         move.w    NumQ,d6
  283.         clr.w    NumQ
  284.         jsr    SetActivation
  285.         move.w    d6,NumQ
  286.         jsr    OthActivation
  287.  
  288. SaveAs0.1    jsr    MenusOff
  289.         move.w    QueCount,QueCount2
  290.     
  291.         lea.l    SS_SaveAs,a0
  292.         jsr    Speaker
  293.  
  294.         lea.l    SaveName,a5
  295.         move.l    #FRQABSOLUTEXYM+FRQSAVINGM,d5
  296.         jsr    FileRequester
  297.         tst.l    d0
  298.         beq    SaveOut
  299.  
  300.         lea.l    FRPathName,a1
  301.         move.l    a1,d1
  302.         cmp.b    #$00,(a1)
  303.         beq    SaveOut
  304.         move.l    #MODE_OLDFILE,d2
  305.         lib    Dos,Open
  306.         move.l    d0,QueFile
  307.         beq    Save1        ;file doesn't exist...
  308.  
  309. ;The file already exists so we'll ask if the user wants to replace old file 
  310.  
  311.         lea.l    SS_ERR_File3,a0
  312.         jsr    Speaker
  313.  
  314.         lea.l    AskReplace,a0
  315.         move.l    #$00,a1
  316.         jsr    TwoGadRequest
  317.         tst.l    d0
  318.         beq    Save5
  319.  
  320.         move.l    QueFile,d1
  321.         lib    Dos,Close
  322.         move.l    #$00,QueFile
  323.  
  324. SaveAsOut:    jsr    MenusOn
  325.         jsr    SetActivation
  326.         jsr    OthActivation1
  327.         jsr    NormalPointer
  328.  
  329. Save:        jsr    SleepPointer
  330.         cmp.w    #$02,Mode
  331.         bne    Save0.1
  332.         move.w    NumQ,d6
  333.         clr.w    NumQ
  334.         jsr    SetActivation
  335.         move.w    d6,NumQ
  336.         jsr    OthActivation
  337.  
  338. Save0.1:    jsr    MenusOff
  339.         jsr    SaveQuestion
  340.  
  341.         lea.l    SS_Save,a0
  342.         jsr    Speaker
  343.  
  344. Save1:        tst.l    QueFile
  345.         bne    Save2
  346.         lea.l    FRPathName,a1
  347.         move.l    a1,d1
  348.         move.l    #MODE_NEWFILE,d2
  349.         lib    Dos,Open
  350.         move.l    d0,QueFile
  351.         bne    Save2
  352.         jsr    FileError
  353.         jmp    SaveOut
  354.  
  355.         move.l    #"Ques",Que
  356.  
  357. Save2:        move.l    QueFile,d1
  358.         lea.l    Que,a0
  359.         move.l    a0,d2
  360.         move.l    #8,d3
  361.         lib    Dos,Write
  362.         cmp.l    #-1,d0
  363.         beq    SaveError
  364.  
  365. ;Save description for questions
  366.  
  367.         move.l    DesMem1,d2
  368.         jsr    GetLength
  369.         move.l    QueFile,d1
  370.         move.l    DesMem1,d2
  371.         lib    Dos,Write
  372.         tst.l    d0
  373.         beq    SaveError
  374.  
  375.         move.l    DesMem1,d2
  376.         add.l    #LineLeng,d2
  377.         jsr    GetLength
  378.         move.l    QueFile,d1
  379.         lib    Dos,Write
  380.         tst.l    d0
  381.         beq    SaveError
  382.  
  383.         move.w    QueCount,QueCount2        ;save position
  384.         move.w    #$00,QueCount
  385. Save3:        move.b    #$00,d5
  386.         jsr    Find
  387. Save3.1:    move.l    a4,d2
  388.         jsr    GetLength
  389.         move.l    QueFile,d1
  390.         lib    Dos,Write
  391.         tst.l    d0
  392.         beq    SaveError
  393.  
  394. ;Save two lines of questions
  395.  
  396.         cmp.b    #$01,d5
  397.         beq    Save3.2
  398.         add.b    #$01,d5
  399.         jsr    Find
  400.         add.l    #LineLeng,a4
  401.         jmp    Save3.1
  402.  
  403. ;Save 10 answers
  404.  
  405. Save3.2:    jsr    Find
  406.         add.l    #QueLeng,a4
  407.         move.w    #$00,d5
  408. Save3.3:    move.l    a4,d2
  409.         jsr    GetLength
  410.         move.l    QueFile,d1
  411.         lib    Dos,Write
  412.         tst.l    d0
  413.         beq    SaveError
  414.  
  415.         cmp.w    #9,d5
  416.         beq    Save3.4
  417.         add.w    #$01,d5
  418.         jsr    Find
  419.         move.w    d5,d1
  420.         add.l    #QueLeng,a4
  421.         mulu.w    #AnsLeng,d1
  422.         add.l    d1,a4
  423.         jmp    Save3.3
  424.  
  425. Save3.4:    add.w    #$01,QueCount
  426.         move.w    QueCount,d1
  427.         cmp.w    NumQ,d1
  428.         bne    Save3
  429.  
  430. ;Close the file
  431.  
  432. Save5:        move.l    QueFile,d1
  433.         lib    Dos,Close
  434.         move.l    #$00,QueFile
  435.         move.w    QueCount2,QueCount        ;Get position
  436.         jsr    Find
  437.         jsr    PrintTeach
  438.  
  439. SaveOut:    lea.l    SS_Done,a0
  440.         jsr    Speaker
  441.         jsr    MenusOn
  442.         jsr    SetActivation
  443.         jsr    OthActivation1
  444.         jsr    NormalPointer
  445.         jmp    Window1IDCMP
  446.  
  447. SaveError:    jsr    FileError
  448.         lea.l    SS_ERR_File1,a0
  449.         jsr    Speaker
  450.         jmp    Save5
  451.  
  452.         INCLUDE    "FH1:Language/WF/Questions/Que.i"
  453.  
  454.         end
  455.