4 ; APCS interface to WIMP SWIs
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Steel library.
13 ; Steel 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 ; Steel 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 Steel. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Initialising the WIMP ------------------------------------------------
29 ; --- wimp_initialise ---
31 ; On entry: a1 == pointer to where to put the version number
33 EXPORT wimp_initialise
34 wimp_initialise STMFD sp!,{lr} ;Save the link register
35 MOV ip,a1 ;Save this away for a bit
36 MOV a1,#120 ;Make sure it's Arthur :-)
37 MOV a2,#0 ;Don't start a WIMP task
38 SWI XWimp_Initialise ;Start up the WIMP
39 STRVC a1,[ip] ;Store the version number
40 MOVVC a1,#0 ;If no error, return no error
41 LDMFD sp!,{pc}^ ;Return to caller
43 ; --- wimp_taskinit ---
45 ; On entry: a1 == pointer to name of task
46 ; a2 == pointer to version number (to be updated)
47 ; a3 == pointer to task handle to set
48 ; a4 == optional pointer to messages block
51 wimp_taskinit STMFD sp!,{a2,a3,lr} ;Stash lots of registers
52 MOV a3,a1 ;Point to the task name
53 LDR a1,[a2] ;Get the version number
54 LDR a2,wimp__magic ;Load the strange magic value
55 SWI XWimp_Initialise ;Initialise the WIMP
56 LDMIA sp!,{a3,a4,lr} ;Get the pointers back
57 STRVC a1,[a3] ;Store the version number
58 STRVC a2,[a4] ;Store the task handle too
59 MOVVC a1,#0 ;If no error, clear return
60 MOVS pc,lr ;Return to caller
62 wimp__magic DCB "TASK" ;The magic value for initing
64 ;----- Closing the WIMP down again ------------------------------------------
66 ; --- wimp_closedown ---
71 wimp_closedown SWI XWimp_CloseDown ;Close down the WIMP
72 MOVVC a1,#0 ;If no error, return clear
73 MOVS pc,lr ;Return to caller
75 ; --- wimp_taskclose ---
77 ; On entry: a1 == my task handle to use
80 wimp_taskclose LDR a2,wimp__magic ;Get the magic number again
81 SWI XWimp_CloseDown ;Close down my task only
82 MOVVC a1,#0 ;Clear error if it worked
83 MOVS pc,lr ;Return to caller
85 ;----- Everything else :-) --------------------------------------------------
87 ; --- wimp_create_wind ---
89 ; On entry: a1 == pointer to window definition
90 ; a2 == pointer to window handle to fill in
92 EXPORT wimp_create_wind
94 MOV a4,a2 ;Keep pointer to handle too
95 MOV a2,a1 ;Point to window definition
96 SWI XWimp_CreateWindow ;Create the new window
97 STRVC a1,[a4] ;Store the handle away
98 MOVVC a1,#0 ;And clear the error code
99 MOVS pc,lr ;Return to caller
101 ; --- wimp_create_icon ---
103 ; On entry: a1 == pointer to icon creation block
104 ; a2 == pointer to icon handle to fill in
106 EXPORT wimp_create_icon
108 MOV a4,a2 ;Keep pointer to icon handle
109 MOV a2,a1 ;Point to the icon block
110 SWI XWimp_CreateIcon ;Create the icon now
111 STRVC a1,[a4] ;Store the icon handle away
112 MOVVC a1,#0 ;Clear any error code
113 MOVS pc,lr ;Return to caller
115 ; --- wimp_delete_wind ---
117 ; On entry: a1 == window handle
119 EXPORT wimp_delete_wind
121 STMFD sp!,{a1} ;Store window handle on stack
122 MOV a2,sp ;Point to saved handle
123 SWI XWimp_DeleteWindow ;Delete the window
124 MOVVC a1,#0 ;Return no error if success
125 ADD sp,sp,#4 ;Restore stack pointer
126 MOVS pc,lr ;Return to caller
128 ; --- wimp_delete_icon ---
130 ; On entry: a1 == window handle
133 EXPORT wimp_delete_icon
135 STMFD sp!,{a1,a2} ;Stack registers for block
136 MOV a2,sp ;Point to the block
137 SWI XWimp_DeleteIcon ;Do the SWI
138 MOVVC a1,#0 ;Clear the error indicator
139 ADD sp,sp,#8 ;Restore stack pointer
140 MOVS pc,lr ;Return to caller
142 ; --- wimp_open_wind ---
144 ; On entry: a1 == pointer to window block
146 EXPORT wimp_open_wind
147 wimp_open_wind MOV a2,a1 ;Point to window block
148 SWI XWimp_OpenWindow ;Do the SWI
152 ; --- wimp_close_wind ---
154 ; On entry: a1 == window handle
156 EXPORT wimp_close_wind
157 wimp_close_wind STMFD sp!,{a1} ;Store window handle away
158 MOV a2,sp ;Point to the `block'
159 SWI XWimp_CloseWindow ;Close the window
161 ADD sp,sp,#4 ;Restore the stack
164 ; --- wimp_redraw_wind ---
166 ; On entry: a1 == pointer to a redraw structure to fill in
167 ; a2 == pointer to a `more' variable to fill in
169 EXPORT wimp_redraw_wind
171 MOV a3,a2 ;Keep this pointer safe
172 MOV a2,a1 ;Point to redraw structure
173 SWI XWimp_RedrawWindow ;Do the redraw window call
174 STRVC a1,[a3] ;Store the `more' variable
176 MOVS pc,lr ;Return to caller
178 ; --- wimp_update_wind ---
180 ; On entry: a1 == pointer to a redraw structure to fill in
181 ; a2 == pointer to a `more' variable to fill in
183 EXPORT wimp_update_wind
185 MOV a3,a2 ;Keep this pointer safe
186 MOV a2,a1 ;Point to redraw structure
187 SWI XWimp_UpdateWindow ;Do the update window call
188 STRVC a1,[a3] ;Store the `more' variable
190 MOVS pc,lr ;Return to caller
192 ; --- wimp_get_rectangle ---
194 ; On entry: a1 == pointer to a redraw structure to fill in
195 ; a2 == pointer to a `more' variable to fill in
197 EXPORT wimp_get_rectangle
199 MOV a3,a2 ;Keep this pointer safe
200 MOV a2,a1 ;Point to redraw structure
201 SWI XWimp_GetRectangle ;Get the next rectangle
202 STRVC a1,[a3] ;Store the `more' variable
204 MOVS pc,lr ;Return to caller
206 ; --- wimp_get_wind_state ---
208 ; On entry: a1 == window handle
209 ; a2 == pointer to block to fill in
211 EXPORT wimp_get_wind_state
213 STR a1,[a2,#0] ;Fill in the window handle
214 SWI XWimp_GetWindowState
218 ; --- wimp_get_wind_info ---
220 ; On entry: a1 == pointer to block to fill in
222 EXPORT wimp_get_wind_info
225 SWI XWimp_GetWindowInfo
229 ; --- wimp_set_icon_state ---
231 ; On entry: a1 == window handle
236 EXPORT wimp_set_icon_state
240 SWI XWimp_SetIconState
245 ; --- wimp_get_icon_info ---
247 ; On entry: a1 == window handle
249 ; a3 == pointer to structure to fill in
251 EXPORT wimp_get_icon_info
253 SUB sp,sp,#40 ;Make space for icon block
254 STMIA sp,{a1,a2} ;Fill in the handles nicely
255 MOV a2,sp ;Point to the block
256 SWI XWimp_GetIconState ;Get information about icon
257 ADDVS sp,sp,#40 ;If it failed, restore stack
258 MOVVSS pc,lr ;And return to caller
259 ADD sp,sp,#8 ;Point to icon info
260 LDMIA sp!,{a1,a2,a4,ip} ;Get some of the data
261 STMIA a3!,{a1,a2,a4,ip} ;Store in the caller's buffer
262 LDMIA sp!,{a1,a2,a4,ip} ;Get the rest of the icon
263 STMIA a3!,{a1,a2,a4,ip} ;And store that away too
264 MOV a1,#0 ;Nothing went wrong
265 MOVS pc,lr ;Return to caller
267 ; --- wimp_get_point_info ---
269 ; On entry: a1 == pointer to block to fill in
271 EXPORT wimp_get_point_info
273 MOV a2,a1 ;Point to the block
274 SWI XWimp_GetPointerInfo ;Get the mouse information
278 ; --- wimp_drag_box ---
280 ; On entry: a1 == pointer to a drag structure
283 wimp_drag_box MOV a2,a1 ;Point to the block
284 SWI XWimp_DragBox ;Perform the drag
288 ; --- wimp_force_redraw ---
290 ; On entry: a1 == pointer to a redraw block
292 EXPORT wimp_force_redraw
294 STMFD sp!,{v1,lr} ;Store v1 away nicely
295 LDMIA a1,{a1-a4,v1} ;Get registers from the block
296 SWI XWimp_ForceRedraw
300 ; --- wimp_set_caret_pos ---
302 ; On entry: a1 == pointer to a caret structure to set
304 EXPORT wimp_set_caret_pos
306 STMFD sp!,{v1,v2,lr} ;Store v1 and v2 away nicely
307 LDMIA a1,{a1-a4,v1,v2}
308 SWI XWimp_SetCaretPosition
310 LDMFD sp!,{v1,v2,pc}^
312 ; --- wimp_get_caret_pos ---
314 ; On entry: a1 == pointer to caret structure to fill in
316 EXPORT wimp_get_caret_pos
319 SWI XWimp_GetCaretPosition
323 ; --- wimp_create_menu ---
325 ; On entry: a1 == pointer to menu
326 ; a2 == x coordinate to open menu
327 ; a3 == y coordinate to open menu
329 EXPORT wimp_create_menu
338 ; --- wimp_decode_menu ---
340 ; On entry: a1 == pointer to menu
341 ; a2 == pointer to menu hit array
342 ; a3 == pointer to buffer for string
344 EXPORT wimp_decode_menu
353 ; --- wimp_which_icon ---
355 ; On entry: a1 == pointer to strange which block thing
356 ; a2 == pointer to where to store the results
358 EXPORT wimp_which_icon
359 wimp_which_icon LDMIA a1,{a1,a3,a4} ;Get arguments from block
364 ; --- wimp_set_extent ---
366 ; On entry: a1 == pointer to strange block with window handle
368 EXPORT wimp_set_extent
369 wimp_set_extent ADD a2,a1,#4 ;Point to extent block
370 LDR a1,[a1] ;Get the window handle
375 ; --- wimp_set_point_shape ---
377 ; On entry: a1 == pointer to a freaky pointer shape structure
379 EXPORT wimp_set_point_shape
382 LDMIA a1,{a1-a4,v1,v2}
383 SWI XWimp_SetPointerShape
385 LDMFD sp!,{v1,v2,pc}^
387 ; --- wimp_open_template ---
389 ; On entry: a1 == pointer to name of template file
391 EXPORT wimp_open_template
394 SWI XWimp_OpenTemplate
398 ; --- wimp_close_template ---
402 EXPORT wimp_close_template
404 SWI XWimp_CloseTemplate
408 ; --- wimp_load_template ---
410 ; On entry: a1 == pointer to a template structure
412 EXPORT wimp_load_template
414 MOV ip,a1 ;Keep the pointer safe
415 STMFD sp!,{v1-v3,lr} ;Save lots of registers
416 LDMIA ip,{a1-a4,v1-v3} ;Get all the arguments
417 CMP v1,#0 ;If no font array specified
418 MOVEQ v1,#-1 ;Pass the *correct* value
419 SWI XWimp_LoadTemplate ;Load the template
420 STMVCIA ip,{a1-a4,v1-v3} ;Store the information back
421 MOVVC a1,#0 ;Clear error indicator
422 LDMFD sp!,{v1-v3,pc}^ ;Return to caller
424 ; --- wimp_processkey ---
426 ; On entry: a1 == key to process
428 EXPORT wimp_processkey
429 wimp_processkey SWI XWimp_ProcessKey
433 ; --- wimp_starttask ---
435 ; On entry: a1 == pointer to command to execute
437 EXPORT wimp_starttask
438 wimp_starttask SWI XWimp_StartTask
442 ; --- wimp_reporterror ---
444 ; On entry: a1 == pointer to error block
445 ; a2 == Wimp_ReportError flags word
446 ; a3 == pointer to application name
448 EXPORT wimp_reporterror
450 SWI XWimp_ReportError
454 ; --- wimp_getwindowoutline ---
456 ; On entry: a1 == pointer to a block to fill in
458 EXPORT wimp_getwindowoutline
459 wimp_getwindowoutline
461 SWI XWimp_GetWindowOutline
465 ; --- wimp_ploticon ---
467 ; On entry: a1 == pointer to icon to plot
470 wimp_ploticon MOV a2,a1
475 ; --- wimp_setmode ---
477 ; On entry: a1 == new mode to set
480 wimp_setmode SWI XWimp_SetMode
484 ; --- wimp_setpalette ---
486 ; On entry: a1 == pointer to palette to set
488 EXPORT wimp_setpalette
489 wimp_setpalette MOV a2,a1
494 ; --- wimp_readpalette ---
496 ; On entry: a1 == pointer to palette block to fill in
498 EXPORT wimp_readpalette
501 SWI XWimp_ReadPalette
504 ; --- It seems we must mangle the colours now ---
506 ; Since Wimp_ReadPalette leaves the bottom nibbles clear for
507 ; no sensible reason, and RISC_OSLib's wimp.c bodges the
508 ; palette to try and make it sensible, we must do the same
509 ; here, being careful to preserve the GCOL numbers at the
510 ; bottom of the palette words.
512 MOV a1,#20 ;Do this once for each entry
513 LDR a4,=&F0F0F000 ;Mask for copying nibbles
514 00 LDR a3,[a2] ;Get the next palette word
515 AND ip,a3,a4 ;Get the top nibbles
516 BIC a3,a3,a4,LSR #4 ;Clear the bottom nibbles
517 ORR a3,a3,ip,LSR #4 ;Shift down to copy nibbles
518 STR a3,[a2],#4 ;Store and bump a2 along
519 SUBS a1,a1,#1 ;Done another one
520 BNE %b00 ;If there's any more, loop
525 ; --- wimp_setcolour ---
527 ; On entry: a1 == colour to set
529 EXPORT wimp_setcolour
530 wimp_setcolour SWI XWimp_SetColour
534 ; --- wimp_sendmessage ---
536 ; On entry: a1 == the event type of the message
537 ; a2 == pointer to the message to send
538 ; a3 == the task handle of the recipient
540 ; --- wimp_sendwmessage ---
542 ; On entry: a1 == the event type again
543 ; a2 == pointer to the message to send
544 ; a3 == the window handle of the recipient
545 ; a4 == the icon handle of the recipient
549 ; Since the registers are set up perfectly in both cases, we can use the
552 EXPORT wimp_sendmessage
553 EXPORT wimp_sendwmessage
556 SWI XWimp_SendMessage
560 ; --- wimp_create_submenu ---
562 ; On entry: a1 == pointer to menu to open
563 ; a2 == x coordinate to open it at
564 ; a3 == y coordinate to open it at
566 EXPORT wimp_create_submenu
571 SWI XWimp_CreateSubMenu
575 ; --- wimp_spriteop ---
577 ; On entry: a1 == the reason code to pass
578 ; a2 == the name of the sprite to do it on
581 wimp_spriteop STMFD sp!,{v1-v6,lr}
585 LDMFD sp!,{v1-v6,pc}^
587 ; --- wimp_spriteop_full ---
589 ; On entry: a1 == pointer to registers to use
591 EXPORT wimp_spriteop_full
595 LDMIA ip,{a1-a4,v1-v6}
597 STMVCIA ip,{a1-a4,v1-v6}
599 LDMFD sp!,{v1-v6,pc}^
601 ; --- wimp_baseofsprites ---
604 ; On exit: a1 == pointer to WIMP sprite pool in RMA
606 EXPORT wimp_baseofsprites
612 ; --- wimp_blockcopy ---
614 ; On entry: a1 == window handle
615 ; a2 == pointer to source rectangle
616 ; a3 == destination x coordinate
617 ; a4 == destination y coordinate
619 EXPORT wimp_blockcopy
620 wimp_blockcopy STMFD sp!,{v1-v3,lr}
623 LDMIA a2,{a2,a3,a4,v1}
626 LDMFD sp!,{v1-v3,pc}^
628 ; --- wimp_slotsize ---
630 ; On entry: a1 == pointer to current slot size
631 ; a2 == pointer to next slot size
632 ; a3 == pointer to free pool size
635 wimp_slotsize STMFD sp!,{v1-v3,lr} ;Stack registers
636 MOV a4,a1 ;Keep pointer to current
637 MOV v2,a2 ;Keep pointer to next
638 MOV v3,a3 ;Keep pointer to free
639 LDR a1,[a1] ;Get the actual current slot
640 LDR a2,[a2] ;Get the actual next slot
641 SWI XWimp_SlotSize ;Set or read the slot size
642 STRVC a1,[a4] ;Store current slot size
643 STRVC a2,[v2] ;Store next slot size
644 STRVC a3,[v3] ;Store free area size
645 MOVVC a1,#0 ;Clear error marker
646 LDMFD sp!,{v1-v3,pc}^ ;Return to caller
648 ; --- wimp_readpixtrans ---
650 ; On entry: a1 == pointer to sprite area
651 ; a2 == pointer to sprite id (yuk)
652 ; a3 == pointer to scale factors to fill in
653 ; a4 == pointer to translation table to fill in
655 EXPORT wimp_readpixtrans
659 ; --- Put the registers in the right places ---
666 ; --- Set up the reason code properly ---
668 CMP a2,#0 ;Is it the WIMP or system
669 CMPNE a2,#1 ;sprite area?
670 MOVEQ a1,#&000 ;Then say it's system area
671 BEQ %f00 ;And branch ahead
673 ; --- Munge the sprite ID to get the right reason code ---
675 LDR lr,[a3,#4] ;Get the sprite ID tag
676 CMP lr,#0 ;Is it a name
677 MOVEQ a1,#&100 ;Yes -- user area, named
678 MOVNE a1,#&200 ;No -- user area, pointer
680 ; --- Now get the pixel translation ---
682 00 LDR a3,[a3,#0] ;Get sprite name or pointer
683 SWI XWimp_ReadPixTrans ;Do the actual operation
685 MOVVC a1,#0 ;If it succeeded, no error
686 LDMFD sp!,{v3,v4,pc}^ ;Return to caller
688 ; --- Missing call ---
690 ; We omit a veneer for Wimp_ClaimFreeMemory, since it's not much use unless
691 ; you're in SVC mode, in which case you'd better be writing in assembler
694 ; --- wimp_commandwindow ---
696 ; On entry: a1 == pointer to a funny structure
698 EXPORT wimp_commandwindow
700 MOV a2,a1 ;Keep pointer to structure
701 LDR a3,[a2,#0] ;Get the operation code
703 ; --- Work out what the operation is meant to be ---
705 ; If we don't recognise the `tag' then all hell breaks loose.
707 CMP a3,#0 ;Create window with title
708 LDREQ a1,[a2,#4] ;Then find the title
709 CMP a3,#1 ;Just make window `active'
710 MOVEQ a1,#1 ;Horrors -- that's right
711 CMP a3,#2 ;Close the window, prompting
712 MOVEQ a1,#0 ;Then set up the code
713 CMP a3,#3 ;Close the window, no prompt
714 MOVEQ a1,#-1 ;Do that right too
716 ; --- Now just do it ---
718 SWI XWimp_CommandWindow
722 ; --- wimp_textcolour ---
724 ; On entry: a1 == colour to set
726 EXPORT wimp_textcolour
727 wimp_textcolour SWI XWimp_TextColour
731 ; --- wimp_transferblock ---
733 ; On entry: a1 == source task's handle
734 ; a2 == address of buffer in source task
735 ; a3 == destination task's handle
736 ; a4 == address of buffer in destination task
737 ; [sp] == amount of data to transfer
739 EXPORT wimp_transferblock
741 STMFD sp!,{v1,lr} ;Save v1 on the stack
742 LDR v1,[sp,#8] ;Get the buffer length
743 SWI XWimp_TransferBlock ;Do the operation
747 ; --- wimp_readsysinfo ---
749 ; On entry: a1 == information to read
750 ; a2 == where to put R0 on exit
751 ; a3 == where to put R1 on exit
753 EXPORT wimp_readsysinfo
758 SWI XWimp_ReadSysInfo
767 ; --- wimp_setfontcolours ---
769 ; On entry: a1 == background colour
770 ; a2 == foreground colour
772 EXPORT wimp_setfontcolours
774 SWI XWimp_SetFontColours
778 ; --- wimp_getmenustate ---
780 ; On entry: a1 == what to do
781 ; a2 == pointer to buffer to fill in
782 ; a3 == window handle (optional)
783 ; a4 == icon handle (optional too)
785 EXPORT wimp_getmenustate
787 SWI XWimp_GetMenuState
791 ; --- wimp_addmessages ---
793 ; On entry: a1 == pointer to messages array
795 EXPORT wimp_addmessages
797 SWI XWimp_AddMessages
801 ; --- wimp_removemessages ---
803 ; On entry: a1 == pointer to messages array
805 EXPORT wimp_removemessages
807 SWI XWimp_RemoveMessages
811 ; --- Missing call ---
813 ; We omit a veneer for Wimp_SetColourMapping, since it's for specialised use
814 ; only probably, and not of use to an average application.
816 ;----- That's all, folks ----------------------------------------------------