home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / winsup / SWIs < prev    next >
Encoding:
Text File  |  1992-04-02  |  18.5 KB  |  360 lines

  1. WinSupport SWIs
  2.  
  3.  
  4. The WinSupport module provides a number of SWIs (SoftWare Interrupts). The module has got an official SWI number from Acorn. The module is viewed as an operating system extension and has the  SWI chunk number is &43EC0 and the SWI prefix of "WinSupport"
  5.  
  6.  
  7. SWI:      WinSupport_Lock (&43EC0)
  8. Use:      Identical action to *command of same name
  9. On Entry: -
  10. On Exit:  -
  11. Processor mode: SVC
  12. Re-entrancy: Undefined (unlikely to happen in any case)
  13.  
  14. ***********
  15.  
  16. SWI:      WinSupport_UnLock (&43EC1)
  17. Use:      Identical action to *command of same name
  18. On Entry: -
  19. On Exit:  -
  20. Processor mode: SVC
  21. Re-entrancy: Undefined (unlikely in any case
  22. The reason codes are as follows:
  23.  
  24. ***********
  25.  
  26. SWI:       WinSupport_FlexHeap (&43EC2)
  27.         0: Initialise heap
  28.         1: Describe heap
  29.         2: Claim heap block
  30.         3: Release heap block
  31.         4: Resize claimed heap block
  32.         5: Resize heap 
  33.         6: Read claimed block info
  34.         7: Read Heap Info
  35.         8: Force heap compaction
  36.         9: Change slot (resize heap, release memory, call Wimp)
  37.         10: Minimise task's memory requirement as much as possible
  38.  
  39. Re-entrancy: These SWI's are re-entrant as long as they are re-entered using a different heap pointer. Use of the SWI's in IRQ mode is possible as long as IRQ interrupts are disabled during the call and that the calls that in turn return or claim wimp memory are NEVER used. (if they aren't an interrupt can occur while in a heap manager SWI's, in this scenario, the heap manager would propably pick up the error before it got to exception stage, but your interrupt handler would probably be rendered useless). As SWI's should NEVER be used in FIQ mode, this obviously rules out the heap manger. 
  40.  
  41.  
  42. SWI WinSupport_FlexHeap  (rc. 0 - Initialise heap)
  43.  
  44. On Entry: r0: Reason Code (0)
  45.           Bit 8 set: Initialise heap memory to zero
  46.           r1: Pointer to memory to be claimed
  47.           r3: Size of heap or r3=-1 for auto size
  48.                               r1: Undefined
  49.                               r2: End of code (r2>&8000)
  50.           r4: Size of fixed variable and anchor point area
  51.           r5: Size of 'Stack' block (fixed - 0 for none)
  52.  
  53. On Exit:  r0 & r2-r3 Preserved
  54.           r1: Address of start of heap (if not set already)
  55.           r4: Address of variable/Anchor area
  56.           r5: Address of Heap block                     
  57.  
  58. Re-entrancy:  See above
  59.  
  60. Errors:   Address Range invalid. (memory specified possibly doesn't exist). Shouldn't occur when using automatic slot size calculation.
  61.           Not a multiple of eight. (slot size must be a multiple of eight). Shouldn't occur when using automatic slot size calculation.
  62.           Not enough memory to define heap headers. (Total heap size smaller than sizes of header, var/anchor area and stack area). If using automatic slot calculation, try increasing minimum slot size. 
  63.  
  64.  
  65. Notes:   If the size of the heap is not a multiple of eight, it will be rouded down to the next multiple. Always store r1 on return somewhere, it is the pointer to the base of the heap and is needed for all heap manager calls. In future versions of the heap manager, the base of the heap might be rounded up to a multiple of sixteen to speed the operation up slightly (Crossing a sixteen bytes boundary when loading a lot of memory can slow things down by a small amount). By aligning to sixteen bytes, there is a 50/50 chance of a chunk being on the boundary
  66.  
  67.  
  68. SWI WinSupport_FlexHeap  (rc. 1 - Describe heap)
  69.  
  70. On Entry: r0: Reason code (1)
  71.           r1: Pointer to heap
  72.           
  73. On Exit:  r0-r1 Preserved
  74.           r2: Largest block free - Same as r3
  75.           r3: Total memory free              
  76.           r4: Size of Variable/Anchor area
  77.           r5: Stack block size
  78.           r6: Memory awaiting return            
  79.  
  80. Errors:   Only simple heap validation errors described above.
  81.                                                     
  82. SWI WinSupport_FlexHeap  (rc. 2 - Claim heap block)
  83.  
  84. On Entry: r0: Reason Code (2) (Bit 8 set: Expand Slot if necessary)
  85.           r1: Heap pointer
  86.           r3: Size of block required
  87.           r4: Anchor offset
  88.  
  89. ON Exit:  r0-r1: Preserved
  90.           r2: Address of block
  91.           r3-r4: Preserved
  92.               
  93.  
  94. Errors: Not a multiple of eight.
  95.         No memory to expand heap (when heap expansion is used due to lack of room)                                                  
  96.  
  97.  
  98. Notes: The heap manager doesn't keep track of allocated anchor points. If a claimed anchor point is reused when it still points to a block, you will have completely screwed up your heap! The call will be allowed but the next call that validates the heap won't be, so take care. This one may be sorted out in the next version.   
  99. Any extra memory that was borrowed from the WIMP (Bit 8 set on entry) is returned by free block and resize block (with negative change).
  100.  
  101. SWI WinSupport_FlexHeap  (rc. 3 - Release heap block)   
  102.  
  103. On Entry: r0: Reason code (3) (Bit: 8 Return memory that is borrowed.
  104.           r1: Heap Pointer
  105.           r2: Block Pointer 
  106.         
  107. On Exit:  r0-r2: Preserved
  108.  
  109. Errors:   Invalid heap pointer, invalid heap, invalid heap block
  110.  
  111. Notes:  Memory is returned if Bit 8 is set and if memory was 'borrowed' from the wimp when the block was claimed.          
  112.  
  113. SWI WinSupport_FlexHeap  (rc. 4 - Resize heap block) 
  114.  
  115. On Entry: r0: Reason code (4) (Bit 8: Return/claim memory)
  116.           r1: Heap Pointer
  117.           r2: Block Pointer
  118.           r3: Size change (negative for release, positive for claim)
  119.  
  120. On Exit:  r0-r3: Preserved
  121.  
  122. Errors:  Invalid heap pointer, invalid heap, invalid heap block, no memory to expand heap (bit 8 clear and not enough memory), unable to expand heap (bit 8 set, not memory in Wimp 'free' slot), Not a multiple of eight. You can't reduce size to zero. Negative change bigger that heap block.
  123.  
  124. Notes: Bit 8 set enables automatic claim/release. The M.P.R. Value is altered accordingly. See claim/release for more info
  125. At the moment, you cannot shrink a block to zero (release it completely). I consider this to be an advantage rather than a disadvantage, I think it is unlikely that you would ever need to do it. ie. it would only happen due to error. Obviously, heap blocks cannot assume negative sizes!
  126. Unlike the Acorn heap manager, the block stays put, but everything after it move so read their anchors points again.
  127.                                                       
  128. SWI WinSupport_FlexHeap  (rc. 5 - Resize heap)
  129.  
  130. On Entry: r0: Reason code (5) (Bit 8: Return/claim memory)
  131.           r1: Heap Pointer
  132.           r3: Size change (negative for release, positive for claim)
  133.  
  134. On Exit:  r0-r1,r2: Preserved          
  135.  
  136. Errors: Invalid heap, Invalid heap pointer, no memory to expand heap, Heap cannot contract this far (not enough free space in heap)
  137.  
  138. Notes: If bit 8 is set, memory is claimed or release (dependant on r3 on entry). If bit 8 is clear, the heap manager assumes you have got some memory for it to expand into. As it is not checked, you could get an address exception or data abort. Again, obviously, you cannot contract the heap below the header block, or smaller than the top of the heap (above the blocks).
  139.  
  140. SWI WinSupport_FlexHeap  (rc. 6 Read block size)
  141.  
  142. On Entry: r0: Reason Code (6)
  143.           r1: Heap Pointer
  144.           r2: Block pointer
  145.  
  146. On Exit:  r0-r2: Preserved
  147.           r3: Size of block
  148.           r4: Achor point
  149.  
  150. Errors: Invalid heap, Invalid heap pointer, Invalid heap block.
  151.  
  152. Notes: None
  153.  
  154. SWI WinSupport_FlexHeap  (rc. 7 Read Heap Info)
  155.  
  156. On Entry: r0: Reason Code (7)
  157.           r1: Heap pointer (for some info reason codes)
  158.           r2: Info Number
  159.  
  160. On Exit:  r0-r1: Preserved
  161.           r2: Value
  162.  
  163.           Info Numbers: (r2)
  164.           0:  Task Slot Size        (r1=hp)
  165.           1:  Memory Pending Return (r1=hp)
  166.           2:  Lock number
  167.  
  168. Errors:   Heap invalid, Heap pointer invalid (only on some operations)
  169.           
  170. Notes:    Three info numbers are supported at present. If you've got a suggestion for other heap info you need to know, please let me know.....
  171.  
  172. SWI WinSupport_FlexHeap  (rc. 8 Compact heap)
  173.  
  174. On Entry: r0: Reason code (8)
  175.           r1: Heap pointer
  176.           
  177. On Exit:  r0-r1: Preserved
  178.  
  179. Errors: Invalid heap, Invalid heap pointer
  180.  
  181. Notes:  This SWI forces heap compaction, the only reason I can see for this is to save processor time in long processing. (Call a while before). As compaction is forced for any heap manager SWIs that resizes the heap or heap block, therefore, whenever bit 8 is set, I cannot see much use for it. Well anyway it's here if you want it.........
  182.  
  183. SWI WinSupport_FlexHeap  (rc. 9 Process wimp slot size message)
  184.  
  185. On Entry: r0: Reason code (9)
  186.           r1: Pointer to block returned from Wimp_Poll
  187.           r2: Heap Pointer
  188.           r3: Task Handle
  189.  
  190. On Exit:  r0-r3: Preserved
  191.  
  192. Errors: No errors will be returned from this SWI, if errors do occur, they are just suppressed and the message gets acknowledged but not processed. 
  193.  
  194. Notes: Of course only call this SWI if it is a SetSlot message (&400C5). If it is this message, just call the SWI and then return to your polling loop on return. The SWI compacts the heap, then either claims more memory or releases memory as necessary. The applications task manager slot will become a red one (user dragable).
  195.  
  196. SWI WinSupport_FlexHeap  (rc. 10 Minimize task memory)
  197.  
  198. On Entry: r0: Reason code (1)
  199.           r1: Heap Pointer
  200.  
  201. On Exit:  r0-r1: Preserved
  202.  
  203. Errors: Heap not valid, Heap pointer not valid.
  204.  
  205. Notes: This SWI will simply minimise the size of the heap by compacting it and automatically returning memory to the Wimp. The use of this is that minimising memory in the task manager can be difficult
  206.  
  207. SWI WinSupport_Debug (&43EC3)
  208.  
  209. This SWI provides debug code that may be called from your code. It is generally best to put the routine on the bottom of the icon bar memu. Again, just call this SWI
  210. The important addresses in the heap are listed and a *Command prompt provided. Just press return on an empty prompt to end. From my experience, this the the best way to debug wimp applications.
  211.  
  212. Watch what you type on the prompt, anyting that loads another application or starts another task, will take your task's domain (ie quit it automatically).
  213. without return.
  214.  
  215. On Entry: r1: Base of heap
  216.           r2: Buffer (256 bytes long or more, The Poll block is fine)
  217.  
  218. On Exit: r1-r2 Preserved
  219.  
  220. SWI WinSupport_MemMove (&43EC4)
  221.  
  222. Use fast memory move routines employed in heap.
  223.  
  224. On Entry: r1: Source block
  225.           r2: Destination block (-1 to read address of negative mem routine)
  226.           r3: Length of block (-1 to read addess of positive mem routine)
  227.  
  228. On Exit:  r1-r3: Preserved
  229.           if r2=-1, address of routine
  230.           if r3=-1, address of routine
  231.  
  232. Errors: None
  233.  
  234. Notes: Uses extremely fast memory move routine, moves in multiples of 40 bytes (providing there are 40) and then finds the most economical combination of moves for the rest (32,24,16,8,4,3,2,1 in fact). These are in fact the routines used in the heap for compaction (negative) and block expand (positive) and they have been optimised considerably. Ratio: for 240 bytes/31 Instrctions for large quantities. Progressively lower ratios for smaller quantities. Best used for 40+ bytes although they are reasonably efficient for smaller quantities. Address of routines: These are provided for programmers who need fast memory move many times (more than two) in a routine, saving the accumulated effect of calling the SWI handler a few times. Read address at the beginning of the routine and put somewhere safe. Call as necessary. They work in any processor mode and preserve all registers. Entry to both routines is identical but the effect is very different!!!!
  235.  
  236. On Entry:  r0: Number of bytes to move. NEVER zero or negative
  237.            r3: Destination block
  238.            r4: Source block
  239.           r13: Full descending stack (if entering in same processor mode)
  240.  
  241. On Exit:   all registers preserved (r0-12,r14}
  242.  
  243. Further optimisation can be achieved by using quad-word aligning blocks (at a sixteen byte boundary). According to what I have heard, you should be able to knock off 1 instruction per 16 Bytes this way.
  244.  
  245. Example:
  246.  
  247. \\\\ r0,r3 & r4 set up. r11 contain routine address
  248. SWI     "OS_EnterOS"    \\ Do this if you want to do it in SVC mode
  249. MOV     r14,pc          \ make it work like a BL instruction (12 bytes ahead)
  250. either BIC     r14,r14,#3  \ if using SVC clear to USR mode for return
  251. or     ADDNV   r0,r0,#0    \ if not waste a processor instrcution.
  252. \ but not neither!!!!
  253. MOVS   pc,r11              \ go to routine                                 
  254. .return                    \ with any luck we end up here! (if not don't ask)
  255.                                           
  256.  
  257.  
  258.  
  259.  
  260. SYS         "WinSupport_XTemplate"  (&43EC5)
  261.  
  262. Use:        Open/Load Template/Close extended template file. Extended Template calls complement the Wimp ones by providing a menu template system, housed in the same file as window templates (use the wimp for these).                           
  263. SYS         "WinSupport_XTemplate"
  264.  
  265. rc:         0 - Load template file'
  266.             1 - Load menu template
  267.             2 - Close template
  268.                                 
  269.  
  270. SYS         "WinSupport_XTemplate" (rc: 0)
  271.  
  272. On Entry:   r0 - Reason code (0)
  273.             r1 - Zero terminated filename 
  274.  
  275. On Exit:    r0-r1 Preserved
  276.  
  277. Notes: This in fact load the template file into module workspace to save time when actually loading templates. Only one can be opened at once (Remember to close it when finished)
  278.  
  279.  
  280. SYS         "WinSupport_XTemplate" (rc: 1)
  281.  
  282. On Entry:   r0 - Reason Code (1)                                 
  283.             r1 - Buffer for Menu
  284.             r2 - Pointer to indirected icon workspace
  285.             r3 - Pointer to end of indirected icon workspace
  286.             r4 - Pointer to font table (-1 if non are to be used)
  287.             r5 - Pointer to template name.
  288.             r6 - Index into template list (0 for first call)
  289.  
  290. On Exit:    r0-r2 & r4-r5 Preserved
  291.             r2 - Next Free byte in indirected icon workspace
  292.             r6 - Index 
  293.  
  294. Notes:      The entry and exit is very similar to Wimp_LoadTemplate and the wildcarded template names work in a similar way: '*' - End of string wildcard (if it is found the string is automatically passed) '.' - single character wildcard. If found any character is matched to it. The wildcard index is used when there are many templates with similar names and a wildcarded search string is used. On exit, the index points to the template that has just been loaded, so if you pass it back in through the SWI the next template will be found (if it exists).   
  295.  
  296. The idirected icon buffer will never exceded if the correct end is specified in r3. 
  297.  
  298. Fonts are treated in the same way as they are in Wimp_LoadTemplate. If the font array pointer is -1 fonts and fonts are found a the template, the references to fonts are turned into references to the system font and an error is returned after the process has finished so that the template is usable. 
  299.  
  300. Due to the recursive nature of the routine used in this SWI, error trapping is handled unusually. An error flag is kept, and if at the end of processing, it is set, the relevant error is returned. Unfortunately, only the first error is returned so other errors may well also have occured. 
  301.  
  302. Don't put menus into sliding heap blocks unless you use SWI "WinSupport_RelocateMenu" before creating the menu each time or the block are unlikely to move
  303.  
  304.  
  305. File format: I originally intended to include menu templates into normal template files with a different object tag, but Acorn doesn't approve of this idea..... Instead, they suggest that a data (&FFD) file is used instead. The file format is identical to normal template except that  that there is a file header "MENU" before the normal header word (&FFFFFFFF). See Page 1789 (Appendix E in Volume IV) of the RISC OS programmer's reference manual for more information. The menu template has an entry in the Index just as a normal template has with a tag type of 2.
  306.  
  307. The Menu template data block as pointed to by the index contains the menu and all associated indirected data. Fonts are numbered internally and refer to the template file font table. 
  308.  
  309. All absolute address are substituted with file offsets (from word 0 of the file) and are replaced by real address on being loaded.
  310.  
  311. A menu must appear at the beginning of the block, but after that, indirected icon data and further submenus can appear in any order.
  312.  
  313. The word at byte 4 of menu items is treated differently:
  314.  
  315. Bit 31 set: No submenu/window. Translated into -1 when loaded
  316. Bit 30 set: Submenu. Bit 0-26: File Offset: Translated to real address
  317. Bit 30+31 set: Window used instead. (you store window handle here later)
  318.                                                                         
  319. SWI "XWinSupport_RelocateMenu" (&43EC6)
  320.  
  321. Provided with old and new addresses, this routine will correct all pointers to absolute addresses in the menu structure  which may have become corrupt due to the movement of heap blocks.
  322. On Entry:
  323.  
  324. r2 -Old Menu pointer
  325. r3- Old Indirected data pointer
  326. r4- New Menu Pointer
  327. r5- New Indirected data pointer
  328.  
  329. On Exit:
  330. r2-r5 preserved
  331.  
  332. SWI "XWinSupport_FindMessage"  (&43EC7)
  333.  
  334. This routine is designed to find messages in a file. Messages are identified by their position in the file. The first word of the file is expected to the size of the file in bytes. You can create the files in edit leaving out the size. The file format you use and how you load the messages doesn't really matter as long as the message area is valid. The SWI is designed to be convenient to pass the message to SWI"Wimp_ReportError". NB terminators of 10 (LF) and 13 (CR) are used in files. If you need the terminator to be 0 (NULL) you will have to change it after requesting a message.  There is no problem with putting message files in sliding heap blocks as there are no absolute pointers.
  335.  
  336. On Entry:
  337.  
  338. r0 - Message number
  339. r1 - Pointer beginning of file in memory (size word)
  340.  
  341. On Exit:
  342.  
  343. r0 - Pointer to message (if you need to change mesage, copy it into your own memory)
  344. r1 - Preserved.
  345.  
  346. NB. This SWI may well provide facilities similar to those provided by MessageTrans which is provided on ROM in RISCOS III and with the Acorn printer drivers (release 2.44 or above). Unfortunately, I have not found documentation of the module anywhere.
  347.  
  348.  
  349.  
  350. Note about the use of sliding heap blocks
  351.  
  352. If you claim a number of blocks at the beginning of the heap and then do not release or resize any of them, they all should stay at the same position in memory, therefore meaning it is safe to put data that is pointed to by something else in them. (useful for indirected icon data etc.)
  353.  
  354. What can go in a 'loose' heap block. (block that could move) 
  355.  
  356. Sprite areas
  357. WinSupport Messagefiles
  358. Menus definitions (if you always use WinSupport_RelocateMenu)
  359. Most wimp parameter blocks
  360. Anything else that does not keep absolute pointers.