Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: ACagliano on May 17, 2011, 04:31:30 pm

Title: Please Help
Post by: ACagliano on May 17, 2011, 04:31:30 pm
I've been coding so long and hard, I'm getting lazy. Can someone please help me with a few small routines:


AppVar Format, per entry

I1  I2  I3  I4  I5  U1  U2  U3  U4  U5  U6  U7  U8  C9  C1  C2  C3  C4  C5  C6  C7  C8  C9  C10  C11  C12
I = Calc ID (5-bytes)
U= Username
C= Coordinates

1: Routine to search an appvar pointed to by 'de' for an 8 byte username, pointed to by 'hl'. At the end, 'de' should point to I1

2: Routine to search an appvar pointed to by 'de' for the 12-byte coordinates pointed to by 'hl'. At the end, 'de' should point to I1

3: Routines to search an appvar pointed to by 'de' for the ID, pointed to by 'hl'. At the end, 'de' should point to (1) the associated user name (U1), and (2) the associated coordinates (C1).
Title: Re: Please Help
Post by: thepenguin77 on May 17, 2011, 06:08:17 pm
So are these all different appvars? If they are, why don't you throw them all into one big appvar?
Title: Re: Please Help
Post by: ACagliano on May 17, 2011, 06:26:36 pm
No, it is one appvar, with one entry right after the next. Each player's info requires 25 bytes, 5 for the ID, 8 for the username, and 12 for the coordinates.
Title: Re: Please Help
Post by: thepenguin77 on May 17, 2011, 06:59:03 pm
Ok, I'm glad it was all in one appvar because that makes it way easier.

Code: [Select]

;##########################################
;search for a user
;input: de = ptr to start of appvar data, (including size bytes)
; hl = ptr to username
;ouput: de = ptr to start of user section
; carry set if not found

searchForUser:
ld a, 8
ld bc, 5

jr realSearch




;##########################################
;search for a coordinate
;input: de = ptr to start of appvar data, (including size bytes)
; hl = ptr to coordinate
;output: de = ptr to start of user section
; carry set if not found

searchForCoordinate:
ld a, 12
ld bc, 13
jr realSearch


;##########################################
;search for an ID
;input: de = ptr to start of appvar data, (including size bytes)
; hl = ptr to coordinate
;ouput: de = ptr to start of user section
; carry set if not found

searchForAnId:
ld a, 5
ld bc, 0


; jr realSearch
; fall through

;#######
realSearch:
push bc
push hl
ex de, hl
ld e, (hl)
inc hl
ld d, (hl)
inc hl
add hl, bc
push hl
ex de, hl
push af
ld a, 25
bcall(_divHLbyA)
pop bc
ld c, l
pop hl
pop de


actualFindLoop:
push bc
push de
push hl
checkMatchLoop:
ld a, (de)
cp (hl)
jr nz, isntMatch

inc hl
inc de
djnz checkMatchLoop

pop hl
pop af
pop af
pop de
or a
sbc hl, de
ex de, hl
ret


isntMatch:
pop hl
ld de, 25
add hl, de
pop de
pop bc
dec c
jr nz, actualFindLoop
pop af
scf
ret

These routines are pretty simple. Just give it the DE that bcall(_chkFindSym) gives you and it will search the appvar for the data you give it. If it runs out of entries, it will return with carry set. Make sure that you don't have an appvar with more than 255 entries though, or else it won't look very far. I tried to make them as small as possible and a few times I was tempted to use the shadow registers, but I didn't.

I also have no idea what you wanted for your third routine. I just made one that searches for a specific ID, you can add whatever you want to the output it gives.

And if you need to search for other stuff, my realSearch: function should work quite nicely.
Title: Re: Please Help
Post by: ACagliano on May 17, 2011, 07:13:50 pm
Thanks thepenguin. As for the last option, the program needs to be able to accept a calc ID in hl and have de point to the start of that user's data section.

Suppose I wanted to use freeRAM instead. i know that won't change the program, i will just have to store $address into de, rather than ChkFindSym. But, I'm wondering what freeRAM areas are open to me. I use CALCnet, and the DCS7 GUI API, so the areas used by them are offlimits (not to mention Kerm recommends declaring RAM used as programs/appvars, to avoid corruption). Also, I use the first 60 bytes of saferam1, as defined by dcs7.inc
Title: Re: Please Help
Post by: thepenguin77 on May 17, 2011, 09:37:03 pm
I'm not sure what areas CALCnet uses, so I couldn't really tell you. There's nothing wrong moving it to static memory though. The only problem is that you might have to modify that routine a little because it relies on the two size bytes being out front.
Title: Re: Please Help
Post by: ACagliano on May 18, 2011, 05:49:47 pm
Code: [Select]
;##########################################
;search for a user
;input: de = ptr to start of appvar data, (including size bytes)
; hl = ptr to username
;ouput: de = ptr to start of user section
; carry set if not found

searchForUser:
ld a, 8
ld bc, 5

jr realSearch




;##########################################
;search for a coordinate
;input: de = ptr to start of appvar data, (including size bytes)
; hl = ptr to coordinate
;output: de = ptr to start of user section
; carry set if not found

searchForCoordinate:
ld a, 12
ld bc, 13
jr realSearch


;##########################################
;search for an ID
;input: de = ptr to start of appvar data, (including size bytes)
; hl = ptr to coordinate
;ouput: de = ptr to start of user section
; carry set if not found

searchForAnId:
ld a, 5
ld bc, 0

Shouldn't that last section have hl pointing to the ID to search for?

Title: Re: Please Help
Post by: thepenguin77 on May 18, 2011, 06:43:27 pm
Oh, yes. I forgot to change it when I was retyping it. But at least you understand it enough to realize that it was wrong :D
Title: Re: Please Help
Post by: ACagliano on May 18, 2011, 06:59:09 pm
Ok. So...

Each seperate section funnels into the realSearch section, which will return with de pointing to the start of that player's data section? Can I do a call on it? Where is the actual end, where de is output?
Title: Re: Please Help
Post by: thepenguin77 on May 19, 2011, 05:59:30 pm
The header for real search would be:
Code: [Select]
;############################################
;input: a = field length
; bc = field offset from start of data
; de = start of appvar
; hl = ptr to field to match

So you can call it if you want. There are two ret's out of realSearch, the first one is the good one, where DE = the start of the data section, and the second is just an error ret.
Title: Re: Please Help
Post by: ACagliano on May 20, 2011, 05:36:42 pm
Nice. Ok, another question. Is there a (_DeleteMem) command, like there is an (_InsertMem) command? Or if not, is there a work around?

Also, is there a two-byte subtract command?
Title: Re: Please Help
Post by: thepenguin77 on May 20, 2011, 07:47:37 pm
Yes, bcall(_delMem) exists. I believe you should download this (http://education.ti.com/calculators/downloads/US/Software/Download/en/177/6585/83psysroutines.pdf). I pull it out about every 1 out of 4 programming sessions.

And two byte subtract? sbc hl, rr. Where rr is bc or de. Just remember though that since this is sbc and not sub, you will have to make sure the carry flag is not set. So typically, you will see it used like this.
Code: [Select]
or a
sbc hl, de
Title: Re: Please Help
Post by: Munchor on May 20, 2011, 08:15:04 pm
Nice. Ok, another question. Is there a (_DeleteMem) command, like there is an (_InsertMem) command? Or if not, is there a work around?

Also, is there a two-byte subtract command?

As I said earlier on IRC, yes there is.

You can find a list of all BCalls here (http://davidgom.co.cc/bcalls.html).
Title: Re: Please Help
Post by: thepenguin77 on May 20, 2011, 08:53:11 pm
As I said earlier on IRC, yes there is.

You can find a list of all BCalls here (http://davidgom.co.cc/bcalls.html).

That list doesn't include ones not officially listed in ti83plus.inc. Check out BrandonW's list (http://brandonw.net/calcstuff/ti83plus.txt) it has every one listed, and most of them named. (Unnamed ones are unknown as of now, so they wouldn't be useful anyways.)

And between TI's list (http://education.ti.com/calculators/downloads/US/Software/Download/en/177/6585/83psysroutines.pdf) (linked above) and WikiTi (http://wikiti.brandonw.net/index.php?title=WikiTI_Home) you can figure out the inputs for most of the useful bcalls.
Title: Re: Please Help
Post by: Deep Toaster on May 22, 2011, 03:49:09 pm
This list on WikiTI (http://wikiti.brandonw.net/index.php?title=Category:83Plus:BCALLs:By_Name) is really useful to me. It's far from complete, but it links to pages that describe each routine pretty well. For everything else there's TI's System Routines guide, which thepenguin77 already linked to (twice) :)
Title: Re: Please Help
Post by: ACagliano on May 23, 2011, 06:56:26 pm
KK. Thanks everyone. This project is getting dangerously close to beta. I need help with one last routine. This routine should scan the same appvar that the routines above address. It should look for any COORDINATE entries that are 50 units in front of you and, if an entry is found, it should jump to another routine. Coordinate entries are formatted (x,y,z), two bytes each, starting at (xposition) and encompassing the x,y,and z position and the x,y,and z sector.

This info is crucial:  ship direction= 1 forward, 2backward, 3left, 4right, 5up, 6down
               backwards/forwards=y axis, left/right=x axis, up/down= z axis

Another question, but I'll code this myself...I need to place sprites on the screen in a relative position. The viewing window covers 50 units left-to-right. I need a way to determine where to place a ship on the screen. Thus, a ship with an x coordinate less than yours as you move forwards will appear on the left side of your screen. Any idea on how to do this, mathematically? Thanks.
Title: Re: Please Help
Post by: ACagliano on May 27, 2011, 10:46:50 am
^^Bumpity bump.
Title: Re: Please Help
Post by: thepenguin77 on May 27, 2011, 04:38:03 pm
Well, I'm not going to make the first routine, either you can do it or find someone else, but don't wait for me to post it ;)


As for relative positions, that's easy. There are two ways to go about it, and it depends on how you want your ship to move:

1. Ship is always dead center of screen:
    For this, we want to first see how the other ship compares relative to your ship. So (opponentX) - (yourX). That will tell you where they are relative to you. Then, just add the location of your ship on the screen. So lets say that your ship is on X=25 of the physical LCD, then you would add the little math problem from up above to 25 to get your location.

Example: (yourX) = 190, (opponentX) = 180, Your 50x50 screen is in the top left corner of the LCD. Your ship is displayed at (25,25)
     180 - 190 + 25 = 15. So you would display the enemy at X=15.

2. The ship can move freely and the screen scrolls when it gets close to the edge:
     I'll let you take care of the scrolling, we're only worried about displaying other ships. For this, the equation is just (opponentX) - (scrolledX) + offsetToScreen. It doesn't even matter where (yourX) is.

Example: (opponentX) = 180, (scrolledX) = 175, Your 50x50 screen is in the top left corner of the LCD.
     180 - 175 + 0 = 5. So you would display the enemy at X=5.
Title: Re: Please Help
Post by: ACagliano on November 26, 2011, 12:24:26 pm
Well, I'm not going to make the first routine, either you can do it or find someone else, but don't wait for me to post it ;)


As for relative positions, that's easy. There are two ways to go about it, and it depends on how you want your ship to move:

1. Ship is always dead center of screen:
    For this, we want to first see how the other ship compares relative to your ship. So (opponentX) - (yourX). That will tell you where they are relative to you. Then, just add the location of your ship on the screen. So lets say that your ship is on X=25 of the physical LCD, then you would add the little math problem from up above to 25 to get your location.

Example: (yourX) = 190, (opponentX) = 180, Your 50x50 screen is in the top left corner of the LCD. Your ship is displayed at (25,25)
     180 - 190 + 25 = 15. So you would display the enemy at X=15.

2. The ship can move freely and the screen scrolls when it gets close to the edge:
     I'll let you take care of the scrolling, we're only worried about displaying other ships. For this, the equation is just (opponentX) - (scrolledX) + offsetToScreen. It doesn't even matter where (yourX) is.

Example: (opponentX) = 180, (scrolledX) = 175, Your 50x50 screen is in the top left corner of the LCD.
     180 - 175 + 0 = 5. So you would display the enemy at X=5.

Ok, sorry. I hiatused this for a while and am back to it now. The original routines you gave me to search for stuff in the appvar, i will be using, however the format is now: 5-byte ID, 8-byte username, 6-byte coordinates (2 for x, 2 for y, 2 for z), and 3 byte sector (1 for x, 1 for y, 1 for z). Plus, I will be using saferam, rather than an appvar, so it should make this easier, right? Once we edit those original routines that search for username, ID, or coordinate, I should be able to handle the rest.
Title: Re: Please Help
Post by: thepenguin77 on November 26, 2011, 12:26:18 pm
Yep, or if you need more space. You can just throw the extra ram page in the $4000 region and use that.
Title: Re: Please Help
Post by: ACagliano on November 26, 2011, 12:42:27 pm
well, i cap at 30 members to a server, so...30x21 is 630 bytes...fittable within saferam1. :)