Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: ElementCoder on February 01, 2014, 01:29:30 pm

Title: [ARM/Nspire] Drawing sprites
Post by: ElementCoder 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?
Title: Re: [ARM/Nspire] Drawing sprites
Post by: Legimet 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.
Title: Re: [ARM/Nspire] Drawing sprites
Post by: Matrefeytontias 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.
Title: Re: [ARM/Nspire] Drawing sprites
Post by: Vogtinator 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
Title: Re: [ARM/Nspire] Drawing sprites
Post by: fb39ca4 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.
Title: Re: [ARM/Nspire] Drawing sprites
Post by: chickendude 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!
Title: Re: Re: Re: [ARM/Nspire] Drawing sprites
Post by: DJ Omnimaga 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
Title: Re: [ARM/Nspire] Drawing sprites
Post by: chickendude on February 17, 2014, 03:48:49 am
"bl lcd_ingray" sets it in grayscale mode, that's how ;)
Title: Re: [ARM/Nspire] Drawing sprites
Post by: Vogtinator 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