From 92144104ecb919b02454030b34f278e80ed54701 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Mon, 1 Jul 2024 20:48:39 +0200 Subject: [PATCH] inital commit --- bcd.h | 2 ++ long_add.c | 33 ++++++++++++++++++ long_rlc__.c | 24 +++++++++++++ long_rrc__.c | 29 ++++++++++++++++ long_tobcd.c | 33 ++++++++++++++++++ long_tobcd__.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ usebank0.h | 21 ++++++++++++ 7 files changed, 234 insertions(+) create mode 100644 long_add.c create mode 100644 long_rlc__.c create mode 100644 long_rrc__.c create mode 100644 long_tobcd.c create mode 100644 long_tobcd__.c create mode 100644 usebank0.h diff --git a/bcd.h b/bcd.h index 279a076..6a954e8 100644 --- a/bcd.h +++ b/bcd.h @@ -10,5 +10,7 @@ void bcd_invert(__idata uint8_t *v1, uint8_t len); void bcd_addbyte(__idata uint8_t *v1, uint8_t len, uint8_t b) __reentrant; uint8_t bcd_getsig(__idata uint8_t*v, uint8_t len); +void long_tobcd(__idata uint8_t *binval, __idata uint8_t *bcdval, uint8_t binlen, uint8_t bcdlen) __reentrant; + #endif diff --git a/long_add.c b/long_add.c new file mode 100644 index 0000000..b80ebd6 --- /dev/null +++ b/long_add.c @@ -0,0 +1,33 @@ +#include "mc8051fun.h" +#include "bcd.h" + +#pragma disable_warning 59 // Disable "must return a value" warning + +uint8_t long_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentrant +{ + (void)v1; (void)v2; (void)len; + __asm + mov a,_bp + add a,#0xfd + mov sp,a + pop ar1 + pop ar7 + mov ar0,dpl + clr c +001$: + mov a,@r0 + addc a,@r1 + mov @r0,a + inc r0 + inc r1 + djnz r7,001$ + mov dpl,#0x00 + jnc $002 + inc dpl +$002: + mov sp,_bp + __endasm; +} + + + diff --git a/long_rlc__.c b/long_rlc__.c new file mode 100644 index 0000000..b4bdb7a --- /dev/null +++ b/long_rlc__.c @@ -0,0 +1,24 @@ + +/* + * @r0 = number + * r7 = len + * + * modyfies: r0,r7,a + */ +static void long_rlc__() __naked +{ + __asm + .globl long_rlc + +long_rlc: + mov a,@r0 + rlc a + mov @r0,a + inc r0 + djnz r7,long_rlc + ret + + __endasm; +} + + diff --git a/long_rrc__.c b/long_rrc__.c new file mode 100644 index 0000000..d9b775c --- /dev/null +++ b/long_rrc__.c @@ -0,0 +1,29 @@ + +/* + * @r0 = number + * r7 = len + * + * modyfies: r0,r7,a + */ +static void long_rrc__() __naked +{ + __asm + .globl long_rrc +long_rrc: + push PSW + mov a,r0 + add a,r7 + mov r0,a + pop PSW +001$: + dec r0 + mov a,@r0 + rrc a + mov @r0,a + djnz r7,001$ + ret + + __endasm; +} + + diff --git a/long_tobcd.c b/long_tobcd.c new file mode 100644 index 0000000..f698d8e --- /dev/null +++ b/long_tobcd.c @@ -0,0 +1,33 @@ + +#include "mc8051fun.h" + +/* + * C-Wrapper for long_tobcd + */ + +void long_tobcd(__idata uint8_t *binval, __idata uint8_t *bcdval, uint8_t binlen, uint8_t bcdlen) __reentrant +{ + (void)binval; + (void)bcdval; + (void)binlen; + (void)bcdlen; + + __asm + mov a,_bp + add a,#0xfd + mov r0,a + mov a,@r0 + mov r1,a + dec r0 + mov a,@r0 + mov r7,a + dec r0 + mov a,@r0 + mov r6,a + mov r0,dpl + lcall long_tobcd + + __endasm; +} + + diff --git a/long_tobcd__.c b/long_tobcd__.c new file mode 100644 index 0000000..ab7d4da --- /dev/null +++ b/long_tobcd__.c @@ -0,0 +1,92 @@ + +/* +r0 = bin +r1 = bcd +r7 = len of bin +r6 = len of bcd +*/ + +#include "mc8051fun.h" + +#include "usebank0.h" + +// double dabble + +void long_tobcd__() __naked +{ + __asm + .globl long_tobcd + +long_tobcd: + + ; fill dst with zeroes + + mov r3,AR1 ; save r1 in r3 + mov r4,AR6 ; use r4 as counter +; mov a,#0x00 + +000$: + mov @r1,#0x0 + inc r1 + djnz r4,000$ + + + + mov a,r0 + add a,r7 + dec a + mov r0,a ; r0 points to last byte of bin + mov r2,AR0 ; save r0 in r2 + +006$: + mov a,@r0 + mov r5,#0x08 +005$: + mov r4,AR6 ; use r4 as counter + mov r1,AR3 + + push ACC +004$: + mov a,@r1 + acall 003$ + acall 003$ + mov @r1,a + inc r1 + djnz r4,004$ + + pop ACC + + + rlc a + push ACC + push AR0 + push AR7 + mov r7,AR6 + mov r0,AR3 + lcall long_rlc + pop AR7 + pop AR0 + pop ACC + djnz r5,005$ + + + dec r0 + djnz r7,006$ + ret + + +003$: + swap a + clr c + subb a,#0x50 + jc 002$ + add a,#0x30 +002$: + add a,#0x50 + ret + +__endasm; +} + + + diff --git a/usebank0.h b/usebank0.h new file mode 100644 index 0000000..f7228ed --- /dev/null +++ b/usebank0.h @@ -0,0 +1,21 @@ + +#undef AR0 +#undef AR1 +#undef AR2 +#undef AR3 +#undef AR4 +#undef AR5 +#undef AR6 +#undef AR7 + + +#define AR0 0x00 +#define AR1 0x01 +#define AR2 0x02 +#define AR3 0x03 +#define AR4 0x04 +#define AR5 0x05 +#define AR6 0x06 +#define AR7 0x07 + +