Last active
October 4, 2017 10:27
-
-
Save dave-f/6c2204d6a3288eab36c535b0e7ecab15 to your computer and use it in GitHub Desktop.
Extract map data for BBC micro game Castle Quest into a recognisable emacs buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; Extracting Castle Quest map data; the file is 2K from BBC Micro memory 0x400 | |
; See https://en.wikipedia.org/wiki/Castle_Quest_(1985_video_game)#Development | |
; | |
(defun extract-cq-map() | |
(interactive) | |
(let ((map-data (f-read-bytes "C:/Path/To/Raw/CastleQuestMap"))) | |
(switch-to-buffer (get-buffer-create "*CQ*")) | |
(erase-buffer) | |
(ruler-mode 1) | |
(linum-mode 1) | |
(let ((this-offset 0)) ; 0, 350, 700 | |
(loop for scr from 0 to 4 do ; 4, 4, 3 | |
(loop for i from 0 to 9 do ; 10 across | |
(loop for j from 0 to 6 do ; 7 down | |
(let ((this-byte (string-to-char (substring map-data this-offset (1+ this-offset))))) | |
(insert (propertize (format "%02d" (lsh this-byte -4)) 'face `(:foreground ,(if (= (lsh this-byte -4) 0) "yellow" "red")))) | |
(insert (propertize (format "%02d" (logand this-byte 15)) 'face `(:foreground ,(if (= (logand this-byte 15) 0) "yellow" "red")))) | |
(when (= (forward-line 1) 1) (newline)) | |
(end-of-line) | |
(setq this-offset (1+ this-offset)))) | |
(goto-char (point-min)) | |
(end-of-line))) | |
(reverse-region (point-min) (point-max)) | |
(message "Done. Offset ends at %d" this-offset)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment