[Coco] Help with some HiRes CoCo 3 MMU settings

Glen Hewlett glen.hewlett at sympatico.ca
Wed Dec 7 16:41:03 EST 2016


Hi William,

Those are things I didn’t think of.  Thanks a lot for the insight.  I thought (incorrectly) that in COCO3 mode and enabling the GIME IRQs that the old Coco 1 & 2 interrupts were also disabled.  I will look into disabling the CoCo 1 & 2 interrupts and remove the ORCC #$10 and ANDDCC #$EF instructions from my Interrupt routine test.  Thanks also for the tip about the Timer resting automatically on it’s own.

This is all great stuff that I’m learning.  I’ll let you know how I make out.

Cheers,
Glen

> On Dec 7, 2016, at 4:23 PM, William Astle <lost at l-w.ca> wrote:
> 
> First thing: you are leaving the PIA IRQ enabled so you're still getting the legacy 60Hz interrupt from there (unless you're disabling that elsewise). Remember that the Coco3 has all the Coco1/2 interrupts from the PIAs in addition to the new GIME ones and they can all be operating at the same time.
> 
> Second, the GIME timer resets automatically so you don't need to reset it during the interrupt.
> 
> Third, CC is saved by the CPU as part of the interrupt service process. IRQ service also disables IRQ (your ORCC #$10). RTI will restore CC (which will re-enable the IRQ). That means you don't need to do anything with the "I" flag going into or out of the IRQ routine.
> 
> Here is what I think is probably happening:
> 
> 1. You enable the IRQ
> 2. And interrupt fires (probably the 60Hz PIA interrupt)
> 3. The service routine determines that it isn't the TIMER interrupt and re-enables IRQ (ANDCC #$EF); because you haven't cleared the interrupt status for the PIA this triggers an immediate re-interrupt, thus going back to step (2), and the RTI instruction does not execute.
> 
> What's happening is that the stack is growing infinitely until it overwrites your actual executing code (which would likely crash the system) OR starts trampling all over the I/O space (that would mess up the MMU registers among other things).
> 
> Basically, you have two problems:
> 
> There is an interrupt source you aren't dealing with (the PIA IRQ) by either disabling it or clearing the PIA interrupt status. See the IRQ handler for, say, Color Basic to see what it does about that. This is the really big thing that's causing your trouble.
> 
> Second, you're adjusting CC needlessly in your IRQ handler. Fixing that would still cause your program to fail but it would probably hang instead of crashing badly since RTI would at least be executing and, thus, preventing the stack from exploding.
> 
> 
> 
> On 2016-12-07 01:58 PM, Glen Hewlett wrote:
>> Hi Robert,
>> 
>> Thanks for looking at the code, I’ve been trying so many things to figure out why I’m having my problem that I’ve changed code without updating the comments many times...  I should have gone back and looked through my code and comments a little better last night before posting.  I was just at that point where I was getting really frustrated and really tired.  I was going to wait before posting but I figured it would mean at least another day before getting any help.
>> 
>> I actually noticed the INIT0_Register0 entry today myself and changed it to the proper INIT1_Register1 so my code will use MMU Bank 0 (%00100000 stored at $FF91).
>> 
>> I was using pages $30 & $31 originally (which is what I eventually want to use) but had changed them to $38 & $39 to see if putting them back to normal would stop the swapping out that seems to be happening while my program is running.  But it didn’t help.
>> 
>> I think my problem might not be with the RAM and MMU configuration and setup.  But more to do with my program using the IRQ.  But I was wondering if there was something I might have missed that is needed for the basic setup of the graphics memory on the CoCo 3.
>> 
>> The current program I’m working on is specifically so I get get a grasp on Interrupts more.  I’ve done a lot of programming on my old CoCo and Coco 3 in assembly so I’m comfortable in my coding but I’ve never really understood Interrupts.  Since I listened to John Linville talk about the hardware of the 6809 on the CoCo Crew podcast that I thought I really should get a grasp on this.
>> 
>> Currently I’m
>> 
>> SetIRQs ORCC    #$50                    * Disable All the IRQs (Interrupts)
>>        LDA     #$00                    * Vertical border interrupt Enabled        STA     IRQENR                  * Timer interrupt Enabled
>>        STA     IRQENR
>>        LDA     #$00                    *
>>        STA     FIRQENR                 * FIRQ are all disabled
>> 
>>        CLR     Timer_register_LSB      * Set the Timer to 0
>>        CLR     Timer_register_MSB      * The Timer Interrupt will activate whenever the timer counts down to zero
>>        LDA     #$7E                    * Setup IRQ jump location, Opcode for JMP instruction
>>        STA     IRQ_Jump_position       * Store it at FEF7 which is the address the the IRQ will jump to
>>        LDX     #My_IRQ		        * the actual address that will run when an IRQ hits (C2F9)
>>        STX     IRQ_Start_Address       * Store the program start at the IRQ Address (FEF8)
>> 
>> Later in my code to enable only the IRQ so I can do stuff with the Timer I use:
>> 		ANDCC	#$EF
>> 
>> The program runs for about 10 seconds then it seems like the CoCo is still doing something on its own in the background (bank switching) while my program is running and it’s erasing my data.
>> Here is the little test IRQ command that just increments a byte on the screen so I can see it working.
>> 
>> My_IRQ
>>        ORCC    #$10                    * Disable the IRQ Interrupt
>> 	INC	$100			; See on screen if IRQ is doing something
>>        LDA     IRQENR                  * IRQENR - Interrupt request enable register
>>        BITA    #$20                    * Test Timer interrupt (TMR)
>> 	BNE	TestIRQ
>> 	ANDCC   #$EF                    * Restore Condition Codes to re-enable IRQ Interrupt
>>        RTI
>> 
>> TestIRQ	
>> 	LDD     #$0FFF                  *C336: 86 95          Set Timer to Max of 4095
>>        STD     Timer_register_MSB      *C33D: B7 FF 94       Store Timer in FF94 Timer register
>> 	ANDCC   #$EF                    * Restore Condition Codes to re-enable IRQ Interrupt
>>        RTI
>> 
>> I’d appreciate any pointers or things you know that might be causing my problem.
>> 
>> Sorry for the long post,
>> Glen.
>> 
>>> On Dec 7, 2016, at 10:02 AM, Robert Gault <robert.gault at att.net> wrote:
>>> 
>>> Glen Hewlett wrote:
>>>> Hi All,
>>>> 
>>>> I’ve been fighting for days trying to figure out why the program I’ve written is crashing.  I think it’s the MMU doing some bank switching in the background while my program is running.
>>>> 
>>>> My program disables all the interrupts the sets up the graphic mode in my case a 256x225 2 colour screen.  I’m trying to use blocks 0 ($0000 to $1fff) and block 1 ($2000 to $3fff) for my graphics output screen and variables.  My program code is running at $4000 and the stack is at $7FFF.
>>>> 
>>>> While testing my program with the MAME emulator in debug mode, my program shows some graphics on the screen and runs along for a about 10 seconds then blamo, it crashes.  As far as I can tell the bank memory is coming into play somehow.  With Mame’s debugger I can see the banks of memory have wiped out my graphics screen and my program and filled it all with a bunch of $CD values in my RAM.  Does this sound familiar to anyone maybe you know what I’m missing or doing wrong that would cause such a thing to happen.
>>>> 
>>>> I looked all over the internet to see if anyone has some example code for  setting up graphics modes and the MMU in assembly.  All I’ve been able to find is tons and tons of technical manuals that do a great job of explaining what all the values do, but there aren’t any real world examples that I could find.  If someone has some nice code that they want to share that would be awesome…
>>>> 
>>>> Below is the initializing code that I’ve written and plan to use over and over for future programs.
>>>> 
>>>> Thanks for looking,
>>>> Glen
>>>> 
>>> 
>>> Glen,
>>> 
>>> There are several things that likely are not right.
>>> 
>>> 1) As already mentioned, you did not set the Task register but rather sent a second value to $FF90. The value sent would have caused the Task register to use a 279nsec clock and not Task#1. Should be %00000001
>>> 
>>> 2) Your comments and values do not match.
>>> * Load GIME pages $30 & $31 into CPU RAM $0000-$1FFF & $2000-$4000
>>>       LDA     #$38                    * Start at Hi-Res page #1
>>> 	STA	$FFA0
>>> 	LDA	#$39
>>> 	STA	$FFA1
>>> 
>>> With these changes, MESS does not crash.
>>> 
>>> Robert
>>> 
>>> 
>>> --
>>> Coco mailing list
>>> Coco at maltedmedia.com <mailto:Coco at maltedmedia.com>
>>> https://pairlist5.pair.net/mailman/listinfo/coco <https://pairlist5.pair.net/mailman/listinfo/coco>
>> 
> 
> 
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco



More information about the Coco mailing list