Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Projets de programmation


Index du Forum » Projets de programmation » CSV to Casio G1M spreadsheet conversion script
Calamari Hors ligne Membre Points: 404 Défis: 0 Message

CSV to Casio G1M spreadsheet conversion script

Posté le 03/10/2024 05:16

Motivation
I've written a couple of Casio S-SHT spreadsheet games for my own amusement, the absurdity of which have hopefully brought a few laughs to the community. For my S-SHT Tic-Tac-Toe game, I manually entered each cell on the calculator. Well, I didn't wish to repeat that unique experience for S-SHT Video Poker! So, I wrote this script instead, which probably took me days longer than if I'd just typed it all in.

Script Usage
Note: I've only tested any of this with LibreOffice Calc. I imagine Google Sheets and Microsoft Excel offer similar formulas and CSV export functionality. So other spreadsheet software MIGHT generate CSV's compatible with this script... or it might not.

Prerequisites: LibreOffice Calc, Python 3. Download the script here: csv2g1m.py (1.0)

1. Write and test your spreadsheet using LibreOffice, saving in the ODS format.

2. "Save As" the spreadsheet to "Text CSV (.csv)". Use
,
(comma) for the field delimiter, and
"
(quotation mark) for the string delimiter. Select "Save cell content as shown", "Save cell formulas instead of calculated values", and "Quote all text cells". Deselect "Fixed column width".

3. Close the CSV spreadsheet (important!) and then re-open the CSV using LibreOffice Calc. Closing the CSV immediately is a good idea anyhow, as there were times where I realized I was making changes to the CSV when I meant to be editing the original ODS! Verify that the spreadsheet still works from the CSV. If it doesn't, fix it before proceeding.

4. Run
./csv2g1m.py CSV_FILENAME SPREADSHEET_NAME
. Note that the spreadsheet name must be at most 8 letters long, and will be automatically capitalized. I don't know which characters are allowed, so I'd recommend sticking to letters and numbers, for safety. The script will write a G1M file based on the spreadsheet name. A spreadsheet name of MYGAME will result in the output file MYGAME.g1m.

5. Back up any of your calculator's important programs or data, just in case. I used https://bible.planet-casio.com/simlo/chm/v20/fx_legacy_SpreadSheetFormat.htm to implement Casio's spreadsheet format. The document was invaluable. However, it seems to have been written before text cells and formulas, so I had to reverse engineer those parts of the G1M format myself. I believe I got it right, but I don't have the knowledge of Casio internals like the authors of that documentation do, so I could have easily made mistakes or incorrect assumptions.

6. Transfer the spreadsheet to the SSHEET directory of the Casio's main memory.

7. Open the spreadsheet using S-SHT. You'll see a LOT of errors. This is because the script is not computing any values. Using FILE > RECAL should fix the errors. If errors remain, there are many reasons. Perhaps a formula you are using isn't supported, or isn't fully supported by Casio's spreadsheet implementation. Or a formula might not be allowed in certain contexts, or might not support the same range of numbers as LibreOffice. See below for a list of limitations and omissions that I'm aware of. There are almost certainly additional limitations that I'm currently unaware of.

Supported Formulas and Operators
The script supports the following LibreOffice Calc formulas, some with limitations (see below). Consult the LibreOffice Function Wizard or LibreOffice documentation for an explanation of what each of these do:

ABS(n), ACOS(n), ACOSH(n), ASIN(n), ASINH(n), ATAN(n), ATANH(n), AVERAGE(range), BITAND(n,n), BITOR(n,n), BITXOR(n,n), COS(n), COSH(n), EXP(n), FACT(n), FALSE(), GCD(n,n), IF(test_expr,then_expr,else_expr), INT(n), LCM(n,n), LOG10(n), LN(n), MEDIAN(range), MOD(n,n), MIN(range), MAX(range), NOT(n), PI(), PRODUCT(range), RANDBETWEEN(n,n), RAND(), SUM(range), SIN(n), SINH(n), SQRT(n), TAN(n), TANH(n), TRUE()

The script also supports the following LibreOffice operators: <=, <>, >=, +, -, ^, *, /

The script supports text cells (including lowercase letters!) and converts the following Unicode characters in text cells to their Casio equivalents: ◢→⇒√⁻²⸋∛°×⏨÷⌟𝐫𝑟θπ𝐢ⅈ∠. If the first character in a text cell is
'
(apostrophe), the cell will be considered a comment and not exported to the G1M.

Limitations and Omissions
The AND(n,...) and OR(n,...) formulas are not implemented. For OR, add a sequence of test expressions, such as ((A1=5)+(B1=6)). For AND, you could multiply the test expressions, but I add them up the same as for OR, then test that the sum is equal to the number of expressions: ((A1=5)+(B1=6))=2.

MOD(n,d) is converted to ((n) Rmdr (d)). This was done as Casio's MOD didn't seem to be usable inside a CellIf. Casio's Rmdr seems to only allow for 10 integer digits, despite the calculator supporting larger integers still with full internal precision. As a result, for Video Poker I ended up using the formula n-INT(n/d)*d instead.

Casio's GCD and LCM functions only support two arguments, compared to multiple in LibreOffice.

Casio's spreadsheet app does not support string literals in formulas, nor any string operations. You can't even reference a cell with a string in it from a CellIf. As a result, no string-related LibreOffice formula is supported, nor the “&” operator.

Casio's CellIf, which LibreOffice IF() is converted to, has some severe limitations. CellIf's cannot be nested, and can't seem to contain other range functions like CellSum. So, while you might happily code such things in LibreOffice, they won't actually work on the calculator. Use separate cells for each one. You can add IF()'s using “+”, though.

Formulas that accept a range, such as SUM only support a single range on the Casio.

I didn't implement the percent operator “%”. Divide the value by 100 instead.

The following formulas are also unimplemented, but I've worked out replacements. Most of these are untested, so if I've made any mistakes please let me know:
• ACOT(n) = ATAN(1/(n))
• ACOTH(n) = (LOG((n)+1)/((n)-1))/2)
• BITLSHIFT(a,b) = ((a)*2^(b))
• BITRSHIFT(a,b) = INT((a)/2^(b))
• COT(n) = (1/TAN(n))
• COTH(n) = (EXP(2*(n))+1)/(EXP(2*(n))-1))
• CSC(n) = (1/SIN(n))
• CSCH(n) = (1/SINH(n))
• DEGREES(n) = ((n)*PI()/180)
• DELTA(a,b) = ((a)=(b))
• ISEVEN(n) = (INT((n)/2)=((n)/2))
• ISODD(n) = (INT((n)/2)<>((n)/2))
• LOG(a,b) = (LOG(a)/LOG(b))
• POWER(a,b) = ((a)^(b))
• QUOTIENT(a,b) = INT((a)/(b))
• RADIANS(n) = ((n)*180/PI())
• SEC(n) = (1/COS(n))
• SECH(n) = (1/COSH(n))
• SIGN(n) = IF((n),ABS(n)/(n),0)
• SQRTPI(n) = SQRT((n)*PI())

Spreadsheet Programming Techniques
When writing the spreadsheet games, I came up with a few things that helped me, such as something resembling a C switch statement. If there is interest. perhaps this would also be a good thread to share spreadsheet programming techniques.



LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 75 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd