home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / asm / tbsource / questions / versions / 0.99f / 0.99f.lha / QueIO.bak < prev    next >
Encoding:
Text File  |  1991-10-20  |  7.5 KB  |  473 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    QAList
  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.  
  83.         move.l    Window1,a0
  84.         lea.l    MainMGad1,a1
  85.         move.l    #-1,d0
  86.         lib    Intuition,RemoveGList
  87.  
  88. LoadCont1:    cmp.w    #$02,Mode
  89.         bne    Load0.1
  90.         move.w    NumQ,d6
  91.         clr.w    NumQ
  92.         jsr    SetActivation
  93.         move.w    d6,NumQ
  94.         jsr    OthActivation
  95.  
  96. Load0.1:    jsr    MenusOff
  97.  
  98.         lea.l    SS_Load,a0
  99.         jsr    Speaker
  100.  
  101.         lea.l    LoadName,a5
  102.         move.l    #FRQABSOLUTEXYM+FRQLOADINGM,d5
  103.         jsr    FileRequester
  104.         tst.l    d0
  105.         beq    Load_Out1
  106.  
  107.         lea.l    FRPathName,a1
  108.         move.l    a1,d1
  109.         cmp.b    #$00,(a1)
  110.         beq    Load_Out1
  111.         move.l    #MODE_OLDFILE,d2
  112.         lib    Dos,Open
  113.         move.l    d0,QueFile
  114.         bne    Load1
  115.         jsr    FileError
  116.         jmp    Load_Out1
  117.  
  118. ;reading "logic"
  119.  
  120. Load1:        jsr    CheckFile
  121.         tst.l    d0
  122.         beq    Load_Out2
  123.  
  124.         jsr    KillQueMem1
  125.  
  126.         lea.l    SS_Load2,a0
  127.         jsr    Speaker
  128.  
  129. ;Load descriptions (2 lines)
  130.  
  131.         move.l    DesMem1,d4
  132. Load1.1:    move.l    QueFile,d1
  133.         move.l    d4,d2
  134.         move.l    #1,d3
  135.         lib    Dos,Read
  136.         tst.l    d0
  137.         beq    Load5
  138.         move.l    d4,a2
  139.         add.l    #1,d4
  140.         tst.b    (a2)
  141.         bne    Load1.1
  142.  
  143.         move.l    DesMem1,d4
  144.         add.l    #LineLeng,d4
  145. Load1.2:    move.l    QueFile,d1
  146.         move.l    d4,d2
  147.         move.l    #1,d3
  148.         lib    Dos,Read
  149.         tst.l    d0
  150.         beq    Load5
  151.         move.l    d4,a2
  152.         add.l    #1,d4
  153.         tst.b    (a2)
  154.         bne    Load1.2
  155.  
  156. ;Then load the questions and answers MAYBE USE 'AddQues'!!!
  157.  
  158.         move.w    #$00,d4
  159. Load2:        move.l    #QA_SIZE,d0        ;reserve memory for node
  160.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  161.         lib    Exec,AllocMem
  162.         tst.l    d0
  163.         bne    Load2.01
  164.         jsr    NoMem1
  165.         jmp    Load6
  166. Load2.01:    move.l    d0,a2            ;Hold node address in a2
  167.         move.l    #NextQues,d0        ;Reserve ques-ans memory
  168.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  169.         lib    Exec,AllocMem        
  170.         tst.l    d0
  171.         bne    Load2.02
  172.         move.l    a2,a1            ;No mem. Clear Node mem
  173.         move.l    #QA_SIZE,d0
  174.         lib    Exec,FreeMem
  175.         jsr    NoMem1
  176.         jmp    Load6
  177. Load2.02:    move.l    d0,a3            ;Hold memory info in a3
  178.         lea.l    QAList,a0
  179.         move.l    a2,a1
  180.         ADDTAIL                ;Add Node to list
  181.         move.l    a3,QA_Data(a2)        ;Add memory info to node
  182.  
  183. Load2.1:    add.w    #1,d4
  184.         cmp.w    NumQ,d4
  185.         bne    Load2
  186.  
  187.         move.w    #$00,QueCount
  188. Load3:        move.b    #$00,d5
  189.         jsr    Find
  190. Load3.1:    move.l    QueFile,d1
  191.         move.l    a4,d2
  192.         move.l    #1,d3
  193.         lib    Dos,Read
  194.         tst.l    d0
  195.         beq    Load5
  196.         add.l    #1,a4
  197.         tst.b    -1(a4)
  198.         bne    Load3.1
  199.  
  200. ;Read two lines of questions
  201.  
  202.         cmp.b    #$01,d5
  203.         beq    Load3.2
  204.         add.b    #$01,d5
  205.         jsr    Find
  206.         add.l    #LineLeng,a4
  207.         jmp    Load3.1
  208.  
  209. ;Read 10 answers
  210.  
  211. Load3.2:    jsr    Find
  212.         add.l    #QueLeng,a4
  213.         move.w    #$00,d5
  214. Load3.3:    move.l    QueFile,d1
  215.         move.l    a4,d2
  216.         move.l    #1,d3
  217.         lib    Dos,Read
  218.         tst.l    d0
  219.         beq    Load5
  220.         add.l    #1,a4
  221.         tst.b    -1(a4)
  222.         bne    Load3.3
  223.  
  224.         cmp.w    #9,d5
  225.         beq    Load3.4
  226.         add.w    #$01,d5
  227.         jsr    Find
  228.         move.w    d5,d1
  229.         add.l    #QueLeng,a4
  230.         mulu.w    #AnsLeng,d1
  231.         add.l    d1,a4
  232.         jmp    Load3.3
  233.  
  234. Load3.4:    add.w    #$01,QueCount
  235.         move.w    QueCount,d1
  236.         cmp.w    NumQ,d1
  237.         bne    Load3
  238.  
  239. Load4:        move.l    QueFile,d1
  240.         lib    Dos,Close
  241.         move.l    #$00,QueFile
  242.         move.w    #$00,QueCount
  243.         jmp    Load_Out
  244.  
  245. Load5:        jsr    FileError
  246.         lea.l    SS_ERR_File1,a0
  247.         jsr    Speaker
  248.         jsr    KillQueMem1
  249.         move.w    #00,NumQ
  250.         jmp    Load4
  251. Load6:        jsr    NoMem1
  252.         lea.l    SS_ERR_File1,a0
  253.         jsr    Speaker
  254.         jsr    KillQueMem1
  255.         move.w    #00,NumQ
  256.         jmp    Load4
  257.  
  258. Load_Out:    lea.l    SS_Done,a0
  259.         jsr    Speaker
  260.         jsr    MenusOn
  261.         jsr    NormalPointer
  262.         cmp.w    #$02,Mode
  263.         bne    Game
  264.         jsr    SetActivation
  265.         jsr    OthActivation1
  266.         jmp    DoTeach
  267. Load_Out1:    jsr    MenusOn
  268.         jsr    NormalPointer
  269.         cmp.w    #$02,Mode
  270.         bne    GoMainMenu
  271.         jsr    SetActivation
  272.         jsr    OthActivation1
  273.         jmp    Window1IDCMP
  274. Load_Out2:    lea.l    SS_ERR_File2,a0
  275.         jsr    Speaker
  276.         move.l    QueFile,d1
  277.         lib    Dos,Close
  278.         move.l    #$00,QueFile
  279.         jsr    MenusOn
  280.         jsr    NormalPointer
  281.         move.w    #$00,NumQ
  282.         cmp.w    #$02,Mode
  283.         bne    GoMainMenu
  284.         jsr    SetActivation
  285.         jsr    OthActivation1
  286.         jmp    Window1IDCMP
  287.  
  288. GoMainMenu:    jsr    MainMenu
  289.         jmp    Window1IDCMP
  290.  
  291. SaveAs:        jsr    SleepPointer
  292.         jsr    SaveQuestion
  293.  
  294.         cmp.w    #$02,Mode
  295.         bne    SaveAs0.1
  296.         move.w    NumQ,d6
  297.         clr.w    NumQ
  298.         jsr    SetActivation
  299.         move.w    d6,NumQ
  300.         jsr    OthActivation
  301.  
  302. SaveAs0.1    jsr    MenusOff
  303.         move.w    QueCount,QueCount2
  304.     
  305.         lea.l    SS_SaveAs,a0
  306.         jsr    Speaker
  307.  
  308.         lea.l    SaveName,a5
  309.         move.l    #FRQABSOLUTEXYM+FRQSAVINGM,d5
  310.         jsr    FileRequester
  311.         tst.l    d0
  312.         beq    SaveOut
  313.  
  314.         lea.l    FRPathName,a1
  315.         move.l    a1,d1
  316.         cmp.b    #$00,(a1)
  317.         beq    SaveOut
  318.         move.l    #MODE_OLDFILE,d2
  319.         lib    Dos,Open
  320.         move.l    d0,QueFile
  321.         beq    Save1        ;file doesn't exist...
  322.  
  323. ;The file already exists so we'll ask if the user wants to replace old file 
  324.  
  325.         lea.l    SS_ERR_File3,a0
  326.         jsr    Speaker
  327.  
  328.         lea.l    AskReplace,a0
  329.         move.l    #$00,a1
  330.         jsr    TwoGadRequest
  331.         tst.l    d0
  332.         beq    Save5
  333.  
  334.         move.l    QueFile,d1
  335.         lib    Dos,Close
  336.         move.l    #$00,QueFile
  337.  
  338. SaveAsOut:    jsr    MenusOn
  339.         jsr    SetActivation
  340.         jsr    OthActivation1
  341.         jsr    NormalPointer
  342.  
  343. Save:        jsr    SleepPointer
  344.         cmp.w    #$02,Mode
  345.         bne    Save0.1
  346.         move.w    NumQ,d6
  347.         clr.w    NumQ
  348.         jsr    SetActivation
  349.         move.w    d6,NumQ
  350.         jsr    OthActivation
  351.  
  352. Save0.1:    jsr    MenusOff
  353.         jsr    SaveQuestion
  354.  
  355.         lea.l    SS_Save,a0
  356.         jsr    Speaker
  357.  
  358. Save1:        tst.l    QueFile
  359.         bne    Save2
  360.         lea.l    FRPathName,a1
  361.         move.l    a1,d1
  362.         move.l    #MODE_NEWFILE,d2
  363.         lib    Dos,Open
  364.         move.l    d0,QueFile
  365.         bne    Save2
  366.         jsr    FileError
  367.         jmp    SaveOut
  368.  
  369.         move.l    #"Ques",Que
  370.  
  371. Save2:        move.l    QueFile,d1
  372.         lea.l    Que,a0
  373.         move.l    a0,d2
  374.         move.l    #8,d3
  375.         lib    Dos,Write
  376.         cmp.l    #-1,d0
  377.         beq    SaveError
  378.  
  379. ;Save description for questions
  380.  
  381.         move.l    DesMem1,d2
  382.         jsr    GetLength
  383.         move.l    QueFile,d1
  384.         move.l    DesMem1,d2
  385.         lib    Dos,Write
  386.         tst.l    d0
  387.         beq    SaveError
  388.  
  389.         move.l    DesMem1,d2
  390.         add.l    #LineLeng,d2
  391.         jsr    GetLength
  392.         move.l    QueFile,d1
  393.         lib    Dos,Write
  394.         tst.l    d0
  395.         beq    SaveError
  396.  
  397.         move.w    QueCount,QueCount2        ;save position
  398.         move.w    #$00,QueCount
  399. Save3:        move.b    #$00,d5
  400.         jsr    Find
  401. Save3.1:    move.l    a4,d2
  402.         jsr    GetLength
  403.         move.l    QueFile,d1
  404.         lib    Dos,Write
  405.         tst.l    d0
  406.         beq    SaveError
  407.  
  408. ;Save two lines of questions
  409.  
  410.         cmp.b    #$01,d5
  411.         beq    Save3.2
  412.         add.b    #$01,d5
  413.         jsr    Find
  414.         add.l    #LineLeng,a4
  415.         jmp    Save3.1
  416.  
  417. ;Save 10 answers
  418.  
  419. Save3.2:    jsr    Find
  420.         add.l    #QueLeng,a4
  421.         move.w    #$00,d5
  422. Save3.3:    move.l    a4,d2
  423.         jsr    GetLength
  424.         move.l    QueFile,d1
  425.         lib    Dos,Write
  426.         tst.l    d0
  427.         beq    SaveError
  428.  
  429.         cmp.w    #9,d5
  430.         beq    Save3.4
  431.         add.w    #$01,d5
  432.         jsr    Find
  433.         move.w    d5,d1
  434.         add.l    #QueLeng,a4
  435.         mulu.w    #AnsLeng,d1
  436.         add.l    d1,a4
  437.         jmp    Save3.3
  438.  
  439. Save3.4:    add.w    #$01,QueCount
  440.         move.w    QueCount,d1
  441.         cmp.w    NumQ,d1
  442.         bne    Save3
  443.  
  444. ;Close the file
  445.  
  446. Save5:        move.l    QueFile,d1
  447.         lib    Dos,Close
  448.         move.l    #$00,QueFile
  449.         move.w    QueCount2,QueCount        ;Get position
  450.         jsr    Find
  451.         jsr    PrintTeach
  452.  
  453. SaveOut:    lea.l    SS_Done,a0
  454.         jsr    Speaker
  455.         jsr    MenusOn
  456.         jsr    SetActivation
  457.         jsr    OthActivation1
  458.         jsr    NormalPointer
  459.         jmp    Window1IDCMP
  460.  
  461. SaveError:    jsr    FileError
  462.         lea.l    SS_ERR_File1,a0
  463.         jsr    Speaker
  464.         jmp    Save5
  465.  
  466.         INCLUDE    "FH1:Language/WF/Questions/Que.i"
  467.  
  468.         STRUCTURE  QA,MLN_SIZE
  469.             APTR    QA_Data
  470.             LABEL   QA_SIZE
  471.  
  472.         END
  473.