Re: [cc65] c64 question

Date view Thread view Subject view

From: Adam Dunkels (trident_at_c64.org)
Date: 2001-03-06 12:07:16


On Tuesday 06 March 2001 12:17, you wrote:
> Hello,
>
> I'm sorry to a post computer-specific question here, but you guys are
> my last hope.. ;)
>
> What I'm trying to do is to scroll the lines 100 through 150 by using a
> raster-interrupt (two actually). But I can't get it to work.

What happens? One good thing I used to do when testing was to do stuff with 
the border color (0xd020), like setting it to 1 (white) in the first 
interrupt and to 0 (black) in the second. Then you usually can see what's 
going on. 

A few things that I see in this program:

When exiting from an interrupt, you only want to call 0xea31 once per raster 
update. This function takes quite alot of time to execute, and there is no 
need to call it more often that 50 times per second. Also, since it takes 
time, the second interrupt might go off while executing 0xea31, and things 
will be generally messed up. Instead, the first interrupt should jump to 
0xea7e (which is at the end of the 0xea31 routine).

Upon entry of the interrupt routines, the compiler generates a jump to the 
"enter" function. At the end of the function, the compiler generates a jump 
to the "leave" function. The purpose of these functions is to adjust the cc65 
runtime stack to account for local variables. Since you jump to 0xea31 before 
"leave" is called, the runtime stack might be screwed up. Since these 
interrupts are executed 100 times per seconds, the stack is then totally 
trashed in a few tenths of a second. 

/adam

> My questions are:
>
> What am I missing? why doesn't it work the way I want it to?
> If I want to make a function that ends with an "rti" instead of "rts",
> is there a keyword/modifier in cc65 that does that to a function?
> in some compilers you can to write:
>
> interrupt void IRQ_handler(void)
> {
> 	...
> }
>
> ok then, here's the source:
> -------------------
>
> #include <c64.h>
> #include <6502.h>
>
> #define irq_vector (*(void**)0x314)
>
> void IRQ_handler_bottom();
> void IRQ_handler_top();
> void main();
>
> void IRQ_handler_top()
> {
> 	if (VIC.irr & 1) // make sure we got a raster interrupt
> 	{
> 		static unsigned char a = 0;
> 		a = (a + 1) & 7; // increase the scroll-counter
>
> 		// select 38 column mode and scroll this part of the screen 'a'
> pixels
> 		VIC.ctrl2 = a;
>
> 		// let the next interrupt handler get executed on line 150
> 		irq_vector = IRQ_handler_bottom;
> 		VIC.rasterline = 150;
>
> 		// tell the VIC-chip that we have handled the interrupt
> 		VIC.irr &= ~1;
> 	}
>
> 	// jump to the standard interrupt routine
> 	__asm__("	jmp	$ea31");
> }
>
> void IRQ_handler_bottom()
> {
> 	if (VIC.irr & 1) // make sure we got a raster interrupt
> 	{
> 		// select 40 columns mode and
> 		VIC.ctrl2 = 0x8;
>
> 		// let the first interrupt handler get executed on line 100
> 		irq_vector = IRQ_handler_top;
> 		VIC.rasterline = 100;
>
> 		// tell the VIC-chip that we have handled the interrupt
> 		VIC.irr &= ~1;
> 	}
>
> 	// jump to the standard interrupt routine
> 	__asm__("	jmp	$ea31");
> }
>
>
> void main()
> {
> 	SEI(); // make sure we don't get an interrupt while we are setting
> up our own
>
> 	irq_vector = IRQ_handler_top;
>
> 	CIA1.icr = 0x7f;
> 	VIC.imr = 1;			// enable raster IRQ
> 	VIC.rasterline = 100;	// the line where we want to get an
> interrupt
>
> 	CLI(); // enable interrupts again
>
> 	while (1); // just wait here
> }
>
>
> ---
> Arvid Norberg
> ----------------------------------------------------------------------
> To unsubscribe from the list send mail to majordomo_at_musoftware.de with
> the string "unsubscribe cc65" in the body(!) of the mail.

-- 
Adam Dunkels <trident_at_c64.org>
C64 coder/musician
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:39 CET