home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 4: The Falcon Archive / nf_archive_four_v1.0.iso / ARCHIVE / DEMOS / LAZER / LAZEROS.ZIP / LAZEROS / MAIN / MAIN_02.S < prev    next >
Text File  |  1995-10-08  |  26KB  |  1,401 lines

  1. ;--------------------------------------------------------
  2. ;           Multitasking Demo-operating-system
  3. ;           (c) 1995: Lazer / The Independent
  4. ;             
  5. ;    Main coding:         Photon
  6. ;    Additional coding:     Energizer
  7. ;
  8. ; This source may only be used in non-commercial demos!
  9. ; In case of commercial use contact:
  10. ;
  11. ; Photon:
  12. ; Gerhard Seiler
  13. ; Feldgasse 29
  14. ; A-2326 Maria Lanzedorf
  15. ; Austria
  16. ;
  17. ; or send email to Energizer (Harald Riegler): 
  18. ;                             e9327376@stud1.tuwien.ac.at
  19. ;--------------------------------------------------------
  20.  
  21. ;--------------------------------------------------------
  22. ;     This source was programmed using Devpac 3.
  23. ;--------------------------------------------------------
  24.  
  25.  
  26.  
  27.  
  28.     output    h:\dba\INTRO.PRG    ;Output Filename
  29.  
  30.  
  31. FASTEXIT                ;Enable -Space- check
  32.  
  33. internal_speaker=0
  34.  
  35.     jmp    main
  36.  
  37.     include    demo.s            
  38. ;-----------------------------------------------------------
  39. TASK_PTR    = 0        ;  1L 
  40. TASK_PRIOR    = 4        ;  1W
  41. TASK_FLAGS    = 6        ;  1W
  42. TASK_PC        = 8        ;  1L
  43. TASK_SR        = 12        ;  1W
  44. TASK_REGS    = 14        ; 16L
  45.  
  46.  
  47. VBL_ANZ=8
  48. TASK_ANZ=8
  49.  
  50. STACK_SIZE=4000
  51.  
  52. ;-----------------------------------------------------------
  53. ADD_TASK MACRO
  54.     lea    \1,a0
  55.     move.w    \2,d0
  56.     bsr    add_task
  57.     ENDM
  58. ;-----------------------------------------------------------
  59. DELETE_TASK MACRO
  60.     lea    \1,a0
  61.     bsr    delete_task
  62.     ENDM
  63. ;-----------------------------------------------------------
  64. ADD_VBL MACRO
  65.     lea    \1,a0
  66.     move.w    \2,d0
  67.     bsr    add_vbl
  68.     ENDM
  69. ;-----------------------------------------------------------
  70. DELETE_VBL MACRO
  71.     lea    \1,a0
  72.     bsr    delete_vbl
  73.     ENDM
  74. ;-----------------------------------------------------------
  75. save_sr MACRO
  76.     move.w    sr,-(sp)
  77.     ENDM
  78. ;-----------------------------------------------------------
  79. restore_sr MACRO
  80.     move.w    (sp)+,sr
  81.     ENDM
  82. ;-----------------------------------------------------------
  83.  
  84. ;-----------------------------------------------------------
  85.     include startup.s
  86.     include    packfire\fireunp3.s
  87.     include    pack_ice.240\ice_unp2.s
  88. ;-----------------------------------------------------------
  89.  
  90. ;-----------------------------------------------------------
  91. depack_prg MACRO
  92.     lea    \1,a0
  93.     lea    \1_end,a2
  94.     lea    buffer+\2+256-$1c,a1
  95.     bsr    copy_prg
  96.     lea    buffer+\2+256-$1c,a0
  97.     jsr    fire_decrunch_3
  98.     *jsr    ice_decrunch_2        ;depack data
  99.     ENDM
  100.  
  101. relocate_prg MACRO
  102.     lea    buffer+\1,a0
  103.     bsr    setup_basepage
  104.     ENDM
  105.  
  106. init_prg MACRO
  107.     move.l    #buffer+256+\1,a6
  108.  
  109.     lea    demo_param,a0
  110.     jsr    6(a6)            ; start program
  111.     ENDM
  112.  
  113. do_prg MACRO
  114.     move.l    #buffer+256+\1,a6
  115.     lea    demo_param,a0
  116.     jsr    8+6(a6)            ; start program
  117.     ENDM
  118. ;-----------------------------------------------------------
  119.  
  120.  
  121. ;-----------------------------------------------------------
  122. check_keys
  123.     cmp.b    #$4a,key
  124.     bne.s    .not_vol_down
  125. *    cmp.b    #$4a+128,key        ; NUM -
  126. *    bne.s    .not_vol_down
  127.  
  128.     sub.w    #$200,main_volume
  129.     bpl.s    .1
  130.     move.w    #0,main_volume
  131. .1
  132.  
  133.     bsr    set_volume
  134.  
  135.     clr.b    key
  136.     bra.s    .end
  137. .not_vol_down
  138.  
  139.     cmp.b    #$4e,key
  140.     bne.s    .not_vol_up
  141. *    cmp.b    #$4e+128,key        ; NUM +
  142. *    bne.s    .not_vol_up
  143.  
  144.     add.w    #$200,main_volume
  145.     cmp.w    #$7fff,main_volume
  146.     blo.s    .2
  147.     move.w    #$7fff,main_volume
  148. .2
  149.  
  150.     bsr    set_volume
  151.  
  152.     clr.b    key
  153.     bra.s    .end
  154. .not_vol_up
  155.  
  156.     cmp.b    #$72,old_key
  157.     bne.s    .not_speaker
  158.     cmp.b    #$72+128,key        ; NUM ENTER
  159.     bne.s    .not_speaker
  160.         move.b  #14,$ffff8800.w
  161.         move.b  $ffff8800.w,d0
  162.         bchg    #6,d0
  163.         move.b  d0,$ffff8802.w
  164.  
  165.     clr.b    old_key
  166.     bra.s    .end
  167. .not_speaker
  168.  
  169.  
  170.     nop
  171. .end
  172.     rts
  173. ;-----------------------------------------------------------
  174. main
  175.     shrink_memory
  176.  
  177.     bsr    init
  178.  
  179.     save_stack
  180.     bsr    phoenix_init
  181.  
  182.     save_interrupts
  183.  
  184.     move.l    scr1,d0    
  185.     setscreen
  186.  
  187.     bsr    rout_clear
  188.  
  189.     lea    demo_settings,a0
  190.     move.w    4(a0),d0
  191.     muls    #$e30,d0
  192.     move.w    d0,main_volume        ;set_main_volume
  193.  
  194.  
  195.     set_interrupts
  196.     move.w    #$2700,sr
  197.     move.l    #vbl,$70.w
  198.     move.w    #$2300,sr
  199.  
  200.  
  201. *    bsr    load_module
  202.     bsr    init_sound
  203.  
  204.     bsr    init_vbl_queue
  205.     bsr    init_task_queue
  206.     bsr    init_multitask_interrupt
  207.     st    multitasking
  208.  
  209.     move.l    scr1,d0
  210.     setscreen
  211.     vsync
  212.  
  213.  
  214.     lea    demo_param,a0
  215.     move.l    scr1,SHOW_SCREEN(a0)
  216.     move.l    scr2,WORK_SCREEN(a0)
  217.     move.l    scr3,EXTRA_SCREEN(a0)
  218.  
  219.     move.w    #$2700,sr
  220.     ADD_TASK main_task,#20        ;main task is first active 
  221.                     ;task
  222.     clr.w    -(sp)
  223.     move.l    #main_task,-(sp)
  224.     move.w    #$2300,-(sp)
  225.     rte                ;jmp main_task
  226.  
  227. ;-----------------------------------------------------------
  228. demo_settings
  229.     dc.w    1    ;Speaker
  230.     dc.w    0    ;Lock
  231.     dc.w    3    ;Volume    (9=max)
  232. ;-----------------------------------------------------------
  233.  
  234.  
  235.  
  236. ;-----------------------------------------------------------
  237. main_task
  238.     move.w    #2300,vsync_count
  239.  
  240. .wait_until_next
  241.     bsr    check_keys
  242.  
  243.     move.l    demo_listptr,a6
  244.     move.l    (a6)+,d0
  245.     cmp.w    vsync_count,d0
  246. *    bgt.s    .wait_until_next
  247.     ble.s    .next
  248.     RETURN .wait_until_next
  249.  
  250. .next
  251.     move.l    (a6)+,d0
  252.     move.l    (.routs,d0.w*4),a0
  253.     jsr    (a0)
  254.  
  255.     move.l    a6,demo_listptr
  256.     bra.s    .wait_until_next
  257.     rts
  258.  
  259. .routs        dc.l    rout_endlist
  260.         dc.l    rout_start
  261.         dc.l    rout_addvbl
  262.         dc.l    rout_delvbl
  263.         dc.l    rout_startsound
  264.         dc.l    rout_addtask
  265.         dc.l    rout_deltask
  266.         dc.l    rout_restart
  267.         dc.l    rout_load
  268.         dc.l    rout_exit
  269.         dc.l    rout_clear
  270.         dc.l    rout_stopsound
  271.         dc.l    rout_loadmodule
  272.         dc.l    rout_demo_locked
  273.         dc.l    rout_repair_all
  274.  
  275.  
  276. ;-----------------------------------------------------------
  277. rout_endlist
  278.     bra.s    rout_endlist
  279. ;-----------------------------------------------------------
  280. pos    dc.l    0
  281. prio    dc.l    0
  282. loadflag    dc.w    0
  283. rout_start
  284. *    move.l    (a6)+,a0    ; program
  285.     move.l    (a6)+,d1    ; position
  286.     move.l    (a6)+,d0    ; priority
  287.  
  288.     move.l    d1,pos
  289.     move.l    d0,prio
  290.  
  291. .1
  292.     tst.w    loadflag
  293.     beq.s    .ok
  294.     add.l    #$12340056,$ffff9800.w
  295.     bra.s    .1
  296. .ok
  297.  
  298.     move.w    #1,loadflag
  299.     lea    rout_start2,a0
  300.     ; d0 : priority
  301.     pusha
  302.     bsr    add_task
  303.     popa
  304.     rts
  305.  
  306.  
  307. rout_start2
  308.     move.l    pos,d1
  309.     move.l    prio,d0
  310.  
  311. ; ------------- Copy program to new position
  312.     IFNE 0
  313.     pusha
  314.     move.l    -4(a0),d2
  315.     move.l    a0,a2            ; program end
  316.     add.l    d2,a2
  317.     lea    buffer+256-$1c,a1    ; program position
  318.     add.l    d1,a1
  319.     bsr    copy_prg
  320.     popa
  321.     ENDC
  322.  
  323. ; ------------- Depack Program
  324.     pusha
  325.     lea    buffer+256-$1c,a0    ; program position
  326.     add.l    d1,a0
  327.     jsr    fire_decrunch_3
  328.     popa
  329.  
  330. ; ------------- Relocate Program
  331.     pusha
  332.     lea    buffer,a0    ; program position
  333.     add.l    d1,a0
  334.     bsr    setup_basepage
  335.     popa
  336.  
  337. ; ------------- Init Program
  338.     pusha
  339.     lea    buffer+256,a6
  340.     add.l    d1,a6
  341.     lea    demo_param,a0
  342.     jsr    6(a6)        ; start program
  343.     popa
  344.  
  345.  
  346.     clr.w    loadflag
  347.     lea    rout_start2,a0
  348.     bsr    delete_task
  349. .1    bra    .1
  350.     rts
  351. ;-----------------------------------------------------------
  352. rout_exit
  353.     move.l    (a6)+,d1    ; position
  354.  
  355. ; ------------- Exit Program
  356.     pusha
  357.     lea    buffer+256,a6
  358.     add.l    d1,a6
  359.     lea    demo_param,a0
  360.     jsr    6+4(a6)        ; start program
  361.     popa
  362.     rts
  363. ;-----------------------------------------------------------
  364. rout_clear
  365.  
  366. ; ------------- Exit Program
  367.     pusha
  368.     lea    screens,a0
  369.     lea    buffer_end,a6
  370.  
  371.     moveq    #0,d7
  372. .1    
  373.     move.l    d7,(a0)+
  374.     move.l    d7,(a0)+
  375.     move.l    d7,(a0)+
  376.     move.l    d7,(a0)+
  377.     cmp.l    a6,a0
  378.     blt.s    .1
  379.  
  380.     popa
  381.     rts
  382. ;-----------------------------------------------------------
  383. rout_addvbl
  384.     move.l    (a6)+,d1    ; position
  385.     move.l    (a6)+,d0    ; priority
  386.  
  387.     pusha
  388.     lea    buffer+256+14,a0
  389.     add.l    d1,a0
  390.     bsr    add_vbl
  391.     popa
  392.     rts
  393. ;-----------------------------------------------------------
  394. rout_delvbl
  395.     move.l    (a6)+,d1    ; position
  396.  
  397.     pusha
  398.     lea    buffer+256+14,a0
  399.     add.l    d1,a0
  400.     bsr    delete_vbl
  401.     popa
  402.     rts
  403. ;-----------------------------------------------------------
  404. rout_startsound
  405.     pusha
  406.     bsr    start_sound
  407.     popa
  408.     rts
  409. ;-----------------------------------------------------------
  410. rout_addtask
  411.     move.l    (a6)+,d1    ; position
  412.     move.l    (a6)+,d0    ; priority
  413.  
  414.     pusha
  415.     lea    buffer+256+14,a0
  416.     add.l    d1,a0
  417.     bsr    add_task
  418.     popa
  419.     rts
  420. ;-----------------------------------------------------------
  421. rout_deltask
  422.     move.l    (a6)+,d1    ; position
  423.  
  424.     pusha
  425.     lea    buffer+256+14,a0
  426.     add.l    d1,a0
  427.     bsr    delete_task
  428.     popa
  429.     rts
  430. ;-----------------------------------------------------------
  431. rout_restart
  432.     move.l    (a6)+,d0
  433.     move.l    (a6)+,d1
  434.  
  435.     move.l    d0,a6
  436.  
  437.     move.w    d1,vsync_count
  438.     move.l    d1,counter_abs
  439.     rts
  440. ;-----------------------------------------------------------
  441. rout_load
  442.     move.l    (a6)+,a0
  443.     move.l    (a6)+,a1
  444.  
  445. **    lea    buffer+256-$1c,a1    ; program position
  446.     add.l    #buffer+256-$1c,a1
  447.  
  448.     pusha
  449.     bsr    read_data
  450.     popa
  451.     move.l    len,-4(a1)
  452.     rts
  453. ;-----------------------------------------------------------
  454. rout_stopsound
  455.     pusha
  456.     bsr    stop_sound
  457.     popa
  458.     rts
  459. ;-----------------------------------------------------------
  460. rout_loadmodule
  461.     move.l    (a6)+,a0
  462.  
  463.     pusha
  464.     lea    module,a0
  465.     lea    module_end,a1
  466. .1    clr.l    (a0)+
  467.     cmp.l    a1,a0
  468.     blt.s    .1
  469.     popa
  470.     
  471.  
  472.     lea    module,a1
  473.     pusha
  474.     bsr    read_data
  475.     popa
  476.  
  477.     pusha
  478.     lea    module,a0
  479.     jsr    fire_decrunch_3
  480.     popa
  481.  
  482.     rts
  483. ;-----------------------------------------------------------
  484. rout_demo_locked
  485.     tst.w    demo_settings+2
  486.     bne.s    .ok
  487. .blabla
  488.     jmp    .blabla
  489. .ok
  490.     rts
  491. ;-----------------------------------------------------------
  492. rout_repair_all
  493.     pusha
  494.  
  495.     move.l    #screens+256,d0
  496.     clr.b    d0
  497.     move.l    d0,scr1
  498.     add.l    #384*240*2,d0
  499.     move.l    d0,scr2
  500.     add.l    #384*240*2,d0
  501.     move.l    d0,scr3
  502.  
  503.     move.w    #FALSE,palette_update
  504.     move.w    #FALSE,scrmode_update
  505.     move.w    #FALSE,screen_swap
  506.  
  507.     clr.l    counter_rel
  508.  
  509.     move.l    scr1,d0
  510.     setscreen
  511.  
  512.     lea    rgb_320x200xtrue,a0
  513.     set_resolution
  514.  
  515.     lea    $ffff9800,a0
  516.     move.l    palette,a1
  517.     moveq    #0,d1
  518.     move.w    #255,d0
  519. .1    move.l    d1,(a0)+
  520.     move.l    d1,(a1)+
  521.     dbf    d0,.1
  522.  
  523.     move.w    #2,screen_count
  524.  
  525.     popa
  526.  
  527.     rts
  528. ;-----------------------------------------------------------
  529.  
  530. dummy
  531.     add.l    #4,$ffff9800.w
  532.     bra    dummy
  533. ;-----------------------------------------------------------
  534. main_exit
  535.     move.l    #mystack,a7
  536.  
  537.     bsr    exit_sound
  538.  
  539.     restore_interrupts
  540.     bsr    phoenix_exit
  541.     restore_stack
  542.     bsr    exit
  543.     terminate
  544. ;-----------------------------------------------------------
  545.  
  546.  
  547.  
  548. ;-----------------------------------------------------------
  549. load_module
  550.     lea    modname,a0
  551.     lea    module,a1
  552.     bsr    read_data
  553.  
  554.     lea    module,a0
  555.     jsr    fire_decrunch_3
  556.  
  557.     rts
  558. ;-----------------------------------------------------------
  559. read_data2                ;read single files
  560.     move.l    a1,-(sp)
  561.  
  562.     move.w    #0,-(sp)        ; open file
  563.     move.l    a0,-(sp)
  564.     move.w    #$3d,-(sp)
  565.     trap    #1
  566.     lea    8(sp),sp
  567.     move.w    d0,filehandle
  568.  
  569. ; ------------------------- seek to the end
  570.     move.w    #2,-(sp)
  571.     move.w    filehandle,-(sp)
  572.     move.l    #0,-(sp)
  573.     move.w    #$42,-(sp)
  574.     trap    #1
  575.     add.l    #10,sp
  576.     move.l    d0,len
  577.  
  578. ; ------------------------- seek to the start
  579.     move.w    #0,-(sp)
  580.     move.w    filehandle,-(sp)
  581.     move.l    #0,-(sp)
  582.     move.w    #$42,-(sp)
  583.     trap    #1
  584.     add.l    #10,sp
  585.  
  586.  
  587.     move.l    (sp)+,a1
  588.  
  589.  
  590.     move.l    a1,-(sp)
  591.     move.l    len,-(sp)        ; read file
  592.     move.w    filehandle,-(sp)
  593.     move.w    #$3f,-(sp)
  594.     trap    #1
  595.     lea    12(sp),sp
  596.  
  597.     move.w    filehandle,-(sp)    ; close file
  598.     move.w    #$3e,-(sp)
  599.     trap    #1
  600.     lea    4(sp),sp
  601.     rts
  602.  
  603. filehandle    dc.w    0
  604. len        dc.l    0
  605. ;-----------------------------------------------------------
  606. read_data            ;read data from a file generated
  607.                 ;by onefile.gfa
  608.                 
  609.     move.l    a1,-(sp)
  610.  
  611.     move.b    (a0),d0        ;pos in file
  612.     ext.w    d0
  613.     addq    #1,a0        ;Fname
  614.  
  615.     move.l    d0,-(sp)
  616.  
  617.     move.w    #0,-(sp)        ; open file
  618.     move.l    a0,-(sp)
  619.     move.w    #$3d,-(sp)
  620.     trap    #1
  621.     lea    8(sp),sp
  622.     move.w    d0,filehandle
  623.  
  624. ; ------------------------- read file inventory
  625.  
  626.     pea    file_header
  627.     move.l    #256,-(sp)        ; read file
  628.     move.w    filehandle,-(sp)
  629.     move.w    #$3f,-(sp)
  630.     trap    #1
  631.     lea    12(sp),sp
  632.  
  633. ; ------------------------- search for file
  634.  
  635.     move.l    (sp)+,d0
  636.  
  637.     lea    file_header,a0
  638.     move.l    (a0,d0.w*8),d1        ;pos in file
  639.     move.l    4(a0,d0.w*8),d2        ;length
  640.  
  641.     move.l    d2,-(sp)
  642.     move.l    d1,-(sp)
  643.  
  644. ; ------------------------- seek to the start
  645.  
  646.     move.w    #0,-(sp)
  647.     move.w    filehandle,-(sp)
  648.     move.l    #0,-(sp)
  649.     move.w    #$42,-(sp)
  650.     trap    #1
  651.     add.l    #10,sp
  652.  
  653. ; ------------------------- search to file
  654.     move.l    (sp)+,d1
  655.  
  656.     move.w    #0,-(sp)
  657.     move.w    filehandle,-(sp)
  658.     move.l    d1,-(sp)
  659.     move.w    #$42,-(sp)
  660.     trap    #1
  661.     add.l    #10,sp
  662.  
  663. ; ------------------------- read file
  664.  
  665.     move.l    (sp)+,d2
  666.     move.l    (sp)+,a1
  667.  
  668.     move.l    a1,-(sp)
  669.     move.l    d2,-(sp)        ; read file
  670.     move.w    filehandle,-(sp)
  671.     move.w    #$3f,-(sp)
  672.     trap    #1
  673.     lea    12(sp),sp
  674.  
  675.     move.w    filehandle,-(sp)    ; close file
  676.     move.w    #$3e,-(sp)
  677.     trap    #1
  678.     lea    4(sp),sp
  679.     rts
  680.  
  681. ;-----------------------------------------------------------
  682. copy_prg
  683. .loop
  684.     move.l    (a0)+,(a1)+
  685.     cmp.l    a2,a0
  686.     ble    .loop
  687.     rts
  688. ;-----------------------------------------------------------
  689. ; -> A0: Program start-adress
  690. setup_basepage
  691.     move.l    a0,d6
  692.  
  693.     move.l    d6,d7
  694.     add.l    #256,d7        ; program start
  695.  
  696.     move.l    d7,d0
  697.     sub.l    #$1c,d0
  698.     move.l    d0,a1
  699.     move.l    $02(a1),d0    ;textlen
  700.     move.l    $06(a1),d1    ;datalen
  701.     move.l    $0a(a1),d2    ;bsslen
  702.     move.l    $0e(a1),d3    ;symlen
  703.  
  704.     move.l    d6,a1        ; clr basapage
  705.     move.w    #255,d4
  706. clr    clr.b    (a1)+
  707.     dbf    d4,clr
  708.  
  709.     move.l    d6,a0
  710.     move.l    d6,(a0)        ;low tpa
  711.     move.l    $436,4(a0)    ;high tpa+1
  712.     sub.l    #2048,4(a0)
  713.     move.l    d7,8(a0)    ;text start
  714.     move.l    d0,$c(a0)    ;textlen
  715.     move.l    d7,$10(a0)
  716.     add.l    d0,$10(a0)    ;data start
  717.     move.l    d1,$14(a0)    ;data len
  718.     move.l    d7,$18(a0)
  719.     add.l    d0,$18(a0)
  720.     add.l    d1,$18(a0)    ;bss start
  721.     move.l    d2,$1c(a0)    ;bss len
  722.  
  723.     move.l    d7,a1
  724.     add.l    d0,a1        ;textseg
  725.     add.l    d1,a1        ;dataseg
  726.     add.l    d3,a1        ;sym seg
  727.  
  728.     move.l    d7,a0
  729.     move.l    a0,d1
  730.     moveq.l    #0,d0
  731.  
  732.     move.l    (a1)+,d0    ; relocate first address
  733.     tst.l    d0
  734.     beq.s    end
  735.     add.l    d0,a0
  736.     add.l    d1,(a0)
  737.  
  738. loop    move.b    (a1)+,d0    ; relocate loop
  739.     tst.b    d0
  740.     beq.s    end
  741.     cmp.b    #1,d0
  742.     bne.s    rel
  743.     add.l    #$fe,a0
  744.     bra.s    weiter
  745. rel    add.l    d0,a0
  746.     add.l    d1,(a0)
  747. weiter    bra.s    loop
  748.  
  749. end
  750.     rts
  751. ;-----------------------------------------------------------
  752. init_sound
  753.     lea    vol_tab,a0
  754.     move.w    main_volume,d0
  755.     REPT 8
  756.     move.w    d0,(a0)+
  757.     ENDR
  758.  
  759.     jsr    player+28        ;install
  760.  
  761.     lea    demo_settings,a0    ;internal speaker y/n
  762.     tst.w    (a0)
  763.     bne.s    .int
  764.         move.b  #14,$ffff8800.w
  765.         move.b  $ffff8800.w,d0
  766.         bset    #6,d0
  767.         move.b  d0,$ffff8802.w
  768.     bra.s    .ext
  769. .int    move.b  #14,$ffff8800.w
  770.         move.b  $ffff8800.w,d0
  771.         bclr    #6,d0
  772.         move.b  d0,$ffff8802.w
  773. .ext
  774.  
  775.     rts
  776. ;-----------------------------------------------------------
  777. exit_sound
  778.  
  779.     move.w    #0,do_play
  780.                     ;disable vbl-sound-jmp 
  781.  
  782.     jsr    player+40        ;off
  783.  
  784.     jsr    player+32        ;deinstall
  785.     
  786.  
  787.     rts
  788. ;-----------------------------------------------------------
  789. start_sound
  790.     lea    vol_tab,a0
  791.     move.w    main_volume,d0
  792.     REPT 8
  793.     move.w    d0,(a0)+        ;set volume
  794.     ENDR
  795.  
  796.     lea    module,a0
  797.     lea    vol_tab,a1
  798.     jsr    player+36        ;on
  799.  
  800.     move.w    #-1,do_play
  801.                     ;vbl-jmp enable
  802.  
  803.     rts
  804. ;-----------------------------------------------------------
  805. stop_sound
  806.  
  807.  
  808.     jsr    player+40        ;off
  809.  
  810.     rts
  811. ;-----------------------------------------------------------
  812. ;-----------------------------------------------------------
  813. set_volume
  814.     move.w    main_volume,d0
  815.     move.l    player+68,a0
  816. i set 0
  817.     REPT 8
  818.     move.w    d0,24+28*i(a0)
  819. i set i+1
  820.     ENDR
  821.     rts
  822. ;-----------------------------------------------------------
  823.  
  824.  
  825. ;-----------------------------------------------------------
  826. ; ********************** TIME-SHARING **********************
  827. ;-----------------------------------------------------------
  828. ; -> a0 : pointer to rout
  829. ;    d0 : priority
  830. add_task
  831.     save_sr
  832.     move.w    #$2700,sr
  833.     lea    task_queue,a6
  834.  
  835.     moveq    #0,d6
  836.     move.w    #TASK_ANZ-1,d7
  837. .1    move.l    TASK_PTR(a6),d1
  838.     beq.s    .found
  839.     lea    128(a6),a6
  840.     addq    #1,d6
  841.     dbf    d7,.1
  842.     restore_sr
  843.     rts
  844.  
  845. .found
  846.     move.l    a0,TASK_PC(a6)
  847.     move.w    #$2300,TASK_SR(a6)
  848.     move.l    a0,TASK_PTR(a6)
  849.     move.b    d0,TASK_PRIOR(a6)
  850.  
  851.     lea    test_stack,a1
  852.     muls    #STACK_SIZE,d6
  853.     add.l    d6,a1
  854.     add.l    #STACK_SIZE,a1
  855.  
  856.     move.l    TASK_PTR(a6),-(a1)
  857.     move.l    #task_finished,-(a1)
  858.     clr.w    -(a1)            ; 4 word stack frame
  859.     move.l    TASK_PC(a6),-(a1)
  860.     move.w    TASK_SR(a6),-(a1)
  861.     move.l    a1,TASK_REGS+15*4(a6)
  862.  
  863.     restore_sr
  864.     rts
  865. ;-----------------------------------------------------------
  866. task_finished
  867.     move.l    (sp)+,a0
  868.     bsr    delete_task
  869.     rts
  870. ;-----------------------------------------------------------
  871. ; -> a0 : pointer to rout
  872. delete_task
  873.     save_sr
  874.     move.w    #$2700,sr
  875.     lea    task_queue,a6
  876.  
  877.     move.w    #TASK_ANZ-1,d7
  878. .1    move.l    TASK_PTR(a6),a1
  879.     cmp.l    a1,a0
  880.     beq.s    .found
  881.     lea    128(a6),a6
  882.     dbf    d7,.1
  883.     restore_sr
  884.     rts
  885.  
  886. .found
  887.     clr.l    TASK_PTR(a6)
  888.     clr.w    TASK_PRIOR(a6)
  889.     restore_sr
  890.     rts
  891. ;-----------------------------------------------------------
  892. init_task_queue
  893.     lea    task_queue,a0
  894.  
  895.     lea    test_stack,a1
  896.     add.l    #STACK_SIZE,a1
  897.     
  898.     move.w    #TASK_ANZ-1,d0
  899. .1    clr.l    TASK_PTR(a0)        ; pointer
  900.     clr.w    TASK_PRIOR(a0)        ; priority
  901.     clr.w    TASK_FLAGS(a0)        ; flags
  902.     move.l    a1,TASK_REGS+15*4(a0)
  903.     lea    128(a0),a0
  904.     add.l    #STACK_SIZE,a1
  905.     dbf    d0,.1
  906.     rts
  907. ;-----------------------------------------------------------
  908. init_multitask_interrupt
  909.     move.w    #$2700,sr
  910.  
  911.     move.l    #task_switch,$120.w
  912.  
  913.     bset    #0,$fffffa07.w            ; IERB
  914.     bset    #0,$fffffa13.w            ; IMRB
  915.  
  916.     clr.b    $fffffa1b.w
  917.     move.b    #50,$fffffa21.w            ; Timer B Data
  918.     move.b    #7,$fffffa1b.w            ; Timer B Control
  919.  
  920.     move.w    #$2300,sr
  921.     rts
  922. ;-----------------------------------------------------------
  923. task_switch
  924.     clr.b    $fffffa1b.w
  925.     tst.w    multitasking
  926.     beq    .not_active
  927.  
  928. *    not.l    $ffff9800.w
  929.     movem.l    d0-a7,save_regs
  930.  
  931.     move.w    active_task,d0
  932.     lea    task_queue,a0
  933.     lsl.w    #7,d0
  934.     lea    (a0,d0.w),a0
  935.  
  936.     movem.l    d0-a7,TASK_REGS(a0)
  937.     move.l    save_regs,TASK_REGS(a0)
  938.     move.l    save_regs+8*4,TASK_REGS+8*4(a0)
  939.  
  940.     move.l    2(sp),TASK_PC(a0)
  941.     move.w    (sp),TASK_SR(a0)
  942.  
  943. .find_active
  944.     move.w    active_task,d0
  945.     lea    task_queue,a0
  946.     moveq    #7,d1
  947. .loop    
  948.     addq    #1,d0
  949.     and.w    #7,d0
  950.  
  951.     move.w    d0,d2
  952.     lsl.w    #7,d2
  953.     lea    (a0,d2.w),a1
  954.     cmp.l    #0,TASK_PTR(a1)
  955.     bne.s    .found
  956.     dbf    d1,.loop
  957.     bra.s    .not_found
  958. .found
  959.     move.w    d0,active_task
  960.  
  961.     move.l    TASK_REGS+15*4(a1),a7
  962.  
  963.     move.b    TASK_PRIOR(a1),$fffffa21.w    ; Timer B Data
  964.  
  965.     move.l    TASK_PC(a1),2(sp)
  966.     move.w    TASK_SR(a1),(sp)
  967.  
  968.     movem.l    TASK_REGS(a1),d0-a7
  969.  
  970.     bra.s    .ok
  971. .not_found
  972.     movem.l    save_regs,d0-a7
  973. .not_active
  974.     move.b    #100,$fffffa21.w        ;######??????
  975.  
  976. .ok
  977.  
  978. *    not.l    $ffff9800.w
  979.  
  980.     move.b    #7,$fffffa1b.w            ; Timer B Control
  981.  
  982.     bclr    #0,$fffffa0f.w            ; IPRB
  983.     rte
  984. ;-----------------------------------------------------------
  985. save_regs    ds.l    16
  986. ;-----------------------------------------------------------
  987.  
  988.  
  989. ;-----------------------------------------------------------
  990. ; ********************** VBL-HANDLING **********************
  991. ;-----------------------------------------------------------
  992. ; -> a0 : pointer to rout
  993. ;    d0 : priority
  994. add_vbl
  995.     lea    vbl_queue,a6
  996.  
  997.     move.w    #VBL_ANZ-1,d7
  998. .1    move.l    (a6),d1
  999.     beq.s    .found
  1000.     lea    8(a6),a6
  1001.     dbf    d7,.1
  1002.     rts
  1003.  
  1004. .found
  1005.     move.l    a0,(a6)
  1006.     move.l    d0,4(a6)
  1007.     rts
  1008. ;-----------------------------------------------------------
  1009. ; -> a0 : pointer to rout
  1010. ;    d0 : priority
  1011. delete_vbl
  1012.     lea    vbl_queue,a6
  1013.  
  1014.     move.w    #VBL_ANZ-1,d7
  1015. .1    move.l    (a6),a1
  1016.     cmp.l    a1,a0
  1017.     beq.s    .found
  1018.     lea    8(a6),a6
  1019.     dbf    d7,.1
  1020.     rts
  1021.  
  1022. .found
  1023.     clr.l    (a6)
  1024.     clr.w    4(a6)
  1025.     rts
  1026. ;-----------------------------------------------------------
  1027. handle_vbl_list
  1028.     bsr    clear_vbl_flags
  1029.  
  1030.     lea    vbl_queue,a0
  1031.  
  1032.     move.w    #VBL_ANZ-1,d0
  1033. .1    move.l    (a0),a6
  1034.     cmp.l    #0,a6
  1035.     beq.s    .no
  1036.     pusha
  1037.     jsr    (a6)
  1038.     popa
  1039. .no
  1040.     lea    8(a0),a0
  1041.     dbf    d0,.1
  1042.     
  1043.     rts
  1044. ;-----------------------------------------------------------
  1045. clear_vbl_flags
  1046.     lea    vbl_queue,a0
  1047.     
  1048.     move.w    #VBL_ANZ-1,d0
  1049. .1    clr.w    6(a0)
  1050.     lea    8(a0),a0
  1051.     dbf    d0,.1
  1052.     rts
  1053. ;-----------------------------------------------------------
  1054. init_vbl_queue
  1055.     lea    vbl_queue,a0
  1056.     
  1057.     move.w    #VBL_ANZ-1,d0
  1058. .1    clr.l    0(a0)        ; pointer
  1059.     clr.w    4(a0)        ; priority
  1060.     clr.w    6(a0)        ; flags
  1061.     lea    8(a0),a0
  1062.     dbf    d0,.1
  1063.     rts
  1064. ;-----------------------------------------------------------
  1065.  
  1066.  
  1067.  
  1068. ;-----------------------------------------------------------
  1069. do_main_vbl
  1070.     lea    demo_param,a0
  1071.     tst.w    SCREEN_SWAP(a0)
  1072.     beq.s    .no_scrswap
  1073.  
  1074.     cmp.w    #3,SCREEN_COUNT(a0)
  1075.     bne.s    .swp1
  1076.     move.l    SHOW_SCREEN(a0),d0
  1077.     move.l    EXTRA_SCREEN(a0),SHOW_SCREEN(a0)
  1078.     move.l    WORK_SCREEN(a0),EXTRA_SCREEN(a0)
  1079.     move.l    d0,WORK_SCREEN(a0)
  1080.     bra.s    .swap_ok
  1081. .swp1
  1082.     move.l    SHOW_SCREEN(a0),d0
  1083.     move.l    WORK_SCREEN(a0),SHOW_SCREEN(a0)
  1084.     move.l    d0,WORK_SCREEN(a0)
  1085. .swap_ok
  1086.     clr.w    SCREEN_SWAP(a0)
  1087.  
  1088.     move.l    SHOW_SCREEN(a0),d0
  1089.     move.l    d0,d1
  1090.     move.w    d1,d2
  1091.  
  1092.     swap    d0
  1093.     lsr.w    #8,d1
  1094.  
  1095.     move.b    d0,$ffff8201.w
  1096.     move.b    d1,$ffff8203.w
  1097.     move.b    d2,$ffff820d.w
  1098. *    move.b    d0,$ffff8205.w
  1099. *    move.b    d1,$ffff8207.w
  1100. *    move.b    d2,$ffff8209.w
  1101.  
  1102. .no_scrswap
  1103.  
  1104.     tst.w    SCRMODE_UPDATE(a0)
  1105.     beq.s    .no_scrmode
  1106.  
  1107.     pusha
  1108.     move.l    SCRMODE(a0),a0
  1109.     set_resolution
  1110.     popa
  1111.     clr.w    SCRMODE_UPDATE(a0)
  1112. .no_scrmode
  1113.  
  1114.  
  1115.     tst.w    PALETTE_UPDATE(a0)
  1116.     beq.s    .no_palette
  1117.  
  1118.     move.l    PALETTE(a0),a1
  1119.     lea    $ffff9800.w,a2
  1120.     moveq    #256/16-1,d0
  1121. .1    REPT 16
  1122.     move.l    (a1)+,(a2)+
  1123.     ENDR
  1124.     clr.w    PALETTE_UPDATE(a0)
  1125.     dbf    d0,.1
  1126. .no_palette
  1127.  
  1128.     tst.w    do_play
  1129.     beq.s    .no_sound
  1130.     jsr    player+44        ;play
  1131. .no_sound
  1132.     rts
  1133. ;-----------------------------------------------------------
  1134. vbl
  1135.     sf    multitasking
  1136.     move.w    #$2500,sr
  1137. *    clr.b    $fffffa1b.w
  1138.     movem.l    d0-a7,vbl_regs
  1139.  
  1140.  
  1141.     bsr    do_main_vbl
  1142.  
  1143.     bsr    handle_vbl_list
  1144.     movem.l    vbl_regs,d0-a7
  1145.  
  1146.     move.b    key,old_key
  1147.     move.b    $fffffc02.w,key
  1148.  
  1149.  
  1150.     tst.w    demo_settings+2
  1151.     bne.s    .no_exit        ;demo_lock
  1152.  
  1153.     tst.w    loadflag
  1154.     bne.s    .no_exit
  1155.     cmp.b    #$39,key
  1156.     bne.s    .no_exit
  1157.     move.w    #$2700,sr
  1158.     clr.w    do_play
  1159.     bra    main_exit
  1160. .no_exit
  1161.  
  1162. ****************************************
  1163. **    pusha
  1164. **    not.l    $ffff9800.w
  1165. **    move.w    #200,d0
  1166. **.1    dbf    d0,.1
  1167. **    not.l    $ffff9800.w
  1168. **    popa
  1169. ****************************************
  1170.  
  1171.     add.w    #1,vsync_count
  1172.     add.l    #1,counter_abs
  1173.     add.l    #1,counter_rel
  1174.     st    multitasking
  1175. *    move.b    #7,$fffffa1b.w            ; Timer B Control
  1176.     move.w    #$2300,sr
  1177.     rte
  1178.  
  1179. old_vbl    jmp    $12345678
  1180.  
  1181. vbl_regs    ds.l    16
  1182. ;-----------------------------------------------------------
  1183. ; ********************** TIME-SHARING **********************
  1184. ;-----------------------------------------------------------
  1185.  
  1186.  
  1187.  
  1188. ;-----------------------------------------------------------
  1189. clrscr
  1190.     move.l    scr1,a5
  1191.     moveq    #0,d0
  1192.     moveq    #0,d1
  1193.     moveq    #0,d2
  1194.     moveq    #0,d3
  1195.     moveq    #0,d4
  1196.     moveq    #0,d5
  1197.     moveq    #0,d6
  1198.     move.l    d0,a0
  1199.     move.l    d0,a1
  1200.     move.l    d0,a2
  1201.  
  1202.     move.w    #459,d7
  1203. .1    
  1204.     rept    10
  1205.     movem.l    d0-d6/a0-a2,(a5)
  1206.     lea    40(a5),a5
  1207.     endr
  1208.     dbf    d7,.1
  1209.     rts
  1210. ;-----------------------------------------------------------
  1211. init
  1212.     clr_bss
  1213.  
  1214.     super_on
  1215.     mouse_off
  1216.  
  1217.     cache_on
  1218.  
  1219.         move.l  $44e.w,old_screen
  1220.     save_resolution
  1221.  
  1222.     move.l    #screens+256,d0
  1223.     clr.b    d0
  1224.     move.l    d0,scr1
  1225.     add.l    #384*240*2,d0
  1226.     move.l    d0,scr2
  1227.     add.l    #384*240*2,d0
  1228.     move.l    d0,scr3
  1229.  
  1230.     move.l    scr1,d0
  1231.     setscreen
  1232.  
  1233.     lea    rgb_320x200xtrue,a0
  1234.     set_resolution
  1235.  
  1236.     move.l    #0,$ffff9800.w
  1237.         rts
  1238. ;-----------------------------------------------------------
  1239. exit
  1240.     
  1241.     move.l    old_screen,d0
  1242.     setscreen
  1243.     restore_resolution
  1244.  
  1245.     mouse_on
  1246.     super_off
  1247.     rts
  1248. ;-----------------------------------------------------------
  1249.  
  1250.  
  1251.  
  1252. ;-----------------------------------------------------------
  1253. scr1        dc.l    0
  1254. scr2        dc.l    0
  1255. scr3        dc.l    0
  1256. ;-----------------------------------------------------------
  1257. ;----------------------------------------------------------
  1258.  
  1259. credits        dc.b    1,"h:\dba\dba.dat",0
  1260. dba_3d        dc.b    2,"h:\dba\dba.dat",0
  1261. rotator        dc.b    3,"h:\dba\dba.dat",0
  1262. mag        dc.b    4,"h:\dba\dba.dat",0
  1263.  
  1264. modname     dc.b    0,"h:\dba\dba.dat",0
  1265. endmodule     *dc.b    1,"lostbl_4.dat",0
  1266.     even
  1267. ;-----------------------------------------------------------
  1268.  
  1269. active_task    dc.w    0
  1270. multitasking    dc.w    0
  1271.  
  1272.  
  1273. ENDLIST        = 0
  1274. START        = 1
  1275. ADDVBL        = 2
  1276. DELVBL        = 3
  1277. STARTSOUND    = 4
  1278. ADDTASK        = 5
  1279. DELTASK        = 6
  1280. RESTART        = 7
  1281. LOAD        = 8
  1282. EXIT        = 9
  1283. CLEAR        = 10
  1284. STOPSOUND    = 11
  1285. LOADMODULE    = 12
  1286. DEMOLOCKED    = 13
  1287. REPAIR_ALL    = 14            ;Commando list
  1288.  
  1289.  
  1290. _DBA_3D_    = 100000
  1291. _MAG_        = 1400000        
  1292. _ROTATOR_    = 600000
  1293. _CREDITS_    = 100000        ;Memory occupation
  1294.  
  1295.  
  1296.  
  1297. demo_listptr    dc.l    demo_list
  1298.  
  1299. ;-------------------------------------------- Refrain 1
  1300. demo_list
  1301. test
  1302.  
  1303. demo_start
  1304.     dc.l    2310,REPAIR_ALL
  1305.  
  1306.     dc.l    2350,LOADMODULE,modname
  1307.  
  1308.     dc.l    2400,LOAD,dba_3d,_DBA_3D_
  1309.     dc.l    2450,START,_DBA_3D_,100
  1310.     dc.l    2500,STARTSOUND
  1311.  
  1312.     dc.l    2510,ADDTASK,_DBA_3D_,200
  1313.     dc.l    3010,LOAD,mag,_MAG_
  1314.     dc.l    3100,START,_MAG_,100
  1315.     dc.l    3209,DELTASK,_DBA_3D_
  1316.  
  1317.     dc.l    3211,ADDTASK,_MAG_,200
  1318.     dc.l    3410,DELTASK,_MAG_
  1319.  
  1320.     dc.l    3411,LOAD,rotator,_ROTATOR_
  1321.     dc.l    3450,START,_ROTATOR_,100
  1322.  
  1323.     dc.l    3470,ADDTASK,_ROTATOR_,200
  1324.     dc.l    3500,LOAD,credits,_CREDITS_
  1325.     dc.l    3570,START,_CREDITS_,50
  1326.     dc.l    3710,DELTASK,_ROTATOR_
  1327.  
  1328.     dc.l    3711,ADDTASK,_CREDITS_,200
  1329.     dc.l    3720,DELTASK,_CREDITS_
  1330.  
  1331.     dc.l    3721,ADDVBL,_CREDITS_+4,100
  1332.     dc.l    5250,DELVBL,_CREDITS_+4
  1333.  
  1334.     
  1335. end_of_demo
  1336.     dc.l    69500,DEMOLOCKED
  1337.  
  1338.     dc.l    69510,DELTASK,_CREDITS_
  1339.     dc.l    69520,STOPSOUND
  1340.     dc.l    69530,CLEAR
  1341.     dc.l    69750,RESTART,demo_start,2300
  1342.     
  1343.  
  1344.     dc.l    999999,ENDLIST
  1345.  
  1346.  
  1347.  
  1348. demo_param
  1349. show_screen    dc.l    0
  1350. work_screen    dc.l    0
  1351. extra_screen    dc.l    0
  1352. screen_count    dc.w    3
  1353. screen_swap    dc.w    0
  1354. palette        dc.l    pal_buffer
  1355. palette_update    dc.w    1
  1356. counter_abs    dc.l    0
  1357. counter_rel    dc.l    0
  1358. scrmode        dc.l    rgb_320x200xtrue
  1359. scrmode_update    dc.w    0
  1360.  
  1361. pal_buffer    ds.l    256
  1362.  
  1363.  
  1364.  
  1365. ;-----------------------------------------------------------
  1366.     IFNE internal_speaker=0
  1367. main_volume    dc.w    $7fff
  1368.     ELSE
  1369. main_volume    dc.w    $1fff
  1370.     ENDC
  1371.  
  1372. do_play        dc.w    0        ;Player running 0=off 1=on
  1373.  
  1374. vol_tab        dcb.w    8,0
  1375.  
  1376. player    incbin    dspmod\dspmod2.tce
  1377.     EVEN
  1378.  
  1379.     section bss
  1380.     ds.b    33000
  1381.  
  1382.     even
  1383.  
  1384.     ds.l    1000
  1385. mystack        ds.l    0
  1386.  
  1387. test_stack    ds.b    9*STACK_SIZE+100
  1388. vbl_queue    ds.b    8*VBL_ANZ
  1389. task_queue    ds.b    128*TASK_ANZ
  1390. file_header    ds.b    256
  1391.  
  1392. start_bss
  1393. module        ds.b    400000
  1394. module_end    ds.l    1
  1395.  
  1396. screens        ds.b    3*384*240*2+256        ;Screenbuffer
  1397. end_bss
  1398.  
  1399. buffer        ds.b    1500000
  1400. buffer_end
  1401.