1 votes

Tetris

Old good tetris - without show of next figure and with fixed speed. Use arrows to move/rotate figure

Download .dasm16 file |
:start
  jsr InitScreen
  jsr PressAnyKeyText
  jsr Input
  add [Seed],[Timer]

  jsr InitFieldScreen
  jsr InitScore
:l1
  jsr SetRandomFig
  set i,0x8006     ; starting position, I is global
  jsr TestFig
  ifn a,0
  set pc,_GameOver
:l0
  jsr ShowFig
:l3
  set z,[TWait]    ; time to fall, Z is global
:l2
  sub z,1
  ifn z,0
  set pc,l5
  jsr ClearFig
:_down
  add i,0x20  ; down
  jsr TestFig
  ife a,0     ; 0 => can place
  set pc,l0
  sub i,0x20
  jsr ShowFig
  jsr TestField
  set pc,l1
:l5
  jsr Input1
  ife a,0
  set pc,l2
  set push,a
  jsr ClearFig
  set a,pop
  set j,i
  set x,[Orient]
  ifn a,1  ;; KEY_LEFT
  set pc,l6
  sub i,2
  set pc,l8
:l6
  ifn a,2  ;; KEY_RIGHT
  set pc,l7
  add i,2
  set pc,l8
:l7
  ife a,4   ;; KEY_DOWN
  set pc,_down
  ifn a,3   ;; KEY_UP
  set pc,l2
  set a,x
  add a,4
  and a,15
  set [Orient],a
:l8
  jsr TestFig
  ife a,0
  set pc,l9
  set i,j
  set [Orient],x
:l9
  jsr ShowFig
  set pc,l2
:_GameOver
  jsr InitScreen
  jsr GameOverText
  set a,0
  sub a,1
  ifn a,0
  sub pc,3
  set pc,start

:Input1
  add [Timer],1
  set a,[0x9000]
  ifn a,0
  set [0x9000],0
  set pc,pop

:Input
  add [Timer],1
  set a,[0x9000]
  ife a,0
  set pc,Input
  set [0x9000],0
  set pc,pop

:InitScreen
  set b,0x8000
  set a,0xf058 ; 'X'
:l10
  set c,0x10
  jsr drawXX
  set c,0x0C
  jsr drawXX
  ifn b,0x8180
  set pc,l10
  set pc,pop
:drawXX
  set [b],a
  set [1+b],a
  add b,2
  set [b],0xf020
  add b,1
  sub c,1
  ifn c,0
  sub pc,6
  set pc,pop
:_pressanykey dat 0x8065,"P R E S S",0x80A7,"A N Y",0x80E7,"K E Y",0
:_gameovertext dat 0x8086,"G A M E",0x80C6,"O V E R",0
:_scoretext dat 0x8056,"SCORE:",0x8096,"0x0000",0

:GameOverText
  set b,_gameovertext
  set pc,WriteText
:PressAnyKeyText
  set b,_pressanykey
:WriteText
  set c,0x8000
:l20
  set a,[b]
  add b,1
  ife a,0
  set pc,pop
  ifg a,0x7fff
  set pc,l21
  bor a,0xf000
  set [c],a
  add c,1
  set pc,l20
:l21
  set c,a
  set pc,l20

:InitFieldScreen
  set b,0
:l30
  set[0x8002+b],0xf020
  add b,1
  ifb b,0x10
  add b,0x10
  ifn b,0x180
  set pc,l30
  set pc,pop

:InitScore
  set [Score],0
  set b,_scoretext
  set pc,WriteText

:SetRandomFig
  set a,[Seed]
  mul a,0x1235
  add a,1
  set [Seed],a
  mul a,7
  set a,o
  mul a,17
  add a,Figs
  set [Fig],a
  set [Orient],1
  set pc,pop

:FigAddr    ;; a=color, b=offset
  set b,[Fig]
  set a,[b]
  add b,[Orient]
  set pc,pop
:TestFig
  jsr FigAddr
  set c,4
:l40
  set a,[b]
  add b,1
  add a,i
  ifn [a],0xf020
  set pc,pop
  sub c,1
  ifn c,0
  set pc,l40
  set a,0
  set pc,pop

:ClearFig
  jsr FigAddr
  set c,4
:l50
  set a,[b]
  add b,1
  add a,i
  set [a],0xf020
  set [1+a],0xf020
  sub c,1
  ifn c,0
  set pc,l50
  set pc,pop

:ShowFig
  jsr FigAddr
  set push,x
  set c,4
:l60
  set x,[b]
  add b,1
  add x,i
  set [x],a
  set [1+x],a
  sub c,1
  ifn c,0
  set pc,l60
  set x,pop
  set pc,pop

:TestField
  set push,x
  set push,y

  set x,0x8162
  set y,0x8162
:l74
  set b,x
  set c,8
:l70
  ife [b],0xf020
  set pc,l71
  add b,2
  sub c,1
  ifn c,0
  set pc,l70
  add [Score],1
  sub x,32
  set pc,l72
:l71
  set c,16
:l73
  set [y],[x]
  add x,1
  add y,1
  sub c,1
  ifn c,0
  set pc,l73
  sub x,48
  sub y,48
:l72
  ifn x,0x7fe2
  set pc,l74
:l75
  ife y,0x7fe2
  set pc,l76
  set c,16
  set [y],0xf020
  add y,1
  sub c,1
  ifn c,0
  sub pc,6
  sub y,48
  set pc,l75
:l76
  set b,0x809B
  set c,[Score]
:l77
  set a,c
  and a,15
  ifg a,9
  add a,7
  add a,0x30
  bor a,0xf000
  set [b],a
  sub b,1
  shr c,4
  ifn c,0
  set pc,l77
  set y,pop
  set x,pop
  set pc,pop

:Score dat 0
:Seed dat 0x5678
:Timer dat 0x1234
:TWait dat 4000
:Orient dat 0
:Fig dat 0

:Figs
  dat 0x0920
  dat 0x20,0x22,0x24,0x26,0x02,0x22,0x42,0x62,0x40,0x42,0x44,0x46,0x04,0x24,0x44,0x64
  dat 0x0A20
  dat 0x00,0x02,0x04,0x20,0x00,0x20,0x40,0x42,0x40,0x42,0x44,0x24,0x2,0x4,0x24,0x44
  dat 0x0B20
  dat 0x00,0x02,0x04,0x24,0x00,0x20,0x40,0x02,0x40,0x42,0x44,0x20,0x42,0x4,0x24,0x44
  dat 0x0C20
  dat 0x00,0x02,0x04,0x22,0x00,0x20,0x40,0x22,0x40,0x42,0x44,0x22,0x22,0x4,0x24,0x44
  dat 0x0D20
  dat 0x22,0x02,0x04,0x20,0x00,0x20,0x22,0x42,0x40,0x42,0x22,0x24,0x2,0x22,0x24,0x44
  dat 0x0E20
  dat 0x00,0x02,0x22,0x24,0x22,0x20,0x40,0x02,0x22,0x42,0x44,0x20,0x42,0x4,0x24,0x22
  dat 0x0F20
  dat 0x22,0x24,0x42,0x44,0x22,0x24,0x42,0x44,0x22,0x24,0x42,0x44,0x22,0x24,0x42,0x44



Comments

Sign in to comment and vote

No comments yet