Add automatic calibration for timing.

This commit is contained in:
giomba 2024-03-17 22:18:40 +01:00
parent c8a3cc7758
commit 6dba62943c
1 changed files with 54 additions and 5 deletions

View File

@ -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