Would you use SmartNotes CE when I finish it?
Yes
 23%  [ 3 ]
No
 15%  [ 2 ]
If you finish...
 61%  [ 8 ]
Total Votes : 13

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:

#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.
Here is the Github Repo: https://github.com/randomguy70/SmartNotesCE
I have only been coding in C for a few weeks, so please please tell me if I should format anything differently, or if I am making any n00b mistakes!
Thank you in advance!
I was asked about getting GetCSC scan codes using keypadc, so here you go:
Code:
uint8_t get_single_key_pressed(void) {
    static uint8_t last_key;
    uint8_t only_key = 0;
    kb_Scan();
    for (uint8_t key = 1, group = 7; group; --group) {
        for (uint8_t mask = 1; mask; mask <<= 1, ++key) {
            if (kb_Data[group] & mask) {
                if (only_key) {
                    last_key = 0;
                    return 0;
                } else {
                    only_key = key;
                }
            }
        }
    }
    if (only_key == last_key) {
        return 0;
    }
    last_key = only_key;
    return only_key;
}
progress update: i gave up on using appvar text data files, and am using some simple hexadecimal character arrays instead. now the input text function works. this is the first time in a while I have been able to work on this at all Smile.
Congrats Smile, on finishing the input routine.
Okay, so apparently this code is not working; it is supposed to copy the pointers to the names of every txt appvar to an array of string pointers.

Code:

uint8_t loadFileNames(char **buffer) {
   uint8_t numFiles = 0;
   char *namePtr;
   void *search_pos = NULL;

   while ((namePtr = ti_Detect(&search_pos, "TXT")) != NULL) {
      uint8_t i = 0;
      while(namePtr[i]!='\0'){
         buffer[numFiles][i] = namePtr[i];
         i++;
      }
      numFiles++;
   }
   return numFiles;
}

char fileNames[20][9] = {0};
loadFileNames(fileNames);

thank you in advance1 Very Happy

Edit:
Jacobly helped me to fix it.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement