Commit 96774c09 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Suspicious work on parsing graphics.

parent 13be4b10
......@@ -116,9 +116,26 @@
;; verkar även finnas speciella för Spear of Destiny
(define NUMCHUNKS 149) ; GFXV_WL6.H, 183
(define NUMPICS 132) ; GFXV_WL6.H
(define NUMFONT 2) ; 184
(define NUMFONTM 0) ; 185
(define NUMPICS 132) ; GFXV_WL6.H, 186
(define NUMPICM 0)
(define NUMSPRITES 0)
(define NUMTILE8 72)
(define NUMTILE8M 0)
(define NUMTILE16 0)
(define NUMTILE16M 0)
(define NUMTILE32 0)
(define NUMTILE32M 0)
(define NUMEXTERNS 13)
(define STRUCTPIC 0) ; GFXV_WL6.H, 199
(define STARTTILE8 135) ; GFXV_WL6.H, 206
(define STARTTILE8M 136) ; GFXV_WL6.H, 207
(define STARTTILE16 136) ; GFXV_WL6.H, 208
(define STARTTILE16M 136) ; GFXV_WL6.H, 209
(define STARTTILE32 136) ; GFXV_WL6.H, 210
(define STARTTILE32M 136) ; GFXV_WL6.H, 211
(define STARTEXTERNS 136) ; GFXV_WL6.H, 212
......@@ -157,39 +174,47 @@
(define (get-gr-chunk-expanded-size chunk source)
(if (<= STARTTILE8 chunk (1- STARTEXTERNS))
(let ((BLOCK 64)
(MASKBLOCK 128))
(cond [(< chunk STARTTILE8M) (* BLOCK NUMTILES)]
[(< chunk STARTTILE16) (* MASKBLOCK NUMTILES)]
[(< chunk STARTTILE16M) (* BLOCK 4)]
[(< chunk STIRTTILE32) (* MASKBLOCK 4)]
[[< chunk STARTTILE32M] (* BLOCK 16)]
[else (* MASKBLOCK 16)]))
;; ID_CA.C, 1261
(define (get-gr-chunk-expanded-size idx source)
(define BLOCK 64)
(define MASKBLOCK 128)
(if (<= STARTTILE8 idx (1- STARTEXTERNS))
(cond [(< idx STARTTILE8M) (* BLOCK NUMTILE8)]
[(< idx STARTTILE16) (* MASKBLOCK NUMTILE8)]
[(< idx STARTTILE16M) (* BLOCK 4)]
[(< idx STARTTILE32) (* MASKBLOCK 4)]
[[< idx STARTTILE32M] (* BLOCK 16)]
[else (* MASKBLOCK 16)])
(begin1
(bytevector-u32-ref source 0 (endianness little))
(bytevector-drop! source 4))))
;; ID_CA.C, 1261
;; int, bytevector ->
#;
(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)
dest)))
;; int, bytevector ->
;; ID_CA.C, 1318
;; TODO rework this into being sencible, it's mostly a loading routine
;; TODO rework this into being sensible, it's mostly a loading routine
;; since caching is done in a completely different way
(define (cache-gr-chunk idx)
;; port, 24bit-int-table, huff-tree, int ->
(define (load-gr-chunk port chunk-table huff-tree idx) ; (cache-gr-chunk idx)
(define compressed-size (chunk-length chunk-table idx))
;; TODO skip sparse tiles, ID_CA.C, 1341
(define compressed-size (- (gr-file-pos gr-starts (1+ idx))
(gr-file-pos gr-starts idx)))
(define start (chunk-start chunk-table idx))
(seek port start SEEK_SET)
(seek gr-handle (gr-file-pos gr-starts idx) SEEK_SET)
(expand-gr-chunk idx (get-bytevector-n gr-handle compressed-size)))
(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)
dest))
......@@ -206,6 +231,7 @@
;; gr-starts
;; read the table off offsets into the data
;; in VGAGRAPH.
(define chunk-table
(call-with-input-file "VGAHEAD.WL6"
get-bytevector-all #:binary #t))
......@@ -215,7 +241,7 @@
(* FILEPOSSIZE (1+ NUMCHUNKS))
;; => 450
;; open the actual input file
;; open the actual graphics file
(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)
......@@ -238,5 +264,58 @@
(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-syntax-rule (comment c ...) #f)
(comment
(begin
(sdl-init)
(define w (make-window))
(define r (make-renderer w))
(let ((x 0)
(y 0))
(for-each (lambda (c)
(apply set-render-draw-color r c)
(render-draw-point r x y)
(set! x (1+ x))
(when (= x 48)
(set! x 0)
(set! y (1+ y))))
colors)
(format #t "~ax~a~%" x y))
(present-renderer)
))
;; => #t
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