FS and HS interrupt flags

Hardware Hacking, Programming and Game Solutions/Cheats
gacaffe
Posts: 6
Joined: Sun Dec 06, 2015 7:41 pm
Location: Madrid

FS and HS interrupt flags

Post by gacaffe » Fri Dec 02, 2016 11:29 pm

Hi guys,

I am writing a test routine to increase two counters. Counter CHS is increased with the HS interrupt (falling edge) and the other counter (CFS) with the FS interrupt (rising edge).
First, I set the interrupts:

Code: Select all

ORCC #$10 ; Disable IRQ
; set hsync interrupt
;set bit 0 of P0CRB (enable FS IRQs)
;clear bit 1 of P0CRB to get IRQs on the falling edge
		LDA P0CRB
		ANDA #$FD
		ORA #%01
		STA P0CRB

;set bit 0 of P0CRA (enable HS IRQs)
;Set bit 1 of P0CRA to get IRQs on the rising edge

		LDA P0CRA
		ORA #%11
		STA P0CRA
		

		lda P0PDRA ; clear IRQ
		lda P0PDRB ; clear IRQ
		
		LDA P0CRB
		
		LDX #HIRQ   ; Set up entry address
		STX $10D     ; and store into IRQSV

                ANDCC #$EF   ; Enable IRQ
The ISR is the following:

Code: Select all

HIRQ	PSHS A, X
               ORCC #$10    ; Disable IRQ
	
		LDA P0CRB
		BITA #$80	; check if FS
		BEQ NO_FS	; if not set...
		
		INC CFS
		
NO_FS	LDA P0CRA
		BITA #$80	; check if HS
		BEQ NO_HS	; if not set...
		
		INC CHS
        
NO_HS 	LDA P0PDRA  ; clear HS interrupt flag
                LDA P0PDRB  ; clear FS interrupt flag
		ANDCC #$EF   ; Enable IRQ 

		PULS A, X
		RTI
And finally, I tested if it is counting like this:

Code: Select all

INFL    LDA CHS
		SUBA #100
		BNE INFL
        LDA screen1+8
		EORA #$FF
		STA screen1+8
		LDA CFS
		SUBA #100
		BNE INFL
        LDA screen1+16
		EORA #$FF
		STA screen1+16
		BRA INFL
Thus, there is a byte (at screen+8) blinking every two seconds due to the frame sync, and another byte (at screen+16) is blinking much more faster (and out of frame synchronization).

Ok, I have two question:
i) I disabled the HS interrupt and I kept the ISR as above. I was surprised to see that the HS flag is always '1', so the counter CHS is being increased (at the rate of the FS). Is that supposed to be the right behaviour? Why is the flag '1' at all?

ii) I need to know the exact timing of both the HS and FS sync signals. Where can I get that information for Dragon 32 and Dragon 64?

Cheers
A bit of this, a byte of that

http://biolab.uspceu.com/~gabriel/retro.htm
@gacaffe

User avatar
robcfg
Posts: 1221
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden

Re: FS and HS interrupt flags

Post by robcfg » Sat Dec 03, 2016 11:00 pm

Hi Gabriel, welcome to the Dragon Archive!

I cannot answer your question but it's possible that the behaviour of the FS/HS signal is slightly different across several Dragon board revisions.

If you take a look at our board scans, there's a Dragon 32 one (PC10087 Issue 6 P/N 48127) that has a daughterboard (P/N 48200) that is supposed to correct some timing issues in order to provide better picture quality which may be FS/HS related.

That fix seems to be later included in the Dragon 64 boards.

As you're also in Madrid, I can help you test your program on several Dragon models and if you like to, we can meet and talk on the subject.

New users have private messaging disabled until a number of posts is reached, but I'll ask Rolf to enable this for you.

Besides the board scans, you can also check the schematics.

Cheers,
Rob

gacaffe
Posts: 6
Joined: Sun Dec 06, 2015 7:41 pm
Location: Madrid

Re: FS and HS interrupt flags

Post by gacaffe » Sun Dec 04, 2016 11:43 am

Thanks robcfg!

It's a bit worrying that the video timing changes from board to board. Anyway, I think I forgot to mention some important points:
1. I am using Xroar to do the test. I do have a Dragon 64 (made in Wales), so at some point I will test the code in this machine.
2. What I need is the following:
- A timer based on FS so that I can use double buffering
- A much faster timer based on HS, so I can generate music.

So my main concerned is about the HS interrupt, since I read somewhere (maybe here :D ) that the timing changes from D32 to D64, but I didn't expect to change between board revisions. So...
robcfg wrote: As you're also in Madrid, I can help you test your program on several Dragon models and if you like to, we can meet and talk on the subject.
What I need is to use the HS interrupt so that it works more or less fine in all D32 and D64 computers. My idea is to count the HS ints and generate a quasi-periodic signal that I can use to generate music. Given that the video time is not consistent, I will be satisfy if the periodic int does not have a huge error and that it does not disturb the music quality a lot. So, yes, at some point it will be great if you can help me to test the programs in different dragons, but it will take a while before that is needed.
robcfg wrote: Besides the board scans, you can also check the schematics.
This is great! I think that the info I was asking for is in the MC6847 data sheet. Thanks!

About private messages, I am also a user of zonadepruebas (gacaffe) so we can communicate through that. I try to attend to RetroParla events, so maybe we can meet there and bring some Dragon machines to play with. (I wonder, have we met at all?)

OK. I will post more as I progress with my "experiments".

Cheers,

Gabriel
A bit of this, a byte of that

http://biolab.uspceu.com/~gabriel/retro.htm
@gacaffe

sixxie
Posts: 1061
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: FS and HS interrupt flags

Post by sixxie » Sun Dec 04, 2016 12:56 pm

Re the HS being flagged even when disabled: food for thought; this could be a bug in XRoar. The interrupt received line of the control register is always updated in the PIA code, even if the IRQ isn't signalled to the CPU.

It's been that way (bar a brief period from about July 2005, where it was replaced by more egregious bugs) for as long as XRoar's been in version control (checking further: since 0.10 in 2004!). Very weird that nothing else has ever shown this up - need to get the real hardware out to verify!

gacaffe
Posts: 6
Joined: Sun Dec 06, 2015 7:41 pm
Location: Madrid

Re: FS and HS interrupt flags

Post by gacaffe » Sun Dec 04, 2016 5:22 pm

sixxie wrote:Re the HS being flagged even when disabled: food for thought; this could be a bug in XRoar. The interrupt received line of the control register is always updated in the PIA code, even if the IRQ isn't signalled to the CPU.

It's been that way (bar a brief period from about July 2005, where it was replaced by more egregious bugs) for as long as XRoar's been in version control (checking further: since 0.10 in 2004!). Very weird that nothing else has ever shown this up - need to get the real hardware out to verify!
Sixxie,

It might be that this is the right behaviour of the MC6821. In the datasheet, when it explain CRA and CRB it says that the flags indicate if lines CA1/2, CB1/2 performed an "active transition" if they are set as inputs. It doesn't say that the flag must be disable if the interrupt is disable. CA1 and CB1 are always inputs, so HS is always setting the flag with disregard of the inputs issuing the interrupt IRQA. So after all, I think that this is the normal behaviour and there is no bug in Xroar and whatsoever.

For me it sound good, since it is possible to poll the FS/HS flags to check the state of the sync signals without using interrupts.

Does this sound OK?

Gabriel
A bit of this, a byte of that

http://biolab.uspceu.com/~gabriel/retro.htm
@gacaffe

sixxie
Posts: 1061
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: FS and HS interrupt flags

Post by sixxie » Mon Dec 05, 2016 8:55 pm

I hope you're right. It seems like the sort of thing I would have tested, but that was so long ago and oh look didn't take notes ;)

(Absent-mindedness is a good way to make sure you always need to be doing things on your Dragon though)

simon
Posts: 159
Joined: Wed Nov 27, 2013 8:56 pm

Re: FS and HS interrupt flags

Post by simon » Tue Dec 06, 2016 4:31 pm

HS/FS will always be flagged in $ff01/03 even with the interrupts disabled via orcc #$nn

this is useful behaviour for *polling* an irq instead of having a vectored irq at $10c

the costs of a vectored irq are prohibitive as the 6809 stacks all the registers... thus a polled irq (using the flags at $ff01/03) is alot cheaper... (just remember to ACK) the irq (lda$ff00/$ff02) or else they wil stack up on you

/Simon :-)

gacaffe
Posts: 6
Joined: Sun Dec 06, 2015 7:41 pm
Location: Madrid

Re: FS and HS interrupt flags

Post by gacaffe » Fri Dec 09, 2016 6:59 pm

Thank you Simon,

I am concerned about your comment on polling instead of using an ISR.
simon wrote: the costs of a vectored irq are prohibitive as the 6809 stacks all the registers... thus a polled irq (using the flags at $ff01/03) is alot cheaper... (just remember to ACK) the irq (lda$ff00/$ff02) or else they wil stack up on you
I would like to program a game with scroll and music (at least two channels) and I was thinking on using the HS interrupt to update the DAC at 1 KHz. I do not see how I can do that by polling, specially because scrolling and sprite drawing are going to take several frames and I really need to interrupt to send a new data to te DAC. I am going to try anyway, bu any ideas are welcome.

I was thinking of a shmup. I can always give up real scroll and just move some stars downwards, but I do want to have nice music in the game. I think that there are no many Dragon games with music or good sound effects (by the way, if you know of any please tell).

Thanks a lot!

Gabriel
A bit of this, a byte of that

http://biolab.uspceu.com/~gabriel/retro.htm
@gacaffe

simon
Posts: 159
Joined: Wed Nov 27, 2013 8:56 pm

Re: FS and HS interrupt flags

Post by simon » Sat Dec 10, 2016 9:10 am

Hi Gabriel....

you can do it another way if you want to.....

if you know what frequency the noteplayer has to be serviced at, then you can interleave some jsr's into your code at regular intervals...

i do just that in this demo:

https://www.youtube.com/watch?v=prkZSet3MbM

this is 2 voice music being played at around 3.5Khz

gacaffe
Posts: 6
Joined: Sun Dec 06, 2015 7:41 pm
Location: Madrid

Re: FS and HS interrupt flags

Post by gacaffe » Sat Dec 10, 2016 12:45 pm

Amazing stuff Simon.

simon wrote:Hi Gabriel....

you can do it another way if you want to.....

if you know what frequency the noteplayer has to be serviced at, then you can interleave some jsr's into your code at regular intervals...

i do just that in this demo:

https://www.youtube.com/watch?v=prkZSet3MbM

this is 2 voice music being played at around 3.5Khz
I knew it wasn't going to be easy... Thanks for the tip.

Cheers,

Gabriel
A bit of this, a byte of that

http://biolab.uspceu.com/~gabriel/retro.htm
@gacaffe

Post Reply