COBOL capture arrow keystrokes - input

I'm completely new to COBOL, so as a learning excercise (and just for the sake of it) I'm trying to make a small console based game of connect 4. However I'm struggling to find a way of listening for and reading in keystrokes (for example using the arrow keys to move a piece left and right) without having to press enter after. So far the best solution I've found is to use Microfocus' Enhanced Accept/Display (Adis) which allows the use of the function keys in the manner I would like. I was wondering if there was something I may have missed, or a way of using Adis that would permit me the same sort of functionality with other keys than the function keys. The following program (shamelessly copied from https://www.microfocus.co.jp/manuals/SE/books/uisckb.htm) demonstrates the use of the function keys in the manner I would like:
1$set noosvs mf ans85
2**********************************************************
3* Copyright Micro Focus International 2000. All Rights *
4* Reserved. This demonstration program is provided for *
5* use by users of Micro Focus products and may be used, *
6* modified and distributed as part of your application *
8* provided that you properly acknowledge the copyright *
9* of Micro Focus in this material. *
9**********************************************************
10
11**********************************************************
12* *
13* FUNKEY.CBL *
14* *
15* This program demonstrates how to decode function *
16* keys using the x"af" call. *
17* *
18**********************************************************
19 special-names.
20 crt status is key-status.
21
22 working-storage section.
23 01 flag pic 9(2) comp-x value 1.
24 01 user-key-control.
25 05 enable-fn-keys pic 9(2) comp-x value 1.
26 05 filler pic x value "1".
27 05 first-user-key pic 9(2) comp-x value 1.
28 05 number-of-keys pic 9(2) comp-x value 10.
29
30 01 key-status.
31 05 key-type pic x.
32 05 key-code-1 pic 9(2) comp-x.
33 05 filler pic x.
34 01 any-data pic x.
35 01 key-code-1-display pic z9.
36
37 procedure division.
38 perform enable-keys
39 perform accept-function-key
40 perform tell-which-key-was-pressed
41 perform stop-run.
42
43 enable-keys.
44 call x"af" using flag user-key-control.
45
46 accept-function-key.
47 display spaces upon crt
48 display "Press a function key: F1 to F10" at 0505
49 accept any-data at 0540.
50
51 tell-which-key-was-pressed.
52 evaluate key-type
53 when 0 display "You pressed <Enter>" at 0705
54 when 1
55 move key-code-1 to key-code-1-display
56 display "You pressed function key" at 0705
57 display key-code-1-display at 0730
58 end-evaluate.
59
60 stop-run.
61 stop run.

It you are up for using a little non-conventional COBOL, the S-Lang library is the bee's knees when it comes to keyboard handling. No ADIS required, but with care the two can live peacefully together. Trying this example will require GNU Cobol 1.1 and libslang (by John E. Davis, jedsoft).
OCOBOL >>SOURCE FORMAT IS FIXED
*> ***************************************************************
*> Date: 20090503
*> License: Copyright 2009, Brian Tiffin
*> licensed for use under the GNU GPLv2
*> Purpose: Experimental S-Lang keyboard interface
*> Tectonics: cobc -x slangkey.cob -lslang
*> ***************************************************************
identification division.
program-id. slangkey.
data division.
working-storage section.
01 thekey usage binary-long unsigned.
01 thekm usage binary-long.
01 result usage binary-long.
*> exit handler address and priority (prio is IGNORED with OC1.1)
01 install-flag pic 9 comp-x value 0.
01 install-params.
02 exit-addr usage is procedure-pointer.
02 handler-prio pic 999 comp-x.
*> ***************************************************************
procedure division.
*> Initialize low and high level S-Lang terminal routines
call "SLtt_get_terminfo" end-call
call "SLkp_init" returning result end-call
if result equal -1
display "problem intializing S-Lang tty" end-display
stop run giving 1
end-if
call "SLang_init_tty" using
by value -1 *> abort char
by value -1 *> flow ctrl
by value 0 *> output processing
returning result
end-call
if result equal -1
display "problem intializing S-Lang tty" end-display
stop run giving 1
else
display "Keyboard in special mode" x"0d" end-display
end-if
*> install an exit handler to put terminal back
set exit-addr to entry "tty-reset"
call "CBL_EXIT_PROC" using
install-flag
install-params
returning result
end-call
if result not equal zero
display "error installing exit procedure" end-display
end-if
*> Not sure? Have SLang handle ^C or let GNU Cobol take over?
call "SLang_set_abort_signal" using by value 0 end-call
*> The demo. Fetch a key, then fetch a keycode. 4 times.
*> SLang terminals display newline as newline. Need explicit
*> CR to get a carriage return. Hence the x"0d".
*> Plus, output is buffered until line terminators.
display
"Tap a normal key, then tap a 'special' key, ie F1, 4 times"
x"0d"
end-display
perform 4 times
call "SLang_getkey" returning thekey end-call
display thekey space with no advancing end-display
call "SLkp_getkey" returning thekm end-call
display thekm x"0d" end-display
end-perform
*> Exit handler will take care of resetting terminal
goback.
*> ***************************************************************
*> Exit procedure to ensure terminal properly reset
*> ***************************************************************
entry "tty-reset".
call "SLang_reset_tty" end-call
display "exit proc reset the tty" end-display
goback.
end program slangkey.

A bit late to the party but:
Documentation for ADIS can be found at https://supportline.microfocus.com/Documentation/books/sx51/sx51indx.htm - look for "Character user interfaces", and specifically the section "Keyboard handling via ADIS". The paragraph "enable-function-keys" in your code enables the function keys from F1 to F10. What you need to do is change the function of the cursor keys, which are ADIS keys, and to do this you need
01 adis-key-control.
05 enable-adis-keys pic 9(2) comp-x value 1.
05 filler pic x value "2".
05 first-adis-key pic 9(2) comp-x value 3.
05 number-of-adis-keys pic 9(2) comp-x value 8.
Then add the line
call x"af" using flag adis-key-control.
to the paragraph enable-function-keys. This will allow you to capture cursor left, right, up, and down, plus Home, tab, backtab, and End.

I do not have Micro Focus COBOL, but a quick internet search seems to indicate that the example you chose introduces some confusion by using the term function-keys and show values received from pressing function-keys.
It may be that using the function-keys was the simplest for the example, because the key-value is 1 to 10, so needing no translation from key-value to key that you understand. It shows 3, you know it means F3.
The only clue in the example you show is 05 number-of-keys pic 9(2) comp-x val. If the number of keys used by the x'af' CALL is configurable, then it can changed, then, likely, keys themselves can be changed.
You ask about ADIS (Micro Focus's Extended ACCEPT and DISPLAY)? Yes. It is all within ADIS. All the cursor keys are part of the Standard Adis Key Functions.
If you run the example program and press the arrow keys instead of a function key, what happens?
I searched for micro focus user interface manual and found enough information to make it necessary to know which particular Micro Focus product you have.

Related

How to erase msp430f2619 flash using bsl?

I want to do mass erase on my msp430f2619 using bsl. I use software jump in my code to invoke bsl. I send 0x80, get 0x90 from BSL(ack). Then i send mass erase command and get 0x90 again. Then i power off my device, then i power on the device, then i send 0x80 and get 0x90, that means there was no mass erase operation.
Read command is not working too. I send password (0xFF 32 times), after that send rx command, then i get few coorect bytes, and then infinite raw of 0xff.
I think i miised something before jump to bsl, please give an example code, or step by step instruction on how to make software jump to bsl and make it work correctly.
If you are sending 0x80 only, then get back 0x90, this confirms you have entered into the BSL since this completes the required synchronization sequence (see section 2.1 of this document). You should not require the "RX password" command since the "Mass erase" command is not protected.
The next sequence after the synchronization is to send the desired command, which should be the "Mass erase". There is a format to each of the BSL commands called the data frame. You want to send the following data frame: eight mandatory bytes (note two dummy bytes), and two checksum bytes. Note the "Mass erase" command does not contain data bytes, but you need to calculate the checksum bytes. Here are the bytes to be sent to perform the mass erase:
80 18 04 04 dd dd 06 A5 CL CH
Where: dd = dummy bytes (any value accepted), CL = Checksum low, CH = Checksum high
After sending this data frame then you should receive the ACK (0x90) byte. Then power off the device.

How to set and update ICC card PIN with APDU command

I have a contact smartcard.(I dont know about what kind of applet installed on it. But I can authenticate, read, update and verify pin with standart APDU commands.) And I want to do some changes on PIN.
So, my question is:
If card has PIN, then update the PIN with new value. If card dont have any PIN, then set PIN.
Standart update command is not working on PIN file. I am getting 6982 response message from ICC card. So, what is the approach to success above situation.
I searched on internet about it, But I didnt find any useful Docs&Articles.
Error 6982 stands for "Security condition not satisfied".
PINs are never transmitted plain as you have mentioned in your packet. They are always encrypted for the software involved between a User and the ICC can sneak peak the packet. A public key has to be obtained using GET_CHALLENGE command and used for enciphering of the PIN.
According EMV spec, the APDU for PIN change is
CLA = 8C or 84;
INS = 24
P1 = 00
P2 = 01/ 02
Lc = Number of data bytes
Data = Enciphered PIN data component, if present, and MAC data component;
CLA and Data are to be coded according to the secure messaging specified in EMV Book 2
P2 = 01 => PIN Data Generated Using the Current PIN
P2 = 02 => PIN Data Generated Without Using the Current PIN
new PIN is encapsulated in the Data field
Finaly I found solution, and I am putting the answer here.
Firstly, we need to select PIN FILE. For this
Select MF(Master File)
Select DF(Dedicated file)
Select PIN EF (Elementry file)
Select App Master File : 00 A4 00 00 02 XX XX
Select App Dedicated File : 00 A4 00 00 02 XX XX
Select App Pin File : 00 A4 00 00 02 XX XX
Change Pin coommand: 00 24 [TM] [KN] [LN] XX XX .. ..
TM: Transfer Mode (Clear Transfer) : 00 KN: Key Number: 10 LN:
Total Pin Length(Every time 16 bytes): 10
For example (Old pin is “1234” and we want to change pin to
“5678”:
Change Pin : 00 24 00 10 10 31 32 33 34 FF FF FF FF 35 36 37 38 FF
FF FF FF (FF: padding value)

STM32 Atollic TrueSTUDIO - Graphical view of the Memory

I'm using Atollic TrueSTUDIO for STM32 as an Eclipse Based IDE to perform Digital Signal Processing on audio signal. I'm looking for a way to plot an array (16 bits audio samples) from RAM memory. For the moment I'm using :
The memory View
The SWV real time data time line
None of this tools are powerful to analyse signal on an array, and it doesn't have to be on real time : Just ploting an array after reaching a breakpoint.
Is there an Eclipse Plugin or some other ways to do this ?
I'm considering to export the RAM memory and in a file and plot it in Matlab, but it seems really inapropriate for such a simple thing.
Thanks for any advices
In Atollic, you can easily attach gdb commands to breakpoints. Doing this, allows you to automaticly dump any variables. Additionally, you can execute an external programm once afterwards, to plot the content of the dumped variable.
To do so, goto breakpoint properties and create a new action. Select "Debugger Command Action" and use dump binary value x.bin x to dump variable x to file x.bin
You can also start a python script from the breakpoint to plot the data.
Use an additonal "External Tool Action" and select your python location. Make sure to select your current Working Dictonary. Use the arguments to pass the full path of the python file. The following file will import a float array and plot it.
import struct
import numpy as np
import matplotlib.pyplot as plt
import os
def readBinaryDump(filename):
result = []
N=8
with open(filename,'rb') as f:
while(True):
b = f.read(4*N);
if len(b) ==0:
break
fn = "f"*N
result.append(struct.unpack(fn,b))
result = np.array(result)
return result.ravel()
plt.plot(readBinaryDump("x.bin"))
Don't forget to add the actions to the current breakpoint. Now once the breakpoint is reached, the variable should be dumped and plotted automaticly.
While it's surprising nothing could be embeded in Atollic/Eclipse, I followed the idea of writing an specific application. Here are the steps I used :
Dump Memory :
Debug your software
Stop on a BreakPoint
View > Memory > Export Button > Format : "Plain Text"
The file representing a sine wawe looks like this :
00 00 3E 00 7D 00 BC 00 FB 00 39 01 78 01
B7 01 F6 01 34 02 73 02 B2 02 F0 02 2F 03
You should read these int16 samples like this :
1. 0x0000
2. 0x003E
3. 0x007D
4. etc...
Write this Matlab script :
fileID = fopen('your_file','r');
samples = textscan(fileID,'%s')
fclose(fileID);
samples = samples{1};
words = strcat(samples(2:2:end,1), samples(1:2:end,1));
values = typecast(uint16(hex2dec(words)),'int16');
plot(values) ;
The sinus wave plotted in Matlab
While there aren't any Eclipse plugins that would do what you're asking for that I'm personally aware of, there's STM Studio whose main purpose is displaying variables in real-time. It parses your ELF file to get the available variables, so the effort to at least give it a try should be minimal.
It's available here: https://www.st.com/en/development-tools/stm-studio-stm32.html
ST-Link is required to run it.
Write the simple app in C#. Use semi hosting to dump the memory to the text file. Open it and display.
Recently I had problem with MEMS-es and this was written in less than one hour. IMO (In My Opinion) it is easier to write program which will visualize the data instead of wasting hours or days searching for the ready made one:

Understanding the bitstream generated for iCE40 I/O tiles

When I synthesize an empty circuit using Yosys and arachne-pnr, I get a few irregular bits:
.io_tile 6 17
IoCtrl IE_1
.io_tile 6 0
IoCtrl REN_0
IoCtrl REN_1
These are also part of every other file I could generate so far. Since an unused I/O tile has both IE bits set, I read this as:
for IE/REN block 6 17 0, the input buffer is enabled
for IE/REN block 6 0 0, the input buffer is enabled and the pull-up resistor is disabled
for IE/REN block 6 0 1, the input buffer is enabled and the pull-up resistor is disabled
However, according to the documentation, there is no IE/REN block 6 17 0.
What is the meaning of these bits? If the IE bit of block 6 17 0 is unset because the block doesn't exist, why aren't the bits of the other blocks which don't exist unset, too? The other IE/REN blocks seem to correspond to I/O blocks 6 0 1 and 7 0 0. What do these blocks do, and why are they always configured as inputs?
The technology library entry for SB_IO does not mention the IE bit. How is it related to the PIN_TYPE parameter settings?
When I use an I/O pin as an input, the REN bit is set (the pull-up resistor disabled). This suggests that the pull-up resistors are primarily intended to keep unused pins from floating, not to provide a pull-up resistor for conditionally connected inputs (e.g. buttons). Is this assumption correct? Would it be ok to use the internal pull-up resistors for that purpose?
The technology library says the following:
defparam IO_PIN_INST.PULLUP = 1'b0;
// By default, the IO will have NO pull up.
// This parameter is used only on bank 0, 1,
// and 2. Ignored when it is placed at bank 3
Does this mean bank 3 doesn't have pull-up resistors, or merely that they can't be re-enabled using Verilog? What would happen if I clear that bit in the ASCII bitstream manually? (I'd be trying this, but the iCEstick evaluation board doesn't make any pin on bank 3 accessible – a coincidence? – and I'm not sure if I want to mess with the hardware yet.)
When I use an I/O pin as an output, the IE bit isn't cleared, but the input pin function is set to PIN_INPUT. What effect does this have, and why is it done?
The default behavior for unused IO pins is to enable the pullup resistors and disable input enable. On iCE40 1k chips this means IE_0 and IE_1 are set and REN_0 and REN_1 are cleared in an unused IO tile. (On 8k chips IE_* is active high, i.e. all bits are cleared in an unused IO tile on an 8k chip.)
icebox_explain by default hides tiles that have "uninteresting" contents. (Run icebox_explain -A to disable this feature.)
It looks like arachne-pnr does not set those bits for IO pins that are not available in the current package. Thus you get some unusual bit pattern in some IO tiles that contain IE/REN bits for IO blocks not connected to any package pin.
This is what a "normal" unused IO tile looks like on the 1k architecture:
$ icebox_explain -mAt '1 0' example.asc
Reading file 'example.asc'..
Fabric size (without IO tiles): 12 x 16
.io_tile 1 0
B0 ------------------
B1 ------------------
B2 ------------------
B3 ------------------
B4 ------------------
B5 ------------------
B6 ---+--------------
B7 ------------------
B8 ------------------
B9 ---+--------------
B10 ------------------
B11 ------------------
B12 ------------------
B13 ------------------
B14 ------------------
B15 ------------------
IoCtrl IE_0
IoCtrl IE_1
Would it be ok to use the internal pull-up resistors for that purpose?
Yes.
The technology library entry for SB_IO does not mention the IE bit. How is it related to the PIN_TYPE parameter settings?
When D_IN_0 or D_IN_1 from SB_IO is connected to something, then this implies IE.
When I use an I/O pin as an output, the IE bit isn't cleared
Note that IE is active low on 1k chips and active high on 8k chips. When you use an I/O pin as output-only pin on a 1k device, then the corresponding IE bit should be set, otherwise it should be cleared.
I found the explanation, so I'm sharing it here for future reference:
.io_tile 6 17
IoCtrl IE_1
I/O block 16 7 0 is connected to a pin in some packages but not in the TQFP package.
.io_tile 6 0
IoCtrl REN_0
IoCtrl REN_1
This corresponds to I/O blocks 6 0 1 and 7 0 0 (pins 49 and 50) into whose input paths the PLL PORTA and PORTB clocks are fed, respectively.

View executed sql statements from a crash dump

How can I view executed SQL stored procedures from a memory crash dump of a C# .net application?
The information you want might not be available any more. The objects representing connections, queries and results may already have been garbage collected.
If you know the name of the class that is used for a query, you can use windbg, load the sos extension and use the !dumpheap -type <classname> command to find those objects. Then use !do <address> to display the details of such an object. This might reveal the statement behind it.
If you're looking for a specific query, download the netext extension. It comes with the !wfrom command which allows you to select objects from the .NET heap based on criteria that you define.
This question has no trivial answer and many experienced debuggers had to face this issue one way of another. Getting the information for a single SQL command is tedious, but straightforward. For many it is difficult. I was helping a colleague on a situation like this and put together this solution. It requires NetExt (download the zip file): https://github.com/rodneyviana/netext/tree/master/Binaries
0:067> !windex
Starting indexing at 14:18:54 PM
1000000 objects...
2000000 objects...
3000000 objects...
4000000 objects...
Indexing finished at 14:19:04 PM
399,314,598 Bytes in 4,049,972 Objects
Index took 00:00:10
0:067> .foreach ({$addr} {!wfrom -type *.sqlcommand -nospace -nofield where (_commandType == 4) select _parameters._items._items}) { r #$t1= {$addr} ;!wfrom -type *.sqlcommand -nofield -nospace where (_parameters._items._items==$dbgeval("#$t1")) "\n", _commandText," [",$addr(),"]\n========================"; !wfrom -nospace -nofield -array {$addr} _parameterName,"=",$pp(_value) }
dbo.proc_getSiteIdOfHostHeaderSite [00000001011FCD90]
========================
#RETURN_VALUE=0n0
#HostHeader=sp.contoso.com
#RequestGuid={00000000-0000-0000-0000-000000000000}
proc_GetTpWebMetaDataAndListMetaData [0000000101D98DA0]
========================
#RETURN_VALUE=0n0
#WebSiteId={2815591d-55c8-4caf-842c-101d8807cb2a}
#WebId=NULL
#Url=
#ListId=NULL
#ViewId=NULL
#RunUrlToWebUrl=1
#DGCacheVersion=0n2
#SystemId=69 3a 30 29 2e 77 7c 73 2d 31 2d 35 2d 32 31 2d 31 33 38 35 31 37 34 39 39 32 2d 39 37 39 39 35 i:0).w|s-1-5-21-1385174992-97995 (...more...)
#MetadataFlags=0n18
#ThresholdScopeCount=0n5000
#CurrentFolderUrl=NULL
#RequestGuid={a00a0b30-1fcc-44d6-8346-ec20f8c49304}
proc_EnumLists [000000010236EDF0]
========================
#RETURN_VALUE=0n0
#WebId={a0a099b2-6023-4877-a7c1-378ec68df759}
#Collation=Latin1_General_CI_AS
#BaseType=NULL
#BaseType2=NULL
#BaseType3=NULL
#BaseType4=NULL
#ServerTemplate=NULL
#FMobileDefaultViewUrl=NULL
#FRootFolder=NULL
#ListFlags=0n-1
#FAclInfo=0n1
#Scopes=NULL
#FRecycleBinInfo=NULL
#UserId=NULL
#FGP=NULL
#RequestGuid={a00a0b30-1fcc-44d6-8346-ec20f8c49304}
(...)