Confusing crash Address Error.

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Confusing crash Address Error.

Post by Count SymphoniC » Sun Oct 12, 2014 12:49 am

I've spent all day trying to figure this one out. Basically I've been working on the Synth editor. I added a new table for editing the YM2612's parameters. I haven't yet tied these tables in with the parameters themselves. When I go into the Synth editor to edit the data with the cursor, it works ok at first. But for some reason, if the lower digit goes anywhere between 2-F, it crashes. Setting the higher digit beyond 9 automatically sets both digits to 9F (it's supposed to do this), since the lower digit is in the range of 2-F, it crashes. The RAM viewer in Regen shows that the data is being written to the correct location in RAM, but when the crash occurs a 04 is written to the next byte, and I'm pretty certain that my code doesn't point to that location. That's likely the irrelevant part, as I've investigated deeply into this matter and the code that handles the digits and drawing to screen is pretty much the same and works fine elsewhere. My digit handling code is perfectly fine, it works everywhere else no problem.

Image
The video never updates the new value to the cursor.

I've recorded the event in GENS kmod, and took a look at the debugger and found where the crash occurs and guys this is where my mind gets melted. It occurs in the Frame waiting code (to slow everything down) that takes place in the main loop on a cmp.l instruction. What??? So I tried everything, pushing pulling data to/from the stack, wiping my registers clean. Here's something more confusing, if I remove this frame waiting code from the program... I get bad graphical glitches and even a complete freeze. This frame waiting code has caused me no other issues before. Even more confusing, if I keep the frame waiting code and set it to wait for 0 frames, it works fine, just everything is super fast of course. (still have that crash though)

Anyways the crash goes to the address error vector as defined in the init code. I've checked to make sure I'm doing my .b and .w properly. What the hell is going on?

Does this have to do with interrupts? Am I missing something? Is there any debug tips anyone might have that could help me solve this mess?
Last edited by Count SymphoniC on Sun Oct 12, 2014 1:23 am, edited 2 times in total.

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Sun Oct 12, 2014 1:16 am

Address error means you tried to do a word or long-word read/write to an odd address. The most common cause is that you have a word or long-word sized variable after a byte-sized one without any alignment directives, but it can also be caused by code being misaligned or buggy pointer math.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 12, 2014 1:23 am

Mask of Destiny wrote:Address error means you tried to do a word or long-word read/write to an odd address. The most common cause is that you have a word or long-word sized variable after a byte-sized one without any alignment directives, but it can also be caused by code being misaligned or buggy pointer math.
I'm 100% positive that I'm doing byte read/write only, but even in this case it happens on an even address, although the second byte that isn't supposed to be touched at all especially with the way I've coded it does fall on an odd address, but either way this shouldn't be happening, I mean look at it!

Although in this case it might be the misaligned code or buggy pointer math, I shall check some more.

EDIT: I should also add that editing that first byte in the RAM editor to that number range has the same effect as using the cursor to edit the data.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 12, 2014 3:18 am

HAHAHAHAHAHAHA!!!!!

Wow. This was one royal bitch hard to find of a bug!

Check this out. I have two different routines for drawing my cursor to the screen, one for two digit values and one for triple digit values (musical notation). I use a meta routine (that's what I call it anyways) to do checks for which screen we're on, to decide which cursor to draw to screen. Well in this metaroutine:

Code: Select all

UPDATECURSORMETA:
    move.b                  CURRENTSCREEN, d0
    cmp.b                   #MAINSCREEN, d0
    beq                       UPDATECURSORY
    cmp.b                    #CHAINSCREEN, d0
    beq                        UPDATECURSORY
    cmp.b                   #PHRASESCREEN, d0
    jsr                       UPDATENOTEENTRYCURSOR     ; Note Entry screen has multiple rules for the cursor, we'll handle them here
    cmp.b                    #SYNTHSCREEN, d0
    beq                        UPDATECURSORY
    rts
This was the bug.

Code: Select all

jsr                       UPDATENOTEENTRYCURSOR     ; Note Entry screen has multiple rules for the cursor, we'll handle them here
That jsr was supposed to be a beq. AHHHHHHH!!!!!!!!
Okay anyways. Back to work.

HardWareMan
Very interested
Posts: 745
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Post by HardWareMan » Sun Oct 12, 2014 4:30 am

Miracles don't happen. Only human error.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Sun Oct 12, 2014 8:46 am

In 99% cases, it's bug in your code, in other cases you may catch bug in emulator. And as I see, you keep posting bugs in your code. Why? Do you want from us to find out your bug? It's impossible until you show all your code. And even in this case, I don't think someone will look into it.
Image

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 12, 2014 2:54 pm

r57shell wrote:In 99% cases, it's bug in your code, in other cases you may catch bug in emulator. And as I see, you keep posting bugs in your code. Why? Do you want from us to find out your bug? It's impossible until you show all your code. And even in this case, I don't think someone will look into it.
I know that computers only do exactly what they're programmed to do, sometimes my bugs perplex me to the point of stress. Posting about it helps me vent and there's always the chance that someone will say something that will lead me to the answer even if it's not the answer itself. I don't think I'll ever show all of my code, there's too many lines of code! If someone wanted me to try to debug 13,396 lines of code and it wasn't my own program that I wrote??? I would probably say, "sorry pal". So yeah, I really want to finish this project... and I don't want my frustrations to be the reason why I don't finish it. So when things get really weird and stressful, I post. Remember, I'm still new to 68k assembly, but I'm getting better at it.

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Sun Oct 12, 2014 4:36 pm

Many members of the forum get by everyday fixing difficult bugs without questions. For example fairly recently I wrote my first NES program and didn't need to ask any questions. Everything could be found using a search engine. I am learning latex and got an error I just looked it up and within a minute it was fixed. When I write code for the genesis I fix bugs myself. Summer of this year I fixed many bugs for my program Retro Graphics Toolkit in addition to adding lots of features. Most of the time it is faster to fix than waiting for a response and even when it takes awhile you still learn stuff. You cannot get the same experience by asking a question and taking the easy way out. I looked back at my post history here and on other boards and have not asked a programming question since 2012 the reason for this is because I can solve my own problems and being able to do such has lead to an increase in productivity and has improved my programming skill significantly as I actually learn what is going on. If you were to compare some of my old code even from 2013 to my recent 2014 code you will see that it is better. I do understand that sometimes a question is justified if you have already tried lots of things and still cannot get it to work. In this case it is good to know that you already tried to solve the problem but it sounds like your problem solving skills are a bit low. One idea I have is to check the code again. I remember one time I was debugging some code and was looking at the wrong part of it. It turns out that another change was causing a crash latter on. When I saw the other part of the code it was immediately obvious and I was disapointed in the time taken to fix it but at the same time I did learn a lesson however and would not have the same experience if I asked a question. Also I would have to have waited longer for a response yes I could have done other things but still you do see my point?

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 12, 2014 5:04 pm

sega16 wrote:Many members of the forum get by everyday fixing difficult bugs without questions. For example fairly recently I wrote my first NES program and didn't need to ask any questions. Everything could be found using a search engine. I am learning latex and got an error I just looked it up and within a minute it was fixed. When I write code for the genesis I fix bugs myself. Summer of this year I fixed many bugs for my program Retro Graphics Toolkit in addition to adding lots of features. Most of the time it is faster to fix than waiting for a response and even when it takes awhile you still learn stuff. You cannot get the same experience by asking a question and taking the easy way out. I looked back at my post history here and on other boards and have not asked a programming question since 2012 the reason for this is because I can solve my own problems and being able to do such has lead to an increase in productivity and has improved my programming skill significantly as I actually learn what is going on. If you were to compare some of my old code even from 2013 to my recent 2014 code you will see that it is better. I do understand that sometimes a question is justified if you have already tried lots of things and still cannot get it to work. In this case it is good to know that you already tried to solve the problem but it sounds like your problem solving skills are a bit low. One idea I have is to check the code again. I remember one time I was debugging some code and was looking at the wrong part of it. It turns out that another change was causing a crash latter on. When I saw the other part of the code it was immediately obvious and I was disapointed in the time taken to fix it but at the same time I did learn a lesson however and would not have the same experience if I asked a question. Also I would have to have waited longer for a response yes I could have done other things but still you do see my point?
Yes I understand. I google and search forums more than you might think.

Like most of the bugs I've ran into, I've figured the majority of them all by myself, just because I don't make these revelations public, doesn't mean they don't exist. Even in this case, I solved it without help. There are a couple of cases to where I got help from others, but I've learned either way. I still agree with most of what you say, although it's not in my opinion completely fair to point out on a public forum that it sounds like my problem solving skills are a bit low. The reason why I don't think it's completely fair is because I've pointed out multiple times on these forums that I'm still new to assembly and I should probably point out that this is my first real programming project (mostly hello worlds and just messing around previously). So what do you honestly expect? God like problem solving skills? I've been doing this for about 3 weeks now... and the fact that I've managed to get a decent gui working, control the VDP, PSG and YM2612... more on the way, in 3 weeks time, speaks for itself. I'm not a programming prodigy, but I would like to be treated with a little bit more respect.

Now I will say that it may be very well true that my problem solving skills are a bit low. Everyone has their blind spots I believe myself included. There was one and only one clue that pointed to the actual problem and that was the fact that the extra byte was being written when entering the number range 3-F. That was a hint that it was related to my Notation handler, because that's the only code in the entire program that handles digits like that. So I figured maybe I had used the wrong global variable somewhere, or I got my registers switched up. I would have never guessed that it was the jsr, in fact it was only after re-reading countless lines of code over and over again, multiple times, that I discovered that. That jsr being there didn't cause any noticeable problems previously and it had been there for a couple of revisions so it kinda got buried from the foreground of my focus.

Last but not least, if I wanted people to fix my bugs for me, I would've posted all the source code. I tend to post these complex explanations of what's going on in my program, but all I'm ever looking for is tips on debugging or a general idea of what can cause these problems... I can fix it from there.

Finally but more importantly, I hope I didn't sound too abrasive. I can get a bit moody sometimes. I do thank you for sharing your perspective, it sounds like a good standard for working with software and that's a standard I can look forward to adopting one day. Just given the time of course. Still learning over here.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Sun Oct 12, 2014 5:29 pm

You do what you do, don't let others sit on you !
(lol, it even rhymed hahaha)
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 12, 2014 5:38 pm

TmEE co.(TM) wrote:You do what you do, don't let others sit on you !
(lol, it even rhymed hahaha)
Haha honestly from you I was expecting another drawn out "Let's rant to the noob". You've been working with this stuff for years! But instead this? It can plausibly be theorized that I may have actually chuckled... this forum is full of surprises.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Oct 12, 2014 5:59 pm

Sometimes we'll rant on the noob, but it's mostly things they need to hear. Everyone starts as a noob, and makes noob-ish mistakes. We hope people are nicer about correcting them, but around here, we're all devs, so we can tend to be a bit more cutting. We aren't being mean, we just tend to think that it's better in the long run to simply cut to the chase. Think of it as "tough love". :D

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 12, 2014 6:41 pm

Chilly Willy wrote:Sometimes we'll rant on the noob, but it's mostly things they need to hear. Everyone starts as a noob, and makes noob-ish mistakes. We hope people are nicer about correcting them, but around here, we're all devs, so we can tend to be a bit more cutting. We aren't being mean, we just tend to think that it's better in the long run to simply cut to the chase. Think of it as "tough love". :D
Yeah I get what you're saying and it's true.

See I've always been the type to take things very personally, usually after I've thought about it I'll come around though. I really do appreciate everyone's thoughts and perspectives around here as they've been most helpful in me even getting this far and my personal growth.

Anyways, back to the Synth editor. I only need to tie the arrays with the YM2612 parameters and I'll be on my way to starting the actual playback engine! Holy crap! This is one heck of an adventure working on a music sequencer for the first console I ever played on as a child and old time favorite - the Genesis! See??? I'm a very moody person. Okay well back to work.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Mon Oct 13, 2014 9:10 am

Count SymphoniC wrote:I've been doing this for about 3 weeks now... and the fact that I've managed to get a decent gui working, control the VDP, PSG and YM2612... more on the way, in 3 weeks time, speaks for itself. I'm not a programming prodigy, but I would like to be treated with a little bit more respect.
If you "not a programming prodigy" it does not mean that you may ask to find some bug. If you want to learn about Debug techniques: ask about techniques, not about bug! :)

Why it's useless to ask about finding bug? Because it may be in any part of your program. And that's why, you can't even imagine how some very simple bug may cause some very wierd behavior. For example I had one interesting bug. I had code looks like this:

Code: Select all

move.b (some_var).l, d0
@loop:
// some code in loop
dbf  d0, @loop
It was working fine, until some moment. And it was quite challenge to find it. I tried everything, it was hard, but I found it. What was wrong? Until some moment, previous code always forced high byte of d0 to zero, so loop was working as it should. But when I changed some code before, high byte of d0 might be $FF for example, that cause very long loop, because dbf works only with words. So fix is:

Code: Select all

clr.w d0
move.b (some_var).l, d0
@loop:
// some code in loop
dbf  d0, @loop
So, it's completely useless to ask about your bugs, because only you can find them. But when you need to ask, is when you think that you have bug in understanding. That's how to realize, that bug is in code, not in your viewing of things. So... Always welcome for questions about understanding things. And, please, don't ask about bugs in your code. :D
Also, ask about "how to easily implement some thing", or "is it possible to do something" and so on.
Chilly Willy wrote:Sometimes we'll rant on the noob, but it's mostly things they need to hear.
I'll rant on anyone who is wrong in my opinion.
Image
For example I already ranted on Delek, while his DefleMask was crushing every now and then, and he could not find the bug in his program, because he could not replicate it. He did for me around 20 different debug versions of his DefleMask to find this bug. And after he found bug, he was so suprised how simple bug was. Also, as far as I know, I'm in "thanks to" section because of that.
Image

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Oct 14, 2014 2:39 am

r57shell wrote:So fix is:

Code: Select all

clr.w d0
move.b (some_var).l, d0
@loop:
// some code in loop
dbf  d0, @loop
Um - no. The fix is

Code: Select all

moveq #0,d0
move.b (some_var).l, d0
@loop:
// some code in loop
dbf  d0, @loop
;)

Image

Post Reply