home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 166.lha / QuickView / QView.asm < prev    next >
Encoding:
Assembly Source File  |  1988-04-28  |  24.8 KB  |  1,006 lines

  1. ;                           QView 1.0  by Lyman Epp
  2. ;
  3. ;        Another "File Viewer???"  What for?  It seems that all the other
  4. ;        file viewers have been written in "C".  This is okay, but the
  5. ;        programs are 10-20K.  This file viewer is written in assembler
  6. ;        and contains most of the features of the others, but the program
  7. ;        size is less than 3K bytes!  Also, the source is included so that
  8. ;        you can add more features (please send me a copy if you do.)
  9. ;        QView stands for "Quick View."
  10. ;
  11. ;        This is being distributed as ShareWare.  If you think that QView
  12. ;        is useful, please send $10.  Your response will insure the release
  13. ;        of more quality programs for your Amiga!  Programs already in the
  14. ;        works include: a disk based print spooler, a window dump that
  15. ;        converts the window bitmap back to text, and more.  Be sure to
  16. ;        check out the latest shareware version of QMouse.
  17. ;
  18. ;        The latest version of QView can always be found on the Wind Dragon
  19. ;        Inn BBS, (402)-291-8053.
  20. ;
  21. ;                Lyman R. Epp
  22. ;                10072 Wirt Plaza #15
  23. ;                Omaha, Nebraska 68134
  24.  
  25.  
  26.         SECTION text,CODE
  27.  
  28.         INCLUDE "exec/types.i"
  29.         INCLUDE "exec/ports.i"
  30.         INCLUDE "exec/libraries.i"
  31.         INCLUDE "exec/memory.i"
  32.         INCLUDE "libraries/dos.i"
  33.         INCLUDE "libraries/dosextens.i"
  34.         INCLUDE "intuition/intuition.i"
  35.         INCLUDE "intuition/intuitionbase.i"
  36.  
  37.  
  38. NULL            EQU     0
  39. RAW_ESCAPE      EQU     $45
  40. RAW_SEARCH      EQU     $21      "S"
  41. RAW_AGAIN       EQU     $20      "A"
  42.  
  43. fileNameSize    EQU     70
  44. lineBfrSize     EQU     200
  45. searchSize      EQU     100
  46. titleSize       EQU     80
  47.  
  48. IDCMP_FLAGS     EQU     ACTIVEWINDOW!NEWSIZE!CLOSEWINDOW!RAWKEY!GADGETUP
  49. WINDOW_FLAGS    EQU     NOCAREREFRESH!ACTIVATE!WINDOWSIZING!WINDOWDRAG!WINDOWDEPTH!WINDOWCLOSE
  50.  
  51. UPDATE_SCREEN   EQU     0
  52. UPDATE_TITLE    EQU     1
  53.  
  54.  
  55.         STRUCTURE work,0
  56.  
  57.         STRUCT  newWindowStruct,nw_SIZE
  58.  
  59.         LABEL   parms
  60.         APTR    parmLen
  61.         APTR    parmAddr
  62.  
  63.         APTR    dosBase
  64.         APTR    intuitionBase
  65.         APTR    gfxBase
  66.         APTR    windowPtr
  67.         APTR    rastPort
  68.  
  69.         UWORD   screenCols
  70.         UWORD   screenRows
  71.         UWORD   screenLineNum
  72.         UWORD   screenLineOffset
  73.         ULONG   screenMaxX
  74.         ULONG   screenMaxY
  75.  
  76.         ULONG   borderLeft
  77.         ULONG   borderRight
  78.         ULONG   borderTop
  79.         ULONG   borderBottom
  80.  
  81.         ULONG   filePtr
  82.         ULONG   fileHandle
  83.         UWORD   fileNameLen
  84.         UWORD   fileNumLines
  85.         ULONG   fileSize
  86.         UWORD   numLength
  87.  
  88.         APTR    linePtr
  89.         ULONG   linePtrSize
  90.  
  91.         ULONG   msgClass
  92.         UWORD   msgCode
  93.         UWORD   msgQual
  94.  
  95.         UBYTE   flags
  96.  
  97.         STRUCT  fileName,fileNameSize
  98.         STRUCT  lineBuffer,lineBfrSize
  99.         STRUCT  searchBuffer,searchSize
  100.         STRUCT  titleBuffer,titleSize
  101.  
  102.         LABEL   work_SIZEOF
  103.  
  104.  
  105.  
  106.         xref    _AbsExecBase
  107.  
  108. CALLSYS MACRO
  109.         xref    _LVO\1
  110.         CALLLIB _LVO\1
  111.         ENDM
  112.  
  113. LINKSYS MACRO
  114.         xref    _LVO\1
  115.         LINKLIB _LVO\1,\2
  116.         ENDM
  117.  
  118.  
  119. start:
  120.         move.l  _AbsExecBase,a6             ; get ExecBase ptr
  121.         move.l  #workarea,a5
  122.  
  123.         IFD     MANX
  124.         move.l  a5,a1
  125.         move.l  #(work_SIZEOF-1)/4,d1       ; round to the number of longs - 1 !!
  126. Clear_Mem:
  127.         clr.l   (a1)+                       ; manx doesn't set the length
  128.         dbf     d1,Clear_Mem                ; of the BSS hunk, so the loader
  129.         ENDC                                ; doesn't clear it !!!
  130.  
  131.         movem.l d0/a0,parms(a5)             ; save parm len/address
  132.  
  133.         lea     dosName(pc),a1              ; open "dos.library"
  134.         moveq   #LIBRARY_VERSION,d0
  135.         CALLSYS OpenLibrary
  136.         move.l  d0,dosBase(a5)
  137.         beq     ErrFatal
  138.  
  139.         lea     intuitionName(pc),a1        ; open "intuition.library"
  140.         moveq   #LIBRARY_VERSION,d0
  141.         CALLSYS OpenLibrary
  142.         move.l  d0,intuitionBase(a5)
  143.         beq     ErrFatal
  144.  
  145.         lea     graphicsName(pc),a1         ; open "graphics.library"
  146.         moveq   #LIBRARY_VERSION,d0
  147.         CALLSYS OpenLibrary
  148.         move.l  d0,gfxBase(a5)
  149.         beq     ErrFatal
  150.  
  151.         movem.l parms(a5),d0/a0             ; get parm len/address
  152.         lea     fileName(a5),a1
  153.         moveq   #0,d0                       ; length of filename
  154.         moveq   #0,d1                       ; quote flag
  155.         cmpi.b  #' ',(a0)                   ; make it work with MetaScope
  156.         bne     MoveFileName
  157.         addq.l  #1,a0
  158. MoveFileName:
  159.         cmpi.b  #10,(a0)
  160.         beq     DoneFileName
  161.         cmpi.b  #'"',(a0)
  162.         beq     MoveQuoteChar
  163.         btst    #0,d1                       ; quoted argument ?
  164.         bne     MoveQuotedArg               ; yes - don't check for spaces
  165.         cmpi.b  #' ',(a0)
  166.         beq     DoneFileName
  167. MoveQuotedArg:
  168.         move.b  (a0)+,(a1)+
  169.         addq.w  #1,d0
  170.         bra     MoveFileName
  171. MoveQuoteChar:
  172.         addq.l  #1,a0
  173.         bchg    #0,d1
  174.         beq     MoveFileName
  175. DoneFileName:
  176.         btst    #0,d1
  177.         bne     ErrUsage                    ; hanging quote ?
  178.         clr.b   (a1)
  179.         move.w  d0,fileNameLen(a5)
  180.  
  181.         lea     fileName(a5),a1
  182.         tst.b   (a1)
  183.         beq     ErrUsage
  184.         cmpi.b  #'?',(a1)
  185.         beq     ErrUsage
  186.  
  187.         move.l  a1,d1
  188.         move.l  #MODE_OLDFILE,d2
  189.         LINKSYS Open,dosBase(a5)
  190.         move.l  d0,fileHandle(a5)
  191.         beq     ErrNotFound
  192.  
  193.         move.l  fileHandle(a5),d1
  194.         moveq   #0,d2
  195.         moveq   #OFFSET_END,d3
  196.         LINKSYS Seek,dosBase(a5)
  197.  
  198.         move.l  fileHandle(a5),d1
  199.         moveq   #0,d2
  200.         moveq   #OFFSET_BEGINNING,d3
  201.         LINKSYS Seek,dosBase(a5)
  202.         move.l  d0,fileSize(a5)
  203.  
  204. ;       fileSize is still in d0!!
  205.         move.l  #MEMF_PUBLIC,d1
  206.         CALLSYS AllocMem
  207.         move.l  d0,filePtr(a5)
  208.         beq     ErrFatal
  209.  
  210.         move.l  fileHandle(a5),d1
  211.         move.l  filePtr(a5),d2
  212.         move.l  fileSize(a5),d3
  213.         LINKSYS Read,dosBase(a5)
  214.         cmp.l   fileSize(a5),d0
  215.         bne     ErrFatal
  216.  
  217. ;       fileSize is still in d0!!
  218.         move.l  filePtr(a5),a0
  219.         moveq   #0,d1
  220. GetNumLines:
  221.         cmpi.b  #10,(a0)+
  222.         bne     GetNumNotLF
  223.         addq.w  #1,d1
  224. GetNumNotLF:
  225.         subq.l  #1,d0
  226.         bne     GetNumLines
  227.         move.w  d1,fileNumLines(a5)
  228.         move.w  d1,d0
  229.         bsr     ILen
  230.         move.w  d0,numLength(a5)
  231.  
  232.         move.l  d1,d0
  233.         addq.l  #1,d0
  234.         lsl.l   #2,d0
  235.         move.l  d0,linePtrSize(a5)
  236.         move.l  #MEMF_PUBLIC,d1
  237.         CALLSYS AllocMem
  238.         move.l  d0,linePtr(a5)
  239.         beq     ErrFatal
  240.  
  241.         move.l  d0,a1
  242.         move.l  filePtr(a5),a0
  243.         move.l  fileSize(a5),d0
  244.         move.l  a0,(a1)+
  245. FindNewLine:
  246.         cmpi.b  #10,(a0)+
  247.         bne     FindNotLF
  248.         move.l  a0,(a1)+
  249. FindNotLF:
  250.         subq.l  #1,d0
  251.         bne     FindNewLine
  252.  
  253.         move.l  intuitionBase(a5),a1
  254.         move.l  ib_ActiveScreen(a1),a1
  255.         lea     newWindowStruct(a5),a0
  256.  
  257.         move.w  sc_Width(a1),nw_Width(a0)
  258.         move.w  sc_Height(a1),nw_Height(a0)
  259.         move.b  #1,nw_BlockPen(a0)
  260.         move.l  #IDCMP_FLAGS,nw_IDCMPFlags(a0)
  261.         move.l  #WINDOW_FLAGS,nw_Flags(a0)
  262.         move.w  #100,nw_MinWidth(a0)
  263.         move.w  #30,nw_MinHeight(a0)
  264.         move.w  #-1,nw_MaxWidth(a0)
  265.         move.w  #-1,nw_MaxHeight(a0)
  266.         move.w  #WBENCHSCREEN,nw_Type(a0)
  267.  
  268.         LINKSYS OpenWindow,intuitionBase(a5)
  269.         move.l  d0,windowPtr(a5)
  270.         beq     ErrFatal
  271.  
  272.         move.l  d0,a0
  273.         moveq   #0,d0
  274.         move.b  wd_BorderLeft(a0),d0
  275.         move.l  d0,borderLeft(a5)
  276.         move.b  wd_BorderRight(a0),d0
  277.         move.l  d0,borderRight(a5)
  278.         move.b  wd_BorderTop(a0),d0
  279.         move.l  d0,borderTop(a5)
  280.         move.b  wd_BorderBottom(a0),d0
  281.         move.l  d0,borderBottom(a5)
  282.  
  283.         move.l  wd_RPort(a0),rastPort(a5)
  284.  
  285.         bset    #UPDATE_TITLE,flags(a5)
  286.         bsr     UpdateTitle
  287.         bsr     UpdateScreen
  288.  
  289.  
  290. GetNextEvent:
  291.         bclr    #UPDATE_SCREEN,flags(a5)
  292.         beq     ScreenOK
  293.         bsr     UpdateScreen
  294. ScreenOK:
  295.  
  296.         move.l  windowPtr(a5),a0
  297.         move.l  wd_UserPort(a0),a0
  298.         CALLSYS WaitPort
  299.  
  300.         move.l  d0,a1
  301.         CALLSYS Remove
  302.  
  303.         move.l  d0,a1
  304.         move.l  im_Class(a1),msgClass(a5)
  305.         move.w  im_Code(a1),msgCode(a5)
  306.         move.w  im_Qualifier(a1),msgQual(a5)
  307.         CALLSYS ReplyMsg
  308.  
  309.         move.l  msgClass(a5),d0
  310.  
  311.         cmpi.l  #CLOSEWINDOW,d0
  312.         beq     Terminate
  313.  
  314.         cmpi.l  #NEWSIZE,d0
  315.         bne     NotNewSize
  316.         bset    #UPDATE_SCREEN,flags(a5)
  317.         bra     GetNextEvent
  318. NotNewSize:
  319.  
  320.         cmpi.l  #RAWKEY,d0
  321.         bne     GetNextEvent
  322.  
  323.         move.w  msgCode(a5),d0
  324.  
  325.         cmpi.w  #CURSORUP,d0
  326.         bne     NotCursorUp
  327.         bsr     ScrollUp
  328.         bra     GetNextEvent
  329. NotCursorUp:
  330.  
  331.         cmpi.w  #CURSORDOWN,d0
  332.         bne     NotCursorDown
  333.         bsr     ScrollDown
  334.         bra     GetNextEvent
  335. NotCursorDown:
  336.  
  337.         cmpi.w  #CURSORLEFT,d0
  338.         bne     NotCursorLeft
  339.         bsr     ScrollLeft
  340.         bra     GetNextEvent
  341. NotCursorLeft:
  342.  
  343.         cmpi.w  #CURSORRIGHT,d0
  344.         bne     NotCursorRight
  345.         bsr     ScrollRight
  346.         bra     GetNextEvent
  347. NotCursorRight:
  348.  
  349.         cmpi.w  #RAW_SEARCH,d0
  350.         bne     NotSearchKey
  351.         bsr     ForwardSearch
  352.         bra     GetNextEvent
  353. NotSearchKey:
  354.  
  355.         cmpi.w  #RAW_AGAIN,d0
  356.         bne     NotAgainKey
  357.         bsr     ForwardSearch
  358.         bra     GetNextEvent
  359. NotAgainKey:
  360.  
  361.         cmpi.w  #RAW_ESCAPE,d0
  362.         beq     Terminate
  363.         bra     GetNextEvent
  364.  
  365.  
  366. ERR_USAGE       dc.b    $9b,'0;33mQView 1.0',$9b,'0m  by Lyman Epp',10
  367.                 dc.b    'Usage: QView filename',10
  368. ERR_USAGE_SIZE  EQU     55
  369.  
  370. ERR_NOTFND      dc.b    'File not found',10
  371. ERR_NOTFND_SIZE EQU     15
  372.  
  373. ERR_FATAL       dc.b    'QView: Fatal error',10
  374. ERR_FATAL_SIZE  EQU     19
  375.  
  376.         CNOP    0,2
  377.  
  378. ErrUsage:
  379.         lea     ERR_USAGE(pc),a0
  380.         moveq   #ERR_USAGE_SIZE,d3
  381.         bra     ErrDisplay
  382.  
  383. ErrNotFound:
  384.         lea     ERR_NOTFND(pc),a0
  385.         moveq   #ERR_NOTFND_SIZE,d3
  386.         bra     ErrDisplay
  387.  
  388. ErrFatal:
  389.         lea     ERR_FATAL(pc),a0
  390.         moveq   #ERR_FATAL_SIZE,d3
  391.         bra     ErrDisplay
  392.  
  393. ErrDisplay:
  394.         move.l  a0,d2
  395.         LINKSYS Output,dosBase(a5)
  396.         move.l  d0,d1
  397.         LINKSYS Write,dosBase(a5)
  398.  
  399.  
  400. Terminate:
  401.         move.l  linePtr(a5),d0
  402.         beq     TermNoLineMem
  403.         move.l  d0,a1
  404.         move.l  linePtrSize(a5),d0
  405.         CALLSYS FreeMem
  406. TermNoLineMem:
  407.  
  408.         move.l  fileHandle(a5),d1
  409.         beq     TermNoFileHandle
  410.         LINKSYS Close,dosBase(a5)
  411. TermNoFileHandle:
  412.  
  413.         move.l  filePtr(a5),d0
  414.         beq     TermNoFileMem
  415.         move.l  d0,a1
  416.         move.l  fileSize(a5),d0
  417.         CALLSYS FreeMem
  418. TermNoFileMem:
  419.  
  420.         move.l  windowPtr(a5),d0
  421.         beq     TermNoWindow
  422.         move.l  d0,a0
  423.         LINKSYS CloseWindow,intuitionBase(a5)
  424. TermNoWindow:
  425.  
  426.         move.l  gfxBase(a5),d0
  427.         beq     TermNogfxBase
  428.         move.l  d0,a1
  429.         CALLSYS CloseLibrary
  430. TermNogfxBase:
  431.  
  432.         move.l  intuitionBase(a5),d0
  433.         beq     TermNoIntBase
  434.         move.l  d0,a1
  435.         CALLSYS CloseLibrary
  436. TermNoIntBase:
  437.  
  438.         moveq   #0,d1
  439.         LINKSYS Exit,dosBase(a5)
  440.  
  441.  
  442.  
  443.  
  444. ScrollUp:
  445.         tst.w   screenLineNum(a5)
  446.         beq     ScrollUpExit
  447.  
  448.         move.w  msgQual(a5),d0
  449.         andi.w  #IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT,d0
  450.         beq     ScrollUpNotShift
  451.         move.w  screenLineNum(a5),d0
  452.         sub.w   screenRows(a5),d0
  453.         bpl     ScrollUpNotFirst
  454.         moveq   #0,d0
  455. ScrollUpNotFirst:
  456.         move.w  d0,screenLineNum(a5)
  457.         bset    #UPDATE_SCREEN,flags(a5)
  458.         bra     ScrollUpExit
  459.  
  460. ScrollUpNotShift:
  461.         move.w  msgQual(a5),d0
  462.         andi.w  #IEQUALIFIER_LALT!IEQUALIFIER_RALT!IEQUALIFIER_CONTROL,d0
  463.         beq     ScrollUpNotAlt
  464.         clr.w   screenLineNum(a5)
  465.         bset    #UPDATE_SCREEN,flags(a5)
  466.         bra     ScrollUpExit
  467.  
  468. ScrollUpNotAlt:
  469.         subq.w  #1,screenLineNum(a5)
  470.         move.l  rastPort(a5),a1
  471.         moveq   #0,d0
  472.         moveq   #0,d1
  473.         sub.w   rp_TxHeight(a1),d1
  474.         move.l  borderLeft(a5),d2
  475.         move.l  borderTop(a5),d3
  476.         move.l  screenMaxX(a5),d4
  477.         move.l  screenMaxY(a5),d5
  478.         LINKSYS ScrollRaster,gfxBase(a5)
  479.  
  480.         moveq   #0,d0
  481.         bsr     OutputLine
  482.  
  483. ScrollUpExit:
  484.         bsr     UpdateTitle
  485.         rts
  486.  
  487.  
  488.  
  489. ScrollDown:
  490.         move.w  msgQual(a5),d0
  491.         andi.w  #IEQUALIFIER_LALT!IEQUALIFIER_RALT!IEQUALIFIER_CONTROL,d0
  492.         beq     ScrollDownNotAlt
  493.         move.w  fileNumLines(a5),d0
  494.         sub.w   screenRows(a5),d0
  495.         bmi     ScrollDownExit
  496.         cmp.w   screenLineNum(a5),d0
  497.         beq     ScrollDownExit
  498.         move.w  d0,screenLineNum(a5)
  499.         bset    #UPDATE_SCREEN,flags(a5)
  500.         bra     ScrollDownExit
  501.  
  502. ScrollDownNotAlt:
  503.         move.w  fileNumLines(a5),d0
  504.         sub.w   screenLineNum(a5),d0
  505.         sub.w   screenRows(a5),d0
  506.         ble     ScrollDownExit
  507.  
  508.         move.w  msgQual(a5),d0
  509.         andi.w  #IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT,d0
  510.         beq     ScrollDownNotShift
  511.         move.w  screenLineNum(a5),d0
  512.         add.w   screenRows(a5),d0
  513.         move.w  d0,screenLineNum(a5)
  514.         bset    #UPDATE_SCREEN,flags(a5)
  515.         bra     ScrollDownExit
  516.  
  517. ScrollDownNotShift:
  518.         addq.w  #1,screenLineNum(a5)
  519.         move.l  rastPort(a5),a1
  520.         moveq   #0,d0
  521.         move.w  rp_TxHeight(a1),d1
  522.         move.l  borderLeft(a5),d2
  523.         move.l  borderTop(a5),d3
  524.         move.l  screenMaxX(a5),d4
  525.         move.l  screenMaxY(a5),d5
  526.         LINKSYS ScrollRaster,gfxBase(a5)
  527.  
  528.         move.w  screenRows(a5),d0
  529.         subq.w  #1,d0
  530.         ext.w   d0
  531.         bsr     OutputLine
  532.  
  533. ScrollDownExit:
  534.         bsr     UpdateTitle
  535.         rts
  536.  
  537.  
  538.  
  539. ScrollLeft:
  540.         tst.w   screenLineOffset(a5)
  541.         beq     ScrollLeftExit
  542.  
  543.         bset    #UPDATE_TITLE,flags(a5)
  544.         bset    #UPDATE_SCREEN,flags(a5)
  545.         subi.w  #20,screenLineOffset(a5)
  546.  
  547.         move.w  msgQual(a5),d0
  548.         andi.w  #IEQUALIFIER_LALT!IEQUALIFIER_RALT!IEQUALIFIER_CONTROL,d0
  549.         beq     ScrollLeftExit
  550.         clr.w   screenLineOffset(a5)
  551.  
  552. ScrollLeftExit:
  553.         bsr     UpdateTitle
  554.         rts
  555.  
  556.  
  557.  
  558. ScrollRight:
  559.         addi.w  #20,screenLineOffset(a5)
  560.         bset    #UPDATE_TITLE,flags(a5)
  561.         bset    #UPDATE_SCREEN,flags(a5)
  562.         bsr     UpdateTitle
  563.  
  564. ScrollRightExit:
  565.         rts
  566.  
  567.  
  568.  
  569. ItoA:             ; (a0:buffer, d0:integer, d1:length)
  570.         subq.w  #1,d1
  571. ItoA_Blank:
  572.         move.b  #' ',(a0)+
  573.         dbf     d1,ItoA_Blank
  574.         move.l  a0,-(sp)
  575.  
  576.         ext.l   d0
  577. ItoA_Next:
  578.         divu    #10,d0
  579.         move.l  d0,d1
  580.         swap    d1
  581.         ori.b   #'0',d1
  582.         move.b  d1,-(a0)
  583.         ext.l   d0
  584.         bne     ItoA_Next
  585.  
  586.         move.l  (sp)+,a0
  587.         rts
  588.  
  589.  
  590.  
  591. ILen:             ; (d0:integer)
  592.         move.l  d1,-(sp)
  593.  
  594.         moveq   #0,d1
  595. ILen_Loop:
  596.         addq.w  #1,d1
  597.         ext.l   d0
  598.         divu    #10,d0
  599.         bne     ILen_Loop
  600.  
  601.         move.l  d1,d0
  602.         move.l  (sp)+,d1
  603.         rts
  604.  
  605.  
  606.  
  607. UpdateTitle:
  608.         lea     titleBuffer(a5),a0
  609.         move.w  screenLineNum(a5),d0
  610.         addq.w  #1,d0
  611.         move.w  numLength(a5),d1
  612.         bsr     ItoA
  613.  
  614.         move.b  #'/',(a0)+
  615.  
  616.         move.w  fileNumLines(a5),d0
  617.         move.w  numLength(a5),d1
  618.         bsr     ItoA
  619.  
  620.         tst.w   screenLineOffset(a5)
  621.         beq     TitleNoOffset
  622.         move.b  #'+',(a0)+
  623.         move.w  screenLineOffset(a5),d0
  624.         bsr     ILen
  625.         move.w  d0,d1
  626.         move.w  screenLineOffset(a5),d0
  627.         bsr     ItoA
  628. TitleNoOffset:
  629.  
  630.         move.b  #' ',(a0)+
  631.  
  632.         lea     fileName(a5),a1
  633.         move.w  fileNameLen(a5),d0
  634.         subq.w  #1,d0
  635. ShowFileName:
  636.         move.b  (a1)+,(a0)+
  637.         dbf     d0,ShowFileName
  638.  
  639.         move.b  #' ',(a0)+
  640.         clr.b   (a0)
  641.  
  642.         bclr    #UPDATE_TITLE,flags(a5)
  643.         beq     TitleOK
  644.         move.l  windowPtr(a5),a0
  645.         lea     titleBuffer(a5),a1
  646.         move.l  #-1,a2
  647.         LINKSYS SetWindowTitles,intuitionBase(a5)
  648. TitleOK:
  649.  
  650.         move.l  rastPort(a5),a0
  651.         lea     IText1(pc),a1
  652.         moveq   #0,d0
  653.         moveq   #0,d1
  654.         LINKSYS PrintIText,intuitionBase(a5)
  655.  
  656.         rts
  657.  
  658.  
  659.  
  660. UpdateScreen:
  661.         move.l  rastPort(a5),a1
  662.         moveq   #0,d0
  663.         LINKSYS SetAPen,gfxBase(a5)
  664.  
  665.         move.l  windowPtr(a5),a0
  666.         move.l  borderLeft(a5),d0
  667.         move.l  borderTop(a5),d1
  668.         move.w  wd_Width(a0),d2
  669.         ext.l   d2
  670.         sub.l   borderRight(a5),d2
  671.         move.w  wd_Height(a0),d3
  672.         ext.l   d3
  673.         sub.l   borderBottom(a5),d3
  674.         move.l  rastPort(a5),a1
  675.         LINKSYS RectFill,gfxBase(a5)
  676.  
  677.         move.l  rastPort(a5),a1
  678.         moveq   #1,d0
  679.         LINKSYS SetAPen,gfxBase(a5)
  680.  
  681.         move.l  windowPtr(a5),a0
  682.         move.l  rastPort(a5),a1
  683.         move.w  wd_Width(a0),d0
  684.         ext.l   d0
  685.         sub.l   borderLeft(a5),d0
  686.         sub.l   borderRight(a5),d0
  687.         divu    rp_TxWidth(a1),d0
  688.         move.w  d0,screenCols(a5)
  689.         mulu    rp_TxWidth(a1),d0
  690.         add.l   borderLeft(a5),d0
  691.         subq.l  #1,d0
  692.         move.l  d0,screenMaxX(a5)
  693.  
  694.         move.w  wd_Height(a0),d0
  695.         ext.l   d0
  696.         sub.l   borderTop(a5),d0
  697.         sub.l   borderBottom(a5),d0
  698.         divu    rp_TxHeight(a1),d0
  699.         move.w  d0,screenRows(a5)
  700.         mulu    rp_TxHeight(a1),d0
  701.         add.l   borderTop(a5),d0
  702.         subq.l  #1,d0
  703.         move.l  d0,screenMaxY(a5)
  704.  
  705.  
  706.         moveq   #0,d0
  707. UpdateLine:
  708.         bsr     OutputLine
  709.         addq.w  #1,d0
  710.         cmp.w   screenRows(a5),d0
  711.         bne     UpdateLine
  712.  
  713.         rts
  714.  
  715.  
  716.  
  717. OutputLine:
  718.         movem.l d0-d7/a0-a1,-(sp)
  719.         move.l  d0,d7
  720.         add.w   screenLineNum(a5),d0
  721.         cmp.w   fileNumLines(a5),d0
  722.         bpl     OutputLineExit
  723.         lsl.l   #2,d0
  724.         move.l  linePtr(a5),a0
  725.         move.l  0(a0,d0),a0
  726.  
  727.         lea     lineBuffer(a5),a1
  728.         moveq   #0,d0
  729. OutputLineNextChar:
  730.         move.b  (a0)+,d1
  731.         cmpi.b  #10,d1
  732.         beq     OutputLineEnd
  733.         cmpi.b  #13,d1
  734.         beq     OutputLineNextChar
  735.         cmpi.b  #9,d1
  736.         beq     OutputLineTab
  737.  
  738.         move.b  d1,(a1)+
  739.         addq.l  #1,d0
  740.         cmpi.w  #lineBfrSize,d0
  741.         bne     OutputLineNextChar
  742.         bra     OutputLineEnd
  743.  
  744. OutputLineTab:
  745.         move.l  d0,d2
  746.         move.w  lineTabSize(pc),d3
  747.         divu    d3,d2
  748.         lsr.l   #8,d2
  749.         lsr.l   #8,d2
  750.         sub.w   d2,d3
  751.         move.l  d0,d2
  752.         add.w   d3,d2
  753.         cmpi.w  #lineBfrSize,d2
  754.         bpl     OutputLineEnd
  755.         add.w   d3,d0
  756.         subq.w  #1,d3
  757. OutputLineMoveTab:
  758.         move.b  #' ',(a1)+
  759.         dbf     d3,OutputLineMoveTab
  760.         bra     OutputLineNextChar
  761.  
  762. OutputLineEnd:
  763.         move.w  d0,d6
  764.         move.l  d7,d1
  765.         move.l  rastPort(a5),a1
  766.         mulu    rp_TxHeight(a1),d1
  767.         add.l   borderTop(a5),d1
  768.         add.w   rp_TxBaseline(a1),d1
  769.         move.l  borderLeft(a5),d0
  770.         LINKSYS Move,gfxBase(a5)
  771.  
  772.         move.w  d6,d0
  773.         sub.w   screenLineOffset(a5),d0
  774.         bmi     OutputLineExit
  775.         cmp.w   screenCols(a5),d0
  776.         ble     OutputLineLenOk
  777.         move.w  screenCols(a5),d0
  778. OutputLineLenOk:
  779.  
  780.         lea     lineBuffer(a5),a0
  781.         add.w   screenLineOffset(a5),a0
  782.         move.l  rastPort(a5),a1
  783.         LINKSYS Text,gfxBase(a5)
  784.  
  785. OutputLineExit:
  786.         movem.l (sp)+,d0-d7/a0-a1
  787.         rts
  788.  
  789.  
  790.  
  791. ForwardSearch:
  792.         move.w  fileNumLines(a5),d0
  793.         sub.w   screenLineNum(a5),d0
  794.         ble     Search_Exit
  795.  
  796.         cmpi.w  #RAW_AGAIN,msgCode(a5)
  797.         beq     Search_Again
  798.  
  799.         bset    #UPDATE_SCREEN,flags(a5)
  800.  
  801.         bsr     GetString
  802.         tst.l   d0                       ; did an error occur?
  803.         bne     Search_Exit              ; yes, just leave
  804.  
  805. Search_Again:
  806.         lea     GadgetInfo(pc),a0
  807.         move.w  si_NumChars(a0),d2       ; length of search string
  808.         beq     Search_Exit
  809.  
  810.         move.w  screenLineNum(a5),d3
  811.         addq.w  #1,d3
  812.         cmp.w   fileNumLines(a5),d3
  813.         bge     Search_NotFound
  814.  
  815.         ext.l   d3
  816.         lsl.l   #2,d3
  817.         move.l  linePtr(a5),a0
  818.         move.l  0(a0,d3.l),a0
  819.         lsr.l   #2,d3
  820.  
  821.         ext.l   d2
  822.         move.l  filePtr(a5),a2
  823.         add.l   fileSize(a5),a2
  824.         sub.l   d2,a2                    ; last address to search
  825.         lea     searchBuffer(a5),a1      ; address of buffer
  826.  
  827.         moveq   #0,d2
  828.  
  829. Search_Loop:
  830.         cmp.l   a2,a0
  831.         bgt     Search_NotFound
  832.         move.b  0(a1,d2.w),d1
  833.         beq     Search_Found
  834.         cmpi.b  #'A',d1
  835.         blt     Search_Case1OK
  836.         cmpi.b  #'Z',d1
  837.         bgt     Search_Case1OK
  838.         ori.b   #$20,d1
  839. Search_Case1OK:
  840.         move.b  0(a0,d2.w),d0
  841.         cmpi.b  #'A',d0
  842.         blt     Search_Case2OK
  843.         cmpi.b  #'Z',d0
  844.         bgt     Search_Case2OK
  845.         ori.b   #$20,d0
  846. Search_Case2OK:
  847.         addq.w  #1,d2
  848.         cmp.b   d1,d0
  849.         beq     Search_Loop
  850.  
  851.         moveq   #0,d2
  852.         cmpi.b  #10,(a0)+
  853.         bne     Search_Loop
  854.         addq.w  #1,d3
  855.         bra     Search_Loop
  856.  
  857. Search_NotFound:
  858.         move.l  windowPtr(a5),a0
  859.         lea     NOT_FOUND(pc),a1
  860.         move.l  #-1,a2
  861.         LINKSYS SetWindowTitles,intuitionBase(a5)
  862.         bset    #UPDATE_TITLE,flags(a5)
  863.         bra     Search_Exit
  864.  
  865. Search_Found:
  866.         move.w  d3,screenLineNum(a5)
  867.         bset    #UPDATE_SCREEN,flags(a5)
  868.         bsr     UpdateTitle
  869.  
  870. Search_Exit:
  871.         rts
  872.  
  873.  
  874.  
  875. GetString:
  876.         movem.l d2/a1-a3,-(sp)
  877.  
  878.         clr.b   searchBuffer(a5)
  879.         move.l  windowPtr(a5),a3
  880.  
  881.         move.w  wd_Width(a3),d0
  882.         subi.w  #22,d0
  883.         move.w  d0,BorderVectors+4
  884.  
  885.         move.l  a3,a0
  886.         lea     StringGadget(pc),a1
  887.         moveq   #-1,d0
  888.         LINKSYS AddGadget,intuitionBase(a5)
  889.  
  890.         lea     StringGadget(pc),a0
  891.         move.l  a3,a1
  892.         sub.l   a2,a2
  893.         LINKSYS RefreshGadgets,intuitionBase(a5)
  894.  
  895.         lea     StringGadget(pc),a0
  896.         move.l  a3,a1
  897.         LINKSYS ActivateGadget,intuitionBase(a5)
  898.  
  899. GetStringWait:
  900.         move.l  wd_UserPort(a3),a0
  901.         CALLSYS WaitPort
  902.  
  903.         move.l  d0,a1
  904.         CALLSYS Remove
  905.  
  906.         move.l  d0,a1
  907.         move.l  im_Class(a1),d2
  908.         CALLSYS ReplyMsg
  909.  
  910.         cmpi.l  #NEWSIZE,d2
  911.         beq     GetString_Exit
  912.  
  913.         cmpi.l  #GADGETUP,d2
  914.         bne     GetStringWait
  915.         moveq   #0,d2
  916.  
  917. GetString_Exit:
  918.         move.l  a3,a0
  919.         lea     StringGadget(pc),a1
  920.         LINKSYS RemoveGadget,intuitionBase(a5)
  921.  
  922.         move.l  d2,d0
  923.         movem.l (sp)+,d2/a1-a3
  924.         rts
  925.  
  926.  
  927.  
  928.  
  929. dosName         dc.b    'dos.library',0
  930. intuitionName   dc.b    'intuition.library',0
  931. graphicsName    dc.b    'graphics.library',0
  932.  
  933.  
  934. lineTabSize     dc.w    8
  935.  
  936.  
  937. NOT_FOUND:
  938.         dc.b    'No match found',0
  939.         CNOP    0,2
  940.  
  941.  
  942.  
  943. StringGadget:
  944.         dc.l        NULL            ;next gadget
  945.         dc.w        4,-9            ;origin XY of hit box relative to window TopLeft
  946.         dc.w        -22,8           ;hit box width and height
  947.         dc.w        GRELBOTTOM!GRELWIDTH   ;gadget flags
  948.         dc.w        RELVERIFY       ;activation flags
  949.         dc.w        STRGADGET       ;gadget type flags
  950.         dc.l        GadgetBorder    ;gadget border or image to be rendered
  951.         dc.l        NULL            ;alternate imagery for selection
  952.         dc.l        NULL            ;first IntuiText structure
  953.         dc.l        NULL            ;gadget mutual-exclude long word
  954.         dc.l        GadgetInfo      ;SpecialInfo structure
  955.         dc.w        NULL            ;user-definable data
  956.         dc.l        NULL            ;pointer to user-definable data
  957. GadgetInfo:
  958.         dc.l        workarea+searchBuffer  ;buffer where text will be edited
  959.         dc.l        NULL            ;optional undo buffer
  960.         dc.w        0               ;character position in buffer
  961.         dc.w        searchSize      ;maximum number of characters to allow
  962.         dc.w        0               ;first displayed character buffer position
  963.         dc.w        0,0,0,0,0       ;Intuition initialized and maintained variables
  964.         dc.l        0               ;Rastport of gadget
  965.         dc.l        0               ;initial value for integer gadgets
  966.         dc.l        NULL            ;alternate keymap (fill in if you set the flag)
  967. GadgetBorder:
  968.         dc.w        -1,-1           ;XY origin relative to container TopLeft
  969.         dc.b        3,0,RP_JAM1     ;front pen, back pen and drawmode
  970.         dc.b        2               ;number of XY vectors
  971.         dc.l        BorderVectors   ;pointer to XY vectors
  972.         dc.l        NULL            ;next border in list
  973. BorderVectors:
  974.         dc.w        0,0
  975.         dc.w        -1,0            ; GetString will modify this!
  976.  
  977.  
  978. IText1:
  979.         dc.b        0,1,RP_JAM2,0   ;front and back text pens, drawmode and fill byte
  980.         dc.w        30,1            ;XY origin relative to container TopLeft
  981.         dc.l        NULL            ;font pointer or NULL for default
  982.         dc.l        workarea+titleBuffer  ;pointer to title text
  983.         dc.l        NULL            ;next IntuiText structure
  984.  
  985.  
  986.  
  987.  
  988.         IFD     MANX
  989.  
  990.         BSS     workarea,work_SIZEOF
  991.  
  992.         ENDC
  993.  
  994.         IFND    MANX
  995.  
  996.         SECTION uninit,BSS
  997.  
  998. workarea:
  999.         ds.b    work_SIZEOF
  1000.  
  1001.         ENDC
  1002.  
  1003.  
  1004.         END
  1005.  
  1006.