218 lines
4.8 KiB
Plaintext
218 lines
4.8 KiB
Plaintext
'time sliced version of clock using TIME module
|
|
|
|
_runtimePath_ "../runtime"
|
|
_codeRomType_ ROMv1
|
|
|
|
'Keeping time using the
|
|
'59.98 Hz frame counter
|
|
|
|
const TICKS = 60
|
|
const SECSX = &h60A0
|
|
const SECSY = &h61A0
|
|
const MINSX = &h62A0
|
|
const MINSY = &h63A0
|
|
const HOURX = &h64A0
|
|
const HOURY = &h65A0
|
|
|
|
const CENTERX = 80
|
|
const CENTERY = 59
|
|
|
|
const SECS_LEN = 45
|
|
const MINS_LEN = 37
|
|
const HOUR_LEN = 29
|
|
|
|
const BACK_COLOUR = &h30
|
|
const DIAL_COLOUR = &h10
|
|
const DIAL_RADIUS = 43
|
|
|
|
'Seconds
|
|
def byte(SECSX, x, -90.0, 270.0, TICKS) = cos(x)*SECS_LEN + CENTERX
|
|
def byte(SECSY, y, -90.0, 270.0, TICKS) = sin(y)*SECS_LEN + CENTERY
|
|
|
|
'Minutes
|
|
def byte(MINSX, x, -90.0, 270.0, TICKS) = cos(x)*MINS_LEN + CENTERX
|
|
def byte(MINSY, y, -90.0, 270.0, TICKS) = sin(y)*MINS_LEN + CENTERY
|
|
|
|
'Hours
|
|
def byte(HOURX, x, -90.0, 270.0, TICKS) = cos(x)*HOUR_LEN + CENTERX
|
|
def byte(HOURY, y, -90.0, 270.0, TICKS) = sin(y)*HOUR_LEN + CENTERY
|
|
|
|
'Tictoc
|
|
const T_SIZ=8
|
|
const T_LUT=&h66A0
|
|
def byte(T_LUT, y, 0.0, 3.0, T_SIZ) = 63.0 - 1.398*exp(-y)*(1.0-exp(-10.0*y))*63.0
|
|
|
|
'audio fix for ROMv5a
|
|
poke &h21, peek(&h21) OR 3
|
|
|
|
init time
|
|
|
|
|
|
restart:
|
|
|
|
' disable video, (except last line so that we don't lose sync), for fast cls
|
|
set VIDEO_TOP, 238
|
|
set BG_COLOUR, BACK_COLOUR
|
|
set FG_COLOUR, &h0F
|
|
cls
|
|
set VIDEO_TOP, 0 'enable video
|
|
|
|
scroll off
|
|
at 2, 119 : print "Press Enter to reset clock";
|
|
at 2, 0 : input "Enter Time ", H,"H:";2;, M,"M:";2;, S,"S:";2;
|
|
B=get("FRAME_COUNT")
|
|
scroll off
|
|
at 2,0 : print " ";
|
|
at 2,119 : print " ";
|
|
|
|
set TIME_MODE, 12
|
|
set TIME_EPOCH, 1
|
|
|
|
H = H % 13 : if H &= 0 then H = 12
|
|
M = M % 60
|
|
S = S % 60
|
|
set TIME_H, H : set TIME_M, M : set TIME_S, S
|
|
|
|
HH = H : MM = M : SS = S
|
|
Hm12 = H % 12
|
|
Md12 = M / 12 : MMd12 = Md12
|
|
|
|
' disable video, (except last line so that we don't lose sync), for fast dial draw
|
|
set VIDEO_TOP, 238 'disable video
|
|
gosub drawDial
|
|
gosub drawClock
|
|
set VIDEO_TOP, 0 'enable video
|
|
|
|
|
|
loop:
|
|
'use this if no runtime calls are in main loop, (e.g. wait)
|
|
tick time
|
|
|
|
S = get("TIME_S")
|
|
if S &&<> SS
|
|
H = get("TIME_H") : M = get("TIME_M")
|
|
gosub drawClock
|
|
SS = S
|
|
endif
|
|
|
|
'restart
|
|
if get("SERIAL_RAW") <> 255
|
|
goto restart
|
|
endif
|
|
goto &loop:
|
|
|
|
|
|
'this sound generation is 'main loop' frequency dependant, that is why it messes up
|
|
'when the minute hand hits 12 and when the mode is changed, (it was tuned for mode 1)
|
|
'you could rewrite it as a vertical blank user proc, but you cannot use any of the runtime
|
|
'within the vertical blank, (except for the time and midi modules), thus coding it directly
|
|
'in vASM would be the wisest choice
|
|
proc tictoc
|
|
local t
|
|
|
|
t = peek(T_LUT + (get("TIMER") AND (T_SIZ - 1)))
|
|
sound on, 1, t LSL 4, t, 0
|
|
set SOUND_TIMER, 1
|
|
endproc
|
|
|
|
drawClock:
|
|
call tictoc
|
|
gosub drawDigits
|
|
gosub drawSeconds
|
|
gosub drawMinutes
|
|
gosub drawHours
|
|
return
|
|
|
|
drawDigits:
|
|
set FGBG_COLOUR, &h0C00
|
|
at 57,82 : print time$
|
|
set BG_COLOUR, DIAL_COLOUR
|
|
return
|
|
|
|
drawSeconds:
|
|
gosub eraseSecondHand
|
|
t=SS : gosub drawTicks
|
|
gosub drawSecondHand
|
|
return
|
|
|
|
drawMinutes:
|
|
if M &<> MM
|
|
gosub eraseMinuteHand
|
|
MM = M : Md12 = M/12
|
|
if Md12 &&<> MMd12
|
|
gosub eraseHourHand
|
|
MMd12 = Md12
|
|
endif
|
|
endif
|
|
gosub drawMinuteHand
|
|
return
|
|
|
|
drawHours:
|
|
if H &&<> HH
|
|
HH = H : Hm12 = H%12
|
|
endif
|
|
Hx5 = (Hm12 LSL 2) + Hm12
|
|
gosub drawHourHand
|
|
return
|
|
|
|
drawTicks:
|
|
x = peek(SECSX + t)
|
|
y = peek(SECSY + t) + 8
|
|
poke (y LSL 8) + x, &h3F
|
|
return
|
|
|
|
|
|
drawDial:
|
|
set FG_COLOUR, DIAL_COLOUR
|
|
circlef CENTERX, CENTERY, DIAL_RADIUS
|
|
|
|
ox=CENTERX : oy=CENTERY
|
|
cr=DIAL_RADIUS + 1 : cc=&h00 : gosub jitterCircle
|
|
cr=DIAL_RADIUS + 3 : cc=&h00 : gosub jitterCircle
|
|
cr=DIAL_RADIUS + 5 : cc=&h01 : gosub jitterCircle
|
|
cr=DIAL_RADIUS + 9 : cc=&h03 : gosub jitterCircle
|
|
cr=DIAL_RADIUS + 7 : cc=&h02 : gosub jitterCircle
|
|
|
|
for t=0 &to TICKS-1
|
|
gosub drawTicks
|
|
next t
|
|
return
|
|
|
|
eraseSecondHand:
|
|
set FG_COLOUR, DIAL_COLOUR
|
|
line CENTERX,CENTERY, peek(SECSX + SS),peek(SECSY + SS)
|
|
return
|
|
|
|
drawSecondHand:
|
|
set FG_COLOUR, &h3F
|
|
line CENTERX,CENTERY, peek(SECSX + S),peek(SECSY + S)
|
|
return
|
|
|
|
eraseMinuteHand:
|
|
set FG_COLOUR, DIAL_COLOUR
|
|
line CENTERX,CENTERY, peek(MINSX + MM),peek(MINSY + MM)
|
|
return
|
|
|
|
drawMinuteHand:
|
|
set FG_COLOUR, &h2A
|
|
line CENTERX,CENTERY, peek(MINSX + M),peek(MINSY + M)
|
|
return
|
|
|
|
eraseHourHand:
|
|
set FG_COLOUR, DIAL_COLOUR
|
|
line CENTERX,CENTERY, peek(HOURX + Hx5 + MMd12),peek(HOURY + Hx5 + MMd12)
|
|
return
|
|
|
|
drawHourHand:
|
|
set FG_COLOUR, &h15
|
|
line CENTERX,CENTERY, peek(HOURX + Hx5 + Md12),peek(HOURY + Hx5 + Md12)
|
|
return
|
|
|
|
jitterCircle:
|
|
for oxx=ox-1 to ox+1
|
|
for oyy=oy-1 to oy+1
|
|
set FG_COLOUR, cc
|
|
circle oxx, oyy, cr
|
|
next oyy
|
|
next oxx
|
|
return |