asm
  ld sp,$5FFF
  end asm

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

dim eee as uinteger at $5010
dim seed as uinteger at $5012
dim ee0 as uinteger at $5014
dim ee1 as uinteger at $5016
dim ee2 as uinteger at $5018
dim ee3 as uinteger at $501A
dim eex as uinteger at $501C
dim eey as uinteger at $501E
seed=0

sub putchar(tx1 as uinteger, ty1 as uinteger, tch1 as uinteger, tat1 as uinteger)
  dim ttv0 as uinteger at $5000
  if ty1>=3 and ty1<=34 then
    poke ($C440+(tx1*32)+ty1-3)bxor %1111100000,tch1
    poke ($CC40+(tx1*32)+ty1-3)bxor %1111100000,tat1
  else
    ttv0=((((ty1 band 32)shr 5)+ty1+1+(int(ty1/32)))mod 3)+(13*(1-((ty1 band 32)shr 5)))+((29-tx1)*32)
    poke $D000+ttv0,tch1
    poke $D010+ttv0,tat1
    end if
  end sub


for ee1=0 to 37
  for ee0=0 to 27
    ee2=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    putchar(ee0,ee1,seed band 3,ee2)
    next:next

for ee1=0 to 15
  for ee0=0 to 15
    putchar(ee0+11,ee1+21,ee1*16+ee0,0)
    next:next

eee=0:eex=8:eey=8
do

putchar(1,1,48+(int(eee/10000) mod 10),0)
putchar(2,1,48+(int(eee/1000) mod 10),0)
putchar(3,1,48+(int(eee/100) mod 10),0)
putchar(4,1,48+(int(eee/10) mod 10),0)
putchar(5,1,48+(eee mod 10),0)

ee0=peek($6000) bxor $FF
putchar(3,5,48+(int(ee0/100) mod 10),0)
putchar(4,5,48+(int(ee0/10) mod 10),0)
putchar(5,5,48+(ee0 mod 10),0)

ee1=peek($6001) bxor $FF
putchar(3,6,48+(int(ee1/100) mod 10),0)
putchar(4,6,48+(int(ee1/10) mod 10),0)
putchar(5,6,48+(ee1 mod 10),0)

eex=eex+((ee0 band 2)/2)-((ee0 band 1)/1)
eey=eey+((ee0 band 4)/4)-((ee0 band 8)/8)

putchar(eex,eey,32+(eee mod 64),0)

eee=eee+1
loop



do:loop
'testar: q= ((  (int(y/32)mod 2)    +y+1                 )   mod 3)    +(13*(1-    (int(y/32)mod 2)    ))      - 'wrong, doesnt work fine on the lower part
for ee1=0 to 2
  for ee0=0 to 27
    ee2=    ((  (int(ee1/32)mod 2)  +ee1+1+(int(ee1/32)) )   mod 3)    +(13*(1-    (int(ee1/32)mod 2)  ))
    seed=smsrnd(seed)
    poke $D000+ee2+((29-ee0)*32),seed
    seed=smsrnd(seed)
    poke $D010+ee2+((29-ee0)*32),seed
    smsdelay(500)
    next:next

for ee1=3 to 34
  for ee0=0 to 27
    seed=smsrnd(seed)
    poke ($C440+(ee0*32)+ee1-3)bxor %1111100000,seed
    seed=smsrnd(seed)
    poke ($CC40+(ee0*32)+ee1-3)bxor %1111100000,seed
    smsdelay(500)
    next:next

for ee1=35 to 37
  for ee0=0 to 27
    ee2=    ((  (int(ee1/32)mod 2)  +ee1+1+(int(ee1/32)) )   mod 3)    +(13*(1-    (int(ee1/32)mod 2)  ))
    seed=smsrnd(seed)
    poke $D000+ee2+((29-ee0)*32),seed
    seed=smsrnd(seed)
    poke $D010+ee2+((29-ee0)*32),seed
    smsdelay(500)
    next:next

do
loop



do

for eee=$D00E to $D3DF step 16 'videoram2
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(2000)
  next

for eee=$D00F to $D3DF step 16 'videoram2
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(2000)
  next

for eee=$D00D to $D3DF step 16 'videoram2
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(2000)
  next



for eee=$0000 to $7FF 'videoram, colorram
  seed=smsrnd(seed)
  poke $C000+eee,seed
  poke $C800+eee,seed
  smsdelay(1000)
  next




for eee=$D002 to $D3DF step 16 'videoram2
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(2000)
  next

for eee=$D000 to $D3DF step 16 'videoram2
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(2000)
  next

for eee=$D001 to $D3DF step 16 'videoram2
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(2000)
  next

loop






for eee=$C3E0 to $D3FF 'spriteram
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(1000)
  next



do:loop

'-------------------------------

'sub pingpongputsprite(tlayer as ubyte,tx as ubyte,ty as ubyte,tid as ubyte,tclut as ubyte):
'  poke $9006+((tlayer band 15)*4),tx  '- x sprite 0
'  poke $9004+((tlayer band 15)*4),ty bxor 255  '- y sprite 0
'  poke $9005+((tlayer band 15)*4),tid          '- shape sprite 0
'  poke $9003+((tlayer band 15)*4),tclut        '- clut? sprite 0
'  end sub
'
'function test1(t1 as uinteger,t2 as uinteger,t3 as uinteger,t4 as uinteger)  as uinteger
'  end function
'
'sub zpoke(t1 as uinteger,t2 as ubyte)
'  poke t1,t2
'  end sub
'


'static ADDRESS_MAP_START( gotya_map, AS_PROGRAM, 8, gotya_state )
'AM_RANGE(0x0000, 0x3fff) AM_ROM
'AM_RANGE(0x5000, 0x5fff) AM_RAM
'AM_RANGE(0x6000, 0x6000) AM_READ_PORT("P1")
'AM_RANGE(0x6001, 0x6001) AM_READ_PORT("P2")
'AM_RANGE(0x6002, 0x6002) AM_READ_PORT("DSW")
'AM_RANGE(0x6004, 0x6004) AM_WRITE(gotya_video_control_w)
'AM_RANGE(0x6005, 0x6005) AM_WRITE(gotya_soundlatch_w)
'AM_RANGE(0x6006, 0x6006) AM_WRITEONLY AM_SHARE("scroll")
'AM_RANGE(0x6007, 0x6007) AM_WRITE(watchdog_reset_w)
'AM_RANGE(0xc000, 0xc7ff) AM_RAM_WRITE(gotya_videoram_w) AM_SHARE("videoram")
'AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(gotya_colorram_w) AM_SHARE("colorram")
'AM_RANGE(0xd000, 0xd3df) AM_RAM AM_SHARE("videoram2")
'AM_RANGE(0xd3e0, 0xd3ff) AM_RAM AM_SHARE("spriteram")
'ADDRESS_MAP_END


'pingpongputsprite(0,21,10,4,3)
'pingpongputsprite(1,21,30,4,3)
'pingpongputsprite(2,21,50,4,3)
'pingpongputsprite(3,21,70,4,3)
'pingpongputsprite(4,21,90,4,3)
'pingpongputsprite(5,21,110,4,3)
'pingpongputsprite(6,21,130,4,3)
'pingpongputsprite(7,21,150,4,3)
'
'seed=0
'
'for ee2=64 to 1023-64
'  for ee3=1 to 100
'    poke $8400+ee2,$01
'    next:next
'
'ee4=0
'for ee2=3 to 3+15
'  for ee3=15 to 15+15
'    poke $8400+ee3+(ee2*32),ee4
'    ee4=ee4+1
'    next:next
'
'ee4=0
'for ee2=20 to 20+7
'  for ee3=15 to 15+15
'    poke $8400+ee3+(ee2*32),ee4 band 3
'    poke $8000+ee3+(ee2*32),int(ee4/4)
'    ee4=ee4+1
'    next:next
'
'
'
'
'for ee2=4 to 7
'  for ee3=2 to 5
'    poke $8400+ee3+(ee2*32),code("X")
'    next
'    next
'
'test1(377,2445,63888,2342)
'
'eee=$4207
'i=code("Q")
'poke eee,i
'eee=eee+1
'i=code("T")
'poke eee,i
'
'seed=0
'for eee=$4400 to $47FF
'  seed=smsrnd(seed)
'  poke eee,seed
'  next
'
'ex0=80:ey0=176
'
'eee=0
'ecsp=0:ecsq=0
'
'
'do
'poke $A600,255 '- watchdog? - it seems to work! thanks, Jim Bagley!!!!
'
'ej0=peek($A800) bxor $ff
'ej1=peek($A880) bxor $ff
'
'poke ($8400+(10*32)+6) bxor %0000001111100000,ej0
'poke ($8400+(10*32)+7) bxor %0000001111100000,ej1
'
'poke ($8400+(12*32)+8) bxor %0000001111100000,48+(ex0 mod 10)
'poke ($8400+(12*32)+7) bxor %0000001111100000,48+((int(ex0/10)) mod 10)
'poke ($8400+(12*32)+6) bxor %0000001111100000,48+((int(ex0/100)) mod 10)
'
'poke ($8400+(13*32)+8) bxor %0000001111100000,48+(ey0 mod 10)
'poke ($8400+(13*32)+7) bxor %0000001111100000,48+((int(ey0/10)) mod 10)
'poke ($8400+(13*32)+6) bxor %0000001111100000,48+((int(ey0/100)) mod 10)
'
'poke ($8400+(14*32)+8) bxor %0000001111100000,48+(eee mod 10)
'poke ($8400+(14*32)+7) bxor %0000001111100000,48+((int(eee/10)) mod 10)
'poke ($8400+(14*32)+6) bxor %0000001111100000,48+((int(eee/100)) mod 10)
'poke ($8400+(14*32)+5) bxor %0000001111100000,48+((int(eee/1000)) mod 10)
'poke ($8400+(14*32)+4) bxor %0000001111100000,48+((int(eee/10000)) mod 10)
'
'poke ($8400+(15*32)+8) bxor %0000001111100000,48+(ej0 mod 10)
'poke ($8400+(15*32)+7) bxor %0000001111100000,48+((int(ej0/10)) mod 10)
'poke ($8400+(15*32)+6) bxor %0000001111100000,48+((int(ej0/100)) mod 10)
'
'poke ($8400+(16*32)+8) bxor %0000001111100000,48+(ej1 mod 10)
'poke ($8400+(16*32)+7) bxor %0000001111100000,48+((int(ej1/10)) mod 10)
'poke ($8400+(16*32)+6) bxor %0000001111100000,48+((int(ej1/100)) mod 10)
'
'poke ($8400+(17*32)+8) bxor %0000001111100000,48+(ecsp mod 10)
'
'if (ej1 band 64)<>0 then: ex0=ex0+1:end if
'if (ej1 band 32)<>0 then: ex0=ex0-1:end if
'if (ej1 band 4)<>0 then: ey0=ey0+1:end if
'if (ej1 band 2)<>0 then: ey0=ey0-1:end if
'
'if (ej1 band 15)<>0 then: ecsq=ecsq+1:end if
'ecsp=(int(ecsq/4))mod 8
'
'ee3=int(eee/4)
'
'pingpongputsprite( 0,ex0   ,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 1,ex0+16,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 2,ex0+32,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 3,ex0+48,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 4,ex0   ,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 5,ex0+16,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 6,ex0+32,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 7,ex0+48,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 8,ex0   ,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 9,ex0+16,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(10,ex0+32,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(11,ex0+48,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(12,ex0   ,ey0+48,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(13,ex0+16,ey0+48,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(14,ex0+32,ey0+48,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(15,ex0+48,ey0+48,4,3)  '- layer,x,y,id,clut
'
'
'eee=eee+1
'loop
'
''-------------------------------------------------------------------------------
'
'text01:
'asm
'  defb "HELLO WORLD!!!!!"
'  end asm
'
''-------------------------------------------------------------------------------
'
'
