comparison src/varargs.inc @ 634:4050675965ea

3.10 stable release
author heinrichsweikamp
date Tue, 28 Apr 2020 17:34:31 +0200
parents c40025d8e750
children 75e90cd0c2c3
comparison
equal deleted inserted replaced
633:690c48db7b5b 634:4050675965ea
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File varargs.inc combined next generation V3.0.1 3 ; File varargs.inc * combined next generation V3.0.1
4 ; 4 ;
5 ; Utilities to pass multiple arguments in compact code stream. 5 ; Utilities to pass multiple arguments in compact code stream.
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-05-27 : [jDG] Creation. 10 ; 2011-05-27 : [jDG] Creation.
11 ; 11 ;
12 12
13
14 ;-----------------------------------------------------------------------------
15 ; Prepare reading inline Data: set Table Pointer to the Beginn of the inline Data
16 ;
13 VARARGS_BEGIN macro 17 VARARGS_BEGIN macro
14 movff TOSL, TBLPTRL 18 movff TOSL, TBLPTRL ; copy program counter address to table pointer
15 movff TOSH, TBLPTRH 19 movff TOSH, TBLPTRH ; ...
16 movff TOSU, TBLPTRU 20 movff TOSU, TBLPTRU ; ...
17 endm 21 endm
18 22
19 VARARGS_GET8 macro register 23
20 tblrd*+ 24 ;-----------------------------------------------------------------------------
21 movff TABLAT, register 25 ; Read 1 Byte of inline Data
26 ;
27 VARARGS_GET8 macro register
28 tblrd*+ ; read 1 byte from program memory
29 movff TABLAT, register ; store to register
22 endm 30 endm
23 31
32
33 ;-----------------------------------------------------------------------------
34 ; Read 2 Bytes of inline Data
35 ;
24 VARARGS_GET16 macro register 36 VARARGS_GET16 macro register
25 tblrd*+ 37 tblrd*+ ; read 1st byte from program memory
26 movff TABLAT, register+0 38 movff TABLAT, register+0 ; store to register
27 tblrd*+ 39 tblrd*+ ; read 2nd byte from program memory
28 movff TABLAT, register+1 40 movff TABLAT, register+1 ; store to register
29 endm 41 endm
30 42
43
44 ;-----------------------------------------------------------------------------
45 ; Read 3 Bytes of inline Data
46 ;
31 VARARGS_GET24 macro register 47 VARARGS_GET24 macro register
32 tblrd*+ 48 tblrd*+ ; read 1st byte from program memory
33 movff TABLAT, register+0 49 movff TABLAT, register+0 ; store to register
34 tblrd*+ 50 tblrd*+ ; read 2nd byte from program memory
35 movff TABLAT, register+1 51 movff TABLAT, register+1 ; store to register
36 tblrd*+ 52 tblrd*+ ; read 3rd byte from program memory
37 movff TABLAT, register+2 53 movff TABLAT, register+2 ; store to register
38 endm 54 endm
39 55
56
57 ;-----------------------------------------------------------------------------
58 ; Align Table Pointer to an even Address
59 ;
40 VARARGS_ALIGN macro 60 VARARGS_ALIGN macro
41 local no_tblptr_align 61 btfsc TBLPTRL,0 ; table pointer pointing to an even address?
42 62 tblrd*+ ; NO - do a dummy read to advance to next even address
43 btfss TBLPTRL,0
44 bra no_tblptr_align
45 incf TBLPTRL
46 movlw 0
47 addwfc TBLPTRH
48 addwfc TBLPTRU
49 no_tblptr_align:
50 endm 63 endm
51 64
65
66 ;-----------------------------------------------------------------------------
67 ; End reading inline Data: set Return Address behind End of the inline Data
68 ;
52 VARARGS_END macro 69 VARARGS_END macro
53 ; compute string length (modulo 256): 70 movf TOSL,W ; compute how may inline bytes have been read
54 movf TOSL,W 71 subwf TBLPTRL,W ; WREG = (TBLPTRL - TOSL) modulo 256
55 subwf TBLPTRL,W 72 addwf TOSL,F ; advance the return address by this number
56 73 movlw 0 ; ...
57 ; then 24 bit add to return address 74 addwfc TOSH,F ; ...
58 addwf TOSL,F 75 addwfc TOSU,F ; ...
59 movlw 0 ; clear WREG, but keep carry
60 addwfc TOSH,F
61 addwfc TOSU,F
62 endm 76 endm