summaryrefslogtreecommitdiff
path: root/frontends/calculator/CEdev/examples/fileio_read_write
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/calculator/CEdev/examples/fileio_read_write')
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/autotester.json33
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.8xpbin0 -> 827 bytes
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.binbin0 -> 751 bytes
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.map154
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/makefile15
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/obj/main.src343
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/readme.md10
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/screenshot.pngbin0 -> 54385 bytes
-rw-r--r--frontends/calculator/CEdev/examples/fileio_read_write/src/main.c88
9 files changed, 643 insertions, 0 deletions
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/autotester.json b/frontends/calculator/CEdev/examples/fileio_read_write/autotester.json
new file mode 100644
index 0000000..bd30851
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/autotester.json
@@ -0,0 +1,33 @@
+{
+ "rom": "84pce_515.rom",
+ "transfer_files": [
+ "bin/DEMO.8xp"
+ ],
+ "target": {
+ "name": "DEMO",
+ "isASM": true
+ },
+ "sequence": [
+ "action|launch",
+ "delay|1000",
+ "hash|1",
+ "key|enter",
+ "delay|200",
+ "hashWait|2"
+ ],
+ "hashes": {
+ "1": {
+ "description": "Assert that the read was succesful",
+ "start": "vram_start",
+ "size": "vram_16_size",
+ "expected_CRCs": [ "D720F0D9" ]
+ },
+ "2": {
+ "description": "Back to the home screen (exit check)",
+ "start": "vram_start",
+ "size": "vram_16_size",
+ "expected_CRCs": [ "FFAF89BA", "101734A5", "9DA19F44" ]
+ }
+ }
+}
+
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.8xp b/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.8xp
new file mode 100644
index 0000000..8c3e091
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.8xp
Binary files differ
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.bin b/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.bin
new file mode 100644
index 0000000..0b69716
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.bin
Binary files differ
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.map b/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.map
new file mode 100644
index 0000000..7cf5131
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/bin/DEMO.map
@@ -0,0 +1,154 @@
+Segment Base Top High Length
+-------- ------ ------ ------ -------
+icon D1A882 D1A882 0h
+launcher D1A882 D1A8DA 58h
+libs D1A8DA D1A906 2Ch
+startup D1A906 D1A945 3Fh
+cleanup D1A945 D1A959 14h
+exit D1A959 D1A95F 6h
+code D1A95F D1AB0A 1ABh
+data D1AB0A D1AB2F 25h
+strsect D1AB2F D1AB6E 3Fh
+text D1AB6E D1AB6E 0h
+bss D031F6 D03207 D13FD6 11h
+header D1A87F D1A882 3h
+
+Label Value
+------------------------- ------
+_os_DisableHomeTextBuffer = D1A95F
+_os_EnableHomeTextBuffer = D1A971
+_boot_GetBootMajorVer = 000080
+_boot_GetHardwareVer = 000084
+_boot_GetBootMinorVer = 00008C
+_boot_DebugPrintf = 0000B4
+_boot_ClearVRAM = 000374
+_boot_TurnOff = 000388
+_boot_NewLine = 000390
+_boot_Set6MHzMode = 00039C
+_boot_Set48MHzMode = 0003A0
+_boot_Set6MHzModeI = 0003A4
+_boot_Set48MHzModeI = 0003A8
+_boot_GetBatteryStatus = 0003B0
+_boot_WaitShort = 0003B4
+_boot_CheckOnPressed = 00057C
+_boot_SetDate = 000598
+_boot_GetDate = 0005A8
+_boot_GetTime = 0005B0
+_boot_SetTime = 0005B4
+_boot_IsAfterNoon = 0005C8
+_os_NewLine = 0207F0
+_os_PushErrorHandler = 021C78
+_os_PopErrorHandler = 021C7C
+_os_ThrowError = 021C80
+_os_RealCopy = 021C84
+_os_RealAsinRad = 021C88
+_os_RealAcosRad = 021C8C
+_os_RealAtanRad = 021C90
+_os_RealAdd = 021C94
+_os_CplxSquare = 021C98
+_os_RealCompare = 021C9C
+_os_RealCosRad = 021CA0
+_os_RealRadToDeg = 021CA4
+_os_RealDiv = 021CA8
+_os_RealExp = 021CAC
+_os_RealFloor = 021CB0
+_os_RealToStr = 021CB4
+_os_RealFrac = 021CB8
+_os_RealGcd = 021CBC
+_os_RealRoundInt = 021CC0
+_os_RealLcm = 021CC4
+_os_RealLog = 021CC8
+_os_RealMax = 021CCC
+_os_RealMin = 021CD0
+_os_RealMul = 021CD4
+_os_RealNcr = 021CD8
+_os_RealNeg = 021CDC
+_os_RealNpr = 021CE0
+_os_RealPow = 021CE4
+_os_RealDegToRad = 021CE8
+_os_RealRandInt = 021CEC
+_os_RealInv = 021CF0
+_os_RealMod = 021CF4
+_os_RealRound = 021CF8
+_os_RealSinRad = 021CFC
+_os_RealSqrt = 021D00
+_os_RealSub = 021D04
+_os_RealTanRad = 021D08
+_os_StrToReal = 021D0C
+_os_RealInt = 021D10
+_os_SetFlagBits = 021D14
+_os_ResetFlagBits = 021D18
+_os_TestFlagBits = 021D1C
+_os_SetFlagByte = 021D20
+_os_GetFlagByte = 021D24
+_os_GetCursorPos = 021D28
+_os_PutStrFull = 021D2C
+_os_PutStrLine = 021D30
+_os_SetCursorPos = 021D34
+_os_AppInit = 021D40
+_os_GetKey = 021D38
+_os_GetCSC = 021D3C
+_os_DisableCursor = 021DE4
+_os_EnableCursor = 021DE8
+_os_FontDrawText = 021E00
+_os_FontGetHeight = 021E14
+_os_FontGetWidth = 021E18
+_os_InitDrawing = 021E1C
+_os_SetDrawBGColor = 021E20
+_os_SetDrawFGColor = 021E24
+_os_FontSelect = 021E28
+_os_RclAns = 021E70
+_os_SetTimer1 = 021EC8
+_os_DisableTimer1 = 021ECC
+_os_GetSystemStats = 021ED4
+_os_GetDrawBGColor = 021EE4
+_os_GetDrawFGColor = 021EE8
+_os_FontGetID = 021EEC
+_os_RealToInt24 = 021EF4
+_os_Int24ToReal = 021EF8
+_os_ForceCmdNoChar = 021FA8
+_os_GetSymTablePtr = 021FB0
+_os_NextSymEntry = 021FB4
+_os_ChkFindSym = 021FB8
+_os_MemChk = 021FF0
+_os_SetTimer2 = 022080
+_os_DisableTimer2 = 022084
+_os_FloatToReal = 022170
+_os_RealToFloat = 022174
+_os_FontDrawTransText = 022178
+_os_CreateAppVar = 022184
+_asm_MoveDown = 0207F4
+_asm_MoveUp = 020800
+_asm_ClrLCDFull = 020808
+_asm_ClrLCD = 02080C
+_asm_ClrTxtShd = 020818
+_asm_HomeUp = 020828
+_asm_RunIndicOn = 020844
+_asm_RunIndicOff = 020848
+_asm_DelRes = 020E5C
+_asm_DisableAPD = 021134
+_asm_EnableAPD = 021138
+_asm_DrawStatusBar = 021A3C
+_asm_ArcChk = 022040
+__OS = D1A983
+__frameset0 = D1A98D
+__frameset = D1A998
+_strcpy = 0000CC
+__findlibload = D1A882
+__ccleanup = D1A945
+_errno = D008DC
+_init = D1A882
+_exit = D1A95B
+__exit = D1A934
+__exitsp = D1A934
+__errsp = D1A934
+_printText = D1AAE8
+_main = D1A9A6
+_data = D031F6
+_appvarName = D1AB2C
+_ti_CloseAll = D1A8EE
+_ti_Open = D1A8F2
+_ti_Write = D1A8F6
+_ti_Read = D1A8FA
+_ti_Rewind = D1A8FE
+_ti_GetName = D1A902
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/makefile b/frontends/calculator/CEdev/examples/fileio_read_write/makefile
new file mode 100644
index 0000000..1f1b36b
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/makefile
@@ -0,0 +1,15 @@
+# ----------------------------
+# Set NAME to the program name
+# Set ICON to the png icon file name
+# Set DESCRIPTION to display within a compatible shell
+# Set COMPRESSED to "YES" to create a compressed program
+# ----------------------------
+
+NAME ?= DEMO
+COMPRESSED ?= NO
+ICON ?= iconc.png
+DESCRIPTION ?= "C SDK Demo"
+
+# ----------------------------
+
+include $(CEDEV)/include/.makefile
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/obj/main.src b/frontends/calculator/CEdev/examples/fileio_read_write/obj/main.src
new file mode 100644
index 0000000..3371816
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/obj/main.src
@@ -0,0 +1,343 @@
+; Zilog eZ80 ANSI C Compiler Release 3.4
+; -optsize -noreduceopt -nomodsect -peephole -globalopt
+; -localcse -const=ROM
+ FILE "SRC\MAIN.C"
+ .assume ADL=1
+ SEGMENT STRSECT
+L__0:
+ DB "AppVar"
+ DB 0
+ SEGMENT DATA
+_appvarName:
+ DW24 L__0
+ SEGMENT BSS
+_data:
+ DS 17
+; 1 #include <stdbool.h>
+; 2 #include <stddef.h>
+; 3 #include <stdint.h>
+; 4 #include <tice.h>
+; 5
+; 6 #include <stdio.h>
+; 7 #include <stdlib.h>
+; 8 #include <string.h>
+; 9
+; 10 #include <fileioc.h>
+; 11
+; 12 /* Declare some variables */
+; 13 const char *appvarName = "AppVar";
+; 14
+; 15 typedef struct {
+; 16 char name[15];
+; 17 uint8_t var1;
+; 18 uint8_t var2;
+; 19 } data_t;
+; 20
+; 21 data_t data;
+ SEGMENT CODE
+; 22
+; 23 #define VAR1_VALUE 10
+; 24 #define VAR2_VALUE 20
+; 25
+; 26 /* Function prototypes */
+; 27 void printText(int8_t xpos, int8_t ypos, const char *text);
+; 28
+; 29 /* Main Function */
+; 30 void main(void) {
+_main:
+ LD HL,-11
+ CALL __frameset
+; 31 char nameBuffer[10];
+; 32 ti_var_t myAppVar;
+; 33 int x;
+; 34
+; 35 /* Clear the homescreen */
+; 36 os_ClrHome();
+ LD BC,_asm_ClrLCD
+ PUSH BC
+ CALL __OS
+ POP BC
+ LD BC,_asm_HomeUp
+ PUSH BC
+ CALL __OS
+ POP BC
+ LD BC,_asm_DrawStatusBar
+ PUSH BC
+ CALL __OS
+ POP BC
+; 37
+; 38 /* Declare some variable values */
+; 39 strcpy(data.name, "My Data");
+ LD BC,L__1
+ PUSH BC
+ LD BC,_data
+ PUSH BC
+ CALL _strcpy
+ POP BC
+ POP BC
+; 40 data.var1 = VAR1_VALUE;
+ LD A,10
+ LD (_data+15),A
+; 41 data.var2 = VAR2_VALUE;
+ LD A,20
+ LD (_data+16),A
+; 42
+; 43 /* Close any files that may be open already */
+; 44 ti_CloseAll();
+ CALL _ti_CloseAll
+; 45
+; 46 /* Open a new variable; deleting it if it already exists */
+; 47 myAppVar = ti_Open(appvarName, "w");
+ LD BC,L__2
+ PUSH BC
+ LD BC,(_appvarName)
+ PUSH BC
+ CALL _ti_Open
+ POP BC
+ POP BC
+ LD (IX+-1),A
+; 48
+; 49 /* Make sure we opened okay */
+; 50 if (!myAppVar) goto err;
+ OR A,A
+ JR Z,L_3
+; 51
+; 52 /* Write the structure to the appvar */
+; 53 if (ti_Write(&data, sizeof(data_t), 1, myAppVar) != 1) goto err;
+ LD C,(IX+-1)
+ LD B,0
+ PUSH BC
+ LD BC,1
+ PUSH BC
+ LD BC,17
+ PUSH BC
+ LD BC,_data
+ PUSH BC
+ CALL _ti_Write
+ POP BC
+ POP BC
+ POP BC
+ POP BC
+ LD BC,1
+ OR A,A
+ SBC HL,BC
+ JR NZ,L_3
+; 54
+; 55 /* Go back to the start of the file */
+; 56 if (ti_Rewind(myAppVar) == EOF) goto err;
+ LD C,(IX+-1)
+ LD B,0
+ PUSH BC
+ CALL _ti_Rewind
+ POP BC
+ LD BC,16777215
+ OR A,A
+ SBC HL,BC
+ JR Z,L_3
+; 57
+; 58 /* Let's read it just to make sure we wrote it correctly */
+; 59 if (ti_Read(&data, sizeof(data_t), 1, myAppVar) != 1) goto err;
+ LD C,(IX+-1)
+ LD B,0
+ PUSH BC
+ LD BC,1
+ PUSH BC
+ LD BC,17
+ PUSH BC
+ LD BC,_data
+ PUSH BC
+ CALL _ti_Read
+ POP BC
+ POP BC
+ POP BC
+ POP BC
+ LD BC,1
+ OR A,A
+ SBC HL,BC
+ JR NZ,L_3
+; 60
+; 61 /* Make sure we read these variables correctly too */
+; 62 if (data.var1 != VAR1_VALUE && data.var2 != VAR2_VALUE) goto err;
+ LD A,(_data+15)
+ CP A,10
+ JR Z,L_14
+ LD A,(_data+16)
+ CP A,20
+ JR NZ,L_3
+L_14:
+; 63
+; 64 /* Ensure the name of the AppVar is correct */
+; 65 ti_GetName(nameBuffer, myAppVar);
+ LD C,(IX+-1)
+ LD B,0
+ PUSH BC
+ PEA IX+-11
+ CALL _ti_GetName
+ POP BC
+ POP BC
+; 66
+; 67 printText(0, 0, "Appvar: ");
+ LD BC,L__9
+ PUSH BC
+ LD BC,0
+ PUSH BC
+ PUSH BC
+ CALL _printText
+ POP BC
+ POP BC
+ POP BC
+; 68 printText(8, 0, nameBuffer);
+ PEA IX+-11
+ LD BC,0
+ PUSH BC
+ LD BC,8
+ PUSH BC
+ CALL _printText
+ POP BC
+ POP BC
+ POP BC
+; 69 printText(0, 1, "Read was successful");
+ LD BC,L__10
+ PUSH BC
+ LD BC,1
+ PUSH BC
+ LD BC,0
+ PUSH BC
+ CALL _printText
+ POP BC
+ POP BC
+ POP BC
+; 70 goto noerr;
+ JR L_16
+L_3:
+; 71
+; 72 err:
+; 73 printText(0, 0, "An error occured");
+ LD BC,L__11
+ PUSH BC
+ LD BC,0
+ PUSH BC
+ PUSH BC
+ CALL _printText
+ POP BC
+ POP BC
+ POP BC
+; 74 noerr:
+; 75
+; 76 /* Pause */
+; 77 while (!os_GetCSC());
+L_16:
+ CALL _os_GetCSC
+ OR A,A
+ JR Z,L_16
+; 78
+; 79 /* Close all open files */
+; 80 ti_CloseAll();
+ CALL _ti_CloseAll
+; 81 }
+ LD SP,IX
+ POP IX
+ RET
+
+
+;**************************** _main ***************************
+;Name Addr/Register Size Type
+;_os_GetCSC IMPORT ----- function
+;_printText IMPORT ----- function
+;_ti_GetName IMPORT ----- function
+;_ti_Read IMPORT ----- function
+;_ti_Rewind IMPORT ----- function
+;_ti_Write IMPORT ----- function
+;_appvarName STATIC 3 variable
+;_ti_Open IMPORT ----- function
+;_ti_CloseAll IMPORT ----- function
+;_data STATIC 17 variable
+;_strcpy IMPORT ----- function
+;_asm_DrawStatusBar IMPORT ----- function
+;_asm_HomeUp IMPORT ----- function
+;_asm_ClrLCD IMPORT ----- function
+;__OS IMPORT ----- function
+;nameBuffer IX-11 10 variable
+;myAppVar IX-1 1 variable
+
+
+; Stack Frame Size: 17 (bytes)
+; Spill Code: 0 (instruction)
+
+
+ SEGMENT STRSECT
+L__1:
+ DB "My Data"
+ DB 0
+L__2:
+ DB "w"
+ DB 0
+L__9:
+ DB "Appvar: "
+ DB 0
+L__10:
+ DB "Read was successful"
+ DB 0
+L__11:
+ DB "An error occured"
+ DB 0
+ SEGMENT CODE
+; 82
+; 83 /* Draw text on the homescreen at the given X/Y location */
+; 84 void printText(int8_t xpos, int8_t ypos, const char *text) {
+_printText:
+ CALL __frameset0
+; 85 os_SetCursorPos(ypos, xpos);
+ LD C,(IX+6)
+ LD B,0
+ PUSH BC
+ LD C,(IX+9)
+ PUSH BC
+ CALL _os_SetCursorPos
+ POP BC
+ POP BC
+; 86 os_PutStrFull(text);
+ LD BC,(IX+12)
+ PUSH BC
+ CALL _os_PutStrFull
+ POP BC
+; 87 }
+ LD SP,IX
+ POP IX
+ RET
+
+
+;**************************** _printText ***************************
+;Name Addr/Register Size Type
+;_os_PutStrFull IMPORT ----- function
+;_os_SetCursorPos IMPORT ----- function
+;text IX+12 3 parameter
+;ypos IX+9 1 parameter
+;xpos IX+6 1 parameter
+
+
+; Stack Frame Size: 15 (bytes)
+; Spill Code: 0 (instruction)
+
+
+ XREF _strcpy:ROM
+ XREF _ti_GetName:ROM
+ XREF _ti_Rewind:ROM
+ XREF _ti_Read:ROM
+ XREF _ti_Write:ROM
+ XREF _ti_Open:ROM
+ XREF _ti_CloseAll:ROM
+ XREF _asm_DrawStatusBar:ROM
+ XREF _asm_ClrLCD:ROM
+ XREF _asm_HomeUp:ROM
+ XREF __OS:ROM
+ XREF _os_GetCSC:ROM
+ XREF _os_PutStrFull:ROM
+ XREF _os_SetCursorPos:ROM
+ XREF __frameset0:ROM
+ XREF __frameset:ROM
+ XDEF _printText
+ XDEF _main
+ XDEF _data
+ XDEF _appvarName
+ END
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/readme.md b/frontends/calculator/CEdev/examples/fileio_read_write/readme.md
new file mode 100644
index 0000000..8666507
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/readme.md
@@ -0,0 +1,10 @@
+### FileIO Write/Read Demo
+
+This example demonstrates writing some data to a file and then reading it back out to make sure it was written correctly
+
+![Screenshot](screenshot.png)
+
+---
+
+This demo is a part of the C SDK Toolchain for use on the CE.
+
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/screenshot.png b/frontends/calculator/CEdev/examples/fileio_read_write/screenshot.png
new file mode 100644
index 0000000..8f22d44
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/screenshot.png
Binary files differ
diff --git a/frontends/calculator/CEdev/examples/fileio_read_write/src/main.c b/frontends/calculator/CEdev/examples/fileio_read_write/src/main.c
new file mode 100644
index 0000000..a776037
--- /dev/null
+++ b/frontends/calculator/CEdev/examples/fileio_read_write/src/main.c
@@ -0,0 +1,88 @@
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <tice.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fileioc.h>
+
+/* Declare some variables */
+const char *appvarName = "AppVar";
+
+typedef struct {
+ char name[15];
+ uint8_t var1;
+ uint8_t var2;
+} data_t;
+
+data_t data;
+
+#define VAR1_VALUE 10
+#define VAR2_VALUE 20
+
+/* Function prototypes */
+void printText(int8_t xpos, int8_t ypos, const char *text);
+
+/* Main Function */
+void main(void) {
+ char nameBuffer[10];
+ ti_var_t myAppVar;
+ int x;
+
+ /* Clear the homescreen */
+ os_ClrHome();
+
+ /* Declare some variable values */
+ strcpy(data.name, "My Data");
+ data.var1 = VAR1_VALUE;
+ data.var2 = VAR2_VALUE;
+
+ /* Close any files that may be open already */
+ ti_CloseAll();
+
+ /* Open a new variable; deleting it if it already exists */
+ myAppVar = ti_Open(appvarName, "w");
+
+ /* Make sure we opened okay */
+ if (!myAppVar) goto err;
+
+ /* Write the structure to the appvar */
+ if (ti_Write(&data, sizeof(data_t), 1, myAppVar) != 1) goto err;
+
+ /* Go back to the start of the file */
+ if (ti_Rewind(myAppVar) == EOF) goto err;
+
+ /* Let's read it just to make sure we wrote it correctly */
+ if (ti_Read(&data, sizeof(data_t), 1, myAppVar) != 1) goto err;
+
+ /* Make sure we read these variables correctly too */
+ if (data.var1 != VAR1_VALUE && data.var2 != VAR2_VALUE) goto err;
+
+ /* Ensure the name of the AppVar is correct */
+ ti_GetName(nameBuffer, myAppVar);
+
+ printText(0, 0, "Appvar: ");
+ printText(8, 0, nameBuffer);
+ printText(0, 1, "Read was successful");
+ goto noerr;
+
+err:
+ printText(0, 0, "An error occured");
+noerr:
+
+ /* Pause */
+ while (!os_GetCSC());
+
+ /* Close all open files */
+ ti_CloseAll();
+}
+
+/* Draw text on the homescreen at the given X/Y location */
+void printText(int8_t xpos, int8_t ypos, const char *text) {
+ os_SetCursorPos(ypos, xpos);
+ os_PutStrFull(text);
+}
+