<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Fri, 01 Apr 2016 21:33:07 +0100
From   : jgh@... (J.G.Harston)
Subject: Emulation

Julian Stenning wrote:
> There's something I'm not understanding correctly about enabling
> interrupts. I'm looking at $FE40 (doing nothing with User VIA at the
> moment) and in the disassembly I see:
> DA80 LDX #&F2 ;enable interrupts 1,4,5,6 of system VIA
> DA82 STX &FE4E ;
>  ;0 Keyboard enabled as needed
>  ;1 Frame sync pulse
>  ;4 End of A/D conversion
>  ;5 T2 counter (for speech)
>  ;6 T1 counter (10 mSec intervals)
> 
> What does 'enabled as needed' mean? I'm assuming here that each bit of
> FE4E being high means IRQ enabled, but bit zero is not set, is this a
> special case (and what does bit 7 do)?

Bit 7 is the state to write to the bits specified by bits 6-0. So, 
writing &F2 writes %11110010 so sets to '1' (bit 7) bits 6,5,4,1 (the 
bits set to 1) and leaves everything else unchanged. Conversely, writing 
&72 would clear bits 6,5,4,1 and leave everything else unchanged. So, 
will enable (b7=1) interrupts for:
bit 6 : T1 counter
bit 5 : T2 counter
bit 4 : CB1 input, which is fed from A/D conversion signal
bit 1 : CA1 input which is fed from Frame Sync pulse

everything else is unchanged, but will actually be disabled as earlier 
on in the code &7F has been written which disables (b7=0) everything 
(b6-b0=1).

The comments are a bit confusing as they try to point out that bit 0 CA2 
input (keyboard IRQ) is enabled as and when needed in other bits of the 
code. The comments would be cleared not actually mentioning this as all 
at that point.

> Another part of the disassembly I don't understand is "Clear interrupt
> and enable registers of Both VIAs", which does the following:
> DA6B LDA #&7F
> DA6D INX
> DA6E STA &FE4D,X
> DA71 STA &FE6D,X
> DA74 DEX
> DA75 BPL &DA6E
> 
> Why is an offset of FE4D / FE6D being addressed?

VIA offset 13 is the Interupt Flag register, offset 14 is the 
above-mentioned Interrupt Enable register. That code is a wrapped-up 
loop that does:

LDA #&7F
STA &FE4E ; Write &7F to SystemVIQ ENB - disable all SystemVIA IRQs
STA &FE6E ; Write &7F to UserVIQ ENB - disable all UserVIA IRQs
STA &FE4D ; Write &7F to SystemVIA IRQ - clear all SystemVIA IRQs
STA &FE6D ; Write &7F to UserVIA IRQ - clear all UserVIA IRQs

The loop saves four bytes compared to unrolling it. This is the earlier 
code that leaves the VIAs with all their interupts disabled before some 
of them are selectively enabled later on at DA80.

-- 
J.G.Harston - jgh@...      - mdfs.net/jgh
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>