PDA

View Full Version : Code in PBPPI18L.LIB, can I ?



amgen
- 23rd September 2011, 13:48
Trying to have ARRAYREAD read more than 255 chars and in LIB, R6, the max char counter is word and only used as byte for max parse.
Would changing the DECREMENT to 16 bit work without messing up something ?


ArrayRead in LIB 18L

;************************************************* ***************
;* ARRAYREAD : Read char from array *
;* *
;* Input : R5 = pointer to next char in array *
;* : R6 = number of chars left in array (timeout) *
;* Output : W *
;* *
;* Notes : C clear if timed out. *
;************************************************* ***************
ifdef ARRAYREADTO_USED
LIST
ARRAYREADTO movf R6, F ; Check for no chars left in array
bcf STATUS, C ; Preset for timed out (C clear)
bz arrayreaddone ; No chars left
decf R6, F ; Count down the characters left and fall through to ARRAYREAD
NOLIST
ARRAYREAD_USED = 1
endif



Code to DECREMENT 16 bit val,

The Decrement of a 16 Bit value isn't quite so simple:




CODE





movf Reg, f ;Set "Z" if LOW "Reg" == 0
btfsc STATUS, Z
decf Reg + 1, f ; If Low byte is Zero, Decrement High
decf Reg, f













To make count up to 16bit

To make count up to 16bit

 
ifdef ARRAYREADTO_USED
LIST
ARRAYREADTO movf R6, F ; Check for no chars left in array
bcf STATUS, C ; Preset for timed out (C clear)
bz arrayreaddone ; No chars left

movf R6, f ; Set "Z" if LOW "Reg" == 0
btfsc STATUS, Z
decf R6 + 1, f ; If Low byte is Zero, Decrement High
decf R6, f

NOLIST
ARRAYREAD_USED = 1
endif












I want to check with experts before I screw things up.
Thanks
Don
amgen

amgen
- 23rd September 2011, 21:03
Are you even allowed to reply to your own thread. Seems like talking to yourself..Oh well....

Tried successfully to make MAX chars to word, although all you can have 500, 1000 or 2000 array depending on ram (I think),


;************************************************* ***************
;* ARRAYREAD : Read char from array *
;* *
;* Input : R5 = pointer to next char in array *
;* : R6 = number of chars left in array (timeout) *
;* Output : W *
;* *
;* Notes : C clear if timed out. *
;************************************************* ***************
ifdef ARRAYREADTO_USED
LIST
ARRAYREADTO movf R6, F ; Check for no chars left in array
bcf STATUS, C ; Preset for timed out (C clear)
btfsc STATUS, Z
movf R6+1, F
bz arrayreaddone ; No chars left

movf R6, F ; Set "Z" if LOW "Reg" == 0
btfsc STATUS, Z
decf R6+1, F ; If Low byte is Zero, Decrement High
decf R6, F ; Count down the characters left and fall through to ARRAYREAD
NOLIST
ARRAYREAD_USED = 1
endif



arrayread arr1,500,done,[wait("123qwe")]

Don
(does anyone see redundent code ?)

Darrel Taylor
- 28th September 2011, 17:40
Well, I don't see redundant code. But there's probably not enough code.
I was running it in proteus and found that it stops reading the array whenever a borrow occurs from the high byte of R6.

At points like 1023, 767, 511, 255 bytes remaining, it exits the ARRAYREAD.

It uses the carry flag (STATUS,C) to indicate the "Timeout", which should only be cleared when both bytes are 0.

HTH,

amgen
- 28th September 2011, 18:48
Preface...... I think,

Max readarray would/could TRY to be 65K, (word)...... too long for any possible array to read in PIC.
So, is your check looping thru 64KB ??? (I assssume no one wants to parse flash)

example of my code

array1Test: ' arr1 has INDX chars that is < ARR1[declared legnth]
Flag1=0
arrayread arr1,INDX,done,[wait("1qwe")]:Flag1=1 'found match
done: 'no match

My little array is 1000, and the arrayread matched the match anywhere from begining to the end.
But, I was wondering if a "MATCH-TO-EXIT" compare char code, could be added. Like arraywrite, then tested on each pass, without extensive code addition.

Then it would be;
ARRAYREAD array_to_read, max_legnth, compare_char_to_exit, escape_labl[.....xyz....]

As you stated somewhere, array read & write is making string usage much more practical.
Don

amgen
- 28th September 2011, 19:43
forget misinterpreted last post,
not sure if you saw,
In second post I had added the check for 16 bit =0,at top of routine, few lines asm for that

LIST
ARRAYREADTO movf R6, F ; Check for no chars left in array hi & low R6
bcf STATUS, C ; Preset for timed out (C clear)
btfsc STATUS, Z ; Set "Z" if LOW "Reg" == 0
movf R6+1, F
bz arrayreaddone ; No chars left
movf R6, F
btfsc STATUS, Z ;decrement high and low
decf R6+1, F ;If Low byte is Zero, Decrement High
decf R6, F ; Count down the characters left and fall through to ARRAYREAD

NOLISTARRAYREAD_USED = 1
endif


hard to format text in code window.
Don

Darrel Taylor
- 29th September 2011, 00:21
OK, and you can forget my misinterpreted last post too. :o
After further testing, your changes do work as advertised. My test was flawed.

Back to the redundant code question, I think you can save 1 WORD by changing the second part to ...

; movf R6, F
decf R6, F ; Count down the characters left and fall through to ARRAYREAD
btfss STATUS, C ; If Low byte borrowed
decf R6+1, F ; Decrement High

It's not much, but ...

Darrel Taylor
- 29th September 2011, 18:00
Don,

Would you like melabs to include your changes in the next update to PBP3?

amgen
- 29th September 2011, 19:36
By all means,
I would feel honored.

Don

ShoKre
- 13th June 2014, 13:54
Hi, I just seen this post, but i already post my problem (http://www.picbasic.co.uk/forum/showthread.php?p=127378#post127378) regarding array.0(word-sized-variable)
as this isue is similar for reading, can someone give me hint how can we patch writing routine
to have array.0(word-sized-variable) working, as now only byte size index works....

regards, & thenx for any kind oh help