Skip to content
Snippets Groups Projects
Select Git revision
  • 6c8ada3599370d10d98fc0e049bcccc6689a3908
  • master default protected
  • 9.0
  • marcus/wix3
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

docode.c

  • parse-map.scm 3.10 KiB
    (use-modules (system foreign)
                 (ice-9 binary-ports)
                 (ice-9 iconv)
                 (rnrs bytevectors)
                 (srfi srfi-1)
                 (srfi srfi-4)
                 (srfi srfi-9)
                 (srfi srfi-9 gnu)
                 )
    
    
    ;;; sizeof:
    ;;; long => 4
    ;;; int  => 2
    
    (begin
      (define long int32)
      (define unsigned uint16)
      (define int int16)
      (define char uint8)
    
      (define NUMMAPS 60)
      (define MAPPLANES 2))
    
    
    (chdir "/home/hugo/wolf3d/WOLF3D-D/")
    
    (define mapfiletype
      (list unsigned      ; RLEWtag
            (make-list 100 long)  ; headeroffsets
            ))
    
    (define-record-type <maphead>
      (make-maphead rlew headeroffsets)
      maphead?
      (rlew get-rlew)
      (headeroffsets get-offsets))
    
    (set-record-type-printer!
     <maphead>
     (lambda (r p)
       (format p "#<<maphead> RLEW: #x~:@(~x~), offsets: (~{#x~:@(~4,'0x~)~^ ~})>"
               (get-rlew r)
               (take-while (negate zero?) (get-offsets r)))))
    
    
    (define maphead
      (call-with-input-file "MAPHEAD.WL1"
        (lambda (port)
          (make-maphead (u16vector-ref (get-bytevector-n port 2) 0)
                        (u32vector->list (get-bytevector-all port))))
        #:binary #t))
    
    (= #xABCD (get-rlew maphead))
    
    (define maptype
      (list (make-list 3 long)              ; planestart
            (make-list 3 unsigned)          ; planelength
            unsigned unsigned               ; width, height
            (make-list 16 char)))           ; name
    
    
    (define-record-type <maptype>
      (make-maptype planestart planelength width height name)
      maptype?
      (planestart  get-planestart)
      (planelength get-planelength)
      (width       get-width)
      (height      get-height)
      (name        get-name))
    
    ;;; ID_CA.C, 1000
    (define maps
     (call-with-input-file "GAMEMAPS.WL1"
       (lambda (port)
         (filter-map
          (lambda (pos)
            (if (= pos 0) #f
                (begin
                  (seek port pos SEEK_SET)
                  (make-maptype
                   (u32vector->list         ; planestart
                    (get-bytevector-n port (* 3 (sizeof long))))
                   (u16vector->list         ; planelength
                    (get-bytevector-n port (* 3 (sizeof unsigned))))
                   (u16vector-ref (get-bytevector-n port (sizeof unsigned)) 0) ; width
                   (u16vector-ref (get-bytevector-n port (sizeof unsigned)) 0) ; height
                   (string-filter           ; name
                    (bytevector->string (get-bytevector-n port 16) "ASCII")
                    (lambda (c) (not (eq? c #\nul))))
                   ;; (bytevector->string (get-bytevector-n port  4) "ASCII") ; "!ID!"
                   ))))
          (get-offsets maphead)))
       #:binary #t))
    
    (let ((m (car maps)))
     (map (lambda (plane)
            (let ((pos (list-ref (get-planestart m) plane))
                  (compressed (list-ref (get-planelength m) plane)))
              (call-with-input-file "GAMEMAPS.WL1"
                (lambda (port)
                  (seek port pos SEEK_SET)
                  (let ((source (get-bytevector-n port compressed)))
                    (let ((expanded (bytevector->int source)))
                      ;; ID_CA.C, 1474
                      ;; aaaaahhhhhh
                      )
                    ))
                #:binary #t)))
          (iota MAPPLANES)))