Register

Syscalls (serial communication, ...)

Discuss issues related to Calculator Hacking/Modding.
Senior Member
User avatar
Posts: 94
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9750 G II, Casio fx-9860 GII

Syscalls (serial communication, ...)

Postby cakeisalie5 » Mon Mar 13, 2017 8:56 pm

Hi! I am trying to make a simple add-in using libp7 to make a simple Protocol 7 transaction and display the other calculator's information (HardwareID, ProductID). I wanted to use fxlib, but as libp7 wouldn't compile with it, I made a simple libc aside, called libcarrot, which contains standard C features and an fxlib and MonochromeLib compatible interface. This lib is totally a work-in-progress and I only implement what I need for it to work for now.

I want to use syscalls to interact with the serial interface, so I was reading the Communication page in the chm, but I couldn't find the Comm_TransmitNBytes referenced in the syscalls reference's prototype. Is it the same than Serial_BufferedTransmitNBytes (0x40F) documented in the Serial page?

Thanks in advance :)
Last edited by cakeisalie5 on Wed Mar 22, 2017 1:19 pm, edited 1 time in total.
Part of the Planète Casio community (FR) - main author of the P7 project - libp7 - libg1m - FONTCHARACTER reference

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Serial Communication

Postby SimonLothar » Thu Mar 16, 2017 7:12 am

cakeisalie5 wrote:...but I couldn't find the Comm_TransmitNBytes referenced in the syscalls reference's prototype. Is it the same than Serial_BufferedTransmitNBytes (0x40F) documented in the Serial page?
Yes, seems to have the same interface.
I'll be back!

Senior Member
User avatar
Posts: 94
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9750 G II, Casio fx-9860 GII

Re: Syscalls (serial communication, ...)

Postby cakeisalie5 » Wed Mar 22, 2017 1:27 pm

Thanks! I implemented it. But I have other questions:
- There are several packet preparing function, and a packet receiving function, but I couldn't find, in your reference, any function to send a packet using the structure. What should I use, and how?
- Screenstreaming-related: for what I know, when you call the system functions, they call other functions, in screenstreaming mode, for sending the screen, but is there a way to call these functions in a separate way (know if screenstreaming is enabled, send a VRAM), in order to implement them in separate screen updating functions?

Thanks in advance :)
Part of the Planète Casio community (FR) - main author of the P7 project - libp7 - libg1m - FONTCHARACTER reference

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Syscalls (serial communication, ...)

Postby SimonLothar » Fri Mar 24, 2017 8:31 am

cakeisalie5 wrote:- There are several packet preparing function, and a packet receiving function, but I couldn't find, in your reference, any function to send a packet using the structure. What should I use, and how?

0x02DA: int Comm_SendPacket( TCommSendPacket*p );

see fxReverse.PDF p. 14

struct TCommSendPacket{
unsigned char T;
unsigned char ST;
unsigned short DS;
unsigned char*D;
};

The function sends a packet based on the contents of the passed TCommSendPacket p. The packet is built up in a local buffer.
If D is zero, EX (local buffer) will be set to "0" and D is ignored.
If D is not zero, EX (local buffer) will be set to "1" and the contents of D is copied to the local buffer.
The the checksum is added to the local buffer.
Finally the local buffer is sent.
 
I'll be back!

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Syscalls (serial communication, ...)

Postby SimonLothar » Fri Mar 24, 2017 10:19 am

cakeisalie5 wrote:- Screenstreaming-related: for what I know, when you call the system functions, they call other functions, in screenstreaming mode, for sending the screen, but is there a way to call these functions in a separate way (know if screenstreaming is enabled, send a VRAM), in order to implement them in separate screen updating functions?

There is
0x029D: void AutoImageTransfer_OHP();
AutoImageTransfer_OHP only works under certain circumstances. It exclusively uses the USB channel. The capture setting has to be either OHP, Projector or ScreenReceiver.
There are additional prerequisites.
It is not very likely, that it could be used from out of some addin, because setting up the prerequsites is difficult or possibly impossible.

Perhapy this could come in handy (Though I did not verify this observation, yet):
It looks as if AutoImageTransfer_OHP basically sends the sequence 0B 54 59 50 30 31 followed by the screen image (0x400 bytes, freshly retrieved using syscall 0x024).
A checksum is calculated over these 0x406 bytes by subtracting the bytes (SUB Rm,Rn) starting with checksum=0 (Rn=0).
The checksum is appended as ascii hex byte at buffer[0x406] and buffer[0x407].

The buffer is sent using syscall 0x0293 (Comm_BufferedTransmitNBytes) exclusively over the USB line.

syscall 0x024 is the SDK function Bdisp_GetDisp_DD (see fx-9860G Libraries.pdf).
 
I'll be back!

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Syscalls (serial communication, ...)

Postby SimonLothar » Fri Mar 24, 2017 10:55 pm

cakeisalie5 wrote:- Screenstreaming-related: for what I know, when you call the system functions, they call other functions, in screenstreaming mode, for sending the screen, but is there a way to call these functions in a separate way (know if screenstreaming is enabled, send a VRAM), in order to implement them in separate screen updating functions?

Syscall 0x02A0 / void USB_CaptureDisplay( void ); works with FA-124 Screen Capture.
It is not necessary to set LINK Capture to "ScreenCapture".
I'll be back!

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Syscalls (serial communication, ...)

Postby SimonLothar » Sat Mar 25, 2017 6:17 am

SimonLothar wrote:It looks as if AutoImageTransfer_OHP basically sends the sequence 0B 54 59 50 30 31 followed by the screen image (0x400 bytes, freshly retrieved using syscall 0x024).
A checksum is calculated over these 0x406 bytes by subtracting the bytes (SUB Rm,Rn) starting with checksum=0 (Rn=0). 
I have to correct this. The checksum is calculated over 0x405 bytes starting with the second byte (0x54).
Code: Select all
   buffer[0] = 0xB;
   buffer[1] = 0x54;
   buffer[2] = 0x59;
   buffer[3] = 0x50;
   buffer[4] = 0x30;
   buffer[5] = 0x31;
   Bdisp_GetDisp_DD( buffer+6 );
   chksum = 0;
   for ( i=1; i<0x406; i++ ){
      chksum -= buffer[ i ];
   };
   ByteToHex( chksum, buffer+0x406 );
   iResult = Comm_BufferedTransmitNBytes( buffer, 0x408 );
I'll be back!

Senior Member
User avatar
Posts: 94
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9750 G II, Casio fx-9860 GII

Re: Syscalls (serial communication, ...)

Postby cakeisalie5 » Sun Mar 26, 2017 12:04 am

Simon Lothar wrote:struct TCommSendPacket{
unsigned char T;
unsigned char ST;
unsigned short DS;
unsigned char*D;
};

In the chm (TReceivePacketDesc structure), you added the checksum member, is this member never read/written by any syscall or always generated before sending or at reception, without sending to the user? (was this structure member a supposition that, in the end, was not correct?)

Simon Lothar wrote:Perhapy this could come in handy (Though I did not verify this observation, yet):
It looks as if AutoImageTransfer_OHP basically sends the sequence 0B 54 59 50 30 31 followed by the screen image (0x400 bytes, freshly retrieved using syscall 0x024).
A checksum is calculated over these 0x406 bytes by subtracting the bytes (SUB Rm,Rn) starting with checksum=0 (Rn=0).
The checksum is appended as ascii hex byte at buffer[0x406] and buffer[0x407].

Yup, that's described in the fxReverse project documentation, screenstreaming section (TYP01 subtype) :p
I find that quite not nice to read from the display driver when they could read from the system VRAM... that may be the reason why screenstreaming slows everything down. :(

Also, using the code you've disassembled, I understand why the ~checksum + 1 if they start from zero and substract! It could be called checksubbing :p

Also, for what I've seen, Projector and ScreenReceiver are the same things, and ScreenCapture is basically just about sending one OHP packet then going offline. Is there any difference between Projector and ScreenReceiver, maybe in the syscalls it uses to read screens? Does USB_CaptureDisplay also read from the display driver?

Thanks for what you've already unraveled :D
Part of the Planète Casio community (FR) - main author of the P7 project - libp7 - libg1m - FONTCHARACTER reference

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Syscalls (serial communication, ...)

Postby SimonLothar » Sun Mar 26, 2017 6:42 am

cakeisalie5 wrote:...you added the checksum member, is this member never read/written by any syscall or always generated before sending or at reception, without sending to the user? (was this structure member a supposition that, in the end, was not correct?)
The Comm_Prepare****Packet-syscalls set this byte to zero. Comm_SendPacket does not use this member, but calculates the checksum internally.
I'll be back!

Senior Member
User avatar
Posts: 578
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750 G II, Casio fx-9750 G II (SH4), Casio fx-9860G, Casio fx-9860 G SD, Casio fx-9860G Slim, Casio fx-9860 GII SD, Casio fx-9860 GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG 20, Casio Classpad fx-cp400, Casio fx-CG 50

Re: Syscalls (serial communication, ...)

Postby SimonLothar » Sun Mar 26, 2017 12:21 pm

cakeisalie5 wrote:Also, for what I've seen, Projector and ScreenReceiver are the same things, and ScreenCapture is basically just about sending one OHP packet then going offline. Is there any difference between Projector and ScreenReceiver, maybe in the syscalls it uses to read screens? Does USB_CaptureDisplay also read from the display driver?

sys029d_AutoImageTransfer_OHP does not distinguish between "Projector" and "ScreenReceiver".
It is called out of various display syscalls (f. i. 0x28, 0x34) and quits, if LINK/Capture is not "Projector" or "ScreenReceiver" ("OHP" with OSes 1.xx).

sys02a0_USB_CaptureDisplay checks the battery and if USB is already open.
It is called from out of GetKey(), if the key 0x7567 (KEY_CTRL_CAPTURE) is pressed and LINK/Capture is set to "ScreenCapture".
Or if the virtual key 0x7568 is injected and LINK/Capture is set to "ScreenCapture".
PutKey( 0x7568, 0 );
GetKey( &key );
It can be called from out of an addin, if the above mentioned prerequisites are fulfilled.

Both use the same transfer buffer format.
I'll be back!

Next

Return to Calculator Hacking/Modding Discussions

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 2 guests