On this page:
with-emulator
6.1 GUI Window
with-emulator-window
emuwin%
new
on-close
wait
6.2 GUI Video
gen:  emufb
emufb?
emufb-width
emufb-height
emufb-dirty?
reset-emufb-dirty!
get-emufb-argb-pixels
emucan%
new
on-char
6.3 Emulated Controller
gen:  emuctrl
emuctrl?
emuctrl-press
emuctrl-release
9.2

6 Emulation🔗

 (require ledum/define/emul) package: ledum-definers

This module provides the with-emulator binding and re-provides the with-emulator-window binding from ledum/define/emul/window.

syntax

(with-emulator (addr word) body ...)

 
  addr : exact-positive-integer?
  word : exact-positive-integer?
Captures log with topic 'ledum for the inner body expressions and sets up the current-bus of given address width addr and data width word.

6.1 GUI Window🔗

 (require ledum/define/emul/window) package: ledum-definers

syntax

(with-emulator-window (vfb) maybe-options body ...)

 
maybe-options = maybe-title maybe-fps maybe-scale
     
maybe-title = 
  | #:title title
     
maybe-fps = 
  | #:fps fps
     
maybe-scale = 
  | #:scale scale
 
  vfb : emufb?
  title : string?
  fps : exact-positive-integer?
  scale : positive-real?
Creates a new emulator window. The initial size is given by the default resolution provided by vfb. If title is given, it is used as the window title. Default title is "Ledum Emulator %wx%h".

The emulator window ensures vfb is regularly checked for updates and if an update is detected, the window contents are redrawn. The frequency of updates is specified in the frames-per-second fps argument which defaults to 25.

The scaling factor scale is applied to the actual window size and the image drawn is scaled by the same factor. Defaults to 1.0. Fractional scaling is supported.

The "%?" sequences are interpreted dynamically by the emuwin% implementation. See its constructor for more information.

class

emuwin% : class?

  superclass: frame%

Extends frame% to provide a full graphics emulator which also captures key events for simple controller processing.

constructor

(new emuwin%    
    [vfb vfb]    
    [ctrl ctrl]    
    [main main]    
    [title title]    
    [[fps fps]    
    [scale scale]])  (is-a?/c emuwin%)
  vfb : emufb?
  ctrl : controller?
  main : (-> any)
  title : string?
  fps : exact-positive-integer? = 25
  scale : positive-real? = 1.0
Creates a new emuwin% with given video framebuffer device vfb as its backend. All the events of key presses and releases are forwarded to given ctrl controller.

The min-width, min-height, width, height, stretchable-width and stretchable-height init fields of frame% class cannot be specified. However all other init fields are passed through.

Creates a background thread in which main is evaluated.

It also creates an internal timer which ticks fps times per second and checks vfb for any updates ensuring given frames per second refresh.

The frame% label is set to title with the following substitutions for character pairs beginning with #\% implemented:

  • #\w - width of the framebuffer

  • #\h - height of the framebuffer

  • #\s - scaling factor in use

  • anything else - the string "%?" is used to signal soft error

method

(send an-emuwin on-close)  void?

Stops the internal timer, breaks the background thread running the main program and waits for it to finish.

method

(send an-emuwin wait)  void?

Waits for the internal thread. Used by with-emulator-window to ensure the control remains in parameterized eventspace.

6.2 GUI Video🔗

 (require ledum/define/emul/video) package: ledum-definers

This module provides a generic interface for any device that can be used with with-emulator-window.

generic interface

gen:emufb

A generic interface for device used as backing framebuffer for the emuwin% emulator window. The interface specifies the following methods:

procedure

(emufb? v)  boolean?

  v : any/c
A predicate returning #t if given v implements the gen:emufb generic interface.

procedure

(emufb-width efb)  exact-positive-integer?

  efb : emufb?
Must return the width in pixels.

procedure

(emufb-height efb)  exact-positive-integer?

  efb : emufb?
Must return the height in pixels.

procedure

(emufb-dirty? efb)  boolean?

  efb : emufb?
Should return #t if redraw is needed.

procedure

(reset-emufb-dirty! efb)  void?

  efb : emufb?
Should reset the dirty flag.

procedure

(get-emufb-argb-pixels efb bs)  bytes?

  efb : emufb?
  bs : (or/c #f bytes?)
Needs to fill the given mutable byte string or produce a new one if none or insufficiently sized is given. The result must be ready to be used for set-argb-pixels of bitmap% class.

class

emucan% : class?

  superclass: canvas%

Overrides on-char to intercept key presses and releases on the canvas. Used by emuwin% for the actual display and keyboard capture.

constructor

(new emucan% 
    [[key-press-callback key-press-callback] 
    [key-release-callback key-release-callback]]) 
  (is-a?/c emucan%)
  key-press-callback : procedure? = void
  key-release-callback : procedure? = void
Creates a new emucan% with given callbacks for respective keyboard events.

method

(send an-emucan on-char ch)  void?

  ch : (is-a?/c key-event%)
Passes key presses and releases to the corresponding key-press-callback and key-release-callback.

6.3 Emulated Controller🔗

 (require ledum/define/emul/controller)
  package: ledum-definers

This module provides a generic interface to keyboard-like controllers.

generic interface

gen:emuctrl

A generic interface for device used as controller with keys that can be pressed and released. The interface specifies the following methods:

  • (emuctrl-press emuctrl kc)

  • (emuctrl-release emuctrl kc)

procedure

(emuctrl? v)  boolean?

  v : any/c
A predicate returning #t if given v implements the gen:emuctrl generic interface.

procedure

(emuctrl-press ec kc)  void?

  ec : emuctrl?
  kc : (or/c char? symbol?)
The emulator calls this method when an actual emulated key of the controller is pressed.

procedure

(emuctrl-release ec kc)  void?

  ec : emuctrl?
  kc : (or/c char? symbol?)
The emulator calls this method when an actual emulated key of the controller is released.