interrupts in dot commands

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

User avatar
sol_hsa
Posts: 273
Joined: Fri Jun 02, 2017 10:10 am
Location: Finland
Contact:

Re: interrupts in dot commands

Postby sol_hsa » Mon Apr 27, 2020 7:45 pm

SevenFFF wrote:
Mon Apr 27, 2020 7:18 pm
I think you're making it much more complicated that it needs to be.
...
Same thing as with sdcc vs z88dk, really. You're making a rod for your own back by trying to reinvent the wheel with your own more complicated techniques.
Maybe I want to make things complicated ;) or to be more precise, I want to build simple tools that I can understand.

Reinventing the wheel is fun, and once you've done so, when you have problems you're more likely to figure them out.

I really do wonder why my IM2 routine isn't triggering. I allocate a new page and map it to mmu7, and then put the hop table there. The way I see it, it should either work or crash - but it does not seem to be doing either, as if the interrupt didn't happen.

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: interrupts in dot commands

Postby SevenFFF » Mon Apr 27, 2020 8:04 pm

Indeed! There’s no reason why IM2 shouldn’t work inside a dot command. I will hack it into one of my commands in a while to confirm whether it works.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: interrupts in dot commands

Postby SevenFFF » Mon Apr 27, 2020 8:10 pm

I just saw what you said about M1 NMIs. Those are disabled while dot commands are running, as the Multiface hardware is not fully compatible with the divMMC hardware (it never was, even with physical add-ons).

For that reason it’s much easier to write and debug dot commands on an emulator running full NextZXOS than it is on the board. I debug mine in CSpect and find it very convenient.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: interrupts in dot commands

Postby SevenFFF » Mon Apr 27, 2020 8:53 pm

I added a simple IM2 routine that cycles between two border colours to one of my dot commands. It works fine, without needing to do anything special to enable it.

Here's the code, for what it's worth. Nothing particularly special.

You are actually copying the ISR and the 257 byte table into higher RAM, are you? NextZXOS won't put it there for you, it will only load 8K of code into 2000-3FFF.

Code: Select all

org $2000
Start:
                        di
                        ld a, $fd
                        ld i, a
                        im 2
                        FillLDIR($fd00, 257, $fe)
                        CopyLDIR(ISR, $fefe, ISRLen)
                        ei
                        jr $-2

TestColour:             db 1                            ; blue

ISR:                    ld a, (TestColour)
                        out ($fe), a
                        xor 3                           ; Flips between red and blue every time ISR is run
                        ld (TestColour), a
                        ei
                        reti
ISRLen equ $-ISR


FillLDIR                macro(SourceAddr, Size, Value) ; Parameterised wrapper for LDIR fill
                        ld a, Value
                        ld hl, SourceAddr
                        ld (hl), a
                        ld de, SourceAddr+1
                        ld bc, Size-1
                        ldir
mend

CopyLDIR                macro(SourceAddr, DestAddr, Size) ; Parameterised wrapper for LDIR copy
                        ld hl, SourceAddr
                        ld de, DestAddr
                        ld bc, Size
                        ldir
mend
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
sol_hsa
Posts: 273
Joined: Fri Jun 02, 2017 10:10 am
Location: Finland
Contact:

Re: interrupts in dot commands

Postby sol_hsa » Tue Apr 28, 2020 5:11 am

Well, I found ONE bug that explains why my interrupts weren't triggering, can you spot it?

Code: Select all

...
    ld  (hl),   e
    inc hl
    ld  (hl),   d
    im  2           ; set the interrupt mode (remember to change back before you exit)

;extern void closeisr7()
_closeisr7::
    im  1
    ret
I've managed to get the system to crash now in a controlled manner even, so I know the interrupts do trigger. Now just to get them to actually work..

User avatar
sol_hsa
Posts: 273
Joined: Fri Jun 02, 2017 10:10 am
Location: Finland
Contact:

Re: interrupts in dot commands

Postby sol_hsa » Tue Apr 28, 2020 6:02 am

..and now it works, was missing di/ei guards in my interrupt routine. Did not expect to need them when I was just saving registers in stack and incrementing one value, but apparently things blew up without them.

Thanks for the help, I think I have everything in place now to start doing some actual stuff.

User avatar
sol_hsa
Posts: 273
Joined: Fri Jun 02, 2017 10:10 am
Location: Finland
Contact:

Re: interrupts in dot commands

Postby sol_hsa » Tue Apr 28, 2020 6:06 am

For the record, now I have custom text output, keyboard input, disk i/o, memory allocations, memory mapping and raster interrupt going on in a dot executable. I guess I should clean this up and put in in github.

Ped7g
Posts: 256
Joined: Mon Jul 16, 2018 7:11 pm

Re: interrupts in dot commands

Postby Ped7g » Tue Apr 28, 2020 7:32 am

it's basically impossible you need DI+EI if your handler is quick enough to not re-enter (or at least quick enough to resolve the re-entrance over time without filling up stack too much). Maybe you triggered both ULA + scanline in quick succession?

But EI itself is needed, you get DI for free upon entering maskable interrupt from the CPU. it's Z80 feature. So if you don't do EI, you will stay with interrupts disabled after the first handler return.

But if you have short handler and it does crash without DI on start, then something is still wrong about your setup.

And you can return from interrupt with "ei + ret", the "reti" is identical to ret but it has two bytes. It was meant to be individual opcode (reti/retni) so any external device listening on the bus can see the reti/retni opcode was executed and do it's own agenda upon "interrupt handling was finished", but in your own im2 handler you probably don't care about external devices. (I'm not even aware of any ZX device using this feature, but then again I'm heavily HW ignorant person)

(btw your code did miss the RET so it did go into IM1 setup).

I think these experiments are not visible in the github you have in signature? Sometimes it may be easier to just post here some link to full project (as long as I can easily build it with sjasmplus, I could debug it in few seconds then...)

User avatar
sol_hsa
Posts: 273
Joined: Fri Jun 02, 2017 10:10 am
Location: Finland
Contact:

Re: interrupts in dot commands

Postby sol_hsa » Tue Apr 28, 2020 8:27 am

Ped7g wrote:
Tue Apr 28, 2020 7:32 am
But EI itself is needed, you get DI for free upon entering maskable interrupt from the CPU. it's Z80 feature. So if you don't do EI, you will stay with interrupts disabled after the first handler return.
Ah, that explains it. Without EI the interrupt triggered once. The DI isn't needed.
Ped7g wrote:
Tue Apr 28, 2020 7:32 am
And you can return from interrupt with "ei + ret", the "reti" is identical to ret but it has two bytes.
I've used 'ret' to end interrupt handler on the 48k speccy but I figured it will be safer to use reti on the next as there may be some peripherals that care. I don't know if there are.
Ped7g wrote:
Tue Apr 28, 2020 7:32 am
(btw your code did miss the RET so it did go into IM1 setup).
Yup, that was the bug.
Ped7g wrote:
Tue Apr 28, 2020 7:32 am
I think these experiments are not visible in the github you have in signature? Sometimes it may be easier to just post here some link to full project (as long as I can easily build it with sjasmplus, I could debug it in few seconds then...)
I've posted the projects on the github in the sig now. Not easily compilable with sjasmplus because for some reason sdcc has its own assembler syntax. (Personally I have no preference in assembler syntax, and I'd rather use a syntax everybody else was using.. maybe I should just write a transpiler)

Ped7g
Posts: 256
Joined: Mon Jul 16, 2018 7:11 pm

Re: interrupts in dot commands

Postby Ped7g » Tue Apr 28, 2020 8:38 am

you can't easily transpile z88dk/z80asm to sjasmplus, I was already taking a look, and there are certain features of z88dk/z80asm which are simply not compatible with sjasmplus, the way how it deals with local symbols and linking vs sjasmplus modules and local labels.

Anyway, with small sources like your initial prototypes, I guess I would be able to assemble it and run in my own variant to just figure out what your asm part does, plus I often need just to read the source to spot some issues, actual debugging is like last-resort for me, it used to be so time consuming on old platforms, that I still prefer to think about the problem first in head, even if lately with the current tools and setups it's actually surprisingly fast to "just launch CSpect with -debug and see it", but I'm still not used to it. Usually I just write the source without the bugs, so I don't have to debug (but it takes me 10x longer time than just writing "something" and then debugging it). :) .. difficult to get it right (productivity vs quality), at least for me, I'm usually very wrong on this. :)


Who is online

Users browsing this forum: No registered users and 3 guests