upscheme/scheme-core/dump.scm

18 lines
792 B
Scheme

(define (dump-buffers-as-c-literal . bufs)
(display "unsigned char boot_image[] = {")
(let loop-bufs ((bufs bufs) (any #f))
(if (not (null? bufs))
(begin (let ((buf (car bufs)))
(let loop-buf-bytes ((i 0) (any any))
(let ((char (read-u8 buf)))
(if (not (io.eof? buf))
(let ((code (+ char 0)))
(if any (display ","))
(if (= 0 (mod i 8)) (display "\n"))
(display "0x")
(if (< code #x10) (display "0"))
(display (number->string code 16))
(loop-buf-bytes (+ i 1) #t))))))
(loop-bufs (cdr bufs) #t))))
(display "};\n"))