Commit 6f4d69de authored by Hugo Hörnquist's avatar Hugo Hörnquist

Work on parse-graphics.

parent 270534c7
......@@ -63,7 +63,7 @@
;; ID_CA.C, 418
;; bytevector -> bytevector -> huffman-tree
(define (huffman-expand source dest tree)
(define (huffman-expand! source dest tree)
;; Returns the next bit in from the source vector.
(define next-bit!
......@@ -211,7 +211,7 @@
(define (expand-gr-chunk chunk source)
(let ((expanded-size (get-gr-chunk-expanded-size chunk source)))
(let ((dest (make-bytevector expanded-size)))
(huffman-expand source dest huff-tree)
(huffman-expand! source dest huff-tree)
dest)))
;; int, bytevector ->
......@@ -230,7 +230,7 @@
(let* ((source (get-bytevector-n port compressed-size))
(expanded-size (get-gr-chunk-expanded-size idx source))
(dest (make-bytevector expanded-size)))
(huffman-expand source dest huff-tree)
(huffman-expand! source dest huff-tree)
dest))
......@@ -270,20 +270,27 @@
;; open the actual graphics file
;; ID_CA.C, 915
(define gr-handle (open-input-file "VGAGRAPH.WL6" #:binary #t))
;; seek to start of STRUCTPIC (usually 0)
;; (seek gr-handle (chunk-start chunk-table STRUCTPIC) SEEK_SET)
(seek gr-handle (list-ref gr-file-pos STRUCTPIC) SEEK_SET)
(define structpic-size (s32vector-ref (get-bytevector-n gr-handle 4) 0))
(define chunk-compressed-length
(- (list-ref gr-file-pos (1+ STRUCTPIC))
(list-ref gr-file-pos STRUCTPIC)
4))
(define compressed-data (get-bytevector-n gr-handle chunk-compressed-length))
(define pictable (make-bytevector (* NUMPICS (sizeof int16) 2)))
(define (read-s32 port)
(s32vector-ref (get-bytevector-n port 4) 0))
(define (read-entry port chunk-idx)
(define start (list-ref gr-file-pos chunk-idx))
(define end (list-ref gr-file-pos (1+ chunk-idx)))
(define comp-length (- end start 4))
(seek port start SEEK_SET)
(let ((exp-length (read-s32 port)))
(values exp-length (get-bytevector-n port comp-length))))
(define dest-bv (make-bytevector structpic-size))
;; Huff-expand fails, it REALLY shouldn't
(huffman-expand compressed-data dest-bv huff-tree)
;; ID_CA.C, 923
(define-values (exp-size bv) (read-entry gr-handle STRUCTPIC))
(huffman-expand! bv pictable huff-tree)
......@@ -293,46 +300,8 @@
;; }
;; @end example
;; ID_CA.C, 928
(define pictable
(let* ((size (* NUMPICS 2 2))
(dest (make-bytevector size)))
(assert (= structpic-size size))
(huffman-expand (get-bytevector-n gr-handle (- (chunk-length chunk-table STRUCTPIC) 4))
dest huff-tree)
dest))
(define piclist
(bytevector->sint-list pictable (endianness little) 2))
(define p1 (load-gr-chunk gr-handle chunk-table huff-tree STARTTILE8))
;;; WL_GAME.C, 877
(define MACHINEGUNPIC 94) ; GFXV_WL6.H, 103
(define machine-gun-pic-bytes (load-gr-chunk gr-handle chunk-table huff-tree MACHINEGUNPIC))
(define (list-slice lst from to)
(list-head (list-tail lst from) (- to from)))
;;; transform bytevector of length 1152 into 24 * 48 list
(define machine-gun-list
(let ((l (bytevector->u8-list machine-gun-pic-bytes)))
(map (lambda (i) (list-slice l (* 24 i) (* 24 (1+ i))))
(iota 48))))
(define (print-list-list list-list)
(format #t "~{|~{~2,x ~}|~%~}~%" list-list))
(define machine-gun-planes
(list
(list-slice machine-gun-list 0 12)
(list-slice machine-gun-list 12 24)
(list-slice machine-gun-list 24 36)
(list-slice machine-gun-list 36 48)))
;; rgba? tupples
(define colors (apply zip (map concatenate machine-gun-planes)))
;; this looks far from good
;; => (41 7192 -26214 7453 7709 4608 19753 7453 13086 2048 25856 23016 23016 11234 -8919 13056 11550 10537 28416 -26643 200 11752 41 -5502 5916 7453 0 12288 -7168 5916 7453 12303 19 41 10541 4937 10496 11520 18729 18761 18761 18761 -25088 0 6626 13056 2078 18729 2078 18729 -7650 10541 -13056 10541 -13056 10541 -13056 10541 -13056 10541 -13056 10541 -26861 10623 32617 41 24296 15 41 21992 21986 6626 1821 -26214 15 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 -5225 12303 41 -26769 4075 10544 28416 16279 5916 32663 48 -25639 25615 25615 18703 9472 -8960 10745 2048 7680 7704 18703 22016 37 6174 6400 7465 205 10649 11550 41 11725 41 11725 41 11725 41 -26879 7231 -26857 12415 256 16279 5916 32663 48 -26879 7231 -26857 12415 256 16279 5916 32663 48 -26879 7231 23 -18135 19 41 10541 4937 10496 11520 18729 19 41 10541 4937 10496 11520 18729 19 41 10541 4937 10496 11520 18729 19 41 10541 4937 10496 11520 18729 19 41 10541 4937 10496 11520 18729 19 41 10541 4937 10496 16384 10623 24832 7465 31458 -5888 107 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
;; (define (print-list-list list-list)
;; (format #t "~{|~{~2,x ~}|~%~}~%" list-list))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment