%endoflist; ! Raster  package

! For annotation and IMP version look after the %endoffile

%recordformat rasterf(%integer height,width,address)

%routine move raster(%record(rasterf)%name source,dest,%integer x,y)
! Draw raster SOURCE into raster DEST at offset X,Y within DEST.
%integer shiftcount = x&15
%integer sourcead = source_address
%integer destad = dest_address+(x>>4+y*(dest_width+15)>>4)<<1
%integer horizontal = (source_width+15)>>4
%integer adjustment = ((dest_width+15)>>4-horizontal)<<1
%integer vcount = source_height-1
%integer hcount
%integer pattern
! D0:hcount D1:vcount D2:pattern D3:shiftcount A0:sourcead A1:destad
   *move.l vcount,d1
   *move.l shiftcount,d3
   *move.l sourcead,a0
   *move.l destad,a1
l1:*moveq #-1,d0; *add.l horizontal,d0
l2:*moveq #0,d2; *move.w (a0)+,d2
   *ror.l d3,d2
   *swap d2
   *move.l d2,(a1)
   *addq.l #2,a1
   *dbra d0,l2
   *add.l adjustment,a1
   *dbra d1,l1
%end

%record(rasterf)screen
screen_height = 1024; screen_width = 1024; screen_address = 16_c00000
%list
%endoffile

! A raster is a sequence of bits representing a rectangular array of dots.
! It is held in an array of 16-bit words, of which the first N words
! represent the bottom (minimum Y) scan line, the next N words the next scan
! line, the last N words the top (maximum Y) scan line.  The total number of
! words is H*N where N=(W+15)//16, where the size of the rectangle is W dots
! wide by H dots high.  Within each scan line (group of N words) the first
! word represents the 16 left-most (minimum X) dots, with the most significant
! bit representing the left-most dot.
! Rasters are manipulated through descriptor records which contain the size
! (i.e. the height and width in number of dots) of the rectangle and the
! address of the first word.  The reference point for the rectangles (which
! is the most significant bit of the first word) is the lower left corner.

%recordformat rasterf(%integer height,width,address)

%routine move raster(%record(rasterf)%name source,dest,%integer x,y)
! Draw raster SOURCE into raster DEST at offset X,Y within DEST.
%integer shiftcount = x&15
%integer sourcead = source_address
%integer destad = dest_address+(x>>4+y*(dest_width+15)>>4)<<1
%integer horizontal = (source_width+15)>>4
%integer adjustment = ((dest_width+15)>>4-horizontal)<<1
%integer vcount = source_height-1
%integer hcount
%integer pattern
  %cycle
    hcount = horizontal-1
    %cycle
      pattern = shortinteger(sourcead)&65535; sourcead = sourcead+2
      shiftcount = shiftcount+16
      pattern = pattern>>shiftcount + pattern<<(32-shiftcount); !ROR.L shc,pat
      shiftcount = shiftcount-16;                               !SWAP   pat
      integer(destad) = pattern; destad = destad+2
      hcount = hcount-1
    %repeatuntil hcount<0
    destad = destad+adjustment
    vcount = vcount-1
  %repeatuntil vcount<0
%end

%record(rasterf)screen
screen_height = 1024; screen_width = 1024; screen_address = 16_c00000
%list
%endoffile
