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.S < prev    next >
Encoding:
Text File  |  1991-10-20  |  8.6 KB  |  484 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.         jmp    Load6
  165. Load2.01:    move.l    d0,a2            ;Hold node address in a2
  166.         move.l    #NextQues,d0        ;Reserve ques-ans memory
  167.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  168.         lib    Exec,AllocMem        
  169.         tst.l    d0
  170.         bne    Load2.02
  171.         move.l    a2,a1            ;No mem. Clear Node mem
  172.         move.l    #QA_SIZE,d0
  173.         lib    Exec,FreeMem
  174.         jmp    Load6
  175. Load2.02:    move.l    d0,a3            ;Hold memory info in a3
  176.         lea.l    QAList,a0
  177.         move.l    a2,a1
  178.         ADDTAIL                ;Add Node to list
  179.         move.l    a3,QA_Data(a2)        ;Add memory info to node
  180.  
  181. Load2.1:    add.w    #1,d4
  182.         cmp.w    NumQ,d4
  183.         bne    Load2
  184.  
  185.         move.w    #$00,QueCount        ;Start from first question
  186. Load3:        move.b    #$00,d5            ;d5 = question line counter
  187.         jsr    Find            ;get mem add of QueCount'th ques
  188. Load3.1:    move.l    QueFile,d1        ;file stuff
  189.         move.l    a4,d2            ;get question mem address
  190.         move.l    #1,d3            ;read one byte only
  191.         lib    Dos,Read        ;read
  192.         tst.l    d0            ;errors?
  193.         beq    Load5            ;if so goto Load5
  194.         add.l    #1,a4            ;increase memory pointer
  195.         tst.b    -1(a4)            ;was last read zero?
  196.         bne    Load3.1            ;if not continue looping
  197.  
  198. ;Read two lines of questions
  199.  
  200.         cmp.b    #$01,d5            ;see if done two questoions
  201.         beq    Load3.2            ;if so, goto Load3.2
  202.         add.b    #$01,d5            ;no. add ques line counter
  203.         jsr    Find            ;get start of memory again
  204.         add.l    #LineLeng,a4        ;add LineLeng to get next
  205.         jmp    Load3.1            ;lines address. Loop.
  206.  
  207. ;Read 10 answers
  208.  
  209. Load3.2:    jsr    Find            ;get start of curr memory
  210.         add.l    #QueLeng,a4        ;skip questions
  211.         move.w    #$00,d5            ;d5 = answer line counter
  212. Load3.3:    move.l    QueFile,d1        ;file stuff
  213.         move.l    a4,d2            ;move memory address
  214.         move.l    #1,d3            ;read one byte only
  215.         lib    Dos,Read        ;read.
  216.         tst.l    d0            ;errors?
  217.         beq    Load5            ;If so goto Load5
  218.         add.l    #1,a4            ;increase mem address
  219.         tst.b    -1(a4)            ;was last byte zero?
  220.         bne    Load3.3            ;if not continue looping
  221.  
  222.         cmp.w    #9,d5            ;done 10 answers?
  223.         beq    Load3.4            ;if so continue at Load3.4
  224.         add.w    #$01,d5            ;increasee counter
  225.         jsr    Find            ;get start of current mem
  226.         move.w    d5,d1
  227.         add.l    #QueLeng,a4        ;Skip questions
  228.         mulu.w    #AnsLeng,d1        ;skip read answers
  229.         add.l    d1,a4
  230.         jmp    Load3.3            ;loop.
  231.  
  232. Load3.4:    add.w    #$01,QueCount        ;increase QueCounter
  233.         move.w    QueCount,d1        ;compare with NumQ
  234.         cmp.w    NumQ,d1            ;to see if done all
  235.         bne    Load3            ;questions. loop if not
  236.  
  237. Load4:        move.l    QueFile,d1        ;Close File
  238.         lib    Dos,Close
  239.         move.l    #$00,QueFile
  240.         move.w    #$00,QueCount        ;Reset QueCount
  241.         jmp    Load_Out        ;-->OUT
  242.  
  243. ;Come here if read error during des/que/ans
  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.  
  252. ;Come here if no memory available
  253.  
  254. Load6:        jsr    NoMem1
  255.         lea.l    SS_ERR_File1,a0
  256.         jsr    Speaker
  257.         jsr    KillQueMem1
  258.         move.w    #00,NumQ
  259.         jmp    Load4
  260.  
  261. ;come here if everything ok during load
  262.  
  263. Load_Out:    lea.l    SS_Done,a0
  264.         jsr    Speaker
  265.         jsr    MenusOn
  266.         jsr    NormalPointer
  267.         cmp.w    #$02,Mode
  268.         bne    Game
  269.         jsr    SetActivation
  270.         jsr    OthActivation1
  271.         jmp    DoTeach
  272.  
  273. ;come here if users clicked closewindow or couldn't open that file
  274.  
  275. Load_Out1:    jsr    MenusOn
  276.         jsr    NormalPointer
  277.         cmp.w    #$02,Mode
  278.         bne    GoMainMenu
  279.         jsr    SetActivation
  280.         jsr    OthActivation1
  281.         jmp    Window1IDCMP
  282.  
  283. ;Incorrect file etc.
  284.  
  285. Load_Out2:    lea.l    SS_ERR_File2,a0
  286.         jsr    Speaker
  287.         move.l    QueFile,d1
  288.         lib    Dos,Close
  289.         move.l    #$00,QueFile
  290.         jsr    MenusOn
  291.         jsr    NormalPointer
  292.         move.w    #$00,NumQ
  293.         cmp.w    #$02,Mode
  294.         bne    GoMainMenu
  295.         jsr    SetActivation
  296.         jsr    OthActivation1
  297.         jmp    Window1IDCMP
  298.  
  299. GoMainMenu:    jsr    MainMenu
  300.         jmp    Window1IDCMP
  301.  
  302. SaveAs:        jsr    SleepPointer
  303.         jsr    SaveQuestion
  304.  
  305.         cmp.w    #$02,Mode
  306.         bne    SaveAs0.1
  307.         move.w    NumQ,d6
  308.         clr.w    NumQ
  309.         jsr    SetActivation
  310.         move.w    d6,NumQ
  311.         jsr    OthActivation
  312.  
  313. SaveAs0.1    jsr    MenusOff
  314.         move.w    QueCount,QueCount2
  315.     
  316.         lea.l    SS_SaveAs,a0
  317.         jsr    Speaker
  318.  
  319.         lea.l    SaveName,a5
  320.         move.l    #FRQABSOLUTEXYM+FRQSAVINGM,d5
  321.         jsr    FileRequester
  322.         tst.l    d0
  323.         beq    SaveOut
  324.  
  325.         lea.l    FRPathName,a1
  326.         move.l    a1,d1
  327.         cmp.b    #$00,(a1)
  328.         beq    SaveOut
  329.         move.l    #MODE_OLDFILE,d2
  330.         lib    Dos,Open
  331.         move.l    d0,QueFile
  332.         beq    Save1        ;file doesn't exist...
  333.  
  334. ;The file already exists so we'll ask if the user wants to replace old file 
  335.  
  336.         lea.l    SS_ERR_File3,a0
  337.         jsr    Speaker
  338.  
  339.         lea.l    AskReplace,a0
  340.         move.l    #$00,a1
  341.         jsr    TwoGadRequest
  342.         tst.l    d0
  343.         beq    Save5
  344.  
  345.         move.l    QueFile,d1
  346.         lib    Dos,Close
  347.         move.l    #$00,QueFile
  348.  
  349. SaveAsOut:    jsr    MenusOn
  350.         jsr    SetActivation
  351.         jsr    OthActivation1
  352.         jsr    NormalPointer
  353.  
  354. Save:        jsr    SleepPointer
  355.         cmp.w    #$02,Mode
  356.         bne    Save0.1
  357.         move.w    NumQ,d6
  358.         clr.w    NumQ
  359.         jsr    SetActivation
  360.         move.w    d6,NumQ
  361.         jsr    OthActivation
  362.  
  363. Save0.1:    jsr    MenusOff
  364.         jsr    SaveQuestion
  365.  
  366.         lea.l    SS_Save,a0
  367.         jsr    Speaker
  368.  
  369. Save1:        tst.l    QueFile
  370.         bne    Save2
  371.         lea.l    FRPathName,a1
  372.         move.l    a1,d1
  373.         move.l    #MODE_NEWFILE,d2
  374.         lib    Dos,Open
  375.         move.l    d0,QueFile
  376.         bne    Save2
  377.         jsr    FileError
  378.         jmp    SaveOut
  379.  
  380.         move.l    #"Ques",Que
  381.  
  382. Save2:        move.l    QueFile,d1
  383.         lea.l    Que,a0
  384.         move.l    a0,d2
  385.         move.l    #8,d3
  386.         lib    Dos,Write
  387.         cmp.l    #-1,d0
  388.         beq    SaveError
  389.  
  390. ;Save description for questions
  391.  
  392.         move.l    DesMem1,d2
  393.         jsr    GetLength
  394.         move.l    QueFile,d1
  395.         move.l    DesMem1,d2
  396.         lib    Dos,Write
  397.         tst.l    d0
  398.         beq    SaveError
  399.  
  400.         move.l    DesMem1,d2
  401.         add.l    #LineLeng,d2
  402.         jsr    GetLength
  403.         move.l    QueFile,d1
  404.         lib    Dos,Write
  405.         tst.l    d0
  406.         beq    SaveError
  407.  
  408.         move.w    QueCount,QueCount2        ;save position
  409.         move.w    #$00,QueCount
  410. Save3:        move.b    #$00,d5
  411.         jsr    Find
  412. Save3.1:    move.l    a4,d2
  413.         jsr    GetLength
  414.         move.l    QueFile,d1
  415.         lib    Dos,Write
  416.         tst.l    d0
  417.         beq    SaveError
  418.  
  419. ;Save two lines of questions
  420.  
  421.         cmp.b    #$01,d5
  422.         beq    Save3.2
  423.         add.b    #$01,d5
  424.         jsr    Find
  425.         add.l    #LineLeng,a4
  426.         jmp    Save3.1
  427.  
  428. ;Save 10 answers
  429.  
  430. Save3.2:    jsr    Find
  431.         add.l    #QueLeng,a4
  432.         move.w    #$00,d5
  433. Save3.3:    move.l    a4,d2
  434.         jsr    GetLength
  435.         move.l    QueFile,d1
  436.         lib    Dos,Write
  437.         tst.l    d0
  438.         beq    SaveError
  439.  
  440.         cmp.w    #9,d5
  441.         beq    Save3.4
  442.         add.w    #$01,d5
  443.         jsr    Find
  444.         move.w    d5,d1
  445.         add.l    #QueLeng,a4
  446.         mulu.w    #AnsLeng,d1
  447.         add.l    d1,a4
  448.         jmp    Save3.3
  449.  
  450. Save3.4:    add.w    #$01,QueCount
  451.         move.w    QueCount,d1
  452.         cmp.w    NumQ,d1
  453.         bne    Save3
  454.  
  455. ;Close the file
  456.  
  457. Save5:        move.l    QueFile,d1
  458.         lib    Dos,Close
  459.         move.l    #$00,QueFile
  460.         move.w    QueCount2,QueCount        ;Get position
  461.         jsr    Find
  462.         jsr    PrintTeach
  463.  
  464. SaveOut:    lea.l    SS_Done,a0
  465.         jsr    Speaker
  466.         jsr    MenusOn
  467.         jsr    SetActivation
  468.         jsr    OthActivation1
  469.         jsr    NormalPointer
  470.         jmp    Window1IDCMP
  471.  
  472. SaveError:    jsr    FileError
  473.         lea.l    SS_ERR_File1,a0
  474.         jsr    Speaker
  475.         jmp    Save5
  476.  
  477.         INCLUDE    "FH1:Language/WF/Questions/Que.i"
  478.  
  479.         STRUCTURE  QA,MLN_SIZE
  480.             APTR    QA_Data
  481.             LABEL   QA_SIZE
  482.  
  483.         END
  484.