--_002_alpineLNX200170809004036022279tinallotropenet_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I agree with Bob, use two offsets pointer_in and pointer_out (or as I like= =20 to call them "head" and "tail") The only complicated bit is to then map these offsets into your real RAM.=20 But as Bob has shown this simply means loading the offset, mapping it=20 (with his 4 instruction code) and saving this address into the FSR before=20 loading a byte from the buffer or saving a byte to the buffer (using=20 INDF). The rest of FIFO read and write then becomes trivial. Just remember: DON'T update "head" and "tail" until after you've read or=20 written the byte to or from the buffer. Regards Sergio Masci On Tue, 8 Aug 2017, Bob Ammerman wrote: > Why are you keeping an offset from pointer_in, instead of just keeping > pointer_out as a virtual pointer in its own right? > > ~ Bob Ammerman > RAm Systems > >> -----Original Message----- >> From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf >> Of noname >> Sent: Tuesday, August 08, 2017 3:55 PM >> To: Microcontroller discussion list - Public. >> Subject: Re: [PIC] pic16f628a memory bank switching in a large circular > buffer. >> >> Follow up question: >> >> >> Following the same method as outlined by Bob, is it possible to map the >> (absolute) pointer_out directly from (abs) pointer_in? I have tried > several >> ways on paper, but I do not get to a simple solution. >> >> >> So starting with a valid (abs) pointer_in (mapped in the range 0x20-0x6F > or >> 0xA0-0xEF) >> >> I need to add the offset that can be anything between 0 and 0xA0, and th= en >> account for =B4bankgaps=B4 and finally land in the same range 0x20-0x6F = and >> 0xA0-0xEF . I tried something by adding 0xB0 to the offset (is it smalle= r > or >> larger than 50?) but I diverge in such bookkeeping I cannot oversee. >> >> >> My current code utilises the virtual pointer_in as reference, but I thin= k > I can >> go even faster if I took the absolute pointer_in as reference. >> >> Nonetheless my code is some 30% smaller now: >> >> >> Current code: >> >> >> getpointers_table160 >> decfsz virt_pointer_in, w ; if 0 th= en > point to top of the >> buffer again >> goto _skipifset ; = if > not 0 then skip next line >> addlw CIRCULAR_BUFFER_LENGTH ; + 0xA0 >> _skipifset >> movwf virt_pointer_in ; wreg > holds the current >> virt_pointer_in minus 1 >> >> addlw h'B0'-1 ; > carry set if bank1 >> btfsc STATUS,C >> addlw h'30' >> addlw h'70' = ; > bank set 0x20-6F or 0xA0-EF >> movwf pointer_in ; now > wreg holds the abs value of >> pointer_in >> >> > ; calc the pointer out >> movf pointer_offset, w ; offse= t > from 0 to 0xA0 >> addwf virt_pointer_in, w ; > virt_pointer_in is used as ref >> here >> btfsc STATUS, C >> addlw h'60' >> addlw h'60' - 1 ; > Carry is set if >0xff >> btfss STATUS, C >> addlw h'A0' >> >> > ; At this point wreg =3D virtual >> pointer_out >> addlw h'B0' ; carry set if bank1 >> btfsc STATUS,C >> addlw h'30' >> addlw h'70' ; bank set 0x20-6F or 0x80-EF >> movwf pointer_out >> return >> >> >> >> >> >> ________________________________ >> Van: piclist-bounces@mit.edu namens Bob >> Ammerman >> Verzonden: maandag 7 augustus 2017 19:52 >> Aan: 'Microcontroller discussion list - Public.' >> Onderwerp: RE: [PIC] pic16f628a memory bank switching in a large circula= r >> buffer. >> >> NOTE: all numbers are in HEX below. The trick below >> works because we are working MODULO 100 hex. >> >> Input: W is a pointer ranging from 00h thru 9Fh >> Output: W points to the correct register in bank 0 or 1 >> >> ; At entry, the value of W is as follows: >> ; 00..4F - we want to map to page 0 addresses 20..6F ; 50..9F - we wan= t > to >> map to page 1 addresses A0..EF >> >> ; We start by adding B0. This will set STATUS,C to 1, ; if we have a pag= e > 1 >> address, and to 0 if we have a ; page 0 address. After this add, we will > have: >> ; B0..FF - which we want to map to page 0 addresses 20..6F ; 00..4F - > which >> we want to map to page 1 addresses A0..EF >> >> ADDLW 0B0h >> >> ; Now, if carry is set, we add 30. After this conditional ; add, we will > have: >> ; B0..FF - which we want to map to page 0 addresses 20..6F ; 30..7F - > which >> we want to map to page 1 addresses A0..EF >> >> BTFSC STATUS,C >> ADDLW 030h >> >> ; One more add gives us our answer. By adding 70 we get: >> ; 20..6F for page 0 addresses >> ; A0..EF for page 1 addresses >> >> ADDLW 070h >> >> -- Problem solved in 4 instructions! >> >> ~ Bob Ammerman >> RAm Systems >> >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive PIClist= , >> Microchip PIC >> www.piclist.com >> The PICList is a collection of people interested in the Microchip PIC > processor. >> >> >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist > > > --=20 > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist >= --_002_alpineLNX200170809004036022279tinallotropenet_ Content-Type: text/plain; name="ATT00001.txt" Content-Description: ATT00001.txt Content-Disposition: attachment; filename="ATT00001.txt"; size=224; creation-date="Tue, 08 Aug 2017 22:54:20 GMT"; modification-date="Tue, 08 Aug 2017 22:54:20 GMT" Content-Transfer-Encoding: base64 LS0gDQpodHRwOi8vd3d3LnBpY2xpc3QuY29tL3RlY2hyZWYvcGljbGlzdCBQSUMvU1ggRkFRICYg bGlzdCBhcmNoaXZlDQpWaWV3L2NoYW5nZSB5b3VyIG1lbWJlcnNoaXAgb3B0aW9ucyBhdA0KaHR0 cDovL21haWxtYW4ubWl0LmVkdS9tYWlsbWFuL2xpc3RpbmZvL3BpY2xpc3QNCg== --_002_alpineLNX200170809004036022279tinallotropenet_-- .