include "inc/cmdsys.plh"
include "inc/dgrlib.plh"
include "inc/vblank.plh"
include "inc/lines.plh"
sysflags restxt1|restxt2|resxtxt1|resxtxt2    // Reserve all text pages

byte[] sprite1 = $80,$80,$00,$00,$00,$00,$80,$80
byte[]         = $80,$00,$0A,$0A,$0A,$0A,$00,$80
byte[]         = $00,$0A,$0F,$0F,$0F,$0F,$0A,$00
byte[]         = $00,$0A,$0F,$80,$80,$0F,$0A,$00
byte[]         = $00,$0A,$0F,$80,$80,$0F,$0A,$00
byte[]         = $00,$0A,$0F,$0F,$0F,$0F,$0A,$00
byte[]         = $80,$00,$0A,$0A,$0A,$0A,$00,$80
byte[]         = $80,$80,$00,$00,$00,$00,$80,$80

byte[] tile1 = $88,$11,$88,$11,$88,$11,$AA,$00
byte[]       = $88,$11,$88,$11,$88,$11,$AA,$00
byte[]       = $88,$11,$88,$11,$88,$11,$AA,$00
byte[]       = $0A,$05,$0A,$05,$0A,$05,$0A,$00

//
// Test routine
//
def dgrTest#0
  byte b, l, k
  word i, j, ii, ij

  b = dgrMode(dgrPage1)
  dgrDrawBuf(dgrPage1)
  for k = 15 downto 0
    dgrClear(k)
  next
  setlinespans(@dgrHLin, @dgrVLin)
  for l = 0 to 79
    dgrColor(l)
    linespans(0, 0, l, 47)
  next
  for l = 47 downto 0
    dgrColor(l)
    linespans(0, 0, 79, l)
  next
  ii = 2
  ij = -1
  i = 40
  j = 10
  ^$C010
  dgrDrawBuf(dgrPage2)
  while ^$C000 < 128
    dgrFill(k, k, @tile1)
    dgrBLT(i, j, 8, 8, @sprite1)
    waitVBL
    dgrSwap
    k++
    i = i + ii
    if i < -3 or i > 75
      ii = -ii
    fin
    j = j + ij
    if j < -3 or j > 43
      ij = -ij
    fin
  loop
  ^$C010
  dgrMode(dgrOff)
end

dgrTest
done
