2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 Desc: BCPL stubs that call into Exec and Dos libraries.
9 #include <aros/m68k/asm.h>
13 #define BCPL(id,name) .equ GV_##name, id
17 #define MAXARGS (1 + 26) /* Up to 26 arguments to the format */
19 /* BCPL writef format strings:
22 * %S - Send argument to writes(BSTR)
23 * %Tn - Send argument and n to writet(BSTR, n)
24 * %C - Send argument to wrch(LONG)
25 * %Bn - Send argument and n to writebin(LONG, n)
26 * %On - Send argument and n to writeoct(LONG, n)
27 * %Xn - Send argument and n to writehex(LONG, n)
28 * %In - Send argument and n to writei(LONG, n)
29 * %N - Send argument to writei(LONG, 0)
38 * A1[0] - BSTR Format (also in D1)
39 * A1[1..] - LONG Arguments
43 * A7 - C stack pointer
47 move.l %d1, %d6 /* D6 = Format pointer - 1 */
52 move.l #(3*4 + MAXARGS*4),%d0
53 move.l %a2@(GV_wrch),%a4
56 move.l #(3*4 + MAXARGS*4),%d0
57 move.l %a2@(GV_writes),%a4
60 move.l #(3*4 + MAXARGS*4),%d0
61 move.l %a2@(GV_wrch),%a4
63 move.l #(3*4 + MAXARGS*4),%d0
64 move.l %a2@(GV_newline),%a4
69 clr.l %d5 /* D5 = Format Length */
72 /* Zero length format - nothing to do */
73 tst %d5 /* Done already? */
76 clr.l %d4 /* D4 = Arg Index */
78 addq.l #1, %d6 /* D6 = Format Pointer */
79 clr.l %d7 /* D7 = Current char to test */
82 bne .Lformat_loop_wrch
84 .Lformat_loop_perc: /* Seen a '%' sign */
85 addq.l #1, %d6 /* D6 = Address of char after the '%' */
86 subq.l #1, %d5 /* D5 = length - 1 */
87 move.b %a0@(%d6),%d7 /* D7 = char after the '%' */
89 cmp.b #'%',%d7 /* Handle '%%' */
90 beq .Lformat_loop_wrch
92 bclr #5,%d7 /* To Upper */
96 cmp.b #'S', %d7 /* Handle '%S' */
100 move.l #(3*4 + MAXARGS*4),%d0
101 move.l %a2@(GV_writes),%a4
103 jmp .Lformat_loop_next
107 cmp.b #'T', %d7 /* Handle '%Tn' */
109 addq.l #1, %d6 /* D6 = Address of char after the 'T' */
110 subq.l #1, %d5 /* D5 = length - 1 */
111 addq.l #4,%d4 /* D4 = Next argument */
112 move.l %a1@(%d4), %d1 /* D1 = BSTR to print */
114 move.b %a0@(%d6),%d7 /* D7 = char after the 'T' */
115 jsr BCPL_writef_de36/* D2 = Base36 of D7 */
117 move.l #(3*4 + MAXARGS*4),%d0
118 move.l %a2@(GV_writet),%a4
120 jmp .Lformat_loop_next
124 cmp.b #'C', %d7 /* Handle '%C' */
127 move.l %a1@(%d4), %d1
128 move.l #(3*4 + MAXARGS*4),%d0
129 move.l %a2@(GV_wrch),%a4
131 jmp .Lformat_loop_next
135 cmp.b #'O', %d7 /* Handle '%On' */
137 addq.l #1, %d6 /* D6 = Address of char after the '%' */
138 subq.l #1, %d5 /* D5 = length - 1 */
139 move.b %a0@(%d6),%d7 /* D7 = char after the 'O' */
140 jsr BCPL_writef_de36/* D2 = Field width */
142 addq.l #4,%d4 /* D4 = Next argument */
143 move.l %a1@(%d4), %d1 /* D1 = LONG to print */
145 move.l #(3*4 + MAXARGS*4),%d0
146 move.l %a2@(GV_writeoct),%a4
148 jmp .Lformat_loop_next
152 cmp.b #'X', %d7 /* Handle '%Xn' */
154 addq.l #1, %d6 /* D6 = Address of char after the '%' */
155 subq.l #1, %d5 /* D5 = length - 1 */
156 move.b %a0@(%d6),%d7 /* D7 = char after the 'X' */
157 jsr BCPL_writef_de36/* D2 = Field width */
159 addq.l #4,%d4 /* D4 = Next argument */
160 move.l %a1@(%d4), %d1 /* D1 = LONG to print */
162 move.l #(3*4 + MAXARGS*4),%d0
163 move.l %a2@(GV_writehex),%a4
165 jmp .Lformat_loop_next
168 .Lformat_loop_integer:
169 cmp.b #'I', %d7 /* Handle '%In' */
171 addq.l #1, %d6 /* D6 = Address of char after the '%' */
172 subq.l #1, %d5 /* D5 = length - 1 */
173 move.b %a0@(%d6),%d7 /* D7 = char after the 'I' */
174 jsr BCPL_writef_de36/* D2 = Field width */
176 addq.l #4,%d4 /* D4 = Next argument */
177 move.l %a1@(%d4), %d1 /* D1 = LONG to print */
179 move.l #(3*4 + MAXARGS*4),%d0
180 move.l %a2@(GV_writei),%a4
182 jmp .Lformat_loop_next
185 .Lformat_loop_natural:
186 cmp.b #'N', %d7 /* Handle '%N' */
189 move.l %a1@(%d4), %d1
190 move.l #(3*4 + MAXARGS*4),%d0
192 move.l %a2@(GV_writei),%a4
194 jmp .Lformat_loop_next
197 /* Default: Write D7 via wrch */
200 move.l #(3*4 + MAXARGS*4),%d0
201 move.l %a2@(GV_wrch),%a4
203 jmp .Lformat_loop_next
210 movem.l %sp@+,%d2-%d7
214 /* Helper functions */
216 /* In: D7 '0'..'9','A'..'Z','a'..'z'
223 blt .LBCPL_writef_de36_invalid
225 ble .LBCPL_writef_de36_exit
226 subi.b #(('A'-'0')-10),%d2
227 blt .LBCPL_writef_de36_invalid
229 ble .LBCPL_writef_de36_exit
230 .LBCPL_writef_de36_invalid:
232 .LBCPL_writef_de36_exit: