home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / utilities / viewer / source / viewerv4.4-le-ß.asm < prev   
Encoding:
Assembly Source File  |  1999-11-19  |  251.8 KB  |  10,722 lines

  1. ****************************************************************************
  2. *
  3. * RAM-based Console-Device text- and binary file viewer.
  4. * RAM-based virtual screen picture/image viewer.
  5. *
  6. ** THIS IS THE SPEICIAL VERSION, 4.4-LE - REAL "LINE EDIT" IMPLEMENTED!!!!!
  7. *
  8. *
  9. * Copyright 1992 - 1999 Jörg van de Loo
  10. *            Hövel 15
  11. *            47559 Kranenburg
  12. *            Germany
  13. *
  14. * No e-mail address ( - released to the public!).
  15. *
  16. * -13.06.1992, 22:58:59- V1.0 - Text viewer (PowerPacker (© Nico François) support)
  17. * -14.06.1992  23:55:43- V2.0 - Text and picture viewer (thanks to Holger Gzella for picture decoding)
  18. * -24.09.1992, 14:47:32- V3.0 - Text, picture and binary files viewer
  19. *  ...
  20. * -04.04.1993, 23:07:01- V3.6 - Rewritten for OS 3 (mainly, console handling...)
  21. * -18.06.1994, 21:05:22- V3.7 - Up from this version 100% OS 3 compatible, also brush support
  22. *                (complete re-work of picture decoding)
  23. * -24.06.1994, 15:33:28- V3.8
  24. * -26.06.1994, 01:54:47- V3.9
  25. * -28.06.1994, 14:42:19- V3.A
  26. * -30.06.1994, 00:23:00- V3.B  - Bug fixed version
  27. * -08.01.1995, 22:04:00- V3.BA - better Monitor handling plus ACBM files viewer -
  28. *                 pure sentimental - want to see old Amiga Basic used
  29. *                 pictures.
  30. *                 Now Viewer supports also a masking plane ....
  31. * -15.05.1996, 12:45:47- V3.C1 - FinalCopy-II and IFF-Text ASCII extracting support
  32. * -25.05.1996, 16:03:25- V3.D3 - Pweeh, string search routine implemented....
  33. *                 I crashed my system totally with lost of the source
  34. *                 because I forgot to give DisplayBeep() a parameter (NULL).
  35. *                 With MasterSekaV1.71 I recovered the lost source.
  36. * -23.08.1997, 21:22:54- V3.D38 - Viewer can now display 8bit images 100% correctly on a CyberGrafX (41.2+) screen
  37. * -28.12.1997, 23:03:31- V3.D39 - After heavy request AutoRequester now supports keys (AMIGA-V, AMIGA-B)
  38. * -19.02.1998, 09:53:16- V3.D3A - Viewer is now compatible (97%) to the Picasso96 software package
  39. *                  and to other alien gfx-board software packages (I hope so).
  40. * -18.10.1998, 21:44:21- V3.D3B - Viewer is now able to display 24 bit images on my gfx-card (CyberVision3D)
  41. * -09.04.1999, 22:26:29- V3.E00 - Conversion from HAM8 to 24 bit added (Picasso96 now 100% compatible to Viewer!!!)
  42. * -23.04.1999, 20:04:31- V3.ED0 - HAM6 to 24 bit tune-up implemented (removed code for HAM6 to 16 bit - too less brillance)
  43. * -01.05.1999, 23:31:48- V3.EDE - Removed bug that caused machine to crash upon displaying non-super bitmap images
  44. *                  on native AMIGAs and which was introduced with the code to display HAM8 images on
  45. *                  a 24 bit screen (set two `bne´ to wrong labels where one lead to an invalid stack)
  46. * -12.08.1999, 19:47:20- V4.0 - Added function to play either compressed or uncompressed 8SVX mono sound files from
  47. *                fast memory.
  48. * -19.11.1999, 15:32:17- V4.4 - Added support for 9 to 16 bitplane images (versions 4.1 - 4.3 extremly faulty)
  49. *
  50. *
  51. *
  52. *
  53. * Simple Text-, Binary- and Image-file viewer for the Amiga Operation System.
  54. *
  55. * This material is released "as it", no warranties are made!
  56. *
  57. * The program-code is position independent and resident capable.
  58. * It  requires  kickstart  1.2  or  higher and an Amiga Custom-Chip-Set (due
  59. * some  code  which  can be easily rewritten for non based Amiga Custom Chip
  60. * Set computers). AA- (AGA) resolution support added for pic-viewer of V3.7.
  61. *
  62. * Tested  successfully  under  SegTracker,  Enforcer, Mungwall, IOTorture in 
  63. * many circumstances.
  64. *
  65. * The  executeable  based  on this source may freely distributed so long the
  66. * copyright notice is unmodified - known as FreeWare.
  67. *
  68. * The  source-code  may improved by anyone who wants to do it - in this case
  69. * please read the "PRG-ShouldRead" file first - for the agreements.
  70. *
  71. * This  source-code  may  enclosed  to  _ANY_  assembler  package  (also  in
  72. * modified  form)  for  an example "how to code in 680x0 assembler", but the
  73. * copyright notice must be at least unaltered.
  74. *
  75. *
  76. * Noone can say: Copyright "Whose name" - I'm (J.v.d.Loo) the copyright holder!
  77. *
  78. *
  79. * This  program  was  written  using  HiSoft's  Devpac  Amiga  3 assembler -
  80. * without its special advantages.
  81. *
  82. *
  83. * If  anyone  takes  money  for  this  source-code,  object-file or enclosed |
  84. * documentation  and  someone  tells me - the fellow who took the money will |
  85. * meet  me  - more than 6 foots tall, more than 200 pounds - and what's very |
  86. * dangerous  -  carrier of the stinking sock - but my Master told me to take |
  87. * off  my  shoes only in an emergency - the smell is not the worst - he said |
  88. * - but the burning eyes...                             |
  89. *
  90. *
  91. * NOTES:
  92. * This source file can be assembled unmodified at least with:
  93. *    HiSoft's Devpac Amiga Assembler 3   (commercial) [fast assembler]
  94. *    Samu Noujua's SNMA Assembler 1.99   (freeware)   [fast assembler]
  95. *    Frank Wille's PhxAss Assembler 4.18 (shareware)  [medium assembler/ fast linker]
  96. *
  97. * For  the  Macro-System's Draco computer you have to remove all lines which
  98. * are accessing the hardware directly.
  99. *
  100. * List of what to do...
  101. *     Printer  status should be tested via parallel/and or serial devices,
  102. *     using QUERY-command.
  103. *    Picture  display  routine must first open the screen, then a window.
  104. *    'Blit' the image to the window rastport instead of screen's bitmap.
  105. *    May  replace code for scrolling SuperBitMaps through 'Blits' because
  106. *    the  most 3rd graphic board software doesn't support changes of View
  107. *    dx/dy,  or  they  don't  support  custom  bitmaps and then the image
  108. *    screen's bitmap is only as tall as the standard monitor resolution.
  109. *    Status  of  left-  and  right mousebuttons can be easily checked via
  110. *    IDCMPs of the (added) image window.
  111. *    The other code is system-conform (I hope...).
  112.  
  113.  
  114.     IFD    __G2
  115.  
  116.     OUTPUT    RAM:Viewer        ; Child's name when using Devpac
  117.  
  118.     MACHINE    MC68000            ; Processor selection
  119.  
  120.     ENDC
  121.  
  122. *    OPT    D+
  123.  
  124.     include    exec/types.i
  125.     include    exec/memory.i
  126.     include    exec/ports.i
  127.     include    exec/lists.i
  128.     include    exec/devices.i
  129.     include    exec/execbase.i
  130.  
  131.     include    graphics/gfx.i
  132.     include    graphics/text.i
  133.     include    graphics/rastport.i
  134.     include    graphics/gfxbase.i
  135.     include    graphics/graphics_lib.i
  136.  
  137.     include    intuition/intuition.i
  138.     include    intuition/screens.i
  139.     include    intuition/intuitionbase.i
  140.     include    intuition/intuition_lib.i
  141.  
  142.     include    dos/dos.i
  143.  
  144.     include    devices/audio.i
  145.  
  146.  
  147. ***********************************
  148. *
  149. * Define needed constants and arrays
  150. *
  151.     STRUCTURE    _Table,68        ; Begin at offset 68 (end of table used by startup-code)
  152.  
  153.     ULONG    _dummy000        ; Only to make "FIB" staying on a through eight
  154. *                      divisible address - you may use "ALIGNLONG"
  155. *                      MACRO instead...
  156.  
  157.     STRUCT    _FIB,272        ; FileInfoBlock
  158.  
  159.     STRUCT    _NewScreen,ens_SIZEOF    ; Screen's structure
  160.     STRUCT    _StdTags,56        ; Screen's taglist (up from OS 2.0)
  161.  
  162.     STRUCT    _WindowRecord,nw_SIZEOF    ; Window's structure
  163.     STRUCT    _ErrWindowStruc,nw_SIZEOF ; Ditto
  164.  
  165.     STRUCT    _Gad1,gg_SIZEOF
  166.     STRUCT    _Gad2,gg_SIZEOF
  167.     STRUCT    _GTxt1,it_SIZEOF
  168.     STRUCT    _GTxt2,it_SIZEOF
  169.  
  170.     STRUCT    _Gad3,gg_SIZEOF        ; Audio Hit Gadget, no text
  171.  
  172.     STRUCT    _ArpReqStruc,32        ; Only 26 bytes are needed
  173.     STRUCT    _UserFontStruc,8    ; Font-record
  174.  
  175.     ALIGNLONG
  176.  
  177.     ULONG    _RealIWidth        ; No boundary
  178.     ULONG    _ImageWidth        ; 16 bit boundary
  179.  
  180. * BMHD-settings follow..... - used for picture
  181.     UWORD    _Width            ; May be taller than displayable... (64 bit boundary)
  182.     UWORD    _Height            ; ditto
  183.     UWORD    _XPos
  184.     UWORD    _YPos
  185.     UBYTE    _Depth
  186.     UBYTE    _Masking
  187.     UBYTE    _Compresstyp
  188.     UBYTE    _BMHDFlags        ; Was before ks 3.0 unused (bmhd_pad)
  189.     UWORD    _TransColour
  190.     UBYTE    _XAspect
  191.     UBYTE    _YAspect
  192.     UWORD    _PlaneWidth        ; Visible size
  193.     UWORD    _PlaneHeight        ; ditto
  194.     UWORD    _Dummy            ; Strictly for longword adjustment
  195.     ULONG    _ViewPortMod
  196.     STRUCT    _Colourmap,1024        ; Max. room for 256 colours
  197.  
  198.     ULONG    _TypeOfMem        ; Which memory type used for bitmap allocation? (~0 = CHIP, 0 = ANY)
  199.     LONG    _ViewPortShare        ; Can we change through RasInfo the visible part of an image ( 0=yes,1=yes,-1=no)
  200.     ULONG    _HAMSet            ; Depth of image in case image is HAM encoded
  201.  
  202.     UWORD    _OldY            ; Used only for ks lower than v36
  203.     UWORD    _OldX            ; Used only for ks lower than v36
  204.  
  205.     UWORD    _BgPen            ; Colour-index for background of window's title
  206.  
  207.     STRUCT    _DisplayInfo,dis_SIZEOF    ; Buffer for DisplayInfoData
  208.  
  209.     ALIGNLONG            ; <- EXEC/EXEC_TYPES.I
  210.  
  211.     APTR    _GfxBase
  212.     APTR    _IntuitionBase
  213.     APTR    _ReqToolsBase
  214.     APTR    _ArpBase
  215.     APTR    _CyberGfxBase
  216.     APTR    _ScreenPtr
  217.  
  218.     APTR    _ReqPtr            ; ReqTools requester record
  219.  
  220.     ULONG    _argError        ; Not zero upon argument error
  221.     ULONG    _LinesInFile        ; Number of lines in file
  222.     ULONG    _UPFSize        ; Uncompressed file size
  223.     ULONG    _IncSize        ; Increased uncompressed file size
  224.     ULONG    _Line            ; Current line where cursor stays
  225.     ULONG    _PageWidth
  226.     UWORD    _StdPageSize        ; Std. scrollwidth for console in lines
  227.  
  228.     ALIGNLONG
  229.  
  230.     APTR    _ErrWindowPtr        ; Intuition window record
  231.     APTR    _DecrunchAddr        ; Address decrunched file
  232.     APTR    _StdprWindowPtr        ; Old pointer for system requesters
  233.     APTR    _PtrToWTitle        ; Pointer to window's title text
  234.     APTR    _UserProject        ; Info-file (for icon.library)
  235.     APTR    _WindowPtr        ; Intuition window record
  236.     APTR    _IAddr            ; Window's object that raised message
  237.  
  238.     STRUCT    _WindowTitle,148    ; Room for window's title (title is
  239. *                      changed each time a new file is loaded)
  240.  
  241.     LABEL    _WriteIo        ; Startaddress for console-write message
  242.     STRUCT    _Msg,20            ; Message length, 20 byte
  243.     STRUCT    _Io,12            ; Console-write IO, 12 bytes
  244.     STRUCT    _WriteReq,16        ; Console-write request, 16 bytes
  245.     STRUCT    _WriteReply,34        ; ReplyPort for Console-write
  246.  
  247.     STRUCT    _ReadIo,48        ; Console-read message including IO and REQ
  248.     STRUCT    _ReadReply,34        ; Console-read reply port
  249.  
  250.     ALIGNLONG
  251.  
  252.     APTR    _TextPtr        ; Address file in memory
  253.     APTR    _BufferSize        ; Allocated size
  254.     LONG    _FileSize        ; File's real size
  255.  
  256.     BPTR    _LockSave        ; Key to file (closed)
  257.     BPTR    _FileHandle        ; Handle (closed)
  258.  
  259.     APTR    _UserFontPtr        ; Font record (perhaps opened)
  260.     APTR    _OldFontPtr        ; System's default font
  261.  
  262.     APTR    _SearchStrPtr        ; Pointer to search address (from where to continue)
  263.     ULONG    _SearchStrLen        ; Length of search string
  264.     ULONG    _CharBuffer        ; Read char of IO-request to build complete search string
  265.     STRUCT    _IOReqString,256    ; Buffer which contains search string
  266.  
  267.     STRUCT    _IOInlineBuf,64        ; Buffer for converting IO-status report to ascii
  268.  
  269.  
  270.     APTR    arg_1            ; Shell arguments....
  271.     APTR    arg_2
  272.     APTR    arg_3
  273.  
  274.     STRUCT    WB_arg_1,60        ; WBench arguments (tooltypes) (max.: 14!!!)
  275.  
  276.     BPTR    lock_1            ; Overgiven files (Workbench, -the trick
  277.     APTR    file_1            ;  with the shift...)
  278. *    BPTR    lock_2
  279. *    APTR    file_2
  280. *    BPTR    lock_3
  281. *    APTR    file_3
  282.  
  283.  
  284.     STRUCT    _Drive,256        ; Buffer for volume's/directory's name
  285.     STRUCT    _File,108        ; The filename itself
  286.     STRUCT    _FileName,364        ; Merged name in dos-convention
  287.  
  288.     STRUCT    _UserFontBuf,108    ; Into this buffer the name of the font
  289. *                      the user want to use is copied from the
  290. *                      tooltypes - so that we can modify it
  291.  
  292.     STRUCT    _ConBuffer,256        ; Buffer for console commands
  293.  
  294.     APTR    _SourceFileSize        ; Same as FileSize (used by picture)
  295.     APTR    _SourceFilePtr        ; Same as TextPtr + 2 (used by picture)
  296.  
  297.     APTR    _RGB24Ptr
  298.     ULONG    _RGB24Size
  299.  
  300.     APTR    _Bitplane        ; Address decompressed ILBM file (chip mem)
  301.     ULONG    _AllPlaneSize        ; Size of all planes (connected bitplanes)
  302.  
  303.     STRUCT    _BitmapStruc,bm_SIZEOF+(4*16)    ; Screen's or image's bitmap (for safety, 24 bit depth)
  304.  
  305.     ULONG    _CMapNumEntries        ; Colourmap entries (max. 256)
  306.  
  307.     APTR    _RGB32Values        ; Pointer to 32Bit colours of ILBM-file
  308.     STRUCT    _RGB32Colours,((256*3)+2)*4    ; Room for 256 32Bit colours (see LoadRGB32())
  309.  
  310.     UWORD    _RMB            ; State of right mouse button
  311.     UWORD    _Max            ; Local used (haven't got enough unused registers)
  312.  
  313.     UWORD    _MouseID        ; Saved mouse event
  314.  
  315.     UWORD    _PageSize        ; Number of lines of one page
  316.     UWORD    _XOffset        ; X and Y offset for console window,
  317.     UWORD    _YOffset        ; specified in ToolType
  318.  
  319.  
  320.     UBYTE    _NoLineFlag        ; Flag, if it is non-zero, the lines are
  321. *                      not counted, e.g. when restoring window
  322. *                      contents
  323.     UBYTE    _NoWarnFlag        ; When this flag is set, displaying
  324. *                      warnings is supressed
  325.     UBYTE    _NoCheckPrtFlag        ; When this is set, the printer is not checked
  326.     UBYTE    _WrapFlag        ; When this is set, make a word wrap when
  327. *                      the contents of one line do not fit in window
  328.     UBYTE    _PageSizeFlag        ; When this flag is set, the user has got defined the
  329. *                      scrollwidth
  330.     UBYTE    _ReqFlag        ; Indicates which requester is used,
  331. *                      0 == no requester opened till now
  332. *                      1 == ReqTools
  333. *                      2 == Arp
  334. *                     -1 == bad luck, ReqTools nor Arp could be opened
  335.     UBYTE    _LoadFlag        ; Indicates loading or saving, 0 == saving
  336.  
  337.     UBYTE    _BlitFlag        ; Local used, means blit image to screen
  338.     UBYTE    _SuperBitMap        ; Local used, means screen uses a superbitmap
  339.     UBYTE    _RIChanged        ; Local used, RasInfo is changed, so call
  340. *                      MakeScreen() and RetinkDisplay()
  341.  
  342.     ALIGNLONG
  343.  
  344.     APTR    _AudioBuffer        ; Address audio datas in Chip-Mem
  345.     ULONG    _AudioBufferSize    ; How tall is that buffer?
  346.     ULONG    _AudioPeriod        ; How many samples per second?
  347.     APTR    _VHDRPtr
  348.     APTR    _BODYPtr
  349.     ULONG    _BODYSize
  350.     APTR    _IOAudio
  351.     UBYTE    _AudGadget
  352.  
  353.     LABEL    _TableSize        ; Pweeh, size of the defined constants and
  354. *                      arrays, is automatically allocated when
  355. *                      this program is started (done by startup-code)
  356.  
  357.  
  358. *
  359. ** Include the startup-code
  360. *
  361.     include    RAD:include/startup.easy    ; Simple but effective startup-code
  362. *                          - perhaps you should change directory...
  363.  
  364. *
  365. ** RAW-key equates....
  366. *
  367. CRSR_UP        equ    $4C            ; Page Up
  368. CRSR_DN        equ    $4D            ; Page down
  369. CRSR_BK        equ    $4E            ; one line back
  370. CRSR_FD        equ    $4F            ; one line further
  371. L_Key        equ    $28            ; load new
  372. E_Key        equ    $12            ; enlarge window
  373. H_Key        equ    $25            ; help page
  374. I_Key        equ    $17            ; info
  375. A_Key        equ    $20            ; about page
  376. T_Key        equ    $14            ; top of file
  377. B_Key        equ    $35            ; bottom of file
  378. W_Key        equ    $11            ; window contents to prt
  379. P_Key        equ    $19            ; print file to prt
  380. F_Key        equ    $23            ; print file to file
  381. C_Key        equ    $33            ; window contents to file 
  382. PG_UP        equ    $3F            ; page up
  383. PG_DN        equ    $1F            ; page down
  384. RETURN        equ    $44            ; one line down
  385. ENTER        equ    $43            ; one line down
  386. HOME        equ    $3D            ; top of file
  387. END        equ    $1D            ; button of file
  388. R_SHIFT        equ    $61            ; one line back (step)
  389. R_Key        equ    $13            ; refresh Window
  390. S_Key        equ    $21            ; Search (find)
  391. N_Key        equ    $36            ; Next search (find)
  392. PrtSc        equ    $5D            ; print screen to prt
  393. HELP_Key    equ    $5F            ; Display title
  394.  
  395.  
  396. * - ReqTools
  397.     IFND    _LVOrtAllocRequestA
  398. _LVOrtAllocRequestA    EQU    -30
  399.     ENDC
  400.  
  401.     IFND    _LVOrtFreeRequestA
  402. _LVOrtFreeRequestA    EQU    -36
  403.     ENDC
  404.  
  405.     IFND    _LVOrtChangeReqAttrA
  406. _LVOrtChangeReqAttrA    EQU    -48
  407.     ENDC
  408.  
  409.     IFND    _LVOrtFileRequestA
  410. _LVOrtFileRequestA    EQU    -54
  411.     ENDC
  412.  
  413. * - Arp
  414.     IFND    _LVOArpFileRequest
  415. _LVOArpFileRequest    EQU    -294
  416.     ENDC
  417.  
  418. * - DiskFont
  419.     IFND    _LVOOpenDiskFont
  420. _LVOOpenDiskFont    EQU    -30
  421.     ENDC
  422.  
  423. * - CyberGraphics
  424.     IFND    _LVOWritePixelArray
  425. _LVOWritePixelArray    EQU    -126
  426.     ENDC
  427.  
  428.     IFND    RECTFMT_RGB
  429. RECTFMT_RGB    EQU    0
  430.     ENDC
  431.  
  432. *************************************************************
  433. *
  434. * This subroutine parses the Shell arguments.
  435. * Inputs: none (routine uses global constants).
  436. * Result: ErrorCode placed in "_argError", see "EQU's" below.
  437. *
  438. * Remarks: Only three arguments are parsed (if available).
  439. *
  440.  
  441. ed_QuoteNotAllowed    EQU    1    ; Possible errorcodes
  442. ed_MissingEndQuote    EQU    10    ; stored in "_argError"
  443.  
  444. _getArg
  445.     movea.l    _argv(A5),A0
  446.     lea    arg_1(A5),A1
  447.     moveq    #0,D2
  448.     bra.s    _getArg1.1
  449. _getArg.1
  450.     addq.b    #4,D2
  451.     cmpi.b    #12,D2            ; 3 args * à 4 bytes = 12
  452.     beq.s    _argEnd
  453.     cmpi.b    #' ',(A0)
  454.     beq.s    _skipUnused
  455. _getArg1.1
  456.     cmpi.b    #10,(A0)
  457.     beq.s    _argEnd
  458. _getArg.2
  459.     cmpi.b    #'"',(A0)
  460.     beq.s    _inQuotes
  461. _noQuotes
  462.     move.l    A0,(A1,D2.w)
  463. _stdLoop
  464.     cmpi.b    #'"',(A0)
  465.     beq.s    _argError.1
  466.     cmpi.b    #10,(A0)
  467.     beq.s    _noMoreArg
  468.     cmpi.b    #' ',(A0)
  469.     beq.s    _nextArgument
  470.     addq.l    #1,A0
  471.     bra.s    _stdLoop
  472. _nextArgument
  473.     clr.b    (A0)+
  474.     bra.s    _getArg.1
  475. _inQuotes
  476.     addq.l    #1,A0
  477.     move.l    A0,(A1,D2.w)
  478. _quoteLoop
  479.     cmpi.b    #10,(A0)
  480.     beq.s    _argError.2
  481.     cmpi.b    #'"',(A0)
  482.     beq.s    _nextArgument
  483.     addq.l    #1,A0
  484.     bra.s    _quoteLoop
  485. _noMoreArg
  486.     clr.b    (A0)
  487. 1$
  488.     addq.b    #4,D2
  489.     cmpi.b    #12,D2            ; max: 3 arguments
  490.     beq.s    _argEnd
  491.     clr.l    (A1,D2.w)
  492.     bra.s    1$
  493. _argEnd
  494.     rts                ; back
  495. _skipUnused
  496.     addq.l    #1,A0
  497.     cmpi.b    #' ',(A0)
  498.     beq.s    _skipUnused
  499.     bra.s    _getArg1.1
  500. _argError.1
  501.     moveq    #ed_QuoteNotAllowed,D0
  502.     bsr.s    _setArgError
  503.     subq.b    #4,D2
  504.     bra.s    _noMoreArg
  505. _argError.2
  506.     moveq    #ed_MissingEndQuote,D0
  507.     bsr.s    _setArgError
  508.     subq.b    #4,D2
  509.     bra.s    _noMoreArg
  510. _setArgError
  511.     move.l    D0,_argError(A5)
  512.     rts
  513.  
  514. ******************************************************************************
  515. *
  516. * Routine to parse from Workbench overgiven files.
  517. * Inpts: D0 - how many arguments (files) allowed to store
  518. *        D1 - how many arguments are there?,
  519. *     A0 - pointer to sm_ArgList (global - startup-code -> WBench-message),
  520. *     A1 - address array for lock of file and filename, -
  521. *          - array must look like this:
  522. *        BPTR Lock
  523. *        APTR File (string pointer)
  524. *        BPTR Lock
  525. *        APTR File (string pointer)
  526. *        ... and so on
  527. * Results: none
  528. *
  529.  
  530. _GetWBFiles
  531.     subq.l    #1,D1
  532.     beq.s    3$
  533.     bcs.s    3$
  534.     addq.l    #4,A0
  535.     bra.s    2$
  536. 1$
  537.     addq.l    #4,A0
  538.     move.l    (A0),(A1)+        ; Lock
  539.     addq.l    #4,A0
  540.     move.l    (A0),(A1)+        ; Filename
  541.     subq.l    #1,D1            ; argc -1
  542.     beq.s    3$
  543. 2$
  544.     dbf    D0,1$
  545. 3$
  546.     rts
  547.  
  548. ****************************************************
  549. *
  550. * Subroutine to set the returncode for this program,
  551. * use Shell-command why to investigate the error.
  552. *
  553. * Inputs: D0 - errorcode
  554. * Results: none
  555. *
  556.  
  557. _SetError
  558.     move.l    D0,_errno(A5)
  559. _setError4Task
  560.     movea.l    _SysBase(A5),A0
  561.     movea.l    276(A0),A0        ; ThisTask
  562.     move.l    D0,pr_Result2(A0)
  563.     rts
  564.  
  565. ******************************************
  566. *
  567. * Entry point, called out of startup-code.
  568. *
  569.  
  570. _main    ; Startup-Code enters here...
  571.     bsr.w    _InitStandard        ; Init windows
  572.  
  573.     tst.l    _WBenchMsg(A5)
  574.     bne.s    .GetWBArgs        ; If we are started from workbench
  575.     bsr.w    _getArg            ; otherwise parse Shell arguments
  576.     bra.s    .argsOk
  577. .GetWBArgs
  578.     tst.l    _argc(A5)        ; Any file given (from WB)?
  579.     beq.s    0$
  580.  
  581.     moveq    #1,D0            ; Max. allowed number of arguments!
  582.     move.l    _argc(A5),D1        ; Number of arguments stored (WB)
  583.     movea.l    _argv(A5),A0        ; sm_ArgList pointer
  584.     lea    lock_1(A5),A1        ; Address buffer
  585.     bsr.s    _GetWBFiles        ; Call subroutine to parse files
  586.  
  587. 0$
  588.     moveq    #13,D0            ; 14 Entries
  589.     tst.l    _ToolTypesArray(A5)
  590.     beq.s    .argsOk
  591.  
  592.     movea.l    _ToolTypesArray(A5),A0    ; Pointer to ToolTypeArray
  593.     lea    WB_arg_1(A5),A1        ; Address first WB-Text
  594. 1$
  595.     tst.l    (A0)
  596.     beq.s    .argsOk            ; If no more texts are set...
  597.     move.l    (A0)+,(A1)+        ; WB-Arg-Text -> Arg[1..] a.s.o.
  598.     dbf    D0,1$
  599.  
  600. .argsOk        
  601.     move.l    #20,_errno(A5)
  602.     bsr.w    _SetPrefs        ; See there
  603.     bsr.w    _OpenROMLibs        ; Open libraries
  604.     tst.l    _WBenchMsg(A5)        ; WB-start?
  605.     beq.s    4$            ; No? - then it was a Shell-start
  606.     bsr.w    _SetDirection        ; Get user datas
  607.     bsr.w    _CheckWarning
  608.     bsr.w    _CheckExecute        ; Execute (if a specification) a command
  609. 4$
  610.     bsr.w    _SetWindow        ; Set window limits
  611.     bsr.w    _CheckWrap        ; Check Word-Wrap (ToolTypes)
  612.     move.l    #100,_errno(A5)
  613.     bsr.w    _OpenWindow
  614.     tst.l    D0
  615.     beq.w    _Out_02            ; Don't bomb
  616.  
  617. **********************************************
  618. *
  619. * Open console device for reading and writing.
  620. *
  621.  
  622.     move.l    #80,_errno(A5)
  623.     movea.l    _SysBase(A5),A6        ; Make ReadReplyPort
  624.     lea    _ReadReply(A5),A0
  625.     move.l    _OwnTask(A5),MP_SIGTASK(A0)    ; Task to be signalled
  626.     lea    MP_MSGLIST(A0),A0        ; Console-read reply port
  627.     NEWLIST    A0
  628.  
  629.     lea    _WriteReply(A5),A0    ; Make WriteReplyPort
  630.     lea    MP_MSGLIST(A0),A0    ; Console-read reply port
  631.     NEWLIST    A0
  632.  
  633.     lea     _ReadIo(A5),A1
  634.     move.l    _WindowPtr(A5),IO_DATA(A1)
  635.     move.l    #wd_SIZEOF,IO_LENGTH(A1)
  636.     moveq    #0,D0            ; Unit
  637.     moveq    #0,D1            ; Flags
  638.     lea    _DeviceName(pc),A0
  639.     jsr    _LVOOpenDevice(A6)    ; Open console device
  640.     tst.l    D0
  641.     beq.s    .ConsoleIsOpen
  642.     lea    _ErrorOpenDevTxt(pc),A0    ; else...
  643.     bsr.w    _DisplayError
  644.     bra.w    _Out_01
  645.  
  646. .ConsoleIsOpen
  647.     lea    _ReadIo(A5),A0        ; ReadIo<->WriteIo 
  648.     lea    _WriteIo(A5),A1
  649.     move.l    IO_DEVICE(A0),IO_DEVICE(A1)    ; Device
  650.     move.l    IO_UNIT(A0),IO_UNIT(A1)        ; Unit
  651.  
  652.     lea    _ReadReply(A5),A2
  653.     move.l    A2,MN_REPLYPORT(A0)
  654.  
  655.     lea    _WriteReply(A5),A2
  656.     move.l    A2,MN_REPLYPORT(A1)
  657.  
  658.     clr.l    _errno(A5)
  659.  
  660. ***********************
  661. *
  662. * Some useful stuff....
  663. *
  664.  
  665.     bsr.w    _CursorOff        ; Cursor invisible
  666.     bsr.w    _SetPtr4Req        ; Twist pointer for system-requesters
  667.     bsr.w    _SetScrollWidth        ; Seek and set scrollwidth
  668.     bsr.w    _SetPageWidthAndLen    ; Seek and set page sizes
  669.  
  670.     lea    _ConBuffer(A5),A0    ; Address buffer
  671.     move.w    #$9B48,(A0)        ; Cursor Home
  672.     moveq    #2,D0            ; 2 chars for output
  673.     bsr.w    _ConOut_Rel        ; Write down to console...
  674.  
  675.     tst.l    arg_1(A5)        ; Any file placed?
  676.     bne.w    _CLILoad        ; Yes..
  677.     tst.l    file_1(A5)        ; Or is there a file?
  678.     bne.w    _WBLoad            ; Yes...
  679. *                      Otherwise....
  680. _InitRequester
  681.     bsr.w    OpenReq            ; Open for requests needed libraries
  682.     tst.b    _ReqFlag(A5)        ; ReqTools or Arp opened?
  683.     bmi.w    _End_1            ; No, bad luck
  684. _NextTry
  685.     st.b    _LoadFlag(A5)        ; We want to load...
  686.     bsr.w    _GetFile        ; Build request and get file
  687.     cmpi.l    #-1,D0            ; Hard error?
  688.     beq.w    _End_1            ; Ok, finish immediately
  689.     tst.l    D0            ; No file?
  690.     beq.s    _NoFileChosen        ; Too bad
  691.     
  692.     bsr.w    _ReadFile        ; Read that file
  693.     tst.l    D0            ; Any error?
  694.     beq.s    _Loop            ; Yes...
  695.  
  696. *
  697. ** Now we check the file. If it returns to this point all went ok.
  698. ** We check for ascii files, binary files, PP20 files, ILBM files.
  699. *
  700.     bsr.w    _CheckFile
  701.  
  702.     bsr.w    _IgnoreSettings        ; ANSI-Filter
  703.  
  704.     bsr.w    _SetViewerPrefs        ; Preferences
  705.  
  706.     bra.w    _FirstPage        ; Display first page
  707.  
  708. _NoFileChosen
  709.     lea    _NoFileMsg(pc),A0
  710.     bsr.w    _DisplayError
  711.     tst.l    D0            ; User said: "Cancle" loading
  712.     beq.w    _End            ; If so, terminate...
  713.  
  714. ***********************************************
  715. *
  716. * Main routine, is waiting until an event occurs.
  717. *
  718.  
  719. _Loop
  720.     clr.b    _NoLineFlag(A5)        ; Allow line counting
  721.     bsr.w    _ComLine        ; Make window-title
  722.  
  723. .noComLine
  724.     bsr.w    _SetActionWait        ; Allow intuition to send us RAW-key messages
  725.  
  726.     tst.l    _TextPtr(A5)        ; Any text to display?
  727.     beq.s    .NoNextTxt        ; If not
  728.  
  729.     tst.b    _AudGadget(A5)
  730.     bne.s    .NoNextTxt
  731.  
  732.     tst.w    _MouseID(A5)        ; This inidicates if a mousebutton
  733. *                      was already touched, if it was touched,
  734.     bne.w    .MouseWasTouched    ; we have to jump to an other routine...
  735.  
  736. .NoNextTxt
  737.     move.l    A2,-(sp)
  738.     movea.l    _WindowPtr(A5),A2
  739.     movea.l    wd_UserPort(A2),A2
  740.     movea.l    A2,A0
  741.     movea.l    _SysBase(A5),A6
  742.     jsr    _LVOWaitPort(A6)    ; Wait until a message has reached us
  743.  
  744.     movea.l    A2,A0
  745.     jsr    _LVOGetMsg(A6)
  746.     movea.l    D0,A1
  747.     movea.l    D0,A2
  748.     jsr    _LVOReplyMsg(A6)
  749.  
  750.     move.l    20(A2),D0        ; im_Class
  751.     move.w    24(A2),D1        ; im_Code
  752.     move.l    28(A2),_IAddr(A5)
  753.     movea.l    (sp)+,A2
  754. *
  755. ** Some notes at this point: normally you should remember the received things i.e.
  756. ** im_Class, im_Code, im_IAddress and so on into private constants and _THEN_
  757. ** reply the message to avoid conflicts with intuition. Because intuition does
  758. ** only send us (at most) each 1/10 second a message - and this is assembler -
  759. ** _AND_ we awoke yet (running task) it's not too critical to save the message
  760. ** things not - _BUT_ - if intuition is rewritten for (may be) Kickstart 41/42
  761. ** and it's then a lot faster, the replying without saving will cause BIG trouble.
  762. *
  763.     cmpi.l    #$8,D0            ; MouseButtons?
  764.     beq.s    4$            ; Startup for mouse-buttons!!!!
  765.  
  766.     cmpi.l    #$40,D0
  767.     beq.s    3$
  768.  
  769.     bsr.w    _SetNILWait        ; Tell intuition we don't want to have message
  770. *                      for now, do it via a PA_IGNORE flag which
  771. *                      blocks messages for our window
  772.  
  773.     clr.w    _MouseID(A5)        ; Erase ID
  774.  
  775.     movem.l    D0-D1,-(sp)
  776. 1$
  777.     movea.l    _WindowPtr(A5),A0
  778.     movea.l    wd_UserPort(A0),A0
  779.     jsr    _LVOGetMsg(A6)        ; Ignore following messages until
  780.     tst.l    D0            ; flag is active...
  781.     beq.s    2$
  782.  
  783.     movea.l    D0,A1
  784.     jsr    _LVOReplyMsg(A6)    ; Free message
  785.     bra.s    1$
  786. 2$
  787.     movem.l    (sp)+,D0-D1
  788.  
  789.     cmpi.l    #$200,D0        ; CLOSEWINDOW ?
  790.     beq.w    _End            ; If so...
  791.  
  792.     cmpi.l    #$400,D0        ; RAWKEY?
  793.     beq.w    _RawKey            ; If so...
  794.  
  795. 3$
  796.     cmpi.l    #$40,D0            ; Gadget up ?
  797.     bne.w    _Loop
  798.     movea.l    _IAddr(A5),A0
  799.     cmpi.w    #3,gg_GadgetID(A0)    ; Gadget id = 3?
  800.     bne.w    _Loop
  801.     bra.w    _AudioHit
  802.  
  803. *
  804. ** If the first time a mousebutton was clicked, we are at this point.
  805. *
  806. 4$
  807.     tst.b    _AudGadget(A5)
  808.     bne.w    _Loop
  809.  
  810.     move.w    D1,_MouseID(A5)
  811.  
  812.     cmpi.w    #$69,D1            ; Right one?
  813.     bne.s    .LeftOne
  814.     move.w    D1,_MouseID(A5)
  815. .RO1
  816.     move.w    #CRSR_FD,D1
  817.     bra.s    _RawKey
  818.  
  819. .LeftOne
  820.     cmpi.w    #$68,D1            ; Left one?
  821.     bne.s    .NotValid        ; Not a valid message...
  822.     move.w    D1,_MouseID(A5)
  823. .LO1
  824.     move.w    #CRSR_BK,D1
  825.     bra.s    _RawKey
  826. .NotValid
  827.     clr.w    _MouseID(A5)
  828.     bra.w    _Loop
  829.  
  830. *
  831. ** A mouse-button was clicked a while ago, we have now to check if the mousebutton
  832. ** was released.
  833. *
  834. .MouseWasTouched
  835.     move.l    A2,-(sp)
  836.     movea.l    _WindowPtr(A5),A0
  837.     movea.l    wd_UserPort(A0),A0
  838.     movea.l    _SysBase(A5),A6
  839.     jsr    _LVOGetMsg(A6)        ; Do we have a message?
  840.     tst.l    D0
  841.     beq.s    .further        ; No, just do it like a mousebutton was clicked
  842.     movea.l    D0,A1
  843.     movea.l    D0,A2
  844.     jsr    _LVOReplyMsg(A6)
  845.     cmpi.l    #$8,im_Class(A2)    ; MouseButtons?        | SEE NOTES ABOUT
  846.     bne.s    .further        ; see above        | MESSAGES A PIECE
  847.     cmpi.w    #$68+$80,im_Code(A2)    ; Left one released?    | FURTHER ABOVE....
  848.     beq.s    .EndMouse
  849.     cmpi.w    #$69+$80,im_Code(A2)    ; or right one released?
  850.     bne.s    .further
  851. .EndMouse
  852.     movea.l    (sp)+,A2
  853.     clr.w    _MouseID(A5)        ; Clear ID (code), indicates that no mouse-
  854.     bra.w    _Loop            ; button is held down
  855.  
  856. .further
  857.     movea.l    (sp)+,A2
  858.     cmpi.w    #$68,_MouseID(A5)    ; Left mousebutton?
  859.     beq.s    .LO1
  860.     bra.s    .RO1            ; else it was the right one!
  861. *
  862. ** Startup for console action
  863. *
  864. _RawKey
  865.     lea    _ConBuffer(A5),A0    ; Buffer
  866.     move.w    D1,(A0)            ; Store there the raw-key
  867.     bra.w    _ConsoleEvent        ; just go ahead
  868.  
  869.  
  870. **********************
  871. *
  872. * Our end has come....
  873. *
  874.  
  875. _End_1
  876.     lea    _NoReqTxt(pc),A0    ; Fail with message (couldn't open file-
  877.     bsr.w    _DisplayError        ; requester)
  878. _End
  879.     movea.l    4.w,A6
  880.     suba.l    A1,A1
  881.     jsr    _LVOFindTask(A6)
  882.     movea.l    D0,A0
  883.     movea.l    pr_ReturnAddr(A0),A0    ; Program's exit address
  884.     subq.l    #8,A0
  885.     movea.l    (A0),A5            ; Restore basetable pointer
  886.  
  887.     movea.l    _OwnTask(A5),A0        ; Restore pointer for system-requesters
  888.     move.l    _StdprWindowPtr(A5),184(A0)
  889.  
  890.     tst.l    _UserProject(A5)    ; .info-file there?
  891.     beq.s    0$
  892.     movea.l    _IconBase(A5),A6
  893.     movea.l    _UserProject(A5),A0
  894.     jsr    _LVOFreeDiskObject(A6)    ; Free the info-file resources
  895. 0$
  896.     movea.l    _SysBase(A5),A6
  897.     lea    _ReqToolsBase(A5),A2    ; ReqTools-library open?
  898.     tst.l    (A2)
  899.     beq.s    1$            ; No
  900.     movea.l    A6,A4            ; Save Exec
  901.     movea.l    (A2),A6            ; ReqTools-Base
  902.     movea.l    _ReqPtr(A5),A1        ; File-requester-record
  903.     jsr    _LVOrtFreeRequestA(A6)    ; Free it
  904.     movea.l    A6,A1            ; ReqTools-Base A1
  905.     movea.l    A4,A6            ; Exec
  906.     jsr    _LVOCloseLibrary(A6)
  907. 1$
  908.     tst.l    _ArpBase(A5)        ; Arp-Library open?
  909.     beq.s    2$            ; No
  910.     movea.l    _ArpBase(A5),A1
  911.     jsr    _LVOCloseLibrary(A6)
  912. 2$
  913.     tst.l    _CyberGfxBase(A5)
  914.     beq.s    3$
  915.     movea.l    _CyberGfxBase(A5),A1
  916.     jsr    _LVOCloseLibrary(A6)
  917. 3$
  918.     move.l    _BufferSize(A5),D0    ; Something allocated?
  919.     beq.s    4$            ; No
  920.     movea.l    _TextPtr(A5),A1        ; Else
  921.     jsr    _LVOFreeMem(A6)        ; free it
  922. 4$
  923.     bsr.w    _FreeAudio
  924.  
  925.     movea.l    _SysBase(A5),A6
  926.     lea    _ReadIo(A5),A1
  927.     jsr    _LVOCloseDevice(A6)    ; Close console-device
  928. _Out_01
  929.     bsr.w    _CloseWindow        ; Close main-window
  930. _Out_02
  931.     bsr.w    _CloseROMLibs        ; Close 'em
  932.  
  933.     rts                ; Back into startup-code
  934.  
  935. ********************************************
  936. *
  937. * One routine with a few entries to call....
  938. *
  939. * It will write down to the console-window
  940. * the overgiven text.
  941. *
  942.  
  943. _ConOut        ; Write down 1 char, the char is in the "_ConBuffer"
  944.     movea.l    _SysBase(A5),A6
  945.     lea    _WriteIo(A5),A1        ; Io-structure for writing
  946.     move.l    #1,IO_LENGTH(A1)    ; 1 char for output
  947.  
  948. _ContConOut    ; Write down x-chars, the chars are in the "_ConBuffer"
  949.     move.w    #CMD_WRITE,IO_COMMAND(A1)    ; Command = Write
  950.     lea    _ConBuffer(A5),A0    ; Address char
  951.  
  952. _ContConOut_01    ; Check first for tab-width (take 1 tab as 8 blanks)
  953.     bsr.s    _CheckTAB
  954. _ContConOut_02    ; Just do it (writing)
  955.     move.l    A0,IO_DATA(A1)        ; Address string
  956.     movea.l    _SysBase(A5),A6
  957.     jsr    _LVODoIO(A6)        ; Do it, but wait until done
  958.     lea    _ConBuffer(A5),A0
  959.     rts
  960.  
  961. _ConOut_Rel    ; Relative length, rigid address (number of chars in D0)
  962.     lea    _WriteIo(A5),A1
  963.     move.l    D0,IO_LENGTH(A1)
  964.     bra.s    _ContConOut
  965.  
  966. _ConOut_Reloc    ; Relative length, relative address (number of chars in D0,
  967. *                             address string in A0)
  968.     movea.l    _SysBase(A5),A6
  969.     lea    _WriteIo(A5),A1
  970.     move.l    D0,IO_LENGTH(A1)
  971.     move.w    #CMD_WRITE,IO_COMMAND(A1)    ; Command = Write
  972.     bra.s    _ContConOut_01
  973.  
  974. *****************************************************
  975. *
  976. * Compute length for one line, take 1 tab as 8 blanks.
  977. *
  978.  
  979. _CheckTAB
  980.     tst.b    _WrapFlag(A5)        ; Word Warp allowed?
  981.     bne.w    .CT_End            ; If so...
  982.  
  983.     tst.l    _PageWidth(A5)
  984.     beq.w    .CT_End
  985.  
  986.     movem.l    D0-D3/A0-A2,-(sp)
  987.     move.l    _PageWidth(A5),D3    ; Number of Displayable columns
  988.     addq.w    #1,D3
  989.     move.l    D0,D2            ; Number of chars to print down
  990.     movea.l    A0,A2            ; Address string
  991. .CT_Next
  992.     movea.l    A2,A0            ; Current string
  993.     moveq    #0,D0            ; Number of Chars
  994.     moveq    #0,D1            ; Number of columns
  995. .CT_Search
  996.     addq.w    #1,D0            ; Number of chars plus 1
  997.     addq.w    #1,D1            ; Number of columns plus 1
  998.     cmp.l    D1,D3            ; Compare width maximum of possible
  999. *                      displayable columns
  1000.     bls.s    .CT_Store
  1001.  
  1002.     cmpi.b    #10,(A2)        ; LineFeed
  1003.     beq.s    .CT_Store
  1004.     cmpi.b    #9,(A2)            ; TAB
  1005.     beq.s    .CT_AddTAB
  1006.     cmpi.b    #27,(A2)        ; ESC
  1007.     beq.s    .CT_IgnoreESC
  1008.  
  1009.     addq.l    #1,A2
  1010.     subq.w    #1,D2            ; Number of chars minus 1
  1011.     beq.s    .CT_Store
  1012.     bra.s    .CT_Search
  1013.  
  1014. .CT_Store
  1015.     lea    _WriteIo(A5),A1        ; Io-structure for writing
  1016.     move.w    #CMD_WRITE,IO_COMMAND(A1)    ; Command = Write
  1017.     move.l    D0,IO_LENGTH(A1)    ; Chars for output
  1018.     move.l    A0,IO_DATA(A1)        ; Address string
  1019.     movea.l    _SysBase(A5),A6
  1020.     jsr    _LVODoIO(A6)        ; Do it, but wait until done
  1021.  
  1022.     tst.w    D2
  1023.     beq.s    .CT_End_1
  1024.  
  1025.     moveq    #-1,D0
  1026. 1$
  1027.     subq.w    #1,D2
  1028.     beq.s    .CT_End_1
  1029.     cmpi.b    #10,(A2)+        ; LineFeed
  1030.     dbeq    D0,1$
  1031.  
  1032.     bra.s    .CT_Next
  1033.  
  1034. .CT_AddTAB
  1035.     addq.w    #7,D1
  1036.     andi.w    #-8,D1
  1037.     addq.l    #1,A2
  1038.     subq.w    #1,D2
  1039.     beq.s    .CT_Store
  1040.     bra.s    .CT_Search
  1041.  
  1042. .CT_IgnoreESC
  1043.     subq.w    #1,D1
  1044.     addq.l    #4,A2            ; Ignore 4 chars (currently no real length
  1045.     addq.w    #3,D0            ; checking (Sequencer) is done...)
  1046.     subq.w    #4,D2
  1047.     beq.s    .CT_Store
  1048.     bcs.s    2$
  1049.     bra.s    .CT_Search
  1050. 2$
  1051.     subq.l    #1,A2
  1052.     subq.w    #1,D0
  1053.     addq.w    #1,D2
  1054.     bcs.s    2$
  1055.     bra.s    .CT_Store
  1056.  
  1057. .CT_End_1
  1058.     movem.l    (sp)+,D0-D3/A0-A2
  1059. .CT_End
  1060.     rts
  1061.  
  1062. ***********************************************
  1063. *
  1064. * Read from console-window - but don't wait for
  1065. * the result.
  1066. *
  1067. * Inputs: D0 - number of chars to read
  1068. * Results: Chars in gloabal "_ConBuffer"
  1069. *
  1070.  
  1071. _QueueRead
  1072.     lea    _ReadIo(A5),A1
  1073.     move.l    D0,IO_LENGTH(A1)    ; Number of chars to read
  1074.     move.l    A0,IO_DATA(A1)
  1075.     move.w    #CMD_READ,IO_COMMAND(A1) ; Command READ
  1076.     movea.l    _SysBase(A5),A6
  1077.     jmp    _LVOSendIO(A6)        ; Send command
  1078.  
  1079. _GetConMsg
  1080.     moveq    #20,D0
  1081.     lea    _ConBuffer(A5),A0
  1082.     bsr.s    _QueueRead        ; Get the message
  1083.     movea.l    _SysBase(A5),A6
  1084.     lea    _ReadReply(A5),A0
  1085.     jmp    _LVOGetMsg(A6)
  1086.  
  1087.  
  1088. ************************************************************
  1089. *
  1090. * Open graphic and intuition libraries,
  1091. * required version is 33 (ks 1.2).
  1092. *
  1093. * Inputs: None
  1094. * Result: GfxBase and IntuitionBase
  1095. *      (NULL not possible!!! - noone works with a ks. lower 33!!!)
  1096. * At the moment I know only one person who got a ks. lower than 33, 32,
  1097. * OS1.1 PAL - Amiga 1000, the machine with the WOM; no, he doesn't sells it...
  1098. *
  1099.  
  1100. _OpenROMLibs
  1101.     movea.l    _SysBase(A5),A6
  1102.     lea    _IntuitionName(pc),A1
  1103.     moveq    #33,D0
  1104.     jsr    _LVOOpenLibrary(A6)
  1105.     move.l    D0,_IntuitionBase(A5)
  1106.     moveq    #33,D0
  1107.     lea    _GfxName(pc),A1
  1108.     jsr    _LVOOpenLibrary(A6)
  1109.     move.l    D0,_GfxBase(A5)
  1110.     rts
  1111.  
  1112. ****************************************
  1113. *
  1114. * Close graphic and intuition libraries.
  1115. *
  1116. * Inputs: None
  1117. * Results: None
  1118. *
  1119.  
  1120. _CloseROMLibs
  1121.     movea.l    _SysBase(A5),A6
  1122.     movea.l    _IntuitionBase(A5),A1
  1123.     jsr    _LVOCloseLibrary(A6)
  1124.     movea.l    _GfxBase(A5),A1
  1125.     jmp    _LVOCloseLibrary(A6)
  1126.  
  1127.  
  1128. *******************************************
  1129. *
  1130. * Open main window which is used as console
  1131. * window.
  1132. *
  1133. * We take from the tooltypes (if wb-start)
  1134. * the specified X- and Y-offset for our
  1135. * window and of course the font the user
  1136. * specified (in tooltypes) for this window.
  1137. *
  1138. * Inputs: None
  1139. * Results: _UserFontPtr (may be NULL)
  1140. *       _WindowPtr (may be NULL)
  1141. *
  1142.  
  1143. _OpenWindow
  1144.     lea    WB_arg_1(A5),A0
  1145. .NextTType
  1146.     tst.l    (A0)            ; Argument there?
  1147.     beq.s    _NoOffsetDeclared    ; No
  1148.     movea.l    (A0)+,A1        ; Address overgiven string
  1149.     lea    _OffsetSpecName(pc),A2    ; Address string to compare
  1150.     moveq    #12,D0            ; 13 chars to compare
  1151. .CheckTType
  1152.     cmpm.b    (A1)+,(A2)+        ; Compare strings
  1153.     bne.s    .NextTType        ; "WINDOWOFFSET="
  1154.     dbf    D0,.CheckTType
  1155.     movea.l    A1,A0            ; Pointer to following string
  1156.  
  1157.     moveq    #0,D0
  1158.     move.b    (A0),D0
  1159.     lsl.w    #8,D0
  1160.     move.b    1(A0),D0
  1161.     lsl.l    #8,D0
  1162.     move.b    2(A0),D0
  1163.     lsl.l    #8,D0
  1164.     move.b    3(A0),D0
  1165.     cmpi.l    #'AUTO',D0        ; Auto adjustment?
  1166.     bne.s    .Value    
  1167.     tst.b    4(A0)
  1168.     bne.s    .Value
  1169.  
  1170.     movea.l    _IntuitionBase(A5),A1
  1171.     movea.l    ib_ActiveScreen(A1),A1
  1172.     moveq    #0,D0
  1173.     move.b    sc_BarHeight(A1),D0
  1174.     addq.w    #1,D0
  1175.     move.w    D0,_YOffset(A5)
  1176.     bra.s    _NoOffsetDeclared    ; ...altough it is...
  1177. .Value
  1178.     moveq    #0,D0            ; No mask
  1179.     bsr.w    _StrToLong
  1180.     tst.l    D1
  1181.     bmi.s    _NoOffsetDeclared    ; Upon error
  1182. .XOffsetGot
  1183.     move.w    D0,_XOffset(A5)        ; Save X-Offset
  1184.  
  1185.     moveq    #0,D0            ; No mask
  1186.     bsr.w    _StrToLong
  1187.     tst.l    D1
  1188.     bmi.s    _NoOffsetDeclared    ; Upon error
  1189. .YOffsetGot
  1190.     move.w    D0,_YOffset(A5)        ; Save Y-Offset
  1191.  
  1192. *
  1193. ** Look for the font...
  1194. *
  1195. _NoOffsetDeclared
  1196.     lea    WB_arg_1(A5),A0
  1197. .NextTType
  1198.     tst.l    (A0)            ; Argument there?
  1199.     beq.w    _NoFontDeclared        ; No
  1200.     movea.l    (A0)+,A1        ; Address overgiven string
  1201.     lea    _FontSpecName(pc),A2    ; Address string to compare
  1202.     moveq    #4,D0            ; 5 chars to compare
  1203. .CheckTType
  1204.     cmpm.b    (A1)+,(A2)+        ; Compare strings
  1205.     bne.s    .NextTType        ; "FONT="
  1206.     dbf    D0,.CheckTType
  1207.     movea.l    A1,A0            ; Pointer to following string
  1208.  
  1209.     lea    _UserFontBuf(A5),A1    ; Our private buffer
  1210.     tst.b    (A0)            ; End of user's string?
  1211.     beq.w    _NoFontDeclared
  1212. 1$
  1213.     move.b    (A0)+,(A1)+        ; Copy font's name
  1214.     beq.w    _NoFontDeclared        ; If an interrupted end...
  1215.     cmpi.b    #',',(A0)        ; Comma = number follows!
  1216.     bne.s    1$
  1217.  
  1218.     move.b    #'.',(A1)+        ; Add string ".font" to font's name
  1219.     move.b    #'f',(A1)+
  1220.     move.b    #'o',(A1)+
  1221.     move.b    #'n',(A1)+
  1222.     move.b    #'t',(A1)+
  1223.     clr.b    (A1)
  1224.  
  1225.     moveq    #0,D0            ; No mask
  1226.     bsr.w    _StrToLong
  1227.     cmpi.l    #-1,D1
  1228.     beq.s    _NoFontDeclared
  1229.  
  1230. _OpenUserFont
  1231.     lea    _UserFontStruc(A5),A0    ; FontAttr-record
  1232.     move.w    D0,4(A0)        ; Save height of font
  1233.     move.b    #$40|1,7(A0)        ; Designed and ROM-Font (on first try)
  1234.     lea    _UserFontBuf(A5),A1    ; Buffer with font's name
  1235.     move.l    A1,(A0)            ; Set name in FontAttr-record
  1236.     movea.l    _GfxBase(A5),A6
  1237.     jsr    _LVOOpenFont(A6)    ; Try to open the font
  1238.     tst.l    D0            ; Font opened?
  1239.     beq.s    .OpenDiskFont        ; If not...
  1240.     movea.l    D0,A1            ; TextFont
  1241.     lea    _UserFontStruc(A5),A0    ; FontAttr-record
  1242.     move.w    4(A0),D1        ; Get height of font
  1243.     cmp.w    20(A1),D1        ; Height of opened font same as...
  1244.     beq.s    _GotFont        ; Of course...
  1245.  
  1246.     movea.l    _GfxBase(A5),A6        ; Otherwise close
  1247.     jsr    _LVOCloseFont(A6)    ; opened font (got not the right height)
  1248.  
  1249. .OpenDiskFont
  1250.     lea    _DiskFontName(pc),A1    ; "diskfont.library"
  1251.     moveq    #33,D0
  1252.     movea.l    _SysBase(A5),A6
  1253.     jsr    _LVOOpenLibrary(A6)    ; Open the library
  1254.     tst.l    D0
  1255.     beq.s    _NoFontDeclared        ; Damned!
  1256.  
  1257.     movea.l    D0,A6            ; DiskfontBase
  1258.     lea    _UserFontStruc(A5),A0    ; Addr. FontAttr-record
  1259.     move.b    #$40|2,7(A0)        ; Designed and DISK-Font!
  1260.     jsr    _LVOOpenDiskFont(A6)    ; Load the disk-resident-font
  1261.     tst.l    D0            ; Got font?
  1262.     beq.s    1$            ; No...
  1263.     move.l    D0,D2            ; Save font-pointer
  1264.     movea.l    A6,A1            ; DiskFontBase
  1265.     movea.l    _SysBase(A5),A6
  1266.     jsr    _LVOCloseLibrary(A6)    ; Close "diskfont.library"
  1267.     move.l    D2,D0            ; Font-pointer
  1268.     bra.s    _GotFont
  1269. 1$
  1270.     movea.l    A6,A1            ; DiskfontBase
  1271.     movea.l    _SysBase(A5),A6
  1272.     jsr    _LVOCloseLibrary(A6)
  1273.     bra.s    _NoFontDeclared        ; Error exit
  1274. _GotFont
  1275.     move.l    D0,_UserFontPtr(A5)    ; Save font-pointer
  1276.  
  1277. *
  1278. ** Attempt to open the window with (if) overgiven X- and Y-Offsets
  1279. ** and (if) user specified font.
  1280. *
  1281. _NoFontDeclared
  1282.     movea.l    _SysBase(A5),A6
  1283.     jsr    _LVOForbid(A6)
  1284.  
  1285.     movea.l    _IntuitionBase(A5),A6
  1286.     move.l    ib_ActiveScreen(A6),_ScreenPtr(A5)    ; Get active screen
  1287.  
  1288.     lea    _WindowRecord(A5),A0    ; Window-record
  1289.     move.l    _ScreenPtr(A5),nw_Screen(A0) ; On this screen our window should appear
  1290.     movea.l    _ScreenPtr(A5),A1    ; Address screen-record
  1291.  
  1292.     move.w    _XOffset(A5),D0
  1293.     beq.s    0$
  1294.     add.w    D0,(A0)            ; Set left edge of window
  1295. 0$
  1296.     move.w    _YOffset(A5),D0
  1297.     beq.s    1$
  1298.     add.w    D0,nw_TopEdge(A0)    ; Set top edge of window
  1299. 1$
  1300.     tst.w    nw_Width(A0)
  1301.     bne.s    2$
  1302.     move.w    sc_Width(A1),nw_Width(A0)
  1303. 2$
  1304.     tst.w    nw_Height(A0)
  1305.     bne.s    3$
  1306.     move.w    sc_Height(A1),nw_Height(A0)
  1307. 3$
  1308.     move.w    _XOffset(A5),D0
  1309.     beq.s    4$
  1310.     sub.w    D0,nw_Width(A0)
  1311. 4$
  1312.     move.w    _YOffset(A5),D0
  1313.     beq.s    5$
  1314.     sub.w    D0,nw_Height(A0)
  1315. 5$
  1316.     jsr    _LVOOpenWindow(A6)    ; Open the window
  1317.     move.l    D0,-(sp)
  1318.     movea.l    _SysBase(A5),A6
  1319.     jsr    _LVOPermit(A6)
  1320.     move.l    (sp)+,D0
  1321.     move.l    D0,_WindowPtr(A5)    ; Save window pointer
  1322.     beq.w    7$
  1323.  
  1324.     movem.l    D0/A2-A3,-(sp)
  1325.     movea.l    D0,A3            ; Window
  1326.     movea.l    wd_BorderRPort(A3),A2    ; RastPort of titlebar
  1327.  
  1328.     movea.l    _IntuitionBase(A5),A6
  1329.     cmpi.w    #35,LIB_VERSION(A6)    ; Kickstart 2.x or higher?
  1330.     bls.s    .Read            ; No...
  1331.     movea.l    wd_WScreen(A3),A0    ; Window's screen
  1332.     jsr    _LVOGetScreenDrawInfo(A6)    ; Get drawing infos
  1333.     tst.l    D0
  1334.     beq.s    .Read
  1335.     movea.l    D0,A1            ; DrawInfos
  1336.     movea.l    dri_Pens(A1),A0        ; Pointer to pen-array
  1337.     move.w    5*2(A0),D0        ; Get fillpen (aktive window's bar background)
  1338.     move.l    D0,-(sp)
  1339.     movea.l    wd_WScreen(A3),A0    ; Window's screen
  1340.     jsr    _LVOFreeScreenDrawInfo(A6)
  1341.     move.l    (sp)+,D0
  1342.     movea.l    _GfxBase(A5),A6        ; Restore Base
  1343.     bra.s    .SavePen
  1344. .Read
  1345.     movea.l    A2,A1
  1346.     moveq    #28,D0            ; X
  1347.     moveq    #1,D1            ; Y (room of first vertical pixel)
  1348.     movea.l    _GfxBase(A5),A6
  1349.     jsr    _LVOReadPixel(A6)    ; Get title bar's background colour
  1350. .SavePen
  1351.     move.w    D0,_BgPen(A5)        ; Save colour
  1352. *
  1353. ** Now we have to set the font for the title bar, it's the same like the screen's
  1354. ** default font!
  1355. *
  1356.     movea.l    wd_WScreen(A3),A0    ; The window our screen appears on
  1357.     lea    sc_RastPort(A0),A0    ; Screen's rastport
  1358.     movea.l    rp_Font(A0),A0        ; Default font
  1359.     movea.l    A2,A1            ; Window's title bar rastport
  1360.     jsr    _LVOSetFont(A6)        ; Set font (there isn't one - til now!)
  1361.     movem.l    (sp)+,D0/A2-A3
  1362.  
  1363.     tst.l    _UserFontPtr(A5)    ; Font opened?
  1364.     beq.s    6$
  1365.     move.l    D0,-(sp)
  1366.     movea.l    _WindowPtr(A5),A1
  1367.     movea.l    wd_RPort(A1),A1        ; RastPort
  1368.     move.l    rp_Font(A1),_OldFontPtr(A5)    ; Save old font for later
  1369.     movea.l    _UserFontPtr(A5),A0
  1370.     jsr    _LVOSetFont(A6)        ; Set font the user want
  1371.  
  1372.     move.l    (sp)+,D0
  1373. 6$
  1374.     movea.l    _WindowPtr(A5),A1
  1375.     movea.l    wd_RPort(A1),A1        ; RastPort
  1376.     cmpi.b    #1,rp_Mask(A1)        ; Only one bitplane?
  1377.     beq.s    .okBP            ; Yes...
  1378.     move.b    #%11,rp_Mask(A1)    ; Max. 2 bitplanes for Gfx-output!
  1379. * At the moment (ks 3.0) it's not supported, may be ks 3.1 will support it.
  1380. * If this cause trouble with your 3rd party graphic board, remove the lines.
  1381.  
  1382. .okBP
  1383.     rts
  1384.  
  1385. 7$
  1386.     tst.l    _UserFontPtr(A5)
  1387.     beq.s    8$
  1388.     movea.l    _UserFontPtr(A5),A1
  1389.     movea.l    _GfxBase(A5),A6
  1390.     jsr    _LVOCloseFont(A6)
  1391. 8$
  1392.     moveq    #0,D0
  1393.     lea    _WindowRecord(A5),A0
  1394.     move.w    nw_Height(A0),D0
  1395.     move.l    D0,-(sp)
  1396.     move.w    nw_Width(A0),D0
  1397.     move.l    D0,-(sp)
  1398.     move.w    nw_TopEdge(A0),D0
  1399.     move.l    D0,-(sp)
  1400.     move.w    (A0),D0            ; LeftEdge
  1401.     move.l    D0,-(sp)
  1402.     pea    _ErrorOpenWindowTxt(pc)
  1403.     bsr.w    _FmtDisplay
  1404.     lea    20(sp),sp        ; Restore stack
  1405.     moveq    #0,D0
  1406.     rts
  1407.  
  1408. *******************************************
  1409. *
  1410. * Close the main window.
  1411. * If a font was opened for this window,
  1412. * the system-default font is first set
  1413. * to the window (restored), then the opened
  1414. * font is closed and after that, the window
  1415. * is closed.
  1416. *
  1417. * Inputs: None
  1418. * Results: None
  1419. *
  1420.  
  1421. _CloseWindow
  1422.     tst.l    _UserFontPtr(A5)
  1423.     beq.s    1$
  1424.     movea.l    _GfxBase(A5),A6
  1425.  
  1426.     movea.l    _WindowPtr(A5),A1
  1427.     move.l    wd_RPort(A1),A1
  1428.     movea.l    _OldFontPtr(A5),A0
  1429.     jsr    _LVOSetFont(A6)
  1430.  
  1431.     movea.l    _UserFontPtr(A5),A1
  1432.     jsr    _LVOCloseFont(A6)
  1433.  
  1434. 1$
  1435.     movea.l    _IntuitionBase(A5),A6
  1436.     movea.l    _WindowPtr(A5),A0
  1437.     jmp    _LVOCloseWindow(A6)
  1438.  
  1439. *************************************
  1440. *
  1441. * Short subroutine to set window's name
  1442. * pc-relative.
  1443. *
  1444. * Inputs: None
  1445. * Results: None
  1446. *
  1447.  
  1448. _SetPrefs
  1449.     lea    _WindowRecord(A5),A0
  1450.     lea    _WindowName(pc),A1
  1451.     move.l    A1,nw_Title(A0)
  1452.     rts
  1453.  
  1454. *****************************************
  1455. *
  1456. * Main routine calls this one.
  1457. * This one will jump to the routine which
  1458. * belongs to the key.
  1459. *
  1460. * Inputs: A0 - "_ConBuffer"
  1461. *              Key in "_ConBuffer"
  1462. * Results: None
  1463. * Notes: Never call it via "bsr" or "jsr"!
  1464. *
  1465.  
  1466. _ConsoleEvent
  1467.     cmpi.w    #L_Key,(A0)
  1468.     beq.w    _LoadNew
  1469.     cmpi.w    #E_Key,(A0)
  1470.     beq.w    _EnlargeWindow
  1471.     cmpi.w    #H_Key,(A0)
  1472.     beq.w    _DisplayHelp
  1473.     cmpi.w    #I_Key,(A0)
  1474.     beq.w    _Info
  1475.     cmpi.w    #A_Key,(A0)
  1476.     beq.w    _About
  1477.     tst.l    _TextPtr(A5)
  1478.     beq.w    _Loop
  1479.     move.w    (A0),D0
  1480.     cmpi.b    #CRSR_UP,D0
  1481.     beq.w    _PageUp
  1482.     cmpi.b    #CRSR_DN,D0
  1483.     beq.w    _PageDown
  1484.     cmpi.b    #CRSR_FD,D0
  1485.     beq.w    _OneLineUp
  1486.     cmpi.b    #CRSR_BK,D0
  1487.     beq.w    _OneLineDown
  1488.     cmpi.b    #T_Key,D0
  1489.     beq.w    _Top
  1490.     cmpi.b    #B_Key,D0
  1491.     beq.w    _Bottom
  1492.     cmpi.b    #RETURN,D0
  1493.     beq.w    _OneLineDown
  1494.     cmpi.b    #ENTER,D0
  1495.     beq.w    _OneLineDown
  1496.     cmpi.b    #HOME,D0
  1497.     beq.w    _Top
  1498.     cmpi.b    #END,D0
  1499.     beq.w    _Bottom
  1500.     cmpi.b    #PG_UP,D0
  1501.     beq.w    _PageUp_01
  1502.     cmpi.b    #PG_DN,D0
  1503.     beq.w    _PageDown_01
  1504.     cmpi.b    #R_SHIFT,D0
  1505.     beq.w    _OneLineUp
  1506.     cmpi.b    #W_Key,D0
  1507.     beq.w    _WindowContentsPrt
  1508.     cmpi.b    #PrtSc,D0
  1509.     beq.w    _WindowContentsPrt
  1510.     cmpi.b    #C_Key,D0
  1511.     beq.w    _WindowContensFile
  1512.     cmpi.b    #P_Key,D0
  1513.     beq.w    _Print2Prt
  1514.     cmpi.b    #F_Key,D0
  1515.     beq.s    _Print2File
  1516.     cmpi.b    #R_Key,D0
  1517.     beq.w    _RestorePage
  1518.     cmpi.w    #S_Key,D0
  1519.     beq.w    _SearchSequence
  1520.     cmpi.w    #N_Key,D0
  1521.     beq.w    _ContinueSearch
  1522.     cmpi.b    #HELP_Key,D0
  1523.     bsr.s    _DisplayTitle
  1524.     bra.w    _Loop
  1525.  
  1526. **************************************************
  1527. *
  1528. * Allow counting lines and create new window-title.
  1529. *
  1530. * Inputs: none
  1531. * Results: none
  1532. *
  1533.  
  1534. _DisplayTitle
  1535.     clr.b    _NoLineFlag(A5)        ; Allow to count lines
  1536.     bsr.w    _ComLine        ; Create (modify) window-title
  1537.     rts
  1538.  
  1539. **************************************
  1540. *
  1541. * Set prefs to display the ascii-text,
  1542. * set up registers.
  1543. *
  1544. * Inputs: none
  1545. * Results: A3 - textstart, A2 - textend
  1546. *
  1547.  
  1548. _SetViewerPrefs
  1549.     movea.l    _TextPtr(A5),A4        ; Current text-position
  1550.     addq.l    #2,A4            ; Overread #$200A
  1551.     movea.l    A4,A3            ; Textstart A3
  1552.     movea.l    A4,A2            ;     ^        A2
  1553.     move.l    _FileSize(A5),D0    ; Length file
  1554.     add.l    D0,A2            ; = textend
  1555.     addq.l    #3,A2            ; + #$0200A + 1 byte behind source
  1556.     move.b    #10,(A2)        ; = textend
  1557.     move.l    A3,D5
  1558.     move.l    A3,D6
  1559.     rts
  1560.  
  1561. *************************************
  1562. *
  1563. * Print that ascii-text-file to file.
  1564. *
  1565. * Inputs: none
  1566. * Reslts: none
  1567. *
  1568.  
  1569. _Print2File
  1570.     clr.b    _LoadFlag(A5)        ; Set save-flag
  1571.     tst.b    _ReqFlag(A5)
  1572.     bne.s    1$            ; Requester already opened?
  1573.     bsr.w    OpenReq            ; No...
  1574. 1$
  1575.     bsr.w    _GetFile        ; Get filename
  1576.     cmpi.l    #-1,D0            ; Hard error?
  1577.     beq.w    _CantPrint        ; If so...
  1578.     tst.l    D0            ; No file?
  1579.     bne.s    _PrintFileTO        ; If so...
  1580.     bra.w    _Loop            ; ...and back
  1581.  
  1582. *
  1583. ** Ok, do further...
  1584. *
  1585. _PrintFileTO
  1586.     lea    _PrintFileTxt(pc),A0
  1587.     bsr.w    _DisplayError
  1588.     tst.l    D0            ; User cancelled?
  1589.     beq.s    _DoNotPrint        ; ..then do not write down the file
  1590.  
  1591.     lea    _FileName(A5),A0
  1592.     movea.l    A3,A1            ; Textstart
  1593.     move.l    _FileSize(A5),D0    ; Length file
  1594.     bsr.w    _PrintFile        ; Write down the file
  1595.     bra.w    _Loop            ; ...and end
  1596.  
  1597. ***************************************
  1598. *
  1599. * Write down window contents to a file.
  1600. *
  1601. * Inputs: none
  1602. * Reslts: none
  1603. *
  1604.  
  1605. _WindowContensFile
  1606.     clr.b    _LoadFlag(A5)        ; Indicate loading
  1607.     tst.b    _ReqFlag(A5)
  1608.     bne.s    1$            ; Requester already opened?
  1609.     bsr.w    OpenReq            ; No...
  1610. 1$
  1611.     bsr.w    _GetFile        ; Get filename
  1612.     cmpi.l    #-1,D0            ; Hard error?
  1613.     beq.s    _CantPrint        ; If so...
  1614.     tst.l    D0            ; No file?
  1615.     bne.s    _PrintFileTO_01        ; If so...
  1616.     bra.w    _Loop
  1617.  
  1618. *
  1619. ** Further....
  1620. *
  1621. _PrintFileTO_01
  1622.     lea    _PrintContentsTxt(pc),A0
  1623.     bsr.w    _DisplayError
  1624.     tst.l    D0            ; Right mosebutton?
  1625.     beq.s    _DoNotPrint        ; Then do not write
  1626.     movea.l    D6,A1            ; Current address (current line D6)
  1627.     movea.l    A1,A0
  1628.     move.w    _PageSize(A5),D1    ; Number of lines of one page
  1629.     addq.w    #2,D1            ; plus one line and one for linefeed
  1630.     moveq    #0,D0            ; Counter
  1631. 1$
  1632.     cmpa.l    A2,A0            ; Textend == current textposition?
  1633.     bge.s    2$            ; If so, error
  1634.     addq.w    #1,D0
  1635.     cmpi.b    #10,(A0)+        ; Search for linefeed
  1636.     bne.s    1$
  1637.     dbf    D1,1$            ; Lines of one page
  1638. 2$
  1639.     lea    _FileName(A5),A0    ; The filename
  1640.     bsr.w    _PrintFile        ; Write down file
  1641.     bra.w    _Loop            ; back to main
  1642.  
  1643. *******************************
  1644. *
  1645. * Print window contents to PRT:
  1646. *
  1647. * Inputs: none
  1648. * Reslts: none
  1649. *
  1650.  
  1651. _WindowContentsPrt
  1652.     lea    _FileName(A5),A0
  1653.     move.l    #'PRT:',(A0)+
  1654.     clr.b    (A0)
  1655.     bsr.s    _CheckPrinter        ; Check if printer is turned off or so...
  1656.     bra.s    _PrintFileTO_01
  1657.  
  1658. *
  1659. ** Error handling....
  1660. *
  1661. _DoNotPrint
  1662.     lea    _PrintCancelTxt(pc),A0
  1663.     bsr.w    _DisplayError
  1664.     bra.w    _Loop
  1665. _CantPrint
  1666.     bra.w    _End    
  1667.  
  1668. **************************
  1669. *
  1670. * Print whole file to PRT:
  1671. *
  1672. * Inputs: none
  1673. * Reslts: none
  1674. *
  1675.  
  1676. _Print2Prt
  1677.     lea    _FileName(A5),A0
  1678.     move.l    #'PRT:',(A0)+
  1679.     clr.b    (A0)
  1680.     bsr.s    _CheckPrinter
  1681.     bra.w    _PrintFileTO    
  1682.  
  1683. ****************************************
  1684. *
  1685. * Check printer: uses direct CIA-access.
  1686. * Works only 100% correctly with Epson-
  1687. * printers.
  1688. *
  1689. * Inputs: none
  1690. * Reslts: none
  1691. * Notes: Checking can be disabled
  1692. *
  1693.  
  1694. _CheckPrinter
  1695.     tst.b    _NoCheckPrtFlag(A5)    ; Allowed to check?
  1696.     bne.s    1$
  1697.     move.b    $BFD000,D0        ; CIA PRA
  1698.     cmpi.b    #255,D0
  1699.     beq.s    .PrinterOFF
  1700.     cmpi.b    #253,D0
  1701.     beq.s    .NotOneLine
  1702.     cmpi.b    #255,D0
  1703.     bne.s    .PrinterOFF
  1704. 1$
  1705.     rts
  1706. .PrinterOFF
  1707.     lea    _PrinterOFFTxt(pc),A0
  1708.     bsr.w    _DisplayError
  1709.     addq.l    #4,sp
  1710.     bra.w    _Loop
  1711. .NotOneLine
  1712.     lea    _NotOnelineTxt(pc),A0
  1713.     bsr.w    _DisplayError
  1714.     addq.l    #4,sp
  1715.     bra.w    _Loop
  1716.  
  1717. *********************
  1718. *
  1719. * How to explain....?
  1720. *
  1721.  
  1722. _PageUp
  1723.     move.w    _PageSize(A5),D7    ; ditto
  1724.     bra.w    _LinesUp
  1725. _PageUp_01
  1726.     move.w    _StdPageSize(A5),D7    ; Set scrollwidth
  1727.     addq.w    #1,D7            ; We can display one line more
  1728.     bra.w    _OnePageUp
  1729. _PageDown
  1730.     move.w    _PageSize(A5),D7    ; see above
  1731.     bra.w    _LinesDown
  1732. _PageDown_01
  1733.     move.w    _StdPageSize(A5),D7    ; see above
  1734.     addq.w    #1,D7            ; We can display one line more
  1735.     bra.w    _OnePageDown
  1736. _OneLineUp
  1737.     moveq    #0,D7            ; 1 line!
  1738.     bra.w    _LinesUp
  1739. _OneLineDown
  1740.     moveq    #0,D7            ; ditto
  1741.     bra.w    _LinesDown
  1742. _RestorePage
  1743.     bsr.w    _SetPageWidthAndLen
  1744. _RestorePage_1
  1745.     bsr.w    _RestoreCurrentPage
  1746.     bra.w    _Loop
  1747.  
  1748. ****************************************************
  1749. *
  1750. * Load from Shell overgiven file and set scrollwidth.
  1751. *
  1752. * Inputs: none
  1753. * Reslts: none
  1754. *
  1755.  
  1756. _CLILoad
  1757.     tst.l    arg_2(A5)        ; 2. argument empty?
  1758.     beq.s    1$            ; If so...
  1759.     movea.l    arg_2(A5),A0
  1760.  
  1761. *
  1762. ** Convert chars of second argument to uppercase.
  1763. ** 2. argument should look like this: 1> viewer <textfile> scrollwidth=11
  1764. **                               ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  1765. *
  1766. 2$
  1767.     tst.b    (A0)
  1768.     beq.s    4$
  1769.     cmpi.b    #'@',(A0)
  1770.     bls.s    3$
  1771.     cmpi.b    #'z',(A0)
  1772.     bhi.s    3$
  1773.     bclr    #5,(A0)
  1774. 3$
  1775.     addq.l    #1,A0
  1776.     bra.s    2$
  1777. 4$
  1778.     lea    arg_2(A5),A0
  1779.     clr.l    4(A0)            ; Clear next argument
  1780.     bsr.w    _SetScrollWidth_01    ; Get scrollwidth
  1781. 1$
  1782.     movea.l    arg_1(A5),A0        ; Address 1. argument (filename)
  1783.     lea    _FileName(A5),A1    ; Address buffer for filename
  1784. _StoreArgName
  1785.     move.b    (A0)+,(A1)+        ; Copy argument
  1786.     tst.b    -1(A0)
  1787.     bne.s    _StoreArgName    
  1788.     bra.s    _ReadIn
  1789.  
  1790. *******************************************
  1791. *
  1792. * Startup to load workbench overgiven file.
  1793. *
  1794. * Inputs: none
  1795. * Results: none
  1796. *
  1797.  
  1798. _WBLoad
  1799.     tst.l    lock_1(A5)        ; Lock to dir?
  1800.     beq.s    1$            ; No...
  1801.     move.l    lock_1(A5),D1
  1802.     movea.l    _DOSBase(A5),A6
  1803.     jsr    _LVOCurrentDir(A6)    ; else set as current directory
  1804. 1$
  1805.     tst.l    file_1(A5)
  1806.     beq.w    _InitRequester
  1807.  
  1808.     movea.l    file_1(A5),A0        ; Address name from file
  1809.     lea    _FileName(A5),A1
  1810.     bra.s    _StoreArgName
  1811.  
  1812. *****************************************
  1813. *
  1814. * Build requester, check file, read file.
  1815. *
  1816. * Inputs: none
  1817. * Results: none
  1818. *
  1819.  
  1820. _LoadNew
  1821.     st.b    _LoadFlag(A5)        ; Flag == load
  1822.     tst.b    _ReqFlag(A5)
  1823.     bne.s    1$            ; Requester already opened?
  1824.     bsr.w    OpenReq            ; No...
  1825. 1$
  1826.     bsr.w    _GetFile        ; Get filename
  1827.     tst.l    D0
  1828.     bmi.w    _End_1            ; Hard error?
  1829.     tst.l    D0
  1830.     beq.w    _Loop            ; No file?
  1831. _ReadIn
  1832.     bsr.w    _FreeAudio
  1833.  
  1834.     bsr.w    _ReadFile        ; Read file in
  1835.     tst.l    D0            ; Error?
  1836.     beq.w    _Loop            ; If so...
  1837.  
  1838.     bsr.w    _ClearWindow        ; Erase window contents
  1839.  
  1840.     bsr.w    _CheckFile        ; Check if ASCII, PP-crunched or IFF-screen
  1841.  
  1842.     bsr.w    _IgnoreSettings        ; ANSI-filter
  1843.  
  1844. *    bsr.w    _SetViewerPrefs        ; Set up ascii-file to display
  1845.  
  1846.     bra.w    _FirstPage        ; Display first page
  1847.  
  1848. *********************************************
  1849. *
  1850. * Display first page of ascii-text in window.
  1851. *
  1852. * Inputs: none
  1853. * Results: none
  1854. *
  1855.  
  1856. _Top
  1857.     bra.w    _FirstPage        ; Display first page
  1858.  
  1859. *********************************************
  1860. *
  1861. * Display last page of ascii-text in window.
  1862. *
  1863. * Inputs: none
  1864. * Results: none
  1865. *
  1866.  
  1867. _Bottom
  1868.     bra.w    _LastPage
  1869.  
  1870. **********************************************
  1871. *
  1872. * Page up - clear window and write down string
  1873. *
  1874. * Inputs: D5 == Address of last char in window (or NULL)
  1875. *         D6 == Address of 1. char in window
  1876. *         D7 == Number of lines to scroll (display)
  1877. *         A2 == Address last char of text
  1878. *         A3 == Address first char of text
  1879. *         A4 == used
  1880. * Results:
  1881. *      D5 == Address of last char in window
  1882. *         D6 == Address of 1. char in window
  1883. *
  1884.  
  1885. _OnePageUp
  1886.     movea.l    D6,A4
  1887.     movea.l    A4,A0
  1888.     subq.l    #4,A0            ; Any chars to display?
  1889.     cmpa.l    A3,A0
  1890.     bls.w    _Loop            ; If not...
  1891.  
  1892.     bsr.w    _ClearWindow
  1893.  
  1894.     moveq    #0,D2            ; Number of chars!
  1895. 0$
  1896.     cmpa.l    A3,A4            ; A3 == lowest address, A4 == current address, does it fit?
  1897.     bls.s    6$            ; If not...
  1898.  
  1899. 1$
  1900.     moveq    #0,D0            ; Counter for number of chars
  1901. 2$
  1902.     addq.w    #1,D0            ; Else counter for number of chars plus 1
  1903.     subq.l    #1,A4
  1904.     cmpi.b    #10,(A4)        ; Next line?
  1905.     bne.s    2$
  1906.     add.w    D0,D2
  1907. 3$    
  1908.     tst.b    _NoLineFlag(A5)        ; Counting lines allowed?
  1909.     bne.s    4$            ; No...
  1910.     subq.l    #1,_Line(A5)
  1911. 4$
  1912.     move.l    A4,D6            ; Remember startaddress of string in D6 as next pointer
  1913. *                      for LinesUp-routine
  1914.     movea.l    D5,A0            ; Address last char in window
  1915. 5$
  1916.     cmpi.b    #10,-(A0)        ; Find LineFeed
  1917.     bne.s    5$
  1918.     move.l    A0,D5            ; New address last char in window
  1919.  
  1920.     dbf    D7,0$
  1921.  
  1922.     move.l    D2,-(sp)
  1923.     lea    _ConBuffer(A5),A0    ; Address buffer
  1924.     move.w    #$9B48,(A0)        ; Cursor Home
  1925.     moveq    #2,D0            ; 2 chars for output
  1926.     bsr.w    _ConOut_Rel        ; Output
  1927.     move.l    (sp)+,D0
  1928.  
  1929.     movea.l    A4,A0
  1930.     addq.l    #1,A0
  1931.     subq.w    #1,D0
  1932.     bsr.w    _ConOut_Reloc        ; Print down those lines
  1933.  
  1934.     bra.w    _Loop
  1935.  
  1936. 6$
  1937.     bsr.w    _RestoreCurrentPage
  1938.     bra.w    _Loop
  1939.  
  1940. ***********************************************
  1941. *
  1942. * Number of lines to scroll up....
  1943. *
  1944. * Inputs: D5 == Address of last char in window (or NULL)
  1945. *         D6 == Address of 1. char in window
  1946. *         D7 == Number of lines to scroll (display)
  1947. *         A2 == Address last char of text
  1948. *         A3 == Address first char of text
  1949. *         A4 == used
  1950. * Results:
  1951. *      D5 == Address of last char in window
  1952. *         D6 == Address of 1. char in window
  1953. *
  1954.  
  1955. _LinesUp
  1956.     movea.l    D6,A4            ; Last address from LinesDown as current address for us
  1957. 0$
  1958.     cmpa.l    A3,A4            ; A3 == lowest address, A4 == current address, does it fit?
  1959.     bls.w    _Loop            ; If not...
  1960.  
  1961.     lea    _ConBuffer(A5),A0    ; Address buffer
  1962.     move.w    #$9B48,(A0)+        ; Cursor Home
  1963.     move.l    #$9B314100,(A0)        ; Scroll 1 line up
  1964.     moveq    #5,D0            ; 5 chars for output
  1965.     bsr.w    _ConOut_Rel        ; Output
  1966. 1$
  1967.     moveq    #0,D0            ; Counter for number of chars
  1968. 2$
  1969.     addq.w    #1,D0            ; Else counter for number of chars plus 1
  1970.     subq.l    #1,A4
  1971.     cmpi.b    #10,(A4)
  1972.     bne.s    2$
  1973. 3$    
  1974.     tst.b    _NoLineFlag(A5)        ; Counting lines allowed?
  1975.     bne.s    4$            ; No...
  1976.     subq.l    #1,_Line(A5)
  1977. 4$
  1978.     movea.l    A4,A0
  1979.     addq.l    #1,A0
  1980.     subq.w    #1,D0
  1981.     bsr.w    _ConOut_Reloc        ; Print down the line
  1982.  
  1983.     move.l    A4,D6            ; Remember startaddress of string in D6 as next pointer
  1984. *                      for LinesUp-routine
  1985.     movea.l    D5,A0            ; Address last char in window
  1986. 5$
  1987.     cmpi.b    #10,-(A0)        ; Find LineFeed
  1988.     bne.s    5$
  1989.     move.l    A0,D5            ; New address last char in window
  1990.  
  1991.     dbf    D7,0$
  1992.  
  1993.     bra.w    _Loop
  1994.  
  1995. *******************************************************************
  1996. *
  1997. * Scroll down one complete page an write to freed room the strings.
  1998. *
  1999. * Inputs: D5 == Address of last char in window (or NULL)
  2000. *         D6 == Address of 1. char in window
  2001. *         D7 == Number of lines to scroll (display)
  2002. *         A2 == Address last char of text
  2003. *         A3 == Address first char of text
  2004. *         A4 == used
  2005. * Results:
  2006. *      D5 == Address of last char in window
  2007. *         D6 == Address of 1. char in window
  2008. *
  2009.  
  2010. _OnePageDown
  2011.     movea.l    D5,A4            ; Last address char in window
  2012.     movea.l    A4,A0
  2013.     addq.l    #2,A0            ; At least a few bytes to display?
  2014.     cmpa.l    A2,A0            ; Does it fit?
  2015.     bge.w    _Loop
  2016.  
  2017.     bsr.w    _ClearWindow
  2018.     addq.l    #1,A4            ; Ignore introducing LineFeed
  2019.  
  2020.     lea    _ConBuffer(A5),A0
  2021.     move.w    #$9B48,(A0)
  2022.     moveq    #2,D0
  2023.     bsr.w    _ConOut_Rel
  2024.  
  2025.     bra.s    _Lines_Down
  2026.  
  2027. **************************************************************
  2028. *
  2029. * Scroll down and print contents, number of lines: ScrollWidth.
  2030. *
  2031. * Inputs: D5 == Address of last char in window (or NULL)
  2032. *         D6 == Address of 1. char in window
  2033. *         D7 == Number of lines to scroll (display)
  2034. *         A2 == Address last char of text
  2035. *         A3 == Address first char of text
  2036. *         A4 == used
  2037. * Results:
  2038. *      D5 == Address of last char in window
  2039. *         D6 == Address of 1. char in window
  2040. *
  2041.  
  2042. _LinesDown
  2043.     movea.l    D5,A4            ; Last address char in window
  2044.     cmpa.l    A2,A4            ; Does it fit?
  2045.     bge.w    _Loop
  2046.  
  2047.     lea    _ConBuffer(A5),A0
  2048.     move.l    #$9B393939,(A0)+    ; Cursor End of Display
  2049.     move.b    #$48,(A0)        ; <CSI>999H
  2050.     moveq    #5,D0
  2051.     bsr.w    _ConOut_Rel
  2052.  
  2053. _Lines_Down
  2054.     movea.l    A4,A0
  2055.     moveq    #0,D0            ; Counter for number of chars
  2056. 1$
  2057.     cmpa.l    A2,A4            ; A2 == highest address, A4 == current
  2058.     bge.w    _Loop
  2059.  
  2060.     addq.w    #1,D0            ; Counter for chars plus 1
  2061.     addq.l    #1,A4
  2062.     cmpi.b    #10,(A4)        ; LineFeed?
  2063.     bne.s    1$            ; If not, do it further
  2064.     bsr.w    _ConOut_Reloc        ; Print down one line
  2065.  
  2066.     move.l    A4,D5            ; Last char address in window
  2067.     movea.l    D6,A0            ; First char in window
  2068. 2$
  2069.     addq.l    #1,A0
  2070.     cmpi.b    #10,(A0)        ; LineFeed (next line)?
  2071.     bne.s    2$
  2072.     move.l    A0,D6            ; New address (first char in window)
  2073.  
  2074.     tst.b    _NoLineFlag(A5)        ; Allowed to count lines?
  2075.     bne.s    3$            ; No...
  2076.     addq.l    #1,_Line(A5)
  2077. 3$
  2078.     dbf    D7,_Lines_Down        ; Number of lines
  2079.  
  2080.     bra.w    _Loop    
  2081.  
  2082. *********************************
  2083. *
  2084. * Restore current window contents
  2085. *
  2086. * Inputs: D5 == Address of last char in window (or NULL)
  2087. *         D6 == Address of 1. char in window
  2088. *         A2 == Address last char of text
  2089. *         A3 == Address first char of text
  2090. *         A4 == used
  2091. * Results:
  2092. *      D5 == Address of last char in window
  2093. *         D6 == Address of 1. char in window
  2094. *
  2095.  
  2096. _RestoreCurrentPage
  2097.     tst.l    _BufferSize(A5)        ; Any datas to display out there?
  2098.     beq.s    2$            ; If not...
  2099.  
  2100.     move.l    D6,D5            ; Last address == current
  2101.     addq.l    #1,D5            ; Ignore introducing linefeed
  2102.  
  2103.     move.w    _StdPageSize(A5),D7
  2104.     addq.w    #1,D7
  2105.  
  2106.     movea.l    D5,A4            ; Last address char in window
  2107.     cmpa.l    A2,A4            ; Does it fit?
  2108.     bge.s    2$
  2109.  
  2110.     lea    _ConBuffer(A5),A0    ; Address buffer
  2111.     move.l    #$1B5B306D,(A0)+    ; Reset display
  2112.     move.l    #$9B639B48,(A0)+    ; Reset console and Cursor Home
  2113.     move.l    #$9B4A9B48,(A0)        ; Erase to end of display Cursor Home
  2114.     moveq    #12,D0            ; 12 chars for output
  2115.     bsr.w    _ConOut_Rel        ; Output
  2116.  
  2117. 0$
  2118.     movea.l    A4,A0
  2119.     moveq    #0,D0            ; Counter for number of chars
  2120. 1$
  2121.     cmpa.l    A2,A4            ; A2 == highest address, A4 == current
  2122.     bge.s    2$
  2123.  
  2124.     addq.w    #1,D0            ; Counter for chars plus 1
  2125.     addq.l    #1,A4
  2126.     cmpi.b    #10,(A4)        ; LineFeed?
  2127.     bne.s    1$            ; If not, do it further
  2128.     bsr.w    _ConOut_Reloc        ; Print down one line
  2129.  
  2130.     move.l    A4,D5            ; Last char address in window
  2131.     dbf    D7,0$            ; Number of lines
  2132. 2$
  2133.     rts
  2134.  
  2135. ***************************************
  2136. *
  2137. * Display first page of ascii-text-file
  2138. *
  2139. * Inputs: D5 == Address of last char in window (or NULL)
  2140. *         D6 == Address of 1. char in window
  2141. *         A2 == Address last char of text
  2142. *         A3 == Address first char of text
  2143. *         A4 == used
  2144. * Results:
  2145. *      D5 == Address of last char in window
  2146. *         D6 == Address of 1. char in window
  2147. *
  2148.  
  2149. _FirstPage
  2150.     bsr.w    _SetViewerPrefs        ; Prefs == as on start!
  2151.  
  2152.     moveq    #0,D7
  2153.     move.w    _StdPageSize(A5),D7
  2154.     addq.w    #1,D7
  2155.     move.l    D7,_Line(A5)        ; == number of lines that "are" displayed"!?"
  2156.  
  2157.     movea.l    D5,A4            ; Last address char in window
  2158.     cmpa.l    A2,A4            ; Does it fit?
  2159.     bge.w    _Loop
  2160.  
  2161.     lea    _ConBuffer(A5),A0    ; Address buffer
  2162.     move.l    #$1B5B306D,(A0)+    ; Reset display
  2163.     move.l    #$9B639B48,(A0)+    ; Reset and Cursor Home
  2164.     move.l    #$9B4A9B48,(A0)        ; Erase to end of display + Cursor Home
  2165.     moveq    #12,D0            ; 12 chars for output
  2166.     bsr.w    _ConOut_Rel        ; Output
  2167. 0$
  2168.     movea.l    A4,A0
  2169.     moveq    #0,D0            ; Counter for number of chars
  2170. 1$
  2171.     cmpa.l    A2,A4            ; A2 == highest address, A4 == current
  2172.     bge.w    _Loop
  2173.  
  2174.     addq.w    #1,D0            ; Counter for chars plus 1
  2175.     addq.l    #1,A4
  2176.     cmpi.b    #10,(A4)        ; LineFeed?
  2177.     bne.s    1$            ; If not, do it further
  2178.     bsr.w    _ConOut_Reloc        ; Print down one line
  2179.  
  2180.     move.l    A4,D5            ; Last char's address in window
  2181.     dbf    D7,0$            ; Number of lines
  2182.  
  2183.     bra.w    _Loop    
  2184.  
  2185. **************************************
  2186. *
  2187. * Display last page of ascii-text-file
  2188. *
  2189. * Inputs: D5 == Address of last char in window (or NULL)
  2190. *         D6 == Address of 1. char in window
  2191. *         A2 == Address last char of text
  2192. *         A3 == Address first char of text
  2193. *         A4 == used
  2194. * Results:
  2195. *      D5 == Address of last char in window
  2196. *         D6 == Address of 1. char in window
  2197. *
  2198.  
  2199. _LastPage
  2200.     move.l    A2,D5            ; Highest address as current for LinesDown
  2201.     move.l    D5,D6            ; Highest address as current for us!
  2202.  
  2203.     lea    _ConBuffer(A5),A0    ; Address buffer
  2204.     move.l    #$1B5B306D,(A0)+    ; Reset display
  2205.     move.l    #$9B639B48,(A0)+    ; Reset console and Cursor Home
  2206.     move.w    #$9B4A,(A0)        ; Erase to end of display + Cursor Home
  2207.     moveq    #10,D0            ; 10 chars for output
  2208.     bsr.w    _ConOut_Rel        ; Output
  2209.  
  2210.     move.w    _StdPageSize(A5),D7    ; Number of scrolls
  2211.     addq.w    #1,D7            ; Plus 1
  2212.  
  2213.     movea.l    D6,A4
  2214. 0$
  2215.     cmpa.l    A3,A4            ; A3 == lowest address, A4 == current address, does it fit?
  2216.     bls.w    _Loop            ; If not...
  2217.  
  2218.     lea    _ConBuffer(A5),A0    ; Address buffer
  2219.     move.w    #$9B48,(A0)+        ; Cursor Home
  2220.     move.l    #$9B314100,(A0)        ; Scroll 1 line up
  2221.     moveq    #5,D0            ; 5 chars for output
  2222.     bsr.w    _ConOut_Rel        ; Output
  2223. 1$
  2224.     moveq    #0,D0            ; Counter for number of chars
  2225. 2$
  2226.     addq.w    #1,D0            ; Counter for number of chars plus 1
  2227.     subq.l    #1,A4            ; Next char
  2228.     cmpi.b    #10,(A4)        ; Next line?
  2229.     bne.s    2$
  2230.  
  2231.     movea.l    A4,A0
  2232.     addq.l    #1,A0
  2233.     subq.w    #1,D0
  2234.     bsr.w    _ConOut_Reloc        ; Print down the line
  2235.  
  2236.     move.l    A4,D6            ; Remember startaddress of string in D6 as next pointer
  2237. *                      for LinesUp-routine
  2238.     dbf    D7,0$
  2239.  
  2240.     move.l    _LinesInFile(A5),D0    ; How many lines in file?
  2241.     addq.l    #1,D0
  2242.     move.l    D0,_Line(A5)        ; = lines
  2243.  
  2244.     bra.w    _Loop
  2245.  
  2246. ************************
  2247. *
  2248. * Make cursor invisible.
  2249. *
  2250. * Inputs: none
  2251. * Results: none
  2252. *
  2253.  
  2254. _CursorOff
  2255.     clr.l    -(sp)
  2256.     movea.l    sp,A0
  2257.     move.b    #$9B,(A0)
  2258.     move.b    #'0',1(A0)
  2259.     move.b    #' ',2(A0)
  2260.     move.b    #'p',3(A0)
  2261.     moveq    #4,D0
  2262.     bsr.w    _ConOut_Reloc        ; Output
  2263.     addq.l    #4,sp
  2264.     rts
  2265.  
  2266. _CursorOn
  2267.     clr.l    -(sp)
  2268.     movea.l    sp,A0
  2269.     move.b    #$9B,(A0)
  2270.     move.b    #' ',1(A0)
  2271.     move.b    #'p',2(A0)
  2272.     moveq    #3,D0
  2273.     bsr.w    _ConOut_Reloc        ; Output
  2274.     addq.l    #4,sp
  2275.     rts
  2276.  
  2277. ****************************************************************
  2278. *
  2279. * Twist pointer for system-requester so that system-requesters
  2280. * which mean us, will appear on our window; must be done because
  2281. * any other screen as the Workbench's one can be used by Viewer.
  2282. *
  2283. * Inputs: none
  2284. * Results: none
  2285. *
  2286.  
  2287. _SetPtr4Req
  2288.     movea.l    _OwnTask(A5),A0
  2289.     move.l    pr_WindowPtr(A0),_StdprWindowPtr(A5)    ; Save default pointer
  2290.     move.l    _WindowPtr(A5),pr_WindowPtr(A0)        ; Twist
  2291.     rts
  2292.  
  2293. ***********************************************
  2294. *
  2295. * Find in tooltypes a string which tells us to make a
  2296. * word warp when the contents of one line do not fit
  2297. * in one line (window limits)
  2298. *
  2299. * Inputs: none
  2300. * Results: none
  2301. *
  2302.  
  2303. _CheckWrap
  2304.     lea    WB_arg_1(A5),A0
  2305. 1$
  2306.     tst.l    (A0)            ; Any argument?
  2307.     beq.s    4$
  2308.  
  2309.     movea.l    (A0)+,A1
  2310.     lea    _WrapDef(pc),A2        ; String to compare
  2311.     moveq    #7,D0
  2312. 2$
  2313.     cmpm.b    (A1)+,(A2)+
  2314.     bne.s    1$
  2315.     dbf    D0,2$
  2316.     st.b    _WrapFlag(A5)        ; Set flag
  2317. 4$
  2318.     rts
  2319.  
  2320. *************************************************
  2321. *
  2322. * Get window limits out of tooltypes,
  2323. * (EXTENTWINDOW=<width>,<height>)
  2324. *
  2325. * Inputs: (GetNextArg() - pointer to string in A0
  2326. * Results: none
  2327. *
  2328.  
  2329. _SetWindow                ; Only if WB-start!!!
  2330.     lea    WB_arg_1(A5),A0
  2331. _GetNextArg                ; this one for the Shell
  2332. 1$
  2333.     tst.l    (A0)            ; Argument there?
  2334.     beq.s    .EndSetWindow        ; No
  2335.     movea.l    (A0)+,A1        ; Address overgiven string
  2336.     lea    _WindowDef(pc),A2    ; Address string to compare
  2337.     moveq    #12,D0            ; 13 chars to compare
  2338. 3$
  2339.     cmpm.b    (A1)+,(A2)+        ; Compare strings
  2340.     bne.s    1$            ; "EXTENTWINDOW="
  2341.     dbf    D0,3$
  2342.  
  2343.     moveq    #0,D0            ; Fill up (no mask)
  2344.     movea.l    A1,A0            ; A0 string (contains value)
  2345.     bsr.w    _StrToLong
  2346.     tst.l    D1            ; Error?
  2347.     bmi.s    .EndSetWindow
  2348.  
  2349. .SetWidth
  2350.     lea    _WindowRecord(A5),A3    ; Address window-record
  2351.     move.w    D0,nw_Width(A3)        ; Set width
  2352.  
  2353.     moveq    #0,D0            ; No mask
  2354. * String to convert already in A0
  2355.     bsr.w    _StrToLong
  2356.     tst.l    D1
  2357.     bmi.s    .EndSetWindow
  2358.  
  2359. .SetHeight
  2360.     lea    _WindowRecord(A5),A3    ; Window-record
  2361.     move.w    D0,nw_Height(A3)    ; Set height
  2362.  
  2363. .EndSetWindow
  2364.     rts
  2365.  
  2366. *********************************************************
  2367. *
  2368. * Set scrollwidth, user has to specify it on his own,
  2369. * tooltyes or Shell.
  2370. *
  2371. * Inputs: (SetScrollWidth_01() - only Shell: A0 - string)
  2372. * Results: none
  2373. *
  2374.  
  2375. _SetScrollWidth                ; Only available from Workbench
  2376.     lea    WB_arg_1(A5),A0        ; Address constant of 1. argument
  2377. _SetScrollWidth_01            ; Jumpmark for Shell use
  2378.     tst.l    (A0)            ; Address 1. argument there?
  2379.     beq.s    1$
  2380.  
  2381.     movea.l    (A0)+,A1        ; Out of it address 1. argument
  2382.     lea    _PageDef(pc),A2
  2383.     moveq    #11,D0            ; 12 loops
  2384. 2$
  2385.     cmpm.b    (A1)+,(A2)+        ; Compare char for char
  2386.     bne.s    _SetScrollWidth_01    ; "SCROLLWIDTH="
  2387.     dbf    D0,2$
  2388.  
  2389.     moveq    #0,D0            ; No mask
  2390.     movea.l    A1,A0            ; Text into A0    
  2391.     bsr.w    _StrToLong        ; Get value
  2392.     cmpi.l    #-1,D1            ; On error
  2393.     beq.s    1$
  2394.     subq.w    #1,D0            ; Because scrolling can be done once more!
  2395.     move.w    D0,_PageSize(A5)    ; Set length to scroll
  2396.     st.b    _PageSizeFlag(A5)    ; Set flag
  2397. 1$
  2398.     rts
  2399.  
  2400. ****************************************************
  2401. *
  2402. * Get from and only! from Workbench overgiven file,
  2403. * may be specified in the defaulttool of the project-
  2404. * icon of a file.
  2405. *
  2406. * Inputs: none
  2407. * Results: none
  2408. *
  2409.  
  2410. _SetDirection
  2411.     tst.l    _argc(A5)        ; Any argument?
  2412.     beq.s    2$            ; If not...
  2413.  
  2414.     move.l    lock_1(A5),D1        ; Get the lock to the file
  2415.     beq.s    3$
  2416.     movea.l    _DOSBase(A5),A6
  2417.     jsr    _LVOCurrentDir(A6)    ; Change current directory to project's one
  2418. 3$
  2419.     tst.l    file_1(A5)        ; No file?
  2420.     beq.s    2$
  2421.  
  2422.     movea.l    file_1(A5),A0        ; Name of file
  2423.     tst.l    _IconBase(A5)
  2424.     beq.s    2$
  2425.     movea.l    _IconBase(A5),A6
  2426.     jsr    _LVOGetDiskObject(A6)    ; Load ".info"-file
  2427.     move.l    D0,_UserProject(A5)    ; Save its handle
  2428.     movea.l    D0,A0            ; Pointer to entries A0
  2429.     tst.l    D0
  2430.     beq.s    2$            ; Upon error
  2431.  
  2432.     movea.l    do_ToolTypes(A0),A0    ; Get those tooltype-pointer
  2433.     move.l    A0,_ToolTypesArray(A5)
  2434.  
  2435.     moveq    #14,D0            ; Allow 15 entries to be stored
  2436.     lea    WB_arg_1(A5),A1        ; Address for 1. argument
  2437. 1$
  2438.     move.l    (A0)+,(A1)+        ; Save these pointers
  2439.     beq.s    2$            ; Last pointer?
  2440.     dbf    D0,1$            ; No...
  2441. 2$
  2442.     rts
  2443.  
  2444. *************************************************
  2445. *
  2446. * Get page width and length in lines. Do it via a
  2447. * console status report.
  2448. *
  2449. * Maximums for now:
  2450. * 999 lines and 999 columns.
  2451. * The console will report if we set the limits to
  2452. * 999 the maximum which is displayable, e.g.
  2453. * <CSI>20;78R - mean 20 lines and 78 columns.
  2454. *
  2455. * Inputs: none
  2456. * Results: none
  2457. *
  2458.  
  2459. _SetPageWidthAndLen
  2460.     movem.l    D0-D7/A0-A6,-(sp)
  2461. .GetConReport
  2462.     lea    _ConBuffer(A5),A0
  2463.     move.l    #$9B39393B,(A0)+    ; Move Cursor <CSI>99; [ NOTEZ-BIEN: We cannot use 999
  2464. *                      here - due to the below menitioned bug! ]
  2465.     move.l    #$39393948,(A0)+    ; 999H - here it works...
  2466.     moveq    #8,D0
  2467.     bsr.w    _ConOut_Rel
  2468.  
  2469.     lea    _ConBuffer(A5),A0
  2470.     move.l    #$9B393939,(A0)+    ; Because of a bug in the con-routines
  2471.     move.b    #'B',(A0)        ; we have to set the cursor as single CSI
  2472.     moveq    #5,D0            ; to end of the display (<CSI>999B
  2473.     bsr.w    _ConOut_Rel
  2474.  
  2475.     lea    _ConBuffer(A5),A0
  2476.     move.l    #$9B366E00,(A0)+    ; Console Device Status Report
  2477. *                      <CSI>6n
  2478.     moveq    #3,D0            ; 3 chars
  2479.     bsr.w    _ConOut_Rel        ; Output
  2480.     lea    _ConBuffer(A5),A0
  2481.     moveq    #20,D0
  2482. .ClearIt
  2483.     clr.b    (A0)+
  2484.     dbf    D0,.ClearIt
  2485. 1$
  2486.     bsr.w    _GetConMsg        ; Get the message from the console-device
  2487.     tst.l    D0            ; Message?
  2488.     beq.s    1$
  2489.     movea.l    D0,A1
  2490.     jsr    _LVOReplyMsg(A6)
  2491.  
  2492.     lea    _ConBuffer(A5),A0
  2493.     addq.l    #1,A0
  2494.     move.l    A0,D2
  2495.     move.l    _stdout(A5),D1
  2496.     beq.s    8$
  2497.     moveq    #7,D3
  2498.     movea.l    _DOSBase(A5),A6        ; Print message to Shell-window
  2499.     jsr    _LVOWrite(A6)
  2500. 8$
  2501.  
  2502.     lea    _ConBuffer(A5),A0
  2503.     addq.l    #1,A0            ; Overread CSI
  2504.  
  2505.     moveq    #0,D0            ; No mask
  2506.     bsr.w    _StrToLong        ; Get value
  2507.     cmpi.l    #-1,D1            ; Error ?
  2508.     bne.s    2$
  2509.     cmpi.b    #';',-1(A0)        ; Last char the semicolon?
  2510.     beq.s    2$            ; If so, it is ok
  2511.     bra.w    .GetConReport        ; Upon error
  2512. 2$
  2513.     subq.w    #2,D0            ; Minus 2 = scrollwidth
  2514.     move.w    D0,_StdPageSize(A5)    ; Standard scrollwidth
  2515.     tst.b    _PageSizeFlag(A5)    ; Already defined (ToolTypes)?
  2516.     bne.s    3$            ; If so...
  2517.     move.w    D0,_PageSize(A5)    ; Else save it
  2518. 3$
  2519. *
  2520. ** Get count which stays after the semicolon
  2521. ** (returned by the status-report)
  2522. *
  2523.     moveq    #0,D0            ; No mask
  2524.     bsr.w    _StrToLong        ; Get value
  2525.     cmpi.l    #-1,D1            ; Error ?
  2526.     bne.s    4$
  2527.     cmpi.b    #'R',-1(A0)        ; Last char the 'R'?
  2528.     beq.s    4$            ; If so, it is ok
  2529.     bra.w    .GetConReport        ; Else get new
  2530. 4$
  2531.     subq.w    #1,D0
  2532.     move.l    D0,_PageWidth(A5)    ; Set max. length
  2533.  
  2534.     lea    _IOInlineBuf(A5),A0
  2535.     move.b    #10,(A0)+
  2536.     move.l    _PageWidth(A5),D0    
  2537.     bsr.w    _comdec
  2538.     move.b    #10,(A0)+
  2539.     clr.b    (A0)
  2540.     lea    _IOInlineBuf(A5),A0
  2541.     move.l    _stdout(A5),D1
  2542.     beq.s    6$
  2543.     move.l    A0,D2
  2544.     moveq    #-1,D3
  2545. 7$
  2546.     tst.b    (A0)+
  2547.     dbeq    D3,7$
  2548.     not.l    D3
  2549.     movea.l    _DOSBase(A5),A6
  2550.     jsr    _LVOWrite(A6)        ; Print down settings to Shell-window
  2551. 6$
  2552.     movem.l    (sp)+,D0-D7/A0-A6
  2553. 5$
  2554.     rts
  2555.  
  2556. ********************************************************************
  2557. *
  2558. * Open and init a filerequester, only Arp and ReqTools supported yet.
  2559. *
  2560. *
  2561. * Inputs: none
  2562. * Results: Gloabal Flag ("_ReqFlag), indicates which requester is used,
  2563. *                  1 ReqTools
  2564. *                  2 Arp
  2565. *                 -1 failed to open (hard error)
  2566. *
  2567.  
  2568. OpenReq
  2569.     tst.l    _ReqPtr(A5)
  2570.     bne.s    1$
  2571.     movea.l    _SysBase(A5),A6
  2572.     moveq    #37,D0
  2573.     lea    _ReqToolsName(pc),A1
  2574.     jsr    _LVOOpenLibrary(A6)
  2575.     move.l    D0,_ReqToolsBase(A5)
  2576.     beq.s    _ArpReq            ; If it failed...
  2577.     movea.l    _ReqToolsBase(A5),A6    ; else
  2578.     moveq    #0,D0            ; Must be NULL for the moment
  2579.     suba.l    A0,A0            ; (Tags) ditto
  2580.     jsr    _LVOrtAllocRequestA(A6)    ; Allocate structure
  2581.     move.l    D0,_ReqPtr(A5)
  2582.     beq.s    .noReqToolsReq        ; Upon error
  2583. 1$
  2584.     move.b    #1,_ReqFlag(A5)        ; Say: ok reqtools
  2585.     rts
  2586. .noReqToolsReq
  2587.     movea.l    A6,A1
  2588.     movea.l    _SysBase(A5),A6
  2589.     jsr    _LVOCloseLibrary(A6)
  2590.     clr.l    _ReqToolsBase(A5)    ; Important!!!
  2591.  
  2592. _ArpReq
  2593.     tst.l    _ArpBase(A5)
  2594.     bne.s    2$
  2595.     movea.l    _SysBase(A5),A6
  2596.     moveq    #39,D0
  2597.     lea    _ArpName(pc),A1
  2598.     jsr    _LVOOpenLibrary(A6)
  2599.     move.l    D0,_ArpBase(A5)
  2600.     beq.s    .NoArp            ; Hard error, failed to open any requester!
  2601.     bsr.s    _InitReq        ; Init Arp-structure
  2602. 2$
  2603.     move.b    #2,_ReqFlag(A5)        ; Flag for Ok Arp
  2604.     rts
  2605.  
  2606. .NoArp
  2607.     move.b    #-1,_ReqFlag(A5)    ; Say: damned, failed to open
  2608.     rts
  2609.  
  2610. **********************************
  2611. *
  2612. * Display ReqTools file-requester.
  2613. *
  2614. * Inputs: none
  2615. * Results: none
  2616. *
  2617.  
  2618. _ReqLoad
  2619.     movem.l    A2-A3,-(sp)
  2620.     suba.l    A0,A0            ; TAG-list
  2621.     movea.l    _ReqPtr(A5),A1        ; ReqTools-structure
  2622.     lea    _File(A5),A2        ; Buffer for filename
  2623.     tst.b    _LoadFlag(A5)        ; Shall we load?
  2624.     bne.s    3$            ; No, save!
  2625.     lea    _SaveTitle(pc),A3    ; Save-string (title-text)
  2626.     bra.s    2$
  2627. 3$
  2628.     lea    _AWTitle(pc),A3        ; Window-title == load
  2629. 2$
  2630.     movea.l    _ReqToolsBase(A5),A6
  2631.     jsr    _LVOrtFileRequestA(A6)
  2632.     tst.l    D0
  2633.     beq.s    4$            ; No file was chosen!
  2634.     lea    _Drive(A5),A1        ; Address buffer for directory
  2635.     movea.l    _ReqPtr(A5),A0        ; Address Requester-structure
  2636.     movea.l    16(A0),A0        ; rtfi_Dir(A0),A0! - pointer to directory
  2637. 1$
  2638.     move.b    (A0)+,(A1)+        ; Copy drive-name
  2639.     tst.b    -1(A0)            ; Copy also NULL-byte
  2640.     bne.s    1$
  2641.     moveq    #1,D0            ; Signal ok
  2642. 4$
  2643.     movem.l    (sp)+,A2-A3
  2644.     rts
  2645.  
  2646. ************************************
  2647. *
  2648. * Initialize Arp-requester structure.
  2649. *
  2650. * Inputs: none
  2651. * Results: none
  2652. *
  2653.  
  2654. _InitReq
  2655.     lea    _ArpReqStruc(A5),A0    ; Address structure
  2656.     lea    _AWTitle(pc),A1        ; Address title for requester
  2657.     move.l    A1,(A0)
  2658.     lea    _File(A5),A1        ; Address buffer for name
  2659.     move.l    A1,4(A0)
  2660.     lea    _Drive(A5),A1        ; Address buffer for directory
  2661.     move.l    A1,8(A0)
  2662.     move.b    #':',_Drive(A5)        ; Say current directory
  2663.     rts
  2664.  
  2665. *****************************
  2666. *
  2667. * Display Arp-file-requester.
  2668. *
  2669. * Inputs: none
  2670. * Results: none
  2671. *
  2672.  
  2673. _ArpLoad
  2674.     movem.l    D2-D7/A2-A6,-(sp)    ; <-I don't trust Arp
  2675.     lea    _ArpReqStruc(A5),A0    ; Address structure
  2676.     tst.b    _LoadFlag(A5)        ; Shall we load a file?
  2677.     bne.s    1$            ; Yes...
  2678.     lea    _SaveTitle(pc),A1    ; Otherwise set saving-title
  2679.     move.l    A1,(A0)
  2680.     bra.s    2$
  2681. 1$
  2682.     lea    _AWTitle(pc),A1        ; Title (Load)
  2683.     move.l    A1,(A0)
  2684. 2$
  2685.     movea.l    _ArpBase(A5),A6
  2686.     lea    _ArpReqStruc(A5),A0    ; Structure of requester
  2687.     jsr    _LVOArpFileRequest(A6)
  2688.     movem.l    (sp)+,D2-D7/A2-A6
  2689.     rts
  2690.  
  2691. ***************************************************
  2692. *
  2693. * Merge volume's/directory's name with file's name.
  2694. *
  2695. * Inputs: none
  2696. * Results: none
  2697. *
  2698.  
  2699. _GetFileName
  2700.     move.l    A2,-(sp)
  2701.     lea    _Drive(A5),A0
  2702.     lea    _File(A5),A1
  2703.     lea    _FileName(A5),A2
  2704. 1$
  2705.     tst.b    (A0)
  2706.     beq.s    2$
  2707.     move.b    (A0)+,(A2)+
  2708.     bra.s    1$
  2709. 2$
  2710.     tst.b    -1(A0)
  2711.     beq.s    3$
  2712.     cmpi.b    #':',-1(A0)
  2713.     beq.s    3$
  2714.     cmpi.b    #'/',-1(A0)
  2715.     beq.s    3$
  2716.     move.b    #'/',(A2)+
  2717. 3$
  2718.     move.b    (A1)+,(A2)+
  2719.     tst.b    -1(A1)
  2720.     bne.s    3$
  2721.     movea.l    (sp)+,A2
  2722.     rts
  2723.  
  2724. ***********************************
  2725. *
  2726. * Startup to display filerequester.
  2727. *
  2728. * Inputs: none
  2729. * Results: D0 == NULL upon error
  2730. *
  2731.  
  2732. *------------------------------------------------------
  2733. _GetFile
  2734.     cmpi.b    #-1,_ReqFlag(A5)    ; No requester at all?
  2735.     beq.s    .NoReqAtAll
  2736.     cmpi.b    #1,_ReqFlag(A5)        ; ReqTools-Load-routine?
  2737.     bne.s    .ArpMustLoad        ; No, Arp
  2738.     bsr.w    _ReqLoad        ; else ReqTools-file-requester
  2739.     tst.l    D0            ; Ok?
  2740.     beq.s    .NoFileGet        ; No, no file selected!
  2741.     bsr.s    _GetFileName        ; Combinate filename in dos-convention
  2742.     moveq    #$11,D0            ; Return ok
  2743.     rts
  2744.  
  2745. .ArpMustLoad
  2746.     bsr.w    _ArpLoad        ; Arp-file-requester
  2747.     tst.l    D0            ; No file?
  2748.     beq.s    .NoFileGet
  2749.     bsr.s    _GetFileName        ; Combinate filename in dos-convention
  2750.     moveq    #$11,D0            ; Return ok.
  2751.     rts
  2752. .NoReqAtAll
  2753.     moveq    #-1,D0            ; Damned, no requester at all!
  2754.     rts
  2755. .NoFileGet                ; No file was selected
  2756.     rts
  2757.  
  2758. ***************************************************************
  2759. *
  2760. * Complex routine which loads a file, sets up needed parameters.
  2761. *
  2762. * Inputs: none
  2763. * Results: D0 - NULL upon error
  2764. *
  2765.  
  2766. _ReadFile
  2767.     movea.l    _SysBase(A5),A6
  2768.     movea.l    _TextPtr(A5),A1
  2769.     move.l    _BufferSize(A5),D0
  2770.     beq.s    1$
  2771.     jsr    _LVOFreeMem(A6)        ; Free last pointed text
  2772.     clr.l    _BufferSize(A5)
  2773.     clr.l    _TextPtr(A5)
  2774.     clr.l    _Line(A5)
  2775.     clr.l    _SearchStrPtr(A5)    ; Don't access what isn't valid....
  2776.     clr.l    _SearchStrLen(A5)
  2777. 1$
  2778.     movea.l    _DOSBase(A5),A6
  2779.     lea    _FileName(A5),A0
  2780.     move.l    A0,D1
  2781.     moveq    #ACCESS_READ,D2        ; Mode: READ
  2782.     jsr    _LVOLock(A6)
  2783.     move.l    D0,_LockSave(A5)    ; Save lock of file
  2784.     beq.w    .LockErr
  2785.     move.l    _LockSave(A5),D1    ; The key to the file
  2786.     lea    _FIB(A5),A0        ; Address FileInfoBlock
  2787.     move.l    A0,D2            ; into D2
  2788.     jsr    _LVOExamine(A6)        ; Get file's status
  2789.     lea    _FIB(A5),A0        ; Address FileInfoBlock
  2790.     tst.l    (A0)            ; Was function Examine successful?
  2791.     beq.w    .ExamineErr        ; No, oh boy
  2792.     move.l    _LockSave(A5),D1    ; Key to D1
  2793.     jsr    _LVOUnLock(A6)        ; Free key
  2794.     lea    _FIB(A5),A0        ; Address FileInfoBlock
  2795.     tst.l    4(A0)            ; Dir or file?
  2796.     bpl.w    .ItsADir        ; Too bad, it's a dir
  2797.     move.l    124(A0),_FileSize(A5)    ; Get size in bytes of file
  2798.     move.l    124(A0),D0        ; also into D0
  2799.     beq.w    .FileEmpty        ; If the file is empty
  2800.     addq.l    #8,D0            ; else filelength plus 8 bytes
  2801.     bsr.w    _MakeCountEven        ; Align count
  2802.  
  2803.     move.l    D0,_BufferSize(A5)    ; Save extended count
  2804.  
  2805.     movea.l    _SysBase(A5),A6
  2806.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  2807.     jsr    _LVOAllocMem(A6)    ; Mem demand
  2808.     move.l    D0,_TextPtr(A5)        ; Save address allocated memory
  2809.     beq.w    .AllocError        ; Upon error...
  2810.  
  2811.     movea.l    _DOSBase(A5),A6
  2812.     lea    _FileName(A5),A0    ; Address string (file's name)
  2813.     move.l    A0,D1            ; into D1
  2814.     move.l    #MODE_OLDFILE,D2    ; Mode = OLD
  2815.     jsr    _LVOOpen(A6)        ; Open file
  2816.     move.l    D0,_FileHandle(A5)    ; Save handle
  2817.     beq.s    .FileOpenErr        ; Upon error
  2818.     move.l    _FileHandle(A5),D1
  2819.     movea.l    _TextPtr(A5),A0        ; Address buffer for file to read in
  2820.     move.w    #$200A,(A0)+        ; Write first a Blank and a LineFeed
  2821.     move.l    A0,D2            ; Current address into D2
  2822.     move.l    _FileSize(A5),D3    ; Length file        
  2823.     jsr    _LVORead(A6)        ; Read file into buffer
  2824.     tst.l    D0
  2825.     bmi.s    .ReadError        ; Upon error
  2826.     bsr.s    .CloseFile        ; Close file
  2827.     movea.l    _TextPtr(A5),A0
  2828.     move.l    _FileSize(A5),D0
  2829.     cmpi.b    #10,1(A0,D0.l)
  2830.     beq.s    .ok
  2831.     move.b    #10,2(A0,D0.l)        ; LineFeed (end)
  2832. .ok
  2833.     moveq    #$11,D0            ; Say ok
  2834.     rts                ; and back
  2835.  
  2836. .ReadError
  2837.     movea.l    _DOSBase(A5),A6        ; - Because of bug in DOS v39
  2838. *                      we have to restore DOSBase....
  2839.     jsr    _LVOIoErr(A6)        ; Get the error
  2840.     bsr.w    _SetError        ; Set the error
  2841.     bsr.s    .CloseFile        ; Close file
  2842.     bsr.w    _FreeFile        ; Free allocated memory
  2843.     lea    _ReadErrTxt(pc),A0    ; Errorstring
  2844.     bsr.w    _DisplayError        ; Tell user...
  2845.     moveq    #0,D0
  2846.     rts
  2847.  
  2848. .CloseFile
  2849.     move.l    A6,-(sp)
  2850.     movea.l    _DOSBase(A5),A6
  2851.     move.l    _FileHandle(A5),D1
  2852.     jsr    _LVOClose(A6)
  2853.     movea.l    (sp)+,A6
  2854.     rts
  2855.  
  2856. .FileOpenErr
  2857.     jsr    _LVOIoErr(A6)        ; Get the error
  2858.     bsr.w    _SetError        ; and set it
  2859.     bsr.w    _FreeFile        ; Free memory
  2860.     lea    _OpenFileErrTxt(pc),A0    ; Errorstring
  2861.     bsr.w    _DisplayError        ; Tell user...
  2862.     moveq    #0,D0
  2863.     rts
  2864.  
  2865. .AllocError
  2866.     movea.l    _DOSBase(A5),A6        ; Get errorcode (103)
  2867.     jsr    _LVOIoErr(A6)
  2868.     bsr.w    _SetError        ; Set the errorcode
  2869.     lea    _AllocErrTxt(pc),A0    ; Errorstring
  2870.     bsr.w    _DisplayError        ; Tell user...
  2871.     moveq    #0,D0
  2872.     rts
  2873.  
  2874. .FileEmpty
  2875.     lea    _EmptyTxt(pc),A0    ; Errorstring
  2876.     bsr.w    _DisplayError        ; Tell user...
  2877.     moveq    #0,D0
  2878.     rts
  2879.  
  2880. .ItsADir
  2881.     lea    _DirTxt(pc),A0        ; Errorstring
  2882.     bsr.w    _DisplayError        ; Tell user...
  2883.     tst.l    D0
  2884.     beq.s    3$            ; If user said abort...
  2885.  
  2886.     bsr.w    OpenReq            ; Initialize requester (Arp or Reqtools)
  2887.     cmpi.b    #-1,_ReqFlag(A5)    ; No requester at all?
  2888.     beq.s    3$            ; If so...
  2889.  
  2890.     lea    _FileName(A5),A0    ; Name of directory
  2891.     move.l    A0,D1
  2892.     moveq    #ACCESS_READ,D2        ; Mode: Read
  2893.     movea.l    _DOSBase(A5),A6
  2894.     jsr    _LVOLock(A6)        ; Lock Directory
  2895.     move.l    D0,D2            ; Lock into D2
  2896.     beq.s    3$            ; If we can't get lock
  2897.  
  2898. *    move.l    D0,D0            ; Lock
  2899.     lea    _Drive(A5),A0        ; Buffer for name from Lock
  2900.     lea    _FIB(A5),A1        ; FileInfoBlock
  2901.     bsr.w    _GetNameFromLock    ; Get complete name of Lock, e.g. "DF0:pics/brushes/"
  2902.  
  2903.     move.l    D2,D1            ; Lock
  2904.     movea.l    _DOSBase(A5),A6
  2905.     jsr    _LVOUnLock(A6)        ; Free Lock
  2906.  
  2907.     cmpi.b    #1,_ReqFlag(A5)        ; Reqtools-requester?
  2908.     bne.s    2$            ; If not, it must be arp (for now)
  2909.     clr.l    -(sp)            ; Local TagItems....
  2910.     clr.l    -(sp)            ;   TAG_DONE
  2911.     clr.l    -(sp)            ;   ti_DATA (pointer to directory string)
  2912.     clr.l    -(sp)            ;   ti_TAG (RTFI_Dir)
  2913.     movea.l    sp,A0            ; As TagList...
  2914.     move.l    #$80000000+50,(A0)    ; Tell: change directory (RTFI_Dir)
  2915.     lea    _Drive(A5),A1        ; Address new directory string
  2916.     move.l    A1,4(A0)        ;  as pointer for ReqTools
  2917.     movea.l    _ReqPtr(A5),A1        ; Reqtools-Requester-Record
  2918.     movea.l    _ReqToolsBase(A5),A6
  2919.     jsr    _LVOrtChangeReqAttrA(A6) ; Change directory to overgiven one
  2920.     lea    16(sp),sp        ; Correct stack
  2921. 2$
  2922.     st.b    _LoadFlag(A5)        ; Tell: we're going to "load" a file
  2923.     bsr.w    _GetFile        ; Get filename (display requester)
  2924.     tst.l    D0            ; Nothing picked?
  2925.     beq.s    3$            ; Hard error not possible, only "no file chosen"
  2926.     bra.w    _ReadFile        ; Again, try to load the file...
  2927. 3$
  2928.     moveq    #0,D0            ; Tell, didn't fit to read file
  2929.     rts
  2930.  
  2931. .ExamineErr                ; Should never occur
  2932.     jsr    _LVOIoErr(A6)
  2933.     bsr.w    _SetError
  2934.     move.l    _LockSave(A5),D1    ; Key
  2935.     jsr    _LVOUnLock(A6)        ; We allow other people to modify that file...
  2936.     lea    _ExamineErrTxt(pc),A0
  2937.     bsr.w    _DisplayError
  2938.     moveq    #0,D0
  2939.     rts
  2940.  
  2941. .LockErr
  2942.     jsr    _LVOIoErr(A6)
  2943.     bsr.w    _SetError
  2944.     lea    _LockErrTxt(pc),A0
  2945.     bsr.w    _DisplayError
  2946. *
  2947. ** Now we do something smart....
  2948. *
  2949. ** When the user calls us directly from CLI/Shell with the path and file and
  2950. ** the file he/she wants to displayed can't be locked because he/she entered
  2951. ** an invalid path or filename, we search as long as the path is valid, example:
  2952. *
  2953. **   1> viewer hd2:dtp/pictures/btush/aga/lamp.bsh   <- incorrect
  2954. ** was chosen by the user, but the valid name is:
  2955. **   1> viewer hd2:dtp/pictures/brush/aga/lamp.bsh   <- correct
  2956. *
  2957. ** The only thing we now have to do is to search backward if the string is valid, i.e.
  2958. ** if the directory can be locked:
  2959. *
  2960. ** (--------) "hd2:dtp/pictures/btush/aga/lamp.bsh" - caused the lock-error
  2961. ** (1st loop) "hd2:dtp/pictures/btush/aga/"        - isn't still valid
  2962. ** (2nd loop) "hd2:dtp/pictures/btush/"            - isn't still valid
  2963. ** (3rd loop) "hd2:dtp/pictures/"            - valid!!!
  2964. *
  2965. ** Now we copy this valid string into the buffer for the "_Drive" and depending
  2966. ** of the requester-modules (ReqTools/Arp) we setup the necessary things.
  2967. ** That's all!
  2968. *
  2969.  
  2970. * Let's say the the volume isn't available (e.g. "DF7:"), then it makes no sense
  2971. * to execute the following routine (if we can't access the disk, we can't access
  2972. * the directories...).
  2973.     move.l    _errno(A5),D0        ; Get current IoErr-errornumber
  2974.     cmpi.l    #ERROR_DEVICE_NOT_MOUNTED,D0
  2975.     beq.w    .NotFound
  2976.     cmpi.l    #ERROR_NOT_A_DOS_DISK,D0
  2977.     beq.w    .NotFound
  2978.     cmpi.l    #ERROR_NO_DISK,D0
  2979.     beq.w    .NotFound
  2980.     cmpi.l    #ERROR_OBJECT_IN_USE,D0 ; Does somebody format the drive?
  2981.     beq.w    .NotFound
  2982.  
  2983. .FindValidDir
  2984.     lea    _FileName(A5),A0    ; Address string of filename
  2985.     movea.l    A0,A1            ; Startaddress of string also in A1
  2986.     moveq    #-1,D0            ; Dummy-counter
  2987. .FindStrEnd
  2988.     tst.b    (A0)+            ; Find string end
  2989.     dbeq    D0,.FindStrEnd
  2990.     subq.l    #1,A0            ; Pointer to NULL-byte (terminator) of string
  2991.  
  2992. .Find
  2993.     cmpa.l    A0,A1            ; Original same as decreased address?, i.e.
  2994.     beq.w    .NotFound        ; stringstart found - then no trailing was found
  2995.     cmpi.b    #':',(A0)        ; Else...
  2996.     beq.s    .Found
  2997.     cmpi.b    #'/',(A0)
  2998.     beq.s    .Found
  2999.     subq.l    #1,A0
  3000.     dbf    D0,.Find        ; So long not found...
  3001.  
  3002. .Found
  3003.     move.b    (A0),D1            ; Remember last valid char
  3004.     clr.b    (A0)            ; Last valid char is the ":" or the "/", so
  3005. *                      terminate string (_FileName), i.e. replace ":"
  3006. *                      or "/" through NULL-byte - otherwise at next loop
  3007. *                      we found the same char (never ending loop)
  3008. *                      "Viewer Hang Up"
  3009.     move.l    A2,-(sp)
  3010.     lea    _Drive(A5),A2        ; Stringbuffer for volume/directory
  3011. .Cpy
  3012.     cmpa.l    A1,A0            ; Copy all chars until we reach the right address
  3013.     beq.s    .Done
  3014.     move.b    (A1)+,(A2)+
  3015.     dbf    D0,.Cpy
  3016.  
  3017. .Done
  3018.     move.b    D1,(A2)+        ; Copy also remembered trailing
  3019.     clr.b    (A2)            ; Terminate new string
  3020.     movea.l    (sp)+,A2
  3021.  
  3022.     lea    _Drive(A5),A0
  3023.     move.l    A0,D1
  3024.     moveq    #ACCESS_READ,D2
  3025.     movea.l    _DOSBase(A5),A6
  3026.     jsr    _LVOLock(A6)        ; Can we lock the directory (or volume)
  3027.     move.l    D0,D1
  3028.     beq.s    .FindValidDir        ; If not, try again...
  3029.     jsr    _LVOUnLock(A6)        ; Else give back not more needed lock
  3030.  
  3031.     bsr.w    OpenReq            ; Initialize requester (Arp or Reqtools)
  3032.     cmpi.b    #-1,_ReqFlag(A5)    ; No requester at all?
  3033.     beq.s    .NotFound        ; If so...
  3034.  
  3035.     cmpi.b    #1,_ReqFlag(A5)        ; Reqtools-requester?
  3036.     bne.s    .NotFound        ; If not, it must be arp (for now)
  3037.     clr.l    -(sp)            ; Local TagItems....
  3038.     clr.l    -(sp)            ;   TAG_DONE
  3039.     clr.l    -(sp)            ;   ti_DATA (pointer to directory string)
  3040.     clr.l    -(sp)            ;   ti_TAG (RTFI_Dir)
  3041.     movea.l    sp,A0            ; As TagList...
  3042.     move.l    #$80000000+50,(A0)    ; Tell: change directory (RTFI_Dir)
  3043.     lea    _Drive(A5),A1        ; Address new directory string
  3044.     move.l    A1,4(A0)        ;  as pointer for ReqTools
  3045.     movea.l    _ReqPtr(A5),A1        ; Reqtools-Requester-Record
  3046.     movea.l    _ReqToolsBase(A5),A6
  3047.     jsr    _LVOrtChangeReqAttrA(A6) ; Change directory to overgiven one
  3048.     lea    16(sp),sp        ; Correct stack
  3049.  
  3050. .NotFound
  3051.     moveq    #0,D0            ; Indicates no file was loaded...
  3052.     rts
  3053.  
  3054. ***************************************************************
  3055. *
  3056. *
  3057. * Inputs: D0 - Lock of directory
  3058. *      A0 - buffer for name of merged volume/directory name
  3059. *      A1 - buffer for FileInfoBlock (272 byte here)
  3060. *
  3061.  
  3062. _GetNameFromLock
  3063.     movem.l    D2/D6-D7/A3-A4,-(sp)
  3064.  
  3065.     movea.l    _DOSBase(A5),A6
  3066.  
  3067.     move.l    D0,D6            ; Lock
  3068.     beq.s    .ErrorEnd
  3069.  
  3070.     move.l    A0,A3            ; Buffer
  3071.     move.l    A1,A4            ; FIB
  3072.  
  3073.     moveq    #1,D7            ; Counter
  3074.     move.l    D6,-(sp)        ; Lock onto stack
  3075.  
  3076. .Parent
  3077.     move.l    D6,D1            ; Lock
  3078.     jsr    _LVOParentDir(A6)
  3079.     tst.l    D0            ; Previous dir
  3080.     beq.s    .Volume            ; Home-directory e.g. DF0
  3081.     move.l    D0,-(sp)        ; Lock passed onto stack
  3082.     addq.l    #1,D7            ; 1 more Lock
  3083.     move.l    D0,D6            ; Save this Lock
  3084.     bra.s    .Parent            ; So long home-directory not found...
  3085. .Volume
  3086.     move.l    (sp)+,D1        ; Lock
  3087.     bsr.s    .ExamineDir        ; Get those infos
  3088.     bsr.s    .CopyName        ; Copy volume's name
  3089.     move.b    #':',-1(A3)        ; Set colon
  3090.     subq.l    #1,D7            ; 1 less argument
  3091.     beq.s    .FoundThem        ; If all...
  3092. .Drawer
  3093.     move.l    (sp)+,D1        ; Lock
  3094.     bsr.s    .ExamineDir        ; Get the infos
  3095.     bsr.s    .CopyName        ; Copy drawer's name
  3096.     move.b    #'/',-1(A3)        ; Set trailing
  3097.     subq.l    #1,D7            ; 1 less argument
  3098.     beq.s    .FoundThem
  3099.     bra.s    .Drawer
  3100.  
  3101. .FoundThem
  3102.     clr.b    (A3)
  3103.     moveq    #0,D0            ; Indicates no error
  3104. .end
  3105.     movem.l    (sp)+,D2/D6-D7/A3-A4
  3106.     rts
  3107.  
  3108. .ErrorEnd
  3109.     moveq    #-1,D0
  3110.     bra.s    .end
  3111.  
  3112.  
  3113. .ExamineDir
  3114.     move.l    A4,D2        ; FIB
  3115.     jmp    _LVOExamine(A6)
  3116.  
  3117. .CopyName
  3118.     move.l    A4,A0        ; FIB
  3119.     addq.l    #8,A0        ; Lock
  3120. .CopyIt
  3121.     move.b    (A0)+,(A3)+
  3122.     bne.s    .CopyIt
  3123.     rts
  3124.  
  3125. ************************
  3126. *
  3127. * Free allocated data...
  3128. *
  3129. * Inputs: none
  3130. * Results: none
  3131.  
  3132. _FreeFile
  3133.     move.l    A6,-(sp)
  3134.     movea.l    _SysBase(A5),A6
  3135.     movea.l    _TextPtr(A5),A1
  3136.     move.l    _BufferSize(A5),D0
  3137.     jsr    _LVOFreeMem(A6)
  3138.     clr.l    _BufferSize(A5)        ; Important!!!
  3139.     clr.l    _TextPtr(A5)        ; Important!!!
  3140.     clr.l    _SearchStrPtr(A5)
  3141.     clr.l    _SearchStrLen(A5)
  3142.     movea.l    (sp)+,A6
  3143.     rts
  3144.  
  3145. ******************************************
  3146. *
  3147. * File is an object module or a binary file.
  3148. * Called out of "CheckFile()
  3149. *
  3150. * Inputs: none
  3151. * Results: none
  3152. *
  3153.  
  3154. *------------------------------------------------------
  3155. _WrongFileType
  3156.     tst.b    _NoWarnFlag(A5)
  3157.     bne.s    1$
  3158.     bsr.w    _GetConvertedSize
  3159.     move.l    D0,-(sp)
  3160.     pea    _ObjectFileTxt(pc)    ; Display the error
  3161.     bsr.w    _FmtDisplay
  3162.     addq.l    #8,sp
  3163.     tst.l    D0            ; Right mouse button?
  3164.     beq.s    0$            ; Yes
  3165. 1$
  3166.     bra.w    _ConvertBinary
  3167. 0$
  3168.     addq.l    #4,sp            ; Remove "bsr"
  3169.     bsr.s    _FreeFile
  3170.     bra.w    _Loop
  3171.  
  3172. _BinaryFile
  3173.     tst.b    _NoWarnFlag(A5)
  3174.     bne.s    1$
  3175.     bsr.w    _GetConvertedSize
  3176.     move.l    D0,-(sp)
  3177.     pea    _BinaryFileTxt(pc)
  3178.     bsr.w    _FmtDisplay
  3179.     addq.l    #8,sp
  3180.     tst.l    D0            ; Right mouse button?
  3181.     beq.s    0$            ; Yes
  3182. 1$
  3183.     bra.w    _ConvertBinary
  3184. 0$
  3185.     addq.l    #4,sp            ; Remove "bsr"
  3186.     bsr.s    _FreeFile
  3187.     bra.w    _Loop
  3188.  
  3189. **********************************************
  3190. *
  3191. * Check if the file is an ascii-text file,
  3192. *  a powerpacker.library packed ascii-textfile,
  3193. *  a picture,
  3194. *  a powerpacker.library packed picture or -what is
  3195. * not truely displayable
  3196. *  an object file,
  3197. *  a binary file (like ANIMs).
  3198. *
  3199. * Inputs: none
  3200. * Results: none
  3201. *
  3202.  
  3203. _CheckFile
  3204.     movea.l    _TextPtr(A5),A0        ; Source in memory
  3205.     addq.l    #2,A0            ; Overread #$200A
  3206.     cmpi.l    #'PP20',(A0)        ; PowerPacker.library packed?
  3207.     beq.w    _Decrunch
  3208.     cmpi.l    #$000003F3,(A0)        ; Hunk header?
  3209.     beq.s    _WrongFileType        ; If so ...
  3210.     cmpi.l    #'CAT ',(A0)
  3211.     beq.w    _LoadFCFile
  3212.     cmpi.l    #'LIST',(A0)
  3213.     beq.w    _LoadFCFile
  3214.     cmpi.l    #'FORM',(A0)        ; IFF-file?
  3215.     bne.s    _CheckFile_1        ; If not...
  3216.     cmpi.l    #'ILBM',8(A0)        ; Picture?
  3217.     beq.w    _LoadScreen        ; If so...
  3218.     cmpi.l    #'ACBM',8(A0)        ; Picture?
  3219.     beq.w    _LoadScreen        ; If so...
  3220.     cmpi.l    #'SWRT',8(A0)        ; FinalCopy document?
  3221.     beq.w    _LoadFCFile
  3222.     cmpi.l    #'FTXT',8(A0)        ; IFF-text document?
  3223.     beq.w    _LoadFCFile
  3224.     cmpi.l    #'WOWO',8(A0)        ; WordWoorth text document?
  3225.     beq.w    _LoadFCFile
  3226.     cmpi.l    #'8SVX',8(A0)        ; Audio file?
  3227.     beq.w    _LoadAudio
  3228.  
  3229. *
  3230. ** Test if file contains binary datas...
  3231. *
  3232. _CheckFile_1
  3233.     move.l    #255,D0            ; Counter
  3234.     move.l    _FileSize(A5),D1    ; Old filelength
  3235.     cmp.l    D0,D1            ; Compare
  3236.     ble.s    SetLittleFileSize    ; Smaller than 256!
  3237.     bra.s    Test_If_Binary        ; Else test 256 bytes
  3238. SetLittleFileSize:
  3239.     move.b    D1,D0            ; As much bytes file is large (smaller than 256)
  3240.     subq.b    #1,D0            ; Minus 1 - because of DBF
  3241.  
  3242. Test_If_Binary
  3243.     move.b    (A0),D1
  3244.     cmpi.b    #$9B,D1
  3245.     beq.s    .Ok
  3246.     cmpi.b    #127,D1
  3247.     bls.s    .Ok1
  3248.     cmpi.b    #159,D1
  3249.     bls.w    _BinaryFile
  3250.     bra.s    .Ok
  3251. .Ok1
  3252.     cmpi.b    #31,D1
  3253.     bhi.s    .Ok
  3254.     cmpi.b    #6,D1
  3255.     bls.w    _BinaryFile
  3256. .Ok2
  3257.     cmpi.b    #15,D1
  3258.     beq.w    .Ok
  3259.     cmpi.b    #16,D1
  3260.     beq.w    .Ok
  3261.     cmpi.b    #27,D1
  3262.     beq.s    .Ok
  3263.     bhi.w    _BinaryFile
  3264.     cmpi.b    #15,D1
  3265.     bhi.w    _BinaryFile
  3266. .Ok
  3267.     addq.l    #1,A0            ; One char further
  3268.     dbf    D0,Test_If_Binary    ; All bytes tested?
  3269.     rts
  3270.  
  3271. *******************************************
  3272. *
  3273. * Decrunch startup for PP20 crunched files.
  3274. *
  3275. * Inputs: none
  3276. * Results: none
  3277. *
  3278.  
  3279. _Decrunch
  3280.     movea.l    _TextPtr(A5),A0        ; Source
  3281.     addq.l    #2,A0            ; Overread #$200A
  3282.     move.l    _FileSize(A5),D0    ; Length file
  3283.     lea    -4(A0,D0.l),A0        ; Pointer to last longword of crunched file
  3284.  
  3285.     move.l    (A0),D0            ; Only upper 24 bits are intresting
  3286.     lsr.l    #8,D0            ; Skip crunch-info
  3287.     move.l    D0,_UPFSize(A5)        ; UnPackedFileSize
  3288.     addi.l    #12,D0            ; Plus 8 bytes :-) Nico François
  3289. *                      plus 4 :-) Jörg van de Loo
  3290.     bsr.w    _MakeCountEven        ; Align size
  3291.     move.l    D0,_IncSize(A5)        ; Increased file size
  3292.  
  3293.     tst.b    _NoWarnFlag(A5)        ; Allowed to display warning?
  3294.     bne.s    1$
  3295.     move.l    _UPFSize(A5),D0        ; Length file
  3296.     move.l    D0,-(sp)
  3297.     pea    _PPCrunchTxt(pc)    ; Tell user
  3298.     bsr.w    _FmtDisplay
  3299.     addq.l    #8,sp
  3300.     tst.l    D0            ; Right mousebtton?
  3301.     beq.w    _BinaryFile        ; If so...
  3302. 1$
  3303.     move.l    _IncSize(A5),D0
  3304.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  3305.     movea.l    _SysBase(A5),A6
  3306.     jsr    _LVOAllocMem(A6)
  3307.     move.l    D0,_DecrunchAddr(A5)    ; Buffer for decrunched datas
  3308.     beq.s    .DecrunchError
  3309.  
  3310.     movea.l    _TextPtr(A5),A0        ; = Decrunch address
  3311.     addq.l    #2,A0            ; Overread #$200A
  3312.     move.l    _FileSize(A5),D0    ; Length crunched file
  3313.     movea.l    _DecrunchAddr(A5),A1    ; Address for uncrunched file
  3314.     move.w    #$200A,(A1)+        ; (but write down Blank and LineFeed as first
  3315. *                      entries, important for the ascii-text-viewer).
  3316.  
  3317.     bsr.s    _PPDecrunch        ; Decrunch datas
  3318.  
  3319.     movea.l    _DecrunchAddr(A5),A0
  3320.     move.l    _UPFSize(A5),D0
  3321.     cmpi.b    #10,1(A0,D0.l)
  3322.     beq.s    .CrunchOk
  3323.     move.b    #10,2(A0,D0.l)        ; Write LineFeed at end of uncrunched file
  3324. .CrunchOk
  3325.     bsr.w    _FreeFile        ; Free not needed thing
  3326.  
  3327.     move.l    _DecrunchAddr(A5),_TextPtr(A5)    ; Copy pointer
  3328.     move.l    _IncSize(A5),_BufferSize(A5)    ; Copy size
  3329.     move.l    _UPFSize(A5),_FileSize(A5)    ; Copy size
  3330.  
  3331.     bra.w    _CheckFile        ; Check unpacked file
  3332.  
  3333. .DecrunchError
  3334.     lea    _DecrunchErrTxt(pc),A0
  3335.     bsr.w    _DisplayError
  3336.     bsr.w    _FreeFile        ; see above
  3337.     addq.l    #4,sp            ; Remove "bsr" CheckFile
  3338.     bra.w    _Loop
  3339.  
  3340.  
  3341. ***********************************
  3342. *
  3343. * Copyright Nico François
  3344. *
  3345.  
  3346. _PPDecrunch
  3347.     movem.l    D1-D3/D5-D7/A2-A3,-(sp)
  3348.     bsr.s    .PowerPackerDecruncher
  3349.     movem.l    (sp)+,D1-D3/D5-D7/A2-A3
  3350.     rts
  3351. .PowerPackerDecruncher
  3352.     lea    4(A0),A3
  3353.     lea    0(A0,D0.l),A0
  3354.     movea.l    A1,A2
  3355.     moveq    #3,D6
  3356.     moveq    #7,D7
  3357.     moveq    #1,D5
  3358.     movea.l    A2,A1
  3359.     move.l    -(A0),D1
  3360.     tst.b    D1
  3361.     beq.s    1$
  3362.     bsr.s    5$
  3363.     subq.b    #1,D1
  3364.     lsr.l    D1,D5
  3365. 1$
  3366.     lsr.l    #8,D1
  3367.     add.l    D1,A2
  3368. 2$
  3369.  
  3370.     bsr.s    5$
  3371.     bcs.s    12$
  3372.     moveq    #0,D2
  3373. 3$
  3374.     moveq    #1,D0
  3375.     bsr.s    8$
  3376.     add.w    D1,D2
  3377.     cmp.w    D6,D1
  3378.     beq.s    3$
  3379. 4$
  3380.     moveq    #7,D0
  3381.     bsr.s    8$
  3382.     move.b    D1,-(A2)
  3383.     dbf    D2,4$
  3384.     cmp.l    A2,A1
  3385.     bcs.s    12$
  3386.     rts
  3387. 5$
  3388.     lsr.l    #1,D5
  3389.     beq.s    6$
  3390.     rts
  3391. 6$
  3392.     move.l    -(A0),D5
  3393.     roxr.l    #1,D5
  3394.     rts
  3395. 7$
  3396.     subq.w    #1,D0
  3397. 8$
  3398.     moveq    #0,D1
  3399. 9$
  3400.     lsr.l    #1,D5
  3401.     beq.s    11$
  3402. 10$
  3403.     roxl.l    #1,D1
  3404.     dbf    D0,9$
  3405.     rts
  3406. 11$
  3407.     move.l    -(A0),D5
  3408.     roxr.l    #1,D5
  3409.     bra.s    10$
  3410. 12$
  3411.     moveq    #1,D0
  3412.     bsr.s    8$
  3413.     moveq    #0,D0
  3414.     move.b    0(A3,D1.w),D0
  3415.     move.w    D1,D2
  3416.     cmp.w    D6,D2
  3417.     bne.s    15$
  3418.     bsr.s    5$
  3419.     bcs.s    13$
  3420.     moveq    #7,D0
  3421. 13$
  3422.     bsr.s    7$
  3423.     move.w    D1,D3
  3424. 14$
  3425.     moveq    #2,D0
  3426.     bsr.s    8$
  3427.     add.w    D1,D2
  3428.     cmp.w    D7,D1
  3429.     beq.s    14$
  3430.     bra.s    16$
  3431. 15$
  3432.     bsr.s    7$
  3433.     move.w    D1,D3
  3434. 16$
  3435.     addq.w    #1,D2
  3436. 17$
  3437.     move.b    0(A2,D3.w),-(A2)
  3438.     dbf    D2,17$
  3439.     cmpa.l    A2,A1
  3440.     bcs.s    2$
  3441.     rts
  3442.  
  3443. ***********************************************
  3444. *
  3445. * Attempt to find a display ID which does match
  3446. * with the settings of the computed image.
  3447. *
  3448. * Needed for the Picasso96 software package.
  3449. *
  3450. * Should also works with other by me unknown
  3451. * 3rd party software packages.
  3452. *
  3453.  
  3454. _GetMode
  3455.     movem.l    D2-D3/D5-D7/A2,-(sp)
  3456.  
  3457.     moveq    #0,D5
  3458.     move.b    D0,D5
  3459.  
  3460.     cmpi.w    #1360,_Width(A5)    ; Maximum widtn for a 24 bit display (CV3D)
  3461.     bls.s    1$
  3462.     cmpi.b    #16,D5            ; If not 24 bitplanes deep
  3463.     bls.s    1$
  3464.     moveq    #16,D5            ; Else, force screen from 24 to 16 bitplanes
  3465. 1$
  3466.     moveq    #0,D7            ; Error code or Monitor ID
  3467.  
  3468.     movea.l    _SysBase(A5),A6
  3469.     move.l    #128,D0            ; Buffer for DimensionInfo (di)
  3470.     move.l    #MEMF_CLEAR,D1
  3471.     jsr    _LVOAllocMem(A6)
  3472.     tst.l    D0
  3473.     beq.w    .end
  3474.     movea.l    D0,A2            ; DimensionInfo
  3475.  
  3476.     movea.l    _GfxBase(A5),A6
  3477.     moveq    #INVALID_ID,D6        ; Get really first ID!
  3478.  
  3479.     cmpi.b    #7,D5
  3480.     bhi.s    .loop
  3481.     moveq    #8,D5            ; Less than 8 bitplanes -> now 8 bitplanes!
  3482.  
  3483. .loop
  3484.     move.l    D6,D0            ; Last monitor ID
  3485.     jsr    _LVONextDisplayInfo(A6)
  3486.     cmpi.l    #INVALID_ID,D0        ; End of monitor ID list?
  3487.     beq.s    .notfound
  3488.  
  3489.     move.l    D0,D6            ; Monitor ID
  3490.     andi.l    #$FFF00000,D0        ; Only non native AMIGA modes allowed!
  3491.     beq.s    .loop
  3492.     cmpi.l    #$FFF00000,D0        ; Test monitor? - ignore!
  3493.     beq.s    .loop
  3494.  
  3495.     suba.l    A0,A0            ; handle = 0
  3496.     movea.l    A2,A1            ; di
  3497.     move.l    #128,D0            ; size of buffer
  3498.     move.l    #DTAG_DIMS,D1        ; TAG
  3499.     move.l    D6,D2            ; Monitor ID
  3500.     jsr    _LVOGetDisplayInfoData(A6)
  3501.     tst.l    D0
  3502.     beq.s    .loop            ; If it failed...
  3503.  
  3504. *    cmpi.w    #15,dim_MaxDepth(A2)    ; Ignore 15bit modes!
  3505. *    beq.s    .loop
  3506.  
  3507.     cmp.w    #16,D5            ; More than 16 bitplanes?
  3508.     bls.s    .normalDepthCheck    ; If not, a normal depth check
  3509.  
  3510.     cmp.w    #23,dim_MaxDepth(A2)    ; Can we display 24 bitplanes at a time with this monitor?
  3511.     bls.s    .loop            ; No...
  3512.  
  3513.     bra.s    .dimCheck        ; Yes...
  3514.  
  3515. .normalDepthCheck
  3516.     cmp.w    dim_MaxDepth(A2),D5    ; Right depth?
  3517.     bne.s    .loop            ; If not...
  3518.  
  3519. .dimCheck
  3520.     lea    dim_Nominal(A2),A0    ; Get dimension of monitor
  3521.     move.w    ra_MaxX(A0),D0        ; Last X-position of monitor (e.g. 639)
  3522.     move.w    ra_MaxY(A0),D1        ; Last Y-position of monitor (e.g. 479)
  3523.     addq.w    #1,D0            ; e.g. == 640
  3524.     addq.w    #1,D1            ; e.g. == 480
  3525.  
  3526.     move.w    _PlaneWidth(A5),D2    ; e.g. 640
  3527.     move.w    _PlaneHeight(A5),D3    ; e.g. 480
  3528.  
  3529.     cmp.w    D0,D2
  3530.     bne.s    .loop
  3531.     cmp.w    D1,D3
  3532.     bne.s    .loop
  3533.  
  3534.     move.l    D6,D7            ; Found ID!
  3535.  
  3536. * Now figure out if this monitor supports changes of RasInfo,
  3537. * set ViewPortShare by default to no (#-1)!
  3538.  
  3539. * Completey removed because Picasso96 1.4x supports now changing of View^dx/dy
  3540.     moveq    #0,D0            ; Must be set to minus 1 if the check should work!!!
  3541.     move.l    D0,_ViewPortShare(A5)
  3542.  
  3543. *    suba.l    A0,A0            ; handle = 0
  3544. *    movea.l    A2,A1            ; Now MonitorInfo!!!
  3545. *    move.l    #128,D0            ; size of buffer
  3546. *    move.l    #DTAG_MNTR,D1        ; TAG
  3547. *    move.l    D6,D2            ; Monitor ID
  3548. *    jsr    _LVOGetDisplayInfoData(A6)
  3549. *    tst.l    D0
  3550. *    beq.s    .freeDI
  3551.  
  3552. *    move.l    mtr_Compatibility(A2),_ViewPortShare(A5)
  3553. *    bra.s    .freeDI
  3554.  
  3555. .notfound
  3556. *    moveq    #0,D7            ; No ID!
  3557. *    move.l    D7,_ViewPortShare(A5)    ; Reset
  3558.  
  3559. .freeDI
  3560.     movea.l    _SysBase(A5),A6
  3561.     movea.l    A2,A1
  3562.     move.l    #128,D0
  3563.     jsr    _LVOFreeMem(A6)
  3564. .end
  3565.     move.l    D7,D0
  3566.     movem.l    (sp)+,D2-D3/D5-D7/A2
  3567.     rts                ; Return ID in D0 or zero for not found
  3568. *                      (only foreign modes will be returned)
  3569.  
  3570. ************************************************
  3571. *
  3572. * Display picture or image...
  3573. *
  3574. * Inputs: none
  3575. * Results: none
  3576. *
  3577.  
  3578. _LoadScreen
  3579.     tst.b    _NoWarnFlag(A5)
  3580.     bne.s    0$
  3581.  
  3582.     cmpi.l    #'ACBM',8(A0)        ; ACBM-file?
  3583.     bne.s    .IFF_ILBM        ; if not, must be ILBM-file
  3584.  
  3585.     lea    _ACBMTxt(pc),A0
  3586.     bsr.w    _DisplayError
  3587.     tst.l    D0            ; User cancelled?
  3588.     beq.w    _BinaryFile        ; If so, don't display
  3589.     bra.s    0$
  3590.  
  3591. .IFF_ILBM
  3592.     lea    _ILBMTxt(pc),A0
  3593.     bsr.w    _DisplayError
  3594.     tst.l    D0            ; User cancelled?
  3595.     beq.w    _BinaryFile        ; If so, don't display
  3596. 0$
  3597.     movea.l    _TextPtr(A5),A0        ; Source in memory
  3598.     addq.l    #2,A0            ; Overread #$200A
  3599.  
  3600.     move.l    A0,_SourceFilePtr(A5)    ; Copy pointer and size
  3601.     move.l    _FileSize(A5),_SourceFileSize(A5)
  3602.  
  3603.     bsr.w    _Convert        ; Decrunch image
  3604.     move.l    D0,-(sp)        ; Save returncode
  3605.  
  3606.     movea.l    _SysBase(A5),A6
  3607.     movea.l    _TextPtr(A5),A1
  3608.     move.l    _BufferSize(A5),D0    ; Free old datas
  3609.     jsr    _LVOFreeMem(A6)
  3610.     clr.l    _TextPtr(A5)        ; Important!!!
  3611.     clr.l    _BufferSize(A5)
  3612.     clr.l    _SearchStrPtr(A5)
  3613.     clr.l    _SearchStrLen(A5)
  3614.  
  3615.     move.l    (sp)+,D0        ; Get return code
  3616.     cmpi.l    #1,D0            ; 1 means all ok.
  3617.     bne.w    2$
  3618.  
  3619.  
  3620.     moveq    #0,D0
  3621.     move.b    _Depth(A5),D0
  3622.     move.l    _ViewPortMod(A5),D1
  3623.     andi.l    #HAM_KEY,D1        ; HAM6 or HAM8?
  3624.     beq.s    .noham            ; If not...
  3625.  
  3626. .ham
  3627.     moveq    #0,D1
  3628.     move.b    _Depth(A5),D1
  3629.     move.l    D1,_HAMSet(A5)
  3630.     move.b    #24,_Depth(A5)        ; Always use a 24 bit depth screen for HAM modes
  3631.  
  3632.     moveq    #1,D1            ; Initial val
  3633.     subq.b    #2,D0            ; 8 to 6 or 6 to 4
  3634.     lsl.w    D0,D1            ; HAM8: 1 << 6 = 64 or HAM6: 1 << 4 = 16
  3635.     lsl.l    D0,D1            ; Perform 64 * 64 * 64 or
  3636.     lsl.l    D0,D1            ; 16 * 16 * 16
  3637.     bra.s    .giveMsg        ; Done for HAM
  3638.  
  3639. .noham
  3640.     clr.l    _HAMSet(A5)
  3641.     moveq    #1,D1
  3642.     lsl.l    D0,D1            ; 1 << x = number of colours used
  3643.  
  3644. .giveMsg
  3645.     tst.b    _NoWarnFlag(A5)
  3646.     bne.s    .DontWrite
  3647.  
  3648.     move.l    _AllPlaneSize(A5),D0    ; Allocated size (in bytes)
  3649.     move.l    D0,-(sp)
  3650.     move.l    D1,-(sp)        ; Number of colours
  3651.     move.w    _Height(A5),D0        ; Height of image
  3652.     move.l    D0,-(sp)
  3653.     move.l    _RealIWidth(A5),D0    ; Width of image (no boundary)
  3654.     move.l    D0,-(sp)
  3655.     move.w    _Height(A5),D0        ; Number of rows used by bitmap
  3656.     move.l    D0,-(sp)
  3657.     move.w    _Width(A5),D0        ; Width in pixels of bitmap
  3658.     move.l    D0,-(sp)
  3659.     move.w    _PlaneHeight(A5),D0    ; Original screen's height
  3660.     move.l    D0,-(sp)
  3661.     move.w    _PlaneWidth(A5),D0    ; Original screen's width
  3662.     move.l    D0,-(sp)
  3663.     pea    _ImageInfoTxt(pc)
  3664.     bsr.w    _FmtDisplay
  3665.     lea    9*4(sp),sp
  3666.     tst.l    D0
  3667.     beq.w    2$
  3668.  
  3669. .DontWrite
  3670.     clr.b    _BlitFlag(A5)        ; Reset flags, important!!!
  3671.     clr.b    _SuperBitMap(A5)
  3672.     moveq    #0,D0
  3673.     move.l    D0,_ViewPortShare(A5)
  3674.  
  3675. *
  3676. ** If we're in OS3(+) we ask the system for the proberty ViewPort ModeID!
  3677. *
  3678.     movea.l    _GfxBase(A5),A6
  3679.     cmpi.w    #38,LIB_VERSION(A6)
  3680.     bls.w    .stdcheck
  3681.  
  3682.     tst.l    _TypeOfMem(A5)        ; TypeOfMem set up by routine _Convert(), if it is zero
  3683. *                      the bitplanes for the image where forces to public (FAST)
  3684. *                      memory, since an alien gfx board software created the window's bitmap
  3685.     bne.w    .stdcheck
  3686.  
  3687.     bsr.w    _CheckEHB
  3688.  
  3689.     clr.l    -(sp)            ; Assumption: 3rd party GFX device
  3690.     clr.l    -(sp)
  3691.     clr.l    -(sp)
  3692.     clr.l    -(sp)
  3693.     clr.l    -(sp)
  3694.     clr.l    -(sp)
  3695.     clr.l    -(sp)
  3696.     movea.l    sp,A0
  3697.  
  3698.     moveq    #0,D1
  3699.     move.l    D1,D2
  3700.     move.w    _PlaneHeight(A5),D1    ; Screen's dimension (not bitmap !!!)
  3701.     move.w    _PlaneWidth(A5),D2
  3702.  
  3703. *
  3704. ** Make a 4 to 3 aspect ratio so that any 3rd party device can handle it...
  3705. *    
  3706.     lsl.l    #2,D1            ; * 4
  3707.     divu.w    #3,D1            ; / 3
  3708.  
  3709.     cmp.w    D1,D2            ; Range check...
  3710.     bhi.s    .align0
  3711.  
  3712.     andi.l    #$FFFF,D1 
  3713.     move.w    D1,D2            ; New Width
  3714.  
  3715. .align0
  3716.     cmpi.w    #360,D2            ; Following are resolutions which can be used
  3717.     bhi.s    .align1            ; for 8 bitplane images, the other do only
  3718.     move.w    #320,D2            ; support 15/16 and 24/32 bit resolutions...
  3719.     move.w    #240,D1
  3720.     bra.s    .dimset
  3721. .align1
  3722.     cmpi.w    #768,D2
  3723.     bhi.s    .align2
  3724.     move.w    #640,D2
  3725.     move.w    #480,D1
  3726.     bra.s    .dimset
  3727. .align2
  3728.     cmpi.w    #896,D2
  3729.     bhi.s    .align3
  3730.     move.w    #800,D2
  3731.     move.w    #600,D1
  3732.     bra.s    .dimset
  3733. .align3
  3734.     move.w    #1024,D2        ; Default...
  3735.     move.w    #768,D1
  3736. .dimset
  3737.     move.w    D2,_PlaneWidth(A5)
  3738.     move.w    D1,_PlaneHeight(A5)
  3739.  
  3740.     moveq    #0,D0
  3741.     move.b    _Depth(A5),D0
  3742.     cmpi.b    #14,D0            ; Force a 9-14 bitplane display to 15 bit
  3743.     bhi.s    .depthok
  3744.     cmpi.b    #8,D0
  3745.     bls.s    .depthok
  3746.     moveq    #15,D0
  3747.     bra.s    .startscan
  3748.  
  3749. .depthok
  3750.     cmpi.b    #16,D0
  3751.     bls.s    .startscan
  3752.  
  3753.     cmpi.w    #1360,_Width(A5)
  3754.     bls.s    .startscan
  3755.     moveq    #16,D0
  3756.  
  3757. .startscan
  3758.     movem.l    D0-D2,-(sp)
  3759.  
  3760.     move.l    #BIDTAG_NominalWidth,(A0)
  3761.     move.w    D2,4(A0)
  3762.     move.l    #BIDTAG_NominalHeight,6(A0)
  3763.     move.w    D1,10(A0)
  3764.     move.l    #BIDTAG_Depth,12(A0)
  3765.     move.b    D0,14(A0)
  3766.     clr.l    16(A0)            ; TAG_Done
  3767.     movea.l    _GfxBase(A5),A6
  3768.     jsr    _LVOBestModeIDA(A6)
  3769.     move.l    D0,_ViewPortMod(A5)    ; Save 3rd party GFX device View Mode ID (only CyberGraphX)
  3770.  
  3771.     andi.l    #$FFF00000,D0        ; Only foreign modes!
  3772.     beq.s    .getModeID
  3773.     cmpi.l    #$FFF00000,D0        ; Do not use a test monitor!
  3774.     bne.s    .modeok
  3775.  
  3776. .getModeID
  3777.     move.l    (sp),D0            ; Depth
  3778.     bsr.w    _GetMode        ; Find monitor id that suits...
  3779.     move.l    D0,_ViewPortMod(A5)
  3780.     bne.s    .modeok            ; If found
  3781.     movem.l    (sp)+,D0-D2
  3782.     cmpi.b    #15,D0            ; 15 bit?
  3783.     bne.s    .wrongMode        ; No
  3784.     moveq    #16,D0            ; Try 16 bit instead of 15
  3785.     bra.s    .startscan
  3786.  
  3787. .wrongMode
  3788.     lea    _ErrorInvalidIDTxt(pc),A0
  3789.     bsr.w    _DisplayError
  3790.     lea    7*4(sp),sp
  3791.     bra.w    2$
  3792.  
  3793. .modeok
  3794.     movem.l    (sp)+,D0-D2
  3795.     lea    7*4(sp),sp
  3796.     bsr.w    _BrightenColours    ; Adjust the colours, e.g.: native AA = 8 bits per pen, 3rd party e.g. only 6
  3797.     bra.s    .ViewModeSet
  3798.  
  3799. .stdcheck
  3800.     move.l    _ViewPortMod(A5),D0    ; ViewModes
  3801.     movea.l    _SysBase(A5),A6
  3802.     cmpi.w    #35,LIB_VERSION(A6)
  3803.     bls.s    .StdChipSet
  3804.     movea.l    _GfxBase(A5),A6
  3805.     jsr    _LVOModeNotAvailable(A6)
  3806.     tst.l    D0
  3807.     beq.s    .ViewModeSet
  3808.  
  3809.     move.l    _ViewPortMod(A5),D0    ; Take as std-chip-set because Monitor isn't installed
  3810.  
  3811. .StdChipSet
  3812.     andi.l    #$FFFF,D0        ; Clear upper 16 bits because
  3813.     move.l    D0,_ViewPortMod(A5)    ; OS 1.x doesn't cares about Monitors!
  3814.     bsr.w    _DefaultMonitor        ; Choose screen-mode depending on video system...
  3815.  
  3816. .ViewModeSet
  3817.     lea    _NewScreen(A5),A0    ; Init screen-record
  3818.     clr.l    (A0)+
  3819.     move.w    _PlaneWidth(A5),(A0)+
  3820.     move.w    _PlaneHeight(A5),(A0)+
  3821.     moveq    #0,D0
  3822.     move.b    _Depth(A5),D0
  3823.     tst.l    _TypeOfMem(A5)
  3824.     bne.s    .storeDepth
  3825.     cmpi.b    #16,D0
  3826.     bls.s    .storeDepth
  3827.     cmp.w    #1360,_Width(A5)
  3828.     bls.s    .storeDepth
  3829.     moveq    #16,D0            ; Reduce 24 bit to 16
  3830. .storeDepth
  3831.     move.w    D0,(A0)+
  3832.     move.b    #-1,(A0)+
  3833.     move.b    #-1,(A0)+
  3834.     move.l    _ViewPortMod(A5),D0
  3835.     move.w    D0,(A0)+
  3836.     move.w    #NS_EXTENDED|CUSTOMSCREEN|CUSTOMBITMAP|SCREENQUIET,D1
  3837.     move.w    D1,(A0)+
  3838.     clr.l    (A0)+            ; Font
  3839.     lea    _ScreenName(pc),A1
  3840.     move.l    A1,(A0)+
  3841.     clr.l    (A0)+            ; Gadgets
  3842.     lea    _BitmapStruc(A5),A1    ; Set bitmap as screen's bitmap
  3843.     move.l    A1,(A0)+
  3844.     lea    _StdTags(A5),A1        ; Init tag-list for screen
  3845.     move.l    A1,(A0)+
  3846.     move.l    #SA_DisplayID,(A1)+
  3847.  
  3848.     move.l    _ViewPortMod(A5),D0
  3849.     tst.l    _TypeOfMem(A5)        ; Check if bitplanes forced to FAST-RAM - then
  3850. *                      the monitor ID isn't (shouldn't be) a normal AMIGA view mode
  3851.     beq.s    .Set
  3852.  
  3853.     btst.l    #12,D0            ; An ECS or AA monitor?
  3854.     bne.s    .ECS_AA            ; if so...
  3855.  
  3856.     andi.l    #$FFFF,D0        ; else mask out unused bytes
  3857.     bra.s    .Set
  3858.  
  3859. .ECS_AA
  3860.     cmpi.l    #$5FFFF,D0        ; Highest possible OS1 and! OS2 monitor ID
  3861.     bhi.s    .NewAAMode        ; We do have an AA display mode - so
  3862. *                      check if we have the "AA-chip-set"
  3863.     bra.s    .Set            ; We have only to open a standard or ECS display
  3864.  
  3865. *
  3866. ** AA monitor used for displaying, do we have the right chip-set?
  3867. ** NOTE: I check here the hardware but for the sakeness of completeness the info-data-
  3868. ** base of the monitor itselfs must be examined.
  3869. *
  3870. .NewAAMode
  3871.     movea.l    _SysBase(A5),A6
  3872.     cmpi.w    #38,LIB_VERSION(A6)    ; OS3.x or greater?
  3873.     bls.s    .MustEraseDbl        ; If not...
  3874.     movea.l    _GfxBase(A5),A6
  3875.     move.b    gb_ChipRevBits0(A6),D1    ; AA custom chip-set enabled?
  3876.     andi.b    #GFXF_AA_ALICE|GFXF_AA_LISA,D1
  3877.     bne.s    .Set            ; If enabled...
  3878.  
  3879. .MustEraseDbl
  3880.     andi.l    #$FFFF,D0        ; else take as default monitor
  3881.  
  3882. .Set
  3883.     tst.l    D0
  3884.     bne.s    .gotMID
  3885.     bsr.w    _DefaultMonitor
  3886. .gotMID
  3887.     move.l    D0,(A1)+        ; Set DisplayID
  3888.     clr.l    (A1)
  3889.  
  3890.     clr.b    _BlitFlag(A5)        ; Erase flag
  3891.  
  3892.     move.w    _Height(A5),D0
  3893.     move.w    _PlaneHeight(A5),D1
  3894.     cmp.w    D0,D1
  3895.     slt.b    _SuperBitMap(A5)    ; Bitmap taller than screen? - see there
  3896.     shi.b    _BlitFlag(A5)        ; Displaying a brush?
  3897.  
  3898.     move.w    _Width(A5),D0
  3899.     move.w    _PlaneWidth(A5),D1
  3900.     tst.l    _TypeOfMem(A5)        ; Foreign display HW used to display image?
  3901.     beq.s    .widthSetOk        ; If so,
  3902.  
  3903.     addi.w    #63,D1            ;  otherwise care about the BURST-Fetch-mode
  3904.     andi.w    #-64,D1            ;  so we have to correct this value
  3905. .widthSetOk
  3906.     tst.b    _SuperBitMap(A5)    ; Already dimension for a superbitmap?
  3907.     bne.s    1$            ; If so, skip next
  3908.  
  3909.     cmp.w    D0,D1            ; Check for superbitmap
  3910.     slt.b    _SuperBitMap(A5)    ; Set flag when encountered
  3911.  
  3912. 1$
  3913.     tst.b    _BlitFlag(A5)        ; Already a brush encountered?
  3914.     bne.s    .MustSet        ; If so...
  3915.  
  3916.     cmp.w    D0,D1
  3917.     shi.b    _BlitFlag(A5)        ; Encountered now
  3918.  
  3919.     tst.b    _BlitFlag(A5)        ; Do we display a brush?
  3920.     bne.s    .MustSet        ; If so...
  3921.  
  3922.     bra.s    .CheckDevice        ; Normal fullscreen image either with a superbitmap or without
  3923.  
  3924. .MustSet
  3925.     lea    _NewScreen(A5),A0
  3926.     move.w    #NS_EXTENDED|CUSTOMSCREEN|SCREENQUIET,ns_Type(A0) ; No custom bitmap used when displaying brushes!
  3927.  
  3928. .CheckDevice
  3929.     tst.l    _TypeOfMem(A5)        ; If the bitplanes have been forced to public memory
  3930. *                      I assume that a 3rd party GFX software driver is installed,
  3931. *                      this means we cannot use the system function to set the view
  3932. *                      since AMIGA 3rd party GFX boards are originally from the PC 
  3933. *                      and PCs don't support overscan!!!
  3934.     beq.s    .3rdParty
  3935.     bsr.w    _SetView        ; See there... (only for real AMIGA monitors/screens)
  3936.     bra.s    .ScreenSet
  3937.  
  3938. .3rdParty
  3939.     lea    _NewScreen(A5),A0
  3940.     move.w    #NS_EXTENDED|CUSTOMSCREEN|SCREENQUIET,ns_Type(A0) ; No custom bitmap!
  3941.     clr.l    ns_CustomBitMap(A0)
  3942.  
  3943.     tst.b    _SuperBitMap(A5)    ; Do we have a super bitmap?
  3944.     beq.s    .ScreenSet
  3945.  
  3946.     lea    _StdTags(A5),A0        ; Taglist for screen, SA_DisplayID already set
  3947.     move.l    #SA_AutoScroll,8(A0)
  3948.     move.l    #0,12(A0)        ; FALSE
  3949.     move.l    #SA_Type,16(A0)
  3950.     move.l    #CUSTOMSCREEN,20(A0)
  3951.     move.l    #SA_Width,24(A0)
  3952.     move.l    _ImageWidth(A5),28(A0)    ; How tall must be the screen's bitmap (without alignments)
  3953.     move.l    #SA_Height,32(A0)
  3954.     clr.w    36(A0)            ; Clear upper word of longword
  3955.     move.w    _Height(A5),38(A0)
  3956.     clr.l    40(A0)            ; TAG_DONE
  3957.  
  3958. .ScreenSet
  3959.     lea    _NewScreen(A5),A0
  3960.     movea.l    _IntuitionBase(A5),A6
  3961.     jsr    _LVOOpenScreen(A6)
  3962.     tst.l    D0
  3963.     bne.s    .OkScreen        ; Screen is open...
  3964.  
  3965.     lea    _ErrorOpeningScreen(pc),A0
  3966.     bsr.w    _DisplayError
  3967.     bra.w    2$
  3968.  
  3969. .OkScreen
  3970.     move.l    D0,D2            ; ScreenPtr
  3971.     movea.l    D0,A0
  3972.     lea    sc_ViewPort(A0),A0    ; Get screen's viewport
  3973.     lea    _Colourmap(A5),A1    ; Get screen's colourmap
  3974.     move.l    _CMapNumEntries(A5),D0    ; Number of colours (max 256)
  3975.     movea.l    _GfxBase(A5),A6
  3976.     cmpi.w    #38,LIB_VERSION(A6)
  3977.     bhi.s    .set32Bit        ; Running an AGA machine!
  3978.     jsr    _LVOLoadRGB4(A6)    ; Else use old colour-set function
  3979.     bra.s    .ColoursSet
  3980.  
  3981. .set32Bit
  3982.     tst.l    _TypeOfMem(A5)
  3983.     bne.s    .modifyCM32
  3984.  
  3985. *
  3986. ** Following only for displays with more than 8 bitplanes
  3987. *
  3988.     cmpi.b    #8,_Depth(A5)
  3989.     bls.s    .modifyCM32
  3990.  
  3991.     move.l    D2,-(sp)
  3992.     movea.l    D2,A2
  3993.  
  3994.     lea    sc_ViewPort(A2),A0
  3995.     moveq    #0,D0
  3996.     move.l    D0,D1
  3997.     move.l    D0,D2
  3998.     move.l    D0,D3
  3999.     jsr    _LVOSetRGB32(A6)    ; Colour zero of ViewPort to black
  4000.  
  4001.     lea    sc_RastPort(A2),A1
  4002.     moveq    #0,D0
  4003.     jsr    _LVOSetAPen(A6)        ; Use Rastport's pen zero
  4004.  
  4005.     lea    sc_RastPort(A2),A1
  4006.     moveq    #0,D0
  4007.     moveq    #0,D1
  4008.     move.w    sc_Width(A2),D2
  4009.     subq.w    #1,D2
  4010.     move.w    sc_Height(A2),D3
  4011.     subq.w    #1,D3
  4012.     jsr    _LVORectFill(A6)    ; Flood Screen with pen zero (black background)
  4013.  
  4014.     move.l    (sp)+,D2
  4015.     bra.s    .ColoursSet
  4016.  
  4017. .modifyCM32
  4018.     lea    _RGB32Colours(A5),A1    ; RGB32 Colourtable
  4019.     jsr    _LVOLoadRGB32(A6)    ; Load them
  4020.  
  4021. .ColoursSet
  4022.     tst.l    _TypeOfMem(A5)        ; Since the most 3rd party GFX board drivers don't support
  4023.     beq.s    .blit            ; custom BitMaps we have to copy the bitplanes manually...
  4024.  
  4025.     tst.b    _BlitFlag(A5)        ; Do we have to blit an image to the screen?
  4026.     beq.w    .noneedblit        ; No...
  4027.  
  4028. .blit
  4029.     movem.l    D2-D7/A2,-(sp)
  4030.  
  4031. .loop
  4032.     movea.l    _IntuitionBase(A5),A6
  4033.     move.l    ib_FirstScreen(A6),D0
  4034.     cmp.l    D2,D0
  4035.     beq.s    .startblit
  4036.  
  4037.     movea.l    _DOSBase(A5),A6
  4038.     moveq    #1,D1
  4039.     jsr    _LVODelay(A6)
  4040.     bra.s    .loop
  4041.  
  4042. .startblit
  4043.     tst.l    _HAMSet(A5)
  4044.     bne.s    .convertHAM
  4045.  
  4046.     lea    _BitmapStruc(A5),A0    ; Image's bitmap
  4047.     cmpi.b    #24,bm_Depth(A0)
  4048.     bne.s    .check16bit
  4049.     movea.l    D2,A1            ; Screen A1
  4050.     lea    sc_RastPort(A1),A1
  4051.     bsr.w    _PlanarBMtoRGB24
  4052.     tst.l    D0
  4053.     bne.w    .none
  4054.     bra.s    .realstartblit
  4055.  
  4056. .convertHAM
  4057.     tst.l    _TypeOfMem(A5)        ; HAM and no gfx-board?
  4058.     bne.s    .realstartblit
  4059.  
  4060.     lea    _BitmapStruc(A5),A0    ; Image's bitmap
  4061.     movea.l    D2,A1            ; Screen A1
  4062.     lea    sc_RastPort(A1),A1
  4063.     bsr.w    _HAMtoRGB24
  4064.     tst.l    D0
  4065.     bne.w    .none
  4066.  
  4067. .check16bit
  4068.     cmpi.b    #8,bm_Depth(A0)
  4069.     bls.s    .realstartblit
  4070.     cmpi.b    #16,bm_Depth(A0)
  4071.     bhi.s    .realstartblit
  4072.     movea.l    D2,A1            ; Screen A1
  4073.     lea    sc_RastPort(A1),A1
  4074.     bsr.w    _CLUTtoRGB16
  4075.     tst.l    D0
  4076.     bne.w    .none
  4077.     
  4078. .realstartblit
  4079.     lea    _BitmapStruc(A5),A0    ; Image's bitmap
  4080.     movea.l    D2,A1            ; Screen A1
  4081.     movea.l    A1,A2
  4082.     lea    sc_RastPort(A1),A1    ; Screen's RastPort
  4083.     movea.l    rp_BitMap(A1),A1
  4084.     moveq    #0,D0
  4085.     move.l    D0,D1
  4086.     moveq    #0,D2
  4087.     move.w    sc_Width(A2),D2        ; Screen's dimensions
  4088.     lsr.w    #1,D2            ; Half
  4089.     moveq    #0,D7
  4090.     move.l    _RealIWidth(A5),D7    ; Image's width
  4091.     lsr.w    #1,D7            ; Half
  4092.     sub.w    D7,D2            ; == X-Offset for image
  4093.  
  4094.     move.w    sc_Height(A2),D3
  4095.     lsr.w    #1,D3            ; Half
  4096.     move.w    _Height(A5),D7
  4097.     lsr.w    #1,D7            ; Half
  4098.     sub.w    D7,D3            ; Y-Offset for image
  4099.  
  4100.     move.l    _RealIWidth(A5),D4    ; Image's width
  4101.     move.w    _Height(A5),D5        ; Image's height
  4102.  
  4103. *
  4104. ** Because a blit must be friendly, we now check the bounds
  4105. *
  4106.     tst.w    D2
  4107.     bpl.s    .XOk
  4108.     moveq    #0,D2
  4109. .XOk
  4110.     tst.w    D3
  4111.     bpl.s    .YOk
  4112.     moveq    #0,D3
  4113. .YOk
  4114.     move.w    D4,D7
  4115.     add.w    D2,D7
  4116.     cmp.w    sc_Width(A2),D7
  4117.     bls.s    .WOk
  4118.     move.w    sc_Width(A2),D7
  4119.     addq.w    #1,D7
  4120.  
  4121.     move.w    D4,D6
  4122.     add.w    D2,D6
  4123.     sub.w    D7,D6
  4124.  
  4125.     sub.w    D6,D4
  4126. .WOk
  4127.     move.w    D5,D7
  4128.     add.w    D3,D7
  4129.     cmp.w    sc_Height(A2),D7
  4130.     bls.s    .doblit
  4131.     move.w    sc_Height(A2),D7
  4132.     addq.w    #1,D7
  4133.  
  4134.     move.w    D5,D6            ; e.g. 832
  4135.     add.w    D3,D6            ; e.g. 0
  4136.     sub.w    D7,D6            ; 800 from 832 = 32
  4137.  
  4138.     sub.w    D6,D5            ; 832 - 32 = 800
  4139.  
  4140. .doblit
  4141.     move.b    #$C0,D6            ; Minterm == blit all
  4142.     move.l    #$FF,D7            ; Only byte treated...
  4143.     suba.l    A2,A2
  4144.  
  4145.     movem.l    D0-D1/A0-A1,-(sp)
  4146.     movea.l    _GfxBase(A5),A6
  4147.     jsr    _LVOWaitBlit(A6)
  4148.     movem.l    (sp)+,D0-D1/A0-A1
  4149.     jsr    _LVOBltBitMap(A6)     ; Blit the image to the display (only first 8 bitplanes... shit...)
  4150.  
  4151. .none
  4152.     movem.l    (sp)+,D2-D7/A2
  4153.  
  4154. .noneedblit
  4155.     movem.l    D2-D7/A2-A4,-(sp)
  4156.     movea.l    D2,A4            ; Screen
  4157.     lea    sc_ViewPort(A4),A3    ; Screen's ViewPort
  4158.     movea.l    vp_RasInfo(A3),A3    ; Screen's RasInfo
  4159.     move.w    _PlaneWidth(A5),D2    ; Visible size (screen)
  4160.     move.w    _PlaneHeight(A5),D3    ; Visible size (screen)
  4161.     move.l    _RealIWidth(A5),D4    ; Whole size (bitmap)
  4162.     move.w    _Height(A5),D5        ; Whole size (bitmap)
  4163.     move.w    D2,D6            ; Current Width
  4164.     move.w    D3,D7            ; Current Height
  4165.  
  4166. .Wait
  4167.     clr.b    _RIChanged(A5)        ; Important
  4168.  
  4169.     tst.b    _SuperBitMap(A5)    ; Do we have a superbitmap?
  4170.     beq.w    .PureWait        ; No, wait only
  4171.  
  4172.     move.w    sc_MouseX(A4),D0    ; Mouse-x-position on screen
  4173.     move.w    sc_MouseY(A4),D1    ; Mouse-y-position on screen
  4174.     move.w    $DFF016.l,_RMB(A5)    ; Right mouse button state
  4175.     addq.w    #1,D0            ; Important!
  4176.     addq.w    #1,D1            ; Important!
  4177.  
  4178. *
  4179. ** When the mouse hits the limits of the screen, we scroll the bitmap
  4180. ** to the direction where the mouse hits the screen limits, so we display
  4181. ** the normally invisible parts.
  4182. *
  4183. .ScrollRight
  4184.     cmp.w    D0,D2            ; MouseX + 1 same as screenwidth (not bitmap!)
  4185.     bhi.s    .ScrollDown        ; If not, mouse not at border...
  4186.  
  4187.     cmp.w    D4,D6            ; Right border reached ? (max == current ?)
  4188.     bge.s    .ScrollDown        ; - then not at the border of the bitmap...
  4189.  
  4190.     st.b    _RIChanged(A5)        ; Else indicate: Must "Rethink Display" after this action
  4191.  
  4192.     btst    #2,_RMB(A5)        ; Right mouse button?
  4193.     beq.s    .SR16            ; - then move faster...
  4194. .SR1
  4195.     addq.w    #1,D6            ; One more pixel (right side) + 1 to display
  4196.     addq.w    #1,ri_RxOffset(A3)    ; Change offset so the hidden pixel can be displayed
  4197.     bra.s    .ScrollDown        ; Check for down scrolling
  4198. .SR16    
  4199.     move.w    D6,_Max(A5)        ; RMB - maximum visible  (_Max(A5) is only a dummy -
  4200. *                      haven't got enought registers....
  4201.     addi.w    #16,_Max(A5)        ; plus 16 pixels
  4202.     cmp.w    _Max(A5),D4        ; In range? - does it fit?
  4203.     blt.s    .SR1            ; If not...
  4204.     addi.w    #16,D6            ; Else 16 pixels more to display
  4205.     addi.w    #16,ri_RxOffset(A3)    ; Change offset (X) so those hidden 16 pixels can
  4206. *                    ; be displayed    
  4207. .ScrollDown
  4208.     cmp.w    D1,D3            ; MouseY + 1 same as bottom of screen (not bitmap!)
  4209.     bhi.s    .ScrollLeft        ; If not, screen border not touched...
  4210.  
  4211.     cmp.w    D5,D7            ; max == current ?
  4212.     bge.s    .ScrollLeft
  4213.  
  4214.     st.b    _RIChanged(A5)
  4215.  
  4216.     btst    #2,_RMB(A5)
  4217.     beq.s    .SD16
  4218. .SD1
  4219.     addq.w    #1,D7
  4220.     addq.w    #1,ri_RyOffset(A3)
  4221.     bra.s    .ScrollLeft
  4222. .SD16
  4223.     move.w    D7,_Max(A5)
  4224.     addi.w    #16,_Max(A5)
  4225.     cmp.w    _Max(A5),D5
  4226.     blt.s    .SD1
  4227.  
  4228.     addi.w    #16,D7
  4229.     addi.w    #16,ri_RyOffset(A3)
  4230.  
  4231. .ScrollLeft
  4232.     tst.w    sc_MouseX(A4)        ; Top of screen touched with mouse?
  4233.     bne.s    .ScrollUp
  4234.  
  4235.     cmp.w    D2,D6            ; std == current ?
  4236.     bls.s    .ScrollUp
  4237.  
  4238.     st.b    _RIChanged(A5)
  4239.  
  4240.     btst    #2,_RMB(A5)
  4241.     beq.s    .SL16
  4242. .SL1
  4243.     subq.w    #1,D6
  4244.     subq.w    #1,ri_RxOffset(A3)
  4245.     bra.s    .ScrollUp
  4246. .SL16
  4247.     move.w    D6,_Max(A5)
  4248.     subi.w    #16,_Max(A5)
  4249.     cmp.w    _Max(A5),D2
  4250.     bhi.s    .SL1
  4251.  
  4252.     subi.w    #16,D6
  4253.     subi.w    #16,ri_RxOffset(A3)
  4254.  
  4255. .ScrollUp
  4256.     tst.w    sc_MouseY(A4)        ; Left border touched with mouse?
  4257.     bne.s    .Check
  4258.  
  4259.     cmp.w    D3,D7            ; std == current ?
  4260.     bls.s    .Check
  4261.  
  4262.     st.b    _RIChanged(A5)
  4263.  
  4264.     btst    #2,_RMB(A5)
  4265.     beq.s    .SU16
  4266. .SU1
  4267.     subq.w    #1,D7
  4268.     subq.w    #1,ri_RyOffset(A3)
  4269.     bra.s    .Check
  4270. .SU16
  4271.     move.w    D7,_Max(A5)
  4272.     subi.w    #16,_Max(A5)
  4273.     cmp.w    _Max(A5),D3
  4274.     bhi.s    .SU1
  4275.  
  4276.     subi.w    #16,D7
  4277.     subi.w    #16,ri_RyOffset(A3)
  4278.  
  4279. .Check
  4280.     tst.b    _RIChanged(A5)        ; RasInfo changed?
  4281.     beq.s    .PureWait        ; No, wait only
  4282.  
  4283.     tst.l    _ViewPortShare(A5)    ; Assumption: If we can share the ViewPort we
  4284.     bmi.s    .mustblit        ; can also change the RasInfo-offsets!
  4285.  
  4286. * Called under OS1.x, 2.x and OS3.x when a native Amiga monitor is available.
  4287. * CyberGraphX will also end here...
  4288.     movea.l    _IntuitionBase(A5),A6
  4289.     movea.l    A4,A0            ; Screen
  4290.     jsr    _LVOMakeScreen(A6)    ; Move screen contents
  4291.     jsr    _LVORethinkDisplay(A6)    ; and make them visible
  4292.     bra.s    .CheckLMB
  4293.  
  4294. .mustblit    ; This is only for alien gfx-board software packages... (Picasso96)
  4295.     movem.l    D2-D7/A2,-(sp)        ; » We have to blit the non visible part
  4296. *                        into the display
  4297.  
  4298.     lea    _BitmapStruc(A5),A0    ; Image's bitmap
  4299.     lea    sc_RastPort(A4),A1    ; Screen's RastPort
  4300.     movea.l    rp_BitMap(A1),A1    ; Screen's BitMap
  4301.     suba.l    A2,A2            ; No Temp
  4302.     move.w    D6,D0            ; Last displayable pixel X
  4303.     move.w    D7,D1            ; Last displayable pixel Y
  4304.     moveq    #0,D2            ; DestX
  4305.     moveq    #0,D3            ; DestY
  4306.     move.w    _PlaneWidth(A5),D4    ; Width
  4307.     move.w    _PlaneHeight(A5),D5    ; Height
  4308.     sub.w    D4,D0            ; = SrcX
  4309.     sub.w    D5,D1            ; = SrcY
  4310.     move.b    #$C0,D6            ; Cooky cut
  4311.     move.b    #$FF,D7            ; All planes
  4312.  
  4313.     movem.l    D0-D1/A0-A1,-(sp)
  4314.     movea.l    _GfxBase(A5),A6
  4315.     jsr    _LVOWaitBlit(A6)
  4316.     movem.l    (sp)+,D0-D1/A0-A1
  4317.  
  4318.     jsr    _LVOBltBitMap(A6)
  4319.     jsr    _LVOWaitBlit(A6)
  4320.  
  4321.     movem.l    (sp)+,D2-D7/A2
  4322.     bra.s    .CheckLMB
  4323.  
  4324. .PureWait
  4325.     moveq    #4,D1            ; Wait 4/50 or 4/60 seconds
  4326.     movea.l    _DOSBase(A5),A6
  4327.     jsr    _LVODelay(A6)
  4328.  
  4329. .CheckLMB
  4330.     btst    #6,$BFE001        ; Left mouse button?
  4331.     bne.w    .Wait
  4332.  
  4333.     movem.l    (sp)+,D2-D7/A2-A4
  4334.  
  4335.     movea.l    D2,A0            ; Screen
  4336.     movea.l    _IntuitionBase(A5),A6
  4337.     jsr    _LVOCloseScreen(A6)
  4338.     bsr.w    _RestoreView        ; See there
  4339. 2$
  4340.     tst.l    _Bitplane(A5)        ; Bitplane allocated?
  4341.     beq.s    3$
  4342.     movea.l    _Bitplane(A5),A1
  4343.     move.l    _AllPlaneSize(A5),D0
  4344.     clr.l    _AllPlaneSize(A5)
  4345.     clr.l    _Bitplane(A5)
  4346.     movea.l    _SysBase(A5),A6
  4347.     jsr    _LVOFreeMem(A6)        ; Free bitplanes
  4348. 3$
  4349.     movea.l    _IntuitionBase(A5),A6
  4350.     movea.l    _WindowPtr(A5),A0
  4351.     jsr    _LVOActivateWindow(A6)    ; Activate our window
  4352.  
  4353.     addq.l    #4,sp
  4354.     bra.w    _LoadNew        ; Display requester
  4355.  
  4356. ************************************************************************
  4357. *
  4358. ** Subroutines to set correct view for overscan pictures of ks lower v36.
  4359. *
  4360.  
  4361. _SetView
  4362.     movem.l    D0-D1/A0-A1/A6,-(sp)
  4363.     movea.l    _IntuitionBase(A5),A6
  4364.     cmpi.w    #35,LIB_VERSION(A6)    ; Lower V36?
  4365.     bhi.s    .OSOScanSet
  4366.  
  4367.     jsr    _LVOViewAddress(A6)    ; Get view
  4368.     movea.l    D0,A0
  4369.     move.w    v_DyOffset(A0),_OldY(A5) ; Save old offset
  4370.     move.w    v_DxOffset(A0),_OldX(A5)
  4371.  
  4372.     cmpi.w    #320,_PlaneWidth(A5)    ; Lower than 320?
  4373.     bls.s    1$            ; No overscan!
  4374.     cmpi.w    #352,_PlaneWidth(A5)    ; If it fits, we have
  4375.     bls.s    2$            ; an overscan-screen
  4376.  
  4377.     cmpi.w    #640,_PlaneWidth(A5)    ; Lower than 640?
  4378.     bls.s    1$            ; No overscan!
  4379.  
  4380.     bra.s    2$            ; Else we have an overscan-screen
  4381.  
  4382. 1$
  4383.     cmpi.w    #256,_PlaneHeight(A5)    ; Lower than 256?
  4384.     bls.s    .NoOScan        ; No overscan!
  4385.     cmpi.w    #290,_PlaneHeight(A5)    ; If it fits, we have
  4386.     bls.s    2$            ; an overscan-screen
  4387.  
  4388.     cmpi.w    #512,_PlaneHeight(A5)    ; Lower than 512?
  4389.     bls.s    .NoOScan        ; No overscan!
  4390.  
  4391. 2$    ; We have an overscan screen!
  4392.     move.w    #30,v_DyOffset(A0)    ; Change dyOffset
  4393.     move.w    #112,v_DxOffset(A0)    ; Change dxOffset
  4394.     jsr    _LVORethinkDisplay(A6)    ; Make display
  4395.  
  4396. .NoOScan
  4397.     movem.l    (sp)+,D0-D1/A0-A1/A6
  4398.     rts
  4399.  
  4400. * Let the system do the work (up from OS2.0)...
  4401. .OSOScanSet
  4402.     lea    _StdTags(A5),A0
  4403.     movea.l    4(A0),A0        ; MonitorID
  4404.     clr.l    -(sp)            ; Make room for rectangle - see gfx.i
  4405.     clr.l    -(sp)
  4406.     movea.l    sp,A1            ; Rectangle
  4407.     moveq    #OSCAN_STANDARD,D0    ; The simply - may improve on your own...
  4408.     jsr    _LVOQueryOverscan(A6)    ; Give me informations...
  4409.     tst.l    D0            ; Failed?
  4410.     beq.s    .NoOScan
  4411.     movea.l    sp,A0            ; Rectangle
  4412.     lea    _NewScreen(A5),A1
  4413.     move.w    (A0),(A1)        ; ( ra_MinX(A0),ns_LeftEdge(A1) )
  4414.     move.w    ra_MinY(A0),ns_TopEdge(A1)
  4415.     addq.l    #8,sp
  4416.     bra.s    .NoOScan        ; Set...
  4417.  
  4418. _RestoreView
  4419.     movem.l    D0-D1/A0-A1/A6,-(sp)
  4420.     movea.l    _IntuitionBase(A5),A6
  4421.     cmpi.w    #35,LIB_VERSION(A6)    ; Ks 1.3 including Headly-Monitor?
  4422.     bhi.s    .NotNeeded        ; At least Kickstart 2.0 ßeta...
  4423.  
  4424.     jsr    _LVOViewAddress(A6)    ; Get old offsets
  4425.     movea.l    D0,A0
  4426.     move.w    _OldY(A5),v_DyOffset(A0); Restore them
  4427.     move.w    _OldX(A5),v_DxOffset(A0)
  4428.     jsr    _LVORethinkDisplay(A6)
  4429. .NotNeeded
  4430.     movem.l    (sp)+,D0-D1/A0-A1/A6
  4431.     rts
  4432.  
  4433. ************************************************************************
  4434. *
  4435. ** Running OS 1.x or the required mode is not available (up from OS 2.x)
  4436. *
  4437. * Video Overscan taken as limit to check against...
  4438. *
  4439.  
  4440. _DefaultMonitor
  4441.     moveq    #0,D0
  4442.     cmpi.w    #362,_PlaneWidth(A5)    ; Los-Res maximum?
  4443.     bhi.s    .MinMedRes        ; If taller, at least Med-Res
  4444.     bra.s    .CheckILace
  4445. .MinMedRes
  4446.     ori.w    #V_HIRES,D0        ; Set Hires key
  4447.  
  4448. .CheckILace
  4449.     cmpi.w    #283,_PlaneHeight(A5)    ; Maximum for PAL non-interlace
  4450.     bhi.s    .ItsInterlace        ; else we have to set interlace-bit
  4451.     bra.s    .CheckNTSC
  4452. .ItsInterlace
  4453.     ori.w    #V_LACE,D0        ; Set LACE-key
  4454.  
  4455. .CheckNTSC
  4456.     movea.l    _GfxBase(A5),A6
  4457.     move.w    gb_DisplayFlags(A6),D1
  4458.     btst    #2,D1            ; PAL or NTSC ($4 means PAL)?
  4459.     bne.s    .VMSet            ; was PAL
  4460.  
  4461.     btst    #2,D0            ; else NTSC - check for interlace ($4 means V_LACE)
  4462.     bne.s    .VMSet            ; Since already set
  4463.  
  4464.     cmpi.w    #241,_PlaneHeight(A5)    ; Maximum for NTSC non-lace
  4465.     bls.s    .VMSet
  4466.     ori.w    #V_LACE,D0
  4467.  
  4468. .VMSet
  4469.     move.l    _ViewPortMod(A5),D1
  4470.     btst    #11,D1            ; HAM-Key? (HAM or HAM8?)
  4471.     beq.s    .SetDim            ; No HAM, else
  4472.     ori.w    #V_HAM,D0        ; set HAM-Key
  4473.  
  4474. .SetDim
  4475.     move.l    D0,_ViewPortMod(A5)    ; Save new ViewModes
  4476.  
  4477.     move.w    gb_DisplayFlags(A6),D1
  4478.     andi.w    #V_HIRES,D0
  4479.     bne.s    .Hires
  4480.  
  4481.     cmpi.w    #362,_PlaneWidth(A5)    ; We have a Lores display
  4482.     bls.s    .checkDimHeight
  4483.     move.w    #362,_PlaneWidth(A5)
  4484.     bra.s    .checkDimHeight
  4485.  
  4486. .Hires
  4487.     cmpi.w    #724,_PlaneWidth(A5)    ; We have a Medres or Hires display
  4488.     bls.s    .checkDimHeight
  4489.     move.w    #724,_PlaneWidth(A5)
  4490.  
  4491. .checkDimHeight
  4492.     move.l    _ViewPortMod(A5),D0
  4493.     andi.w    #V_LACE,D0        ; Check for interlace
  4494.     bne.s    .Interlace
  4495.  
  4496.     btst    #2,D1            ; Check display against NTSC / PAL
  4497.     bne.s    .noILacePAL
  4498.  
  4499.     cmpi.w    #241,_PlaneHeight(A5)    ; Non interlace NTSC display
  4500.     bls.s    .done
  4501.     move.w    #241,_PlaneHeight(A5)
  4502.     bra.s    .done
  4503.  
  4504. .noILacePAL
  4505.     cmpi.w    #283,_PlaneHeight(A5)    ; Non interlace PAL display
  4506.     bls.s    .done
  4507.     move.w    #283,_PlaneHeight(A5)
  4508.     bra.s    .done
  4509.  
  4510. .Interlace
  4511.     btst    #2,D1            ; Check Display against NTSC / PAL
  4512.     bne.s    .ILacePAL
  4513.  
  4514.     cmpi.w    #482,_PlaneHeight(A5)    ; Interlace NTSC display
  4515.     bls.s    .done
  4516.     move.w    #482,_PlaneHeight(A5)
  4517.     bra.s    .done
  4518.  
  4519. .ILacePAL
  4520.     cmpi.w    #566,_PlaneHeight(A5)    ; Interlace PAL display
  4521.     bls.s    .done
  4522.     move.w    #566,_PlaneHeight(A5)
  4523. .done
  4524.     rts
  4525.  
  4526. *************************************************************************
  4527. *
  4528. ** Convert a AMIGA BitMap-Structure with 24 bitplanes to the RGB values a
  4529. ** 3rd party gfx-board support.
  4530. ** This routines needs a 68020 CPU.
  4531. ** This routine has been designed as a hack (late after midnight) and so
  4532. ** it looks really dirty. Sorry for that.
  4533. *
  4534.  
  4535.     OPT    P=68020
  4536.  
  4537. _PlanarBMtoRGB24
  4538. *    A0 - bitmap, A1 Rastport
  4539.  
  4540.     movem.l    D2-D7/A2-A6,-(sp)
  4541.  
  4542.     movea.l    A0,A3            ; Bitmap
  4543.     movea.l    A1,A2            ; RastPort
  4544.  
  4545.     tst.l    _CyberGfxBase(A5)
  4546.     bne.s    .start
  4547.     movea.l    _SysBase(A5),A6
  4548.     lea    _CyberGfxName(pc),A1
  4549.     moveq    #40,D0
  4550.     jsr    _LVOOpenLibrary(A6)
  4551.     move.l    D0,_CyberGfxBase(A5)
  4552.     beq.w    .endall
  4553. .start
  4554.     OPT    OW-
  4555.     move.w    bm_BytesPerRow(A3),D0
  4556.     mulu.w    #24,D0
  4557.     move.l    D0,D3
  4558.     move.l    D0,_RGB24Size(A5)
  4559.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  4560.     movea.l    _SysBase(A5),A6
  4561.     jsr    _LVOAllocMem(A6)
  4562.     move.l    D0,_RGB24Ptr(A5)
  4563.     beq.w    .endall
  4564.     OPT    OW+
  4565.  
  4566.     move.l    _CyberGfxBase(A5),D1
  4567.     move.l    _ImageWidth(A5),D2
  4568.  
  4569.     move.l    A5,-(sp)
  4570.     lea    -48(sp),sp        ; Mixed buffer
  4571.     movea.l    sp,A5
  4572.  
  4573.     move.l    D0,24(A5)        ; Data buffer
  4574.     move.l    D1,28(A5)        ; CyberGfxBase
  4575.     move.l    D2,32(A5)        ; ImageWidth
  4576.     move.l    A2,36(A5)        ; RastPort
  4577.     move.l    D3,44(A5)        ; Size of one 24 bit RGB row
  4578.     
  4579.     movea.l    D0,A4            ; RGB24
  4580.  
  4581.     OPT    OW-
  4582.     moveq    #0,D3            ; Line
  4583.     moveq    #0,D4            ; Bytes per row
  4584.     move.w    bm_BytesPerRow(A3),D4    ; As it tells
  4585.     moveq    #0,D7            ; Offset (X) in planar bitmap
  4586.     moveq    #0,D6            ; Pixel per line
  4587.     OPT    OW+
  4588.  
  4589. .nextpixel                ; Read eight pixel (one byte) of each bitplane
  4590. *    moveq    #23,D0            ; For 24 bit-planes
  4591. *    lea    8(A3),A0        ; 1st plane ptr
  4592. *    movea.l    A5,A2            ; Mixed buffer
  4593.  
  4594. *.getB
  4595. *    movea.l    (A0)+,A1
  4596. *    move.b    0(A1,D7.l),(A2)+    ; Read eight pixel (one byte) of each bitplane
  4597. *    subq.w    #1,D0
  4598. *    bcc.s    .getB            ; For 24 bitplanes
  4599.  
  4600. *    movem.l    D3-D4/D6-D7/A3-A5,-(sp)
  4601.  
  4602. *    movea.l    A5,A0
  4603. *    movem.l    (A0)+,D1-D6
  4604.  
  4605. *
  4606. ** Replaces above, consider yourself what's faster. Read eight pixel (one byte) of each bitplane
  4607. *
  4608.     movem.l    D3-D4/D6-D7/A3-A5,-(sp)    ; Replacement start
  4609.     OPT    OW-
  4610.  
  4611.     lea    bm_Planes(A3),A0    ; 1st plane ptr
  4612.     moveq    #8,D0
  4613.  
  4614.     move.b    ([0,A0],D7.l),D1    ; Read 8 pixel of bit-plane 0
  4615.     lsl.w    D0,D1
  4616.     move.b    ([4,A0],D7.l),D1    ; Read 8 pixel of bit-plane 1
  4617.     lsl.l    D0,D1
  4618.     move.b    ([8,A0],D7.l),D1    ; Read 8 pixel of bit-plane 2
  4619.     lsl.l    D0,D1
  4620.     move.b    ([12,A0],D7.l),D1    ; Read 8 pixel of bit-plane 3
  4621.  
  4622.     move.b    ([16,A0],D7.l),D2    ; Read 8 pixel of bit-plane 4
  4623.     lsl.w    D0,D2
  4624.     move.b    ([20,A0],D7.l),D2    ; Read 8 pixel of bit-plane 5
  4625.     lsl.l    D0,D2
  4626.     move.b    ([24,A0],D7.l),D2    ; Read 8 pixel of bit-plane 6
  4627.     lsl.l    D0,D2
  4628.     move.b    ([28,A0],D7.l),D2    ; Read 8 pixel of bit-plane 7
  4629.  
  4630.     move.b    ([32,A0],D7.l),D3    ; Read 8 pixel of bit-plane 8
  4631.     lsl.w    D0,D3
  4632.     move.b    ([36,A0],D7.l),D3    ; Read 8 pixel of bit-plane 9
  4633.     lsl.l    D0,D3
  4634.     move.b    ([40,A0],D7.l),D3    ; Read 8 pixel of bit-plane 10
  4635.     lsl.l    D0,D3
  4636.     move.b    ([44,A0],D7.l),D3    ; Read 8 pixel of bit-plane 11
  4637.  
  4638.     move.b    ([48,A0],D7.l),D4    ; Read 8 pixel of bit-plane 12
  4639.     lsl.w    D0,D4
  4640.     move.b    ([52,A0],D7.l),D4    ; Read 8 pixel of bit-plane 13
  4641.     lsl.l    D0,D4
  4642.     move.b    ([56,A0],D7.l),D4    ; Read 8 pixel of bit-plane 14
  4643.     lsl.l    D0,D4
  4644.     move.b    ([60,A0],D7.l),D4    ; Read 8 pixel of bit-plane 15
  4645.  
  4646.      move.b    ([64,A0],D7.l),D5    ; Read 8 pixel of bit-plane 16
  4647.     lsl.w    D0,D5
  4648.     move.b    ([68,A0],D7.l),D5    ; Read 8 pixel of bit-plane 17
  4649.     lsl.l    D0,D5
  4650.     move.b    ([72,A0],D7.l),D5    ; Read 8 pixel of bit-plane 18
  4651.     lsl.l    D0,D5
  4652.     move.b    ([76,A0],D7.l),D5    ; Read 8 pixel of bit-plane 19
  4653.  
  4654.     move.b    ([80,A0],D7.l),D6    ; Read 8 pixel of bit-plane 20
  4655.     lsl.w    D0,D6
  4656.     move.b    ([84,A0],D7.l),D6    ; Read 8 pixel of bit-plane 21
  4657.     lsl.l    D0,D6
  4658.     move.b    ([88,A0],D7.l),D6    ; Read 8 pixel of bit-plane 22
  4659.     lsl.l    D0,D6
  4660.     move.b    ([92,A0],D7.l),D6    ; Read 8 pixel of bit-plane 23
  4661.  
  4662.     OPT    OW+            ; Replacement end
  4663.  
  4664. *
  4665. ** Registers (D1-D6) filled with 24 bytes each holding 8 pixel
  4666. *
  4667. .getColour
  4668.     movea.l    A4,A0            ; RGB24 buffer
  4669.  
  4670.     move.l    D1,A1
  4671.     move.l    D2,A2
  4672.     move.l    D3,A3
  4673.     move.l    D4,A4
  4674.     move.l    D5,A5
  4675.     move.l    D6,A6
  4676.  
  4677.     move.l    #$80808080,D0
  4678.     and.l    D0,D1            ; bit 0 of plane 0,1,2,3
  4679.     and.l    D0,D2            ; bit 0 of plane 4,5,6,7
  4680.     and.l    D0,D3            ; bit 0 of plane 8,9,10,11
  4681.     and.l    D0,D4            ; bit 0 of plane 12,13,14,15
  4682.     and.l    D0,D5            ; bit 0 of plane 16,17,18,19
  4683.     and.l    D0,D6            ; bit 0 of plane 20,21,22,23
  4684.  
  4685.     moveq    #-34,D0            ; See 'Counting ...' below for explain
  4686.     move.l    D0,-(sp)
  4687.  
  4688. .GetPixelColour
  4689.  
  4690. * Get the red bits (8 per gun) (24 bit)
  4691.  
  4692. * Original R0 pixel 0 bit 31 , R1 pixel 0 bit 23 , R2 pixel 0 bit 15, R3 pixel 0 bit 0 in D1.L
  4693.  
  4694.     move.b    D1,D0            ; R3 pixel 0 in D0.b
  4695.     lsr.w    #8,D1            ; Get R2 pixel 0 on byte position in D1.b
  4696.     lsr.b    #4,D0            ; R3 pixel 0 on position 3
  4697.     lsr.b    #5,D1            ; R2 pixel 0 on position 2
  4698.     or.b    D0,D1
  4699.     move.b    D1,D7            ; Half lower nibble in D7 (bits 3 and 2)    
  4700.  
  4701.     swap.w    D1            ; Original R0 pixel 0, R1 pixel 0, R2 pixel 0, R3 pixel 0 in D1.L
  4702. *                      R0 pixel 0 and R1 pixel 0 in D1.w
  4703.  
  4704.     move.b    D1,D0            ; R1 pixel 0 in D0
  4705.     lsr.w    #8,D1            ; Get R0 pixel 0 on byte position
  4706.     lsr.b    #6,D0            ; R1 pixel 0 on position 1
  4707.     lsr.b    #7,D1            ; R0 pixel 0 on position 0
  4708.     or.b    D0,D1
  4709.     or.b    D1,D7            ; R3 R2 R1 R0
  4710.  
  4711. * --------------------
  4712.  
  4713. * Original R4 pixel 0 bit 31 , R5 pixel 0 bit 23 , R6 pixel 0 bit 15, R7 pixel 0 bit 0 in D2.L
  4714.  
  4715.     move.b    D2,D0            ; R7 pixel 0 in D0
  4716.     lsr.w    #8,D2            ; Get R6 pixel 0 on byte position
  4717. *    lsr.b    #0,D0            ; R7 pixel 0 on position 7
  4718.     lsr.b    #1,D2            ; R6 pixel 0 on position 6
  4719.     or.b    D0,D2
  4720.     or.b    D2,D7            ; R7 R6 nn nn R3, R2, R1, R0
  4721.  
  4722.     swap.w    D2            ; Original R4 pixel 0, R5 pixel 0 in D2.L
  4723. *                      R4 pixel 0, R5 pixel 0 in D2.w
  4724.  
  4725.     move.b    D2,D0            ; R5 pixel 0 in D0
  4726.     lsr.w    #8,D2            ; Get R4 pixel 0 on byte position
  4727.     lsr.b    #2,D0            ; R5 pixel 0 on position 5
  4728.     lsr.b    #3,D2            ; R4 pixel 0 on position 4
  4729.     or.b    D0,D2
  4730.     or.b    D2,D7            ; R0, R1, R2, R3, R4, R1 nn nn
  4731.  
  4732.     move.b    D7,(A0)+        ; Store red value
  4733.  
  4734. * -------------------------------------------------------------------
  4735.  
  4736. * Get the green bits (8 ber gun) (24 bit)
  4737.  
  4738.     move.b    D3,D0            ; G3 pixel 0 in D0
  4739.     lsr.w    #8,D3            ; Get G2 pixel 0 on byte position
  4740.     lsr.b    #4,D0            ; G3 pixel 0 on position 3
  4741.     lsr.b    #5,D3            ; G2 pixel 0 on position 2
  4742.     or.b    D0,D3
  4743.     move.b    D3,D7            ; nn nn nn nn G3 G2 nn nn    
  4744.  
  4745.     swap.w    D3            ; Original G0 pixel 0, G1 pixel 0, G2 pixel 0, G3 pixel 0
  4746. *                      now G0 pixel 0, G1 pixel 0 in D3.w
  4747.  
  4748.     move.b    D3,D0            ; G1 pixel 0 in D0
  4749.     lsr.w    #8,D3            ; Get G0 pixel 0 on byte position
  4750.     lsr.b    #6,D0            ; G1 pixel 0 on position 1
  4751.     lsr.b    #7,D3            ; G0 pixel 0 on position 0
  4752.     or.b    D0,D3
  4753.     or.b    D3,D7            ; nn nn nn nn G3 G2 G1 G0
  4754.  
  4755. * -------------------
  4756.  
  4757.     move.b    D4,D0            ; G7 pixel 0 in D0
  4758.     lsr.w    #8,D4            ; Get G6 pixel 0 on byte position
  4759. *    lsr.b    #0,D0            ; G7 pixel 0 on position 7
  4760.     lsr.b    #1,D4            ; G6 pixel 0 on position 6
  4761.     or.b    D0,D4
  4762.     or.b    D4,D7            ; G7 G6 nn nn G3 G2 G1 G0    
  4763.  
  4764.     swap.w    D4            ; Original G4 pixel 0, G5 pixel 0, G6 pixel 0, G7 pixel 0
  4765. *                      now G4 pixel 0, G5 pixel 0 in D4.w
  4766.  
  4767.     move.b    D4,D0            ; G5 pixel 0 in D0
  4768.     lsr.w    #8,D4            ; Get G4 pixel 0 on byte position
  4769.     lsr.b    #2,D0            ; G5 pixel 0 on position 5
  4770.     lsr.b    #3,D4            ; G4 pixel 0 on position 4
  4771.     or.b    D0,D4
  4772.     or.b    D4,D7            ; G7 G6 G5 G4 G3 G2 G1 G0
  4773.  
  4774.     move.b    D7,(A0)+        ; Store green value
  4775. * -------------------------------------------------------------------
  4776.  
  4777. * Get the blue bits (8 ber gun) (24 bit)
  4778.  
  4779.     move.b    D5,D0            ; B3 pixel 0 in D0
  4780.     lsr.w    #8,D5            ; Get B2 pixel 0 on byte position
  4781.     lsr.b    #4,D0            ; B3 pixel 0 on position 3
  4782.     lsr.b    #5,D5            ; B2 pixel 0 on position 2
  4783.     or.b    D0,D5
  4784.     move.b    D5,D7            ; nn nn nn nn B3 B2 nn nn    
  4785.  
  4786.     swap.w    D5            ; Original B0 pixel 0, B1 pixel 0, B2 pixel 0, B3 pixel 0
  4787. *                      now B0 pixel 0, B1 pixel 0 in D5.w
  4788.  
  4789.     move.b    D5,D0            ; B1 pixel 0 in D0
  4790.     lsr.w    #8,D5            ; Get B0 pixel 0 on byte position
  4791.     lsr.b    #6,D0            ; B1 pixel 0 on position 1
  4792.     lsr.b    #7,D5            ; B0 pixel 0 on position 0
  4793.     or.b    D0,D5
  4794.     or.b    D5,D7            ; nn nn nn nn B3 B2 B1 B0
  4795.  
  4796. * -------------------
  4797.  
  4798.     move.b    D6,D0            ; B7 pixel 0 in D0
  4799.     lsr.w    #8,D6            ; Get B6 pixel 0 on byte position
  4800. *    lsr.b    #0,D0            ; B7 pixel 0 on position 7
  4801.     lsr.b    #1,D6            ; B6 pixel 0 on position 6
  4802.     or.b    D0,D6
  4803.     or.b    D6,D7            ; B7 B6 nn nn B3 B2 B1 B0    
  4804.  
  4805.     swap.w    D6            ; Original B4 pixel 0, B5 pixel 0, B6 pixel 0, B7 pixel 0
  4806. *                      now B4 pixel 0, B5 pixel 0 in D6.w
  4807.  
  4808.     move.b    D6,D0            ; B5 pixel 0 in D0
  4809.     lsr.w    #8,D6            ; Get B4 pixel 0 on byte position
  4810.     lsr.b    #2,D0            ; B5 pixel 0 on position 5
  4811.     lsr.b    #3,D6            ; B4 pixel 0 on position 4
  4812.     or.b    D0,D6
  4813.     or.b    D6,D7            ; B7 B6 B5 B4 B3 B2 B1 B0
  4814.  
  4815.     move.b    D7,(A0)+        ; Store blue value
  4816. * -------------------------------------------------------------------
  4817.  
  4818. * Repeat GetPixelColour until a complete byte (8 pixel) is worked out...
  4819.  
  4820.     move.l    (sp)+,D0
  4821.  
  4822.     move.l    A1,D1
  4823.     move.l    A2,D2
  4824.     move.l    A3,D3
  4825.     move.l    A4,D4
  4826.     move.l    A5,D5
  4827.     move.l    A6,D6
  4828.  
  4829. .thejump
  4830.     addi.l    #36,D0
  4831.     move.l    D0,-(sp)
  4832.  
  4833.     jmp    (pc,D0.w)        ; An opcode for 32 bit CPUs only
  4834.  
  4835. .mask1                    ; Counting 2 :: (-34) = (+2 - +36 = -34) -> 1st offset to PC to reach this (.mask1)
  4836.     move.l    #$40404040,D0        ; -- Each mask has got 15 instruction surrounded by 36 bytes code
  4837.     and.l    D0,D1            ; bit 1 of plane 0,1,2,3
  4838.     and.l    D0,D2            ; bit 1 of plane 4,5,6,7
  4839.     and.l    D0,D3            ; bit 1 of plane 8,9,10,11
  4840.     and.l    D0,D4            ; bit 1 of plane 12,13,14,15
  4841.     and.l    D0,D5            ; bit 1 of plane 16,17,18,19
  4842.     and.l    D0,D6            ; bit 1 of plane 20,21,22,23
  4843.     moveq    #1,D0
  4844.     lsl.l    D0,D1
  4845.     lsl.l    D0,D2
  4846.     lsl.l    D0,D3
  4847.     lsl.l    D0,D4
  4848.     lsl.l    D0,D5
  4849.     lsl.l    D0,D6
  4850.     bra.w    .GetPixelColour
  4851.  
  4852. .mask2
  4853.     move.l    #$20202020,D0
  4854.     and.l    D0,D1            ; bit 2 of plane 0,1,2,3
  4855.     and.l    D0,D2            ; bit 2 of plane 4,5,6,7
  4856.     and.l    D0,D3            ; bit 2 of plane 8,9,10,11
  4857.     and.l    D0,D4            ; bit 2 of plane 12,13,14,15
  4858.     and.l    D0,D5            ; bit 2 of plane 16,17,18,19
  4859.     and.l    D0,D6            ; bit 2 of plane 20,21,22,23
  4860.     moveq    #2,D0
  4861.     lsl.l    D0,D1
  4862.     lsl.l    D0,D2
  4863.     lsl.l    D0,D3
  4864.     lsl.l    D0,D4
  4865.     lsl.l    D0,D5
  4866.     lsl.l    D0,D6
  4867.     bra.w    .GetPixelColour
  4868.  
  4869. .mask3
  4870.     move.l    #$10101010,D0
  4871.     and.l    D0,D1            ; bit 3 of plane 0,1,2,3
  4872.     and.l    D0,D2            ; bit 3 of plane 4,5,6,7
  4873.     and.l    D0,D3            ; bit 3 of plane 8,9,10,11
  4874.     and.l    D0,D4            ; bit 3 of plane 12,13,14,15
  4875.     and.l    D0,D5            ; bit 3 of plane 16,17,18,19
  4876.     and.l    D0,D6            ; bit 3 of plane 20,21,22,23
  4877.     moveq    #3,D0
  4878.     lsl.l    D0,D1
  4879.     lsl.l    D0,D2
  4880.     lsl.l    D0,D3
  4881.     lsl.l    D0,D4
  4882.     lsl.l    D0,D5
  4883.     lsl.l    D0,D6
  4884.     bra.w    .GetPixelColour
  4885.  
  4886. .mask4
  4887.     move.l    #$08080808,D0
  4888.     and.l    D0,D1            ; bit 4 of plane 0,1,2,3
  4889.     and.l    D0,D2            ; bit 4 of plane 4,5,6,7
  4890.     and.l    D0,D3            ; bit 4 of plane 8,9,10,11
  4891.     and.l    D0,D4            ; bit 4 of plane 12,13,14,15
  4892.     and.l    D0,D5            ; bit 4 of plane 16,17,18,19
  4893.     and.l    D0,D6            ; bit 4 of plane 20,21,22,23
  4894.     moveq    #4,D0
  4895.     lsl.l    D0,D1
  4896.     lsl.l    D0,D2
  4897.     lsl.l    D0,D3
  4898.     lsl.l    D0,D4
  4899.     lsl.l    D0,D5
  4900.     lsl.l    D0,D6
  4901.     bra.w    .GetPixelColour
  4902.  
  4903. .mask5
  4904.     move.l    #$04040404,D0
  4905.     and.l    D0,D1            ; bit 5 of plane 0,1,2,3
  4906.     and.l    D0,D2            ; bit 5 of plane 4,5,6,7
  4907.     and.l    D0,D3            ; bit 5 of plane 8,9,10,11
  4908.     and.l    D0,D4            ; bit 5 of plane 12,13,14,15
  4909.     and.l    D0,D5            ; bit 5 of plane 16,17,18,19
  4910.     and.l    D0,D6            ; bit 5 of plane 20,21,22,23
  4911.     moveq    #5,D0
  4912.     lsl.l    D0,D1
  4913.     lsl.l    D0,D2
  4914.     lsl.l    D0,D3
  4915.     lsl.l    D0,D4
  4916.     lsl.l    D0,D5
  4917.     lsl.l    D0,D6
  4918.     bra.w    .GetPixelColour
  4919.  
  4920. .mask6
  4921.     move.l    #$02020202,D0
  4922.     and.l    D0,D1            ; bit 6 of plane 0,1,2,3
  4923.     and.l    D0,D2            ; bit 6 of plane 4,5,6,7
  4924.     and.l    D0,D3            ; bit 6 of plane 8,9,10,11
  4925.     and.l    D0,D4            ; bit 6 of plane 12,13,14,15
  4926.     and.l    D0,D5            ; bit 6 of plane 16,17,18,19
  4927.     and.l    D0,D6            ; bit 6 of plane 20,21,22,23
  4928.     moveq    #6,D0
  4929.     lsl.l    D0,D1
  4930.     lsl.l    D0,D2
  4931.     lsl.l    D0,D3
  4932.     lsl.l    D0,D4
  4933.     lsl.l    D0,D5
  4934.     lsl.l    D0,D6
  4935.     bra.w    .GetPixelColour
  4936.  
  4937. .mask7
  4938.     move.l    #$01010101,D0
  4939.     and.l    D0,D1            ; bit 7 of plane 0,1,2,3
  4940.     and.l    D0,D2            ; bit 7 of plane 4,5,6,7
  4941.     and.l    D0,D3            ; bit 7 of plane 8,9,10,11
  4942.     and.l    D0,D4            ; bit 7 of plane 12,13,14,15
  4943.     and.l    D0,D5            ; bit 7 of plane 16,17,18,19
  4944.     and.l    D0,D6            ; bit 7 of plane 20,21,22,23
  4945.     moveq    #7,D0
  4946.     lsl.l    D0,D1
  4947.     lsl.l    D0,D2
  4948.     lsl.l    D0,D3
  4949.     lsl.l    D0,D4
  4950.     lsl.l    D0,D5
  4951.     lsl.l    D0,D6
  4952.     bra.w    .GetPixelColour
  4953.  
  4954. .mask8                    ; Does not exist!!!
  4955.     move.l    (sp)+,D0        ; - so, continue...
  4956.  
  4957.     movem.l    (sp)+,D3-D4/D6-D7/A3-A5
  4958.  
  4959.     addq.l    #1,D7            ; Worked out 8 pixel
  4960.     lea    24(A4),A4        ; Increase RGB24 buffer
  4961.  
  4962.     addq.w    #1,D6            ; New byte (8 pixel)
  4963.     cmp.w    D6,D4            ; End of line?
  4964.     bne.w    .nextpixel        ; If no new line
  4965.  
  4966.     movem.l    D3-D4/D7,-(sp)
  4967.  
  4968. * WritePixelArray( SrcRect [pointer to src datas A0]
  4969. *           SrcX    X position D0
  4970. *           SrcY    Y position D1
  4971. *           SrcMod bytes per row in source rectangle D2
  4972. *           RastPort A1
  4973. *           DestX  D3
  4974. *           DestY  D4
  4975. *           SizeX  D5
  4976. *           SizeY  D6
  4977. *           SrcFmt RECTFMT_RGB )
  4978.  
  4979.     OPT    OW-
  4980.     movea.l    24(A5),A0        ; Datas
  4981.     moveq    #0,D0
  4982.     moveq    #0,D1
  4983.     moveq    #0,D2
  4984.     move.l    44(A5),D2
  4985.     movea.l    36(A5),A1        ; RastPort
  4986.     move.l    D3,D4            ; DestY
  4987.     moveq    #0,D3            ; DestX
  4988.     move.l    32(A5),D5        ; Width
  4989.     move.w    #1,D6            ; Height
  4990.     moveq    #RECTFMT_RGB,D7
  4991.     movea.l    28(A5),A6
  4992.     jsr    _LVOWritePixelArray(A6)
  4993.     OPT    OW+
  4994.  
  4995.     movem.l    (sp)+,D3-D4/D7
  4996.  
  4997.     move.l    24(A5),A4        ; RGB24 buffer
  4998.  
  4999.     moveq    #0,D6            ; New X position (starting at zero)
  5000.     addq.w    #1,D3            ; Increase line number
  5001.  
  5002.     cmp.w    bm_Rows(A3),D3        ; Already done for all lines?
  5003.     bne.w    .nextpixel
  5004.  
  5005.     lea    48(sp),sp
  5006.     movea.l    (sp)+,A5
  5007.  
  5008.     move.l    _RGB24Ptr(A5),A1
  5009.     move.l    _RGB24Size(A5),D0
  5010.     movea.l    _SysBase(A5),A6
  5011.     jsr    _LVOFreeMem(A6)
  5012.  
  5013.     moveq    #-1,D0
  5014. .endall
  5015.     movem.l    (sp)+,D2-D7/A2-A6
  5016.     rts
  5017.  
  5018. _PlanarBMtoRGB24end
  5019.     OPT    P=68000
  5020.  
  5021. *****************************************************
  5022. *
  5023. ** Same as above only for 6/8 bitplanes (HAM encoded)
  5024. *
  5025.  
  5026.     OPT    P=68020
  5027.  
  5028. _HAMtoRGB24
  5029. *    A0 - bitmap, A1 Rastport
  5030.  
  5031.     movem.l    D2-D7/A2-A6,-(sp)
  5032.  
  5033.     movea.l    A0,A3            ; Bitmap
  5034.     movea.l    A1,A2            ; RastPort
  5035.  
  5036.     tst.l    _CyberGfxBase(A5)
  5037.     bne.s    .start
  5038.     movea.l    _SysBase(A5),A6
  5039.     lea    _CyberGfxName(pc),A1
  5040.     moveq    #40,D0
  5041.     jsr    _LVOOpenLibrary(A6)
  5042.     move.l    D0,_CyberGfxBase(A5)
  5043.     beq.w    .endall
  5044. .start
  5045.     OPT    OW-
  5046.     move.w    bm_BytesPerRow(A3),D0
  5047.     mulu.w    #24,D0
  5048.     move.l    D0,D3
  5049.     addq.l    #8,D0            ; For one black RGB pixel (mem-allocation boundary = 8 - thus use 8 instead of 3) at left of image
  5050.     move.l    D0,_RGB24Size(A5)
  5051.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  5052.     movea.l    _SysBase(A5),A6
  5053.     jsr    _LVOAllocMem(A6)
  5054.     move.l    D0,_RGB24Ptr(A5)    ; Buffer for RGB24 format
  5055.     beq.w    .endall
  5056.     OPT    OW+
  5057.  
  5058.     move.l    _CyberGfxBase(A5),D1
  5059.     move.l    _ImageWidth(A5),D2
  5060.     lea    _RGB32Colours(A5),A0
  5061.     move.l    A0,D4
  5062.     addq.l    #4,D4            ; Pointer to colours (RGB) for index 0
  5063.  
  5064.     move.l    _HAMSet(A5),D5
  5065.  
  5066.     move.l    A5,-(sp)
  5067.     lea    -56(sp),sp        ; Mixed buffer
  5068.     movea.l    sp,A5
  5069.  
  5070.     addq.l    #8,D0            ; Ignore the black pixel
  5071.     move.l    D0,24(A5)        ; Data buffer
  5072.     move.l    D1,28(A5)        ; CyberGfxBase
  5073.     move.l    D2,32(A5)        ; ImageWidth
  5074.     move.l    A2,36(A5)        ; RastPort
  5075.     move.l    D3,44(A5)        ; Size of one 24 bit RGB row
  5076.     move.l    D4,48(A5)        ; RGB32Colours
  5077.     move.l    D5,52(A5)        ; HAM indicator (HAM6/HAM8)
  5078.     
  5079.     movea.l    D0,A4            ; Data
  5080.  
  5081.     OPT    OW-
  5082.     moveq    #0,D3            ; Line
  5083.     moveq    #0,D4            ; Bytes per row
  5084.     move.w    bm_BytesPerRow(A3),D4    ; As it tells
  5085.     moveq    #0,D5            ; Offset (X) in planar bitmap
  5086.     moveq    #0,D6            ; Pixel per line
  5087.     OPT    OW+
  5088.  
  5089. .nextpixel
  5090.     move.l    52(A5),D0        ; For `n´ bit-planes
  5091.     subq.w    #1,D0
  5092.     lea    8(A3),A0        ; 1st plane ptr
  5093.     movea.l    A5,A2            ; Mixed buffer
  5094.  
  5095. .getB
  5096.     movea.l    (A0)+,A1
  5097.     move.b    0(A1,D5.l),(A2)+    ; Read eight pixel (one byte) of each bitplane
  5098.     subq.w    #1,D0
  5099.     bcc.s    .getB            ; For `n´ bitplanes
  5100.  
  5101.     cmpi.l    #7,52(A5)        ; HAM6 ?
  5102.     bhi.s    .doconvert
  5103.  
  5104.     clr.b    (A2)+            ; HAM6 has got 2 bits less than HAM8
  5105.     clr.b    (A2)+
  5106.  
  5107. .doconvert
  5108.     movem.l    D3-D6/A3-A5,-(sp)
  5109.     bsr.s    .getC
  5110.     movem.l    (sp)+,D3-D6/A3-A5
  5111.  
  5112.     addq.l    #1,D5            ; Worked out 8 pixel
  5113.     lea    24(A4),A4        ; Increase RGB24 buffer
  5114.  
  5115.     addq.w    #1,D6            ; New byte (8 pixel)
  5116.     cmp.w    D6,D4            ; End of line?
  5117.     bne.s    .nextpixel        ; If no new line
  5118.  
  5119.     movem.l    D3-D5,-(sp)
  5120.  
  5121. * WritePixelArray( SrcRect [pointer to src datas A0]
  5122. *           SrcX    X position D0
  5123. *           SrcY    Y position D1
  5124. *           SrcMod bytes per row in source rectangle D2
  5125. *           RastPort A1
  5126. *           DestX  D3
  5127. *           DestY  D4
  5128. *           SizeX  D5
  5129. *           SizeY  D6
  5130. *           SrcFmt RECTFMT_RGB )
  5131.  
  5132.     OPT    OW-
  5133.     movea.l    24(A5),A0        ; Datas
  5134.     moveq    #0,D0
  5135.     moveq    #0,D1
  5136.     moveq    #0,D2
  5137.     move.l    44(A5),D2
  5138.     movea.l    36(A5),A1        ; RastPort
  5139.     move.l    D3,D4            ; DestY
  5140.     moveq    #0,D3            ; DestX
  5141.     move.l    32(A5),D5        ; Width
  5142.     move.w    #1,D6            ; Height
  5143.     moveq    #RECTFMT_RGB,D7
  5144.     movea.l    28(A5),A6
  5145.     jsr    _LVOWritePixelArray(A6)
  5146.     OPT    OW+
  5147.  
  5148.     movem.l    (sp)+,D3-D5
  5149.  
  5150.     move.l    24(A5),A4        ; RGB24 buffer
  5151.  
  5152.     moveq    #0,D6            ; New X position (starting at zero)
  5153.     addq.w    #1,D3            ; Increase line number
  5154.  
  5155.     cmp.w    bm_Rows(A3),D3        ; Already done for all lines?
  5156.     bne.s    .nextpixel
  5157.  
  5158.     lea    56(sp),sp
  5159.     movea.l    (sp)+,A5
  5160.  
  5161.     move.l    _RGB24Ptr(A5),A1
  5162.     move.l    _RGB24Size(A5),D0
  5163.     movea.l    _SysBase(A5),A6
  5164.     jsr    _LVOFreeMem(A6)
  5165.  
  5166.     moveq    #-1,D0
  5167. .endall
  5168.     movem.l    (sp)+,D2-D7/A2-A6
  5169.     rts
  5170.  
  5171. *
  5172. ** Buffer filled with 24 bytes which hold 8 pixel
  5173. *
  5174. .getC
  5175.     movea.l    A5,A0            ; Mixed buffer
  5176.  
  5177.     move.l    (A0)+,D1        ; 4 bytes (plane0 pixel 0-7, plane1 pixel 0-7 and so on
  5178.     move.l    (A0)+,D2
  5179.     moveq    #0,D3
  5180.  
  5181.     movea.l    A4,A0            ; RGB24 buffer
  5182.     movea.l    48(A5),A3        ; Index colour table
  5183.     move.l    D1,A1
  5184.     move.l    D2,A2
  5185.  
  5186.     move.l    #$80808080,D0
  5187.     and.l    D0,D1            ; bit 0 of plane 0,1,2,3
  5188.     and.l    D0,D2            ; bit 0 of plane 4,5,6,7
  5189.  
  5190.     moveq    #-14,D0            ; See 'Counting ...' below for explantion
  5191.     move.l    D0,-(sp)
  5192.  
  5193. .GetPixelColour
  5194.  
  5195. * Original D1 pixel-0 bit 0 , P1 pixel-0 0 bit 1, P2 pixel-0 bit 2, P3 pixel-0 bit 4
  5196.  
  5197.     move.b    D1,D0            ; P3 pixel 0 in D0.b
  5198.     lsr.w    #8,D1            ; Get P2 pixel 0 on byte position in D1.b
  5199.     lsr.b    #4,D0            ; P3 pixel 0 on position 3
  5200.     lsr.b    #5,D1            ; P2 pixel 0 on position 2
  5201.     or.b    D0,D1
  5202.     move.b    D1,D7            ; Half lower nibble in D7 (bits 3 and 2)    
  5203.  
  5204.     swap.w    D1            ; Original P2 pixel 0, P3 pixel 0, P0 pixel 0, P1 pixel 0
  5205. *                      P0 pixel 0 and P1 pixel 0 in D1.w
  5206.  
  5207.     move.b    D1,D0            ; P1 pixel 0 in D0
  5208.     lsr.w    #8,D1            ; Get P1 pixel 0 on byte position
  5209.     lsr.b    #6,D0            ; P1 pixel 0 on position 1
  5210.     lsr.b    #7,D1            ; P0 pixel 0 on position 0
  5211.     or.b    D0,D1
  5212.     or.b    D1,D7            ; P3 P2 P1 P0
  5213.  
  5214. * --------------------
  5215.  
  5216. * Original P4 pixel 0 bit 4, P5 pixel 0 bit 5 , P6 pixel 0 bit 6, P7 pixel 0 bit 7
  5217.  
  5218.     move.b    D2,D0            ; P7 pixel 0 in D0
  5219.     lsr.w    #8,D2            ; Get P6 pixel 0 on byte position
  5220. *    lsr.b    #0,D0            ; P7 pixel 0 on position 7
  5221.     lsr.b    #1,D2            ; P6 pixel 0 on position 6
  5222.     or.b    D0,D2
  5223.     or.b    D2,D7            ; P7 P6 nn nn P3, P2, P1, P0
  5224.  
  5225.     swap.w    D2            ; Original P6 pixel 0, P7 pixel 0
  5226. *                      P6 pixel 0, P7 pixel 0 in D2.w
  5227.  
  5228.     move.b    D2,D0            ; P4 pixel 0 in D0
  5229.     lsr.w    #8,D2            ; Get P5 pixel 0 on byte position
  5230.     lsr.b    #2,D0            ; P4 pixel 0 on position 5
  5231.     lsr.b    #3,D2            ; P5 pixel 0 on position 4
  5232.     or.b    D0,D2
  5233.     or.b    D2,D7            ; P7, P6, P5, P4, P3, P2 P1 P0
  5234.  
  5235.     cmpi.l    #7,52(A5)        ; HAMSet equal to HAM8?
  5236.     bhi.s    .checkham8
  5237.  
  5238.     cmpi.b    #15,D7            ; Index = 15? (HAM6 used)
  5239.     bls.s    .storeHAM6        ; If index lower or equal 15 store unmodified index
  5240.     bra.s    .modifyHAM6        ; Else compute modified index
  5241.  
  5242. .checkham8
  5243.     cmpi.b    #63,D7            ; Index = 63? (HAM8 used)
  5244.     bls.s    .store            ; If index lower or equal 63 store unmodified index
  5245.  
  5246. .modify                    ; Modifiy new pixel by last stored
  5247.     move.b    -3(A0),(A0)+        ; Get red and take over
  5248.     move.b    -3(A0),(A0)+        ; Get green and take over
  5249.     move.b    -3(A0),(A0)+        ; Get blue and take over
  5250.  
  5251.     move.w    D7,D6            ; Index
  5252.  
  5253.     andi.w    #63,D7            ; Without H(old)A(nd)M(odified) bits
  5254.     lsl.b    #2,D7            ; 6-bit value to an 8 bit one
  5255.  
  5256.     andi.w    #192,D6            ; Only H(old)A(nd)M(odified) bits
  5257.     lsr.w    #6,D6            ; into lowest bit positions
  5258.     jmp    (pc,D6.w*2)        ; Calls one of the three `bra.s´ below
  5259.  
  5260.     bra.s    .modifyblue
  5261.     bra.s    .modifyred
  5262.     bra.s    .modifygreen
  5263.  
  5264. .modifyblue
  5265.     move.b    D7,-1(A0)
  5266.     bra.s    .repeat
  5267. .modifygreen
  5268.     move.b    D7,-2(A0)
  5269.     bra.s    .repeat
  5270. .modifyred
  5271.     move.b    D7,-3(A0)
  5272.     bra.s    .repeat
  5273.  
  5274. .modifyHAM6
  5275.     move.b    -3(A0),(A0)+        ; Get red
  5276.     move.b    -3(A0),(A0)+        ; Get green
  5277.     move.b    -3(A0),(A0)+        ; Get blue
  5278.  
  5279.     move.w    D7,D6
  5280.  
  5281.     andi.w    #15,D7            ; Without H(old)A(nd)M(odified) bits
  5282.     move.b    D7,D5            ; Save result
  5283.     lsl.b    #4,D5            ; Low nibble to high nibble
  5284.     or.b    D5,D7            ; Make new value
  5285.  
  5286.     andi.w    #48,D6            ; Only H(old)A(nd)M(odified) bits
  5287.     lsr.w    #4,D6            ; into lowest bit positions
  5288.     jmp    (pc,D6.w*2)
  5289.  
  5290.     bra.s    .modifyblue
  5291.     bra.s    .modifyred
  5292.     bra.s    .modifygreen
  5293.  
  5294. .storeHAM6
  5295.     andi.w    #15,D7
  5296.     move.w    D7,D3            ; INDEX to colour value
  5297.     lsl.w    #3,D3            ; INDEX * 8
  5298.     move.w    D7,D4
  5299.     lsl.w    #2,D4            ; INDEX * 4
  5300.     add.w    D4,D3            ; == mulu 12 D3 (12 bytes per RGB gun used by OS3 structure)
  5301.     lea    0(A3,D3.w),A4        ; Colour values (longwords)
  5302.     move.b    (A4),(A0)+        ; Get only most significant byte
  5303.     move.b    4(A4),(A0)+        ; the same...
  5304.     move.b    8(A4),(A0)+        ; and again
  5305.     bra.s    .repeat
  5306.  
  5307. .store
  5308.     andi.w    #63,D7
  5309.     move.w    D7,D3            ; INDEX to colour value
  5310.     lsl.w    #3,D3            ; INDEX * 8
  5311.     move.w    D7,D4
  5312.     lsl.w    #2,D4            ; INDEX * 4
  5313.     add.w    D4,D3            ; == mulu 12 D3
  5314.     lea    0(A3,D3.w),A4        ; Colour values (longwords)
  5315.     move.b    (A4),(A0)+        ; See above
  5316.     move.b    4(A4),(A0)+
  5317.     move.b    8(A4),(A0)+
  5318.  
  5319. * Repeat GetPixelColour until a complete byte (8 pixel) is worked out...
  5320. .repeat
  5321.     move.l    (sp)+,D0
  5322.  
  5323.     move.l    A1,D1
  5324.     move.l    A2,D2
  5325.  
  5326. .thejump
  5327.     addi.l    #20,D0
  5328.     move.l    D0,-(sp)
  5329.  
  5330.     jmp    (pc,D0.w)        ; Call one of the masks below depending on value in D0
  5331.  
  5332. .end
  5333.     move.l    (sp)+,D0        ; Counting 2
  5334.     rts                ; Counting 4
  5335.  
  5336. .mask1                    ; Counting 6 :: (-14) = (+6 - +20 = -14) -> 1st offset to PC to reach this (.mask1)
  5337.     move.l    #$40404040,D0        ; -- Each mask has got 15 instruction surrounded by 20 bytes code
  5338.     and.l    D0,D1            ; bit 1 of plane 0,1,2,3
  5339.     and.l    D0,D2            ; bit 1 of plane 4,5,6,7
  5340.     moveq    #1,D0
  5341.     lsl.l    D0,D1
  5342.     lsl.l    D0,D2
  5343.     bra.w    .GetPixelColour
  5344.  
  5345. .mask2                    ; 26
  5346.     move.l    #$20202020,D0
  5347.     and.l    D0,D1            ; bit 2 of plane 0,1,2,3
  5348.     and.l    D0,D2            ; bit 2 of plane 4,5,6,7
  5349.     moveq    #2,D0
  5350.     lsl.l    D0,D1
  5351.     lsl.l    D0,D2
  5352.     bra.w    .GetPixelColour
  5353.  
  5354. .mask3                    ; 46
  5355.     move.l    #$10101010,D0
  5356.     and.l    D0,D1            ; bit 3 of plane 0,1,2,3
  5357.     and.l    D0,D2            ; bit 3 of plane 4,5,6,7
  5358.     moveq    #3,D0
  5359.     lsl.l    D0,D1
  5360.     lsl.l    D0,D2
  5361.     bra.w    .GetPixelColour
  5362.  
  5363. .mask4                    ; 66
  5364.     move.l    #$08080808,D0
  5365.     and.l    D0,D1            ; bit 4 of plane 0,1,2,3
  5366.     and.l    D0,D2            ; bit 4 of plane 4,5,6,7
  5367.     moveq    #4,D0
  5368.     lsl.l    D0,D1
  5369.     lsl.l    D0,D2
  5370.     bra.w    .GetPixelColour
  5371.  
  5372. .mask5                    ; 86
  5373.     move.l    #$04040404,D0
  5374.     and.l    D0,D1            ; bit 5 of plane 0,1,2,3
  5375.     and.l    D0,D2            ; bit 5 of plane 4,5,6,7
  5376.     moveq    #5,D0
  5377.     lsl.l    D0,D1
  5378.     lsl.l    D0,D2
  5379.     bra.w    .GetPixelColour
  5380.  
  5381. .mask6
  5382.     move.l    #$02020202,D0
  5383.     and.l    D0,D1            ; bit 6 of plane 0,1,2,3
  5384.     and.l    D0,D2            ; bit 6 of plane 4,5,6,7
  5385.     moveq    #6,D0
  5386.     lsl.l    D0,D1
  5387.     lsl.l    D0,D2
  5388.     bra.w    .GetPixelColour
  5389.  
  5390. .mask7
  5391.     move.l    #$01010101,D0
  5392.     and.l    D0,D1            ; bit 7 of plane 0,1,2,3
  5393.     and.l    D0,D2            ; bit 7 of plane 4,5,6,7
  5394.     moveq    #7,D0
  5395.     lsl.l    D0,D1
  5396.     lsl.l    D0,D2
  5397.     bra.w    .GetPixelColour
  5398.  
  5399. .mask8                    ; Does not exists!!!
  5400.     bra.w    .end
  5401.  
  5402. _HAMtoRGB24end
  5403.     OPT    P=68000
  5404.  
  5405. *****************************************************
  5406. *
  5407. ** Same as above only for more than 9 and less than 17 bitplanes (not HAM) encoded
  5408. *
  5409.  
  5410.     OPT    P=68020
  5411.  
  5412. _CLUTtoRGB16
  5413. *    A0 - bitmap, A1 Rastport
  5414.  
  5415.     movem.l    D2-D7/A2-A6,-(sp)
  5416.  
  5417.     movea.l    A0,A3            ; Bitmap
  5418.     movea.l    A1,A2            ; RastPort
  5419.  
  5420.     tst.l    _CyberGfxBase(A5)
  5421.     bne.s    .start
  5422.     movea.l    _SysBase(A5),A6
  5423.     lea    _CyberGfxName(pc),A1
  5424.     moveq    #40,D0
  5425.     jsr    _LVOOpenLibrary(A6)
  5426.     move.l    D0,_CyberGfxBase(A5)
  5427.     beq.w    .endall
  5428. .start
  5429.     OPT    OW-
  5430.     move.w    bm_BytesPerRow(A3),D0    ; CLUT (9-16 bits) become to a RGB (24 bit) gun, which is written to a 16 bit display
  5431.     mulu.w    #24,D0
  5432.     move.l    D0,D3
  5433.     move.l    D0,_RGB24Size(A5)
  5434.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  5435.     movea.l    _SysBase(A5),A6
  5436.     jsr    _LVOAllocMem(A6)
  5437.     move.l    D0,_RGB24Ptr(A5)    ; Buffer for RGB24 format
  5438.     beq.w    .endall
  5439.     OPT    OW+
  5440.  
  5441.     move.l    _CyberGfxBase(A5),D1
  5442.     move.l    _ImageWidth(A5),D2
  5443.     move.l    _RGB32Values(A5),D4
  5444.  
  5445.     move.l    A5,-(sp)
  5446.     lea    -56(sp),sp        ; Mixed buffer
  5447.     movea.l    sp,A5
  5448.  
  5449. *    move.l    D0,24(A5)        ; Data buffer
  5450. *    move.l    D1,28(A5)        ; CyberGfxBase
  5451. *    move.l    D2,32(A5)        ; ImageWidth
  5452. *    move.l    A2,36(A5)        ; RastPort
  5453. *    move.l    D3,44(A5)        ; Size of one 24 bit RGB row
  5454. *    move.l    D4,48(A5)        ; RGB32Values
  5455.  
  5456.     move.l    D0,32(A5)        ; Data buffer
  5457.     move.l    D1,36(A5)        ; CyberGfxBase
  5458.     move.l    D2,40(A5)        ; ImageWidth
  5459.     move.l    A2,44(A5)        ; RastPort
  5460.     move.l    D3,48(A5)        ; Size of one 24 bit RGB row
  5461.     move.l    D4,52(A5)        ; RGB32Values
  5462.     
  5463.     movea.l    D0,A4            ; Data
  5464.  
  5465.     OPT    OW-
  5466.     moveq    #0,D3            ; Line
  5467.     moveq    #0,D4            ; Bytes per row
  5468.     move.w    bm_BytesPerRow(A3),D4    ; As it tells
  5469.     moveq    #0,D5            ; Offset (X) in planar bitmap
  5470.     moveq    #0,D6            ; Pixel per line
  5471.     OPT    OW+
  5472.  
  5473. .nextpixel
  5474.     moveq    #15,D0            ; For 16 bit-planes
  5475.     lea    8(A3),A0        ; 1st plane ptr
  5476.     movea.l    A5,A2            ; Mixed buffer
  5477.  
  5478. .getB
  5479.     move.l    (A0)+,D1
  5480.     bne.s    .exists
  5481.     move.b    D1,(A2)+        ; No data (e.g. 13 bitplanes and bitplane 14/15/16 encountered)
  5482.     bra.s    .further
  5483. .exists
  5484.     movea.l    D1,A1
  5485.     move.b    0(A1,D5.l),(A2)+    ; Read eight pixel (one byte) of each bitplane
  5486. .further
  5487.     subq.w    #1,D0
  5488.     bcc.s    .getB            ; For `n´ bitplanes
  5489.  
  5490. .doconvert
  5491.     movem.l    D3-D6/A3-A5,-(sp)
  5492.     bsr.s    .getC
  5493.     movem.l    (sp)+,D3-D6/A3-A5
  5494.  
  5495.     addq.l    #1,D5            ; Worked out 8 pixel
  5496.     lea    24(A4),A4        ; Increase RGB24 buffer
  5497.  
  5498.     addq.w    #1,D6            ; New byte (8 pixel)
  5499.     cmp.w    D6,D4            ; End of line?
  5500.     bne.s    .nextpixel        ; If no new line
  5501.  
  5502.     movem.l    D3-D5,-(sp)
  5503.  
  5504. * WritePixelArray( SrcRect [pointer to src datas A0]
  5505. *           SrcX    X position D0
  5506. *           SrcY    Y position D1
  5507. *           SrcMod bytes per row in source rectangle D2
  5508. *           RastPort A1
  5509.  
  5510. *           DestX  D3
  5511. *           DestY  D4
  5512. *           SizeX  D5
  5513. *           SizeY  D6
  5514. *           SrcFmt RECTFMT_RGB )
  5515.  
  5516.     OPT    OW-
  5517.     movea.l    32(A5),A0        ; Datas
  5518.     moveq    #0,D0
  5519.     moveq    #0,D1
  5520.     moveq    #0,D2
  5521.     move.l    48(A5),D2
  5522.     movea.l    44(A5),A1        ; RastPort
  5523.     move.l    D3,D4            ; DestY
  5524.     moveq    #0,D3            ; DestX
  5525.     move.l    40(A5),D5        ; Width
  5526.     move.w    #1,D6            ; Height
  5527.     moveq    #RECTFMT_RGB,D7
  5528.     movea.l    36(A5),A6
  5529.     jsr    _LVOWritePixelArray(A6)
  5530.     OPT    OW+
  5531.  
  5532.     movem.l    (sp)+,D3-D5
  5533.  
  5534.     move.l    32(A5),A4        ; RGB24 buffer
  5535.  
  5536.     moveq    #0,D6            ; New X position (starting at zero)
  5537.     addq.w    #1,D3            ; Increase line number
  5538.  
  5539.     cmp.w    bm_Rows(A3),D3        ; Already done for all lines?
  5540.     bne.s    .nextpixel
  5541.  
  5542.     lea    56(sp),sp
  5543.     movea.l    (sp)+,A5
  5544.  
  5545.     move.l    _RGB24Ptr(A5),A1
  5546.     move.l    _RGB24Size(A5),D0
  5547.     movea.l    _SysBase(A5),A6
  5548.     jsr    _LVOFreeMem(A6)
  5549.  
  5550.     moveq    #-1,D0
  5551. .endall
  5552.     movem.l    (sp)+,D2-D7/A2-A6
  5553.     rts
  5554.  
  5555. *
  5556. ** Buffer filled with 24 bytes which hold 8 pixel
  5557. *
  5558. .getC
  5559.     movea.l    A5,A0            ; Mixed buffer
  5560.     move.l    52(A5),A5        ; RGB32Values
  5561.     movem.l    (A0)+,D1-D4        ; 8 bytes (plane0 pixel 0-15, plane1 pixel 0-15 and so on
  5562.     movea.l    A4,A0            ; RGB24 buffer
  5563.  
  5564.     move.l    D1,A1
  5565.     move.l    D2,A2
  5566.     move.l    D3,A3
  5567.     move.l    D4,A4
  5568.  
  5569.     move.l    #$80808080,D0
  5570.     and.l    D0,D1            ; bit 0 of plane 0,1,2,3
  5571.     and.l    D0,D2            ; bit 0 of plane 4,5,6,7
  5572.     and.l    D0,D3            ; bit 0 of plane 8,9,10,11
  5573.     and.l    D0,D4            ; bit 0 of plane 12,13,14,15
  5574.  
  5575.     moveq    #-22,D0            ; See 'Counting ...' below for explantion
  5576.     move.l    D0,-(sp)
  5577.  
  5578. .GetPixelColour
  5579.     moveq    #0,D7
  5580.     move.l    D7,D5
  5581.  
  5582. * Original D1 pixel-0 bit 0 , P1 pixel-0 bit 1, P2 pixel-0 bit 2, P3 pixel-0 bit 4
  5583.  
  5584.     move.b    D1,D0            ; P3 pixel 0 in D0.b
  5585.     lsr.w    #8,D1            ; Get P2 pixel 0 on byte position in D1.b
  5586.     lsr.b    #4,D0            ; P3 pixel 0 on position 3
  5587.     lsr.b    #5,D1            ; P2 pixel 0 on position 2
  5588.     or.b    D0,D1
  5589.     move.b    D1,D7            ; Half lower nibble in D7 (bits 3 and 2)    
  5590.  
  5591.     swap.w    D1            ; Original P2 pixel 0, P3 pixel 0, P0 pixel 0, P1 pixel 0
  5592. *                      P0 pixel 0 and P1 pixel 0 in D1.w
  5593.  
  5594.     move.b    D1,D0            ; P1 pixel 0 in D0
  5595.     lsr.w    #8,D1            ; Get P1 pixel 0 on byte position
  5596.     lsr.b    #6,D0            ; P1 pixel 0 on position 1
  5597.     lsr.b    #7,D1            ; P0 pixel 0 on position 0
  5598.     or.b    D0,D1
  5599.     or.b    D1,D7            ; P3 P2 P1 P0
  5600.  
  5601. * --------------------
  5602.  
  5603. * Original P4 pixel 0 bit 4, P5 pixel 0 bit 5 , P6 pixel 0 bit 6, P7 pixel 0 bit 7
  5604.  
  5605.     move.b    D2,D0            ; P7 pixel 0 in D0
  5606.     lsr.w    #8,D2            ; Get P6 pixel 0 on byte position
  5607. *    lsr.b    #0,D0            ; P7 pixel 0 on position 7
  5608.     lsr.b    #1,D2            ; P6 pixel 0 on position 6
  5609.     or.b    D0,D2
  5610.     or.b    D2,D7            ; P7 P6 nn nn P3, P2, P1, P0
  5611.  
  5612.     swap.w    D2            ; Original P6 pixel 0, P7 pixel 0
  5613. *                      P6 pixel 0, P7 pixel 0 in D2.w
  5614.  
  5615.     move.b    D2,D0            ; P4 pixel 0 in D0
  5616.     lsr.w    #8,D2            ; Get P5 pixel 0 on byte position
  5617.     lsr.b    #2,D0            ; P4 pixel 0 on position 5
  5618.     lsr.b    #3,D2            ; P5 pixel 0 on position 4
  5619.     or.b    D0,D2
  5620.     or.b    D2,D7            ; P7, P6, P5, P4, P3, P2 P1 P0
  5621.  
  5622. * --------------------
  5623.  
  5624.     move.b    D3,D0            ; P3 pixel 0 in D0.b
  5625.     lsr.w    #8,D3            ; Get P2 pixel 0 on byte position in D1.b
  5626.     lsr.b    #4,D0            ; P3 pixel 0 on position 3
  5627.     lsr.b    #5,D3            ; P2 pixel 0 on position 2
  5628.     or.b    D0,D3
  5629.     move.b    D3,D5            ; Half lower nibble in D7 (bits 3 and 2)    
  5630.  
  5631.     swap.w    D3            ; Original P2 pixel 0, P3 pixel 0, P0 pixel 0, P1 pixel 0
  5632. *                      P0 pixel 0 and P1 pixel 0 in D1.w
  5633.  
  5634.     move.b    D3,D0            ; P1 pixel 0 in D0
  5635.     lsr.w    #8,D3            ; Get P1 pixel 0 on byte position
  5636.     lsr.b    #6,D0            ; P1 pixel 0 on position 1
  5637.     lsr.b    #7,D3            ; P0 pixel 0 on position 0
  5638.     or.b    D0,D3
  5639.     or.b    D3,D5            ; P3 P2 P1 P0
  5640.  
  5641. * --------------------
  5642.  
  5643. * Original P4 pixel 0 bit 4, P5 pixel 0 bit 5 , P6 pixel 0 bit 6, P7 pixel 0 bit 7
  5644.  
  5645.     move.b    D4,D0            ; P7 pixel 0 in D0
  5646.     lsr.w    #8,D4            ; Get P6 pixel 0 on byte position
  5647. *    lsr.b    #0,D0            ; P7 pixel 0 on position 7
  5648.     lsr.b    #1,D4            ; P6 pixel 0 on position 6
  5649.     or.b    D0,D4
  5650.     or.b    D4,D5            ; P7 P6 nn nn P3, P2, P1, P0
  5651.  
  5652.     swap.w    D4            ; Original P6 pixel 0, P7 pixel 0
  5653. *                      P6 pixel 0, P7 pixel 0 in D2.w
  5654.  
  5655.     move.b    D4,D0            ; P4 pixel 0 in D0
  5656.     lsr.w    #8,D4            ; Get P5 pixel 0 on byte position
  5657.     lsr.b    #2,D0            ; P4 pixel 0 on position 5
  5658.     lsr.b    #3,D4            ; P5 pixel 0 on position 4
  5659.     or.b    D0,D4
  5660.     or.b    D4,D5            ; P7, P6, P5, P4, P3, P2 P1 P0
  5661.  
  5662.     lsl.w    #8,D5
  5663.     or.w    D5,D7
  5664.  
  5665. .store
  5666.     move.w    D7,D5            ; INDEX
  5667.     add.l    D5,D5            ; Index * 2
  5668.     add.l    D5,D7            ; = Index * 3
  5669.     
  5670.     move.b    0(A5,D7.l),(A0)+    ; Colour value R
  5671.     move.b    1(A5,D7.l),(A0)+    ; Colour value G
  5672.     move.b    2(A5,D7.l),(A0)+    ; Colour value B
  5673.  
  5674.  
  5675. * Repeat GetPixelColour until a complete byte (8 pixel) is worked out...
  5676. .repeat
  5677.     move.l    (sp)+,D0
  5678.  
  5679.     move.l    A1,D1
  5680.     move.l    A2,D2
  5681.     move.l    A3,D3
  5682.     move.l    A4,D4
  5683.  
  5684. .thejump
  5685.     addi.l    #28,D0
  5686.     move.l    D0,-(sp)
  5687.  
  5688.     jmp    (pc,D0.w)        ; Call one of the masks below depending on value in D0
  5689.  
  5690. .end
  5691.     move.l    (sp)+,D0        ; Counting 2
  5692.     rts                ; Counting 4
  5693.  
  5694. .mask1                    ; Counting 6 :: (-22) = (+6 - +28 = -22) -> 1st offset to PC to reach this (.mask1)
  5695.     move.l    #$40404040,D0        ; -- Each mask has got 19 instruction surrounded by 28 bytes code
  5696.     and.l    D0,D1            ; bit 1 of plane 0,1,2,3
  5697.     and.l    D0,D2            ; bit 1 of plane 4,5,6,7
  5698.     and.l    D0,D3
  5699.     and.l    D0,D4
  5700.     moveq    #1,D0
  5701.     lsl.l    D0,D1
  5702.     lsl.l    D0,D2
  5703.     lsl.l    D0,D3
  5704.     lsl.l    D0,D4
  5705.     bra.w    .GetPixelColour
  5706.  
  5707. .mask2                    ; 26
  5708.     move.l    #$20202020,D0
  5709.     and.l    D0,D1            ; bit 2 of plane 0,1,2,3
  5710.     and.l    D0,D2            ; bit 2 of plane 4,5,6,7
  5711.     and.l    D0,D3            ; bit 2 of plane 4,5,6,7
  5712.     and.l    D0,D4            ; bit 2 of plane 4,5,6,7
  5713.     moveq    #2,D0
  5714.     lsl.l    D0,D1
  5715.     lsl.l    D0,D2
  5716.     lsl.l    D0,D3
  5717.     lsl.l    D0,D4
  5718.     bra.w    .GetPixelColour
  5719.  
  5720. .mask3                    ; 46
  5721.     move.l    #$10101010,D0
  5722.     and.l    D0,D1            ; bit 3 of plane 0,1,2,3
  5723.     and.l    D0,D2            ; bit 3 of plane 4,5,6,7
  5724.     and.l    D0,D3            ; bit 3 of plane 4,5,6,7
  5725.     and.l    D0,D4            ; bit 3 of plane 4,5,6,7
  5726.     moveq    #3,D0
  5727.     lsl.l    D0,D1
  5728.     lsl.l    D0,D2
  5729.     lsl.l    D0,D3
  5730.     lsl.l    D0,D4
  5731.     bra.w    .GetPixelColour
  5732.  
  5733. .mask4                    ; 66
  5734.     move.l    #$08080808,D0
  5735.     and.l    D0,D1            ; bit 4 of plane 0,1,2,3
  5736.     and.l    D0,D2            ; bit 4 of plane 4,5,6,7
  5737.     and.l    D0,D3            ; bit 4 of plane 4,5,6,7
  5738.     and.l    D0,D4            ; bit 4 of plane 4,5,6,7
  5739.     moveq    #4,D0
  5740.     lsl.l    D0,D1
  5741.     lsl.l    D0,D2
  5742.     lsl.l    D0,D3
  5743.     lsl.l    D0,D4
  5744.     bra.w    .GetPixelColour
  5745.  
  5746. .mask5                    ; 86
  5747.     move.l    #$04040404,D0
  5748.     and.l    D0,D1            ; bit 5 of plane 0,1,2,3
  5749.     and.l    D0,D2            ; bit 5 of plane 4,5,6,7
  5750.     and.l    D0,D3            ; bit 5 of plane 4,5,6,7
  5751.     and.l    D0,D4            ; bit 5 of plane 4,5,6,7
  5752.     moveq    #5,D0
  5753.     lsl.l    D0,D1
  5754.     lsl.l    D0,D2
  5755.     lsl.l    D0,D3
  5756.     lsl.l    D0,D4
  5757.     bra.w    .GetPixelColour
  5758.  
  5759. .mask6
  5760.     move.l    #$02020202,D0
  5761.     and.l    D0,D1            ; bit 6 of plane 0,1,2,3
  5762.     and.l    D0,D2            ; bit 6 of plane 4,5,6,7
  5763.     and.l    D0,D3            ; bit 6 of plane 4,5,6,7
  5764.     and.l    D0,D4            ; bit 6 of plane 4,5,6,7
  5765.     moveq    #6,D0
  5766.     lsl.l    D0,D1
  5767.     lsl.l    D0,D2
  5768.     lsl.l    D0,D3
  5769.     lsl.l    D0,D4
  5770.     bra.w    .GetPixelColour
  5771.  
  5772. .mask7
  5773.     move.l    #$01010101,D0
  5774.     and.l    D0,D1            ; bit 7 of plane 0,1,2,3
  5775.     and.l    D0,D2            ; bit 7 of plane 4,5,6,7
  5776.     and.l    D0,D3            ; bit 7 of plane 4,5,6,7
  5777.     and.l    D0,D4            ; bit 7 of plane 4,5,6,7
  5778.     moveq    #7,D0
  5779.     lsl.l    D0,D1
  5780.     lsl.l    D0,D2
  5781.     lsl.l    D0,D3
  5782.     lsl.l    D0,D4
  5783.     bra.w    .GetPixelColour
  5784.  
  5785. .mask8                    ; Does not exists!!!
  5786.     bra.w    .end
  5787.  
  5788. _CLUT16oRGB16end
  5789.     OPT    P=68000
  5790.  
  5791. ***********************************
  5792. * ONIX 02.10.'91
  5793. *
  5794. * MakeCounteven
  5795. *
  5796. * Inputs: D0 - value
  5797. * Results: D0 - value
  5798. *
  5799.  
  5800. _MakeCountEven
  5801.     addq.l    #7,D0
  5802.     andi.l    #-8,D0
  5803.     rts
  5804.  
  5805. ********************************
  5806. *
  5807. * Filter ANSI-escape code.
  5808. *
  5809. * Inputs: none
  5810. * Results: none
  5811. *
  5812.  
  5813. _IgnoreSettings
  5814.     movea.l    _TextPtr(A5),A0        ; Address file in memory
  5815.     addq.l    #2,A0            ; Overread #$200A
  5816.     move.l    _FileSize(A5),D0    ; Length of this file
  5817.     moveq    #0,D1            ; Amount lines
  5818.  
  5819. 1$
  5820.     subq.l    #1,D0            ; Length -1
  5821.     bmi.s    .done
  5822.  
  5823.     cmpi.b    #10,(A0)+        ; LineFeed?
  5824.     beq.s    6$            ; If so...
  5825.  
  5826.     cmpi.b    #12,-1(A0)        ; ANSI-sequence?
  5827.     beq.s    5$            ; If so...
  5828.  
  5829.     cmpi.b    #13,-1(A0)        ; LineFeed?
  5830.     beq.s    5$            ; If not...
  5831.  
  5832. 2$
  5833.     cmpi.b    #31,-1(A0)
  5834.     bhi.s    1$
  5835.  
  5836.     cmpi.b    #27,-1(A0)
  5837.     beq.s    1$
  5838.  
  5839.     cmpi.b    #8,-1(A0)
  5840.     bls.s    3$    
  5841.  
  5842.     bra.s    1$
  5843.  
  5844. 3$
  5845.     move.b    #' ',-1(A0)
  5846.     bra.s    1$
  5847.  
  5848. .done
  5849.     move.l    D1,_LinesInFile(A5)    ; Lines in file
  5850.     bra.s    _SetTitle
  5851.  
  5852. 5$
  5853.     move.b    #10,-1(A0)        ; LineFeed instead of ANSI!
  5854. 6$
  5855.     addq.l    #1,D1
  5856.     bra.s    1$
  5857. ************************************
  5858. *
  5859. * Make title for main-window
  5860. *
  5861. * Inputs: none
  5862. * Results: none
  5863. *
  5864.  
  5865. _SetTitle
  5866.     move.l    A2,-(sp)
  5867.     lea    _WindowTitle(A5),A2    ; Address buffer
  5868.     lea    _FIB(A5),A0        ; Address FileInfoBlock
  5869.     addq.l    #8,A0            ; Get the name of the file
  5870. 1$
  5871.     move.b    (A0)+,(A2)+        ; Copy the file's name
  5872.     tst.b    (A0)
  5873.     bne.s    1$
  5874.     move.b    #' ',(A2)+        ; Write Blank
  5875.     move.b    #'(',(A2)+
  5876.     movea.l    A2,A0            ; Address buffer
  5877.     move.l    _LinesInFile(A5),D0    ; Number of lines in file
  5878.     bsr.w    _comdec            ; Convert count into ascii
  5879.     move.b    #' ',(A0)+        ; Write String ' Lines)  Current line: '
  5880.     move.b    #'L',(A0)+
  5881.     move.b    #'i',(A0)+
  5882.     move.b    #'n',(A0)+
  5883.     move.b    #'e',(A0)+
  5884.     move.b    #'s',(A0)+
  5885.     move.b    #')',(A0)+
  5886.     move.b    #' ',(A0)+
  5887.     move.b    #' ',(A0)+
  5888.     move.b    #'C',(A0)+
  5889.     move.b    #'u',(A0)+
  5890.     move.b    #'r',(A0)+
  5891.     move.b    #'r',(A0)+
  5892.     move.b    #'e',(A0)+
  5893.     move.b    #'n',(A0)+
  5894.     move.b    #'t',(A0)+
  5895.     move.b    #' ',(A0)+
  5896.     move.b    #'l',(A0)+
  5897.     move.b    #'i',(A0)+
  5898.     move.b    #'n',(A0)+
  5899.     move.b    #'e',(A0)+
  5900.     move.b    #':',(A0)+
  5901.     move.b    #' ',(A0)+
  5902.     move.l    A0,_PtrToWTitle(A5)    ; Remember current buffer address
  5903.  
  5904.     movea.l    _IntuitionBase(A5),A6
  5905.     movea.l    _WindowPtr(A5),A0
  5906.     lea    _WindowTitle(A5),A1    ; Address new window title
  5907.     lea    _WindowName(pc),A2    ; Address new screen title
  5908.     jsr    _LVOSetWindowTitles(A6)    ; Set window and screen title
  5909.  
  5910.     movea.l    (sp)+,A2    
  5911.     rts
  5912.  
  5913. _ComLine
  5914.     tst.l    _TextPtr(A5)        ; File in memory?
  5915.     beq.w    2$            ; No...
  5916.  
  5917.     tst.b    _AudGadget(A5)        ; We make a sound audible, thus no text and lines!
  5918.     bne.w    2$
  5919.  
  5920.     move.l    A2,-(sp)
  5921.  
  5922.     movea.l    _PtrToWTitle(A5),A0    ; Save current buffer address for later
  5923.     move.l    _Line(A5),D0        ; Current line
  5924.     bsr.w    _comdec
  5925.     move.b    #' ',(A0)+        ; Write blanks...
  5926.     move.b    #' ',(A0)+
  5927.     move.b    #' ',(A0)+
  5928.     move.b    #' ',(A0)+
  5929.     move.b    #' ',(A0)+
  5930.     move.b    #' ',(A0)+
  5931.     move.b    #' ',(A0)+
  5932.     clr.b    (A0)            ; End of window-title
  5933.  
  5934.     movea.l    _GfxBase(A5),A6
  5935.     movea.l    _WindowPtr(A5),A0
  5936.     movea.l    wd_BorderRPort(A0),A2    ; RastPort
  5937.  
  5938.  
  5939.     move.w    _BgPen(A5),D0        ; Backgroundcolour of window's titel bar
  5940.     movea.l    A2,A1
  5941.     jsr    _LVOSetBPen(A6)
  5942.  
  5943.     moveq    #1,D0            ; Foregroundcolour
  5944.     movea.l    A2,A1
  5945.     jsr    _LVOSetAPen(A6)
  5946.  
  5947.     movea.l    rp_BitMap(A2),A0    ; Bitmap for the title
  5948.     cmpi.b    #1,bm_Depth(A0)        ; Only one bitplane used?
  5949.     bne.s    .normal            ; No, more.
  5950.  
  5951.     moveq    #0,D0            ; Because of the inversed title bar
  5952.     movea.l    A2,A1
  5953.     jsr    _LVOSetAPen(A6)
  5954.  
  5955. .normal
  5956.     move.b    #RP_JAM2,D0
  5957.     movea.l    A2,A1
  5958.     jsr    _LVOSetDrMd(A6)
  5959.  
  5960.     moveq    #30,D0            ; X
  5961.     moveq    #1,D1            ; Y
  5962.     movea.l    A2,A1
  5963.     add.w    62(A2),D1        ; TxBaseLine
  5964.     jsr    _LVOMove(A6)
  5965.  
  5966.     lea    _WindowTitle(A5),A0
  5967.     moveq    #-1,D0
  5968. 1$
  5969.     tst.b    (A0)+
  5970.     dbeq    D0,1$
  5971.     not.l    D0
  5972.     lea    _WindowTitle(A5),A0
  5973.     movea.l    A2,A1
  5974.     jsr    _LVOText(A6)
  5975.     movea.l    (sp)+,A2
  5976. 2$
  5977.     rts
  5978.  
  5979. **********************************************
  5980. *
  5981. * Size window to maximum "!?!?|?" .
  5982. *
  5983. * Inputs: none
  5984. * Results: none
  5985. *
  5986.  
  5987. _EnlargeWindow
  5988.     movem.l    D0-D3/A0-A2/A6,-(sp)
  5989.     movea.l    _IntuitionBase(A5),A6
  5990.     movea.l    _WindowPtr(A5),A0
  5991.     movea.l    A0,A2
  5992.     lea    _WindowRecord(A5),A1
  5993.     move.w    wd_LeftEdge(A0),D0
  5994.     move.w    wd_TopEdge(A0),D1
  5995.     neg.w    D0            ; Place it to 0,
  5996.     neg.w    D1            ; 0
  5997.     add.w    (A1),D0            ; leftEdge
  5998.     add.w    nw_TopEdge(A1),D1    ; topEdge
  5999.     jsr    _LVOMoveWindow(A6)    ; Move window to 0,0 or to user specified X- and Y-position
  6000.  
  6001.     bsr.s    1$            ; Wait for intuition timer tick
  6002.     movea.l    A2,A0            ; Intuition-Engage-Window-Record
  6003.     move.w    wd_Width(A0),D2        ; Current window-width
  6004.     move.w    wd_Height(A0),D3    ; Current window-height
  6005.  
  6006.     lea    _WindowRecord(A5),A1    ; Address window-record
  6007.     move.w    nw_Width(A1),D0        ; User's width
  6008.     move.w    nw_Height(A1),D1    ; Users's height
  6009.     sub.w    D2,D0            ; Substract
  6010.     sub.w    D3,D1
  6011.     jsr    _LVOSizeWindow(A6)    ; Enlarge? window
  6012.     movem.l    (sp)+,D0-D3/A0-A2/A6
  6013.  
  6014.     bsr.s    1$            ; Wait
  6015.  
  6016.     bsr.w    _SetPageWidthAndLen
  6017.     bsr.w    _RestoreCurrentPage
  6018.     bra.w    _Loop
  6019.  
  6020. 1$
  6021.     movem.l    D0-D3/A0-A3/A6,-(sp)
  6022.     moveq    #6,D1            ; 6/60 seconds = 1/10 second == int. timer tick
  6023.     movea.l    _DOSBase(A5),A6
  6024.     jsr    _LVODelay(A6)
  6025.     movem.l    (sp)+,D0-D3/A0-A3/A6
  6026.     rts
  6027.  
  6028. *******************************************************************
  6029. *
  6030. * Format text, display that text in a window, get Gadget-status and
  6031. * return.
  6032. *
  6033. * Inputs: Stack - reverse arguments on stack
  6034. * Results: D0 = NULL = FALSE , D0 ~NULL = OK
  6035. *
  6036.  
  6037.     IFD    __G2
  6038.     OPT    OW-            ; Devpac: Don't display optimisation warnings
  6039.     ENDC
  6040.  
  6041. _FmtDisplay
  6042.  
  6043.      STRUCTURE    printfBuf,0
  6044.     STRUCT    _Cnt,4            ; Counter for number of chars
  6045.     STRUCT    _Buffer,512        ; Room for max. 511 chars
  6046.     LABEL    _Args            ; Dynamic wide
  6047.     LABEL    _pfbso
  6048.  
  6049. .printf
  6050.     movem.l    D2-D6/A2-A3,-(sp)
  6051.     movea.l    32(sp),A0        ; Pointer to the string which should be formatted
  6052.     moveq    #-1,D1            ; Dummy-counter
  6053.     moveq    #0,D0            ; Counter for arguments
  6054. 0$
  6055.     cmpi.b    #'%',(A0)        ; Argument?
  6056.     bne.s    .NoArg            ; No...
  6057.     addq.w    #1,D0            ; Argument +1
  6058. .NoArg
  6059.     tst.b    (A0)+            ; End of string?
  6060.     dbeq    D1,0$            ; If not
  6061.  
  6062.     lsl.l    #2,D0            ; * 4 == longwords
  6063.     addi.l    #_pfbso,D0        ; 4 bytes count, plus buffer
  6064.     addq.l    #7,D0
  6065.     andi.l    #-8,D0            ; Align size
  6066.     move.l    D0,D5            ; Save size
  6067.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  6068.     movea.l    _SysBase(A5),A6
  6069.     jsr    _LVOAllocMem(A6)
  6070.     move.l    D0,D4            ; Address table
  6071.     beq.s    3$            ; Upon error
  6072.  
  6073.     movea.l    32(sp),A0        ; Pointer to string
  6074.     lea    36(sp),A1        ; Pointer to 1. argument
  6075.     movea.l    D4,A2            ; Address table
  6076.     lea    _Args(A2),A2        ; Address arguments-buffer (up from 516)
  6077.  
  6078.     moveq    #-1,D1            ; Dummy-counter
  6079.     bra.s    1$
  6080.  
  6081. * --    #############  -- *
  6082. .skip
  6083.     addq.l    #2,A0            ; Overread both %-chars
  6084.     subq.w    #2,D1            ; 2 chars less in text
  6085.     bmi.s    3$            ; Upon error
  6086.  
  6087. * --- Here we start! --- *
  6088. 1$
  6089.     cmpi.b    #'%',(A0)        ; Argument?
  6090.     bne.s    2$            ; No
  6091.     cmpi.b    #'%',1(A0)        ; or only to display %-char?
  6092.     beq.s    .skip            ; If so, overread both %-chars
  6093.     addq.l    #1,A0            ; Else only one %-char
  6094.     subq.w    #1,D1            ; Counter -1
  6095. .getType
  6096.     cmpi.b    #'b',(A0)        ; Argument = BCPL?
  6097.     beq.s    .typeFound        ; If so
  6098.     cmpi.b    #'d',(A0)        ; Decimal?
  6099.     beq.s    .typeFound.1
  6100.     cmpi.b    #'x',(A0)        ; Sedicimal?
  6101.     beq.s    .typeFound.1
  6102.     cmpi.b    #'s',(A0)        ; String?
  6103.     beq.s    .typeFound
  6104.     cmpi.b    #'c',(A0)        ; One char?
  6105.     beq.s    .typeFound.1
  6106. *
  6107. ** Because an argument can look like this: '%-08ld' we only search for the
  6108. ** valid description of the argument, here 'd' in a loop.
  6109. *
  6110.     tst.b    (A0)+            ; Search further
  6111.     dbeq    D1,.getType
  6112.  
  6113.     bra.s    3$            ; Upon error, string without end of argument
  6114.  
  6115. .typeFound.1
  6116.     cmpi.b    #'l',-1(A0)        ; Longword?
  6117.     beq.s    .typeFound        ; then the other routine
  6118.     move.l    (A1),D0            ; Get argument (ever longword)
  6119.     move.w    D0,(A2)+        ; write down for Exec only a word
  6120.     addq.l    #4,A1            ; Pointer to following argument
  6121.     bra.s    2$            ; and do it normal
  6122. .typeFound
  6123.     move.l    (A1),(A2)+        ; Argument-contents into buffer
  6124.     addq.l    #4,A1            ; see above
  6125. 2$
  6126.     tst.b    (A0)+            ; Search for NULL-byte
  6127.     dbeq    D1,1$
  6128.     bra.s    .FmtString        ; == End of string, now format string
  6129. 3$
  6130.     moveq    #0,D6            ; Return error
  6131. .printf_end
  6132.     tst.l    D4            ; Address table?
  6133.     beq.s    4$
  6134.     movea.l    D4,A1            ; Address table
  6135.     move.l    D5,D0            ; Size table
  6136.     movea.l    _SysBase(A5),A6
  6137.     jsr    _LVOFreeMem(A6)        ; Free table
  6138. 4$
  6139.     move.l    D6,D0
  6140.     movem.l    (sp)+,D2-D6/A2-A3
  6141.     rts
  6142.  
  6143.  
  6144. .FmtString
  6145.     movea.l    32(sp),A0        ; Pointer to unformatted string
  6146.     movea.l    D4,A3            ; Address table
  6147.     lea    _Args(A3),A1        ; Address arguments-buffer
  6148.     lea    .Hook(pc),A2        ; Call-Back-Routine
  6149. *    movea.l    A3,A3            ; Address table already in A3
  6150.     movea.l    _SysBase(A5),A6        ; Base Exec
  6151.     jsr    _LVORawDoFmt(A6)    ; Format the string
  6152.  
  6153.     movea.l    D4,A1
  6154.     lea    _Buffer(A1),A0        ; Address formatted text in buffer
  6155.     move.l    _Cnt(A1),D0        ; Size of text
  6156.     beq.s    .okEnd            ; If zero
  6157.     bsr.s    _DisplayError        ; else print text to window
  6158.     move.l    D0,D6
  6159. .okEnd
  6160.     bra.s    .printf_end
  6161.  
  6162.  
  6163. .Hook
  6164. * D0 == char, returned by RawDoFmt()
  6165. * A3 == Pointer to table, returned by RawDoFmt()
  6166.     movem.l    D1/A0,-(sp)
  6167.     lea    _Buffer(A3),A0        ; Buffer for formatted text
  6168.     move.l    _Cnt(A3),D1        ; Number of chars that are in buffer
  6169.     move.b    D0,0(A0,D1.w)        ; Store current
  6170.     addq.l    #1,_Cnt(A3)        ; Counter plus 1
  6171.     cmpi.l    #510,D1            ; 511 chars in buffer?
  6172.     bls.s    .ok            ; If ok.
  6173.     subq.l    #1,_Cnt(A3)        ; One too far
  6174.     clr.b    0(A0,D1.w)        ; Clear byte
  6175. .ok    
  6176.     movem.l    (sp)+,D1/A0
  6177.     rts
  6178.  
  6179.     IFD    __G2
  6180.     OPT    OW+
  6181.     ENDC
  6182.  
  6183. ******************************************************************
  6184. *
  6185. * Open in the middle of a screen a window where we will display
  6186. * a text.
  6187. *
  6188. * Inputs: A0 - text
  6189. * Results: D0 - NULL == ABORT, else OK
  6190.  
  6191.  
  6192. _DisplayError
  6193.     movem.l    D1-D4/A0-A4,-(sp)
  6194.  
  6195.     movea.l    A0,A4            ; Save text for later
  6196.     lea    _ErrWindowStruc(A5),A0
  6197.  
  6198.     tst.l    _ScreenPtr(A5)
  6199.     bne.s    .GotScreen
  6200.  
  6201.     movea.l    _IntuitionBase(A5),A1
  6202.     movea.l    ib_ActiveScreen(A1),A1
  6203. .GotScreen
  6204.     movea.l    _ScreenPtr(A5),A1
  6205.     move.l    A1,nw_Screen(A0)     ; ScreenPtr->WindowRecord
  6206.  
  6207. * Center window on screen.
  6208.     move.w    sc_Width(A1),D0        ; Width of screen
  6209.     subi.w    #320,D0            ; Width of ErrorWindow
  6210.     lsr.w    #1,D0            ; Half
  6211.     move.w    D0,(A0)            ; == leftEdge
  6212.  
  6213.     move.w    sc_Height(A1),D0    ; Height of screen
  6214.     subi.w    #100,D0            ; Height of ErrorWindow
  6215.     lsr.w    #1,D0            ; Half
  6216.     move.w    D0,nw_TopEdge(A0)    ; == topEdge
  6217.  
  6218. * Open the window.
  6219.     clr.l    nw_FirstGadget(A0)
  6220.     movea.l    _IntuitionBase(A5),A6
  6221.     jsr    _LVOOpenWindow(A6)
  6222.     move.l    D0,_ErrWindowPtr(A5)
  6223.     beq.w    .NoErrWindow        ; Upon error
  6224.     movea.l    D0,A0            ; Window
  6225.     movea.l    wd_RPort(A0),A3        ; ^RastPortPtr
  6226.  
  6227.     bsr.w    _InitGadgets        ; Init gadgets
  6228.     lea    _Gad1(A5),A1        ; First gadget
  6229.     moveq    #0,D0            ; Begin with number zero
  6230.     moveq    #-1,D1            ; All gadgets
  6231.     moveq    #0,D2
  6232.     movea.l    D2,A2            ; No requester
  6233.     jsr    _LVOAddGList(A6)    ; Set gadgets to window
  6234.     lea    _Gad1(A5),A0        ; Gadgets
  6235.     movea.l    _ErrWindowPtr(A5),A1    ; Window
  6236.     moveq    #0,D2
  6237.     movea.l    D2,A2            ; No requester
  6238.     jsr    _LVORefreshGList(A6)    ; Draw gadgets
  6239.  
  6240. * Set pens.
  6241.     moveq    #1,D0            ; 1. foregroundcolour
  6242.     movea.l    A3,A1            ; RastPort
  6243.     movea.l    _GfxBase(A5),A6
  6244.     jsr    _LVOSetAPen(A6)        ; Set text-pen
  6245.  
  6246. * Fill background of window with 1. foreground colour.
  6247.     movea.l    _ErrWindowPtr(A5),A0
  6248.     movea.l    A3,A1            ; RastPort
  6249.     move.w    #0,D0            ; leftEdge
  6250.     move.w    #0,D1            ; topEdge
  6251.     move.w    #319,D2            ; width
  6252.     move.w    #79,D3            ; height
  6253.  
  6254.     moveq    #0,D4
  6255.     move.b    wd_BorderLeft(A0),D4
  6256.     add.w    D4,D0
  6257.     addq.w    #1,D0
  6258.     move.b    wd_BorderRight(A0),D4
  6259.     sub.w    D4,D2
  6260.     subq.w    #1,D2
  6261.     move.b    wd_BorderTop(A0),D4
  6262.     add.w    D4,D1
  6263.     addq.w    #1,D1
  6264.     move.b    wd_BorderBottom(A0),D4
  6265.     sub.w    D4,D3    
  6266.     subq.w    #1,D3
  6267.     movem.l    D0/D2,-(sp)        ; Save coordinates
  6268.     jsr    _LVORectFill(A6)    ; Draw rectangle
  6269.  
  6270.     move.w    #2,D0            ; 2. Foregroundcolour
  6271.     movea.l    A3,A1            ; RastPort
  6272.     jsr    _LVOSetAPen(A6)        ; Set text-pen
  6273.  
  6274.     movea.l    A3,A1            ; RastPort
  6275.     move.w    #RP_JAM1,D0
  6276.     jsr    _LVOSetDrMd(A6)
  6277.  
  6278.     movem.l    (sp)+,D0/D2        ; Get coordinates
  6279.  
  6280. *    D0 contains X-Offset
  6281.     moveq    #76,D1            ; Y-Offset
  6282.     movea.l    A3,A1
  6283.     jsr    _LVOMove(A6)
  6284.     move.l    D2,D0            ; D2 == X-Offset - to D0
  6285.     moveq    #76,D1            ; Y-Offset
  6286.     movea.l    A3,A1
  6287.     jsr    _LVODraw(A6)
  6288.  
  6289.     moveq    #0,D0            ; X-, Y-offsets = 0
  6290.     move.l    D0,D1
  6291.     move.b    (A4)+,D1        ; Y-Offset out of text
  6292.     movea.l    A3,A1            ; RastPortPtr
  6293.     jsr    _LVOMove(A6)        ; Set Gfx-cursor
  6294.  
  6295.     move.l    A4,-(sp)        ; Text
  6296.     moveq    #0,D0
  6297.     move.w    rp_TxHeight(A3),D0
  6298.     addq.w    #2,D0            ; Spacing
  6299.     sub.w    rp_TxBaseline(A3),D0
  6300.     move.l    D0,-(sp)
  6301.     move.l    _ErrWindowPtr(A5),-(sp)    ; Window
  6302.     bsr.w    _CenterPage        ; CenterText (struct Window *, ULONG Spacing, char *)
  6303.     lea    12(sp),sp        ; Restore stack
  6304.  
  6305. .Wait
  6306.     movea.l    _ErrWindowPtr(A5),A0    ; WindowPointer
  6307.     movea.l    wd_UserPort(A0),A0    ; MsgPort
  6308.     movea.l    A0,A3            ; save it
  6309.     movea.l    _SysBase(A5),A6
  6310.     jsr    _LVOWaitPort(A6)    ; Sleep
  6311.  
  6312.     movea.l    A3,A0            ; MsgPort
  6313.     jsr    _LVOGetMsg(A6)        ; Get the message
  6314.     tst.l    D0
  6315.     beq.s    .Wait
  6316.     movea.l    D0,A1            ; into A1
  6317.     movea.l    A1,A2
  6318.     move.l    im_Class(A2),D2
  6319.     move.w    im_Code(A2),D3
  6320.     swap    D3
  6321.     move.w    im_Qualifier(A2),D3
  6322.     jsr    _LVOReplyMsg(A6)
  6323.  
  6324.     cmpi.l    #$40,D2            ; GadgetUp?
  6325.     beq.s    .Gadget
  6326.  
  6327.     btst.l    #6,D3            ; Left AMIGA (Commodore) key?
  6328.     beq.s    .Wait            ; If not...
  6329.  
  6330.     swap    D3
  6331.  
  6332.     cmpi.b    #53,D3
  6333.     beq.s    .KeyB
  6334.  
  6335.     cmpi.b    #52,D3
  6336.     beq.s    .KeyV
  6337.  
  6338.     bra.s    .Wait
  6339. .KeyB
  6340.     moveq    #0,D3
  6341.     bra.s    .EndDisplayError
  6342. .KeyV
  6343.     moveq    #1,D3
  6344.     bra.s    .EndDisplayError
  6345. .Gadget
  6346.     tst.l    im_IAddress(A2)
  6347.     beq.s    .Wait            ; No gadget?
  6348.     movea.l    im_IAddress(A2),A0    ; Get gadget's address
  6349.     move.w    gg_GadgetID(A0),D3    ; Get my ID
  6350.  
  6351. .EndDisplayError
  6352.     movea.l    _ErrWindowPtr(A5),A0
  6353.     movea.l    _IntuitionBase(A5),A6
  6354.     jsr    _LVOCloseWindow(A6)
  6355.     move.w    D3,D0            ; im_Code (gadget's ID)
  6356.     cmpi.w    #1,D0            ; Left gadget (OK) ?
  6357.     beq.s    .NoErrWindow        ; If so...
  6358.     moveq    #0,D0            ; It was the right one
  6359. .NoErrWindow
  6360.     movem.l    (sp)+,D1-D4/A0-A4
  6361.     rts
  6362.  
  6363. *
  6364. * void CenterPage( struct Window *Window, ULONG Spacing, STRPTR TextPage );
  6365. *
  6366.  
  6367. _CenterPage
  6368.     movem.l    D2-D3/A2-A3,-(sp)
  6369.  
  6370.     movea.l    _GfxBase(A5),A6
  6371.     movea.l    20(sp),A0        ; Window
  6372.     movea.l    50(A0),A3        ; RastPort
  6373.     moveq    #0,D3
  6374.     move.l    24(A0),D0        ; Window flags
  6375.     btst.l    #10,D0            ; gimme zero zero ?
  6376.     bne.s    0$            ; if gzz
  6377.     move.w    8(A0),D3        ; Window-width
  6378.     lsr.w    #1,D3            ; == half window width
  6379.     bra.s    1$
  6380. 0$
  6381.     move.w    112(A0),D3        ; gzzWidth
  6382.     lsr.w    #1,D3            ; == half window width
  6383. 1$
  6384.     movea.l    28(sp),A2        ; Text
  6385. 2$
  6386.     movea.l    A2,A0
  6387.     moveq    #-1,D2            ; Counter
  6388. 3$
  6389.     tst.b    (A0)            ; End?
  6390.     beq.s    4$
  6391.     cmpi.b    #10,(A0)+        ; Search for line-end
  6392.     dbeq    D2,3$
  6393.  
  6394.     move.l    A0,-(sp)        ; Save pointer to next line
  6395.  
  6396.     not.l    D2            ; Compute length
  6397.     move.l    D2,D0            ; Length in number of chars
  6398.     movea.l    A3,A1            ; RastPort
  6399.     movea.l    A2,A0            ; Text
  6400.     jsr    _LVOTextLength(A6)
  6401.     move.l    D0,D1            ; Length in pixels 
  6402.     lsr.w    #1,D1            ; == half length
  6403.     move.l    D3,D0            ; Half window-width
  6404.     sub.w    D1,D0            ; minus half text-width == X-offset for 1. char
  6405.     move.w    38(A3),D1        ; Current Y
  6406.     add.w    62(A3),D1        ; plus rp_TxBaseline
  6407.     movea.l    A3,A1            ; RastPort
  6408.     jsr    _LVOMove(A6)
  6409.  
  6410.     movea.l    (sp)+,A0        ; Get pointer to next line
  6411.  
  6412.     exg.l    A0,A2            ; A0 == now old position, A2 new position of text
  6413.     move.l    D2,D0            ; TextLength in number of chars
  6414.     movea.l    A3,A1            ; RastPort    
  6415.     jsr    _LVOText(A6)
  6416.  
  6417.     move.w    38(A3),D1        ; Current Y-Offset
  6418.     move.l    24(sp),D0        ; Spacing (user's Y-offset)
  6419.     add.w    D0,D1            ; Next line offset (Y)
  6420.     move.w    36(A3),D0        ; Current X-Offset
  6421.     movea.l    A3,A1            ; RastPort
  6422.     jsr    _LVOMove(A6)
  6423.  
  6424.     bra.s    2$
  6425. 4$
  6426.     movem.l    (sp)+,D2-D3/A2-A3
  6427.     rts
  6428.  
  6429. ***************************************
  6430. *
  6431. * Convert long-value into ascii-string.
  6432. *
  6433. * Inputs: D0 - value (ulong), A0 - buffer
  6434. * Result: none
  6435. *
  6436.  
  6437. _comdec
  6438.     movem.l    D2/A2,-(sp)
  6439.     move.l    D0,D2
  6440.     lea    _Divutable(pc),A2
  6441.     movea.l    A0,A1
  6442.     moveq    #9,D0
  6443.  
  6444. 1$
  6445.     moveq    #48,D1
  6446. 2$
  6447.     addq.b    #1,D1
  6448.     sub.l    (A2),D2
  6449.     bcc.s    2$
  6450.     subq.b    #1,D1
  6451.     add.l    (A2)+,D2
  6452.  
  6453.     cmpi.b    #'0',D1
  6454.     bne.s    3$
  6455.     cmpi.b    #0,D0
  6456.     beq.s    3$
  6457.     cmpa.l    A1,A0
  6458.     bne.s    3$
  6459.  
  6460.     dbf    D0,1$
  6461. 3$
  6462.     move.b    D1,(A0)+
  6463. 4$
  6464.     dbf    D0,1$
  6465.     clr.b    (A0)
  6466.     movem.l    (sp)+,D2/A2
  6467.     rts
  6468.  
  6469. *************************************************************
  6470. *
  6471. * Print file to ???.
  6472. *
  6473. * Inputs: D0 - length datas, A0 - filename, A1 - startaddress
  6474. * Results: none
  6475. * Note: The datas are not stored in once to the device (PRT:/DFx:)
  6476. * because when a disk-error occurs, we get the chance to terminate
  6477. * saving/printing earlier, which in fact will not destroy the whole
  6478. * disk as it is possible under OS1.x .
  6479.  
  6480. _PrintFile
  6481.     movem.l    D2-D5/A2,-(sp)
  6482.     move.l    D0,D5            ; Save length
  6483.     movea.l    A1,A2            ; Save address datas
  6484.     move.l    A0,D1            ; Name
  6485.     move.l    #MODE_NEWFILE,D2    ; Mode: New
  6486.     movea.l    _DOSBase(A5),A6
  6487.     jsr    _LVOOpen(A6)
  6488.     move.l    D0,D4            ; FileHandle
  6489.     beq.s    .PrintOpenError
  6490. 3$
  6491.     subi.l    #4096,D5        ; Length -4096 bytes
  6492.     bcs.s    1$            ; If there aren't at least 4096 chars to store
  6493.     move.l    #4096,D3        ; Number of chars to write: 4096
  6494.     bra.s    2$            ; Go and write these chars...
  6495. 1$
  6496.     addi.l    #4096,D5        ; Add these - now D5 contains again the rest to store
  6497.     move.l    D5,D3            ; Number of chars to store
  6498.     moveq    #0,D5            ; Indicates: no chars anymore for next loop
  6499. 2$
  6500.     move.l    D4,D1            ; FileHandle
  6501.     move.l    A2,D2            ; Address
  6502.     jsr    _LVOWrite(A6)
  6503.     tst.l    D0
  6504.     bmi.s    .WriteError
  6505.     lea    4096(A2),A2        ; Increase address by 4096 bytes
  6506.     tst.l    D5            ; Rest there?
  6507.     bne.s    3$            ; If there...
  6508.     move.l    D4,D1            ; FileHandle
  6509.     jsr    _LVOClose(A6)        ; Close file/prt: or something like that
  6510.  
  6511. .PrintFileEnd
  6512.     movem.l    (sp)+,D2-D5/A2
  6513.     rts
  6514. .PrintOpenError
  6515.     jsr    _LVOIoErr(A6)
  6516.     bsr.w    _SetError
  6517.     lea    _OpenPrintErrTxt(pc),A0
  6518.     bsr.w    _DisplayError
  6519.     bra.s    .PrintFileEnd
  6520. .WriteError
  6521.     movea.l    _DOSBase(A5),A6        ; - Because of a bug in DOS v39
  6522. *                      we have to restore DOSBase....
  6523.     jsr    _LVOIoErr(A6)
  6524.     bsr.w    _SetError
  6525.     move.l    D4,D1
  6526.     jsr    _LVOClose(A6)
  6527.     lea    _WriteErrTxt(pc),A0
  6528.     bsr.w    _DisplayError
  6529.     bra.s    .PrintFileEnd    
  6530.  
  6531. ************************
  6532. *
  6533. * Erase window contents.
  6534. *
  6535. * Inputs: none
  6536. * Results: none
  6537. *
  6538.  
  6539. _ClearWindow
  6540.     lea    _ConBuffer(A5),A0
  6541.     move.l    #$9B489B4A,(A0)        ; Cursor Home & erase to end of display
  6542.     moveq    #4,D0
  6543.     bra.w    _ConOut_Rel
  6544.  
  6545. *****************************************************************
  6546. *
  6547. * Search for overgiven string....
  6548. *
  6549. * Will use the console.device as input stream and also for output.
  6550. * Searching is done only forward and also case insensitive.
  6551. *
  6552.  
  6553. _SearchSequence
  6554.     movem.l    D2-D4/A2-A4,-(sp)
  6555.  
  6556.     move.l    #$200,D0
  6557.     movea.l    _WindowPtr(A5),A0
  6558.     movea.l    _IntuitionBase(A5),A6
  6559.     jsr    _LVOModifyIDCMP(A6)
  6560.  
  6561.     bsr.s    _ClearWindow
  6562.  
  6563.     tst.l    _TextPtr(A5)
  6564.     beq.s    .end
  6565.  
  6566.     lea    _ConBuffer(A5),A0
  6567.     move.w    #$9B48,(A0)        ; Cursor Home
  6568.     moveq    #2,D0
  6569.     bsr.w    _ConOut_Rel
  6570.  
  6571.     lea    _SearchText(pc),A0
  6572.     lea    _SearchTextEnd(pc),A1    ; Address end of help-text
  6573.     suba.l    A0,A1            ; == length text
  6574.     move.l    A1,D0            ; into D0
  6575.     bsr.w    _ConOut_Reloc        ; Output
  6576.  
  6577.     bsr.w    _CursorOn
  6578.  
  6579.     lea    _IOReqString(A5),A3    ; Buffer to store the complete string the user enters
  6580.     moveq    #0,D3            ; Amount of already stored chars
  6581.     moveq    #0,D4            ; Position in textbuffer
  6582.  
  6583.     movea.l    A3,A0            ; Clear IOReqString
  6584.     move.w    #256-1,D0
  6585. .clear
  6586.     clr.b    (A0)+
  6587.     subq.w    #1,D0
  6588.     bcc.s    .clear
  6589.  
  6590.     lea    _CharBuffer(A5),A0    ; At least, two chars wide (only for console reading)
  6591.     clr.l    (A0)            ; Indicator: Nothing entered!
  6592.  
  6593. .loop
  6594.     moveq    #2,D0
  6595.     lea    _CharBuffer(A5),A0
  6596.     lea    _ReadIo(A5),A1
  6597.     move.l    D0,IO_LENGTH(A1)    ; Number of chars to read
  6598.     move.l    A0,IO_DATA(A1)
  6599.     move.b    #IOF_QUICK,IO_FLAGS(A1)
  6600.     move.w    #CMD_READ,IO_COMMAND(A1) ; Command READ
  6601.     movea.l    _SysBase(A5),A6
  6602.     jsr    _LVODoIO(A6)        ; Send command
  6603.  
  6604.     lea    _CharBuffer(A5),A0    ; Get the chars
  6605.     tst.b    (A0)            ; Too bad, no char
  6606.     beq.s    .loop
  6607.     
  6608.     lea    _CharBuffer(A5),A0    ; Get address of buffer
  6609.     move.b    (A0),D0            ; Get the char (or sequencer <CSI> ($9B))
  6610.     move.b    1(A0),D1        ; When D0 sequencer, D1 keycode
  6611.  
  6612.     clr.l    (A0)            ; Indicator: No char stored!
  6613.     bra.s    .SetString        ; Parse that char...
  6614.  
  6615.  
  6616. * ------ finish (not found) ------ *
  6617. .end
  6618.     bsr.w    _CursorOff
  6619.  
  6620.     move.l    #$8|$200|$400,D0
  6621.     movea.l    _WindowPtr(A5),A0
  6622.     movea.l    _IntuitionBase(A5),A6
  6623.     jsr    _LVOModifyIDCMP(A6)
  6624.  
  6625.     movem.l    (sp)+,D2-D4/A2-A4
  6626.  
  6627.     bsr.w    _RestoreCurrentPage
  6628.     bra.w    _Loop
  6629.  
  6630. ***********************************
  6631. *
  6632. * React to read char
  6633. *
  6634. * INPUTS:    D0 - char
  6635. *    or    D0 - sequence ($9B)
  6636. *    then    D1 - char
  6637.  
  6638. .SetString
  6639.     cmpi.b    #13,D0            ; Carridge return?
  6640.     beq.w    .done
  6641.     cmpi.b    #8,D0            ; Backspace
  6642.     beq.s    .BackSpace
  6643.     cmpi.b    #$7F,D0            ; DEL
  6644.     beq.s    .Delete
  6645.     cmpi.b    #$9B,D0            ; <CSI> (sequence)
  6646.     beq.w    .Sequencer
  6647.     cmpi.b    #$1B,D0            ; ESC
  6648.     beq.w    .Escape
  6649.  
  6650. * ############ -------- Any other char -------- *
  6651.     cmpi.b    #255,D3            ; Maximum editable chars
  6652.     beq.w    .loop
  6653.     move.b    D0,D2            ; The char
  6654.     bsr.w    _InsertChar        ; Store char (D2) to TextBuffer
  6655.     bsr.w    _PrintChar
  6656.     bra.w    .loop            ; and normal...
  6657.  
  6658. * ############ -------- Delete last character -------- *
  6659. .BackSpace
  6660.     tst.l    D3            ; At least one char stored?
  6661.     beq.w    .loop    
  6662.  
  6663.     tst.l    D4
  6664.     beq.w    .loop
  6665.  
  6666.     cmpi.b    #9,-1(A3,D4.l)
  6667.     bne.s    .donormal
  6668.  
  6669.     moveq    #0,D2
  6670.     bsr.w    _MoveTAB
  6671.     bsr.w    _RemChar
  6672.     bra.s    .delete            ; <- see there...
  6673.  
  6674. * ------------------------------ *
  6675.  
  6676. .donormal
  6677.     lea    _ConBuffer(A5),A0
  6678.     move.w    #$9B44,(A0)        ; <CSI>D
  6679.     moveq    #2,D0
  6680.     bsr.w    _ConOut_Rel
  6681.  
  6682.     subq.l    #1,D4
  6683.     bsr.w    _RemChar
  6684.  
  6685.     bra.s    .delete            ; <- see there...
  6686.  
  6687. * ############ ------ Delete current character ------ *
  6688. .Delete
  6689.     tst.l    D3
  6690.     beq.w    .loop
  6691.  
  6692.     cmp.l    D3,D4
  6693.     beq.w    .loop
  6694.  
  6695.     bsr.w    _RemChar
  6696.  
  6697. .delete
  6698.     tst.l    D4
  6699.     beq.s    .dprint            ; Start of line (first char)
  6700.     lea    _ConBuffer(A5),A0
  6701.     move.w    #$9B44,(A0)        ; <CSI>D
  6702.     moveq    #2,D0
  6703.     bsr.w    _ConOut_Rel
  6704. .dprint
  6705.     bsr.w    _PrintChar
  6706.  
  6707.     cmp.l    D3,D4
  6708.     bne.s    .chardeleted
  6709.  
  6710.     lea    _ConBuffer(A5),A0
  6711.     move.w    #$9B50,(A0)        ; <CSI>1D
  6712.     moveq    #2,D0
  6713.     bsr.w    _ConOut_Rel
  6714.  
  6715. .chardeleted
  6716.     bra.w    .loop
  6717.  
  6718.  
  6719. * ############ ------ Cursor keys or something like that picked... ------ *
  6720. .Sequencer    ; D0=$9B, D1=xx,
  6721. *     where xx is:
  6722. *    HELP        $3F
  6723. *    CursorLeft     $44
  6724. *    CursorRight    $43
  6725. *    CursorUp    $41
  6726. *    CursorDown    $42
  6727.     tst.l    D3
  6728.     beq.w    .loop
  6729.  
  6730.     cmpi.b    #$44,D1
  6731.     beq.s    .left
  6732. .right
  6733.     cmp.w    D3,D4
  6734.     beq.w    .loop
  6735.  
  6736.     moveq    #~0,D2
  6737.     cmpi.b    #9,0(A3,D4.l)
  6738.     bne.s    .charright
  6739.     bsr.w    _MoveTAB
  6740.     bra.w    .loop
  6741. .charright
  6742.     addq.l    #1,D4
  6743.     lea    _ConBuffer(A5),A0
  6744.     move.w    #$9B43,(A0)        ; <CSI>C
  6745.     moveq    #2,D0
  6746.     bsr.w    _ConOut_Rel    
  6747.     bra.w    .loop
  6748. * ------------------------------ *
  6749.  
  6750. .left
  6751.     tst.w    D4
  6752.     beq.w    .loop
  6753.  
  6754.     moveq    #0,D2
  6755.     cmpi.b    #9,-1(A3,D4.l)
  6756.     bne.s    .charleft
  6757.     bsr.w    _MoveTAB
  6758.     bra.w    .loop
  6759.  
  6760. .charleft
  6761.     subq.l    #1,D4
  6762.     lea    _ConBuffer(A5),A0
  6763.     move.w    #$9B44,(A0)        ; <CSI>D
  6764.     moveq    #2,D0
  6765.     bsr.w    _ConOut_Rel
  6766.     bra.w    .loop
  6767.  
  6768. * ############ ------- Escape key pressed... -------- *
  6769. .Escape
  6770.     cmpi.b    #255,D3            ; Maximum editable chars
  6771.     beq.w    .loop
  6772.     move.b    #'·',D2
  6773.     bsr.w    _InsertChar
  6774.     bsr.w    _PrintChar
  6775.     bra.w    .loop
  6776.  
  6777. * ############ ------- Carridge Return - string complete! ------- *
  6778. .done
  6779.     tst.l    D3            ; If user cancled entering
  6780.     beq.w    .end
  6781.  
  6782.     clr.b    (A3,D3.l)        ; Terminator
  6783.     bsr.w    _CursorOff
  6784.  
  6785. * ------- Replace '·' (synonym for escape) through escape character ------- *
  6786.     lea    _IOReqString(A5),A0    ; Buffer with chars...
  6787. .escapeSearch
  6788.     tst.b    (A0)
  6789.     beq.s    .searchStart
  6790.     cmpi.b    #'·',(A0)+
  6791.     bne.s    .escapeSearch
  6792.     move.b    #27,-1(A0)
  6793.     bra.s    .escapeSearch
  6794.  
  6795. * -------- Search for the overgiven string --------- *
  6796. .searchStart
  6797.     lea    _IOReqString(A5),A2    ; Buffer with chars...
  6798.     movea.l    _TextPtr(A5),A3        ; Text start
  6799.     addq.l    #2,A3            ; Overread #$200A
  6800.     movea.l    A3,A4
  6801.     adda.l    _BufferSize(A5),A4    ; Size of chars of text
  6802.     subq.l    #4,A4            ; Ignore introducing ($200A) and terminator
  6803. .search
  6804.     move.l    D3,-(sp)
  6805.     move.l    A2,-(sp)
  6806.     move.l    A3,-(sp)
  6807.     bsr.w    _strincmp        ; Compare case insensitive strings
  6808.     lea    12(sp),sp
  6809.     tst.l    D0
  6810.     beq.s    .found            ; D0 = 0 means ok.
  6811.  
  6812.     addq.l    #1,A3            ; Else, next char
  6813.     cmpa.l    A3,A4            ; Check against limit
  6814.     bls.s    .notfound        ; If out of limit
  6815.     bra.s    .search            ; Else, search
  6816. .found
  6817.     move.l    A3,D0            ; Found text
  6818.     addq.l    #1,D0            ; No trouble shooting....
  6819.     move.l    D0,_SearchStrPtr(A5)    ; There where we can continue if user said "search next"
  6820.     move.l    D3,_SearchStrLen(A5)    ; Remember length of string to search for
  6821.  
  6822. * -------- Search for linestart -------- *
  6823.     movea.l    _TextPtr(A5),A0
  6824.     addq.l    #2,A0            ; Overread #$200A
  6825. .searchLF
  6826.     cmpi.b    #10,(A3)        ; LineFeed (line start)
  6827.     beq.s    .foundLineStart
  6828.     cmpa.l    A0,A3            ; Does it fit?
  6829.     bls.s    .notfound
  6830.     subq.l    #1,A3            ; Else one less char...
  6831.     bra.s    .searchLF
  6832. .foundLineStart
  6833.     move.l    #$8|$200|$400,D0
  6834.     movea.l    _WindowPtr(A5),A0
  6835.     movea.l    _IntuitionBase(A5),A6
  6836.     jsr    _LVOModifyIDCMP(A6)
  6837.  
  6838.     move.l    A3,D0
  6839.     movem.l    (sp)+,D2-D4/A2-A4
  6840.  
  6841.     move.l    D0,-(sp)
  6842.     bsr.w    _GetCurrentLine        ; Compute the line (last one in window)
  6843.     move.l    (sp)+,D6        ; First char in window
  6844.     bsr.w    _RestoreCurrentPage
  6845.     bra.w    _Loop
  6846.  
  6847. * ############ ------- Couldn't find the string... ------- *
  6848. .notfound
  6849.     suba.l    A0,A0
  6850.     movea.l    _IntuitionBase(A5),A6
  6851.     jsr    _LVODisplayBeep(A6)
  6852.  
  6853.     clr.l    _SearchStrPtr(A5)
  6854.     clr.l    _SearchStrLen(A5)
  6855.  
  6856.     bra.w    .end
  6857.  
  6858. ****************************************************************
  6859. *
  6860. * Move a char which is a tabulator - to the left or to the right
  6861. *
  6862. * D2    - indicator: zero = leftmove, unequal zero = move right
  6863. *
  6864.  
  6865. _MoveTAB
  6866.     lea    _ConBuffer(A5),A0    ; Buffer for created string
  6867.     move.b    #$9B,(A0)        ;<CSI>
  6868.     lea    _IOReqString(A5),A1    ; Buffer with chars
  6869.     moveq    #12,D0            ; Initial column offset, here "Search for: " <- 12 chars
  6870. *    For a real editor replace 12 through 0, 'cause of line start...
  6871.  
  6872.     tst.b    D2
  6873.     beq.s    .leftsetup        ; ...because left move cursor
  6874. .rightsetup
  6875.     move.l    A0,-(sp)
  6876.     lea    0(A3,D4.l),A0
  6877.     bra.s    .searchtab
  6878. .leftsetup
  6879.     move.l    A0,-(sp)
  6880.     lea    -1(A3,D4.l),A0
  6881. .searchtab
  6882.     cmpa.l    A0,A1            ; Last char before tab?
  6883.     beq.s    .gottab            ; If found
  6884.     addq.w    #1,D0            ; Else counter for chars plus 1
  6885.     cmpi.b    #9,(A1)            ; A tab?
  6886.     bne.s    .next1            ; If not...
  6887.     addq.w    #7,D0            ; Else calc position (every time divisible through 8)
  6888.     andi.w    #-8,D0
  6889. .next1
  6890.     addq.l    #1,A1            ; Get next char('s position(address))
  6891.     bra.s    .searchtab        ; And search further
  6892. .gottab    ; Current position in D0 before tab
  6893.     movea.l    (sp)+,A0
  6894.     tst.b    D2
  6895.     bne.s    .rightmove
  6896. .leftmove
  6897.     move.b    #'D',D2
  6898.     move.l    D0,D1
  6899.     addq.l    #8,D1            ; Add a char (1) and make width divisible by 8 (7) 
  6900.     andi.l    #-8,D1
  6901.     sub.l    D0,D1            ; Number of space to move left
  6902.     subq.l    #1,D4
  6903.     bra.s    .write
  6904.  
  6905. .rightmove    
  6906.     move.b    #'C',D2
  6907.     move.l    D0,D1
  6908.     addq.l    #8,D1            ; Add a char (the tab) and make width divisible by 8 (7) 
  6909.     andi.l    #-8,D1
  6910.     sub.l    D0,D1
  6911.     addq.l    #1,D4
  6912.  
  6913. .write
  6914.     addi.b    #'0',D1            ; Convert it into ASCII
  6915.     move.b    D1,1(A0)        ; Into ConBuffer
  6916.     
  6917.     move.b    D2,2(A0)        ; <CSI>nD = cursor n positions backward
  6918.     moveq    #3,D0            ; Three chars for output
  6919.     bsr.w    _ConOut_Rel        ; Output!
  6920.  
  6921.     rts
  6922.  
  6923. **************************************************
  6924. *
  6925. * Print yet entered char to window.
  6926. *
  6927. * INPUTS:    D3 - amount of chars in TextBuffer
  6928. *        D4 - current BufPosition
  6929. *
  6930. _PrintChar
  6931.     cmp.l    D3,D4
  6932.     bne.s    .givestring
  6933.  
  6934.     tst.l    D3
  6935.     beq.s    .erase
  6936.  
  6937.     lea    -1(A3,D3),A0        ; Address string (including new charcter)
  6938.     moveq    #1,D0
  6939.     bsr.w    _ConOut_Reloc
  6940.     rts
  6941.  
  6942. .givestring
  6943.     lea    _ConBuffer(A5),A0
  6944.     move.w    #$9B4B,(A0)        ; <CSI>K [erase to end of line]
  6945.     moveq    #2,D0
  6946.     bsr.w    _ConOut_Rel
  6947.  
  6948.     lea    -1(A3,D4),A0        ; Address string (including new charcter)
  6949.     move.l    D3,D0            ; Length
  6950.     move.l    D4,D1            ; - minus current position
  6951.     addq.l    #1,D0
  6952.     bsr.w    _ConOut_Reloc        ; Print rest of string
  6953.  
  6954. * Because the cursor is at end of line, we have to move it to current BufPosition...
  6955.     move.l    D4,-(sp)
  6956.     move.l    D3,D4            ; End of line = current BufPosition
  6957.  
  6958. .loopmove
  6959.     moveq    #0,D2            ; Indicator: left move
  6960.     cmpi.b    #9,-1(A3,D4.l)        ; A tab?
  6961.     bne.s    .moveleft        ; If not...
  6962.     bsr.w    _MoveTAB        ; Else, move it as tab...
  6963.     bra.s    .movedone        ; done (for this time)
  6964.  
  6965. .moveleft
  6966.     subq.l    #1,D4            ; BufPosition minus 1
  6967.     lea    _ConBuffer(A5),A0
  6968.     move.l    #$9B314400,(A0)        ; <CSI>1D
  6969.     moveq    #3,D0
  6970.     bsr.w    _ConOut_Rel        ; Move cursor 1 position left
  6971.  
  6972. .movedone
  6973.     move.l    (sp),D0            ; Get original BufPosition
  6974.     cmp.l    D0,D4            ; reached?
  6975.     bne.s    .loopmove        ; If not
  6976.     addq.l    #4,sp
  6977. .done
  6978.     rts
  6979. .erase
  6980.     lea    _ConBuffer(A5),A0
  6981.     move.w    #$9B50,(A0)        ; <CSI>1D
  6982.     moveq    #2,D0
  6983.     bsr.w    _ConOut_Rel
  6984.     rts
  6985.  
  6986. *******************************
  6987. *
  6988. * Insert a char in text buffer
  6989. *
  6990. * INPUTS:    D2 - the char to store
  6991. *        D3 - amount of currently stored chars
  6992. *        D4 - currently used BufPosition
  6993. * RESULTS:    D3 - increased by one
  6994. *        D4 - increased by one
  6995.  
  6996. _InsertChar
  6997.     cmp.l    D3,D4
  6998.     beq.s    .atend            ; It's currently the last char...
  6999.  
  7000.     lea    0(A3,D4.l),A0        ; Source
  7001.     lea    1(A3,D4.l),A1        ; Destination
  7002.     move.l    D3,D0
  7003.     sub.l    D4,D0
  7004.     bsr.s    _DupCopy        ; Free room at current position in textbuffer
  7005.     move.b    D2,0(A3,D4.l)        ; and store there the char
  7006.  
  7007.     addq.l    #1,D3
  7008.     addq.l    #1,D4
  7009.     rts
  7010. .atend                    ; Insert char at last position
  7011.     move.b    D2,0(A3,D4.l)
  7012.     clr.b    1(A3,D4.l)        ; Terminator
  7013.     addq.l    #1,D3
  7014.     addq.l    #1,D4
  7015.     rts
  7016.  
  7017. *****************************************************
  7018. *
  7019. * Because Exec function CopyMem() cannot be used when
  7020. * "ascended overlay copying" is required,
  7021. * we have to make an own, which copies "reverse" the
  7022. * datas.
  7023. *
  7024. * Inputs: A0/A1/D0   -  source/destination/size
  7025. *
  7026.  
  7027. _DupCopy
  7028.     subq.l    #1,D0
  7029. .loop
  7030.     move.b    0(A0,D0.l),0(A1,D0.l)
  7031.     subq.l    #1,D0
  7032.     bcc.s    .loop
  7033.     rts
  7034.  
  7035. ******************************************************************
  7036. *
  7037. * Remove char in text buffer which currently stays on BufPosition
  7038. *
  7039. * INPUTS:    D3 - currently amount of char in buffer (old length)
  7040. *        D4 - current buffers poisition (BufPosition)
  7041. * REULTS:    char on BufPosition removed
  7042. *        D3 - decreased by one (char removed)
  7043. * NOTES:    D4 unchanged...
  7044. *
  7045.  
  7046. _RemChar
  7047.     subq.l    #1,D3            ; New size
  7048.     move.l    D3,D0            ; Amount chars in buffer
  7049.     move.l    D4,D1            ; Buffers position
  7050.     sub.l    D1,D0            ; Number of bytes behind BufPosition
  7051.     beq.s    .endchar
  7052.     bmi.s    .endchar
  7053.     lea    1(A3,D4.l),A0        ; Source
  7054.     lea    0(A3,D4.l),A1        ; Destination
  7055.     movea.l    _SysBase(A5),A6
  7056.     jsr    _LVOCopyMem(A6)
  7057. .endchar
  7058.     clr.b    0(A3,D3.l)
  7059.     rts
  7060.  
  7061. ****************************************************************
  7062. *
  7063. * Compare case insensitive string1 and string2 with width-limit.
  7064. *
  7065. * Input:  string1, string2, num-chars (stackargs)
  7066. * Result: D0 = FALSE (0L) if strings are the same.
  7067. *
  7068.  
  7069. _strincmp    ;cargs    string1.l,string2.l, num-chars.l
  7070.     move.l    D2,-(sp)
  7071.     movea.l    8(sp),A0
  7072.     movea.l    12(sp),A1
  7073.     move.l    16(sp),D2
  7074.     andi.l    #$FFFF,D2
  7075.     subq.w    #1,D2
  7076. .start
  7077.     move.b    (A0)+,D0
  7078.     bsr.s    _UpperCase
  7079.     move.b    D0,D1
  7080.     move.b    (A1)+,D0
  7081.     bsr.s    _UpperCase
  7082.     tst.b    D0
  7083.     bne.s    .tst
  7084.     tst.b    D1
  7085.     beq.s    .same
  7086. .tst
  7087.     cmp.b    D0,D1
  7088.     bne.s    .differ
  7089.     dbf    D2,.start
  7090. .same
  7091.     move.l    (sp)+,D2
  7092.     moveq    #0,D0
  7093.     rts
  7094. .differ
  7095.     move.l    (sp)+,D2
  7096.     moveq    #-1,D0
  7097.     rts
  7098.  
  7099. *********************************************
  7100. *
  7101. * Change char in D0 to uppercase if possible.
  7102. * Supports all ASCII-one characters!
  7103. *
  7104. * Returns char in D0
  7105. *
  7106.  
  7107. _UpperCase
  7108.     tst.b    D0
  7109.     beq.s    .back
  7110.     cmpi.b    #96,D0
  7111.     bls.s    .back
  7112.     cmpi.b    #122,D0
  7113.     bls.s    .change
  7114.     cmpi.b    #255,D0
  7115.     beq.s    .back
  7116.     cmpi.b    #223,D0
  7117.     bhi.s    .change
  7118.     rts
  7119. .change
  7120.     andi.b    #$DF,D0
  7121. .back
  7122.     rts
  7123.  
  7124.  
  7125. *************************************************
  7126. *
  7127. * If the N-key is pressed, we are at this point.
  7128. * Same as SearchSequence() but without any
  7129. * input()...
  7130. *
  7131. _ContinueSearch
  7132.     movem.l    D2/A2-A4,-(sp)
  7133.  
  7134.     move.l    #$200,D0
  7135.     movea.l    _WindowPtr(A5),A0
  7136.     movea.l    _IntuitionBase(A5),A6
  7137.     jsr    _LVOModifyIDCMP(A6)
  7138.  
  7139.     tst.l    _TextPtr(A5)        ; Any text to examine?
  7140.     beq.w    .end
  7141.     lea    _IOReqString(A5),A0    ; Any search string given?
  7142.     tst.b    (A0)
  7143.     beq.w    .end
  7144.     move.l    _SearchStrLen(A5),D2    ; Length of search string set?
  7145.     beq.w    .end
  7146.     tst.l    _SearchStrPtr(A5)    ; An address remembered?
  7147.     beq.s    .end
  7148.  
  7149.     lea    _IOReqString(A5),A2    ; String to search for....
  7150.     movea.l    _SearchStrPtr(A5),A3    ; Address from where to search
  7151.     movea.l    _TextPtr(A5),A4        ; Address text-start
  7152.     addq.l    #2,A4            ; Overread #$200A
  7153.     adda.l    _BufferSize(A5),A4    ; = end of text
  7154.     subq.l    #4,A4
  7155. .search
  7156.     move.l    D2,-(sp)
  7157.     move.l    A2,-(sp)
  7158.     move.l    A3,-(sp)
  7159.     bsr.w    _strincmp
  7160.     lea    12(sp),sp
  7161.     tst.l    D0
  7162.     beq.s    .found
  7163.     cmpa.l    A3,A4
  7164.     bls.s    .notfound
  7165.     addq.l    #1,A3
  7166.     bra.s    .search
  7167. .found
  7168.     move.l    A3,D0
  7169.     addq.l    #1,D0
  7170.     move.l    D0,_SearchStrPtr(A5)    ; Remember address where we found string (plus 1 byte)
  7171.     move.l    D2,_SearchStrLen(A5)
  7172.  
  7173.     movea.l    _TextPtr(A5),A0        ; Address text-start
  7174.     addq.l    #2,A0            ; Overread #$200A
  7175. .searchLF
  7176.     cmpi.b    #10,(A3)
  7177.     beq.s    .foundLineStart
  7178.     cmpa.l    A0,A3            ; Does it fit?
  7179.     bls.s    .notfound
  7180.     subq.l    #1,A3            ; Else one less char...
  7181.     bra.s    .searchLF
  7182. .foundLineStart
  7183.     move.l    A3,D0
  7184.  
  7185.     movem.l    (sp)+,D2/A2-A4
  7186.  
  7187.     move.l    D0,-(sp)
  7188.     bsr.s    _GetCurrentLine
  7189.  
  7190.     move.l    #$8|$200|$400,D0
  7191.     movea.l    _WindowPtr(A5),A0
  7192.     movea.l    _IntuitionBase(A5),A6
  7193.     jsr    _LVOModifyIDCMP(A6)
  7194.  
  7195.     move.l    (sp)+,D6            ; First char in window
  7196.     bsr.w    _RestoreCurrentPage
  7197.     bra.w    _Loop
  7198.  
  7199. .notfound
  7200.     suba.l    A0,A0
  7201.     movea.l    _IntuitionBase(A5),A6
  7202.     jsr    _LVODisplayBeep(A6)
  7203.  
  7204. .end
  7205.     move.l    #$8|$200|$400,D0
  7206.     movea.l    _WindowPtr(A5),A0
  7207.     movea.l    _IntuitionBase(A5),A6
  7208.     jsr    _LVOModifyIDCMP(A6)
  7209.     movem.l    (sp)+,D2/A2-A4
  7210.  
  7211.     bsr.w    _RestoreCurrentPage
  7212.     bra.w    _Loop
  7213.  
  7214.  
  7215. ******************************************
  7216. *
  7217. * Compute current line.
  7218. *
  7219. * Input: D0 - address within text buffer.
  7220. *
  7221.  
  7222. _GetCurrentLine
  7223.     movea.l    _TextPtr(A5),A0
  7224.     move.l    D0,A1
  7225.     moveq    #0,D1
  7226. .cmp
  7227.     cmpi.b    #10,(A0)
  7228.     beq.s    .add
  7229. .tst
  7230.     cmpa.l    A0,A1
  7231.     beq.s    .found
  7232. .next
  7233.     addq.l    #1,A0
  7234.     bra.s    .cmp
  7235. .add
  7236.     addq.l    #1,D1
  7237.     bra.s    .tst
  7238. .found
  7239.     moveq    #0,D0
  7240.     move.w    _StdPageSize(A5),D0    ; Amount of lines in window
  7241.     add.l    D0,D1
  7242.     move.l    D1,_Line(A5)
  7243.     rts
  7244.  
  7245.  
  7246. ***************************
  7247. *
  7248. * Display commands summary.
  7249. *
  7250. * Inputs: none
  7251. * Results: none
  7252. *
  7253.  
  7254. _DisplayHelp
  7255.     bsr.w    _SetActionWait        ; See there
  7256.     bsr.w    _ClearWindow
  7257.  
  7258.     lea    _HelpText(pc),A0    ; Address help-text
  7259.     lea    _HelpTextEnd(pc),A1    ; Address end of help-text
  7260.     suba.l    A0,A1            ; == length text
  7261.     move.l    A1,D0            ; into D0
  7262.     bsr.w    _ConOut_Reloc        ; Output
  7263.  
  7264.     move.l    A2,-(sp)
  7265. 1$
  7266.     movea.l    _SysBase(A5),A6
  7267.     movea.l    _WindowPtr(A5),A2
  7268.     movea.l    wd_UserPort(A2),A2
  7269.     movea.l    A2,A0
  7270.     jsr    _LVOWaitPort(A6)
  7271.     movea.l    A2,A0
  7272.     jsr    _LVOGetMsg(A6)
  7273.     movea.l    D0,A1
  7274.     movea.l    D0,A2
  7275.     jsr    _LVOReplyMsg(A6)
  7276.  
  7277.     cmpi.w    #H_Key+$80,im_Code(A2)    ; H-key released?
  7278.     bne.s    1$
  7279.  
  7280.     movea.l    _WindowPtr(A5),A2
  7281.     movea.l    wd_UserPort(A2),A2
  7282.     movea.l    A2,A0
  7283.     jsr    _LVOWaitPort(A6)    ; Wait for any event
  7284.     movea.l    A2,A0
  7285.     jsr    _LVOGetMsg(A6)
  7286.     movea.l    D0,A1
  7287.     jsr    _LVOReplyMsg(A6)
  7288.  
  7289.     movea.l    (sp)+,A2
  7290.  
  7291.     tst.l    _TextPtr(A5)        ; Any text there?
  7292.     beq.s    2$            ; If not
  7293.     bsr.w    _RestoreCurrentPage    ; Else restore the page
  7294. 2$
  7295.     bra.w    _Loop
  7296.  
  7297.  
  7298. **************************
  7299. *
  7300. * Display the standard....
  7301. *
  7302. * Inputs: none
  7303. * Results: none
  7304. *
  7305.  
  7306. _About
  7307.     lea    _AboutTxt(pc),A0        ; I like this...
  7308.     bsr.w    _DisplayError
  7309.     bra.w    _Loop
  7310.  
  7311.  
  7312. ****************************************
  7313. *
  7314. * Display informations about program....
  7315. *
  7316. * Inputs: none
  7317. * Results: none
  7318. *
  7319.  
  7320. _Info
  7321.     move.l    #_TableSize,D0        ; Size BSS
  7322.     addq.l    #7,D0
  7323.     andi.l    #-8,D0            ; Aligned size
  7324.     move.l    D0,-(sp)
  7325.  
  7326.     lea    _startup(pc),A0        ; Code start
  7327.     subq.l    #4,A0            ; Next hunk...
  7328.     movea.l    (A0),A0            ; BPTR next hunk
  7329.     adda.l    A0,A0
  7330.     adda.l    A0,A0            ; == APTR next hunk
  7331.     move.l    -4(A0),D0        ; Size next hunk
  7332.     subq.l    #8,D0            ; Ignore hunk-header (8 bytes)
  7333.     move.l    D0,-(sp)        ; Size datas-chip
  7334.  
  7335.     lea    _Divutable(pc),A0    ; Start datas
  7336.     lea    _EndDatas(pc),A1    ; End datas
  7337.     sub.l    A0,A1            ; == size datas
  7338.     move.l    A1,D0
  7339.     addq.l    #3,D0
  7340.     andi.l    #-4,D0            ; Aligned size (longword)
  7341.     move.l    D0,-(sp)
  7342.  
  7343.     lea    _startup(pc),A0        ; Entry point of program
  7344.     lea    _Divutable(pc),A1    ; End of code
  7345.     suba.l    A0,A1            ; == size of code
  7346.     move.l    A1,-(sp)
  7347.  
  7348.     pea    _InfoTxt(pc)        ; Text...
  7349.     bsr.w    _FmtDisplay
  7350.     lea    20(sp),sp        ; Restore stack    
  7351.     bra.w    _Loop
  7352.  
  7353. *************************
  7354. *
  7355. * Allow messages for now.
  7356. *
  7357. * Inputs: none
  7358. * Results: none
  7359. *
  7360.  
  7361. _SetActionWait
  7362.     move.l    A0,-(sp)
  7363.     movea.l    _WindowPtr(A5),A0
  7364.     movea.l    wd_UserPort(A0),A0
  7365.     clr.b    MP_FLAGS(A0)
  7366.     movea.l    (sp)+,A0
  7367.     rts
  7368.  
  7369. ***********************************
  7370. *
  7371. * Do not allow any message for now.
  7372. *
  7373. * Inputs: none
  7374. * Results: none
  7375. *
  7376.  
  7377. _SetNILWait
  7378.     move.l    A0,-(sp)
  7379.     movea.l    _WindowPtr(A5),A0
  7380.     movea.l    wd_UserPort(A0),A0
  7381.     move.b    #PA_IGNORE,MP_FLAGS(A0)
  7382.     movea.l    (sp)+,A0
  7383.     rts
  7384.  
  7385. ********************************************
  7386. *
  7387. * Check for user specification in tooltypes.
  7388. *
  7389. * Inputs: none
  7390. * Results: none
  7391. *
  7392.  
  7393. _CheckWarning
  7394.     lea    WB_arg_1(A5),A0        ; Address constant of 1. argument
  7395. 1$
  7396.     tst.l    (A0)            ; Address 1. argument there?
  7397.     beq.s    3$
  7398.     movea.l    (A0)+,A1        ; Out of it address 1. argument
  7399.     lea    _NoWarningName(pc),A2    ; "NOWARN",0
  7400.     moveq    #6,D0            ; 7 loops
  7401. 2$
  7402.     cmpm.b    (A1)+,(A2)+        ; Compare char for char
  7403.     bne.s    1$            ; "NOWARN"
  7404.     dbf    D0,2$
  7405.     st.b    _NoWarnFlag(A5)
  7406.  
  7407. 3$
  7408.     lea    WB_arg_1(A5),A0        ; Address constant of 1. argument
  7409. 4$
  7410.     tst.l    (A0)            ; Address 1. argument there?
  7411.     beq.s    6$
  7412.     movea.l    (A0)+,A1        ; Out of it address 1. argument
  7413.     lea    _NoCheckPrinterTxt(pc),A2    ; "NOPRTCHECK",0
  7414.     moveq    #10,D0            ; 11 loops
  7415. 5$
  7416.     cmpm.b    (A1)+,(A2)+        ; Compare char for char
  7417.     bne.s    4$
  7418.     dbf    D0,5$
  7419.     st.b    _NoCheckPrtFlag(A5)
  7420. 6$
  7421.     rts
  7422.  
  7423. *************************************************
  7424. *
  7425. * Check for user specification in tooltypes.
  7426. * If specification was made, execute the command.
  7427. * Inputs: none
  7428. * Results: none
  7429. *
  7430.  
  7431. _CheckExecute
  7432.     lea    WB_arg_1(A5),A0
  7433. .NextTType
  7434.     tst.l    (A0)            ; Argument there?
  7435.     beq.s    .EndExecute        ; No
  7436.     movea.l    (A0)+,A1        ; Address overgiven string
  7437.     lea    _ExecuteTxt(pc),A2    ; Address string to compare
  7438.     moveq    #7,D0            ; 8 chars to compare
  7439. .CheckTType
  7440.     cmpm.b    (A1)+,(A2)+        ; Compare strings
  7441.     bne.s    .NextTType        ; "EXECUTE="
  7442.     dbf    D0,.CheckTType
  7443.     movea.l    A1,A0            ; Pointer to following string
  7444.  
  7445.     moveq    #0,D4
  7446.     lea    _ConBuffer(A5),A1
  7447. 1$
  7448.     move.b    (A0)+,(A1)+
  7449.     bne.s    1$
  7450.     move.l    _stdout(A5),D3
  7451.     bne.s    2$
  7452.     lea    _NilName(pc),A0
  7453.     move.l    A0,D1
  7454.     move.l    #MODE_NEWFILE,D2
  7455.     movea.l    _DOSBase(A5),A6
  7456.     jsr    _LVOOpen(A6)
  7457.     move.l    D0,D4
  7458.     beq.s    .EndExecute
  7459.     move.l    D4,D3
  7460. 2$
  7461.     lea    _ConBuffer(A5),A0
  7462.     move.l    A0,D1
  7463.     moveq    #0,D2
  7464.     movea.l    _DOSBase(A5),A6
  7465.     jsr    _LVOExecute(A6)
  7466.     tst.l    D4
  7467.     beq.s    .EndExecute
  7468.     move.l    D4,D1
  7469.     jsr    _LVOClose(A6)    
  7470. .EndExecute
  7471.     rts
  7472.  
  7473. **********************************
  7474. *
  7475. * Init gadgets for "DisplayError".
  7476. * Do it position independent.
  7477. *
  7478. * Inputs: None
  7479. * Results: None
  7480. *
  7481.  
  7482. _InitGadgets
  7483.     movem.l    D0-D2/A0-A4/A6,-(sp)
  7484.  
  7485. BoolGadFlags    EQU    GADGIMMEDIATE|RELVERIFY
  7486.  
  7487.     lea    _Gad1(A5),A0
  7488.     move.w    #20,gg_LeftEdge(A0)
  7489.     move.w    #78,gg_TopEdge(A0)
  7490.     move.w    #74,gg_Width(A0)
  7491.     move.w    #19,gg_Height(A0)
  7492.     move.w    #GADGHIMAGE|GADGIMAGE,gg_Flags(A0)
  7493.     move.w    #BoolGadFlags,gg_Activation(A0)
  7494.     move.w    #BOOLGADGET,gg_GadgetType(A0)
  7495.     move.w    #1,gg_GadgetID(A0)
  7496.  
  7497.     lea    _Gad2(A5),A1
  7498.     moveq    #gg_SIZEOF,D0
  7499.     bra.s    2$
  7500. 1$
  7501.     move.b    (A0)+,(A1)+
  7502. 2$
  7503.     dbf    D0,1$
  7504.  
  7505.     lea    _Gad2(A5),A0
  7506.     clr.l    (A0)            ; No next gadget!  - otherwise on second
  7507. *                      initializing it would point to itself!!!
  7508.     move.w    #226,gg_LeftEdge(A0)
  7509.     move.w    #2,gg_GadgetID(A0)
  7510.  
  7511.     lea    _GTxt1(A5),A0
  7512.     move.b    #1,(A0)            ; DetailPen
  7513.     lea    _GTxt2(A5),A0
  7514.     move.b    #1,(A0)            ; DetailPen
  7515.  
  7516.     lea    _Image.1(pc),A0
  7517.     lea    _Image.2(pc),A1
  7518.     lea    _Gad1(A5),A2
  7519.     lea    _Gad2(A5),A3
  7520.  
  7521.     move.l    A3,(A2)
  7522.     move.l    A0,gg_GadgetRender(A2)
  7523.     move.l    A1,gg_SelectRender(A2)
  7524.     lea    _GTxt1(A5),A4
  7525.     move.l    A4,gg_GadgetText(A2)
  7526.  
  7527.     move.l    A0,gg_GadgetRender(A3)
  7528.     move.l    A1,gg_SelectRender(A3)
  7529.     lea    _GTxt2(A5),A4
  7530.     move.l    A4,gg_GadgetText(A3)
  7531.  
  7532.     lea    _GTxt1(A5),A0
  7533.     lea    _GStr1(pc),A1
  7534.     move.l    A1,it_IText(A0)
  7535.  
  7536.     lea    _GTxt2(A5),A0
  7537.     lea    _GStr2(pc),A1
  7538.     move.l    A1,it_IText(A0)
  7539.  
  7540.     lea    _startup(pc),A0        ; First instruction of Viewer (startup-code)
  7541.     subq.l    #4,A0            ; Pointer to BPTR next hunk
  7542.     movea.l    (A0),A0            ; BPTR NextHunk
  7543.     adda.l    A0,A0
  7544.     adda.l    A0,A0            ; APTR NextHunk
  7545.     addq.l    #4,A0            ; Section Chip (_Gad.1, size 190 bytes)
  7546.     movea.l    A0,A1
  7547.     lea    190(A1),A1        ; _Gad.2
  7548.     lea    _Image.1(pc),A2
  7549.     lea    _Image.2(pc),A3
  7550.     move.l    A0,ig_ImageData(A2)
  7551.     move.l    A1,ig_ImageData(A3)
  7552.  
  7553.     bsr.s    _CenterGadTxt
  7554.  
  7555.     movem.l    (sp)+,D0-D2/A0-A4/A6
  7556.     rts
  7557.  
  7558. _CenterGadTxt
  7559.     lea    _Gad1(A5),A2        ; First-Gadget
  7560.     bra.s    .set
  7561. .NextGadget
  7562.     tst.l    (A2)            ; Next gadget?
  7563.     beq.w    .NoNext
  7564.     movea.l    (A2),A2
  7565. .set
  7566.     move.w    gg_GadgetType(A2),D0
  7567.     btst    #0,D0            ; BoolGadget ?
  7568.     beq.s    .NextGadget        ; If not
  7569.  
  7570.     tst.l    gg_GadgetText(A2)    ; Intuition-text-structure?
  7571.     beq.s    .NextGadget
  7572.     movea.l    gg_GadgetText(A2),A0
  7573.     movea.l    A0,A3            ; Save Intuition-text-structure
  7574.     tst.l    it_IText(A0)        ; Any Text placed?
  7575.     beq.s    .NextGadget
  7576.     movea.l    it_IText(A0),A0        ; Pointer to string
  7577.     movea.l    A0,A1
  7578.     moveq    #-1,D0
  7579. .getChars
  7580.     tst.b    (A1)+
  7581.     dbeq    D0,.getChars
  7582.     not.l    D0            ; Length in chars of string
  7583.     movea.l    _ErrWindowPtr(A5),A1    ; Window
  7584.     movea.l    wd_WScreen(A1),A1    ; Screen's
  7585.     lea    sc_RastPort(A1),A1    ; RastPort!!! <- default font!!!
  7586.     movea.l    _GfxBase(A5),A6
  7587.     jsr    _LVOTextLength(A6)    ; Get stringlength in pixel
  7588.  
  7589.     move.w    gg_Width(A2),D1        ; Width of gadget
  7590.  
  7591.     lsr.w    #1,D0            ; Half textlength
  7592.     lsr.w    #1,D1            ; Half gadget width
  7593.     sub.w    D0,D1            ; Offset 1. char
  7594.     move.w    D1,it_LeftEdge(A3)    ; Store it in IntuiText-structure
  7595.  
  7596.     moveq    #0,D2            ; Flags
  7597.     movea.l    _ErrWindowPtr(A5),A0    ; Window
  7598.     movea.l    wd_WScreen(A0),A0    ; Get screen's
  7599.     lea    sc_RastPort(A0),A0    ; rastport - not window's one, because
  7600. *                      the default-font is used for a gadget-text
  7601.     move.w    rp_TxHeight(A0),D0    ; Height in pixel of font
  7602.     btst    #0,D0            ; Font-height even (8, 10, 12 a.s.o.)?
  7603.     bne.s    2$
  7604. 1$
  7605.     move.b    #1,D2    
  7606. 2$
  7607.     move.w    #19,D1            ; Height gadget
  7608.     lsr.w    #1,D0            ; Half
  7609.     lsr.w    #1,D1            ; Half
  7610.     sub.w    D0,D1            ; Y-offset font
  7611.     add.w    D2,D1            ; Add (may be NULL) for even font-sizes
  7612.     move.w    D1,it_TopEdge(A3)    ; Set Top-Offset
  7613.     bra.w    .NextGadget
  7614. .NoNext
  7615.     rts
  7616.  
  7617. ***************
  7618. *
  7619. * Init windows.
  7620. *
  7621. * Inputs: none
  7622. * Results: none
  7623. *
  7624.  
  7625. _InitStandard
  7626.     lea    _WindowRecord(A5),A0
  7627.     move.b    #1,nw_DetailPen(A0)
  7628.     move.b    #3,nw_BlockPen(A0)
  7629.     move.l    #$8|$40|$200|$400,nw_IDCMPFlags(A0)
  7630.     move.l    #1|2|4|8|$10|$400|$1000|$10000,nw_Flags(A0)
  7631.     move.w    #240,nw_MinWidth(A0)    
  7632.     move.w    #70,nw_MinHeight(A0)    
  7633.     moveq    #-1,D0
  7634.     move.w    D0,nw_MaxWidth(A0)
  7635.     move.w    D0,nw_MaxHeight(A0)
  7636.     move.w    #CUSTOMSCREEN,nw_Type(A0)
  7637.  
  7638.     lea    _ErrWindowStruc(A5),A0
  7639.     move.w    #320,nw_Width(A0)
  7640.     move.w    #100,nw_Height(A0)
  7641.     move.b    #-1,nw_DetailPen(A0)
  7642.     move.b    #-1,nw_BlockPen(A0)
  7643.     move.l    #$40|$400,nw_IDCMPFlags(A0)
  7644.     move.l    #$1000|$10000,nw_Flags(A0)
  7645.     move.w    #320,nw_MinWidth(A0)    
  7646.     move.w    #100,nw_MinHeight(A0)    
  7647.     move.w    #320,nw_MaxWidth(A0)
  7648.     move.w    #100,nw_MaxHeight(A0)
  7649.     move.w    #CUSTOMSCREEN,nw_Type(A0)
  7650.  
  7651.     rts
  7652.  
  7653.  
  7654. ****************************************************************************
  7655. *
  7656. * Allocate AudioIO-request
  7657. *
  7658. * Inputs: Priority (should be NULL or negative)  D0 (byte, word, longword, but signed!)
  7659. *
  7660. * Result: APTR IOAudio - pointer to IORequest or zero upon error
  7661. *
  7662. * Notes: IOAudio is larger than it seems, so never deallocate it on your own.
  7663. *
  7664.  
  7665. IOReq_size    EQU    68+4    ; size: divisible by eight
  7666. MsgPort_size    EQU    34+6    ; size: divisible by eight
  7667. IOAudio_size    EQU    IOReq_size+MsgPort_size
  7668.  
  7669. _AllocIOAudioA ; (D0)(Pri)
  7670.     movem.l    D2/A3-A4/A6,-(sp)
  7671.  
  7672.     move.l    D0,D2            ; Pri
  7673.  
  7674.     moveq    #IOAudio_size,D0    ; 68 bytes IOAudio, 34 bytes MsgPort - aligned!
  7675.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  7676.     movea.l    _SysBase(A5),A6
  7677.     jsr    _LVOAllocMem(A6)
  7678.     tst.l    D0
  7679.     beq.w    .AllocAudioEnd        ; Error no mem
  7680.     movea.l    D0,A4            ; IOReq ( *IOAudio)
  7681.     movea.l    D0,A3            ; IOAudio
  7682.     lea    IOReq_size(A3),A3    ; Skip IOAudio - thus pointer to MessagePort
  7683.  
  7684.     moveq    #-1,D0            ; Any signal will do it
  7685.     jsr    _LVOAllocSignal(A6)
  7686.     cmpi.l    #-1,D0            ; Failed?
  7687.     beq.w    .errNoSignal
  7688.  
  7689.     move.b    D0,MP_SIGBIT(A3)    ; SignalBit
  7690.     suba.l    A1,A1
  7691.     jsr    _LVOFindTask(A6)    ; Own task
  7692.     move.l    D0,MP_SIGTASK(A3)    ; Task who is signalled
  7693.     move.b    #NT_MSGPORT,LN_TYPE(A3) ; Type = message port
  7694.     lea    MP_MSGLIST(A3),A0
  7695.     NEWLIST    A0            ; Set up empty list
  7696.  
  7697.     btst    #31,D2            ; A signed long value?
  7698.     bne.s    .signed            ; If so...
  7699.     btst    #15,D2            ; A signed word value?
  7700.     beq.s    .setup            ; If not...
  7701. .signed
  7702.     bset    #7,D2            ; Make a signed byte
  7703. .setup
  7704.     move.b    D2,LN_PRI(A4)        ; Priority of message (IOAudio->io_Message->ln_Pri)
  7705.     move.b    #NT_REPLYMSG,LN_TYPE(A4) ; Type = ~message - due to a buck in CheckIO()
  7706.     move.l    A3,MN_REPLYPORT(A4)    ; Set replyport
  7707.     move.w    #ioa_SIZEOF,MN_LENGTH(A4); Length of message
  7708.  
  7709.     lea    _Channels(pc),A0
  7710.     move.l    A0,ioa_Data(A4)        ; Address channel map
  7711.     move.l    #4,ioa_Length(A4)    ; Length channel map
  7712.     move.b    #ADIOF_NOWAIT,IO_FLAGS(A4)    ; Do not wait until channels are unlocked
  7713.     move.w    #ADCMD_ALLOCATE,IO_COMMAND(A4)    ; Alloc channels upon opening device
  7714.  
  7715.     lea    _AudioName(pc),A0    ; Device
  7716.     movea.l    A4,A1            ; IOReq
  7717.     moveq    #0,D0            ; Unit
  7718.     moveq    #0,D1            ; Flags
  7719.     jsr    _LVOOpenDevice(A6)
  7720.     tst.l    D0
  7721.     bne.s    .errNoDev
  7722.  
  7723.     move.l    A4,D0            ; IOAudio
  7724. .AllocAudioEnd
  7725.     movem.l    (sp)+,D2/A3-A4/A6
  7726.     rts
  7727.  
  7728. .errNoMem
  7729.     moveq    #ERROR_NO_FREE_STORE,D0
  7730.     bsr.s    .SetIoErr
  7731.     moveq    #0,D0
  7732.     bra.s    .AllocAudioEnd
  7733. .errNoSignal
  7734.     move.l    #ERROR_NO_MORE_ENTRIES,D0
  7735.     bsr.s    .SetIoErr
  7736.     bsr.s    .FreeAudioIOReq
  7737.     moveq    #0,D0
  7738.     bra.s    .AllocAudioEnd
  7739. .errNoDev
  7740.     move.l    #ERROR_OBJECT_IN_USE,D0
  7741.     bsr.s    .SetIoErr
  7742.     moveq    #0,D0
  7743.     move.b    MP_SIGBIT(A3),D0
  7744.     jsr    _LVOFreeSignal(A6)
  7745.     bsr.s    .FreeAudioIOReq
  7746.     moveq    #0,D0
  7747.     bra.s    .AllocAudioEnd
  7748. .FreeAudioIOReq
  7749.     movea.l    A4,A1
  7750.     moveq    #IOAudio_size,D0
  7751.     jmp    _LVOFreeMem(A6)
  7752.  
  7753. .SetIoErr
  7754.     movea.l    276(A6),A0        ; ThisTask(A6)
  7755.     cmpi.b    #NT_PROCESS,LN_TYPE(A0)    ; Are we a process or task?
  7756.     bne.s    .done
  7757.     move.l    D0,pr_Result2(A0)    ; Set error code in process' error field
  7758. .done
  7759.     rts
  7760.  
  7761. *************************************************************************
  7762. *
  7763. * Free through AllocAudioIO() allocated IORequest, MessagePort, Signalbit.
  7764. *
  7765. * Inputs: IOAudio A0, APTR
  7766. *
  7767. * Results: None
  7768. *
  7769.  
  7770. _FreeIOAudioA ; (A0)(IOAudio)
  7771.     movem.l    A3-A4/A6,-(sp)
  7772.     move.l    A0,D0
  7773.     beq.s    .out
  7774.     movea.l    A0,A4
  7775.     movea.l    A0,A3
  7776.     lea    IOReq_size(A3),A3    ; Skip IOAudio
  7777.  
  7778.     tst.l    IO_DEVICE(A4)
  7779.     beq.s    .NotInProgress
  7780.  
  7781.     movea.l    A4,A1
  7782.  
  7783. *    clr.b    LN_TYPE(A4)
  7784.  
  7785. * Although I set the type of IORequest to zero (as stated in autodocs) CheckIO() will ever hang...
  7786. *    movea.l    _SysBase(A5),A6
  7787. *    jsr    _LVOCheckIO(A6)        ; A process running?
  7788. *    tst.l    D0            ; ~0 == no process
  7789. *    bne.s    .NotInProgress
  7790.  
  7791.     movea.l    A4,A1
  7792.     ABORTIO
  7793.  
  7794. *    movea.l    A4,A1
  7795. *    jsr    _LVOWaitIO(A6)
  7796.  
  7797. .NotInProgress
  7798.     moveq    #0,D0
  7799.     move.b    MP_SIGBIT(A3),D0    ; Get allocated signal
  7800.     jsr    _LVOFreeSignal(A6)    ; Free allocated signal
  7801.  
  7802.     movea.l    A4,A1
  7803.     jsr    _LVOCloseDevice(A6)    ; Close the audio-device
  7804.  
  7805.     movea.l    A4,A1
  7806.     moveq    #IOAudio_size,D0    ; Full size (aligned)
  7807.     jsr    _LVOFreeMem(A6)        ; Free allocated memory
  7808. .out
  7809.     movem.l    (sp)+,A3-A4/A6
  7810.     rts
  7811.  
  7812. *******************************************************
  7813. *
  7814. * Move the datas to the audio-channels.
  7815. * Breaks the current IOAudio-process.
  7816. * Does not wait until datas are completely worked out.
  7817. *
  7818. * Inputs: D0 (ULONG) Length in Bytes
  7819. *      D1 (UWORD) Cycles ( NULL = neverending)
  7820. *      D2 (UWORD) Period
  7821. *      D3 (UWORD) Volume
  7822. *      A0 (APTR) IOAudio
  7823. *      A1 (APTR) AudioDatas (must stay in chip-mem)
  7824. *
  7825. * Results: NULL - error - zero IOAudio
  7826. *
  7827.  
  7828. _SendIOAudioA ; (D0,D1,D2,D3,A0,A1)(length,cycles,period,volume,IOAudio,audiodata)
  7829.     movem.l    D2-D5/A2-A3/A6,-(sp)
  7830.  
  7831.     movea.l    A0,A2            ; IOAudio
  7832.     movea.l    A1,A3            ; audiodata
  7833. *           D2            ; period
  7834. *           D3            ; volume
  7835.     move.l    D0,D4            ; length
  7836.     move.w    D1,D5            ; cycles
  7837.     move.l    A0,D0
  7838.     beq.s    .failed
  7839. *
  7840. ** There seems to be a bug in the audio.device. CheckIO() will here
  7841. ** return ever that there is a process running, even there isn't one.
  7842. ** If we _do_ ABORTIO with an afterward WaitIO() (convention!) we wait
  7843. ** here until world's ruin....
  7844. *
  7845.     movea.l    A2,A1
  7846.     movea.l    _SysBase(A5),A6
  7847.     jsr    _LVOCheckIO(A6)        ; A process running?
  7848.     tst.l    D0            ; ~0 == no process
  7849.     bne.s    .NotInProgress
  7850.  
  7851.     movea.l    A2,A1
  7852.     ABORTIO
  7853.  
  7854. .NotInProgress
  7855.     movea.l    A2,A1            ; IOAudio
  7856.     move.l    A3,ioa_Data(A1)
  7857.     move.l    D4,ioa_Length(A1)
  7858.     move.w    D2,ioa_Period(A1)
  7859.     move.w    D3,ioa_Volume(A1)
  7860.     move.w    D5,ioa_Cycles(A1)
  7861.     move.b    #ADIOF_PERVOL|ADIOF_SYNCCYCLE|IOF_QUICK,IO_FLAGS(A1)
  7862.     move.w    #CMD_WRITE,IO_COMMAND(A1)
  7863.     BEGINIO                ; BEGINIO and ABORTIO are MARCOS of "exec/io.i"!
  7864.     move.l    A2,D0
  7865. .out
  7866.     movem.l    (sp)+,D2-D5/A2-A3/A6
  7867.     rts
  7868. .failed
  7869.     moveq    #0,D0
  7870.     bra.s    .out
  7871.  
  7872. *******************************************
  7873. *
  7874. ** Make the sound audible
  7875. *
  7876.  
  7877. _AudioHit
  7878.     movem.l    D2-D7,-(sp)
  7879.     tst.b    _AudGadget(A5)
  7880.     beq.w    1$
  7881.     tst.l    _AudioBuffer(A5)
  7882.     beq.w    1$
  7883.     tst.l    _IOAudio(A5)
  7884.     beq.w    1$
  7885.  
  7886.     movea.l    _IOAudio(A5),A0
  7887.     move.b    IO_ERROR(A0),D0        ; Any error?
  7888.     bpl.s    .gogo            ; No...
  7889.  
  7890.     bsr.w    _FreeIOAudioA        ; Error, so free device block
  7891.     moveq    #-50,D0            ; and allocate a new one
  7892.     bsr.w    _AllocIOAudioA        ; with the same priority
  7893.     move.l    D0,_IOAudio(A5)
  7894.     beq.w    .errorPlay        ; If we still can't them...
  7895.  
  7896. .gogo
  7897.     move.l    _BODYSize(A5),D0
  7898.     move.l    _AudioBufferSize(A5),D1
  7899.     cmp.l    D0,D1
  7900.     bls.s    2$
  7901.  
  7902. * Normal, one shot sample play, sample size lower or equal to 28 kbyte 
  7903.     move.l    _BODYSize(A5),D0
  7904.     moveq    #1,D1
  7905.     move.l    _AudioPeriod(A5),D2
  7906.     moveq    #64,D3
  7907.     movea.l    _IOAudio(A5),A0
  7908.     move.l    _AudioBuffer(A5),A1
  7909.     bsr.w    _SendIOAudioA
  7910.  
  7911.     movea.l    _IOAudio(A5),A0
  7912.     tst.b    IO_ERROR(A0)
  7913.     bne.w    .errorPlay
  7914.  
  7915.     bra.w    .done            ; Done
  7916.  
  7917. * Smart, sample size taller than 28 kbyte
  7918. 2$
  7919.     movea.l    _IOAudio(A5),A0
  7920.     movea.l    MN_REPLYPORT(A0),A0
  7921.     move.b    MP_SIGBIT(A0),D1    ; Get SigBit of IO Request
  7922.     moveq    #0,D4
  7923.     move.b    D1,D4
  7924.     moveq    #1,D0
  7925.     lsl.l    D1,D0            ; ... and convert it into a bitmask
  7926.     move.l    D0,D7
  7927.  
  7928.     movea.l    _WindowPtr(A5),A0    ; Same for our window
  7929.     movea.l    wd_UserPort(A0),A0
  7930.     move.b    MP_SIGBIT(A0),D1
  7931.     moveq    #1,D0
  7932.     lsl.l    D1,D0
  7933.     or.l    D0,D7            ; Combine both mask
  7934.  
  7935.     move.l    _BODYSize(A5),D6    ; The size of the whole audio datas
  7936.     moveq    #0,D5            ; How many bytes already played
  7937.  
  7938.     moveq    #0,D0            ; Refer to chip-ram buffer 0
  7939.     bsr.w    .SetupAudBuffer
  7940.     move.l    D0,D2            ; Amount datas to play
  7941.  
  7942. 3$    
  7943.     tst.l    D2
  7944.     beq.w    .done
  7945.     move.l    D2,D0            ; Play how many ....
  7946.     moveq    #1,D1            ; One cycle
  7947.     move.l    _AudioPeriod(A5),D2    ; Period
  7948.     moveq    #64,D3            ; Volume
  7949.     move.l    _IOAudio(A5),A0        ; Device IO Request block
  7950.     move.l    _AudioBuffer(A5),A1    ; Datas
  7951.     bsr.w    _SendIOAudioA        ; Play them!
  7952.  
  7953.     moveq    #1,D0            ; Refer to chip-ram buffer 1
  7954.     bsr.s    .SetupAudBuffer
  7955.     move.l    D0,D2
  7956.     beq.s    .done
  7957.  
  7958.     movea.l    _IOAudio(A5),A0
  7959.     tst.b    IO_ERROR(A0)        ; Error occurred?
  7960.     bne.s    .errorPlay
  7961.  
  7962.     movea.l    _SysBase(A5),A6
  7963.     move.l    D7,D0            ; Mask
  7964.     jsr    _LVOWait(A6)        ; Wait for this part to finish
  7965.     moveq    #0,D3
  7966.     btst.l    D4,D0            ; Not an audio signal?
  7967.     beq.w    4$            ; If no audio signal!
  7968.  
  7969. .InJump
  7970.     move.l    D2,D0            ; Play how many ....
  7971.     moveq    #1,D1
  7972.     move.l    _AudioPeriod(A5),D2
  7973.     moveq    #64,D3
  7974.     movea.l    _IOAudio(A5),A0
  7975.     move.l    _AudioBuffer(A5),A1
  7976.     lea    14*1024(A1),A1
  7977.     bsr.w    _SendIOAudioA
  7978.  
  7979.     moveq    #0,D0            ; Refer to chip-ram buffer 0
  7980.     bsr.s    .SetupAudBuffer
  7981.  
  7982.     move.l    D0,D2
  7983.  
  7984.     movea.l    _IOAudio(A5),A0
  7985.     tst.b    IO_ERROR(A0)
  7986.     bne.s    .errorPlay
  7987.  
  7988.     movea.l    _SysBase(A5),A6
  7989.     move.l    D7,D0
  7990.     jsr    _LVOWait(A6)        ; Wait for that part to finish
  7991.     moveq    #1,D3
  7992.     btst.l    D4,D0            ; Not an audio signal?
  7993.     beq.s    4$            ; If no audio signal!
  7994.  
  7995.     bra.s    3$            ; Restart (next data block)
  7996.  
  7997. .errorPlay
  7998.     lea    _AudErrTxt(pc),A0
  7999.     bsr.w    _DisplayError
  8000.     bra.s    1$
  8001. .done
  8002.     movea.l    _SysBase(A5),A6
  8003.     movea.l    _IOAudio(A5),A1
  8004.     jsr    _LVOWaitIO(A6)
  8005. 1$
  8006.     movem.l    (sp)+,D2-D7
  8007.     bra.w    _Loop
  8008.  
  8009. * -------- Fill either first or second buffer with audio datas -------- *
  8010. * D0 = 0, 1st buffer, D0 = 1, second buffer
  8011.  
  8012. .SetupAudBuffer
  8013.     subi.l    #14*1024,D6        ; Try to work out 14 kbyte
  8014.     bcs.s    .overload        ; If there isn't such a amount
  8015.  
  8016.     movea.l    _BODYPtr(A5),A0        ; Pointer to datas (in fast ram/hopefully)
  8017.     add.l    D5,A0            ; Fetch datas that aren't worked out yet
  8018.     movea.l    _AudioBuffer(A5),A1    ; Chip-ram buffer (28 kbyte)
  8019.     mulu.w    #14*1024,D0        ; Two which part we refer (14 kbyte)
  8020.     adda.l    D0,A1
  8021.     move.l    #14*1024,D0        ; Size: 14 kbyte to copy
  8022.     movea.l    _SysBase(A5),A6
  8023.     jsr    _LVOCopyMemQuick(A6)
  8024.     move.l    #14*1024,D0        ; Size to play: 14 kbyte
  8025.     add.l    D0,D5            ; Amount datas that worked out already
  8026.     rts
  8027.  
  8028. .overload
  8029.     add.l    #14*1024,D6        ; Get rest of datas
  8030.  
  8031.     movea.l    _BODYPtr(A5),A0
  8032.     add.l    D5,A0
  8033.     movea.l    _AudioBuffer(A5),A1
  8034.     mulu.w    #14*1024,D0        ; To which chip-ram buffer we refer ?
  8035.     adda.l    D0,A1
  8036.     move.l    D6,D0
  8037.     movea.l    _SysBase(A5),A6
  8038.     jsr    _LVOCopyMem(A6)
  8039.     add.l    D6,D5
  8040.     move.l    D6,D0            ; Size to play
  8041.     moveq    #0,D6            ; No more datas
  8042.     rts
  8043.  
  8044. * -------- React to user input (while something is played)-------- *
  8045. 4$
  8046.     movea.l    _WindowPtr(A5),A0
  8047.     movea.l    wd_UserPort(A0),A0
  8048.     movea.l    _SysBase(A5),A6
  8049.     jsr    _LVOGetMsg(A6)
  8050.     tst.l    D0
  8051.     beq.s    7$
  8052.  
  8053.     movea.l    D0,A1
  8054.     move.l    20(A1),D0        ; im_Class
  8055.     move.w    24(A1),D1        ; im_Code
  8056.     move.l    28(A1),_IAddr(A5)
  8057.  
  8058.     movem.l    D0-D1,-(sp)
  8059.     jsr    _LVOReplyMsg(A6)
  8060.     movem.l    (sp)+,D0-D1
  8061.  
  8062.     cmpi.l    #$200,D0        ; CLOSEWINDOW ?
  8063.     bne.s    5$
  8064.     movem.l    (sp)+,D2-D7
  8065.     bsr.s    .WaitAction
  8066.     bra.w    _End            ; If so...
  8067. 5$
  8068.     cmpi.l    #$40,D0            ; GADGETUP
  8069.     bne.s    6$
  8070.     movea.l    _IAddr(A5),A0
  8071.     cmpi.w    #3,gg_GadgetID(A0)
  8072.     bne.s    7$
  8073.     bsr.s    .WaitAction
  8074.     bra.w    2$            ; Redo from start!
  8075. 6$
  8076.     cmpi.l    #$400,D0        ; RAWKEY?
  8077.     bne.s    7$            ; If not...
  8078.     cmpi.w    #L_Key,D1
  8079.     bne.s    7$
  8080.     movem.l    (sp)+,D2-D7
  8081.     bsr.s    .WaitAction
  8082.     bra.w    _LoadNew
  8083. 7$
  8084.     bsr.s    .WaitAction
  8085.     tst.l    D3
  8086.     beq.w    .InJump            ; Jump where we can continue
  8087.     bra.w    3$
  8088.  
  8089. * -------- Ignore multiple intuition messages and wait for the IO to complete -------- *
  8090. .WaitAction
  8091.     movea.l    _WindowPtr(A5),A0
  8092.     movea.l    wd_UserPort(A0),A0
  8093.     movea.l    _SysBase(A5),A6
  8094.     jsr    _LVOGetMsg(A6)
  8095.     tst.l    D0
  8096.     beq.s    8$
  8097.     movea.l    D0,A1
  8098.     jsr    _LVOReplyMsg(A6)
  8099.     bra.s    .WaitAction
  8100. 8$
  8101.     movea.l    _IOAudio(A5),A1
  8102.     jsr    _LVOWaitIO(A6)
  8103.     rts
  8104.  
  8105. *************************************************
  8106. *
  8107. ** Load Audio File
  8108. *
  8109.  
  8110. _LoadAudio
  8111.     lea    _8SVXTxt(pc),A0
  8112.     bsr.w    _DisplayError
  8113.     tst.l    D0
  8114.     beq.w    _BinaryFile
  8115.  
  8116.     bsr.s    _GetAudioSettings
  8117.  
  8118.     moveq    #-50,D0
  8119.     bsr.w    _AllocIOAudioA
  8120.     move.l    D0,_IOAudio(A5)
  8121.     beq.s    .error
  8122.  
  8123.     bsr.w    _DisplayAudioGadget
  8124.  
  8125.     addq.l    #4,sp            ; Remove "bsr.w _CheckFile"
  8126.     bra.w    _Loop
  8127.  
  8128. .error
  8129.     bsr.w    _FreeAudio
  8130.     bsr.w    _FreeFile
  8131.     lea    _8SVXErrTxt(pc),A0
  8132.     bsr.w    _DisplayError
  8133.     addq.l    #4,sp
  8134.     bra.w    _Loop
  8135.  
  8136.  
  8137. _GetAudioSettings
  8138.     bsr.w    _CheckFibDelta
  8139.     tst.l    D0
  8140.     beq.w    .error
  8141.  
  8142.     move.l    #28*1024,D0
  8143.     move.l    D0,_AudioBufferSize(A5)
  8144.     move.l    #MEMF_CLEAR|MEMF_CHIP|MEMF_PUBLIC,D1
  8145.     movea.l    _SysBase(A5),A6
  8146.     jsr    _LVOAllocMem(A6)
  8147.     move.l    D0,_AudioBuffer(A5)
  8148.     beq.w    .error
  8149.  
  8150.     movea.l    _TextPtr(A5),A0        ; Address datas
  8151.     move.l    _FileSize(A5),D0    ; Size datas
  8152.     cmpi.w    #'FO',(A0)
  8153.     beq.s    .startScan
  8154.     addq.l    #2,A0
  8155.     subq.l    #2,D0
  8156. .startScan
  8157.     lea    12(A0),A0
  8158.     subi.l    #12,D0
  8159.     move.l    #'VHDR',D1
  8160.     bsr.w    .getChunk
  8161.     tst.l    D1
  8162.     beq.s    .error
  8163. .scanBody
  8164.     move.l    A0,_VHDRPtr(A5)
  8165.     addq.l    #8,_VHDRPtr(A5)
  8166.     move.l    #'BODY',D1
  8167.     bsr.w    .getChunk
  8168.     tst.l    D1
  8169.     beq.s    .error
  8170. .gotBody
  8171.     move.l    A0,_BODYPtr(A5)
  8172.     addq.l    #8,_BODYPtr(A5)
  8173.     move.l    4(A0),_BODYSize(A5)
  8174.  
  8175.     move.l    _VHDRPtr(A5),A0
  8176.     moveq    #0,D1
  8177.     move.w    12(A0),D1
  8178.  
  8179. * Hertz to Period, the slow way...
  8180.     move.l    #100000000,D0
  8181. *    move.l    D1,D1            ; Hertz
  8182.     moveq    #28,D2
  8183.     mulu.w    D2,D1
  8184.  
  8185.     moveq    #-1,D2
  8186. .divlong
  8187.     addq.l    #1,D2
  8188.     sub.l    D1,D0
  8189.     bcc.s    .divlong
  8190.  
  8191.     move.l    D2,_AudioPeriod(A5)
  8192.  
  8193.     move.l    _BODYSize(A5),D0
  8194.     move.l    _AudioBufferSize(A5),D1
  8195.     cmp.l    D0,D1
  8196.     bhi.s    .cpy
  8197.  
  8198.     move.l    _BODYPtr(A5),A0
  8199.     move.l    _AudioBuffer(A5),A1
  8200.     move.l    #28*1024,D0
  8201.     movea.l    _SysBase(A5),A6
  8202.     jsr    _LVOCopyMemQuick(A6)
  8203.     rts
  8204.  
  8205. .cpy
  8206.     move.l    _BODYPtr(A5),A0
  8207.     move.l    _AudioBuffer(A5),A1
  8208.     move.l    _BODYSize(A5),D0
  8209.     movea.l    _SysBase(A5),A6
  8210.     jsr    _LVOCopyMem(A6)
  8211.     rts
  8212.  
  8213. .error
  8214.     lea    _8SVXErrTxt(pc),A0
  8215.     bsr.w    _DisplayError
  8216.     bsr.w    _FreeFile
  8217.     bsr.w    _FreeAudio
  8218.     addq.l    #8,sp            ; Remove "bsr.w _CheckFile" and "bsr.s GetAudioSettings"
  8219.     bra.w    _Loop
  8220.  
  8221. .getChunk
  8222.     cmp.l    (A0),D1
  8223.     beq.s    .chunkFound
  8224. .getNextChunk
  8225.     move.l    4(A0),D2        ; Size of this chunk
  8226.     addq.l    #1,D2
  8227.     andi.l    #-2,D2            ; In case it was odd, it's now even
  8228.     addq.l    #8,D2            ; Skip chunk name and its size entry
  8229.     sub.l    D2,D0            ; A rest left?
  8230.     beq.s    .chunkError
  8231.     bmi.s    .chunkError
  8232.     lea    0(A0,D2),A0        ; Point to next chunk name
  8233.     cmp.l    (A0),D1            ; Compare
  8234.     bne.s    .getNextChunk
  8235. .chunkFound
  8236.     rts
  8237. .chunkError
  8238.     moveq    #0,D1
  8239.     rts
  8240.  
  8241. _FindVHDR
  8242.     move.l    D0,D2            ; Size file
  8243.     subi.l    #12,D2
  8244.     lea    12(A0),A1        ; Chunk name
  8245. .restart
  8246.     move.l    4(A1),D1        ; Chunk size
  8247.     addq.l    #1,D1
  8248.     andi.l    #-2,D1            ; Even chunk size
  8249.     addq.l    #8,D1            ; Chunk name + sizeof(chunk size var) (4 bytes)
  8250.     sub.l    D1,D2
  8251.     beq.s    .notfound
  8252.     bmi.s    .notfound
  8253.     lea    0(A1,D1),A1        ; Next chunk name
  8254.     cmpi.l    #'VHDR',(A1)
  8255.     bne.s    .restart
  8256. .found
  8257.     addq.l    #8,A1
  8258.     bra.s    _TestIfFibDeltaComp
  8259. .notfound
  8260.     lea    _8SVXErrTxt(pc),A0
  8261.     bsr.w    _DisplayError
  8262.     bsr.w    _FreeFile
  8263.     lea    12(sp),sp            ; Remove "bsr.w _CheckFile" and "bsr.s GetAudioSettings" and "bsr.s _CheckFibDelta"
  8264.     bra.w    _Loop
  8265.  
  8266.  
  8267. _FreeAudio
  8268.     tst.l    _AudioBuffer(A5)
  8269.     beq.s    1$
  8270.     movea.l    _AudioBuffer(A5),A1
  8271.     move.l    _AudioBufferSize(A5),D0
  8272.     movea.l    _SysBase(A5),A6
  8273.     jsr    _LVOFreeMem(A6)
  8274.     clr.l    _AudioBuffer(A5)
  8275. 1$
  8276.     move.l    _IOAudio(A5),D0
  8277.     beq.s    2$
  8278.     movea.l    D0,A0    
  8279.     bsr.w    _FreeIOAudioA
  8280.     clr.l    _IOAudio(A5)
  8281. 2$
  8282.     bsr.w    _RemoveAudioGadget
  8283.     rts
  8284.  
  8285. _CheckFibDelta
  8286.     movem.l    D2-D4/A2-A4,-(sp)
  8287.     move.l    _FileSize(A5),D0
  8288.     movea.l    _TextPtr(A5),A0
  8289.     addq.l    #2,A0            ; Overread
  8290.     subq.l    #2,D0
  8291.  
  8292.     cmpi.l    #'FORM',(A0)        ; IFF?
  8293.     bne.s    _CheckFibEnd
  8294.     cmpi.l    #'8SVX',8(A0)        ; 8SVX?
  8295.     bne.s    _CheckFibEnd
  8296.     cmpi.l    #'VHDR',12(A0)        ; IFF?
  8297.     bne.w    _FindVHDR
  8298.     lea    20(A0),A1
  8299. _TestIfFibDeltaComp
  8300.     cmpi.b    #1,15(A1)
  8301.     bne.s    _CheckFibEndOk
  8302.     bra.s    _StartUnpack
  8303. _CheckFibEnd
  8304.     moveq    #0,D0
  8305.     movem.l    (sp)+,D2-D4/A2-A4
  8306.     rts
  8307. _CheckFibEndOk
  8308.     moveq    #-1,D0
  8309.     movem.l    (sp)+,D2-D4/A2-A4
  8310.     rts
  8311.  
  8312.  
  8313. _StartUnpack
  8314.     move.l    D0,D1
  8315.     movea.l    A0,A1
  8316.     moveq    #0,D2
  8317. 1$
  8318.     subq.l    #2,D1
  8319.     bls.s    _CheckFibEnd
  8320.     addq.l    #2,D2
  8321.     cmpi.w    #'BO',(A1)+
  8322.     bne.s    1$
  8323.     addq.l    #6,D2            ; plus 'BODY' text ('DY' plus room for 1 longword)
  8324.     move.l    2(A1),D3        ; Length Body
  8325.     addq.l    #6,A1            ; Ignore 'DY' plus length
  8326.  
  8327.     movea.l    A0,A2            ; IFF-Header
  8328.     movea.l    A1,A3            ; Compressed datas
  8329. *    A2 pointer to IFF header
  8330. *    A3 pointer to compressed datas
  8331. *    D2 length IFF header
  8332. *    D3 length sample (compressed) datas
  8333.     move.l    D2,D0
  8334.     add.l    D3,D0
  8335.     add.l    D3,D0            ; Length new IFF-file! (2* D3 !!!)
  8336.     addq.l    #3,D0            ; + 7 - 4 = 3 ( because of 2*(n-2) ! )
  8337.     andi.l    #-8,D0
  8338.     move.l    D0,D4            ; New IFF-file length
  8339.     move.l    #MEMF_CLEAR|MEMF_PUBLIC,D1
  8340.     movea.l    4.w,A6
  8341.     jsr    _LVOAllocMem(A6)
  8342.     tst.l    D0
  8343.     beq.s    _CheckFibEnd
  8344.     movea.l    D0,A4
  8345. *    A2 pointer to IFF header
  8346. *    A3 pointer to compressed datas
  8347. *    A4 pointer to allocated memory
  8348. *    D2 length IFF header
  8349. *    D3 length sample (compressed) datas
  8350. *    D4 size allocated memory
  8351.     move.l    A2,A0
  8352.     movea.l    A4,A1
  8353.     move.l    D2,D0
  8354.     subq.l    #4,D0            ; Minus length of 'BODY' length set
  8355.     jsr    _LVOCopyMem(A6)        ; Copy IFF-Header
  8356.  
  8357.     add.l    D3,4(A4)        ; Add double size of datas of FORM-chunk
  8358.     subq.l    #4,4(A4)
  8359.     clr.b    35(A4)            ; Erase comression sign
  8360.  
  8361.     move.l    D3,D0            ; length datas
  8362.     movea.l    A3,A0            ; Source datas
  8363.     movea.l    A4,A1
  8364.     add.l    D2,A1            ; Destination (pointer right behind IFF header!)
  8365.     move.l    D3,D1
  8366.     add.l    D1,D1            ; New length of BODY = length * 2
  8367.     subq.l    #4,D1            ; Because of 2*(n-2) !
  8368.     move.l    D1,-4(A1)        ; Set length
  8369.  
  8370.     bsr.s    _FibDeltaUnpack        ; Unpack datas
  8371.  
  8372.     bsr.w    _FreeFile
  8373.  
  8374.     move.l    D4,_BufferSize(A5)
  8375.     move.l    D2,D0
  8376.     add.l    D3,D0
  8377.     add.l    D3,D0            ; 2 * D3!!!!
  8378.     subq.l    #4,D0
  8379.     move.l    D0,_FileSize(A5)
  8380.     move.l    A4,_TextPtr(A5)
  8381.     bra.w    _CheckFibEndOk
  8382.  
  8383. ******************************************************************************
  8384. *
  8385. * FibDelatUnpack
  8386. *
  8387. * Based on Steve Hayes' DUnpack for his Fibonacci Delta compression algorythm.
  8388. *
  8389. * Converted to assembly by Jörg van de Loo
  8390. *               Hövel 15
  8391. *               47559 Kranenburg
  8392. *               Germany
  8393. *
  8394.  
  8395. _FibDeltaUnpack    ; (numdatas,source,destination)(D0,A0,A1)
  8396.     movem.l    D2-D5/A2,-(sp)
  8397.  
  8398.     subq.l    #2,D0        ; numdatas-2 ( n - 2 )
  8399.     moveq    #0,D1
  8400.     move.b    1(A0),D1    ; x = source[1] = initial value!
  8401.     addq.l    #2,A0        ; source + 2
  8402. *    movea.l    A1,A1        ; destination
  8403. *
  8404. ** (rawdatas-2,data,source+2,destination)(D0,D1,A0,A1)
  8405. *
  8406.     move.l    D0,D2        ; maximum datas =
  8407.     add.l    D2,D2        ; doubled ( 2*(n-2) )
  8408.     moveq    #0,D3        ; internal counter ( i )
  8409.     moveq    #0,D5        ; Dummy
  8410.     lea    __DeltaTable(pc),A2 ; Table of deltas to add to value x
  8411.     bra.s    .checkend
  8412. .next
  8413.     move.l    D3,D4        ; counter
  8414.     lsr.l    #1,D4        ; counter / 2
  8415.     move.b    0(A0,D4.l),D5    ; d = source[i]
  8416.     btst    #0,D3        ; even or odd, i.e. low nibble or high nibble to affect
  8417.     beq.s    .highnibble
  8418. .lownibble
  8419.     andi.b    #15,D5        ; d &= 15 (only low nibble (4 bits))
  8420.     bra.s    .store
  8421. .highnibble
  8422.     lsr.b    #4,D5        ; d / 16 (high nibble (4 bits) on low nibble's position)
  8423. .store
  8424.     move.b    0(A2,D5.w),D4    ; Delta out of table
  8425.     add.b    D4,D1        ; x += Delta
  8426.     move.b    D1,0(A1,D3.l)    ; write data value (uncompressed now!)
  8427.     addq.l    #1,D3        ; i ++
  8428.  
  8429. .checkend
  8430.     cmp.l    D3,D2
  8431.     bhi.s    .next
  8432.  
  8433.     movem.l    (sp)+,D2-D5/A2
  8434.     move.b    D1,D0        ; return x
  8435.     rts
  8436.  
  8437. __DeltaTable
  8438.     dc.b    -34,-21,-13,-8,-5,-3,-2,-1,0,1,2,3,5,8,13,21
  8439.  
  8440.  
  8441. *************************************************
  8442. *
  8443. ** Init Audio Hit Gadget
  8444. *
  8445. _DisplayAudioGadget
  8446.     movem.l    D2/A2-A3,-(sp)
  8447.  
  8448.     lea    _Gad3(A5),A2
  8449.     clr.l    (A2)
  8450.     move.w    #8,gg_LeftEdge(A2)
  8451.     move.w    #6,gg_TopEdge(A2)
  8452.     move.w    #45,gg_Width(A2)
  8453.     move.w    #28,gg_Height(A2)
  8454.     move.w    #GADGHIMAGE|GADGIMAGE,gg_Flags(A2)
  8455.     move.w    #BoolGadFlags,gg_Activation(A2)
  8456.     move.w    #BOOLGADGET,gg_GadgetType(A2)
  8457.     move.w    #3,gg_GadgetID(A2)
  8458.  
  8459.     lea    _Image.3(pc),A0
  8460.     lea    _Image.4(pc),A1
  8461.  
  8462.     move.l    A0,gg_GadgetRender(A2)
  8463.     move.l    A1,gg_SelectRender(A2)
  8464.  
  8465.     lea    _startup(pc),A0        ; First instruction of Viewer (startup-code)
  8466.     subq.l    #4,A0            ; Pointer to BPTR next hunk
  8467.     movea.l    (A0),A0            ; BPTR NextHunk
  8468.     adda.l    A0,A0
  8469.     adda.l    A0,A0            ; APTR NextHunk
  8470.     addq.l    #4,A0            ; Section Chip (_Gad.1, size 190 bytes)
  8471.     lea    380(A0),A0        ; Skip both images (each 190 bytes)
  8472.     lea    336(A0),A1        ; Pointer to Select Audio Image
  8473.     lea    _Image.3(pc),A2
  8474.     lea    _Image.4(pc),A3
  8475.     move.l    A0,ig_ImageData(A2)
  8476.     move.l    A1,ig_ImageData(A3)
  8477.  
  8478.     movea.l    _WindowPtr(A5),A0    ; Window
  8479.     movea.l    wd_RPort(A0),A3        ; ^RastPortPtr
  8480.     lea    _Gad3(A5),A1        ; Audio gadget
  8481.     moveq    #0,D0            ; Begin with number zero
  8482.     moveq    #-1,D1            ; All gadgets
  8483.     moveq    #0,D2
  8484.     movea.l    D2,A2            ; No requester
  8485.     move.l    _IntuitionBase(A5),A6
  8486.     jsr    _LVOAddGList(A6)    ; Set gadgets to window
  8487.  
  8488.     lea    _Gad3(A5),A0        ; Gadgets
  8489.     movea.l    _WindowPtr(A5),A1    ; Window
  8490.     moveq    #0,D2
  8491.     movea.l    D2,A2            ; No requester
  8492.     jsr    _LVORefreshGList(A6)    ; Draw gadgets
  8493.  
  8494.     st.b    _AudGadget(A5)
  8495.  
  8496.     movem.l    (sp)+,D2/A2-A3
  8497.     rts
  8498.  
  8499. _RemoveAudioGadget
  8500.     tst.b    _AudGadget(A5)
  8501.     beq.s    1$
  8502.     movea.l    _WindowPtr(A5),A0
  8503.     lea    _Gad3(A5),A1
  8504.     moveq    #1,D0
  8505.     movea.l    _IntuitionBase(A5),A6
  8506.     jsr    _LVORemoveGList(A6)
  8507.  
  8508.     clr.b    _AudGadget(A5)
  8509. 1$
  8510.     rts
  8511.  
  8512. ********************************************************
  8513. *
  8514. *  (C) 1994 J.v.d.Loo
  8515. *
  8516. *  AA-support routines
  8517. *
  8518. *  Decompressor and 32 bit gun colour converter
  8519. *
  8520. *  Taken out of BitMapSaver
  8521. *
  8522. * Inputs: none
  8523. * Results: D0 = 1 when all went ok
  8524. *
  8525.  
  8526. * ------------------------------------------------------ *
  8527. * This is an fully decrompress routine for images of 64bit boundary (modulo).
  8528.  
  8529. _Convert
  8530.     movem.l    D2-D6/A2-A4,-(sp)
  8531.  
  8532.     bsr.w    _Init24BitPal        ; Grey colour image setup when no palette set...
  8533.  
  8534.     movea.l    _WindowPtr(A5),A0    ; Window
  8535.     movea.l    wd_RPort(A0),A0        ; Its rastport
  8536.     movea.l    rp_BitMap(A0),A0    ; BitMap being used
  8537.     moveq    #BMA_FLAGS,D1        ; Ask for flags being used
  8538.     movea.l    _GfxBase(A5),A6
  8539.     cmpi.w    #38,LIB_VERSION(A6)    ; OS 3 required for this check
  8540.     bls.s    .std            ; If not available, treat it as the original GFX device
  8541. *                      is used...
  8542.     jsr    _LVOGetBitMapAttr(A6)
  8543.     andi.l    #BMF_STANDARD,D0    ; Standard bitmap or one created by a 3rd graphic device?
  8544.     beq.s    .alien
  8545. .std
  8546.     move.l    #MEMF_CHIP,_TypeOfMem(A5)    ; BitMap forced to CHIP-RAM (standard AMIGA device)
  8547.     bra.s    .doconvert
  8548. .alien
  8549.     move.l    #0,_TypeOfMem(A5)    ; BitMap forced to FAST-RAM (3rd party GFX device)
  8550.  
  8551. .doconvert
  8552.     movea.l    _SourceFilePtr(A5),A0    ; Address datas
  8553.     cmpi.l    #'FORM',(A0)+        ; IFF ?
  8554.     bne.w    .finish_1
  8555.     addq.l    #4,A0            ; Length IFF-file!?!?
  8556.     cmpi.l    #'ACBM',(A0)
  8557.     bne.s    .check4ILBM
  8558.     addq.l    #4,A0
  8559.     bra.s    .okType
  8560. .check4ILBM
  8561.     cmpi.l    #'ILBM',(A0)+        ; Picture?
  8562.     bne.w    .finish_1
  8563. .okType
  8564.     move.l    _SourceFileSize(A5),D4
  8565.     subi.l    #12,D4            ; Length datas - length header
  8566. .searchChunks
  8567.     subq.l    #4,D4            ; Length datas -4
  8568.     beq.w    .finish_1        ; If end reached
  8569.     bmi.w    .finish_1
  8570.     move.l    (A0)+,D3        ; Chunk-name
  8571.     cmpi.l    #'BMHD',D3        ; Bitmap-header?
  8572.     beq.s    .foundBMHD
  8573.     cmpi.l    #'CAMG',D3        ; ViewPort-display?
  8574.     beq.w    .foundCAMG
  8575.     cmpi.l    #'CMAP',D3        ; Colour-map?
  8576.     beq.w    .foundCMAP
  8577.     cmpi.l    #'BODY',D3        ; Datas?
  8578.     beq.w    .foundBODY
  8579.     cmpi.l    #'ABIT',D3        ; Amiga Bitplane Datas?
  8580.     beq.w    .foundABIT 
  8581. .unknownChunk
  8582.     subq.l    #4,D4            ; Datas -4
  8583.     move.l    (A0)+,D0        ; Length of this chunk
  8584.     addq.l    #1,D0
  8585.     andi.l    #-2,D0            ; Through 2 divisible
  8586.     sub.l    D0,D4            ; Datas minus (over)readed entries
  8587.     lea    0(A0,D0.w),A0        ; New address
  8588.     bra.s    .searchChunks
  8589.  
  8590. .foundBMHD
  8591.     subq.l    #4,D4            ; Datas -4
  8592.     move.l    (A0)+,D0        ; Save number entries
  8593.     lea    _Width(A5),A1        ; Address data-array
  8594.     moveq    #0,D1
  8595.     move.w    (A0),D1            ; Get width
  8596.     move.l    D1,_RealIWidth(A5)    ; Non aligned width of image
  8597.     addi.l    #15,D1
  8598.     andi.l    #-16,D1
  8599.     move.l    D1,_ImageWidth(A5)    ; Save dafault width (aligned)
  8600.     addi.l    #63,D1
  8601.     andi.l    #-64,D1            ; Set up to BURST-FETCH mode, needed for AGA
  8602.     move.w    D1,(A1)            ; Save width
  8603.     move.w    2(A0),2(A1)        ; Height
  8604.     move.w    4(A0),4(A1)        ; X-Position
  8605.     move.w    6(A0),6(A1)        ; Y-Position
  8606.     move.b    8(A0),8(A1)        ; Depth
  8607.     move.b    9(A0),9(A1)        ; Masking-type
  8608.     move.b    10(A0),10(A1)        ; compression-mode
  8609.     move.b    11(A0),11(A1)        ; Unused
  8610.     move.w    12(A0),12(A1)        ; Transparent colour
  8611.     move.b    14(A0),14(A1)        ; X-aspect
  8612.     move.b    15(A0),15(A1)        ; Y-aspect
  8613.     move.w    16(A0),16(A1)        ; Page width
  8614.     move.w    18(A0),18(A1)        ; Page height
  8615.     lea    (A0,D0.w),A0        ; Overread header
  8616.     sub.l    D0,D4            ; Length Datas minus entries
  8617.     bra.w    .searchChunks
  8618.  
  8619. .foundCAMG
  8620.     subq.l    #4,D4            ; Datas -4
  8621.     move.l    (A0)+,D0        ; Length
  8622.     addq.l    #1,D0
  8623.     andi.l    #-2,D0            ; Through 2 divisible
  8624.     move.l    (A0),_ViewPortMod(A5)    ; ViewPort mode
  8625.     andi.l    #$FFFF9ABD,_ViewPortMod(A5)    ; means:
  8626. *    bclr    #1,D0            ; no genlocVideo
  8627. *    bclr    #6,D0            ; no pfba
  8628. *    bclr    #8,D0            ; no genlocAudio
  8629. *    bclr    #10,D0            ; no dualpf
  8630. *    bclr    #13,D0            ; no vpHide
  8631. *    bclr    #14,D0            ; no sprites
  8632.  
  8633.     lea    0(A0,D0.w),A0        ; Skip unused
  8634.     sub.l    D0,D4            ; Length datas
  8635.     bra.w    .searchChunks
  8636.  
  8637. .foundCMAP
  8638.     subq.l    #4,D4            ; Datas -4
  8639.     move.l    (A0)+,D0        ; Entry length (ever through 2 divisible!!!)
  8640.     move.l    D0,-(sp)        ; Remember
  8641.     divu.w    #3,D0            ; /3
  8642.     andi.l    #$FFFF,D0
  8643.     move.l    D0,_CMapNumEntries(A5)    ; = number of words of Colourmap
  8644.     lea    _Colourmap(A5),A1    ; Address colour-array
  8645.     move.l    A0,_RGB32Values(A5)
  8646.     move.l    A0,-(sp)
  8647.     cmpi.l    #256*3,D0
  8648.     bhi.s    .getRGB32
  8649.  
  8650. .getRGB
  8651.     moveq    #0,D1
  8652.     move.b    (A0)+,D1        ; R-value
  8653.     andi.w    #$F0,D1
  8654.     lsl.w    #4,D1            ; Clear Half-byte position (G-value)
  8655.     move.b    (A0)+,D2        ; G-value
  8656.     andi.w    #$F0,D2            ; Mask it out
  8657.     or.w    D2,D1            ; Store G-value
  8658.     move.b    (A0)+,D2        ; B-value
  8659.     andi.w    #$F0,D2
  8660.     lsr.b    #4,D2            ; Half-byte position
  8661.     or.w    D2,D1            ; D1 = RGB-word
  8662.     move.w    D1,(A1)+        ; Store RGB-word
  8663.     subq.l    #1,D0
  8664.     bgt.s    .getRGB
  8665.  
  8666. .getRGB32
  8667.     move.l    _CMapNumEntries(A5),D0
  8668.     movea.l    _RGB32Values(A5),A0
  8669.     lea    _RGB32Colours(A5),A1
  8670.     bsr.w    _RGBtoRGB32
  8671.     movea.l    (sp)+,A0
  8672.     move.l    (sp)+,D0
  8673.     addq.l    #1,D0
  8674.     andi.l    #-2,D0    
  8675.     sub.l    D0,D4            ; Datas minus (over)readed entries
  8676.     lea    0(A0,D0.l),A0        ; New address
  8677.     bra.w    .searchChunks
  8678.  
  8679. .foundBODY
  8680.     cmpi.b    #1,_Compresstyp(A5)
  8681.     bhi.w    .finish_3
  8682.     tst.b    _Masking(A5)
  8683.     beq.s    .go
  8684.     move.b    _Masking(A5),D0
  8685.     btst.l    #0,D0
  8686.     beq.s    .go
  8687.     tst.b    _NoWarnFlag(A5)
  8688.     bne.s    .go
  8689.     movem.l    A0-A1,-(sp)
  8690.     lea    _WarnMaskingTxt(pc),A0    ; MASKING = DATA of 1st line for all bitplanes + masking line
  8691.     bsr.w    _DisplayError        ;           DATA of 2nd line for all bitplanes + masking line
  8692.     move.l    #5,_errno(A5)        ;           DATA of 3rd line for all bitplanes + masking line
  8693.     movem.l    (sp)+,A0-A1        ;           ........... and so on
  8694. .go
  8695.     lea    _BitmapStruc(A5),A2    ; Address bitmap-structure
  8696.     moveq    #23,D0
  8697.     addq.l    #8,A2
  8698. .clear
  8699.     clr.l    (A2)+            ; Clear all 24 bitplane pointers
  8700.     subq.w    #1,D0
  8701.     bcc.s    .clear
  8702.  
  8703.     lea    _BitmapStruc(A5),A2    ; Address bitmap-structure
  8704.     moveq    #0,D0            ; Clear it
  8705.     move.w    _Width(A5),D0        ; Pixel width
  8706.     lsr.w    #3,D0            ; /8 = bytes
  8707.     move.w    D0,(A2)+        ; Bytes per row
  8708.     move.w    _Height(A5),(A2)+    ; Height graphic
  8709.     move.b    _Depth(A5),1(A2)    ; Number of bitplanes
  8710.  
  8711. *
  8712. ** Allocate needed bitplanes (all in once).
  8713. ** <- D0 still holds number of bytes per line.
  8714. *
  8715.     move.l    A0,-(sp)        ; Save current address
  8716.     movea.l    _SysBase(A5),A6        ; Base Exec
  8717.     mulu.w    _Height(A5),D0        ; = size of one bitplane
  8718.     move.l    D0,D2            ; to D2
  8719.  
  8720.     moveq    #0,D1            ; Clear it
  8721.     move.b    _Depth(A5),D1        ; Number of bitplanes
  8722.  
  8723. *
  8724. ** For those bug I searched 3 days... - so stupid I'm.
  8725. ** I use normally images up to 736*566 pixel, that means that one plane is
  8726. ** 736/8*566 pixel = 52072 bytes large, this size fits in a word,
  8727. ** so "mulu" #8,Dx did not cause trouble (for 8 bitplanes).
  8728. ** While testing "BitMapSaver" with an images of 960*724 pixel width, my 
  8729. ** A4000 crashed - no guru but no input was furthermore possible!
  8730. ** Today I got it. 960/8 = 120 = fits in a word, mulu #724,120 = ? -
  8731. ** 86880 bytes = longword!!! Until that point all went ok, but after
  8732. ** mulu.w #8,86880 (8 bitplanes) the value was not as you may expect 695040
  8733. ** instead of it 170752 was returned. So the images was loaded to unallocated
  8734. ** memory, "Amiga hang up".
  8735. ** The crash occurred each time when DOS-function "Write" was called - and
  8736. ** because there is a bug in the v39 ROM of the dos.library, I thought this
  8737. ** was a bug of it, too.
  8738. ** [( v39 bug: After a read/write error occures and the "Write"-routine returns
  8739. **    to the program, the baseregister A6 does not contain the DOSBase any more.)]
  8740. ** But further:
  8741. ** The mistake I made was to multiply a longword with a word - what is not
  8742. ** possible with the 68000 instruction "mulu.w". I know this, but I never
  8743. ** cared in this routine about it....
  8744. ** But... here is the solution...
  8745. *
  8746.  
  8747.     moveq    #0,D0            ; Zero !!!
  8748.     bra.s    .x1
  8749. .mul
  8750.     add.l    D2,D0            ; Longword multiply!!!
  8751. .x1
  8752.     dbf    D1,.mul
  8753.  
  8754.     move.l    D0,_AllPlaneSize(A5)    ; Save size of all bitplanes
  8755.     move.l    _TypeOfMem(A5),D1    ; Set as CHIP or FAST
  8756.     ori.l    #MEMF_CLEAR,D1        ; Requirements
  8757.     jsr    _LVOAllocMem(A6)    ; Mem demand
  8758.     move.l    D0,_Bitplane(A5)    ; Save memory address
  8759.     beq.w    .finish_2        ; If error
  8760.  
  8761.     lea    _BitmapStruc(A5),A0    ; Address bitmap-structure
  8762.     moveq    #0,D1            ; Clear it
  8763.     move.w    (A0),D1            ; Bytes per row
  8764.     mulu.w    2(A0),D1        ; Number bytes of one bitplane
  8765.  
  8766.     moveq    #0,D2
  8767.     move.b    5(A0),D2        ; Number of bitplanes
  8768.     addq.l    #8,A0            ; Address constant for first plane
  8769.  
  8770.     movea.l    D0,A1            ; Address memory
  8771. .StoreBPPtr
  8772.     move.l    A1,(A0)+        ; Set address of bitplane to constant
  8773.     add.l    D1,A1            ; Get next bitplane's memory address
  8774.     subq.b    #1,D2            ; Decrease number of bitplanes
  8775.     bne.s    .StoreBPPtr        ; If not all are set yet...
  8776.  
  8777. *
  8778. ** Do it normal.
  8779. *
  8780.     movea.l    (sp)+,A0        ; Get back current address    
  8781.  
  8782.     move.l    D4,D2            ; Size in bytes of datas
  8783.  
  8784.     moveq    #0,D0            ; Initialiize them with NULL for first time
  8785.     move.l    D0,D1
  8786.     move.l    D1,D3
  8787.     move.l    D3,D4
  8788.     move.l    D4,D5            ; Linecounter
  8789.  
  8790.     addq.l    #4,A0
  8791.     subq.l    #4,D2
  8792.  
  8793.     lea    _BitmapStruc(A5),A2    ; Address bitmap-structure
  8794.     addq.l    #8,A2            ; Address pointer to first bitplane
  8795.  
  8796.     move.w    _Width(A5),D3        ; Pixelwidth of image
  8797.     lsr.w    #3,D3            ; in bytes
  8798.     move.b    _Depth(A5),D4        ; Number of planes
  8799.  
  8800.     tst.b    _Compresstyp(A5)
  8801.     bne.s    .Decompress        ; If compressed...
  8802.  
  8803.     movem.l    D0-D1/A0-A1,-(sp)
  8804.     tst.b    _NoWarnFlag(A5)
  8805.     bne.s    .NoWarn.1
  8806.     lea    _WarnUncompressedTxt(pc),A0
  8807.     bsr.w    _DisplayError
  8808.     move.l    #5,_errno(A5)
  8809. .NoWarn.1
  8810.     movem.l    (sp)+,D0-D1/A0-A1
  8811.  
  8812.     bra.w    .StoreUnpacked
  8813.  
  8814. .Decompress
  8815.     moveq    #0,D6            ; Bitplanecounter
  8816. .Decompressing
  8817.     lsl.w    #2,D6            ; Bitplanecounter * 4 = longword adjustment
  8818.     movea.l    0(A2,D6.w),A3        ; Current bitplane
  8819.     lsr.w    #2,D6            ; Normal
  8820. * Instead of the last three lines you can write
  8821. *    movea.l    0(A2,D6.w*4),A3
  8822. * if you have a turboboard.
  8823.  
  8824.     move.w    D3,D0            ; Bytes per line
  8825.     mulu.w    D5,D0            ; mutilply with current line
  8826.     lea    0(A3,D0.l),A3        ; Startoffset to A3
  8827.     movea.l    A3,A4            ; Address plane(x) to A4
  8828.     move.l    _ImageWidth(A5),D0    ; Real pixel width of image
  8829.     lsr.w    #3,D0            ; in bytes
  8830.     lea    0(A4,D0.w),A4        ; == End of line
  8831. .CheckOperation
  8832.     subq.l    #1,D2            ; Data counter
  8833.     bmi.w    .IncorrectSize
  8834.     moveq    #0,D0
  8835.     move.b    (A0)+,D0
  8836.     cmpi.b    #-128,D0        ; #-128 = no operation
  8837.     beq.s    .NoOperation
  8838.     cmpi.b    #127,D0
  8839.     bhi.s    .StoreNeg        ; If negativ (greater #128!)
  8840. .CopyBytes
  8841.     subq.l    #1,D2
  8842.     bmi.w    .IncorrectSize
  8843.     move.b    (A0)+,(A3)+
  8844.     dbf    D0,.CopyBytes
  8845.     bra.s    .NoOperation
  8846. .StoreNeg
  8847.     neg.b    D0            ; To positive value
  8848.     subq.l    #1,D2
  8849.     bmi.w    .IncorrectSize
  8850.     move.b    (A0)+,D1        ; Next byte
  8851. .StoreNegCopy
  8852.     move.b    D1,(A3)+        ; Store byte
  8853.     dbf    D0,.StoreNegCopy    ; While not all
  8854. .NoOperation
  8855.     tst.l    D2
  8856.     beq.w    .finish
  8857.     bmi.s    .IncorrectSize
  8858.  
  8859.     cmpa.l    A3,A4            ; Position(x),line(x) the same as
  8860. *                    ; the end of line(x),plane(x)?
  8861.     bhi.s    .CheckOperation
  8862.  
  8863.     addq.w    #1,D6            ; Increase planecounter
  8864.     cmp.w    D4,D6            ; Last plane?
  8865.     bne.s    .Decompressing
  8866.  
  8867.     move.b    _Masking(A5),D0
  8868.     btst.l    #0,D0
  8869.     beq.s    .goon
  8870.     bsr.w    _IgnoreCompMaskLine
  8871.  
  8872. .goon
  8873.     addq.w    #1,D5            ; Next line
  8874.     lea    _BitmapStruc(A5),A1
  8875.     cmp.w    2(A1),D5        ; Last line?
  8876.     bne.s    .Decompress
  8877.  
  8878.     bra.w    .finish
  8879.  
  8880. .StoreUnpacked
  8881.     moveq    #0,D6            ; Bitplanecounter
  8882. .StoreUncompress
  8883.     lsl.w    #2,D6            ; Bitplanecounter * 2 = longword adjustment
  8884.     movea.l    0(A2,D6.w),A3        ; Current bitplane
  8885.     lsr.w    #2,D6            ; Normal
  8886.  
  8887.     move.w    D3,D0            ; Bytes per line
  8888.     mulu.w    D5,D0            ; multiply with current line
  8889.     lea    0(A3,D0.l),A3        ; StartOffset to A3
  8890.     movea.l    A3,A4            ; Address plane(x) to A4
  8891.     move.l    _ImageWidth(A5),D0    ; Real pixel width of image
  8892.     lsr.w    #3,D0            ; in bytes
  8893.     lea    0(A4,D0.w),A4        ; == End of line
  8894.  
  8895. *    move.w    D0,D0            ; Set counter (already done!)
  8896.     bra.s    .StoreUncmp_1        ; 'Cause of DBF
  8897. .StoreUncmp
  8898.     move.b    (A0)+,(A3)+        ; Copy byte into bitplane
  8899. .StoreUncmp_1
  8900.     dbf    D0,.StoreUncmp        ; until all are done
  8901.  
  8902.     addq.w    #1,D6            ; Increase planecounter
  8903.     cmp.w    D4,d6            ; All planes worked out?
  8904.     bne.s    .StoreUncompress    ; No - so do further
  8905.  
  8906.     move.b    _Masking(A5),D0
  8907.     btst.l    #0,D0
  8908.     beq.s    .goon1
  8909.     bsr.w    _IgnoreMaskLine
  8910.  
  8911. .goon1
  8912.     addq.w    #1,D5            ; Next line
  8913.  
  8914.     lea    _BitmapStruc(A5),A1
  8915.     cmp.w    2(A1),D5        ; Last line?
  8916.     bne.s    .StoreUnpacked        ; No...
  8917.  
  8918.     bra.s    .finish
  8919.  
  8920. .IncorrectSize
  8921.     lea    _IncorrectSizeTxt(pc),A0
  8922.     bsr.w    _DisplayError
  8923.     move.l    #20,_errno(A5)
  8924.     movem.l    (sp)+,D2-D6/A2-A4
  8925.     moveq    #0,D0            ; Bad IFF-file
  8926.     rts
  8927. .finish_3
  8928.     lea    _NoByteRunTxt(pc),A0
  8929.     bsr.w    _DisplayError
  8930.     move.l    #20,_errno(A5)
  8931.     movem.l    (sp)+,D2-D6/A2-A4
  8932.     moveq    #0,D0            ; Unknown compression methode
  8933.     rts
  8934. .finish_2
  8935.     lea    _AllocBufErrTxt(pc),A0
  8936.     bsr.w    _DisplayError
  8937.     addq.w    #4,sp            ; Overread "move.l A0,-(sp)"
  8938.     movem.l    (sp)+,D2-D6/A2-A4
  8939.     moveq    #-1,D0            ; Error, no mem
  8940.     rts
  8941.  
  8942. .finish_1
  8943.     lea    _NoIFFFileTxt(pc),A0
  8944.     bsr.w    _DisplayError
  8945.     move.l    #20,_errno(A5)
  8946.     movem.l    (sp)+,D2-D6/A2-A4
  8947.     moveq    #0,D0            ; Not an IFF-file
  8948.     rts
  8949. .finish
  8950.     movem.l    (sp)+,D2-D6/A2-A4
  8951.     moveq    #1,D0            ; No error
  8952.     rts
  8953.  
  8954. *
  8955. ** This is the engine to store the datas of the ABIT-chunk into the
  8956. ** planar-datas needed for plain Amigas-screens. I ask myself a lot times
  8957. ** why no demo-coder use this type of data, instead of it they use RAW-datas
  8958. ** which is the same, but without an IFF-header...
  8959. *
  8960. .foundABIT
  8961.     lea    _BitmapStruc(A5),A2    ; Address bitmap-structure
  8962.     moveq    #0,D0            ; Clear it
  8963.     move.w    _Width(A5),D0        ; Pixel width
  8964.     lsr.w    #3,D0            ; /8 = bytes
  8965.     move.w    D0,(A2)+        ; Bytes per row
  8966.     move.w    _Height(A5),(A2)+    ; Height graphic
  8967.     move.b    _Depth(A5),1(A2)    ; Number of bitplanes
  8968.  
  8969. *
  8970. ** Allocate needed bitplanes (all in once).
  8971. ** <- D0 still holds number of bytes per line.
  8972. *
  8973.     move.l    A0,-(sp)        ; Save current address
  8974.  
  8975.     mulu.w    _Height(A5),D0        ; = size of one bitplane
  8976.     move.l    D0,D2            ; to D2
  8977.  
  8978.     move.b    _Depth(A5),D1        ; Number of bitplanes
  8979.     moveq    #0,D0            ; Zero !!!
  8980. .addsize
  8981.     add.l    D2,D0            ; Longword multiply!!!
  8982.     subq.b    #1,D1
  8983.     bne.s    .addsize
  8984.  
  8985.     move.l    D0,_AllPlaneSize(A5)    ; Save size of all bitplanes
  8986.     move.l    #MEMF_CHIP|MEMF_CLEAR,D1 ; Requirements
  8987.     movea.l    _SysBase(A5),A6        ; Base Exec
  8988.     jsr    _LVOAllocMem(A6)    ; Mem demand
  8989.     move.l    D0,_Bitplane(A5)    ; Save memory address
  8990.     beq.s    .finish_2        ; If error
  8991.  
  8992.     lea    _BitmapStruc(A5),A0    ; Address bitmap-structure
  8993.     move.w    (A0),D1            ; Bytes per row
  8994.     mulu.w    2(A0),D1        ; Number bytes of one bitplane
  8995.  
  8996.     move.b    5(A0),D2        ; Number of bitplanes
  8997.     addq.l    #8,A0            ; Address constant for first plane
  8998.  
  8999.     movea.l    D0,A1            ; Address memory
  9000. .StoreBAddr
  9001.     move.l    A1,(A0)+        ; Set address of bitplane to constant
  9002.     adda.l    D1,A1            ; Get next bitplane's memory address
  9003.     subq.b    #1,D2            ; Decrease number of bitplanes
  9004.     bne.s    .StoreBAddr        ; If not all are set yet...
  9005.  
  9006.     movea.l    (sp)+,A0        ; Get back current address (source)    
  9007.     addq.l    #4,A0            ; Overread length entry
  9008.     move.l    D4,D2            ; Size in bytes of datas
  9009.     subq.l    #8,D2            ; Minus two longword ( ABIT[length] )
  9010.  
  9011.     lea    _BitmapStruc(A5),A2    ; Address bitmap-structure
  9012.     addq.l    #8,A2            ; Address pointer to first bitplane
  9013.     moveq    #0,D3
  9014.     move.w    _Width(A5),D3        ; Pixelwidth of page (64 bit boundary)
  9015.     lsr.w    #3,D3            ; in bytes
  9016.     move.l    _ImageWidth(A5),D4    ; Aligned width (16 bit boundary)
  9017.     lsr.l    #4,D4            ; in words
  9018.     move.w    _Height(A5),D5        ; Number of lines
  9019.     move.b    _Depth(A5),D6        ; Number of planes
  9020.  
  9021. *    A0 - original Datas
  9022. *    A2 - BitPlane-Address-Array
  9023. *    D2 - length original Datas
  9024. *    D3 - Pagewidth (boundary 64 bit) in bytes (longword)
  9025. *    D4 - Image width ( boundary 16 bit)
  9026. *    D5 - Height of Image in number of lines
  9027. *    D6 - Depth
  9028.  
  9029.     subq.w    #1,D4            ; 'Cause of DBF
  9030.     subq.w    #1,D5            ; 'Couse of DBF
  9031.  
  9032.     move.w    D4,D1
  9033.     move.w    D5,D0
  9034.  
  9035.     movea.l    (A2)+,A3        ; Out of constant address of bitplane
  9036.     movea.l    A3,A4            ; ...also in A4
  9037.     adda.l    D3,A4            ; Next line's address (destination) after comming loop
  9038.  
  9039. .copyLine
  9040.     move.w    (A0)+,(A3)+        ; Store data-word
  9041.     subq.l    #2,D2
  9042.     beq.w    .finish
  9043.     bcs.w    .IncorrectSize
  9044.     dbf    D1,.copyLine        ; Store this line...
  9045.  
  9046.     movea.l    A4,A3            ; Next line's address into A3
  9047.     adda.l    D3,A4            ; Add  bytesize of one line to A4
  9048.     move.w    D4,D1            ; Image width in number of words
  9049.     dbf    D0,.copyLine        ; Store next line
  9050.  
  9051.     subq.b    #1,D6            ; One less bitplane to go...
  9052.     beq.w    .finish
  9053.  
  9054. * One complete Bitplane stored, so do next
  9055.     movea.l    (A2)+,A3        ; Next bitplane's address out of constant
  9056.     movea.l    A3,A4            ; Address also in A4
  9057.     adda.l    D3,A4            ; Address next line of this Bitplane
  9058.     move.w    D5,D0            ; Number of lines
  9059.     move.w    D4,D1            ; Image width in number of words
  9060.     bra.s    .copyLine        ; Store next bitplane
  9061.  
  9062.  
  9063. *
  9064. ** These routines are only called if a mask is set for the picture (brush)
  9065. *
  9066.  
  9067. _IgnoreMaskLine        ; Uncompressed IFF
  9068.     move.l    _ImageWidth(A5),D0
  9069.     lsr.w    #3,D0
  9070.     adda.l    D0,A0
  9071.     sub.l    D0,D2
  9072.     rts
  9073.  
  9074.  
  9075. _IgnoreCompMaskLine    ; Compressed IFF
  9076.     move.l    D3,-(sp)
  9077.     move.l    _ImageWidth(A5),D3
  9078.     lsr.w    #3,D3
  9079.     moveq    #0,D1
  9080.  
  9081.  
  9082. .CheckOperation
  9083.     cmp.w    D3,D1
  9084.     beq.s    .out
  9085.  
  9086.     subq.l    #1,D2            ; Data counter
  9087.     bmi.s    .out
  9088.     moveq    #0,D0
  9089.     move.b    (A0)+,D0
  9090.     cmpi.b    #-128,D0        ; #-128 = no operation
  9091.     beq.s    .NoOperation
  9092.     cmpi.b    #127,D0
  9093.     bhi.s    .StoreNeg        ; If negativ (greater #128!)
  9094. .CopyBytes
  9095.     subq.l    #1,D2
  9096.     bmi.s    .out
  9097.     addq.l    #1,A0            ; Store byte of mask to nowhere...
  9098.     addq.w    #1,D1
  9099.     dbf    D0,.CopyBytes
  9100.     bra.s    .NoOperation
  9101. .StoreNeg
  9102.     neg.b    D0            ; To positive value
  9103.     subq.l    #1,D2
  9104.     bmi.s    .out
  9105.     addq.l    #1,A0
  9106. .StoreNegCopy
  9107.     addq.w    #1,D1            ; Store byte of mask to nowhere and decrease counter...
  9108.     dbf    D0,.StoreNegCopy    ; While not all
  9109. .NoOperation
  9110.     tst.l    D2
  9111.     bmi.s    .out
  9112.     bra.s    .CheckOperation
  9113. .out
  9114.     movem.l    (sp)+,D3
  9115.     rts
  9116.  
  9117. *************************************************************
  9118. *
  9119. * Init the standard palette (RGB32) to one which contains
  9120. * only grey values, so called Grey Palette.
  9121. * Since the OS doesn't support 24 bit screens and 3rd party
  9122. * GFX boards will not allow custom applications to copy
  9123. * 24 bitplanes into a screen they made via OS functions,
  9124. * the first 8 bitplanes are treated as they contain only grey
  9125. * colours (those 8 which we gonna display).
  9126. * When there is a device that will allow to copy 24 bitplanes
  9127. * to a screen, Viewer can display it immediately, since
  9128. * I never stripped the code to support only 8 bitplanes,
  9129. * although 3rd party graphic board software emulation does!
  9130. *
  9131.  
  9132. _Init24BitPal
  9133.     move.l    #256,D0
  9134.     lea    _RGB32Colours(A5),A1
  9135.     move.l    D0,D1
  9136.     swap    D1            ; number of colours (1st word) start at colour (2nd word)
  9137.     move.l    D1,(A1)+        ; store number of entries in table and
  9138. *                      startoffset for colours
  9139.  
  9140. .GoAhead
  9141.     movem.l    D2-D4,-(sp)
  9142.  
  9143.     moveq    #0,D1
  9144.     moveq    #0,D2
  9145.     moveq    #0,D3
  9146.     bra.s    .sneek
  9147. .convert
  9148.     moveq    #2,D4            ; 3 loops
  9149. .storeOneLW
  9150. *    move.b    D1,D1            ; the value
  9151.     move.b    D1,D3            ; save it
  9152.     andi.b    #$F,D3            ; only low nibble
  9153.     move.b    D3,D2            ; also in D2
  9154.     lsl.b    #4,D2            ; store it as high nibble
  9155.     add.b    D3,D2            ; add low nibble
  9156.  
  9157.     move.b    D1,(A1)+        ; save high byte of high word
  9158.     move.b    D2,(A1)+        ; save low byte of high word
  9159.     move.b    D2,(A1)+        ; save high byte of low word
  9160.     move.b    D2,(A1)+        ; save low byte of low word
  9161.  
  9162.     dbf    D4,.storeOneLW        ; for one colour (R, G, B)
  9163.     addq.b    #1,D1
  9164. .sneek
  9165.     dbf    D0,.convert
  9166.     moveq    #0,D0
  9167.     move.l    D0,(A1)            ; terminator!!!
  9168.  
  9169.     movem.l    (sp)+,D2-D4
  9170.     rts
  9171.  
  9172. ***************************************************************
  9173. *
  9174. ** Check if the hardware display supports 8 bit per gun as the
  9175. ** original AMIGA hardware. If not, brighten up the display...
  9176. *
  9177. ** Because only simple device for the AMIGA are available (3rd
  9178. ** party gfx-boards) this routine might not work perfectly since
  9179. ** those cards don't work proberly in an AMIGA surround due to
  9180. ** their limits and not implemented AMIGA features:
  9181. ** only 3 colour sprites, only one sprite, no soft-scrolling
  9182. ** screens, no overscan, only one hardware screen, incorrect
  9183. ** bits per gun (a 256 colour display offers only 262144 colour
  9184. ** palette) where the original double A chip set offers 16.7 million!)
  9185. ** and a lot more.
  9186. *
  9187.  
  9188. _BrightenColours
  9189.     movem.l    D0-D2/A0-A1/A6,-(sp)
  9190. * GetDisplayInfoData( 0, di, sizeof( di), DTAG_DISP, DisplayID)
  9191.     suba.l    A0,A0            ; Handle
  9192.     lea    _DisplayInfo(A5),A1    ; Buffer
  9193.     moveq    #dis_SIZEOF,D0        ; sizeof
  9194.     move.l    #DTAG_DISP,D1        ; TAG
  9195.     move.l    _ViewPortMod(A5),D2    ; DisplayID
  9196.     movea.l    _GfxBase(A5),A6
  9197.     cmpi.w    #38,LIB_VERSION(A6)
  9198.     beq.s    .done            ; Since we have not AMIGA OS3...
  9199.     jsr    _LVOGetDisplayInfoData(A6)
  9200.     tst.l    D0
  9201.     beq.s    .done
  9202.  
  9203.     lea    _DisplayInfo(A5),A0
  9204.     move.b    RedBits(A0),D0
  9205.     cmpi.b    #7,D0
  9206.     bls.s    .adjust
  9207.  
  9208.     move.b    GreenBits(A0),D0
  9209.     cmpi.b    #7,D0
  9210.     bls.s    .adjust
  9211.  
  9212.     move.b    BlueBits(A0),D0
  9213.     cmpi.b    #7,D0
  9214.     bhi.s    .done
  9215.  
  9216. .adjust
  9217. * AdjustPal32( struct DisplayInfo *, struct RGB32 *)
  9218.     lea    _RGB32Colours(A5),A1
  9219.     bsr.s    _AdjustPal32
  9220. .done
  9221.     movem.l    (sp)+,D0-D2/A0-A1/A6
  9222.     rts
  9223.  
  9224. ***********************************************************
  9225. *
  9226. ** Adjust (brighten) RGB32 colour table values to supported
  9227. ** less than 8 bits per gun.
  9228. *
  9229. ** This routine was just a quick hack...
  9230. *
  9231. ** Only useful when a simple 3rd party graphic device is
  9232. ** installed, such as for IBM-compatible computers which are
  9233. ** adapted to the AMIGA system, e.g. Picasso II(+) & IV,
  9234. ** Picollo, Picollo SD 64, Retina Z2 & Z3, CyberVision 64,
  9235. ** CyberVision 64 3D etc. .
  9236. ** Does the GVP (Spectrum) and the Merlin support 8 bit per
  9237. ** gun also in non 24 bit displays? If you know, tell me.
  9238. *
  9239.  
  9240. _AdjustPal32
  9241.     movem.l    D2-D7,-(sp)
  9242.  
  9243.     btst    #7,_BMHDFlags(A5)    ; Indicates if colourmap of file is
  9244.     bne.s    .RGB32            ; stored as 8-bit values (AGA resolution (RGB32))
  9245.  
  9246. *
  9247. ** This one is to convert the original RGB4 values (now RGB32) to values
  9248. ** which looks on this simple device (3rd party gfx device) the same as
  9249. ** with the OCS or ECS CHIP SET.
  9250. *
  9251. .RGB4
  9252.     move.b    RedBits(A0),D5        ; e.g. 6
  9253.     moveq    #8,D0
  9254.     sub.b    D5,D0            ; 8 - 6 = 2
  9255.     moveq    #16,D5
  9256.     mulu.w    D0,D5            ; = 16
  9257.  
  9258.     move.b    GreenBits(A0),D6    ; e.g. 5
  9259.     moveq    #8,D0
  9260.     sub.b    D6,D0            ; 8 - 5 = 3
  9261.     moveq    #16,D6
  9262.     mulu.w    D0,D6            ; = 24
  9263.  
  9264.     move.b    BlueBits(A0),D7        ; e.g. 4
  9265.     moveq    #8,D0
  9266.     sub.b    D7,D0            ; 8 - 4 = 4
  9267.     moveq    #16,D7
  9268.     mulu.w    D0,D7            ; = 32
  9269.     bra.s    .doit
  9270.  
  9271. *
  9272. ** This one to adjust palette to reflect less bits per gun as the AA (AGA) hardware.
  9273. *
  9274. .RGB32
  9275.     moveq    #0,D0
  9276.     move.b    RedBits(A0),D0        ; e.g. 6
  9277.     moveq    #32,D1            ; = 32 (256 luminanz / 8 bit per luminanz = 32)
  9278.     mulu.w    D0,D1            ; 6 * 32  = 192
  9279.     move.l    #256,D5
  9280.     sub.w    D1,D5            ; 256 - 192 = 64
  9281.     divu.w    D0,D5            ; 64 / 6 = ~10
  9282.  
  9283.     moveq    #0,D0
  9284.     move.b    GreenBits(A0),D0    ; e.g. 5
  9285.     moveq    #32,D1            ; = 32 (256 luminanz / 8 bit per luminanz = 32)
  9286.     mulu.w    D0,D1            ; 5 * 32  = 160
  9287.     move.l    #256,D6
  9288.     sub.w    D1,D6            ; 256 - 160 = 96
  9289.     divu.w    D0,D6            ; 96 / 5 = ~19
  9290.  
  9291.     moveq    #0,D0
  9292.     move.b    BlueBits(A0),D0        ; e.g. 4
  9293.     moveq    #32,D1            ; = 32 (256 luminanz / 8 bit per luminanz = 32)
  9294.     mulu.w    D0,D1            ; 4 * 32  = 128
  9295.     move.l    #256,D7
  9296.     sub.w    D1,D7            ; 256 - 128 = 128
  9297.     divu.w    D0,D7            ; 128 / 4 = 32
  9298.  
  9299. .doit
  9300.     move.l    (A1)+,D0        ; Number of colours (1st word, offset colour 2nd word)
  9301.     swap    D0            ; D0 = number colours used
  9302.     bra.s    .dec 
  9303. .loop
  9304.     move.l    D0,-(sp)        ; number of colours
  9305.  
  9306.     move.l    (A1),D0            ; Colour value (red) (32 bit)
  9307.     moveq    #24,D1            ; into
  9308.     lsr.l    D1,D0            ; lowest byte
  9309.     add.w    D5,D0
  9310. .adjred
  9311.     cmpi.w    #255,D0            ; Range check
  9312.     bls.s    .okred
  9313.     move.l    #255,D0
  9314. .okred    
  9315.     bsr.s    .storeNew
  9316.  
  9317.     move.l    (A1),D0            ; Colour value (green) (32 bit)
  9318.     moveq    #24,D1            ; into
  9319.     lsr.l    D1,D0            ; lowest byte
  9320.     add.w    D6,D0
  9321. .adjgreen
  9322.     cmpi.w    #255,D0            ; Range check
  9323.     bls.s    .okgreen
  9324.     move.l    #255,D0
  9325. .okgreen
  9326.     bsr.s    .storeNew
  9327.  
  9328.     move.l    (A1),D0            ; Colour value (blue) (32 bit)
  9329.     moveq    #24,D1            ; into
  9330.     lsr.l    D1,D0            ; lowest byte
  9331.     add.w    D7,D0
  9332. .adjblue
  9333.     cmpi.w    #255,D0            ; Range check
  9334.     bls.s    .okblue
  9335.     move.l    #255,D0
  9336. .okblue    
  9337.     bsr.s    .storeNew
  9338.  
  9339.     move.l    (sp)+,D0
  9340. .dec
  9341.     subq.w    #1,D0
  9342.     bcc.s    .loop
  9343.     
  9344.     movem.l    (sp)+,D2-D7
  9345.     rts
  9346.  
  9347. .storeNew
  9348.     move.w    D0,D1
  9349.     lsl.w    #8,D0
  9350.     andi.w    #$F,D1            ; Only low nible
  9351.     move.b    D1,D0
  9352.     lsl.b    #4,D1
  9353.     or.b    D0,D1
  9354.     move.b    D1,D0
  9355.     lsl.l    #8,D0
  9356.     move.b    D1,D0
  9357.     lsl.l    #8,D0
  9358.     move.b    D1,D0
  9359.     move.l    D0,(A1)+        ; Store new computed red value
  9360.     rts
  9361.  
  9362. ********************************************************
  9363. * V39 RGB32 format
  9364. *
  9365. * Highest byte of longword contains colour-value, e.g. 237 (0xED).
  9366. * The rest (lower 3 bytes) containing the low nibble of
  9367. * the highest byte, here 13, fully:
  9368. * ED DD DD DD == 0xEDDDDDDD
  9369. *
  9370. * Inputs: D0 - number of colours to convert (max. 256)
  9371. *         A0 - RGB source table (like CMAP chunk)
  9372. *         A1 - RGB32 destionation buffer (safety = (256*3+2)*4 bytes large)
  9373. * Results: RGB32 buffer filled with 32bit RGB values (used by LoadRGB32, SA_Colors32)
  9374. *          D0 == -1L on error (too much colours, max. 256)
  9375.  
  9376. _RGBtoRGB32     ; (colours, tableRGB, tableRGB32)(D0, A0, A1)
  9377.     andi.l    #$1FF,D0        ; max 256 colours
  9378.     cmpi.w    #256,D0
  9379.     bls.s    .cok            ; if not more colours
  9380.     move.l    #256,D0
  9381. .cok
  9382.     move.l    D0,D1
  9383.     swap    D1            ; number of colours (1st word) start at colour (2nd word)
  9384.     move.l    D1,(A1)+        ; store number of entries in table and
  9385. *                      startoffset for colours
  9386.  
  9387.     btst    #7,_BMHDFlags(A5)    ; Full byte used by colour value?
  9388.     bne.s    .GoAhead        ; If so...
  9389.  
  9390.     cmpi.w    #32,D0            ; More than 32 colours?
  9391.     bhi.s    .AGA            ; Assumption: an AGA-picture where the programmer forgot
  9392. *                      to set the bit
  9393.  
  9394.     bsr.s    .ModifyColours        ; Else take as 4-bit
  9395.     bra.s    .GoAhead    
  9396.  
  9397. .AGA
  9398.     bset    #7,_BMHDFlags(A5)    ; Indicates it's valid
  9399.  
  9400. .GoAhead
  9401.     movem.l    D2-D4,-(sp)
  9402.  
  9403.     moveq    #0,D1
  9404.     moveq    #0,D2
  9405.     moveq    #0,D3
  9406.     bra.s    .sneek
  9407. .convert
  9408.     moveq    #2,D4            ; 3 loops
  9409. .storeOneLW
  9410.     move.b    (A0)+,D1        ; get value
  9411.     move.b    D1,D3            ; save it
  9412.     andi.b    #$F,D3            ; only low nibble
  9413.     move.b    D3,D2            ; also in D2
  9414.     lsl.b    #4,D2            ; store it as high nibble
  9415.     add.b    D3,D2            ; add low nibble
  9416.  
  9417.     move.b    D1,(A1)+        ; save high byte of high word
  9418.     move.b    D2,(A1)+        ; save low byte of high word
  9419.     move.b    D2,(A1)+        ; save high byte of low word
  9420.     move.b    D2,(A1)+        ; save low byte of low word
  9421.  
  9422.     dbf    D4,.storeOneLW        ; for one colour (R, G, B)
  9423. .sneek
  9424.     dbf    D0,.convert
  9425.     moveq    #0,D0
  9426.     move.l    D0,(A1)            ; terminator!!!
  9427.  
  9428.     movem.l    (sp)+,D2-D4
  9429.     rts
  9430.  
  9431. .failed
  9432.     moveq    #-1,D0
  9433.     rts
  9434.  
  9435. *
  9436. ** Change 4-bit colour value to 8-bit colour value ( needed for LoadRGB32() )
  9437. *
  9438. .ModifyColours
  9439.     movem.l    D0-D2/A0,-(sp)
  9440.     bra.s    2$
  9441. 1$
  9442.     move.b    (A0)+,D1        ; Get value
  9443.     andi.b    #$F0,D1            ; Ignore unused nibble
  9444.     move.b    D1,D2            ; Save result
  9445.     lsr.b    #4,D2            ; High nibble to low nibble
  9446.     add.b    D2,D1            ; Make new value
  9447.     move.b    D1,-1(A0)        ; Store new computed value
  9448. 2$
  9449.     dbf    D0,1$            ; Until all are done
  9450.     movem.l    (sp)+,D0-D2/A0
  9451.     rts
  9452.  
  9453. ********************************************************
  9454. *
  9455. ** This routine will only be called before the dimension
  9456. ** and MonitorID grab is fired up!
  9457. *
  9458. _CheckEHB
  9459.     movem.l    D0-D2/A0-A1,-(sp)
  9460.  
  9461.     move.l    _ViewPortMod(A5),D0    ; Original (not modified till now)
  9462.     andi.l    #V_EXTRA_HALFBRITE,D0
  9463.     beq.s    .done
  9464.  
  9465.     lea    _RGB32Colours(A5),A0
  9466.     move.l    (A0),D0        ; Get color offset and amount colors e.g. 0x00200000
  9467.     swap    D0        ; e.g. 0x00000020
  9468.     moveq    #0,D2
  9469.     move.w    D0,D2        ; Remember amount colors (e.g. 32)
  9470.     add.w    D0,D0        ; Double amount of colors (e.g. 64)
  9471.     swap    D0
  9472.     move.l    D0,(A0)+    ; Store new amount of colors
  9473.  
  9474.     move.l    D2,D0        ; Amount colors (e.g. 32)
  9475.     move.l    D0,D1        ; ditto
  9476.     lsl.l    #3,D0        ; Amount colors * 8
  9477.     lsl.w    #2,D1        ; Amount colors * 4
  9478.     add.l    D1,D0        ; == amount colors in bytes (e.g. 32) * 12)
  9479.     lea    0(A0,D0.l),A1    ; Destination
  9480.  
  9481.     move.l    D2,D0        ; e.g. 32
  9482.     add.w    D0,D0        ; == 64
  9483.     add.w    D2,D0        ; == 96 runs (== 384 bytes of source to touch)
  9484.     bra.s    .loopdec
  9485. .loop
  9486.     move.l    (A0)+,D1
  9487.     lsr.l    #1,D1
  9488.     move.l    D1,(A1)+
  9489. .loopdec
  9490.     dbf    D0,.loop
  9491.     clr.l    (A1)
  9492. .done
  9493.     movem.l    (sp)+,D0-D2/A0-A1
  9494.     rts
  9495.  
  9496. **************************
  9497. *
  9498. * Convert binary to ascii.
  9499. *
  9500. * Inputs: none
  9501. * Results: none
  9502. *
  9503.  
  9504. _ConvertBinary
  9505.     movem.l    D2-D7/A2-A4,-(sp)
  9506.  
  9507.     move.l    _BufferSize(A5),D2    ; Length allocated buffer
  9508.     move.l    _FileSize(A5),D3    ; Real filelength
  9509.     movea.l    _TextPtr(A5),A2        ; Adress buffer
  9510.     addq.l    #2,A2            ; Skip #$020A
  9511.  
  9512.     bsr.w    _GetConvertedSize
  9513.     move.l    D0,D4            ; Save new size
  9514.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,D1
  9515.     movea.l    _SysBase(A5),A6
  9516.     jsr    _LVOAllocMem(A6)
  9517.     movea.l    D0,A4            ; Save new buffer pointer
  9518.     tst.l    D0
  9519.     beq.w    .ErrorAlloc        ; Upon error
  9520.     movea.l    D0,A3            ; Address buffer
  9521.     move.w    #$200A,(A3)+        ; Write Blank and LineFeed
  9522.  
  9523.  
  9524. * A4 - allocated buffer - do not scratch
  9525. * A3 - allocated buffer - used
  9526. * A2 - old datas - used
  9527. * D4 - allocated size - do not scratch
  9528. * D3 - FileSize - used
  9529.  
  9530.     moveq    #0,D7            ; New filesize
  9531.     moveq    #-16,D5            ; Linenumber
  9532.  
  9533.     movea.l    A3,A0            ; Address buffer
  9534. 1$
  9535.     tst.l    D3            ; Soruce file end?
  9536.     beq.w    .end            ; If so...
  9537.     cmpi.l    #15,D3            ; Do we have a rest of 4 longwords to convert?
  9538.     bls.w    .ARest            ; If not...
  9539.     addi.l    #16,D5            ; Else add 16 bytes (4 longwords)
  9540.     move.l    D5,D0            ; Line number
  9541.     bsr.w    _comhex            ; Convert count to ascii
  9542.     move.b    #':',(A0)+        ; Write colon at end of number
  9543.     move.b    #' ',(A0)+        ; Write 2 blanks
  9544.     move.b    #' ',(A0)+
  9545.     addi.l    #11,D7            ; New filelength plus 11 bytes
  9546.  
  9547.     move.l    (A2),D0            ; Get 1. longword of line to convert
  9548.     bsr.w    _comhex            ; Convert it to ascii
  9549.     move.b    #' ',(A0)+        ; Write Blank
  9550.     addi.l    #9,D7            ; New filesize plus 9
  9551.  
  9552.     move.l    4(A2),D0        ; 2. longword
  9553.     bsr.w    _comhex
  9554.     move.b    #' ',(A0)+
  9555.     addi.l    #9,D7
  9556.  
  9557.     move.l    8(A2),D0        ; 3. longword
  9558.     bsr.w    _comhex
  9559.     move.b    #' ',(A0)+
  9560.     addi.l    #9,D7
  9561.  
  9562.     move.l    12(A2),D0        ; 4. longword
  9563.     bsr.w    _comhex
  9564.     move.b    #' ',(A0)+
  9565.     move.b    #' ',(A0)+
  9566.     move.b    #' ',(A0)+
  9567.     move.b    #' ',(A0)+
  9568.     addi.l    #12,D7
  9569.  
  9570.     subi.l    #16,D3            ; Old filesize -16
  9571.     moveq    #15,D0            ; 16 bytes to write
  9572. 0$
  9573.     move.b    (A2)+,D1        ; Get byte
  9574.     cmpi.b    #31,D1            ; Displayable char?
  9575.     bls.s    .exchange        ; If not
  9576.     cmpi.b    #160,D1            ; Displayable char?
  9577.     bhi.s    .ok            ; If so
  9578.     cmpi.b    #127,D1            ; Displayable char
  9579.     bls.s    .ok            ; If so
  9580. .exchange
  9581.     move.b    #'.',(A0)+        ; Not displayable, exchange through point
  9582.     bra.s    2$
  9583. .ok
  9584.     move.b    D1,(A0)+        ; Displayable...
  9585. 2$
  9586.     dbf    D0,0$            ; Number of bytes in one line (16)
  9587.     move.b    #10,(A0)+        ; Write LineFeed
  9588.     addi.l    #17,D7            ; New filelength +17
  9589.     bra.w    1$    
  9590.  
  9591. * ------------ *
  9592.  
  9593. .ARest    ; Less than 16 bytes....
  9594.     addi.l    #16,D5            ; Linenumber
  9595.     move.l    D5,D0            ; Convert linenumber (binary)
  9596.     bsr.w    _comhex            ; into ascii-chars
  9597.     move.b    #':',(A0)+        ; Write colon after linenumber
  9598.     move.b    #' ',(A0)+
  9599.     move.b    #' ',(A0)+
  9600.     addi.l    #11,D7            ; New filelength +11 bytes
  9601.  
  9602.     movea.l    A2,A1            ; Address current offset in source file
  9603.     move.l    D3,D5            ; Rest-length of old file
  9604. .longLoop
  9605.     cmpi.b    #3,D5            ; Less than 3 bytes?
  9606.     bls.s    .byteWidth
  9607.  
  9608.     subq.l    #4,D5            ; Because one longword contains 4 bytes
  9609.  
  9610.     move.l    (A1)+,D0        ; Get longword to convert
  9611.     bsr.w    _comhex            ; into ascii
  9612.     move.b    #' ',(A0)+
  9613.     addi.l    #9,D7            ; New filesize plus 9
  9614.     bra.s    .longLoop
  9615.  
  9616. .byteWidth
  9617.     subq.b    #1,D5            ; Old filelength -1
  9618.     bcs.s    .MakeASCII        ; When end is reached
  9619.     move.b    (A1)+,D0        ; Get byte
  9620.     bsr.w    _comhexByte        ; and convert it into ascii
  9621.     addq.l    #1,D7            ; New filelength +1
  9622.     bra.s    .byteWidth
  9623.  
  9624. .MakeASCII    
  9625.     move.l    A0,-(sp)        ; Current buffer address
  9626.     moveq    #-1,D0            ; Counter
  9627. 3$
  9628.     cmpi.b    #10,-(A0)        ; Find LineFeed of last line
  9629.     dbeq    D0,3$
  9630.     not.l    D0            ; Compute length
  9631.     movea.l    (sp)+,A0        ; Current buffer address
  9632.     moveq    #49,D1            ; At this position we write down the ascii-values
  9633.     sub.b    D0,D1
  9634. 4$
  9635.     move.b    #' ',(A0)+        ; Write as much Blank until we reach position 49
  9636.     addq.l    #1,D7            ; New filelength +1
  9637.     dbf    D1,4$
  9638.  
  9639.     add.l    D3,D7            ; Add rest of old filelength to new filelength
  9640.     move.l    D3,D0            ; Rest
  9641.     subq.b    #1,D0            ; Because of DBF
  9642. 5$
  9643.     move.b    (A2)+,D1        ; Get value
  9644.     cmpi.b    #31,D1            ; Displayable char?
  9645.     bls.s    6$
  9646.     cmpi.b    #160,D1            ; Displayable char?
  9647.     bhi.s    7$
  9648.     cmpi.b    #127,D1            ; Displayable char?
  9649.     bls.s    7$
  9650. 6$
  9651.     move.b    #'.',(A0)+        ; Not displayable!
  9652.     bra.s    8$
  9653. 7$
  9654.     move.b    D1,(A0)+
  9655. 8$
  9656.     dbf    D0,5$
  9657.     bra.w    .end            ; ....finish
  9658.  
  9659. * --------------- *
  9660.  
  9661. .end
  9662.     move.b    #10,(A0)        ; Last char of file should be a LineFeed
  9663.     bsr.w    _FreeFile        ; Free old file (buffer)
  9664.     move.l    A4,_TextPtr(A5)        ; New buffer address
  9665.     move.l    D4,_BufferSize(A5)    ; New buffer size
  9666.     move.l    D7,_FileSize(A5)    ; New filesize
  9667.     movem.l    (sp)+,D2-D7/A2-A4
  9668.     rts
  9669.  
  9670. .ErrorAlloc
  9671.     lea    _AllocErrTxt(pc),A0    ; Display error
  9672.     bsr.w    _DisplayError
  9673.     bsr.w    _FreeFile        ; Free old file
  9674.     movem.l    (sp)+,D2-D7/A2-A4
  9675.     addq.l    #4,sp
  9676.     bra.w    _Loop
  9677.  
  9678. _GetConvertedSize
  9679.     move.l    _FileSize(A5),D0    ; Original
  9680.     move.l    D0,D1
  9681.     lsl.l    #2,D0            ; *4
  9682.     lsr.l    #2,D1            ; /4
  9683.     add.l    D1,D0            ; == * 4.25
  9684.     addi.l    #76,D0            ; For safety
  9685.     andi.l    #-8,D0            ; Align size
  9686.     rts
  9687.  
  9688. _comhex
  9689.     move.l    D2,-(sp)
  9690.     moveq    #7,D1
  9691. 1$
  9692.     rol.l    #4,D0
  9693.     move.l    D0,D2
  9694.     and.b    #$F,D2
  9695.     addi.b    #'0',D2
  9696.     cmpi.b    #'9',D2
  9697.     bls.s    2$
  9698.     addq.b    #7,D2
  9699. 2$
  9700.     move.b    D2,(A0)+
  9701.     dbf    D1,1$
  9702.     move.l    (sp)+,D2
  9703.     rts
  9704.  
  9705. _comhexByte
  9706.     move.l    D2,-(sp)
  9707.     moveq    #1,D1
  9708. 1$
  9709.     rol.b    #4,D0
  9710.     move.b    D0,D2
  9711.     and.b    #$F,D2
  9712.     addi.b    #'0',D2
  9713.     cmpi.b    #'9',D2
  9714.     bls.s    2$
  9715.     addq.b    #7,D2
  9716. 2$
  9717.     move.b    D2,(A0)+
  9718.     dbf    D1,1$
  9719.     move.l    (sp)+,D2
  9720.     rts
  9721.  
  9722. ******************************************************************************
  9723. *
  9724. * This routine will extract the ASCII-characters of a `known' document.
  9725. * It will only search for each known-chunk, remember the length of it, and
  9726. * then it allocates a buffer based on the computed length, and after that,
  9727. * it will re-scan the file and copy the plain characters into the new allocated
  9728. * buffer.
  9729. *
  9730. * This routine is rather a joke than useful...
  9731. *
  9732.  
  9733. _LoadFCFile
  9734.     tst.b    _NoWarnFlag(A5)        ; Allowed to display warnings?
  9735.     bne.s    .doit            ; If not...
  9736.  
  9737.     lea    _IFFAsciiTxt(pc),A0    ; Else, give out this
  9738.     bsr.w    _DisplayError        ; message
  9739.  
  9740.     tst.l    D0            ; User said ok.?
  9741.     beq.w    _BinaryFile        ; If not, don't display...
  9742.  
  9743. .doit
  9744.     movea.l    _TextPtr(A5),A0        ; Start of datas
  9745.     addq.l    #2,A0            ; Overread $200A ( Blank and LineFeed )
  9746.     movea.l    A0,A1
  9747.     move.l    _BufferSize(A5),D0    ; Get length of buffer
  9748.     subq.l    #2,D0            ; Because of Blank and LineFeed ($200A)
  9749.     move.l    D0,D1
  9750.     moveq    #0,D4            ; Amount of charcaters
  9751.  
  9752.     cmpi.l    #'CAT ',(A0)
  9753.     beq.s    .valid
  9754.     cmpi.l    #'LIST',(A0)
  9755.     beq.s    .valid
  9756.     cmpi.l    #'FORM',(A0)        ; Check IDs
  9757.     bne.w    .errNonStd
  9758.  
  9759.     cmpi.l    #'SWRT',8(A0)
  9760.     beq.s    .valid
  9761.     cmpi.l    #'WOWO',8(A0)
  9762.     beq.s    .valid
  9763.     cmpi.l    #'FTXT',8(A0)
  9764.     bne.w    .errNonStd
  9765. .valid
  9766.     lea    12(A0),A0        ; Pointer to e.g. "HYPH"-chunk
  9767.     sub.l    #12,D0
  9768.  
  9769. .ChunkName
  9770.     cmpi.l    #8,D0            ; Less than 9 bytes?
  9771.     ble.w    .gotLength        ; So call second pass
  9772.  
  9773.     move.l    (A0),D3            ; Name of chunk
  9774.     move.l    4(A0),D2        ; Length of chunk
  9775.  
  9776.     cmpi.l    #'FORM',D3
  9777.     beq.s    .skipType
  9778.  
  9779.     cmpi.l    #'CAT ',D3
  9780.     beq.s    .skipType
  9781.  
  9782.     cmpi.l    #'LIST',D3
  9783.     beq.s    .skipType
  9784.  
  9785.     cmpi.l    #'PROP',D3
  9786.     bne.s    .goon
  9787.  
  9788. .skipType
  9789.     lea    12(A0),A0
  9790.     sub.l    #12,D0
  9791.     bra.s    .ChunkName
  9792.  
  9793. .goon
  9794.     addq.l    #8,A0            ; Overread chunk-name and its size setting
  9795.     subq.l    #8,D0            ; Rest of filelength
  9796.     bmi.w    .errIncomplete        ; Upon error
  9797.  
  9798.     cmpi.l    #'CHRS',D3        ; Characters?
  9799.     beq.s    .addLength
  9800.  
  9801.     cmpi.l    #'RULE',D3        ; "RULE"-chunk treated as LineFeed
  9802.     beq.s    .addLF
  9803.  
  9804.     cmpi.l    #'WTXT',D3        ; "WTXT"-chunk treated as text
  9805.     beq.s    .addLength
  9806.  
  9807.     addq.l    #1,D2            ; Make chunk-size even
  9808.     andi.l    #-2,D2
  9809.  
  9810.     add.l    D2,A0            ; Pointer to next chunk
  9811.     sub.l    D2,D0            ; Rest of filelength
  9812.     bra.s    .ChunkName        ; and scan...
  9813.  
  9814. .addLength    ; CHRS-chunk found
  9815.     tst.l    D2            ; CHRS-chunk with size zero?
  9816.     bne.s    .asciichars        ; If size set
  9817.  
  9818.     addq.l    #1,D4            ; else size == 0 so set a LineFeed
  9819.     bra.s    .next
  9820.  
  9821. .asciichars
  9822.     add.l    D2,D4            ; else add size
  9823.  
  9824. .next
  9825.     addq.l    #1,D2            ; Make chunk-size even
  9826.     andi.l    #-2,D2
  9827.  
  9828.     add.l    D2,A0            ; Pointer to next chunk
  9829.     sub.l    D2,D0
  9830.     bra.w    .ChunkName
  9831.  
  9832. .addLF    ; RULE-chunk is treated as a LineFeed
  9833.     addq.l    #1,D4            ; Size plus 1
  9834.  
  9835.     addq.l    #1,D2            ; Make chunk-size even
  9836.     andi.l    #-2,D2
  9837.  
  9838.     add.l    D2,A0            ; Pointer to next chunk
  9839.     sub.l    D2,D0
  9840.     bra.w    .ChunkName
  9841.  
  9842. *****************************
  9843. * Parsing done ( first pass )
  9844. * Now allocate the buffer and
  9845. * store the characters.
  9846.  
  9847. .gotLength
  9848.     move.l    _PageWidth(A5),D7    ; Limit for word-wrap
  9849.  
  9850.     move.l    D4,D5            ; Size of characters
  9851.     add.l    #15,D5            ; Plus 7 and! plus 8 bytes (8-Bytes = $200A at front and $0A
  9852. *                      at end of datas ( rest for safety ))
  9853.     andi.l    #-8,D5            ; Make size divisible through eight (round it up)
  9854.  
  9855.     movem.l    D1/A1,-(sp)        ; Remember source and source's size
  9856.  
  9857.     move.l    D5,D0            ; Size in bytes
  9858.     move.l    #MEMF_CLEAR,D1
  9859.     movea.l    _SysBase(A5),A6
  9860.     jsr    _LVOAllocMem(A6)    ; Mem demand
  9861.  
  9862.     movem.l    (sp)+,D1/A1
  9863.     tst.l    D0
  9864.     beq.w    .errNoMem        ; Upon error
  9865.  
  9866.     movea.l    D0,A2            ; Destination
  9867.     movea.l    A2,A3            ; Remember
  9868.  
  9869.     move.w    #$200A,(A2)+        ; Write first down Blank and LineFeed
  9870.  
  9871.     movea.l    A1,A0            ; Source
  9872.     move.l    D1,D0            ; Length source
  9873.  
  9874.     lea    12(A0),A0        ; Pointer to first important chunk-name (e.g. HYPH)
  9875.     subi.l    #12,D0
  9876.  
  9877.     moveq    #0,D6            ; Amount of chars in line...
  9878.  
  9879. .checkChunk
  9880.     cmpi.l    #8,D0            ; At least 8 bytes?
  9881.     ble.w    .done            ; else pass 2 ends...
  9882.  
  9883.     move.l    (A0),D1            ; Name of chunk
  9884.     move.l    4(A0),D2        ; Length of chunk
  9885.  
  9886.     cmpi.l    #'FORM',D1
  9887.     beq.s    .noParseYet
  9888.  
  9889.     cmpi.l    #'CAT ',D1
  9890.     beq.s    .noParseYet
  9891.  
  9892.     cmpi.l    #'PROP',D1
  9893.     beq.s    .noParseYet
  9894.  
  9895.     cmpi.l    #'LIST',D1
  9896.     bne.s    .parse
  9897.  
  9898. .noParseYet
  9899.     lea    12(A0),A0        ; Overread e.g. FORM####ANHD
  9900.     sub.l    #12,D0            ; i.e. point to e.g. DLTA chunk (FORM####ANHDDLTA####)
  9901.     bra.s    .checkChunk        ;                         ¯¯¯¯
  9902.  
  9903. .parse
  9904.     addq.l    #8,A0            ; Overread chunk-name and its size
  9905.     subq.l    #8,D0
  9906.     bmi.w    .errIncomplete_1    ; Upon error
  9907.  
  9908.     cmpi.l    #'CHRS',D1        ; Characters?
  9909.     beq.s    .copyTxt
  9910.  
  9911.     cmpi.l    #'RULE',D1        ; Or a ruler which is interpreted as a LineFeed
  9912.     beq.w    .SetLF
  9913.  
  9914.     cmpi.l    #'WTXT',D1        ; Characters?
  9915.     beq.s    .copyTxt
  9916.  
  9917.     addq.l    #1,D2            ; Make chunk-size even
  9918.     andi.l    #-2,D2
  9919.  
  9920.     add.l    D2,A0            ; Pointer to next chunk
  9921.     sub.l    D2,D0
  9922.     bra.s    .checkChunk        ; And search again...
  9923.  
  9924. .copyTxt
  9925.     move.l    D2,D1            ; Size of this chunk
  9926.  
  9927.     addq.l    #1,D2            ; Make chunk-size even
  9928.     andi.l    #-2,D2
  9929.  
  9930.     tst.l    D1            ; Chunk-size == 0?
  9931.     beq.s    .OnlyLF            ; Interpret as linefeed
  9932.  
  9933.     movea.l    A0,A1            ; Source of characters
  9934.     bra.s    .cpy
  9935. .cpyChar
  9936.     cmpi.b    #9,(A1)            ; Tab?
  9937.     bne.s    .store            ; ...if not
  9938.     addq.b    #7,D6            ; Else, this char [1] (Tab) + [7]
  9939.     andi.b    #-8,D6            ; on a position which is divisable by eight
  9940. *    subq.b    #1,D6            ; Minus 1, because 2 lines further we add one...
  9941. .store
  9942.     cmpi.b    #$9B,(A1)        ; CSI?
  9943.     beq.s    .ignoredouble        ; Ignore CSI
  9944.     cmpi.b    #15,(A1)        ; Ignore shift-in etc.
  9945.     beq.s    .addLineFeed
  9946.     cmpi.b    #16,(A1)
  9947.     beq.s    .ignore
  9948.     cmpi.b    #17,(A1)
  9949.     beq.s    .ignore
  9950.     cmpi.b    #18,(A1)
  9951.     beq.s    .ignore
  9952.     move.b    (A1)+,(A2)+        ; Copy characters
  9953.     cmpi.b    #10,-1(A2)        ; A new line?
  9954.     beq.s    .reset
  9955.     addq.b    #1,D6            ; New line length plus 1
  9956.     cmp.b    D7,D6            ; Range limit reached?
  9957.     bls.s    .cpy            ; If not yet reached...
  9958.     bra.s    .findterminator        ; Else, split line...
  9959. .reset
  9960.     moveq    #0,D6
  9961.     bra.s    .cpy
  9962. .addLineFeed
  9963.     addq.l    #1,A1
  9964.     move.b    #10,(A2)+
  9965.     moveq    #0,D6
  9966.     bra.s    .cpy
  9967.  
  9968. .ignoredouble
  9969.     addq.l    #1,A1
  9970.     subq.l    #1,D1
  9971.     subq.l    #1,D4
  9972. .ignore
  9973.     addq.l    #1,A1
  9974.     subq.l    #1,D4
  9975. .cpy
  9976.     subq.l    #1,D1            ; One less...
  9977.     bcc.s    .cpyChar
  9978.  
  9979.     add.l    D2,A0            ; Pointer to next chunk
  9980.     sub.l    D2,D0
  9981.     bra.w    .checkChunk        ; and restart...
  9982.  
  9983. .OnlyLF    ; <- Chunk-size of CHRS-chunk zero!!!
  9984.     move.b    #10,(A2)+        ; Add a LineFeed at the end of each line
  9985.  
  9986.     add.l    D2,A0            ; Pointer to next chunk
  9987.     sub.l    D2,D0
  9988.  
  9989.     moveq    #0,D6            ; No chars in this line at the moment!
  9990.  
  9991.     bra.w    .checkChunk        ; Restart
  9992.  
  9993. .SetLF    ; <- RULER
  9994.     move.b    #10,(A2)+        ; Add a LineFeed at the end of each line
  9995.  
  9996.     addq.l    #1,D2            ; Make chunk-size even
  9997.     andi.l    #-2,D2
  9998.  
  9999.     add.l    D2,A0            ; Pointer to next chunk
  10000.     sub.l    D2,D0
  10001.  
  10002.     moveq    #0,D6            ; No chars in this line at the moment!
  10003.  
  10004.     bra.w    .checkChunk        ; Restart
  10005.  
  10006. .findterminator
  10007.     move.l    A2,-(sp)
  10008.     subq.l    #1,A2            ; Pointer to last stored char
  10009.     moveq    #0,D6            ; Chars in next line (this line will be split into two part)
  10010. .loop
  10011.     subq.l    #1,A2            ; One less char
  10012.     addq.b    #1,D6            ; Amount of chars in newline plus one
  10013.     cmp.b    D7,D6            ; Range checking...
  10014.     bhi.s    .err
  10015.     cmpi.b    #9,1(A2)        ; Tab?
  10016.     beq.s    .found            ; <- Replace Tab through LineFeed
  10017.     cmpi.b    #' ',1(A2)        ; Blank
  10018.     bne.s    .loop            ; If not
  10019. .found
  10020.     move.b    #10,1(A2)        ; Replace Blank or Tab through LineFeed
  10021.     movea.l    (sp)+,A2
  10022.     bra.s    .cpy
  10023.  
  10024. .err                    ; A line without any Blanks or Tabs
  10025.     moveq    #0,D6
  10026.     movea.l    (sp)+,A2
  10027.     bra.s    .cpy
  10028.  
  10029. ***** HELLO *****
  10030.  
  10031. .done
  10032.     move.b    #10,(A2)        ; Write as last char of ascii-file the LineFeed!
  10033.     addq.l    #1,D4
  10034.  
  10035.     bsr.w    _FreeFile        ; Free old (not more needed datas)
  10036.  
  10037.     move.l    A3,_TextPtr(A5)        ; Set up source
  10038.     move.l    D4,_FileSize(A5)    ; Set up source's size (plain ascii-chars)
  10039.     move.l    D5,_BufferSize(A5)    ; Set up source's size (extended)
  10040.     rts
  10041.  
  10042. .errNoMem
  10043.     lea    _NoFreeStoreTxt(pc),A0
  10044.     bsr.w    _DisplayError
  10045.     bra.w    _CheckFile_1        ; Set up as binary
  10046. .errNonStd
  10047.     lea    _NoAsciiDatasTxt(pc),A0
  10048.     bsr.w    _DisplayError
  10049.     bra.w    _CheckFile_1        ; Set up as binary
  10050. .errIncomplete_1
  10051.     movea.l    A3,A1
  10052.     move.l    D4,D0
  10053.     movea.l    _SysBase(A5),A6
  10054.     jsr    _LVOFreeMem(A6)
  10055. .errIncomplete
  10056.     lea    _IncompleteIFFTxt(pc),A0
  10057.     bsr.w    _DisplayError
  10058.     bra.w    _CheckFile_1        ; Set up as binary
  10059.  
  10060. ********************************************************
  10061. *
  10062. * StrToLong( ULONG mask, char *buffer );
  10063. *
  10064. *
  10065. * Convert an ascii-string into computer internal number.
  10066. * Converted are: dual, decimal, signed decimal and
  10067. * hexadecimal ascii-strings.
  10068. *
  10069. * Valid terminators for the string-counts are: NULL-byte,
  10070. * tabulator, LineFeed, Blank (Space) and the comma.
  10071. *
  10072. * Introducion for strings:
  10073. * "#" = decimal (max. 10 chars for count)
  10074. * ""  = decimal (max. 10 chars for count)
  10075. * "+" = decimal (max. 10 chars for count)
  10076. *
  10077. * "-" = signed decimal (max. 10 chars for count)
  10078. *
  10079. * "0x" = sedecimal (hexadecimal) (max. 8 chars for count)
  10080. * "$"  = sedecimal (hexadecimal) (max. 8 chars for count)
  10081. *
  10082. * "%"  = dual (max. 32 chars for count)
  10083. *
  10084. * Inputs:  D0 - when NULL (zero) the routine is working normal.
  10085. *        - You can put a key-byte (mask) into D0 - the
  10086. *          subroutine is called then directly without
  10087. *          checking introducing arguments, note: in this
  10088. *          case no introducion has to be set in the ascii-
  10089. *          string, eg: D0 contains the "$" char - then
  10090. *          the ascii-string must be pointed to a plain
  10091. *          text, eg. "0003f000" - result here: converted
  10092. *          string to hexadecimal.
  10093. *       A0 - Pointer to the string which should be converted.
  10094. * Results: Count in D0
  10095. *       D1 contains -1L on error
  10096. *          A0 points to next argument if no error occured,
  10097. *       otherwise check -1(A0) and (A0) for the error,
  10098. *       it holds the char which caused the error!
  10099. *
  10100. *
  10101.  
  10102.     XDEF    _StrToLong
  10103. _StrToLong
  10104.     movem.l    D2-D3,-(sp)
  10105.  
  10106. *
  10107. ** When called as C-stub, set following two lines.
  10108. *
  10109.     ;move.l    12(sp),D0
  10110.     ;move.l    16(sp),A0
  10111.  
  10112.  
  10113.     move.w    D0,D2            ; Save mask
  10114.  
  10115.     moveq    #0,D0            ; Count to return
  10116.     move.l    D0,D1            ; Local count-buffer
  10117.  
  10118.     tst.w    D2            ; Mask set?
  10119.     beq.s    .Sneek            ; No, do it normal
  10120.  
  10121.     cmpi.b    #'$',D2            ; Hexadecimal?
  10122.     beq.w    .Hex_01
  10123.     cmpi.w    #'0x',D2        ; Hexadecimal?
  10124.     beq.w    .Hex_01
  10125.     cmpi.b    #'#',D2            ; Decimal?
  10126.     beq.w    .Dec_01
  10127.     cmpi.b    #' ',D2            ; Decimal?
  10128.     beq.w    .Dec_01
  10129.     cmpi.b    #'-',D2            ; Signed decimal?
  10130.     beq.s    .SignedDec_01
  10131.     cmpi.b    #'%',D2            ; Dual?
  10132.     beq.w    .Dual_01
  10133.  
  10134. .Sneek
  10135. *
  10136. ** Find chars we have to skip...
  10137. *
  10138.  
  10139.     cmpi.b    #9,(A0)            ; Tab-key?
  10140.     beq.s    .Skip
  10141.     cmpi.b    #' ',(A0)        ; Blank?
  10142.     beq.s    .Skip
  10143.     cmpi.b    #'!',(A0)        ; For complex string arguments
  10144.     beq.s    .Skip
  10145.     cmpi.b    #'|',(A0)        ; For complex string arguments
  10146.     beq.s    .Skip
  10147.     cmpi.b    #',',(A0)        ; Comma?
  10148.     beq.s    .Skip
  10149.     cmpi.b    #';',(A0)        ; Semicolon?
  10150.     beq.s    .Skip
  10151. *
  10152. ** Check if an interrupted end...
  10153. *
  10154.     tst.b    (A0)            ; End?
  10155.     beq.w    .Error_StringToLong
  10156.     cmpi.b    #10,(A0)        ; CR (LF)?
  10157.     beq.w    .Error_StringToLong
  10158. *
  10159. ** Parse argument (string's introducion)...
  10160. *
  10161.     cmpi.b    #'-',(A0)        ; Minus-char?
  10162.     beq.s    .SignedDec
  10163.     cmpi.b    #'+',(A0)        ; Plus-char?
  10164.     beq.w    .Dec
  10165.     cmpi.b    #'$',(A0)        ; Hex-char?
  10166.     beq.s    .Hex
  10167.     cmpi.b    #'%',(A0)        ; Dual-char?
  10168.     beq.w    .Dual
  10169.     cmpi.b    #'#',(A0)        ; Sometimes used for decimal introducion
  10170.     beq.w    .Dec
  10171.     cmpi.b    #'0',(A0)        ; Zero-char?
  10172.     bne.w    .Dec_01
  10173.     cmpi.b    #'x',1(A0)        ; 0x == C-introducion for hex
  10174.     bne.w    .Dec_01
  10175.     addq.l    #1,A0            ; Overread '0' of '0x'
  10176.     bra.s    .Hex
  10177.  
  10178. * ----------------------- *
  10179.  
  10180. .Skip
  10181.     addq.l    #1,A0
  10182.     bra.s    .Sneek
  10183.  
  10184. * ----------------------- *
  10185.  
  10186. .SignedDec
  10187.     addq.l    #1,A0            ; Overread sign
  10188. .SignedDec_01
  10189.     moveq    #9,D2            ; 10 chars to convert
  10190. .SDC
  10191.     tst.b    (A0)            ; End?
  10192.     beq.s    .End_SDC
  10193.     cmpi.b    #9,(A0)            ; Tab-key?
  10194.     beq.s    .End_SDC
  10195.     cmpi.b    #10,(A0)        ; CR (LF)-key?
  10196.     beq.s    .End_SDC
  10197.     cmpi.b    #' ',(A0)        ; Blank-key?
  10198.     beq.s    .End_SDC
  10199.     cmpi.b    #',',(A0)        ; Comma-key?
  10200.     beq.s    .End_SDC
  10201.  
  10202.     move.b    (A0)+,D1        ; Get char
  10203.     cmpi.b    #'0',D1
  10204.     blt.w    .Error_StringToLong
  10205.     cmpi.b    #'9',D1
  10206.     bhi.w    .Error_StringToLong
  10207.     subi.b    #48,D1            ; Computer intern number
  10208.     move.l    D0,D3            ; Save D0
  10209.     lsl.l    #3,D0            ; D0 * 8
  10210.     add.l    D3,D3            ; D3 * 2
  10211.     add.l    D3,D0            ; == mulu.l #10,D0
  10212.     add.l    D1,D0            ; Store new nibble
  10213.     dbf    D2,.SDC
  10214. .End_SDC
  10215.     neg.l    D0
  10216.     bra.w    .End_StringToLong
  10217.  
  10218. * ----------------------- *
  10219. .Hex
  10220.     addq.l    #1,A0            ; Overread introducion
  10221. .Hex_01
  10222.     moveq    #7,D2            ; 8 chars to convert
  10223. .HC
  10224.     tst.b    (A0)            ; End?
  10225.     beq.w    .End_StringToLong
  10226.     cmpi.b    #9,(A0)            ; Tab-key?
  10227.     beq.w    .End_StringToLong
  10228.     cmpi.b    #10,(A0)        ; CR (LF)-key?
  10229.     beq.w    .End_StringToLong
  10230.     cmpi.b    #' ',(A0)        ; Blank-key?
  10231.     beq.w    .End_StringToLong
  10232.     cmpi.b    #',',(A0)        ; Comma-key?
  10233.     beq.w    .End_StringToLong
  10234.  
  10235.     move.b    (A0)+,D1        ; Get char
  10236.     cmpi.b    #'0',D1            ; 0-char?
  10237.     blt.w    .Error_StringToLong
  10238.     cmpi.b    #'9',D1            ; 9-char
  10239.     bls.s    .OkHC
  10240.  
  10241.     bclr.l    #5,D1            ; To uppercase
  10242.     cmpi.b    #'F',D1            ; F-char
  10243.     bhi.w    .Error_StringToLong
  10244.     cmpi.b    #'A',D1            ; A-char?
  10245.     blt.w    .Error_StringToLong
  10246.     subi.b    #55,D1
  10247.     lsl.l    #4,D0            ; Room for nibble
  10248.     or.l    D1,D0            ; Store new nibble
  10249.     dbf    D2,.HC    
  10250.     bra.w    .End_StringToLong
  10251. .OkHC    
  10252.     subi.b    #48,D1            ; Computer intern number
  10253.     lsl.l    #4,D0            ; Room for nibble
  10254.     or.l    D1,D0            ; Store new nibble
  10255.     dbf    D2,.HC
  10256.     bra.w    .End_StringToLong
  10257.  
  10258. * ----------------------- *
  10259. .Dec
  10260.     addq.l    #1,A0            ; Overread introducion
  10261. .Dec_01
  10262.     moveq    #9,D2            ; 10 chars to convert
  10263. .DC
  10264.     tst.b    (A0)            ; End?
  10265.     beq.w    .End_StringToLong
  10266.     cmpi.b    #9,(A0)            ; Tab-key?
  10267.     beq.s    .End_StringToLong
  10268.     cmpi.b    #10,(A0)        ; CR (LF)-key?
  10269.     beq.s    .End_StringToLong
  10270.     cmpi.b    #' ',(A0)        ; Blank-key?
  10271.     beq.s    .End_StringToLong
  10272.     cmpi.b    #',',(A0)        ; Comma-key?
  10273.     beq.s    .End_StringToLong
  10274.  
  10275.     move.b    (A0)+,D1        ; Get char
  10276.     cmpi.b    #'0',D1
  10277.     blt.s    .Error_StringToLong
  10278.     cmpi.b    #'9',D1
  10279.     bhi.s    .Error_StringToLong
  10280.     subi.b    #48,D1            ; Computer intern number
  10281.     move.l    D0,D3            ; Save D0
  10282.     lsl.l    #3,D0            ; D0 * 8
  10283.     add.l    D3,D3            ; D3 * 2
  10284.     add.l    D3,D0            ; == mulu.l #10,D0
  10285.     add.l    D1,D0            ; Store new nibble
  10286.     dbf    D2,.DC
  10287.     bra.s    .End_StringToLong
  10288.  
  10289. * ----------------------- *
  10290.  
  10291. .Dual
  10292.     addq.l    #1,A0            ; Overread '%'
  10293. .Dual_01
  10294.     moveq    #31,D2            ; 32 chars to convert
  10295. .DUC
  10296.     tst.b    (A0)            ; End?
  10297.     beq.s    .End_StringToLong
  10298.     cmpi.b    #9,(A0)            ; Tab-key?
  10299.     beq.s    .End_StringToLong
  10300.     cmpi.b    #10,(A0)        ; CR (LF)-key?
  10301.     beq.s    .End_StringToLong
  10302.     cmpi.b    #' ',(A0)        ; Blank-key?
  10303.     beq.s    .End_StringToLong
  10304.     cmpi.b    #',',(A0)        ; Comma-key?
  10305.     beq.s    .End_StringToLong
  10306.     cmpi.b    #'.',(A0)        ; A dot set between?
  10307.     beq.s    .Skip_Dot
  10308.  
  10309.     move.b    (A0)+,D1        ; Get char
  10310.     subi.b    #48,D1            ; Computer internal number
  10311.     cmpi.b    #1,D1
  10312.     bhi.s    .Error_StringToLong
  10313.     add.l    D0,D0            ; Base = 2 - so add it!
  10314.     add.l    D1,D0            ; Add also new count
  10315.     dbf    D2,.DUC
  10316.     bra.s    .End_StringToLong
  10317.  
  10318. .Skip_Dot
  10319.     addq.l    #1,A0
  10320.     bra.s    .DUC
  10321. * ----------------------- *
  10322.  
  10323. .Error_StringToLong
  10324.     movem.l    (sp)+,D2-D3
  10325.     moveq    #-1,D1
  10326.     rts
  10327.  
  10328. .End_StringToLong
  10329.     movem.l    (sp)+,D2-D3
  10330.     moveq    #0,D1
  10331.     rts
  10332.  
  10333. * ----------------------------------------------------- *
  10334. *                            *
  10335. *                            *
  10336. *            Data Array            *
  10337. *                            *
  10338. *                            *
  10339. * ----------------------------------------------------- *
  10340.  
  10341. _Divutable
  10342.     dc.l    1000000000
  10343.     dc.l    100000000
  10344.     dc.l    10000000
  10345.     dc.l    1000000
  10346.     dc.l    100000
  10347.     dc.l    10000
  10348.     dc.l    1000
  10349.     dc.l    100
  10350.     dc.l    10
  10351.     dc.l    1
  10352.  
  10353.  
  10354. _Image.1
  10355.     dc.w    0,0,74,19,%1
  10356.     dc.l    0
  10357.     dc.b    %1,%10            ; Plane pick, plane off
  10358.     dc.l    0
  10359.  
  10360. _Image.2
  10361.     dc.w    0,0,74,19,%1
  10362.     dc.l    0
  10363.     dc.b    %1,%10            ; Plane pick, plane off
  10364.     dc.l    0
  10365.  
  10366. _Image.3
  10367.     dc.w    0,0,45,28,%11
  10368.     dc.l    0
  10369.     dc.b    %11,%0            ; Plane pick, plane off
  10370.     dc.l    0
  10371.  
  10372. _Image.4
  10373.     dc.w    0,0,45,28,%11
  10374.     dc.l    0
  10375.     dc.b    %11,%0            ; Plane pick, plane off
  10376.     dc.l    0
  10377.  
  10378. _Channels
  10379.     dc.b    1,2,4,8            ; One of those channels I want to allocate...
  10380.  
  10381. _GStr1
  10382.     dc.b    'Ok',0
  10383. _GStr2
  10384.     dc.b    'Abort',0
  10385. _ScreenName
  10386.     dc.b    'Viewer''s image screen',0
  10387. _WindowName
  10388.     dc.b    ' Viewer V4.4 - © 92-99 ONIX',0
  10389. _IntuitionName
  10390.     dc.b    'intuition.library',0
  10391. _GfxName
  10392.     dc.b    'graphics.library',0
  10393. _DiskFontName
  10394.     dc.b    'diskfont.library',0
  10395. _DeviceName
  10396.     dc.b    'console.device',0
  10397. _AudioName
  10398.     dc.b    'audio.device',0
  10399. _ReqToolsName
  10400.     dc.b    'reqtools.library',0
  10401. _ArpName
  10402.     dc.b    'arp.library',0
  10403. _CyberGfxName
  10404.     dc.b    'cybergraphics.library',0
  10405.  
  10406. _AWTitle
  10407.     dc.b    'Load A File...',0
  10408. _SaveTitle
  10409.     dc.b    'Save Text File As...',0
  10410. _PageDef
  10411.     dc.b    'SCROLLWIDTH=',0
  10412. _WindowDef
  10413.     dc.b    'EXTENTWINDOW=',0
  10414. _WrapDef
  10415.     dc.b    'WRAP=ON',0
  10416. _FontSpecName
  10417.     dc.b    'FONT=',0
  10418. _OffsetSpecName
  10419.     dc.b    'WINDOWOFFSET=',0
  10420. _NoWarningName
  10421.     dc.b    'NOWARN',0
  10422. _NoCheckPrinterTxt
  10423.     dc.b    'NOPRTCHECK',0
  10424. _ExecuteTxt
  10425.     dc.b    'EXECUTE=',0
  10426. _NilName
  10427.     dc.b    'NIL:',0
  10428. * --------------------------------------------------- *
  10429.  
  10430. _HelpText
  10431.     dc.b    $9B,'1;31;42m'
  10432.     dc.b    'CRSR-down  :-) (n) lines down   ',10
  10433.     dc.b    'CRSR-up    :-) (n) lines up     ',10
  10434.     dc.b    'CRSR-right :-) line down        ',10
  10435.     dc.b    'CRSR-left  :-) line up          ',10
  10436.     dc.b    'L-Key      :-) load new file    ',10
  10437.     dc.b    'E-Key      :-) enlarge window   ',10
  10438.     dc.b    'H-Key      :-) this page        ',10    
  10439.     dc.b    'A-Key      :-) about page       ',10
  10440.     dc.b    'R-Key      :-) restore page     ',10
  10441.     dc.b    'T/B-Keys   :-) toggle Top/Bottom',10 
  10442.     dc.b    'HOME/END   :-) toggle Top/Bottom',10
  10443.     dc.b    'PgUp/PgDn  :-) PageUp/PageDown  ',10
  10444.     dc.b    'Ret/Enter  :-) one line down    ',10
  10445.     dc.b    'SHIFT-R    :-) single step back ',10    
  10446.     dc.b    'S_KEY      :-) search for string',10
  10447.     dc.b    'N-Key      :-) next occurrence  ',10    
  10448.     dc.b    'P/F        :-) file to prt/file ',10
  10449.     dc.b    'W/C-Keys   :-) page to prt/file ',10 
  10450.     dc.b    'PrtSc      :-) page to prt      ',10 
  10451.     dc.b    $1B,'[0m'
  10452.                         
  10453.     dc.b    $9B,$48                    ; Cursor Home
  10454.     dc.b    $9B,'33C','  For more details read',10
  10455.     dc.b    $9B,'33C','  Viewer.doc.',10,10
  10456.     dc.b    $9B,'33C','  Press any key to continue.',10
  10457. _HelpTextEnd
  10458.  
  10459.  
  10460. _SearchText
  10461.     dc.b    $1B,'c',10,$1B,'[1mSearch for: ',$1B,'[0m'
  10462. _SearchTextEnd
  10463.  
  10464. *
  10465. ** The first byte of a string contains the upper offset (Y-coordinate)
  10466. ** where the text start (X-offset is computed). A linefeed (10) tells
  10467. ** that a second (or more) string line(s) follow. NULL indicates the
  10468. ** end of the string(s).
  10469. ** If you have strings which only contain one line, the linefeed must
  10470. ** also be set, also the NULL-byte (i.e. "30,'Decrunching failed!',10,0").
  10471. *
  10472.  
  10473. _NoFileMsg
  10474.     dc.b    22,'You didn''t pick a file.',10
  10475.     dc.b    'Press key "L" to load one.',10,0
  10476. _ErrorOpenWindowTxt
  10477.     dc.b    8,'Couldn''t open main-window with',10
  10478.     dc.b    'leftedge at %d, topedge at %d -',10
  10479.     dc.b    'with a width of %d pixels and a',10
  10480.     dc.b    'height of %d rows!',10,0
  10481. _ErrorOpenDevTxt
  10482.     dc.b    22,'Couldn''t open the',10
  10483.     dc.b    '"console.device". Terminating.',10,0
  10484. _EmptyTxt
  10485.     dc.b    22,'Selected file contains no',10
  10486.     dc.b    'datas. Loading file terminated.',10,0
  10487. _DirTxt
  10488.     dc.b    22,'You have chosen a directory and',10
  10489.     dc.b    'I expected a file.',10,0
  10490. _ReadErrTxt
  10491.     dc.b    22,'Could not load that file, it',10
  10492.     dc.b    'has a read error.',10,0
  10493. _OpenFileErrTxt
  10494.     dc.b    30,'Could not open file.',10,0
  10495. _AllocErrTxt
  10496.     dc.b    22,'Impossile to allocate memory',10
  10497.     dc.b    'for this file.',10,0
  10498. _ExamineErrTxt
  10499.     dc.b    30,'DOS function examine failed!',10,0
  10500. _LockErrTxt
  10501.     dc.b    22,'Cannot get lock of file, thus',10
  10502.     dc.b    'I cannot examine the file!',10,0
  10503. _ObjectFileTxt
  10504.     dc.b    8,'The selected file is an object',10
  10505.     dc.b    'module, shall I display its',10
  10506.     dc.b    'contents?',10
  10507.     dc.b    '(Converted size: %ld bytes)',10,0
  10508. _BinaryFileTxt
  10509.     dc.b    8,'The selected file contains ',10
  10510.     dc.b    'binary datas.',10
  10511.     dc.b    'Shall I display them?',10
  10512.     dc.b    '(Converted size: %ld bytes)',10,0
  10513. _NoReqTxt
  10514.     dc.b    22,'Impossible to work without',10
  10515.     dc.b    'ReqTools or Arp libraries!',10,0
  10516. _OpenPrintErrTxt
  10517.     dc.b    22,'Unable to open file or printer',10
  10518.     dc.b    'for output. Printjob aborted.',10,0
  10519. _WriteErrTxt
  10520.     dc.b    22,'Error while printing file.',10
  10521.     dc.b    'Printjob aborted.',10,0
  10522. _PrintFileTxt
  10523.     dc.b    30,'Going to write whole file...',10,0
  10524. _PrintContentsTxt
  10525.     dc.b    30,'Going to write window contents...',10,0
  10526. _PrintCancelTxt
  10527.     dc.b    30,'Job cancelled.',10,0
  10528. _PrinterOFFTxt
  10529.     dc.b    16,'Printer is turned off or',10
  10530.     dc.b    'there is no printer.',10
  10531.     dc.b    'Printing failed.',10,0
  10532. _NotOnelineTxt
  10533.     dc.b    22,'Your printer is not online.',10
  10534.     dc.b    'Printing failed.',10,0
  10535.  
  10536. * - These messages I love... -
  10537.  
  10538. _AboutTxt
  10539.     dc.b    8,'Date: 12/08/1999  10:22:29 pm',10
  10540.     dc.b    'Programmer: Joerg van de Loo.',10
  10541.     dc.b    'Simple text, binary and image viewer.',10
  10542.     dc.b    'Granted to use free of charge.',10,0
  10543. _InfoTxt
  10544.     dc.b    8,'CODE %ld - DATA %ld bytes,',10
  10545.     dc.b    'DATA-CHIP = %ld bytes,',10
  10546.     dc.b    'BSS = %ld bytes.',10
  10547.     dc.b    'Assembled with HiSoft Devpac Amiga.',10,0
  10548.  
  10549. * - Messages for PowerPacker(.library) support -
  10550.  
  10551. _PPCrunchTxt
  10552.     dc.b    8,'This is a PowerPacker',10
  10553.     dc.b    '(library) packed file.',10
  10554.     dc.b    'Unpacked length: %ld bytes.',10
  10555.     dc.b    'Shall I unpack it?',10,0
  10556.  
  10557. _DecrunchErrTxt
  10558.     dc.b    30,'Decrunching failed!',10,0
  10559.  
  10560. * - Message for displaying/loading pictures -
  10561.  
  10562. _ILBMTxt
  10563.     dc.b    22,'This is an IFF-ILBM file.',10
  10564.     dc.b    'Shall I display it?',10,0
  10565. _ACBMTxt
  10566.     dc.b    22,'This is an IFF-ACBM file.',10
  10567.     dc.b    'Shall I display it?',10,0
  10568. _ImageInfoTxt
  10569.     dc.b    8,'Screen: %d * %d pixels.',10
  10570.     dc.b    'Bitmap: %d * %d pixels.',10
  10571.     dc.b    'Image: %d * %d pixels.',10
  10572.     dc.b    '%ld colours, %ld bytes.',10,0
  10573. _WarnMaskingTxt
  10574.     dc.b    8,'WARNING:',10
  10575.     dc.b    'IFF makes use of masking.',10
  10576.     dc.b    'This isn''t 100% supported.',10
  10577.     dc.b    'Strange output may occur!',10,0
  10578. _WarnUncompressedTxt
  10579.     dc.b    22,'INFORMATION:',10
  10580.     dc.b    'IFF already uncompressed.',10,0
  10581. _IncorrectSizeTxt
  10582.     dc.b    22,'ERROR:',10
  10583.     dc.b    'Corrupt IFF-file!',10,0
  10584. _NoByteRunTxt
  10585.     dc.b    22,'ERROR:',10
  10586.     dc.b    'Unknown compression method!',10,0
  10587. _AllocBufErrTxt
  10588.     dc.b    30,'Error allocating bitmaps!',10,0
  10589. _NoIFFFileTxt
  10590.     dc.b    22,'Bad or incomplete IFF!',10
  10591.     dc.b    'Perhaps only a palette file?',10,0
  10592. _ErrorOpeningScreen
  10593.     dc.b    22,'Can''t open monitor/screen...',10
  10594.     dc.b    'Too many bitplanes?!?!?',10,0
  10595. _ErrorInvalidIDTxt
  10596.     dc.b    16,'Cannot find right monitor for',10
  10597.     dc.b    'installed alien gfx-board which',10
  10598.     dc.b    'does support this resolution!',10,0
  10599.  
  10600. * - Messages for converting IFF to ASCII -
  10601.  
  10602. _IFFAsciiTxt
  10603.     dc.b    16,'This IFF-file perhaps',10
  10604.     dc.b    'contains embedded strings.',10
  10605.     dc.b    'Shall I try to extract them?',10,0
  10606. _NoFreeStoreTxt
  10607.     dc.b    16,'Cannot allocate buffer',10
  10608.     dc.b    'to store plain ASCII-',10
  10609.     dc.b    'characters. Extracting aborted',10,0
  10610. _NoAsciiDatasTxt
  10611.     dc.b    16,'This file does not contain',10
  10612.     dc.b    'ASCII-characters at all or I',10
  10613.     dc.b    'cannot handle them!',10,0
  10614. _IncompleteIFFTxt
  10615.     dc.b    16,'IFF-file does not contain',10
  10616.     dc.b    'all chunks it should have.',10
  10617.     dc.b    'Incomplete (bad) IFF-file!',10,0
  10618.  
  10619. * - Messages for audio files -
  10620.  
  10621. _8SVXTxt
  10622.     dc.b    22,'This is an audio file.',10
  10623.     dc.b    'Shall I make it audible?',10,0
  10624. _8SVXErrTxt
  10625.     dc.b    8,'Error during setup of',10
  10626.     dc.b    '8SVX file. VHDR on invalid',10
  10627.     dc.b    'position or I simply ran out of',10
  10628.     dc.b    'memory!',10,0
  10629. _AudErrTxt
  10630.     dc.b    22,'Error while attempting to make',10
  10631.     dc.b    'datas audible; channel stolen?',10,0
  10632.  
  10633. * - The standard...
  10634.  
  10635. _ProgID
  10636.     dc.b    '$VER: Viewer 4.4 (12.08.99)'
  10637. *                    ^^^^
  10638. *               Internal: 4
  10639.     dc.b    '© 1992-99 J.v.d.Loo (ONIX) - IFF-TEXT/ILBM/ACBM/8SVX viewer; RTG emulation.',0
  10640. _EndDatas
  10641.  
  10642. ****************************************************************
  10643. *
  10644. * Image-data. Datas for gadgets, 1 colour, 190 bytes (for each).
  10645. *
  10646.  
  10647.     SECTION    GadgetImage,DATA_C
  10648. _Gad.1
  10649.     dc.w    $AAAA,$AAAA,$AAAA,$AAAA,$AAC0,$D555,$5555,$5555,$5555,$55C0
  10650.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10651.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10652.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10653.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10654.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10655.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10656.     dc.w    $A000,$0000,$0000,$0000,$01C0,$C000,$0000,$0000,$0000,$01C0
  10657.     dc.w    $A000,$0000,$0000,$0000,$01C0,$DFFF,$FFFF,$FFFF,$FFFF,$FFC0
  10658.     dc.w    $FFFF,$FFFF,$FFFF,$FFFF,$FFC0
  10659.  
  10660. _Gad.2
  10661.     dc.w    $FFFF,$FFFF,$FFFF,$FFFF,$FFC0,$FFFF,$FFFF,$FFFF,$FFFF,$FEC0
  10662.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10663.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10664.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10665.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10666.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10667.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10668.     dc.w    $E000,$0000,$0000,$0000,$0140,$E000,$0000,$0000,$0000,$00C0
  10669.     dc.w    $E000,$0000,$0000,$0000,$0140,$EAAA,$AAAA,$AAAA,$AAAA,$AAC0
  10670.     dc.w    $D555,$5555,$5555,$5555,$5540
  10671.  
  10672. *
  10673. ** Normal Audio Image: 45 x 28 x 2, bitmap: 48 x 28 x 2 (336 bytes)
  10674. *
  10675. _AudioGad.1_1
  10676.     dc.w    $0000,$0000,$0000,$0000,$0000,$0008,$0000,$0000,$0008,$0000
  10677.     dc.w    $0400,$0048,$0000,$0A00,$0048,$0000,$1A00,$0048,$0000,$2A00
  10678.     dc.w    $0048,$0000,$4A00,$0048,$003C,$8A00,$0048,$0043,$8A00,$0048
  10679.     dc.w    $0042,$8A00,$0048,$0042,$8A00,$0048,$0042,$8A00,$0048,$0042
  10680.     dc.w    $8A00,$0048,$0042,$8A00,$0048,$0042,$8A00,$0048,$0042,$8A00
  10681.     dc.w    $0048,$0043,$8A00,$0048,$003C,$8A00,$0048,$0000,$4A00,$0048
  10682.     dc.w    $0000,$2A00,$0048,$0000,$1A00,$0048,$0000,$0A00,$0048,$0000
  10683.     dc.w    $0400,$0048,$0FFF,$FFFF,$FFC8,$0000,$0000,$0008,$0000,$0000
  10684.     dc.w    $0008,$7FFF,$FFFF,$FFF8
  10685. _AudioGad.1_2
  10686.     dc.w    $FFFF,$FFFF,$FFF8,$8000,$0000,$0000,$8000,$0000,$0000,$9FFF
  10687.     dc.w    $FBFF,$FF80,$9555,$5455,$5500,$9555,$4455,$5500,$9555,$5455
  10688.     dc.w    $5500,$9555,$3455,$5500,$9541,$7455,$5500,$953C,$7455,$5500
  10689.     dc.w    $953D,$7455,$5500,$953D,$7455,$5500,$953D,$7455,$5500,$953D
  10690.     dc.w    $7455,$5500,$953D,$7455,$5500,$953D,$7455,$5500,$953D,$7455
  10691.     dc.w    $5500,$953C,$7455,$5500,$9540,$7455,$5500,$9540,$3455,$5500
  10692.     dc.w    $9550,$5455,$5500,$9555,$4455,$5500,$9555,$5455,$5500,$9555
  10693.     dc.w    $5155,$5500,$9000,$0000,$0000,$8000,$0000,$0000,$8000,$0000
  10694.     dc.w    $0000,$8000,$0000,$0000
  10695.  
  10696. *
  10697. ** Select Audio Image: 45 x 28 x 2, bitmap: 48 x 28 x 2 (336 bytes)
  10698. *
  10699. _AudioGad.2_1
  10700.     dc.w    $FFFF,$FFFF,$FFF0,$8000,$0000,$0000,$8000,$0200,$4000,$8000
  10701.     dc.w    $0500,$8000,$8000,$0D01,$0020,$8000,$1502,$0020,$8000,$2504
  10702.     dc.w    $0020,$801E,$4500,$1820,$8021,$C500,$6020,$8021,$4501,$8020
  10703.     dc.w    $8021,$4500,$0020,$8021,$4500,$0020,$8021,$4500,$FC20,$8021
  10704.     dc.w    $4500,$0020,$8021,$4500,$0020,$8021,$4501,$8020,$8021,$C500
  10705.     dc.w    $6020,$801E,$4500,$1820,$8000,$2504,$0020,$8000,$1502,$0020
  10706.     dc.w    $8000,$0D01,$0020,$8000,$0500,$8020,$8000,$0200,$4020,$8000
  10707.     dc.w    $0000,$0020,$8000,$0000,$0020,$87FF,$FFFF,$FFE0,$8000,$0000
  10708.     dc.w    $0000,$8000,$0000,$0000
  10709. _AudioGad.2_2
  10710.     dc.w    $0000,$0000,$0008,$0000,$0000,$0008,$0000,$0000,$0008,$0000
  10711.     dc.w    $0200,$0008,$0FFF,$F27E,$EFC8,$0AAA,$AA28,$8A88,$0AAA,$9A2A
  10712.     dc.w    $AA88,$0AA0,$BA2A,$2288,$0A9E,$3A2A,$8A88,$0A9E,$BA2A,$2888
  10713.     dc.w    $0A9E,$BA2A,$A288,$0A9E,$BA2A,$8A88,$0A9E,$BA2A,$0288,$0A9E
  10714.     dc.w    $BA2A,$AA88,$0A9E,$BA2A,$8088,$0A9E,$BA2A,$2A88,$0A9E,$3A2A
  10715.     dc.w    $8A88,$0AA0,$3A2A,$8288,$0AA0,$1A2A,$A288,$0AA8,$2A28,$A888
  10716.     dc.w    $0AAA,$A22A,$AA88,$0AAA,$AA2A,$2A88,$0AAA,$A82A,$AA88,$0AAA
  10717.     dc.w    $AA2A,$8A88,$0AAA,$AA2A,$AA88,$0800,$0000,$0008,$0000,$0000
  10718.     dc.w    $0008,$7FFF,$FFFF,$FFF8
  10719.  
  10720.     END
  10721.