img_to_script 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +14 -2
- data/lib/img_to_script/abs_token_type.rb +2 -0
- data/lib/img_to_script/abstract_token/load_and_run.rb +19 -0
- data/lib/img_to_script/abstract_token/read_key_value.rb +16 -0
- data/lib/img_to_script/generators/generator.rb +38 -15
- data/lib/img_to_script/generators/hex_mask/enhanced.rb +0 -9
- data/lib/img_to_script/generators/hex_mask/forced_point_move.rb +54 -0
- data/lib/img_to_script/generators/hex_mask/hex_mask.rb +9 -0
- data/lib/img_to_script/languages/mk90_basic/formatters/formatter.rb +1 -1
- data/lib/img_to_script/languages/mk90_basic/formatters/minificator.rb +5 -3
- data/lib/img_to_script/languages/mk90_basic/translators/mixin.rb +4 -13
- data/lib/img_to_script/languages/mk90_basic/translators/mk90_basic_10.rb +25 -0
- data/lib/img_to_script/languages/mk90_basic/translators/mk90_basic_20.rb +26 -0
- data/lib/img_to_script/languages/mk90_basic/translators/translator.rb +4 -0
- data/lib/img_to_script/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711c09a2ddc4d5ac5df11d748d266acab0cc6ea9bf1ea4032e0074920629c373
|
4
|
+
data.tar.gz: be7bdc44d5393fa8ce073b4e18352f27d9182aa21dc2a1cef9d358ca8e7e8e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6648a5244cea7d45c22220b6b6e7e329eee5752335340bda94366a418677bd167bd9d14e3ee4b26836e3adf8cb943c101afd6cdcfe1df155e47a98fe80d7ee1d
|
7
|
+
data.tar.gz: a35c8376f8d67812710a890443fd77cec590dfeaaa353e021d41bc179504d8b203fb63d277a50668cbd08ca9d721b88cb06cf146281df75be1071b7cd91d3cf3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## [1.2.0] - 2024-01-27
|
2
|
+
|
3
|
+
- New experimental feature: load and run another file at the end of the script.
|
4
|
+
|
5
|
+
- Different pause subroutine.
|
6
|
+
|
7
|
+
- Bug fix in the MK90 minificator.
|
8
|
+
|
9
|
+
## [1.1.0] - 2024-01-26
|
10
|
+
|
11
|
+
- New generator: `HexMask::ForcedPointMove`.
|
12
|
+
|
13
|
+
Due to a found bug in the MK90 BASIC v.2.0, hex-mask based generators won't work on this systems. This generator is a workaround that should be used to generate scripts for the v.2.0 systems.
|
14
|
+
|
15
|
+
- Improved MK90 BASIC v.2.0 compatibility
|
16
|
+
|
17
|
+
Due to yet another found bug in the MK90 BASIC v.2.0, the DRAW O statement won't work on this systems. The update introduces a workaround for this bug.
|
18
|
+
|
1
19
|
## [1.0.1] - 2023-12-29
|
2
20
|
|
3
21
|
- Bug fix.
|
data/README.md
CHANGED
@@ -170,22 +170,34 @@ script = task.run(
|
|
170
170
|
|
171
171
|
Add a statement that marks the end of the program.
|
172
172
|
|
173
|
+
- run_another_file, default: ""
|
174
|
+
|
175
|
+
Load and run another script file at the end of the script. String argument represents a file ID (e.g., a filename). If the string is empty, no file should be loaded.
|
176
|
+
|
173
177
|
- **ImgToScript::Generators::HexMask::Default**
|
174
178
|
|
175
|
-
Specific for the Elektronika MK90 BASIC.
|
179
|
+
Specific for the Elektronika MK90 BASIC v.1.0 **only**.
|
176
180
|
|
177
181
|
MK90's BASIC has a balanced build-in method to encode and render images. The Elektronika MK90's manual refers to it as the *hex-mask rendering* method. Each 8x1 px block of a binary image is being represented as a hex value (e.g. '00' for a tile of the 8 white pixels in a row, 'FF' for a tile of the 8 black pixels in a row, etc.). Then these hex values are being passed as arguments to the DRAM/M BASIC statement that renders the image according to the provided data.
|
178
182
|
|
179
183
|
Due to the logic of the DRAM/M operator, only vertical scan lines are supported.
|
180
184
|
|
185
|
+
**Note**: due to a bug in the MK90 BASIC v.2.0 software, this generation method works only on the BASIC v.1.0 systems.
|
186
|
+
|
187
|
+
- **ImgToScript::Generators::HexMask::ForcedPointMove**
|
188
|
+
|
189
|
+
Same as `HexMask::Default`, but with a workaround for the MK90 BASIC v.2.0.
|
190
|
+
|
181
191
|
- **ImgToScript::Generators::HexMask::Enhanced**
|
182
192
|
|
183
|
-
Specific for the Elektronika MK90 BASIC.
|
193
|
+
Specific for the Elektronika MK90 BASIC v.1.0 **only**.
|
184
194
|
|
185
195
|
Hex-mask encoding with modifications what make output BASIC code more compact.
|
186
196
|
|
187
197
|
Due to the logic of the DRAM/M operator, only vertical scan lines are supported.
|
188
198
|
|
199
|
+
**Note**: due to a bug in the MK90 BASIC v.2.0 software, this generation method works only on the BASIC v.1.0 systems.
|
200
|
+
|
189
201
|
- **ImgToScript::Generators::RunLengthEncoding::Horizontal**
|
190
202
|
|
191
203
|
RLE, horizontal scan lines.
|
@@ -15,6 +15,7 @@ module ImgToScript
|
|
15
15
|
DRAW_PIXEL_BY_ABS_COORDS = :draw_pixel_by_abs_coords
|
16
16
|
GO_TO = :go_to
|
17
17
|
IF_CONDITION = :if_condition
|
18
|
+
LOAD_AND_RUN = :load_and_run
|
18
19
|
LOOP_BEGIN = :loop_begin
|
19
20
|
LOOP_END = :loop_end
|
20
21
|
MATH_ADD = :math_add
|
@@ -25,6 +26,7 @@ module ImgToScript
|
|
25
26
|
PARENTHESES = :parentheses
|
26
27
|
PROGRAM_BEGIN = :program_begin_lbl
|
27
28
|
PROGRAM_END_LBL = :program_end_lbl
|
29
|
+
READ_KEY_VALUE = :read_key_value
|
28
30
|
REMARK = :remark
|
29
31
|
SIGN_FUNC = :sign_func
|
30
32
|
SIGN_GREATER_THAN = :sign_greater_than
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ImgToScript
|
4
|
+
module AbstractToken
|
5
|
+
#
|
6
|
+
# Load and run another script file.
|
7
|
+
#
|
8
|
+
class LoadAndRun < AbstractToken
|
9
|
+
attr_reader :filename
|
10
|
+
|
11
|
+
def initialize(filename:, **)
|
12
|
+
@type = AbsTokenType::LOAD_AND_RUN
|
13
|
+
@filename = filename
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ImgToScript
|
4
|
+
module AbstractToken
|
5
|
+
#
|
6
|
+
# Read a key value from the keyboard.
|
7
|
+
#
|
8
|
+
class ReadKeyValue < AbstractToken
|
9
|
+
def initialize(**)
|
10
|
+
@type = AbsTokenType::READ_KEY_VALUE
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -14,6 +14,7 @@ module ImgToScript
|
|
14
14
|
setting :pause_program, default: PAUSE_PROGRAM
|
15
15
|
setting :program_begin_lbl, default: PRORGAM_BEGIN_LBL
|
16
16
|
setting :program_end_lbl, default: PROGRAM_END_LBL
|
17
|
+
setting :run_another_file, default: ""
|
17
18
|
|
18
19
|
#
|
19
20
|
# Generate abstract tokens that represent the image.
|
@@ -44,12 +45,13 @@ module ImgToScript
|
|
44
45
|
private
|
45
46
|
|
46
47
|
def _generate_tokens
|
47
|
-
@tokens = [] # append new tokens
|
48
|
+
@tokens = [] # append new tokens to this arr.
|
48
49
|
|
49
50
|
_program_begin if config.program_begin_lbl
|
50
51
|
_clear_screen if config.clear_screen
|
51
52
|
_generate
|
52
53
|
_program_pause if config.pause_program
|
54
|
+
_run_another_file unless config.run_another_file.empty?
|
53
55
|
_program_end if config.program_end_lbl
|
54
56
|
end
|
55
57
|
|
@@ -98,34 +100,55 @@ module ImgToScript
|
|
98
100
|
# Append a sub-routine to pause the program.
|
99
101
|
#
|
100
102
|
def _program_pause
|
101
|
-
|
102
|
-
|
103
|
-
|
103
|
+
_read_key_value
|
104
|
+
_check_key_value
|
105
|
+
_loop
|
104
106
|
end
|
105
107
|
|
106
|
-
def
|
108
|
+
def _read_key_value
|
107
109
|
@tokens.append(
|
108
|
-
AbstractToken::
|
109
|
-
|
110
|
-
|
111
|
-
var_name: LOOP_VAR,
|
110
|
+
AbstractToken::AssignValue.new(
|
111
|
+
left: "K",
|
112
|
+
right: AbstractToken::ReadKeyValue.new,
|
112
113
|
require_nl: true
|
113
114
|
)
|
114
115
|
)
|
115
116
|
end
|
116
117
|
|
117
|
-
def
|
118
|
+
def _check_key_value
|
119
|
+
expression = AbstractToken::MathGreaterThan.new(
|
120
|
+
left: "K",
|
121
|
+
right: "0"
|
122
|
+
)
|
123
|
+
|
124
|
+
consequent = AbstractToken::GoTo.new(
|
125
|
+
line: CurrentLinePlaceholder.new(2),
|
126
|
+
require_nl: false
|
127
|
+
)
|
128
|
+
|
118
129
|
@tokens.append(
|
119
|
-
AbstractToken::
|
120
|
-
|
130
|
+
AbstractToken::IfCondition.new(
|
131
|
+
expression: expression,
|
132
|
+
consequent: consequent,
|
133
|
+
require_nl: false
|
121
134
|
)
|
122
135
|
)
|
123
136
|
end
|
124
137
|
|
125
|
-
def
|
138
|
+
def _loop
|
126
139
|
@tokens.append(
|
127
|
-
AbstractToken::
|
128
|
-
|
140
|
+
AbstractToken::GoTo.new(
|
141
|
+
line: CurrentLinePlaceholder.new(-1),
|
142
|
+
require_nl: true
|
143
|
+
)
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
def _run_another_file
|
148
|
+
@tokens.append(
|
149
|
+
AbstractToken::LoadAndRun.new(
|
150
|
+
filename: config.run_another_file,
|
151
|
+
require_nl: true
|
129
152
|
)
|
130
153
|
)
|
131
154
|
end
|
@@ -162,15 +162,6 @@ module ImgToScript
|
|
162
162
|
)
|
163
163
|
end
|
164
164
|
|
165
|
-
def _append_move_point(x, y)
|
166
|
-
@tokens.append(
|
167
|
-
AbstractToken::MovePointToAbsCoords.new(
|
168
|
-
x: x,
|
169
|
-
y: y
|
170
|
-
)
|
171
|
-
)
|
172
|
-
end
|
173
|
-
|
174
165
|
#
|
175
166
|
# Replace long sequences of white chunks (0x00) with a shorter manual shift of the (X, Y) point.
|
176
167
|
#
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ImgToScript
|
4
|
+
module Generators
|
5
|
+
module HexMask
|
6
|
+
#
|
7
|
+
# Workaround for the MK90 BASIC v.2.0.
|
8
|
+
#
|
9
|
+
class ForcedPointMove < HexMask
|
10
|
+
SEG_CHUNK_LENGTH = 28
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def _generate
|
15
|
+
_process_seg_chunks(
|
16
|
+
_encode_img.each_slice(SEG_CHUNK_LENGTH).to_a
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def _process_seg_chunks(seg_chunks)
|
21
|
+
x = 0
|
22
|
+
y = 0
|
23
|
+
|
24
|
+
seg_chunks.each do |chunk|
|
25
|
+
# Append only non-white segments:
|
26
|
+
_append_hex_values(chunk) unless _all_elements_equal?(chunk, "00")
|
27
|
+
|
28
|
+
if y + SEG_CHUNK_LENGTH > @scr_height - 1
|
29
|
+
y = (y + SEG_CHUNK_LENGTH) - @scr_height
|
30
|
+
x += CHUNK_WIDTH
|
31
|
+
else
|
32
|
+
y += SEG_CHUNK_LENGTH
|
33
|
+
end
|
34
|
+
|
35
|
+
_append_move_point(x, y)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def _all_elements_equal?(array, value)
|
40
|
+
array.all? { |element| element == value }
|
41
|
+
end
|
42
|
+
|
43
|
+
def _append_hex_values(hex_values)
|
44
|
+
@tokens.append(
|
45
|
+
AbstractToken::DrawChunkByHexValue.new(
|
46
|
+
hex_values: hex_values,
|
47
|
+
require_nl: true
|
48
|
+
)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -174,7 +174,7 @@ module ImgToScript
|
|
174
174
|
end
|
175
175
|
|
176
176
|
def _update_line_num
|
177
|
-
@
|
177
|
+
@i_line += @line_step
|
178
178
|
|
179
179
|
# Since line number has been changed, it is required to
|
180
180
|
# re-evaluate placeholders with the updated value.
|
@@ -210,7 +210,7 @@ module ImgToScript
|
|
210
210
|
# @return [String]
|
211
211
|
#
|
212
212
|
def _select_line_label
|
213
|
-
@number_lines ? @
|
213
|
+
@number_lines ? @i_line.to_s : ""
|
214
214
|
end
|
215
215
|
|
216
216
|
#
|
@@ -242,7 +242,7 @@ module ImgToScript
|
|
242
242
|
def _evaluate_placeholders
|
243
243
|
@placeholders_idx.each do |i|
|
244
244
|
e = @token.args[i]
|
245
|
-
@args[i] = @
|
245
|
+
@args[i] = @i_line + e.shift * @line_step
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
@@ -296,6 +296,8 @@ module ImgToScript
|
|
296
296
|
def _minificator
|
297
297
|
Minificator.new.configure do |config|
|
298
298
|
config.number_lines = false
|
299
|
+
config.line_offset = @i_line + @line_step
|
300
|
+
config.line_step = @line_step
|
299
301
|
end
|
300
302
|
end
|
301
303
|
|
@@ -22,6 +22,10 @@ module ImgToScript
|
|
22
22
|
_single_keyword(token, "END")
|
23
23
|
end
|
24
24
|
|
25
|
+
def _read_key_value(token)
|
26
|
+
_single_keyword(token, "INC")
|
27
|
+
end
|
28
|
+
|
25
29
|
def _data_store(token)
|
26
30
|
MK90BasicToken.new(
|
27
31
|
keyword: "DATA",
|
@@ -96,19 +100,6 @@ module ImgToScript
|
|
96
100
|
_math_operation(token, "*")
|
97
101
|
end
|
98
102
|
|
99
|
-
def _move_point_to_abs_coords(token)
|
100
|
-
MK90BasicToken.new(
|
101
|
-
keyword: "DRAWO",
|
102
|
-
args: _translate_arguments([
|
103
|
-
token.x,
|
104
|
-
token.y
|
105
|
-
]),
|
106
|
-
separator: ",",
|
107
|
-
require_nl: token.require_nl,
|
108
|
-
sliceable: false
|
109
|
-
)
|
110
|
-
end
|
111
|
-
|
112
103
|
def _go_to(token)
|
113
104
|
MK90BasicToken.new(
|
114
105
|
keyword: "GOTO",
|
@@ -20,6 +20,31 @@ module ImgToScript
|
|
20
20
|
sliceable: false
|
21
21
|
)
|
22
22
|
end
|
23
|
+
|
24
|
+
# MK90 BASIC v1.0 - load and run another BASIC file.
|
25
|
+
def _load_and_run(token)
|
26
|
+
MK90BasicToken.new(
|
27
|
+
keyword: "LOAD",
|
28
|
+
args: ["\"", token.filename, "\"", ",", "R"],
|
29
|
+
separator: "",
|
30
|
+
require_nl: token.require_nl,
|
31
|
+
sliceable: false
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# MK90 BASIC v.1.0 does support the DRAW O statement.
|
36
|
+
def _move_point_to_abs_coords(token)
|
37
|
+
MK90BasicToken.new(
|
38
|
+
keyword: "DRAWO",
|
39
|
+
args: _translate_arguments([
|
40
|
+
token.x,
|
41
|
+
token.y
|
42
|
+
]),
|
43
|
+
separator: ",",
|
44
|
+
require_nl: token.require_nl,
|
45
|
+
sliceable: false
|
46
|
+
)
|
47
|
+
end
|
23
48
|
end
|
24
49
|
end
|
25
50
|
end
|
@@ -20,6 +20,32 @@ module ImgToScript
|
|
20
20
|
sliceable: false
|
21
21
|
)
|
22
22
|
end
|
23
|
+
|
24
|
+
# MK90 BASIC v2.0 - load and run another BASIC file.
|
25
|
+
def _load_and_run(token)
|
26
|
+
MK90BasicToken.new(
|
27
|
+
keyword: "LOAD",
|
28
|
+
args: ["\"", token.filename, "\"", ",", "A", ",", "R"],
|
29
|
+
separator: "",
|
30
|
+
require_nl: token.require_nl,
|
31
|
+
sliceable: false
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# MK90 BASIC v.2.0 does NOT support the DRAW O statement due to a bug,
|
36
|
+
# the LOCATE statement should be used instead.
|
37
|
+
def _move_point_to_abs_coords(token)
|
38
|
+
MK90BasicToken.new(
|
39
|
+
keyword: "LOCATE",
|
40
|
+
args: _translate_arguments([
|
41
|
+
token.x,
|
42
|
+
token.y
|
43
|
+
]),
|
44
|
+
separator: ",",
|
45
|
+
require_nl: token.require_nl,
|
46
|
+
sliceable: false
|
47
|
+
)
|
48
|
+
end
|
23
49
|
end
|
24
50
|
end
|
25
51
|
end
|
@@ -46,6 +46,8 @@ module ImgToScript
|
|
46
46
|
_draw_chunk_by_hex_value(token)
|
47
47
|
when AbsTokenType::MOVE_POINT_TO_ABS_COORDS
|
48
48
|
_move_point_to_abs_coords(token)
|
49
|
+
when AbsTokenType::LOAD_AND_RUN
|
50
|
+
_load_and_run(token)
|
49
51
|
when AbsTokenType::MATH_ADD
|
50
52
|
_math_add(token)
|
51
53
|
when AbsTokenType::MATH_SUB
|
@@ -64,6 +66,8 @@ module ImgToScript
|
|
64
66
|
_loop_begin(token)
|
65
67
|
when AbsTokenType::PROGRAM_END_LBL
|
66
68
|
_program_end(token)
|
69
|
+
when AbsTokenType::READ_KEY_VALUE
|
70
|
+
_read_key_value(token)
|
67
71
|
when AbsTokenType::LOOP_END
|
68
72
|
_loop_end(token)
|
69
73
|
when AbsTokenType::IF_CONDITION
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: img_to_script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 8bit-mate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-system
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/img_to_script/abstract_token/draw_pixel_by_abs_coords.rb
|
119
119
|
- lib/img_to_script/abstract_token/go_to.rb
|
120
120
|
- lib/img_to_script/abstract_token/if_condition.rb
|
121
|
+
- lib/img_to_script/abstract_token/load_and_run.rb
|
121
122
|
- lib/img_to_script/abstract_token/loop_begin.rb
|
122
123
|
- lib/img_to_script/abstract_token/loop_end.rb
|
123
124
|
- lib/img_to_script/abstract_token/math_add.rb
|
@@ -128,6 +129,7 @@ files:
|
|
128
129
|
- lib/img_to_script/abstract_token/parentheses.rb
|
129
130
|
- lib/img_to_script/abstract_token/program_begin.rb
|
130
131
|
- lib/img_to_script/abstract_token/program_end.rb
|
132
|
+
- lib/img_to_script/abstract_token/read_key_value.rb
|
131
133
|
- lib/img_to_script/abstract_token/remark.rb
|
132
134
|
- lib/img_to_script/abstract_token/sign_func.rb
|
133
135
|
- lib/img_to_script/abstract_token/wait.rb
|
@@ -139,6 +141,7 @@ files:
|
|
139
141
|
- lib/img_to_script/generators/hex_mask.rb
|
140
142
|
- lib/img_to_script/generators/hex_mask/default.rb
|
141
143
|
- lib/img_to_script/generators/hex_mask/enhanced.rb
|
144
|
+
- lib/img_to_script/generators/hex_mask/forced_point_move.rb
|
142
145
|
- lib/img_to_script/generators/hex_mask/hex_mask.rb
|
143
146
|
- lib/img_to_script/generators/run_length_encoding.rb
|
144
147
|
- lib/img_to_script/generators/run_length_encoding/horizontal.rb
|