;mmc-ses-lmc-minor-mode - Define an incomplete minor mode to turn GNU SES into an MMC LMC targeting. ;Copyright (C) 2025 Prince Trippy . ;This program is free software: you can redistribute it and/or modify it under the terms of the ;GNU Affero General Public License version 3 as published by the Free Software Foundation. ;This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ;See the GNU Affero General Public License for more details. ;You should have received a copy of the GNU Affero General Public License along with this program. ;If not, see . ;I've never written a minor mode beforehand; I haven't yet figured out how to do many simple things. ;This minor mode sucks, bluntly, and is meant to do little more than demonstrate my very basic idea. (defvar mmc-ses-lmc-minor-mode-map ;These bindings are meant for the Dvorak layout; adjust to taste. (let ((keymap (make-sparse-keymap))) (define-key keymap (kbd "'") 'mmc-ses-lmc-1xx) (define-key keymap (kbd ",") 'mmc-ses-lmc-2xx) (define-key keymap (kbd ".") 'mmc-ses-lmc-3xx) (define-key keymap (kbd "y") 'mmc-ses-lmc-5xx) (define-key keymap (kbd "f") 'mmc-ses-lmc-6xx) (define-key keymap (kbd "g") 'mmc-ses-lmc-7xx) (define-key keymap (kbd "c") 'mmc-ses-lmc-8xx) (define-key keymap (kbd "r") 'mmc-ses-lmc-901) (define-key keymap (kbd "l") 'mmc-ses-lmc-902) keymap)) (define-minor-mode mmc-ses-lmc-minor-mode "Toggle the Meta-Machine Code (MMC) targeting the Little Man Computer (LMC) for GNU SES." nil " MMC-LMC" mmc-ses-lmc-minor-mode-map (goto-line 2) ;The spreadsheet uses its first line for header cells and starting the address step. (narrow-to-region (point) (point-max))) (defun mmc-ses-lmc-disassemble (integer) "Return the preferred textual form of an instruction in the format required by GNU SES." (list (format (case (/ integer 100) (1 "Increment from %02d") (2 "Decrement from %02d") (3 "Save to %02d") (5 "Load in %02d") (6 "Jump to %02d") (7 "If zero, jump to %02d") (8 "If not negative, jump to %02d") (9 (cond ((= 901 integer) "Take from the in box") ((= 902 integer) "Send to the out box") (t ""))) (otherwise "")) (mod integer 100)))) (defmacro mmc-ses-lmc-definstruction (name code) `(defun ,name (integer) (interactive "nAddress: ") (ses-edit-cell (1- (line-number-at-pos)) 1 (+ (* 100 ,code) integer)))) (mmc-ses-lmc-definstruction mmc-ses-lmc-1xx 1) (mmc-ses-lmc-definstruction mmc-ses-lmc-2xx 2) (mmc-ses-lmc-definstruction mmc-ses-lmc-3xx 3) (mmc-ses-lmc-definstruction mmc-ses-lmc-5xx 5) (mmc-ses-lmc-definstruction mmc-ses-lmc-6xx 6) (mmc-ses-lmc-definstruction mmc-ses-lmc-7xx 7) (mmc-ses-lmc-definstruction mmc-ses-lmc-8xx 8) (defun mmc-ses-lmc-901 () (interactive) (ses-edit-cell (1- (line-number-at-pos)) 1 901)) (defun mmc-ses-lmc-902 () (interactive) (ses-edit-cell (1- (line-number-at-pos)) 1 902)) .