home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USERJL90.MSA / TEXT_SCREENFL.DOC < prev    next >
Text File  |  1990-05-15  |  4KB  |  95 lines

  1.                         Squeeze a quart into a pint pot
  2.  
  3. SCREENFULL is an exciting new challenge for programmers _ to write a program
  4. that will fit on one standard 80 column by 22 row monitor or TV screen. The
  5. program can be a game, utility, graphic designer, music and MIDI editor or even
  6. a business program. You can use whatever programming language you feel most
  7. comfotable with such as Basic, C, Pascal, STOS or 68000 machine code. The only
  8. condition is that the whole of the source code must fit onto one screen.
  9.     The very small size limit on source code may sound quite restricting to ST
  10. programmers who are used to producing large applications, but it is surprising
  11. what can be squeezed into such a small space. Lateral thinking and ingenuity
  12. are essential requirements.
  13.     To give you an idea of what can be achieved in Screenfull RLE.BSC and
  14. RLD.BSC are two useful utility programs that will compact almost any file on
  15. disk.
  16.     The first utility, a Fast Basic program called RLE.BSC, performs run length
  17. encoding on a file to remove any continuous runs of identical bytes. First, the
  18. file is scanned to see if any byte values in the range 0 to 255 are not used.
  19. If one is found then it is used as a flag to indicate a run. For instance, if a
  20. file contained the following sequence of bytes:
  21.  
  22. 12 17 05 05 05 05 05 05 05 05 05 05 20 18
  23.  
  24. then a suitable flag would be 00 and the bytes would be conmpacted to:
  25.  
  26. 12 17 00 05 10 20 18
  27.  
  28.     The 00 indicates that a run follows, the byte is 05 and the length of the
  29. run is 10. Notice that here we have a 50% reduction in file size. However, this
  30. compaction method is dependent on there being an unused byte value and runs of
  31. more than three identical bytes.
  32.     Text files contain very few runs of identical characters and therefore
  33. aren't good candidates for this compaction method. Pictures, images, data files
  34. and even some program files can usually be compacted to a certain extent.
  35.     The second utility, another Fast Basic program called RLD.BSC, takes a run
  36. length encoded file and decompacts it. The run flag is always the first byte of
  37. the file and the utility reads in byte, expands any runs and writes the
  38. decompacted file to disk.
  39.     The source code for RLE.BSC and RLD.BSC has been stripped down to the bone
  40. to fit the requirements of Screenfull. Fast Basic's file handling appears to be
  41. quite slow so the code should be converted into a compiled language such as
  42. HiSoft or GFA Basic if you intend to use the utilities seriously.
  43.  
  44. -----------------------------------------------------------------------------
  45.                            A:\LISTINGS\RLE.BSC
  46. -----------------------------------------------------------------------------
  47. REM Run Length Encoding - by R.A.Waddilove - in Fast Basic
  48. INPUT "File to compact:"i$
  49. INPUT "Archive filename:"o$
  50. PRINT:PRINT "Scanning file..."
  51. DIM byte%(255)
  52. F%=OPENIN i$
  53. c%=0:REPEAT:byte%(BGET#F%)=1:c%=c%+1:UNTIL EOF#F%:CLOSE#F%
  54. flag%=-1:FOR i%=0 TO 255:IF byte%(i%)=0 THEN flag%=i%
  55. NEXT:IF flag%=-1 THEN PRINT "Can't compact!":END
  56. PRINT "Encoding...":I%=OPENIN i$:O%=OPENOUT o$:BPUT#O%,flag%:b1%=BGET#I%
  57. REPEAT:b2%=BGET#I%:IF b2%=b1% AND EOF#I%=0 THEN
  58. b3%=BGET#I%:IF b3%=b2% AND EOF#I%=0 THEN
  59. BPUT#O%,flag%:BPUT#O%,b1%:c%=2:REPEAT:b1%=BGET#I%:c%=c%+1
  60. UNTIL b1%<>b2% OR c%=255 OR EOF#I%:IF EOF#I% THEN b1%=c%+1 ELSE BPUT#O%,c%
  61. ELSE
  62. BPUT#O%,b1%:BPUT#O%,b2%:b1%=b3%
  63. ENDIF
  64. ELSE
  65. BPUT#O%,b1%:b1%=b2%
  66. ENDIF
  67. UNTIL EOF#I%:BPUT#O%,b1%:CLOSE#I%:CLOSE#O%
  68. END
  69. -----------------------------------------------------------------------------
  70.                            A:\LISTINGS\RLD.BSC
  71. -----------------------------------------------------------------------------
  72. REM Run Length Decoding - by R.A.Waddilove - in Fast Basic
  73. INPUT "File to decompact:"i$
  74. INPUT "New filename:"o$
  75. DELFILE o$    : \just a precaution
  76. PRINT:PRINT "Decoding file..."
  77. I%=OPENIN i$  : \open file to compact
  78. flag%=BGET#I% : \get run length flag
  79. O%=OPENOUT o$ : \open file to create
  80. REPEAT
  81.      byte%=BGET#I%
  82.      IF byte%=flag% THEN
  83.           byte%=BGET#I% : count%=BGET#I%
  84.           FOR J%=1 TO count%
  85.                BPUT#O%,byte% : \ run of count%, bytes%
  86.           NEXT
  87.      ELSE
  88.           BPUT#O%,byte%
  89.      ENDIF
  90. UNTIL EOF#I%
  91. CLOSE#I%:CLOSE#O% : \close files
  92. END
  93.  
  94. -----------------------------------------------------------------------------
  95.