#include "library/enterprisestart.bas"

#include "library/smsrnd.bas"
#include "library/smsdelay.bas"
#include "library/charmap01_enterprisehires.bas"
#include "library/ldiruintegeradd.bas"

dim eee as uinteger at $1F10
dim seed as uinteger at $1F12
dim ee0 as uinteger at $1F14
dim ee1 as uinteger at $1F16
dim ee2 as uinteger at $1F18
dim ee3 as uinteger at $1F1A
dim eex as uinteger at $1F1C
dim eey as uinteger at $1F1E
dim ee4 as uinteger at $1F20

sub enterpriseputchar(txp1 as uinteger,typ1 as uinteger,tch1 as uinteger,tad1 as uinteger):
  ldiruintegeradd($C000+(txp1*2)+(typ1*640),tad1+(tch1*16),8,80)
  end sub

for ee0=$FF08 to $FF0F
  seed=smsrnd(seed)
  poke ee0,seed
  next
seed=smsrnd(seed):out $80,seed band %00011111

for ee0=$FF08 to $FF0F
  seed=smsrnd(seed)
  poke ee0,seed
  next
seed=smsrnd(seed):out $80,seed band %00011111

  for ee0=0 to 24
    for ee1=0 to 39
      ee2=seed:seed=smsrnd(seed)
      ee2=seed:seed=smsrnd(seed)
      enterpriseputchar(ee1,ee0,96+(seed mod 5),@charmap01-512)
      seed=smsrnd(seed)
      next:next

  for ee0=0 to 15
    for ee1=0 to 15
      ee2=ee0*16+ee1
      enterpriseputchar(ee1+23,ee0+8,ee2,@charmap01-512)
      seed=smsrnd(seed)
      next:next

eee=0:eex=8:eey=8
do
  enterpriseputchar(1,1,48+(int(eee/10000) mod 10),@charmap01-512)
  enterpriseputchar(2,1,48+(int(eee/1000) mod 10),@charmap01-512)
  enterpriseputchar(3,1,48+(int(eee/100) mod 10),@charmap01-512)
  enterpriseputchar(4,1,48+(int(eee/10) mod 10),@charmap01-512)
  enterpriseputchar(5,1,48+(eee mod 10),@charmap01-512)

  out $B5,0
  ee1=in($B5) bxor $FF
  enterpriseputchar(3,3,48+(int(ee1/100) mod 10),@charmap01-512)
  enterpriseputchar(4,3,48+(int(ee1/10) mod 10),@charmap01-512)
  enterpriseputchar(5,3,48+(ee1 mod 10),@charmap01-512)

  out $B5,1
  ee1=in($B5) bxor $FF
  enterpriseputchar(3,4,48+(int(ee1/100) mod 10),@charmap01-512)
  enterpriseputchar(4,4,48+(int(ee1/10) mod 10),@charmap01-512)
  enterpriseputchar(5,4,48+(ee1 mod 10),@charmap01-512)

  eex=eex-((ee1 band 64)/64)+((ee1 band 8)/8)
  eey=eey+((ee1 band 32)/32)
  
  out $B5,2
  ee1=in($B5) bxor $FF
  enterpriseputchar(3,5,48+(int(ee1/100) mod 10),@charmap01-512)
  enterpriseputchar(4,5,48+(int(ee1/10) mod 10),@charmap01-512)
  enterpriseputchar(5,5,48+(ee1 mod 10),@charmap01-512)

  eey=eey-((ee1 band 64)/64)

  enterpriseputchar(eex,eey,(eee mod 106),@charmap01-512)

  eee=eee+1
  loop

do:loop

do

for ee0=$FF08 to $FF0F
  seed=smsrnd(seed)
  poke ee0,seed
  next
seed=smsrnd(seed):out $80,seed band %00011111

for ee0=0 to 24
  for ee1=0 to 39
    seed=smsrnd(seed):ee2=seed
    seed=smsrnd(seed)
    enterpriseputchar(ee1,ee0,seed mod 74,@charmap01-512)
    next:next

loop

do:loop

do





for ee0=0 to 24
  for ee1=0 to 39
    for ee2=0 to 7
      seed=smsrnd(seed):poke $C000+(ee2*40)+ee1+(ee0*320),seed
      seed=smsrnd(seed):poke $DF40+(ee2*40)+ee1+(ee0*320),seed
      smsdelay(100)
      next:next:next




for ee0=$C000 to $FEFF
  seed=smsrnd(seed)
  poke ee0,seed
  next

loop





do:loop

eee=0
do
  for ee0=0 to 49
    for ee1=0 to 79
      for ee2=0 to 3
        poke $C000+(ee2*80)+ee1+(ee0*320),eee
        next
      smsdelay(1000)
      eee=eee+1
      next:next
  for ee0=0 to 49
    for ee1=0 to 79
      seed=smsrnd(seed)
      for ee2=0 to 3
        poke $C000+(ee2*80)+ee1+(ee0*320),seed
        next
      smsdelay(1000)
      next:next
  loop



do
  for ee0=0 to 24
    for ee1=0 to 39
      seed=smsrnd(seed)
      for ee2=0 to 7
        for ee3=0 to 1
          poke $C000+(ee2*80)+ee3+(ee1*2)+(ee0*640),peek(@charmap01+ee2*2+ee3+((seed mod 8)*16))
          next:next
      seed=smsrnd(seed)
      if (seed mod 20)<2 then:
        for ee4=0 to 7:
          seed=smsrnd(seed):poke $FF08+ee4,seed
          next
        seed=smsrnd(seed):out $80,seed
        end if
      smsdelay(10000)
      next:next
  loop

do
  for ee0=0 to 24
    for ee1=0 to 39
      for ee2=0 to 7
        for ee3=0 to 1
          seed=smsrnd(seed)
          poke $C000+(ee2*80)+ee3+(ee1*2)+(ee0*640),seed
          next:next
      smsdelay(10000)
      next:next
  loop

do:loop



