- SmartNotes CE
- 25 Apr 2021 02:12:19 pm
- Last edited by randomguy on 27 Apr 2021 06:55:10 pm; edited 1 time in total
So I have been working on a text editor for the TI 84 PCE in ICE recently, and just yesterday I started porting the program to C. I am very new to C, so pardon any n00b mistakes i have made, am making, and might (will) make in the future. Up to this point, I have only been working on the homescreen and file detector/shell (detects appvars starting with "TXT"). Here is a screenshot:
However, when porting the program to C, I encountered a strange error:
I encountered this earlier when programming in ICE but never found what caused it. right now i am using gfx_SetDraw(1) and gfx_SwapDraw() in a while loop.
Code:
Thank you in advance for any help I receive!
Edit: Jacobly reminded me to put gfx_Begin(); and it worked.

However, when porting the program to C, I encountered a strange error:

I encountered this earlier when programming in ICE but never found what caused it. right now i am using gfx_SetDraw(1) and gfx_SwapDraw() in a while loop.
Code:
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <keypadc.h>
#include <compression.h>
#include <graphx.h>
#include <fileioc.h>
/*necessary information
-3 modes
mode 1 = homescreen
mode 2 = editor
mode 3 = settings
-3 txt modes
mode 1=Caps
mode 2 = math
mode 3 = lowercase
*/
/* functon prototypes */
//char * input_string(char*, char*, uint8_t, uint8_t, uint8_t);
void exitFull();
void handleKeyPresses();
void dispButtons(uint8_t);
void dispFiles();
uint8_t waitForGetKey();
void archiveAll();
/* main loop */
int main() {
gfx_Begin();
kb_SetMode(MODE_3_CONTINUOUS);
uint8_t mode = 1; // 3 modes are homescreen, editor, and settings. DIFFERENT from txtMode
// main homescreen loop. displays files, options, etc...
while(1) {
uint8_t numFiles = 0; // total number of files detected
uint8_t numFilesShown = 0; // number of files currently shown on screen. can't be more than 10
uint8_t fileSlot; // slot of currently detected file
uint8_t numFile = 0; // number of currently detected file
uint8_t fileY = 61; // y coord for currently detected file
char * fileName; // pointer to name of currently detected file
int fileSize = 0; // size of currently detected file
uint8_t selectedNum = 0; // number of currently selected file
char * selectedName; // pointer to name of selected file
gfx_SetDraw(1);
// SCREEN SETUP
gfx_FillScreen(149);
gfx_SetColor(0);
gfx_Rectangle(50,1,222,30);
gfx_Rectangle_NoClip(35,55,250,152);
gfx_SetColor(255);
gfx_FillRectangle_NoClip(36,56,248,150);
gfx_SetTextFGColor(0);
gfx_PrintStringXY("SMARTNOTES CE",115,5);
gfx_PrintStringXY("VERSION 1.0 BY JOHNPAUL MALLOY",55,20);
gfx_PrintStringXY("NAME",40,45);
gfx_PrintStringXY("SIZE",135,45);
gfx_PrintStringXY("STATUS",210,45);
// displays the button options (delete, rename, settings, open, etc...)
// dispButtons(mode);
// close all open slots
ti_CloseAll();
// vat offset for appvar detection loop
void *search_pos = NULL;
// loop to detect and display files
while (((fileName = ti_Detect(&search_pos, "TXT")) != NULL) && (numFilesShown<10)) {
// get file info, archive all text file appvars detected et cetera...
fileSlot = ti_Open(fileName,"r");
fileSize = ti_GetSize(fileSlot);
ti_SetArchiveStatus(1,fileSlot);
// display currently selected file with highlighting rect
if (selectedNum == numFile) {
// check if should be deleted
gfx_SetColor(0);
gfx_FillRectangle_NoClip(35,fileY-5,250,15);
gfx_SetTextFGColor(149);
} else {
gfx_SetTextFGColor(0);
}
// display detected file name & size
gfx_PrintStringXY(fileName,40,fileY);
gfx_SetTextXY(135,fileY);
gfx_PrintInt(fileSize,4);
// update search-dependant vars
numFiles++;
numFile++;
numFilesShown++;
fileY += 15;
}
// display when no appvars are found
if (numFiles == 0) {
gfx_SetTextFGColor(244);
gfx_PrintStringXY("--NO FILES FOUND--",93,80);
}
/*
// move selected down
if ((getKey(1)) and (SELECTED<9) and (SELECTED<NUMBER-1))
SELECTED+1->SELECTED
}
// move selected up
if getKey(4) and (SELECTED>0)
SELECTED-1->SELECTED
End
// button functions(new file, etc...)
// create new file
If getKey(50
Call NEW
FillScreen(0
End
// delete selected file (name = os_Str1)
If getKey(51
Call DELETE
End
*/
kb_Scan();
// move selected down
if((kb_IsDown(kb_KeyDown)) && (selectedNum < numFiles)) {
selectedNum++;
} else if((kb_IsDown(kb_KeyUp)) && (selectedNum > 1)) {
selectedNum--;
} else if((kb_IsDown(kb_KeyClear))) {
exitFull();
} else if((kb_IsDown(kb_KeyZoom) && (numFiles >0))) {
ti_Delete(selectedName);
} else {
gfx_Blit(1);
}
gfx_SwapDraw();
}
}
// string input needs work. like a lot of work.
/*
char * input_string(uint8_t min_len, uint8_t max_len, uint8_t x, uint8_t y) {
while(1) {
}
return string;
}
*/
void dispFiles()
{
uint8_t numFiles = 0; //total number of files detected
uint8_t numFilesShown = 0; //number of files currently shown on screen. can't be more than 10
uint8_t fileSlot; //slot of currently detected file
uint8_t fileNum = 0; //number of currently detected file
uint8_t fileY = 61; //y coord for currently detected file to be displayed at
char * fileName; //pointer to name of currently detected file
int fileSize; //size of currently detected file
uint8_t selectedNum = 0; //number of currently selected file
char * selectedName; //pointer to name of selected file
void *search_pos = 0;
//loop to detect and display files
while (((fileName = ti_Detect(&search_pos, "TXT")) != NULL) && (numFilesShown<10)) {
//have to do this before calling any file IO functions
ti_CloseAll();
//get file info...
fileSlot = ti_Open(fileName,"r");
ti_SetArchiveStatus(1,fileSlot);
//display currently selected file with highlighting rect
if (selectedNum == fileNum){
selectedName = fileName;
gfx_SetColor(0);
gfx_FillRectangle_NoClip(35,fileY-5,250,15);
gfx_SetTextFGColor(149);
} else {
gfx_SetTextFGColor(0);
}
//display detected file name & size
gfx_PrintStringXY(fileName,40,fileY);
gfx_SetTextXY(135,fileY);
gfx_PrintInt(ti_GetSize(fileSlot),4);
//update search-dependant vars
numFiles++;
fileY += 15;
}
}
void dispButtons(uint8_t mode)
{
int i = 0;
if(mode == 1) {
//button rects at bottom of screen
for(i=0; i<320; i=i+64) {
gfx_SetColor(0);
gfx_Rectangle_NoClip(i,220,62,19);
gfx_SetColor(42);
gfx_FillRectangle_NoClip(i+1,221,60,17);
}
//button text
gfx_SetTextFGColor(0);
gfx_PrintStringXY("Open",16,227);
gfx_PrintStringXY("Rename",73,227);
gfx_PrintStringXY("Delete",137,227);
gfx_PrintStringXY("New",211,227);
gfx_PrintStringXY("Other",270,227);
}
};
void handleKeyPresses(int mode)
{
}
void archiveAll()
{
uint8_t fileSlot;
char * fileName;
int search_pos = NULL;
while (((fileName = ti_Detect(&search_pos, "TXT")) != NULL)) {
fileSlot = ti_Open(fileName, "r");
ti_SetArchiveStatus(1, fileSlot);
}
ti_CloseAll();
}
void exitFull() {
archiveAll();
gfx_End();
abort();
};
Thank you in advance for any help I receive!
Edit: Jacobly reminded me to put gfx_Begin(); and it worked.