img_to_script 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c994729915516c1b890ec338d85867ac2e8071d442f934c00f512645dbc42fa8
4
- data.tar.gz: 9e396865898b8f4bb1644b9120b60163aa850d2e84118959f3a2e21fb914b982
3
+ metadata.gz: 711c09a2ddc4d5ac5df11d748d266acab0cc6ea9bf1ea4032e0074920629c373
4
+ data.tar.gz: be7bdc44d5393fa8ce073b4e18352f27d9182aa21dc2a1cef9d358ca8e7e8e35
5
5
  SHA512:
6
- metadata.gz: d200b4b5f8494e54096941652285689e6bb27f85217381f260b37992dacf02fc428d1d8a902083497701d014739cc7f74435893e91f9afb03121bc524aa14d00
7
- data.tar.gz: bbba0740ea201d70e330bcac059ae9f6904488585f9794e5e66b8f6b02d444cce053b2dfff6e8e6625c0decd70856e7298e57b8cc6d6d5e1154f642c360b9ecb
6
+ metadata.gz: 6648a5244cea7d45c22220b6b6e7e329eee5752335340bda94366a418677bd167bd9d14e3ee4b26836e3adf8cb943c101afd6cdcfe1df155e47a98fe80d7ee1d
7
+ data.tar.gz: a35c8376f8d67812710a890443fd77cec590dfeaaa353e021d41bc179504d8b203fb63d277a50668cbd08ca9d721b88cb06cf146281df75be1071b7cd91d3cf3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  ## [1.1.0] - 2024-01-26
2
10
 
3
11
  - New generator: `HexMask::ForcedPointMove`.
data/README.md CHANGED
@@ -170,6 +170,10 @@ 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
179
  Specific for the Elektronika MK90 BASIC v.1.0 **only**.
@@ -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 here
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
- _loop_begin
102
- _wait
103
- _loop_end
103
+ _read_key_value
104
+ _check_key_value
105
+ _loop
104
106
  end
105
107
 
106
- def _loop_begin
108
+ def _read_key_value
107
109
  @tokens.append(
108
- AbstractToken::LoopBegin.new(
109
- start_value: 1,
110
- end_value: WAIT_LOOP_COUNT,
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 _wait
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::Wait.new(
120
- time: WAIT_TIME
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 _loop_end
138
+ def _loop
126
139
  @tokens.append(
127
- AbstractToken::LoopEnd.new(
128
- var_name: LOOP_VAR
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
@@ -40,7 +40,7 @@ module ImgToScript
40
40
  end
41
41
 
42
42
  def _calc_initial_line_number
43
- @n_line = @line_offset - @line_step
43
+ @i_line = @line_offset - @line_step
44
44
  end
45
45
  end
46
46
  end
@@ -174,7 +174,7 @@ module ImgToScript
174
174
  end
175
175
 
176
176
  def _update_line_num
177
- @n_line += @line_step
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 ? @n_line.to_s : ""
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] = @n_line + e.shift * @line_step
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",
@@ -21,6 +21,17 @@ module ImgToScript
21
21
  )
22
22
  end
23
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
+
24
35
  # MK90 BASIC v.1.0 does support the DRAW O statement.
25
36
  def _move_point_to_abs_coords(token)
26
37
  MK90BasicToken.new(
@@ -21,6 +21,17 @@ module ImgToScript
21
21
  )
22
22
  end
23
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
+
24
35
  # MK90 BASIC v.2.0 does NOT support the DRAW O statement due to a bug,
25
36
  # the LOCATE statement should be used instead.
26
37
  def _move_point_to_abs_coords(token)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImgToScript
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
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.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: 2024-01-26 00:00:00.000000000 Z
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