First step towards an pseudo-LCD display

Words: lcdon, lcdoff, pixon, pixoff
This commit is contained in:
Gwenhael Le Moine 2023-07-06 15:09:29 +02:00
parent a97d8061d7
commit 422a7828a5
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 84 additions and 2 deletions

11
bin/rpl
View file

@ -60,6 +60,8 @@ class RplRepl
end
end
refresh_lcd if @interpreter.show_lcd
print_stack
rescue Interrupt
puts '^C'
@ -68,6 +70,15 @@ class RplRepl
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
stack_size = @interpreter.stack.size

View file

@ -52,6 +52,7 @@ class Rpl < Interpreter
prepend RplLang::Words::Display
prepend RplLang::Words::FileSystem
prepend RplLang::Words::General
prepend RplLang::Words::Graphics
prepend RplLang::Words::List
prepend RplLang::Words::Logarithm
prepend RplLang::Words::Mode

View file

@ -32,9 +32,12 @@ class Interpreter
attr_reader :stack,
:frame_buffer,
:dictionary,
:version
:version,
:lcd_width,
:lcd_height
attr_accessor :precision
attr_accessor :show_lcd,
:precision
def initialize( stack: [], dictionary: Dictionary.new )
@dictionary = dictionary
@ -45,6 +48,12 @@ class Interpreter
def initialize_frame_buffer
@frame_buffer = BitArray.new
# TODO: make this configurable from rpl?
@lcd_width = 131
@lcd_height = 64
@show_lcd = false
end
def run!( input )

View file

@ -19,3 +19,4 @@ require 'rpl/words/trig'
require 'rpl/words/logarithm'
require 'rpl/words/filesystem'
require 'rpl/words/list'
require 'rpl/words/graphics'

52
lib/rpl/words/graphics.rb Normal file
View 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

View file

@ -79,6 +79,14 @@ module RplLang
category,
'() print internal state of local variables 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