chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / report
1 ;
2 ; report.s
3 ;
4 ; A simple report box handler (MDW)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32 ;----- External dependencies ------------------------------------------------
33
34                 GET     sapphire:buttons
35                 GET     sapphire:errorBox
36                 GET     sapphire:except
37                 GET     sapphire:msgs
38                 GET     sapphire:sapphire
39                 GET     sapphire:seh
40                 GET     sapphire:string
41
42 ;----- Main code ------------------------------------------------------------
43
44                 AREA    |Sapphire$$Code|,CODE,READONLY
45
46 ; --- report_register ---
47 ;
48 ; On entry:     R0 == pointer to routine to use
49 ;               R1 == R12 to pass to the routine
50 ;               R2 == stack pointer to set when it gets control
51 ;
52 ; On exit:      --
53 ;
54 ; Use:          Registers a resume point so that the application can recover
55 ;               from errors.  Error messages are reported using errorBox.
56
57                 EXPORT  report_register
58 report_register ROUT
59
60                 STMFD   R13!,{R0,R1,R12,R14}    ;Save some registers
61                 WSPACE  report__wspace          ;Get my workspace pointer
62                 STMIA   R12,{R0,R1}             ;Save these for later
63                 ADR     R0,report__report       ;Point to my own resumer
64                 MOV     R1,R12                  ;And set up my workspace
65                 BL      except_returnPt         ;Set this up as the handler
66                 LDMFD   R13!,{R0,R1,R12,PC}^    ;Return to the caller
67
68 ; --- report__report ---
69 ;
70 ; On entry:     R0 == pointer to an error block
71 ;
72 ; On exit:      R0 == pointer to user-supplied resume point
73 ;               R1 == value of R12 to pass to the resume point
74 ;
75 ; Use:          Pops up an error box reporting the error in a `OK to
76 ;               continue, Cancel to cancel program' type way.
77
78 report__report  ROUT
79
80                 STMFD   R13!,{R14}              ;Save some registers
81                 BL      report_error            ;Ask the user about quitting
82                 LDMIA   R12,{R0,R1}             ;Get the resume point out
83                 LDMFD   R13!,{PC}^              ;Return to caller
84
85                 LTORG
86
87 ; --- report_catchAll ---
88 ;
89 ; On entry:     --
90 ;
91 ; On exit:      R13 modified
92 ;
93 ; Use:          Sets up an exception handler to catch errors and other SEH
94 ;               exceptions.  Errors are reported in the usual way, and the
95 ;               user is given the option to close the application.  Other
96 ;               exceptions are reported as errors.
97
98                 EXPORT  report_catchAll
99 report_catchAll ROUT
100
101                 STMFD   R13!,{R0-R12,R14}       ;Save some registers
102 report__resume  MOV     R12,R13                 ;Remember where this lot is
103                 ADR     R0,report__catch        ;Point to the try block
104                 BL      seh_try                 ;Register it with SEH
105                 LDMIA   R12,{R0-R12,PC}^        ;And return to caller
106
107 report__catch   MOVS    PC,R14
108                 DCW     &FFFF,1
109                 B       report__catchErr
110                 DCD     -1
111                 B       report__catchUK
112                 DCD     0
113
114 report__catchUK ADR     R0,report__special      ;Point to emergency try block
115                 BL      seh_try                 ;Register that nicely
116                 MOV     R2,R0                   ;Put the exception in R2
117                 ADR     R0,report__ukExc        ;Point to error skeleton
118                 BL      msgs_error              ;Translate the message
119                 MOV     R1,R0                   ;And move error to R1
120                 B       %f00                    ;Skip emergency handler
121
122 report__catchErr
123                 ADR     R0,report__special      ;Point to emergency try block
124                 BL      seh_try                 ;Register that nicely
125 00              MOV     R0,R1                   ;Point to the error block
126                 BL      report_error            ;Report it to the user
127                 BL      seh_unTry               ;Remove emergency handler
128                 B       report__resume          ;And resume the application
129
130 report__ukExc   DCD     1
131                 DCB     "rptUKEXC",0
132
133 report__special MOVS    PC,R14
134                 DCD     -1
135                 B       report__abort
136                 DCD     0
137
138 report__abort   ADR     R0,report__badExc       ;Point to the error message
139                 B       except_fatal            ;And report it, and die
140
141 report__badExc  DCD     &80000000
142                 DCB     "Fatal error: couldn't recover from error",0
143
144                 LTORG
145
146 ; --- report_error ---
147 ;
148 ; On entry:     R0 == pointer to error
149 ;
150 ; On exit:      --
151 ;
152 ; Use:          Prompts the user about quitting the application in response
153 ;               to a really bad error.  If the user decides to quit, we
154 ;               quit.  Otherwise we return.
155
156                 EXPORT  report_error
157 report_error    ROUT
158
159                 STMFD   R13!,{R0-R4,R14}        ;Save lots of registers
160
161                 ; --- Set up the message to display in the box ---
162
163                 ADD     R3,R0,#4                ;Point to error message
164                 LDR     R4,[R0,#-4]             ;Get PC when error happened
165                 BIC     R4,R4,#&FC000003        ;Clear off nasty PSR bits
166                 LDR     R2,sapph_appName        ;Keep this name pointer
167                 ADR     R0,report__msg1         ;Point to the error skeleton
168                 BL      msgs_error              ;Construct the error message
169
170                 ; --- Display the message and get a response ---
171
172                 ADR     R1,report__buttons      ;Point to buttons block
173                 BL      errorBox                ;Do all the real business
174                 BCS     %10report_error         ;If OK, skip ahead
175
176                 ; --- If the user pressed Cancel, we give another go ---
177
178                 ADR     R0,report__msg2         ;Point to confirm message
179                 BL      msgs_error              ;Construct the error message
180                 ADR     R1,report__buttons      ;Point to buttons block
181                 BL      errorBox                ;Get another response
182                 SWICC   OS_Exit                 ;If `Quit' then we die
183
184 10report_error  LDMFD   R13!,{R0-R4,PC}^        ;Return to caller
185
186 report__msg1    DCD     1
187                 DCB     "rptERR",0
188
189 report__msg2    DCD     1
190                 DCB     "rptCONF",0
191
192 report__buttons BUTTON  "rptCONT"
193                 BCANCEL "rptQUIT"
194                 BUTEND
195
196                 LTORG
197
198 report__wspace  DCD     0                       ;Workspace pointer
199
200 ;----- Workspace ------------------------------------------------------------
201
202                 ^       0,R12
203 report_wstart   #       0
204
205 report_routine  #       4                       ;Pointer to resume routine
206 report_R12      #       4                       ;Value of R12 it wants
207
208 report_wsize    EQU     {VAR}-report_wstart
209
210                 AREA    |Sapphire$$LibData|,CODE,READONLY
211
212                 DCD     report_wsize            ;Workspace size I want
213                 DCD     report__wspace          ;Pointer to my pointer :-/
214                 DCD     0                       ;No scratchpad required
215                 DCD     0                       ;No initialisation either
216
217 ;----- That's all, folks ----------------------------------------------------
218
219                 END