Authors
Publication
Pub Details
Date
Pages
The Z80 has three Interrupt modes (IM) two of which are of special interest to the programmer. An “interrupt” is a signal sent to the microprocessог, which generally suspends the execution of the current program without the program being aware of it.
IM1 is the normal operating mode for the TS2068 and when an interrupt occurs, control is passed to address 56 (36h) in the ROM. This ROM routine updates the clock (FRAMES) and reads the keyboard. On exit from the routine, control is passed back to the exact place where the interrupt occurred. These interrupts take place at the rate of 60 per second.
IM2 allows us to divert interrupts to a user-generated routine and thus provides us with a powerful facility with almost limitless uses. This mode is called a vectored interrupt.
When the Z80 receives an IM2 interrupt, it expects the interrupting device (the TS2068 ULA) to place one byte of data on the data bus. This byte acts as the lou order of an address; the high order comes from the I register. These two bytes are concatenated to form an address and the Z80 looks at the contents of this address for a secопd address to which control is vectored.
The problem with the TS2068 is that the low order byte supplied to the Z80 varies from 0 to 255 and is not just 255 (FFh) at we аге told happens with the Spectrum. Опе technique to get around this is to create a block of addresses each filled with the same byte. The I register is changed to point to this block and IM2 is called. No matter what low order byte is supplied to the Z80, the block will produce the same address which will vector control to the start of our user-generated routine.
Meanwhile, the computer is able to carry out its main program as normal and the special routine is also acted upon so that in effect two programs аге operating in tandem. This allows for some interesting applications: digital clock; automatic line numbering; creation of function keys; constant read out of memory left; tracing of BASIC programs; disabling NEW; smooth sprite movement, to name a few.
Provided below is a program with one of these applications: automatic line numbering. Type in listing 2 and run it.
Now RANDOMIZE USR 65024 to create the special block of IM2 vector addresses. Use RANDOMIZE USR 65120 to start the autoline feature and USR 65124 to stop it. If you use NEW, RANDOMIZE USR 65024 and USR 65120 again before proceeding.
Clear 64255 before using the program.
The line number stepping is set to 10; you can change this with POKE 65192, s, where s is the step value.
If the line number exceeds 9999, a colon will be printed in the first position to warn that the line cannot be entered.
Be sure to turn the program off before overwriting any of the code used by the program.
Listing 1 generates the block of bytes required for the IM2 vectoring.
Listing 2 is the assembly language version of the AUTOLINE code.
Listing 1
FE00 C5 PUSH BC
FE01 D5 PUSH DE
FE02 E5 PUSH HL
FE03 F5 PUSH AF
FE04 2100FB LD HL,FB00
FE07 0600 LD B,00
FE09 36FC LD (HL),FC
FE0B 23 INC HL
FE0C 10FB DJNZ FE09
FE0E 36FC LD (HL),FC
FE10 3EC3 LD A,C3
FE12 32FCFC LD (FCFC),A
FE15 2169FE LD HL,FE69
FE18 22FDFC LD (FCFD),HL
FE1B 3EFB LD A,FB
FE1D ED47 LD I,A
FE1F F1 POP AF
FE20 E1 POP HL
FE21 D1 POP DE
FE22 C1 POP BC
FE29 C9 RET
Listing 2
FE60 ED5E IM 2
FE62 C9 RET
FE63 00 NOP
FE64 ED56 IM 1
FE66 C9 RET
FE67 00 NOP
FE68 00 NOP
FE69 FF RST 38
FE6A F3 DI
FE6B F5 PUSH AF
FE6C E5 PUSH HL
FE6D D5 PUSH DE
FE6E C5 PUSH BC
FE6F 3A68FE LD A,(FE68)
FE72 FE00 CP 00
FE74 2027 JR NZ,FE9D
FE76 3A825C LD A,(5C82)
FE79 FE20 CP 20
FE7B 2071 JR NZ,FEEE
FE7D 3A835C LD A,(5C83)
FE80 FE17 CP 17
FE82 206A JR NZ,FEEE
FE84 21085C LD HL,5C08
FE87 7E LD A,(HL)
FE88 FE0C CP 0C
FE8A 2862 JR Z,FEEE
FE8C 21045C LD HL,5C04
FE8F 7E LD A,(HL)
FE90 FE0D CP 0D
FE92 2804 JR Z,FE98
FE94 FEFF CP FF
FE96 2056 JR NZ,FEEE
FE98 3E04 LD A,04
FE9A 3268FE LD (FE68),A
FE9D 3A68FE LD A,(FE68)
FEA0 3D DEC A
FEA1 3268FE LD (FE68),A
FEA4 2A495C LD HL,(5C49)
FEA7 110A00 LD HE,000A
FEAA 19 ADD HL,DE
FEAB 0118FC LD BC,FC18
FEAE CDD1FE CALL FED1
FEB1 FE03 CP 03
FEB3 2839 JR Z,FEEE
FEB5 019CFF LD BC,FF9C
FEB8 CDD1FE CALL FED1
FEBB FE02 CP 02
FEBD 282F JR Z,FEEE
FEBF 01F6FF LD BC,FFF6
FEC2 CDD1FE CALL FED1
FEC5 FE01 CP 01
FEC7 2825 JR Z,FEEE
FEC9 01FFFF LD BC,FFFF
FECC CDD1FE CALL FED1
FECF 181D JR FEEE
FED1 AF XOR A
FED2 09 ADD HL,BC
FED3 3C INC A
FED4 38FC JR C,FED2
FED6 ED42 SBC HL,BC
FED8 3D DEC A
FED9 C630 ADD A,38
FEDB E5 PUSH HL
FEDC 21085C LD HL,5C08
FEDF 77 LD (HL),A
FEE0 3A3B5C LD A,(5C3B)
FEE3 CBEF SET 5,A
FEE5 213B5C LD HL,5C3B
FEE8 77 LD (HL),A
FEE9 E1 POP HL
FEEA 3A68FE LD A,(FE68)
FEED C9 RET
FEEE C1 POP BC
FEEF D1 POP DE
FEEF E1 POP HL
FEF0 F1 POP AF
FEF2 FB EI
FEF3 C9 RET
Listing 3
1 REM AUTOLINE
120 LET a=0: LET b=11: LET C=12: LET d=13: LET e=14: LET f=15
130 LET line=1000
140 LET address=65024+(line-1000)*6.4
150 RESTORE line
160 READ s$,sum
170 LET tot=0
180 LET byte=16*val s$(1)+val s$(2)
190 LET tot=tot+byte
200 POKE address,byte
210 Let s$=s$(3 TO )
220 LET address=address+1
230 IF s$<>"" THEN GO TO 180
240 POKE 23692,255
250 IF sum=tot THEN PRINT "Line ";line;" OK.":LET line=line+1:GO TO 150
260 PRINT "Error in line ";line
270 BEEP .4,-10: Beep .4,-16
280 STOP
300 SAVE "AUTOLINE"
310 STOP
1000 DATA "C5D5E5F52100FB060036FC2310FB36FC3EC332FCFC2169FE22FDFC3EFBED47F1E1D1C1C900000000000000000000000000000000000000000000000000000000",5520
1001 DATA "0000000000000000000000000000000000000000000000000000000000000000ED5EC900ED56C90000FFF3F5E5D5C53A68FEFE0020273A825CFE2020713A835C",4171
1002 DATA "FE17206A21085C7EFE0C286221045C7EFE0D2804FEFF20563E043268FE3A68FE3D3268FE2A495C110A00190118FCCDD1FEFE032839019CFFCDD1FEFE02282F01",6612
1003 DATA "F6FFCDD1FEFE01282501FFFFCDD1FE181DAF093C38FCED423DC630E521085C773A4B5CCBEF213B5C77E13A68FEC9C1D1E1F1FBC9000000000000000000000000",7492
Products
Downloadable Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.