Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Insertchar is different in 2085 as in 2084

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
MichaelB.

Bascom Member



Joined: 04 May 2017
Posts: 58

germany.gif
PostPosted: Wed Jan 05, 2022 9:31 pm    Post subject: Insertchar is different in 2085 as in 2084 Reply with quote

I was trying to Figure out the hole Day why my Code isnt Working in 2085 as in 2084.
The Point is that i found a Issue with the INSERTCHAR.
In 2084 , "A" was shown "333333"
In 2085 , "A" is shown "333330"

Michael

Code:

$regfile = "m128def.dat"
$crystal = 7372800
$baud = 9600
$hwstack = 30
$swstack = 20
$framesize = 100
$Sim

Dim Pos as Byte
Dim A as String * 6
Dim Input as String * 1

Pos = 1
A = "ÿÿÿÿÿÿ"
B = "3"

DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B


(BASCOM-AVR version : 2.0.8.5 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Jan 06, 2022 9:59 am    Post subject: Reply with quote

your sample does not work. i had to modify it. but then it shows a problem : the last character can not be inserted.
as a tip ; you can use mid() statement. this also saves you from delchar first.
anyway this is a bug of course. when the code was changed to allow bigstrings and was also made safe to not allow writing beyond the string, an error was introduced. so the order of the test must be changed.
here is a modified routine. just replace it with the one from mcs.lib and compile the lib

[_INSERTCHAR]
; r20 contains char,r24r25 index,X points to the string
_insertchar0:
Clr R25 ; version without bigstring
_insertchar:
#IF _xmega
* In r23,RAMPZ
Clr r16
* Out RAMPZ,R16
#ENDIF
cpi r24,0 ; check index
brne _InsertChar1 ; not zero
cpi r25,0 ; check both zero
brne _InsertChar1 ; ok
ret ; zero not allowed

_insertchar1a:
cpi r16,0 ; end of string ?
breq _InsertChar2 ; yes so exit

_insertchar1:
ld r16,x+ ; load data
sbiw r24,1 ; dec index
brne _InsertChar1a ; for total index

sbiw r26,1 ; compensate
movw r30,r26 ; copy pointer X to Z
_InsertChar3:
ld r17,z+ ; get byte
st x+,r20 ; write the data
cpi r20,0 ; done when zero
breq _InsertChar2
mov r20,r17 ; now copy the previous saved data
rjmp _InsertChar3 ; and copy all the remaining data
_InsertChar2:
#IF _XMEGA
*OUT RAMPZ,R23
#ENDIF
ret
[END]


and here is your sample i changed to work :

Code:
$regfile = "m128def.dat"
$crystal = 7372800
$baud = 9600
$hwstack = 30
$swstack = 20
$framesize = 100
$Sim
'$lib "mcs.lib"

Dim Pos As Byte
Dim Satelit1 As String * 6
'Dim Input As String * 1
Dim B As Byte
Pos = 1
Satelit1 = "ÿÿÿÿÿ"
B = "3"

'Insertchar Satelit1 , 6 , B
Insertchar Satelit1 , 7 , B

Delchar Satelit1 , 6 : Insertchar Satelit1 , Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
Delchar Satelit1 , 6 : Insertchar Satelit1 , Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
DELCHAR Satelit1 , 6 : INSERTCHAR Satelit1, Pos , B
Incr Pos
Delchar Satelit1 , 6
Insertchar Satelit1 , Pos , B
Print Satelit1
End
 

_________________
Mark
Back to top
View user's profile Visit poster's website
MichaelB.

Bascom Member



Joined: 04 May 2017
Posts: 58

germany.gif
PostPosted: Thu Jan 06, 2022 3:25 pm    Post subject: Reply with quote

Thank you Mark. Smile
Back to top
View user's profile
MichaelB.

Bascom Member



Joined: 04 May 2017
Posts: 58

germany.gif
PostPosted: Thu Jan 06, 2022 4:07 pm    Post subject: Reply with quote

You know what, the Libmanager wants a Text file. So i saved your Assembler code in a Text File and want to Add it to the MCSlib, after i deleted the "old" _Insertchar Funktion.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Jan 06, 2022 4:14 pm    Post subject: Reply with quote

you best replace the code with notepad or with bascom editor (make sure lib is not reformatted).
or simply save the routine in notepad with a new name like : "mynewcode.lib"
then use $lib to include this code instead of the code from mcs
but the best way is to used the editor, select the old text, delete it, and then paste the code from this topic.

i will check what you tried later.

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Jan 06, 2022 5:36 pm    Post subject: Reply with quote

First step->



You can always back because you have copy Wink

Second step->



Third->



After save you can compile lib with Lib manager. All steps takes about 1min max Very Happy
Back to top
View user's profile Visit poster's website
MichaelB.

Bascom Member



Joined: 04 May 2017
Posts: 58

germany.gif
PostPosted: Thu Jan 06, 2022 6:11 pm    Post subject: Reply with quote

Exelent
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Jan 06, 2022 9:19 pm    Post subject: Reply with quote

Indeed excellent. fully agree.

i added add from clipboard for a next release. that makes it simpler.
and i fixed a bug with [end]

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum