Author Topic: [ARM/Nspire] Inserting a new line in text  (Read 4078 times)

0 Members and 1 Guest are viewing this topic.

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
[ARM/Nspire] Inserting a new line in text
« on: August 20, 2013, 04:38:12 pm »
I've been trying to have some sort of text input with ARM now but I've hit a wall at this point. I've implemented enter/newline continuing at the same x position and also managed to get it back to the start of the line.
The problem I have is incorporating the delete/backspace functionality. The code below shows how I imagined it to go, but this makes enter act all funky and weird, offsetting the letters from the right by the amount of characters deleted.
When uncommenting the commented code in delkey the program will not even build, resulting in an error message "149: Error: invalid constant (408) after fixup".

Code:
Code: [Select]
#include <os.h>
 
main: .global main
@ setup
push {r4-r11, lr}
bl lcd_ingray
bl clrscr
mov r11, #0
keycheck:
ldr r10, =0xC0000010
ldr r10, [r10]
add r10, r11
  
@ check for keypresses
ldr r0, =0x900E0010
  
ldrh r1, [r0, #8]
@ a key
tst r1, #1 << 6
adrne r0, letter_a
bne draw
  
@ b key
tst r1, #1 << 5
adrne r0, letter_b
bne draw
  
@ c key
tst r1, #1 << 4
adrne r0, letter_c
bne draw
  
@ d key
tst r1, #1 << 2
adrne r0, letter_d
bne draw
  
@ e key
tst r1, #1 << 1
adrne r0, letter_e
bne draw
  
@ f key
tst r1, #1 << 0
adrne r0, letter_f
bne draw
  
ldrh r1, [r0, #6]
@ g key
tst r1, #1 << 6
adrne r0, letter_g
bne draw
  
@ h key
tst r1, #1 << 5
adrne r0, letter_h
bne draw
  
@ i key
tst r1, #1 << 4
adrne r0, letter_i
bne draw
  
@ j key
tst r1, #1 << 2
adrne r0, letter_j
bne draw
  
@ k key
tst r1, #1 << 1
adrne r0, letter_k
bne draw
  
@ l key
tst r1, #1 << 0
adrne r0, letter_l
bne draw
  
ldrh r1, [r0, #4]
@ m key
tst r1, #1 << 6
adrne r0, letter_m
bne draw
  
@ n key
tst r1, #1 << 5
adrne r0, letter_n
bne draw
  
@ o key
tst r1, #1 << 4
adrne r0, letter_o
bne draw
  
@ p key
tst r1, #1 << 2
adrne r0, letter_p
bne draw
  
@ q key
tst r1, #1 << 1
adrne r0, letter_q
bne draw
  
@ r key
tst r1, #1 << 0
adrne r0, letter_r
bne draw
  
ldrh r1, [r0, #2]
@ s key
tst r1, #1 << 6
adrne r0, letter_s
bne draw
  
@ t key
tst r1, #1 << 5
adrne r0, letter_t
bne draw
  
@ u key
tst r1, #1 << 4
adrne r0, letter_u
bne draw
  
@ v key
tst r1, #1 << 2
adrne r0, letter_v
bne draw
  
@ w key
tst r1, #1 << 1
adrne r0, letter_w
bne draw
  
@ x key
tst r1, #1 << 0
adrne r0, letter_x
bne draw

ldrh r1, [r0, #0]
@ y key
tst r1, #1 << 6
adrne r0, letter_y
bne draw
  
@ z key
tst r1, #1 << 5
adrne r0, letter_z
bne draw

@ special keys
@ space key
ldrh r1, [r0, #0]
tst r1, #1 << 4
bne spacekey
  
@ enter key
ldrh r1, [r0, #0]
tst r1, #1 << 1
bne enterkey
  
@ del key
ldrh r1, [r0, #10]
tst r1, #1 << 9
bne delkey
@bne keycheck
@ ctrl key
ldrh r1, [r0, #14]
tst r1, #1 << 9
bne ctrlkey
  
b keycheck
draw:
mov r2, #8
drawa:
ldr r1, [r0], #4
str r1, [r10], #SCREEN_WIDTH/2
subs r2, #1
bne drawa
bl wait_key_pressed
  
adr r0, off
ldr r1, [r0]
add r1, #4
str r1, [r0]
  
add r11, #4
b keycheck

@ handle special keys
spacekey:
adr r0, off
ldr r1, [r0]
add r1, #4
str r1, [r0]
  
add r11, #4
bl wait_key_pressed
b keycheck
delkey:
@ set the screen pointer back one step
sub r10, #4
sub r11, #4
@ set the offset back one step
@adr r0, off
@ldr r1, [r0]
@cmp r1, #0
@subne r1, #4
@str r1, [r0]
  
@ store emptyness at the characters place
ldr r0, =0xFFFFFFFF
mov r1, #8
drawdel:
str r0, [r10]
add r10 ,#SCREEN_WIDTH/2
subs r1, #1
bne drawdel
bl wait_key_pressed
b keycheck
enterkey:
ldr r0, =SCREEN_WIDTH/2 * 9
ldr r1, off
sub r0, r1
add r11, r0
  
adr r0, off
mov r1, #0
str r1, [r0]
  
bl wait_key_pressed
b keycheck
ctrlkey:
b end
end:
mov r0, #0
pop {r4-r11, pc}
 
@ Sprites; pixels go lik 0x78563412 !!!!
letter_a: .word 0xFF0FF0FF, 0xFF0FF0FF, 0x0FF00FF0, 0x0FF00FF0, 0x0F0000F0, 0x0F0000F0, 0x0FF00FF0, 0x0FF00FF0
letter_b: .word 0x0F0000F0, 0x0F0000F0, 0x0FF00FF0, 0xFF0F00F0, 0xFF0F00F0, 0x0FF00FF0, 0x0F0000F0, 0x0F0000F0
letter_c: .word 0x0F0000FF, 0x0F0000F0, 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0, 0x0F0000F0, 0x0F0000FF
letter_d: .word 0xFF0F00F0, 0xFF0000F0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0F0000F0, 0xFF0000F0
letter_e: .word 0x0F0000F0, 0x0F0000F0, 0xFFFF0FF0, 0xFF0000F0, 0xFF0000F0, 0xFFFF0FF0, 0x0F0000F0, 0x0F0000F0
letter_f: .word 0x0F0000F0, 0x0F0000F0, 0xFFFF0FF0, 0xFF0F00F0, 0xFF0F00F0, 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0
letter_g: .word 0x0F0000FF, 0x0F0000F0, 0xFFFF0FF0, 0xFFFF0FF0, 0x0F000FF0, 0x0F000FF0, 0x0FF00FF0, 0x0F0000FF
letter_h: .word 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0F0000F0, 0x0F0000F0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0
letter_i: .word 0x0F0000F0, 0x0F0000F0, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0FF0FF, 0x0F0000F0, 0x0F0000F0
letter_j: .word 0x0F00F0FF, 0x0F00F0FF, 0x0FF0FFFF, 0x0FF0FFFF, 0x0FF0FFFF, 0x0FF00FF0, 0x0F0000F0, 0xFF0000FF
letter_k: .word 0x0FF00FF0, 0x0F000FF0, 0xFF000FF0, 0xFF0F00F0, 0xFF0F00F0, 0xFF000FF0, 0x0F000FF0, 0x0FF00FF0
letter_l: .word 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0, 0xFFFF0FF0, 0x0F0000F0, 0x0F0000F0
letter_m: .word 0x0FFFFFF0, 0x0FF00FF0, 0x0F0000F0, 0x0F0000F0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0
letter_n: .word 0x0FF00FF0, 0x0FF000F0, 0x0F0000F0, 0x0F000FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0
letter_o: .word 0xFF0000FF, 0x0F0000F0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0F0000F0, 0xFF0000FF
letter_p: .word 0xFF0F00F0, 0x0F0000F0, 0x0FF00FF0, 0x0FF00FF0, 0x0F0000F0, 0xFF0F00F0, 0xFFFF0FF0, 0xFFFF0FF0
letter_q: .word 0xFF0000FF, 0x0F0000F0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF000F0, 0x0F000FF0, 0xFF0000F0, 0x0F0F00FF
letter_r: .word 0xFF0000F0, 0x0F0000F0, 0x0FF00FF0, 0x0F0000F0, 0xFF0000F0, 0xFF000FF0, 0x0FF00FF0, 0x0FF00FF0
letter_s: .word 0x0F00F0FF, 0x0F0000F0, 0xFFFF0FF0, 0xFF0F00F0, 0x0F0000F0, 0x0FF0FFFF, 0x0F0000F0, 0x0F0000F0
letter_t: .word 0x0F0000F0, 0x0F0000F0, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0FF0FF
letter_u: .word 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0F0000F0, 0x0F0000F0
letter_v: .word 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0x0FF00FF0, 0xFF0000FF, 0xFF0FF0FF
letter_w: .word 0x0FFFFFF0, 0x0FFFFFF0, 0x0FFFFFF0, 0x0FFFFFF0, 0x0F0FF0F0, 0x0F0FF0F0, 0x0FF00FF0, 0x0FF00FF0
letter_x: .word 0x0FF00FF0, 0x0FF00FF0, 0xFF0000FF, 0xFF0FF0FF, 0xFF0FF0FF, 0xFF0000FF, 0x0FF00FF0, 0x0FF00FF0
letter_y: .word 0x0FF00FF0, 0x0FF00FF0, 0xFFF00FFF, 0xFF0000FF, 0xFF00FFFF, 0xFF0FFFFF, 0xFF0F0FFF, 0xFFFF00FF
letter_z: .word 0x0F0000F0, 0x0F00FFF0, 0xFF00FFF0, 0xFF00FFFF, 0xFF0FF0FF, 0x0FFF00FF, 0x0FFF00F0, 0x0F0000F0
 
off: .word 0


« Last Edit: August 20, 2013, 04:40:36 pm by ElementCoder »

Some people need a high five in the face... with a chair.
~EC

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [ARM/Nspire] Inserting a new line in text
« Reply #1 on: August 21, 2013, 01:20:52 am »
You could use macros to make your code more readable :)
Invalid constant (408) after fixup probably means that the target line is too far, though I can't see why (I'd expect such an error at an earlier line). The range of displacements for "adr" is limited, and IIRC, it's precisely to 0x400 (1024) bytes.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: [ARM/Nspire] Inserting a new line in text
« Reply #2 on: August 21, 2013, 04:27:29 am »
A bit later, after I posted this question, I started commenting out the lines it said. If I don't use the letter z it builds and works fine, so I thought it might had something to do with that adr and errors if anything is placed after it. However, it also works fine if I place letter_z anywhere above letter_y, why doesn't it this then also generate an error for the lowest letter (lowest as in las of he sprites)?
I'll have a look at macros and see what I can do with them :)

Some people need a high five in the face... with a chair.
~EC

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: [ARM/Nspire] Inserting a new line in text
« Reply #3 on: August 21, 2013, 06:38:36 am »
I think adr works from +/- 255 bytes from the instruction, or +/- 1024 bytes if it's word-aligned. I haven't looked at the code and it doesn't seem very likely, but maybe it's not word-aligned? I also think there's a cleaner way to do it than all those tst instructions. It might also be worthwhile to define some constants for things like reading keypresses: "ldr r0, =0x900E0010". What is =0x900E0010? ;)

Try putting "ALIGN" in front of the letter_z label.

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: [ARM/Nspire] Inserting a new line in text
« Reply #4 on: August 21, 2013, 10:13:16 am »
I'm sure there are cleaner/better ways to do this as I'm only starting :) 0x900E0010 is the address from where to read for key presses. Putting ALIGN in front gives an error "bad instruction".
The 0x400 as a limit makes sense with the error messages, thanks for pointing it out.

Some people need a high five in the face... with a chair.
~EC

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: [ARM/Nspire] Inserting a new line in text
« Reply #5 on: August 21, 2013, 10:39:40 am »
You might try "align 4", but it looks like you've gone beyond the limit, i just saw all those sprites :O

Try ldr instead of adr. It'll put the value into a literal pool (basically a list of constants in your code, if you don't designate any specific area i believe it'll just put it at the end of the program, but it's gotta be within 4kb of the ldr instruction) and load it from there.

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: [ARM/Nspire] Inserting a new line in text
« Reply #6 on: August 21, 2013, 10:44:36 am »
I'll try that when I go with a serious program. Right now I'm just seeing what I can do and ask some questions :) I want to have a couple of things done before I start a project, so that I know a bit about it. Though I'll try your suggestion of using ldr instead of adr. Thanks for the help :)

Some people need a high five in the face... with a chair.
~EC