home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / !BONUS / GAMES / ENGINES / DOOMES19.ZIP / DOOM_ES / CACHE.S < prev    next >
Text File  |  1997-06-16  |  8KB  |  289 lines

  1. *=======================================================*
  2. *    Graphics cache module: latest update 25/03/96    *
  3. *=======================================================*
  4. *    Page unavailable graphics resources into RAM    *
  5. *=======================================================*
  6.  
  7.             rsreset
  8. cache_lt        rs.l    1
  9. cache_rt        rs.l    1
  10. cache_base        rs.l    1
  11. cache_entry        rs.w    1
  12. cache_type        rs.w    1
  13. cache_slen        rs.b    0
  14.  
  15.             rsreset
  16. crout_alloc        rs.l    1
  17. crout_load        rs.l    1
  18. crout_slen        rs.b    0
  19.  
  20.             rsreset
  21. ctype_raw        rs.b    1
  22. ctype_texture        rs.b    1
  23.  
  24. *-------------------------------------------------------*
  25. *    Make graphics available for rendering        *
  26. *-------------------------------------------------------*
  27. cache_resource:
  28. *-------------------------------------------------------*
  29.     lea        cache_slots,a0
  30.     lsl.l        #4,d0
  31.     add.l        d0,a0
  32.     move.l        cache_base(a0),d0
  33.     beq.s        cache_load
  34. *-------------------------------------------------------*
  35. *    Bring resource to front of priority chain    *
  36. *-------------------------------------------------------*
  37. .cache_hit:
  38. *-------------------------------------------------------*
  39. *    Unlink cache slot                *
  40. *-------------------------------------------------------*
  41.     move.l        cache_lt(a0),a1
  42.     move.l        cache_rt(a0),a2
  43.     move.l        a2,cache_rt(a1)
  44.     move.l        a1,cache_lt(a2)
  45. *-------------------------------------------------------*
  46. *    Re-link cache slot at start of chain        *
  47. *-------------------------------------------------------*
  48.     lea        left_cacheslot(pc),a1
  49.     move.l        cache_rt(a1),a2
  50.     move.l        a0,cache_rt(a1)
  51.     move.l        a0,cache_lt(a2)
  52.     move.l        a1,cache_lt(a0)
  53.     move.l        a2,cache_rt(a0)
  54. *-------------------------------------------------------*
  55. .echo_hit:
  56. *-------------------------------------------------------*
  57.     rts
  58.     
  59. *-------------------------------------------------------*
  60. *    Texture is not available - load it from disk    *
  61. *-------------------------------------------------------*
  62. cache_load:
  63. *-------------------------------------------------------*
  64.     pushall
  65. *-------------------------------------------------------*
  66. .cache_alloc:
  67. *-------------------------------------------------------*
  68. *    Determine method for preparing graphics        *
  69. *-------------------------------------------------------*
  70.     move.l        graphics_array,a4
  71.     move.w        cache_entry(a0),d0
  72.     move.l        (a4,d0.w*4),a4
  73.     move.w        cache_type(a0),d0
  74.     lea        cache_routines(pc),a1
  75.     move.l        crout_alloc(a1,d0.w*8),a1
  76.     jsr        (a1)
  77.     move.l        d0,cache_base(a0)
  78.     bne.s        .space_allocated
  79. *-------------------------------------------------------*
  80. *    Deallocate lowest priority slot & retry        *
  81. *-------------------------------------------------------*
  82. .cache_full:
  83. *-------------------------------------------------------*
  84. *    Deallocate memory for resouce            *
  85. *-------------------------------------------------------*
  86.     lea        right_cacheslot(pc),a3
  87.     move.l        cache_lt(a3),a3
  88.     moveq        #0,d1
  89.     move.l        cache_base(a3),d0
  90.     move.l        d1,cache_base(a3)
  91.     bsr        deallocate_chunk
  92. *-------------------------------------------------------*
  93. *    Unlink cache slot                *
  94. *-------------------------------------------------------*
  95.     move.l        cache_lt(a3),a1
  96.     move.l        cache_rt(a3),a2
  97.     move.l        a2,cache_rt(a1)
  98.     move.l        a1,cache_lt(a2)
  99.     bra.s        .cache_alloc
  100. *-------------------------------------------------------*
  101. .space_allocated
  102. *-------------------------------------------------------*
  103. *    Sufficient space allocated for texture        *
  104. *-------------------------------------------------------*
  105. *    Link into list of allocated slots        *
  106. *-------------------------------------------------------*
  107.     lea        left_cacheslot(pc),a1
  108.     move.l        cache_rt(a1),a2
  109.     move.l        a0,cache_rt(a1)
  110.     move.l        a0,cache_lt(a2)
  111.     move.l        a1,cache_lt(a0)
  112.     move.l        a2,cache_rt(a0)
  113. *-------------------------------------------------------*
  114. *    Read data into allocated space            *
  115. *-------------------------------------------------------*
  116.     move.w        cache_type(a0),d0
  117.     lea        cache_routines(pc),a1
  118.     move.l        crout_load(a1,d0.w*8),a1
  119.     jsr        (a1)
  120.     popall
  121.     move.l        cache_base(a0),d0
  122.     rts
  123.  
  124. *-------------------------------------------------------*
  125. init_cache:
  126. *-------------------------------------------------------*
  127.     lea        cache_slots,a1
  128.     move.w        #max_graphics-1,d0
  129.     moveq        #0,d1
  130. .init:    move.w        d1,cache_entry(a1)
  131.     addq.w        #1,d1
  132.     lea        cache_slen(a1),a1
  133. .go:    dbra        d0,.init
  134.     rts
  135.  
  136. *-------------------------------------------------------*
  137. cache_routines:
  138. *-------------------------------------------------------*
  139.     dc.l        alloc_flat,load_flat
  140.     dc.l        alloc_texture,load_texture
  141.  
  142. *-------------------------------------------------------*
  143. alloc_flat:
  144. *-------------------------------------------------------*
  145.     move.l        wd_size(a4),d0
  146.     moveq        #VRAM_preferred,d1
  147.     bsr        allocate_chunk
  148.     rts
  149.  
  150. *-------------------------------------------------------*
  151. alloc_texture:
  152. *-------------------------------------------------------*
  153.     move.w        cache_entry(a0),d0
  154.     move.l        graphics_array,a1
  155.     move.l        (a1,d0.w*4),a1
  156.     move.w        tex_width(a1),d0
  157.     mulu.w        tex_height(a1),d0
  158.     moveq        #VRAM_preferred,d1
  159.     bsr        allocate_chunk
  160.     tst.l        d0
  161.     ble.s        .err
  162. *-------------------------------------------------------*
  163. *    Clear out texture                *
  164. *-------------------------------------------------------*
  165.     push.l        d0
  166.     move.w        tex_width(a1),d1
  167.     mulu.w        tex_height(a1),d1
  168.     lsr.l        #2,d1
  169.     subq.w        #1,d1
  170.     move.l        d0,a1
  171.     moveq        #0,d0
  172. .clr:    move.l        d0,(a1)+
  173.     dbra        d1,.clr
  174.     pop.l        d0
  175. .err:    rts
  176.  
  177. *-------------------------------------------------------*
  178. load_flat:
  179. *-------------------------------------------------------*
  180.     move.l        cache_base(a0),a5
  181. *-------------------------------------------------------*
  182. *    Patch sky flat                    *
  183. *-------------------------------------------------------*
  184.     cmp.l        #'F_SK',wd_name(a4)
  185.     bne.s        .load
  186.     cmp.w        #'Y1',wd_name+4(a4)
  187.     bne.s        .load
  188.     move.w        #(64*64)-1,d0
  189.     move.b        #sky_colour,d1
  190. .clr:    move.b        d1,(a5)+
  191.     dbra        d0,.clr
  192.     bra.s        .done
  193. *-------------------------------------------------------*
  194. *    Load flat from wad                *
  195. *-------------------------------------------------------*
  196. .load:    Fseek        wd_offset(a4),wad_handle,#0
  197.     Fread        wad_handle,wd_size(a4),a5
  198. .done:    rts
  199.  
  200. *-------------------------------------------------------*
  201. load_texture:
  202. *-------------------------------------------------------*
  203.     move.l        cache_base(a0),texture_ptr
  204.     move.w        cache_entry(a0),d0
  205.     pushall
  206.     bsr        render_texture
  207.     popall
  208.     rts
  209.  
  210. *-------------------------------------------------------*
  211. thrash_level:
  212. *-------------------------------------------------------*
  213.     Cconws        #ascii_loadflats
  214.     bsr        thrash_flats
  215.     Cconws        #ascii_loadwalls
  216.     bsr        thrash_textures
  217.     rts
  218.  
  219. *-------------------------------------------------------*
  220. thrash_flats:
  221. *-------------------------------------------------------*
  222.     move.l        Sector_Array,a3
  223.     move.w        NumSectors,d7
  224.     bra.s        .segs
  225. .seg:    move.w        sector_ctns(a3),d0
  226.     bsr        thrash_resource
  227.     move.w        sector_ftns(a3),d0
  228.     bsr        thrash_resource
  229.     lea        sector_len(a3),a3
  230. .segs:    dbra        d7,.seg
  231.     rts
  232.  
  233. *-------------------------------------------------------*
  234. thrash_textures:        
  235. *-------------------------------------------------------*
  236.     move.l        Side_Array,a3
  237.     move.w        NumSides,d7
  238.     bra.s        .segs
  239. .seg:    move.w        sidedef_utns(a3),d0
  240.     bsr        thrash_resource
  241.     move.w        sidedef_ltns(a3),d0
  242.     bsr        thrash_resource
  243.     move.w        sidedef_mtns(a3),d0
  244.     bsr        thrash_resource
  245.     lea        sidedef_len(a3),a3
  246. .segs:    dbra        d7,.seg
  247.     rts
  248.     
  249. *-------------------------------------------------------*
  250. thrash_resource:
  251. *-------------------------------------------------------*
  252.     swap        d0
  253.     clr.w        d0
  254.     swap        d0
  255.     tst.w        d0
  256.     bmi.s        .err
  257.     pushall
  258.     bsr        cache_resource
  259.     popall
  260. .err:    rts
  261.     
  262. *-------------------------------------------------------*
  263. left_cacheslot:
  264. *-------------------------------------------------------*
  265.     dc.l        left_cacheslot
  266.     dc.l        right_cacheslot
  267.     dc.l        0
  268.     dc.w        0
  269.     dc.w        0
  270.  
  271. *-------------------------------------------------------*
  272. right_cacheslot:
  273. *-------------------------------------------------------*
  274.     dc.l        left_cacheslot
  275.     dc.l        right_cacheslot
  276.     dc.l        0
  277.     dc.w        0
  278.     dc.w        0
  279.  
  280. *-------------------------------------------------------*
  281.             bsslong
  282. *-------------------------------------------------------*
  283.  
  284. cache_slots:        ds.b    cache_slen*max_graphics
  285.  
  286. *-------------------------------------------------------*
  287.             txtlong
  288. *-------------------------------------------------------*
  289.