ucisc 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/core/stdlib.ucisc +101 -0
- data/examples/everest_12bit.ucisc +195 -0
- data/examples/factorial.ucisc +24 -22
- data/examples/fib.ucisc +40 -35
- data/examples/hello_world.ucisc +59 -68
- data/examples/paint_image.ucisc +261 -0
- data/exe/png_to_hex +38 -0
- data/exe/ucisc +8 -5
- data/lib/micro_cisc.rb +30 -7
- data/lib/micro_cisc/compile/compiler.rb +10 -2
- data/lib/micro_cisc/compile/instruction.rb +40 -13
- data/lib/micro_cisc/compile/statement.rb +118 -34
- data/lib/micro_cisc/version.rb +1 -1
- data/lib/micro_cisc/vm/color_lcd_display.rb +115 -0
- data/lib/micro_cisc/vm/device.rb +32 -21
- data/lib/micro_cisc/vm/processor.rb +20 -9
- data/lib/micro_cisc/vm/term_device.rb +4 -8
- data/ucisc.gemspec +2 -0
- data/ucisc.vim +14 -8
- metadata +36 -4
- data/examples/image.ucisc +0 -543
- data/lib/micro_cisc/vm/video.rb +0 -151
data/lib/micro_cisc/vm/video.rb
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
module MicroCisc
|
2
|
-
module Vm
|
3
|
-
class Video
|
4
|
-
attr_reader :config_page, :start_page, :page_count, :end_page
|
5
|
-
def initialize(proc_count, mem_size, rom, debug = false)
|
6
|
-
@bytes_per_pixel = 2
|
7
|
-
@w = 640
|
8
|
-
@h = 480
|
9
|
-
@refresh = 24
|
10
|
-
@page_count = (@w * @h * @bytes_per_pixel + 511) / 512
|
11
|
-
@enabled = 1
|
12
|
-
|
13
|
-
# Initialize the control section of main memory
|
14
|
-
config_mem = [@enabled, @w, @h, @bytes_per_pixel, @refresh]
|
15
|
-
config_mem = config_mem + Array.new(256 - config_mem.size).map { 0 }
|
16
|
-
@config_page = 16
|
17
|
-
@start_page = 17
|
18
|
-
@end_page = @config_page + @page_count
|
19
|
-
|
20
|
-
@reader, @writer = IO.pipe
|
21
|
-
|
22
|
-
fork do
|
23
|
-
@reader.close
|
24
|
-
system = System.new(proc_count, mem_size, rom, self, debug)
|
25
|
-
system.write_page(@config_page, config_mem)
|
26
|
-
system.run
|
27
|
-
end
|
28
|
-
|
29
|
-
@writer.close
|
30
|
-
# Initialize the video memory space
|
31
|
-
@memory = [config_mem] + Array.new(@page_count).map { Array.new(256).map { 0 } }
|
32
|
-
launch
|
33
|
-
end
|
34
|
-
|
35
|
-
def send_page_update(main_page, data)
|
36
|
-
msg = Message.new
|
37
|
-
msg.write(main_page, main_page - @config_page, data)
|
38
|
-
msg.write_to_stream(@writer)
|
39
|
-
end
|
40
|
-
|
41
|
-
def launch
|
42
|
-
require 'gtk2'
|
43
|
-
|
44
|
-
Gtk.init
|
45
|
-
|
46
|
-
@image_data = Array.new(@w * @h * 3).map { 0 }
|
47
|
-
pixel_buffer = GdkPixbuf::Pixbuf.new(
|
48
|
-
data: @image_data.pack("C*"),
|
49
|
-
colorspace: GdkPixbuf::Colorspace::RGB,
|
50
|
-
has_alpha: false,
|
51
|
-
bits_per_sample: 8,
|
52
|
-
width: 640,
|
53
|
-
height: 480
|
54
|
-
)
|
55
|
-
@image = Gtk::Image.new(pixel_buffer)
|
56
|
-
|
57
|
-
@window = Gtk::Window.new.set_default_size(640, 480)
|
58
|
-
@window.set_title("uCISC Virtual Machine")
|
59
|
-
@window.set_resizable(false)
|
60
|
-
@window.add(@image)
|
61
|
-
@image.show
|
62
|
-
@window.signal_connect("destroy") do
|
63
|
-
Gtk.main_quit
|
64
|
-
end
|
65
|
-
GLib::Timeout.add(15) do
|
66
|
-
do_update
|
67
|
-
true
|
68
|
-
end
|
69
|
-
@window.show
|
70
|
-
|
71
|
-
Gtk.main
|
72
|
-
end
|
73
|
-
|
74
|
-
def do_update
|
75
|
-
@t0 ||= Time.now
|
76
|
-
@tcount ||= 0
|
77
|
-
changed = false
|
78
|
-
|
79
|
-
while(@reader.ready?) do
|
80
|
-
msg = Message.read_from_stream(@reader)
|
81
|
-
if msg.write?
|
82
|
-
changed = true
|
83
|
-
page = msg.local_page
|
84
|
-
data = msg.data
|
85
|
-
data = data[0...256] if data.size > 256
|
86
|
-
@memory[page] = data
|
87
|
-
|
88
|
-
if msg.local_page == 0
|
89
|
-
@config_page = data
|
90
|
-
@enabled, @w, @h, @bytes_per_pixel, @refresh = @config_page[0...4]
|
91
|
-
@window.resize(@w, @h)
|
92
|
-
else
|
93
|
-
update_page(page)
|
94
|
-
end
|
95
|
-
else
|
96
|
-
exit(0)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
if changed
|
101
|
-
pixel_buffer = GdkPixbuf::Pixbuf.new(
|
102
|
-
data: @image_data.pack("C*"),
|
103
|
-
colorspace: GdkPixbuf::Colorspace::RGB,
|
104
|
-
has_alpha: false,
|
105
|
-
bits_per_sample: 8,
|
106
|
-
width: 640,
|
107
|
-
height: 480
|
108
|
-
)
|
109
|
-
new_image = Gtk::Image.new(pixel_buffer)
|
110
|
-
@window.remove(@image)
|
111
|
-
@window.add(new_image)
|
112
|
-
new_image.show
|
113
|
-
@window.show
|
114
|
-
@image = new_image
|
115
|
-
end
|
116
|
-
|
117
|
-
@tcount += 1
|
118
|
-
if @tcount == 60
|
119
|
-
delta = Time.now - @t0
|
120
|
-
#puts "60 frames in #{delta}s (#{60 / delta} fps)"
|
121
|
-
@t0 = Time.now
|
122
|
-
@tcount = 0
|
123
|
-
end
|
124
|
-
rescue Interrupt
|
125
|
-
end
|
126
|
-
|
127
|
-
def update_page(page)
|
128
|
-
word_offset = (page - 1) * 256
|
129
|
-
finish = word_offset + 256
|
130
|
-
row_words = @bytes_per_pixel * @w / 2
|
131
|
-
pixel_x = word_offset % row_words
|
132
|
-
pixel_y = (word_offset / row_words)
|
133
|
-
|
134
|
-
while word_offset < finish
|
135
|
-
word = @memory[page][word_offset % 256]
|
136
|
-
pixel_offset = (pixel_y * @w + pixel_x) * 3
|
137
|
-
@image_data[pixel_offset] = ((word & 0xF800) >> 8) + 7
|
138
|
-
@image_data[pixel_offset + 1] = ((word & 0x07E0) >> 3) + 3
|
139
|
-
@image_data[pixel_offset + 2] = ((word & 0x001F) << 3) + 7
|
140
|
-
|
141
|
-
word_offset += 1
|
142
|
-
pixel_x += 1
|
143
|
-
if pixel_x % @w == 0
|
144
|
-
pixel_x = 0
|
145
|
-
pixel_y += 1
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|