uxn-utils/gui/calendar/calendar.tal

644 lines
13 KiB
Tal
Raw Permalink Normal View History

2023-03-18 00:04:22 -04:00
( uxnemu calendar.rom )
|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2
|10 @Console &vector $2 &read $1 &pad $5 &write $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|80 @Controller &vector $2 &button $1 &key $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &chord $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
|0000
@year $2 @month $1
@pointer &x $2 &y $2 &lastx $2 &lasty $2 &state $1
@line &x $2 &y $2 &dx $2 &dy $2 &e1 $2
@path $10
|0100
( theme )
#d07e .System/r DEO2
#d0d6 .System/g DEO2
#d0c2 .System/b DEO2
load-theme
( size 3bx25 )
#01d8 .Screen/width DEO2
#0128 .Screen/height DEO2
( today )
current-month
( unlock )
;on-mouse .Mouse/vector DEO2
;on-button .Controller/vector DEO2
BRK
(
@|vectors )
@on-mouse ( -> )
( clear last cursor )
#40 draw-pointer
( draw new cursor )
.Mouse/x DEI2 .pointer/x STZ2
.Mouse/y DEI2 .pointer/y STZ2
;pointer-icn .Screen/addr DEO2
#41 .Mouse/state DEI #00 NEQ ADD draw-pointer
.Mouse/y DEI2 #0018 LTH2 ?on-mouse-menu
.Mouse/state DEI #01 GTH ?on-mouse-erase
.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ?on-mouse-down
.Mouse/state DEI #00 EQU .pointer/state LDZ #00 NEQ AND ?on-mouse-up
.Mouse/state DEI ?on-mouse-drag
.Mouse/state DEI .pointer/state STZ
BRK
@on-mouse-erase ( -> )
.Mouse/x DEI2 .Mouse/y DEI2 paint-erase
.Mouse/state DEI .pointer/state STZ
BRK
@on-mouse-drag ( -> )
( draw line )
.pointer/lastx LDZ2
.pointer/lasty LDZ2
.pointer/x LDZ2
.pointer/y LDZ2
#03
paint-line
( record last position )
.Mouse/x DEI2 .pointer/lastx STZ2
.Mouse/y DEI2 .pointer/lasty STZ2
.Mouse/state DEI .pointer/state STZ
BRK
@on-mouse-down ( -> )
( record start position )
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .pointer/lasty STZ2
.Mouse/state DEI .pointer/state STZ
BRK
@on-mouse-up ( -> )
;path .File/name DEO2
#3eb0 .File/length DEO2
;data .File/write DEO2
#00 .pointer/state STZ
draw-page
BRK
@on-mouse-menu ( -> )
.Mouse/state DEI #00 EQU ?&no-touch
.Mouse/y DEI2 #03 SFT2 NIP
DUP #01 NEQ ?&no-menu
.Mouse/x DEI2 #03 SFT2 NIP
DUP #36 NEQ ?&no-l
prev-month
#00 .Mouse/state DEO
&no-l
DUP #37 NEQ ?&no-c
current-month
#00 .Mouse/state DEO
&no-c
DUP #38 NEQ ?&no-r
next-month
#00 .Mouse/state DEO
&no-r
POP
&no-menu
POP
&no-touch
BRK
@on-button ( -> )
.Controller/button DEI
DUP #40 NEQ ?&no-l
prev-month POP BRK
&no-l
DUP #80 NEQ ?&no-r
next-month POP BRK
&no-r
POP
BRK
(
@|core )
@current-month ( -- )
.DateTime/year DEI2
.DateTime/month DEI
@select-month ( year* m -- )
.month STZ .year STZ2
#00 .month LDZ #20 SFT2 ;months ADD2 ;path scpy
.year LDZ2
DUP2 #000a DIV2 #000a DIV2k MUL2 SUB2 NIP LIT "0 ADD ;path #0003 ADD2 STA
#000a DIV2k MUL2 SUB2 NIP LIT "0 ADD ;path #0004 ADD2 STA
;icn-ext ;path #0005 ADD2 scpy
;data #3eb0 mclr
;path .File/name DEO2
#3eb0 .File/length DEO2
;data .File/read DEO2
;draw-page ( .. )
JMP2
@prev-month ( -- )
.month LDZ
DUP #00 EQU ?&year
#01 SUB .year LDZ2 ROT ;select-month ( .. )
JMP2
&year ( m -- )
.year LDZ2k #0001 SUB2 ROT STZ2
POP #0b .year LDZ2 ROT ;select-month ( .. )
JMP2
@next-month ( -- )
.month LDZ
DUP #0b EQU ?&year
INC .year LDZ2 ROT ;select-month ( .. )
JMP2
&year ( m -- )
.year LDZ2k INC2 ROT STZ2
POP #00 .year LDZ2 ROT ;select-month ( .. )
JMP2
(
@|drawing )
@draw-page ( -- )
( start day )
.year LDZ2 .month LDZ #01 dotw ;draw-cell/offset STA
@draw-month ( -- )
#0000
DUP2 .Screen/x DEO2
.Screen/y DEO2
#21 .Screen/auto DEO
;fill-icn .Screen/addr DEO2
.Screen/width DEI2 #03 SFT2 NIP #00
&l
#02 .Screen/sprite DEO
INC GTHk ?&l
POP2
( name )
#0010 .Screen/x DEO2
#0008 .Screen/y DEO2
#05 ;draw-chr/color STA
#00 .month LDZ #20 SFT2 ;months ADD2 draw-str
.Screen/x DEI2k #0008 ADD2 ROT DEO2
.year LDZ2 draw-dec
( arrows )
#01 .Screen/auto DEO
.Screen/width DEI2 #0028 SUB2 .Screen/x DEO2
;arrow-icn .Screen/addr DEO2
#05 .Screen/sprite DEO
;current-icn .Screen/addr DEO2
#05 .year LDZ2 .month LDZ is-month #0a MUL ADD .Screen/sprite DEO
;arrow-icn .Screen/addr DEO2
#15 .Screen/sprite DEO
@draw-week ( -- )
#01 ;draw-chr/color STA
#0020 .Screen/y DEO2
#0700
&ld
#00 OVR #003f MUL2 #0010 ADD2 .Screen/x DEO2
DUP .DateTime/dotw DEI EQU
.year LDZ2 .month LDZ is-month AND DUP ADD INC ;draw-chr/color STA
#00 OVR #20 SFT2 ;days ADD2 draw-str
INC GTHk ?&ld
POP2
@draw-days ( -- )
#04 ;draw-chr/color STA
#2a00
&l
DUP draw-cell
INC GTHk ?&l
POP2
@draw-image ( -- )
#0000 .Screen/x DEO2
#0018 .Screen/y DEO2
;data .Screen/addr DEO2
#05 .Screen/auto DEO
&stream
#0f .Screen/sprite DEO
.Screen/x DEI2 .Screen/width DEI2 LTH2 ?&no-line
#0000 .Screen/x DEO2
.Screen/y DEI2k #0008 ADD2 ROT DEO2
&no-line
.Screen/y DEI2 .Screen/height DEI2 LTH2 ?&stream
JMP2r
@draw-cell ( id -- )
( background )
#00 OVR #07 DIVk MUL SUB #003f MUL2 #0010 ADD2 .Screen/x DEO2
#00 OVR #07 DIV #0027 MUL2 #0030 ADD2 .Screen/y DEO2
#76 .Screen/auto DEO
;cell-icn .Screen/addr DEO2
#01 .Screen/sprite DEOk DEO
;cell-icn/middle .Screen/addr DEO2
#01 .Screen/sprite DEO
;cell-icn/middle .Screen/addr DEO2
#01 .Screen/sprite DEOk DEO
( id )
#01 ;draw-chr/color STA
.Screen/x DEI2k #0003 ADD2 ROT DEO2
.Screen/y DEI2k #0024 SUB2 ROT DEO2
#01 .Screen/auto DEO
[ LIT &offset $1 ] SUB
DUP #80 GTH ?&skip
INCk .year LDZ2 .month LDZ diam GTH ?&skip
STHk .year LDZ2 .month LDZ STHr INC is-today DUP ADD INC
;draw-chr/color STA
#00 OVR INC draw-dec
&skip
POP
JMP2r
@draw-dec ( short* -- )
#00 ,&z STR
#2710 draw-dec/parse
#03e8 draw-dec/parse
#0064 draw-dec/parse
#000a draw-dec/parse
NIP
&emit
DUP [ LIT &z $1 ] EQU ?&skip
#ff ,&z STR DUP #30 ADD draw-chr
&skip
POP
JMP2r
&parse
DIV2k DUP draw-dec/emit MUL2 SUB2
JMP2r
@draw-short ( short* -- )
SWP draw-byte
@draw-byte ( byte -- )
DUP #04 SFT draw-hex
@draw-hex ( char -- )
#0f AND DUP #09 GTH #27 MUL ADD #30 ADD
@draw-chr ( char -- )
#20 SUB #00 SWP #30 SFT2 ;font ADD2 .Screen/addr DEO2
[ LIT &color 04 ] .Screen/sprite DEO
JMP2r
@draw-str ( str* -- )
LDAk #00 EQU ?&skip
#01 .Screen/auto DEO
&while
LDAk draw-chr
INC2 LDAk ?&while
&skip
POP2
JMP2r
@draw-pointer ( color -- )
#00 .Screen/auto DEO
.pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2
.Screen/sprite DEO
JMP2r
(
@|paint )
@paint-line ( x1* y1* x2* y2* color -- )
( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
,&x LDR2 .line/x LDZ2 SUB2 abs2 .line/dx STZ2
#0000 ,&y LDR2 .line/y LDZ2 SUB2 abs2 SUB2 .line/dy STZ2
#ffff #00 .line/x LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
#ffff #00 .line/y LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2
.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
&loop
.line/x LDZ2 [ LIT2 &x $2 ] EQU2
.line/y LDZ2 [ LIT2 &y $2 ] EQU2
.line/x LDZ2 .line/y LDZ2 STHkr paint-pixel
.line/x LDZ2 .line/y LDZ2 #0018 SUB2 STHkr set-pixel
AND ?&end
.line/e1 LDZ2 DUP2 ADD2 DUP2
.line/dy LDZ2 lts2 ?&skipy
.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
&skipy
.line/dx LDZ2 gts2 ?&skipx
.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
&skipx
,&loop JMP
&end
POPr
JMP2r
@paint-erase ( x* y* -- )
#0004 SUB2 ,&y STR2
#0004 SUB2 ,&x STR2
#0800
&h
STHk
#0800
&w
#00 OVR [ LIT2 &x $2 ] ADD2
#00 STHkr [ LIT2 &y $2 ] ADD2
OVR2 OVR2 #00 paint-pixel
#0018 SUB2 remove-pixel
INC GTHk ?&w
POP2
POPr
INC GTHk ?&h
POP2
JMP2r
@paint-pixel ( x* y* color -- )
STH
.Screen/y DEO2
.Screen/x DEO2
STHr .Screen/pixel DEO
JMP2r
@get-row ( x* y* -- row* )
STH2k
#03 SFT2 SWP2
#03 SFT2 SWP2
#003b MUL2 ADD2 #30 SFT2
STH2r
#0007 AND2 ADD2
;data ADD2
JMP2r
@set-pixel ( x* y* color -- )
?add-pixel
,remove-pixel JMP
JMP2r
@add-pixel ( x* y* -- )
( keep x* ) OVR2 NIP #07 AND STH
( get byte ) get-row LDAk
( mask ) #0107 STHr SUB #40 SFT SFT ORA
( save ) ROT ROT STA
JMP2r
@remove-pixel ( x* y* -- )
( keep x* ) OVR2 NIP #07 AND STH
( get byte ) get-row LDAk
( mask ) #0107 STHr SUB #40 SFT SFT #ff EOR AND
( save ) ROT ROT STA
JMP2r
(
@|utils )
( Tomohiko Sakamoto Method )
@is-today ( year* month day -- bool )
.DateTime/month DEI2 EQU2 STH
.DateTime/year DEI2 EQU2 STHr AND
JMP2r
@is-month ( year* month -- bool )
.DateTime/month DEI EQU STH
.DateTime/year DEI2 EQU2 STHr AND
JMP2r
@dotw ( y* m d -- dotw )
( y -= m < 3; )
OVR STH SWP2 #00 STHr #02 LTH SUB2
STH2
( t[m-1] + d )
#00 ROT ;&t ADD2 LDA #00 SWP
ROT #00 SWP ADD2
( y + y/4 - y/100 + y/400 )
STH2kr
STH2kr #02 SFT2 ADD2
STH2kr #0064 DIV2 SUB2
STH2r #0190 DIV2 ADD2
ADD2
( % 7 )
#0007 DIV2k MUL2 SUB2 NIP
JMP2r
&t 00 03 02 05 00 03 05 01 04 06 02 04
@diam ( year* month -- days )
#00 OVR ;&m ADD2 LDA
SWP #01 NEQ ?&no-feb
STH DUP2 is-leap-year STHr ADD
&no-feb
NIP NIP
JMP2r
&m 1f 1c 1f 1e 1f 1e 1f 1f 1e 1f 1e 1f
@is-leap-year ( year* -- bool )
( leap year if perfectly divisible by 400 )
DUP2 #0190 ( MOD2 ) DIV2k MUL2 SUB2 #0000 EQU2 ?&leap
( not a leap year if divisible by 100 )
( but not divisible by 400 )
DUP2 #0064 ( MOD2 ) DIV2k MUL2 SUB2 #0000 EQU2 ?&not-leap
( leap year if not divisible by 100 )
( but divisible by 4 )
DUP2 #0003 AND2 #0000 EQU2 ?&leap
( all other years are not leap years )
&not-leap
POP2 #00
JMP2r
&leap POP2 #01 JMP2r
( theme )
@load-theme ( -- )
;&path .File/name DEO2
#0002 .File/length DEO2
;&r .File/read DEO2
;&g .File/read DEO2
;&b .File/read DEO2
.File/success DEI2 ORA #01 JCN JMP2r
LIT2 &r $2 .System/r DEO2
LIT2 &g $2 .System/g DEO2
LIT2 &b $2 .System/b DEO2
JMP2r
&path ".theme $1
@mclr ( src* len* -- ) OVR2 ADD2 SWP2 &l STH2k #00 STH2r STA INC2 GTH2k ?&l POP2 POP2 JMP2r
@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
@lts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
@gts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
@scpy ( src* dst* -- ) STH2 &w LDAk STH2kr STA INC2r INC2 LDAk ?&w POP2 #00 STH2r STA JMP2r
(
@|tables )
@days
"Sun $1 "Mon $1 "Tue $1 "Wed $1 "Thu $1 "Fri $1 "Sat $1
@months
"Jan $1 "Feb $1 "Mar $1 "Apr $1 "May $1 "Jun $1
"Jul $1 "Aug $1 "Sep $1 "Oct $1 "Nov $1 "Dec $1
@icn-ext ".icn $1
(
@|assets )
@fill-icn
ffff ffff ffff ffff
@pointer-icn
80c0 e0f0 f8e0 1000
@arrow-icn
1030 7efe 7e30 1000
@current-icn
0018 3c7e 3c18 0000
@cell-icn
&top
ff80 8080 8080 8080 ff00 0000 0000 0000
ff00 0000 0000 0000 ff00 0000 0000 0000
ff00 0000 0000 0000 ff00 0000 0000 0000
ff00 0000 0000 0000 ff01 0101 0101 0101
&middle
8080 8080 8080 8080 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0101 0101 0101 0101
&bottom
8080 8080 8080 80ff 0000 0000 0000 00ff
0000 0000 0000 00ff 0000 0000 0000 00ff
0000 0000 0000 00ff 0000 0000 0000 00ff
0000 0000 0000 00ff 0101 0101 0101 01ff
@font ( atari8 )
0000 0000 0000 0000 6060 6060 6000 6000
6666 6600 0000 0000 006c fe6c 6cfe 6c00
183e 603c 067c 1800 0066 6c18 3066 4600
386c 3870 decc 7600 6060 6000 0000 0000
1c30 3030 3030 1c00 380c 0c0c 0c0c 3800
0066 3cff 3c66 0000 0018 187e 1818 0000
0000 0000 0030 3060 0000 007e 0000 0000
0000 0000 0018 1800 0306 0c18 3060 c000
3c66 6e76 6666 3c00 1838 1818 1818 7e00
3c66 060c 1830 7e00 7e0c 180c 0666 3c00
0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00
3c60 607c 6666 3c00 7e06 0c18 3030 3000
3c66 663c 6666 3c00 3c66 663e 060c 3800
0018 1800 0018 1800 0018 1800 1818 3000
0c18 3060 3018 0c00 0000 7e00 007e 0000
3018 0c06 0c18 3000 3c66 060c 1800 1800
3c66 6e6a 6e60 3e00 183c 6666 7e66 6600
7c66 667c 6666 7c00 3c66 6060 6066 3c00
786c 6666 666c 7800 7e60 607c 6060 7e00
7e60 607c 6060 6000 3e60 606e 6666 3e00
6666 667e 6666 6600 3c18 1818 1818 3c00
3e06 0606 0666 3c00 666c 7870 786c 6600
6060 6060 6060 7e00 c6ee fed6 c6c6 c600
6676 7e7e 6e66 6600 3c66 6666 6666 3c00
7c66 667c 6060 6000 3c66 6666 766c 3600
7c66 667c 6c66 6600 3c66 603c 0666 3c00
7e18 1818 1818 1800 6666 6666 6666 3e00
6666 6666 663c 1800 c6c6 c6d6 feee c600
6666 3c18 3c66 6600 6666 663c 1818 1800
7e06 0c18 3060 7e00 3c30 3030 3030 3c00
c060 3018 0c06 0300 3c0c 0c0c 0c0c 3c00
1038 6cc6 0000 0000 0000 0000 0000 fe00
0060 3018 0000 0000 0000 3c06 3e66 3e00
6060 7c66 6666 7c00 0000 3c60 6060 3c00
0606 3e66 6666 3e00 0000 3c66 7e60 3c00
1c30 7c30 3030 3000 0000 3e66 663e 067c
6060 7c66 6666 6600 1800 3818 1818 3c00
1800 1818 1818 1870 6060 666c 786c 6600
3818 1818 1818 3c00 0000 ecfe d6c6 c600
0000 7c66 6666 6600 0000 3c66 6666 3c00
0000 7c66 6666 7c60 0000 3e66 6666 3e06
0000 7c66 6060 6000 0000 3e60 3c06 7c00
0018 7e18 1818 0e00 0000 6666 6666 3e00
0000 6666 663c 1800 0000 c6c6 d67c 6c00
0000 663c 183c 6600 0000 6666 663e 067c
0000 7e0c 1830 7e00 1c30 3060 3030 1c00
1818 1818 1818 1818 380c 0c06 0c0c 3800
0000 60f2 9e0c 0000 3c42 9985 8599 423c
@data