Author Topic: [ARM/Nspire] Drawing sprites  (Read 5239 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] Drawing sprites
« on: February 01, 2014, 01:29:30 pm »
So I have the following piece of code which draws a sprite on the screen:
Code: [Select]
#include <os.h>
main: .global main
push {r4-r11, lr}
bl lcd_ingray
bl clrscr
ldr r0, =0xC0000010
ldr r0, [r0]
mov r2, #8
adr r1, sprite
add r0, #200 @ x
add r0, #SCREEN_WIDTH/2 * 80 @ y
draw:
ldr r3, [r1], #4
str r3, [r0]
add r0, #SCREEN_WIDTH/2
subs r2, #1
bne draw @ if there are lines left, draw the next one
bl wait_key_pressed
mov r0, #0
pop {r4-r11, pc}

sprite: .word 0x00000000, 0x00000000, 0x00FFFF00, 0x00FFFF00, 0x00FFFF00, 0x00FFFF00, 0x00000000, 0x00000000
This is probably a stupid question, but the problem I'm facing is that I can only use x coordinates that are a multiple of 4. What would I need to do to be able to use any number for the x coordinate?
« Last Edit: February 01, 2014, 01:30:09 pm by ElementCoder »

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

Offline Legimet

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +29/-0
    • View Profile
Re: [ARM/Nspire] Drawing sprites
« Reply #1 on: February 01, 2014, 06:53:27 pm »
I dont know ARM asm, but each pixel is a short int in the 16-bit high color format.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [ARM/Nspire] Drawing sprites
« Reply #2 on: February 01, 2014, 07:13:07 pm »
Nope.

Code: [Select]
bl lcd_ingrayEach pixel is 4 bits long. I also don't ARM ASM though.

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [ARM/Nspire] Drawing sprites
« Reply #3 on: February 01, 2014, 07:42:16 pm »
Jup, each pixel is 4 bits, so half a byte. You can either:
-store the half byte in a separate register
-switch to 8bit mode
-use a separate method for reading and writing pixels given x and y
-use c and don't think about the low level stuff

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [ARM/Nspire] Drawing sprites
« Reply #4 on: February 01, 2014, 10:42:25 pm »
You should switch to writing bytes, not words, and then since pixels are 4 bits, have two different routines, one byte aligned and the other not which you choose when the x coordinate is even or odd respectively. Alternatively, if you need this to be really fast, you can set the LCD controller to 8 bits per pixel.
« Last Edit: February 01, 2014, 10:44:01 pm by fb39ca4 »

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: [ARM/Nspire] Drawing sprites
« Reply #5 on: February 16, 2014, 02:23:17 am »
I would also recommend using bytes.

Otherwise, how would you do that in z80? Why not try shifting the word you're trying to draw? Shift right to draw the left side of the sprite, shift left to draw the right side. For example, if you want to draw at SCREEN_ADR+1, you would store r3 shifted to the right one byte (8 pixels) to SCREEN_ADR+0, then r3 shifted to the left (4-1)*8 = 24 pixels to SCREEN_ADR+4. In ARM you get free (immediate) shifts with most commands, or you can load the offset into a register and use LSR or LSL to shift (or ROR to rotate). Register shifts are slightly slower (1 cycle), but still!
« Last Edit: February 16, 2014, 02:23:53 am by chickendude »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Re: Re: [ARM/Nspire] Drawing sprites
« Reply #6 on: February 16, 2014, 02:30:49 pm »
You should switch to writing bytes, not words, and then since pixels are 4 bits, have two different routines, one byte aligned and the other not which you choose when the x coordinate is even or odd respectively. Alternatively, if you need this to be really fast, you can set the LCD controller to 8 bits per pixel.

What I don't get is how a 4 bit pixel can use 65536 different colors on CX models O.O

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: [ARM/Nspire] Drawing sprites
« Reply #7 on: February 17, 2014, 03:48:49 am »
"bl lcd_ingray" sets it in grayscale mode, that's how ;)

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [ARM/Nspire] Drawing sprites
« Reply #8 on: February 17, 2014, 11:16:08 am »
Quote
What I don't get is how a 4 bit pixel can use 65536 different colors on CX models
On the CX, each pixel is 16 bit (RGB 565) :P