inital commit

This commit is contained in:
7u83 2024-07-01 20:48:39 +02:00
parent f1853c097c
commit 92144104ec
7 changed files with 234 additions and 0 deletions

2
bcd.h
View File

@ -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; 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); 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 #endif

33
long_add.c Normal file
View File

@ -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;
}

24
long_rlc__.c Normal file
View File

@ -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;
}

29
long_rrc__.c Normal file
View File

@ -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;
}

33
long_tobcd.c Normal file
View File

@ -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;
}

92
long_tobcd__.c Normal file
View File

@ -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;
}

21
usebank0.h Normal file
View File

@ -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