First step towards an pseudo-LCD display
Words: lcdon, lcdoff, pixon, pixoff
This commit is contained in:
parent
a97d8061d7
commit
422a7828a5
6 changed files with 84 additions and 2 deletions
11
bin/rpl
11
bin/rpl
|
@ -60,6 +60,8 @@ class RplRepl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
refresh_lcd if @interpreter.show_lcd
|
||||||
|
|
||||||
print_stack
|
print_stack
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
puts '^C'
|
puts '^C'
|
||||||
|
@ -68,6 +70,15 @@ class RplRepl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def refresh_lcd
|
||||||
|
@interpreter.lcd_width.times do |x|
|
||||||
|
@interpreter.lcd_height.times do |y|
|
||||||
|
putc @interpreter.frame_buffer[ ( y * @interpreter.lcd_height ) + x ].zero? ? '_' : '.'
|
||||||
|
end
|
||||||
|
puts "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def print_stack
|
def print_stack
|
||||||
stack_size = @interpreter.stack.size
|
stack_size = @interpreter.stack.size
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ class Rpl < Interpreter
|
||||||
prepend RplLang::Words::Display
|
prepend RplLang::Words::Display
|
||||||
prepend RplLang::Words::FileSystem
|
prepend RplLang::Words::FileSystem
|
||||||
prepend RplLang::Words::General
|
prepend RplLang::Words::General
|
||||||
|
prepend RplLang::Words::Graphics
|
||||||
prepend RplLang::Words::List
|
prepend RplLang::Words::List
|
||||||
prepend RplLang::Words::Logarithm
|
prepend RplLang::Words::Logarithm
|
||||||
prepend RplLang::Words::Mode
|
prepend RplLang::Words::Mode
|
||||||
|
|
|
@ -32,9 +32,12 @@ class Interpreter
|
||||||
attr_reader :stack,
|
attr_reader :stack,
|
||||||
:frame_buffer,
|
:frame_buffer,
|
||||||
:dictionary,
|
:dictionary,
|
||||||
:version
|
:version,
|
||||||
|
:lcd_width,
|
||||||
|
:lcd_height
|
||||||
|
|
||||||
attr_accessor :precision
|
attr_accessor :show_lcd,
|
||||||
|
:precision
|
||||||
|
|
||||||
def initialize( stack: [], dictionary: Dictionary.new )
|
def initialize( stack: [], dictionary: Dictionary.new )
|
||||||
@dictionary = dictionary
|
@dictionary = dictionary
|
||||||
|
@ -45,6 +48,12 @@ class Interpreter
|
||||||
|
|
||||||
def initialize_frame_buffer
|
def initialize_frame_buffer
|
||||||
@frame_buffer = BitArray.new
|
@frame_buffer = BitArray.new
|
||||||
|
|
||||||
|
# TODO: make this configurable from rpl?
|
||||||
|
@lcd_width = 131
|
||||||
|
@lcd_height = 64
|
||||||
|
|
||||||
|
@show_lcd = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def run!( input )
|
def run!( input )
|
||||||
|
|
|
@ -19,3 +19,4 @@ require 'rpl/words/trig'
|
||||||
require 'rpl/words/logarithm'
|
require 'rpl/words/logarithm'
|
||||||
require 'rpl/words/filesystem'
|
require 'rpl/words/filesystem'
|
||||||
require 'rpl/words/list'
|
require 'rpl/words/list'
|
||||||
|
require 'rpl/words/graphics'
|
||||||
|
|
52
lib/rpl/words/graphics.rb
Normal file
52
lib/rpl/words/graphics.rb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RplLang
|
||||||
|
module Words
|
||||||
|
module Graphics
|
||||||
|
include Types
|
||||||
|
|
||||||
|
def populate_dictionary
|
||||||
|
super
|
||||||
|
|
||||||
|
category = 'Graphics'
|
||||||
|
|
||||||
|
@dictionary.add_word!( ['lcdon'],
|
||||||
|
category,
|
||||||
|
'( -- ) display lcd',
|
||||||
|
proc do
|
||||||
|
# Sets on a boolean that the REPL will survey and show the Gosu window when true
|
||||||
|
@show_lcd = true
|
||||||
|
end )
|
||||||
|
|
||||||
|
@dictionary.add_word!( ['lcdoff'],
|
||||||
|
category,
|
||||||
|
'( -- ) hide lcd',
|
||||||
|
proc do
|
||||||
|
# Sets on a boolean that the REPL will survey and hide the Gosu window when false
|
||||||
|
@show_lcd = false
|
||||||
|
end )
|
||||||
|
|
||||||
|
@dictionary.add_word!( ['pixon'],
|
||||||
|
category,
|
||||||
|
'( x y -- ) turn on pixel at x y coordinates',
|
||||||
|
proc do
|
||||||
|
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
||||||
|
|
||||||
|
puts "DEBUG: turn on pixel(x: #{args[1].value}, y: #{args[0].value})"
|
||||||
|
x = args[1].value.to_i
|
||||||
|
y = args[0].value.to_i
|
||||||
|
|
||||||
|
@frame_buffer[ ( y * @lcd_height ) + x ] = 1
|
||||||
|
end )
|
||||||
|
@dictionary.add_word!( ['pixoff'],
|
||||||
|
category,
|
||||||
|
'( x y -- ) turn off pixel at x y coordinates',
|
||||||
|
proc do
|
||||||
|
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
||||||
|
|
||||||
|
puts "DEBUG: turn off pixel(x: #{args[1].value}, y: #{args[0].value})"
|
||||||
|
end )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -79,6 +79,14 @@ module RplLang
|
||||||
category,
|
category,
|
||||||
'() print internal state of local variables layers',
|
'() print internal state of local variables layers',
|
||||||
proc { pp @dictionary.local_vars_layers } )
|
proc { pp @dictionary.local_vars_layers } )
|
||||||
|
|
||||||
|
@dictionary.add_word!( ['.fb'],
|
||||||
|
category,
|
||||||
|
'() print internal state of framebuffer',
|
||||||
|
proc do
|
||||||
|
pp @show_lcd
|
||||||
|
pp @frame_buffer
|
||||||
|
end )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue