📄 exa7.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Example 7: DiscAccess</title><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="content-language" content="en" /><meta name="resource-type" content="document"><meta name="copyright" content="This document copyright 2002 by Richard Murray. Use for non-profit and education purposes explicitly granted."><meta name="author" content="Richard Murray"><meta name="rating" content="general"></head><!-- /assembler/exa7.html --><!-- --><!-- (C) Copyright 2002 Richard Murray --><!-- Designed by Richard Murray --><!-- rmurray@heyrick.co.uk --><!-- --><body bgcolor="#f0f0f0" text="#000000" link="#0022dd" vlink="#002288"><table border = "0" width="100%"> <tr> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td> <td> <h1 align="center"><font color="#800080">Example 7 <br>DiscAccess</font></h1> <h2 align="center"><font color="#800080">(and DiscAccess Revisited)</font></h2> </td> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td></table><p> <p> <p><h2>Introduction</h2>When you are using a machine that was never designed to have a harddisc <i>with a harddiscfitted</i>, ie an A3000, then something that is monumentally annoying is the lack of aharddisc light.<br>You see, the HD light on an A5000, RiscPC etc is a very useful thing. I wired my Simtec IDEinterface to hijack the HD light along with the internal disc.<br>Because the blinking is VERY reassuring. Also, you can judge if anything has gone wrong byhow it blinks, or what is happening.<br>Sorta, <blink><blink>, <i>ah yeah - the autosave just kicked in</i>...<p> <p>But when you are using a machine with no indicator, particularly a machine slower than youare used to, you start to get worried when nothing appears to be happening.<p> <p>So for the purposes of this tutorial, we shall create a blinking LED light.<p> <p><h2>The indicator</h2>Our first task is to determine what we should do. An on-screen icon? Excuse my American, but<i>that sucks</i>, as well as limiting us to desktop use. It would be nice to steal thefloppy light, but that appears to be rather tricky.<br>So that leaves us with custom hardware or the keyboard LEDs.<br>So you'll need four BC108 transistors and a piece of veroboard...<p>...only joking. The sane people among us would see that the least used keyboard LED isScroll Lock. Why can't we just use that?<p>Why not indeed.<p> <p><h2>The disc activity</h2>The next thing to consider is how to get information of disc activity from RISC OS. This isa trivial matter, as RISC OS bends over backwards to allow you access to it's innards. Aquick eyeball of the PRMs shows us:<br><center><code>FileV</code>, <code>ArgsV</code>, <code>BGetV</code>, <code>BPutV</code>,<code>GBPBV</code>, and <code>FindV</code>.</center><br>So we have six vectors which should turn our keyboard LED on.<p> <p><h2>Our plan of attack</h2>Let's think about how we're going to do this.<p>Firstly, we hook some code up to all of the vectors. It can be the exact same code. Dumpregisters that must be preserved, then switch on the LED, restore registers, and returnwithout claiming the vector.<p>So our LED is on. Good-oh. What we NOW need is a way to turn it off. We cannot guarantee anyspecific number of calls to the LED switcher oner, so we'll get more complicated.<p>We shall arrange for a callback to kick in after 20cs to turn off the LED.<br>When the LED is turned on, the callback will be set up. If the callback is ALREADY set up,it will have been unset. When the callback is called, it will be unset.<p>So it goes something like:<pre> Vector handler: Preserve registers Is callback set up? Yes? Remove it. Switch on Scroll Lock LED Set up callback handler Restore registers Callback handler Switch off Scroll Lock LED Remove callback</pre><p> <p><h2>Finally, some code</h2>Obviously, this will be implemented as a module. So let's go with a little bit of code:<pre> EQUD 0 ; Start-up code EQUD initialise ; Initialisation EQUD finalise ; Finalisation EQUD 0 ; Service call handler EQUD module_title ; Module title EQUD module_help ; Module help EQUD 0 ; Help and command decoding table EQUD 0 ; SWI chunk base number EQUD 0 ; SWI handling code EQUD 0 ; SWI decoding code EQUD 0 ; SWI decoding code .module_title EQUS "DiscAccess" EQUB 0 ALIGN .module_help EQUS "DiscAccess"+CHR$(9)+"0.01 (14 Oct 2000)" EQUB 0 ALIGN .initialise STMFD R13!, {R14} \ Attach vector handler to the six vectors that deal with file ops. MOV R0, #&8 ; FileV ADR R1, vector_handler MOV R2, #0 SWI "OS_AddToVector" MOV R0, #&9 ; ArgsV ADR R1, vector_handler MOV R2, #0 SWI "OS_AddToVector" MOV R0, #&A ; BGetV ADR R1, vector_handler MOV R2, #0 SWI "OS_AddToVector" MOV R0, #&B ; BPutV ADR R1, vector_handler MOV R2, #0 SWI "OS_AddToVector" MOV R0, #&C ; GBPBV ADR R1, vector_handler MOV R2, #0 SWI "OS_AddToVector" MOV R0, #&D ; FindV ADR R1, vector_handler MOV R2, #0 SWI "OS_AddToVector" LDMFD R13!, {PC} .finalise STMFD R13!, {R14} MOV R0, #&8 ; FileV ADR R1, vector_handler MOV R2, #0 SWI "OS_Release" MOV R0, #&9 ; ArgsV ADR R1, vector_handler MOV R2, #0 SWI "OS_Release" MOV R0, #&A ; BGetV ADR R1, vector_handler MOV R2, #0 SWI "OS_Release" MOV R0, #&B ; BPutV ADR R1, vector_handler MOV R2, #0 SWI "OS_Release" MOV R0, #&C ; GBPBV ADR R1, vector_handler MOV R2, #0 SWI "OS_Release" MOV R0, #&D ; FindV ADR R1, vector_handler MOV R2, #0 SWI "OS_Release" LDMFD R13!, {PC} .vector_handler \ IMPORTANT! WE ARE IN SVC MODE! STMFD R13!, {R0 - R2, R14} ; Preserve registers \ Our code will go here LDMFD R13!, {R0 - R2, R14} ; Restore registers MOVS PC, R14 ; Pass this one on</pre>If you run this, you'll notice that nothing happens. This is good. This is what is supposedto happen.<br>If you have a utility that displays vector claimants, you will see something similar to:<pre> Vector FileV (&08) 01863af0 00000100 DiscAccess 018287f0 00000000 Filer+Util 038310cc 01800204 FileSwitch 0380a5b8 00000000 Vector ArgsV (&09) 01863af0 00000100 DiscAccess 03832b98 01800204 FileSwitch 0380a5b8 00000000 Vector BGetV (&0a) 01863af0 00000100 DiscAccess 03831c04 01800204 FileSwitch 0380a5b8 00000000 Vector BPutV (&0b) 01863af0 00000100 DiscAccess 03831d94 01800204 FileSwitch 0380a5b8 00000000 Vector GBPBV (&0c) 01863af0 00000100 DiscAccess 0182882c 00000000 Filer+Util 03831f6c 01800204 FileSwitch 0380a5b8 00000000 Vector FindV (&0d) 01863af0 00000100 DiscAccess 038317bc 01800204 FileSwitch 0380a5b8 00000000 </pre>which clearly shows that we are hanging on to the file vectors.<p>Please notice two things. Firstly, we use "OS_AddToVector" so that we add ourselvesto the vector list, rather than claiming the vector (which could cause problems with othersoftware!).<br><font color="red">Also note that the "MOVS PC,R14" is not 32 bit compliant,</font>however it is the official (documented) way to return from vector code when passing on.<p> <p><h2>Fleshing it out</h2>Our next task is to add code to the section marked "<code>\ Our code will gohere</code>" to invert the status of the Scroll Lock key, whatever it is currently.<pre> \ Read MOV R0, #202 ; Update keyboard status, but using EOR MOV R1, #0 ; mask 0 and AND mask 255, we can read MOV R2, #255 ; the state... SWI "OS_Byte" ; New value in R1 \ Invert EOR R1, R1, #2 ; Bit 1 is Scroll Lock, invert it. \ Write MOV R2, #0 ; AND mask is 0, so EOR value is used. SWI "OS_Byte" \ Update keyboard LEDs MOV R0, #118 SWI "OS_Byte"</pre>Now assemble the module, and try loading something fairly complicated. Not necessarily large,but something that does a bunch of file accessing, like a word processor or email client.<br>See the Scroll Lock indicator blinking away? Yeah, that is MUCH more reassuring isn't it?<p>In case you are unsure, there should be a "<code>MOV R0, #202</code>" following the"<code>\ Write</code>" marker. However this is unnecessary as OS_Byte preservesR0, and it is not altered between then and when we need it again.<p> <p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -