changeset 1706:6b23465701c0

Tim Kientzle's VIEW
author boisy
date Tue, 10 Aug 2004 23:46:24 +0000
parents bd792517eea1
children 3911533043d3
files 3rdparty/utils/view/about.source 3rdparty/utils/view/debug.a 3rdparty/utils/view/view.a 3rdparty/utils/view/view_arith.a 3rdparty/utils/view/view_clp.a 3rdparty/utils/view/view_cm3.a 3rdparty/utils/view/view_convert.a 3rdparty/utils/view/view_gfx.a 3rdparty/utils/view/view_gfx2.a 3rdparty/utils/view/view_gif.a 3rdparty/utils/view/view_gifcol.a 3rdparty/utils/view/view_gifpix.a 3rdparty/utils/view/view_gifset.a 3rdparty/utils/view/view_global.a 3rdparty/utils/view/view_help.a 3rdparty/utils/view/view_img.a 3rdparty/utils/view/view_io.a 3rdparty/utils/view/view_mac.a 3rdparty/utils/view/view_max.a 3rdparty/utils/view/view_maxcmp.a 3rdparty/utils/view/view_mge.a 3rdparty/utils/view/view_pals.a 3rdparty/utils/view/view_parse.a 3rdparty/utils/view/view_pix.a 3rdparty/utils/view/view_pix2.a 3rdparty/utils/view/view_rat.a 3rdparty/utils/view/view_rle.a 3rdparty/utils/view/view_save.a 3rdparty/utils/view/view_savecomp.a 3rdparty/utils/view/view_setsave.a 3rdparty/utils/view/view_st.a 3rdparty/utils/view/view_table.a 3rdparty/utils/view/view_vef.a 3rdparty/utils/view/view_wait.a
diffstat 34 files changed, 9015 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/about.source	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,36 @@
+Brief description of the source files for VIEW.
+
+about.source   --- This text file
+debug.a        --- Contains debugging routines, esp. "regdmp", "hexout"
+makefile       --- for use with a "decent"  (i.e. non-Tandy) make.
+view.a         --- Main program loop.
+view_arith.a   --- Arithmetic routines
+view_clp.a     --- Support for "CLP", "PUB" formats
+view_cm3.a     --- Support for "CM3" format
+view_convert.a --- Routines to convert between screen formats
+view_gfx.a     --- Graphics Utility routines
+view_gfx2.a    --- more Graphics utility routines
+view_gif.a     --- Basic "GIF" support, LZW decoder
+view_gifcol.a  --- "GIF" color map generation
+view_gifpix.a  --- "GIF" per-pixel screen output, scaling
+view_gifset.a  --- Setup for GIF support... reserves mem for tables, etc.
+view_global.a  --- Global variables for View
+view_help.a    --- Text of help messages.
+view_img.a     --- "IMG" support.
+view_io.a      --- Buffered disk Input, terminal output.
+view_mac.a     --- "MAC" support.
+view_max.a     --- Pmode, BIN, ART, MAX support
+view_mge.a     --- MGE support
+view_pals.a    --- Palette manipulation, conversion
+view_parse.a   --- General-purpose command-line parser
+view_pix.a     --- PIX support
+view_pix2.a    --- Graphics routines for PIX
+view_rat.a     --- RAT support
+view_rle.a     --- RLE support
+view_save.a    --- Save handling
+view_savecomp.a --- Save compression subroutines
+view_setsave.a  --- Handle save command-line options, open file, etc.
+view_st.a      --- ST, STP support
+view_table.a   --- Table of command-line options.
+view_vef.a     --- VEF, VF2, etc. support
+view_wait.a    --- End-of-pic support for animation, etc., signal handler
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/debug.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,192 @@
+*
+* Debug routines
+*
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect debug_a,0,0,0,0,0
+*
+* Output bin byte in A to stdout
+*
+binout:
+  pshs a,b,cc,x,y
+  ldx  #8   8 bits to write out.
+binout1
+  ldb  #'0  
+  lsra      Get next least significant bit
+  adcb #0   B will be 0 or 1
+  pshs b    Save the digit.
+  leax -1,x
+  bne  binout1
+  tfr  s,x  Now, output the 8 digits.
+  ldy  #8
+  lda  #2
+  os9  I$Write
+  leas 8,s
+  puls a,b,cc,x,y,pc  
+
+  
+*
+* Output hex byte in A to stdout
+*
+hexout:
+  pshs a,b,cc,x,y
+  tfr  a,b
+  anda #$0f
+  adda #$90
+  daa
+  adca #$40
+  daa
+  pshs a
+  lda  #$10
+  mul
+  adda #$90
+  daa
+  adca #$40
+  daa
+  pshs a
+  lda  #2
+  tfr  s,x
+  ldy  #2
+  os9  I$Write
+  leas 2,s
+  puls a,b,cc,x,y,pc
+
+CCdat fcc "efhinzvc"
+
+CCOut
+  pshs cc,dp,a,b,x,y,u
+  pshs a
+  leau CCdat,pcr
+  pulu cc,dp,a,b,x,y   Move 8 bytes to the stack.
+  pshs cc,dp,a,b,x,y
+  leax -1,s            X points to CC info - 1
+  ldb  #8
+  lda  #'-
+CCOloop
+  ror  8,s
+  bcs  CCOSet
+  sta  b,x
+CCOSet
+  decb
+  bne  CCOloop
+  lda  #2
+  leax ,s  
+  ldy  #8
+  os9  I$Write
+  leas 9,s      Clean up stack
+  puls a,b,cc,dp,x,y,u,pc
+
+*
+* Output byte in D to stderr
+hexout2
+  pshs a,b,cc
+  bsr  hexout
+  exg  b,a
+  bsr  hexout
+  puls a,b,cc,pc
+
+*
+* for single-byte regs, output hex + ASCII
+hexout1
+  pshs a,b,x,y,cc
+  bsr  hexout
+  anda #$7f   Strip off high bit
+  cmpa #$7f
+  beq  ho0
+  cmpa #$20
+  bhs  ho1
+ho0
+  lda  #'.
+ho1
+  pshs a      Put character on stack.
+  ldb  #$20
+  pshs b      Put space before it.
+  lda  #2
+  ldy  #2
+  tfr  s,x
+  os9  I$Write
+  puls x       Clean up stack.
+  puls a,b,x,y,cc,pc
+
+CCreg fcc " CC:"
+Areg  fcc "  A:"
+Breg  fcc "  B:"
+DPreg fcc " DP:"
+Xreg  fcc "  X:"
+Yreg  fcc "  Y:"
+Sreg  fcc "  S:"
+Ureg  fcc "  U:"
+PCreg fcc " PC:"
+
+regdmp:
+   pshs u    Push actual U
+   leau 4,s  Make U be S  (Note: no CC flags affected.)
+   pshs cc,a,b,dp,x,y,u  Now push rest.
+   tfr  s,u
+
+   leax CCreg,pcr
+   ldy  #4         First do CC register.
+   lda  #2
+   os9  I$Write
+   lda  ,u+
+   lbsr CCOut
+   leax 4,x
+
+   ldb  #3
+dmpregs1
+   pshs b
+   ldy  #4  
+   lda  #2
+   os9  I$Write
+   lda  ,u+
+   bsr  hexout1
+   leax 4,x
+   puls b
+   decb
+   bne  dmpregs1   
+
+   ldb  #5
+dmpregs2
+   pshs b
+   ldy  #4  
+   lda  #2
+   os9  I$Write
+   ldd  ,u++
+   lbsr hexout2
+   leax 4,x
+   puls b
+   decb
+   bne  dmpregs2
+
+   bsr  crlf         Output the final CR.
+
+*   ldx  #300      Sleep for 5 seconds.
+*   os9  F$Sleep
+
+   puls cc,a,b,dp,x,y,u
+   puls u,pc
+
+
+*
+* Miscellaneous output routines
+*
+crlf:
+   pshs a,b,cc,x,y
+   lda  #$0d
+   bra  Chrout
+Space:
+   pshs a,b,cc,x,y
+   lda  #$20
+Chrout
+   pshs a
+   tfr  s,x
+   ldy  #1
+   lda  #2
+   os9  I$WritLn
+   puls a
+   puls a,b,cc,x,y,pc
+
+   endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,226 @@
+*
+* View:  view a picture file on a window screen
+*
+* Global labels:
+*   main:   Main entry point, called by root.a
+*   _exit:  Exit with no error
+*   _error: Exit with error code in B
+*   _abort: Clean up and then exit with no error.
+*   E$Format: Exit with message about illegal file format.
+*
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect View_a,0,0,0,0,0
+
+main:
+ lbsr SetSig     Install signal trap
+ com  <abort     Set for abort on signal.
+ lbsr select     Send select code to current screen.
+
+ pshs a
+ pshs y
+ os9  F$ID       Get our PID, for use with graphics
+ puls y
+ sta  <PID
+ lbsr killbuffs  Kill off buffers in our group before we start
+ lbsr saveopts   Get StdOut options, and save them.
+ puls a
+
+ pshs d,x
+ leax end,y      Set up free space pool.
+ stx  <MemTop
+ pshs x
+ tfr  s,d
+ subd #stacksize
+ subd ,s++
+ std  <MemSiz
+ puls d,x
+
+ lbsr Parse      Parse command line options, open input file
+
+ lda  <format
+ pshs y
+ lbsr showpic    Display the picture
+ puls y
+
+ lbsr bell
+ lbsr sendsig
+
+ lbsr keywait    Wait for a keypress.
+ lbsr DoSave     Save the picture.
+_abort:
+ lbsr sendsig
+ lbsr cleanup    Cleanup-- Select Stdout, turn on cursor, restore options.
+ lbsr killbuffs  Kill any buffers we used.
+
+* Exit with no error
+_exit:
+ clrb
+_error:
+ OS9  F$Exit
+
+BEL fcb $07
+
+bell
+ pshs a,b,x,y
+ tst  <SigPID
+ bne  bellend  Don't bell if we should send a signal.
+ lda  <outpath
+ leax BEL,pcr
+ ldy  #1
+ os9  I$Write
+bellend
+ puls a,b,x,y,pc
+
+sendsig
+ pshs a,b
+ lda  <SigPID
+ beq  nosig
+ ldb  <SigOut
+ os9  F$Send
+ lbcs _error
+ clr  <SigPID
+nosig
+ puls a,b,pc
+
+E$Format:
+ leax  ErrFmt,pcr
+ ldy   #ErrFmt2-ErrFmt
+ bra   DoError
+ErrFmt fcc "Illegal file format."
+ fcb $0d
+ErrFmt2
+DoError
+ lda   #StdErr
+ os9   I$WritLn
+ ldb   #1
+ bra   _error
+
+*
+* Expects allocation size requested in D,
+*  returns pointer in X.  Error is generated if not enough mem.
+malloc:
+  pshs a,b,y
+  clra
+  clrb
+  os9  F$Mem
+  lbcs _error
+  std  <oldmemsize
+  pshs y
+
+  addd 2,s
+  os9  F$Mem
+  lbcs _error
+  std  <newmemsize
+  puls x
+  puls a,b,y,pc
+
+unmalloc:
+  pshs a,b,y
+  ldd  #0
+  os9  F$Mem
+  lbcs _error
+  cmpd <newmemsize
+  bne  unmalend
+  ldd  <oldmemsize
+  os9  F$Mem
+  lbcs _error
+unmalend
+  puls a,b,y,pc
+
+***************************************
+*                                     *
+* Select according to picture format  *
+*                                     *
+***************************************
+
+SPTable
+ fcb   MAXFormat
+ lbra  MAXshowpic   MAXshowpic also handles all the pmodes
+ fcb   P00Format
+ lbra  MAXshowpic
+ fcb   P01Format
+ lbra  MAXshowpic
+ fcb   P10Format
+ lbra  MAXshowpic
+ fcb   P11Format
+ lbra  MAXshowpic
+ fcb   P20Format
+ lbra  MAXshowpic
+ fcb   P21Format
+ lbra  MAXshowpic
+ fcb   P30Format
+ lbra  MAXshowpic
+ fcb   P31Format
+ lbra  MAXshowpic
+ fcb   P40Format
+ lbra  MAXshowpic
+ fcb   P41Format
+ lbra  MAXshowpic
+ fcb   ARTFormat
+ lbra  MAXshowpic
+ fcb   MGEFormat
+ lbra  MGEshowpic
+ fcb   MGE640Format
+ lbra  MGEshowpic
+ fcb   CM3Format
+ lbra  CM3showpic
+ fcb   CLPFormat
+ lbra  CLPshowpic
+ fcb   PUBFormat
+ lbra  CLPshowpic
+ fcb   VEFFormat
+ lbra  VEFshowpic
+ fcb   PIX256Format
+ lbra  PIXshowpic
+ fcb   PIX128Format
+ lbra  PIXshowpic
+ fcb   PIXFormat
+ lbra  PIXshowpic
+ fcb   IMGFormat
+ lbra  IMGshowpic
+ fcb   RATFormat
+ lbra  RATshowpic
+ fcb   STFormat
+ lbra  STshowpic
+ fcb   MACFormat
+ lbra  MACshowpic
+ fcb   RLEFormat
+ lbra  RLEshowpic
+ fcb   GIFFormat
+ lbra  GIFshowpic
+ fcb   GIFBWFormat
+ lbra  GIFshowpic
+ fcb   MAXCMPFormat
+ lbra  MAXshowpic
+ fcb   ARTCMPFormat
+ lbra  MAXshowpic
+ 
+*
+* Does a jump to the appropriate subr entry point.
+*   Expects picture format code in A.
+*
+showpic
+ pshs  x        Space to store jump destination
+ pshs  x        Save X register
+ leax  SPTable-3,pcr
+sploop
+ leax  3,x
+ cmpa  ,x+      Does the format match?
+ bne   sploop
+ stx   2,s      Jump address is table entry
+ puls  x,pc     restore X and jump.
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_arith.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,57 @@
+*
+* Arithmetic routines for VIEW
+*
+*
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect view_arith_a,0,0,0,0,0
+*
+* Divide A by B, return fixed-point result in A.B, rounded.
+*
+divAB:
+  pshs b  Put divisor on stack
+  ldb  #17 17-bit result, with last bit in C.
+  pshs b
+  clrb
+  pshs b
+divABloop
+  rol  ,s
+  rola
+  rolb        Shift into B.
+  cmpb  2,s
+  blo   divAB1
+  subb  2,s
+  orcc  #Carry
+  bra   divAB2
+divAB1
+  andcc #^Carry
+divAB2
+  dec   1,s
+  bne   divABloop
+  puls  b     Get fraction part into B
+  adcb  #0    Round by adding in extra decimal place.
+  adca  #0
+  leas  2,s   Clear up stack.
+  rts
+
+* Divide 16-bit value in X by 8-bit value in A, return 16-bit result in D.
+*
+div168:
+  pshs x     The division we want is (XH * 256 + XL) / A
+  pshs d
+  lda  3,s   First, calculate  XL / A
+  ldb  ,s
+  bsr  divAB
+  sta  1,s   Save it.
+  lda  2,s   Now do (XH/A) *256
+  ldb  ,s
+  clr  ,s
+  bsr  divAB
+  addd ,s    Add them to get answer.
+  std  ,s
+  puls d
+  puls x,pc
+ 
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_clp.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,130 @@
+*
+*
+*  CLP format display, and PUB format
+*
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect view_clp_a,0,0,0,0,0
+
+ vsect
+gpload fcb $1b,$2b,0,2,0,0,0,0,0,0,0
+putblk fcb $1b,$2d,0,2,0,0,0,0
+size   rmb 2
+ endsect
+
+pals fcb $3f,$09,$00,$12,$24,$36,$2d,$1b   Same as OS9 default palettes
+ fcb $3f,$09,$00,$12,$24,$36,$2d,$1b
+
+CLPshowpic:
+* Set up some miscellaneous vars
+   lda  #8
+   sta  <cyclestart
+   lda  #15
+   sta  <cycleend
+   ldd  #5
+   std  <cyclerate
+   lda  #0
+   sta  <extranum
+
+* Set the palettes
+   ldb  #16
+   leax pals,pcr
+   leau palette,y
+paloop
+   lda  ,x+
+   sta  ,u+
+   decb
+   bne  paloop
+
+* Set up the GPLoad command parameters.
+   leax gpload,y
+
+* PUB format?
+   lda  <format
+   cmpa #PUBFormat
+   bne  noPUB
+   ldb  #4
+   leau PUBstuff,pcr
+PUBloop
+   lda  ,u+
+   sta  b,x
+   incb
+   cmpb #11
+   bne  PUBloop   
+   bra  dogpload
+
+* PUB format clips are type 5, 80x40, 400 bytes.
+PUBstuff fcb 5,0,80,0,40,1,$90
+
+noPUB
+
+* Handle CLP format.
+   ldb  #4           Start with byte 5 in GPLoad command.
+headloop
+   lbsr I_GetByte    Get remainder of GPLoad header.
+   lbcs _error
+   sta  b,x
+   incb
+   cmpb #11
+   bne  headloop
+
+dogpload
+   lda  <PID        Use PID for buffer number.
+   sta  2,x
+
+   lda  4,x         Set screen type.
+   sta  <type
+   lbsr setscreen
+   lbsr setpals
+
+   ldd  9,x          Set size of buffer.
+   std  size
+
+   pshs y
+   ldy  #11          Send the GPLoad.
+   lda  <outpath
+   os9  I$Write
+   puls y      
+
+   pshs y            Now copy buffer contents to screen.
+   leax linebuff,y
+loop
+   ldd  size        Read size bytes...
+   beq  loopend
+   cmpd #$100       ... But not more than 256 at a time.
+   bhi  toobig
+   ldd  #$100
+toobig
+   tfr  d,y
+   lbsr I_Read      Get it.
+   bcs  looperr     Exit on error or EOF.
+   pshs y
+   ldd  size        Count down the size to copy.
+   subd ,s++
+   std  size
+   lda  <outpath
+   os9  I$Write     Output it to screen
+   bra  loop
+
+looperr
+   cmpb #E$EOF
+   lbne _error
+
+loopend
+   puls y
+   leax putblk,y
+   lda  <PID
+   sta  2,x
+   lda  <outpath
+   pshs y
+   ldy  #8
+   os9  I$Write
+   lbcs _error
+   puls y
+
+   rts
+
+   endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_cm3.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,390 @@
+*******************************************************************************
+*
+* SUBS for CM3 picture formats
+*
+* CM3showpic -- display picture, using putline routine
+*
+*******************************************************************************
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect view_cm3_a,0,0,0,0,0
+
+ vsect dp
+endoffile  rmb 1     T= EOF reached, so always return linebuff all 0
+patterns   rmb 1     T= patterns must be skipped
+totscreens fcb 1   Total number of screens in picture
+numscreens fcb 1   Number of screens remaining in picture- for Getline sub.
+lines      rmb 1    Number of lines remaining on this screen
+lastbyte   rmb 1
+ endsect
+
+
+ vsect
+image     rmb 20
+action    rmb 25
+ endsect
+
+*
+* Main picture display function
+*
+CM3showpic:
+ bsr  header
+
+ pshs d
+ ldd  <Skiplines
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ lbsr setscreen    
+ lbsr setpals
+ lbsr setbuffer
+ lbsr getline
+
+spscreens
+ ldd  #0
+showpicloop
+ lbsr putline
+ lbsr getline
+ tst  <Size
+ bgt  spnoskip    Size >0, don't do skip.
+ pshs a
+ lda  <totscreens
+ cmpa #2          Two screens?
+ puls a
+ blo  spnoskip    No, ignore this.
+spskip
+ lbsr getline     Yes, get another line.
+spnoskip
+ addd #1
+ cmpd #192
+ bne  showpicloop
+ tst  <Size
+ beq  showpicend   Only do another screen if not small size.
+ lbsr getline
+ tst  <endoffile
+ bne  showpicend
+ lbsr setscreen    
+ lbsr setpals
+ bra  spscreens
+showpicend
+ puls d,pc
+
+*
+* read header info from file, and set window type information
+*      Uses  altbuff  to store header as it's read from disk.
+*
+header
+ pshs a,b,x,y,u
+ leax altbuff,y read in type and palettes
+ pshs y
+ ldy  #29
+ lbsr I_Read
+ puls y
+ lbcs _error
+ leax altbuff,y
+ lda  ,x+      
+ cmpa #1       No patterns
+ beq  head2
+ cmpa #0       0 or $80 are types for screens with patterns
+ beq  head0
+ cmpa #$80
+ lbne E$Format
+ lda  #2
+ sta  numscreens
+ sta  totscreens
+head0
+ com  patterns
+head2
+
+ leau palette,y   Set palettes
+ ldb  #16
+headloop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  headloop
+
+ ldb  ,x+         Store rate for palette rotation
+ clra
+ std  <cyclerate
+
+ ldd  #$0b0e        Palette cycling starts at palette 11, ends at 14
+ sta  <cyclestart
+ stb  <cycleend
+
+ ldb  ,x+         Get rate for color cycling
+ clra
+ std  <extrarate
+
+ ldb  #8
+ leau extrapals,y  Set palette values for color cycling
+head2loop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  head2loop
+
+ lda  #10
+ sta  <extraslot
+
+ lda  ,x+
+ bmi  headanim       If no animation, set cyclestart=cycleend
+ lda  <cyclestart
+ sta  <cycleend
+headanim
+
+ ldb  #8
+ lda  ,x+
+ bmi  headrot       Set number of values for color rotation.
+ clrb
+headrot
+ stb  <extranum
+
+ lda  <type
+ bne  headtype
+ lda  #8        Set screen type to 8
+ sta  <type
+headtype
+
+ lda  #$ff
+ sta  <cycle    Turn cycling on.
+
+ tst  patterns     Do we need to skip pattern info?
+ beq  head3
+ leax linebuff,y
+ pshs y
+ ldy  #243         This many bytes of pattern info must be skipped.
+ lbsr I_Read
+ puls y
+ lbcs _error
+head3
+
+ ldd  <Skiplines  Set lines to skip if not already set.
+ cmpd #$ffff
+ bne  headskip
+ ldd  #0
+ std  <Skiplines
+headskip
+
+ lda  <Size
+ bpl  headsize
+ lda  #1        Default size is BIG.
+ sta  <Size
+headsize
+
+ ldd  #120
+ std  <fliprate    Set to flip every 2 seconds.
+
+ leax altbuff,y  Clear out buffer with "last line" info.
+ clrb
+headclear
+ clr  ,x+
+ decb
+ bne  headclear
+ 
+ puls a,b,x,y,u,pc
+
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* Clear line and check for end-of-file condition
+ leau linebuff,y
+ ldb  #160
+getl1
+ clr  ,u+
+ decb
+ bne  getl1
+ tst  endoffile    Are we at end-of-file?
+ lbne getline1
+* Check if we're at the beginning of a new screen.
+ tst  lines
+ bne  getl2
+* If so, and numscreens=0, then end-of-file
+ dec  numscreens
+ bpl  getl3
+ com  endoffile
+ lbra getline1
+getl3 
+ lbsr I_GetByte
+ sta  lines
+getl2
+* get header byte
+ lbsr I_GetByte
+* Test for compressed/uncompressed line.
+ tsta
+ bpl  getcomp
+*
+* Get uncompressed line.
+*
+getnormal
+ leax linebuff,y   read in one line of screen
+ pshs y
+ ldy  #160
+ lbsr I_Read
+ puls y
+ lbcc getnor2
+geteof
+ cmpb #E$EOF      watch for end-of-file
+ bne  getnor1
+ com  endoffile   Flag end-of-file condition
+ bra  getnor2    Keep on going.
+getnor1
+ lbra _error      If not EOF, just exit with error.
+*
+* Get compressed line.
+*
+getcomp
+ leax image,y    Initialize counters for image and action bits.
+ stx  <imptr
+ leax action,y
+ stx  <actptr
+ ldb  #8
+ stb  <imcnt
+ stb  <actcnt
+
+ tfr  a,b
+ clra
+ cmpd #21
+ lbhi E$Format if >21 action bytes, then error.
+ addd #20      Get total number of bytes for image + action.
+ tfr  d,u
+ leax image,y
+ exg  y,u
+ lbsr I_Read
+ exg  y,u
+ lbcs geteof   Test for end-of-file, etc.
+
+* decode a compressed packet
+ leax altbuff,y
+ leau linebuff,y
+ ldb  #160
+ lda  lastbyte   A always holds the last byte on the line.
+getcomp0
+ bsr tstimage
+ bcc  getcomp9     image byte 0 -> repeat last byte
+ lda  ,x         
+ bsr tstaction    1 image & 0 action -> repeat from above
+ bcc  getcomp9
+ lbsr I_GetByte    1 image & 1 action -> get new value
+getcomp9
+ sta  lastbyte
+ sta  ,u+
+ leax 1,x
+ decb
+ bne  getcomp0
+*
+*  Now, put line where it belongs.
+*
+getnor2
+ leax linebuff,y
+ leau altbuff,y  Copy linebuff to altbuff, to save last line
+ ldb  #160
+getnor3
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  getnor3
+ sta  lastbyte
+* If small and double-screen, then do horizontal compression.
+ tst  <Size
+ bne  getline1
+ lda  <totscreens
+ cmpa #2
+ bne  getline1
+ bsr  squishline
+* Exit getline
+getline1
+ dec  lines
+ puls a,b,x,y,u,pc
+
+*
+* These subs return consecutive bits from the appropriate bit arrays
+*
+ vsect dp
+actptr rmb 2
+actcnt rmb 1
+imptr rmb 2
+imcnt rmb 1
+ endsect
+
+tstaction
+ rol  [actptr]
+ dec  actcnt
+ bne  tstact1
+ pshs a,x
+ ldx  actptr
+ leax 1,x
+ stx  actptr
+ lda  #8
+ sta  actcnt
+ puls a,x
+tstact1
+ rts
+
+tstimage
+ rol  [imptr]
+ dec  imcnt
+ bne  tstim1
+ pshs a,x
+ ldx  imptr
+ leax 1,x
+ stx  imptr
+ lda  #8
+ sta  imcnt
+ puls a,x
+tstim1
+ rts
+
+squishline
+ pshs a,b,x,y,u
+ leax linebuff,y
+ tfr  x,u
+ ldy  #80   Total # of pairs of bytes.
+squish1
+ ldd  ,x++
+ lsrb   Top nybble of B to bottom.
+ lsrb
+ lsrb
+ lsrb
+ andb #$0f  Mask off bottom nybble of B.
+ anda #$f0  .. and top of A.
+ pshs b     Or them together.
+ ora  ,s+
+ sta  ,u+
+ leay -1,y
+ bne  squish1
+
+ ldy  #40   Clear out 40 bytes on right side.
+squish2
+ clr  ,-x
+ leay -1,y
+ bne  squish2
+
+ ldy  #80   Move 80 bytes to center of screen.
+squish3
+ lda  ,-u
+ sta  ,-x
+ leay -1,y
+ bne  squish3
+
+ ldy  #40   Clear out 40 bytes on left side.
+squish4
+ clr  ,-x
+ leay -1,y
+ bne  squish4
+ puls a,b,x,y,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_convert.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,178 @@
+*
+* Routines for converting screen types.
+* Each routine expects a pointer in X to one line of screen data.
+* Data is converted in-place.
+*
+* These conversions lose no data.
+*   MGE57:  Converts type 5 line to type 7 line.
+*   MGE67:  Converts type 6 line to type 7 line.
+*   MGE68:  Converts type 6 line to type 8 line.
+* These conversions, of necessity, lose some data.
+*   MGE76:  Converts type 7 line to type 6 line by throwing out odd pixels
+*   MAC75:  Converts type 7 line to type 5 line by keeping hi-order bit of pixel
+*   MAC76:  Converts type 7 line to type 6 line by averaging pairs of pixels
+*
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect view_convert_a,0,0,0,0,0
+
+*
+* Converts type 6 (320 4-color) into type 7 (640 4-color)
+*
+MGE67tab fcb $00,$05,$0a,$0f,$50,$55,$5a,$5f,$a0,$a5,$aa,$af,$f0,$f5,$fa,$ff
+MGE67:
+ pshs y
+ leay MGE67tab,pcr
+ bsr  MGEconv
+ puls y,pc
+
+*
+* Converts type 5 (2-color) line of data into type 7 (4-color)
+*
+MGE57tab fcb $00,$01,$04,$05,$10,$11,$14,$15,$40,$41,$44,$45,$50,$51,$54,$55
+MGE57:
+ pshs y
+ leay MGE57tab,pcr
+ bsr  MGEconv
+ puls y,pc
+
+MGE68tab fcb $00,$01,$02,$03,$10,$11,$12,$13,$20,$21,$22,$23,$30,$31,$32,$33
+MGE68:
+ pshs y
+ leay MGE68tab,pcr
+ bsr  MGEconv
+ puls y,pc
+
+MGEconv
+ pshs a,b,x,y,u
+ leau 80,x   U pts to end of source.
+ leax 160,x   X pts to end of destination.
+ ldb  #80
+MGEconvloop
+ lda  ,-u
+ anda #$0f
+ lda  a,y
+ sta  ,-x
+ lda  ,u
+ lsra
+ lsra
+ lsra
+ lsra
+ lda  a,y
+ sta  ,-x
+ decb
+ bne  MGEconvloop
+ puls a,b,x,y,u,pc
+
+*
+* Throw out every other pixel to convert 640 4-color to 320 4-color
+MGE76table fcb $00,$10,$20,$30,$40,$50,$60,$70,$80,$90,$a0,$b0,$c0,$d0,$e0,$f0
+MGE76:
+ pshs a,b,x,u,y
+ leay MGE76table,pcr
+ tfr  x,u
+ ldb  #160
+ pshs b
+MGE76loop
+ lda  1,x
+ anda #$0f
+ ldb  ,x++
+ andb #$0f
+ ora  b,y
+ sta  ,u+
+ dec  ,s
+ bne  MGE76loop
+ puls b
+ puls a,b,x,u,y,pc
+
+
+*
+* Convert type 7 data to type 5 data for MAC screen.
+*
+MAC75:
+ pshs a,b,x,y,u
+ leau ,x
+ ldy  #160
+MAC75loop
+ ldb  ,x+
+ lslb
+ rola
+ lslb
+ lslb
+ rola
+ lslb
+ lslb
+ rola
+ lslb
+ lslb
+ rola
+ ldb  ,x+
+ lslb
+ rola
+ lslb
+ lslb
+ rola
+ lslb
+ lslb
+ rola
+ lslb
+ lslb
+ rola
+ sta  ,u+
+ leay -1,y
+ bne  MAC75loop
+ puls a,b,x,y,u,pc 
+
+* Convert type 7 to type 6 by averaging pairs of pixels.
+MAC76table fcb $00,$40,$40,$80,$00,$40,$80,$80,$40,$40,$80,$c0,$40,$80,$80,$c0
+MAC76:
+ pshs a,b,x,y,u
+ leau ,x
+ leay MAC76table,pcr
+ ldb  #160
+ pshs b
+MAC76loop
+ ldb  ,x
+ lsrb
+ lsrb
+ lsrb
+ lsrb
+ ldb  b,y
+ lslb
+ rola
+ lslb
+ rola
+ ldb  ,x+
+ andb #$0f
+ ldb  b,y
+ lslb
+ rola
+ lslb
+ rola
+ ldb  ,x
+ lsrb
+ lsrb
+ lsrb
+ lsrb
+ ldb  b,y
+ lslb
+ rola
+ lslb
+ rola
+ ldb  ,x+
+ andb #$0f
+ ldb  b,y
+ lslb
+ rola
+ lslb
+ rola
+ sta  ,u+
+ dec  ,s
+ bne  MAC76loop
+ puls b
+ puls a,b,x,y,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_gfx.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,452 @@
+*
+* Graphics support routines for "view"
+*
+* Global DP variables:
+*     numscreens:  Total number of graphics screens in use.
+*     curscreen:   Number of currently selected screen
+*     screenpaths: array of path numbers for open screens
+* Global subroutines:
+*     setscreen:   Set a screen to correct type, open new one if appropriate
+*     setborder:   Set border of current screen to palette A.
+*     select:      Select StdOut.
+*     flipscreen:  Select next screen.
+*     flipback:    Select previous screen.
+*     echooff:     Turn off echo to current screen
+*     saveopts:    Get StdOut options packet and save it.
+*     cleanup:     Select StdOut, turn on cursor, restore StdOut.
+*     newscreen:   open a new screen, put path num in "outpath" var.
+*     killscreen:  DWEnd current screen.
+*     killbuffs:   Kill all of our buffers.
+*     setbuffer:   Create one-line buffer for putting stuff on screen.
+*                  Returns number of bytes/line in D.
+*     putline:     Put data in linebuff onto screen line D.
+*     fetchline:   Get screen line D into linebuff
+*
+  ifp1
+  use /dd/defs/os9defs.a
+  endc
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+StdOut equ 1
+
+  psect view_gfx_a,0,0,0,0,0
+
+ vsect dp
+numscreens:  rmb 1   Total number of screens allocated.
+curscreen:   rmb 1   Current screen
+
+buffadd     rmb 2   Address of Get/Put buffer.
+buffsiz     rmb 1   Size of Get/Put buffer.
+ endsect
+
+ vsect
+screenpaths: rmb 16  
+ endsect
+
+********************************
+*
+* Create appropriate screen
+*
+*******************************
+
+
+  vsect
+setscCom 
+  fdb $1b20       DWSet
+  fcb 8           type
+  fcb 0,0
+  fcb 40          screen width
+  fcb 24          screen length
+  fcb 1,0,0       palettes
+  fcb $1b,$21     Select code
+  fcb $05,$20     Cursor off
+  endsect
+
+setscreen:
+  pshs a,b,x,u,y
+  tst  <numscreens
+  bne  setSame0     If we already have 1 screen, we _must_ create a new one.
+  tst  <Samescreen
+  bne  setSame1
+setSame0
+  lbsr newscreen   Open a new screen.
+  lda  <outpath      Store path number to paths array
+  leax screenpaths,y
+  ldb  <numscreens
+  sta  b,x
+  bra  setSame2
+setSame1
+  lbsr killscreen  Kill this screen, so we can re-open with correct type.
+  lda  #1          This screen is StdOut
+  sta  screenpaths,y Set first path.
+setSame2
+  ldb  <numscreens
+  stb  <curscreen   Set current screen to most recent one.
+  incb
+  stb  <numscreens  We now have one more screen.
+  lda  <type      type from header interp
+  sta  setscCom+2,y
+  anda #1
+  nega
+  anda #40
+  adda #40
+  sta  setscCom+5,y    bottom corner
+  leax setscCom,y      Now output this string.
+  lda  <outpath
+  pshs y
+  ldy  #14
+  os9  I$Write
+  lbcs _error
+  puls y
+
+  lbsr echooff        Turn off echo on screen.
+  lbsr setmouse       Turn on mouse signal everywhere.
+  puls a,b,x,u,y,pc
+
+selectCom
+ fdb $1b21     Select screen
+
+select:
+  pshs a,b,x,y
+  leax selectCom,pcr
+  ldy  #2
+  lda  #StdOut
+  os9  I$Write
+  puls a,b,x,y,pc
+
+flipscreen:
+  pshs a,b,x,y
+  ldb  <curscreen
+  incb
+  cmpb <numscreens
+  blo  flip1
+  clrb
+flip1
+  bra  doflip
+flipback:
+  pshs a,b,x,y
+  ldb  <curscreen
+  bne  flip2
+  ldb  <numscreens
+flip2
+  decb
+* Send the select code to the new screen.
+doflip
+  stb  curscreen
+  leax screenpaths,y
+  lda  b,x
+  sta  <outpath
+  leax selectCom,pcr
+  ldy  #2
+  os9  I$Write
+  lbcs _error
+  puls a,b,x,y,pc
+
+ vsect
+borderCom fcb $1b,$34,00,$1b,$33,00,$0c   Set border, set background, cls
+ endsect
+
+setborder:
+  pshs a,b,x,y
+  leax borderCom,y
+  sta  2,x
+  sta  5,x
+  ldy  #7
+  lda  <outpath
+  os9  I$Write
+  lbcs _error
+  puls a,b,x,y,pc
+
+*
+* Set screen modes on outpath
+*
+ vsect dp
+optvalid rmb 1   T = options packet is valid.
+ endsect
+
+ vsect
+options rmb 32
+newopts rmb 32
+ endsect
+
+saveopts:
+ pshs   a,b,x
+ lda    #StdOut    Get options for StdOut, and save them.
+ ldb    #SS.Opt
+ leax   options,y
+ os9    I$GetStt
+ lbcs   _error
+ com    optvalid
+ puls   a,b,x,pc
+
+echooff:
+ pshs   a,b,x
+ lda    <outpath
+ ldb    #SS.Opt
+ leax   newopts,y
+ os9    I$GetStt
+ lbcs   _error
+ clr    4,x      Turn off echo.
+ os9    I$SetStt
+ lbcs   _error
+ puls   a,b,x,pc
+
+
+cleanCom
+ fdb $0521     Turn on cursor.
+ fdb $1b21     Select screen
+
+cleanup:
+ pshs a,b,x,y
+ leax cleanCom,pcr
+ lda  #StdOut
+ pshs y
+ ldy  #4
+ os9  I$Write   Select StdOut and turn on cursor.
+ puls y
+
+ tst  optvalid  If options is valid,
+ beq  echoend
+ ldb  #SS.Opt
+ leax options,y
+ os9  I$SetStt  then restore the initial options.
+ lbcc echoend
+ os9  F$Exit
+echoend
+ puls a,b,x,y,pc
+
+*
+* Open new window
+*
+Winname fcc "/w"
+ fcb  $0d
+
+newscreen:
+ pshs a,b,x
+ leax Winname,pcr
+ lda  #3           Update mode
+ os9  I$Open
+ lbcs _error
+ sta  <outpath
+ puls a,b,x,pc
+ 
+killCom fdb $1b24
+
+killscreen:
+ pshs a,b,x,y
+ leax killCom,pcr
+ lda  <outpath
+ ldy  #2
+ os9  I$Write
+ bcc  killscrend
+ cmpb #E$WUndef   Was it window undefined??  That we can ignore.
+ lbne _error      No, abort.
+killscrend
+ puls a,b,x,y,pc
+
+ vsect
+killbcom  fcb $1b,$2a,0,0
+ endsect
+
+killbuffs:
+ pshs a,b,x,y
+ lda  <PID
+ leax killbcom,y 
+ sta  2,x
+ ldy  #4
+ lda  <outpath
+ os9  I$Write
+ puls a,b,x,y,pc
+
+**************************************************************
+*
+* Create get/put buffer for horizontal imaging
+*
+**************************************************************
+
+ vsect dp
+buflegit rmb 1  True= buffer already allocated and mapped
+ endsect
+
+ vsect
+setbufCom
+ fdb $1b2c
+ fdb 0001    Group/buffer
+ fdb 0000
+ fdb 0000
+ fdb 320
+ fdb 1
+ endsect
+
+setbuffer:
+ pshs x,y
+ tst  buflegit   If buffer already created/mapped, then don't do it again.
+ bne  setbufend
+ com  buflegit
+
+ lda  <PID
+ sta  setbufCom+2,y
+ leax setbufCom,y
+ lda <outpath
+ pshs y
+ ldy #12
+ OS9 I$Write 
+ lbcs _error
+ puls y
+
+ lda <PID
+ ldb #1
+ tfr d,x
+ lda #1
+ ldb #SS.MpGPB map in buffer
+ pshs y
+ ldy #1
+ os9 I$SetStt  Now try to map it.
+ lbcs _error
+ tfr y,d
+ puls y
+ stx buffadd
+
+ lda <type
+ ldb #40
+ cmpa #7
+ beq setbuf8
+ cmpa #8
+ bne  setbuf9
+setbuf8
+ addb #40
+setbuf9
+ stb  buffsiz
+
+setbufend
+ ldb  buffsiz
+ clra
+ lsla
+ rolb
+ puls x,y,pc
+
+
+*
+* Putline: expects number of row in D
+*
+ vsect
+putCom fdb $1b2d
+ fcb 0,1         Grp/Buf
+ fdb 0           Xloc
+ fdb 0           Yloc
+ endsect
+
+
+putline:
+ pshs a,b,x,y,u
+ std  putCom+6,y     Set up PUT buffer command
+ lda  <PID
+ sta  putCom+2,y
+ ldd  #0      First X value is zero.
+ std  putCom+4,y
+
+ leax linebuff,y
+ ldu  buffadd
+ ldb  buffsiz
+
+put1
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  put1
+
+ pshs x,y 
+ leax putCom,y
+ lda  <outpath
+ ldy  #8
+ OS9  I$Write
+ lbcs _error
+ puls x,y
+
+ ldd  #320      Second X value is 320= 1/2 screen.
+ std  putCom+4,y
+
+ ldb  buffsiz
+ ldu  buffadd
+put2
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  put2
+
+ leax putCom,y
+ lda  <outpath
+ ldy  #8
+ OS9  I$Write
+ lbcs _error
+
+ puls a,b,x,y,u,pc
+
+*
+* fetchline: expects number of row in D
+*
+ vsect
+fetchCom fdb $1b2c
+ fcb 0,1  Grp/Buf
+ fdb 0    Xloc
+ fdb 0    Yloc
+ fdb 320  XSize
+ fdb 1    YSize
+ endsect
+
+
+fetchline:
+ pshs a,b,x,y,u
+ std  fetchCom+6,y     Set up GET buffer command
+ lda  <PID
+ sta  fetchCom+2,y
+ ldd  #0      First X value is zero.
+ std  fetchCom+4,y
+
+ pshs x,y 
+ leax fetchCom,y
+ lda  <outpath
+ ldy  #12
+ OS9  I$Write
+ lbcs _error
+ puls x,y
+
+ leax linebuff,y
+ ldu  buffadd
+ ldb  buffsiz
+
+fetch1
+ lda  ,u+
+ sta  ,x+
+ decb
+ bne  fetch1
+
+ ldd  #320      Second X value is 320= 1/2 screen.
+ std  fetchCom+4,y
+
+ pshs x,y
+ leax fetchCom,y
+ lda  <outpath
+ ldy  #12
+ OS9  I$Write
+ lbcs _error
+ puls x,y
+
+ ldb  buffsiz
+ ldu  buffadd
+fetch2
+ lda  ,u+
+ sta  ,x+
+ decb
+ bne  fetch2
+
+
+ puls a,b,x,y,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_gfx2.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,115 @@
+
+* Additional gfx operations.
+*
+* Uses some variables from view_gfx.a
+*    numscreens  - total number of screens allocated
+*    screenpaths - array of path number for screens
+*    curscreen   - current screen displayed
+*
+* Routines included:
+*    getkey:     - poll each open screen for keypress.
+*                  (returns Carry set if no key available)
+*    setmouse:   - Set mouse signal on each open screen
+*    setkey:     - Set key signal on each open screen
+*    nextline:   - Higher-level interface to "putline".
+*                  Automatically increments to next line,
+*                  allocates next screen as appropriate.
+*                  Uses "border" to set screen border for new screens.
+*
+ ifp1
+ use  /dd/defs/os9defs.a
+ endc
+
+check macro
+      pshs  b,cc
+      ldb   #\1
+      os9   F$PErr
+      puls  b,cc
+      endm
+
+ psect view_gfx2_a,0,0,0,0,0
+
+*
+* Poll each open screen
+getkey:
+ pshs  b,x,y
+ leax  screenpaths,y
+ clrb
+getkeyloop
+ lda   b,x
+ pshs  b
+ ldb   #SS.Ready
+ os9   I$GetStt
+ bcc   getkeyok
+ cmpb  #E$NotRdy
+ lbne  _error
+ puls  b
+ incb
+ cmpb  <numscreens
+ bne   getkeyloop
+ clra
+ orcc  #Carry     Turn on carry
+ bra   getkeyend
+getkeyok
+ tfr   s,x
+ ldy   #1
+ os9   I$Read   Read one character
+ lbcs  _error
+ puls  a        Get the char into A.
+ andcc #^Carry  Turn off carry
+getkeyend
+ puls  b,x,y,pc
+
+setmouse:
+  pshs a,b,x,y,u
+  ldb  <numscreens     Get the number of screens.
+  clra
+  leau screenpaths,y
+  tfr  d,y
+  ldx  #MButton       Return this signal code.
+  ldb  #SS.MsSig
+setmloop
+  lda  ,u+     Get path number
+  os9  I$SetStt       Set the mouse signal.
+  lbcs _error
+  leay -1,y
+  bne  setmloop       If we haven't done all paths, keep going
+  puls a,b,x,y,u,pc
+
+setkeysig:
+  pshs a,b,x,y,u
+  ldb  <numscreens     Get the number of screens.
+  clra
+  leau screenpaths,y
+  tfr  d,y
+  ldx  #KButton       Return this signal code.
+  ldb  #SS.SSig
+setkloop
+  lda  ,u+     Get path number
+  os9  I$SetStt       Set the mouse signal.
+  lbcs _error
+  leay -1,y
+  bne  setkloop       If we haven't done all paths, keep going
+  puls a,b,x,y,u,pc
+
+ vsect dp
+curline rmb 2
+ endsect
+
+nextline:
+ pshs a,b
+ ldd  curline
+ cmpd #192       Are we off the screen?
+ blo  nextdoit
+ lbsr setscreen  Get a new screen
+ lbsr setpals    Set the palettes
+ lda  <border
+ lbsr setborder  Set the border color
+ ldd  #0
+nextdoit
+ lbsr putline  Put this line
+ addd #1
+ std  curline
+ puls a,b,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_gif.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,488 @@
+*
+* GIF supervisor and LZW decoding stuff.
+*
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect view_gif_a,0,0,0,0,0
+
+*
+* GIFshowpic
+*
+* Display a GIF picture
+*
+ vsect dp
+* These are initialized by SetGIF in view_gifset.a
+giftable: rmb 2   Pointer to 12k decode table
+gifstack: rmb 2   Pointer to 4k space for reversing codes
+* These are used by the actual screen output routines in view_gifpix.a
+gifiheight: rmb 2 Image height
+gifiwidth:  rmb 2 image width
+gifinterlace: rmb 1 T=Use interlace in displaying picture.
+* These are all used locally.
+sheight rmb 2 Screen height  (We use the image size instead of these).
+swidth  rmb 2 Screen width
+domap   rmb 1 T= Color map follows
+*cr      rmb 1 Number bits of color resolution 
+pixel   rmb 1 Number bits per pixel
+background rmb 1  Background color
+screenset  rmb 1  T= screen has been set.
+ endsect
+
+GIFshowpic:
+ clr  screenset
+ lbsr signature  Find signature in input stream
+ lbsr screendesc Parse the screen descriptor information
+ tst  <domap
+ beq  noglobal
+ lbsr colormap  Read and parse the colormap and set up the screen.
+ clr  <domap
+noglobal
+*
+* Main image processing loop
+*  Searches the input stream for one of the following separator characters,
+* and acts accordingly:
+*    0x2c (comma) - GIF image follows
+*    0x21 (exclamation point) - extension block follows
+*    0x3b (semicolon) - end of GIF file
+GIFLoop
+ lbsr I_GetByte
+ lbcs _error
+ cmpa #$3b    semicolon marks the end of the file
+ beq  GIFend
+ cmpa #$21
+ bne  gif2
+ lbsr skipextension
+ bra  GIFLoop
+gif2
+ cmpa #$2c
+ bne  GIFLoop
+ bsr  gifimage
+ bra  GIFLoop
+GIFend
+ lbsr EndGIF  Return extra memory area.
+ rts
+
+ vsect dp
+mincode rmb 1  Starting code size
+lastcode rmb 2 Last code input
+thiscode rmb 2 the current code
+endcode  rmb 2 Code signifying end of picture
+clrcode  rmb 2 code indicating that we clear the table
+firstcolor rmb 1 First color of code just processed
+codesize   rmb 1 Current code size in bits
+*bethy   rmb 50    How much I love Beth.  (Needs to be MUCH bigger...)
+ endsect
+
+* Process a GIF image
+gifimage
+ pshs a,b,x,y,u
+* First, handle the image descriptor
+ lbsr  GIFgetword   offset of pic from left edge of screen
+ lbsr  GIFgetword   offset of pic from top of screen
+ lbsr  GIFgetword   image width
+ std  gifiwidth
+ lbsr  GIFgetword   image height
+ std  gifiheight
+ lbsr I_GetByte    bitmapped option byte
+ tfr  a,b
+ sex
+ sta  domap       top bit:  T=local map follows
+ tfr  b,a
+ anda #$3
+ inca
+ sta  pixel      Bottom 3 bits: bits/pixel less one.
+ lslb
+ sex
+ sta  gifinterlace  Bit 6: T=Use interlace
+ tst  domap     Is there a local color map?
+ beq  nolocal
+ lbsr colormap  Yes, handle it.
+nolocal
+* Now, we're down to the actual image.
+ lbsr I_GetByte  Get the starting code size.
+ sta  mincode
+ cmpa #8        Does code size make sense?
+ bls  gifcodeok
+ lbra E$Format  No, report a format error.
+gifcodeok
+ lbsr lzwinit    Initialize some machinery
+ lbsr gifoutinit
+* From here on, U holds the address of the next entry in the decode table.
+ lbsr clrtable   Clear table, set endcode and clrcode
+imageloop
+ lbsr nexttoken  Get a code.
+ stx  thiscode
+ cmpx endcode    Is it an end-of-pic code?
+ beq  imageend
+ cmpx clrcode    Is it a clear code?
+ bne  imagenormal
+ lbsr clrtable   If so, reinitialize everything.
+ lbsr nexttoken  Get the next token (always a root)
+ stx  lastcode
+ lbsr outcode    Output it.
+ bra  imageloop
+imagenormal
+ lbsr outcode    Output the code, set the initial color var.
+ ldx  lastcode
+ lda  firstcolor
+ stx  ,u++       Add the code to the decode table.
+ sta  ,u+
+ cmpu <codelimit  Are we at the point where we change code size?
+ blo  addcend
+ lbsr setlimit  Yes, do it.
+addcend
+ ldx  thiscode
+ stx  lastcode
+ bra  imageloop
+imageend
+ puls a,b,x,y,u,pc
+
+* This is an extension block, so skip it.
+skipextension
+ pshs a,b,x,y
+ lbsr I_GetByte  Get function code
+extensloop
+ bsr  getpacket  Get packet, size in A.
+ tsta
+ bne  extensloop  Non-zero, get another.
+ puls a,b,x,y,pc
+
+* Get a packet from input into AltBuff, return packet size in A.
+getpacket
+ pshs b,x,y
+ lbsr I_GetByte
+ tsta
+ beq  getpackend
+ pshs a
+ tfr  a,b
+ clra
+ leax altbuff,y
+ tfr  d,y
+ lbsr I_Read
+ lbcs _error
+ puls a
+getpackend
+ puls b,x,y,pc
+
+* Read and process colormap
+colormap
+ pshs a,b,x,y,u
+ lda  pixel
+ bsr  powertwo
+ leax altbuff,y
+ leau alt2buff,y
+ pshs y
+ tfr  d,y
+ leay d,y
+ leay d,y      Y:=3*D
+ lbsr I_Read   Read global color map
+ lbcs _error
+ puls y
+ tst  <screenset Is screen already set?
+ bne  endcmap    Yes, don't process stuff.
+ com  screenset  No, mark it as set.
+ lbsr GIFcolors  Translate colors, and generate color translation table.
+ lbsr setscreen
+ lbsr setbuffer
+ lbsr setpals    Set the palettes
+ lda  background Translate background color through the translation table
+ leau a,u
+ leau a,u
+ lda  a,u
+ lbsr setborder  Set the border color.
+endcmap
+ puls a,b,x,y,u,pc
+
+* Take value in A and return 2**A in D (assumes A<15).
+powertwo
+ pshs a
+ ldd  #1
+ tst  ,s
+powerloop
+ beq  powerend
+ lslb
+ rola
+ dec  ,s
+ bra  powerloop
+powerend
+ leas 1,s
+ rts
+
+* Read and process screen descriptor
+screendesc
+ pshs a,b
+ bsr  GIFgetword
+ std  swidth   First word is screen width in pixels
+ bsr  GIFgetword
+ std  sheight   Next is screen height in pixels
+ lbsr I_GetByte   This is bit-mapped
+ lbcs _error      Bit 7: T= global map follows
+ tfr  a,b         Bits 6:5:4: number bits of "color resolution" - 1
+ andb #7          Bits 2:1:0: Number of bits per pixel - 1
+ incb                     (Determines size of color map)
+ stb  pixel
+ tfr  a,b
+ sex
+ sta  domap  Top bit is true if global color map follows
+ lbsr I_GetByte
+ lbcs _error
+ sta  background
+ lbsr I_GetByte
+ lbcs _error
+ tsta
+ lbne E$Format
+ puls a,b,pc
+
+GIFgetword
+ lbsr I_GetByte
+ lbcs _error
+ tfr  a,b
+ lbsr I_GetByte
+ lbcs _error
+ rts
+
+* Signature: scan input to find "GIF###", the GIF signature string,
+*   where ### is two digits followed by a lowercase letter, e.g.
+*   '87a'
+sigsub
+  lbsr  I_GetByte
+  lbcs  _error
+  rts
+
+signature
+  pshs a,b
+Sig0
+  bsr   sigsub
+Sig1
+  cmpa  #'G     Search for "GIF"
+  bne   Sig0
+  bsr   sigsub
+  cmpa  #'I
+  bne   Sig1
+  bsr   sigsub
+  cmpa  #'F
+  bne   Sig1
+  clrb
+Sig2
+  bsr   sigsub  Get two digits
+  cmpa  #'0
+  blo   Sig1
+  cmpa  #'9
+  bhi   Sig1
+  comb
+  bne   Sig2
+  bsr   sigsub  and one lowercase letter
+  cmpa  #'a
+  blo   Sig1
+  cmpa  #'z
+  bhi   Sig1
+  puls  a,b,pc
+
+
+*
+*LZW decode subs.
+*
+ vsect dp
+codelimit rmb 2  Point at which we must switch code sizes.
+ endsect
+
+* Miscellaneous initialization
+lzwinit
+ pshs a,b,x
+ clr  <packsiz
+ clr  <numbits
+ puls a,b,x,pc
+
+* Initialize the decode table
+*
+clrtable
+ pshs a,b,x,y
+ ldx  giftable  Get start of table
+ lda  mincode
+ lbsr powertwo
+ pshs y
+ tfr  d,y
+ clra
+ clrb
+clrloop
+ sta  ,x+     Roots have 0 for pointer, themselves for suffix
+ std  ,x++
+ incb
+ leay -1,y
+ bne  clrloop
+ puls y
+ stx  clrcode
+ leax 3,x
+ stx  endcode
+ leax 3,x
+ tfr  x,u        Set up nextentry pointer in U
+ lda  mincode
+ sta  codesize   Pretend we were doing "mincode".
+ lbsr setlimit   Bump to next codesize.
+ puls a,b,x,y,pc
+
+ vsect dp
+packptr rmb 2
+packsiz rmb 1 
+ endsect
+* Return next byte from file
+nextbyte
+ pshs x
+ tst  packsiz
+ bne  nextbyte1
+ lbsr getpacket
+ sta  packsiz
+ leax altbuff,y
+ stx  packptr
+nextbyte1
+ dec  packsiz
+ ldx  packptr
+ lda  ,x+
+ stx  packptr
+ puls x,pc
+
+ vsect dp
+numbits rmb 1  Number of bits in bit buffer
+bitbuff rmb 3  Buffer bits from file here
+codemask rmb 2 Mask off just codesize bits.
+ endsect
+* Return next token from file
+nexttoken
+ pshs d
+ ldb  numbits    First, fill bitbuffer with enough bits to make up codesize
+ bra  nexttokst
+nexttokloop
+ ldx  bitbuff    Move other 16 bits forward.
+ stx  bitbuff+1
+ bsr  nextbyte  Get 8 more bits
+ sta  bitbuff
+ addb #8         Increase bit count.
+nexttokst
+ cmpb codesize
+ blo  nexttokloop
+ stb  numbits
+ cmpb #17     Do we have to deal with three bytes?
+ blo  nexttok2 No, 16 or fewer bits, so just deal with two.
+ ldb  #20
+ subb numbits First, we shift until we get to bit #20.
+ clra
+ tfr  d,x
+ ldd  bitbuff We keep first two bytes in D, leave 3rd one in place.
+nexttok31
+ lsra        Analysis shows that we are never past bit 19, so we will
+ rorb        always have to process this loop at least once.
+ ror  bitbuff+2
+ leax -1,x
+ bne  nexttok31
+ tfr  b,a      Now, the first bit of the token we want is out of the first
+ ldb  bitbuff+2 byte, so we're down to two bytes.
+ lsra
+ rorb    Since we start with the least sig bit in bit #20, and we want it
+ lsra    in bit #24, we must shift exactly 4 times.
+ rorb
+ lsra
+ rorb
+ lsra
+ rorb
+ bra  nexttok10  Now we have our token.
+nexttok2
+ cmpb #9      Do we have to deal with two bytes?
+ blo  nexttok1
+ ldb  #16
+ subb numbits
+ clra
+ tfr  d,x
+ ldd  bitbuff
+ stx  -2,s   Test X for zero.
+ beq  nexttok10
+nexttok21
+ lsra
+ rorb
+ leax -1,x
+ bne  nexttok21
+ bra  nexttok10
+nexttok1
+ ldb  bitbuff
+ lda  #8
+ suba numbits
+ beq  nexttok10
+nexttok11
+ lsrb
+ deca
+ bne  nexttok11
+nexttok10
+ anda codemask
+ andb codemask+1
+ ldx  <giftable
+ leax d,x
+ leax d,x
+ leax d,x
+ ldb  numbits
+ subb codesize
+ stb  numbits
+ puls d,pc
+
+outcode
+ pshs a,b,x,y,u
+ ldu  <gifstack
+ cmpx 6,s        U is on the stack.
+ lbhi E$Format   If the code is too large, report a format error
+ beq  outcode1
+ bsr  outcsub    If it's in the table, process it.
+ bra  outcode2
+outcode1
+ ldx  lastcode   If it's not in the table, then it is the last code
+ bsr  outcsub    followed by the first color of the last code.
+ lda  firstcolor
+ lbsr gifoutpix
+outcode2
+ puls a,b,x,y,u,pc
+
+outcsub
+ pshs y 
+ ldy  #0000
+outc1
+ lda  2,x
+ leay 1,y
+ pshu a
+ ldx  ,x
+ bne  outc1
+ tfr  y,x   Put the count in X
+ puls y
+
+ sta  firstcolor  Now we know the first color, so store it.
+
+outc2
+ pulu a
+ lbsr gifoutpix
+ leax -1,x
+ bne  outc2
+ rts
+
+* Add a code to the table
+addcode
+ pshs a,b
+ puls a,b,pc
+
+setlimit
+ pshs a,b,x
+ lda  codesize
+ cmpa #12
+ bhs  setlim1
+ inca
+setlim1
+ sta  codesize
+ lbsr powertwo
+ ldx  giftable
+ leax d,x
+ leax d,x
+ leax d,x
+ stx  codelimit
+ subd #1
+ std  <codemask
+ puls a,b,x,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_gifcol.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,456 @@
+*
+* GIFcolors: Analyze GIF color map, generate CoCo palette and Gif->coco
+*       translation tables.  Expects X to point to GIF color map, D to hold
+*       number of palettes in that color map, and U to point to buffer
+*       to receive translation table.
+*
+* Data structures
+*   Color translation table contains three bytes for each GIF color:
+*       primary color, secondary color, fraction of secondary color for dither
+*
+* Algorithm
+*      First, convert each GIF color to closest CoCo color, and choose
+*   16 "furthest" apart from those for the palette.
+*      For each GIF color in the original GIF palette, interpolate it
+*   between 2 closest colors in the palette.
+*
+* Notes&Assumptions
+*   There are no more than 256 colors in the GIF palette.  So, B holds
+* the number of palettes, where 0 indicates 256.
+*
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+  psect view_gifcol_a,0,0,0,0,0
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ vsect dp
+numpals rmb 1
+ endsect
+
+GIFcolors:
+ pshs a,b,x,y,u
+ pshs a
+ lda  <format
+ cmpa #GIFBWFormat Or if GIFBW format specified.
+ beq  GIFcol0
+ lda  <type
+ cmpa #5    Was type 5,6,7 forced?
+ blo  GIFcol1 Illegal mode, do auto-determine
+ cmpa #7
+ bhi  GIFcol1 Type 8, use full color.
+GIFcol0
+ puls a
+ bsr  bwpals  If yes, convert pals to grey scales, gen b/w palette.
+ bra  GIFcol2
+
+GIFcol1
+ puls a
+ leau  linebuff,y Temporary storage.
+ bsr  copypals   Copy the palettes over.
+ tfr  u,x
+ lbsr genpals    Use GIF palettes to generate a CoCo palette
+GIFcol2
+
+ ldx  2,s
+ ldu  6,s
+ lbsr gentable   Generate a GIF->CoCo translation table
+
+ lbsr palconv    Now convert actual palette values
+
+ lda  <type
+ cmpa #5       
+ blo  GIFcol3    If legal screen type already, skip this.
+ cmpa #8
+ bls  GIFcolend
+GIFcol3
+ lda  #8      Default to type 8 screen
+ ldb  numpals
+ cmpb #4
+ bhi  GIFcolend
+ lda  #7    Use type 7 if 4 or fewer palette colors.
+GIFcolend
+ sta  <type
+
+ puls a,b,x,y,u,pc
+
+* Copy D pals from X to U
+copypals
+ pshs a,b,x,y,u
+ tfr  d,y
+ leay d,y
+ leay d,y
+copyloop
+ lda  ,x+
+ sta  ,u+
+ leay -1,y
+ bne  copyloop
+ puls a,b,x,y,u,pc
+
+* Convert palettes to grey scale values.
+*   D pals pointed to by X.
+bwpals
+ pshs a,b,x,u
+ tfr  x,u
+ pshs b
+bwpals1
+ ldb  ,u
+ lda  #5
+ mul
+ tfr  d,x
+ ldb 1,u
+ lda  #3
+ mul
+ leax d,x
+ ldb 2,u
+ lda  #1
+ mul
+ leax d,x
+ lda  #9
+ lbsr div168
+ stb  ,u+
+ stb  ,u+
+ stb  ,u+
+ dec  ,s
+ bne  bwpals1
+ puls b
+
+ clra
+ leax palette,y
+bwpals2
+ sta  ,x+
+ sta  ,x+
+ sta  ,x+
+ adda #$55
+ bcc  bwpals2
+ lda  #4
+ sta  numpals
+
+ lda  <type   Type 5 only has 2 colors
+ cmpa #5
+ bne  bwpals3
+ leax palette+3,y
+ ldb  #$ff
+ stb  ,x+     Set 2nd color to white
+ stb  ,x+
+ stb  ,x+
+ lda  #2
+ sta  numpals
+bwpals3
+
+ puls a,b,x,u,pc
+
+*
+* Use D pals pointed to by X to create a CoCo palette stored in "palette"
+* in 3-byte format. (one byte each of R, G, B)
+genpals
+ pshs a,b,x,y,u
+ lbsr normpals   Normalize palettes
+ leau palette,y
+ clra
+ bsr  copypal    First one we get for free
+ inca
+* X points to GIF palettes, U points to palettes, A holds number
+* of palettes we've generated so far.
+genloop
+ ldb  1,s
+ ldx  2,s
+ bsr  minmax   Get the farthest palette from the ones already chosen.
+ tstb
+ beq  genpend  If dist is zero, quit now.
+ bsr  copypal  Copy it to the palette.
+ inca
+ cmpa #16
+ bne  genloop
+genpend
+ sta  numpals
+ puls a,b,x,y,u,pc
+
+* From the B many GIF palettes at [X], choose the one farthest from the A many
+* palettes already selected at [U].
+* Local vars:  ,s -- counts down GIF palettes
+*             1,s -- Max dist so far
+*           2:3,s -- Farthest palette seen so far.
+minmax
+ pshs a,y,u
+ pshs x    Init farthest to first
+ clr  ,-s  Init max dist to zero
+ pshs b    Init counter
+minmaxloop
+ bsr  setdist  Get distance from first palette to set of pals.
+ cmpb 1,s      Is it further??
+ bls  minmaxend  If no farther, keep going.
+ stb  1,s     Set new dist, palette.
+ stx  2,s
+minmaxend
+ leax 3,x
+ dec  ,s   Count down palettes.
+ bne  minmaxloop
+ puls b    Remove null counter.
+ puls b    Get distance into B.
+ puls x    Get pointer to farthest one.
+ puls a,y,u,pc
+
+*  X points to a palette, U points to A many palettes.
+* Return (in B) the minimum distance from [X] to [U]
+setdist
+ pshs u
+ bsr  closest
+ puls u,pc
+
+ vsect dp
+nextclose rmb 2
+nextdist  rmb 1
+ endsect
+* X points to one palette, U to A many palettes.
+* Return minimum distance in B, pointer to closest in U.
+closest
+ pshs a,x
+ pshs a    Number of pals on stack.
+ ldb  #$ff  Min dist starts out as $FF.
+ pshs b,u   Store the min so far on the stack
+ stb  nextdist  ... and in the 2nd closest vars.
+ stu  nextclose
+setdistloop
+ bsr  distance
+ cmpb ,s      Is this one closer than the closest so far?
+ bhs  setdist1
+ lda  ,s      Yes, make old closest into 2nd closest.
+ sta  nextdist
+ stb  ,s      and make this closest.
+ ldd  1,s
+ std  nextclose
+ stu  1,s
+ bra  setdist2
+setdist1
+ cmpb nextdist  Is it closer than the 2nd closest so far?
+ bhs  setdist2
+ stb  nextdist  Yes, store it.
+ stu  nextclose
+setdist2
+ leau 3,u
+ dec  3,s
+ bne  setdistloop
+ puls b,u  Get the minimum into B, and the closest in U.
+ puls a
+ puls a,x,pc
+
+* Copy one palette from [X] to [3*A,U] 
+copypal
+ pshs a,u,x
+ leau a,u
+ leau a,u
+ leau a,u
+ lda  ,x+
+ sta  ,u+
+ lda  ,x+
+ sta  ,u+
+ lda  ,x+
+ sta  ,u+
+ puls a,u,x,pc
+
+* Return the distance from the palette value pointed to by X to the value
+* pointed to by U in B
+distance
+ pshs a,x,u
+ clra
+ ldb  ,x+
+ subb ,u+
+ bhi  dist1
+ negb
+dist1
+ pshs d
+ ldb  ,x+
+ subb ,u+
+ bhi  dist2
+ negb
+dist2
+ pshs d
+ ldb  ,x+
+ subb ,u+
+ bhi  dist3
+ negb
+dist3
+ addd ,s++
+ addd ,s++
+ lsra    divide to get it in one byte.
+ rorb
+ lsra
+ rorb
+ puls a,x,u,pc
+
+
+* Normalize D pals pointed to by X into a CoCo 3-byte format
+normpals
+ pshs a,b,x
+normloop
+ bsr  normcoord
+ bsr  normcoord
+ bsr  normcoord
+ subd #1
+ bne  normloop
+ puls a,b,x,pc
+normcoord
+ pshs a,b
+ lda  ,x
+ ldb  #85
+ lbsr divAB Divide by 85.
+ lslb       Round to nearest integer.
+ adca #0
+ ldb  #85   Mult by 85 to get normed value.
+ mul
+ stb  ,x+
+ puls a,b,pc
+
+* X points to D many GIF palettes
+* U points to destination for translation table.
+*
+* Stage 2 algorithm:
+*  For each GIF color, dither the two closest CoCo colors.
+*  Use the ratio of distances as the dithering percentage.
+ csect
+gentpals  rmb 2  Pointer to CoCo palette
+gentcnt   rmb 1  Counts down number of GIF colors
+gentgif   rmb 2  Ptr to GIF colors
+gentred   rmb 1  Holds one palette value.
+gentgrn   rmb 1
+gentblu   rmb 1
+genttrans rmb 2  Ptr to trans table.
+gent1dist rmb 1  Distance to primary color
+gent2dist rmb 1  Distance to secondary color.
+gent1pal  rmb 2  Ptr to primary color
+gent2pal  rmb 2  Ptr to secondary color
+gentvars  rmb 0  Total number of local vars.
+ endsect
+
+gentable
+ pshs a,b,x,y,u
+ leas -gentvars,s
+ stx  gentgif,s
+ stb  gentcnt,s
+ leay palette,y
+ sty  gentpals,s
+ tfr  u,y
+* Y points to trans table address
+* gentgif,s  points to GIF palettes
+* gentpals,s points to CoCo palettes.
+gentloop
+
+* First, try to get a "primary" color.  Use the closest match.
+ lda  numpals     Number of palettes.
+ ldu  gentpals,s  Palette ptr.
+ ldx  gentgif,s   Ptr to GIF palette.
+ lbsr closest     Get closest coco palette (U points to it)
+ stu  gent1pal,s  Save primary color ptr
+ tfr  u,d         Set primary color.
+ subd gentpals,s  D holds offset to closest palette.
+ lbsr div3        Divide B by 3 to get a palette #.
+ stb  ,y
+
+* Now, get an "ideal" secondary color to dither with it.
+ sty  genttrans,s Save Y
+ ldx  gentgif,s   Get ptr to GIF palette that we're trying to match
+ leay gentred,s   Put result in gentred, etc.
+ bsr  opp3
+ ldy  genttrans,s restore Y.
+
+* The closest to this "ideal" color will be our secondary color
+ lda  numpals     Number of palettes.
+ ldu  gentpals,s  Palette ptr.
+* leax gentred,s   Ptr to "ideal" dither match.
+ ldx  gentgif,s
+ lbsr closest
+ cmpu gent1pal,s  Is the closest same as the primary color?
+ bne  gent2c2     No, use the closest.
+ ldu  nextclose  Otherwise, use the second closest.
+gent2c2
+ tfr  u,d
+ stu  gent2pal,s
+ subd gentpals,s
+ bsr  div3
+ stb  1,y
+
+* Calculate distance from desired color to primary color
+ ldu  gent1pal,s
+ ldx  gentgif,s
+ lbsr distance
+ stb  gent1dist,s
+
+* Calculate distance from desired color to secondary color
+ ldu  gent2pal,s
+ ldx  gentgif,s
+ lbsr distance
+ stb  gent2dist,s
+
+* Now, use the two distances to get the dithering percentage.
+ ldb  gent1dist,s   Set % secondary.= (1st dist) / ( (1st dist) + (2nd dist) )
+ beq  gentzero
+ tfr  b,a
+ addb gent2dist,s Add distances, 9 bit result (B + Carry)
+ rorb             Divide B by 2 (include carry from addition)
+ lsra             Div A by 2.
+ lbsr divAB
+gentzero
+ stb  2,y
+
+ leay 3,y         Point to next trans table entry.
+
+ ldx  gentgif,s
+ leax 3,x
+ stx  gentgif,s   Point to next GIF palette.
+
+ dec  gentcnt,s Count down number.
+ bne  gentloop
+
+ leas gentvars,s  Clean up stack.
+ puls a,b,x,y,u,pc
+
+* Returns in [Y], palette value on other side of [X] from [U]
+opp3
+  pshs a,b,x,y,u
+  bsr  opp31
+  bsr  opp31
+  bsr  opp31
+  puls a,b,x,y,u,pc
+opp31
+  ldb  ,x+
+  lda  ,u+
+  bsr  opposite
+  stb  ,y+
+  rts
+
+* returns in B palette value on other side of B from A.
+*  i.e. calculate 2B-A, truncating at zero and at $ff.
+opposite
+  pshs a
+  clra
+  lslb
+  rola
+  subb ,s
+  sbca #0
+  bpl  opp1
+  ldd  #0   If result is negative, chop at zero.
+opp1
+  tsta      If >255, chop there.
+  beq  opp2
+  ldb  #$ff
+opp2
+  puls a,pc
+
+* Divide positive B by 3.
+div3
+ pshs a
+ tfr  b,a
+ ldb  #3
+ lbsr divAB
+ tfr  a,b
+ puls a,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_gifpix.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,421 @@
+*
+* Setup and Screen support for GIF
+*
+* Globals
+*   gifoutinit  -- Initialize output machinery
+*   gifoutpix   -- output one pixel, with scaling, etc.
+*
+ ifp1
+ use  /dd/defs/os9defs.a
+ endc
+
+ psect view_gifpix_a,0,0,0,0,0
+
+*
+* Screen support-- output one GIF pixel to screen, with scaling and dithering.
+*
+ vsect dp
+pixpline  rmb 2  Number of pixels on a virtual screen line.
+pixscrn   rmb 2  Number of pixels on actual screen line.
+pixcnt    rmb 2  Count of pixels on actual screen line.
+lineptr   rmb 2  Pointer to linebuff, for putting pixels
+pixleft   rmb 2  Number of pixels left for this GIF line
+horscale  rmb 2  Horizontal scaling counter.
+linecount rmb 2  Current GIF line number
+linenumb  rmb 2  Current Coco Line number
+linemax   rmb 2  Max Coco line number
+lineinc   rmb 2  Increment between lines
+verscale  rmb 2  vertical scaling counter.
+ endsect
+
+*    gifinterlace  holds T if we do interlace.
+gifoutinit:
+ pshs d,x
+ ldd  #1
+ tst  <gifinterlace
+ beq  init1
+ ldd  #8
+init1
+ std  lineinc
+
+ ldd  #0
+ std  linecount
+ std  horscale
+ std  verscale
+
+ ldd  <Skipcols
+ bpl  init20   Default value is zero
+ ldd  #0
+ std  <Skipcols
+init20
+
+ ldd  <Skiplines
+ bpl  init21   Default value is zero
+ ldd  #0
+ std  <Skiplines
+init21
+
+ ldd  #0
+ subd <Skipcols
+ std  pixcnt
+
+ leax linebuff,y
+ stx  lineptr
+ ldd  <gifiwidth
+ std  pixleft
+
+ ldx  #320   Type 8 and 6 screens are 320 pixels across.
+ lda  <type
+ cmpa #8
+ beq  init8
+ cmpa #6
+ beq  init8
+ ldx  #640   Type 7 and 5 are 640 pixels across.
+init8
+ stx  pixscrn
+ stx  pixpline
+
+ ldd  #192    For default size, scale pic to 192 lines.
+ std  linemax
+
+ lda  <Size
+ bne  init98
+ ldx  <gifiheight  For small, choose divisor of actual height.
+ clra
+ pshs a
+init92
+ inc  ,s
+ lda  ,s
+ lbsr div168  Divide height by number
+ cmpd #200
+ bhi  init92  If not <200, keep going
+ std  linemax
+ puls a       Clear stack
+ bra  init99
+init98
+ cmpa #2
+ bne  init99
+ ldd  <gifiheight  Huge is 1:1 height
+ std  linemax
+ ldd  <gifiwidth   And 1:1 width
+ cmpd <pixscrn     ... but not less than screen width
+ blo  init99
+ std  pixpline
+init99
+
+ puls d,x,pc
+
+* Output pixel to screen
+*
+* Expects
+*    alt2buff holds color translation table
+*    A  holds pixel to output
+*    gifiheight, gifiwidth hold picture dimensions
+gifoutpix:
+ pshs a,b,x
+ tst  verscale
+ bmi  outpix5
+ ldx  lineptr
+ ldd  horscale
+ subd pixpline
+ std  horscale
+ bpl  outpix5
+outpix1
+ ldd  pixcnt
+ addd #1
+ std  pixcnt
+ bmi  outpix11
+ cmpd pixscrn
+ bgt  outpix11
+ lda  ,s
+ sta  ,x+
+outpix11
+ ldd  horscale
+ addd <gifiwidth
+ std  horscale
+ bmi  outpix1
+ stx  lineptr
+outpix5
+ ldx  pixleft  Count down number of GIF pixels on this line.
+ leax -1,x
+ stx  pixleft
+ bne  outpix9
+ tst  verscale
+ bmi  outpix7
+ lbsr dithline  Translate GIF pixels to CoCo colors
+ lbsr convline  Convert the pixels to bytes.
+ lbsr outline   If we're done, output the line.
+ lbsr clrline
+outpix7
+ lbsr setline
+ leax linebuff,y
+ stx  lineptr
+ ldx  <gifiwidth
+ stx  pixleft
+ ldx  #00
+ stx  horscale
+
+ ldd  #0
+ subd <Skipcols
+ std  pixcnt
+outpix9
+ puls a,b,x,pc
+
+dithline
+ pshs a,b,x,y,u
+ leau alt2buff,y  Color mapping table.
+ ldd  pixscrn    Number of pixels on this line.
+ lsra     Divide by 4, since main loop does 4 pixels at a time.
+ rorb
+ lsra
+ rorb
+ pshs b   Even for a 640-pixel line, this will be less than 256.
+ leay linebuff,y  Y points to line data.
+
+ lda  linenumb+1    What line (mod 4) are we on?
+ anda #3
+ leax dithtable,pcr
+ leax a,x
+ jsr  a,x
+ puls b
+ puls a,b,x,y,u,pc
+
+dithtable
+ bra  dithloop1  Different sub for each line (mod 4).
+ bra  dithloop2
+ bra  dithloop3
+ bra  dithloop4
+
+dithloop1
+ bsr  dofastdith
+ ldb  #$60
+ bsr  dodither
+ bsr  dofastdith
+ ldb  #$40
+ bsr  dodither
+ dec  3,s
+ bne  dithloop1
+ rts
+
+dithloop2
+ ldb  #$20
+ bsr  dodither
+ bsr  dofastdith
+ ldb  #$00
+ bsr  dodither
+ bsr  dofastdith
+ dec  3,s
+ bne  dithloop2
+ rts
+
+dithloop3
+ bsr  dofastdith
+ ldb  #$50
+ bsr  dodither
+ bsr  dofastdither
+ ldb  #$70
+ bsr  dodither
+ dec  3,s
+ bne  dithloop3
+ rts
+
+dithloop4
+ ldb  #$10
+ bsr  dodither
+ bsr  dofastdith
+ ldb  #$30
+ bsr  dodither
+ bsr  dofastdith
+ dec  3,s
+ bne  dithloop4
+ rts
+
+* Dither one pixel.  Get GIF color from ,y and convert it into primary
+* color iff B is above the threshold value.
+dodither
+ pshs b
+ ldb  ,y
+ clra
+ leax d,u
+ abx
+ abx
+ lda  ,x   Get primary color.
+ puls b
+ cmpb 2,x  Are we above the threshold?
+ bhs  dodither1
+ lda  1,x  If not, choose secondary color.
+dodither1
+ anda #$0f
+ sta  ,y+  Store the color.
+ rts
+
+* Since every other pixel is gauranteed to be a primary color, it seems
+* worthwhile to have a faster version of the dither sub for that case.
+dofastdith
+ ldb  ,y
+ clra
+ leax d,u
+ abx
+ lda  d,x  Get primary color.
+ anda #$0f
+ sta  ,y+  Store the color.
+ rts
+
+convline
+ pshs a,b,x,y,u
+ lda  <type
+ cmpa #8
+ bne  conv4no
+ bsr  conv4line    Type 8 screen has 4 bits/pixel
+ bra  conv10
+conv4no
+ cmpa #7
+ beq  conv2
+ cmpa #6
+ bne  conv2no
+conv2
+ bsr  conv2line type 7,6 are 2 bits/pix
+ bra  conv10
+conv2no
+ bsr  conv1line type 5 is 1 bit/pix
+conv10
+ puls a,b,x,y,u,pc
+
+conv4table fcb $00,$10,$20,$30,$40,$50,$60,$70,$80,$90,$a0,$b0,$c0,$d0,$e0,$f0
+conv4line
+ leax linebuff,y
+ tfr  x,u
+ leay conv4table,pcr
+ ldb  #160
+ pshs b
+conv4loop
+ lda  ,x+
+ ldb  ,x+
+ orb  a,y
+ stb  ,u+
+ dec  ,s
+ bne  conv4loop
+ puls b
+ rts
+
+conv2table fcb $00,$40,$80,$c0,$00,$10,$20,$30,$00,$04,$08,$0c
+conv2line
+ leax linebuff,y
+ tfr  x,u
+ leay conv2table,pcr
+ ldd  pixscrn
+ lsra
+ rorb
+ lsra
+ rorb
+ pshs b
+conv2loop
+ lda  ,x+
+ lda  a,y  Convert 1st pixel in byte.
+ ldb  ,x+
+ addb #4
+ ora  b,y
+ ldb  ,x+
+ addb #8
+ ora  b,y
+ ora  ,x+
+ sta  ,u+
+ dec  ,s
+ bne  conv2loop
+ puls b
+ rts
+
+conv1line
+ leax linebuff,y
+ tfr  x,u
+ ldy  #80
+conv1loop
+ ldb  #$80
+ pshs b
+ clra
+conv10loop
+ tst  ,x+
+ beq  conv11
+ ora  ,s 
+conv11
+ ror  ,s
+ bne  conv10loop
+ puls b
+ sta  ,u+
+ leay -1,y
+ bne  conv1loop
+ rts
+
+clrline
+ pshs a,b,x,y
+ leax linebuff,y
+ ldy  pixscrn
+ clra
+clrline1
+ sta  ,x+
+ leay -1,y
+ bne  clrline1
+ puls a,b,x,y,pc
+
+nextline
+ pshs d,x,u
+ ldx  lineinc
+ beq  nextline9
+ ldd  verscale
+nextline1
+ tsta           Actually, test sign of D
+ bmi  nextline2
+ subd <gifiheight  If it's positive, that's another screen line.
+ ldu  linenumb
+ leau 1,u
+ stu  linenumb
+ bra  nextline1
+nextline2
+ addd linemax
+ ldu  linecount   That's another gif line.
+ leau 1,u
+ stu  linecount
+ leax -1,x
+ bne  nextline1
+ std  verscale
+nextline9
+ puls d,x,u,pc
+
+setline
+ pshs a,b,x
+ bsr  nextline
+ ldd  linecount
+ cmpd <gifiheight
+ blo  setline5
+ andb #$7
+ beq  setline3
+ ldd  lineinc
+ lsrb
+ std  lineinc
+setline3
+ ldd  #0
+ std  linecount
+ std  linenumb
+ std  verscale
+ ldd  lineinc
+ lsrb
+ clra
+ std  lineinc  Start off by moving 1/2 of the increment
+ bsr  nextline
+ lslb
+ std  lineinc  Now, set the increment right.
+setline5
+ puls a,b,x,pc
+
+outline
+ pshs a,b,x
+ ldd  linenumb
+ subd <Skiplines
+ bmi  outline1
+ cmpd #192
+ bhs  outline1
+ lbsr putline   Put the line onto the screen
+outline1
+ puls a,b,x,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_gifset.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,45 @@
+*
+* Setup for GIF
+*
+* Globals
+*   SetGIF   -- Initialization. Reserves tables, sets format
+*
+ ifp1
+ use  /dd/defs/os9defs.a
+ endc
+
+ psect view_gifset_a,0,0,0,0,0
+
+*
+* GIF initialization
+* Since GIF requires such large tables, we don't allocate them
+* statically, but instead request them from the operating system at
+* run time.
+*
+giftablesize equ 4096*3  3 bytes, 2^12 entries for 12-bit code size
+gifstacksize equ 4096    Stack for reversing the pixel strings from table
+
+SetGIF:
+ pshs a,b,x
+ tst  <format  If format already set, just ignore this.
+ bne  SetGIF1
+ sta  <format  Set format code.
+
+ ldd  #giftablesize+gifstacksize  Allocate the memory
+ lbsr malloc
+ stx  <giftable
+
+ leax giftablesize+gifstacksize,x
+ stx  <gifstack
+SetGIF1
+ puls a,b,x,pc
+
+*
+* Return memory reserved by SetGIF.
+*
+EndGIF:
+ lbsr unmalloc
+ rts
+
+ endsect
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_global.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,175 @@
+*
+* Global definitions for "view" program.
+*
+* This thing is starting to grow, so I figured I'd put all the
+*  global variables in one file for easy reference.
+* Note: root.a initializes all variables to zero, before it sets up
+*   the explicitly initialized variables.  So, all DP vars not explicitly
+*   initialized will be set to zero.  By not including explicit initializations
+*   for such variables, we actually save on code size, since initializing
+*   constants are stored in the module (by RLink).
+*
+
+* stacksize has to be global, because view_io.a uses it to calculate the
+*  amount of buffer space it can use.  If some format needs a lot of
+*  stack space (for large dynamic data structures, or recursive routines),
+*  then this value will have to be changed.
+stk equ 200 Stack space.  This should be enough for everything.
+
+* This seems a good compromise between keeping a large buffer for efficient
+*  throughput, and keeping a small buffer so we don't stall so long on
+*  slowly growing (i.e. downloading) files.
+buffer equ 2000    Space for input buffering and free pool.
+
+   psect  view_global_a,0,0,0,stk+buffer,0
+
+* !"$# RMA won't make something global unless it's in a PSect, so...
+stacksize: equ stk
+
+*   Constant internal codes for various screen formats.
+ csect 0
+ rmb 1        We can't have a zero format code.
+VEFFormat: rmb 1
+VEFSqFormat: rmb 1 VEF Squash format, only used by Save routine.
+MGEFormat: rmb 1   Color Max 3
+MGE640Format: rmb 1  Color Max 3: 640x200x4color
+CM3Format: rmb 1   CoCo Max 3
+CLPFormat: rmb 1   MVCanvas/OS9 CLP clipboard format
+PIXFormat: rmb 1   DS69 16-level 256x256 and 128x128 pictures
+PIX256Format: rmb 1 Force us to interpret it as 256x256
+PIX128Format: rmb 1 as above, 128x128.
+IMGFormat: rmb 1   Rascan IMG format
+RATFormat: rmb 1   RAT format
+P00Format: rmb 1   Support for various Pmodes.
+P01Format: rmb 1
+P10Format: rmb 1   First digit is "Pmode" type, second is 0 or 1
+P11Format: rmb 1   for standard or alternate color set.
+P20Format: rmb 1
+P21Format: rmb 1
+P30Format: rmb 1
+P31Format: rmb 1
+P40Format: rmb 1
+P41Format: rmb 1
+MAXFormat: equ P41Format   Non-artifacted Pmode-4 pictures (Color Max 2)
+ARTFormat: rmb 1   Artifacted Pmode-4 pictures     (Color Max 2)
+MAXCMPFormat: rmb 1 MAXCMP/PIXCMP
+ARTCMPFormat: rmb 1 Above, with artifacting
+RLEFormat: rmb 1   CIS RLE format
+STFormat:  rmb 1   Degas ST format
+MACFormat: rmb 1   Macintosh MacPaint format
+GIFFormat: rmb 1   GIF format
+GIFBWFormat: rmb 1 GIF with B/W rendering.
+PUBFormat: rmb 1   Home publisher clipart format
+ endsect
+
+ csect 128
+MButton:  rmb 1   signal to return on mouse click (by SS.MsSig)
+KButton:  rmb 1   signal to return on keypress.   (by SS.SSig)
+ endsect
+
+ vsect dp
+PID:        rmb 1       Holds Process ID, for Get/Put buffer stuff
+outpath:    fcb 1       Holds path number for current output screen
+format:     rmb 1       Current format code. $ff -> none.
+
+*
+* For better handling of slowly growing files (i.e. viewing files while
+*   they are downloading), set this small (i.e. 100), which will limit
+*   the size of disk reads.
+MaxBuff:    fdb $ffff
+
+* Routines that need large tables can allocate them by moving up
+* MemTop and decreasing MemSiz.  Note that the I/O routines use up
+* all of this when the input file is opened, so such allocation
+* should be done very early.
+MemTop:     rmb 2       Top of allocated data = bottom of free pool
+MemSiz:     rmb 2       Size of free pool
+
+*
+* These are used by view_gfx.a routines for setting up new screens.
+*  Note: for multi-screen displays, "Samescreen" only affects
+*   the first call to "setscreen".
+Samescreen: rmb 1       T = Use same screen, rather than making new one.
+type:       rmb 1       Type of window.  Set before calling "setscreen"
+border:     rmb 1       Border palette to use for this window.
+
+* View sets up a signal trap at the beginning, and sets this variable.
+*  It also sets a mouse signal (MButton).
+*  This variable instructs the signal handler to abort the program
+*  (through the _abort vector in view.a) if a signal occurs.
+* If you want to use the signal, you should clear this variable first.
+*  The keywait routine clears it in order to handle mouse clicks and
+*  such.
+SigCode:    rmb 1       Signal value received by Signal handler. 0=no signal
+abort:      rmb 1       T= abort on any signal.
+
+* For use with slideshow-type programs, the -signal # # option will
+*   set these variables, which will cause VIEW to send the specified
+*   signal rather than ringing the terminal bell.
+SigPID:     rmb 1
+SigOut:     rmb 1
+
+*
+* These are set by command line parameters.
+*   If used by a picture format, it should first check for out-of-range
+*   values.  In particular, if Skiplines is $ffff, it should be re-set
+*   to an appropriate default value.  Ditto for Skipcols
+Skiplines:  fdb $ffff   Number of lines to skip. $ffff -> not set.
+Skipcols:   fdb $ffff   Number of cols to skip.  Used by very wide formats.
+
+* This determines the size of the picture display.  The following
+* values are used:  0=Small (fits on one screen), 1=Big (normal size)
+* 2=Huge (show as much detail as possible, for non-CoCo formats).
+Size:       fcb $ff     $ff -> Use "default" size.
+
+* Variables for various animation effects.
+*   "cycling" refers to rotating a group of palettes
+*       (What CM3 calls "animation)
+*   "extra" variables control rotating several colors through one palette.
+*   To disable cycling, set cyclestart=cycleend
+*   To disable extra rotation, set extranum = 0
+*
+cycle:      rmb 1       T = All animation effects enabled.
+cyclestart: fcb 8       First palette for palette cycling.
+cycleend:   fcb 15      Last palette for palette cycling.
+cyclerate:  fdb 5       Time in ticks between palette cycles.
+extraslot:  rmb 1       Palette slot for color rotation
+extranum:   rmb 1       Number of colors to rotate through that slot
+extrarate:  fdb 5       Time in ticks between color rotation.
+
+*
+*  Flipping is a technique of quickly switching several screens in order
+*    to provide the appearance of a wider palette.
+*  Setting flipping disables all other animation effects.
+*    This variable is ignored if numscreens < 2.  (see view_gfx.a)
+*  Multi-screen displays can set fliprate high (like 100 to 200) to
+*    allow automatic slow cycling between the screens (CM3, for example)
+flipping:   rmb 1       T = multiple screen flipping should be used.
+fliprate:   fdb 2       2 gives best performance for most.
+
+*
+* Set by -q option to 60 times the number of seconds.
+*  counted down by the keywait routine to timeout the display.
+*  the default of 65,536 ticks is a little over 18 minutes.
+* View ends when this variable hits zero.  In reality, due to overhead
+*  in "keywait", the actual delay time tends to be longer than is
+*  actually set here, especially if animation effects are on.
+MaxTime:    fdb $ffff   Max number of ticks to show picture.
+
+* Used by malloc to dynamically request/return memory from the system
+*
+oldmemsize: rmb 2
+newmemsize: rmb 2
+ endsect
+
+*
+* Large buffers.
+ vsect
+extrapals:  rmb 16      Palette codes to rotate through one palette register.
+palette:    rmb 48      Palette codes to be used by "setpals" call.
+linebuff:   rmb 1024    Space for storing lines of graphics to be output.
+altbuff:    rmb 1024    Extra buffer for various uses.
+alt2buff:   rmb 1024    Extra buffer for various uses.
+ endsect
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_help.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,99 @@
+ psect view_help_a,0,0,0,0,0
+Usage:
+ fcc "Usage: view [-<format>] [<options>] <filename>"
+ fcb $0d
+ fcc "Description: Displays a picture file on a Window screen."
+ fcb $0d
+ fcc "Display Options:"
+ fcb $0d
+ fcc "  -s   Use same screen   -q#  Quit after # seconds"
+ fcb $0d
+ fcc "  -c   Enable cycling    -t#  Use this type screen (5,6,7,or 8)""
+ fcb $0d
+ fcc "  -y#  Skip # lines      -x#  Skip # cols"
+ fcb $0d
+ fcc "  -sml, -big, -huge   Display picture in this size."
+ fcb $0d
+ fcc "Other Options:"
+ fcb $0d
+ fcc "  -save <filename>     Save picture in Squashed VEF format"
+ fcb $0d
+ fcc "  -savevef, -savemge, -savecm3   As above, in normal VEF, MGE, or CM3 format"
+ fcb $0d
+ fcc "  -nobuff    Disable input buffering"
+ fcb $0d
+ fcc "  -help      Get this help message"
+ fcb $0d
+ fcc "  -formats   Gives complete list of picture formats supported."
+ fcb $0d
+ fcc "Control Keys:  After picture is displayed, use:"
+ fcb $0d
+ fcc "  Space  Toggle color cycling   Up/Down arrows  Switch screens"
+ fcb $0d
+ fcc "   <,S   Slow down cycling         F1           Toggle screen flipping"
+ fcb $0d
+ fcc "   >,F   Speed up cycling       Break, Mouse    End display"
+ fcb $0d
+ fcc "Ver. 4.4  Tim Kientzle, 1990.  Released into Public Domain."
+ fcb $0d
+ fcc "If you like this, send $10 to: Tim Kientzle, 14 Croxton Ave, Oakland, CA 94611"
+ fcb $0d,0,0
+
+Formats:
+ fcc "VIEW picture formats supported:"
+ fcb $0d
+ fcc "   Picture formats can be specified with a file extension (i.e. file.cm3)."
+ fcb $0d
+ fcc "A command-line argument overrides the file extension."
+ fcb $0d
+ fcc "640: MGE storage format, 640 x 200 x 4 color display."
+ fcb $0d
+ fcc "ART: Artifacted PMode4 images.  Pressing <ENTER> will swap red/blue."
+ fcb $0d
+ fcc "ARTCMP: MAXCMP-generated images, displayed with artifacting."
+ fcb $0d
+ fcc "BIN: PMode4/CoCoMax images, stored in LOADM format."
+ fcb $0d
+ fcc "CLP: OS9/MVCanvas Clip-art format."
+ fcb $0d
+ fcc "CM3: CoCoMax III pictures."
+ fcb $0d
+ fcc "GIF: CompuServe Graphics Interchange Format."
+ fcb $0d
+ fcc "GIFBW, BWGIF, GBW: GIF format, with grey-scale dither."
+ fcb $0d
+ fcc "IMG: Rascan Video Digitizer picture format."
+ fcb $0d
+ fcc "MAC,MCP: Macintosh MacPaint format.  (supports -huge size option)"
+ fcb $0d
+ fcc "MAX: CoCoMax/CoCoMaxII format (same as P41 or BIN)."
+ fcb $0d
+ fcc "MAXCMP: RSBASIC picture programs generated by the MAXCMP program."
+ fcb $0d
+ fcc "MGE: Color Max III format."
+ fcb $0d
+ fcc "P00,P10,P20,P30,P40: Pmode 0/1/2/3/4, color set 0"
+ fcb $0d
+ fcc "P01,P11,P21,P31,P41: Pmode 0/1/2/3/4, color set 1"
+ fcb $0d
+ fcc "PIX: DS69 Digitizer 16-level pictures, uses file size to determine format."
+ fcb $0d
+ fcc "PIX128,PIX256: Forces 128x128 or 256x256 format."
+ fcb $0d
+ fcc "PIXCMP: RSBASIC picture programs generated by the PIXCMP program."
+ fcb $0d
+ fcc "PUB: Home Publisher clipart format."
+ fcb $0d
+ fcc "RAT: The RAT graphics editor format."
+ fcb $0d
+ fcc "RLE: CompuServe VIDTEX 256x192 and 128x96 2-color RLE images."
+ fcb $0d
+ fcc "ST,STP: Degas ST uncompressed format."
+ fcb $0d
+ fcc "VEF: Standard OS9 VDG Extended Format, normal or Squashed."
+ fcb $0d
+ fcc "VF2,...,VF9: Two to nine VEF images in one file, flickered."
+ fcb $0d
+ fcb 0,0
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_img.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,317 @@
+********************************************************************************
+*
+* SUBS for IMG picture formats
+*
+* IMGshowpic -- displays picture on screen
+*
+********************************************************************************
+
+check macro
+      pshs b,cc      This macro will print "ERROR #xxx", where xxx is the
+      ldb  #\1       . number given as an argument.  Very useful for
+      os9  F$PErr    . checkpointing, to make sure certain routines are
+      puls b,cc      . executed.  Printed to StdErr path.
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect view_img_a,0,0,0,0,0
+
+ vsect dp
+nscreens rmb 1   Number of screens in this picture.
+ endsect 
+
+IMGshowpic:
+ bsr  header
+*lbsr setscreen  Unlike some formats, these are handled by "header".
+*lbsr setpals
+ lbsr setbuffer
+
+spscreens
+ lbsr flipscreen   Select next screen
+ ldd  <Skiplines  First, skip any lines.
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ ldd  #00
+ ldx  #25
+showpicloop
+ lbsr getline
+
+ tst  <Size     If we're displaying a "small" pic, skip every 25th line.
+ bne  showpic2
+ leax -1,x
+ bne  showpic2
+ ldx  #25
+ bra  spnoput
+showpic2
+
+ lbsr putline
+ addd #1
+spnoput
+ cmpd #192
+ bne  showpicloop
+spfinish
+ lbsr getline   Read rest of this screen.
+ tst  <endofpic
+ beq  spfinish
+ clr  <endofpic  Clear for next screen.
+spendscreen
+ dec  nscreens  Any more?
+ bne  spscreens Yes, get it.
+ rts
+
+*
+* read header info from file, and set window type information
+*    Uses altbuff.
+*
+ vsect dp
+count      rmb 1     Count/value is used for compressed packets
+value      rmb 1
+straight   rmb 1     Number of straight bytes.
+compressed fcb $ff   T=we're in a compressed block.
+endoffile  rmb 1     T= EOF reached, so always return linebuff all 0
+endofpic   rmb 1     T= end-of-picture seen.
+zeroflag   rmb 1     T= We've seen one zero.. another will be end-of-pic
+ endsect
+
+header
+ pshs a,b,x,y,u
+
+* Set default Skiplines.
+ ldd  <Skiplines
+ cmpd #$ffff
+ bne  headskip
+ ldd  #0
+ std  <Skiplines
+headskip
+
+* Set default Size
+ lda  <Size
+ bpl  headsize
+ lda  #1
+ sta  <Size
+headsize
+
+* Cancel any color cycling or rotation
+ lda  <cyclestart   one-palette cycle is effectively none
+ sta  <cycleend
+ clr  <extranum     no colors to rotate.
+
+* Now, read in header
+ leax altbuff,y read in type and palettes
+ pshs y
+ ldy  #18      Number of bytes in header.
+ lbsr I_Read
+ lbcs _error
+ puls y
+ leax altbuff,y
+ lda  ,x+      This byte contains RGB/CMP bit and other useless info.
+
+ lda  ,x+      This specifies the picture format and palettes to be used.
+
+ cmpa #0       Dithered grey
+ bne  header0
+ lda  #7
+ sta  <type
+ lbsr setscreen
+ lda  #1
+ sta  nscreens
+ lda  #3
+ lbsr setborder
+ leax greypals,pcr
+ lbsr headpals
+ bra  headend
+header0
+
+ cmpa #1       false 16-color
+ bne  header1
+ lda  #8
+ sta  <type
+ lbsr setscreen
+ lda  #1
+ sta  nscreens
+ lda  #15
+ lbsr setborder
+ lbsr  headpals  Use palettes in header
+ bra   headend
+header1
+
+ cmpa #2        Solid grey
+ bne  header2
+ leax greypals,pcr  Set pals to grey palettes.
+ lda  #7            Use type 7 screen
+ sta  <type
+ lbsr setscreen     Set it.
+ lda  #1
+ sta  nscreens  Only one screen for this format.
+ lda  #3
+ lbsr setborder
+ lbsr headpals
+ bra  headend
+header2
+
+ cmpa #3
+ bne  header3
+ lda  #7
+ sta  <type
+ lda  #3
+ sta  nscreens
+ lda  #$ff
+ sta  <flipping   Turn on flipping.
+ lbsr setscreen   Set up red screen
+ lda  #3
+ lbsr setborder
+ leax redpals,pcr
+ lbsr headpals
+ lbsr setscreen   Set up green screen
+ lbsr setborder
+ leax greenpals,pcr
+ lbsr headpals
+ lbsr setscreen   Set up blue screen
+ lbsr setborder
+ leax bluepals,pcr
+ lbsr headpals
+ bra  headend
+header3
+
+ lbsr E$Format   Illegal file format.
+
+
+headend
+ puls a,b,x,y,u,pc
+
+headpals 
+ pshs a,b,x,u    Set the palettes.
+ leau palette,y
+ ldb  #16
+headloop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  headloop
+ lbsr setpals
+ puls a,b,x,u,pc
+
+greypals  fcb $3f,$38,$07,$00  Only first four palettes matter here.
+redpals   fcb $24,$20,$04,$00
+greenpals fcb $12,$10,$02,$00
+bluepals  fcb $09,$08,$01,$00
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+ leau linebuff,y   First, clear out line buffer to $ff, the background pattern.
+ ldx  #160
+ lda  #$ff   Since palette 3 is the background, use this for fill pattern.
+getl1
+ sta  ,u+
+ leax -1,x
+ bne  getl1
+
+ tst  endoffile    Are we at end-of-file?
+ lbne getline1     Yes, just leave buffer of zeros
+ tst  endofpic
+ lbne getline1
+
+* Get a line from file
+ leau linebuff,y   Where we'll put the line.
+ ldx  #160         Number of bytes in one line.
+* Check if we're in a compressed or uncompressed packet.
+ tst  count      Did we reach the end of the line in a compressed packet?
+ bne  uncompress Yes, finish uncompressing
+ tst  straight   Did we reach it in a straight packet?
+ bne  copystraight Yes, finish the packet.
+ tst  compressed Did we just finish a straight packet?
+ beq  getcomp    Yes, we're just starting a compressed one.
+* Get a straight packet
+getstraight
+ clr  compressed    Mark that we're in a straight packet
+ lbsr I_GetByte
+ bcs  geteof
+ sta  straight
+ bne  copystraight non-zero count, handle it.
+ tst  zeroflag
+ bne  geteop       If already one zero, set endofpic
+ com  zeroflag     Otherwise, set zeroflag.
+ bra  getcomp      If zero, next type of packet.
+* Read in straight data
+copystraight
+ clr  zeroflag
+ ldb  straight     Get number of bytes
+getstr1
+ lbsr I_GetByte    Get the next byte
+ bcs  geteof
+ sta  ,u+          Store the byte.
+ decb              Count down number of reps
+ leax -1,x         Count down size of line
+ beq  getstr2      If end of line, finish.
+ tstb
+ bne  getstr1
+ stb  straight
+ bra  getcomp      Get a compressed packet.
+getstr2
+ stb  straight     Hit end of line, store remaining count.
+ bra  getline1
+* Get a compressed packet
+getcomp
+ com  compressed    Mark that we're in a compressed packet
+ lbsr I_GetByte
+ bcs  geteof
+ sta  count
+ bne  getcomp1
+ tst  zeroflag
+ bne  geteop       If already one zero, set endofpic
+ com  zeroflag     Otherwise, set zeroflag.
+ bra  getstraight  If zero, next type of packet.
+getcomp1
+ lbsr I_GetByte
+ bcs  geteof
+ sta  value
+* Expand compressed data
+uncompress
+ clr  zeroflag
+ ldd  count        Get count/value
+getunc1
+ stb  ,u+          Store a copy of current value
+ deca              Count down number of reps
+ leax -1,x         Count down size of line
+ beq  getunc2      If end of line, finish.
+ tsta
+ bne  getunc1
+ std  count
+ bra  getstraight  Get a straight packet.
+getunc2
+ std  count        Otherwise, store remaining count.
+ bra  getline1
+
+geteop
+ lda  #$ff
+ sta  endofpic    Mark end of picture.
+ sta  compressed
+ clr  straight
+ clr  count
+ clr  zeroflag    Clear zeroflag.
+ bra  getline1
+geteof
+ cmpb #E$EOF
+ lbne _error
+ lda  #$ff
+ sta  endoffile   endoffile is also endofpic
+ sta  endofpic
+getline1
+ puls a,b,x,y,u,pc
+
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_io.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,232 @@
+*************************************************************************
+*
+* Buffered input routines
+*
+* I_Open    - Opens file.  X -> filename, A has permissions
+* I_Read    - Read Y bytes from file into [X]
+* I_GetByte - Returns one byte from file in A.
+* I_Close   - Closes file.
+* I_Size    - returns file size, truncated to $FFFF
+*
+* Terminal output routines
+*
+* O_Write   - Uses I$WritLn to output null-terminated string.
+*
+* Note: as with OS9 I$ system calls, all calls return Carry clear if
+*   no error.  If there is an error, Carry is set, and the error code is in B
+*
+* Global var:
+*    FilePos:  2-byte total number of bytes returned by I_Read or I_GetByte
+*
+*************************************************************************
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdIn  equ 0
+StdOut equ 1
+StdErr equ 2
+
+ psect View_IO_a,0,0,0,0,0
+
+
+ vsect dp
+FilePos:  rmb 2   Current File position
+Buffsize  rmb 2   Size of buffer area
+Buffer    rmb 2   Start of buffer
+Buffstart rmb 2   Start of data in buffer
+Buffend   rmb 2   End of data in buffer
+Path      rmb 1   Path number of file
+errorno   rmb 1   Last error number.
+ endsect
+
+*
+* Open file, initialize buffering
+*
+I_Open:
+ pshs x,a,b
+ clr  errorno
+ ldd  <MemSiz     Use as much memory as is free.
+ cmpd <MaxBuff    But in no case use more than MaxBuff space.
+ blo  IO1
+ ldd  <MaxBuff
+IO1
+ std  Buffsize
+ ldx  <MemTop    Buffer starts at MemTop
+ stx  Buffer
+ stx  Buffend
+ stx  Buffstart
+ leax d,x
+ stx  <MemTop    Move MemTop up
+ pshs d
+ ldd  <MemSiz    Decrease MemSiz accordingly
+ subd ,s++
+ std  <MemSiz
+ puls x,a,b
+ cmpx #0000
+ bne  IO2
+ lda  #StdIn
+ bra  IO3
+IO2
+ os9  I$Open
+ bcs  IOexit
+IO3
+ sta  Path
+IOexit
+ rts
+
+*
+* Return Y bytes from input file, to [X]
+*
+I_Read:
+ cmpy #0
+ beq  _I_R_quit
+ tst  errorno   If there's an error from the last operation,
+ beq  _I_Read     return that as an error code.
+ ldb  errorno
+ orcc #Carry    Set carry.
+_I_R_quit
+ rts
+
+_I_Read
+ pshs a,b,x,u
+ pshs x        Extra copy of initial pointer, for final calculation
+IR_Again
+ ldu  Buffstart  Get start of data
+IR_Loop
+ cmpu Buffend   Is this the end?
+ bne  IR_go
+ bsr  fillBuff  Yes, fill buffer from file
+ bcc  IR_Again
+ stb  errorno   store error if any
+ andcc #^Carry  clear carry
+ bra  IR_exit   return
+IR_go
+ lda  ,u+       move one byte
+ sta  ,x+
+ leay -1,y      Does this fill the request?
+ bne  IR_Loop   No, keep going.
+ andcc #^Carry
+IR_exit
+ pshs cc        Save condition codes, especially Carry
+ stu  Buffstart Save new start of buffer
+ tfr  x,d       Calculate number of bytes copied.
+ subd 1,s
+ tfr  d,y       Y has number of bytes copied
+ addd FilePos   Update FilePos counter.
+ std  FilePos
+ puls cc        Restore CC
+ puls d         Clean up stack.
+ puls a,b,x,u,pc
+
+
+*
+* Return a single byte from input file, return in A
+*
+I_GetByte:
+ tst  errorno   If there's an error from the last operation,
+ beq  _I_GetByte     return that as an error code.
+ ldb  errorno
+ orcc #Carry    Set carry.
+ rts
+_I_GetByte
+ pshs x,b
+ ldx  Buffstart  Get start of data
+ cmpx Buffend   Is this the end?
+ bne  IG_go
+ bsr  fillBuff  Yes, fill buffer from file
+ bcc  IG_go
+ stb  errorno   store error if any
+ andcc #^Carry  clear carry
+ bra  IG_exit   return
+IG_go
+ ldx  Buffstart
+ lda  ,x+       move one byte
+ stx  Buffstart
+ ldx  FilePos
+ leax 1,x
+ stx  FilePos
+ andcc #^Carry
+IG_exit
+ puls b,x,pc
+
+fillBuff
+ pshs a,x,y
+ lda  Path
+ ldy  Buffsize  Maximum number of characters we can buffer
+ ldx  Buffer    Location of buffer
+ stx  Buffstart First char in buffer
+ os9  I$Read
+ bcs  fillexit
+ pshs b
+ tfr  y,d
+ leax d,x
+ stx  Buffend  Set end of buffer
+ puls b
+ andcc #^Carry
+fillexit
+ puls a,x,y,pc
+
+*
+* Close input file
+*
+I_Close:
+  pshs a
+  lda  Path
+  os9  I$Close
+  puls a,pc
+
+*
+* Return size of file in D  (truncated to $ffff)
+*
+I_Size:
+  pshs x,u
+  lda  Path
+  ldb  #SS.Size
+  os9  I$GetStt
+  bcs  ISexit
+  tfr  u,d
+  cmpx #0000    Is top 16 bits = 0000 ??
+  beq  ISexit
+  ldd  #$ffff   No, return file size = $ffff
+ISexit  
+  puls x,u,pc
+
+*
+* Input: X points to null-terminated string, possibly containing embedded
+*    CR characters.
+* String is output to StdOut, with full line editing a la I$WritLn
+*
+O_Write:
+  pshs a,x,y
+  pshs x
+  ldy  #0
+  lda  ,x+
+  beq  OWexit
+OWloop
+  leay 1,y
+  lda  ,x+
+  bne  OWloop
+  ldx  ,s
+
+OWloop1
+  sty  ,s
+  lda  #StdOut
+  os9  I$WritLn
+  bcs  OWexit    
+  pshs y
+  ldd  ,s
+  leax d,x
+  ldd  2,s
+  subd ,s++
+  tfr  d,y
+  bne  OWloop1
+
+OWokay
+  andcc #^Carry
+OWexit
+  puls x
+  puls a,x,y,pc
+
+  endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_mac.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,419 @@
+********************************************************************************
+*
+* SUBS for MAC picture formats
+*
+* MACshowpic -- displays picture on screen
+*
+********************************************************************************
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+StdOut equ 1
+StdErr equ 2
+
+ psect view_mac_a,0,0,0,0,0
+
+ vsect dp
+curline  rmb 2
+pictheight rmb 2
+fitcount rmb 2
+ endsect
+
+MACshowpic:
+ bsr  header
+
+ ldd  <Skiplines
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ lbsr setscreen
+ lbsr setpals
+ lbsr setbuffer
+
+ ldd  #720
+ std  fitcount
+
+spscreens
+ ldd  #00
+showpicloop
+ tst  <endoffile  Quit on end-of-file.
+ bne  showpicend
+ std  curline
+ tst  fitcount
+ bpl  spget
+ lbsr outline
+ addd #1
+ std  curline
+ ldd  fitcount
+ addd #720
+ bra  spendloop
+spget
+ lbsr getline
+ ldd  fitcount
+ subd pictheight  Number of lines in screen display.
+spendloop
+ std  fitcount
+ ldd  curline
+ cmpd #192
+ bne  showpicloop
+
+ tst  <Size
+ beq  showpicend
+ lbsr getline
+ ldd  #720
+ subd pictheight
+ std  fitcount
+ tst  <endoffile
+ bne  showpicend
+ lbsr setscreen
+ lbsr setpals
+ bra  spscreens
+
+showpicend
+ lbsr flipscreens
+ rts
+
+*
+* read header info from file, and set window type information
+*    Uses altbuff to read header info into.
+*
+ vsect dp
+count      rmb 1     Count/value is used for compressed format
+value      rmb 1
+straight   rmb 1
+endoffile  rmb 1     T= EOF reached, so always return linebuff all 0
+numlines   rmb 2
+ endsect
+
+header
+ pshs a,b,x,y,u
+ lbsr I_GetByte
+ lbcs _error
+ lbsr I_GetByte
+ lbcs _error
+
+ leax altbuff,y read in type and palettes
+ pshs y
+ ldy  #255
+ lbsr I_Read
+ lbcs _error
+ ldy  #255
+ lbsr I_Read
+ lbcs _error
+ tsta
+ beq  shorthead
+ ldy  #128
+ lbsr I_Read
+ lbcs _error
+shorthead
+ puls y
+
+ ldx  #720
+ stx  numlines
+
+ lda  <type
+ bne  headtype
+ lda  #7
+ sta  <type
+headtype
+
+* Set limits for palette rotation
+ lda  <cyclestart
+ sta  <cycleend
+
+* Set default Skiplines.
+ ldd  <Skiplines
+ cmpd #$ffff
+ bne  headskip
+ ldd  #0
+ std  <Skiplines
+headskip
+
+ lda  <Size
+ bpl  headsize
+ lda  #0      Default size is small.
+ sta  <Size
+headsize
+
+* Set picture height.
+ ldx  #192    192 lines in "small" size picture.
+ cmpa #1
+ bne  headh2
+ ldx  #327    Big display is 327 lines
+headh2
+ cmpa #2
+ bne  headh3
+ ldx  #720   Huge display is 720 lines
+headh3
+ stx  pictheight
+
+* Set palette
+ ldd  #$3f38
+ std  palette,y
+ ldd  #$0700
+ std  palette+2,y
+
+ lda  <type
+ cmpa #5
+ bne  setpal5
+ ldd  #$3f00
+ std  palette,y
+setpal5
+
+ puls a,b,x,y,u,pc
+
+pal8 fcb $3f,$38,$38,7,$3f,$38,7,7,$38,$38,7,0,$38,7,7,0
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* Clear out linebuffer,altbuff
+ leax altbuff,y
+ clra
+ ldb  #160
+getl1
+ sta  ,x+
+ decb
+ bne  getl1
+
+ tst  endoffile    Are we at end-of-file?
+ bne  getline1
+
+* Count down number of lines
+ ldd  numlines
+ beq  geteof1
+ subd #1
+ std  numlines
+
+* Get a line from compressed file
+ leau altbuff,y  Where we'll put the line.
+ ldb  #72        Number of bytes in one line.
+ lda  count
+ bne  getcomp1
+ lda  straight
+ bne  getstr1
+getpacket
+ lbsr I_GetByte
+ bcs  geteof
+ tsta
+ bpl  getstraight
+* Handle compressed packet
+getcomp
+ coma
+ adda #2
+ sta  count
+ lbsr I_GetByte
+ bcs  geteof
+ sta  value
+getcomp1
+ lda  value
+getcloop
+ sta  ,u+
+ dec  count
+ decb
+ beq  getline1
+ tst  count
+ beq  getpacket
+ bra  getcloop
+ 
+* Handle uncompressed section
+getstraight
+ adda #1
+getstr1
+ sta  straight
+getsloop
+ lbsr I_GetByte
+ bcs  geteof
+ sta  ,u+
+ dec  straight
+ decb
+ beq  getline1
+ tst  straight
+ beq  getpacket
+ bra  getsloop
+
+* Check for EOF.
+geteof
+ cmpb #E$EOF      We have a special message for premature EOF
+ bne  getnor1
+geteof1
+ com  endoffile   Flag end-of-file condition
+ bra  getline1    Keep on going.
+getnor1
+ lbra _error      If not EOF, just exit with error.
+getline1
+ tst  <Size
+ bne  getwide
+ lbsr squish     If small size, squish the data down.
+ bra  getdone
+getwide
+ lbsr widen
+getdone
+ lbsr expand     Now that we have the data, set it up in linebuff.
+ puls a,b,x,y,u,pc
+
+ vsect dp
+expcount rmb 1
+ endsect
+
+clrbuff
+ pshs a,b,x
+ leax linebuff,y
+ ldb  #160
+ clra
+ sta  expcount
+clrloop
+ sta  ,x+
+ decb
+ bne  clrloop
+ puls a,b,x,pc
+ 
+exptable fcb $00,$01,$04,$05,$10,$11,$14,$15,$40,$41,$44,$45,$50,$51,$54,$55
+
+expand
+ pshs a,b,x,u,y
+ lda  expcount  We can merge at most three lines.
+ inca
+ cmpa #4
+ bhs  expend   If four or more, then just skip this step.
+ sta  expcount
+
+ leax altbuff,y
+ leau linebuff,y
+ leay exptable,pcr
+ ldb  #72
+exploop
+ lda  ,x
+ lsra
+ lsra
+ lsra
+ lsra
+ lda  a,y
+ adda ,u
+ sta  ,u+
+ lda  ,x+
+ anda #$0f
+ lda  a,y
+ adda ,u
+ sta  ,u+
+ decb
+ bne  exploop
+expend
+ puls a,b,x,y,u,pc
+
+*
+* Output a line to the screen, and get ready for next one.
+*
+outline
+ lbsr expand  Make sure that a full 3 lines are expanded before output.
+ lbsr expand
+ pshs a,x
+ lda  <type
+ cmpa #7    Default screen type
+ beq  outline9
+ cmpa #8
+ beq  outline8
+ cmpa #6
+ beq  outline6
+outline5
+ leax linebuff,y  Handle conversion to type 5 screen
+ lbsr MAC75
+ bra  outline9
+outline6
+ leax linebuff,y  Handle conversion to type 6 screen
+ lbsr MAC76
+ bra  outline9
+outline8
+ leax linebuff,y
+ lbsr MAC76
+ lbsr MGE68
+outline9
+ puls a,x
+ lbsr putline
+ lbsr clrbuff
+ rts
+
+*
+* Squish a 576-pixel line down to preserve aspect ratio.
+* First try: 8 pixels down to 5
+*
+squish
+ pshs a,b,x,y,u
+ pshs y         Save this, we'll need it later.
+ leax altbuff,y
+ leau alt2buff,y
+ ldy  #72       Count down number of bytes.
+ ldb  #1    Prime B to receive bits.
+sqloop
+ lda  ,x
+ clr  ,x+  Clear altbuff as we go along.
+ lsla
+ bsr  addbit
+ lsla
+ bsr  addbit
+ lsla
+ lsla
+ bsr  addbit
+ lsla
+ bsr  addbit
+ lsla
+ lsla
+ bsr  addbit
+ leay -1,y
+ bne  sqloop
+ puls y 
+
+ leax altbuff+17,y  Now copy the squished line over to altbuff.
+ leau alt2buff,y
+ ldb  #45  Number bytes to move.
+sq1loop
+ lda  ,u+
+ sta  ,x+
+ decb
+ bne  sq1loop
+ puls a,b,x,y,u,pc
+
+addbit
+ rolb
+ bcc  addend
+ stb  ,u+
+ ldb  #1   Single 1 bit will tell us when we're done.
+addend
+ rts
+
+*
+* Move "wide" data into place.
+*
+widen
+ pshs a,b,x,y,u
+ leax altbuff,y
+ leax 72,x
+ leau altbuff,y
+ leau 76,x
+ ldy  #36       Move 36 double-bytes.
+wiloop
+ ldd  ,--x
+ std  ,--u
+ leay -1,y
+ bne  wiloop
+ ldd  #0
+ std  ,--u  Clear out remaining.
+ std  ,--u
+ puls a,b,x,y,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_max.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,411 @@
+*
+*
+* SUBS for Pmode 4  picture format
+*
+* MAXshowpic -- Displays picture, using putline routine
+*
+*
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect  view_max_a,0,0,0,0,0 
+
+ vsect dp
+totlines rmb 2
+fitcount rmb 2
+linesize rmb 2
+ endsect
+
+MAXshowpic:
+ bsr  header       Read header info, set palettes, etc.
+
+ pshs d
+ ldd  <Skiplines
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ lbsr setscreen
+ lbsr setpals
+ lbsr setbuffer
+ lda  <border
+ lbsr setborder  Set the border appropriately.
+ lbsr getline
+
+spscreens
+ lbsr nextline
+ ldd  fitcount
+ addd totlines
+spget
+ std  fitcount
+ lbsr getline
+ tst  <Size
+ bne  spnofit
+ ldd  fitcount
+ subd #192
+ bge  spget
+ std  fitcount
+spnofit
+ tst  <endoffile
+ beq  spscreens
+
+showpicend
+ lbsr flipscreens
+
+ lda  <format
+ cmpa #MAXCMPFormat  If it's MAXCMP or ARTCMP, return extra memory.
+ beq  spspecial
+ cmpa #ARTCMPFormat
+ bne  spnormal
+spspecial
+ lbsr EndMAXCMP
+spnormal
+
+ puls d,pc
+
+*
+* read header info from file, and set window type information
+*
+ vsect dp
+endoffile   rmb 1
+totsize   rmb 2
+double rmb 1   True: each line gets doubled.
+doublef rmb 1  True: this is first time this line's been returned.
+fillval rmb 1  Value to blank out lines with.
+pmode   rmb 1  Pmode 0,1,2,3,4,5=Art.
+pformat rmb 1  Pseudo-format: maxcmpformat ->p41format, artcmp -> art
+ endsect
+
+sizetable fcb 16,32,16,32,32,32  Bytes/line in PMode 0,1,2,3,4, ART
+
+header
+ pshs a,b,x,y,u
+
+ lda  <format
+ cmpa #MAXCMPFormat   Handle MAXCMP specially
+ bne  headmode1
+ lda  #P41Format      MAXCMP looks like PMode 4
+ bra  headmode2
+headmode1
+ cmpa #ARTCMPFormat  Handle ARTCMP specially
+ bne  headmode2
+ lda  #ARTFormat     ARTCMP looks like ART
+headmode2
+ sta  <pformat
+
+ lda  <pformat
+ suba #P00Format
+ lsra           Divide by two, so A holds the pmode
+ sta  pmode
+ leax sizetable,pcr
+ ldb  a,x
+ clra
+ std  linesize   Set number bytes/line
+
+ lda  <pformat
+ cmpa #ARTFormat
+ beq  headbord    ART is _really_ a 2-color mode. 
+ suba #P00Format  2-color modes need border set to 3, 4 color to 0
+ anda #2
+ bne  headbord1
+headbord
+ lda  #3
+ sta  <border
+ lda  #$ff
+ sta  fillval
+headbord1
+
+ lda  <pmode
+ cmpa #1      For PMode's 0 and 1, we double each line to simulate
+ bhi  headdoub    96 line graphics screen
+ com  double
+headdoub
+
+ leax altbuff,y Read in header into altbuff
+ lda  <format
+ cmpa #MAXCMPFormat  First, is this MAXCMP or ARTCMP?
+ beq  headspecial
+ cmpa #ARTCMPFormat
+ beq  headspecial    If so, go decode it, etc.
+ pshs y
+ ldy  #5       Otherwise, just read the header.
+ lbsr I_Read
+ lbcs _error
+ puls y
+ bra  headnormal
+headspecial
+ lbsr MAXCMPdecode  Decode MAXCMP picture, set up header info at ,X
+headnormal
+
+ lda  #6
+ sta  <type   Use screen type 6: 320x192 by 4 color
+
+ leax altbuff,y Now, interpret header.
+ lda  ,x+
+ lbne E$Format  This must be zero.
+ ldd  ,x++
+ std  totsize   This gives total # bytes in file.
+ ldu  linesize  Calculate total number of lines in file.
+ pshs u
+ lsr  1,s
+calclines
+ lsra        Since linesize is always a power of two, this works.
+ rorb
+ lsr  1,s
+ bne  calclines
+ puls u
+ tst  double   Are we doubling lines?
+ beq  doubtot  
+ lsla        Yes, double the number of lines for proper scaling.
+ rolb
+doubtot
+ std  totlines
+
+ leax pals01,pcr  First, handle artifacted stuff as a special case.
+ ldb  <pmode
+ cmpb #5
+ beq  headpals
+ leax pals00,pcr
+ ldb  <pformat
+ subb #P00Format  Formats alternate between the 4 palette choices.
+ andb #3          So, interpret mod 4.
+ lslb             Times 4 to get the beginning of the palette
+ lslb
+ abx
+
+headpals
+ leau palette,y
+ ldb  #16
+ pshs b
+headloop
+ lda  ,x+
+ sta  ,u+
+ dec  ,s
+ bne  headloop
+ puls b
+
+* Set some miscellaneous variables
+ lda  #1
+ sta  <cyclestart   Cycle palettes 1 and 2 to allow switching artifact modes
+ lda  #2
+ sta  <cycleend
+ clr  <cycle
+ clr  <extranum lda  No color rotation
+
+ ldd  <Skiplines
+ cmpd #$ffff        Is Skiplines still default?
+ bne  headskip      No, don't change it.
+ ldd  #0
+ std  <Skiplines   Set it to 0
+headskip
+
+ lda  <Size
+ bpl  headsize
+ lda  #1      Default to BIG size
+ sta  <Size
+headsize
+
+ puls a,b,x,y,u,pc
+
+* Palettes for 2-color set 0, 2-color set 1, 4-color set 0, and 4-color set 1
+pals00  fcb 0,0,0,18   Black and green.
+pals01  fcb 0,9,36,63  Includes artifacted colors.
+pals10  fcb 18,54,36,9
+pals11  fcb 63,27,45,38
+
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* If doublef is set, return same line again
+ tst  double  Is double in effect?
+ beq  nodoub  No, just do normal thing.
+ tst  doublef
+ bne  getline1
+nodoub
+* First, clear out buffer
+ leau linebuff,y
+ lda  fillval
+ ldb  #160
+getline3
+ sta  ,u+
+ decb
+ bne  getline3
+* If at end of file, leave it that way
+ tst  endoffile
+ lbne getline1
+* Get a line from the file
+ leax linebuff+8,y     read in one line of screen
+ ldd  <totsize
+ cmpd linesize
+ bhs  getlok
+ com  endoffile  If <1 line left, mark end of file and quit.
+ lbra getline1
+getlok
+ pshs y
+ ldy  linesize     Get 1 line's worth
+ lbsr getmaxline
+ puls y
+ lbcs geteof       Error through EOF check.
+ ldd  <totsize
+ subd linesize     Count down bytes in file.
+ std  <totsize
+* Now, we have to expand the bytes to get a good picture format.
+ ldb  <pmode
+ bitb #1       Odd pmode's are 4-color
+ bne  cnvcol
+cnvbw
+ bsr  oneexpand    Everything else is 2-color.
+ bra  cnvfinish
+cnvcol
+ bsr  twoexpand
+cnvfinish
+ ldd  linesize
+ lslb    We already doubled the line size once.
+cnfloop
+ cmpb #64
+ bhs  getline7
+ bsr  twoexpand  Expand out line until it's 64 bytes long.
+ lslb
+ bra  cnfloop
+
+getline7
+ tst  <Size
+ bne  getline1  If Big or larger, don't do horizontal scaling
+ ldd  <totlines
+ cmpd #300
+ blo  getline1  If not double-page, don't do scaling.
+ bsr  horscale  Do the scaling
+ bra  getline1  End.
+
+geteof
+ cmpb #E$EOF
+ bne  getline4
+ com  endoffile
+ bra  getline1
+getline4
+ lbra _error      If not EOF, just exit with error.
+getline1
+ com  doublef     Complement double flag.
+ puls a,b,x,y,u,pc
+
+* X points to location, Y holds needed count
+getmaxline
+ pshs a
+ lda  <format
+ cmpa #MAXCMPFormat
+ beq  getlinespecial
+ cmpa #ARTCMPFormat
+ beq  getlinespecial
+
+ lbsr I_Read     Just Read line if normal file
+ bra  getlinenormal
+getlinespecial
+
+ lbsr MAXCMPline
+getlinenormal
+ puls a,pc
+
+arttable fcb $00,$05,$0A,$0F,$50,$55,$5A,$5F,$A0,$A5,$AA,$AF,$F0,$F5,$FA,$FF
+pm4table fcb $00,$03,$0C,$0F,$30,$33,$3C,$3F,$C0,$C3,$CC,$CF,$F0,$F3,$FC,$FF
+
+oneexpand
+ pshs a,b,x,y,u
+ leay pm4table,pcr  Expand each 1 bit to 2 bits
+ bra  cnvdo
+twoexpand
+ pshs a,b,x,y,u
+ leay arttable,pcr  Double each 2 bits
+cnvdo
+ leau 64,x
+ leax 32,x  Expand 32 bytes out to 64.
+ lda  #32
+ pshs a
+cnvloop
+ lda  ,-x
+ tfr  a,b
+ lsra
+ lsra
+ lsra
+ lsra
+ andb #$0f
+ lda  a,y
+ ldb  b,y
+ std  ,--u
+ dec  ,s
+ bne  cnvloop
+ puls a
+ puls a,b,x,y,u,pc
+
+*
+* Take the picture line and squeeze it horizontally by half.
+*
+horscale
+ pshs a,b,x,u
+ leax linebuff+8,y
+ leau linebuff+8,y
+ bsr  horsub1
+ leax linebuff+72,y
+ leau linebuff+40,y
+ bsr  horsub2
+ puls a,b,x,u,pc
+
+horsub0
+ bsr  horsuba  Do it twice.
+horsuba
+ lslb   Move 1 pixel over, skip one.
+ rola
+ lslb
+ rola
+ lslb
+ lslb
+ rts
+
+* Compress the picture.
+horsub1
+ ldb  #32  We do two bytes at a time.
+ pshs b
+horsloop
+ ldb  ,x+
+ bsr  horsub0
+ ldb  ,x+
+ bsr  horsub0
+ sta  ,u+
+ dec  ,s
+ bne  horsloop
+ puls b
+ rts
+
+* Center result data on line.
+horsub2
+ bsr  horsub3 Clear out last 16 bytes on line.
+ ldb  #32
+horsloop2
+ lda  ,-u     Move 32 bytes to center.
+ sta  ,-x
+ decb
+ bne  horsloop2
+horsub3
+ lda  linebuff,y
+ ldb  #16
+horsloop3
+ sta  ,-x     Clear out first 16 bytes.
+ decb
+ bne  horsloop3
+ rts 
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_maxcmp.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,269 @@
+*
+* Setup for MaxCMP format
+*
+* Globals
+*   SetMAXCMP   -- Initialization. Reserves memory for decode buffer
+*   EndMAXCMP   -- return memory
+*   MAXCMPdecode -- decode entire file into buffer
+*   MAXCMPline   -- return next line: Y bytes to buffer at X
+*
+ ifp1
+ use  /dd/defs/os9defs.a
+ endc
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ psect view_maxcmp_a,0,0,0,0,0
+
+ vsect dp
+buffer     rmb 2
+buffend    rmb 2
+increment  rmb 2
+ endsect
+
+*
+* MAXCMP initialization
+* Since MAXCMP requires a large (12k) decode buffer, we don't allocate
+* it statically, but instead request memory from the operating system at
+* run time.
+*
+SetMAXCMP:
+ pshs a,b,x,y
+ tst  <format  If format already set, just ignore this.
+ bne  SetMC1
+ sta  <format  Set format code.
+
+ ldd  #12*1024+1000  Reserve the memory (+1000 bytes for table overflow )
+ lbsr malloc
+ stx  <buffer
+ leax 12*1024,x
+ stx  <buffend
+SetMC1
+ puls a,b,x,y,pc
+
+*
+* Return memory reserved by SetMAXCMP.
+*
+EndMAXCMP:
+ lbsr unmalloc
+ rts
+
+* Return next line from MAXCMP decoded data.
+* Return Y bytes to buffer at X
+MAXCMPline:
+ pshs a,x,y,u
+
+ ldu  <buffer
+line1
+ lda  ,u   Move one byte
+ sta  ,x+
+ ldd  <increment  Bump to next byte
+ leau d,u
+ leay -1,y  Are we done yet?
+ bne  line1
+
+ ldu  <buffer   Bump start of buffer pointer by one
+ leau 1,u
+ stu  <buffer
+
+ andcc #^Carry
+ puls a,x,y,u,pc
+
+*
+* Do actual decoding of picture
+* After done, store header info at ,X
+*
+MAXCMPdecode:
+ pshs a,b,x,y,u
+ pshs x        Save pointer to header info
+
+ lbsr find_data   Find DATA 1 statement that marks the actual picture data
+
+ bsr  getbyte  First byte is the escape code
+ pshs a       Save the escape code
+ bcs  MCdec4
+ ldx  <buffer
+
+MCdec1
+ bsr  getbyte
+ bcs  MCdec4   If error, exit this loop
+ cmpa ,s
+ bne  MCdec2   If not escape, just store it.
+ bsr  getbyte
+ bcs  MCdec4   Exit on EOF error
+ tfr  a,b      B holds repeat count
+ bsr  getbyte  A holds value
+ bcs  MCdec4   exit on error
+MCdec11
+ sta  ,x+     Repeat value appropriate number of times
+ decb
+ bne  MCdec11
+ bra  MCdec3
+MCdec2
+ sta  ,x+     If not count/value code, just store it.
+MCdec3
+ cmpx <buffend  If we're still not at end of buffer,
+ blo  MCdec1   Keep going.
+MCdec4
+ puls a        Clean escape code from stack
+
+ tfr  x,d
+ subd <buffer  How many bytes did we end up with?
+
+ cmpd #7000   More than this -> 2-page picture
+ bhi  MCdec8
+ ldd  #6144   6k of data
+ ldx  #192    or 192 lines for 1 page pic
+ bra  MCdec9
+MCdec8
+ ldd  #12288  12k of data
+ ldx  #384    or 384 lines for 2 page pic
+MCdec9
+
+ stx  <increment
+
+ puls x       Get address to store header
+ clr  ,x
+ std  1,x     Store total length
+ ldd  #$e00
+ std  3,x     Store fake begin address
+ puls a,b,x,y,u,pc
+
+ vsect dp
+bytebuff rmb 1
+shiftval rmb 1
+ endsect
+
+* Return next byte of 4-for-3 encoded data
+*
+getbyte
+ pshs b,x
+ ldb  <shiftval
+ beq  getbyte1
+ bsr  getval
+ bcs  getbyterr
+ sta  <bytebuff
+getbyte1
+ incb
+ stb  <shiftval
+
+ bsr  getval
+ bcs  getbyterr
+ pshs b
+ tfr  a,b
+ lda  <bytebuff
+ stb  <bytebuff
+ lslb
+ lslb
+getbyte2
+ lslb
+ rola
+ lslb
+ rola
+ dec  ,s
+ bne  getbyte2
+ puls b
+
+ ldb  <shiftval
+ cmpb #3
+ blo  getbytend
+ clr  <shiftval
+ bra  getbytend
+
+getbyterr
+ stb  ,s   Store error code on stack to be popped into B
+ clra
+ orcc #Carry
+getbytend
+ lbsr regdmp
+ puls b,x,pc
+ 
+
+* Get next value from BASIC file
+*
+getval
+getval1
+ lbsr I_GetByte  Get next character from file
+ bcs  getvalerr
+ cmpa #$30
+ blo  getval2  If it's in range $30-$6F, return it
+ cmpa #$6f
+ bhi  getval2
+ suba #$30
+ bra  getval3
+
+getval2
+ lbsr I_GetByte  Otherwise, find beginning of next line
+ bcs  getvalerr
+ cmpa #$22       which is marked by a quote.
+ bne  getval2
+
+ bra  getval1    And return the next char after that.
+getvalerr
+ cmpb #E$EOF
+ lbne _error
+ clra
+ orcc #Carry
+getval3
+ rts
+
+ 
+*  Searches for "DATA 1" statement at the end of a line,
+*  then advances to following quote mark
+*
+DATAstring fcc "DATA"
+
+find_data
+ pshs a,b,x
+
+find_0
+ leax DATAstring,pcr
+ ldb  #4
+find_1
+ lbsr I_GetByte  First, we match "DATA" literal
+ bcs  find_err
+ cmpa ,x
+ bne  find_0
+ leax 1,x
+ decb
+ bne  find_1
+
+find_2
+ lbsr I_GetByte  Skip any spaces
+ bcs  find_err
+ cmpa #$20
+ beq  find_2
+
+ cmpa #'1      Must match "1"
+ bne  find_0
+
+find_3
+ lbsr I_GetByte  Skip any spaces
+ bcs  find_err
+ cmpa #$20
+ beq  find_3
+
+ cmpa #$0d     Must match CR
+ bne  find_0
+
+find_4
+ lbsr I_GetByte
+ bcs  find_err
+ cmpa #$22      Find quote mark
+ bne  find_4
+
+ bra  find_end  Matched it!
+
+find_err
+ lbra E$Format
+
+find_end
+ puls a,b,x,pc
+
+ endsect
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_mge.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,251 @@
+********************************************************************************
+*
+* SUBS for MGE picture formats
+*
+* MGEshowpic -- displays picture on screen
+*
+********************************************************************************
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect view_mge_a,0,0,0,0,0
+
+ vsect
+picname rmb 30
+ endsect
+
+MGEshowpic:
+ bsr  header
+ lbsr setscreen
+ lbsr setpals
+ lbsr setbuffer
+ lbsr showname
+
+ ldd  <Skiplines
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ ldd  #00
+showpicouter
+ ldx  #25
+showpicloop
+ lbsr getline
+ tst  <Size
+ bne  showpic2
+ leax -1,x
+ beq  showpicouter
+showpic2
+
+ lbsr putline
+ addd #1
+ cmpd #192
+ bne  showpicloop
+ rts
+
+*
+* read header info from file, and set window type information
+*    Uses altbuff to read header info into.
+*
+ vsect dp
+compressed rmb 1     0=Compressed format in use
+count      rmb 1     Count/value is used for compressed format
+value      rmb 1
+endoffile  fcb 0     T= EOF reached, so always return linebuff all 0
+ endsect
+
+header
+ pshs a,b,x,y,u
+ leax altbuff,y read in type and palettes
+ pshs y
+ ldy  #51
+ lbsr I_Read
+ lbcs _error
+ puls y
+ leax altbuff,y
+ lda  ,x+      This byte must be zero.
+ lbne E$Format
+ leau palette,y
+ ldb  #16
+headloop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  headloop
+
+ lda  ,x+
+ beq  headrgb
+ lbsr cmpconv
+headrgb
+
+ lda  <type
+ bne  headtype
+ lda  #8      Std MGE defaults to type 8
+ sta  <type
+ ldb  <format
+ cmpb #MGE640Format  640 defaults to type 7
+ bne  headtype
+ lda  #7
+ sta  <type
+headtype
+
+ lda  ,x+
+ sta  compressed
+ clr  count
+
+ ldb  #30
+ leau picname,y
+headname
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  headname
+
+* Set rotation speed
+ ldb  ,x+
+ clra
+ std  <cyclerate
+
+* Set limits for palette rotation
+ lda  ,x+
+ tfr  a,b
+ lsra
+ lsra
+ lsra
+ lsra
+ sta  <cyclestart
+ andb #$0f
+ stb  <cycleend
+
+* Set default Skiplines.
+ ldd  <Skiplines
+ cmpd #$ffff
+ bne  headskip
+ ldd  #0
+ std  <Skiplines
+headskip
+
+* Set default Size
+ lda  <Size
+ bpl  headsize  Default to Small size
+ lda  #0
+ sta  <Size
+headsize
+
+ puls a,b,x,y,u,pc
+
+*
+* Getpair
+*
+getpair
+ pshs x,y
+ leax count,y
+ ldy  #2
+ lbsr I_Read
+ lbcc getpair1  No error, don't worry.
+ cmpb #E$EOF    Was it EOF?
+ beq  getpair2
+ lbra _error    No, error.
+getpair2
+ ldd  #0        Yes, translate into compressed MGE 0,0 EOF marker
+ std  count
+getpair1
+ puls x,y
+ ldd  count
+ rts
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+ leau linebuff,y
+ ldb  #160
+getl1
+ clr  ,u+
+ decb
+ bne  getl1
+
+ tst  endoffile    Are we at end-of-file?
+ bne  getline1
+
+ tst  compressed   Is it compressed mode?
+ bne  getnormal    0 -> compressed.
+* Get a line from compressed file
+ leau linebuff,y   Where we'll put the line.
+ ldx  #160         Number of bytes in one line.
+ ldd  count        Get count/value
+getl2
+ tsta              Count non-zero?
+ bne  getl3
+ lbsr getpair      Yes, get another count/value pair.
+ cmpa #0           Zero count -> EOF
+ bne  getl3
+ com  endoffile    Set end-of-file flag
+ bra  getline1
+getl3
+ stb  ,u+          Store a copy of current value
+ deca              Count down number of reps
+ leax -1,x         Count down size of line
+ bne  getl2        If not end of line, continue
+ std  count        Otherwise, store remaining count.
+ bra  getline1
+* Get a line from uncompressed file
+getnormal
+ leax linebuff,y   read in one line of screen
+ ldy  #160         Warning!  Y munged.
+ lbsr I_Read
+ lbcc getline1
+ cmpb #E$EOF      We have a special message for premature EOF
+ bne  getnor1
+ com  endoffile   Flag end-of-file condition
+ bra  getline1    Keep on going.
+getnor1
+ lbra _error      If not EOF, just exit with error.
+getline1
+ puls a,b,x,y,u,pc
+
+CurPos fcb $1b,$32,$0f,$02,$25,$37 Set foreground to pal#15, position cursor
+showname
+ pshs a,b,x,y,u
+ leau picname,y
+
+ tfr  u,x
+ clr  29,x  Just to make sure we do hit a null...
+ ldy  #0
+shownloop
+ leay 1,y
+ ldb  ,x+
+ cmpb #$20
+ bge  shownloop
+
+ pshs y
+
+ leax CurPos,pcr   Position the cursor to the bottom of the screen.
+ tfr  y,d
+ subb #40
+ negb
+ lsrb
+ addb #$20
+ stb  4,x
+ ldy  #6
+ lda  <outpath
+ os9  I$Write
+ lbcs _error
+
+ puls y
+ tfr  u,x
+ lda  <outpath
+ os9  I$Write
+ lbcs _error
+ puls a,b,x,y,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_pals.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,250 @@
+*
+* Palette operations:
+*
+*    palconv:  16 3-byte palette specs (R, G, B for each color)
+*              is converted into CoCo format palette info.
+*    palscale: 16 3-byte palette specs are scaled so largest coordinate
+*              is 255.
+*    setpals:  Set palettes from data in "palette" global buffer
+*    docycle:  Cycle palettes
+*    dorotate: Rotate through one palette slot
+*    cmpconv:  Convert "palette" buffer from Composite color to RGB color
+*
+  ifp1
+  use /dd/defs/os9defs.a
+  endc
+
+StdOut equ 1
+
+  psect view_pals_a,0,0,0,0,0
+
+scaletable
+  fcb $00,$ff,$80,$55
+  fcb $40,$33,$2b,$24
+  fcb $20,$1c,$1a,$17
+  fcb $15,$14,$12,$11
+
+palscale:
+ pshs a,b,x,y,u
+palscale1
+ bsr  findmax   First, rotate down so largest is <16
+ cmpa #15
+ bls  palscale2
+ bsr  divide
+ bra  palscale1
+palscale2
+
+ leax scaletable,pcr  Get multiplier for scaling.
+ ldb  a,x
+ pshs b
+
+ leax palette,y     Now scale each 4-bit palette value to 8 bits.
+ ldb  #48           The chosen multiplier should make the highest
+ pshs b                   palette value be 255 (or at least close).
+palscale3
+ ldb  ,x
+ lda  1,s
+ mul
+ cmpd #$100    Truncate to $ff.
+ blo  palscale4
+ ldb  #$ff
+palscale4
+ stb  ,x+
+ dec  ,s
+ bne  palscale3
+ puls d          Clean up stack.
+ puls a,b,x,y,u,pc
+
+* Divide each palette coordinate by 2
+divide
+ pshs b,x
+ leax palette,y
+ ldb  #48
+divide1
+ lda  ,x
+ lsra
+ sta  ,x+
+ decb
+ bne  divide1
+ puls b,x,pc
+
+* Return largest palette coordinate in A.
+findmax
+ pshs b,x
+ leax palette,y
+ ldb  #48
+ clra
+findmax1
+ cmpa ,x+
+ bhs  findmax2
+ lda  -1,x
+findmax2
+ decb
+ bne  findmax1
+ puls b,x,pc
+
+palconv:
+  pshs a,b,x,u,y
+  leax palette,y
+  leau pctable,pcr
+  leay palette,y
+  ldb  #16  Number of bytes to deal with
+palconvloop
+  clra
+  bsr  pcsub  Add one color component into A.
+  bsr  pcsub
+  bsr  pcsub
+  sta  ,y+
+  decb
+  bne  palconvloop
+  puls a,b,x,u,y,pc
+pctable
+  fcb 0,1,8,9
+
+pcsub
+  pshs b
+  pshs a
+  clrb
+  pshs b
+  ldb  ,x+
+  clra
+pcsloop
+  cmpd #42
+  ble  pcsend
+  inc  ,s
+  subd #85
+  bra  pcsloop
+pcsend
+  puls b
+  puls a
+  lsla
+  ora  b,u
+  puls b,pc
+
+*
+* Set up palette registers
+*
+setpals:
+ pshs x
+ leax palette,y
+ bsr  setpal
+ puls x,pc
+
+ vsect dp
+currot rmb 1
+ endsect
+
+ vsect
+setpCom rmb 64  Space for 16 Set Palette commands.
+curpals rmb 16
+ endsect
+
+setpal
+ pshs a,b,x,y,u
+ leau curpals,y
+ leay setpCom,y
+ pshs y
+ clrb
+setloop
+ lda  #$1b
+ sta  ,y+  Set palette command is $1b $31 <pal#> <value>
+ lda  #$31
+ sta  ,y+
+ stb  ,y+  Put palette number in.
+ lda  ,x+  Get palette value.
+ sta  ,u+  Copy it to curpals storage.
+ sta  ,y+  Put palette value in.
+ incb
+ cmpb #16
+ bne setloop
+ puls x        Pull address of command string.
+ lda  <outpath
+ ldy  #64
+ OS9  I$Write
+ lbcs _error
+ puls a,b,x,y,u,pc
+
+*
+* Rotate palletes down, from cyclestart to cycleend
+*
+
+docycle:
+ pshs  a,b,x
+ leax  curpals,y
+ ldb   <cycleend
+ cmpb  <cyclestart
+ bls   rollcycle     Unreasonable limits?  If so, end.
+ leax  b,x
+ lda   ,x
+ pshs  a
+rollloop
+ lda   ,-x
+ sta   1,x
+ decb
+ cmpb  <cyclestart
+ bne   rollloop
+ puls  a
+ sta   ,x
+ leax  curpals,y
+ bsr   setpal
+rollcycle
+ puls  a,b,x,pc
+
+ vsect
+onepal fcb $1b,$31,0,0
+ endsect
+
+dorotate:
+ pshs  a,b,x,y,u
+ leax  onepal,y
+ ldb   <extranum    If no extra pals to rotate, don't
+ beq   dorotend
+ ldb   currot       Get current rotation value.
+ incb
+ cmpb  <extranum    Should we wrap?
+ blo   dorot
+ clrb               Yes, wrap to zero.
+dorot
+ stb   currot
+
+ leau  extrapals,y  Get new palette value.
+ lda   b,u
+
+ ldb   <extraslot   Set up palette command.
+ stb   2,x          Store palette number
+ sta   3,x          Store color
+
+ leau  curpals,y    Store it into correct palette slot.
+ sta   b,u
+
+ ldy   #4
+ lda   <outpath
+ os9   I$Write 
+ lbcs  _error
+dorotend
+ puls a,b,x,y,u,pc
+
+cmpconv:
+ pshs a,b,x,u
+ leax palette,y
+ leau cmptable,pcr
+ ldb  #16
+cmploop
+ lda  ,x
+ lda  a,u
+ sta  ,x+
+ decb
+ bne  cmploop
+ puls a,b,x,u,pc
+
+cmptable
+ fcb 00,02,02,06,00,04,33,32   From Greg Law.
+ fcb 32,45,05,09,13,08,01,00
+ fcb 07,16,18,21,20,34,38,36
+ fcb 37,44,40,42,11,15,10,27
+ fcb 56,23,19,49,48,55,38,39
+ fcb 37,46,47,41,11,25,24,26
+ fcb 58,63,50,51,62,52,53,60
+ fcb 60,46,61,61,57,59,58,63
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_parse.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,239 @@
+*
+* Parse options line for ``view'' utility.
+*
+* Global labels:
+*  Parse: Do command line parsing, set flags, open file
+*  Getnum: Interpret a number, for use by options subs in view_table.a
+*
+* The table of options is in the file view_table.a
+*   This file contains the actual parsing code.
+*
+*  An option without `-' is interpreted as a filename, and the corresponding
+*         file is opened for buffered input, via the routines in view_io.a
+*
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdIn  equ 0
+StdOut equ 1
+StdErr equ 2
+OPT.DTP equ 0  Offset to Device TyPe byte in Path Descriptor Options section
+
+ psect view_parse_a,0,0,0,0,0
+
+ vsect dp
+fnameptr  rmb 2      Pointer to filename
+ endsect
+
+ vsect
+Option rmb 20
+ endsect
+
+
+*
+* Entry point
+*
+Parse:
+ pshs a,b,x,y,u
+
+ ldd  #0000
+ std  <fnameptr
+
+Parse1
+ lbsr Skipblanks  Move past blanks, return first non-blank char.
+
+ cmpa #$0d      CR marks end of options.
+ beq  Openfile  Try to open the file
+
+ cmpa #'-       Does this word start with '-'?
+ beq  Parse2
+ stx  <fnameptr No, must be filename
+ lbsr Skipword
+ bra  Parse1 
+Parse2
+ leax 1,x       Bump past `-'
+
+ leau PTable,pcr Check table with format type options
+ lbsr DoOption   Try to perform this option.
+ beq  Parse3
+ lbsr Help
+ ldb  #1         Illegal argument error.
+ lbra _error     unrecognized option.
+
+Parse3
+ lda  ,x+       Skip any remaining chars in this option word
+ cmpa #$20
+ bgt  Parse3
+ beq  Parse4    Exit on Space
+ cmpa #$0d      Exit on CR
+ beq  Parse4
+ lbsr Help      Other control-- report error
+ ldb  #1
+ lbra _error
+Parse4
+ leax -1,x
+ bra  Parse1
+
+Openfile
+ ldx  <fnameptr
+ bne  Parse6    If ptr is null, then no name was given.
+
+ lda  #StdIn    Is StdIn from an SCF device?
+ ldb  #SS.Opt
+ leax altbuff,y
+ os9  I$GetStt  Get options section of StdIn path descriptor
+ lbcs _error
+ lda  OPT.DTP,x
+ bne  Parse7    Not SCF, so must be redirected picture coming in.
+
+ lbsr Help      If StdIn is SCF, then give help message and exit.
+ ldb  #1
+ lbra _error
+
+* "fnameptr" points to first char of filename, so search for period
+Parse6
+ lda  ,x+
+ cmpa #$20    If we find a space first, then there is no extension.
+ beq  Parse7
+ cmpa #$0d    ...or a CR.
+ beq  Parse7
+ cmpa #'.     If we find a period first, then we've found the extension.
+ bne  Parse6
+ leau PTable,pcr
+ lbsr DoOption  Treat extension as an option spec.
+ bra  Parse6
+
+* Set default format and open file for input
+Parse7
+ lbsr DefFormat  If no other file format specification, Set default format.
+
+ ldx  <fnameptr
+ lda  #READ. open file
+ lbsr I_Open
+ lbcs _error
+
+ puls a,b,x,y,u,pc
+
+*
+* Call subroutine indicated by option pointed to by X
+*
+* Returns B=1 if error, B=0 otherwise
+*
+DoOption
+ pshs a,u
+DoOpt1
+ tst  ,u         Is this the null string?
+ bne  DoOpt11    If yes, end of table.
+ ldb  #1         Illegal Argument error
+ bra  DoOpt3
+DoOpt11 
+ lbsr CompOptions Compare with this option.
+ beq  DoOpt2
+ leau 4,u        Skip format specifier, branch instruction.
+ bra  DoOpt1
+DoOpt2
+ lda  ,u        Get code to hand to option processor.
+ jsr  1,u       Jump to routine to handle this option.
+ clrb           Exit with no error.
+DoOpt3
+ tstb
+ puls a,u,pc
+
+*
+* Compare initial part of string at X to string at U.
+*         B=0 -> match
+* X is advanced to first character difft from string at U
+* U string is null-terminated, U advanced to point to byte after null.
+*
+CompOptions
+ pshs a,x   We'll overwrite X value if we get a match
+CompLoop
+ ldb  ,u+
+ bne  CompGo
+ stx  1,s     Return first different X
+ bra  CompEnd
+CompGo
+ lda  ,x+
+ cmpa #'A
+ blo  CompCase    Convert letter to lowercase
+ cmpa #'Z
+ bhi  CompCase
+ adda #'a-'A
+CompCase
+ pshs a
+ subb ,s+         Does this character match?
+ beq  CompLoop
+ leax -1,x
+Comp1
+ lda  ,u+         Match failed, advance U anyway
+ bne  Comp1
+CompEnd
+ tstb
+ puls a,x,pc
+
+*
+* Get decimal number at X into D, move X to first non-digit
+*
+Getnum:
+ ldd  #0
+ pshs d
+Getnum0
+ lda  ,x+    Skip leading spaces.
+ cmpa #$20
+ beq  Getnum0
+ leax -1,x
+Getnum1
+ lda  ,x+
+ cmpa #$0d
+ beq  Getnum2
+ cmpa #$20
+ bge Getnum10
+ lbsr Help
+ ldb  #1
+ lbra _error
+Getnum10
+ cmpa #'0
+ blo  Getnum2
+ cmpa #'9
+ bhi  Getnum2
+ suba #'0
+ pshs a
+ ldd  1,s
+ lslb
+ rola
+ pshs d
+ lslb
+ rola
+ lslb
+ rola
+ addd ,s++
+ addb ,s+
+ adca #0
+ std  ,s
+ bra  Getnum1
+Getnum2
+ leax -1,x
+ puls d
+ rts
+
+*
+* Move X to point to first non-blank char.  Return char in A.
+*
+Skipblanks
+ lda  ,x+
+ cmpa #$20
+ beq  Skipblanks
+ cmpa #$09
+ beq  Skipblanks
+ leax -1,x
+ rts
+
+Skipword
+ lda  ,x+
+ cmpa #$20
+ bgt  Skipword
+ leax -1,x
+ rts
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_pix.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,267 @@
+*
+*
+* SUBS for pix picture format
+*
+* PIXshowpic -- Displays picture, using putline routine
+*
+*
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect  view_pix_a,0,0,0,0,0 
+
+ vsect dp
+pixfirstcol:  rmb 2
+pictwidth rmb 2
+linesize rmb 2
+linecount rmb 2
+updown   rmb 2
+pixsize  rmb 2
+ endsect
+
+PIXshowpic:
+ bsr  header       Get header info
+ lbsr setscreen    Set up screen
+ lbsr setpals      Set up palettes
+ lbsr setvert      Set up Get/Put Buffer
+ std  linesize     Store size of line in bytes.
+
+ lbsr getline
+ ldd  #0
+ std  updown
+showpicloop
+ std  linecount
+
+ ldd  updown       If necessary, get a new line
+ cmpd pictwidth
+ blo  spl1
+ lbsr getline
+ subd pictwidth         Subtract 640.
+ std  updown
+spl1
+
+* Now, dither it and put it on the screen
+ leax altbuff,y    Read from altbuff
+ leau linebuff,y   ... into linebuff.
+ ldd  linesize
+ lbsr pixditherline
+
+ ldd  updown      Add 256 to count.
+ addd pixsize
+ std  updown
+
+ ldd  linecount
+ addd #1
+ cmpd pictwidth
+ bne  showpicloop
+
+ lbsr endvert   Trash Get/Put buffer.
+
+ rts
+
+*
+* read header info from file, and set window type information
+*
+ vsect dp
+endoffile   fcb 0
+double      fcb 0   T=128x128, so we need to double things
+count       rmb 1   Counts down lines
+ endsect
+
+
+header
+ pshs a,b,x,y,u
+ lda  <format
+ cmpa #PIX256Format  Is this definitely 256x256?
+ beq  headbig
+ cmpa #PIX128Format  Is it definitely 128x128?
+ beq  headsmall
+ lbsr I_Size     If neither of those was specified, let's try to use file size
+ lbcs _error     to determine the format.
+ cmpd #10000     If it's over 10000 bytes, we'll take it as 256x256
+ bhi  headbig    Yes, treat it as a 256x256.
+ com  double     Otherwise, treat it as a 128x128 picture.
+headsmall
+ ldd  #128
+ std  pixsize
+ bra  headend
+headbig
+ ldd  #256
+ std  pixsize
+headend
+* Set screen type
+ lda  #7
+ sta  <type
+* Set some miscellaneous variables
+ lda  #0
+ sta  <cyclestart
+ sta  <cycleend
+* Set palettes
+ leax ourpals,pcr
+ leau palette,y
+ ldd  ,x++
+ std  ,u++
+ ldd  ,x++
+ std  ,u++
+* Set Skiplines default
+ ldd  <Skiplines
+ cmpd #$ffff
+ bne  head27
+ ldd  #20
+ std  <Skiplines
+head27
+ cmpd #64    Is it too big?
+ blo  head28
+ ldd  #64
+ std  <Skiplines
+head28
+* Set Size default to BIG
+ lda  <Size
+ bpl  headsize
+ lda  #1
+ sta  <Size
+headsize
+* Set picture width
+ ldd  #600   Default picture width
+ tst  <Size
+ bne  head30
+ ldd  #450   width for fitted picture
+head30
+ std  pictwidth
+* Set the first column to  (640-pictwidth)/2
+ ldd  #640
+ subd pictwidth
+ lsra
+ rorb
+ andb #$fc   Force it to a multiple of 4 for put speed
+ std  pixfirstcol
+
+ puls a,b,x,y,u,pc
+
+ourpals fcb  0,7,56,63
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* First, fill buffers with all zeros
+ leau alt2buff,y
+ leax altbuff,y
+ ldb  #200
+getline3
+ clr  ,u+
+ clr  ,x+
+ decb
+ bne  getline3
+* If at end of file, leave it that way
+ tst  endoffile
+ bne  getline1
+* Get a line into alt2buff
+ leax alt2buff,y
+ pshs y
+ ldd  pixsize
+ lsra
+ rorb
+ tfr  d,y     Number of bytes is 1/2 picture size
+ lbsr I_Read
+ puls y
+ lbcc getline2
+ cmpb #E$EOF
+ bne  getline4
+ com  endoffile
+getline2
+* Now, expand it into altbuff
+ leax alt2buff,y
+ leau altbuff,y
+ ldd  #128     Get number of bytes in altbuff to expand into D.
+ tst  double       If we're doubling, only expand half as many bytes.
+ beq  getline21
+ lsra
+ rorb
+getline21
+ bsr  expandline 
+ bsr  scrunchline  Scrunch it down to 192 pixels.
+ bra  getline1
+* Error exit point
+getline4
+ lbra _error      If not EOF, just exit with error.
+getline1
+ puls a,b,x,y,u,pc
+
+*
+* Expand line by nybbles.
+*
+* Take buffer [X], copy each nybble to a separate byte in [U].
+*    Number of bytes in [X] is in D.
+*
+expandline
+ pshs a,b,x,y,u
+ tfr  d,y
+expand1
+ lda  ,x+
+ tfr  a,b
+ andb #$0f
+ lsra
+ lsra
+ lsra
+ lsra
+ tst  <double
+ beq  expand2
+ sta  ,u+
+ sta  ,u+
+ stb  ,u+
+ stb  ,u+
+ bra  expand3
+expand2
+ std  ,u++
+expand3
+ leay -1,y
+ bne  expand1
+ puls a,b,x,y,u,pc
+
+*
+* Take data in altbuff, and either remove bytes to "fit" it down to
+*    192 bytes, or remove "Skiplines" number from beginning.
+scrunchline
+  pshs a,b,x,y,u
+  leax altbuff,y
+  tfr  x,u
+  tst  <Size
+  bne  scrbegin
+* Fit the data into 192 bytes
+  ldb #192
+scrloop
+  lda  ,u+   Take 4 bytes, and copy 3 of them.
+  sta  ,x+
+  lda  ,u+
+  sta  ,x+
+  lda  ,u+
+  sta  ,x+
+  lda  ,u+
+  subb #3
+  bne  scrloop
+  bra  scrend
+* Remove bytes from beginning.
+scrbegin
+  ldd  <Skiplines
+  leau d,u
+  ldb  #192
+scrloop2
+  lda  ,u+
+  sta  ,x+
+  decb
+  bne  scrloop2
+scrend
+  puls a,b,x,y,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_pix2.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,258 @@
+*
+*
+* Graphics subs for PIX picture format.
+*   setvert: Create buffer for vertical imaging.
+*   endvert: Trash the buffer.
+*   pixditherline: Output one vertical row to screen.
+*
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect  view_pix_gfx_a,0,0,0,0,0 
+
+* vsect dp
+*pixfirstcol  rmb 2   Declared in view_pix.a
+* endsect
+
+*
+* These are essentially cloned from the row-at-a-time routines in
+*   view_gfx.a, but since I never expect to see another graphics format
+*   that does column-at-a-time imaging, I decided it should be safe
+*   to just put them here, so I could optimize them for this format.
+* In order to be fully general, they just need to take into account
+*   the screen type (here assumed to be type 7).
+*
+ vsect dp
+buffadd rmb 2   Address of mapped-in get/put buffer
+ endsect
+
+ vsect
+setbufCom
+ fdb $1b2c
+ fdb $0002    Group/buffer
+ fdb 0000    XLoc
+ fdb 0000    YLoc
+ fdb 4       XDim
+ fdb 96      YDim
+ endsect
+
+setvert:
+ pshs x,y
+
+ leax setbufCom,y
+ lda  <PID
+ sta  2,x
+ lda <outpath
+ pshs y
+ ldy #12
+ OS9 I$Write 
+ lbcs _error
+ puls y
+
+ lda <PID
+ ldb #2
+ tfr d,x       Set up group/buffer in X.
+ lda #1
+ ldb #SS.MpGPB map in buffer
+ pshs y
+ ldy #1
+ os9 I$SetStt
+ lbcs _error
+ tfr y,d
+ puls y
+ stx buffadd
+
+ ldd  #192    Return size of vertical buffer.
+ puls x,y,pc
+
+*
+* Endvert:  Kill and unmap buffer
+*
+ vsect
+endbufCom
+ fcb $1b,$2a,$00,$02
+ endsect
+
+endvert:
+ pshs a,b,x,y
+ lda  <PID
+ ldb  #2
+ tfr  d,x
+ lda  #1
+ ldb  #SS.MpGPB
+ pshs y
+ ldy  #0    Unmap buffer.
+ os9  I$SetStt
+ puls y
+
+ leax endbufCom,y
+ lda  <PID
+ sta  2,x
+ lda <outpath
+ ldy #4
+ OS9 I$Write 
+ lbcs _error
+ puls a,b,x,y,pc
+
+*
+* Ditherline:
+*   Takes buffer pointed to by X, of size D, and dithers it into U.
+* 15Feb90- now buffers 4 columns, then calls putvert with all 4 cols.
+* 01Jun90- Changed dither patterns to 12x6, for smoother dithering.
+*
+ vsect dp
+dithmask fcb $c0  Mask off appropriate bits from dither values.
+dithwhich  fcb 0  track which byte column we're in.
+ endsect
+
+pixditherline:
+ pshs a,b,x,y,u
+ pshs y
+ lda  #$2b          Approx 1/6
+ mul                Divide by six, since we do things six bytes at a time.
+ pshs a             Save number of bytes.
+ leay dith1table,pcr
+ lda  <dithwhich
+ cmpa #1
+ bne  dithmod1
+ leay dith2table,pcr
+dithmod1
+ cmpa #2
+ bne  dithmod2
+ leay dith3table,pcr
+dithmod2
+ ldb  <dithmask     Get current dither column
+ pshs b
+dither1
+ ldd  ,x++   Get two bytes,
+ lda  a,y    . translate to color
+ anda ,s     . mask off only pertinent pixel
+ addb #16    . offset into second table
+ ldb  b,y    . translate this color
+ andb ,s     . mask off pixel
+ ora  ,u     . or new pixel into target array
+ orb  1,u    . "
+ std  ,u++   . store it.
+ ldd  ,x++   Get two more bytes,
+ adda #32    . offset into third table
+ lda  a,y    . translate to color
+ anda ,s     . mask off only pertinent pixel
+ addb #48    . offset into fourth table
+ ldb  b,y    . translate this color
+ andb ,s     . mask off pixel
+ ora  ,u     . or new pixel into target array
+ orb  1,u    . "
+ std  ,u++   . store it.
+ ldd  ,x++   Get two more bytes,
+ adda #64    . offset into fifth table
+ lda  a,y    . translate to color
+ anda ,s     . mask off only pertinent pixel
+ addb #80    . offset into sixth table
+ ldb  b,y    . translate this color
+ andb ,s     . mask off pixel
+ ora  ,u     . or new pixel into target array
+ orb  1,u    . "
+ std  ,u++   . store it.
+ dec  1,s
+ bne  dither1
+ puls a,b
+ puls y
+ ldb  <dithmask
+ andcc #^Carry     Clear carry, so we don't mung our pixel mask
+ rorb
+ rorb
+ bcc  dither3
+ rorb
+ lbsr putvert
+ lda  dithwhich   Bump dithwhich mod 3
+ inca
+ cmpa #3
+ blo  dithermod
+ clra
+dithermod
+ sta  dithwhich
+dither3
+ stb  <dithmask
+ puls a,b,x,y,u,pc
+
+dith1table
+ fcb $00,$10,$10,$51,$51,$55,$56,$65,$69,$a6,$aa,$ba,$ae,$be,$fb,$ff
+ fcb $00,$01,$41,$45,$15,$55,$65,$96,$a6,$6a,$aa,$ab,$ba,$fb,$bf,$ff
+dith3table
+ fcb $00,$10,$04,$14,$51,$55,$56,$59,$9a,$a6,$aa,$ba,$eb,$ef,$fb,$ff
+ fcb $00,$01,$10,$51,$15,$55,$65,$65,$69,$6a,$aa,$ab,$ae,$be,$bf,$ff
+dith2table
+ fcb $00,$10,$41,$45,$51,$55,$56,$96,$a6,$a6,$aa,$ba,$ba,$fb,$fb,$ff
+ fcb $00,$01,$04,$14,$15,$55,$65,$59,$9a,$6a,$aa,$ab,$eb,$ef,$bf,$ff
+ fcb $00,$10,$10,$51,$51,$55,$56,$65,$69,$a6,$aa,$ba,$ae,$be,$fb,$ff
+ fcb $00,$01,$41,$45,$15,$55,$65,$96,$a6,$6a,$aa,$ab,$ba,$fb,$bf,$ff
+ fcb $00,$10,$04,$14,$51,$55,$56,$59,$9a,$a6,$aa,$ba,$eb,$ef,$fb,$ff
+ fcb $00,$01,$10,$51,$15,$55,$65,$65,$69,$6a,$aa,$ab,$ae,$be,$bf,$ff
+
+*
+* Putvert
+*
+ vsect dp
+putcol rmb 2
+ endsect
+
+ vsect
+putCom  fdb $1b2d
+        fcb 0,2 Grp/Buf
+putcol2 fdb 0   Xloc
+        fdb 0   Yloc
+ endsect
+
+putvert
+ pshs a,b,x,y,u
+ leax putCom,y
+ ldd  putcol
+ addd #4
+ std  putcol
+ addd <pixfirstcol
+ std  putcol2
+ lda  <PID
+ sta  2,x     Set group number
+
+ leax linebuff,y   Copy linebuff data into get/put buffer
+ bsr  putvert0     Copy first half of data.
+ ldd  #00
+ bsr  putvert1     Put on screen starting at Y offset 0
+ bsr  putvert0     Copy second half.
+ ldd  #96
+ bsr  putvert1     Put at Y offset 96.
+ puls a,b,x,y,u,pc
+
+putvert0
+ pshs a,b,u
+ ldu  buffadd
+ ldb  #96
+putv1
+ lda  ,x
+ clr  ,x+          Clear out linebuff as we go along.
+ coma              Complement our data.
+ sta  ,u+
+ decb
+ bne  putv1
+ puls a,b,u,pc
+
+putvert1
+ pshs a,b,x,y
+ leax putCom,y
+ std  6,x
+ lda  <outpath
+ ldy  #8
+ os9  I$Write
+ lbcs _error
+ puls a,b,x,y,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_rat.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,187 @@
+********************************************************************************
+*
+* SUBS for RAT picture formats
+*
+* RATshowpic -- displays picture on screen
+*
+********************************************************************************
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect view_rat_a,0,0,0,0,0
+
+ vsect dp
+Debug rmb 1
+ endsect
+
+RATshowpic:
+ bsr  header
+ lbsr setscreen
+ lbsr setpals
+ lbsr setbuffer
+
+ pshs d,x
+ ldd  <Skiplines
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ com  <Debug
+
+ ldd  #00
+showpicouter
+ ldx  #25
+showpicloop
+ lbsr getline
+ tst  <Size
+ bne  showpic2
+ leax -1,x
+ beq  showpicouter
+showpic2
+
+ lbsr putline
+ addd #1
+ cmpd #192
+ bne  showpicloop
+ puls d,x,pc
+
+*
+* read header info from file, and set window type information
+*    Uses altbuff to read header info into.
+*
+ vsect dp
+compressed rmb 1     T=Compressed format in use
+compmarker rmb 1     Marker for compressed pairs.
+count      rmb 1     Count/value is used for compressed format
+value      rmb 1
+endoffile  fcb 0     T= EOF reached, so always return linebuff all 0
+ endsect
+
+header
+ pshs a,b,x,y,u
+ leax altbuff,y read in type and palettes
+ pshs y
+ ldy  #19
+ lbsr I_Read
+ lbcs _error
+ puls y
+ leax altbuff,y
+ lda  ,x+
+ sta  compmarker   Escape value for compressed pairs.
+ lda  ,x+
+ sta  compressed   0=noncompressed, non-zero means compressed
+ clr  count
+
+ lda  ,x+         Border color, ignore for now.
+
+ leau palette,y   Next 16 bytes are palettes, store them.
+ ldb  #16
+headloop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  headloop
+
+ lda  type,y
+ bne  headtype
+ lda  #8
+ sta  type,y
+headtype
+
+* Disable animation effects
+ lda  <cyclestart   Disable cycling.
+ sta  <cycleend
+ clr  <extranum
+ 
+* Set default Skiplines.
+ ldd  <Skiplines
+ cmpd #$ffff
+ bne  headskip
+ ldd  #0
+ std  <Skiplines
+headskip
+
+* Set default Size
+ lda  <Size
+ bpl  headsize
+ lda  #1
+ sta  <Size
+headsize
+
+ puls a,b,x,y,u,pc
+
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+ leau linebuff,y
+ ldx  #160
+getl1
+ clr  ,u+
+ leax -1,x
+ bne  getl1
+ tst  endoffile    Are we at end-of-file?
+ bne  getline1
+ tst  compressed   Is it compressed mode?
+ beq  getnormal    0 -> uncompressed.
+* Get a line from compressed file
+ leau linebuff,y   Where we'll put the line.
+ ldx  #160         Number of bytes in one line.
+ lda  value        Get value to repeat
+ tst  count        Is there a left-over compressed packet?
+ bne  getl3        Yes, go finish that packet.
+getl2
+ lbsr I_GetByte   Get a value
+ bcs  geteof
+ cmpa compmarker  Is this the code to mark a compressed pair?
+ beq  getl22      Yes, get the pair and expand.
+getl21
+ sta  ,u+         Store one byte as-is.
+ leax -1,x        Count down line length.
+ bne  getl2
+ bra getline1
+getl22
+ lbsr I_GetByte  Get count/value pair.
+ bcs  geteof
+ sta  count
+ lbsr I_GetByte Get value
+ bcs  geteof
+ sta  value
+getl3
+ sta  ,u+    Store a copy of current value
+ dec  count  Count down number of reps
+ leax -1,x   Count down size of line
+ lbeq  getline1 If end of line, exit
+ tst  count  Is that enough copies?
+ bne  getl3  No, keep going
+ bra  getl2  Yes, get next pair.
+* Get a line from uncompressed file
+getnormal
+ leax linebuff,y   read in one line of screen
+ ldy  #160         Warning!  Y munged.
+ lbsr I_Read
+ lbcc getline1
+* Check error value in B for EOF, mark EOF condition if that's the error,
+*   any other error, exit.
+geteof
+ cmpb #E$EOF      We have special handling for premature EOF
+ bne  getnor1
+ com  endoffile   Flag end-of-file condition
+ bra  getline1    Keep on going.
+getnor1
+ lbra _error      If not EOF, just exit with error.
+getline1
+ puls a,b,x,y,u,pc
+
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_rle.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,174 @@
+*****************************************************************************
+*                                                                           *
+* SUBS for RLE  picture format                                              *
+*                                                                           *
+* RLEshowpic -- Displays picture, using putline routine                     *
+*                                                                           *
+*****************************************************************************
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect  view_rle_a,0,0,0,0,0 
+
+ vsect dp
+double      rmb 1  Yes, double each line, and double each pixel count.
+ endsect
+
+RLEshowpic:
+ bsr  header       Read header info, set palettes, etc.
+
+ lbsr setscreen
+ lbsr setpals
+ lbsr setbuffer
+
+ ldd  #0
+showpicloop
+ lbsr getline
+ lbsr putline
+ tst  double
+ beq  nodoub
+ lbsr putline
+nodoub
+ addd #1
+ cmpd #192
+ bne  showpicloop
+ rts
+
+*
+* read header info from file, and set window type information
+*
+ vsect dp
+endoffile   rmb 1
+ endsect
+
+
+header
+ pshs a,b,x,y,u
+ ldd  #$003f     Set palettes to white on black
+ std  palette,y
+ lda  #6
+ sta  <type
+
+head0
+ lbsr I_GetByte  The start of an RLE picture is an ESC G sequence.
+ lbcs _error
+ cmpa #27
+ bne  head0
+head1
+ lbsr I_GetByte
+ lbcs _error
+ cmpa #27
+ beq  head1
+ cmpa #'G
+ bne  head0
+
+ lbsr I_GetByte
+ lbcs _error
+ cmpa #'H
+ beq  headmisc
+ cmpa #'M
+ lbne E$Format  Illegal format!
+ com  double    Turn on double flag.
+
+headmisc
+* Set some miscellaneous variables
+ clr  <cyclestart
+ lda  #1
+ sta  <cycleend   So we can toggle black/white
+ ldd  #120
+ std  <cyclerate
+
+ clr  <cycle      Turn off cycling
+ clr  <extranum    No color rotation
+ ldd  <Skiplines
+ cmpd #$ffff        Is Skiplines still default?
+ bne  headskip      No, don't change it.
+ ldd  #0
+ std  <Skiplines   Set it to 0
+headskip
+ puls a,b,x,y,u,pc
+
+ vsect dp
+mask       fcb $40   Mask to set a pixel
+foreground rmb 1     In foreground or background? default=0.
+count      rmb 1
+ endsect
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* Clear out linebuff
+ leau linebuff,y
+ ldb  #160
+getline3
+ clr  ,u+
+ decb
+ bne  getline3
+* If at end of file, leave it that way
+ tst  endoffile
+ lbne getline1
+* Get a line from the file
+ leax linebuff+8,y
+ clrb
+ lda  count
+ bne  setdoit
+getbyte
+ com  foreground
+ lbsr I_GetByte
+ bcs  geteof
+ suba #$20
+ blo  getbyte
+ tst  double
+ beq  setdoit
+ lsla            Double count.
+setdoit
+ sta  count
+ beq  getbyte
+setloop
+ bsr  pixset   Set/reset this pixel
+ dec  count
+ decb          Count down pixels on line
+ beq  getline1
+ tst  count
+ beq  getbyte  End of repeat, get another byte.
+ bra  setloop  End of line, save leftover and quit.
+* Handle EOF situation, any I/O error should come here.
+geteof
+ cmpb #E$EOF
+ bne  getline4
+ com  endoffile
+ bra  getline1
+getline4
+ lbra _error      If not EOF, just exit with error.
+getline1
+ puls a,b,x,y,u,pc
+
+pixset
+ pshs a
+ tst  foreground
+ bne  pixreset   If in background, don't set the pixel.
+ lda  ,x
+ ora  mask
+ sta  ,x
+ andcc #^Carry  clear the carry flag.
+pixreset
+ ror  mask
+ bcc  pixend    If we went past the end of the byte,
+ ror  mask      Get the two mask bits out of the carry
+ leax 1,x       Bump X to next byte.
+pixend
+ ror  mask
+ puls a,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_save.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,501 @@
+*
+* Save current picture to a file
+*   DoSave:   - Save current screen to file in specified format
+*               Currently supports VEFFormat, VEFSqFormat, MGEFormat, CM3Format
+*  Note: Since SetSave does not clear a file (DoSave resets the filesize to
+*       zero when it starts), VIEW can be used to convert a file in place
+*       by just saving back to the original file.
+*
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+StdIn  equ 0
+StdOut equ 1
+StdErr equ 2
+
+ psect view_save_a,0,0,0,0,0
+
+ vsect dp
+SaveFormat: rmb 1  Also used in view_setsave.a
+SavePath:   rmb 1
+LineSize   rmb 2
+ endsect
+
+
+*
+* Do the actual save.
+*
+DoSave:
+ pshs a,b,x,y,u
+ lda  #$ff
+ sta  <abort  Set to abort on signal.
+
+* Set up line buffer for screen I/O
+ lbsr setbuffer
+
+*  First, set file size to zero, in case it was pre-existing.
+ lda  SavePath
+ lbeq DoSaveEnd
+
+ ldb  #SS.Size
+ ldx  #0
+ tfr  x,u
+ os9  I$SetStt
+ lbcs _error
+
+
+* We'll need to know the size in bytes of one line, so figure that out
+ lda  <type
+ ldb  #80  Types 5 and 6 are 80 bytes/line
+ cmpa #7
+ blo  Dosize
+ ldb  #160  Types 7 and 8 are 160 bytes/line
+Dosize
+ clra
+ std  LineSize
+
+ lda  SaveFormat   If MGE Format save, write an MGE format header.
+ cmpa #MGE640Format
+ beq  DoMGE1
+ cmpa #MGEFormat
+ bne  DoMGE
+DoMGE1
+ lbsr MGEHeader
+DoMGE
+
+ lda  SaveFormat   If VEF Format save, write a VEF format header.
+ cmpa #VEFFormat
+ beq  DoVEF1
+ cmpa #VEFSqFormat
+ bne  DoVEF
+DoVEF1
+ lbsr VEFHeader
+DoVEF
+
+ lda  SaveFormat
+ cmpa #CM3Format
+ bne  DoCM3
+ lbsr CM3Header
+DoCM3
+
+* Now output rest of file
+ ldd  #0
+DoOut
+ lbsr fetchline
+ lbsr comline
+ lbsr putline       Copy the line back to the screen, for visual feedback.
+ lbsr comline
+ lbsr outline
+ lbsr putline
+ addd #1
+ cmpd #192
+ bne  DoOut
+
+ lda  SaveFormat   For MGE format, add 8 blank lines to end of file.
+ cmpa #MGE640Format
+ beq  DoMGE11
+ cmpa #MGEFormat
+ bne  DoMGE10
+DoMGE11
+ lbsr Save8
+DoMGE10
+
+* Now close the file
+ lda  SavePath
+ os9  I$Close
+ lbcs _error
+
+* Print message on successful completion
+ leax  str1done,pcr  Output first part of message
+ lbsr  O_Write
+
+ ldb  SaveFormat
+ leax strVEF,pcr
+ cmpb #VEFFormat  Is it VEF?
+ beq  DoneSave
+
+ leax strMGE,pcr
+ cmpb #MGEFormat  Is it MGE?
+ bne  DoneSave1
+ ldb  <type
+ cmpb #6       Type 6/8 are MGE
+ beq  DoneSave
+ cmpb #8
+ beq  DoneSave
+ leax str640,pcr  Types 5/7 are 640.
+ bra  DoneSave
+DoneSave1
+
+ leax str640,pcr
+ cmpb #MGE640Format  Is it 640?
+ bne  DoneSave2
+ ldb  <type
+ cmpb #8       Type 8 is MGE
+ bne  DoneSave
+ leax strMGE,pcr
+ bra  DoneSave
+DoneSave2
+
+ leax strVEFSq,pcr
+ cmpb #VEFSqFormat  Is it VEF Squashed?
+ beq  DoneSave
+
+ leax strCM3,pcr
+ cmpb #CM3Format  CM3 format
+ bne  DoneSave3
+ ldb  <type
+ cmpb #6       Type 6/8 are normal CM3
+ beq  DoneSave
+ cmpb #8
+ beq  DoneSave
+ leax strCM3640,pcr  Types 5/7 are 640 across CM3.
+ bra  DoneSave
+DoneSave3
+
+* Add other formats here
+DoneSave
+ lbsr O_Write
+
+ leax str2done,pcr   Output second part.
+ lbsr O_Write
+ 
+DoSaveEnd
+ puls a,b,x,y,u,pc
+
+strVEF fcc "normal VEF"
+       fcb 0
+strMGE fcc "MGE"
+       fcb 0
+str640 fcc "640 (MGE 640x200)"
+       fcb 0
+strVEFSq fcc "VEF Squashed"
+         fcb 0
+strCM3 fcc "CM3"
+       fcb 0
+strCM3640 fcc "CM3 (640x192)"
+       fcb 0
+str1done fcc "Picture saved in "
+         fcb 0
+str2done fcc " format."
+         fcb $0d,0
+
+* Clear out linebuff
+clrline
+ pshs a,b,x
+ leax linebuff,y
+ clra
+ ldb  #200
+DoClear
+ sta  ,x+
+ decb
+ bne  DoClear
+ puls a,b,x,pc
+
+* Complement linebuff
+comline
+ pshs b,x
+ ldb  #160
+ leax linebuff,y
+comline1
+ com  ,x+
+ decb
+ bne  comline1
+ puls b,x,pc
+
+* Output an MGE header
+MGEHeader
+ pshs a,b,x,y,u
+ leax altbuff,y
+ clr  ,x+         Initial 0 byte.
+ lbsr copypals
+ clr  ,x+         Mark RGB
+ lda  #$ff
+ sta  ,x+         We're not using MGE compression (blech!)
+ leau MGEname,pcr Give this a generic name.
+ ldb  #30
+MGEhead1
+ lda  ,u+
+ sta  ,x+
+ decb
+ bne  MGEhead1
+ ldd  <cyclerate
+ stb  ,x+        Save cycle rate
+ lda  <cyclestart
+ lsla
+ lsla
+ lsla
+ lsla
+ ora  <cycleend
+ sta  ,x+        Save first/last palette rotation values.
+
+ leax altbuff,y  Write the actual header.
+ lda  SavePath
+ ldy  #51
+ os9  I$Write
+ puls a,b,x,y,u,pc
+
+MGEname fcc "OS9 picture"
+ fcb 0
+
+* Output a CM3 header
+CM3Header
+ pshs a,b,x,y,u
+ leax altbuff,y
+ lda  #1        Single screen w/o patterns
+ sta  ,x+
+ lbsr copypals  16 palette values
+ ldd  <cyclerate
+ bne  CM3head0
+ ldb  #1
+CM3head0
+ stb  ,x+       Cycle rate
+ ldd  <extrarate
+ bne  CM3head1
+ ldb  #1
+CM3head1
+ stb  ,x+       Extra rate
+ leau extrapals,y
+ ldd  ,u++
+ std  ,x++  Copy extrapals to header
+ ldd  ,u++
+ std  ,x++
+ ldd  ,u++
+ std  ,x++
+ ldd  ,u++
+ std  ,x++
+ lda  <cycle
+ beq  CM3head2
+ lda  #$80
+CM3head2
+ sta  ,x+   Cycle enable flag
+ lda  <extranum
+ beq  CM3head3
+ lda  #$80
+CM3head3
+ sta  ,x+   Extra enable flag
+ lda  #192
+ sta  ,x+   Number lines in picture
+
+ pshs y
+ lda  SavePath
+ leax altbuff,y  Now, save the header.
+ ldy  #30
+ os9  I$Write
+ lbcs _error
+ puls y
+
+ leax alt2buff,y  CM3 uses alt2buff to store last line data
+ ldy  #500
+ clra
+ clrb
+CM3head4
+ std  ,x++
+ leay -1,y
+ bne  CM3head4
+
+ puls a,b,x,y,u,pc
+
+* Output a VEF header
+VEFHeader
+ pshs a,b,x,y,u
+ leax altbuff,y
+ clra            For normal format
+ ldb  SaveFormat
+ cmpb #VEFFormat Plain vanilla??
+ beq  Do1
+ lda  #$80       For Squashed format
+Do1
+ sta  ,x+
+ lda  #9
+ suba  <type     Get VEF screen type
+ cmpa #2
+ bhi  Do2
+ deca
+Do2 
+ sta  ,x+
+
+ bsr  copypals   Now copy the palettes.
+
+* Now save the header out to the file.
+ leax altbuff,y
+ lda  SavePath
+ pshs y
+ ldy  #18
+ os9  I$Write
+ lbcs _error
+ puls y
+ bsr  Save8
+ puls a,b,x,y,u,pc
+
+* Write out 8 blank lines to file.
+Save8
+ pshs b
+ lbsr clrline
+ ldb  #8
+DoBlank
+ lbsr outline
+ decb
+ bne  DoBlank
+ puls b,pc
+
+*
+* Copy palettes to X, advance X by 16 bytes.
+*
+copypals
+ pshs a,b
+ lda  <outpath
+ ldb  #SS.Palet
+ os9  I$GetStt
+ leax 16,x
+ puls a,b,pc
+ 
+*
+* Output linebuff to file
+outline
+ pshs a
+ lda  SaveFormat
+ cmpa #VEFSqFormat
+ bne outline1
+ puls a
+ lbra outsqline    Only VEF Squashed format uses outsqline
+outline1
+ cmpa #VEFFormat
+ bne  outline2
+ puls a
+ lbra outVEFline   Unsquashed VEF line.
+outline2
+ cmpa #MGEFormat
+ bne outline3
+ puls a
+ bra  outMGEline  Unsquashed MGE line.
+outline3
+ cmpa #MGE640Format
+ bne outline4
+ puls a
+ bra  outMGEline  Unsquashed MGE line.
+outline4
+ cmpa #CM3Format
+ bne outline5
+ puls a
+ bra  outCM3line  Output CM3 line.
+outline5
+* Additional formats go here.
+outlineend
+ puls a
+ rts
+
+*
+* Output linebuff to file in normal MGE format
+*
+outMGEline
+ pshs a,b,x,y,u
+ lbsr MGEsame
+ leax altbuff,y
+ lda  <type
+ cmpa #5
+ bne  outMGE1
+ lbsr MGE57    Convert type 5 to type 7.
+ bra  outMGE3
+outMGE1
+ cmpa #6
+ bne  outMGE2
+ ldb  SaveFormat
+ cmpb #MGE640Format
+ beq  outMGE11
+ lbsr MGE68    For MGE, convert type 6 to type 8.
+ bra  outMGE3
+outMGE11
+ lbsr MGE67    For 640, convert type 6 to type 7.
+ bra  outMGE3
+outMGE2
+* Other conversions here.
+outMGE3
+ lda  SavePath
+ leax altbuff,y
+ ldy  #160       After conversion, we always have 160 bytes/line
+ os9  I$Write
+ lbcs _error
+ puls a,b,x,y,u,pc
+
+*
+* Output linebuff to file in CM3 format
+*
+outCM3line
+ pshs a,b,x,y,u
+ lbsr MGEsame copy data to altbuff
+ leax altbuff,y
+ lda  <type
+ cmpa #5
+ bne  outCM31
+ lbsr MGE57  Convert type 5 -> type 7
+ bra  outCM33
+outCM31
+ cmpa #6
+ bne  outCM32
+ lbsr MGE68  Convert type 6 -> type 8
+ bra  outCM33
+outCM32
+outCM33 
+
+ lbsr CM3compress compress data from linebuff into altbuff
+
+ lda  SavePath
+ leax altbuff,y Output line data.
+ ldy  ,x++      Get size of data.
+ os9  I$Write
+ lbcs _error
+ puls a,b,x,y,u,pc
+
+*
+* Output linebuff to file in normal VEF format
+*
+outVEFline
+ pshs a,b,x,y,u
+ lda  SavePath
+ leax linebuff,y
+ ldy  LineSize
+ os9  I$Write
+ lbcs _error
+ puls a,b,x,y,u,pc
+
+*
+* Output linebuff to file in Squashed VEF format
+*
+outsqline
+ pshs a,b,x,y,u
+ ldd  LineSize
+ lsrb
+ rora Divide by two.
+ leax linebuff,y
+ lbsr VEFSquash      Squash the first half of the line
+ bsr  sqoutline   output the packet
+ leax d,x
+ lbsr VEFSquash      Squash the second half
+ bsr  sqoutline   output it.
+ puls a,b,x,y,u,pc
+
+*
+* Output packet in Altbuff to SavePath
+sqoutline
+ pshs a,b,x,y
+ leax altbuff,y
+ ldb  ,x
+ incb
+ clra
+ tfr  d,y
+ lda  SavePath
+ os9  I$Write
+ lbcs _error
+ puls a,b,x,y,pc
+
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_savecomp.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,298 @@
+*
+* Save compression routines.
+* VEFSquash: Squashes data for VEF format.
+* CM3Compress: Compresses altbuff using CM3 compression
+* MGEsame: copy linebuff to altbuff
+*
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ psect view_savecomp_a,0,0,0,0,0
+
+*
+* Compress one line with CM3 compression.
+* Expects: line data in altbuff
+* Returns: compressed line in altbuff, preceded by 2-byte size
+* Uses: alt2buff to store last line of data
+Stash equ 160    Stash new line at end of old line
+CM3compress:
+ pshs a,b
+ bsr  CM3stash   Stash line at alt2buff+Stash
+ lbsr CM3docomp  Try to compress it
+ ldd  altbuff,y  Get the result size
+ cmpd #160
+ bls  CM3comp0   If its small, use compressed line
+ bsr  CM3nocomp  Else don't compress it
+CM3comp0
+ bsr  CM3save    Save old line
+ puls a,b,pc
+
+* Copy from altbuff to stash area
+CM3stash
+ pshs a,b,x,u
+ leax altbuff,y
+ leau alt2buff+Stash,y
+ ldb  #160
+CM3st1
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  CM3st1
+ puls a,b,x,u,pc
+
+* Copy from stash area to save area
+CM3save
+ pshs a,b,x,u
+ leax alt2buff+Stash,y
+ leau alt2buff,y
+ ldb  #160
+CM3save1
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  CM3save1
+ puls a,b,x,u,pc
+
+* No compression: from stash area to altbuff
+CM3nocomp
+ pshs a,b,x,y,u
+ leax altbuff,y  First try, no compression at all.
+ ldd  #161
+ std  ,x++
+ ldb  #160
+ stb  ,x+
+ leau alt2buff+Stash,y  Get data from stash area.
+CM3noc1
+ lda  ,u+
+ sta  ,x+
+ decb
+ bne  CM3noc1
+ puls a,b,x,y,u,pc
+
+ vsect dp
+ImagePtr rmb 2
+ImageBit rmb 1
+ActionPtr rmb 2
+ActionBit rmb 1
+ endsect
+
+SetAction
+ pshs a,x
+ lda ActionBit
+ ldx ActionPtr
+ ora ,x
+ sta ,x
+ puls a,x
+ClrAction
+ pshs a,x
+ lda  ActionBit
+ lsra
+ bcc  ClrAct1
+ ldx  ActionPtr
+ leax 1,x
+ stx  ActionPtr
+ inc  altbuff+2,y  Increment count of Action bytes.
+ rora
+ClrAct1
+ sta  ActionBit
+ puls a,x,pc
+
+SetImage
+ pshs a,x
+ lda ImageBit
+ ldx ImagePtr
+ ora ,x
+ sta ,x
+ puls a,x
+ClrImage
+ pshs a,x
+ lda  ImageBit
+ lsra
+ bcc  ClrIm1
+ ldx  ImagePtr
+ leax 1,x
+ stx  ImagePtr
+ rora
+ClrIm1
+ sta  ImageBit
+ puls a,x,pc
+
+* Try doing CM3 compression
+CM3docomp
+ pshs a,b,x,y,u
+
+ leax altbuff,y  Clear out receiving area.
+ clrb
+CM3do1
+ clr  ,x+
+ decb
+ bne  CM3do1
+
+ leax altbuff+2+1,y  Set up Image and Action stuff
+ stx  ImagePtr
+ leax altbuff+2+1+20,y
+ stx  ActionPtr
+ lda  #$80
+ sta  ImageBit  Start with MSBit
+ sta  ActionBit
+ lda  #1
+ sta  altbuff+2,y  Set # Action bytes to 1
+
+ leax alt2buff+Stash,y  Point to line data
+ leau altbuff+2+1+20+20,y  Point to space for extra bytes.
+ ldb  #160  Number of bytes.
+CM3do3
+ lda  ,x+   Get next byte
+ cmpa -2,x  Same as previous?
+ bne  CM3do4
+ bsr  ClrImage  Yes, mark it.
+ bra  CM3do6
+CM3do4
+ bsr  SetImage
+ cmpa -(Stash+1),x  Same as above?
+ bne  CM3do5
+ bsr  ClrAction  Mark as such
+ bra  CM3do6
+CM3do5
+ lbsr SetAction
+ sta  ,u+       Store byte value
+CM3do6
+ decb
+ bne  CM3do3
+
+ ldb  altbuff+2,y  Minimize this value.
+ lda  ActionBit
+ cmpa #$80     If this is true, then last action byte hasn't been used.
+ bne  CM3do7
+ decb          so we can decrement it.
+ beq  CM3do7   ... but not to zero.
+ stb  altbuff+2,y
+CM3do7
+
+ leax altbuff+2+1+20+20,y Point to start of extra bytes
+ ldb  altbuff+2,y  Get # of action bytes
+ subb #20   Number of unused action bytes
+ bne  CM3do8  If none are unused, just leave extra bytes in place.
+ tfr  u,x     Set X to end.
+ bra  CM3do11
+CM3do8
+
+ pshs u    Save end of extra bytes
+CM3do9
+ cmpx ,s
+ beq  CM3do10
+ lda  ,x
+ sta  b,x
+ leax 1,x  Move extra bytes down
+ bra  CM3do9
+CM3do10
+
+ puls u
+ leax b,x  Point to new end of extra bytes.
+CM3do11
+
+ tfr  x,d
+ leax altbuff+2,y
+ pshs x
+ subd ,s  D holds size of compressed data
+ puls x
+ std  altbuff,y store size. 
+ puls a,b,x,y,u,pc
+
+*
+* Squash one packet worth of data
+* Expects: Number of bytes to squash in D.
+*          Bytes to squash pointed to by X.
+* Returns: Squashed packet in altbuff
+VEFSquash:
+ pshs a,b,x,y,u
+ leau altbuff+1,y Data goes here
+ tfr  d,y         Size of data to compress
+ clrb             This will count up size of compressed packet
+Sq1
+ lda  ,x
+ cmpa 1,x
+ bne  Sq2
+ cmpa 2,x   If three bytes are the same, then do compression.
+ bne  Sq2
+ bsr  sqcomprs  Get a compressed subpacket.
+ bra  Sq3
+Sq2
+ bsr  sqstraight
+Sq3
+ sty  -2,s  Same as tsty
+ bne  Sq1
+ ldy  4,s    Restore Y
+ stb  altbuff,y    Store packet size.
+ puls a,b,x,y,u,pc
+
+* Encode a sequence of straight data
+*
+sqstraight
+ pshs u      Save address of subpacket size.
+ clr  ,u+    Set zero count.
+ lda  ,x+
+sqstr1
+ sta  ,u+
+ incb        Increment total bytes
+ inc  [,s]   Increment subpacket size
+ leay -1,y   Count down bytes to compress
+ beq  sqstr2
+ lda  ,x+
+ cmpa ,x    Three like bytes mean we stop here.
+ bne  sqstr1
+ cmpa 1,x
+ bne  sqstr1
+ leax -1,x
+sqstr2
+ incb       Include subpacket size in total count.
+ leas 2,s   Clean up stack.
+ rts
+
+* Encode a sequence of compressed data
+* B is increased by 2, X points to byte after repeated data,
+* U is increased by 2, Y is decreased by number of bytes compressed.
+sqcomprs
+ lda  ,x+   Store the byte as the second byte.
+ sta  1,u
+ clr  ,u   Clear our count
+sqcomprs1
+ inc  ,u
+ leay -1,y
+ beq  sqcomprs2 Abort the loop if Y goes to zero.
+ cmpa ,x+
+ beq  sqcomprs1
+ leax -1,x     Backup to point to different byte
+sqcomprs2
+ lda  ,u
+ ora  #$80  Set high bit for compressed subpacket
+ sta  ,u
+ leau 2,u Move past this subpacket
+ addb #2  and bump total packet size.
+ rts
+
+*
+* MGEsame -- copy linebuff to altbuff
+*
+MGEsame:
+ pshs a,b,x,u
+ leax linebuff,y
+ leau altbuff,y
+ ldb  #160
+MGEsameloop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  MGEsameloop
+ puls a,b,x,u,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_setsave.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,108 @@
+*
+* Save current picture to a file
+*   SetSave:  - Expects Picture format code in A, X points to filename.
+*               Opens save file, prompts for overwrite, sets up save variables.
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+StdIn  equ 0
+StdOut equ 1
+StdErr equ 2
+
+ psect view_setsave_a,0,0,0,0,0
+
+* vsect dp
+*SaveFormat rmb 1  These are all declared in view_save.a
+*SavePath   rmb 1
+* endsect
+
+
+SetSave:
+ pshs a,b,y,u
+ sta  <SaveFormat  Set picture format for save.
+ clr  <SavePath    SavePath = 0 will flag no save.
+ 
+* Try to Create the file specified.
+ lda  #WRITE.     
+ ldb  #READ.+WRITE.
+ pshs x
+ os9  I$Create    Create the file for Write.
+ puls x
+ bcc  SetSaveOK
+
+* We got an error.
+ cmpb #E$CEF      File already exist?
+ lbne _error
+
+* The error was "file already exists", so ask if the user wants to overwrite.
+ lda  #StdErr
+ pshs y,x
+ leax overwrite,pcr
+ ldy  #owlength
+ os9  I$Write    Output the prompt.
+ puls y,x
+ lbcs _error
+ lda  #StdErr    Read from StdErr, in case StdIn is busy....
+ pshs x,y
+ leax altbuff,y
+ ldy  #2
+ os9  I$ReadLn   Read the response.
+ puls x,y
+ lbcs _error
+ lda  altbuff,y
+ cmpa #'y
+ beq  SetSave5
+ cmpa #'Y
+ bne  SetSaveEnd  It wasn't "y" or "Y", so just quit.
+SetSave5
+ lda  #WRITE.
+ pshs x
+ os9  I$Open   Try to open in write mode.
+ puls x
+ lbcs _error
+ 
+* Exit here after successfully opening the file.
+SetSaveOK
+ sta  <SavePath
+
+* Move X past the end of the filename.
+SetSaveEnd
+ 
+SetSave11
+ lda  ,x+           Skip any leading whitespace.
+ cmpa #$20  Space?
+ beq  SetSave11
+ cmpa #$09  Tab?
+ beq  SetSave11
+ cmpa #$0d
+ beq  SetSave14
+
+SetSave12
+ lda  ,x+       Now skip until we find whitespace.
+ cmpa #$20
+ beq  SetSave14
+ cmpa #$09
+ beq  SetSave14
+ cmpa #$0d
+ beq  SetSave14
+ bra  SetSave12
+
+SetSave14
+ leax -1,x  Backup to last character.
+ 
+ puls a,b,y,u,pc
+
+overwrite fcc "Save file already exists. Overwrite (y/n)?  "
+owlength equ *-overwrite
+
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_st.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,318 @@
+*****************************************************************************
+*                                                                           *
+* SUBS for st  picture format                                               *
+*                                                                           *
+* STshowpic -- Displays picture, using putline routine                      *
+*                                                                           *
+*****************************************************************************
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect  view_st_a,0,0,0,0,0 
+
+ vsect dp
+linesize rmb 2   Bytes per line.
+totlines rmb 2   total lines in picture.
+curline  rmb 2   Number of current screen line.
+fitcount rmb 2   Used to decide what lines to skip.
+linesleft rmb 2  Lines left in picture.
+ endsect
+
+STshowpic:
+ bsr  header       Get header info
+
+ ldd  <Skiplines
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+spscreens
+ lbsr getline
+
+ tst  <endoffile
+ bne  showpicend
+ lbsr setscreen    Set up screen
+ lbsr setpals      Set up palettes
+ lbsr setbuffer    Set up Get/Put Buffer
+
+ ldd  #00
+ std  curline
+showpicloop
+ lbsr putline
+ ldd  fitcount
+ addd totlines
+spget
+ std  fitcount
+ lbsr getline
+ tst  <Size
+ bne  spnofit
+ ldd  fitcount
+ subd #192
+ bge  spget
+ std  fitcount
+spnofit
+ ldd  curline
+ addd #1
+ std  curline
+ cmpd #192
+ bne  showpicloop
+ ldd  linesleft
+ cmpd #16
+ bhi  spscreens
+showpicend
+ rts
+
+*
+* read header info from file, and set window type information
+*
+ vsect dp
+endoffile   rmb 1
+ endsect
+
+header
+ pshs a,b,x,y,u
+ leax altbuff,y read in type and palettes into altbuff
+ pshs y
+ ldy  #34
+ lbsr I_Read
+ lbcs _error
+ puls y
+ leax altbuff,y
+ lda  ,x+
+ 
+ lda  ,x+      This byte is the screen type.
+
+ bne  head0
+ lda  #8
+ sta  <type
+ ldd  #200
+ std  totlines
+ std  linesleft
+ ldd  #160
+ std  linesize
+ bra  headpals
+head0
+
+ cmpa #1
+ bne  head1
+ lda  #7
+ sta  <type
+ ldd  #200
+ std  totlines
+ std  linesleft
+ ldd  #160
+ std  linesize
+ bra  headpals
+head1
+
+ cmpa #2
+ bne  head2
+ lda  #5       640  2-color screen.
+ sta  <type
+ ldd  #400
+ std  totlines
+ std  linesleft
+ ldd  #80
+ std  linesize
+ bra  headpals
+head2
+
+headpals
+ leau palette,y   Need to expand palettes out to 3 bytes/palette
+ ldb  #16          16 palettes to expand out.
+headexp
+ lda  ,x+
+ anda #$0f  Red is in lower nybble of first byte.
+ sta  ,u+
+ lda  ,x    Second byte is: upper nybble green, lower nybble blue.
+ lsra
+ lsra
+ lsra
+ lsra
+ sta  ,u+
+ lda  ,x+
+ anda #$0f
+ sta  ,u+
+ decb
+ bne  headexp
+
+ lbsr palscale    First, scale so largest is 255
+ lbsr palconv     Convert palette values from ST to CoCo format 
+
+* Set some miscellaneous variables
+ lda  <cyclestart   No cycling
+ sta  <cycleend
+ clr  <extranum  No color rotation
+
+ ldd  <Skiplines
+ cmpd #$ffff        Is Skiplines still default?
+ bne  headskip      No, don't change it.
+ ldd  #0
+ std  <Skiplines   Set it to 0
+headskip
+
+ lda  <Size
+ bpl  headsize  Default size is BIG
+ lda  #1
+ sta  <Size
+headsize
+
+ puls a,b,x,y,u,pc
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* First, fill buffers with all zeros
+ leau linebuff,y
+ leax altbuff,y
+ ldb  #160
+getline3
+ clr  ,u+
+ clr  ,x+
+ decb
+ bne  getline3
+* If at end of file, leave it that way
+ tst  endoffile
+ beq  getline5
+ ldd  #0
+ std  linesleft  First, set number of lines remaining to zero.
+ lbra getline1
+getline5
+* Count down lines left
+ ldd  linesleft
+ bne  getline6
+ com  endoffile  If no lines left, force end of file condition.
+ lbra getline1
+getline6
+ subd #1
+ std  linesleft
+* Get a line from the file
+ leax altbuff,y     read in one line of screen
+ pshs y
+ ldy  <linesize       Warning:  Mung Y!
+ lbsr I_Read
+ puls y
+ lbcs geteof       Error through EOF check.
+* Now, we have to interleave the bits to get CoCo screen format.
+ leax altbuff,y
+ leau linebuff,y
+ ldy  <linesize  Total number of bytes to convert.
+ lda  <type
+
+ cmpa #5
+ bne  conv5
+cnv5loop
+ lda  ,x+    This type screen, just copy the data.
+ sta  ,u+
+ leay -1,y
+ bne  cnv5loop
+ lbra getline1
+conv5
+
+ cmpa #7    Type 7 screen requires 2-way interleaving.
+ bne  conv7
+cnv7loop
+ lbsr twolev
+ leax 1,x
+ lbsr twolev
+ leax 3,x
+ leay -4,y
+ bne  cnv7loop
+ lbra getline1  Now we're done.
+conv7
+
+ cmpa #8      Type 8 screen requires 4-way interleaving.
+ bne  conv8 
+cnv8loop
+ lbsr fourlev   Convert 4 bytes out of 8 --  X-X-X-X-
+ leax 1,x       Offset to next 4
+ lbsr fourlev   Convert 4 bytes out of 8 --  -X-X-X-X
+ leax 7,x       Now, skip to next 8.
+ leay -8,y      Count down number of bytes.
+ bne  cnv8loop
+ bra  getline1       Now exit.
+conv8
+ bra  getline1       Now exit.
+
+geteof
+ cmpb #E$EOF
+ bne  getline4
+ com  endoffile
+ bra  getline1
+getline4
+ lbra _error      If not EOF, just exit with error.
+getline1
+ puls a,b,x,y,u,pc
+
+* converts bytes 0,x 2,x 4,x and 6,x into 4 CoCo-format bytes
+* at [u].  U is advanced by 4, other regs unchanged.
+
+fourtab
+ fdb $0000,$0001,$0010,$0011,$0100,$0101,$0110,$0111
+ fdb $1000,$1001,$1010,$1011,$1100,$1101,$1110,$1111
+
+fourlev
+ pshs a,b,x,y
+ leay fourtab,pcr
+ ldb  #4
+ pshs b   4 bytes to worry about.
+ bra  fourlev1
+fourlev0
+ lsl  3,u
+ rol  2,u
+ rol  1,u
+ rol  ,u
+fourlev1
+ lda  ,x         Get high nybble of byte.
+ lsra
+ lsra
+ lsra
+ anda #$1e
+ ldd  a,y        Expand it out.
+ ora  ,u         Or it into stuff so far.
+ orb  1,u
+ std  ,u
+ lda  ,x++       Get low nybble, and advance to next byte.
+ anda #$0f
+ lsla
+ ldd  a,y        Expand it out.
+ ora  2,u        Or into stuff so far.
+ orb  3,u
+ std  2,u
+ dec  ,s         Have we done all four bytes?
+ bne  fourlev0
+ puls b          Clean up stack.
+ leau 4,u
+ puls a,b,x,y,pc
+
+twolev
+ bsr  twolev1
+twolev1
+ pshs a,b
+ ldb  #4
+twoloop
+ lsl  ,x
+ rola
+ lsl  2,x
+ rola
+ decb
+ bne  twoloop
+ sta  ,u+
+ puls a,b,pc
+
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_table.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,372 @@
+*
+*
+* Table to drive command line parser.  The routines to process individual
+*  options are also in this file.
+*
+* Three global symbols:
+*   PTable: options table
+*   DefFormat: Set up Default format (VEF)
+*   Help:  Give usage message.
+*
+*
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect view_table_a,0,0,0,0,0
+
+
+* Options parsing table.
+*  Each entry: null-terminated option string,
+*              one-byte option code,
+*              Lbra instruction to subroutine to process that option.
+* The subroutine is called with the option code in register A, and
+*   X points to the first byte on the command line after the option
+*   (for use in parsing arguments to options).
+* This simplifies the handling of format codes, in particular.
+*
+* In order to prevent incorrect matches, longer options should occur
+*   earlier in the table, since the matching code will match the first
+*   legal option that matches the first part of the given option.
+*   i.e.  if "opt" occurs before "opt1", then "opt1" will never get
+*   a match
+*
+PTable:
+ fcc  "formats"   -formats
+ fcb  0,0
+ lbra ShowFormats
+ fcc  "savemge"   -savemge
+ fcb  0,MGEFormat
+ lbra SetSave
+ fcc  "save640"   -save640
+ fcb  0,MGE640Format
+ lbra SetSave
+ fcc  "savevef"   -savevef
+ fcb  0,VEFFormat
+ lbra SetSave
+ fcc  "savecm3"   -savecm3
+ fcb  0,CM3Format
+ lbra SetSave
+ fcc  "signal"    -signal
+ fcb  0,0
+ lbra SetSignal
+ fcc  "nobuff"    -nobuff forces a very small buffer
+ fcb  0,0
+ lbra NoBuff
+ fcc  "save"      -save    (VEF Squashed)
+ fcb  0,VEFSqFormat
+ lbra SetSave
+ fcc  "small"     -small
+ fcb  0,0
+ lbra SetSize
+ fcc  "large"     -large
+ fcb  0,1
+ lbra SetSize
+ fcc  "huge"      -huge
+ fcb  0,2
+ lbra SetSize
+ fcc  "sml"       -sml
+ fcb  0,0
+ lbra SetSize
+ fcc  "big"       -big
+ fcb  0,1
+ lbra SetSize
+ fcc  "lrg"       -lrg
+ fcb  0,1
+ lbra SetSize
+ fcc  "maxcmp"    -maxcmp
+ fcb  0,MAXCMPFormat
+ lbra SetMAXCMP
+ fcc  "pixcmp"    -pixcmp
+ fcb  0,MAXCMPFormat
+ lbra SetMAXCMP
+ fcc  "artcmp"    -artcmp
+ fcb  0,ARTCMPFormat
+ lbra SetMAXCMP
+ fcc  "pix256"    -pix256   (DS69B 256x256 format)
+ fcb  0,PIX256Format
+ lbra SetFormat
+ fcc  "pix128"    -pix128   (DS69B 128x128 format)
+ fcb  0,PIX128Format
+ lbra SetFormat
+ fcc  "pix"       -pix     (Note: _must_ occur after pix256 & pix128)
+ fcb  0,PIXFormat
+ lbra SetFormat
+ fcc  "vef"       -vef
+ fcb  0,1
+ lbra SetVF       only 1 picture VEF format.
+ fcc  "vf2"       -vf2 option
+ fcb  0,2
+ lbra SetVF
+ fcc  "vf3"       -vf3 option
+ fcb  0,3
+ lbra SetVF
+ fcc  "vf4"       -vf4 option
+ fcb  0,4
+ lbra SetVF
+ fcc  "vf5"       -vf5 option
+ fcb  0,5
+ lbra SetVF
+ fcc  "vf6"       -vf6
+ fcb  0,6
+ lbra SetVF
+ fcc  "vf7"       -vf7
+ fcb  0,7
+ lbra SetVF
+ fcc  "vf8"       -vf8
+ fcb  0,8
+ lbra SetVF
+ fcc  "vf9"       -vf9
+ fcb  0,9
+ lbra SetVF
+ fcc  "mge"       -mge option
+ fcb  0,MGEFormat
+ lbra SetFormat
+ fcc  "cm3"       -cm3 option
+ fcb  0,CM3Format
+ lbra SetFormat
+ fcc  "640"       -640 option
+ fcb  0,MGE640Format
+ lbra SetFormat
+ fcc  "clp"       -clp option
+ fcb  0,CLPFormat
+ lbra SetFormat
+ fcc  "pub"       -pub option  (Home Publisher ClipArt format)
+ fcb  0,PUBFormat
+ lbra SetFormat
+ fcc  "img"       -img option
+ fcb  0,IMGFormat
+ lbra SetFormat
+ fcc  "rat"       -rat option
+ fcb  0,RATFormat
+ lbra SetFormat
+ fcc  "art"       -art option
+ fcb  0,ARTFormat
+ lbra SetFormat
+ fcc  "bin"       -bin same as -max
+ fcb  0,MAXFormat
+ lbra SetFormat
+ fcc  "max"       -max option
+ fcb  0,MAXFormat
+ lbra SetFormat
+ fcc  "p00"       -p00 option
+ fcb  0,P00Format
+ lbra SetFormat
+ fcc  "p01"       -p01 option
+ fcb  0,P01Format
+ lbra SetFormat
+ fcc  "p10"       -p10 option
+ fcb  0,P10Format
+ lbra SetFormat
+ fcc  "p11"       -p11 option
+ fcb  0,P11Format
+ lbra SetFormat
+ fcc  "p20"       -p20 option
+ fcb  0,P20Format
+ lbra SetFormat
+ fcc  "p21"       -p21 option
+ fcb  0,P21Format
+ lbra SetFormat
+ fcc  "p30"       -p30 option
+ fcb  0,P30Format
+ lbra SetFormat
+ fcc  "p31"       -p31 option
+ fcb  0,P31Format
+ lbra SetFormat
+ fcc  "p40"       -p40 option
+ fcb  0,P40Format
+ lbra SetFormat
+ fcc  "p41"       -p41 option
+ fcb  0,P41Format
+ lbra SetFormat
+ fcc  "rle"       -rle option
+ fcb  0,RLEFormat
+ lbra SetFormat
+ fcc  "mac"       -mac option
+ fcb  0,MACFormat
+ lbra SetFormat
+ fcc  "mcp"       -mcp option
+ fcb  0,MACFormat
+ lbra SetFormat
+ fcc  "gifbw"     -gifbw option
+ fcb  0,GIFBWFormat
+ lbra SetGIF
+ fcc  "bwgif"     -bwgif option
+ fcb  0,GIFBWFormat
+ lbra SetGIF
+ fcc  "gbw"       -gbw option
+ fcb  0,GIFBWFormat
+ lbra SetGIF
+ fcc  "gif"       -gif option
+ fcb  0,GIFFormat
+ lbra SetGIF
+ fcc  "stp"       -stp  is synonym for -st, for MultiVue
+ fcb  0,STFormat
+ lbra SetFormat
+ fcc  "st"        -st option
+ fcb  0,STFormat
+ lbra SetFormat
+ fcc  "t"         -t#  Set screen to this type.
+ fcb  0,0
+ lbra Settype
+ fcc  "s"         -s   Use same screen
+ fcb  0,0
+ lbra Setsame
+ fcc  "c"         -c   Enable color cycling
+ fcb  0,0
+ lbra Setcycle
+ fcc  "f"         -f  Fit on one screen
+ fcb  0,0             Now is a synonym for -small
+ lbra SetSize
+ fcc  "y"         -y#  Skip this many lines at top.
+ fcb  0,0
+ lbra Setskip
+ fcc  "x"         -x#  Skip this many columns at left
+ fcb  0,0
+ lbra Setcols
+ fcc  "help"      -help   Give help message
+ fcb  0,0
+ lbra Help
+ fcc  "h"         -h   Give help message
+ fcb  0,0
+ lbra Help
+ fcc  "?"         -?   Give help message
+ fcb  0,0
+ lbra Help
+ fcc  "q"         -q#  Quit after this many seconds
+ fcb  0,0
+ lbra Quit
+* Additional options here
+ fcb  0
+
+Help:
+ pshs x
+ leax Usage,pcr
+ lbsr O_Write
+ ldb  #1
+ os9  F$Exit
+ puls x,pc
+
+ShowFormats
+ pshs x
+ leax Formats,pcr   -formats exits after message.
+ lbsr O_Write
+ ldb  #1
+ os9  F$Exit
+ puls x,pc
+ 
+
+***********************
+*
+* Subroutines to process specific options
+*
+***********************
+*
+* Default Format sets VEF format.
+*
+DefFormat:
+ tst <format    If format already set, ignore.
+ bne SetVEF1
+ lda #1         One-picture VEF is default.
+ lbsr SetVF
+SetVEF1
+ rts
+
+* -t option
+*
+Settype
+ lbsr Getnum   Get argument, check for validity
+ cmpb #5
+ blo  Settype1
+ cmpb #8
+ bhi  Settype1
+
+ lda  <type   Has it already been set?
+ cmpa #5
+ blo  Settype0
+ cmpa #8
+ bls  Settype1
+Settype0
+ stb  <type  All okay, set it.
+Settype1
+ rts
+
+* -s option
+*
+Setsame
+ lda #$FF
+ sta <Samescreen
+ rts
+
+* Size options
+*
+SetSize
+ tst <Size
+ bpl SetSize1  If Size is >=0, then it's already been set.
+ sta <Size
+SetSize1
+ rts
+
+* -c option
+Setcycle
+ lda #$FF
+ sta <cycle
+ rts
+
+* -y option
+Setskip
+ lbsr Getnum
+ pshs d
+ ldd  <Skiplines
+ bpl  noskip
+ ldd  ,s
+ std  <Skiplines
+noskip
+ puls d,pc
+
+* -x option
+Setcols
+ lbsr Getnum
+ pshs d
+ ldd  <Skipcols
+ bpl  nocols
+ ldd  ,s
+ std  <Skipcols
+nocols
+ puls d,pc
+
+* -q option
+Quit
+ lbsr Getnum
+ lda  #60      Multiply by 60 ticks/second.
+ mul
+ std  <MaxTime
+ rts
+
+* -nobuff option
+NoBuff
+ ldd #16      16 bytes of buffer.
+ std <MaxBuff
+ rts
+
+* Handle format options
+* On entry, A holds the format code
+SetFormat
+ tst <format
+ bne SetForm1
+ sta <format
+SetForm1
+ rts
+
+* Set signal PID and value
+SetSignal
+ lbsr Getnum
+ stb  <SigPID
+ lbsr Getnum
+ stb  <SigOut
+ rts
+ 
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_vef.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,308 @@
+*****************************************************************************
+*                                                                           *
+* SUBS for vef picture format                                               *
+*                                                                           *
+* VEFshowpic -- Displays picture, using putline routine                     *
+*                                                                           *
+*****************************************************************************
+
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+ psect  view_vef_a,0,0,0,0,0 
+
+ vsect dp
+linesize rmb 2
+endofpic rmb 1
+VEFtype  rmb 1
+numpics  rmb 1  Total number of pictures to load.
+ endsect
+
+SetVF:
+ tst  <format
+ bne  SetVF1
+ sta  numpics  Set total number of pictures.
+ lda  #VEFFormat
+ sta  <format
+SetVF1
+ rts
+
+VEFshowpic:
+ clra
+VEFshow1
+ bsr  showvef
+ inca
+ cmpa numpics
+ bne  VEFshow1
+
+* Now, were we displaying multiple pix??
+ lda  numpics
+ cmpa #1
+ beq  onepic
+ lda  <cyclestart   Disable cycling
+ sta  <cycleend
+ lda  #$ff
+ sta  <flipping    Enable flipping.
+ ldd  #2
+ std  <fliprate
+onepic
+ rts
+  
+showvef
+ pshs a,b,x,y,u
+ bsr  header       Get header info
+ lbsr setscreen    Set up screen
+ lbsr setpals      Set up palettes
+
+ lbsr setbuffer    Set up Get/Put Buffer
+ std  linesize     Store size of line in bytes.
+ lda  VEFtype
+ cmpa #2
+ bne  showvef00
+ ldd  linesize   Screen type 2 is simulated, so halve the linesize value
+ lsra
+ rorb
+ std  linesize
+showvef00
+
+ ldd  <Skiplines  Skip lines at top.
+ beq  skip01
+skip00
+ lbsr getline
+ subd #1
+ bne  skip00
+skip01
+
+ ldd  #00        Now display 192 lines
+showpicloop
+ lbsr getline
+ lbsr putline
+ addd #1
+ cmpd #192
+ bne  showpicloop
+
+showpicclear
+ lbsr getline    Now read until end of picture (to prepare for next file).
+ tst  endofpic
+ beq  showpicclear
+
+ puls a,b,x,y,u,pc
+
+*
+* read header info from file, and set window type information
+*
+ vsect dp
+endoffile   rmb 1
+compression rmb 1   0= Normal, $80=Squashed
+count       rmb 1   Counts number packets to decode
+linesleft   rmb 1   Counts down lines in picture.
+ endsect
+
+header
+ pshs a,b,x,y,u
+ clr  endofpic
+ ldb  #200
+ stb  linesleft
+ leax altbuff,y read in type and palettes into altbuff
+ pshs y
+ ldy  #18
+ lbsr I_Read
+ lbcs _error
+ puls y
+ leax altbuff,y
+ lda  ,x+      This byte is the compression type: 0=none, $80=squashed.
+ beq  header10
+ cmpa #$80     Squashed format
+ lbne E$Format
+header10
+ sta  compression
+ lda  ,x+
+ cmpa #4
+ lbhi E$Format
+ sta  VEFtype
+ tst  <type
+ bne  headtype
+ leau headtable,pcr
+ lda  a,u
+ sta  <type
+headtype
+ leau palette,y
+ ldb  #16
+headloop
+ lda  ,x+
+ sta  ,u+
+ decb
+ bne  headloop
+ bra  headmisc
+headtable fcb 8,7,8,6,5
+headmisc
+* Set some miscellaneous variables
+ lda  #8            Set first, last palette for animation
+ sta  <cyclestart
+ lda  #15
+ sta  <cycleend
+ ldd  #5            Default animation delay
+ std  <cyclerate
+ lda  #0            No color rotation
+ sta  <extranum
+ ldd  <Skiplines
+ cmpd #$ffff        Is Skiplines still default?
+ bne  headskip      No, don't change it.
+ ldd  #8
+ std  <Skiplines   Set it to 8.
+headskip
+ puls a,b,x,y,u,pc
+
+*
+* Getline
+*
+getline
+ pshs a,b,x,y,u
+* First, fill buffers with all zeros
+ leau linebuff,y
+ ldb  #160
+getline3
+ clr  ,u+
+ decb
+ bne  getline3
+* If at end of file, leave it that way
+ tst  endoffile
+ bne  getline1
+* If at end of picture, leave it that way
+ tst  endofpic
+ bne  getline1
+* Decrement lines left in pic, set endofpic if appropriate
+ dec  linesleft
+ bne  morelines
+ com  endofpic
+morelines
+* Test compression method
+ tst  compression
+ bmi  squash
+* Get an unsquashed line
+ pshs y
+ leax linebuff,y     read in one line of screen
+ ldy  linesize
+ lbsr I_Read
+ puls y
+ lbcs getline2       Error through EOF check.
+ bra  getline0       Now exit.
+* Get a squashed line
+squash
+ leau linebuff,y
+ ldb  #2
+ stb  count
+squash1
+ lbsr I_GetByte
+ bcs  getline2
+ tfr  a,b
+ clra
+ leax altbuff,y    Use AltBuff to store data to unsquash
+ pshs y
+ tfr  d,y
+ lbsr I_Read
+ puls y
+ lbcs getline2
+ ldd  linesize
+ lsra
+ rorb          Always decode half a line at a time.
+ bsr  unsquash
+ dec  count
+ bne  squash1
+ bra  getline0
+* Handle read error
+getline2
+ cmpb #E$EOF
+ bne  getline4
+ com  endoffile
+ bra  getline1
+* Finished reading line
+getline0
+ lda  VEFtype
+ cmpa #2
+ bne  getline1
+ bsr  expand
+ bra  getline1
+* Handle bad errors
+getline4
+ lbra _error      If not EOF, just exit with error.
+* Exit getline
+getline1
+ puls a,b,x,y,u,pc
+
+*
+* Expand a 160 pixel 16-color line to a 320 pixel 16-color line
+*
+expand
+ pshs a,b,x,y,u
+ leax linebuff,y
+ leay exptable,pcr
+ ldd  linesize  (Actually fits in just B)
+ leax d,x   X points to end of 160 pixel line
+ leau d,x   U points to end of 320 pixel line
+exploop
+ lda  ,-x
+ anda #$0f
+ lda  a,y
+ sta  ,-u
+ lda  ,x
+ lsra
+ lsra
+ lsra
+ lsra
+ lda  a,y
+ sta  ,-u
+ decb
+ bne  exploop
+ puls a,b,x,y,u,pc
+
+exptable fcb $00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$AA,$BB,$CC,$DD,$EE,$FF
+
+*
+* X points to data to unsquash, U points to destination buffer
+*    unsquashed result will be exactly B bytes.
+* Exit: U points to end of unsquashed, all else unchanged.
+*
+ vsect dp
+unsq_count rmb 1
+ endsect
+
+unsquash
+ pshs a,b,x
+ stb  unsq_count
+unsq_loop
+ ldb  ,x+
+ beq  unsq_end
+ bpl  gl_straight
+ lda  ,x+
+* Deal with repeated byte
+gl_comp
+ andb #$7f       Strip off high bit
+gl_comp2
+ sta  ,u+         Store a copy of this byte
+ dec  unsq_count
+ beq  unsq_end
+ decb             decrement repeat count
+ bne  gl_comp2    Not done, loop
+ bra  unsq_loop   Done, get another control value from file.
+* Deal with straight section
+gl_straight
+ lda  ,x+
+ sta  ,u+          store it
+ dec  unsq_count
+ beq  unsq_end
+ decb              count down bytes left
+ bne  gl_straight
+ bra  unsq_loop    If done, get next section
+unsq_end
+ puls a,b,x,pc
+
+ endsect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3rdparty/utils/view/view_wait.a	Tue Aug 10 23:46:24 2004 +0000
@@ -0,0 +1,376 @@
+*
+* View_wait.a   -- End-of-picture pause... handles color cycling, screen
+*      flipping, and timeout.
+*
+* Global labels:
+*   keywait: Subroutine to handle end-of-picture pause.
+*   SetSig:  Sets trivial signal trap which stores signal in SigCode
+*
+check macro
+      pshs b,cc
+      ldb  #\1
+      os9  F$PErr
+      puls b,cc
+      endm
+
+ ifp1
+ use /dd/defs/os9defs.a
+ endc
+
+StdOut equ 1
+StdErr equ 2
+
+ psect View_wait_a,0,0,0,0,0
+
+*******************************************************
+*
+* Keywait- wait for keypress or mouse click
+*   Also, handle palette cycling.
+*
+*******************************************************
+ vsect dp
+cycleleft rmb 2
+extraleft rmb 2
+ endsect
+
+keywait:
+ pshs  a,b,x,y,u
+ clr   <abort
+
+ ldd   <cyclerate   Initialize cycle and extra count-down timers.
+ std   <cycleleft
+ ldd   <extrarate
+ std   <extraleft
+
+kwloop
+ lbsr  conscheck    Check for consistency, to make sure we don't waste time.
+ clr   <SigCode     Set up our signals.
+ lbsr  setmouse
+ lbsr  setkeysig
+
+kwchkey
+ lbsr  getkey       Is there a key waiting?
+ bcs   kwnokey
+ clr   <SigCode
+ lbsr  kwdokey      If so, handle it
+ bra   kwchkey      . and then check again.
+kwnokey
+
+ tst   <flipping    If flipping is on, do that.
+ beq   kwnoflip
+ lbsr  kwflip
+ bra   kwsig
+kwnoflip
+
+ tst   <cycle       If animation is on, do that.
+ beq   kwnocycle
+ lbsr  kwanimate
+ bra   kwsig
+kwnocycle
+
+ ldx   <MaxTime     If none of the above, just sleep for MaxTime
+ cmpx  #0
+ beq   kwsig
+ tst   <SigCode
+ bne   nosleep1
+ os9   F$Sleep
+nosleep1
+ stx   <MaxTime
+
+
+*
+* Handle a signal.
+kwsig
+ ldd   <MaxTime   If we timed out, end now.
+ beq   kwend
+ lda   <SigCode
+
+ cmpa  #KButton   Was it a keypress that woke us up?
+ bne   kwnokey1
+ clr   <SigCode   If so, clear sigcode,
+ lbsr  getkey     .  get the key
+ bsr   kwdokey    .  process it
+ bcc   kwloop     .  and keep going.
+ bra   kwend
+kwnokey1
+
+ cmpa  #MButton   Was it a mouse click?
+ bne   kwnomouse      None of the above, we just exit.
+ bsr   kwdomouse
+ lbcc  kwloop
+ bra   kwend
+kwnomouse
+
+kwend
+ puls  a,b,x,y,u,pc
+
+
+*
+* Process a mouse click.
+*
+kwdomouse
+ clr   <SigCode
+ orcc  #Carry    Set carry, since any mouse click should end.
+ rts
+
+*
+* process a key press.
+*  Expects: key in A.
+kwdokey
+ pshs  a,b,x
+ cmpa  #'Z        Convert key to lower case
+ bhi   kwlower
+ cmpa  #'A
+ blo   kwlower
+ suba  #'A-'a
+kwlower
+
+ cmpa  #$20       Was it a space?
+ bne   kwkey1
+ com   <cycle     Yes, turn cycling on/off
+ lbne  kwdonekey
+ lbsr  setpals    Restore original palettes, if we just turned cycling off.
+ lbra  kwdonekey
+kwkey1
+
+ cmpa  #',        Was it a "<"?
+ beq   kwkey21
+ cmpa  #'<
+ beq   kwkey21
+ cmpa  #'s        Was it an "S" (slower)
+ bne   kwkey2
+kwkey21
+ ldx   <cyclerate
+ leax  1,x         Increase the cycle delay
+ beq   kwkey22
+ stx   <cyclerate
+kwkey22
+ tst   <flipping
+ beq   kwkey23    If not flipping, don't do this...
+ ldd   <fliprate
+ addd  #1
+ cmpd  #6000
+ bhs   kwkey23
+ std   <fliprate
+kwkey23
+ lbra  kwdonekey
+kwkey2
+
+ cmpa  #'.
+ beq   kwkey31
+ cmpa  #'>
+ beq   kwkey31
+ cmpa  #'f        "F" (faster)
+ bne   kwkey3
+kwkey31
+ ldx   <cyclerate
+ leax  -1,x       Decrease the cycle delay
+ beq   kwkey32
+ stx   <cyclerate  Don't make it zero!
+kwkey32
+ tst   <flipping
+ beq   kwkey33    If not flipping, don't do this...
+ ldd   <fliprate
+ subd  #1
+ cmpd  #2
+ bls   kwkey33
+ std   <fliprate
+kwkey33
+ lbra  kwdonekey
+kwkey3
+
+ cmpa  #$B2      F2 key
+ beq   kwkey41
+ cmpa  #$0a      Down-arrow
+ bne   kwkey4
+kwkey41
+ lbsr  flipscreen
+ lbra  kwdonekey
+kwkey4
+
+ cmpa  #$0c     Up-arrow
+ bne   kwkey5
+ lbsr  flipback
+ lbra  kwdonekey
+kwkey5
+
+ cmpa  #$B1
+ bne   kwkey6
+ lda   <flipping
+ beq   kwkey61
+ lda   #$ff
+kwkey61
+ coma
+ sta   <flipping
+ lbra  kwdonekey
+kwkey6
+
+ lbsr  docycle   Any other key? Single step.
+ lbsr  dorotate
+ lbra  kwdonekey
+kwdonekey
+ andcc #^Carry   Clear carry flag, since no key forces an exit.
+ puls  a,b,x,pc
+
+*
+* Check cycle, extra, and flipping variables for consistency,
+*   since naive routines may end up with inconsistent or inefficient
+*   combinations of settings (for example, we might end up with
+*   flipping enabled, but only one screen allocated).
+*
+conscheck
+ pshs  a,b
+* Check "cycle" values for consistency.
+ lda   <cyclestart  Do a consistency check on the cycle values.
+ cmpa  <cycleend
+ blo   cons0
+ ldd   #$ffff       if cyclestart >= cycleend, then
+ std   <cyclerate   set cyclerate to $ffff.
+ bra   cons1
+cons0
+ ldd   <cyclerate   otherwise, make sure cyclerate is not 0
+ bne   cons1
+ ldd   #10          Just a random value.
+ std   <cyclerate
+cons1
+
+* Check "extra" palette values for consistency.
+ lda   <extranum    Do a consistency check on extra palette values.
+ bne   cons2
+ ldd   #$ffff       if extranum is zero,
+ std   <extrarate   set extrarate to $ffff.
+ bra   cons3
+cons2
+ ldd   <extrarate   otherwise, make sure extrarate is not 0
+ bne   cons3
+ ldd   #10          Just a random value.
+ std   <extrarate
+cons3
+
+* Check flipping vars for consistency
+ lda   <numscreens  Do a consistency check on flipping var.
+ cmpa  #2
+ bhs   cons4
+ clr   <flipping    If <2 screens, then ensure flipping is off.
+cons4
+
+* Check "cycle" variable for consistency.
+ lda   <cyclestart  A consistency check: If all animation effects
+ cmpa  <cycleend       are disabled, then turn off "cycle"
+ blo   cons5
+ lda   <extranum
+ bne   cons5
+ clr   <cycle    And turn off cycle flag.
+cons5
+
+ puls  a,b,pc
+
+*
+* Do screen flipping
+*    Return when MaxTime goes to zero, or when a signal is received.
+*
+kwflip
+ pshs a,b,x
+kwfliploop
+ ldd  <MaxTime  Count down one extra tick each time through
+ lbeq kwflipend
+ lbsr flipscreen   Do one flip
+ ldd  <fliprate    interval between flips
+ cmpd <MaxTime
+ lbls kwflip0      If MaxTime is shorter than this, use MaxTime instead.
+ ldd  <MaxTime
+kwflip0
+ tfr  d,x
+ pshs x
+ tst  <SigCode
+ bne  nosleep2
+ os9  F$Sleep
+nosleep2
+ pshs x
+ ldd  <MaxTime   Count down MaxTime
+ addd ,s++
+ subd ,s++
+ std  <MaxTime
+ tst  <SigCode   Did we end due to a signal?
+ beq  kwfliploop      No, keep flipping.
+kwflipend
+ puls a,b,x,pc
+
+*
+* Do animation
+*   Return when MaxTime goes to zero, or a signal is received.
+*
+kwanimate
+ pshs  a,b,x
+kwanimloop
+ ldd   <MaxTime
+ lbeq  kwanimend     If MaxTime is zero, quit now.
+
+ ldd   <cycleleft    Have we timed out for cycle?
+ bne   kwanim0
+ lbsr  docycle       Roll the palettes.
+ ldd   <cyclerate    Restore the countdown.
+ std   <cycleleft
+kwanim0
+
+ ldd   <extraleft    Have we timed out for extra?
+ bne   kwanim1
+ lbsr  dorotate      Rotate extra palettes.
+ ldd   <extrarate    Restore the countdown.
+ std   <extraleft    
+kwanim1
+
+ ldd   <cycleleft    Sleep for the appropriate delay
+ cmpd  <extraleft
+ blo   kwanim20      The appropriate delay is the least of
+ ldd   <extraleft    cycleleft, extraleft, and MaxTime.
+kwanim20
+ cmpd  <MaxTime
+ blo   kwanim2
+ ldd   <MaxTime
+kwanim2
+
+ tfr   d,x      Save original delay in D.
+ tst   <SigCode
+ bne   nosleep3
+ os9   F$Sleep  This returns the amount of time that we didn't sleep.
+nosleep3
+ pshs  x
+ subd  ,s     subtract time left
+ std   ,s     This gives total time slept
+ ldd   <MaxTime   Count down maximum time left
+ subd  ,s
+ std   <MaxTime
+ ldd   <cycleleft Count down cycle time left
+ subd  ,s
+ std   <cycleleft
+ ldd   <extraleft count down extra time left
+ subd  ,s++       Clean up the stack while we're at it.
+ std   <extraleft
+
+ tst   <SigCode    Were we woken up by a signal?
+ beq   kwanimloop   No, keep going.
+kwanimend
+ puls  a,b,x,pc
+
+*
+* Trivial signal handler... store signal value and exit
+*
+SigInter
+ stb   SigCode,u   Store the signal code.
+ tfr   u,y         Set up y as it should be.
+ tfr   u,d
+ tfr   a,dp        Set up DP too.
+ tst   <abort      Should we abort now?
+ lbne  _abort
+ rti
+
+SetSig:
+ pshs  x,y,u
+ leax  SigInter,pcr   Set the signal intercept
+ leau  ,y
+ os9   F$Icpt
+ lbcs  _error
+ puls  x,y,u,pc
+
+ endsect