Memory layout of a data structure: Difference between revisions

m
→‎{{header|REXX}}: added version 2. -- ~~~~
(→‎{{header|REXX}}: changed Rexx to REXX. There are still two more to find like this error. -- ~~~~)
m (→‎{{header|REXX}}: added version 2. -- ~~~~)
Line 599:
 
=={{header|REXX}}==
===version 1===
 
<lang rexx>/* REXX ***************************************************************
* Decode Memory structure of RS-232 Plug Definition
Line 758:
8 CTS Clear to send =1
9 RI Ring indicator =1
</pre>
 
===version 2===
<lang rexx>/*REXX pgm displays which pins are active of a 9 or 24 pin RS-232 plug. */
call rs_232 24, 127 /*value for an RS-232 24 pin plug*/
call rs_232 24, '020304x' /*value for an RS-232 24 pin plug*/
call rs_232 9, '10100000b' /*value for an RS-232 9 pin plug*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────RS_232 subroutine───────────────────*/
rs_232: arg pins,x; parse arg ,ox; @.= /*x is uppercased when using ARG.*/
@.24.1 = 'PG protective ground'
@.24.2 = 'TD transmitted data' ; @.9.3 = @.24.2
@.24.3 = 'RD received data' ; @.9.2 = @.24.3
@.24.4 = 'RTS request to send' ; @.9.7 = @.24.4
@.24.5 = 'CTS clear to send' ; @.9.8 = @.24.5
@.24.6 = 'DSR data set ready' ; @.9.6 = @.24.6
@.24.7 = 'SG signal ground' ; @.9.5 = @.24.7
@.24.8 = 'CD carrier detect' ; @.9.1 = @.24.8
@.24.9 = '+ positive voltage'
@.24.10 = '- negative voltage'
@.24.11 = 'B11 unassigned bit 11'
@.24.12 = 'SCD secondary CD'
@.24.13 = 'SCS secondary CTS'
@.24.14 = 'STD secondary td'
@.24.15 = 'TC transmit clock'
@.24.16 = 'SRD secondary RD'
@.24.17 = 'RC receiver clock'
@.24.18 = 'B18 unassigned bit 18'
@.24.19 = 'SRS secondary RTS'
@.24.20 = 'DTR data terminal ready' ; @.9.4 = @.24.20
@.24.21 = 'SQD signal quality detector'
@.24.22 = 'RI ring indicator' ; @.9.9 = @.24.22
@.24.23 = 'DRS data rate select'
@.24.24 = 'XTC external clock'
 
select
when right(x,1)=='B' then bits= strip(x,'T',"B")
when right(x,1)=='X' then bits=x2b(strip(x,'T',"X"))
otherwise bits=x2b( d2x(x))
end /*select*/
 
bits=right(bits,pins,0) /*right justify the pin readings.*/
say; say '───────── For a' pins "pin RS─232 plug, with a reading of: " ox
say
do j=1 for pins; z=substr(bits,j,1); if z==0 then iterate
say right(j,5) 'pin is "on": ' @.pins.j
end /*j*/
return</lang>
'''output''' when using the internal input:
<pre style="overflow:scroll">
───────── For a 24 pin RS─232 plug, with a reading of: 127
 
18 pin is "on": B18 unassigned bit 18
19 pin is "on": SRS secondary RTS
20 pin is "on": DTR data terminal ready
21 pin is "on": SQD signal quality detector
22 pin is "on": RI ring indicator
23 pin is "on": DRS data rate select
24 pin is "on": XTC external clock
 
───────── For a 24 pin RS─232 plug, with a reading of: 020304x
 
7 pin is "on": SG signal ground
15 pin is "on": TC transmit clock
16 pin is "on": SRD secondary RD
22 pin is "on": RI ring indicator
 
───────── For a 9 pin RS─232 plug, with a reading of: 10100000b
 
2 pin is "on": RD received data
4 pin is "on": DTR data terminal ready
</pre>