zemu 0.4.0 → 0.4.1

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: caa59294431c1faadda8328bc7fbefa504526ae43a5531e2cf1d6c2bc7dd5c87
4
- data.tar.gz: 72ced5e284f94e586862e80e97f5d95f55a9a3dbc931dc889fdc73352cef3a82
3
+ metadata.gz: 99d9e825251363ade2a565f28d7545f81b3dc93221951980a12bed3d3b8ab82c
4
+ data.tar.gz: c93e03bccdf934341909811d4a2d07fb58d31121cd25983b0659495a2d9b176c
5
5
  SHA512:
6
- metadata.gz: dbb449fa4a076320a3073391f98687098e4e0f8b484099a7ca2c67325f857e8923397267dc01c5bee521cf66e9457149a8845e15f4a8b74ae7962e1f84623ae1
7
- data.tar.gz: 846f7d09837e09fdb5711ba7d3ee09ca734cf0454c10efaff77a2d92de742e88332cc2c3e008db7026c528460368e410c9c9ebaacf29694e513880255085d579
6
+ metadata.gz: 0c4024d10bfd6521b25f98f8172e40163cd635d354961554406532c48f58b2063a3ac945a0378907c472db3287dff3f8643f7bfbbf256684b81a9511a15dd3e1
7
+ data.tar.gz: c826fa009c55c9890faa7d9ef5f172c3ec123a1912e55ff75dca57c51e377cac7014b9d07f8ea9ab682e9ae1ea718c0fae70fda42b0eb0a471fe24c2f494ef96
data/lib/zemu/config.rb CHANGED
@@ -466,18 +466,9 @@ module Zemu
466
466
  #
467
467
  #
468
468
  def initialize
469
- @blocks = []
470
469
  @initialize_from = nil
471
470
 
472
471
  super
473
-
474
- num_sectors.times do
475
- sector = []
476
- sector_size.times do
477
- sector << 0
478
- end
479
- @blocks << sector
480
- end
481
472
 
482
473
  # Initialize from provided file if applicable.
483
474
  unless @initialize_from.nil?
@@ -486,14 +477,6 @@ module Zemu
486
477
  if (file_size != num_sectors * sector_size)
487
478
  raise RangeError, "Initialization file for Zemu::Config::BlockDrive '#{name}' is of wrong size."
488
479
  end
489
-
490
- File.open(@initialize_from, "rb") do |f|
491
- num_sectors.times do |s|
492
- sector_size.times do |b|
493
- @blocks[s][b] = f.getbyte()
494
- end
495
- end
496
- end
497
480
  end
498
481
 
499
482
  when_setup do
@@ -626,7 +609,27 @@ eos
626
609
 
627
610
  # Array of sectors of this drive.
628
611
  def blocks
629
- @blocks
612
+ b = []
613
+
614
+ if @initialize_from.nil?
615
+ num_sectors.times do
616
+ this_block = []
617
+ sector_size.times do
618
+ this_block << 0
619
+ end
620
+ b << this_block
621
+ end
622
+ return b
623
+ end
624
+
625
+ File.open(@initialize_from, "rb") do |f|
626
+ num_sectors.times do
627
+ this_block = f.read(sector_size)
628
+ b << this_block.unpack("C" * sector_size)
629
+ end
630
+ end
631
+
632
+ b
630
633
  end
631
634
 
632
635
  # Set file to initialize from.
data/lib/zemu/instance.rb CHANGED
@@ -37,6 +37,14 @@ module Zemu
37
37
  "L'" => 19
38
38
  }
39
39
 
40
+ # Mapping of extended registers
41
+ # to the registers that comprise them.
42
+ REGISTERS_EXTENDED = {
43
+ "HL" => ["H", "L"],
44
+ "BC" => ["B", "C"],
45
+ "DE" => ["D", "E"]
46
+ }
47
+
40
48
  # States that the emulated machine can be in.
41
49
  class RunState
42
50
  # Currently executing an instruction.
@@ -91,6 +99,12 @@ module Zemu
91
99
  REGISTERS.each do |reg, num|
92
100
  r[reg] = @wrapper.zemu_debug_register(@instance, num)
93
101
  end
102
+
103
+ REGISTERS_EXTENDED.each do |reg, components|
104
+ hi = components[0]
105
+ lo = components[1]
106
+ r[reg] = (r[hi] << 8) | r[lo]
107
+ end
94
108
 
95
109
  return r
96
110
  end
@@ -105,6 +119,16 @@ module Zemu
105
119
  return @wrapper.zemu_debug_get_memory(address)
106
120
  end
107
121
 
122
+ # Set the value in memory at a given address.
123
+ #
124
+ # @param address The address in memory to be set.
125
+ # @param value The value to set to.
126
+ #
127
+ # Returns nothing.
128
+ def set_memory(address, value)
129
+ @wrapper.zemu_debug_set_memory(address, value)
130
+ end
131
+
108
132
  # Write a string to the serial line of the emulated CPU.
109
133
  #
110
134
  # @param string The string to be sent.
@@ -245,6 +269,7 @@ module Zemu
245
269
  wrapper.attach_function :zemu_debug_pc, [:pointer], :uint16
246
270
 
247
271
  wrapper.attach_function :zemu_debug_get_memory, [:uint16], :uint8
272
+ wrapper.attach_function :zemu_debug_set_memory, [:uint16, :uint8], :void
248
273
 
249
274
  configuration.io.each do |device|
250
275
  device.functions.each do |f|
@@ -5,7 +5,13 @@ module Zemu
5
5
  # Constructor.
6
6
  #
7
7
  # Create a new interactive wrapper for the given instance.
8
- def initialize(instance)
8
+ # The options hash allows the user to configure the behaviour
9
+ # of the interactive instance:
10
+ # :print_serial => true if serial input/output should be logged
11
+ # to the emulator window.
12
+ def initialize(instance, options = {})
13
+ @print_serial = options[:print_serial]
14
+
9
15
  @instance = instance
10
16
 
11
17
  @symbol_table = {}
@@ -275,12 +281,12 @@ module Zemu
275
281
 
276
282
  unless input.empty?
277
283
  @instance.serial_puts input
278
- log "Serial in: #{input}"
284
+ log "Serial in: #{input} ($#{input.ord.to_s(16)})" if @print_serial
279
285
  end
280
286
 
281
287
  unless output.empty?
282
288
  @master.write output
283
- log "Serial out: #{output}"
289
+ log "Serial out: #{output} ($#{output.ord.to_s(16)})" if @print_serial
284
290
  end
285
291
  end
286
292
  end
data/lib/zemu.rb CHANGED
@@ -73,10 +73,10 @@ module Zemu
73
73
  # Starts an interactive instance of an emulator, according to the given configuration.
74
74
  #
75
75
  # @param [Zemu::Config] configuration The configuration for which an emulator will be generated.
76
- def Zemu::start_interactive(configuration)
76
+ def Zemu::start_interactive(configuration, options = {})
77
77
  instance = start(configuration)
78
78
 
79
- interactive = InteractiveInstance.new(instance)
79
+ interactive = InteractiveInstance.new(instance, options)
80
80
  interactive.run
81
81
  end
82
82
 
data/src/debug.c CHANGED
@@ -72,3 +72,8 @@ zuint8 zemu_debug_get_memory(zuint16 address)
72
72
  {
73
73
  return zemu_memory_peek(address);
74
74
  }
75
+
76
+ void zemu_debug_set_memory(zuint16 address, zuint8 value)
77
+ {
78
+ zemu_memory_poke(address, value);
79
+ }
data/src/memory.c.erb CHANGED
@@ -9,10 +9,11 @@
9
9
 
10
10
  zuint8 zemu_memory_read(void * context, zuint16 address)
11
11
  {
12
+ zuint32 address_32 = address;
12
13
  <% memory.each do |mem| %>
13
- if (address >= 0x<%= mem.address.to_s(16) %> && address < 0x<%= (mem.address + mem.size).to_s(16) %>)
14
+ if (address_32 >= 0x<%= mem.address.to_s(16) %> && address_32 < 0x<%= (mem.address + mem.size).to_s(16) %>)
14
15
  {
15
- return zemu_memory_block_<%= mem.name %>[address - 0x<%= mem.address.to_s(16) %>];
16
+ return zemu_memory_block_<%= mem.name %>[address_32 - 0x<%= mem.address.to_s(16) %>];
16
17
  }
17
18
  <% end %>
18
19
  /* Unmapped memory has a value of 0. */
@@ -21,23 +22,38 @@ zuint8 zemu_memory_read(void * context, zuint16 address)
21
22
 
22
23
  void zemu_memory_write(void * context, zuint16 address, zuint8 value)
23
24
  {
25
+ zuint32 address_32 = address;
24
26
  <% memory.each do |mem| %>
25
27
  <% next if mem.readonly? %>
26
- if (address >= 0x<%= mem.address.to_s(16) %> && address < 0x<%= (mem.address + mem.size).to_s(16) %>)
28
+ if (address_32 >= 0x<%= mem.address.to_s(16) %> && address_32 < 0x<%= (mem.address + mem.size).to_s(16) %>)
27
29
  {
28
- zemu_memory_block_<%= mem.name %>[address - 0x<%= mem.address.to_s(16) %>] = value;
30
+ zemu_memory_block_<%= mem.name %>[address_32 - 0x<%= mem.address.to_s(16) %>] = value;
29
31
  }
30
32
  <% end %>
31
33
  }
32
34
 
33
35
  zuint8 zemu_memory_peek(zuint16 address)
34
36
  {
37
+ zuint32 address_32 = address;
35
38
  <% memory.each do |mem| %>
36
- if (address >= 0x<%= mem.address.to_s(16) %> && address < 0x<%= (mem.address + mem.size).to_s(16) %>)
39
+ if (address_32 >= 0x<%= mem.address.to_s(16) %> && address_32 < 0x<%= (mem.address + mem.size).to_s(16) %>)
37
40
  {
38
- return zemu_memory_block_<%= mem.name %>[address - 0x<%= mem.address.to_s(16) %>];
41
+ return zemu_memory_block_<%= mem.name %>[address_32 - 0x<%= mem.address.to_s(16) %>];
39
42
  }
40
43
  <% end %>
41
44
  /* Unmapped memory has a value of 0. */
42
45
  return 0;
43
46
  }
47
+
48
+ void zemu_memory_poke(zuint16 address, zuint8 value)
49
+ {
50
+ zuint32 address_32 = address;
51
+ <% memory.each do |mem| %>
52
+ <% next if mem.readonly? %>
53
+ if (address_32 >= 0x<%= mem.address.to_s(16) %> && address_32 < 0x<%= (mem.address + mem.size).to_s(16) %>)
54
+ {
55
+ zemu_memory_block_<%= mem.name %>[address_32 - 0x<%= mem.address.to_s(16) %>] = value;
56
+ return;
57
+ }
58
+ <% end %>
59
+ }
data/src/memory.h.erb CHANGED
@@ -7,3 +7,5 @@ zuint8 zemu_memory_read(void * context, zuint16 address);
7
7
  void zemu_memory_write(void * context, zuint16 address, zuint8 value);
8
8
 
9
9
  zuint8 zemu_memory_peek(zuint16 address);
10
+
11
+ void zemu_memory_poke(zuint16 address, zuint8 value);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zemu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Valentine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-23 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zemu is a gem which allows the user to configure a Z80-based system