4 ; A simple report box handler (MDW)
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
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)
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.
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.
27 ;----- Standard header ------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
42 ;----- Main code ------------------------------------------------------------
44 AREA |Sapphire$$Code|,CODE,READONLY
46 ; --- report_register ---
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
54 ; Use: Registers a resume point so that the application can recover
55 ; from errors. Error messages are reported using errorBox.
57 EXPORT report_register
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
68 ; --- report__report ---
70 ; On entry: R0 == pointer to an error block
72 ; On exit: R0 == pointer to user-supplied resume point
73 ; R1 == value of R12 to pass to the resume point
75 ; Use: Pops up an error box reporting the error in a `OK to
76 ; continue, Cancel to cancel program' type way.
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
87 ; --- report_catchAll ---
91 ; On exit: R13 modified
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.
98 EXPORT report_catchAll
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
107 report__catch MOVS PC,R14
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
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
133 report__special MOVS PC,R14
138 report__abort ADR R0,report__badExc ;Point to the error message
139 B except_fatal ;And report it, and die
141 report__badExc DCD &80000000
142 DCB "Fatal error: couldn't recover from error",0
146 ; --- report_error ---
148 ; On entry: R0 == pointer to error
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.
159 STMFD R13!,{R0-R4,R14} ;Save lots of registers
161 ; --- Set up the message to display in the box ---
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
170 ; --- Display the message and get a response ---
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
176 ; --- If the user pressed Cancel, we give another go ---
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
184 10report_error LDMFD R13!,{R0-R4,PC}^ ;Return to caller
192 report__buttons BUTTON "rptCONT"
198 report__wspace DCD 0 ;Workspace pointer
200 ;----- Workspace ------------------------------------------------------------
205 report_routine # 4 ;Pointer to resume routine
206 report_R12 # 4 ;Value of R12 it wants
208 report_wsize EQU {VAR}-report_wstart
210 AREA |Sapphire$$LibData|,CODE,READONLY
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
217 ;----- That's all, folks ----------------------------------------------------