Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for resistor.cmd

(view source code of resistor.cmd as plain text)

  1. /* Practice using E12 color codes for resistors  */
  2. /* (C) 1997, 1999, Rob van der Woude             */
  3. /* Latest revision 1999/02/28                    */
  4. /* Use this program at your own risk.            */
  5. /* You may copy, distribute or even modify this  */
  6. /* program, provided you leave a note explaining */
  7. /* your modifications in this header.            */
  8.  
  9. /* Initialize RexxUtil */
  10. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  11. call SysLoadFuncs
  12.  
  13. /* Change code page to enable display of Omega character */
  14. address CMD "@CHCP 437"
  15.  
  16. /* Parse command line parameter, if any */
  17. parse upper arg level and_the_rest
  18.  
  19. /* Constants */
  20. freq   = 220
  21. Esc    = "1B"X
  22.  
  23. /* Colors for first and second ring */
  24. sblack   = Esc||"[0;1;37;40m"
  25. sbrown   = Esc||"[0;1;37;43m"
  26. sred     = Esc||"[0;1;37;41m"
  27. sorange  = Esc||"[0;1;33;41m"
  28. syellow  = Esc||"[0;5;30;43m"
  29. sgreen   = Esc||"[0;1;37;42m"
  30. sblue    = Esc||"[0;1;37;44m"
  31. smagenta = Esc||"[0;1;37;45m"
  32. sgrey    = Esc||"[0;1;5;37;40m"
  33. swhite   = Esc||"[0;5;30;47m"
  34. saqua    = Esc||"[0;46m"
  35.  
  36. /* Colors for third ring (multiplier) */
  37. rsilver  = -2
  38. rgold    = -1
  39. rblack   =  0
  40. rbrown   =  1
  41. rred     =  2
  42. rorange  =  3
  43. ryellow  =  4
  44. rgreen   =  5
  45. rblue    =  6
  46. rmagenta =  7
  47. rgrey    =  8
  48. rwhite   =  9
  49.  
  50. /* Color display */
  51. color.   = ""
  52. color.0  = 19
  53. color.10 = sblack||"  "
  54. color.11 = sbrown||"  "
  55. color.12 = sred||"  "
  56. color.13 = sorange||"±±"
  57. color.14 = syellow||"  "
  58. color.15 = sgreen||"  "
  59. color.16 = sblue||"  "
  60. color.17 = smagenta||"  "
  61. color.18 = sgrey||"  "
  62. color.19 = swhite||"  "
  63.  
  64. /* E12 range */
  65. E12.   = ""
  66. E12.0  = 12
  67. E12.1  = 10
  68. E12.2  = 12
  69. E12.3  = 15
  70. E12.4  = 18
  71. E12.5  = 22
  72. E12.6  = 27
  73. E12.7  = 33
  74. E12.8  = 39
  75. E12.9  = 47
  76. E12.10 = 56
  77. E12.11 = 68
  78. E12.12 = 82
  79.  
  80. /* Header text and position coding */
  81. text1 = sblack||" black  "||sbrown||" brown  "||sred||"   red  "||sorange||"±orange±"||syellow||" yellow "||sgreen||" green  "||sblue||"  blue  "||smagenta||" magenta"||sgrey||"  grey  "||swhite||" white  "||Esc||"[0m"
  82. text2 = sblack||"    0   "||sbrown||"    1   "||sred||"    2   "||sorange||"±±±±3±±±"||syellow||"    4   "||sgreen||"    5   "||sblue||"    6   "||smagenta||"    7   "||sgrey||"    8   "||swhite||"    9   "||Esc||"[0m"
  83. text3 = sblack||"        "||sbrown||"        "||sred||"        "||sorange||"±±±±±±±±"||syellow||"        "||sgreen||"        "||sblue||"        "||smagenta||"        "||sgrey||"        "||swhite||"        "||Esc||"[0m"
  84. pos1 = Esc||"[2J"
  85. pos2 = Esc||"[2;1H"
  86. pos3 = Esc||"[3;1H"
  87. pos4 = Esc||"[4;1H"
  88. pos5 = Esc||"[5;1H"
  89. pos6 = Esc||"[6;1H"
  90. pos7 = Esc||"[7;1H"
  91. pos8 = Esc||"[8;1H"
  92. pos9 = Esc||"[9;1H"
  93. pos10 = Esc||"[10;1H"
  94. pos11 = Esc||"[11;1H"
  95. pos12 = Esc||"[12;1H"
  96. pos13 = Esc||"[13;1H"
  97. pos14 = Esc||"[14;1H"
  98. pos15 = Esc||"[15;1H"
  99. pos16 = Esc||"[16;1H"
  100. pos17 = Esc||"[17;1H"
  101. pos18 = Esc||"[18;1H"
  102.  
  103. /* Display help if needed */
  104. if level = "/?" then do
  105. 	call Syntax
  106. end
  107.  
  108. /* Display header */
  109. do forever
  110. 	select
  111. 		when level = "2" then do
  112. 			line1 = pos1||Esc||"[K"
  113. 			line2 = pos2||Esc||"[K"
  114. 			line3 = pos3||Esc||"[K"
  115. 			leave
  116. 		end
  117. 		when level = "1" then do
  118. 			line1 = pos1||text3
  119. 			line2 = pos2||text1
  120. 			line3 = pos3||text3
  121. 			leave
  122. 		end
  123. 		when level = "0" then do
  124. 			line1 = pos1||text1
  125. 			line2 = pos2||text3
  126. 			line3 = pos3||text2
  127. 			leave
  128. 		end
  129. 		otherwise do
  130. 			call Syntax
  131. 		end
  132. 	end
  133. end
  134. say line1
  135. say line2
  136. say line3
  137.  
  138. /* Run main program */
  139. do forever
  140. 	call Run
  141. end
  142. exit
  143.  
  144.  
  145. /* Main program */
  146. Run:
  147. 	/* Choose random restor value */
  148. 	w = random( 1, 12 )
  149. 	x = random( 0, 6 )
  150. 	R = E12.w * ( 10 ** x )
  151.  
  152. 	/* Convert value to color codes */
  153. 	ring1 = E12.w % 10
  154. 	ring2 = E12.w // 10
  155. 	ring3 = x
  156. 	color1 = 10 + ring1
  157. 	color2 = 10 + ring2
  158. 	color3 = 10 + ring3
  159. 	color1 = color.color1
  160. 	color2 = color.color2
  161. 	color3 = color.color3
  162.  
  163. 	/* Display converted color code */
  164. 	say Esc||"[0;1;30m"||Esc||"[15;20HÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"
  165. 	say Esc||"[14;29H"||saqua||"  "||color1||saqua||"  "||color2||saqua||"  "||color3||saqua||"          "
  166. 	say Esc||"[15;29H"||saqua||"  "||color1||saqua||"  "||color2||saqua||"  "||color3||saqua||"          "
  167. 	say Esc||"[16;29H"||saqua||"  "||color1||saqua||"  "||color2||saqua||"  "||color3||saqua||"          "||Esc||"[0m"
  168.  
  169. 	/* Prefix Omega character with k or M if needed */
  170. 	select
  171. 		when R > 999 & R < 1000000 then do
  172. 			R = R / 1000
  173. 			Ohm = "k"||"EA"X
  174. 		end
  175. 		when R > 999999 then do
  176. 			R = R / 1000000
  177. 			Ohm = "M"||"EA"X
  178. 		end
  179. 		otherwise Ohm = "EA"X
  180. 	end
  181.  
  182. 	/* Ask for input */
  183. 	say Esc||"[20;32HR = .... "||"EA"X
  184. 	call SysCurPos 19, 35
  185. 	pull R2
  186. 	say Esc||"[20;32HR = "||R||" "||Ohm||Esc||"[K"
  187. 	say Esc||"[22;1HPress any key to continue, Esc to quit"
  188.  
  189. 	/* Quit if Esc was pressed */
  190. 	if SysGetKey( "NOECHO" ) = "1B"X then do
  191. 		say Esc||"[22;1H"||Esc||"[K"
  192. 		exit
  193. 	end
  194. 	say Esc||"[22;1H"||Esc||"[K"
  195. return
  196.  
  197.  
  198. Syntax:
  199. 	/* Show help and start program in interactive mode */
  200. 	do forever
  201. 		say pos1||pos2||" Resistor, version 1.10"
  202. 		say pos3||" (C) 1997, 1999, Rob van der Woude"
  203. 		say pos5||" Practice using E12 range of resistor color codes"
  204. 		say pos7||" Usage: RESISTOR <level>"
  205. 		say pos8||"        where <level> can be 0 (easy),"
  206. 		say pos9||"        1 (medium) or 2 (highest level)"
  207. 		say pos11||" Do you want to start the program now?"
  208. 		answer = translate( SysGetKey( ) )
  209. 		if answer = "N" then exit
  210. 		if answer = "Y" then do
  211. 			say pos12||Esc||"[K"||pos13||" What level?"
  212. 			say pos14||" Choose 0 for easyest level, or"
  213. 			say pos15||" choose 1 for medium level, or"
  214. 			say pos16||" choose 2 for the highest level."
  215. 			do forever
  216. 				say pos17
  217. 				level = SysGetKey( )
  218. 				if level = "0" then leave
  219. 				if level = "1" then leave
  220. 				if level = "2" then leave
  221. 				call beep freq, 250
  222. 				freq = freq * 2
  223. 				if freq > 3500 then freq = 220
  224. 			end
  225. 			leave
  226. 		end
  227. 		if answer = "J" then leave
  228. 		call beep freq, 250
  229. 		freq = freq * 2
  230. 		if freq > 3500 then freq = 220
  231. 	end
  232. return
  233.  

page last uploaded: 2017-08-21, 14:26