revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / reqtools / rtfuncs.asm
blobed602018f865db5cdd982bebf3e4e6bbab58acae
1 ********************
2 * ReqTools library *
3 ********************
5 SECTION "text",CODE
7 INCLUDE "exec/types.i"
8 INCLUDE "exec/funcdef.i"
9 INCLUDE "lvo/exec_lib.i"
10 INCLUDE "exec/nodes.i"
11 INCLUDE "exec/lists.i"
12 INCLUDE "exec/alerts.i"
13 INCLUDE "exec/libraries.i"
14 INCLUDE "exec/memory.i"
15 INCLUDE "dos/dos.i"
16 INCLUDE "lvo/dos_lib.i"
17 INCLUDE "dos/var.i"
18 INCLUDE "graphics/gfxbase.i"
19 INCLUDE "intuition/intuition.i"
20 INCLUDE "intuition/classes.i"
21 INCLUDE "intuition/classusr.i"
22 INCLUDE "intuition/screens.i"
23 INCLUDE "lvo/intuition_lib.i"
24 INCLUDE "utility/hooks.i"
26 INCLUDE "libraries/reqtools.i"
27 INCLUDE "lvo/reqtools_lib.i"
29 INCLUDE "boopsigads.i"
31 XREF _myBoopsiDispatch
32 XREF _FreeReqToolsFonts
33 XREF DataTable
34 XREF __BSSLEN
36 XDEF Init
38 Init:
39 dc.l ReqToolsBase_SIZE
40 dc.l FuncTable
41 dc.l DataTable
42 dc.l InitRoutine
44 dosName:
45 dc.b "dos.library",0
46 intName:
47 dc.b "intuition.library",0
48 gfxName:
49 dc.b "graphics.library",0
50 gadName:
51 dc.b "gadtools.library",0
52 utilName:
53 dc.b "utility.library",0
54 layersName:
55 dc.b "layers.library",0
56 localeName:
57 dc.b "locale.library",0
58 consoleName:
59 dc.b "console.device",0
60 imageclass:
61 dc.b "imageclass",0
62 varname:
63 dc.b "ReqTools.prefs",0
64 ds.l 0
65 ; dc.l __BSSLEN ; we need this line for Blink to generate BSS!
67 EVEN
69 *****************************************************************************
71 ; D1 must hold default size, A1 is advanced, D1 is preserved
72 InitReqDefaults:
73 move.l d1,(a0)+ ; rtrd_Size
74 moveq #REQPOS_TOPLEFTSCR,d0
75 move.l d0,(a0)+ ; rtrd_ReqPos
76 InitReqDefs_NoSizeNoReqPos:
77 moveq #25,d0
78 move.w d0,(a0)+ ; rtrd_LeftOffset
79 moveq #18,d0
80 move.w d0,(a0)+ ; rtrd_TopOffset
81 moveq #6,d0
82 move.w d0,(a0)+ ; rtrd_MinEntries
83 moveq #10,d0
84 move.w d0,(a0)+ ; rtrd_MaxEntries
85 rts
87 ; Initialize library
88 ; d0 = library pointer, a0 = seglist, a6 = sysbase
89 ; -> d0 = non zero if lib must be linked in the system list
90 InitRoutine:
91 movem.l d2/a2/a4-a6,-(a7) ; MUST BE SAME AS EXPUNGELIB !!!!!
92 move.l d0,a5
93 lea _ReqToolsBase,a4
94 move.l d0,(a4) ; our base to be used in C routines
95 move.l a6,_SysBase-_ReqToolsBase(a4)
96 move.l a0,rt_SegList(a5)
98 move.w #ReqToolsBase_SIZE,d0 ; set everything private to 0
99 sub.w #rt_RealOpenCnt+1,d0
100 lea rt_RealOpenCnt(a5),a0
101 clear:
102 clr.b (a0)+
103 dbf d0,clear
105 ; Fill in preference size
106 move.l #RTPREFS_SIZE,rt_ReqToolsPrefs+rtpr_PrefsSize(a5)
108 ; Initialize prefs semaphore
109 lea rt_ReqToolsPrefs+rtpr_PrefsSemaphore(a5),a0
110 jsr _LVOInitSemaphore(a6)
112 ; Set default preferences
113 lea rt_ReqToolsPrefs+rtpr_ReqDefaults(a5),a0
114 moveq #75,d1
115 bsr.b InitReqDefaults ; RTPREF_FILEREQ
116 move.w #10,-4(a0) ; set min entries to 10
117 move.w #50,-2(a0) ; set max entries to 50
118 moveq #65,d1
119 bsr.b InitReqDefaults ; RTPREF_FONTREQ
120 bsr.b InitReqDefaults ; RTPREF_PALETTEREQ, size ignored
121 bsr.b InitReqDefaults ; RTPREF_SCREENMODEREQ
122 bsr.b InitReqDefaults ; RTPREF_VOLUMEREQ
123 addq.l #8,a0
124 bsr.b InitReqDefs_NoSizeNoReqPos ; RTPREF_OTHERREQ
126 lea intName(PC),a1
127 jsr _LVOOldOpenLibrary(a6)
128 move.l d0,_IntuitionBase-_ReqToolsBase(a4)
129 move.l d0,rt_IntuitionBase(a5)
130 move.l d0,d2
132 move.l d0,a0
133 moveq #36,d0
134 cmp.w LIB_VERSION(a0),d0 ; is version >= 37
135 bcs.b okkick37
137 lea kickalertstr(PC),a0
138 move.l d2,a6
139 moveq #0,d0
140 moveq #19,d1
141 jsr _LVODisplayAlert(a6)
142 moveq #0,d2
143 bra errorinitlib
145 okkick37:
146 move.l a0,a6
147 lea imageclass(PC),a1
148 sub.l a0,a0
149 sub.l a2,a2
150 moveq #lod_SIZEOF,d0
151 moveq #0,d1
152 jsr _LVOMakeClass(a6)
153 moveq #0,d2
154 move.l d0,_ButtonImgClass-_ReqToolsBase(a4)
155 beq errorinitlib ; A6 MUST hold IntuitionBase!
157 move.l d0,a1
158 move.l #_myBoopsiDispatch,cl_Dispatcher+h_Entry(a1)
159 move.l $4.w,a6
161 lea gadName(PC),a1
162 jsr _LVOOldOpenLibrary(a6)
163 move.l d0,_GadToolsBase-_ReqToolsBase(a4)
164 move.l d0,rt_GadToolsBase(a5)
166 lea dosName(PC),a1
167 jsr _LVOOldOpenLibrary(a6)
168 move.l d0,_DOSBase-_ReqToolsBase(a4)
169 move.l d0,rt_DOSBase(a5)
171 ; Get current ReqTools preferences (D0 = DOSBase)
172 movem.l d2-d4/a6,-(a7)
173 move.l d0,a6
174 lea varname(PC),a0
175 move.l a0,d1
176 lea rt_ReqToolsPrefs+rtpr_Flags(a5),a0
177 move.l a0,d2
178 move.l rt_ReqToolsPrefs+rtpr_PrefsSize(a5),d3
179 move.l #GVF_BINARY_VAR!GVF_GLOBAL_ONLY!LV_VAR,d4
180 jsr _LVOGetVar(a6)
181 movem.l (a7)+,d2-d4/a6
183 lea gfxName(PC),a1
184 jsr _LVOOldOpenLibrary(a6)
185 move.l d0,_GfxBase-_ReqToolsBase(a4)
186 move.l d0,rt_GfxBase(a5)
187 move.l d0,a0
189 lea utilName(PC),a1
190 jsr _LVOOldOpenLibrary(a6)
191 move.l d0,_UtilityBase-_ReqToolsBase(a4)
192 move.l d0,rt_UtilityBase(a5)
194 lea layersName(PC),a1
195 jsr _LVOOldOpenLibrary(a6)
196 move.l d0,_LayersBase-_ReqToolsBase(a4)
198 lea localeName(PC),a1
199 jsr _LVOOldOpenLibrary(a6)
200 move.l d0,_LocaleBase-_ReqToolsBase(a4)
202 lea consoleName(PC),a0
203 lea iorequest-_ReqToolsBase(a4),a1
204 moveq #-1,d0
205 moveq #0,d1
206 jsr _LVOOpenDevice(a6)
207 move.l iorequest-_ReqToolsBase+IO_DEVICE(a4),d0
208 move.l d0,_ConsoleDevice-_ReqToolsBase(a4)
210 move.l a5,d0
211 movem.l (a7)+,d2/a2/a4-a6
214 kickalertstr:
215 dc.b 0,96,11
216 dc.b "This version of reqtools.library needs Kickstart 2.0 V37+",0,0
218 cnop 0,2
220 ; Open library
221 ; d0 = version, a6 = ptr to lib
222 ; -> d0 = ptr to lib
223 Open:
224 ; addq.w #1,LIB_OPENCNT(a6)
225 addq.w #1,rt_RealOpenCnt(a6)
226 ; bclr.b #LIBB_DELEXP,rt_RTFlags(a6) ; Prevent delayed expunges
227 move.l a6,d0
230 ; Close library
231 ; a6 = ptr to lib
232 ; -> d0 = return seglist if lib is completely closed and delayed expunge
233 Close:
234 moveq #0,d0
235 ; subq.w #1,LIB_OPENCNT(a6)
236 subq.w #1,rt_RealOpenCnt(a6)
237 ; bne.s EndClose
239 ; btst #LIBB_DELEXP,rt_RTFlags(a6)
240 ; bne.s Expunge
241 EndClose:
244 ; Expunge the library
245 ; a6 = ptr to lib
246 ; -> d0 = seglist if library is no longer open
247 Expunge:
248 movem.l d2/a2/a4-a6,-(a7) ; MUST BE SAME AS INITLIB !!!!!
249 move.l a6,a5
250 move.l $4.w,a6
252 tst.w rt_AvailFontsLock(a5)
253 bne.b noavailfonts
255 jsr _FreeReqToolsFonts(PC)
256 noavailfonts:
258 ; tst.w LIB_OPENCNT(a5)
259 tst.w rt_RealOpenCnt(a5)
260 beq.b NoOneOpen
262 ; bset.b #LIBB_DELEXP,rt_RTFlags(a5) ; still open, set delayed expunge flag
263 moveq #0,d0
264 bra.b ExpungeEnd
266 NoOneOpen:
267 move.l rt_SegList(a5),d2
268 move.l a5,a1
269 jsr _LVORemove(a6) ; remove lib
270 lea iorequest,a1
271 jsr _LVOCloseDevice(a6) ; close console.device
272 move.l rt_DOSBase(a5),a1
273 jsr _LVOCloseLibrary(a6) ; close DOS
274 move.l rt_GadToolsBase(a5),a1
275 jsr _LVOCloseLibrary(a6) ; close GadTools
276 move.l rt_GfxBase(a5),a1
277 jsr _LVOCloseLibrary(a6) ; close Gfx
278 move.l rt_UtilityBase(a5),a1
279 jsr _LVOCloseLibrary(a6) ; close Utility
280 move.l _LayersBase,a1
281 jsr _LVOCloseLibrary(a6)
282 move.l _LocaleBase,a1
283 jsr _LVOCloseLibrary(a6)
284 move.l rt_IntuitionBase(a5),a6
285 move.l _ButtonImgClass,a0
286 jsr _LVOFreeClass(a6) ; free image class
287 errorinitlib:
288 move.l a6,a1
289 move.l ($4).w,a6
290 jsr _LVOCloseLibrary(a6) ; close Intuition
292 move.l a5,a1
293 moveq #0,d0
294 move.w LIB_NEGSIZE(a5),d0
295 sub.l d0,a1
296 add.w LIB_POSSIZE(a5),d0
297 jsr _LVOFreeMem(a6) ; free our mem
298 move.l d2,d0 ; seglist
299 ExpungeEnd:
300 movem.l (a7)+,d2/a2/a4-a6
303 ; Do nothing function
304 Null:
305 moveq #0,d0
308 ******************************************************************************
310 * ReqTools Functions
312 ******************************************************************************
314 XREF _AllocRequestA
315 XREF _FreeRequest
316 XREF _FreeReqBuffer
317 XREF _FileRequestA
318 XREF _ChangeReqAttrA
319 XREF _FreeFileList
320 XREF _PaletteRequestA
321 XREF _GetVScreenSize
322 XREF _CloseWindowSafely
324 FuncTable:
325 dc.l Open
326 dc.l Close
327 dc.l Expunge
328 dc.l Null
330 dc.l _AllocRequestA
331 dc.l _FreeRequest
332 dc.l _FreeReqBuffer
333 dc.l _ChangeReqAttrA
334 dc.l _FileRequestA
335 dc.l _FreeFileList
336 dc.l rtEZRequestA
337 dc.l rtGetStringA
338 dc.l rtGetLongA
339 dc.l rtInternalGetPasswordA ; private
340 dc.l rtInternalEnterPasswordA ; private
341 dc.l _FileRequestA ; = _FontRequestA!
342 dc.l _PaletteRequestA
343 dc.l rtReqHandlerA
344 dc.l rtSetWaitPointer
345 dc.l _GetVScreenSize
346 dc.l rtSetReqPosition
347 dc.l rtSpread
348 dc.l rtScreenToFrontSafely
349 dc.l _FileRequestA ; rtScreenModeRequestA
350 dc.l _CloseWindowSafely
351 dc.l rtLockWindow
352 dc.l rtUnLockWindow
353 ; private funcs for preferences
354 dc.l rtLockPrefs
355 dc.l rtUnlockPrefs
356 dc.l -1
358 *----------------------------------------------------------------------------*
359 * -- PRIVATE --
360 * struct ReqToolsPrefs *rtLockPrefs (void);
361 * d0
363 rtLockPrefs:
364 move.l a6,-(a7)
365 lea rt_ReqToolsPrefs+rtpr_PrefsSemaphore(a6),a0
366 move.l $4.w,a6
367 jsr _LVOObtainSemaphore(a6)
368 move.l (a7)+,a6
369 lea rt_ReqToolsPrefs(a6),a0
370 move.l a0,d0
373 *----------------------------------------------------------------------------*
374 * -- PRIVATE --
375 * void rtUnlockPrefs (void);
377 rtUnlockPrefs:
378 move.l a6,-(a7)
379 lea rt_ReqToolsPrefs+rtpr_PrefsSemaphore(a6),a0
380 move.l $4.w,a6
381 jsr _LVOReleaseSemaphore(a6)
382 move.l (a7)+,a6
385 XREF _GetString
387 CHECK_PASSWORD equ 0
388 ENTER_PASSWORD equ 1
389 ENTER_STRING equ 2
390 ENTER_NUMBER equ 3
391 IS_EZREQUEST equ 4
393 *----------------------------------------------------------------------------*
394 * -- PRIVATE --
395 * BOOL rtInternalEnterPasswordA (UBYTE *, char *(*)(), struct TagItem *);
396 * d0 a1 d2 a0
398 rtInternalEnterPasswordA:
399 movem.l d2-d4/a2,-(a7)
400 moveq #ENTER_PASSWORD,d3
401 bra.b getpass
403 *----------------------------------------------------------------------------*
404 * -- PRIVATE --
405 * BOOL rtInternalGetPasswordA (UBYTE *, ULONG, char *(*)(), struct TagItem *);
406 * d0 a1 d1:16 d2 a0
408 rtInternalGetPasswordA:
409 movem.l d2-d4/a2,-(a7)
410 moveq #CHECK_PASSWORD,d3
411 clr.b (a1)
412 getpass:
413 moveq #16,d0
414 lea PwTitle(PC),a2
415 andi.l #$ffff,d1
416 bra.b GetStr_PopD2toD4_A2_RTS
418 PwTitle:
419 dc.b "Password",0
420 cnop 0,2
422 *----------------------------------------------------------------------------*
423 * BOOL rtGetStringA
424 * (UBYTE *, ULONG, char *, struct rtReqInfo *, struct TagItem *);
425 * d0 a1 d0 a2 a3 a0
427 XREF _CheckStackCallFunc
429 rtGetStringA:
430 movem.l d2-d4/a2,-(a7)
431 moveq #ENTER_STRING,d3
432 GetStr_PopD2toD4_A2_RTS:
433 move.l a3,d4
435 pea _GetString(PC)
436 jsr _CheckStackCallFunc(PC)
438 movem.l (a7)+,d2-d4/a2
441 *----------------------------------------------------------------------------*
442 * ULONG rtEZRequestA
443 * (char *, char *, struct rtReqInfo *, APTR, struct TagItem *);
444 * d0 a1 a2 a3 a4 a0
446 rtEZRequestA:
447 movem.l d2-d4/a2,-(a7)
448 move.l a4,d0 ; args
449 moveq #IS_EZREQUEST,d3
450 bra.b GetStr_PopD2toD4_A2_RTS
452 *----------------------------------------------------------------------------*
453 * BOOL rtGetLongA (ULONG *, char *, struct rtReqInfo *, struct TagItem *);
454 * d0 a1 a2 a3 a0
456 rtGetLongA:
457 movem.l d2-d4/a2,-(a7)
458 move.l a1,d2
459 moveq #ENTER_NUMBER,d3
460 bra.b GetStr_PopD2toD4_A2_RTS
462 *----------------------------------------------------------------------------*
463 * ULONG rtReqHandlerA (APTR, ULONG *, struct TagItem *);
464 * d0 a1 a2 a0
466 XDEF rtReqHandlerA
468 rtReqHandlerA:
469 move.l (a1),-(a7) ; first longword holds real function address!
472 *----------------------------------------------------------------------------*
473 * void rtSetWaitPointer (struct Window *);
474 * a0
476 XREF _waitpointer
478 rtSetWaitPointer:
479 movem.l d2/d3/a6,-(a7)
480 move.l $4.w,a1
481 moveq #38,d0
482 cmp.w LIB_VERSION(a1),d0 ; is version >= 39
483 bcs.b .iskick39
484 lea _waitpointer,a1
485 moveq #16,d0
486 moveq #16,d1
487 moveq #-6,d2
488 moveq #0,d3
489 move.l rt_IntuitionBase(a6),a6
490 jsr _LVOSetPointer(a6)
491 bra.b .endsetwaitpointer
492 .iskick39:
493 lea setpointertaglist(PC),a1
494 move.l rt_IntuitionBase(a6),a6
495 jsr _LVOSetWindowPointerA(a6)
496 .endsetwaitpointer:
497 movem.l (a7)+,d2/d3/a6
500 setpointertaglist:
501 dc.l WA_BusyPointer,1,TAG_DONE
503 *----------------------------------------------------------------------------*
504 * APTR rtLockWindow (struct Window *);
505 * a0
507 STRUCTURE rtWindowLock,0
508 * requester structure (MUST BE FIRST ITEM!!!)
509 STRUCT rtwl_Requester,rq_SIZEOF
510 APTR rtwl_Magic
511 ULONG rtwl_RequesterPtr
512 ULONG rtwl_LockCount
513 ULONG rtwl_ReqInstalled
514 * same as in Window structure (same order as well!)
515 APTR rtwl_Pointer
516 BYTE rtwl_PtrHeight
517 BYTE rtwl_PtrWidth
518 BYTE rtwl_XOffset
519 BYTE rtwl_YOffset
520 WORD rtwl_MinWidth
521 WORD rtwl_MinHeight
522 WORD rtwl_MaxWidth
523 WORD rtwl_MaxHeight
524 LABEL rtwl_SIZEOF
526 LOCKWINMAGIC equ 'rtLW'
528 rtLockWindow:
529 movem.l d2/d3/a0/a2/a6,-(a7) ; DON'T CHANGE THIS WITHOUT THINKING!!
531 * First see if we already locked this window.
532 move.l wd_FirstRequest(a0),a1
533 .nextreq:
534 move.l a1,d0
535 beq.b .noreq
537 move.l rtwl_Magic(a1),d0
538 cmp.l #LOCKWINMAGIC,d0
539 bne.b .nomagic
541 cmp.l rtwl_RequesterPtr(a1),a1
542 beq.b .increasecount
544 .nomagic:
545 move.l (a1),a1
546 bra.b .nextreq
548 * If the window was already locked increase lock-count
550 .increasecount:
551 addq.l #1,rtwl_LockCount(a1)
552 move.l a1,d0 ; return window lock
553 bra endlockwin
555 * Lock the window
556 .noreq:
557 move.l #rtwl_SIZEOF,d0
558 move.l #MEMF_CLEAR,d1
559 move.l a6,-(a7)
560 move.l $4.w,a6
561 jsr _LVOAllocVec(a6)
562 move.l (a7)+,a6
563 tst.l d0
564 beq.b endlockwin
566 move.l d0,a2
567 move.l d0,rtwl_RequesterPtr(a2)
568 move.l #LOCKWINMAGIC,rtwl_Magic(a2)
570 move.l rt_IntuitionBase(a6),a6
572 move.l 8(a7),a0 ; A0 on stack + 8 = window ptr
573 lea rtwl_MinWidth(a2),a1
574 move.l wd_MinWidth(a0),(a1)+ ; remember wd_MinWidth and wd_MinHeight
575 move.l wd_MaxWidth(a0),(a1)+ ; remember wd_MaxWidth and wd_MaxHeight
576 moveq #0,d0
577 move.w wd_Width(a0),d0
578 moveq #0,d1
579 move.w wd_Height(a0),d1
580 move.l d0,d2
581 move.l d1,d3
582 jsr _LVOWindowLimits(a6) ; set window limits to current size
584 move.l a2,a0
585 jsr _LVOInitRequester(a6)
587 move.l 8(a7),a1 ; A0 on stack + 8 = window ptr
588 move.l a2,a0
589 jsr _LVORequest(a6)
590 move.l d0,rtwl_ReqInstalled(a2)
592 move.l 8(a7),a0
593 move.l 16(a7),a6
594 lea rtwl_Pointer(a2),a1
595 move.l wd_Pointer(a0),(a1)+ ; remember wd_Pointer
596 move.l wd_PtrHeight(a0),(a1)+ ; remember wd_PtrHeight, wd_PtrWidth,...
597 jsr _LVOrtSetWaitPointer(a6)
599 move.l a2,d0
600 endlockwin:
601 movem.l (a7)+,d2/d3/a0/a2/a6
604 *----------------------------------------------------------------------------*
605 * ULONG rtUnLockWindow (struct Window *, APTR lock);
606 * a0 a1
608 rtUnLockWindow:
609 movem.l d2/d3/a0/a1/a6,-(a7)
610 move.l a1,d0
611 beq endunlockwin
613 move.l rtwl_LockCount(a1),d0
614 beq.b .unlockwin
616 subq.l #1,rtwl_LockCount(a1)
617 bra.b endunlockwin
619 .unlockwin:
620 * restore old window pointer
621 move.l rt_IntuitionBase(a6),a6
622 tst.l rtwl_Pointer(a1)
623 beq.b .clrptr
625 moveq #0,d0
626 move.b rtwl_PtrHeight(a1),d0
627 moveq #0,d1
628 move.b rtwl_PtrWidth(a1),d1
629 move.b rtwl_XOffset(a1),d2
630 ext.w d2
631 ext.l d2
632 move.b rtwl_YOffset(a1),d3
633 ext.w d3
634 ext.l d3
635 move.l rtwl_Pointer(a1),a1
636 jsr _LVOSetPointer(a6)
637 bra.b endreq
638 .clrptr:
639 jsr _LVOClearPointer(a6)
641 endreq:
642 movem.l 8(a7),a0/a1
643 tst.l rtwl_ReqInstalled(a1)
644 beq.b noreqinstalled
646 exg.l a0,a1
647 jsr _LVOEndRequest(a6)
648 movem.l 8(a7),a0/a1
649 noreqinstalled:
651 * restore wd_MinWidth, wd_MinHeight, wd_MaxWidth and wd_MaxHeight
652 moveq #0,d0
653 move.w rtwl_MinWidth(a1),d0
654 moveq #0,d1
655 move.w rtwl_MinHeight(a1),d1
656 moveq #0,d2
657 move.w rtwl_MaxWidth(a1),d2
658 moveq #0,d3
659 move.w rtwl_MaxHeight(a1),d3
660 jsr _LVOWindowLimits(a6) ; reset window limits
661 movem.l 8(a7),a0/a1
663 * free lock
664 move.l $4.w,a6
665 jsr _LVOFreeVec(a6)
667 endunlockwin:
668 movem.l (a7)+,d2/d3/a0/a1/a6
671 *----------------------------------------------------------------------------*
672 * void rtSpread (ULONG *, ULONG *, ULONG, ULONG, ULONG, ULONG);
673 * (pos, width, length, x1, x2, num);
674 * D0 A0 A1 D0 D1 D2 D3
676 rtSpread:
677 movem.l d2/d3/d4/d5,-(a7)
678 move.l d1,d5
679 swap d5
680 clr.w d5 ; gadpos (D5) = x1 << 16
681 move.l d3,d4 ; num-- (D4)
682 subq.l #1,d4
683 move.l d2,d3
684 sub.l d1,d3
685 sub.l d0,d3
686 divs d4,d3
687 swap d3
688 clr.w d3 ; gadgap (D3) = ((x2-x1-totwidth) / num) << 16
689 moveq #0,d0 ; i (D0) = 0
690 loopspread:
691 cmp.w d0,d4
692 bcs.s endspread
693 bne.s notnum
695 move.l d2,d1 ; pos[i] = x2 - width[i]
696 sub.l (a1),d1
697 bra.b addpos
698 notnum:
699 move.l d5,d1 ; pos[i] = gadpos >> 16
700 clr.w d1
701 swap d1
702 addpos:
703 move.l d1,(a0)+
704 move.l (a1)+,d1 ; gadpos += (width[i] << 16) + gadgap
705 swap d1
706 clr.w d1
707 add.l d3,d1
708 add.l d1,d5
709 addq.l #1,d0
710 bra.b loopspread
712 endspread:
713 movem.l (a7)+,d2/d3/d4/d5
716 *----------------------------------------------------------------------------*
717 * void rtScreenToFrontSafely (struct Screen *);
718 * a0
720 rtScreenToFrontSafely:
721 move.l a6,-(a7)
722 move.l rt_IntuitionBase(a6),a1
723 move.l ($4).w,a6
724 jsr _LVOForbid(a6) ; a1 will be preserved
725 move.l a1,a6
726 move.l ib_FirstScreen(a6),a1
727 loopscr:
728 move.l a1,d0
729 beq.b nofoundscr
731 cmp.l a1,a0
732 beq.b foundscr
734 move.l (a1),a1 ; == move.l sc_NextScreen(a1),a1
735 bra.b loopscr
736 foundscr:
737 jsr _LVOScreenToFront(a6)
738 nofoundscr:
739 move.l ($4).w,a6
740 jsr _LVOPermit(a6)
741 move.l (a7)+,a6
744 *----------------------------------------------------------------------------*
745 * void rtSetReqPosition
746 * (ULONG, struct NewWindow *, struct Screen *, struct Window *);
747 * d0 a0 a1 a2
749 ;void __asm SetReqPosition (
750 ; register __d0 int reqpos,
751 ; register __a0 struct NewWindow *nw,
752 ; register __a1 struct Screen *scr,
753 ; register __a2 struct Window *win)
755 ; int mx, my, val, leftedge, topedge;
756 ; int scrwidth, scrheight;
757 ; int width, height, left, top;
759 ; rtGetVScreenSize (scr, &scrwidth, &scrheight);
760 ; leftedge = -scr->LeftEdge;
761 ; if (leftedge < 0) leftedge = 0;
762 ; topedge = -scr->TopEdge;
763 ; if (topedge < 0) topedge = 0;
765 ; left = leftedge; top = topedge;
766 ; width = scrwidth; height = scrheight;
767 ; switch (reqpos) {
768 ; case REQPOS_DEFAULT:
769 ; nw->LeftEdge = 25;
770 ; nw->TopEdge = 18;
771 ; goto topleftscr;
772 ; case REQPOS_POINTER:
773 ; mx = scr->MouseX; my = scr->MouseY;
774 ; break;
775 ; case REQPOS_CENTERWIN:
776 ; if (win) {
777 ; left = win->LeftEdge; top = win->TopEdge;
778 ; width = win->Width; height = win->Height;
780 ; case REQPOS_CENTERSCR:
781 ; mx = (width - nw->Width) / 2 + left;
782 ; my = (height - nw->Height) / 2 + top;
783 ; break;
784 ; case REQPOS_TOPLEFTWIN:
785 ; if (win) {
786 ; left = win->LeftEdge;
787 ; top = win->TopEdge;
789 ; case REQPOS_TOPLEFTSCR:
790 ;topleftscr:
791 ; mx = left; my = top;
792 ; break;
795 ; /* keep window completely visible */
796 ; mx += nw->LeftEdge; my += nw->TopEdge;
797 ; val = leftedge + scrwidth - nw->Width;
798 ; if (mx < leftedge) mx = leftedge;
799 ; else if (mx > val) mx = val;
800 ; val = topedge + scrheight - nw->Height;
801 ; if (my < topedge) my = topedge;
802 ; else if (my > val) my = val;
804 ; nw->LeftEdge = mx; nw->TopEdge = my;
807 REQPOS_DEFAULT equ $FFFF
809 rtSetReqPosition:
810 movem.l d2-d7/a2-a5,-(a7)
811 move.l a0,a4 ; a4 = newwindow
812 move.l a1,a3 ; a3 = screen
813 move.l a2,a5 ; a5 = win
814 move.l a1,a0
815 subq.w #4,a7
816 move.l a7,a1
817 subq.w #4,a7
818 move.l a7,a2
819 move.l d0,-(a7)
820 jsr _LVOrtGetVScreenSize(a6)
821 move.l (a7)+,d0
822 move.l (a7)+,d7 ; d7 = scrheight
823 move.l (a7)+,d6 ; d6 = scrwidth
824 moveq #0,d1
825 move.w sc_LeftEdge(a3),d1
826 ext.l d1
827 neg.l d1 ; d1 = leftedge
828 bpl.b posleft
830 moveq #0,d1
831 posleft:
832 moveq #0,d2
833 move.w sc_TopEdge(a3),d2
834 ext.l d2
835 neg.l d2 ; d2 = topedge
836 bpl.b postop
838 moveq #0,d2
839 postop:
840 move.l d1,d3 ; d3 = left
841 move.l d2,d4 ; d4 = top
842 move.l d6,a1 ; a1 = width
843 move.l d7,a2 ; a2 = height
844 ; switch (reqpos) {
845 cmp.l #REQPOS_DEFAULT,d0 ; is d0 == REQPOS_DEFAULT
846 bne.b notdefault
848 ; case REQPOS_DEFAULT:
849 moveq #25,d0
850 move.w d0,(a4) ; == move.w d5,nw_LeftEdge(a4)
851 moveq #18,d0
852 move.w d0,nw_TopEdge(a4)
853 bra.b tlscr
855 notdefault:
856 tst.l d0
857 bne.b notpointer
859 ; case REQPOS_POINTER:
860 move.w sc_MouseX(a3),d3 ; mx = scr->MouseX
861 move.w sc_MouseY(a3),d4 ; my = scr->MouseY
862 bra.b endswitch
864 notpointer:
865 subq.l #1,d0
866 bne.b notcentwin
868 ; case REQPOS_CENTERWIN:
869 move.l a5,d0
870 beq.b centscr
872 move.w wd_LeftEdge(a5),d3 ; left = win->LeftEdge
873 move.w wd_TopEdge(a5),d4 ; top = win->TopEdge
874 move.w wd_Width(a5),a1 ; width = win->Width
875 move.w wd_Height(a5),a2 ; height = win->Height
876 bra.b centscr
878 notcentwin:
879 subq.l #1,d0
880 bne.b notcentscr
882 ; case REQPOS_CENTERSCR:
883 centscr:
884 move.l a1,d0
885 moveq #0,d5
886 move.w nw_Width(a4),d5
887 sub.l d5,d0
888 lsr.l #1,d0
889 add.l d0,d3 ; mx = (width - nw->Width) / 2 + left
890 move.l a2,d0
891 move.w nw_Height(a4),d5
892 sub.l d5,d0
893 lsr.l #1,d0
894 add.l d0,d4 ; my = (height - nw->Height) / 2 + top
895 bra.b endswitch
897 notcentscr:
898 subq.l #1,d0
899 bne.b nottlwin
901 ; case REQPOS_TOPLEFTWIN:
902 move.l a5,d0
903 beq.b tlscr
905 move.w wd_LeftEdge(a5),d3 ; left = win->LeftEdge
906 move.w wd_TopEdge(a5),d4 ; top = win->TopEdge
907 * bra.b tlscr
909 nottlwin:
910 * subq.l #1,d0
911 * bne.b endswitch
913 ; case REQPOS_TOPLEFTSCR:
914 tlscr:
915 * move.l d3,d3 ; mx = left
916 * move.l d4,d4 ; my = top
917 endswitch:
918 ; } /* switch */
920 add.w (a4),d3 ; == add.w nw_LeftEdge(a4),d3
921 cmp.w d1,d3
922 bgt.s okleft
924 move.w d1,d3
925 okleft:
926 add.w d6,d1
927 sub.w nw_Width(a4),d1 ; leftedge + scrwidth - nw->Width
928 cmp.w d1,d3
929 blt.s okright
931 move.w d1,d3
932 okright:
934 add.w nw_TopEdge(a4),d4
935 cmp.w d2,d4
936 bgt.s oktop
938 move.w d2,d4
939 oktop:
940 add.w d7,d2
941 sub.w nw_Height(a4),d2 ; leftedge + scrwidth - nw->Width
942 cmp.w d2,d4
943 blt.s okbottom
945 move.w d2,d4
946 okbottom:
948 move.w d3,(a4) ; == move.w d3,nw_LeftEdge(a4)
949 move.w d4,nw_TopEdge(a4)
951 movem.l (a7)+,d2-d7/a2-a5
955 SECTION __MERGED,BSS
957 XDEF _ReqToolsBase
958 XDEF _IntuitionBase
959 XDEF _GadToolsBase
960 XDEF _DOSBase
961 XDEF _GfxBase
962 XDEF _UtilityBase
963 XDEF _LayersBase
964 XDEF _LocaleBase
965 XDEF _ConsoleDevice
966 XDEF _ButtonImgClass
967 XDEF _SysBase
969 _ReqToolsBase: ds.b 4
970 _SysBase: ds.b 4
971 _IntuitionBase: ds.b 4
972 _GadToolsBase: ds.b 4
973 _DOSBase: ds.b 4
974 _GfxBase: ds.b 4
975 _UtilityBase: ds.b 4
976 _LayersBase: ds.b 4
977 _LocaleBase: ds.b 4
978 _ConsoleDevice: ds.b 4
979 _ButtonImgClass: ds.b 4
980 iorequest: ds.b IOSTD_SIZE