Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Jerros on September 12, 2010, 11:38:55 am

Title: Why doesn't "this" work?
Post by: Jerros on September 12, 2010, 11:38:55 am
Okay, the idea was to store a 1 or 2-byte number in an AppVar, then compare it to a new 2-byte number and store the biggest number (the idea of a Hi-Score:))
Secondly, I wanted to show that number.
Now, what I'm doing works only "half", in that it does show the correct number, but it's always an increment of 256 off.
This suggests that when using "b_call _DispHL" the "H" is off.
I have no idea why it randomly fills in H (it's not randomly though, but to keep things simple I won't explain/elaborate too much)
Basically, without posting the whole script, this is what I'm doing to show the stored number:
Code: [Select]
CALL Appvarstartcall ; These 3 lines just set HL to the Hi-Score, so that it's now at the adress of the 2-byte score.
LD B, 23 ; "B" is just how many times I want to inc hl to get to the right adress. For exemple's sake I use 23 here.
CALL lookup ; INC HL a couple of times to get to the right adress...
ld D, (hl) ; Load the most significant bute in D
inc hl ; inc HL to get to the adress of the least significant byte
ld E, (hl) ; And load the least significant byte in E.
ex DE, HL ; Put DE in HL so the next line works :P
b_call _DispHL ; It should show the stored hiscore now, exept that it doesn't. "D" seems to be a bit off.
             .........rest of stuff.......

Appvarstartcall:
ld hl, "NameOfTheAppVar"
rst 20h
bcall(_chkFindSym)
inc de
inc de
ex de, hl
ret
lookup:
inc hl
djnz lookup
ret
The problem is either at how I show the number, or at how I store it.
If I'm not doing horrable things above at displaying the number, it must be the way I store it.
Above is how I display the number, the way I store it is:
Code: [Select]
Score .equ AppBackUpScreen

CALL Appvarstartcall
LD B, 23
CALL lookup
ld D, (hl)
inc hl
ld E, (hl)
LD HL, (score) ; Score is the current score, to be compared to the previously stored hi-score.
or a
sbc hl, de
add hl, de
CALL p, NewHiScore ; if "Score" > Hiscore, store it.
........rest of script........

NewHiScore: ;  Basically store "Score" at the given adress.
CALL Appvarstartcall
LD B, 23
CALL lookup
LD DE, (score) ; score is the "new" number to store. It can hold any value between 0-9999
LD (HL), D
inc hl
LD (HL), E
ret
So one of the two (or both) is/are wrong.
Either I don't store "Score" correctly, or the way the number gets displayed is wrong.
Anyone that can shine his light and brighten my day here?

Thanks in advance!
Title: Re: Why doesn't "this" work?
Post by: SirCmpwn on September 14, 2010, 08:47:54 am
Hmm, I don't entirely follow your code.
It would be easier to debug if you posted the entire code and a binary.
Title: Re: Why doesn't "this" work?
Post by: Jerros on September 14, 2010, 12:46:48 pm
I think I've narrowed down the problem...
I feel silly to say, but the problem might not be the way I store/show the number, but the actuall content of (score) itself...
To reset the number, I simply do:
Code: [Select]
   LD    A, 0
    LD    (score), A
This of course fails as soon as (score) gets bigger than 255...
It also explains why only the most significant byte seems messed up, but isn't random.
I haven't tested it yet (don't have acces to my stuff right now) but that's probably the whole problem... /ashamed  :-[


Hmm, I don't entirely follow your code.
It would be easier to debug if you posted the entire code and a binary.
I just don't want to be that guy that posts infinite strings of code and then states "it doesn't work".
You people got better things to do than debugging over 7000 lines.
But what part you don't understand?
The first part is how to show a number stored in an AppVar at the 24th Byte.
The second part is how to store a number there.
Seems pretty straight forward to me, but if I need to clarify some things, please say so  :D
If there's indeed no miskate in there, feel free to use these routines.
Title: Re: Why doesn't "this" work?
Post by: _player1537 on September 14, 2010, 04:01:44 pm
Isn't there a "Ld HL, (location)" instruction in z80 ASM?  Assuming that, use it to make your score able to go up to 65535 (or something like that).  I'll look at your code more when I get home, but someone good at ASM might beat me :P
Title: Re: Why doesn't "this" work?
Post by: calcdude84se on September 14, 2010, 07:05:18 pm
There's also a "ld (addr),hl" ;D
You should be able to use that to solve your problem :)
Edit: I might look at the code myself later.
Title: Re: Why doesn't "this" work?
Post by: Jerros on September 16, 2010, 03:00:32 am
Please, safe your effords untill I've checked what I stated in the third post.
Don't want to bother anyone with a problem that's already solved >.<
If, however, what I said in the third post doesn't help I'll state that.
Unfortunately I can't acces my stuff right now, but please don't waste your time on a problem that *might* not exist.
Good to see so many helpfull people though.
Title: Re: Why doesn't "this" work?
Post by: DJ Omnimaga on September 16, 2010, 05:00:23 am
Just one thing: Since the forum activity is very high, if you have an update on your situation (problem fixed, new problem, solution), I suggest that if it has been over 6 hours since your last post, that you bump the topic with a new post, as a simple edit will not bump the topic in the list. It will ensure your update won't get missed. Double-posting is allowed if it has been over 6 hours between consecutive posts by the same person.
Title: Re: Why doesn't "this" work?
Post by: Jerros on September 19, 2010, 04:18:02 am
Okay, didn't knew that.
In this case, problem solved.
The error was that (score) was 2 bytes, so doing ld (score), A with A=0 only resetted the least significant byte.
There's no error in the codes that I posted in the first post, so feel free to use it.
Title: Re: Why doesn't "this" work?
Post by: DJ Omnimaga on September 19, 2010, 04:58:57 am
Glad to hear it works!

One day I really need to give ASM another try... but so much stuff in my to-do list...