Page 1 of 1

[TI Asm] Tron Project

Posted: Tue 16 Dec, 2008 9:26 pm
by waeV
Well, I started getting back into assembly (but I'm still too lazy to spend the full 28 days taking the tutorial). I started by making a tron clone in basic, then refining it to make it run as fast as possible. I've reached the limits of Ti-basic, however, and anything with a halfway decent AI is pretty dang slow. Naturally, I turned to assembly.

Here's the pseudocode for what i did in Ti-Basic:

Code: Select all

Lbl A
pxl-on(x1,y1)
pxl-on(x2,y2)

prgmAISUB

getkey
determine direction based on input

inc / dec x and y variables according to direction

check if the pixel about to be turned on is already on, if so goto B
goto A

Lbl B
determine winner/loser
The first problem I see is that I don't know how to display the 1 pixel lightcycle. Can a sprite be defined as one pixel? Ideally there would be a pixel-on and pixel-text command that I could use.

Re: [TI Asm] Tron Project

Posted: Tue 16 Dec, 2008 10:01 pm
by King Harold
Well with asm, you don't have to use commands. You can just test/set the pixels directly, making it faster. Day 24 of the 28 days tells you most of what you should know about testing/setting pixels. If the pixel-coordinate is a constant (not likely, but who knows?) you could just use the bit/set instructions. Theoretically it's also possible for non-constant coordinates, but not usually a good plan (smc or a large switch block for something so simple?)

Now that I think about it, maybe smc would be viable alternative..
Maybe something like this?

Code: Select all

CheckPixel:
;returns Z if white, NZ if black
;A = x coordinate
;L = y coordinate
;coordinates must be inside the valid range for the result to make sense
 ld h,0
 ld d,h
 ld e,l
 add hl,hl
 add hl,de
 add hl,hl
 add hl,hl
 ld e,a
 srl e
 srl e
 srl e
 add hl,de
 ld de,PlotScreen
 add hl,de
 and 7
 add a,a
 add a,a
 add a,a
 or $46
 ld (bit+1),a
bit:
 bit 0,(hl)
 ret
Ok maybe not such a good plan after all, this is huge, and mostly a copy of GetPixel.. But no loop (which can only be up to 7 iterations long anyway..)

Re: [TI Asm] Tron Project

Posted: Tue 16 Dec, 2008 10:34 pm
by waeV
Oh, ok I don't know why I didn't think to look in day 24, I was milling about in the sprite section. Thanks. :mrgreen:

Re: [TI Asm] Tron Project

Posted: Wed 17 Dec, 2008 3:14 am
by cjgone
Ah... I remember learning sprites in 28 days and being utterly confused for like an extremely long time.

Have fun with that I guess. :P