Mercurial > public > hwos_code
diff src/varargs.inc @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | c40025d8e750 |
children | 75e90cd0c2c3 |
line wrap: on
line diff
--- a/src/varargs.inc Thu Mar 05 15:06:14 2020 +0100 +++ b/src/varargs.inc Tue Apr 28 17:34:31 2020 +0200 @@ -1,6 +1,6 @@ ;============================================================================= ; -; File varargs.inc combined next generation V3.0.1 +; File varargs.inc * combined next generation V3.0.1 ; ; Utilities to pass multiple arguments in compact code stream. ; @@ -10,53 +10,67 @@ ; 2011-05-27 : [jDG] Creation. ; + +;----------------------------------------------------------------------------- +; Prepare reading inline Data: set Table Pointer to the Beginn of the inline Data +; VARARGS_BEGIN macro - movff TOSL, TBLPTRL - movff TOSH, TBLPTRH - movff TOSU, TBLPTRU + movff TOSL, TBLPTRL ; copy program counter address to table pointer + movff TOSH, TBLPTRH ; ... + movff TOSU, TBLPTRU ; ... endm -VARARGS_GET8 macro register - tblrd*+ - movff TABLAT, register + +;----------------------------------------------------------------------------- +; Read 1 Byte of inline Data +; +VARARGS_GET8 macro register + tblrd*+ ; read 1 byte from program memory + movff TABLAT, register ; store to register endm + +;----------------------------------------------------------------------------- +; Read 2 Bytes of inline Data +; VARARGS_GET16 macro register - tblrd*+ - movff TABLAT, register+0 - tblrd*+ - movff TABLAT, register+1 + tblrd*+ ; read 1st byte from program memory + movff TABLAT, register+0 ; store to register + tblrd*+ ; read 2nd byte from program memory + movff TABLAT, register+1 ; store to register endm + +;----------------------------------------------------------------------------- +; Read 3 Bytes of inline Data +; VARARGS_GET24 macro register - tblrd*+ - movff TABLAT, register+0 - tblrd*+ - movff TABLAT, register+1 - tblrd*+ - movff TABLAT, register+2 + tblrd*+ ; read 1st byte from program memory + movff TABLAT, register+0 ; store to register + tblrd*+ ; read 2nd byte from program memory + movff TABLAT, register+1 ; store to register + tblrd*+ ; read 3rd byte from program memory + movff TABLAT, register+2 ; store to register endm + +;----------------------------------------------------------------------------- +; Align Table Pointer to an even Address +; VARARGS_ALIGN macro - local no_tblptr_align - - btfss TBLPTRL,0 - bra no_tblptr_align - incf TBLPTRL - movlw 0 - addwfc TBLPTRH - addwfc TBLPTRU -no_tblptr_align: + btfsc TBLPTRL,0 ; table pointer pointing to an even address? + tblrd*+ ; NO - do a dummy read to advance to next even address endm + +;----------------------------------------------------------------------------- +; End reading inline Data: set Return Address behind End of the inline Data +; VARARGS_END macro - ; compute string length (modulo 256): - movf TOSL,W - subwf TBLPTRL,W - - ; then 24 bit add to return address - addwf TOSL,F - movlw 0 ; clear WREG, but keep carry - addwfc TOSH,F - addwfc TOSU,F + movf TOSL,W ; compute how may inline bytes have been read + subwf TBLPTRL,W ; WREG = (TBLPTRL - TOSL) modulo 256 + addwf TOSL,F ; advance the return address by this number + movlw 0 ; ... + addwfc TOSH,F ; ... + addwfc TOSU,F ; ... endm