Page 1 of 1

Resetting IRQs

Posted: Mon Feb 05, 2024 1:39 pm
by heaven6502
hmmm..

Me toying again with the VIC20 and for days I try to reset my double IRQ for stable rasters routines... and all I do stops my trackloader at some point...

so simple question... i have a part which has set 2 VIAs timers and i simply want to "switch it back" to normal mode... where I have a simple VBL based IRQ running through $314/15...

i saved all regs prior setting the IRQinit routines and the IRQserver to handle the raster-IRQ and vblank... when I call $fdf9 in ROM to init i/o my trackloader seems fucked up...

Code: Select all

;**************************************************************************
;*
;* IRQ Interrupt server
;*
;******
IRQServer:
	lda	$912d
	asl
	asl
	bcs	irq_skp1
	asl
	bcc	irq_ex1
	jsr	T2Timeout ;raster IRQ
	jmp	irq_ex1
irq_skp1:
	jsr	T1Timeout ;VBL
irq_ex1:
	pla
	tay
	pla
	tax
	pla
	rti
;**************************************************************************
;*
;* Routines + stuff
;*
;******
T1Timeout:
	lda	#[75+[<t1_TComp]]&255
	sec
	sbc	$9124	;68-73 (for PAL)
	sta	t1_SelfModJMP+1
t1_SelfModJMP:
	jmp	t1_TComp
;	START_SAMEPAGE	"T1COMP"

t1_TComp:
	.byte	$a9,$a9,$a9,$a9,$a9,$a9
	.byte	$a9,$a9,$a9,$a9,$24,$ea
;	END_SAMEPAGE

	lda	InterruptTab
	sta	$9128
	lda	InterruptTab+1
	sta	$9129	;load T2
	lda	#$00
	sta	Line
	jsr	Update

	jsr	VertBlanking
	.IF	DEBUG2
	lda	t1_SelfModJMP+1
	sec
	sbc	#<t1_TComp
	tax
	lda	#$01
	sta	$5100,x	
	.ENDIF ;DEBUG2
	rts

T2Timeout:
	lda	#[$c0+[<t2_TComp]]&255
	sec
	sbc	$9128	;$ba-$bd (for PAL)
	sta	t2_SelfModJMP+1
t2_SelfModJMP:
	jmp	t2_TComp
;	START_SAMEPAGE	"T2COMP"
;	.align $100
t2_TComp:
	.byte	$a9,$a9,$a9,$a9,$a9,$a9
	.byte	$a9,$a9,$a9,$a9,$24,$ea
;	END_SAMEPAGE

	lda	TimeLow
	sta	$9128
	lda	TimeHigh
	sta	$9129

SelfModJSR:
	jsr	SelfModJSR

	.IF	DEBUG2
	lda	t2_SelfModJMP+1
	sec
	sbc	#<t2_TComp
	tax
	lda	#$01
	sta	$5000,x	
	.ENDIF ;DEBUG2
Update:
	lda	Line
	inc	Line
	asl
	asl
	tax
	lda	InterruptTab+4,x
	sta	TimeLow
	lda	InterruptTab+5,x
	sta	TimeHigh
	lda	InterruptTab+2,x
	sta	SelfModJSR+1
	lda	InterruptTab+3,x
	sta	SelfModJSR+2
	rts ;$2095

TimeLow:
	.byte	0
TimeHigh:
	.byte	0
Line:
	.byte	0
InterruptTab: ;$2099 $13 $54
	.word	ROWTIME*70-COMPTIME,Rast0
	.word	-1,-1
PS: revision anyone? ;)

Re: Resetting IRQs

Posted: Mon Feb 05, 2024 1:40 pm
by heaven6502

Code: Select all

    .align $100
InterruptInit:
;save the registers
	ldx #31
@
	lda $9110,x
	sta $b9e0,x
	dex 
	bpl @-

;	IF	RESTOREDISABLE
	lda	#%00000010
	sta	$911e	;No RestoreKey
	sta	$911d
;	ENDIF

	lda	#$7f
	sta	$912e
	sta	$912d
	lda	#%11100000
	sta	$912e
	lda	#%01000000
	sta	$912b
	lda	#<IRQServer
	sta	$0314
	lda	#>IRQServer
	sta	$0315

	jsr	Stab	;Find Fixpoint!!! (VertBlank)

	lda	#<SCREENTIME
	sta	$9124
	lda	#>SCREENTIME
	sta	$9125	;load T1
	rts

Re: Resetting IRQs

Posted: Mon Feb 05, 2024 1:41 pm
by heaven6502
i used those routines back 2018 in Gnork! demo and never run into that issue that it fcks up the trackloader...

Re: Resetting IRQs

Posted: Mon Feb 05, 2024 4:30 pm
by Mike
heaven6502 wrote:

Code: Select all

;save the registers
	ldx #31
@
	lda $9110,x
	sta $b9e0,x
	dex 
	bpl @-
That idiom isn't all that helpful to restore the state of the VIAs later - some of the registers (most notably the IER!) react differently to writes than to reads.

Instead I'd simply do a SEI, then clear both IERs with LDA #$7F:STA $911E:STA $912E and finally call JSR $FDF9 in the KERNAL. That routine then (re-)inits the VIAs to a known good state.
PS: revision anyone? ;)
Look here and leave a short comment in that thread. :mrgreen:

Re: Resetting IRQs

Posted: Tue Feb 06, 2024 3:09 am
by heaven6502
Tried that but when I call the rom routine the starting of next part was stopping. So could be something different there after the trackloader. Those 2 IRQs are not used for IO? As Atari guy the sound chip is envolved into IO that's why I am asking dumb questions.

Re: Resetting IRQs

Posted: Tue Feb 06, 2024 3:47 am
by Mike
heaven6502 wrote:Those 2 IRQs are not used for IO?
The two VIA #2 timers control the timing of either the KERNAL IRQ (keyboard, jiffy clock, tape motor control) or the timing of tape load (T1 only) and save (T1 and T2). The VIA #1 timers produce NMIs (mostly for RS232 operations).

It is somewhat possible to run standard IEC I/O alongside VIA#2 T1 IRQs, however as the KERNAL does block IRQs at certain time-critical points, the interrupt routine will be disturbed.

Some time ago I wrote a demonstrator that used both VIA#1 T1 and T2 to do multiple 'raster' IRQs per frame (T1 for sync, T2 for the actual work) - I need to check (in VICE) whether T2 might collide with IEC I/O.
As Atari guy the sound chip is envolved into IO that's why I am asking dumb questions.
There are no dumb questions ... :wink:

The VIC chip does the sound, there's no I/O involved here. Maybe you overwrote some vital data in OS workspace?

Re: Resetting IRQs

Posted: Tue Feb 06, 2024 3:54 am
by heaven6502
Now as you mention OS space 😂 I am used to no OS in the way as switched off on C64/Atari800 anyway 😂.

But good point to check.

Is there a vice version which has a history in debugger to have more clue?

Re: Resetting IRQs

Posted: Tue Feb 06, 2024 8:58 am
by groepaz
use "chis" in the monitor. its enabled by default in any half recent build

Re: Resetting IRQs

Posted: Wed Feb 07, 2024 2:40 pm
by heaven6502
ok... i kicked out everything from the loader part which has IRQ influence.

Code: Select all

	lda #10
	jsr vsync

	sei
	lda #$7f
	sta $911e
	sta $912e
	jsr $fdf9 ;reset i/o ;seems this is necessary --> $314/$315 is default
	lda	#<22150
	sta	$9124
	lda	#>22150
	sta	$9125

	lda #<$0114
	sta $314
	lda #>$0114
	sta $315

	cli

	lda #<$5a00 ;startadress
	sta $0112
	lda #>$5a00
	sta $0113

	jmp $100 ;load next part

then I did the above code... at $0114 is music player jsr $xxxx and the jump to the rom routine to $eb15.

the music plays still at normal speed but the track loader stops to load next part....I have no clue now... the head moves to track 18 which is the directory and remains...

Re: Resetting IRQs

Posted: Wed Feb 07, 2024 2:41 pm
by heaven6502
CHIS shows in monitor

loop BIT $911f
BNE loop

in the track loader part...

Re: Resetting IRQs

Posted: Wed Feb 07, 2024 4:37 pm
by groepaz
I'd just ask Krill to port his loader... 8)