Skip to content

Instantly share code, notes, and snippets.

@dave-f
Last active October 4, 2017 10:27
Show Gist options
  • Save dave-f/6c2204d6a3288eab36c535b0e7ecab15 to your computer and use it in GitHub Desktop.
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
;
; 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