Archimedes Operating System
Total Page:16
File Type:pdf, Size:1020Kb
Archimedes Operating System A Dabhand Guide Alex and Nic van Someren DABS PRESS For Alice and Carol Archimedes Operating System: A Dabhand Guide © Alex and Nic van Someren ISBN 1-870336-48-8 First edition, third impression June 1991 Editor: Bruce Smith Proofreading: Syd Day Typesetting: Bruce Smith Cover: Clare Atherton All Trademarks and Registered Trademarks are hereby acknowledged. Within this Reference Guide the term BBC refers to the British Broadcasting Corporation. All rights reserved. No part of this book (except brief passages quoted for critical purposes) or any of the computer programs to which it relates may be reproduced or translated in any form, by any means mechanical electronic or otherwise without the prior written consent of the copyright holder. Disclaimer: Because neither Dabs Press nor the authors have any control over the way in which the contents of this book are used, no warranty is given or should be implied as to the suitability of the advice or programs for any given application. No liability can be accepted for any consequential loss or damage, however caused, arising as a result of using the programs or advice printed in this book. Published by Dabs Press, PO Box 48, Prestwich, Manchester M25 7HN. Tel. 061-773 8632 Fax. 061-773 8290 Typeset in 10 on llpt Palatino by Dabs Press using the Acornsoft VIEW wordprocessor, MacAuthor, Apple Macintosh SE and LaserWriter II NT. Printed and bound in the UK by BPCC Wheaton, Exeter, Devon EX2 8RP 2 Contents Introduction 13 Listing and Appendicies 13 What this Book is Not About 14 1: RISC Technology 15 The History of RISC 15 RISC and the Archimedes 16 The ARM 17 The MEMC Memory Controller 18 The VIDC Video Controller 18 The IOC Input/Output Controller 18 Conclusion 19 2: The ARM Instruction Set 20 The Programmer's Model 20 R15: The Program Counter 20 Conditional Execution 22 ARM Assembler Command Syntax 24 Shifted Operands 24 Brannch Instructions: B, BL 25 Arithmetic & Logical Instructions 26 Comparison Instructions 27 Multiplication Instructions 27 Single Register Load and Store Instructions 29 Multiple Register Load/Store Instructions 31 Softv/are Interrupts 32 3: The BASIC V Assembler 33 Basic Concepts 33 Using the Assembler 33 Variable Initialisation from BASIC 33 Archimedes Operating System Labels in Assembler Source 34 Allocating Memory 34 Assembling Into Memory 35 Offset Assembly 35 Dealing with Forward References 35 Implementing Two-pass Assembly 36 Other Assembler Directives 37 Position Independence of Object Code 37 Executing Assembler Programs 38 Conclusion 39 4 : The Operating System 40 Communicating with the OS 40 How SWis Work 41 SWI Names 42 SWI Error Handling 43 Error Handling - Numbering 44 Error Generation 45 5 : Command Line Interpreter 47 OS_CLl Command Syntax 47 File Redirection 48 Command Line Aliases 49 OS_CLi Commands 50 ^CONFIGURE 51 *ECHO 52 *ERROR 52 *EVAL 53 *FX 53 *GO 53 *COS 54 *HELP 54 *IF 55 ""IGNORE 55 *KEY 56 *SET 57 *SETEVAL 58 *SETMACRO 58 *SHADOW 58 4 Contents *SHOW 59 *STATUS 59 "TIME 60 *TV 60 *UNSET 60 6 : OS_CLI Related SWIs 61 OS_CLI 61 OS_ReadVarVal 61 OS_SetVarVal 62 Marvin 62 7: Filing Systems 66 Introduction 66 Naming of Filing Systems, Files and Directories 67 Directories 67 Files on Different Filing Systems 68 Device Filing Systems 69 Ancillary File Information 70 Load and Execute Addresses 70 File Types and Date Stamping 71 Libraries and Search Paths 71 8 : The FileSwitch Module 74 FileSwitch Commands 74 *ACCESS 75 *APPEND 76 *BUILD 76 *CAT 77 *CDIR 77 *CLOSE 77 *COPY 78 ''COUNT 79 *CREATE 80 *DELETE 80 *DIR 81 *DUMP 81 *ENUMDIR 82 *EX 82 5 Archimedes Operating System *EXEC 83 *INFO 83 *LCAT 83 *LEX 84 *LIB 84 *LIST 84 *LOAD 85 *OPT 86 *PRINT 86 *REMOVE 87 ""RENAME 87 *RUN 88 *SAVE 88 *SETTYPE 89 *SHUT 89 "•SHUTDOWN 89 *SPOOL 90 *SPOOLON 90 *STAMP 90 *TYPE 91 *UP 91 *WIPE 92 9 : Filing System SWIs 93 OS.File (SWI &08) 93 OS.Find (SWI &0D) 100 File Path Considerations in OS_Find 101 Error Handling Extension 102 OS_GBPB (SWI &0C) 102 OS_BGet (SWI &0A) 105 OS.BPut (SWI &0B) 107 OS_Args (SWI &09) 107 OS.FSControl (SWI &29) 109 10: Modules 119 Module Related Commands 119 "MODULES 120 *RMCLEAR 120 *RMKILL 120 6 Contents *RMLOAD 121 *RMREINIT 121 *RMRUN 121 *RMTIDY 122 *UNPLUG 122 11: Writing Modules 123 Workspace Memory 123 Module Errors 123 The Format of Module Code 124 Module Start-up Code 125 Module Initialisation Code 125 Module Finalisation Code 126 Service Call Handling Code 126 Service Call Reason Codes 127 Module Title String 132 Help String 132 Help and Command Decoding Table 133 Decoding Table Layout 133 SWI Chunk Base Number 136 SWI Handling Code Offset 136 SWI Decoding Table 137 SWI Decode Code 137 A Note About SWI Translations 137 OS.Module (SWI &1E) 138 Printer Buffer Module 141 12 : Writing Applications 149 Starting Applications 149 OS_GetEnv (SWI &10) 150 Alternative Ways of Starting Applications 150 Temporarily Running Another Application 151 Top Down Applications 151 The TWIN Text Editor 152 Memory Management 153 ARM Memory Structure 153 Heap Management Software and SWls 154 OS_Heap (SWI &1D) 154 OS.ValidateAddress (SWI &3A) 156 7 Archimedes Operating System General Guidelines on Compatibility 156 The Shell Module - Source Code 157 13 : The Window Manager 161 What's On Offer? 161 The Structure of Windows 162 Window Manager Co-ordinate System 163 Programming Using the Window Manager 163 Writing a Window Manager Application 164 The Polling Loop 166 Dealing With Reason Codes 167 Closing Down the Application Window 172 Window Manager Support for Menus 172 The Structure of Menus 173 Programming Menus 173 Menus in the WimpMaze Example 175 14: The Font Manager 186 Dealing with the Font Manager 186 An Example 187 Getting Text on the Display 188 Plot Type Options 189 Conversions Between the Co-ordinate Systems 190 Conclusion 193 15: Sound Introduction 195 The Three Levels of Sound 196 Level 0 - SoundDMA 196 Level 1 - SoundChannels 196 Level 2 - SoundScheduler 197 16: Sound Star Commands 199 Level 0 Commands 199 Level 1 Commands 200 Level 2 Commands 205 17: Sound SWI Calls 207 Level 0 SWI Commands 207 Level 1 SWI Commands 215 8 Contents Level 2 SWI Commands 221 18 : The Voice Generator 226 The SVCB 226 Gate On 227 Fill 228 Gate Off 231 Update 232 Instantiate 232 Free 232 Install 232 Voice Generator Code 232 19 : Character Input/Output 238 Simple Input/Output 238 Character Input 238 Getting Hold of Single Characters 239 Whole Lines of Characters 240 Keyboard Control Functions 241 Character Output 244 Selecting Which Output Streams are to be Used 245 Selecting the VDU Stream 246 Selecting the RS423 Output Stream 246 Selecting the Printer Stream 246 Selecting the Spool File Stream 247 Character Output to the Selected Streams 248 20: Vectors 255 The Hardware Vectors 255 The Operating System Software Vectors 258 Writing Code which Intercepts Vectors 259 SWIs Which Deal with Vectors 260 21: Interrupts and Events 263 Good Behaviour 264 Switching Interrupts on and Off 264 The Main Interrupt Vector 265 Events 265 9 Archimedes Operating System 22: Conversion SWIs 271 String Conversion and Decoding 271 ASCII to Binary Conversions 273 Binary to ASCII Conversions 274 23 : Miscellaneous SWIs 278 Timer Functions 278 VDU Related SWIs 281 24 : The ARM Chip Set 287 Inside MEMC 287 Virtual Memory Support 289 The MEMC Control Register 289 The Logical to Physical Translator 290 DMA Address Generators 290 Inside VIDC 291 Sound Frequency and Stereo Position 292 Inside IOC 293 25 : Floating Point Model 295 Floating Point Programmer's Model 295 The ARM Floating Point Instructions 296 Co-processor Data Transfer 297 Co-processor Register Transfer 297 Co-processor Data Operations 298 Co-processor Status Transfer Instructions 300 Conclusion 300 Appendices A : Programs Disc 302 B : Dabhand Guides Guide 304 Index 311 10 Contents Program Listings 4.1. Demonstrating OS_SWlNumberToString 45 4.2. Demonstrating OS_ReadEscapeState 46 6.1. Marvin 63 9.1. Save screen using OS_File SWI 94 9.2. Use of OS_File to read catalogue information 96 9.3. Load a block of screen memory 99 9.4. Using OS_Bget to count spaces and words 106 9.5. Use of OS_FSControl to convert a file type number 113 9.6. Display directory tree 116 9.7. Manipulating file attributes 117 11.1. Printer Buffer Module 141 12.1. The Shell source 157 12.2. The Heap 159 12.3. Validate Address 160 13.1. WimpMaze 176 14.1. Font demonstration 193 17.1. Demonstrating the Sound_Configure swi 208 17.2. Storing sounds 211 17.3. Stereo re-positioning 213 17.4. Attaching channels 220 17.5. Demonstrating the QSchedule command 222 17.6. Using QTempo and QBeat 224 18.1. Voice Generator Module Creator 233 18.2. Sound Sample 237 19.1. Simple I/O 252 19.2. Writel example 253 19.3. PrettyPlot 253 20.1. Manipulating the hardware vectors 256 20.2. Using OS_CallAVector 261 20.3. Intercepting ReadC 262 21.1. Turning interrupts on and off 264 21.2. The bouncing mouse pointer 268 22.1. Using GS calls 272 22.2. Binary to Decimal Conversion 274 22.3. Demonstrating number conversion 276 23.1. Using timed function SWls 279 23.2. Reading time elapsed since power-on 280 11 Archimedes Operating System 23.3. Checking screen mode 281 23.4. Cursor related SWIs 282 23.5. Reading the mouse buffer 282 23.6. Read VDU variables for given mode 284 23.7. Using OS_ReadPalette 285 23.8. Reading a pixel 286 This Book and You! This book was written using the TWIN Text Editor on an Archimedes microcomputer.