home *** CD-ROM | disk | FTP | other *** search
- 4] ------------------------------------
- 3] LIRE (revised)
- 3] © by Charles VASSALLO
- 4] ------------------------------------
-
- (All rights reserved.)
-
- This is the second version of my minimal text reader, that reads text
- files and nothing more. It is a few bytes shorter (2044 instead of 2084) but
- one block less (5 instead of 6). Some bugs have been fixed; maybe new ones
- have appeared -- let me know. It lost a few peculiarities (no copper list
- now) but it gained a few additional features.
-
- (i) the cursor indicates the location in the text and allows you to directly
- jump anywhere you want to go, instead of flipping pages.
-
- (ii) more color features. The text is displayed in a 4-color window opened
- in a custom screen. The background is in color 1 and the text is normally
- printed in color 2, except for the lines beginning with codes 3] or 4], which
- are printed in color 3 or 4 respectively. Can be useful for highlighting
- titles, as shown above; this is commonly used throughout JUMPDISK.
- (By the way, I think that it would be more consistent with the internal
- operating system numeration to number colors from 0 to 3, but it is now
- customary to go from 1 to 4)
- The default palette (the colors you are presently seeing) is imposed by
- the program. This is a deliberate choice, my personal taste. If you don't
- share it , you can change the palette either by means of a little surgery
- on the binary file, or using the more fanciful color possibilities of the
- routine. More on this later on.
-
- There is no depth gadget. However, a custom screen is used for the
- display, so you can push it in the back or in the front of the other screens
- by pressing <left-AMIGA+ N> or <left-AMIGA + M>. The drawback of the custom
- screen is that it eats up 32 Kbytes of precious chip ram ; I also considered
- a less greedy version with a display in the Workbench screen, but I had to
- set up special hotkeys for screen switching (because AMIGA+N/M keys do not
- work with the various windows in the Workbench screen). All in all, I feel
- that the present version is simpler to use.
-
- In principle, lines are not truncated at 80 characters. Words that would
- be cut by the 80-th character limit are gently shifted to the next line.
- There are 2 intentional exceptions (not to mention those unintentional) :
- - lines with a first word larger than 80 characters, i.e. 80 characters or
- more without any space. What language do you speak? Or maybe you are
- reading a binary file? Such lines are definitely truncated.
- - lines where the 1st character is ']', for reasons that will be explained
- later on.
- Files can be prepared with any text editor. You can even use a text processor
- provided that you save the file as a plain ASCII file, otherwise all the
- control characters would be rendered as various uncontrolled hieroglyphs.
- For the same reason, try to avoid TAB codes. (Most of text editors designed
- for programmers can insert TAB codes. You can remove them with a special
- utility like 'Repstring' -- see JumpDisk, Sept.88 -- or by loading the file
- with ED and saving it).
-
- LIRE is re-executable and reentrant, i.e. it can be made resident. If
- anybody meets a guru after that, please tell me. Though the practical
- interest of making such a tiny text-reader resident is questionable, it was an
- interesting exercice to do so. Also, it allowed me to shorten the routine,
- mainly because a lot of local variables are now dynamically allocated by the
- system instead of being part of the program itself. Here are some details
- about that :
-
- ]]12 ]13 ]21
- ]]12 Traditional program ]13 Reentrant program ]21
- ]]12 ]13 ]21
- ]]12 Variables are directly reserved ]13 The direct reservation of memory for ]21
- ]]12 within the program itself, like ]13 local variables is replaced with a ]21
- ]]12 var1: dc.l 0 ]13 calculation of offsets, like ]21
- ]]12 var2: dc.w 0 ]13 var1=0 ]21
- ]]12 var3: dc.w 0 ]13 var2=var1+4 ]21
- ]]12 ............. ]13 var3=var2+2 ]21
- ]]12 and so on. The corresponding ]13 ........... ]21
- ]]12 memory is a physical part of ]13 total=last.var+4 ]21
- ]]12 the object file (that in your ]13 These numbers are calculated by the ]21
- ]]12 diskette). In the program, ]13 assembler and do not correspond to any ]21
- ]]12 variables are called with a ]13 physical memory. A block of 'total' ]21
- ]]12 direct addressing, like ]13 bytes is dynamically allocated and ]21
- ]]12 move.l var1,d0 ]13 its address is put into some address ]21
- ]]12 add.w var2,d0 ]13 register, let's say a4. The variables ]21
- ]]12 .............. ]13 are called with indirect addressing : ]21
- ]]12 Since a program can be loaded ]13 move.l var1(a4),d0 ]21
- ]]12 anywhere in the memory, DOS needs ]13 add.w var2(a4),d0 ]21
- ]]12 special information to relocate ]13 ................. ]21
- ]]12 the variables. This information ]13 The code is "position-independent". ]21
- ]]12 is provided by the assembler and ]13 ]21
- ]]12 it can somewhat increase the ]13 NO RELOCATION INFORMATION REQUIRED! ]21
- ]]12 length of the object file. ]13 ]21
- ]]12 ]13 ]21
-
- I thus obtained a routine with about 1800 bytes (the initial LIRE was
- 2084 bytes). However, since a 1800-byte file occupies the same place in a
- diskette as a 2048-byte files, i.e. 5 blocks, why not add some extra
- functions until the 5 blocks are filled ? I decided to add new color
- features, such as those just above. Similar features were already displayed
- in "Read2.0", by Thomas Beale (see JumpDisk, March 1989).
- Skeptical ? Color is vanity ? (But do you realize that you are using an
- Amiga ??) Well, you can find a reduced LIRE0 in this drawer. Only 1836 bytes
- long, without any more fanciful peculiarity than the ability to read the
- lines beginning with "c]". As for you, color-fancying readers, follow me!
-
- Color instructions must be set in the text file itself. Obviously, they
- don't improve its readeability when displayed with another reader, but
- after all, such files should not be normally displayed in that way. You are
- given two new possibilities :
- - you can change both pen and background colors anywhere in a line,
- - you can change the whole palette.
-
- ]]14 ]21
- ]]14 TO CHANGE PEN/BG COLORS LOCALLY, ]21 you must first inform the program that
- ]]14 ]21 there is a special coding in the line,
- by inserting "]" at its very beginning. Then, insert "]pb" (where p or b are
- 1,2,3,4) to set the pen color to "p" and the background color to "b", at the
- exact location where you wish the new colors to be set. For instance,
- the lines
-
- "] Now, default colors (pen=2 bg=1);]32 now, pen=3 bg=2;]14 now, pen=1 bg=4"
- "] Default again; ]13now, pen=1 bg=3 ]21"
-
- (actually without the double quotes) will be rendered as
-
- ] Now, default colors (pen=2 bg=1);]32 now, pen=3 bg=2;]14 now, pen=1 bg=4
- ] Default again; ]13now, pen=1 bg=3 ]21
-
- Notice that the default colors are restored at the final linefeed, just after
- the last character of the line; the next line begins with them. If you want a
- whole paragraph printed with special colors, you must insert a sequence ]]pb
- ahead of each line (a "]" to announce a special line, and "]pb" to switch
- colors immediately). Similarly, in the second line above, notice the extra ]21
- after the spaces to be rendered in the new background color; without it, ED
- would have put its linefeed just after the last character ("1") and the
- colored line would have stopped here.
-
- C]AA9004A22549
- ]]14 ]21
- ]]14 HOW TO CHANGE THE WHOLE PALETTE ]21 Inside the operating system, colors are
- ]]14 ]21 defined with their amounts of red, green
- and blue, coded as hex numbers from 0 to F (F=maximum value, 0=null value).
- The brightest white is thus FFF; a medium grey is 999; a dark green is 050;
- a clear reddish yellow (not the brightest) is B90, and so on.
- To change the palette, you just have to insert a special line, beginning
- with a code C], followed by the four triplets RGB, for the four colors of
- the workbench display (see below)
- Putting this line ahead of the whole file allows you to bypass the
- default colors of the routine.
-
- As an example ,let's assume that we want the following colors
- 1 (background), dark bluish gray : 445
- 2 (normal printing), bright pale yellow : BB9
- 3 (highlight 1) , medium cyan : 0AA
- 4 (highlight 2) , unsaturated red : F77
- The special command line will be
-
- "C]445BB90AAF77" (of course, no double quote; the C must be the 1st letter;
- also, no space. Use capital letters only)
- C]445BB90AAF77
- The palette is changed as soon as this line is read, i.e. just now if you
- are scrolling (or flipping pages) forward in this text. It will remain active
- as long as no other palette command line is read. Actually, I placed another
- command (restoring my favorite default palette) just above the title of
- this paragraph. Now, scroll backwards to observe this restoration and come
- back here, line by line.
- Of course, if there is a single palette change in the middle of the text,
- it can be bypassed if the user goes directly from the beginning to the end
- of the text without passing by each page. Nothing is perfect! Remember this
- problem when preparing your text file.
-
- ]]14 ]21
- ]]14 THE HARD WAY TO CHANGE THE DEFAULT PALETTE ]21 If you don't like either my
- ]]14 ]21 default palette or my way of
- changing it (for instance, because you adopted the shorter LIRE0), you can
- still change it. If you TYPE (with OPT H) the routine file, the end reads
-
- 07D0: 20746578 74293C3C 3C3C2020 20203E3E text)<<<< >>
- 07E0: 3E3E4558 49540AA9 00040A22 05490000 >>EXIT.....".I..
- 07F0: 000003F2 ....
-
- Just after the binary for EXIT, you can read 0AA9 0004 0A22 0549. Apart from
- the leading zeros, this directly gives the triplets RGB of the four colors.
- With your favourite disk editor, replace them according to your own choice
- (don't change the leading zeros).
-
-
-
- C]AA9004A22549
- ]]14 ]21
- ]]14 HOW TO USE THE ROUTINE ]21 The routine call be called from Workbench or from
- ]]14 ]21 CLI. From CLI, merely type
-
- lire filename <and press RETURN>
-
- To use it with Workbench icons, attach a Project type icon to the text file
- you wish to read. Click this icon (once) and select "Info" from the pulldown
- Workbench menu at top left of the Workbench screen. In the ToolTypes box,
- type
- :lire
-
- and click the Save box at bottom left of the screen. You must copy "lire" to
- the same diskette as the text file.
-
-
- ]]14 ]21
- ]]14 IN A NUTSHELL ]21
- ]]14 ]21 When EDiting the file :
-
- p] prints the line in color p (p=1,2,3,4). Background remains in color 1
-
- ] announces that special codes ]pb follow in the line, to set pen color
- to p and background color to b
-
- C]RGBXYZUVWKLM (all symbols after ] must be hex numbers. Use capital
- letters only. No space). Sets a new palette
- color 1 = red R , green G, blue B
- color 2 = red X , green Y, blue Z
- ... and so on.
-
- ]]12 The codes p], ], C] must be at the extreme left of the line. ]21
-
- 2] Also, don't forget, when viewing the text :
- 2] leftAMIGA+N pushes the display to the back of other screens
- 2] leftAMIGA+M recalls it in the front
-
-