From 6dba62943ca651a8ead6b8de02deb7b352dc8388 Mon Sep 17 00:00:00 2001 From: giomba Date: Sun, 17 Mar 2024 22:18:40 +0100 Subject: [PATCH] Add automatic calibration for timing. --- MATTEO.BAS | 59 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/MATTEO.BAS b/MATTEO.BAS index ac97b56..f8e6309 100644 --- a/MATTEO.BAS +++ b/MATTEO.BAS @@ -1,9 +1,23 @@ +DECLARE SUB CALIBRATION () +DECLARE SUB BUSYDELAY (ms!) DECLARE SUB RAINBOW () DECLARE SUB CENTER (text$) DECLARE SUB SETUP () DECLARE SUB LOADBAR () DECLARE SUB SONG () + +KEY(3) ON +ON KEY(3) GOSUB Terminate + CLS +REM Numero di cicli nel ritardo con attesa attiva +DIM SHARED timecycles AS LONG +timecycles = 100 +REM Costante temporale per ritardo di 1ms (calibrazione) +DIM SHARED timeconst AS INTEGER + +CALL CALIBRATION +CALL BUSYDELAY(1000) CALL SETUP CALL SONG @@ -13,11 +27,46 @@ PRINT "da GiulioF e giomba" LOCATE 13, 60 PRINT " 23 marzo 2024" +LOCATE 4, 1 +PRINT SPACE$(80) +LOCATE 4 +CENTER "Premere F3 per uscire" + DO CALL RAINBOW - IF NOT INKEY$ = "" THEN EXIT DO LOOP +Terminate: +END + +SUB BUSYDELAY (ms) + +FOR i = 1 TO ms: FOR d = 1 TO timeconst: NEXT d: NEXT i + +END SUB + +SUB CALIBRATION + +REM Ritorna numero di cicli da eseguire per attesa di 1ms +PRINT "Calibrazione velocit… processore in corso..." +DIM delay AS LONG + +diff = 0 + +WHILE diff < 1 + PRINT "."; + timecycles = timecycles * 2 + tstart = TIMER + FOR delay = 1 TO timecycles: NEXT delay + tend = TIMER + diff = tend - tstart +WEND + +timeconst = .001 * timecycles / diff + +PRINT timeconst; " cicli" + +END SUB SUB CENTER (text$) @@ -36,7 +85,7 @@ FOR col% = 1 TO 30 COLOR 4 PRINT CHR$(c); NEXT row% - FOR d = 1 TO 10000: NEXT d + CALL BUSYDELAY(100) FOR row% = 10 TO 14 c = SCREEN(row%, col%) LOCATE row%, col% @@ -70,16 +119,16 @@ NEXT i FOR i = 19 TO 59 STEP 1 LOCATE 20, i + 1 PRINT CHR$(&HDB) - FOR d = 0 TO 2000: NEXT d + CALL BUSYDELAY(100) NEXT i -SLEEP 1 +CALL BUSYDELAY(1000) PRINT CENTER "come sono burlone" CENTER CHR$(1) -SLEEP 2 +CALL BUSYDELAY(2000) END SUB