6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Apr 25, 2024 10:04 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Sep 08, 2020 10:16 pm 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
I'm putting in a few BRK instructions here and there for debugging. What I want to do is print a debug message to the screen and then exit the program. However, brk clears the screen. How can I just drop out of my program and leave the screen contents intact? Re-vector the interrupt routine maybe?


Last edited by DanielS on Wed Sep 09, 2020 12:04 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 08, 2020 11:09 pm 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 293
This is completely dependent on the machine you're running your code on. Commodore 64 again? Please put this in the subject, or at least in the post. My psychic powers have limits.

BRK is a software-generated interrupt. The C64's interrupt handler starts at $FF48. The first thing it does after pushing registers is look at the B flag. If it's clear it jumps through the vector CINV at $0314. If it's set (because we got here from a BRK instruction) it jumps through the vector CBINV at $0316. Point CBINV at your handler, and you can do whatever you like. Your handler will have to pop the registers before returning, and there's a handy snippet of code at $EA81 that will do it for you.

But doing that will return to your program. If you wanted to warm-start BASIC without clearing the screen, JMP ($A002) will probably do it. If you've changed any VIC registers JSR PANIC ($E5A0) will reset them.

I'm using the very useful KERNAL and BASIC source code posted by Michael Steil at https://github.com/mist64/c64ref/blob/master/c64disasm/c64disasm_cbm.txt and https://github.com/mist64/c64ref/blob/master/c64disasm/c64disasm_ms.txt


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 09, 2020 12:05 am 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
Sorry John. I edited it. Thanks for your answer.


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 09, 2020 5:24 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 672
Alternatively, if you use SYS from BASIC to jump into your asm program, then you can RTS out of it cleanly (assuming that you didn't muck up BASIC's zeropage variables or bank the ROMs out or anything). BASIC will still print a blank like and the READY. prompt once it returns, so if you're on the bottom of the screen it might scroll a few lines.

If you're nested somewhere inside your own subroutines and want to exit this way, you could save the stack pointer on entry with TSX, STX <somewhere>, then restore the stack pointer with TXS and RTS.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: