Skip to content

Commit 88497a8

Browse files
author
roudoudou
committed
SUM16 directive
1 parent 42bc2dd commit 88497a8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

rasm.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ E_POKER_CIPHER001=2,
959959
E_POKER_CIPHER002=3,
960960
E_POKER_CIPHER003=4,
961961
E_POKER_CIPHER004=5,
962+
E_POKER_SUM16=6,
962963
E_POKER_END
963964
};
964965

@@ -969,6 +970,7 @@ char *strpoker[]={
969970
"CIPHER002 running XOR initialised with memory location",
970971
"CIPHER003 XOR with LSB of memory location",
971972
"CIPHER004 XOR with key looping",
973+
"SUM16",
972974
NULL
973975
};
974976

@@ -20659,6 +20661,29 @@ void __SUMMEM(struct s_assenv *ae) {
2065920661
}
2066020662
}
2066120663

20664+
void __SUM16(struct s_assenv *ae) {
20665+
struct s_poker poker={0};
20666+
20667+
if (!ae->wl[ae->idx].t && !ae->wl[ae->idx+1].t && ae->wl[ae->idx+2].t==1) {
20668+
/* no poke in a NOCODE section */
20669+
if (!ae->nocode) {
20670+
poker.method=E_POKER_SUM16;
20671+
poker.istart=ae->idx+1;
20672+
poker.iend=ae->idx+2;
20673+
ExpressionFastTranslate(ae,&ae->wl[ae->idx+1].w,1);
20674+
ExpressionFastTranslate(ae,&ae->wl[ae->idx+2].w,1);
20675+
poker.outputadr=ae->outputadr;
20676+
poker.ibank=ae->activebank;
20677+
poker.ipoker=ae->idx;
20678+
ObjectArrayAddDynamicValueConcat((void**)&ae->poker,&ae->nbpoker,&ae->maxpoker,&poker,sizeof(poker));
20679+
}
20680+
___output(ae,0);
20681+
___output(ae,0);
20682+
} else {
20683+
MakeError(ae,ae->idx,GetCurrentFile(ae),ae->wl[ae->idx].l,"usage is SUM16 start,end\n");
20684+
}
20685+
}
20686+
2066220687
void __XORMEM(struct s_assenv *ae) {
2066320688
struct s_poker poker={0};
2066420689

@@ -20996,6 +21021,7 @@ struct s_asm_keyword instruction[]={
2099621021
{"ENDMODULE",0,0,__ENDMODULE},
2099721022
{"TIMESTAMP",0,0,__TIMESTAMP},
2099821023
{"SUMMEM",0,0,__SUMMEM},
21024+
{"SUM16",0,0,__SUM16},
2099921025
{"XORMEM",0,0,__XORMEM},
2100021026
{"CIPHERMEM",0,0,__CIPHERMEM},
2100121027
{"EXTERNAL",0,0,__EXTERNAL},
@@ -22285,6 +22311,7 @@ int Assemble(struct s_assenv *ae, unsigned char **dataout, int *lenout, struct s
2228522311
for (i=0;i<ae->nbpoker;i++) {
2228622312
int istart=-1,iend=-1;
2228722313
unsigned char xorval,sumval;
22314+
unsigned short int sum16;
2228822315

2228922316
/* start/end */
2229022317
ae->idx=ae->poker[i].istart; /* exp hack */
@@ -22346,6 +22373,14 @@ int Assemble(struct s_assenv *ae, unsigned char **dataout, int *lenout, struct s
2234622373
if (zekey) MemFree(zekey);
2234722374
}
2234822375
break;
22376+
case E_POKER_SUM16:
22377+
sum16=0;
22378+
for (j=istart;j<iend;j++) {
22379+
sum16+=ae->mem[ae->poker[i].ibank][j];
22380+
}
22381+
ae->mem[ae->poker[i].ibank][ae->poker[i].outputadr]=sum16&0xFF;
22382+
ae->mem[ae->poker[i].ibank][ae->poker[i].outputadr+1]=sum16>>8;
22383+
break;
2234922384
default:printf("warning remover\n");break;
2235022385
}
2235122386

@@ -27168,6 +27203,8 @@ int RasmAssembleInfoParam(const char *datain, int lenin, unsigned char **dataout
2716827203
#define AUTOTEST_GTILES_KO "incbin 'autotest_include.raw',GTILES,5"
2716927204
#define AUTOTEST_ITILES_KO "incbin 'autotest_include.raw',ITILES,5"
2717027205

27206+
#define AUTOTEST_SUM16 " tot=0: repeat 256: v=rnd(256): defb v: tot+=v: rend: sum16 0,256: defw tot"
27207+
2717127208

2717227209
struct s_autotest_keyword {
2717327210
char *keywordtest;
@@ -28618,6 +28655,11 @@ printf("testing formula function for Plus color management OK\n");
2861828655
if (!ret) {} else {printf("Autotest %03d ERROR (formula func FRAC)\n",cpt);exit(-1);}
2861928656
if (opcode) MemFree(opcode);opcode=NULL;cpt++;
2862028657
printf("testing formula FRAC function OK\n");
28658+
28659+
ret=RasmAssemble(AUTOTEST_SUM16,strlen(AUTOTEST_SUM16),&opcode,&opcodelen);
28660+
if (!ret && opcodelen==260 && opcode[256]==opcode[258] && opcode[257]==opcode[259]) {} else {printf("Autotest %03d ERROR (SUMMEM16)\n",cpt);exit(-1);}
28661+
if (opcode) MemFree(opcode);opcode=NULL;cpt++;
28662+
printf("testing directive SUMMEM16 OK\n");
2862128663

2862228664
ret=RasmAssemble(AUTOTEST_RND,strlen(AUTOTEST_RND),&opcode,&opcodelen);
2862328665
if (!ret) {} else {printf("Autotest %03d ERROR (formula func RND)\n",cpt);exit(-1);}

0 commit comments

Comments
 (0)