OverBug

Descripción del contenido de la página

Herramienta para investigar un fallo de Beta DOS en Beta BASIC, para la Sinclair ZX Spectrum.

Etiquetas:

En setiembre de 2010, durante el desarrollo de Alien-B me encontré con un molesto fallo de Beta DOS que ya había observado en ocasiones anteriores: El comando SAVE OVER da problemas en Beta BASIC cuando se ejecuta en un procedimiento, en un bucle DO... LOOP o en una subrutina. Parece que ese comando de Beta DOS corrompe la pila de retorno de Beta BASIC.

Empecé escribiendo un sencillo programa para hacer comprobaciones e intentar encontrar la causa del fallo o las condiciones exactas en que se producía y el resultado fue OverBug, una especie de demo de los diferentes efectos del fallo.

Pantallazos

MenúAcerca del programaTest 1Test 2Test 3Test 4Test 5Test 6Test 7

Código fuente

  10 REM OverBug

  20 REM This program tests in Beta BASIC the Beta DOS's SAVE OVER command, that has a bug even in the fixed version of Beta DOS.
  30 REM It is written in Beta BASIC 4.0+D for ZX Spectrum 128 with a +D interface, on the fixed version of Beta DOS 1.3.
  40 
     REM Copyright (C) 2010 Marcos Cruz (programandala.net)
  50 REM License
     programandala.net/license

  60 
     REM 2010-09-11 First version.

  70 
     REM Init

  75 RANDOMIZE USR 58419
     INPUT ""
     REM Beta BASIC on 
  80 WINDOW ERASE
     CLS #
  90 LET titlewin=1,mainwin=2
 100 WINDOW titlewin,0,175,255,25
     WINDOW mainwin,0,143,255,143
 110 LET tests=7
 120 DIM t$(tests,30)
     RESTORE
     FOR n=1 TO tests
       READ t$(n)
     NEXT n
 130 
     REM Main

 140 title
     WINDOW mainwin
 150 CLS mainwin
 160 PRINT INVERSE 1;"0"; INVERSE 0;" "; OVER 1; CSIZE 7;"About the SAVE OVER bug"
 170 PRINT '"Tests to run:"''
 180 FOR n=1 TO tests
       PRINT INVERSE 1;n; INVERSE 0;" "; OVER 1; CSIZE 7;t$(n)
     NEXT n
 190 PRINT #0;"Choose an option (0-";tests;")"
 200 DO
       GET option
     LOOP UNTIL tests>=option
 210 CLS mainwin
 220 IF NOT option THEN about
       GO TO 150
 230 
     REM Test dispatch

 240 PRINT INVERSE 1;"Test ";option; INVERSE 0;":"'t$(option)'
 250 PRINT ' INK 2;"Effect after SAVE OVER:"
 260 GO TO ON option;500,560,640,730,820,920,1030
 270 
     REM Procs

 280 DEF PROC title
 290   CLS titlewin
       WINDOW titlewin
 300   PRINT OVER 2; CSIZE 13;AT 0,0;"OverBug"
 310   PRINT CSIZE 4,8;AT 0,24;"(C)2010 Marcos Cruz (programandala.net)"
 320   PRINT CSIZE 6,8;AT 2,0; OVER 1;"Beta BASIC tester for Beta DOS's SAVE OVER"
 330   PLOT 0,150
       DRAW 255,0
 340 END PROC

 350 DEF PROC about
 360   PRINT '"It seems the Beta DOS's SAVE"'"OVER command works fine in Beta"'"BASIC only in the main program"'"flow, but it corrupts the Beta"'"BASIC's return stack when"'"executed in a subrutine, a"'"DO...LOOP or a PROC."
 370   PRINT '"I experienced that with the"'"fixed version of Beta DOS 1.3"'"and Beta BASIC 4.0+D."
 380   PRINT '"In order to investigate the"'"issue I wrote this program."
 390   PRINT #0;"Press any key"
       PAUSE 0
 400 END PROC

 410 DEF PROC warning
 420   LOCAL k$
 430   PRINT #0;"Press ENTER to proceed;"'"any other key to cancel."
 440   GET k$
       IF k$<>CHR$ 13 THEN POP
         GO TO 150
 450 END PROC

 460 DEF PROC s
 470   RENUM
 480   SAVE d*"OverBug" LINE 10
 490 END PROC

 500 
     REM Test 1

 510 DATA "Normal"
 520 PRINT "None."
 530 PAPER 4
     PRINT
     LIST 550 TO 550
     PAPER 7
 540 warning
 550 SAVE OVER d*"rubbish"
     STOP
 560 
     REM Test 2

 570 DATA "GO SUB+RETURN"
 580 PRINT "The border shows blue and cyan"'"stripes, like a turbo-loader."'"After pressing Space, the"'"stripes get red and cyan. After"'"pressing Break for a while"'"the system returns to BASIC."
 590 PAPER 4
     PRINT
     LIST 610 TO 630
     PAPER 7
 600 warning
 610 GO SUB 630
 620 STOP
 630 SAVE OVER d*"rubbish"
     RETURN
 640 
     REM Test 3

 650 DATA "GO SUB+POP+GO TO"
 660 PRINT "None."
 670 PAPER 4
     PRINT
     LIST 690 TO 720
     PAPER 7
 680 warning
 690 GO SUB 710
 700 STOP
 710 POP ret
     PRINT "POP address:";ret
 720 SAVE OVER d*"rubbish"
     GO TO ret+1
 730 
     REM Test 4

 740 DATA "DO...LOOP"
 750 PRINT "Error 'LOOP without DO'."
 760 PAPER 4
     PRINT
     LIST 780 TO 810
     PAPER 7
 770 warning
 780 DO
 790   SAVE OVER d*"rubbish"
 800 LOOP UNTIL 1
 810 STOP
 820 
     REM Test 5

 830 DATA "DO...LOOP+GO SUB+RETURN"
 840 PRINT "The border shows blue and cyan"'"stripes, like a turbo-loader."'"After pressing Space, the"'"stripes get red and cyan. After"'"pressing Break for a while"'"the system returns to BASIC."
 850 PAPER 4
     PRINT
     LIST 870 TO 910
     PAPER 7
 860 warning
 870 DO
 880   GO SUB 910
 890 LOOP UNTIL 1
 900 STOP
 910 SAVE OVER d*"rubbish"
     RETURN
 920 
     REM Test 6

 930 DATA "DO...LOOP+GO SUB+POP+GO TO"
 940 PRINT "Error 'LOOP without DO'."
 950 PAPER 4
     PRINT
     LIST 970 TO 1020
     PAPER 7
 960 warning
 970 DO
 980   GO SUB 1010
 990 LOOP UNTIL 1
1000 STOP
1010 POP ret
     PRINT "POP address:";ret
1020 SAVE OVER d*"rubbish"
     GO TO ret+1
1030 
     REM Test 7

1040 DATA "PROC"
1050 PRINT "The border shows blue and green"'"stripes, like a turbo-loader."'"Pressing some keys will change"'"the colors. "; INK 2;"Eventually, the"'"system will crash."
1060 PAPER 4
     PRINT
     LIST 1080 TO 1120
     PAPER 7
1070 warning
1080 test7
1090 DEF PROC test7
1100   SAVE OVER d*"rubbish"
1110 END PROC
1120 STOP

Descargas

Las imágenes de disquete de +D contienen, además del programa OverBug:

El fichero de autoarranque Autoload carga Beta BASIC y el programa OverBug.

Páginas relacionadas

Apuntes sobre Beta BASIC 4.0+D
Relación de características destacadas, limitaciones, fallos y trucos de Beta BASIC 4.0+D (para ZX Spectrum 128 con interfaz +D).
stringBug
Demostración de un fallo de Beta BASIC, para la Sinclair ZX Spectrum.
bb4d-fixer
Programa que corrige varios fallos de Beta BASIC 4.0+D.