35 | 35 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,16 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+echo "Formatting.." |
|
4 |
+clang-format -i tables.c |
|
5 |
+ |
|
6 |
+echo "Cleaning.." |
|
7 |
+rm -f ../../bin/tables |
|
8 |
+ |
|
9 |
+echo "Building.." |
|
10 |
+mkdir -p ../../bin |
|
11 |
+cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -lm tables.c -o ../../bin/tables |
|
12 |
+ |
|
13 |
+echo "Assembling.." |
|
14 |
+../../bin/tables |
|
15 |
+ |
|
16 |
+echo "Done." |
0 | 17 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,37 @@ |
1 |
+#include <stdio.h> |
|
2 |
+#include <math.h> |
|
3 |
+ |
|
4 |
+/* |
|
5 |
+Copyright (c) 2020 Devine Lu Linvega |
|
6 |
+ |
|
7 |
+Permission to use, copy, modify, and distribute this software for any |
|
8 |
+purpose with or without fee is hereby granted, provided that the above |
|
9 |
+copyright notice and this permission notice appear in all copies. |
|
10 |
+ |
|
11 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
12 |
+WITH REGARD TO THIS SOFTWARE. |
|
13 |
+*/ |
|
14 |
+ |
|
15 |
+#define PI 3.14159265358979323846 |
|
16 |
+ |
|
17 |
+typedef unsigned char Uint8; |
|
18 |
+ |
|
19 |
+int |
|
20 |
+main() |
|
21 |
+{ |
|
22 |
+ int i; |
|
23 |
+ printf("60 points on a circle128(bytex,bytey):\n\n"); |
|
24 |
+ for(i = 0; i < 60; ++i) { |
|
25 |
+ double cx = 128, cy = 128, r = 127; |
|
26 |
+ double pos = (60 - i + 30) % 60; |
|
27 |
+ double deg = (pos / 60.0) * 360.0; |
|
28 |
+ double rad = deg * (PI / 180); |
|
29 |
+ double x = cx + r * cos(rad); |
|
30 |
+ double y = cy + r * sin(rad); |
|
31 |
+ if(i > 0 && i % 8 == 0) |
|
32 |
+ printf("\n"); |
|
33 |
+ printf("%02x%02x ", (Uint8)x, (Uint8)y); |
|
34 |
+ } |
|
35 |
+ printf("\n\n"); |
|
36 |
+ return 0; |
|
37 |
+} |
... | ... |
@@ -1,8 +1,17 @@ |
1 |
+%RTN { JMP2r } |
|
2 |
+%ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 } |
|
3 |
+%SCALE { #0002 DIV2 #0020 ADD2 } |
|
4 |
+ |
|
1 | 5 |
;current { second 1 } |
6 |
+;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 } |
|
7 |
+;color { byte 1 } |
|
8 |
+;needles { hx 2 hy 2 mx 2 my 2 sx 2 sy 2 } |
|
2 | 9 |
|
3 | 10 |
( devices ) |
4 | 11 |
|
5 | 12 |
|0100 ;Console { pad 8 char 1 byte 1 short 2 } |
13 |
+|0110 ;Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } |
|
14 |
+|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |
|
6 | 15 |
|0190 ;Time { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 get 1 } |
7 | 16 |
|01F0 ;System { pad 8 r 2 g 2 b 2 } |
8 | 17 |
|0200 ,RESET JMP2 |
... | ... |
@@ -11,12 +20,139 @@ |
11 | 20 |
|
12 | 21 |
( program ) |
13 | 22 |
|
14 |
-@RESET BRK |
|
23 |
+@RESET |
|
24 |
+ |
|
25 |
+ ( theme ) #0ff8 =System.r #0f08 =System.g #0f08 =System.b |
|
26 |
+ |
|
27 |
+ ,draw-circle JSR2 |
|
28 |
+ |
|
29 |
+BRK |
|
15 | 30 |
|
16 | 31 |
@FRAME |
32 |
+ |
|
17 | 33 |
#00 =Time.get |
18 | 34 |
~Time.second ~current.second NEQ #01 JNZ BRK |
19 |
- ~Time.second DUP =current.second =Console.byte |
|
20 | 35 |
|
21 |
-@ERROR BRK |
|
36 |
+ ( clear ) |
|
37 |
+ #0080 SCALE #0080 SCALE ~needles.sx ~needles.sy #00 ,draw-line JSR2 |
|
38 |
+ #0080 SCALE #0080 SCALE ~needles.mx ~needles.my #00 ,draw-line JSR2 |
|
39 |
+ #0080 SCALE #0080 SCALE ~needles.hx ~needles.hy #00 ,draw-line JSR2 |
|
40 |
+ |
|
41 |
+ ( place ) |
|
42 |
+ #00 ~Time.second #0002 MUL2 ,table ADD2 LDR2 |
|
43 |
+ #00 SWP SCALE =needles.sy #00 SWP SCALE =needles.sx |
|
44 |
+ |
|
45 |
+ #00 ~Time.minute #0002 MUL2 ,table ADD2 LDR2 |
|
46 |
+ #00 SWP #0004 DIV2 #0003 MUL2 #0020 ADD2 SCALE =needles.my |
|
47 |
+ #00 SWP #0004 DIV2 #0003 MUL2 #0020 ADD2 SCALE =needles.mx |
|
48 |
+ |
|
49 |
+ #00 ~Time.hour #0005 MUL2 #0002 MUL2 ,table ADD2 LDR2 |
|
50 |
+ #00 SWP #0002 DIV2 #0040 ADD2 SCALE =needles.hy |
|
51 |
+ #00 SWP #0002 DIV2 #0040 ADD2 SCALE =needles.hx |
|
52 |
+ |
|
53 |
+ ( draw ) |
|
54 |
+ #0080 SCALE #0080 SCALE ~needles.sx ~needles.sy #02 ,draw-line JSR2 |
|
55 |
+ #0080 SCALE #0080 SCALE ~needles.mx ~needles.my #01 ,draw-line JSR2 |
|
56 |
+ #0080 SCALE #0080 SCALE ~needles.hx ~needles.hy #03 ,draw-line JSR2 |
|
57 |
+ |
|
58 |
+ ,draw-circle JSR2 |
|
59 |
+ |
|
60 |
+ ( display ) |
|
61 |
+ #0000 =Sprite.x |
|
62 |
+ ,font_hex #00 ~Time.hour #f0 AND #04 SFT #08 MUL ADD2 =Sprite.addr |
|
63 |
+ #02 =Sprite.color |
|
64 |
+ #0008 =Sprite.x |
|
65 |
+ ,font_hex #00 ~Time.hour #0f AND #08 MUL ADD2 =Sprite.addr |
|
66 |
+ #02 =Sprite.color |
|
67 |
+ |
|
68 |
+ |
|
69 |
+ #0018 =Sprite.x |
|
70 |
+ ,font_hex #00 ~Time.minute #f0 AND #04 SFT #08 MUL ADD2 =Sprite.addr |
|
71 |
+ #02 =Sprite.color |
|
72 |
+ #0020 =Sprite.x |
|
73 |
+ ,font_hex #00 ~Time.minute #0f AND #08 MUL ADD2 =Sprite.addr |
|
74 |
+ #02 =Sprite.color |
|
75 |
+ |
|
76 |
+ |
|
77 |
+ #0030 =Sprite.x |
|
78 |
+ ,font_hex #00 ~Time.second #f0 AND #04 SFT #08 MUL ADD2 =Sprite.addr |
|
79 |
+ #02 =Sprite.color |
|
80 |
+ #0038 =Sprite.x |
|
81 |
+ ,font_hex #00 ~Time.second #0f AND #08 MUL ADD2 =Sprite.addr |
|
82 |
+ #02 =Sprite.color |
|
83 |
+ |
|
84 |
+BRK |
|
85 |
+ |
|
86 |
+@ERROR |
|
87 |
+ |
|
88 |
+BRK |
|
89 |
+ |
|
90 |
+@draw-circle ( -- ) |
|
91 |
+ |
|
92 |
+ #00 #3c |
|
93 |
+ $loop |
|
94 |
+ ( load ) OVR #00 SWP #0002 MUL2 ,table ADD2 LDR2 |
|
95 |
+ |
|
96 |
+ #00 SWP SCALE =Screen.y |
|
97 |
+ #00 SWP SCALE =Screen.x |
|
98 |
+ #01 =Screen.color |
|
99 |
+ |
|
100 |
+ ( incr ) SWP #01 ADD SWP |
|
101 |
+ DUP2 LTH ^$loop JNZ |
|
102 |
+ POP2 |
|
103 |
+ |
|
104 |
+ #00 ,table PEK2 SCALE =Screen.x |
|
105 |
+ #00 ,table #0001 ADD2 PEK2 SCALE =Screen.y |
|
106 |
+ #02 =Screen.color |
|
107 |
+ |
|
108 |
+RTN |
|
109 |
+ |
|
110 |
+@draw-line ( x1 y1 x2 y2 color -- ) |
|
111 |
+ |
|
112 |
+ ( load ) =color =line.y0 =line.x0 =line.y =line.x |
|
113 |
+ ~line.x0 ~line.x SUB2 ABS2 =line.dx |
|
114 |
+ ~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy |
|
115 |
+ #ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx |
|
116 |
+ #ffff #00 ~line.y ~line.y0 LTS2 #0002 MUL2 ADD2 =line.sy |
|
117 |
+ ~line.dx ~line.dy ADD2 =line.e1 |
|
118 |
+ $loop |
|
119 |
+ ~line.x =Screen.x ~line.y =Screen.y ~color =Screen.color |
|
120 |
+ ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 ^$end JNZ |
|
121 |
+ ~line.e1 #0002 MUL2 =line.e2 |
|
122 |
+ ~line.e2 ~line.dy LTS2 ^$skipy JNZ |
|
123 |
+ ~line.e1 ~line.dy ADD2 =line.e1 |
|
124 |
+ ~line.x ~line.sx ADD2 =line.x |
|
125 |
+ $skipy |
|
126 |
+ ~line.e2 ~line.dx GTS2 ^$skipx JNZ |
|
127 |
+ ~line.e1 ~line.dx ADD2 =line.e1 |
|
128 |
+ ~line.y ~line.sy ADD2 =line.y |
|
129 |
+ $skipx |
|
130 |
+ ,$loop JMP2 |
|
131 |
+ |
|
132 |
+ $end |
|
133 |
+ |
|
134 |
+RTN |
|
135 |
+ |
|
136 |
+@table ( 60 positions on a circle in bytes ) |
|
137 |
+[ |
|
138 |
+ 0180 018d 039a 07a7 0bb3 12bf 19ca 21d4 |
|
139 |
+ 2bde 35e6 40ed 4cf4 58f8 65fc 72fe 80ff |
|
140 |
+ 8dfe 9afc a7f8 b3f4 bfed cae6 d4de ded4 |
|
141 |
+ e6ca edbf f4b3 f8a7 fc9a fe8d ff80 fe72 |
|
142 |
+ fc65 f858 f44c ed40 e635 de2b d421 ca19 |
|
143 |
+ bf12 b30b a707 9a03 8d01 7f01 7201 6503 |
|
144 |
+ 5807 4c0b 4012 3519 2b21 212b 1935 1240 |
|
145 |
+ 0b4c 0758 0365 0172 |
|
146 |
+] |
|
22 | 147 |
|
148 |
+@font_hex ( 0-F ) |
|
149 |
+[ |
|
150 |
+ 007c 8282 8282 827c 0030 1010 1010 1010 |
|
151 |
+ 007c 8202 7c80 80fe 007c 8202 1c02 827c |
|
152 |
+ 000c 1424 4484 fe04 00fe 8080 7c02 827c |
|
153 |
+ 007c 8280 fc82 827c 007c 8202 1e02 0202 |
|
154 |
+ 007c 8282 7c82 827c 007c 8282 7e02 827c |
|
155 |
+ 007c 8202 7e82 827e 00fc 8282 fc82 82fc |
|
156 |
+ 007c 8280 8080 827c 00fc 8282 8282 82fc |
|
157 |
+ 007c 8280 f080 827c 007c 8280 f080 8080 |
|
158 |
+] |