home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Questions / QueIO.bak < prev    next >
Text File  |  1993-12-21  |  16KB  |  776 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    "XREF:exec.xref"
  17.     INCLUDE    "XREF:dos.xref"
  18.     INCLUDE    "XREF:intuition.xref"
  19.  
  20.     INCLUDE    "libraries/reqbase.i"
  21.     INCLUDE    "exec/types.i"
  22.  
  23. ; XDEFs
  24.  
  25.     XDEF    Load
  26.     XDEF    LoadV
  27.     XDEF    VLoad
  28.     XDEF    Save
  29.     XDEF    SaveAs
  30.     XDEF    IOMode
  31.  
  32. ;XREFs
  33.  
  34.     XREF    OKTxt
  35.     XREF    FCorruptTxt1
  36.     XREF    FileMem1
  37.     XREF    FileLeng1
  38.     XREF    DesLeng
  39.     XREF    InitQAList
  40.     XREF    AddQues
  41.     XREF    _DosBase
  42.     XREF    _IntuitionBase
  43.     XREF    SetActivation
  44.     XREF    OthActivation
  45.     XREF    OthActivation1
  46.     XREF    SleepPointer
  47.     XREF    NormalPointer
  48.     XREF    AddMode
  49.     XREF    Mode
  50.     XREF    NumQ
  51.     XREF    QueCount
  52.     XREF    QueCount2
  53.     XREF    MenusOff
  54.     XREF    MenusOn
  55.     XREF    Speaker
  56.     XREF    LoadName
  57.     XREF    LoadName2
  58.     XREF    SaveName
  59.     XREF    SaveName2
  60.     XREF    FileRequester
  61.     XREF    FRPathName
  62.     XREF    QueFile
  63.     XREF    FileError
  64.     XREF    CheckFile
  65.     XREF    VCheckFile
  66.     XREF    KillQueMem1
  67.     XREF    DesMem1
  68.     XREF    QAList
  69.     XREF    Find
  70.     XREF    SS_ERR_File1
  71.     XREF    SS_ERR_File2
  72.     XREF    SS_ERR_File3
  73.     XREF    SS_ERR_File4
  74.     XREF    SS_Done
  75.     XREF    SS_Load
  76.     XREF    SS_Load2
  77.     XREF    SS_Save
  78.     XREF    SS_SaveAs
  79.     XREF    NoMem1
  80.     XREF    NotSupported
  81.     XREF    Game
  82.     XREF    DoTeach
  83.     XREF    PrintTeach
  84.     XREF    Window1IDCMP
  85.     XREF    SaveQuestion
  86.     XREF    AskReplace
  87.     XREF    TwoGadRequest
  88.     XREF    Que
  89.     XREF    GetLength
  90.     XREF    Window1
  91.     XREF    MainMGad1
  92.     XREF    MainMenu
  93.  
  94. EOD:        EQU    $E6        ;End Of Desc
  95. EOQ:        EQU    $E7        ;End Of Ques
  96. EOA:        EQU    $E8        ;End Of Ans
  97. EOF:        EQU    $E9        ;End Of File
  98. EOL:        EQU    $EA        ;End Of Line
  99. EOB:        EQU    $F0        ;End of both (Q+A)
  100.  
  101. LoadV:        move.w    #1,IOMode
  102. Load:        jsr    SleepPointer
  103.  
  104.         cmp.w    #$00,Mode
  105.         bne    LoadCont1
  106.  
  107.         move.l    Window1,a0
  108.         lea.l    MainMGad1,a1
  109.         move.l    #-1,d0
  110.         lib    Intuition,RemoveGList
  111.  
  112. LoadCont1:    cmp.w    #$02,Mode
  113.         bne    Load0.1
  114.         move.w    NumQ,d6
  115.         clr.w    NumQ
  116.         jsr    SetActivation
  117.         jsr    OthActivation
  118.         move.w    d6,NumQ
  119.  
  120. Load0.1:    jsr    MenusOff
  121.  
  122.         lea.l    SS_Load,a0
  123.         jsr    Speaker
  124.  
  125.         cmp.w    #$01,IOMode
  126.         bne    Load0.2
  127.         lea.l    LoadName2,a5
  128.         jmp    Load0.3
  129. Load0.2:    lea.l    LoadName,a5
  130. Load0.3:    move.l    #FRQABSOLUTEXYM+FRQLOADINGM,d5
  131.         jsr    FileRequester
  132.         tst.l    d0
  133.         beq    Load_Out1
  134.  
  135.         lea.l    FRPathName,a1
  136.         move.l    a1,d1
  137.         cmp.b    #$00,(a1)
  138.         beq    Load_Out1
  139.         move.l    #MODE_OLDFILE,d2
  140.         lib    Dos,Open
  141.         move.l    d0,QueFile
  142.         bne    Load1
  143.         jsr    FileError
  144.         jmp    Load_Out1
  145.  
  146. ;reading "logic"
  147.  
  148. Load1:        cmp.w    #$01,IOMode
  149.         beq    VLoad
  150.  
  151.         jsr    CheckFile
  152.         tst.l    d0
  153.         beq    Load_Out2
  154.  
  155.         jsr    KillQueMem1
  156.  
  157.         lea.l    SS_Load2,a0
  158.         jsr    Speaker
  159.  
  160. ;Load descriptions (2 lines)
  161.  
  162.         move.l    DesMem1,d4
  163. Load1.1:    move.l    QueFile,d1
  164.         move.l    d4,d2
  165.         move.l    #1,d3
  166.         lib    Dos,Read
  167.         tst.l    d0
  168.         beq    Load5
  169.         move.l    d4,a2
  170.         add.l    #1,d4
  171.         tst.b    (a2)
  172.         bne    Load1.1
  173.  
  174.         move.l    DesMem1,d4
  175.         add.l    #LineLeng,d4
  176. Load1.2:    move.l    QueFile,d1
  177.         move.l    d4,d2
  178.         move.l    #1,d3
  179.         lib    Dos,Read
  180.         tst.l    d0
  181.         beq    Load5
  182.         move.l    d4,a2
  183.         add.l    #1,d4
  184.         tst.b    (a2)
  185.         bne    Load1.2
  186.  
  187. ;Then load the questions and answers MAYBE USE 'AddQues'!!!
  188.  
  189.         move.w    #$00,d4
  190. Load2:        move.l    #QA_SIZE,d0        ;reserve memory for node
  191.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  192.         lib    Exec,AllocMem
  193.         tst.l    d0
  194.         bne    Load2.01
  195.         jmp    Load6
  196. Load2.01:    move.l    d0,a2            ;Hold node address in a2
  197.         move.l    #NextQues,d0        ;Reserve ques-ans memory
  198.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  199.         lib    Exec,AllocMem        
  200.         tst.l    d0
  201.         bne    Load2.02
  202.         move.l    a2,a1            ;No mem. Clear Node mem
  203.         move.l    #QA_SIZE,d0
  204.         lib    Exec,FreeMem
  205.         jmp    Load6
  206. Load2.02:    move.l    d0,a3            ;Hold memory info in a3
  207.         lea.l    QAList,a0
  208.         move.l    a2,a1
  209.         ADDTAIL                ;Add Node to list
  210.         move.l    a3,QA_Data(a2)        ;Add memory info to node
  211.  
  212. Load2.1:    add.w    #1,d4
  213.         cmp.w    NumQ,d4
  214.         bne    Load2
  215.  
  216.         move.w    #$00,QueCount        ;Start from first question
  217. Load3:        move.b    #$00,d5            ;d5 = question line counter
  218.         jsr    Find            ;get mem add of QueCount'th ques
  219. Load3.1:    move.l    QueFile,d1        ;file stuff
  220.         move.l    a4,d2            ;get question mem address
  221.         move.l    #1,d3            ;read one byte only
  222.         lib    Dos,Read        ;read
  223.         tst.l    d0            ;errors?
  224.         beq    Load5            ;if so goto Load5
  225.         add.l    #1,a4            ;increase memory pointer
  226.         tst.b    -1(a4)            ;was last read zero?
  227.         bne    Load3.1            ;if not continue looping
  228.  
  229. ;Read two lines of questions
  230.  
  231.         cmp.b    #$01,d5            ;see if done two questoions
  232.         beq    Load3.2            ;if so, goto Load3.2
  233.         add.b    #$01,d5            ;no. add ques line counter
  234.         jsr    Find            ;get start of memory again
  235.         add.l    #LineLeng,a4        ;add LineLeng to get next
  236.         jmp    Load3.1            ;lines address. Loop.
  237.  
  238. ;Read 9 + one fake answers
  239.  
  240. Load3.2:    jsr    Find            ;get start of curr memory
  241.         add.l    #QueLeng,a4        ;skip questions
  242.         move.w    #$00,d5            ;d5 = answer line counter
  243. Load3.3:    move.l    QueFile,d1        ;file stuff
  244.         move.l    a4,d2            ;move memory address
  245.         move.l    #1,d3            ;read one byte only
  246.         lib    Dos,Read        ;read.
  247.         tst.l    d0            ;errors?
  248.         beq    Load5            ;If so goto Load5
  249.         add.l    #1,a4            ;increase mem address
  250.         tst.b    -1(a4)            ;was last byte zero?
  251.         bne    Load3.3            ;if not continue looping
  252.  
  253.         cmp.w    #8,d5            ;done 9 answers?
  254.         beq    Load3.4            ;if so continue at Load3.4
  255.         add.w    #$01,d5            ;increase counter
  256.         jsr    Find            ;get start of current mem
  257.         move.w    d5,d1
  258.         add.l    #QueLeng,a4        ;Skip questions
  259.         mulu.w    #AnsLeng,d1        ;skip read answers
  260.         add.l    d1,a4
  261.         jmp    Load3.3            ;loop.
  262.  
  263. Load3.4:    add.w    #$01,QueCount        ;increase QueCounter
  264.         move.w    QueCount,d1        ;compare with NumQ
  265.         cmp.w    NumQ,d1            ;to see if done all
  266.         beq    Load4
  267. ;--- CUT ---
  268.         move.l    QueFile,d1
  269.         move.l    #1,d2
  270.         move.l    #0,d3
  271.         lib    Dos,Seek
  272.  
  273. ;--- CUT ---
  274. ;        bne    Load3            ;questions. loop if not
  275.         jmp    Load3
  276.  
  277. Load4:        move.l    QueFile,d1        ;Close File
  278.         lib    Dos,Close
  279.         move.l    #$00,QueFile
  280.         move.w    #$00,QueCount        ;Reset QueCount
  281.         jmp    Load_Out        ;-->OUT
  282.  
  283. ;Come here if read error during des/que/ans
  284.  
  285. Load5:        jsr    FileError
  286.         lea.l    SS_ERR_File1,a0
  287.         jsr    Speaker
  288.         jsr    KillQueMem1
  289.         move.w    #00,NumQ
  290.         jmp    Load4
  291.  
  292. ;Come here if no memory available
  293.  
  294. Load6:        jsr    NoMem1
  295.         lea.l    SS_ERR_File1,a0
  296.         jsr    Speaker
  297.         jsr    KillQueMem1
  298.         move.w    #00,NumQ
  299.         jmp    Load4
  300.  
  301. ;come here if everything ok during load
  302.  
  303. Load_Out:    lea.l    SS_Done,a0
  304.         jsr    Speaker
  305.         jsr    MenusOn
  306.         jsr    NormalPointer
  307.         cmp.w    #$02,Mode
  308.         bne    Game
  309.         jsr    SetActivation
  310.         jsr    OthActivation1
  311.         jmp    DoTeach
  312.  
  313. ;come here if users clicked closewindow or couldn't open that file
  314.  
  315. Load_Out1:    jsr    MenusOn
  316.         jsr    NormalPointer
  317.         cmp.w    #$02,Mode
  318.         bne    GoMainMenu
  319.         jsr    SetActivation
  320.         jsr    OthActivation1
  321.         jmp    Window1IDCMP
  322.  
  323. ;Incorrect file etc.
  324.  
  325. Load_Out2:    lea.l    SS_ERR_File2,a0
  326.         jsr    Speaker
  327.         move.l    QueFile,d1
  328.         lib    Dos,Close
  329.         move.l    #$00,QueFile
  330.         jsr    MenusOn
  331.         jsr    NormalPointer
  332.         move.w    #$00,NumQ
  333.         cmp.w    #$02,Mode
  334.         bne    GoMainMenu
  335.         jsr    SetActivation
  336.         jsr    OthActivation1
  337.         jmp    Window1IDCMP
  338.  
  339. GoMainMenu:    jsr    MainMenu
  340.         jmp    Window1IDCMP
  341.  
  342. SaveAs:        jsr    SleepPointer
  343.         jsr    SaveQuestion
  344.  
  345.         cmp.w    #$02,Mode
  346.         bne    SaveAs0.1
  347.         move.w    NumQ,d6
  348.         clr.w    NumQ
  349.         jsr    SetActivation
  350.         move.w    d6,NumQ
  351.         jsr    OthActivation
  352.  
  353. SaveAs0.1    jsr    MenusOff
  354.         move.w    QueCount,QueCount2
  355.     
  356.         lea.l    SS_SaveAs,a0
  357.         jsr    Speaker
  358.  
  359.         lea.l    SaveName,a5
  360.         move.l    #FRQABSOLUTEXYM+FRQSAVINGM,d5
  361.         jsr    FileRequester
  362.         tst.l    d0
  363.         beq    SaveOut
  364.  
  365.         lea.l    FRPathName,a1
  366.         move.l    a1,d1
  367.         cmp.b    #$00,(a1)
  368.         beq    SaveOut
  369.         move.l    #MODE_OLDFILE,d2
  370.         lib    Dos,Open
  371.         move.l    d0,QueFile
  372.         beq    Save1        ;file doesn't exist...
  373.  
  374. ;The file already exists so we'll ask if the user wants to replace old file 
  375.  
  376.         lea.l    SS_ERR_File3,a0
  377.         jsr    Speaker
  378.  
  379.         lea.l    AskReplace,a0
  380.         move.l    #$00,a1
  381.         jsr    TwoGadRequest
  382.         tst.l    d0
  383.         beq    Save5
  384.  
  385.         move.l    QueFile,d1
  386.         lib    Dos,Close
  387.         move.l    #$00,QueFile
  388.  
  389. SaveAsOut:    jsr    MenusOn
  390.         jsr    SetActivation
  391.         jsr    OthActivation1
  392.         jsr    NormalPointer
  393.  
  394. Save:        jsr    SleepPointer
  395.         cmp.w    #$02,Mode
  396.         bne    Save0.1
  397.         move.w    NumQ,d6
  398.         clr.w    NumQ
  399.         jsr    SetActivation
  400.         move.w    d6,NumQ
  401.         jsr    OthActivation
  402.  
  403. Save0.1:    jsr    MenusOff
  404.         jsr    SaveQuestion
  405.  
  406.         lea.l    SS_Save,a0
  407.         jsr    Speaker
  408.  
  409. Save1:        tst.l    QueFile
  410.         bne    Save2
  411.         lea.l    FRPathName,a1
  412.         move.l    a1,d1
  413.         move.l    #MODE_NEWFILE,d2
  414.         lib    Dos,Open
  415.         move.l    d0,QueFile
  416.         bne    Save2
  417.         jsr    FileError
  418.         jmp    SaveOut
  419.  
  420.         move.l    #"Ques",Que
  421.  
  422. Save2:        move.l    QueFile,d1
  423.         lea.l    Que,a0
  424.         move.l    a0,d2
  425.         move.l    #8,d3
  426.         lib    Dos,Write
  427.         cmp.l    #-1,d0
  428.         beq    SaveError
  429.  
  430. ;Save description for questions
  431.  
  432.         move.l    DesMem1,d2
  433.         jsr    GetLength
  434.         move.l    QueFile,d1
  435.         move.l    DesMem1,d2
  436.         lib    Dos,Write
  437.         tst.l    d0
  438.         beq    SaveError
  439.  
  440.         move.l    DesMem1,d2
  441.         add.l    #LineLeng