0
|
1 ;=============================================================================
|
|
2 ;
|
634
|
3 ; File varargs.inc * combined next generation V3.0.1
|
0
|
4 ;
|
|
5 ; Utilities to pass multiple arguments in compact code stream.
|
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2011-05-27 : [jDG] Creation.
|
|
11 ;
|
|
12
|
634
|
13
|
|
14 ;-----------------------------------------------------------------------------
|
|
15 ; Prepare reading inline Data: set Table Pointer to the Beginn of the inline Data
|
|
16 ;
|
604
|
17 VARARGS_BEGIN macro
|
634
|
18 movff TOSL, TBLPTRL ; copy program counter address to table pointer
|
|
19 movff TOSH, TBLPTRH ; ...
|
|
20 movff TOSU, TBLPTRU ; ...
|
604
|
21 endm
|
0
|
22
|
634
|
23
|
|
24 ;-----------------------------------------------------------------------------
|
|
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
|
604
|
30 endm
|
0
|
31
|
634
|
32
|
|
33 ;-----------------------------------------------------------------------------
|
|
34 ; Read 2 Bytes of inline Data
|
|
35 ;
|
604
|
36 VARARGS_GET16 macro register
|
634
|
37 tblrd*+ ; read 1st byte from program memory
|
|
38 movff TABLAT, register+0 ; store to register
|
|
39 tblrd*+ ; read 2nd byte from program memory
|
|
40 movff TABLAT, register+1 ; store to register
|
604
|
41 endm
|
0
|
42
|
634
|
43
|
|
44 ;-----------------------------------------------------------------------------
|
|
45 ; Read 3 Bytes of inline Data
|
|
46 ;
|
604
|
47 VARARGS_GET24 macro register
|
634
|
48 tblrd*+ ; read 1st byte from program memory
|
|
49 movff TABLAT, register+0 ; store to register
|
|
50 tblrd*+ ; read 2nd byte from program memory
|
|
51 movff TABLAT, register+1 ; store to register
|
|
52 tblrd*+ ; read 3rd byte from program memory
|
|
53 movff TABLAT, register+2 ; store to register
|
604
|
54 endm
|
0
|
55
|
634
|
56
|
|
57 ;-----------------------------------------------------------------------------
|
|
58 ; Align Table Pointer to an even Address
|
|
59 ;
|
604
|
60 VARARGS_ALIGN macro
|
634
|
61 btfsc TBLPTRL,0 ; table pointer pointing to an even address?
|
|
62 tblrd*+ ; NO - do a dummy read to advance to next even address
|
604
|
63 endm
|
0
|
64
|
634
|
65
|
|
66 ;-----------------------------------------------------------------------------
|
|
67 ; End reading inline Data: set Return Address behind End of the inline Data
|
|
68 ;
|
0
|
69 VARARGS_END macro
|
634
|
70 movf TOSL,W ; compute how may inline bytes have been read
|
|
71 subwf TBLPTRL,W ; WREG = (TBLPTRL - TOSL) modulo 256
|
|
72 addwf TOSL,F ; advance the return address by this number
|
|
73 movlw 0 ; ...
|
|
74 addwfc TOSH,F ; ...
|
|
75 addwfc TOSU,F ; ...
|
604
|
76 endm
|