Computus Interruptus, Part 6

Authors

Wes Brzozowski

Publication

Publication Details

Volume: 4 Issue: 3

Date

March - April 1986

Pages

8-10
See all articles from SINCUS v4 n3

Now, it’s time to fire up your T/S 2068. Type in and RUN the listing below. This must be done with the original Timex ROMs in control.

10 REM RUN this program when the TS2068 ROM is in control. It will SAVE the "TS2068 Emulator" program to tape.
20 CLEAR 32767: FOR j=0 TO 16383: POKE j+32768,PEEK j: NEXT J
30 SAVE "EMUL-2068" LINE 60
40 SAVE "emul-2068" CODE 32768,16384
50 STOP
60 CLEAR 32767: LOAD ""CODE 32768
70 OUT 244,192: RESTORE
80 FOR j=23296 to 23307
90 READ k: POKE j,k
100 NEXT j
110 DATA 1,0,64,17,0,192,33,0,128,237,176,201
120 RANDOMIZE USR 23296: OUT 244,0
130 PAUSE 0: RANDOMIZE USR 0

When the program runs, it will SAVE to tape a “TS2068 Enulator” program. The program will take a fairly long time to run before the SAVE message appears, but you only have to do this once to produce the new program, so this is not a real problem.

Once the new program is LOADed in, it will insert a copy of the T/S 2068 code into RAM in the DOCK bank, but it won’t run it, yet. The T/S 2068 Emulator program includes a complete copy of the T/S 2068 HOME ROM code.

For those who want to produce their own emulator prograns, you should note that the code isn’t LOADed right into the DOCK bank memory. It turns out that the T/S 2068 bank switching hardware gets in your way if you try. Instead, the code is first LOADed into RAM in the home bank, and then moved to the DOCK bank with a short machine code prograa.

In order to switch to the enulator, you need only type OUT 244, 3, but don’t do this yet. We want to make CHANGES to our T/S 2068 emulator. This article contains several BASIC programs that make changes to the emulator code. These programs should run when the real ROM is in control. It’s possible to rewrite them for when the eamlator is running the show, but for consistency in this article, we will ALWAYS make our patches when the real (HOME) ROM is in control, as running them will alvwys return control to the HOME ROM.

It’s finally time to start talking about interrupts. We’ll assume that you’ve installed your DOCK RAM and NMI switch, turned on your T/S 2068 with the T/S 2068 Emulator program. We’ll also assume you’ve done NOTHING else.

Nov, type in and run the listing below. This is just about the simplest possible program you can use to change code in the emulator: It changes a single byte. Let’s see what were changing, and why, before we try to understand what it does.

10 CLEAR 49151
20 OUT 244,192
30 POKE 49152+109,0
40 OUT 244,0

The machine code listing below is a copy of the NMI routine in both the Timex, and it is the program that’s run when you push the NMI switch. If you’ve tried pushing this switch, you’ll have found that this resets the machine. This is due to a bug in the NMI routine. The machine looks at the contents of locations 5CB0/1h, and if these contents are zero, the machine JUMPS to the address contained in the locations 5CB0/1h. In other words, it jumps to location zero, causing a machine reset. Hovever, if these locations do NOT contain zero, the nachine goes right back to what it was doing, and no reset occurs.

0066 F5     PUSH AF
0067 E5     PUSH HL
0068 2AB05C LD HL,(5CB0)
006B 7C     LD A,H
006C B5     OR L
006D 2001   JR NC,0070
006F E9     JP (HL)
0070 E1     POP HL
0071 F1     POP AF
0072 ED45   RETN

Now, type OUT 244,3. Although nothing important seems to have happened, the T/S 2068 emulator is now in control. Press the NMI switch. If you ran the second listing (above), you’ll find that pressing the switch no longer resets the machine. We’ve corrrected the bug. Type NEW or RANDOMIZE USR 0, or OUT 244,0. Any of these will switch you back to the old ROM. Now, the NMI switch causes the machine to reset.

What have we done? Look at the second listing. Line 10 makes sure that nothing important is going on in the upper 16K of the conputer. Line 20 opens the upper 16K of memory to the cartridge bank. Now, when we poke something into the top 16K of menory, it will appear in the emulator, and the addresses will alvays be seperated exactly by 49152. So, in line 30, we POKE a number into location (49152 +109), and expect that it will go into location 109. This is location 006D in listing 3, and it changes the JR NZ, 0070 into JR Z, 0070. Line 40 gives the upper 16K back to the nornal memory. It also will switch out the T/S 2068 eaulator, if it’s active, and you won’t get the results we’ve been discussing.

After using the second listing and switching in the T/S 2068 emulator, you can cause the computer to run your own custom machine code program at the push of an NMI svitch. Just insert it into some unused portion of memory and put its address into locations 5CB0/1h. However, if you then want the computer to resume where it left off, you’ll have to follow a couple of additional rules. First, note that the NMI routine saved the values of AF and HL. For this reason, the last 3 lines of your routine must be POP HL, POP AF, RETN, and they must be done in that order! Second, if your program uses any other registers, you must save their original values and restore them before you return.

Third, you must not use EI or DI. The NMI sill automatically disable the maskable interrupt, and RETN will restore its original status, but using EI or DI can upset this. In a monment, we’ll run a new program that breaks sone of these rules, and we’ll see what happens.

Next, with the main ROM in control, LOAD in one of the emulator tapes. Then, before switching to the emulator, type in and RUN the listing below. This modifies the NMI routine as shown in machine code after.

10 REM NMI Screen COPY
20 CLEAR 49151: OUT 244,192
30 POKE 49152+104,6
31 POKE 49152+105,192
32 POKE 49152+106,205
33 POKE 49152+107,5
34 POKE 49152+108,10
35 POKE 49152+109,24
40 OUT 244,0
0066 F5       PUSH AF
0067 E5       PUSH HL
0068 06C0     LD B, C0
006A CD050A   CALL 0A05
006D 1801     JR 0070
006F E9       JP (HL)
0070 E1       POP HL
0071 F1       POP AF
0072 ED45     RETN

The CALL instruction runs the screen-copy routine in the ROM. As such, pressing the NMI switch will cause a copy of the screen to be sent to the T/S 2040 printer. But look at the program! I’ve modified the B register vithout first saving it somewhere, and if you trace through the COPY routine, you’ll see that it uses DI and EI. I’ve broken my own rules.

As a result, the programs you interrupt in this manner say act erratic or crash altogether, after the screen is printed out.

Scroll to Top