Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - lkj

Pages: [1] 2
1
TI-Nspire / nAssembler - Nspire on-calc assembler
« on: March 11, 2015, 01:41:14 pm »
As the title suggests, this is an on-calc assembler for the Nspire :)
It's written in python, so you need micropython on your calc.
All instructions I'm aware of are supported (except CDP, LDC, STC. They are useless on the Nspire)
What's still missing are some pseudoinstructions which don't add functionality but make your life easier,
like for example automatically creating x when you write LDR R0, =x
There is also no linker or anything which means that programs are just translated to binary in the order
they are written and the first line is also the entry point.
Read the readme in the spoiler below for more details on the assembly language syntax used or look at the example.


Please report bugs, missing instructions and feature suggestions.
The code is available at https://github.com/lkjcalc/nAssembler

Download from tiplanet archives: https://tiplanet.org/forum/archives_voir.php?id=821835


Spoiler For Readme:
Usage
-----
Install micropython on your calc.
Launch the nassembler.py.tns file using micropython.
The program will ask you to specify the input file (containing the assembly source code)
and the output file (where the binary will be stored).
You have to specify the full path (for example /documents/test/clrscr.asm.tns)
If there are no errors, micropython will now tell you "Press any key to exit".
You should now see the output file after refreshing the docbrowser
(just go to the homescreen and back to the docbrowser).

Assembly language
-----------------
(Also look at the examples)
IMPORTANT (syntax is not very flexible at the moment):
-Instruction names must be preceded by whitespace
-Labels must not be preceded by any whitespace
-The instruction names and syntax are like in standard ARM assembly
(like in the official ARM online documentation)
-No automatic substitution of e.g. MVN for MOV if the immediate value can only be encoded in the inverted case
-Two operands were three are required is not allowed (no implicit destination register), e.g. "ADD r0,#28" must be written out as "ADD r0,r0,#28"

All usual instructions are supported:
ADC(S), ADD(S), AND(S), B, BIC(S), BL, BX, CLZ, CMP, CMN,
EOR(S), LDM.., LDR(B/T/BT/H/SH/SB), MCR, MLA(S), MOV(S),
MRC, MRS, MSR, MUL(S), MVN(S), ORR(S),
RSB(S), RSC(S), SBC(S), SMLAL(S), SMULL(S), STM..,
STR(B/T/BT/H), SUB(S), SVC/SWI, SWP(B), TEQ, TST, UMLAL(S), UMULL(S)

The DCD, DCDU, DCW, DCWU, DCB and ALIGN directives are supported.

The ADR pseudo instruction is now also implemented.

Some other pseudo instruction (like PUSH etc) are not implemented.
Other instructions may be missing (report if you need one).

The first line of the source is also the entry point of the program.

Numeric literals:
Prefix with 0x for hexadecimal numbers, 0 for octal, 0b for binary.
Single characters enclosed in single quotes ' are interpreted as their ascii value
You can use DCB "some string" to create a string.

Feature suggestions/Bug reports
--------------------------------------------
Here or in the following places:
Topic on tiplanet: https://tiplanet.org/forum/viewtopic.php?t=16174&p=178789
Code on github: https://github.com/lkjcalc/nAssembler

2
Other / Planning on buying a Samsung Galaxy Note 3
« on: December 23, 2013, 03:21:52 pm »
My old phone (iphone 3gs) has many problems so I'm looking for a new phone. It mustn't be from Apple and should have a big screen so that it's comfortable to code on it. The battery life should also be not too bad. I was thinking about the Note 2 because of its big screen and good reviews, and now about its successor. The mainstream public seems to like the Note 3 very much, but I also heard two bad things about it. First, the region lock. I don't care about it myself, but it's a bit of a unfriendly move like Apple would do. And second, I read that you could break it by rooting because of some hardware protection, which would be a reason for me not to buy it.

So yeah, would you recommend buying it?

3
General Calculator Help / Semi-broken Nspire Touchpad calculator
« on: August 15, 2013, 10:44:18 am »
I have a TI Nspire CAS Touchpad calculator which sometimes works normally but sometimes seems like it's dead (doesn't do anything when ON is pressed). Sometimes the calculator also makes strange noises instead of starting up when I switch it on, but after removing a battery it works normally again.
The keypad and the battery aren't the problem, I already changed them.

Attached is a recording of the noise it sometimes makes.

Does anyone have an idea if I can somehow fix it, or what is broken?

4
Site Feedback and Questions / Forum search broken?
« on: March 16, 2013, 11:40:43 am »
Today I tried to search the forum, but I got an error "You are not allowed to search for posts in this forum. "
Is it just intentionally disabled or did it break?

5
Calculator C / Weird stat() error
« on: December 26, 2012, 11:20:05 am »
I'm writing a file browser and use this piece of code to find out if something is a directory:
Code: [Select]
int is_dir(const char *path) {
struct stat filestat;
stat(path, &filestat);
printf("%s %i", path, filestat.st_mode);
return S_ISDIR(filestat.st_mode);
}

".." is reported as a directory in every directory except from /documents/, which most probably means in every directory in which ".." isn't the root directory. So I looked at hofa's code and saw he didn't handle this case separately and it still works in the prebuilt tns. But when I recompile his code, it doesn't work, either.

Do I have to write a workaround or is something wrong with my ndless, as the code apparently worked with an older revision?

Edit: sometimes it works, but most of the time not  ???

Edit2: it sometimes doesn't work for other folders, either

Spoiler For my filebrowser code:
Code: [Select]
#include <os.h>
#include "filebrowser.h"
#include "output.h"
#include "menu.h"

#define DIR_HEIGHT (CHAR_HEIGHT + 10)
#define DIR_DIRLIST_DIST CHAR_HEIGHT
#define FILENAME_WIDTH 200
#define FILEDATE_WIDTH 0
#define FILESIZE_WIDTH (SCREEN_WIDTH - FILENAME_WIDTH - FILEDATE_WIDTH)

#define FILES_SHOWN ((SCREEN_HEIGHT - DIR_HEIGHT) / CHAR_HEIGHT)

#define MENU_SELECTION_COLOR (has_colors?0b011101111111111:0x0)

//TODO: display long directory names correctly

//some parts are adapted from hoffa's code

int is_dir(const char *path) {
struct stat filestat;
stat(path, &filestat);
printf("%s %i", path, filestat.st_mode);
return S_ISDIR(filestat.st_mode);
}

void get_filesize(const char *path, char* buffer){
    struct stat filestat;
    stat(path, &filestat);
    int size = filestat.st_size;
    const char units[4][3] = {"B\0", "kB\0", "MB\0", "GB\0"};
    int i = 0;
    while (size >= 1024) {
        size /= 1024;
        ++i;
    }
    sprintf(buffer, "%d%s", size + 1, units[i]);
}

int get_filenames(const char* folder, char** result){
    DIR* dp;
    struct dirent* entryp;
    int i = 0;
    if((dp = opendir(folder)) == NULL){
        printf("opendir error\n");
        return 1;
    }
    while((entryp = readdir(dp)) != NULL){
        char* dirname = (char*) malloc(strlen(entryp->d_name)+1);
        strcpy(dirname, entryp->d_name);
        result[i] = dirname;
        i++;
    }
    return i;
}

int filebrowser(uint8_t* scrbuf, char* file){
    char currentdir[FILENAME_MAX];
    char* filenames[1024];
    int num_files;
    int filescroll = 0;
    int fileselected = 0;
    int i;
    NU_Current_Dir("A:", currentdir);
    num_files = get_filenames(currentdir, filenames);
    while(1){
        //disp:
        memset(scrbuf, 0xFF, SCREEN_BYTES_SIZE);
        dispHorizLine(scrbuf, 0, DIR_HEIGHT-1, 320, 0);
        dispString(scrbuf, 4, (DIR_HEIGHT-CHAR_HEIGHT)/2, currentdir);
        for(i = filescroll; i < filescroll + FILES_SHOWN && i < num_files; i++){

            //disp file symbol
            if(is_dir(filenames[i]) && strcmp(filenames[i], ".") && strcmp(filenames[i], ".."))
                putChar(scrbuf, CHAR_WIDTH*2, DIR_HEIGHT+DIR_DIRLIST_DIST+(i-filescroll)*CHAR_HEIGHT, '\\');
            //disp filename, filesize and selection
            if(i != fileselected){
                dispString(scrbuf, CHAR_WIDTH*3, DIR_HEIGHT+DIR_DIRLIST_DIST+(i-filescroll)*CHAR_HEIGHT, filenames[i]);
                if(!is_dir(filenames[i])){
                    char size[10];
                    get_filesize(filenames[i], size);
                    dispString(scrbuf, FILENAME_WIDTH, DIR_HEIGHT+DIR_DIRLIST_DIST+(i-filescroll)*CHAR_HEIGHT, size);
                }
            }
            else{
                filledRect(scrbuf, CHAR_WIDTH*3, DIR_HEIGHT+DIR_DIRLIST_DIST+(i-filescroll)*CHAR_HEIGHT-1, SCREEN_WIDTH - CHAR_WIDTH*4, CHAR_HEIGHT+2, MENU_SELECTION_COLOR);
                dispStringColor(scrbuf, CHAR_WIDTH*3, DIR_HEIGHT+DIR_DIRLIST_DIST+(i-filescroll)*CHAR_HEIGHT, filenames[i], has_colors?0xFFFF:0xF, MENU_SELECTION_COLOR);
                if(!is_dir(filenames[i])){
                    char size[10];
                    get_filesize(filenames[i], size);
                    dispStringColor(scrbuf, FILENAME_WIDTH, DIR_HEIGHT+DIR_DIRLIST_DIST+(i-filescroll)*CHAR_HEIGHT, size, has_colors ? 0xFFFF : 0xF, MENU_SELECTION_COLOR);
                }
            }

        }
        memcpy(SCREEN_BASE_ADDRESS, scrbuf, SCREEN_BYTES_SIZE);

        //input:
        if(isKeyPressed(KEY_NSPIRE_ESC))
            break;
        if(isKeyPressed(KEY_NSPIRE_ENTER)){
            if(is_dir(filenames[fileselected])){
                chdir(filenames[fileselected]);
                filescroll = 0;
                fileselected = 0;
                NU_Current_Dir("A:", currentdir);
                for(i = 0; i < num_files; i++)
                    free(filenames[i]);
                num_files = get_filenames(currentdir, filenames);
            }
            else{
                strcpy(file, filenames[fileselected]);
                for(i = 0; i < num_files; i++)
                    free(filenames[i]);
                return 0;
            }
        }
        if(isKeyPressed(KEY_NSPIRE_UP)){
            fileselected--;
            if(fileselected < 0){
                fileselected = num_files - 1;
                filescroll = num_files - FILES_SHOWN;
                if(filescroll < 0)
                    filescroll = 0;
            }
            else if(fileselected - filescroll <  0)
                filescroll--;
        }
        if(isKeyPressed(KEY_NSPIRE_DOWN)){
            fileselected++;
            if(fileselected >= num_files){
                fileselected = 0;
                filescroll = 0;
            }
            else if(fileselected - filescroll >= FILES_SHOWN)
                ++filescroll;
        }
        sleep(100);
    }
    for(i = 0; i < num_files; i++)
        free(filenames[i]);
    return 1;
}

6
TI-Nspire / nTxt - Nspire Text Editor
« on: October 10, 2012, 01:37:13 pm »
nTxt is a text editor for the Nspire. It requires Ndless to be installed on your calculator.

Some of its features:
- open/save files anywhere in the file system
- cut, copy & paste
- search
- various navigation commands (page up/down etc)
See the readme for a more detailed description.

Tell me what you think and if you have suggestions for improvement  :)

The code is on github: https://github.com/lkjcalc/nTxt
 
Latest download also on github: https://github.com/lkjcalc/nTxt/releases


Spoiler For original 1st post:
I'm working on a new text editor for the Nspire because I never really understood how to use the existing one and it isn't being worked on anymore.

It's already working on both cx and b/w, and you can
- write almost all characters
- delete characters
- navigate with the left/right arrow keys
- save your file anywhere in the filesystem

I will surely add
- opening files
- navigating with up/down arrows
- menus

7
Calculator C / How can I use a static library?
« on: August 30, 2012, 04:53:05 pm »
I'm trying to use fdlibm which hoffa ported, but I get
Code: [Select]
nspire-ld -L ../../../.ndless/lib -lfdm sound.o output.o -o sound.elf
sound.o: In function `playKey':
sound.c:(.text+0xc4): undefined reference to `pow'
collect2.exe: error: ld returned 1 exit status
make: *** [sound.tns] Error 1

with
GCCFLAGS = -I ../../../.ndless/include -Os -Wall -W
LDFLAGS = -L ../../../.ndless/lib -lfdm

What am I doing wrong?

8
TI-Nspire / [contest] Pacman
« on: July 08, 2012, 06:04:51 pm »
I know it isn't really playable on calc, unfortunately I have only tested it on the emulator before entering, and made the speed so that it's good there :(

When will it be allowed to release an updated version? After the voting?

9
Computer Programming / bytes, strings bytearrays???
« on: March 16, 2012, 06:32:09 pm »
I really don't get why this python 3.2 code doesn't work:
Code: [Select]
file = open("evil2.gfx","rb")
tmp = bytearray(file.read())
file.close()
tmp1 = b''
tmp2 = b''
tmp3 = b''
tmp4 = b''
tmp5 = b''
result = b''
for i in range(0,len(tmp)):
    if i%5 == 0:
        tmp1 += bytes(tmp[i])
    elif i%5 == 1:
        tmp2 += bytes(tmp[i])
    elif i%5 == 2:
        tmp3 += bytes(tmp[i])
    elif i%5 == 3:
        tmp4 += bytes(tmp[i])
    elif i%5 == 4:
        tmp5 += bytes(tmp[i])

I really don't understand why I can't add a single byte from a bytestring to a bytestring without typecasting, and if I try to convert it like above with bytes() I get very long bytestrings only containing null ???
Is the typesystem of Python really that much more difficult than that of C or do I just not understand it yet?

10
TI-Nspire / Line Runner for Nspire
« on: February 12, 2012, 02:28:45 pm »
I'm writing a clone of the iphone game Line Runner. It works but I'll need to implement and improve a lot of things, for example better graphics. The CX isn't supported yet because I don't have one to test and I didn't have time to read everything about how to use the ndless functions for this.

Does anyone know why the nspire emulator gets a totally different speed if I use idle()? And even more different if I let the fast timer run? On calc it's too fast and on emulator it's so slow you can't play.

newest version

11
Other Calculators / How did you attach the rs232 wires?
« on: January 30, 2012, 07:28:24 pm »
To all those who succeeded at using the dock connector for sound or rs232: What did you do that the wires don't slip out (don't know if that's the right word)?
Because I'm trying but it doesn't work.

12
Calculator C / program to convert bmp into Nspire c-arrays?
« on: January 30, 2012, 07:52:15 am »
I've been looking for a program which converts .bmp files into c-arrays which are for the nspire (not for the z80 calcs), that means with 4 bits per pixel. But I've only found z80 and 68k programs which even don't work on a recent pc.
So I asked myself if every one who has made games for the nspire has written every sprite by hand?

13
Calculator C / Is there a ftell syscall?
« on: January 15, 2012, 01:22:11 pm »
Am I right that there's no ftell syscall in ndless2?
If yes, is there one that we know but that is only not built in in ndless? Or what can I do instead of using ftell to get a similar result?

14
Computer Programming / Best language for beginners?
« on: January 12, 2012, 03:16:30 pm »
What do you think? What's best to start for someone who doesn't know anything about programming?

15
Calculator C / create files?
« on: December 03, 2011, 03:41:56 pm »
Can you create new files in a C program with ndless? And if yes, how?
Or can you just use fopen() in "w"-mode? I tried this but I'm not sure if I used it correctly.

Pages: [1] 2