TS1000 error code 2 keeps happening

Discussions about Sinclair ZX80 and ZX81 Hardware
bwinkel67
Posts: 83
Joined: Mon Mar 23, 2020 2:38 am

TS1000 error code 2 keeps happening

Post by bwinkel67 »

So I was running a program and it stopped with error code 2 after running a few minutes. I took a look at the statement before, at, and after and all variables were good. I typed CONT and it moved a few lines and gives error code 2 again, this time with different variables. Once again CONT moves to a next set of lines with error code 2?

What's going on here? Is this a "running out of memory so it's corrupting something" error. The program is only about 6K of text and doesn't DIM any arrays. It's a TS1000 with 16K RAM pack. Program is Elite.bas with under 40 different variables.

Note that I've been running this program for a few months now on both the EightyOne emulator and the QL's ZXSimulator without problem, so this was the first time on the actual hardware and after the 4th or 5th enemy ship got destroyed it started misbehaving. It doesn't do anything strange with arrays or anything. Below is the code:

Code: Select all

10 REM ELITE
20 GOSUB 3000
30 GOSUB 1100
400 REM PLAY
410 GOSUB 1700
420 GOTO 440
430 GOSUB 2100
440 GOSUB 1000
450 GOSUB 1300
460 GOSUB 1600
470 LET KEY=CODE INKEY$
480 IF KEY=0 THEN GOTO 440
490 IF KEY=FIRE THEN GOTO 430
500 GOTO 410
999 STOP
1000 REM STAR FIELD
1010 LET SD=INT (RND*6)=1
1020 IF SD=0 AND DX=DY THEN RETURN
1030 LET S$="% "
1040 GOSUB 1160
1050 IF STARS=0 OR SY+SM>14 THEN GOTO 1100
1060 LET SM=SM+SD
1070 LET SX=SX+DX
1080 LET SY=SY-DY
1090 GOTO 1150
1100 REM SHOW STARS
1110 LET STARS=1
1120 LET SM=0
1130 LET SX=INT (RND*3)+5
1140 LET SY=INT (RND*2)+4
1150 LET S$="%."
1160 LET SXC=SX-SM
1170 LET SYC=SY+SM
1180 IF SYC>=0 AND SYC<16 AND SXC>=0 AND SXC<32 THEN PRINT AT SYC,SXC;S$
1190 LET SXC=SX+10
1200 LET SYC=SY+SM*2-4
1210 IF SYC>=0 AND SYC<16 AND SXC>=0 AND SXC<32 THEN PRINT AT SYC,SXC;S$
1220 LET SXC=SX+SM+20
1230 LET SYC=SY-SM+2
1240 IF SYC>=0 AND SYC<16 AND SXC>=0 AND SXC<32 THEN PRINT AT SYC,SXC;S$
1250 RETURN
1300 REM ENEMY SHIP
1310 LET TIME=TIME+1
1320 IF TIME<WAIT THEN RETURN
1330 IF TIME=WAIT THEN GOTO 1550
1340 IF EL=0 THEN GOTO 2600
1350 LET DIR=INT (RND*8)+1
1360 IF DIR>4 AND DX=DY THEN GOTO 1490
1370 IF EX<1 OR EX>62 OR EY<13 OR EY>42 THEN GOTO 1420
1380 PLOT EX-1,EY
1390 PLOT EX+1,EY
1400 PLOT EX,EY-1
1410 PLOT EX,EY+1
1420 IF TIME>LEAVE THEN GOTO 2550
1430 IF DIR=1 THEN LET EY=EY+1
1440 IF DIR=2 THEN LET EX=EX+1
1450 IF DIR=3 THEN LET EY=EY-1
1460 IF DIR=4 THEN LET EX=EX-1
1470 LET EX=EX+DX*2
1480 LET EY=EY+DY
1490 IF EX<1 OR EX>62 OR EY<13 OR EY>42 THEN RETURN
1500 UNPLOT EX-1,EY
1510 UNPLOT EX+1,EY
1520 UNPLOT EX,EY-1
1530 UNPLOT EX,EY+1
1540 RETURN
1550 LET LEAVE=WAIT+INT (RND*25)+75
1560 LET EL=INT (RND*3)+2
1570 LET EX=INT (RND*58)+3
1580 LET EY=INT (RND*18)+23
1590 GOTO 1490
1600 REM LASER SIGHT
1610 PRINT AT 6,14;"\'.";TAB 17;"\.'"
1620 PRINT AT 7,14;"\.'";TAB 17;"\'."
1630 RETURN
1700 REM CONTROLS
1710 PRINT AT 18,15;"  "
1720 PRINT AT 19,14;" \ :\:  "
1730 PRINT AT 20,15;"  "
1740 IF KEY=LEFT THEN GOTO 1790
1750 IF KEY=RIGHT THEN GOTO 1840
1760 IF KEY=UP THEN GOTO 1890
1770 IF KEY=DOWN THEN GOTO 1940
1780 RETURN
1790 LET DX=DX<>1
1800 LET DY=0
1810 IF DX=0 THEN RETURN
1820 PRINT AT 19,14;"\ :"
1830 GOTO 1980
1840 LET DX=-(DX<>-1)
1850 LET DY=0
1860 IF DX=0 THEN RETURN
1870 PRINT AT 19,17;"\: "
1880 GOTO 1980
1890 LET DX=0
1900 LET DY=-(DY<>-1)
1910 IF DY=0 THEN RETURN
1920 PRINT AT 18,15;"\ '\' "
1930 GOTO 1980
1940 LET DX=0
1950 LET DY=DY<>1
1960 IF DY=0 THEN RETURN
1970 PRINT AT 20,15;"\ .\. "
1980 LET FUEL=FUEL-1
1990 GOSUB 2300
2000 IF FUEL=0 THEN GOTO 9010
2010 RETURN
2100 REM FIRE LASER
2110 FOR I=14 TO 7 STEP -1
2120 PRINT AT I,22-I;"\'."
2130 PRINT AT I,9+I;"\.'"
2140 NEXT I
2150 PAUSE 4
2160 FOR I=14 TO 7 STEP -1
2170 PRINT AT I,22-I;"% "
2180 PRINT AT I,9+I;"% "
2190 NEXT I
2200 IF EY<29 OR EY>30 THEN GOTO 2260
2210 IF EX<30 OR EX>33 THEN GOTO 2260
2220 LET EL=EL-1
2230 LET SHIELD=SHIELD-INT (RND*3)
2240 IF SHIELD<14 THEN GOSUB 2400
2250 IF SHIELD<=0 THEN GOTO 9070
2260 LET AMMO=AMMO-1
2270 GOSUB 2350
2280 IF AMMO=0 THEN GOTO 9050
2290 RETURN
2300 REM FUEL
2310 LET BAR=INT (FUEL/3)
2320 PRINT AT 18,BAR;" "
2330 RETURN
2350 REM AMMO
2360 LET BAR=INT (AMMO/2)
2370 PRINT AT 18,25+BAR;" "
2380 RETURN
2400 REM SHIELD
2410 LET BAR=INT (SHIELD/2)
2420 PRINT AT 21,25+BAR;" "
2430 RETURN
2450 REM ENERGY
2460 LET BAR=INT ((ENERGY-1)/2)
2470 PRINT AT 21,BAR;"\##"
2480 IF ENERGY=14 THEN GOTO 9030
2500 REM INIT SHIP
2510 LET STARS=0
2520 LET TIME=0
2530 LET WAIT=INT (RND*5)+8
2540 RETURN
2550 REM LOSE SHIELD
2560 LET SHIELD=SHIELD-1
2570 GOSUB 2400
2580 IF SHIELD<=0 THEN GOTO 9070
2590 GOTO 2500
2600 REM SHIP EXPLODES
2610 PLOT EX-1,EY
2620 PLOT EX+1,EY
2630 PLOT EX,EY-1
2640 PLOT EX,EY+1
2650 FOR I=1 TO 2
2660 UNPLOT EX,EY
2670 UNPLOT EX-1,EY-1
2680 UNPLOT EX+1,EY-1
2690 UNPLOT EX-1,EY+1
2700 UNPLOT EX+1,EY+1
2710 PLOT EX,EY
2720 UNPLOT EX-2,EY-2
2730 UNPLOT EX+2,EY-2
2740 UNPLOT EX-2,EY+2
2750 UNPLOT EX+2,EY+2
2760 PLOT EX-1,EY-1
2770 PLOT EX+1,EY-1
2780 PLOT EX-1,EY+1
2790 PLOT EX+1,EY+1
2800 PLOT EX-2,EY-2
2810 PLOT EX+2,EY-2
2820 PLOT EX-2,EY+2
2830 PLOT EX+2,EY+2
2840 NEXT I
2850 LET I=INT (RND*2)+1
2860 LET BAR=FUEL+I*3
2870 LET FUEL=(BAR<22)*BAR+(BAR>21)*21
2880 PRINT AT 18,0;F$(1 TO INT (FUEL/3))
2890 LET BAR=AMMO+I*3
2900 LET AMMO=(BAR<15)*BAR+(BAR>14)*14
2910 PRINT AT 18,25;F$(1 TO INT (AMMO/2))
2920 LET BAR=SHIELD+I
2930 LET SHIELD=(BAR<15)*BAR+(BAR>14)*14
2940 PRINT AT 21,25;F$(1 TO INT (SHIELD/2))
2950 LET ENERGY=ENERGY+1
2960 GOTO 2450
3000 REM SETTINGS
3010 GOSUB 2500
3020 LET DX=0
3030 LET DY=0
3040 LET EY=0
3050 LET FUEL=21
3060 LET ENERGY=0
3070 LET AMMO=14
3080 LET SHIELD=14
3090 LET FIRE=CODE "F"
3100 LET LEFT=CODE "A"
3110 LET RIGHT=CODE "D"
3120 LET DOWN=CODE "W"
3130 LET UP=CODE "S"
3140 LET F$="\##\##\##\##\##\##\##"
3200 REM DISPLAY
3210 LET S$="% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % "
3220 FOR I=0 TO 15
3230 PRINT S$;
3240 NEXT I
3250 FOR I=16 TO 21
3260 PRINT AT I,7;"\ :"
3270 PRINT AT I,24;"\: "
3280 NEXT I
3290 PRINT AT 17,12;"\ .\..\.'\''\''\'.\..\. "
3300 PRINT AT 18,10;"\..\''\' ","   \ '\''\.."
3310 PRINT AT 19,9;"\.'","      \'."
3320 PRINT AT 20,8;"\ .\' ","      \ '\. "
3330 PRINT AT 21,8;"\ :  E L I T E   \: "
3340 PRINT AT 19,15;"\ :\:  "
3350 PRINT AT 17,0;"FUEL:"
3360 PRINT AT 18,0;F$
3370 PRINT AT 20,0;"ENERGY:"
3380 PRINT AT 17,25;"AMMO:"
3390 PRINT AT 18,25;F$
3400 PRINT AT 20,25;"SHIELD:"
3410 PRINT AT 21,25;F$
3500 REM CONFIGURE
3510 PRINT AT 0,0;"%S%:%T%A%R%T% %C%:%O%N%F%I%G%U%R%E%?";
3520 PRINT AT 2,2;"%D%E%F%A%U%L%T%:% %F%,%A%,%D%,%W%,%S"
3530 GOSUB 3800
3540 PRINT AT 0,0;S$(1 TO 20)
3550 PRINT AT 2,2;S$(1 TO 20)
3560 IF KEY=CODE "S" THEN GOTO 3750
3570 PRINT AT 0,0;"%P%R%E%S%S% %K%E%Y% %F%O%R% %A%C%T%I%O%N"
3580 PRINT AT 2,2;"%F%I%R%E%?"
3590 GOSUB 3800
3600 LET FIRE=KEY
3610 PRINT AT 2,2;"%L%E%F%T%?"
3620 GOSUB 3800
3630 LET LEFT=KEY
3640 PRINT AT 2,2;"%R%I%G%H%T%?"
3650 GOSUB 3800
3660 LET RIGHT=KEY
3670 PRINT AT 2,2;"%U%P%?% % % "
3680 GOSUB 3800
3690 LET UP=KEY
3700 PRINT AT 2,2;"%D%O%W%N%?% "
3710 GOSUB 3800
3720 LET DOWN=KEY
3730 PRINT AT 0,0;S$(1 TO 20)
3740 PRINT AT 2,2;S$(1 TO 6)
3750 LET KEY=0
3760 RETURN
3800 REM GET KEY
3810 LET KEY=CODE INKEY$
3820 IF KEY<>0 THEN RETURN
3830 GOTO 3810
9000 REM GAME END
9010 LET S$="%Y%O%U% %R%A%N% %O%U%T% %O%F% %F%U%E%L"
9020 GOTO 9100
9030 LET S$="%Y%O%U% %G%O%T% %A%L%L% %O%F% %T%H%E%M"
9040 GOTO 9100
9050 LET S$="%Y%O%U% %R%A%N% %O%U%T% %O%F% %A%M%M%O"
9060 GOTO 9100
9070 LET S$="%Y%O%U%R% %S%H%I%E%L%D%S% %F%A%I%L%E%D"
9110 REM MESSAGE
9120 PRINT AT 6,14;"% % % % "
9130 PRINT AT 7,14;"% % % % "
9140 FOR I=1 TO 3
9150 PRINT AT 6,11;"GAME OVER"
9160 PAUSE 20
9170 PRINT AT 6,11;"%G%A%M%E% %O%V%E%R"
9180 PAUSE 20
9190 NEXT I
9200 PRINT AT 7,6;S$
9210 PRINT AT 8,4;"%Y%O%U% %D%E%S%T%R%O%Y%E%D% ";
9220 LET S$="%0%1%2%3%4%5%6%7%8%9"
9230 IF INT (ENERGY/10) THEN PRINT S$(1+INT (ENERGY/10));
9240 PRINT S$(1+ENERGY-10*INT (ENERGY/10));"% %P%I%R%A%T%E%S"
9250 STOP
Addendum: when I do CLEAR and then run the program again it still gives me error code 2 (and even one that was 1). Memory corruption or something -- maybe that famous RAM pack wobble? I don't do PEEK's or POKE's so it has to be maybe running out of memory. All my loops end so I don't go on indefinitely with them, plus all my GOSUB's have pretty quick RETURN's so I don't have an infinite nesting problem.
bwinkel67
Posts: 83
Joined: Mon Mar 23, 2020 2:38 am

Re: TS1000 error code 2 keeps happening

Post by bwinkel67 »

So I get the same problem on a different BASIC program (Minesweeper). What could cause it to consistently complaining about undefined variable. Could it be bad memory in my RAM pack?
User avatar
XavSnap
Posts: 991
Joined: Sat May 10, 2008 4:23 pm

Re: TS1000 error code 2 keeps happening

Post by XavSnap »

Will have a look !
Xavier
bwinkel67
Posts: 83
Joined: Mon Mar 23, 2020 2:38 am

Re: TS1000 error code 2 keeps happening

Post by bwinkel67 »

So multiple programs keep stopping on an error. It can be 2, or 1, or C (and I don't use VAL).

I ran one small program with and without the RAM pack and it runs fine without. So I'm guessing one of the RAM chips on the 16K ram pack might be bad? I suppose I could find a replacement and figure out which one. Any guidance? Should I post this under hardware now?

BTW, the RAM pack caused one of my LCD TV's to glitch with the screen. Not on the other monitors. Wonder if it could be connected.
User avatar
XavSnap
Posts: 991
Joined: Sat May 10, 2008 4:23 pm

Re: TS1000 error code 2 keeps happening

Post by XavSnap »

:shock:

Yes, try to test your ram pack… clean the Zx81's expansion bus with KF, a rubber eraser…
Check the connector pins to find a pushed/destroyed pin.
Only 8kb are used in this program...

May be an bad link to it.
Cap0038.jpg
Cap0038.jpg (11.35 KiB) Viewed 2675 times
ELITE.P
(7.42 KiB) Downloaded 75 times
LCD TV's to glitch : You had to change all capacitors in the RAM pack !
Xavier
bwinkel67
Posts: 83
Joined: Mon Mar 23, 2020 2:38 am

Re: TS1000 error code 2 keeps happening

Post by bwinkel67 »

I did already clean the pad with isopropyl and a cotton swap, rubbing vigorously. Also tried to clean the connector on the RAM pack. Will see if I can find a thin eraser.

Looks like you killed a pirate or two :-) Good to know it's only 8K in size. I need to start adding the planet hopping next but got sidetracked on my adventure of actually using the TS1000. Finally figuring out how to get programs to consistently loaded today so that's how I started trying all these programs, most of which I developed on my simulator.

Thanks for taking a look at it. BTW, how can you figure out how much RAM a program takes?
bwinkel67
Posts: 83
Joined: Mon Mar 23, 2020 2:38 am

Re: TS1000 error code 2 keeps happening

Post by bwinkel67 »

With regard to the 4 caps in the RAM pack, they all looked solid but I can try and change them.
User avatar
XavSnap
Posts: 991
Joined: Sat May 10, 2008 4:23 pm

Re: TS1000 error code 2 keeps happening

Post by XavSnap »

If it's a Sinclair Ram Pack, may be an ULA error… :oops:
Not the inboard ULA in the Zx81, but in the Ram Pack…
A faulty RAM case up to 2kb... too.

4 caps in the RAM pack: Try to install a 1uf per RAM case, and a global polarisez one to ajust de voltage level.

Some of my RAM pack corrupt the display too… it was a know problem.
The Ram pack calibration was set to another zx81's circuit, some of mine seem to run properly on another Zx81 !
Xavier
User avatar
XavSnap
Posts: 991
Joined: Sat May 10, 2008 4:23 pm

Re: TS1000 error code 2 keeps happening

Post by XavSnap »

how can you figure out how much RAM a program takes?
PRINT PEEK (something)-PEEK (something) +something
:mrgreen:

I had to find the RAM pack service manual…
Xavier
User avatar
XavSnap
Posts: 991
Joined: Sat May 10, 2008 4:23 pm

Re: TS1000 error code 2 keeps happening

Post by XavSnap »

Code: Select all

9991 PRINT PEEK 16388+256*PEEK 16389-PEEK 16413;"  RAM"
9992 PRINT PEEK 16412+256*PEEK 16413;"  END STACK"
9993 PRINT PEEK 16396+256*PEEK 16397-16509;"  PROG.LENGHT."
9999 PRINT PEEK 16388+256*PEEK 16389-PEEK 16400-256*PEEK 16401;"   STACK"
Xavier
Post Reply