1
|
1
|
new file mode 100644
|
...
|
...
|
@@ -0,0 +1,130 @@
|
|
1
|
+( simple Dev/File reading example )
|
|
2
|
+
|
|
3
|
+( devices )
|
|
4
|
+
|
|
5
|
+|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
|
6
|
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|
|
7
|
+|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
|
|
8
|
+
|
|
9
|
+( variables )
|
|
10
|
+
|
|
11
|
+|0000
|
|
12
|
+
|
|
13
|
+( program )
|
|
14
|
+
|
|
15
|
+|0100 @reset ( -> )
|
|
16
|
+
|
|
17
|
+ ( load contents from file )
|
|
18
|
+ #1000 .File/length DEO2
|
|
19
|
+ ;filename .File/name DEO2
|
|
20
|
+ ;contents .File/load DEO2
|
|
21
|
+
|
|
22
|
+ .File/success DEI2 ORA ,&success JCN
|
|
23
|
+ ( failed to read: bright yellow background )
|
|
24
|
+ #f0f7 .System/r DEO2
|
|
25
|
+ #f0f7 .System/g DEO2
|
|
26
|
+ #00f7 .System/b DEO2
|
|
27
|
+ BRK
|
|
28
|
+
|
|
29
|
+ &success
|
|
30
|
+ ( read successful: dark blue background, show contents )
|
|
31
|
+ #00f7 .System/r DEO2
|
|
32
|
+ #00f7 .System/g DEO2
|
|
33
|
+ #40f7 .System/b DEO2
|
|
34
|
+ ;contents DUP2 .File/success DEI2 ADD2 SWP2 ;draw JSR2
|
|
35
|
+ BRK
|
|
36
|
+
|
|
37
|
+@draw ( end-ptr* ptr* -- )
|
|
38
|
+ EQU2k ,&end JCN
|
|
39
|
+ LDAk
|
|
40
|
+ DUP #0a EQU ,&linefeed JCN
|
|
41
|
+ #00 #0005 SFT2 ;font ADD2
|
|
42
|
+ .Screen/addr DEO2
|
|
43
|
+ #29 .Screen/color DEO
|
|
44
|
+ .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
|
|
45
|
+ &next
|
|
46
|
+ #0001 ADD2
|
|
47
|
+ ,draw JMP
|
|
48
|
+
|
|
49
|
+ &linefeed
|
|
50
|
+ POP
|
|
51
|
+ #0000 .Screen/x DEO2
|
|
52
|
+ .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
|
|
53
|
+ ,&next JMP
|
|
54
|
+
|
|
55
|
+ &end
|
|
56
|
+ POP2 POP2
|
|
57
|
+ JMP2r
|
|
58
|
+
|
|
59
|
+@get-x-advance ( font-char-addr* -- advance* )
|
|
60
|
+ ( Save two 00 bytes for later use )
|
|
61
|
+ #0000 SWP2
|
|
62
|
+ ( First, load the eight bytes that make up the character )
|
|
63
|
+ LDA2k SWP2 #0002 ADD2
|
|
64
|
+ LDA2k SWP2 #0002 ADD2
|
|
65
|
+ LDA2k SWP2 #0002 ADD2
|
|
66
|
+ LDA2
|
|
67
|
+ ( OR all the bytes together, so we know which columns contain filled pixels )
|
|
68
|
+ ORA2 ORA2 ORA2 ORA
|
|
69
|
+ ( Find the lowest set bit (using one of the 00 bytes at the top, but not consuming it) )
|
|
70
|
+ SUBk AND
|
|
71
|
+ ( Convert the nine possible values (00-80) into an offset into the magic table (00-08). )
|
|
72
|
+ ( They get jumbled up with these two operations, but each possible value remains unique )
|
|
73
|
+ #a3 MUL #16 DIV
|
|
74
|
+ ( Load the byte from the magic table, return a short (consuming/returning the 00 bytes at the top) )
|
|
75
|
+ ;&magic ADD2 LDA
|
|
76
|
+ JMP2r
|
|
77
|
+ ( The magic table performs the last bit of arithmetic we want:
|
|
78
|
+ * the advance in x should be one more than the number of columns with filled pixels,
|
|
79
|
+ * with a maximum of 8, and
|
|
80
|
+ * a minimum of 3. )
|
|
81
|
+ &magic
|
|
82
|
+ 03 ( lowest set bit is 00, 0 columns wide )
|
|
83
|
+ 06 ( lowest set bit is 08, 5 columns wide )
|
|
84
|
+ 05 ( lowest set bit is 10, 4 columns wide )
|
|
85
|
+ 08 ( lowest set bit is 02, 7 columns wide )
|
|
86
|
+ 04 ( lowest set bit is 20, 3 columns wide )
|
|
87
|
+ 03 ( lowest set bit is 80, 1 column wide )
|
|
88
|
+ 07 ( lowest set bit is 04, 6 columns wide )
|
|
89
|
+ 08 ( lowest set bit is 01, 8 columns wide )
|
|
90
|
+ 03 ( lowest set bit is 40, 2 columns wide )
|
|
91
|
+
|
|
92
|
+@font ( spectrum-zx font )
|
|
93
|
+[
|
|
94
|
+ 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
|
|
95
|
+ 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
|
|
96
|
+ 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000
|
|
97
|
+ 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800
|
|
98
|
+ 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800
|
|
99
|
+ 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038
|
|
100
|
+ 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000
|
|
101
|
+ 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000
|
|
102
|
+ 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400
|
|
103
|
+ 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000
|
|
104
|
+ 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800
|
|
105
|
+ 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000
|
|
106
|
+ 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00
|
|
107
|
+ 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000
|
|
108
|
+ 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810
|
|
109
|
+ 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800
|
|
110
|
+ 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00
|
|
111
|
+ 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00
|
|
112
|
+ 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200
|
|
113
|
+ 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00
|
|
114
|
+ 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00
|
|
115
|
+ 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200
|
|
116
|
+ 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00
|
|
117
|
+ 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00
|
|
118
|
+ 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00
|
|
119
|
+ 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c
|
|
120
|
+ 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400
|
|
121
|
+ 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800
|
|
122
|
+ 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800
|
|
123
|
+ 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800
|
|
124
|
+ 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00
|
|
125
|
+ 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
|
|
126
|
+]
|
|
127
|
+
|
|
128
|
+@filename "hello.txt 00
|
|
129
|
+@contents
|
|
130
|
+
|