Bob’s Notebook: TS2068 Interrupts

See all articles from Sinc-Link v3 n5
Author(s): Bob Mitchell
Publication: Sinc-Link
Pub Details: Sinc-Link v3 n5 (Volume 3, Issue 5)
Date: September/October 1985
Pages: 6-7

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 microprocessor 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 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 low 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 second addrress 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) as we are told happens with the Spectrum. One 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 are 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 or AUTOLINE.

Type in listing 3 and run it. If you have made no errors, all DATA lines will be shown as OK. SAVE the program and VERIFY it.

Now RANDOMIZE USR 65024 to create the special block referred to above.

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 proceding.

You should CLEAR 64255 before using the program.

The step between line numbers is set at 10; you can change this: POKE 65192, s where s is the required step.

To alter the next line number, delete the one printed and type in the next number required.

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 is a sample “mother” program used to generate the block of bytes and set up the vectoring.

Listing 2 is the disassembled version of AUTOLINE code.

AUTOLINE was adapted for the TS2068 from a program printed in Your Computer December 1983.

Bob Mitchell Aug 85.

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
FE23 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 DE,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,30
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
FEF0 E1 POP HL
FEF1 F1 POP AF
FEF2 FB EI
FEF3 C9 RET

LISTING 3

   1 REM AUTOLINE
120 LET a=10: 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": VERIFY ""
310 STOP
1000 DATA "C5D5E5F52100FB060036FC2310FB36FC3EC332FCFC2169FE22FDFC3EFBED47F1E1D1C1C900000000000000000000000000000000000000000000000000000000",5520
1001 DATA "0000000000000000000000000000000000000000000000000000000000000000ED5EC900ED56C90000FFF3F5E5D5C53A68FEFE0020273A825CFE2020713A835C",4171
1002 DATA "FE17206A21085C7EFE0C286221045C7EFE0D2804FEFF20563E043268FE3A68FE3D3268FE2A495C110A00190118FCCDD1FEFE032839019CFFCDD1FEFE02282F01",6612
1003 DATA "F6FFCDD1FEFE01282501FFFFCDD1FE181DAF093C38FCED423DC630E521085C773A3B5CCBEF213B5C77E13A68FEC9C1D1E1F1FBC9000000000000000000000000",7492

“On Printing SENSE with DOLLARS”

The following is a short little subroutine which I use to print Dollars and Cents with trailing zeros after the decimal point as required, and a zero before the decimal point when there are no dollars. It also prints a unary minus sign after the figures for negative amounts.

The variable “x” can be assigned a value in your program so that, until changed, it will print the Dollars and Cents in column with the Decimal point in “x” column. Assignment in a For\To loop, for instance, can give you several repeating columns.

Variable “M” must be assigned in your program with the amount you wish to print.

 100 REM PRINT DOLLARS & CENTS
110 LET CN=INT (100*ABS M+.5)-100*INT ABS M
120 PRINT TAB x-1-LEN STR$ INT ABS M;"$";INT ABS M+INT (CN/100);".";("0" AND CN<10);(CN AND CN<100);("0" AND CN=100);("-" AND M<0);
130 RETURN

Contributed by Bob Somerville

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.