Information on NMI's, INT's and timings...

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Information on NMI's, INT's and timings...

Post by bobs »

Can somebody shed some light on how the ZX81 handles, and what can be done with, NMIs & interupts?

From what I've read, IM1 is used to handle the screen redraw, and so if I choose to do my own interupts I'd also have to code my own display update? And presumably if I use the DI instruction I'd lose redraw? Does that make sense? What does the HALT instruction to in these circumstances?

I also seem to remember reading that I can disable the NMI if I want via a port call. What effect would that have?

Siggi has mentioned that in another thread that USA (Timex) 81s' run at 60fps, and so I could use the MARGIN (16424) system variable to ensure a constant rate? I assume IM1 is involved in updating that value?

Any help much appreciated!
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Information on NMI's, INT's and timings...

Post by siggi »

Hi Bobs
forget to use /NMI or /INT with a ZX81!
Both /INT and /NMI are used to make the correct timing for the display. And the interrupt routines use the IX and IY registers, so you should not touch them in "normal" programs (IX is modified for HIRES).

For details of the display generation: Wilf wrote a tutorial with a lot of details ...

http://www.user.dccnet.com/wrigter/inde ... torial.htm

If you switch to FAST mode, the NMI-generator in the ULA is deactivated. That is necessary for time critical progams (like SAVE and LOAD from tape). But it disables the display :o

The HALT instruction is used during display (and enabled INT) to wait for the end-of-line-condition counted by the R register -> causes an INT

HTH Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Information on NMI's, INT's and timings...

Post by siggi »

bobs wrote: From what I've read, IM1 is used to handle the screen redraw, and so if I choose to do my own interupts I'd also have to code my own display update?
Yes and No.
No, because Wilf already did it: he wrote his own (LORES) display routine "NOVA", which allows to integrate own code (a user interrupt routine), which is called regularly during display. See:

http://www.user.dccnet.com/wrigter/inde ... va2005.htm

Yes, if NOVA does not help ;)

Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Information on NMI's, INT's and timings...

Post by bobs »

Cheers for the input & links, will have a read of them today.
User avatar
Thunor
Posts: 42
Joined: Sun Oct 11, 2009 11:37 am
Location: Anglia
Contact:

Re: Information on NMI's, INT's and timings...

Post by Thunor »

For timing I'm currently calling a routine at the bottom of my main loop called timer_tick :-

Code: Select all

; This ticks at 25Hz on a 50Hz ZX81.

timer_tick:     ld      a,(FRAMES)
                and     1
                jr      nz,timer_tick
                ret
My game would then run at 30Hz on a 60Hz machine -- 20% faster -- so is there a better way to deal with this?

Cheers,
Thunor
User avatar
thewiz
Posts: 58
Joined: Sun Aug 16, 2009 8:36 pm
Location: Crewe

Re: Information on NMI's, INT's and timings...

Post by thewiz »

Hi Thundor,

If you wanted more flexibility with the way the ZX81 generates it's display, have a look at the driver I've started developing. It allows adding Interrupt service routines and will eventually free up the IY register. Take a look at the end of the "Developing new ZX81 Video Driver" thread in this forum. Its aimed at games written in M/C.
Memotech rules
User avatar
Thunor
Posts: 42
Joined: Sun Oct 11, 2009 11:37 am
Location: Anglia
Contact:

Re: Information on NMI's, INT's and timings...

Post by Thunor »

thewiz wrote:Hi Thunor,

If you wanted more flexibility with the way the ZX81 generates it's display, have a look at the driver I've started developing. It allows adding Interrupt service routines and will eventually free up the IY register. Take a look at the end of the "Developing new ZX81 Video Driver" thread in this forum. Its aimed at games written in M/C.
Thanks thewiz

Actually I found MARGIN which holds 31 for US machines and 55 for UK, so at least I can make allowances knowing that. I found it whilst researching how to identify more than one key being pressed, my next mountain to climb :)
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Information on NMI's, INT's and timings...

Post by bobs »

Personally I simply read the MARGINS variable, and if running on a 50Hz machine delay for a little while until it is roughly the speed of the 60Hz machine.

As for reading more than one key at once, you need to read from port 254.
User avatar
Thunor
Posts: 42
Joined: Sun Oct 11, 2009 11:37 am
Location: Anglia
Contact:

Re: Information on NMI's, INT's and timings...

Post by Thunor »

bobs wrote:Personally I simply read the MARGINS variable, and if running on a 50Hz machine delay for a little while until it is roughly the speed of the 60Hz machine.

As for reading more than one key at once, you need to read from port 254.
Cheers bobs. I managed to figure out from the ROM the fefe, fdfe, fbfe etc. in regBC.

So then since the ROM is creating the TV picture and it must create 20% more on a 60Hz machine, does this mean that 60Hz machines ran slower overall? Was BASIC even slower? :?

[EDIT] NTSC has a lower vertical resolution but a higher temporal resolution. I get the idea now.
User avatar
Thunor
Posts: 42
Joined: Sun Oct 11, 2009 11:37 am
Location: Anglia
Contact:

Re: Information on NMI's, INT's and timings...

Post by Thunor »

Thunor wrote:So then since the ROM is creating the TV picture and it must create 20% more on a 60Hz machine, does this mean that 60Hz machines ran slower overall? Was BASIC even slower? :?
I found an awesome document here -> http://nocash.emubase.de/zxdocs.htm#displayoutput

It's from the nocash emulator (I've never heard of this before; runs great in DOSBox; loads of debugging stuff).

It says:

Resulting User Available CPU Time
SLOW, 50Hz Effective Speed 0.820800 MHz (54*2*152 cycles, 50 frames)
SLOW, 60Hz Effective Speed 0.547200 MHz (30*2*152 cycles, 60 frames)
FAST, Total CPU Speed 3.250000 MHz (display disabled)
Post Reply