home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / BM192A.ZIP / DOOM.S < prev    next >
Encoding:
Text File  |  1996-02-23  |  14.8 KB  |  526 lines

  1. *=======================================================*
  2. *    Falcon030 Doom project (Bad Mood) v1.92 alpha    *
  3. *=======================================================*
  4. *    Main core: latest update 23/02/96        *
  5. *=======================================================*
  6.  
  7.     OPT        P=68030
  8.     OPT        O+,W-
  9.  
  10. *-------------------------------------------------------*
  11. *    Conditional options                *
  12. *-------------------------------------------------------*
  13.  
  14. test            ; enable for pre-defined WAD (debug).
  15. ;debuggable        ; enable for 'soft' safe interrupts.
  16. enable_timing        ; enable for timing information.
  17.  
  18. *-------------------------------------------------------*
  19. *    Display settings                    *
  20. *-------------------------------------------------------*
  21.  
  22. default_width        =    320    ; default width
  23. default_height        =    200    ; vertical normal mode (status bar)
  24. expanded_height        =    240    ; vertical fullscreen mode
  25.  
  26. base_aspect        =    200    ; base reference (unadjusted) ratio.
  27. vga_aspect        =    240    ; 240-line aspect ratio (VGA).
  28. rgb_aspect        =    200    ; 200-line aspect ratio (PAL).
  29.  
  30. *-------------------------------------------------------*
  31.  
  32. base_red        =    255
  33. base_green        =    255
  34. base_blue        =    255
  35.  
  36. *-------------------------------------------------------*
  37. *    Keycodes for control & player movement        *
  38. *-------------------------------------------------------*
  39. *    These should go away once the event-based    *
  40. *    keyboard routines are ready.            *
  41. *-------------------------------------------------------*
  42.  
  43. rise_key        =    2
  44. drop_key        =    3
  45. hres_key        =    4
  46. vres_key        =    5
  47. text_key        =    28
  48.  
  49. rgb_key            =    19
  50. vga_key            =    47
  51. full_key        =    33
  52.  
  53. quit_key        =    1    ; 'ESC' key
  54. map_key            =    15    ; 'TAB' key
  55.  
  56. minus_key        =    12    ;
  57. plus_key        =    13    ;
  58.  
  59. left_key        =    $4b    ; left arrow
  60. right_key        =    $4d    ; right arrow
  61. forward_key        =    $48    ; up arrow
  62. back_key        =    $50    ; down arrow
  63. alt_key            =    $38    ; 'ALT' key
  64.  
  65. *-------------------------------------------------------*
  66. *    Main program includes                *
  67. *-------------------------------------------------------*
  68.  
  69.     include        include\header.s
  70.     include        include\macros.s
  71.     include        include\video.s
  72.  
  73. *-------------------------------------------------------*
  74. *    DSP core includes                *
  75. *-------------------------------------------------------*
  76.  
  77.     include        include\dspconst.s
  78.     
  79. *-------------------------------------------------------*
  80. *    Mark TEXT, DATA & BSS reference sections    *
  81. *-------------------------------------------------------*
  82.     bss
  83. *-------------------------------------------------------*
  84. bss_start:
  85. *-------------------------------------------------------*
  86.     data
  87. *-------------------------------------------------------*
  88. data_start:
  89. *-------------------------------------------------------*
  90.     text
  91. *-------------------------------------------------------*
  92. text_start:
  93. *-------------------------------------------------------*
  94. *    Path for pre-defined WAD            *    
  95. *-------------------------------------------------------*
  96.     bra        Doom
  97. *-------------------------------------------------------*
  98.  
  99. default_path:        ;dc.b    'l:\wads\doom.wad e1m1'
  100.             dc.b    'l:\wads\doom1.wad'
  101.             ;dc.b    'l:\wads\heretic1.wad e1m2'
  102.             dc.b    0
  103.  
  104. iwad_path:        ds.b    256
  105. levelmarker:        ds.b    8
  106.  
  107. *-------------------------------------------------------*
  108. *    Program starts here                *    
  109. *-------------------------------------------------------*
  110.     txtlong
  111. *-------------------------------------------------------*
  112.  
  113. Doom:    move.l        4(sp),a5
  114.     lea        128(a5),a4    ; command string
  115.     move.l        a4,cli
  116.     move.l        12(a5),d0    ; text segment
  117.     add.l        20(a5),d0    ; data segment
  118.     add.l        28(a5),d0    ; bss segment
  119.     add.l        #$100,d0    ; base page
  120.     move.l        d0,-(sp)
  121.     move.l        a5,-(sp)
  122.     clr.w        -(sp)
  123.     move.w        #$4a,-(sp)
  124.     trap        #1        ; mshrink
  125.     lea        12(sp),sp
  126. *-------------------------------------------------------*
  127. *    Hide mouse                    *
  128. *-------------------------------------------------------*
  129.     dc.w        $A00A
  130. *-------------------------------------------------------*
  131. *    Commandline module                *
  132. *-------------------------------------------------------*
  133.     move.l        cli,a5
  134. *-------------------------------------------------------*
  135.     ifnd        test
  136. *-------------------------------------------------------*
  137.     moveq        #0,d0
  138.     move.b        (a5)+,d0
  139.     bne.s        .load
  140.     moveq        #4,d0
  141.     bra        safe_quit
  142. *-------------------------------------------------------*
  143.     elseif
  144. *-------------------------------------------------------*
  145.     lea        default_path,a5
  146.     move.w        #255,d0
  147. *-------------------------------------------------------*
  148.     endc
  149. *-------------------------------------------------------*
  150. .load:    lea        iwad_path,a0
  151.     lea        levelmarker,a2    
  152.     move.l        #-1,(a2)
  153. .nwad:    move.b        (a5)+,d1
  154.     beq.s        .adon
  155.     fixcase        d1
  156.     cmp.b        #' ',d1
  157.     beq.s        .lwad
  158.     move.b        d1,(a0)+
  159.     subq.w        #1,d0
  160.     bne.s        .nwad
  161.     bra.s        .adon
  162. .nlwad:    move.b        (a5)+,d1
  163.     beq.s        .done
  164.     fixcase        d1
  165.     move.b        d1,(a2)+
  166. .lwad    subq.w        #1,d0
  167.     bne.s        .nlwad
  168. .done:    clr.b        (a2)
  169. .adon:    clr.b        (a0)
  170. *-------------------------------------------------------*
  171. *    Flush out BSS                    *
  172. *-------------------------------------------------------*
  173.     lea        bss_start,a0
  174.     move.l        #(bss_end-bss_start)/4,d0
  175.     moveq        #0,d1
  176. .clr:    move.l        d1,(a0)+
  177.     subq.l        #1,d0
  178.     bne.s        .clr
  179. *-------------------------------------------------------*
  180. *    Flush keyboard buffer                *
  181. *-------------------------------------------------------*
  182.     bsr        empty_buffer
  183. *-------------------------------------------------------*
  184. *    Parse Doom WAD file                *
  185. *-------------------------------------------------------*
  186.     bsr        parse_iwad
  187. *-------------------------------------------------------*
  188. *    Load level resources                *
  189. *-------------------------------------------------------*
  190.     bsr        load_leveldata
  191.     bsr        init_pnodes
  192. *-------------------------------------------------------*
  193. *    Initialise textures & colourmaps        *
  194. *-------------------------------------------------------*
  195.     bsr        init_textures
  196.     bsr        init_colours
  197. *-------------------------------------------------------*
  198. *    Calculate wall lengths                *
  199. *-------------------------------------------------------*
  200.     bsr        measure_linedefs
  201. *-------------------------------------------------------*
  202. *    Wad parsing complete - close wadfile & pause    *
  203. *-------------------------------------------------------*
  204.     bsr        close_wad
  205.     Crawcin
  206. *-------------------------------------------------------*
  207. *    Switch to supervisor mode            *
  208. *-------------------------------------------------------*
  209.     pea        ourstack
  210.     push.w        #32
  211.     trap        #1
  212.     addq.l        #6,sp
  213.     push.l        d0
  214. *-------------------------------------------------------*
  215. *    Allocate space for 3 new screenbuffers        *
  216. *-------------------------------------------------------*
  217.     bsr        allocate_screens
  218. *-------------------------------------------------------*
  219. *    Setup new truecolour video mode            *
  220. *-------------------------------------------------------*
  221.     bsr        select_video
  222. *-------------------------------------------------------*
  223. *    Kickstart DSP Doom Core                *
  224. *-------------------------------------------------------*
  225.     bsr        kickstart_doomcore
  226. *-------------------------------------------------------*
  227. *    Select initial window size & prepare lists    *
  228. *-------------------------------------------------------*
  229.     move.w        #window_max,window_size
  230.     bsr        select_window
  231. *-------------------------------------------------------*
  232. *    Set up global display structure            *
  233. *-------------------------------------------------------*
  234.     bsr        init_displaystruct
  235. *-------------------------------------------------------*
  236. *    Enable VBI & timing interrupts            *
  237. *-------------------------------------------------------*
  238.     bsr        init_timing
  239. *-------------------------------------------------------*
  240. *    Replace keyboard handler            *
  241. *-------------------------------------------------------*
  242.     bsr        initialise_ikbd
  243. *-------------------------------------------------------*
  244.     
  245. *-------------------------------------------------------*
  246. *    Main program loop                *
  247. *-------------------------------------------------------*
  248. game_loop:
  249. *-------------------------------------------------------*
  250. *    Read keyboard (debug mode only)            *
  251. *-------------------------------------------------------*
  252.     ifd        debuggable
  253.     bsr        read_key
  254.     endc
  255. *-------------------------------------------------------*
  256. *    Move player                     *
  257. *-------------------------------------------------------*
  258.     bsr        player_control
  259. *-------------------------------------------------------*
  260. *    Get player direction                *    
  261. *-------------------------------------------------------*
  262.     bsr        triangulate
  263. *-------------------------------------------------------*
  264. *    Display 3D environment                *
  265. *-------------------------------------------------------*
  266.     bsr        display_engine
  267. *-------------------------------------------------------*
  268. *    Display level map                *    
  269. *-------------------------------------------------------*
  270.     bsr        display_map
  271. *-------------------------------------------------------*
  272. *    Display framerate in corner of screen        *
  273. *-------------------------------------------------------*
  274.     ifd        enable_timing
  275.     bsr        timing
  276.     endc
  277. *-------------------------------------------------------*
  278. *    Double-buffered display                *
  279. *-------------------------------------------------------*
  280.     vsync
  281.     bsr        adjust_scanlines
  282.     triplebuffer
  283. *-------------------------------------------------------*
  284. *    Check for exit key                *
  285. *-------------------------------------------------------*
  286.     tst.b        program_quit
  287.     beq.s        game_loop
  288.  
  289. *-------------------------------------------------------*
  290. *    Program end - restore parameters & exit        *
  291. *-------------------------------------------------------*
  292. game_exit:
  293. *-------------------------------------------------------*
  294. *    Restore system                    *
  295. *-------------------------------------------------------*
  296.     bsr        remove_ikbd
  297.     bsr        reset_timing
  298.     bsr        empty_buffer
  299.     bsr        restore_video
  300. *-------------------------------------------------------*
  301. *    Return to user mode                *
  302. *-------------------------------------------------------*
  303.     move.w        #32,-(sp)
  304.     trap        #1
  305.     lea        10(sp),sp
  306. *-------------------------------------------------------*
  307. *    Exit program                    *
  308. *-------------------------------------------------------*
  309. safe_quit:
  310. *-------------------------------------------------------*
  311. *    Unhide the mouse                *
  312. *-------------------------------------------------------*
  313.     dc.w        $A009
  314. *-------------------------------------------------------*
  315. *    Terminate program                *
  316. *-------------------------------------------------------*
  317.     clr.w        -(sp)
  318.     trap        #1
  319.  
  320. *-------------------------------------------------------*
  321. *    Player control module with turning & movement    *
  322. *-------------------------------------------------------*
  323.     txtlong
  324. *-------------------------------------------------------*
  325. player_control:
  326. *-------------------------------------------------------*
  327.     lea        key_buffer,a6
  328.  
  329.     tst.b        rgb_key(a6)
  330.     beq.s        .nrgb
  331.     move.w        #rgb_aspect,aspect_ratio
  332.     bsr        select_window
  333. .nrgb:    tst.b        vga_key(a6)
  334.     beq.s        .nvga
  335.     move.w        #vga_aspect,aspect_ratio
  336.     bsr        select_window
  337. .nvga:
  338.     tst.b        full_key(a6)
  339.     beq.s        .nf
  340.     move.w        #expanded_height,viewport_height
  341.     not.b        fullscreen
  342.     bne.s        .nf1
  343.     move.w        #default_height,viewport_height
  344. .nf1:    bsr        select_window
  345. .nf:
  346.     
  347.     tst.b        text_key(a6)
  348.     beq.s        .ntx
  349.     bsr        texture_loop
  350. .ntx:
  351.     tst.b        hres_key(a6)
  352.     beq.s        .ndh
  353.     not.b        halfrows
  354.     bsr        select_window
  355. .ndh:
  356.     tst.b        vres_key(a6)
  357.     beq.s        .ndv
  358.     not.b        halflines
  359.     bsr        select_window
  360. .ndv:
  361.  
  362.     tst.b        rise_key(a6)
  363.     beq.s        .nr
  364.     addq.w        #4,pho
  365. .nr:    tst.b        drop_key(a6)
  366.     beq.s        .nd
  367.     subq.w        #4,pho
  368. .nd:
  369.  
  370.     tst.b        left_key(a6)
  371.     beq.s        not_left
  372.     tst.b        alt_key(a6)
  373.     bne.s        move_left
  374.     add.w        #turn_speed,pangle
  375.     bra.s        not_left
  376. move_left:
  377.     move.w        #$4000,d1
  378.     move.w        #player_speed,d0
  379.     bsr        move_player
  380. not_left:
  381.     tst.b        right_key(a6)
  382.     beq.s        not_right
  383.     tst.b        alt_key(a6)
  384.     bne.s        move_right
  385.     sub.w        #turn_speed,pangle
  386.     bra.s        not_right
  387. move_right:
  388.     move.w        #$4000,d1
  389.     move.w        #-player_speed,d0
  390.     bsr        move_player
  391. not_right:
  392.     tst.b        forward_key(a6)
  393.     beq.s        not_forward
  394.     move.w        #player_speed,d0
  395.     moveq        #0,d1
  396.     bsr        move_player
  397. not_forward:
  398.     tst.b        back_key(a6)
  399.     beq.s        not_back
  400.     move.w        #-player_speed,d0
  401.     moveq        #0,d1
  402.     bsr        move_player
  403. not_back:
  404.     move.w        mouse_dy,d0
  405.     beq        no_mouse_y
  406.     neg.w        d0
  407.     moveq        #0,d1
  408.     bsr        move_player
  409.     clr.w        mouse_dy
  410. no_mouse_y:
  411.     move.w        mouse_dx,d0
  412.     beq        no_mouse_x
  413.     cmp.b        #1,buttons
  414.     bne.s        rotate
  415.     neg.w        d0
  416.     move.w        #$4000,d1
  417.     bsr        move_player
  418.     bra.s        no_mouse_x
  419. rotate:
  420.     move.w        mouse_dx,d0
  421.     asl.w        #5,d0
  422.     sub.w        d0,pangle
  423. no_mouse_x:
  424.     clr.w        mouse_dx
  425.     tst.b        plus_key(a6)
  426.     beq.s        .nwp
  427.     add.w        #32,window_size
  428.     bsr        select_window
  429. .nwp:    tst.b        minus_key(a6)
  430.     beq.s        .nwm
  431.     sub.w        #32,window_size
  432.     bsr        select_window
  433. .nwm:    tst.b        quit_key(a6)
  434.     beq.s        .nox
  435.     st        program_quit
  436. .nox:    tst.b        map_key(a6)
  437.     beq.s        .nmk
  438.     not.b        map_enabled
  439. .wlp:    tst.b        map_key(a6)
  440.     bne.s        .wlp
  441. .nmk:    rts
  442.  
  443. *-------------------------------------------------------*
  444. * Generic movement routine -    d0 = distance        *
  445. *                d1 = angle offset    *
  446. *-------------------------------------------------------*
  447.     txtlong
  448. *-------------------------------------------------------*
  449. move_player:
  450. *-------------------------------------------------------*
  451.     move.w        d0,d2            ; save distance for later 
  452.     add.w        pangle,d1
  453.     lsr.w        #(16-12),d1
  454.     muls.w        (sine.l,d1.w*2),d0
  455.     lsl.l        #2,d0
  456.     add.l        d0,py
  457.     add.w        #sinres/4,d1
  458.     and.w        #sinres-1,d1
  459.     muls.w        (sine.l,d1.w*2),d2
  460.     lsl.l        #2,d2
  461.     add.l        d2,px
  462.     rts
  463.  
  464. *-------------------------------------------------------*
  465. *    Convert rotational angle into a vector        *
  466. *-------------------------------------------------------*
  467.     txtlong
  468. *-------------------------------------------------------*
  469. triangulate:
  470. *-------------------------------------------------------*
  471.     move.w        pangle,d0
  472.     andi.l        #$ffff,d0    
  473.     neg.l        d0
  474.     lsr.w        #(16-12),d0
  475.     lea        sine,a0
  476.     move.w        (a0,d0.w*2),d1
  477.     add.w        #sinres/4,d0
  478.     and.w        #sinres-1,d0
  479.     ext.l        d1
  480.     lsl.l        #2,d1
  481.     move.l        d1,sinpangle
  482.     move.w        (a0,d0.w*2),d1
  483.     ext.l        d1
  484.     lsl.l        #2,d1
  485.     move.l        d1,cospangle
  486.     rts
  487.     
  488. *-------------------------------------------------------*
  489. *    Program modules                    *
  490. *-------------------------------------------------------*
  491.  
  492.     include        io.s
  493.     include        levelmap.s
  494.     include        keyboard.s
  495.     include        screen.s
  496.     include        textures.s
  497.     include        engine.s
  498.  
  499. *-------------------------------------------------------*
  500.             bsslong
  501. *-------------------------------------------------------*
  502.  
  503. cli:            ds.l    1        ; command line pointer
  504.  
  505. px:            ds.l    1        ; player-x
  506. py:            ds.l    1        ; player-y
  507. ph:            ds.l    1        ; player height above floor
  508. pho:            ds.w    1        ; player height offset (for flying)
  509. pangle:            ds.l    1        ; player direction
  510. cospangle:        ds.l    1        ; Cos[d]
  511. sinpangle:        ds.l    1        ; Sin[d]
  512.  
  513.             ds.b    16384
  514. ourstack:        ds.l    4        ; hefty stack for BSP algorithm
  515.  
  516.  
  517. program_quit:        ds.b    1        ; exit flag
  518.  
  519. string_space:        ds.b    256        ; general string space
  520.  
  521. *-------------------------------------------------------*
  522.             bsslong
  523. *-------------------------------------------------------*
  524. bss_end:
  525. *-------------------------------------------------------*
  526.