Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
LDmicroGitHub committed Apr 25, 2018
2 parents 24ad40a + f32e975 commit ce2c823
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 139 deletions.
8 changes: 8 additions & 0 deletions ldmicro/CHANGES.txt
@@ -1,3 +1,11 @@
== Release 4.3.8.6

* Fixed: Transliterate for non RU (#69). Fixes strange ANSIC output.

* Fixed: pic10f200 pin number (#70)

* Added: MOD (Integer Divide Remainder) operattion.

== Release 4.3.8.5

* Fixed: PIC10F200 compile, issue #65
Expand Down
18 changes: 6 additions & 12 deletions ldmicro/PASCAL.CPP
Expand Up @@ -115,7 +115,7 @@ static void ResetAndRegister(FILE *fr, FILE *fv, char *str, char *_str)
McuIoPinInfo *iop = PinInfoForName(_str);
ShortPinName(iop, str2);

int type = GetAssignedType(_str);
int type = GetAssignedType(_str,_str);
if(str[0] == 'U') {
if(type == IO_TYPE_DIG_INPUT) {
fprintf(fv, " InArr[InCount].Name := '%s';\n", __str);
Expand Down Expand Up @@ -355,9 +355,9 @@ static void PortY(FILE *fi, FILE *fu, char *str)
//-----------------------------------------------------------------------------
static void DeclareBit(FILE *f, FILE *fu, FILE *fi, FILE *fr, FILE *fv, char *str, char *_str)
{
// The mapped symbol has the form U_b_{X,Y,R}name, so look at character
// The mapped symbol has the form Ub_{X,Y,R}name, so look at character
// four to determine if it's an input, output, internal relay.
int type = GetAssignedType(_str);
int type = GetAssignedType(_str,_str);

if(type == IO_TYPE_DIG_INPUT) {
ResetAndRegister(fr, fv, str, _str);
Expand Down Expand Up @@ -427,9 +427,7 @@ static void GenerateDeclarations(FILE *f, FILE *fu, FILE *fi, FILE *fr, FILE *fv
case INT_SET_VARIABLE_AND:
case INT_SET_VARIABLE_OR:
case INT_SET_VARIABLE_XOR:
#ifdef SHARE
case INT_SET_VARIABLE_MOD:
#endif
case INT_SET_VARIABLE_DIVIDE:
case INT_SET_VARIABLE_MULTIPLY:
case INT_SET_VARIABLE_SUBTRACT:
Expand Down Expand Up @@ -768,13 +766,9 @@ static void GenerateSourceCode(FILE *f, int begin, int end)
case INT_SET_VARIABLE_DIVIDE:
op = "/";
goto arith;
#ifdef SHARE
#ifdef NEW_FEATURE
case INT_SET_VARIABLE_MOD:
op = "mod";
goto arith;
#endif
#endif
arith:
fprintf(f,
"%s := %s %s %s;\n",
Expand Down Expand Up @@ -1182,7 +1176,7 @@ void CompilePascal(char *dest)
"#endif\n"
"}\n"
"{ Define NO_PROTOTYPES if you don't want LDmicro to provide prototypes for\n"
" all the I/O procedures (Read_U_xxx, Write_U_xxx) that you must provide.\n"
" all the I/O procedures (Read_Ux_xxx, Write_Ux_xxx) that you must provide.\n"
" If you define this then you must provide your own prototypes for these\n"
" functions in ladder.pas, or provide definitions (e.g. as inlines or macros)\n"
" for them in ladder.pas. }\n"
Expand All @@ -1193,9 +1187,9 @@ void CompilePascal(char *dest)
"#define PROTO(x) x\n"
"#endif\n"
"}\n"
"{ U_xxx symbols correspond to user-defined names. There is such a symbol\n"
"{ Ux_xxx symbols correspond to user-defined names. There is such a symbol\n"
" for every internal relay, variable, timer, and so on in the ladder\n"
" program. I_xxx symbols are internally generated. }\n");
" program. Ix_xxx symbols are internally generated. }\n");

fprintf(f,
"procedure PlcCycle;\n"
Expand Down
54 changes: 19 additions & 35 deletions ldmicro/ansic.cpp
Expand Up @@ -145,7 +145,7 @@ static void DeclareBit(FILE *f, const char *str, int set1)
{
// The mapped symbol has the form U_b_{X,Y,R}name, so look at character
// four to determine if it's an input, output, internal relay.
int type = GetAssignedType(&str[3]);
int type = GetAssignedType(&str[3], str);

//if(str[3] == 'X') {
if(type == IO_TYPE_DIG_INPUT) {
Expand Down Expand Up @@ -560,10 +560,10 @@ static void GenerateDeclarations(FILE *f)
case INT_SET_VARIABLE_SHR:
case INT_SET_VARIABLE_AND:
case INT_SET_VARIABLE_OR:
case INT_SET_VARIABLE_MOD:
break;
case INT_SET_VARIABLE_XOR:
case INT_SET_VARIABLE_SR0:
case INT_SET_VARIABLE_MOD:
case INT_SET_VARIABLE_DIVIDE:
case INT_SET_VARIABLE_MULTIPLY:
case INT_SET_VARIABLE_SUBTRACT:
Expand Down Expand Up @@ -844,6 +844,9 @@ static void GenerateAnsiC(FILE *f, int begin, int end)
case INT_SET_VARIABLE_DIVIDE:
op = '/';
goto arith;
case INT_SET_VARIABLE_MOD:
op = '%';
goto arith;
arith:
fprintf(f,
"%s = %s %c %s;\n",
Expand Down Expand Up @@ -953,23 +956,23 @@ static void GenerateAnsiC(FILE *f, int begin, int end)
case INT_DELAY:
fprintf(f, "#ifdef CCS_PIC_C\n");
doIndent(f, i);
fprintf(f, " delay_us(%s);\n", IntCode[i].name1);
fprintf(f, " delay_us(%s);\n", MapSym(IntCode[i].name1, ASINT));
doIndent(f, i);
fprintf(f, "#elif defined(HI_TECH_C)\n");
doIndent(f, i);
fprintf(f, " __delay_us(%s);\n", IntCode[i].name1);
fprintf(f, " __delay_us(%s);\n", MapSym(IntCode[i].name1, ASINT));
doIndent(f, i);
fprintf(f, "#elif defined(__CODEVISIONAVR__)\n");
doIndent(f, i);
fprintf(f, " delay_us(%s);\n", IntCode[i].name1);
fprintf(f, " delay_us(%s);\n", MapSym(IntCode[i].name1, ASINT));
doIndent(f, i);
fprintf(f, "#elif defined(__GNUC__)\n");
doIndent(f, i);
fprintf(f, " _delay_us(%s);\n", IntCode[i].name1);
fprintf(f, " _delay_us(%s);\n", MapSym(IntCode[i].name1, ASINT));
doIndent(f, i);
fprintf(f, "#else\n");
doIndent(f, i);
fprintf(f, " delayMicroseconds(%s);\n", IntCode[i].name1);
fprintf(f, " delayMicroseconds(%s);\n", MapSym(IntCode[i].name1, ASINT));
doIndent(f, i);
fprintf(f, "#endif\n");
break;
Expand Down Expand Up @@ -1614,26 +1617,21 @@ void CompileAnsiC(char *dest, int MNU)
" #include <%s.h>\n",
Prog.mcu->mcuH2,
Prog.mcu->mcuH);
if(AdcFunctionUsed()) {
fprintf(f, " #device ADC=10\n");
}
if(PwmFunctionUsed()) {
fprintf(f, " #USE PWM\n");
}
fprintf(f, " #FUSES 1=0x%04X\n", (WORD)Prog.configurationWord & 0xFFFF);
if(Prog.configurationWord & 0xFFFF0000) {
fprintf(f, " #FUSES 2=0x%04X\n", (WORD)(Prog.configurationWord >> 16) & 0xFFFF);
}
if(UartFunctionUsed()) {
fprintf(f, " #USE RS232(BAUD=%d, BITS=8, PARITY=N, STOP=1, ERRORS, UART1) // ENABLE=pin\n", Prog.baudRate);
}
if(DelayUsed() || UartFunctionUsed()) {
fprintf(f, " #USE DELAY(CLOCK=%d)\n", Prog.mcuClock);
/*
fprintf(f,
" #USE DELAY(INTERNAL=%d)\n"
, Prog.mcuClock);
*/
}
if(UartFunctionUsed()) {
fprintf(f, " #USE RS232(BAUD=%d, BITS=8, PARITY=N, STOP=1, ERRORS, UART1) // ENABLE=pin\n", Prog.baudRate);
if(AdcFunctionUsed()) {
fprintf(f, " #device ADC=10\n");
}
if(PwmFunctionUsed()) {
fprintf(f, " //TODO #USE PWM // http://www.ccsinfo.com/newsdesk_info.php?newsdesk_id=182 \n");
}
int i;
if(Prog.mcu)
Expand Down Expand Up @@ -2001,27 +1999,13 @@ void CompileAnsiC(char *dest, int MNU)
fprintf(f, " analogReference(analogReference_type);\n\n");

Comment(" Set up I/O pins");
int i;
for(i = 0; i < Prog.io.count; i++) {
for(int i = 0; i < Prog.io.count; i++) {
if((Prog.io.assignment[i].type == IO_TYPE_INT_INPUT) || (Prog.io.assignment[i].type == IO_TYPE_DIG_INPUT))
fprintf(f, " pinMode(pin_%s, INPUT_PULLUP);\n", MapSym(Prog.io.assignment[i].name, ASBIT));
else if(Prog.io.assignment[i].type == IO_TYPE_PWM_OUTPUT)
fprintf(f, " pinMode(pin_%s, OUTPUT);\n", MapSym(Prog.io.assignment[i].name, ASBIT));
else if(Prog.io.assignment[i].type == IO_TYPE_DIG_OUTPUT)
fprintf(f, " pinMode(pin_%s, OUTPUT);\n", MapSym(Prog.io.assignment[i].name, ASBIT));
/*
if((Prog.io.assignment[i].type == IO_TYPE_INT_INPUT)
|| (Prog.io.assignment[i].type == IO_TYPE_PWM_OUTPUT)
|| (Prog.io.assignment[i].type == IO_TYPE_DIG_INPUT)
|| (Prog.io.assignment[i].type == IO_TYPE_DIG_OUTPUT)) {
if(Prog.io.assignment[i].name[0] == 'X')
fprintf(f," pinMode(pin_%s, INPUT);\n", MapSym(Prog.io.assignment[i].name, ASBIT));
else if(Prog.io.assignment[i].name[0] == 'Y')
fprintf(f," pinMode(pin_%s, OUTPUT);\n", MapSym(Prog.io.assignment[i].name, ASBIT));
// else if(Prog.io.assignment[i].name[0] == 'A')
// fprintf(f," analogReference(analogReference_type);\n");
}
*/
}
if(SleepFunctionUsed()) {
fprintf(f,
Expand Down
1 change: 0 additions & 1 deletion ldmicro/avr.cpp
Expand Up @@ -4061,7 +4061,6 @@ static void CompileFromIntermediate()
break;

case INT_SET_VARIABLE_MOD:
break;
case INT_SET_VARIABLE_DIVIDE:
// Do this one separately since the divide routine uses
// slightly different in/out registers and I don't feel like
Expand Down
6 changes: 0 additions & 6 deletions ldmicro/build412/git_commit.h

This file was deleted.

11 changes: 10 additions & 1 deletion ldmicro/compilecommon.cpp
Expand Up @@ -393,9 +393,18 @@ int SingleBitAssigned(const char *name)
}

//-----------------------------------------------------------------------------
int GetAssignedType(const char *name)
int GetAssignedType(const char *name, const char *fullName)
{
int type = NO_PIN_ASSIGNED;
if(fullName && strlen(fullName))
if(fullName[0] == 'I') {
if(fullName[1] == 'b')
return IO_TYPE_INTERNAL_RELAY;
else if(fullName[1] == 'i')
return IO_TYPE_GENERAL;
else
oops();
}
for(int i = 0; i < Prog.io.count; i++) {
if(strcmp(Prog.io.assignment[i].name, name) == 0) {
type = Prog.io.assignment[i].type;
Expand Down
6 changes: 0 additions & 6 deletions ldmicro/draw.cpp
Expand Up @@ -1623,12 +1623,6 @@ static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, BOOL poweredBe

int xadj = 0;
switch(which) {
/*
case ELEM_ADD:
case ELEM_SUB:
case ELEM_MUL:
case ELEM_DIV:
*/
case ELEM_QUAD_ENCOD:
case ELEM_NPULSE:
case ELEM_PULSER:
Expand Down
5 changes: 4 additions & 1 deletion ldmicro/intcode.cpp
Expand Up @@ -450,10 +450,12 @@ void IntDumpListing(char *outFile)
fprintf(f, "if ('%s' & (1<<%d)) == 0 {", IntCode[i].name1, IntCode[i].name2);
indent++;
break;

case INT_IF_BITS_SET_IN_VAR: // TODO
fprintf(f, "if ('%s' & %d) == %d {", IntCode[i].name1, IntCode[i].literal, IntCode[i].literal);
indent++;
break;

case INT_IF_BITS_CLEAR_IN_VAR: // TODO
fprintf(f, "if ('%s' & %d) == 0 {", IntCode[i].name1, IntCode[i].literal);
indent++;
Expand Down Expand Up @@ -2814,6 +2816,7 @@ static void IntCodeFromCircuit(int which, void *any, const char *stateInOut, int
case ELEM_SUB: intOp = INT_SET_VARIABLE_SUBTRACT; Comment(3, "ELEM_SUB"); goto math;
case ELEM_MUL: intOp = INT_SET_VARIABLE_MULTIPLY; Comment(3, "ELEM_MUL"); goto math;
case ELEM_DIV: intOp = INT_SET_VARIABLE_DIVIDE; Comment(3, "ELEM_DIV"); goto math;
case ELEM_MOD: intOp = INT_SET_VARIABLE_MOD; Comment(3, "ELEM_MOD"); goto math;
math: {
if(IsNumber(l->d.math.dest)) {
Error(_("Math instruction: '%s' not a valid destination."),
Expand Down Expand Up @@ -3771,7 +3774,7 @@ BOOL DivideRoutineUsed()
return TRUE;

for(int i = 0; i < IntCodeLen; i++)
if(IntCode[i].op == INT_SET_VARIABLE_DIVIDE)
if((IntCode[i].op == INT_SET_VARIABLE_DIVIDE) || (IntCode[i].op == INT_SET_VARIABLE_MOD))
return TRUE;

return FALSE;
Expand Down
10 changes: 8 additions & 2 deletions ldmicro/intcode.h
Expand Up @@ -30,6 +30,7 @@

#define NEW_CMP // (C) GitHub.LDmicro@gmail.com
#define TABLE_IN_FLASH // (C) GitHub.LDmicro@gmail.com
#define NEW_INT 1

// clang-format off

Expand All @@ -38,29 +39,34 @@
#define INT_COPY_BIT_TO_BIT 3
#define INT_COPY_NOT_BIT_TO_BIT 301
#define INT_COPY_XOR_BIT_TO_BIT 302
#if NEW_INT > 0
#define INT_VARIABLE_SET_BIT 3001
#define INT_VARIABLE_CLEAR_BIT 3002
#define INT_VARIABLE_NOT_BIT 3003
#define INT_VARIABLE_SET_BITS 3006
#define INT_VARIABLE_CLEAR_BITS 3007
#endif
#define INT_SET_VARIABLE_TO_LITERAL 4
#define INT_SET_VARIABLE_TO_VARIABLE 5
#if NEW_INT > 0
#define INT_SET_BIN2BCD 5001
#define INT_SET_BCD2BIN 5002
#define INT_SET_OPPOSITE 5003
#endif
#define INT_SET_SWAP 5004
#define INT_DECREMENT_VARIABLE 6001
#define INT_INCREMENT_VARIABLE 6
#define INT_SET_VARIABLE_ADD 7
#define INT_SET_VARIABLE_SUBTRACT 8
#define INT_SET_VARIABLE_MULTIPLY 9
#define INT_SET_VARIABLE_DIVIDE 10

#define INT_SET_VARIABLE_MOD 1001

#if NEW_INT > 0
#define INT_COPY_VAR_BIT_TO_VAR_BIT 1021
#define INT_NOT_VAR_BIT_TO_VAR_BIT 1022
#define INT_XOR_VAR_BIT_TO_VAR_BIT 1023

#endif
#ifdef TABLE_IN_FLASH
#define INT_FLASH_INIT 1003
#define INT_FLASH_READ 1004
Expand Down
2 changes: 1 addition & 1 deletion ldmicro/iolist.cpp
Expand Up @@ -858,7 +858,7 @@ void SaveIoListToFile(FILE *f)
// Don't internationalize this! It's the file format, not UI.
if(Prog.mcu && (Prog.mcu->whichIsa == ISA_PC) && (Prog.io.assignment[i].pin))
fprintf(f, " %s at %s\n", Prog.io.assignment[i].name, PinToName(Prog.io.assignment[i].pin));
else // if(TRUE || (Prog.io.assignment[i].type != IO_TYPE_PWM_OUTPUT))
else
fprintf(f,
" %s at %d %d %d\n",
Prog.io.assignment[i].name,
Expand Down
12 changes: 8 additions & 4 deletions ldmicro/ldinterpret.c
Expand Up @@ -217,6 +217,7 @@ void Disassemble()
case INT_SET_VARIABLE_SUBTRACT: c = '-'; goto arith;
case INT_SET_VARIABLE_MULTIPLY: c = '*'; goto arith;
case INT_SET_VARIABLE_DIVIDE: c = '/'; goto arith;
case INT_SET_VARIABLE_MOD: c = '%'; goto arith;
arith:
printf("int16s[%03x] := int16s[%03x] %c int16s[%03x]",
p->name1, p->name2, c, p->name3);
Expand Down Expand Up @@ -317,10 +318,13 @@ void InterpretOneCycle()
break;

case INT_SET_VARIABLE_DIVIDE:
if(Integers[p->name3] != 0) {
Integers[p->name1] = Integers[p->name2] /
Integers[p->name3];
}
if(Integers[p->name3] != 0)
Integers[p->name1] = Integers[p->name2] / Integers[p->name3];
break;

case INT_SET_VARIABLE_MOD:
if(Integers[p->name3] != 0)
Integers[p->name1] = Integers[p->name2] % Integers[p->name3];
break;

case INT_IF_BIT_SET:
Expand Down
2 changes: 1 addition & 1 deletion ldmicro/ldmicro.h
Expand Up @@ -1771,7 +1771,7 @@ int SetMemForVariable(char *name, DWORD addr, int sizeOfVar);
int MemOfVar(char *name, DWORD *addr);
BYTE MuxForAdcVariable(const char *name);
int SingleBitAssigned(const char *name);
int GetAssignedType(const char *name);
int GetAssignedType(const char *name, const char *fullName);
void AddrBitForPin(int pin, DWORD *addr, int *bit, BOOL asInput);
void MemForSingleBit(const char *name, BOOL forRead, DWORD *addr, int *bit);
void MemForSingleBit(const char *name, DWORD *addr, int *bit);
Expand Down
4 changes: 2 additions & 2 deletions ldmicro/ldversion.h
@@ -1,11 +1,11 @@
#ifndef __LDMICRO_VER_H__
#define __LDMICRO_VER_H__

#define LDMICRO_VER_STR "4.3.8.5" //---+
#define LDMICRO_VER_STR "4.3.8.6" //---+
// |
#define LDMICRO_VER_MAJOR (4) //<--|
#define LDMICRO_VER_MINOR (3) //<--|
#define LDMICRO_VER_PATCH (8) //<--|
#define LDMICRO_VER_TWEAK (5) //<--+
#define LDMICRO_VER_TWEAK (6) //<--+

#endif

0 comments on commit ce2c823

Please sign in to comment.