Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
饶先宏
hdl4se
提交
d8fe6235
H
hdl4se
项目概览
饶先宏
/
hdl4se
通知
12
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hdl4se
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d8fe6235
编写于
7月 16, 2021
作者:
饶先宏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
202107160641
上级
ec34ab25
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
434 addition
and
1267 deletion
+434
-1267
examples/terris/include/terrisengine1.h
examples/terris/include/terrisengine1.h
+1
-5
examples/terris/src/terris_ctrl.c
examples/terris/src/terris_ctrl.c
+429
-63
examples/terris/src/terris_main_module.c
examples/terris/src/terris_main_module.c
+2
-1198
examples/terris/verilog/terris_ctrl.v
examples/terris/verilog/terris_ctrl.v
+1
-1
examples/terris/verilog/terris_main_asm.v
examples/terris/verilog/terris_main_asm.v
+1
-0
未找到文件。
examples/terris/include/terrisengine1.h
浏览文件 @
d8fe6235
...
...
@@ -26,11 +26,7 @@ typedef struct tagTerrisBlock
}
TerrisBlock
;
#define MAXSPPED 2000
static
int
gameScore
=
0
;
static
int
currentspeed
=
MAXSPPED
;
static
int
gameLevel
=
0
;
static
int
currenttick
=
0
;
static
TerrisBlock
currentblock
,
nextblock
;
static
int
terrisGenNewBlock
(
TerrisBlock
*
pBlock
);
...
...
examples/terris/src/terris_ctrl.c
浏览文件 @
d8fe6235
...
...
@@ -33,6 +33,7 @@
* teris_ctrl.c
修改记录:
202106201016: rxh, initial version
202107160614: rxh, macro version
*/
#include "stdlib.h"
#include "stdio.h"
...
...
@@ -42,7 +43,6 @@
#include "bignumber.h"
#include "hdl4secell.h"
#include "terris.h"
#include "terrisengine1.h"
/*
0: input wClk,
...
...
@@ -53,14 +53,373 @@
5: output[31:0] bScore,
6: output[31:0] bSpeed,
7: output[31:0] bLevel,
8: output [63:0] bNext
B
lock,
8: output [63:0] bNext
b
lock,
9: output [63:0] bCurBlock;
10: output [15:0] bCurBlockPos;
11: input [31:0] bResult
11: input [63:0] bNewNext
B
lock
11: input [63:0] bNewNext
b
lock
*/
enum
TERRIS_KEY
{
TK_LEFT
,
TK_DOWN
,
TK_RIGHT
,
TK_TURNLEFT
,
TK_TURNRIGHT
};
#define PANELWIDTH XCOUNT
#define PANELHEIGHT YCOUNT
#define PANELGAP 0
#define BLOCKSIZE 4
typedef
struct
tagTerrisBlock
{
int
posx
,
posy
;
unsigned
long
subblock
[
BLOCKSIZE
][
BLOCKSIZE
];
}
TerrisBlock
;
#define MAXSPPED 2000
static
void
terrisBlockRotate
(
TerrisBlock
*
pBlock
,
int
dir
)
{
/*dir 0:顺时针,否则,逆时针*/
int
i
,
j
;
unsigned
long
paneltemp
[
BLOCKSIZE
][
BLOCKSIZE
];
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
if
(
dir
==
0
)
paneltemp
[
i
][
j
]
=
pBlock
->
subblock
[
BLOCKSIZE
-
1
-
j
][
i
];
else
paneltemp
[
i
][
j
]
=
pBlock
->
subblock
[
j
][
BLOCKSIZE
-
1
-
i
];
}
memcpy
(
pBlock
->
subblock
,
paneltemp
,
sizeof
(
paneltemp
));
}
#if 1
#include "hdl4se_macros.h"
#define M_ID(id) terrisctrl1##id
#define terrisctrl1_MODULE_VERSION_STRING "0.4.0-20210716.0614 Terris Controller V1 module macro version"
#define terrisctrl1_MODULE_CLSID CLSID_TERRISCTRL1
HDL4SE_IDLIST
VID
(
wClk
),
VID
(
nwReset
),
VID
(
bKeyData
),
VID
(
wStateComplete
),
VID
(
bState
),
VID
(
bScore
),
VID
(
bSpeed
),
VID
(
bLevel
),
VID
(
bNextBlock
),
VID
(
bCurBlock
),
VID
(
bCurBlockPos
),
VID
(
bResult
),
VID
(
bNewNextBlock
)
END_HDL4SE_IDLIST
MODULE_DECLARE
(
terrisctrl1
)
int
testx
,
testy
,
testparam
,
testid
;
int
startline
;
int
checklinecount
;
int
gameScore
;
int
currentspeed
;
int
gameLevel
;
int
currenttick
;
int
key
;
int
lastkey
;
int
state
;
int
state_reg
;
TerrisBlock
currentblock
,
nextblock
;
END_MODULE_DECLARE
(
terrisctrl1
)
DEFINE_FUNC
(
terrisctrl1Setup
)
pobj
->
state_reg
=
pobj
->
state
;
pobj
->
lastkey
=
pobj
->
key
;
END_DEFINE_FUNC
static
void
terrisctrl1_hdl4se_unit_PressKeyPro
(
MODULE_DATA_TYPE
*
pobj
,
int
result
)
{
switch
(
pobj
->
testparam
)
//blockCanSetToContext.param)
{
case
TK_LEFT
:
/*left*/
if
(
result
)
pobj
->
currentblock
.
posx
--
;
break
;
case
TK_DOWN
:
/*down*/
break
;
case
TK_RIGHT
:
/*right*/
if
(
result
)
pobj
->
currentblock
.
posx
++
;
break
;
case
TK_TURNLEFT
:
/*逆时针1*/
if
(
result
==
0
)
terrisBlockRotate
(
&
pobj
->
currentblock
,
0
);
break
;
case
TK_TURNRIGHT
:
/*顺时针0*/
if
(
result
==
0
)
terrisBlockRotate
(
&
pobj
->
currentblock
,
1
);
break
;
}
pobj
->
state
=
ST_FLUSHTODISP
;
}
static
void
terrisctrl1_hdl4se_unit_AfterCheckLine
(
MODULE_DATA_TYPE
*
pobj
,
int
result
)
{
if
(
result
==
0
)
{
pobj
->
state
=
ST_INIT
;
}
else
{
pobj
->
state
=
ST_GENBLOCK
;
}
}
static
void
terrisctrl1_hdl4se_unit_MoveDownPro
(
MODULE_DATA_TYPE
*
pobj
,
int
result
)
{
if
(
result
)
{
pobj
->
currentblock
.
posy
++
;
pobj
->
state
=
ST_FLUSHTODISP
;
}
else
{
pobj
->
state
=
ST_BLOCKWRITE
;
}
return
;
}
static
int
terrisctrl1_hdl4se_unit_MoveDown
(
MODULE_DATA_TYPE
*
pobj
)
{
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
+
1
;
pobj
->
testparam
=
0
;
pobj
->
testid
=
0
;
pobj
->
state
=
ST_CHECKBLOCKCANSETTO
;
return
0
;
}
static
int
terrisctrl1_hdl4se_unit_Tick
(
MODULE_DATA_TYPE
*
pobj
)
{
pobj
->
currenttick
++
;
if
((
pobj
->
currenttick
%
pobj
->
currentspeed
)
==
0
)
{
terrisctrl1_hdl4se_unit_MoveDown
(
pobj
);
return
1
;
}
return
0
;
}
static
void
terrisctrl1_hdl4se_unit_PressKeyStart
(
MODULE_DATA_TYPE
*
pobj
,
int
key
)
{
pobj
->
currenttick
=
0
;
if
(
pobj
->
gameScore
==
0
&&
(
key
==
TK_LEFT
||
key
==
TK_RIGHT
||
key
==
TK_TURNLEFT
||
key
==
TK_TURNRIGHT
))
{
pobj
->
state
=
ST_INIT
;
}
else
{
pobj
->
state
=
ST_CHECKBLOCKCANSETTO
;
switch
(
key
)
{
case
TK_LEFT
:
/*left*/
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
-
1
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
case
TK_DOWN
:
/*down*/
pobj
->
gameScore
+=
2
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
+
1
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
0
;
terrisctrl1_hdl4se_unit_MoveDown
(
pobj
);
break
;
case
TK_RIGHT
:
/*right*/
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
+
1
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
case
TK_TURNLEFT
:
/*逆时针1*/
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
terrisBlockRotate
(
&
pobj
->
currentblock
,
1
);
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
case
TK_TURNRIGHT
:
/*顺时针0*/
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
terrisBlockRotate
(
&
pobj
->
currentblock
,
0
);
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
}
}
}
DEFINE_FUNC
(
terrisctrl1ClkTick
)
{
unsigned
int
statecomplete
;
statecomplete
=
VREAD_U32
(
wStateComplete
);
if
(
pobj
->
state
==
ST_INIT
)
{
pobj
->
currentspeed
=
MAXSPPED
;
pobj
->
currenttick
=
0
;
pobj
->
gameScore
=
200
;
pobj
->
gameLevel
=
0
;
if
(
statecomplete
!=
0
)
pobj
->
state
=
ST_GENBLOCK
;
}
else
if
(
pobj
->
state
==
ST_GENBLOCK
)
{
if
(
statecomplete
!=
0
)
{
unsigned
long
long
data
;
int
i
,
j
;
data
=
VREAD_U64
(
bNewNextBlock
);
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
{
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
pobj
->
nextblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
=
data
&
0xf
;
data
>>=
4
;
}
}
pobj
->
state
=
ST_FLUSHTODISP
;
}
}
else
if
(
pobj
->
state
==
ST_FLUSHTODISP
)
{
int
curblockinvalid
=
1
;
int
i
,
j
;
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
{
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
if
(
pobj
->
currentblock
.
subblock
[
i
][
j
]
!=
0
)
curblockinvalid
=
0
;
}
}
if
(
curblockinvalid
)
{
memcpy
(
pobj
->
currentblock
.
subblock
,
pobj
->
nextblock
.
subblock
,
sizeof
(
pobj
->
currentblock
.
subblock
));
pobj
->
currentblock
.
posx
=
PANELWIDTH
/
2
;
pobj
->
currentblock
.
posy
=
0
;
pobj
->
state
=
ST_GENBLOCK
;
}
else
{
if
(
statecomplete
!=
0
)
pobj
->
state
=
ST_CHECKKEY
;
}
}
else
if
(
pobj
->
state
==
ST_CHECKKEY
)
{
pobj
->
key
=
VREAD_U32
(
bKeyData
);
if
(
pobj
->
key
!=
pobj
->
lastkey
)
{
pobj
->
lastkey
=
pobj
->
key
;
if
(
pobj
->
key
&
1
)
terrisctrl1_hdl4se_unit_PressKeyStart
(
pobj
,
TK_RIGHT
);
if
(
pobj
->
key
&
2
)
terrisctrl1_hdl4se_unit_PressKeyStart
(
pobj
,
TK_LEFT
);
if
(
pobj
->
key
&
4
)
terrisctrl1_hdl4se_unit_PressKeyStart
(
pobj
,
TK_DOWN
);
if
(
pobj
->
key
&
8
)
terrisctrl1_hdl4se_unit_PressKeyStart
(
pobj
,
TK_TURNLEFT
);
}
else
if
(
pobj
->
key
==
0
)
{
terrisctrl1_hdl4se_unit_Tick
(
pobj
);
}
}
else
if
(
pobj
->
state
==
ST_CHECKBLOCKCANSETTO
)
{
if
(
statecomplete
)
{
int
result
=
VREAD_U32
(
bResult
);
if
(
pobj
->
testid
==
0
)
{
terrisctrl1_hdl4se_unit_MoveDownPro
(
pobj
,
result
);
}
else
if
(
pobj
->
testid
==
1
)
{
terrisctrl1_hdl4se_unit_PressKeyPro
(
pobj
,
result
);
}
else
{
terrisctrl1_hdl4se_unit_AfterCheckLine
(
pobj
,
result
);
}
}
}
else
if
(
pobj
->
state
==
ST_BLOCKWRITE
)
{
if
(
statecomplete
!=
0
)
{
pobj
->
state
=
ST_CHECKLINE
;
pobj
->
checklinecount
=
0
;
}
}
else
if
(
pobj
->
state
==
ST_CHECKLINE
)
{
if
(
statecomplete
!=
0
)
{
pobj
->
startline
=
VREAD_U32
(
bResult
);
if
(
pobj
->
startline
<
YCOUNT
)
{
pobj
->
state
=
ST_COPYLINES
;
pobj
->
checklinecount
++
;
}
else
{
pobj
->
gameLevel
+=
pobj
->
checklinecount
;
if
(
pobj
->
checklinecount
==
1
)
pobj
->
gameScore
+=
10
;
if
(
pobj
->
checklinecount
==
2
)
pobj
->
gameScore
+=
40
;
if
(
pobj
->
checklinecount
==
3
)
pobj
->
gameScore
+=
160
;
if
(
pobj
->
checklinecount
==
4
)
pobj
->
gameScore
+=
640
;
pobj
->
currentspeed
=
MAXSPPED
-
pobj
->
gameScore
/
3
;
if
(
pobj
->
currentspeed
<
1
)
pobj
->
currentspeed
=
1
;
memcpy
(
&
pobj
->
currentblock
,
&
pobj
->
nextblock
,
sizeof
(
pobj
->
currentblock
));
pobj
->
currentblock
.
posx
=
PANELWIDTH
/
2
;
pobj
->
currentblock
.
posy
=
0
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
pobj
->
testid
=
2
;
pobj
->
state
=
ST_CHECKBLOCKCANSETTO
;
}
}
}
else
if
(
pobj
->
state
==
ST_COPYLINES
)
{
if
(
statecomplete
!=
0
)
{
pobj
->
state
=
ST_CHECKLINE
;
}
}
else
{
pobj
->
state
=
ST_INIT
;
}
}
END_DEFINE_FUNC
MODULE_INIT
(
terrisctrl1
)
PORT_IN
(
wClk
,
1
);
PORT_IN
(
nwReset
,
1
);
PORT_IN
(
bKeyData
,
32
);
PORT_IN
(
wStateComplete
,
1
);
PORT_OUT
(
bState
,
4
);
PORT_OUT
(
bScore
,
32
);
PORT_OUT
(
bSpeed
,
32
);
PORT_OUT
(
bLevel
,
32
);
PORT_OUT
(
bNextBlock
,
64
);
PORT_OUT
(
bCurBlock
,
64
);
PORT_OUT
(
bCurBlockPos
,
16
);
PORT_IN
(
bResult
,
32
);
PORT_IN
(
bNewNextBlock
,
64
);
pobj
->
state
=
ST_INIT
;
memset
(
&
pobj
->
currentblock
,
0
,
sizeof
(
TerrisBlock
));
memset
(
&
pobj
->
nextblock
,
0
,
sizeof
(
TerrisBlock
));
SETUP_FUNC
(
terrisctrl1Setup
);
CLKTICK_FUNC
(
terrisctrl1ClkTick
);
END_MODULE_INIT
(
terrisctrl1
)
MODULE_DEINIT
(
terrisctrl1
)
END_MODULE_DEINIT
(
terrisctrl1
)
#else
#define INPUTPORTCOUNT 5
struct
_sTerrisCtrl1
;
...
...
@@ -82,6 +441,12 @@ struct _sTerrisCtrl1 {
int
startline
;
int
checklinecount
;
int
gameScore
;
int
currentspeed
;
int
gameLevel
;
int
currenttick
;
TerrisBlock
currentblock
,
nextblock
;
int
key
;
int
lastkey
;
...
...
@@ -113,6 +478,7 @@ static int terrisctrl1Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
pobj
=
(
sTerrisCtrl1
*
)
malloc
(
sizeof
(
sTerrisCtrl1
));
if
(
pobj
==
NULL
)
return
-
1
;
memset
(
pobj
,
0
,
sizeof
(
sTerrisCtrl1
));
*
pObject
=
0
;
HDL4SEUNIT_VARINIT
(
pobj
,
CLSID_TERRISCTRL1
);
INTERFACE_INIT
(
IHDL4SEUnit
,
pobj
,
terrisctrl1
,
hdl4se_unit
);
...
...
@@ -134,7 +500,7 @@ static int terrisctrl1Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
pobj
->
name
=
strdup
(
pParams
[
i
].
pvalue
);
}
else
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_PARENT
)
{
pobj
->
parent
=
(
IHDL4SEModule
*
*
)
pParams
[
i
].
pvalue
;
pobj
->
parent
=
(
IHDL4SEModule
Var
*
)
pParams
[
i
].
pvalue
;
}
}
pobj
->
state
=
ST_INIT
;
...
...
@@ -192,27 +558,26 @@ static int terrisctrl1_hdl4se_unit_ConnectInput(HOBJECT object, int index, HOBJE
CONNECTPORT
(
2
,
1
);
/* bKeyData */
CONNECTPORT
(
3
,
2
);
/* wStateComplete */
CONNECTPORT
(
11
,
3
);
/* bResult */
CONNECTPORT
(
12
,
4
);
/* bNew
NextB
lock */
CONNECTPORT
(
12
,
4
);
/* bNew
pobj->nextb
lock */
return
0
;
}
static
int
terrisctrl1_hdl4se_unit_GetValue
(
HOBJECT
object
,
int
index
,
int
width
,
IBigNumber
**
value
)
{
int
i
;
sTerrisCtrl1
*
pobj
;
pobj
=
(
sTerrisCtrl1
*
)
objectThis
(
object
);
if
(
index
==
4
)
{
objectCall1
(
value
,
AssignUint32
,
pobj
->
state_reg
);
}
else
if
(
index
==
5
)
{
objectCall1
(
value
,
AssignUint32
,
gameScore
);
objectCall1
(
value
,
AssignUint32
,
pobj
->
gameScore
);
}
else
if
(
index
==
6
)
{
objectCall1
(
value
,
AssignUint32
,
MAXSPPED
-
currentspeed
);
objectCall1
(
value
,
AssignUint32
,
MAXSPPED
-
pobj
->
currentspeed
);
}
else
if
(
index
==
7
)
{
objectCall1
(
value
,
AssignUint32
,
gameLevel
);
objectCall1
(
value
,
AssignUint32
,
pobj
->
gameLevel
);
}
else
if
(
index
==
8
)
{
unsigned
long
long
data
;
...
...
@@ -221,7 +586,7 @@ static int terrisctrl1_hdl4se_unit_GetValue(HOBJECT object, int index, int width
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
{
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
data
<<=
4
;
data
|=
nextblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
&
0xf
;
data
|=
pobj
->
nextblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
&
0xf
;
}
}
objectCall1
(
value
,
AssignUint64
,
data
);
...
...
@@ -233,7 +598,7 @@ static int terrisctrl1_hdl4se_unit_GetValue(HOBJECT object, int index, int width
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
{
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
data
<<=
4
;
data
|=
currentblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
&
0xf
;
data
|=
pobj
->
currentblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
&
0xf
;
}
}
objectCall1
(
value
,
AssignUint64
,
data
);
...
...
@@ -246,7 +611,7 @@ static int terrisctrl1_hdl4se_unit_GetValue(HOBJECT object, int index, int width
objectCall1
(
value
,
AssignUint32
,
pobj
->
startline
);
}
else
{
objectCall1
(
value
,
AssignUint32
,
((
currentblock
.
posx
+
1
)
&
0xff
)
|
(((
YCOUNT
+
1
-
currentblock
.
posy
)
&
0xff
)
<<
8
));
objectCall1
(
value
,
AssignUint32
,
((
pobj
->
currentblock
.
posx
+
1
)
&
0xff
)
|
(((
YCOUNT
+
1
-
pobj
->
currentblock
.
posy
)
&
0xff
)
<<
8
));
}
}
return
0
;
...
...
@@ -258,21 +623,21 @@ static void terrisctrl1_hdl4se_unit_PressKeyPro(sTerrisCtrl1* pobj, int result)
{
case
TK_LEFT
:
/*left*/
if
(
result
)
currentblock
.
posx
--
;
pobj
->
currentblock
.
posx
--
;
break
;
case
TK_DOWN
:
/*down*/
break
;
case
TK_RIGHT
:
/*right*/
if
(
result
)
currentblock
.
posx
++
;
pobj
->
currentblock
.
posx
++
;
break
;
case
TK_TURNLEFT
:
/*逆时针1*/
if
(
result
==
0
)
terrisBlockRotate
(
&
currentblock
,
0
);
terrisBlockRotate
(
&
pobj
->
currentblock
,
0
);
break
;
case
TK_TURNRIGHT
:
/*顺时针0*/
if
(
result
==
0
)
terrisBlockRotate
(
&
currentblock
,
1
);
terrisBlockRotate
(
&
pobj
->
currentblock
,
1
);
break
;
}
pobj
->
state
=
ST_FLUSHTODISP
;
...
...
@@ -292,7 +657,7 @@ static void terrisctrl1_hdl4se_unit_MoveDownPro(sTerrisCtrl1* pobj, int result)
{
if
(
result
)
{
currentblock
.
posy
++
;
pobj
->
currentblock
.
posy
++
;
pobj
->
state
=
ST_FLUSHTODISP
;
}
else
{
...
...
@@ -303,8 +668,8 @@ static void terrisctrl1_hdl4se_unit_MoveDownPro(sTerrisCtrl1* pobj, int result)
static
int
terrisctrl1_hdl4se_unit_MoveDown
(
sTerrisCtrl1
*
pobj
)
{
pobj
->
testx
=
currentblock
.
posx
;
pobj
->
testy
=
currentblock
.
posy
+
1
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
+
1
;
pobj
->
testparam
=
0
;
pobj
->
testid
=
0
;
pobj
->
state
=
ST_CHECKBLOCKCANSETTO
;
...
...
@@ -313,8 +678,8 @@ static int terrisctrl1_hdl4se_unit_MoveDown(sTerrisCtrl1* pobj)
static
int
terrisctrl1_hdl4se_unit_Tick
(
sTerrisCtrl1
*
pobj
)
{
currenttick
++
;
if
((
currenttick
%
currentspeed
)
==
0
)
pobj
->
currenttick
++
;
if
((
pobj
->
currenttick
%
pobj
->
currentspeed
)
==
0
)
{
terrisctrl1_hdl4se_unit_MoveDown
(
pobj
);
return
1
;
...
...
@@ -325,8 +690,8 @@ static int terrisctrl1_hdl4se_unit_Tick(sTerrisCtrl1* pobj)
static
void
terrisctrl1_hdl4se_unit_PressKeyStart
(
sTerrisCtrl1
*
pobj
,
int
key
)
{
currenttick
=
0
;
if
(
gameScore
==
0
&&
(
key
==
TK_LEFT
||
key
==
TK_RIGHT
||
key
==
TK_TURNLEFT
||
key
==
TK_TURNRIGHT
))
{
pobj
->
currenttick
=
0
;
if
(
pobj
->
gameScore
==
0
&&
(
key
==
TK_LEFT
||
key
==
TK_RIGHT
||
key
==
TK_TURNLEFT
||
key
==
TK_TURNRIGHT
))
{
pobj
->
state
=
ST_INIT
;
}
else
{
...
...
@@ -334,42 +699,42 @@ static void terrisctrl1_hdl4se_unit_PressKeyStart(sTerrisCtrl1* pobj, int key)
switch
(
key
)
{
case
TK_LEFT
:
/*left*/
gameScore
--
;
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
pobj
->
testx
=
currentblock
.
posx
-
1
;
pobj
->
testy
=
currentblock
.
posy
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
-
1
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
case
TK_DOWN
:
/*down*/
gameScore
+=
2
;
pobj
->
testx
=
currentblock
.
posx
;
pobj
->
testy
=
currentblock
.
posy
+
1
;
pobj
->
gameScore
+=
2
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
+
1
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
0
;
terrisctrl1_hdl4se_unit_MoveDown
(
pobj
);
break
;
case
TK_RIGHT
:
/*right*/
gameScore
--
;
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
pobj
->
testx
=
currentblock
.
posx
+
1
;
pobj
->
testy
=
currentblock
.
posy
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
+
1
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
case
TK_TURNLEFT
:
/*逆时针1*/
gameScore
--
;
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
terrisBlockRotate
(
&
currentblock
,
1
);
pobj
->
testx
=
currentblock
.
posx
;
pobj
->
testy
=
currentblock
.
posy
;
terrisBlockRotate
(
&
pobj
->
currentblock
,
1
);
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
case
TK_TURNRIGHT
:
/*顺时针0*/
gameScore
--
;
pobj
->
gameScore
--
;
pobj
->
testparam
=
key
;
pobj
->
testid
=
1
;
terrisBlockRotate
(
&
currentblock
,
0
);
pobj
->
testx
=
currentblock
.
posx
;
pobj
->
testy
=
currentblock
.
posy
;
terrisBlockRotate
(
&
pobj
->
currentblock
,
0
);
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
break
;
}
}
...
...
@@ -386,10 +751,10 @@ static int terrisctrl1_hdl4se_unit_ClkTick(HOBJECT object)
if
(
pobj
->
state
==
ST_INIT
)
{
objectCall3
(
pobj
->
input_unit
[
2
],
GetValue
,
pobj
->
input_index
[
2
],
32
,
pobj
->
inputdata
);
objectCall1
(
pobj
->
inputdata
,
GetUint32
,
&
statecomplete
);
currentspeed
=
MAXSPPED
;
currenttick
=
0
;
gameScore
=
200
;
gameLevel
=
0
;
pobj
->
currentspeed
=
MAXSPPED
;
pobj
->
currenttick
=
0
;
pobj
->
gameScore
=
200
;
pobj
->
gameLevel
=
0
;
if
(
statecomplete
!=
0
)
pobj
->
state
=
ST_GENBLOCK
;
}
...
...
@@ -403,7 +768,7 @@ static int terrisctrl1_hdl4se_unit_ClkTick(HOBJECT object)
objectCall1
(
pobj
->
inputdata
,
GetUint64
,
&
data
);
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
{
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
nextblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
=
data
&
0xf
;
pobj
->
nextblock
.
subblock
[
BLOCKSIZE
-
1
-
i
][
BLOCKSIZE
-
1
-
j
]
=
data
&
0xf
;
data
>>=
4
;
}
}
...
...
@@ -415,14 +780,14 @@ static int terrisctrl1_hdl4se_unit_ClkTick(HOBJECT object)
int
i
,
j
;
for
(
i
=
0
;
i
<
BLOCKSIZE
;
i
++
)
{
for
(
j
=
0
;
j
<
BLOCKSIZE
;
j
++
)
{
if
(
currentblock
.
subblock
[
i
][
j
]
!=
0
)
if
(
pobj
->
currentblock
.
subblock
[
i
][
j
]
!=
0
)
curblockinvalid
=
0
;
}
}
if
(
curblockinvalid
)
{
memcpy
(
currentblock
.
subblock
,
nextblock
.
subblock
,
sizeof
(
currentblock
.
subblock
));
currentblock
.
posx
=
PANELWIDTH
/
2
;
currentblock
.
posy
=
0
;
memcpy
(
pobj
->
currentblock
.
subblock
,
pobj
->
nextblock
.
subblock
,
sizeof
(
pobj
->
currentblock
.
subblock
));
pobj
->
currentblock
.
posx
=
PANELWIDTH
/
2
;
pobj
->
currentblock
.
posy
=
0
;
pobj
->
state
=
ST_GENBLOCK
;
}
else
{
...
...
@@ -487,24 +852,24 @@ static int terrisctrl1_hdl4se_unit_ClkTick(HOBJECT object)
pobj
->
state
=
ST_COPYLINES
;
pobj
->
checklinecount
++
;
}
else
{
gameLevel
+=
pobj
->
checklinecount
;
pobj
->
gameLevel
+=
pobj
->
checklinecount
;
if
(
pobj
->
checklinecount
==
1
)
gameScore
+=
10
;
pobj
->
gameScore
+=
10
;
if
(
pobj
->
checklinecount
==
2
)
gameScore
+=
40
;
pobj
->
gameScore
+=
40
;
if
(
pobj
->
checklinecount
==
3
)
gameScore
+=
160
;
pobj
->
gameScore
+=
160
;
if
(
pobj
->
checklinecount
==
4
)
gameScore
+=
640
;
currentspeed
=
MAXSPPED
-
gameScore
/
3
;
if
(
currentspeed
<
1
)
currentspeed
=
1
;
memcpy
(
&
currentblock
,
&
nextblock
,
sizeof
(
currentblock
));
currentblock
.
posx
=
PANELWIDTH
/
2
;
currentblock
.
posy
=
0
;
pobj
->
testx
=
currentblock
.
posx
;
pobj
->
testy
=
currentblock
.
posy
;
pobj
->
gameScore
+=
640
;
pobj
->
currentspeed
=
MAXSPPED
-
pobj
->
gameScore
/
3
;
if
(
pobj
->
currentspeed
<
1
)
pobj
->
currentspeed
=
1
;
memcpy
(
&
pobj
->
currentblock
,
&
pobj
->
nextblock
,
sizeof
(
pobj
->
currentblock
));
pobj
->
currentblock
.
posx
=
PANELWIDTH
/
2
;
pobj
->
currentblock
.
posy
=
0
;
pobj
->
testx
=
pobj
->
currentblock
.
posx
;
pobj
->
testy
=
pobj
->
currentblock
.
posy
;
pobj
->
testid
=
2
;
pobj
->
state
=
ST_CHECKBLOCKCANSETTO
;
}
...
...
@@ -533,3 +898,4 @@ static int terrisctrl1_hdl4se_unit_Setup(HOBJECT object)
return
0
;
}
#endif
\ No newline at end of file
examples/terris/src/terris_main_module.c
浏览文件 @
d8fe6235
此差异已折叠。
点击以展开。
examples/terris/verilog/terris_ctrl.v
浏览文件 @
d8fe6235
...
...
@@ -79,7 +79,7 @@ endmodule
/* 俄罗斯方块控制器V1 */
(
*
//
HDL4SE="LCOM",
HDL4SE
=
"LCOM"
,
CLSID
=
"158fa52-ca8b-4551-9b87-fc7cff466e2a"
,
softmodule
=
"hdl4se"
*
)
...
...
examples/terris/verilog/terris_main_asm.v
浏览文件 @
d8fe6235
...
...
@@ -622,6 +622,7 @@ endmodule
(
*
HDL4SE
=
"LCOM"
,
CLSID
=
"158fa52-ca8b-4551-9b87-fc7cff466e2a"
,
softmodule
=
"hdl4se"
*
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录