summaryrefslogtreecommitdiff
path: root/src/swis.s
blob: 562747adba8beb1137629e75206e415cb6812bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
; Thomas Leonard
; 24/5/98

ar0	rn	0
ar1	rn	1
ar2	rn	2
ar3	rn	3
ar4	rn	4
ar5	rn	5
ar6	rn	6
ar7	rn	7
ar10	rn	10
ar11	rn	11
lk	rn	14
ar15	rn	15

	AREA	DATA
	align	4

	export	|r0|
r0:	dcd	0

	export	|r1|
r1:	dcd	0

	export	|r2|
r2:	dcd	0

	export	|r3|
r3:	dcd	0

	export	|r4|
r4:	dcd	0

	export	|r5|
r5:	dcd	0

	export	|r6|
r6:	dcd	0

	export	|r7|
r7:	dcd	0

	export	|time_of_last_poll|
time_of_last_poll:  dcd	0

	AREA	CODE, READONLY
	align 4
	import	|r0|
	export	|swi|
	=	"swi"
	align 4
swi:
	; r0 = swi number
	stmfd	sp!,{ar4-ar10,lk}
	orr	ar10,ar0,#1<<17		;always use the X form
	mov	ar0,ar1
	mov	ar1,ar2
	mov	ar2,ar3
	add	ar3,sp,#4*8
	ldmia	ar3,{ar3-ar7}
	swi	0x6f		; OS_CallASWI
	ldr	ar10,regs_addr
	stmia	ar10,{ar0-ar7}
	ldmvcfd	sp!,{ar4-ar10,pc}^
	; report the error and quit on Cancel
	mov	r1,#0x17
	adr	r2,s_title
	swi	0x400df		; Wimp_ReportError
	cmp	r1,#1			;OK selected?
	ldmeqfd	sp!,{ar4-ar10,pc}^	;yes - try to continue
	swi	0x11			;no  - die (OS_Exit)
s_title:
	= "Nasty error - Cancel to quit"
	= 0

	align 4
	export	|xswi|
	=	"xswi"
	align 4
xswi:
	; r0 = swi number
	stmfd	sp!,{ar4-ar10,lk}
	orr	ar10,ar0,#1<<17		;always use the X form
	mov	ar0,ar1
	mov	ar1,ar2
	mov	ar2,ar3
	add	ar3,sp,#4*8
	ldmia	ar3,{ar3-ar7}
	swi	0x6f		; OS_CallASWI
	ldr	ar10,regs_addr
	stmia	ar10,{ar0-ar7}
	mov	ar0,#0
	orr	ar0,ar0,ar15
	ldmfd	sp!,{ar4-ar10,pc}^

regs_addr:
	dcd	r0

	; The Wimp_Poll swis have to be done specially because,
	; for some reason, r13 sometimes gets corrupted by Wimp_Poll
	; (eg when running FileFind)
	AREA	CODE, READONLY
	align 4
	import  |time_of_last_poll|
	export	|wimp_poll|
	=	"wimp_poll"
	align 4
wimp_poll:
	mov	ar3,sp
	swi	0x400c7		; Wimp_Poll
	mov	sp,ar3

	mov	ar3,ar0
	swi	0x42		; OS_ReadMonotonicTime
	ldr	ar2,addr_time
	str	ar0,[ar2]
	mov	ar0,ar3

	mov	ar2,#0
	wfs	ar2		; Write floating point status. Needed?
	movs	pc,lk

	align 4
	export	|wimp_pollidle|
	=	"wimp_pollidle"
	align 4
wimp_pollidle:
	mov	ar3,sp
	swi	0x400e1		; Wimp_PollIdle
	mov	sp,ar3

	mov	ar3,ar0
	swi	0x42		; OS_ReadMonotonicTime
	ldr	ar2,addr_time
	str	ar0,[ar2]
	mov	ar0,ar3

	mov	ar2,#0
	wfs	ar2		; Write floating point status. Needed?
	movs	pc,lk

addr_time: dcd	time_of_last_poll