home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff387.lzh / Wreq / Wreq.a < prev    next >
Text File  |  1990-10-22  |  23KB  |  368 lines

  1.                 INCLUDE "exec/types.i"
  2.                 INCLUDE "exec/tasks.i"
  3.                 INCLUDE "exec/memory.i"
  4.                 INCLUDE "exec/funcdef.i"
  5.                 INCLUDE "exec/exec_lib.i"
  6.                 INCLUDE "libraries/dos_lib.i"
  7.                 INCLUDE "libraries/dos.i"
  8.                 INCLUDE "intuition/intuition.i"
  9.  
  10.                 csect    wreq.o,0,0,1,2
  11.  
  12.                 xdef     _autorequest
  13.                 xdef     __main
  14.  
  15. NULL            EQU      0                  ; Pointing to nowhere
  16. absexecbase     EQU      4                  ; Adress to get the ExecBase
  17. CR              EQU      13                 ; Carriage return
  18. LF              EQU      10                 ; Line feed
  19. TRUE            EQU      1                  ; Boolean TRUE-value
  20. FALSE           EQU      0                  ; Boolean FALSE-value
  21. autoreqoffset   EQU      $FEA4              ; Library offset
  22. ONE             EQU      '1'                ; Primary option
  23. TWO             EQU      '2'                ; Secondary option
  24. HIT_RET_LEN     EQU      27                 ; Prompt lenght
  25. UP_CASE         EQU      $DF                ; Bit 5 masked
  26. FIRST_LEGAL     EQU      'A'                ; First alphabet
  27. LAST_LEGAL      EQU      'Z'                ; End of range
  28. OPT_LEN         EQU      4                  ; Lenght per option query
  29. WRITING         EQU      10000              ; Not just measuring
  30. ONE_LINE        EQU      20000              ; No linefeeds
  31. MAX_COL         EQU      76                 ; Max line lenght
  32. MAX_OPT         EQU      72                 ; Including the option
  33. OPT_ONE_LINE    EQU      13                 ; For both in same line
  34. LIST_LEN        EQU      64                 ; Lenght of the index list
  35.  
  36. __main          MOVEM.L  A2/D2,-(A7)        ; save registers
  37.                 MOVEA.L  absexecbase,A6     ; Exec-librarys base to use
  38.                 LEA      intuitionname(PC),A1 ; A1 = Name of the library
  39.                 MOVEQ    #0,D0              ; D0 = Version
  40.                 JSR      _LVOOpenLibrary(A6) ;Open the intuition-library
  41.                 CMPI.L   #NULL,D0           ; If the library pointer is NULL
  42.                 BEQ      s_exit             ; Then exit immediately
  43.                 MOVEA.L  D0,A2              ; Save the pointer to library
  44.                 LEA      _autorequest(PC),A0 ; Start of function
  45.                 LEA      intuitionname(PC),A1 ; End of function and data
  46.                 SUBA.L   A0,A1              ; Calculate the size
  47.                 MOVE.L   A1,D2              ; Save the size
  48.                 MOVE.L   A1,D0              ; D0 = Size in bytes
  49.                 MOVE.L   #MEMF_PUBLIC,D1    ; D1 = Requirements
  50.                 JSR      _LVOAllocMem(A6)   ; Allocate memory
  51.                 CMPI.L   #NULL,D0           ; If there was no memory
  52.                 BEQ      close              ; Then close and exit
  53.                 MOVEA.L  D0,A1              ; D0 = Pointer to memory
  54.                 SUBQ.W   #1,D2              ; Adjust the counter
  55.                 LEA      _autorequest(PC),A0 ; Pointer to function
  56. copyfunc        MOVE.B   (A0)+,(A1)+        ; Copy bytes
  57.                 DBRA     D2,copyfunc        ; Decrement and branch
  58.                 MOVEA.L  #autoreqoffset,A0  ; A0 = library offset
  59.                 MOVEA.L  A2,A1              ; A1 = pointer to library
  60.                 JSR      _LVOSetFunction(A6) ; Replace function
  61. close           MOVEA.L  A2,A1              ; Restore the pointer to library
  62.                 JSR      _LVOCloseLibrary(A6) ; Close intuition-library
  63. s_exit          MOVEQ    #FALSE,D0          ; Return FALSE
  64.                 MOVEM.L  (A7)+,A2/D2        ; Restore registers
  65.                 RTS                         ; Return to caller
  66.  
  67. _autorequest    MOVEM.L  D2-D7/A2-A6,-(A7)  ; Save registers
  68.                 MOVEQ    #FALSE,D6          ; Return FALSE
  69.                 MOVE.L   A1,A4              ; A1 -> Bodytext (IntuiText)
  70.                 MOVEA.L  absexecbase,A6     ; Exec-librarys base to use
  71.                 MOVEA.L  #0,A1              ; A1 = NULL (my task)
  72.                 JSR      _LVOFindTask(A6)   ; Find the task structure
  73.                 MOVEA.L  D0,A1              ; Structure base to A1
  74.                 CMPI.B   #NT_PROCESS,LN_TYPE(A1) ;If my task is not a process
  75.                 BNE      a_exit             ; Then exit immediately
  76.                 LEA      doslibname(PC),A1  ; A1 = Name of the dos-library
  77.                 MOVEQ    #0,D0              ; D0 = Version
  78.                 JSR      _LVOOpenLibrary(A6) ;Open dos-library
  79.                 CMPI.L   #NULL,D0           ; If the library pointer is NULL
  80.                 BEQ      a_exit             ; Then exit immediately
  81.                 MOVEA.L  D0,A6              ; Dos-librarys base to use
  82.                 JSR      _LVOInput(A6)      ; Get standard input file
  83.                 CMPI.L   #NULL,D0           ; If the file pointer is NULL
  84.                 BEQ      done               ; Then do not write
  85.                 LEA      input(PC),A0       ; Get storing address
  86.                 MOVE.L   D0,(A0)            ; Save the file pointer
  87.                 MOVE.L   D0,D1              ; D1 = file pointer
  88.                 JSR      _LVOIsInteractive(A6) ;Check the input file type
  89.                 TST.L    D0                 ; If not interactive
  90.                 BEQ      done               ; Then do not write
  91.                 JSR      _LVOOutput(A6)     ; Get standard output file
  92.                 CMPI.L   #NULL,D0           ; If the file pointer is NULL
  93.                 BEQ      done               ; Then do not write
  94.                 MOVE.L   D0,D4              ; Save file pointer in D4
  95.                 CMPA.L   #NULL,A2           ; If the positive text not NULL
  96.                 BNE      may_query          ; Query is still possible
  97.                 CMPA.L   #NULL,A3           ; If the negative text not NULL
  98.                 BNE      no_options         ; No need to query
  99.                 CMPA.L   #NULL,A4           ; If the body text is also NULL
  100.                 BEQ      done               ; Then no text to display
  101. no_options      LEA      posit(PC),A0       ; Pointer to good option
  102.                 MOVE.B   #0,(A0)+           ; Mark it meaningless
  103.                 BRA      options_set        ; Go to display text
  104. may_query       CMPA.L   #NULL,A3           ; If the negative text not NULL
  105.                 BNE      query              ; Then read line
  106.                 MOVEQ    #TRUE,D6           ; Return TRUE
  107.                 BRA      no_options         ; No other option
  108. query           MOVEQ    #0,D7              ; Zero the counters
  109.                 MOVEA.L  A3,A5              ; A5 = negative text
  110.                 JSR      writetext(PC)      ; Sort the text
  111.                 MOVEA.L  first(PC),A0       ; Pointer to negative string
  112.                 MOVE.L   A0,-(A7)           ; Save the negative pointer
  113.                 MOVEA.L  A2,A5              ; A5 = positive text
  114.                 JSR      writetext(PC)      ; Sort the text
  115.                 MOVEA.L  first(PC),A0       ; Pointer to positive string
  116.                 MOVEA.L  (A7)+,A1           ; Restore the negative pointer
  117.                 MOVE.B   (A0),D0            ; First character
  118.                 JSR      check_char         ; Check if legal
  119.                 TST.B    D0                 ; Was it illegal?
  120.                 BEQ      one_two            ; Then ask with numbers
  121.                 LEA      posit(PC),A0       ; Positive option = first char
  122.                 MOVE.B   D0,(A0)+           ; A0 -> negat
  123.                 MOVE.B   (A1),D0            ; First character
  124.                 JSR      check_char         ; Check if legal
  125.                 TST.B    D0                 ; Was it illegal?
  126.                 BEQ      one_two            ; Then ask with numbers
  127.                 MOVE.B   D0,(A0)+           ; Negative option = first char
  128.                 CMP.B    posit(PC),D0       ; Aren't the options identical?
  129.                 BNE      options_set        ; Then they are ok.
  130. one_two         LEA      posit(PC),A0       ; A0 -> positive option
  131.                 MOVE.B   #ONE,(A0)+         ; Positive option = '1'
  132.                 MOVE.B   #TWO,(A0)+         ; Negative option = '2'
  133. options_set     JSR      linefeed(PC)       ; D4 = file pointer
  134.                 MOVEQ    #0,D7              ; Zero the counter
  135.                 MOVEA.L  A4,A5              ; A5 = body text
  136.                 JSR      writetext(PC)      ; Measure text
  137.                 MOVEA.L  A4,A5              ; A5 = body text
  138.                 CMP.W    #MAX_COL,D7        ; Is it too long for one line
  139.                 BHI      high_body          ; Then use many lines
  140.                 MOVE.W   #ONE_LINE,D7       ; Use one line
  141.                 BRA      write_body         ; Go to write it
  142. high_body       MOVE.W   #WRITING,D7        ; Set write mode
  143. write_body      JSR      writetext(PC)      ; Write body text
  144.                 CMPI.W   #WRITING,D7        ; Is there LF already
  145.                 BEQ      ask_option         ; Then don't write an other one
  146.                 JSR      linefeed(PC)       ; D4 = file pointer
  147. ask_option      SWAP     D6                 ; Save return value
  148.                 MOVE.W   #OPT_ONE_LINE,D6   ; Set counter starting value
  149.                 MOVEQ    #0,D7              ; Zero the counters
  150.                 MOVEA.L  A3,A5              ; A5 = negative text
  151.                 JSR      writetext(PC)      ; Measure text
  152.                 ADD.W    D7,D6              ; Add lenght to counter
  153.                 CMP.W    #MAX_OPT,D7        ; Is it too long for one line
  154.                 BHI      high_negat         ; Then use many lines
  155.                 MOVE.W   #ONE_LINE,D7       ; Use one line
  156.                 BRA      normal_negat       ; Go to write it
  157. high_negat      MOVE.W   #WRITING,D7        ; Set write mode
  158. normal_negat    SWAP     D7                 ; Save value
  159.                 MOVEA.L  A2,A5              ; A5 = positive text
  160.                 JSR      writetext(PC)      ; Measure text
  161.                 ADD.W    D7,D6              ; Add lenght to counter
  162.                 CMP.W    #MAX_OPT,D7        ; Is it too long for one line
  163.                 BHI      high_posit         ; Then use many lines
  164.                 MOVE.W   #ONE_LINE,D7       ; Use one line
  165.                 BRA      normal_posit       ; Go to write it
  166. high_posit      MOVE.W   #WRITING,D7        ; Set write mode
  167. normal_posit    MOVEQ    #0,D0              ; Get zero
  168.                 CMP.B    posit(PC),D0       ; Is option meaningless
  169.                 BEQ      reply              ; Then just wait for RETURN
  170.                 CMP.W    #MAX_COL,D6        ; Are the options too long
  171.                 BHI      too_long           ; Then use separate lines
  172.                 MOVE.W   #0,D6              ; Use one line for options
  173.                 BRA      show_options       ; Go to show the options
  174. too_long        JSR      linefeed(PC)       ; D4 = file pointer
  175. show_options    LEA      option(PC),A0      ; Pointer to option
  176.                 MOVE.B   posit(PC),0(A0)    ; Option is positive
  177.                 MOVEQ    #OPT_LEN,D3        ; D3 = lenght of write
  178.                 JSR      write_out(PC)      ; Write to output
  179.                 MOVEA.L  A2,A5              ; A5 = positive text
  180.                 JSR      writetext(PC)      ; Write it out
  181.                 TST.W    D6                 ; Aren't we using separate lines?
  182.                 BEQ      write_mid          ; Then separate options
  183.                 CMPI.W   #WRITING,D7        ; Is there LF already
  184.                 BEQ      show_negat         ; Then don't write an other one
  185.                 JSR      linefeed(PC)       ; D4 = file pointer
  186.                 BRA      show_negat         ; Go to show the negative option
  187. write_mid       LEA      mid_part(PC),A0    ; Pointer to option separator
  188.                 JSR      write_two(PC)      ; Write it out
  189. show_negat      LEA      option(PC),A0      ; Pointer option
  190.                 MOVE.B   negat(PC),0(A0)    ; Option is negative
  191.                 MOVEQ    #OPT_LEN,D3        ; D3 = lenght of write
  192.                 JSR      write_out(PC)      ; Write to output
  193.                 SWAP     D7                 ; Restore value
  194.                 MOVEA.L  A3,A5              ; A5 = negative text
  195.                 JSR      writetext(PC)      ; Write it out
  196.                 TST.W    D6                 ; Aren't we using separate lines?
  197.                 BEQ      right_after        ; Then put it right after
  198.                 CMPI.W   #WRITING,D7        ; Is there LF already
  199.                 BEQ      right_after        ; Then don't write an other one
  200.                 JSR      linefeed(PC)       ; D4 = file pointer
  201. right_after     LEA      prompt(PC),A0      ; Pointer to prompt
  202.                 JSR      write_two(PC)      ; Write lenght of two
  203.                 BRA      wait               ; Go to wait answer
  204. reply           MOVEA.L  A2,A5              ; A5 = positive text
  205.                 JSR      writetext(PC)      ; Write it out
  206.                 SWAP     D7                 ; Restore value
  207.                 MOVEA.L  A3,A5              ; A5 = negative text
  208.                 JSR      writetext(PC)      ; Write it out
  209.                 LEA      hit_ret(PC),A0     ; Pointer to Press RETURN text
  210.                 MOVE.L   #HIT_RET_LEN,D3    ; D3 = lenght of write
  211.                 jsr      write_out(PC)      ; Write it out
  212. wait            MOVE.L   input(PC),D5       ; Restore input file pointer
  213.                 SWAP     D6                 ; Restore return value
  214.                 LEA      answer(PC),A0      ; Pointer to answer
  215.                 MOVE.L   D5,D1              ; D1 = pointer to file (input)
  216.                 MOVE.L   A0,D2              ; D2 = pointer to buffer
  217.                 MOVEQ    #1,D3              ; D3 = lenght of read
  218.                 JSR      _LVORead(A6)       ; Read a character
  219.                 MOVEA.L  D2,A0              ; Reastore pointer
  220.                 CMPI.B   #LF,(A0)           ; Was it end of the line
  221.                 BEQ      empty              ; Then stop reading
  222.                 LEA      bucket(PC),A0      ; Pointer to bucket
  223.                 MOVE.L   A0,D2              ; D2 = pointer to buffer
  224. read_next       MOVE.L   D5,D1              ; D1 = pointer to file (input)
  225.                 JSR      _LVORead(A6)       ; Read a character
  226.                 MOVEA.L  D2,A0              ; Reastore pointer 
  227.                 CMPI.B   #LF,(A0)           ; Wasn't it end of the line
  228.                 BNE      read_next          ; Then read next character
  229. empty           MOVEQ    #0,D0              ; Get zero
  230.                 CMP.B    posit(PC),D0       ; Is the option meaningless
  231.                 BEQ      done               ; Then the job is done
  232.                 MOVE.B   answer(PC),D0      ; Pointer to answer
  233.                 CMPI.B   #FIRST_LEGAL,D0    ; Can it be digit
  234.                 BLT      digit              ; Then don't modify
  235.                 ANDI.B   #UP_CASE,D0        ; Convert to upper case
  236. digit           CMP.B    negat(PC),D0       ; Is it negative
  237.                 BEQ      done               ; Then go return FALSE
  238.                 CMP.B    posit(PC),D0       ; Isn't it positive
  239.                 BNE      ask_option         ; Then go to ask again
  240.                 MOVEQ    #TRUE,D6           ; Return TRUE
  241. done            MOVEA.L  A6,A1              ; A1 = pointer to library (dos) 
  242.                 MOVEA.L  absexecbase,A6     ; Exec-librarys base to use
  243.                 JSR      _LVOCloseLibrary(A6) ; Close dos-library
  244. a_exit          MOVEQ    #0,D0              ; Zero the long register
  245.                 MOVE.B   D6,D0              ; Boolean return value
  246.                 MOVEM.L  (A7)+,D2-D7/A2-A6  ; Restore registers
  247.                 RTS                         ; Return to caller
  248.  
  249. writetext       LEA      list(PC),A0        ; Pointer to index list
  250.                 MOVEA.L  A5,A1              ; Pointer to first structure
  251.                 MOVEQ    #0,D5              ; Zero the index counter
  252. count_next      CMPA.L   #NULL,A1           ; If the IntuiText pointer is NULL
  253.                 BEQ      last               ; Then this was the last one
  254.                 MOVE.B   D5,(A0)+           ; Put index to list
  255.                 ADDQ.B   #1,D5              ; Increment the index
  256.                 CMPI.W   #LIST_LEN,D5       ; If the index is too big
  257.                 BEQ      last               ; Then this was the last one
  258.                 MOVEA.L  it_NextText(A1),A1 ; Pointer to next IntuiText
  259.                 BRA      count_next         ; Next structure
  260. last            TST.B    D5                 ; Was there NULL-pointer
  261.                 BEQ      return             ; Then return to caller
  262.                 MOVE.L   D5,D3              ; Initialize outer counter
  263.                 SUBQ.B   #2,D3              ; Adjust the counter
  264.                 BMI      sorted             ; Nothing to sort?
  265. outer_loop      MOVEQ    #0,D2              ; Initialize inner counter
  266. inner_loop      LEA      list(PC,D2.W),A1   ; Pointer to current index
  267.                 ADDQ.B   #1,D2              ; Increment inner counter
  268.                 CMP.B    D5,D2              ; If counter reached max value
  269.                 BEQ      loop_end           ; Then the loop has exhausted
  270.                 MOVEQ    #0,D0              ; Zero the register
  271.                 MOVE.B   (A1)+,D0           ; Get index value
  272.                 JSR      getstruct(PC)      ; Get current structure
  273.                 MOVEQ    #0,D0              ; Zero the register
  274.                 MOVE.B   (A1),D0            ; Get next index value
  275.                 MOVEA.L  A0,A1              ; Current structure to A1
  276.                 JSR      getstruct(PC)      ; Get next structure
  277.                 MOVE.W   it_TopEdge(A0),D0  ; Get the next top edge
  278.                 CMP.W    it_TopEdge(A1),D0  ; If current < next top edge
  279.                 BLT      inner_loop         ; Then don't swap them
  280.                 BNE      swap               ; Swap only if not equal
  281.                 MOVE.W   it_LeftEdge(A0),D0 ; Get the next left edge
  282.                 CMP.W    it_LeftEdge(A1),D0 ; If current < next left edge
  283.                 BLT      inner_loop         ; Then don't swap them
  284. swap            LEA      list(PC,D2.W),A0   ; Pointer to next index
  285.                 MOVE.B   (A0),D0            ; Get next index value
  286.                 SWAP     D0                 ; Save next index value
  287.                 MOVE.B   -(A0),D0           ; Get current index value
  288.                 SWAP     D0                 ; Swap index values
  289.                 MOVE.B   D0,(A0)+           ; Set current index value
  290.                 SWAP     D0                 ; Restore next index value
  291.                 MOVE.B   D0,(A0)+           ; Set next index value
  292.                 BRA      inner_loop         ; Continue looping
  293. loop_end        DBRA     D3,outer_loop      ; Check if outer loop done
  294. sorted          MOVE.L   D5,D0              ; Get counter value
  295.                 SUBQ.B   #1,D0              ; Point to last index
  296.                 MOVE.B   list(PC,D0.W),D0   ; Get last index value
  297.                 JSR      getstruct(PC)      ; Get last IntuiText structure
  298.                 LEA      first(PC),A1       ; Pointer to saving address
  299.                 MOVE.L   it_IText(A0),(A1)+ ; Save string pointer
  300.                 BRA      check_counter      ; Go to write loop
  301.  
  302. list            DS.B     LIST_LEN           ; Sorttable index list
  303.  
  304. continue        MOVEQ    #0,D0              ; Zero the register
  305.                 MOVE.B   list(PC,D5.W),D0   ; Get current index value
  306.                 JSR      getstruct(PC)      ; Get current structure
  307.                 MOVEA.L  it_IText(A0),A0    ; Pointer to string
  308.                 MOVE.L   A0,D2              ; D2 = NULL-terminated string
  309.                 MOVEQ    #-1,D3             ; D3 = lenght to be written
  310. strlen          ADDQ.L   #1,D3              ; Increment lenght
  311.                 TST.B    (A0)+              ; While terminator not found
  312.                 BNE      strlen             ; If lenght = 0 then D3 = -1 + 1
  313.                 CMPI.W   #WRITING,D7        ; Are we actually writing this
  314.                 BGE      writing            ; Then go to write it
  315.                 ADD.W    D3,D7              ; Add lenght to counter
  316.                 ADDQ.W   #1,D7              ; Add one for space character
  317.                 BRA      check_counter      ; Continue measuring
  318. writing         JSR      write_file(PC)     ; Write to output
  319.                 CMPI.W   #ONE_LINE,D7       ; Are we using only one line
  320.                 BEQ      put_space          ; Then don't write linefeed
  321. writenext       JSR      linefeed(PC)       ; D4 = file pointer
  322. check_counter   DBRA     D5,continue        ; If counter exhausted
  323. return          RTS                         ; Then return to caller
  324.  
  325. put_space       TST.B    D5                 ; If counter exhausting
  326.                 BEQ      return             ; Then the write is done
  327.                 LEA      space(PC),A0       ; Pointer to space string
  328.                 MOVEQ    #1,D3              ; D3 = lenght of write
  329.                 JSR      write_out(PC)      ; Write the space character
  330.                 BRA      sorted             ; Continue the line
  331.  
  332. getstruct       MOVEA.L  A5,A0              ; Pointer to first structure
  333.                 BRA      dec_counter        ; Go to counting loop
  334. next_struct     MOVEA.L  it_NextText(A0),A0 ; Pointer to next IntuiText
  335. dec_counter     DBRA    D0,next_struct      ; If counter exhausted
  336.                 RTS                         ; Then return to caller
  337.  
  338. linefeed        LEA      crlf(PC),A0        ; Pointer to line-end string
  339. write_two       MOVEQ    #2,D3              ; D3 = lenght to be written
  340. write_out       MOVE.L   A0,D2              ; D2 = string (not terminated)
  341. write_file      MOVE.L   D4,D1              ; D1 = file pointer
  342.                 JMP      _LVOWrite(A6)      ; Write to output
  343.  
  344. check_char      CMPI.B   #FIRST_LEGAL,D0    ; Is it less than 'A'
  345.                 BLT      not_a_z            ; Then it's not legal
  346.                 ANDI.B   #UP_CASE,D0        ; Convert to upper case
  347.                 CMPI.B   #LAST_LEGAL,D0     ; Is it less or equal to 'Z'
  348.                 BLE      legal              ; Then it's legal
  349. not_a_z         MOVEQ    #0,D0              ; Zero means illegal
  350. legal           RTS                         ; Return to caller
  351.  
  352. input           DC.L     0                  ; Pointer to input file
  353. first           DC.L     0                  ; First IntuiText string
  354. doslibname      DOSNAME                     ; Name of the dos-library
  355. crlf            DC.B     CR,LF              ; End of line characters
  356. prompt          DC.B     '?'                ; Prompt for query
  357. space           DC.B     ' '                ; Space for separator
  358. mid_part        DC.B     ', '               ; Option separator
  359. option          DC.B     'X = '             ; Option expression
  360. answer          DC.B     ' '                ; Store for the answer
  361. bucket          DC.B     ' '                ; Store for the rest ones
  362. posit           DC.B     0                  ; Positive option
  363. negat           DC.B     0                  ; Negative option
  364. hit_ret         DC.B     LF,'Press RETURN to continue! ' ;Dummy query
  365. intuitionname   DC.B     'intuition.library',0 ; Name of the intuition-library
  366.  
  367.                 END
  368.