Initial revision
[ssr] / StraySrc / Utilities / s / hour
1 ;
2 ; hour_util.s
3 ;
4 ; Fiddle with hourglass from command line
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's core utilities (coreutils).
12 ;
13 ; Coreutils 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)
16 ; any later version.
17 ;
18 ; Coreutils 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.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Coreutils. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 GET libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36 IMPORT version
37
38 ;----- Main code ------------------------------------------------------------
39
40 GBLA count
41
42 AREA |!!!Util$$Code|,CODE,READONLY
43
44 main ROUT
45
46 STMFD R13!,{R14} ;Save the return address
47 ADR R0,hour__cmdDef ;Point to command definition
48 MOV R2,R12 ;Point to a workspace buffer
49 MOV R3,#256 ;Size of the buffer
50 SWI XOS_ReadArgs ;Try to interpret the args
51 BVS %90main ;If it failed, return
52
53 ; --- Handle the arguments ---
54
55 LDMIA R12,{R0-R4} ;Load values from block
56
57 CMP R0,#0 ;Does he want some help?
58 BNE hour__help ;Yes -- display help then
59
60 ; --- Make sure at most one is set ---
61
62 MOV R14,#0 ;Clear argument count
63 MOV R0,#1 ;Default is to turn on
64
65 count SETA 1
66 WHILE count<5
67 R$count RN $count
68 CMP R$count,#0 ;Is the argument on?
69 ADDNE R14,R14,#1 ;Yes -- bump the counter
70 MOVNE R0,#count-1 ;And remember the argument
71 count SETA count+1
72 WEND
73
74 CMP R14,#2 ;Is the count valid?
75 ADRCS R0,hour__badArgs ;No -- point to error
76 BCS %90main ;And return to caller
77
78 ; --- Now do the necessaries ---
79 ;
80 ; The following should be two words long each -- this enables
81 ; most operations to be done inline with just a SWI and a
82 ; return.
83
84 MOV R14,PC ;Set up return address
85 ADD PC,PC,R0,LSL #3 ;Do what we must do
86 LDMFD R13!,{PC} ;Return to caller
87
88 ; --- Disable the hourglass ---
89
90 SWI XHourglass_Off
91 MOV PC,R14
92
93 ; --- Enable the hourglass ---
94
95 SWI XHourglass_On
96 MOV PC,R14
97
98 ; --- Trash hourglass totally ---
99
100 SWI XHourglass_Smash
101 MOV PC,R14
102
103 ; --- Turn on the percentage indicator ---
104 ;
105 ; To save space, this should be the last option.
106
107 LDRB R0,[R4],#1 ;Load the expression type
108 CMP R0,#0 ;Is it numeric?
109 ADRNE R0,hour__badType ;No -- must be a bad type
110 ORRNES PC,R14,#V_flag ;So return the error
111 AND R2,R4,#3 ;Get non-wordalignedness
112 BIC R4,R4,#3 ;Word align the address
113 LDMIA R4,{R0,R1} ;Load two overlapping words
114 MOV R2,R2,LSL #3 ;Convert bytes to bits
115 RSB R3,R2,#32 ;And get reverse shift size
116 MOV R0,R0,LSR R2 ;Get the bottom end right
117 ORR R0,R0,R1,LSL R3 ;And move in the top end
118 SWI XHourglass_Percentage ;Set the percentage as reqd
119 MOV PC,R14 ;And return to caller
120
121 90main LDMFD R13!,{R14} ;Load the return address
122 ORRS PC,R14,#V_flag ;And return an error
123
124 hour__cmdDef DCB "help/S," ;Offset 0 (R0)
125 DCB "off/S," ;Offset 8 (R1)
126 DCB "on/S," ;Offset 4 (R2)
127 DCB "smash/S," ;Offset 12 (R3)
128 DCB "percent/K/E," ;Offset 16 (R4)
129 DCB 0
130
131 hour__badArgs DCD 1
132 DCB "Syntax: hour [<command>]",0
133
134 hour__badType DCD 1
135 DCB "Percentage must be a number",0
136
137 hour__help ADR R0,hour__helpText ;Point to the help text
138 MOV R1,#0 ;No dictionary please
139 LDR R2,=version ;Find the version string
140 ADR R14,main ;Find my base address
141 ADD R2,R14,R2 ;Find the actual message
142 SWI XOS_PrettyPrint ;Print the message
143 LDMFD R13!,{PC}^ ;And return to caller
144
145 LTORG
146
147 hour__helpText DCB "hour ",27,0,13
148 DCB 13
149 DCB "Syntax: hour [<command>]",13
150 DCB 13
151 DCB "Performs an Hourglass operation as specified by "
152 DCB "<command>. If no command is specified, the "
153 DCB "Hourglass is turned on.",13
154 DCB 13
155 DCB "Commands allowed are:",13
156 DCB 13
157 DCB "-help",9,9,"Displays this help text",13
158 DCB "-on",9,9,"Turns the Hourglass on",13
159 DCB "-off",9,9,"Turns the Hourglass off",13
160 DCB "-smash",9,9,"Forces the Hourglass off",13
161 DCB "-percent",9,"Displays the given percentage",13
162 DCB 0
163
164 ;----- That's all, folks ----------------------------------------------------
165
166 END