Hello everyone,
edit; perhaps this should be in the programming section. I saw 'newbies' and I figured that it would be best here for some reason.
I've been delving into the realm of 6502 assembly recently, and my code has gotten so large that it's becoming rather difficult to debug. I have coded in x86 assembly and there is an instruction which acts as a breakpoint (int c3?) for debuggers upon execution.
Does anyone know an equivalent which works with VICE? Or perhaps a old school form of debugging? I would prefer to abstain from needle-and-haystack methods. I would use the BRK instruction but that brings you to the monitor, but I'm running on top of BASIC and I don't have any knowledge of software interrupts (yet. Maybe it's time?)
Thanks.
breakpoints in code (ca65, VICE)
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: breakpoints in code (ca65, VICE)
Dvorak wrote:
Hello everyone,
edit; perhaps this should be in the programming section. I saw 'newbies' and I figured that it would be best here for some reason.
I've been delving into the realm of 6502 assembly recently, and my code has gotten so large that it's becoming rather difficult to debug. I have coded in x86 assembly and there is an instruction which acts as a breakpoint (int c3?) for debuggers upon execution.
Does anyone know an equivalent which works with VICE? Or perhaps a old school form of debugging? I would prefer to abstain from needle-and-haystack methods. I would use the BRK instruction but that brings you to the monitor, but I'm running on top of BASIC and I don't have any knowledge of software interrupts (yet. Maybe it's time?)
Thanks.
edit; perhaps this should be in the programming section. I saw 'newbies' and I figured that it would be best here for some reason.
I've been delving into the realm of 6502 assembly recently, and my code has gotten so large that it's becoming rather difficult to debug. I have coded in x86 assembly and there is an instruction which acts as a breakpoint (int c3?) for debuggers upon execution.
Does anyone know an equivalent which works with VICE? Or perhaps a old school form of debugging? I would prefer to abstain from needle-and-haystack methods. I would use the BRK instruction but that brings you to the monitor, but I'm running on top of BASIC and I don't have any knowledge of software interrupts (yet. Maybe it's time?)
Thanks.
BRK is the "traditional" means by which a running machine language program is interrupted for debugging purposes. On the NMOS MPUs and the 65C02, BRK is the only software interrupt available. It is customary for the BRK handler to go into a machine language monitor, which would dump the registers and await input.
Although almost all 6502 assemblers treat BRK as a one byte instruction, it actually is a two byter, as the 65xx family double-increments the program counter when BRK is executed. The byte following BRK is called the signature and can be any value.
Dunno if this information helps you.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: breakpoints in code (ca65, VICE)
Interesting that the BRK instruction increments PC by 2. I was wondering why PC was never at the BRK point itself! This will help me a decent amount. Would you happen to know why the BRK instruction increments PC?
It seems like BRK is half of what I want (convenience-wise), but it will do. I was wanting something which would pause the code, then allow me to step through it using VICE's monitor, but I'm becoming uncertain as to whether or not something like that actually exists. Thanks!
edit; found this on a 6502 instruction set sheet: "BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct. " I take it this has something to do with the stack?
It seems like BRK is half of what I want (convenience-wise), but it will do. I was wanting something which would pause the code, then allow me to step through it using VICE's monitor, but I'm becoming uncertain as to whether or not something like that actually exists. Thanks!
edit; found this on a 6502 instruction set sheet: "BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct. " I take it this has something to do with the stack?
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: breakpoints in code (ca65, VICE)
Dvorak wrote:
Interesting that the BRK instruction increments PC by 2. I was wondering why PC was never at the BRK point itself! This will help me a decent amount. Would you happen to know why the BRK instruction increments PC?
Quote:
It seems like BRK is half of what I want (convenience-wise), but it will do. I was wanting something which would pause the code, then allow me to step through it using VICE's monitor, but I'm becoming uncertain as to whether or not something like that actually exists. Thanks!
Quote:
edit; found this on a 6502 instruction set sheet: "BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct. " I take it this has something to do with the stack?
Worthy of note is that the $FFFE-$FFFF vector is the same one taken when a hardware interrupt request (IRQ) occurs. The 6502 indicates the type of interrupt by setting the B bit in the stack copy SR if the interrupt was caused by a BRK instruction, or by clearing the B bit if the interrupt was caused by an IRQ. Hence the type of interrupt has to be determined in software by fetching a copy of SR from the stack and masking for the B bit. The B bit is meaningless otherwise.
x86? We ain't got no x86. We don't NEED no stinking x86!
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: breakpoints in code (ca65, VICE)
Dvorak wrote:
I've been delving into the realm of 6502 assembly recently, and my code has gotten so large that it's becoming rather difficult to debug.
Quote:
I would use the BRK instruction but that brings you to the monitor, but I'm running on top of BASIC and I don't have any knowledge of software interrupts (yet. Maybe it's time?)
Quote:
I take it this has something to do with the stack?
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: breakpoints in code (ca65, VICE)
BigDumbDinosaur wrote:
Dvorak wrote:
It seems like BRK is half of what I want (convenience-wise), but it will do. I was wanting something which would pause the code, then allow me to step through it using VICE's monitor, but I'm becoming uncertain as to whether or not something like that actually exists. Thanks!
Using the emulator facilities is a great way to explore program behaviour.
Dvorak wrote:
edit; found this on a 6502 instruction set sheet: "BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct. " I take it this has something to do with the stack?
See this simulation.
Cheers
Ed
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: breakpoints in code (ca65, VICE)
BigEd wrote:
BigDumbDinosaur wrote:
Dvorak wrote:
It seems like BRK is half of what I want (convenience-wise), but it will do. I was wanting something which would pause the code, then allow me to step through it using VICE's monitor, but I'm becoming uncertain as to whether or not something like that actually exists. Thanks!
Using the emulator facilities is a great way to explore program behaviour.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: breakpoints in code (ca65, VICE)
This is just theory, I have never implemented this myself and have no idea if this is actually possible.
Assuming the program under debug was running out of RAM, couldn't single stepping be accomplished by poking a BRK into the "next" instruction, stashing the overwritten byte somewhere so the code stream can be stitched back together? Of course the BRK handler would need to know the number of bytes required by the "current" instruction.
Sorry if this is already covered elsewhere. I'm only pondering this from principles. Have only vague practical experience with software interrupts.
Assuming the program under debug was running out of RAM, couldn't single stepping be accomplished by poking a BRK into the "next" instruction, stashing the overwritten byte somewhere so the code stream can be stitched back together? Of course the BRK handler would need to know the number of bytes required by the "current" instruction.
Sorry if this is already covered elsewhere. I'm only pondering this from principles. Have only vague practical experience with software interrupts.
8 bit fun and games: https://www.aslak.net/
Re: breakpoints in code (ca65, VICE)
Yes, you can almost do that. You have to cope separately with branches and other operations which disturb the progression of the program counter. I think at least one of the Apple monitors did exactly that.
Edit: no, it didn't quite do that. It copied the instruction-to-be-executed into RAM and ran it there, unless it was a special case. See the routine STEP here.
Edit: no, it didn't quite do that. It copied the instruction-to-be-executed into RAM and ran it there, unless it was a special case. See the routine STEP here.
Code: Select all
FA43: 20 D0 F8 372 STEP JSR INSTDSP ;DISASSEMBLE ONE INST
-
White Flame
- Posts: 704
- Joined: 24 Jul 2012
Re: breakpoints in code (ca65, VICE)
The nice thing about VICE breakpoints and single stepping is that it also displays the VIC line & cycle counter for you (under the 'r' command), for either measuring performance or trying to hit cycle-specific machine effects.
The only thing that sucks about it is the actual windowed interface, at least on Windows. On Linux, the monitor shows up on the terminal that x64 was launched in, so you can scroll & copy/paste as usual. (in whatever version I happen to have)
The only thing that sucks about it is the actual windowed interface, at least on Windows. On Linux, the monitor shows up on the terminal that x64 was launched in, so you can scroll & copy/paste as usual. (in whatever version I happen to have)
Re: breakpoints in code (ca65, VICE)
BigEd wrote:
Yes, you can almost do that. You have to cope separately with branches and other operations which disturb the progression of the program counter. I think at least one of the Apple monitors did exactly that.
Edit: no, it didn't quite do that. It copied the instruction-to-be-executed into RAM and ran it there, unless it was a special case. See the routine STEP here.
Edit: no, it didn't quite do that. It copied the instruction-to-be-executed into RAM and ran it there, unless it was a special case. See the routine STEP here.
Code: Select all
FA43: 20 D0 F8 372 STEP JSR INSTDSP ;DISASSEMBLE ONE INST
White Flame wrote:
The nice thing about VICE breakpoints and single stepping is that it also displays the VIC line & cycle counter for you (under the 'r' command), for either measuring performance or trying to hit cycle-specific machine effects.
The only thing that sucks about it is the actual windowed interface, at least on Windows. On Linux, the monitor shows up on the terminal that x64 was launched in, so you can scroll & copy/paste as usual. (in whatever version I happen to have)
The only thing that sucks about it is the actual windowed interface, at least on Windows. On Linux, the monitor shows up on the terminal that x64 was launched in, so you can scroll & copy/paste as usual. (in whatever version I happen to have)