Author Topic: Why doesn't "this" work?  (Read 3578 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Why doesn't "this" work?
« 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!
« Last Edit: September 13, 2010, 08:00:21 am by Jerros »


79% of all statistics are made up randomly.

SirCmpwn

  • Guest
Re: Why doesn't "this" work?
« Reply #1 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.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Why doesn't "this" work?
« Reply #2 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.
« Last Edit: September 14, 2010, 12:51:30 pm by Jerros »


79% of all statistics are made up randomly.

_player1537

  • Guest
Re: Why doesn't "this" work?
« Reply #3 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

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Why doesn't "this" work?
« Reply #4 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.
« Last Edit: September 14, 2010, 07:05:57 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Why doesn't "this" work?
« Reply #5 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.


79% of all statistics are made up randomly.

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: Why doesn't "this" work?
« Reply #6 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.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Why doesn't "this" work?
« Reply #7 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.


79% of all statistics are made up randomly.

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: Why doesn't "this" work?
« Reply #8 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...