Interrupts in com files

Everything about programming, including VDP and Sound programming.
Post Reply
under4mhz
Posts: 27
Joined: 11 Apr 2021 05:12
Location: Brisbane, Australia
Contact:

Interrupts in com files

Post by under4mhz »

I'd like to move from using run files to com files, so I can have access to more memory for some of my games.

When I moved to the com format, interrupt stop being run.

I've been setting 0xfa98 to jp my_isr, which works well. But when I moved to using .com files, it doesn't work.

I've also tried setting 0x38 to jp my_isr, but that isn't being run either. I've check the memory address, and it's been set correctly. Interrupts are enabled.

Normally I would run it in mame and check, but I don't know how to load and run com files into mame.

Any suggestions?
Support me on Patreon: https://www.patreon.com/Under4Mhz
Bill B
Posts: 339
Joined: 26 Jan 2014 16:31

Re: Interrupts in com files

Post by Bill B »

Interrupts from VDP or CTC?
  • Have you set the interrupt enable bit on the VDP if that is what you are using?
  • Have you configured the CTC to generate an interrupt, either on a pulse from the VDP, or on a time elapsed?
  • Which interrupt mode is the Z80 in?
  • What is the I register set to?
  • What interrupt vector have you loaded in the CTC?
Try running on MEMU using -diag-z80-interrupts.
Martin A
Posts: 594
Joined: 09 Nov 2013 21:03

Re: Interrupts in com files

Post by Martin A »

The MTX boot sequence passes control to the CPM rom very early.

The relevant part are extracted below.

0194 setup base memory map to page 0 of ROM mode.
019C test how many RAM pages are present
01B1 clear the fixed ram
01C2 check/set the international keyboard settings
01CB minimal system variables setup
01E3 detect and start any auto boot roms

CPM takes control at thre autoboot stage, and doesn't return to the OS in ROM

Other than interrupts being disabled immediately, nothing is done with the CTC or the interrupt mode. So on a cold boot you're in mode 0, on a reset, probably mode 2.

The CPM boot roms for CFX etc will disable the CTC, just in case. But they don't set up any interrupt vectors as CPM doesn't use them.

Code: Select all

                            ;rst0
0000        F3              DI
0001        AF              XOR  A
0002        21 00 40        LD   HL,&4000
0005        C3 94 01        JP   initial
                            
                            
                            
                            .initial
0194        32 D2 FA        LD   (PAGE),A
0197        D3 00           OUT  (&00),A
0199        08              EX   AF,AF'
019A        06 08           LD   B,&08
                            .fill
019C        70              LD   (HL),B
019D        23              INC  HL
019E        10 FC           DJNZ fill
01A0        01 01 08        LD   BC,&0801
                            .test
01A3        2B              DEC  HL
01A4        7E              LD   A,(HL)
01A5        A9              XOR  C
01A6        20 09           JR   NZ,zeroz
01A8        0C              INC  C
01A9        10 F8           DJNZ test
01AB        08              EX   AF,AF'
01AC        3C              INC  A
01AD        FE 10           CP   &10
01AF        20 E3           JR   NZ,initial
                            .zeroz
01B1        21 00 C0        LD   HL,&C000
01B4        11 01 C0        LD   DE,&C001
01B7        01 FF 3F        LD   BC,&3FFF
01BA        AF              XOR  A
01BB        77              LD   (HL),A
01BC        ED B0           LDIR
01BE        08              EX   AF,AF'
01BF        32 7A FA        LD   (LSTPG),A
01C2        DB 06           IN   A,(&06)
01C4        E6 0C           AND  &0C
01C6        1F              RRA
01C7        1F              RRA
01C8        32 45 FB        LD   (CTYSLT),A
01CB        01 18 00        LD   BC,&0018
01CE        21 7C 01        LD   HL,copyblk
01D1        11 8A FA        LD   DE,USER+1
01D4        ED B0           LDIR
01D6        21 0A 09        LD   HL,cdata
01D9        0E 1A           LD   C,&1A
01DB        11 4B FD        LD   DE,RICHJL
01DE        ED B0           LDIR
01E0        31 48 FD        LD   SP,SETCALL
01E3        3E 10           LD   A,&10
01E5        F5              PUSH AF
                            
                            .rmlp
01E6        F1              POP  AF
01E7        C6 10           ADD  A,&10
01E9        FE 80           CP   &80
01EB        28 18           JR   Z,basics
01ED        32 D2 FA        LD   (PAGE),A
01F0        D3 00           OUT  (&00),A
01F2        F5              PUSH AF
01F3        06 08           LD   B,&08
01F5        21 FF 1F        LD   HL,&1FFF
                            .tstlp
01F8        23              INC  HL
01F9        7E              LD   A,(HL)
01FA        B8              CP   B
01FB        20 E9           JR   NZ,rmlp
01FD        10 F9           DJNZ tstlp
01FF        CD 10 20        CALL &2010         ;auto run rom entry point
0202        18 E2           JR   rmlp
under4mhz
Posts: 27
Joined: 11 Apr 2021 05:12
Location: Brisbane, Australia
Contact:

Re: Interrupts in com files

Post by under4mhz »

I've been mostly working on MSX, where the VDP interrupt is connected directly to the z80. I forgot about the CTC.

I don't suppose you have a code snippet to set up the CTC to pass on VDP interrupts?

I'd prefer to run the z80 in interrupt mode 1, if possible.
Support me on Patreon: https://www.patreon.com/Under4Mhz
Bill B
Posts: 339
Joined: 26 Jan 2014 16:31

Re: Interrupts in com files

Post by Bill B »

The CTC (like most Z80 peripherals) is really only designed to work with mode 2 interrupts.

Something like:

Code: Select all

ctc0    equ     0x08

cfgctc: di
        im      2
        ld      a, #0xC5
        out     (ctc0), a       ; Counter mode, interrupt, time constant follows.
        ld      a, #1
        out     (ctc0), a       ; Interrupt on every VDP pulse
        ld      hl, #ijtbl
        ld      a, l
        out     (ctc0), a       ; Interrupt vector
        ld      a, h
        ld      i, a            ; High byte of address
        ei
        ret

        .align  8
ijtbl:  dw      my_isr          ; CTC channel 0 interrupt address
        dw      0               ; CTC channel 1 interrupt address
        dw      0               ; CTC channel 2 interrupt address
        dw      0               ; CTC channel 3 interrupt address
Remember to end your interrupt routine with RETI.
under4mhz
Posts: 27
Joined: 11 Apr 2021 05:12
Location: Brisbane, Australia
Contact:

Re: Interrupts in com files

Post by under4mhz »

Thanks, that worked. For anyone interested, the code for sdas (sdcc's assembler) is:

Code: Select all

    .globl    _vdu_isr

ctc0 = 0x08

cfgctc:
    di
    im    2
    ld    a, #0xC5
    out   (ctc0), a       ; Counter mode, interrupt, time constant follows.
    ld    a, #1
    out   (ctc0), a       ; Interrupt on every VDP pulse
    ld    hl, #ijtbl
    ld    a, l
    out   (ctc0), a       ; Interrupt vector
    ld    a, h
    ld    i, a            ; High byte of address
    
    .bndry 8
ijtbl:
    .dw      _vdu_isr        ; CTC channel 0 interrupt address
    .dw      0               ; CTC channel 1 interrupt address
    .dw      0               ; CTC channel 2 interrupt address
    .dw      0               ; CTC channel 3 interrupt address
As, you said, I had to change the interrupt service routine to end with RETI.
Support me on Patreon: https://www.patreon.com/Under4Mhz
Post Reply