forked from academicpages/academicpages.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIPS_syscalls.html
514 lines (492 loc) · 27.9 KB
/
MIPS_syscalls.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<html data-darkreader-mode="dynamic" data-darkreader-scheme="dark"><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252"><style class="darkreader darkreader--fallback" media="screen"></style><style class="darkreader darkreader--text" media="screen"></style><style class="darkreader darkreader--invert" media="screen">.jfk-bubble.gtx-bubble, .captcheck_answer_label > input + img, span#closed_text > img[src^="https://www.gstatic.com/images/branding/googlelogo"], span[data-href^="https://www.hcaptcha.com/"] > #icon, img.Wirisformula {
filter: invert(100%) hue-rotate(180deg) contrast(90%) !important;
}</style><style class="darkreader darkreader--inline" media="screen">[data-darkreader-inline-bgcolor] {
background-color: var(--darkreader-inline-bgcolor) !important;
}
[data-darkreader-inline-bgimage] {
background-image: var(--darkreader-inline-bgimage) !important;
}
[data-darkreader-inline-border] {
border-color: var(--darkreader-inline-border) !important;
}
[data-darkreader-inline-border-bottom] {
border-bottom-color: var(--darkreader-inline-border-bottom) !important;
}
[data-darkreader-inline-border-left] {
border-left-color: var(--darkreader-inline-border-left) !important;
}
[data-darkreader-inline-border-right] {
border-right-color: var(--darkreader-inline-border-right) !important;
}
[data-darkreader-inline-border-top] {
border-top-color: var(--darkreader-inline-border-top) !important;
}
[data-darkreader-inline-boxshadow] {
box-shadow: var(--darkreader-inline-boxshadow) !important;
}
[data-darkreader-inline-color] {
color: var(--darkreader-inline-color) !important;
}
[data-darkreader-inline-fill] {
fill: var(--darkreader-inline-fill) !important;
}
[data-darkreader-inline-stroke] {
stroke: var(--darkreader-inline-stroke) !important;
}
[data-darkreader-inline-outline] {
outline-color: var(--darkreader-inline-outline) !important;
}
[data-darkreader-inline-stopcolor] {
stop-color: var(--darkreader-inline-stopcolor) !important;
}
[data-darkreader-inline-bg] {
background: var(--darkreader-inline-bg) !important;
}
[data-darkreader-inline-invert] {
filter: invert(100%) hue-rotate(180deg);
}</style><style class="darkreader darkreader--variables" media="screen">:root {
--darkreader-neutral-background: #181a1b;
--darkreader-neutral-text: #e8e6e3;
--darkreader-selection-background: #004daa;
--darkreader-selection-text: #e8e6e3;
}</style><style class="darkreader darkreader--root-vars" media="screen"></style><style class="darkreader darkreader--user-agent" media="screen">@layer {
html {
background-color: #181a1b !important;
}
html {
color-scheme: dark !important;
}
iframe {
color-scheme: dark !important;
}
html, body {
background-color: #181a1b;
}
html, body {
border-color: #736b5e;
color: #e8e6e3;
}
a {
color: #3391ff;
}
table {
border-color: #545b5e;
}
mark {
color: #e8e6e3;
}
::placeholder {
color: #b2aba1;
}
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
background-color: #404400 !important;
color: #e8e6e3 !important;
}
* {
scrollbar-color: #454a4d #202324;
}
::selection {
background-color: #004daa !important;
color: #e8e6e3 !important;
}
::-moz-selection {
background-color: #004daa !important;
color: #e8e6e3 !important;
}
}</style><title>MIPS syscall functions available in MARS
</title>
<meta name="darkreader" content="2de374d2891c4c189e5243fdc2e630fb"><style class="darkreader darkreader--override" media="screen">.vimvixen-hint {
background-color: #684b00 !important;
border-color: #9e7e00 !important;
color: #d7d4cf !important;
}
#vimvixen-console-frame {
color-scheme: light !important;
}
::placeholder {
opacity: 0.5 !important;
}
#edge-translate-panel-body,
.MuiTypography-body1,
.nfe-quote-text {
color: var(--darkreader-neutral-text) !important;
}
gr-main-header {
background-color: #1b4958 !important;
}
.tou-z65h9k,
.tou-mignzq,
.tou-1b6i2ox,
.tou-lnqlqk {
background-color: var(--darkreader-neutral-background) !important;
}
.tou-75mvi {
background-color: #0f3a47 !important;
}
.tou-ta9e87,
.tou-1w3fhi0,
.tou-1b8t2us,
.tou-py7lfi,
.tou-1lpmd9d,
.tou-1frrtv8,
.tou-17ezmgn {
background-color: #1e2021 !important;
}
.tou-uknfeu {
background-color: #432c09 !important;
}
.tou-6i3zyv {
background-color: #245d70 !important;
}
div.mermaid-viewer-control-panel .btn {
background-color: var(--darkreader-neutral-background);
fill: var(--darkreader-neutral-text);
}
svg g rect.er {
fill: var(--darkreader-neutral-background) !important;
}
svg g rect.er.entityBox {
fill: var(--darkreader-neutral-background) !important;
}
svg g rect.er.attributeBoxOdd {
fill: var(--darkreader-neutral-background) !important;
}
svg g rect.er.attributeBoxEven {
fill: var(--darkreader-selection-background);
fill-opacity: 0.8 !important;
}
svg rect.er.relationshipLabelBox {
fill: var(--darkreader-neutral-background) !important;
}
svg g g.nodes rect,
svg g g.nodes polygon {
fill: var(--darkreader-neutral-background) !important;
}
svg g rect.task {
fill: var(--darkreader-selection-background) !important;
}
svg line.messageLine0,
svg line.messageLine1 {
stroke: var(--darkreader-neutral-text) !important;
}
div.mermaid .actor {
fill: var(--darkreader-neutral-background) !important;
}
mitid-authenticators-code-app > .code-app-container {
background-color: white !important;
padding-top: 1rem;
}
iframe#unpaywall[src$="unpaywall.html"] {
color-scheme: light !important;
}
embed[type="application/pdf"] { filter: invert(100%) contrast(90%); }</style></head><body>
<center>
<h3 class="style1"><span class="style2">
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpIntro.html"> <em>Intro</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpSettings.html"> <em>Settings</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/SyscallHelp.html"> <em>Syscalls</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpIDE.html"> <em>IDE</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpDebugging.html"> <em>Debugging</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpCommand.html"> <em>Command</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpTools.html"> <em>Tools</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpHistory.html"> <em>History</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpLimits.html"> <em>Limitations</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsExceptions.html"> <em>Exception Handlers</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/MacrosHelp.html"> <em>Macros</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/Help/Acknowledgements.html"> <em>Acknowledgements</em></a><em> </em>
<a href="https://courses.missouristate.edu/KenVollmar/MARS/index.htm"> <em>MARS home</em></a> </span> </h3>
<h3>SYSCALL functions available in MARS</h3>
</center>
<h3>Introduction</h3>
<p>A number of system services, mainly for input and output, are available for use by
your MIPS program. They are described in the table below.</p>
<p>MIPS register contents are not affected by a system call, except for result registers
as specified in the table below.</p>
<h3>How to use SYSCALL system services</h3>
Step 1. Load the service number in register $v0.<br>
Step 2. Load argument values, if any, in $a0, $a1, $a2, or $f12 as specified.<br>
Step 3. Issue the SYSCALL instruction.<br>
Step 4. Retrieve return values, if any, from result registers as specified.<br>
<p></p>
<strong>Example: display the value stored in $t0 on the console</strong><br>
<pre> li $v0, 1 # service 1 is print integer
add $a0, $t0, $zero # load desired value into argument register $a0, using pseudo-op
syscall
</pre>
<h3>Table of Available Services</h3>
<table border="1">
<tbody><tr> <th>Service</th> <th>Code in $v0</th> <th>Arguments</th> <th>Result</th> </tr>
<tr><td>print integer</td> <td align="center">1</td> <td>$a0 = integer to print</td> <td> </td></tr>
<tr><td>print float</td> <td align="center">2</td> <td>$f12 = float to print</td> <td> </td></tr>
<tr><td>print double</td> <td align="center">3</td> <td>$f12 = double to print</td> <td> </td></tr>
<tr><td>print string</td> <td align="center">4</td> <td>$a0 = address of null-terminated string to print</td> <td> </td></tr>
<tr><td>read integer</td> <td align="center">5</td> <td> </td> <td>$v0 contains integer read</td></tr>
<tr><td>read float</td> <td align="center">6</td> <td> </td> <td>$f0 contains float read</td></tr>
<tr><td>read double</td> <td align="center">7</td> <td> </td> <td>$f0 contains double read</td></tr>
<tr><td>read string</td> <td align="center">8</td> <td>$a0 = address of input buffer<br>$a1 = maximum number of characters to read</td> <td><i>See note below table</i></td></tr>
<tr><td>sbrk (allocate heap memory)</td> <td align="center">9</td> <td>$a0 = number of bytes to allocate</td> <td>$v0 contains address of allocated memory</td></tr>
<tr><td>exit (terminate execution)</td> <td align="center">10</td> <td> </td> <td> </td></tr>
<tr><td>print character</td> <td align="center">11</td> <td>$a0 = character to print</td> <td><i>See note below table</i></td></tr>
<tr><td>read character</td> <td align="center">12</td> <td> </td> <td>$v0 contains character read</td></tr>
<tr><td>open file</td> <td align="center">13</td> <td>$a0 = address of null-terminated string containing filename<br>$a1 = flags<br>$a2 = mode</td> <td>$v0 contains file descriptor (negative if error). <i>See note below table</i></td></tr>
<tr><td>read from file</td> <td align="center">14</td> <td>$a0 = file descriptor<br>$a1 = address of input buffer<br>$a2 = maximum number of characters to read</td> <td>$v0 contains number of characters read (0 if end-of-file, negative if error). <i>See note below table</i></td></tr>
<tr><td>write to file</td> <td align="center">15</td> <td>$a0 = file descriptor<br>$a1 = address of output buffer<br>$a2 = number of characters to write</td> <td>$v0 contains number of characters written (negative if error). <i>See note below table</i></td></tr>
<tr><td>close file</td> <td align="center">16</td> <td>$a0 = file descriptor</td> <td> </td></tr>
<tr><td>exit2 (terminate with value)</td> <td align="center">17</td> <td>$a0 = termination result</td> <td><i>See note below table</i></td></tr>
<tr><td align="center" colspan="4"><em>Services 1 through 17 are
compatible with the SPIM simulator, other than Open File (13) as
described in the Notes below the table.
Services 30 and higher are exclusive to MARS.</em></td></tr>
<tr><td>time (system time)</td> <td align="center">30</td> <td> </td><td>$a0 = low order 32 bits of system time<br>$a1 = high order 32 bits of system time. <i>See note below table</i></td></tr>
<tr><td>MIDI out</td> <td align="center">31</td> <td>$a0 = pitch (0-127)<br>$a1 = duration in milliseconds<br>$a2 = instrument (0-127)<br>$a3 = volume (0-127)</td> <td>Generate tone and return immediately. <i>See note below table</i></td></tr>
<tr><td>sleep</td> <td align="center">32</td> <td>$a0 = the length of time to sleep in milliseconds.</td> <td>Causes
the MARS Java thread to sleep for (at least) the specified number of
milliseconds. This timing will not be precise, as the Java
implementation will add some overhead.</td></tr>
<tr><td>MIDI out synchronous </td><td align="center">33</td> <td>$a0 = pitch (0-127)<br>$a1 = duration in milliseconds<br>$a2 = instrument (0-127)<br>$a3 = volume (0-127)</td> <td>Generate tone and return upon tone completion. <i>See note below table</i></td></tr>
<tr><td>print integer in hexadecimal</td> <td align="center">34</td> <td>$a0 = integer to print</td> <td>Displayed value is 8 hexadecimal digits, left-padding with zeroes if necessary.</td></tr>
<tr><td>print integer in binary</td> <td align="center">35</td> <td>$a0 = integer to print</td> <td>Displayed value is 32 bits, left-padding with zeroes if necessary.</td></tr>
<tr><td>print integer as unsigned</td> <td align="center">36</td> <td>$a0 = integer to print</td> <td>Displayed as unsigned decimal value.</td></tr>
<tr><td align="center">(not used)</td> <td align="center">37-39</td><td> </td> <td> </td></tr>
<tr><td>set seed</td> <td align="center">40</td> <td>$a0 = i.d. of pseudorandom number generator (any int).<br>$a1 = seed for corresponding pseudorandom number generator.</td> <td>No values are returned. Sets the seed of the corresponding underlying Java pseudorandom number generator (<tt>java.util.Random</tt>). <i>See note below table</i></td></tr>
<tr><td>random int</td> <td align="center">41</td> <td>$a0 = i.d. of pseudorandom number generator (any int).</td> <td>$a0 contains the next pseudorandom, uniformly distributed int value from this random number generator's sequence. <i>See note below table</i></td></tr>
<tr><td>random int range</td> <td align="center">42</td> <td>$a0 = i.d. of pseudorandom number generator (any int).<br>$a1 = upper bound of range of returned values.</td> <td>$a0
contains pseudorandom, uniformly distributed int value in the range 0
<= [int] < [upper bound], drawn from this random number
generator's sequence. <i>See note below table</i></td></tr>
<tr><td>random float</td> <td align="center">43</td> <td>$a0 = i.d. of pseudorandom number generator (any int).</td> <td>$f0
contains the next pseudorandom, uniformly distributed float value in
the range 0.0 <= f < 1.0 from this random number generator's
sequence. <i>See note below table</i></td></tr>
<tr><td>random double</td> <td align="center">44</td> <td>$a0 = i.d. of pseudorandom number generator (any int).</td> <td>$f0
contains the next pseudorandom, uniformly distributed double value in
the range 0.0 <= f < 1.0 from this random number generator's
sequence. <i>See note below table</i></td></tr>
<tr><td align="center">(not used)</td> <td align="center">45-49</td><td> </td> <td> </td></tr>
<tr><td>ConfirmDialog</td> <td align="center">50</td> <td>$a0 = address of null-terminated string that is the message to user</td> <td>$a0 contains value of user-chosen option<br>0: Yes<br>1: No<br>2: Cancel</td></tr>
<tr><td>InputDialogInt</td> <td align="center">51</td> <td>$a0 = address of null-terminated string that is the message to user</td> <td>$a0 contains int read<br>$a1 contains status value<br>0: OK status<br>-1: input data cannot be correctly parsed<br>-2: Cancel was chosen<br>-3: OK was chosen but no data had been input into field</td></tr>
<tr><td>InputDialogFloat</td> <td align="center">52</td> <td>$a0 = address of null-terminated string that is the message to user</td> <td>$f0 contains float read<br>$a1 contains status value<br>0: OK status<br>-1: input data cannot be correctly parsed<br>-2: Cancel was chosen<br>-3: OK was chosen but no data had been input into field</td></tr>
<tr><td>InputDialogDouble</td> <td align="center">53</td> <td>$a0 = address of null-terminated string that is the message to user</td> <td>$f0 contains double read<br>$a1 contains status value<br>0: OK status<br>-1: input data cannot be correctly parsed<br>-2: Cancel was chosen<br>-3: OK was chosen but no data had been input into field</td></tr>
<tr><td>InputDialogString</td> <td align="center">54</td> <td>$a0 = address of null-terminated string that is the message to user<br>$a1 = address of input buffer<br>$a2 = maximum number of characters to read</td> <td><i>See Service 8 note below table</i><br>$a1 contains status value<br>0: OK status. Buffer contains the input string.<br>-2: Cancel was chosen. No change to buffer. <br>-3: OK was chosen but no data had been input into field. No change to buffer.<br>-4:
length of the input string exceeded the specified maximum. Buffer
contains the maximum allowable input string plus a terminating null.</td></tr>
<tr><td>MessageDialog</td> <td align="center">55</td> <td>$a0 = address of null-terminated string that is the message to user<br>$a1 = the type of message to be displayed:<br>
0: error message, indicated by Error icon <!-- <img src="SyscallMessageDialogError.gif"> --> <br>
1: information message, indicated by Information icon <!-- <img src="SyscallMessageDialogInformation.gif"> --> <br>
2: warning message, indicated by Warning icon <!-- <img src="SyscallMessageDialogWarning.gif"> --> <br>
3: question message, indicated by Question icon <!-- <img src="SyscallMessageDialogQuestion.gif"> --> <br>
other: plain message (no icon displayed)
</td> <td>N/A</td></tr>
<tr><td>MessageDialogInt</td> <td align="center">56</td> <td>$a0 = address of null-terminated string that is an information-type message to user<br>$a1 = int value to display in string form after the first string</td> <td>N/A</td></tr>
<tr><td>MessageDialogFloat</td> <td align="center">57</td> <td>$a0 = address of null-terminated string that is an information-type message to user<br>$f12 = float value to display in string form after the first string</td> <td>N/A</td></tr>
<tr><td>MessageDialogDouble</td> <td align="center">58</td> <td>$a0 = address of null-terminated string that is an information-type message to user<br>$f12 = double value to display in string form after the first string</td> <td>N/A</td></tr>
<tr><td>MessageDialogString</td> <td align="center">59</td> <td>$a0 = address of null-terminated string that is an information-type message to user<br>$a1 = address of null-terminated string to display after the first string</td> <td>N/A</td></tr>
</tbody></table>
<br>
<b>NOTES: Services numbered 30 and higher are not provided by SPIM</b>
<br><b>Service 8</b> - Follows semantics of UNIX 'fgets'. For specified
length n, string can be no longer than n-1. If less than that, adds
newline to end. In either case, then pads with null byte If n = 1,
input is ignored and null byte placed at buffer address. If n < 1,
input is ignored and nothing is written to the buffer.
<br><b>Service 11</b> - Prints ASCII character corresponding to contents of low-order byte.
<br><b>Service 13</b> - MARS implements three flag values: 0 for
read-only, 1 for write-only with create, and 9 for write-only with
create and append. It ignores mode. The returned file descriptor will
be negative if the operation failed. The underlying file I/O
implementation uses <tt>java.io.FileInputStream.read()</tt> to read and <tt>java.io.FileOutputStream.write()</tt>
to write. MARS maintains file descriptors internally and allocates
them starting with 3. File descriptors 0, 1 and 2 are
always open for: reading from standard input, writing to standard
output, and writing to standard error, respectively (new in release
4.3).
<br><b>Services 13,14,15</b> - In MARS 3.7, the result register was changed to $v0 for SPIM compatability. It was previously $a0 as erroneously printed
in Appendix B of <i>Computer Organization and Design,</i>.
<br><b>Service 17</b> - If the MIPS program is run under control of the MARS graphical interface (GUI), the exit code in $a0 is ignored.
<br><b>Service 30</b> - System time comes from <tt>java.util.Date.getTime()</tt> as milliseconds since 1 January 1970.
<br><b>Services 31,33</b> - Simulate MIDI output through sound card. Details below.
<br><b>Services 40-44</b> use underlying Java pseudorandom number generators provided by the <tt>java.util.Random</tt> class. Each stream (identified
by $a0 contents) is modeled by a different <tt>Random</tt> object. There are no default seed values, so use the Set Seed service (40) if
replicated random sequences are desired.
<p></p>
<hr>
<h3>Example of File I/O</h3>
The sample MIPS program below will open a new file for writing, write
text to it from a memory buffer, then close it. The file will be
created in the
directory in which MARS was run.
<p>
</p><pre># Sample MIPS program that writes to a new file.
# by Kenneth Vollmar and Pete Sanderson
.data
fout: .asciiz "testout.txt" # filename for output
buffer: .asciiz "The quick brown fox jumps over the lazy dog."
.text
###############################################################
# Open (for writing) a file that does not exist
li $v0, 13 # system call for open file
la $a0, fout # output file name
li $a1, 1 # Open for writing (flags are 0: read, 1: write)
li $a2, 0 # mode is ignored
syscall # open a file (file descriptor returned in $v0)
move $s6, $v0 # save the file descriptor
###############################################################
# Write to file just opened
li $v0, 15 # system call for write to file
move $a0, $s6 # file descriptor
la $a1, buffer # address of buffer from which to write
li $a2, 44 # hardcoded buffer length
syscall # write to file
###############################################################
# Close the file
li $v0, 16 # system call for close file
move $a0, $s6 # file descriptor to close
syscall # close file
###############################################################
</pre>
<p></p>
<hr>
<h3>Using SYSCALL system services 31 and 33: MIDI output</h3>
These system services are unique to MARS, and provide a means of producing sound. MIDI output is
simulated by your system sound card, and the simulation is provided by the <tt>javax.sound.midi</tt>
package.
<p>Service 31 will generate the tone then immediately return. Service 33 will generate the tone then
sleep for the tone's duration before returning. Thus it essentially combines services 31 and 32.
</p><p>
This service requires four parameters as follows:
<table width="600" border="0" align="center" cellpadding="2">
<tbody><tr>
<td><h3>pitch ($a0)</h3>
<li>Accepts a positive byte value (0-127) that denotes a pitch as it would
be represented in MIDI </li>
<li>Each number is one semitone / half-step in the chromatic scale.</li>
<li>0 represents a very low C and 127 represents a very high G (a standard
88 key piano begins at 9-A and ends at 108-C).</li>
<li>If the parameter value is outside this range, it applies a default value 60 which is the same as middle C on a piano.</li>
<li>From middle C, all other pitches in the octave are as follows:</li>
<table width="450" border="0" align="center" cellpadding="2">
<tbody><tr>
<td>
<li>61 = C# or Db</li>
<li>62 = D</li>
<li>63 = D# or Eb</li>
<li>64 = E or Fb</li>
</td>
<td>
<li>65 = E# or F</li>
<li>66 = F# or Gb</li>
<li>67 = G</li>
<li>68 = G# or Ab</li>
</td>
<td>
<li>69 = A</li>
<li>70 = A# or Bb</li>
<li>71 = B or Cb</li>
<li>72 = B# or C</li>
</td>
</tr>
</tbody></table>
<li>To produce these pitches in other octaves, add or subtract multiples
of 12.</li>
<br>
</td>
</tr>
<tr>
<td><h3>duration in milliseconds ($a1)</h3>
<li>Accepts a positive integer value that is the length of the tone in milliseconds.</li>
<li>If the parameter value is negative, it applies a default value of one second (1000 milliseconds).</li>
<br>
</td>
</tr>
<tr>
<td><h3>instrument ($a2)</h3>
<li>Accepts a positive byte value (0-127) that denotes the General MIDI
"patch" used to play the tone.</li>
<li>If the parameter is outside this range, it applies a default value 0 which is an <em>Acoustic Grand Piano</em>.</li>
<li>General MIDI standardizes the number associated with each possible instrument
(often referred to as <em>program change</em> numbers), however it does
not determine how the tone will sound. This is determined by the synthesizer
that is producing the sound. Thus a<em> Tuba</em> (patch 58) on one computer
may sound different than that same patch on another computer.</li>
<li>The 128 available patches are divided into instrument families of 8:</li>
<table width="450" border="0" align="center" cellpadding="2">
<tbody><tr>
<td width="60">0-7</td>
<td width="160">Piano</td>
<td width="60">64-71</td>
<td>Reed</td>
</tr>
<tr>
<td width="60">8-15</td>
<td width="160">Chromatic Percussion</td>
<td width="60">72-79</td>
<td>Pipe</td>
</tr>
<tr>
<td width="60">16-23</td>
<td width="160">Organ</td>
<td width="60">80-87</td>
<td>Synth Lead</td>
</tr>
<tr>
<td width="60">24-31</td>
<td width="160">Guitar</td>
<td width="60">88-95</td>
<td>Synth Pad</td>
</tr>
<tr>
<td width="60">32-39</td>
<td width="160">Bass</td>
<td width="60">96-103</td>
<td>Synth Effects</td>
</tr>
<tr>
<td width="60">40-47</td>
<td width="160">Strings</td>
<td width="60">104-111</td>
<td>Ethnic</td>
</tr>
<tr>
<td width="60">48-55</td>
<td width="160">Ensemble</td>
<td width="60">112-119</td>
<td>Percussion</td>
</tr>
<tr>
<td width="60">56-63</td>
<td width="160">Brass</td>
<td width="60">120-127</td>
<td>Sound Effects</td>
</tr>
</tbody></table>
<li>Note that outside of Java, General MIDI usually refers to patches 1-128.
When referring to a list of General MIDI patches, 1 must be subtracted
to play the correct patch. For a full list of General MIDI instruments,
see <a href="http://www.midi.org/">
www.midi.org/about-midi/gm/gm1sound.shtml</a>.
The General MIDI channel 10 percussion key map is not relevant to the
toneGenerator method because it always defaults to MIDI channel 1.</li>
<br>
</td>
</tr>
<tr>
<td><h3>volume ($a3)</h3>
<li>Accepts a positive byte value (0-127) where 127 is the loudest and 0
is silent. This value denotes MIDI velocity which refers to the initial
attack of the tone.</li>
<li>If the parameter value is outside this range, it applies a default value 100.</li>
<li>MIDI velocity measures how hard a <em>note on</em> (or <em>note off</em>)
message is played, perhaps on a MIDI controller like a keyboard. Most
MIDI synthesizers will translate this into volume on a logarithmic scale
in which the difference in amplitude decreases as the velocity value increases.</li>
<li>Note that velocity value on more sophisticated synthesizers can also
affect the timbre of the tone (as most instruments sound different when
they are played louder or softer).</li>
</td>
</tr>
</tbody></table>
System service 31 was developed and documented by Otterbein student Tony Brock in July 2007.
</p></body></html>