Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************/
- /* */
- /* CASIO fx-9860G SDK Library */
- /* */
- /* File name : [ProjectName].c */
- /* */
- /* Copyright (c) 2006 CASIO COMPUTER CO., LTD. */
- /* */
- /*****************************************************************/
- #include "fxlib.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include "MonochromeLib.h"
- #include "fonts.h"
- #define SCROLL 8 //number of pixels to scroll at each press of the up/down key
- unsigned long posY[2]; //array holding the scroll for each view, so that if the user comes back from a comment page, he keeps his scroll position on the post page
- unsigned int key;
- unsigned int postHeights[26];
- char currentView = 1; //0=post, 1=comment
- const char strCmt[] = "<t This is the text post kek.> <1 Another top lvl comment > <1 Top lvl comment, with word wrap > <2 Second level comment with word wrap> <3 Third level comment with word wrap too> <4 Top-level comment that is very long like verrry long daufq> <2 Another second lvl comment>";
- const char str[] = "<r /r/SandersForPresident> <p t=This is the first post.\" a=(ext.link) r/sandersforpresident u/Zezombye 45 upvotes\"> <p t=This is the title of the second post! Gotta make it long though so that I have to scroll.\" a=(self) r/askreddit u/lephenixnoirk\"> <p t=the quick brown fox jumps over the lazy dog\nTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!!! (why are we yelling?)\" a=goddammit test\"> <p t=Fourth post\" a=.\"";
- void dispPost(char* str, int strlen);
- void getPost(unsigned long posY);
- void dispCmt(char* str, int strlen);
- int AddIn_main(int isAppli, unsigned short OptionNum)
- {
- while(1) {
- ML_clear_vram();
- //displays the current view
- if (currentView == 0)
- dispPost(str, sizeof(str));
- else
- dispCmt(strCmt, sizeof(strCmt));
- ML_pixel(127,31,1); //debug pixel, used to test the "hitbox" of posts
- GetKey(&key);
- if (key == KEY_CTRL_DOWN || key == KEY_CTRL_UP) {
- if (key == KEY_CTRL_DOWN)
- posY[currentView] += SCROLL;
- else if (posY[currentView] >= SCROLL)
- posY[currentView] -= SCROLL;
- }
- if (key == KEY_CTRL_EXE && currentView == 0) {
- getPost(posY[0]);
- }
- }
- return 1;
- }
- void getPost(unsigned long posY) {
- int height = 12;
- int rankOfPost = 0;
- while (1) {
- height += postHeights[rankOfPost]+3;
- if (height > posY+33) {
- ML_clear_vram();
- currentView = 1;
- if (rankOfPost == 2) dispCmt(strCmt, sizeof(strCmt));
- break;
- }
- if (rankOfPost > 25)
- break;
- rankOfPost++;
- }
- GetKey(&key);
- }
- void dispCmt(char* str, int strlen) {
- int i;
- int currentPageHeight = 0;
- for (i = 0; i < strlen; i++) {
- if (str[i] == '<') {
- if (str[i+1] == 't') { //it is the post
- int j = i+3;
- int k = 0;
- char post[30100];
- while (str[j] != '>') { //stocks the text of the post
- post[k] = str[j];
- k++;
- j++;
- }
- currentPageHeight += dispStr(post, normfont, 0, currentPageHeight-posY[1], k); //increases the page height and displays it
- ML_horizontal_line(currentPageHeight-posY[1], 0, 127, 1); //draws a line after the post
- currentPageHeight += 3;
- i = j;
- }
- if (str[i+1] >= '1' && str[i+1] <= '9') { //it is a comment
- int j = i+3;
- int k = 0;
- char comment[2000];
- int heightOfComment;
- while (str[j] != '>') {
- comment[k] = str[j];
- k++;
- j++;
- }
- heightOfComment = dispStr(comment, normfont, 2*(str[i+1]-49), currentPageHeight-posY[1], k);
- for (k = 0; k < 2*(str[i+1]-49); k+=2) {
- ML_vertical_line(k, currentPageHeight-2-posY[1], currentPageHeight+heightOfComment+4-posY[1], 1);
- }
- //if (k > 2) ML_vertical_line(k, currentPageHeight-posY[1], currentPageHeight+heightOfComment+4-posY[1], 1);
- currentPageHeight += heightOfComment+7;
- i = j;
- }
- }
- }
- }
- //interprets the html and the tags
- void dispPost(char* str, int strlen) {
- int i;
- int currentPostRank = 0;
- int currentPageHeight = 13;
- ML_horizontal_line(0-posY[0], 0, 127, 1);
- ML_horizontal_line(10-posY[0], 0, 127, 1);
- for (i = 0; i < strlen; i++) {
- if (str[i] == '<') {
- if (str[i+1] == 'p') { //it is a post
- int j = i+2;
- int heightOfPost = 0;
- while (str[j] != '>') { //as long as the post tag doesn't end
- while (str[j] == ' ') //loops through the next attribute
- j++;
- if (str[j] == 't') { //title attribute
- char title[330]; //because f* dynamic allocation, max title size is 300 characters
- int k = 0;
- int strlen = sizeof(title);
- j+=2;
- while (str[j] != '"') {
- title[k] = str[j];
- k++;
- j++;
- }
- heightOfPost += dispStr(title, normfont, 0, currentPageHeight-posY[0], k) + 7;
- j++;
- }
- if (str[j] == 'a') {
- char attributes[64];
- int k = 0;
- int strlen = sizeof(attributes);
- int test;
- j+=2;
- while (str[j] != '"') {
- attributes[k] = str[j];
- k++;
- j++;
- }
- test = dispStr(attributes, normfont, 0, (currentPageHeight+heightOfPost)-posY[0], k);
- heightOfPost += test + 4;
- j++;
- }
- if (str[j] != ' ' && str[j] != 't' && str[j] != 'a' && str[j] != 's') {
- break;
- }
- }
- heightOfPost += 4;
- postHeights[currentPostRank] = heightOfPost;
- if (heightOfPost == 4)
- postHeights[currentPostRank] = 0; //else, non-existant posts will have a height of 4
- ML_horizontal_line(currentPageHeight+postHeights[currentPostRank]-1-posY[0], 0, 127, 1);
- currentPageHeight += postHeights[currentPostRank]+3;
- currentPostRank++;
- i = j;
- }
- if (str[i+1] == 'r') {
- int j = i+3;
- int k = 0;
- int l;
- int subLength = 0;
- char subreddit[64];
- while (str[j] != '>') {
- subreddit[k] = str[j];
- k++;
- j++;
- }
- for (l = 0; l < k; l++)
- subLength += normfont.length[subreddit[l]-32] +1;
- dispStr(subreddit, normfont, 65-(subLength/2), 3-posY[0], k);
- }
- }
- }
- }
- //displays a given string, using a given font, at the given coordinates
- //returns the height of the string
- int dispStr(char* str, struct Font font, int x2, int y, int strlen) {
- int k;
- int x = x2;
- int y2 = y;
- for (k=0; k < strlen; k++) { //browses through the given string
- //word wrap: if the current character isn't a space, simply display it
- if (str[k] != 32 && str[k] != '\0' && str[k] != '\n') {
- //if (option = 1) {
- long j = 1 << (6*font.length[str[k]-32])-1; //initializes a long for bit checking. The long is equal to 0b10000.. with number of zeroes being the maximum length of the character, minus 1 because there's already a 1.
- char i;
- for (i = 0; i < 6*font.length[str[k]-32]; i++) { //browses through the pixels of the character specified, shifting the 1 of j to the right each time, so that it makes 0b01000.., 0b001000... etc
- if (font.ltr[str[k]-32] & (j >> i)) { //checks if the bit that is a 1 in the j is also a 1 in the character
- ML_pixel(x+i%(font.length[str[k]-32]), y+i/font.length[str[k]-32], 1); //if so, locates the pixel at the coordinates, using modulo and division to calculate the coordinates relative to the top left of the character
- }
- }
- //}
- x += font.length[str[k]-32] + 1; //now that the character has been fully displayed, shifts the cursor right by the length of character + 1
- } else if (str[k] == '\n') {
- y += 8;
- x = x2;
- } else if (str[k] == ' ') { //the current character is a space, so see if it manages to display the word without going over x=128
- int i = x+4; //initializes an int to count the number of total pixels the next word takes
- int j = k+1; //initializes the char to the current char+1 (which is always another character)
- while (str[j] != 32 && str[j] != '\0') { //as long as it doesn't encounter another space or end of string
- i += font.length[str[j]-32]+1; //it increments i by the length of the character + 1
- j++;
- }
- if (i > 128) { //the word can't be displayed, note that it is STRICTLY superior because we added an unnecessary pixel at the end
- y += 8; //goes on next line which is 8 pixels down
- x = x2; //puts cursor on beginning of line
- } else {
- x += 4;
- }
- }
- }
- return y+1-y2;
- }
- //****************************************************************************
- //************** ****************
- //************** Notice! ****************
- //************** ****************
- //************** Please do not change the following source. ****************
- //************** ****************
- //****************************************************************************
- #pragma section _BR_Size
- unsigned long BR_Size;
- #pragma section
- #pragma section _TOP
- //****************************************************************************
- // InitializeSystem
- //
- // param : isAppli : 1 = Application / 0 = eActivity
- // OptionNum : Option Number (only eActivity)
- //
- // retval : 1 = No error / 0 = Error
- //
- //****************************************************************************
- int InitializeSystem(int isAppli, unsigned short OptionNum)
- {
- return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
- }
- #pragma section
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement