提交 48e2955c 编写于 作者: 饶先宏's avatar 饶先宏

202106261008

上级 bf111d7e
......@@ -543,6 +543,7 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
if (nstr != NULL)
*nstr = strt;
}
objwidth = width;
numvalid = 0;
}
else {
......@@ -710,7 +711,7 @@ lastnum:
}
if (width == 0)
width = 1;
if (pobj->isunsigned == 0)
// if (pobj->isunsigned == 0)
width++;
}
else {
......@@ -793,15 +794,27 @@ static int bigint_bn_AddInt32(HOBJECT object, HOBJECT src, int value)
{
unsigned long long temp;
int ind;
unsigned int v, vs, widthsrc;
unsigned int v, vs, widthsrc, width;
int objunsigned, srcunsigned;
sBigInteger* pobj;
IBigNumber** numsrc;
pobj = (sBigInteger*)objectThis(object);
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&numsrc))
return -1;
widthsrc = objectCall0(numsrc, GetWidth);
objectCall1(numsrc, SetWidth, widthsrc);
bigint_bn_SetWidth(object, pobj->width);
srcunsigned = objectCall0(numsrc, IsUnsigned);
objunsigned = pobj->isunsigned;
width = pobj->width;
if (width < widthsrc)
width = widthsrc;
objectCall1(numsrc, SetUnsigned, 0);
objectCall1(numsrc, SetWidth, width);
bigint_bn_SetUnsigned(object, 0);
bigint_bn_SetWidth(object, width);
objectCall2(numsrc, GetBits32, 0, &vs);
temp = vs;
temp += *(unsigned int*)&value;
......@@ -820,6 +833,10 @@ static int bigint_bn_AddInt32(HOBJECT object, HOBJECT src, int value)
temp >>= CELL_WIDTH;
ind++;
}
objectCall1(numsrc, SetUnsigned, srcunsigned);
objectCall1(numsrc, SetWidth, widthsrc);
bigint_bn_SetUnsigned(object, objunsigned);
bigint_bn_SetWidth(object, pobj->width);
return 0;
}
......@@ -832,6 +849,7 @@ static int bigint_bn_MulInt32(HOBJECT object, HOBJECT src, int value)
{
IBigNumber ** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 0);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Mul(object, src, temp);
objectRelease(temp);
......@@ -842,6 +860,7 @@ static int bigint_bn_DivInt32(HOBJECT object, HOBJECT src, int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 0);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Div(object, src, temp);
objectRelease(temp);
......@@ -852,6 +871,7 @@ static int bigint_bn_ModInt32(HOBJECT object, HOBJECT src, int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 0);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Mod(object, src, temp);
objectRelease(temp);
......@@ -862,6 +882,7 @@ static int bigint_bn_PowInt32(HOBJECT object, HOBJECT src, int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 0);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Pow(object, src, temp);
objectRelease(temp);
......@@ -870,32 +891,7 @@ static int bigint_bn_PowInt32(HOBJECT object, HOBJECT src, int value)
static int bigint_bn_AddUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
unsigned long long temp;
int ind;
unsigned int vs, widthsrc;
sBigInteger* pobj;
IBigNumber** numsrc;
pobj = (sBigInteger*)objectThis(object);
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&numsrc))
return -1;
widthsrc = objectCall0(numsrc, GetWidth);
objectCall1(numsrc, SetWidth, widthsrc);
bigint_bn_SetWidth(object, pobj->width);
objectCall2(numsrc, GetBits32, 0, &vs);
temp = vs;
temp += *(unsigned int*)&value;
pobj->buf[0] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
ind = 1;
while (ind < pobj->buflen) {
if (0 != objectCall2(numsrc, GetBits32, ind, &vs))
vs = 0;
temp += vs;
pobj->buf[ind] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
ind++;
}
return 0;
return bigint_bn_AddInt32(object, src, value);
}
static int bigint_bn_SubUint32(HOBJECT object, HOBJECT src, unsigned int value)
......@@ -910,6 +906,7 @@ static int bigint_bn_MulUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 1);
bigint_bn_AssignUint32(temp, value);
bigint_bn_Mul(object, src, temp);
objectRelease(temp);
......@@ -920,6 +917,7 @@ static int bigint_bn_DivUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 1);
bigint_bn_AssignUint32(temp, value);
bigint_bn_Div(object, src, temp);
objectRelease(temp);
......@@ -930,6 +928,7 @@ static int bigint_bn_ModUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 1);
bigint_bn_AssignUint32(temp, value);
bigint_bn_Mod(object, src, temp);
objectRelease(temp);
......@@ -940,20 +939,21 @@ static int bigint_bn_PowUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
IBigNumber** temp;
temp = bigintegerCreate(32);
bigint_bn_SetUnsigned(temp, 1);
bigint_bn_AssignUint32(temp, value);
bigint_bn_Pow(object, src, temp);
objectRelease(temp);
return 0;
}
static int bigint_bn_AddFunc(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
static int bigint_bn_Add(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
unsigned long long temp;
sBigInteger* pobj;
IBigNumber** psrc0;
IBigNumber** psrc1;
int widthobj, widthsrc0, widthsrc1;
int widthobj, widthsrc0, widthsrc1, width;
int objunsigned, src0unsigned, src1unsigned;
int i;
pobj = (sBigInteger*)objectThis(object);
if (EIID_OK != objectQueryInterface(src0, IID_BIGNUMBER, (void**)&psrc0)) {
......@@ -966,18 +966,23 @@ static int bigint_bn_AddFunc(HOBJECT object, HOBJECT src0, HOBJECT src1)
widthobj = pobj->width;
widthsrc0 = objectCall0(psrc0, GetWidth);
widthsrc1 = objectCall0(psrc1, GetWidth);
if (widthsrc0 < widthobj) {
objectCall1(psrc0, SetWidth, widthobj);
}
else {
objectCall1(psrc0, SetWidth, widthsrc0);
}
if (widthsrc1 < widthobj) {
objectCall1(psrc1, SetWidth, widthobj);
}
else {
objectCall1(psrc1, SetWidth, widthsrc1);
}
objunsigned = pobj->isunsigned;
src0unsigned = objectCall0(psrc0, IsUnsigned);
src1unsigned = objectCall0(psrc1, IsUnsigned);
bigint_bn_SetUnsigned(object, 0);
objectCall1(psrc0, SetUnsigned, 0);
objectCall1(psrc1, SetUnsigned, 0);
width = widthsrc0;
if (width < widthsrc1)
width = widthsrc1;
if (width < widthobj)
width = widthobj;
objectCall1(psrc0, SetWidth, width);
objectCall1(psrc1, SetWidth, width);
bigint_bn_SetWidth(object, width);
temp = 0;
for (i = 0; i < pobj->buflen; i++) {
unsigned int src0value, src1value;
......@@ -988,64 +993,38 @@ static int bigint_bn_AddFunc(HOBJECT object, HOBJECT src0, HOBJECT src1)
pobj->buf[i] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
}
bigint_bn_SetUnsigned(object, objunsigned);
objectCall1(psrc0, SetUnsigned, src0unsigned);
objectCall1(psrc1, SetUnsigned, src1unsigned);
bigint_bn_SetWidth(object, widthobj);
if (widthsrc0 < widthobj) {
objectCall1(psrc0, SetWidth, widthsrc0);
}
if (widthsrc1 < widthobj) {
objectCall1(psrc1, SetWidth, widthsrc1);
}
objectCall1(psrc0, SetWidth, widthsrc0);
objectCall1(psrc1, SetWidth, widthsrc1);
objectRelease(psrc0);
objectRelease(psrc1);
return 0;
}
static int bigint_bn_Add(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
return bigint_bn_AddFunc(object, src0, src1);
}
static int bigint_bn_Sub(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
IBigNumber** temp = NULL;
IBigNumber** psrc0 = NULL;
IBigNumber** psrc1 = NULL;
int ret;
int width0, width1, width;
pobj = (sBigInteger*)objectThis(object);
if (0 != objectQueryInterface(src0, IID_BIGNUMBER, &psrc0)) {
ret = -1;
goto retresult;
}
if (0 != objectQueryInterface(src1, IID_BIGNUMBER, &psrc1)) {
ret = -1;
goto retresult;
}
width0 = objectCall0(psrc0, GetWidth);
width1 = objectCall0(psrc1, GetWidth);
width = pobj->width;
temp = bigintegerCreate(32);
objectCall1(temp, Clone, src1);
if (width1 < width0)
objectCall1(temp, SetWidth, width0);
if (EIID_OK != bigint_bn_Neg(temp, temp))
return -1;
ret = bigint_bn_Add(object, src0, temp);
retresult:
objectRelease(psrc0);
objectRelease(psrc1);
objectRelease(temp);
return ret;
}
static int bigint_bn_MulFunc(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
static int bigint_bn_Mul(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
IBigNumber** psrc0;
IBigNumber** psrc1;
unsigned int* buf;
int widthobj, widthsrc0, widthsrc1;
int widthobj, widthsrc0, widthsrc1, width;
int objunsigned, src0unsigned, src1unsigned;
int i, j;
pobj = (sBigInteger*)objectThis(object);
if (EIID_OK != objectQueryInterface(src0, IID_BIGNUMBER, (void**)&psrc0)) {
......@@ -1054,31 +1033,32 @@ static int bigint_bn_MulFunc(HOBJECT object, HOBJECT src0, HOBJECT src1)
if (EIID_OK != objectQueryInterface(src1, IID_BIGNUMBER, (void**)&psrc1)) {
objectRelease(psrc0);
return -1;
}
}
widthobj = pobj->width;
widthsrc0 = objectCall0(psrc0, GetWidth);
widthsrc1 = objectCall0(psrc1, GetWidth);
if (widthsrc0 < widthobj) {
objectCall1(psrc0, SetWidth, widthobj);
}
else {
objectCall1(psrc0, SetWidth, widthsrc0);
}
if (widthsrc1 < widthobj) {
objectCall1(psrc1, SetWidth, widthobj);
}
else {
objectCall1(psrc1, SetWidth, widthsrc1);
}
pobj->buflen = (pobj->width + CELL_WIDTH - 1) / CELL_WIDTH;
if (pobj->buflen < 2)
pobj->buflen = 2;
buf = (unsigned int*)malloc(pobj->buflen * CELL_WIDTH / 8);
if (buf == NULL) {
objectRelease(psrc0);
objectRelease(psrc1);
objunsigned = pobj->isunsigned;
src0unsigned = objectCall0(psrc0, IsUnsigned);
src1unsigned = objectCall0(psrc1, IsUnsigned);
bigint_bn_SetUnsigned(object, 0);
objectCall1(psrc0, SetUnsigned, 0);
objectCall1(psrc1, SetUnsigned, 0);
width = widthobj;
if (width < widthsrc0)
width = widthsrc0;
if (width < widthsrc1)
width = widthsrc1;
objectCall1(psrc0, SetWidth, width);
objectCall1(psrc1, SetWidth, width);
bigint_bn_SetWidth(object,width);
buf = (unsigned int *)malloc(pobj->buflen * sizeof(unsigned int));
if (buf == NULL)
return -1;
}
for (i = 0; i < pobj->buflen; i++)
buf[i] = 0;
......@@ -1092,30 +1072,26 @@ static int bigint_bn_MulFunc(HOBJECT object, HOBJECT src0, HOBJECT src1)
for (j = 0; j < pobj->buflen - i; j++) {
objectCall2(psrc1, GetBits32, j, &m1s);
m1 = m1s;
m1 = m0 * m1 + addin + buf[i+j];
m1 = m0 * m1 + addin + buf[i + j];
buf[i + j] = m1 & CELL_MASK;
addin = m1 >> CELL_WIDTH;
}
}
free(pobj->buf);
pobj->buf = buf;
bigint_bn_SetUnsigned(object, objunsigned);
objectCall1(psrc0, SetUnsigned, src0unsigned);
objectCall1(psrc1, SetUnsigned, src1unsigned);
bigint_bn_SetWidth(object, widthobj);
if (widthsrc0 < widthobj) {
objectCall1(psrc0, SetWidth, widthsrc0);
}
if (widthsrc1 < widthobj) {
objectCall1(psrc1, SetWidth, widthsrc1);
}
objectCall1(psrc0, SetWidth, widthsrc0);
objectCall1(psrc1, SetWidth, widthsrc1);
objectRelease(psrc0);
objectRelease(psrc1);
return 0;
}
static int bigint_bn_Mul(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
return bigint_bn_MulFunc(object, src0, src1);
}
static int bigint_bn_Div(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
......@@ -1383,8 +1359,8 @@ static int bigint_bn_IsNotZero(HOBJECT object)
pobj = (sBigInteger*)objectThis(object);
for (i = 0; i < pobj->buflen; i++)
if (pobj->buf[i] != 0)
return 0;
return 1;
return 1;
return 0;
}
static int bigint_bn_IsNeg(HOBJECT object)
......@@ -1661,8 +1637,10 @@ static int bigint_bn_SHL(HOBJECT object, HOBJECT src, int bits)
int ifrom, ito, i;
unsigned long long current, next;
if (bits == 0)
if (bits == 0) {
bigint_bn_Assign(object, src);
return 0;
}
if (bits < 0)
return bigint_bn_SHR(object, src, -bits);
......@@ -1713,8 +1691,10 @@ static int bigint_bn_SHR(HOBJECT object, HOBJECT src, int bits)
int ifrom, ito, i, zerolen;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
if (bits == 0) {
bigint_bn_Assign(object, src);
return 0;
}
if (bits < 0)
return bigint_bn_SHL(object, src, -bits);
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&psrc)) {
......
......@@ -196,7 +196,7 @@ static int terris_copylines_hdl4se_unit_GetValue(HOBJECT object, int index, int
{
sTerrisCopyLines* pobj;
pobj = (sTerrisCopyLines*)objectThis(object);
int y;
unsigned int y;
y = pobj->readindex_1 + pobj->fromline_reg;
if (index == 2) { /* wCtrlStateComplete */
objectCall1(value, AssignUint32, (y > YCOUNT)?1:0);
......@@ -205,7 +205,7 @@ static int terris_copylines_hdl4se_unit_GetValue(HOBJECT object, int index, int
objectCall1(value, AssignUint32, pobj->readindex + pobj->fromline_reg);
}
else if (index == 5) {/* wWrite */
if (pobj->readindex_1 >= 0 && pobj->fromline_reg >= 0 && (y >= 1) && (y <= YCOUNT))
if ((y >= 1) && (y <= YCOUNT))
objectCall1(value, AssignUint32, 1);
else
objectCall1(value, AssignUint32, 0);
......
......@@ -217,7 +217,7 @@ static unsigned int terris_flushtodisp_hdl4se_unit_GetWriteData(sTerrisFlushToDi
unsigned int blockx, blocky;
int i;
int y = pobj->flushreadaddr_last >> 1;
unsigned int y = pobj->flushreadaddr_last >> 1;
objectCall3(pobj->input_unit[7], GetValue, pobj->input_index[7], 16, pobj->inputdata);
objectCall1(pobj->inputdata, GetUint32, &blockpos);
......
......@@ -100,7 +100,14 @@ int main(int argc, char* argv[])
objectCall2(vcdfile, AddSignal, "/simulator/main/bram_WriteAddr", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/wram_Write", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/wCtrlStateComplete", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/wInitCtrlStateComplete", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/flusher/wirein_readaddr", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/flusher/wireout_readaddr", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/flusher/wireout_readaddr_delay_1", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/flusher/bWriteDataSel", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/flusher/curblockline", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/flusher/line", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/wFlushCtrlStateComplete", "out");
objectCall2(vcdfile, AddSignal, "/simulator/main/bram_ReadData", "out");
objectCall1(vcdfile, SetTopModule, sim);
objectCall0(vcdfile, StartRecord);
#endif
......
......@@ -47,21 +47,16 @@
/*
0: input wClk,
1: input nwReset,
2: output wWrite,
3: output[5:0] bWriteAddr,
4: output[63:0] bWriteData,
5: output[5:0] bReadAddr,
6: input[63:0] bReadData,
7: input[31:0] bKeyData,
8: input wStateComplete,
9: output[3:0] bState,
10: output[31:0] bScore,
11: output[31:0] bSpeed,
12: output[31:0] bLevel,
13: output [63:0] bNextBlock,
14: output [63:0] bCurBlock;
15: output [15:0] bCurBlockPos;
16: intput [31:0] bResult
2: input[31:0] bKeyData,
3: input wStateComplete,
4: output[3:0] bState,
5: output[31:0] bScore,
6: output[31:0] bSpeed,
7: output[31:0] bLevel,
8: output [63:0] bNextBlock,
9: output [63:0] bCurBlock;
10: output [15:0] bCurBlockPos;
11: intput [31:0] bResult
*/
struct _sTerrisCtrl1;
......@@ -75,10 +70,6 @@ struct _sTerrisCtrl1 {
IHDL4SEModule** parent;
char* name;
IHDL4SEUnit** readdata_unit;
int readdata_index;
IBigNumber** readdata;
IHDL4SEUnit** keydata_unit;
IBigNumber** keydata;
IBigNumber** lastkeydata;
......@@ -94,15 +85,6 @@ struct _sTerrisCtrl1 {
int resultindex;
IBigNumber** resultdata;
unsigned int write;
unsigned int writeaddr;
unsigned long long writedata;
unsigned int readaddr;
unsigned int write_reg;
unsigned int writeaddr_reg;
unsigned long long writedata_reg;
unsigned int readaddr_reg;
struct tagGenContext {
int index;
int complete;
......@@ -163,8 +145,6 @@ static int terrisctrl1Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
pobj->statecompletedata = bigintegerCreate(1);
pobj->resultunit = NULL;
pobj->resultdata = bigintegerCreate(32);
pobj->readdata_unit = NULL;
pobj->readdata = bigintegerCreate(64);
for (i = 0; i < paramcount; i++) {
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) {
if (pobj->name != NULL)
......@@ -176,7 +156,6 @@ static int terrisctrl1Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
}
}
pobj->genContext.index = 0;
pobj->write = 0;
pobj->state = -1;
terrisInit();
/* 返回生成的对象 */
......@@ -215,28 +194,21 @@ static int terrisctrl1_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT fr
sTerrisCtrl1* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sTerrisCtrl1*)objectThis(object);
if (index == 6) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->readdata_unit);
pobj->readdata_unit = unit;
pobj->readdata_index = fromindex;
}
}
else if (index == 7) {
if (index == 2) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->keydata_unit);
pobj->keydata_unit = unit;
pobj->keydata_index = fromindex;
}
}
else if (index == 8) {
else if (index == 3) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->statecomplete_unit);
pobj->statecomplete_unit = unit;
pobj->statecomplete_index = fromindex;
}
}
else if (index == 16) {
else if (index == 11) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->resultunit);
pobj->resultunit = unit;
......@@ -260,31 +232,19 @@ static int terrisctrl1_hdl4se_unit_GetValue(HOBJECT object, int index, int width
int i;
sTerrisCtrl1* pobj;
pobj = (sTerrisCtrl1*)objectThis(object);
if (index == 2) {
objectCall1(value, AssignUint32, pobj->write_reg);
}
else if (index == 3) {
objectCall1(value, AssignUint32, pobj->writeaddr_reg);
}
else if (index == 4) {
objectCall1(value, AssignUint64, pobj->writedata_reg);
}
else if (index == 5) {
objectCall1(value, AssignUint32, pobj->readaddr_reg);
}
else if (index == 9) {
if (index == 4) {
objectCall1(value, AssignUint32, pobj->state_reg);
}
else if (index == 10) {
else if (index == 5) {
objectCall1(value, AssignUint32, gameScore);
}
else if (index == 11) {
else if (index == 6) {
objectCall1(value, AssignUint32, MAXSPPED - currentspeed);
}
else if (index == 12) {
else if (index == 7) {
objectCall1(value, AssignUint32, gameLevel);
}
else if (index == 13) {
else if (index == 8) {
unsigned long long data;
int i, j;
data = 0;
......@@ -296,7 +256,7 @@ static int terrisctrl1_hdl4se_unit_GetValue(HOBJECT object, int index, int width
}
objectCall1(value, AssignUint64, data);
}
else if (index == 14) {
else if (index == 9) {
unsigned long long data;
int i, j;
data = 0;
......@@ -308,7 +268,7 @@ static int terrisctrl1_hdl4se_unit_GetValue(HOBJECT object, int index, int width
}
objectCall1(value, AssignUint64, data);
}
else if (index == 15) {
else if (index == 10) {
if (pobj->state == ST_CHECKBLOCKCANSETTO) {
objectCall1(value, AssignUint32, ((pobj->blockCanSetToContext.x + 1) & 0xff) | (((YCOUNT + 1 - pobj->blockCanSetToContext.y) & 0xff) << 8));
}
......@@ -453,7 +413,6 @@ static int terrisctrl1_hdl4se_unit_ClkTick(HOBJECT object)
pobj = (sTerrisCtrl1*)objectThis(object);
pobj->write = 0;
if (pobj->state == ST_INIT) {
objectCall3(pobj->statecomplete_unit, GetValue, pobj->statecomplete_index, 32, pobj->statecompletedata);
objectCall1(pobj->statecompletedata, GetUint32, &statecomplete);
......@@ -514,7 +473,6 @@ static int terrisctrl1_hdl4se_unit_ClkTick(HOBJECT object)
objectCall1(pobj->resultdata, GetUint32, &pobj->genContext.index);
if (pobj->genContext.index < YCOUNT) {
pobj->genContext.startindex = pobj->genContext.index;
pobj->readaddr = pobj->genContext.index + 1;
pobj->state = ST_COPYLINES;
pobj->genContext.count++;
} else {
......@@ -567,10 +525,6 @@ static int terrisctrl1_hdl4se_unit_Setup(HOBJECT object)
sTerrisCtrl1* pobj;
pobj = (sTerrisCtrl1*)objectThis(object);
pobj->state_reg = pobj->state;
pobj->write_reg = pobj->write;
pobj->writeaddr_reg = pobj->writeaddr;
pobj->writedata_reg = pobj->writedata;
pobj->readaddr_reg = pobj->readaddr;
pobj->lastkey = pobj->key;
return 0;
}
......
......@@ -60,7 +60,7 @@ module canblocksetto(
assign wirein_readaddr = (bCtrlState == `ST_CHECKBLOCKCANSETTO)? (wireout_readaddr + 1) : 0;
assign wCanSet = wireout_cansetto;
assign bCBWReadAddr = wireout_readaddr + blocky - 2;
assign bCBWReadAddr = wireout_readaddr + blocky - 4;
assign wCtrlStateComplete = wireout_readaddr_delay_1 > 4 || wireout_cansetto == 0;
wire wCanSetCurrent, wCanSetCurrentPre;
......@@ -70,14 +70,14 @@ module canblocksetto(
assign wCanSetCurrentPre = ((wireout_readaddr > 0) && (wCanSetCurrent==0)) ? 0 : wireout_cansetto;
wire [7:0] y = wireout_readaddr_delay_1 + blocky - 2;
wire [7:0] y = wireout_readaddr_delay_1 + blocky;
wire wCanSetCurrent_1, wCanSetCurrent_2, wCanSetCurrent_3;
wire [63:0] curblockline = (bCurBlock >> ((3 - wireout_readaddr_delay_1) * 16)) & 16'hffff;
assign wCanSetCurrent = (wireout_readaddr_delay_1 > 3 || y >= `YCOUNT || curblockline == 0) ? 1 : wCanSetCurrent_1;
assign wCanSetCurrent = ((wireout_readaddr_delay_1 > 4) || (y >= (`YCOUNT+4)) || (curblockline == 0)) ? 1 : wCanSetCurrent_1;
assign wCanSetCurrent_1 = (curblockline != 0 && y < 0) ? 0 : wCanSetCurrent_2;
assign wCanSetCurrent_1 = (curblockline != 0 && y < 4) ? 0 : wCanSetCurrent_2;
wire [63:0] curblockline_0, curblockline_1, curblockline_2, curblockline_3, curblockline_mask, curblockline_mask_1;
assign curblockline_0 = (curblockline & 64'hf)?64'hf:64'h0;
......
......@@ -50,7 +50,7 @@ module checkline(
assign wirein_readaddr = (bCtrlState == `ST_CHECKLINE)? (wireout_readaddr + 1) : 0;
assign bCKLReadAddr = wireout_readaddr;
assign bFindLine = wireout_readaddr_delay_1;
assign wCtrlStateComplete = (wireout_readaddr_delay_1 > `YCOUNT) || blockline;
assign wCtrlStateComplete = (wireout_readaddr_delay_1 > `YCOUNT) || (blockline && (wireout_readaddr > 0));
wire block_0 = bCKLReadData[3:0] != 4'b0;
wire block_1 = bCKLReadData[7:4] != 4'b0;
wire block_2 = bCKLReadData[11:8] != 4'b0;
......
......@@ -49,13 +49,18 @@ module copylines(
);
wire [7:0] wirein_readaddr, wireout_readaddr, wireout_readaddr_delay_1;
hdl4se_reg #(6) ramreadaddr(wClk, wirein_readaddr, wireout_readaddr);
hdl4se_reg #(6) ramreadaddr_delay_1(wClk, wireout_readaddr, wireout_readaddr_delay_1);
hdl4se_reg #(6) reg_readaddr(wClk, wirein_readaddr, wireout_readaddr);
hdl4se_reg #(6) reg_readaddr_delay_1(wClk, wireout_readaddr, wireout_readaddr_delay_1);
wire [15:0] wirein_fromline, wireout_fromline;
hdl4se_reg #(6) reg_fromline(wClk, wirein_fromline, wireout_fromline);
assign wirein_readaddr = (bCtrlState == `ST_COPYLINES)? (wireout_readaddr + 1) : 0;
wire [7:0] y = bFromLine + wireout_readaddr_delay_1;
assign wirein_fromline = (bCtrlState == `ST_COPYLINES)? bFromLine : 0;
wire [7:0] y = wireout_fromline + wireout_readaddr_delay_1;
assign bWriteAddr = y - 1;
assign bWriteData = bReadData;
assign wWrite = (wireout_readaddr_delay_1 < (`YCOUNT + 1)) && (y>=1) && (y<`YCOUNT+1);
assign wCtrlStateComplete = y >= `YCOUNT;
assign bReadAddr = bFromLine + wireout_readaddr;
assign wWrite = (y>=1) && (y<=`YCOUNT);
assign wCtrlStateComplete = y > `YCOUNT;
assign bReadAddr = wireout_fromline + wireout_readaddr;
endmodule
......@@ -37,7 +37,7 @@
这一行如果存在,连接的就是c语言版本。
*/
(*
HDL4SE="LCOM",
//HDL4SE="LCOM",
CLSID="d588064-fcd3-43cc-b131-1a64c74d9e86",
softmodule="hdl4se"
*)
......@@ -72,10 +72,10 @@ module flushtodisp(
hdl4se_reg #(6) ramreadaddr_delay_1(wClk, wireout_readaddr, wireout_readaddr_delay_1);
assign wirein_readaddr = (bCtrlState == `ST_FLUSHTODISP) ? wireout_readaddr + 1 : 6'b0;
assign bFlushReadAddr = wireout_readaddr[6:1];
assign wCtrlStateComplete = wireout_readaddr == 6'd60;
assign wCtrlStateComplete = wireout_readaddr == 8'd60;
assign bWriteAddr = 32'hf000_0010 + wireout_readaddr_delay_1 * 4;
assign wWrite = (bCtrlState == `ST_FLUSHTODISP) ? 1 : 0;
wire [2:0] bWriteDataSel = (wireout_readaddr_delay_1 < 6'd52)?3'd7:(wireout_readaddr_delay_1 - 6'd52);
wire [2:0] bWriteDataSel = (wireout_readaddr_delay_1 < 8'd52)?3'd7:(wireout_readaddr_delay_1 - 8'd52);
/*
0 -- 47,面板内容, --> 7
52, 53: nextblock0, 1 --> 0, 1
......
......@@ -30,9 +30,9 @@
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/* panelinit.v */
(*
//HDL4SE="LCOM",
HDL4SE="LCOM",
CLSID="d6ef2a03-4c58-4b50-a966-44e156694304",
softmodule="hdl4se"
*)
......
......@@ -31,7 +31,7 @@
*/
/* terris_ctrl.v */
/* 用c写的俄罗斯方块控制器V1 */
/* 俄罗斯方块控制器V1 */
(*
HDL4SE="LCOM",
CLSID="158fa52-ca8b-4551-9b87-fc7cff466e2a",
......@@ -41,11 +41,6 @@ module teris_ctrl
(
input wClk,
input nwReset,
output wWrite,
output [5:0] bWriteAddr,
output [63:0] bWriteData,
output [5:0] bReadAddr,
input [63:0] bReadData,
input [31:0] bKeyData,
input wStateComplete,
output [3:0] bState,
......@@ -57,4 +52,46 @@ module teris_ctrl
output [15:0] bCurBlockPos,
input [31:0] wResult
);
wire [3:0] wirein_state, wireout_state;
hdl4se_reg #(4) terris_ctrlstate(wClk, wirein_state, wireout_state);
assign bState = wireout_state;
wire [31:0] wirein_score, wireout_score;
hdl4se_reg #(32) terris_score(wClk, wirein_score, wireout_score);
assign bScore = wireout_score;
wire [31:0] wirein_level, wireout_level;
hdl4se_reg #(32) terris_level(wClk, wirein_level, wireout_level);
assign bLevel = wireout_level;
wire [31:0] wirein_speed, wireout_speed;
hdl4se_reg #(32) terris_speed(wClk, wirein_speed, wireout_speed);
assign bSpeed = wireout_speed;
wire [15:0] wirein_curpos, wireout_curpos;
hdl4se_reg #(15) terris_curpos(wClk, wirein_curpos, wireout_curpos);
assign bCurBlockPos = wireout_curpos;
wire [63:0] wirein_curblock, wireout_curblock;
hdl4se_reg #(64) terris_curblock(wClk, wirein_curblock, wireout_curblock);
assign bCurBlock = wireout_curblock;
wire [63:0] wirein_nextblock, wireout_nextblock;
hdl4se_reg #(64) terris_nextblock(wClk, wirein_nextblock, wireout_nextblock);
assign bNextBlock = wireout_nextblock;
hdl4se_mux8 #(32) mux_nextstate(
wireout_state,
`ST_FLUSHTODISP, // 0: ST_INIT
`ST_CHECKKEY, // 1: ST_FLUSHTODISP,
32'b0, // 2: ST_CHECKKEY,
wCBWCanSetTo, // 3: ST_CHECKBLOCKCANSETTO,
32'b0, // 4: ST_BLOCKWRITE,
bCKLResult, // 5: ST_CHECKLINE,
32'b0, // 6: ST_COPYLINES
32'b0, // 7: empty
bResult
);
endmodule
\ No newline at end of file
......@@ -79,10 +79,6 @@ module main(
);
/* 游戏控制器 */
wire wCtrlWrite;
wire [5:0] bCtrlWriteAddr;
wire [63:0] bCtrlWriteData;
wire [5:0] bCtrlReadAddr;
wire [31:0] bCtrlKeyData;
wire wCtrlStateComplete;
wire [3:0] bCtrlState;
......@@ -94,8 +90,7 @@ module main(
wire [15:0] bCurBlockPos;
wire [31:0] bResult;
teris_ctrl ctrl(wClk, nwReset, wCtrlWrite, bCtrlWriteAddr, bCtrlWriteData,
bCtrlReadAddr,bram_ReadData, bCtrlKeyData,
teris_ctrl ctrl(wClk, nwReset, bCtrlKeyData,
wCtrlStateComplete, bCtrlState,
bCtrlScore, bCtrlSpeed, bCtrlLevel,
bNextBlock, bCurBlock, bCurBlockPos,
......@@ -194,7 +189,7 @@ module main(
bCtrlState,
wInitWrite, // 0: ST_INIT
1'b0, // 1: ST_FLUSHTODISP,
wCtrlWrite, // 2: ST_CHECKKEY,
1'b0, // 2: ST_CHECKKEY,
1'b0, // 3: ST_CHECKBLOCKCANSETTO,
wBWWrite, // 4: ST_BLOCKWRITE,
1'b0, // 5: ST_CHECKLINE,
......@@ -207,7 +202,7 @@ module main(
bCtrlState,
bInitWriteAddr, // 0: ST_INIT
6'b0, // 1: ST_FLUSHTODISP,
bCtrlWriteAddr, // 2: ST_CHECKKEY,
6'b0, // 2: ST_CHECKKEY,
6'b0, // 3: ST_CHECKBLOCKCANSETTO,
bBWWriteAddr, // 4: ST_BLOCKWRITE,
6'b0, // 5: ST_CHECKLINE,
......@@ -220,7 +215,7 @@ module main(
bCtrlState,
bInitWriteData, // 0: ST_INIT
64'b0, // 1: ST_FLUSHTODISP,
bCtrlWriteData, // 2: ST_CHECKKEY,
64'b0, // 2: ST_CHECKKEY,
64'b0, // 3: ST_CHECKBLOCKCANSETTO,
bBWWriteData, // 4: ST_BLOCKWRITE,
64'b0, // 5: ST_CHECKLINE,
......@@ -233,7 +228,7 @@ module main(
bCtrlState,
6'b0, // 0: ST_INIT
bFlushReadAddr,// 1: ST_FLUSHTODISP,
bCtrlReadAddr, // 2: ST_CHECKKEY,
6'b0, // 2: ST_CHECKKEY,
bCBWReadAddr, // 3: ST_CHECKBLOCKCANSETTO,
bBWReadAddr, // 4: ST_BLOCKWRITE,
bCKLReadAddr, // 5: ST_CHECKLINE,
......
......@@ -376,23 +376,34 @@ static int expr_verilognode_dump(HOBJECT object, FILE * pFile, int opt)
fprintf(pFile, conststringFromVar(pobj->data.name));
break;
case EXPRTYPE_BINOP:
fprintf(pFile, "(");
objectCall2(pobj->data.expr0, dump, pFile, opt);
output_operator(pFile, opt, pobj->data.op);
output_attributes(pFile, opt, pobj);
objectCall2(pobj->data.expr1, dump, pFile, opt);
fprintf(pFile, ")");
break;
case EXPRTYPE_UNOP:
fprintf(pFile, "(");
output_operator(pFile, opt, pobj->data.op);
output_attributes(pFile, opt, pobj);
fprintf(pFile, "(");
objectCall2(pobj->data.expr, dump, pFile, opt);
fprintf(pFile, "))");
break;
case EXPRTYPE_IFOP:
fprintf(pFile, "((");
objectCall2(pobj->data.expr0, dump, pFile, opt);
fprintf(pFile, ")");
fprintf(pFile, "?");
output_attributes(pFile, opt, pobj);
fprintf(pFile, "(");
objectCall2(pobj->data.expr1, dump, pFile, opt);
fprintf(pFile, ")");
fprintf(pFile, ":");
fprintf(pFile, "(");
objectCall2(pobj->data.expr2, dump, pFile, opt);
fprintf(pFile, "))");
break;
case EXPRTYPE_HIERARCHICAL_IDENT:
if (dlistItemCount(pobj->data.hierarchical_identifier) > 0) {
......@@ -1209,7 +1220,7 @@ static int expr_verilognode_gencode(HOBJECT object, FILE * pFile, HOBJECT module
expr_verilognode_gencode(pobj->data.expr0, pFile, module, &expr_results[0]);
expr_verilognode_gencode(pobj->data.expr1, pFile, module, &expr_results[2]); /*注意?:的结果和mux的顺序不同,所以结果位置不同*/
expr_verilognode_gencode(pobj->data.expr2, pFile, module, &expr_results[1]);
if (expr_result[1].width == 0 || expr_result[2].width == 0) {
if (expr_results[1].width == 0 || expr_results[2].width == 0) {
width = 0;
}
else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册