home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 39 / af039a.adf / main.s < prev    next >
Text File  |  1992-09-17  |  23KB  |  1,046 lines

  1. ;MUSIC_ON_OR_OFF =    0
  2. FUNC_MAIN        =     1
  3. TESTING            =    1
  4. USE_JOYSTICK    =    1
  5. ;USE_MOUSE        =    0
  6.  
  7.     IFD        USE_MOUSE
  8. MSPRITE_HEIGHT    =    16
  9.     ENDC
  10.  
  11. ;    INCLUDE custom.i
  12. ;    INCLUDE myheader.i
  13. ;    INCLUDE what_key.s
  14. ;    INCLUDE    funcs.f
  15.  
  16. ******************************************************************************
  17.       xdef    _main
  18. _main
  19.     move.w    INTENAR,old_ena
  20.     move.w    DMACONR,old_dma
  21.     IFND        OS_LEGAL
  22.     move.w    #%0111111111011111,INTENA    ; turn off all interuppts
  23.     move.w    #%1100000000101000,INTENA    ; sets vert blank
  24.     move.w    #$7fff,INTREQ
  25.     move.l    #$00fc0c8e,100
  26.     move.l    #$00fc0ce2,104
  27.     move.l    #$00fc0d14,108
  28.     move.l    #$00fc0d6c,112
  29.     move.l    #$00fc0dfa,116
  30.     move.l    #$00fc0e40,120
  31.     move.l    #$00fc0e86,124
  32.     ENDC
  33.     movem.l    d0-d7/a0-a6,-(sp)
  34.     jsr        _setup_libs
  35.     jsr        _setup_keyboard
  36.     jsr         _setup_vbi
  37.     jsr         _setup_screens
  38.     jsr        _swap_screens
  39.     IFD        MUSIC_ON_OR_OFF
  40.     jsr        mt_init
  41.     ENDC
  42.     jsr        _display
  43.     IFD        MUSIC_ON_OR_OFF
  44.     jsr        mt_end
  45.     ENDC
  46.     jsr        _reset_system
  47.     movem.l    (sp)+,d0-d7/a0-a6
  48.     rts
  49.  
  50.     xdef    _reset_system
  51. _reset_system
  52.     movem.l    d0-d7/a0-a6,-(sp)
  53.     move.w    #$7fff,INTENA                ;reset the old interupt values
  54.     move.w    #$7fff,DMACON                ;reset dmacon old values
  55.     jsr        _reset_keyboard
  56.     jsr         _reset_vbi
  57.     jsr         _reset_copper
  58.     move.w    old_ena,d0
  59.     or.w    #$8000,d0
  60.     move.w    d0,INTENA
  61.     move.w    old_dma,d0
  62.     or.w    #$8000,d0
  63.     move.w    d0,DMACON
  64.     movem.l    (sp)+,d0-d7/a0-a6
  65.     rts
  66.  
  67. ******************************************************************************
  68. old_ena    dc.w    0
  69. old_dma    dc.w    0
  70. ******************************************************************************
  71.     xdef    _copper_list
  72. _copper_list
  73.     dc.l    _copper_mem1
  74.     dc.l    _copper_mem2
  75. ******************************************************************************
  76.     xdef    _reset_copper
  77. _reset_copper
  78.     movem.l a0/d0,-(sp)
  79.     move.l  _GFXBase,a0
  80.     move.l  38(a0),d0
  81.     move.l  d0,COP1LC
  82.     move.w  COPJMP1,d0
  83.     movem.l (sp)+,a0/d0
  84.     rts
  85.  
  86. *************************************************************
  87.  
  88.     xdef    _reset_vbi
  89. _reset_vbi
  90.     move.l  20,d0
  91.     move.l  _old2_int_vec,20
  92.     move.l  d0,_old2_int_vec
  93.     move.l  108,d0
  94.     move.l  _old1_int_vec,108
  95.     move.l  d0,_old1_int_vec
  96.     rts
  97.  
  98. *************************************************************
  99.  
  100.     xdef    _setup_vbi
  101. _setup_vbi
  102.     move.l  a0,-(sp)
  103.     IFD        OS_LEGAL
  104.     move.w  #%0000000001110000,INTENA
  105.     ENDC
  106.     move.l  108,_old1_int_vec
  107.     lea         _vbi_interupt,a0
  108.     move.l  a0,108
  109.     move.l  20,_old2_int_vec
  110.     lea         _div_by_zero,a0
  111.     move.l  a0,20
  112.     IFD        OS_LEGAL
  113.     move.w  #%1100000000110000,INTENA
  114.     ELSEIF
  115.     move.w  #%1000000000100000,INTENA
  116.     move.w  #%0000000000100000,INTREQ
  117.     ENDC
  118.     move.l  (sp)+,a0
  119.     rts
  120.  
  121.     xdef    _do_ints
  122.     IFD        OS_LEGAL
  123. _do_ints    dc.w    1
  124.     ELSEIF
  125. _do_ints    dc.w    0
  126.     ENDC
  127.  
  128.  
  129. **************************************************************************
  130. _ijoy1
  131.     dc.w     0,-1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0,-1,-1
  132. _ijoy2
  133.     dc.w     0, 1, 1, 1,-1, 0, 0, 0,-1, 0, 0, 0,-1, 0
  134. **************************************************************************
  135. _joy_table1
  136.    dc.w    0
  137.    dc.w    0
  138.    dc.w    1
  139.    dc.w    1
  140.    dc.w    0
  141.    dc.w    0                               ; not used
  142.    dc.w    0                               ; not used
  143.    dc.w    1
  144.    dc.w    -1
  145.    dc.w    0                               ; not used
  146.    dc.w    0                               ; not used
  147.    dc.w    0                               ; not used
  148.    dc.w    -1
  149.    dc.w    -1
  150. **************************************************************************
  151. _joy_table2
  152.    dc.w    0
  153.    dc.w    1
  154.    dc.w    1
  155.    dc.w    0
  156.    dc.w    -1
  157.    dc.w    0                               ; not used
  158.    dc.w    0                               ; not used
  159.    dc.w    -1
  160.    dc.w    -1
  161.    dc.w    0                               ; not used
  162.    dc.w    0                               ; not used
  163.    dc.w    0                               ; not used
  164.    dc.w    0
  165.    dc.w    1
  166. *************************************************************
  167.  
  168.     xdef    _vbi_interupt
  169. _vbi_interupt
  170.     movem.l  d0-d7/a0-a6,-(sp)
  171.     move.w  INTREQR,d0
  172.     and.w   INTENAR,d0
  173.     and.w   #%0100000000100000,d0
  174.     beq         .not_this_time
  175.  
  176.     IFD        USE_JOYSTICK
  177.  
  178.     move.l  D0,-(sp)
  179.  
  180.     move.w  $dff00c,d0
  181.     and.w   #$0303,d0
  182.     bclr    #8,d0
  183.     beq.s   .zero1
  184.         bset    #2,d0
  185. .zero1
  186.     bclr    #9,d0
  187.     beq.s   .zero2
  188.         bset    #3,d0
  189. .zero2
  190.     add.w   d0,d0
  191.     move.w  _joy_table1(PC,d0.w),_dx_joy
  192.     move.w  _joy_table2(PC,d0.w),_dy_joy
  193.  
  194. .fire_test
  195.     btst.b  #7,$bfe0ff
  196.     bne.s   .no_fire
  197.        add.w    #1,_fire
  198.        bra.s    .fire1_done
  199. .no_fire
  200.     move.w  #0,_fire
  201. .fire1_done
  202.     move.w  #$c000,$dff034                   ; set potgo to correct status
  203.     move.w  $dff016,d0
  204.     btst.l  #14,d0                          ; check the button in potgo_read
  205.     bne.s   .no_fire2
  206.         add.w   #1,_fire2
  207.         bra.s   .fire2_done
  208. .no_fire2
  209.     move.w  #0,_fire2
  210. .fire2_done
  211.     move.w  #$000,$dff034                   ; set potgo to correct status
  212.     cmp.w    #255,_fire
  213.     blt.s    .end
  214.         move.w    #255,_fire
  215. .end
  216.     move.l  (sp)+,D0
  217.     ENDC
  218.     IFD        USE_MOUSE
  219.     jsr     _vbi_mouse
  220.     ENDC
  221.     IFD        MUSIC_ON_OR_OFF
  222.     jsr        mt_music
  223.     ENDC
  224. ;corrupts registers
  225. *******************************
  226.     move.w  #1,_vbi_done
  227.     addq.w  #1,_vbi_timer
  228. *******************************
  229. .not_this_time
  230.     tst.w   _do_ints
  231.     beq.s   .not_dos
  232.         movem.l  (sp)+,d0-d7/a0-a6
  233.         move.l  _old1_int_vec,-(sp)
  234.         rts
  235. .not_dos
  236.     move.w  #%0000000000100000,INTREQ
  237.     movem.l  (sp)+,d0-d7/a0-a6
  238. _div_by_zero
  239.     rte
  240. ************************************************************
  241. ************************************************************
  242. Copper      equr    A0
  243. CColour        equr    A1
  244.  
  245. Custom      equr    D0
  246. Display     equr    D1
  247. DWork1      equr    D2
  248. Sprite        equr    D3
  249. StartCopper    equr    D4
  250.  
  251.     xdef    _setup_screens
  252. _setup_screens
  253.  
  254.     movem.l d1/a0/a1/a2,-(sp)
  255.     IFD        USE_MOUSE
  256.     jsr         _setup_mouse
  257.     ENDC
  258.     lea         _screen_mem,a0
  259.     move.l  a0,Display
  260.     move.l  Display,_d_screen
  261.     lea         _copper_mem1,Copper
  262.     lea         _pallet,CColour
  263.     lea         _copper_list,a2
  264.     jsr         _make_copper
  265.     add.l    #4,Copper
  266.     move.l  Copper,(a2)+
  267.     lea         _copper_mem2,Copper
  268.     add.l   #SCREEN_WIDTH*SCREEN_HEIGHT*NO_PLANES,Display
  269.     move.l  Display,_w_screen
  270.     jsr         _make_copper
  271.     add.l    #4,Copper
  272.     move.l  Copper,(a2)
  273.     movem.l (sp)+,d1/a0/a1/a2
  274.     rts
  275.  
  276. _pallet
  277.     incbin data/pal.dat
  278. ;    dc.w    $000,$111,$222,$333,$444,$555,$666,$777
  279. ;    dc.w    $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
  280. *************************************************************
  281.     xdef    _make_copper
  282. _make_copper
  283.  
  284.     movem.l Custom-StartCopper/Copper-CColour,-(sp)
  285. * the first 4 bytes of the copper list is used for dummy sprites
  286.     move.l    Copper,StartCopper
  287.     clr.l    (Copper)+
  288.  
  289. * first set up all the defaults for the screen
  290.     move.l    #$009c0010,(Copper)+    Set the INTREQ to tell me we are at the TVP
  291.     move.l    #$01004200,(Copper)+    BPLCON0
  292. ;    move.l    #$01020044,(Copper)+    BPLCON1
  293.     move.l    #$01020000,(Copper)+    BPLCON1
  294.     move.l    #$01040024,(Copper)+    BPLCON2
  295.     tst.w       _pal
  296.     beq.s    ntsc
  297.     move.l  #$008e3681,(Copper)+    DIWSTRT
  298.     move.l    #$0090fec1,(Copper)+    DIWSTOP
  299.     bra.s    pal_continue
  300. ntsc
  301.     move.l    #$008e2c81,(Copper)+    DIWSTRT
  302.     move.l  #$0090f4c1,(Copper)+    DIWSTOP
  303. pal_continue
  304.     move.l    #$00920038,(Copper)+    DFFSTRT
  305.     move.l    #$009400d0,(Copper)+    DFFSTOP
  306.     move.l  #$01080000,(Copper)+    BPL1MOD
  307.     move.l  #$010a0000,(Copper)+    BPL2MOD
  308.  
  309. * set up the colour table
  310.     IFD        USE_MOUSE
  311.     move.w    #31,DWork1
  312.     ELSEIF
  313.     move.w    #(1<<NO_PLANES)-1,DWork1
  314.     ENDC
  315.     move.w    #$180,Custom
  316. setup_colour_table
  317.     move.w    Custom,(Copper)+
  318.     move.w    (CColour)+,(Copper)+
  319.     addq.w    #2,Custom
  320.     dbra    DWork1,setup_colour_table
  321.  
  322. * D0 contions offset for bitplane pointers
  323.     move.w    #$E0,Custom
  324.     move.w    #NO_PLANES-1,DWork1
  325. .make_copper_planes
  326.     move.w    Custom,(Copper)+
  327.     addq.w    #2,Custom
  328.     swap    Display
  329.     move.w    Display,(Copper)+
  330.     move.w    Custom,(Copper)+
  331.     addq.w    #2,Custom
  332.     swap    Display
  333.     move.w    Display,(Copper)+
  334.     add.l    #SCREEN_WIDTH*SCREEN_HEIGHT,Display
  335.     dbra    DWork1,.make_copper_planes
  336.  
  337. * D1 contains offset for sprite pointers
  338.     move.w    #$120,Custom
  339.     move.w    #7,DWork1
  340. ;if s\pinter data is defined then we must set up a sprite for this screen
  341.     IFD        USE_MOUSE
  342.     move.l    #_pointer_data,Sprite                ;add sprite 0
  343.     swap    Sprite
  344.     move.w    Custom,(Copper)+
  345.     move.w    Sprite,(Copper)+
  346.     add.w    #2,Custom
  347.     swap    Sprite
  348.     move.w    Custom,(Copper)+
  349.     move.w    Sprite,(Copper)+
  350.     add.w    #2,Custom
  351.  
  352.     add.l    #18*4,Sprite                        ;adjust for size of pointer
  353.     swap    Sprite
  354.     move.w    Custom,(Copper)+
  355.     move.w    Sprite,(Copper)+
  356.     add.w    #2,Custom
  357.     swap    Sprite
  358.     move.w    Custom,(Copper)+
  359.     move.w    Sprite,(Copper)+
  360.     add.w    #2,Custom
  361.     sub.w    #2,DWork1
  362.     ENDC
  363. .make_copper_sprites
  364.     move.w    Custom,(Copper)+
  365.     addq.w    #2,Custom
  366.     swap    StartCopper
  367.     move.w    StartCopper,(Copper)+
  368.     move.w    Custom,(Copper)+
  369.     addq.w    #2,Custom
  370.     swap    StartCopper
  371.     move.w    StartCopper,(Copper)+
  372.     dbra    DWork1,.make_copper_sprites
  373. * terminate the copper list
  374.     move.l    #$0901ff00,(Copper)+    WAIT FOR BOTTOM OF DISPLAY
  375.     IFD        OS_LEGAL
  376.     move.l    #$009c8030,(Copper)+    Set the INTREQ to tell me we are at the BVP
  377.     ELSEIF
  378.     move.l    #$009c8030,(Copper)+    Set the INTREQ to tell me we are at the BVP
  379.     ENDC
  380.     move.l    #$fffffffe,(Copper)
  381.     move.w    #$83c0,DMACON
  382.     
  383.     move.l    #0,$dff140                ;newbit
  384.  
  385.     addq.l  #4,StartCopper
  386.     move.l  StartCopper,COP1LC
  387.     move.l    StartCopper,_showing
  388.     movem.l (sp)+,Custom-StartCopper/Copper-CColour
  389.     rts
  390. *************************************************************
  391.        xdef    _setup_keyboard
  392. _setup_keyboard
  393.     move.w  #%0000000000001000,INTENA
  394.     move.l    $68,old_keyboard_int
  395.     lea        keyboard_interupt,a0
  396.     move.l  a0,$68
  397.     move.w  #%1100000000001000,INTENA
  398.     rts
  399.  
  400.     xdef    _reset_keyboard
  401. _reset_keyboard
  402.     move.w  #%0000000000001000,INTENA
  403.     move.l  $68,d0
  404.     move.l  old_keyboard_int,$68
  405.     move.l  d0,old_keyboard_int
  406.     move.w  #%1100000000001000,INTENA
  407.     rts
  408.  
  409.     xdef    keyboard_interupt
  410. keyboard_interupt
  411.     movem.l    d0/a0,-(sp)                        ;save all registers
  412.     move.b    $bfec01,d0                        ;load in the keyboard value no matter if we are in the system keyboard or not
  413.     move.b    d0,_iinkey                        ;store the raw key into iinkey
  414.     move.b    d0,_iiinkey
  415.     tst.w    _da_flag                        ;are we using the system keyboard ?
  416. ;    beq.s    its_not_the_system
  417.     cmp.b    #KF_10,d0
  418.     bne.s    .not_system_escape
  419.         btst    #0,_scr_system
  420.         bne.s    .not_system
  421.         bset    #0,_scr_system
  422.         move.l  _GFXBase,a0
  423.         move.l  38(a0),d0
  424.         move.w    #1,_da_flag
  425.         bra.s    .alter_copper
  426. .not_system
  427.         bclr    #0,_scr_system
  428.         move.l    _showing,d0
  429.         clr.w    _da_flag
  430. .alter_copper
  431.         move.l  d0,COP1LC
  432.         move.b    _iinkey,d0
  433. .not_system_escape
  434.     and.w    #$ff,d0                            ;now set the keyon value
  435.     lea        _key_on,a0
  436.     btst    #0,d0
  437.     beq.s    .key_up
  438.         add.b    #1,(a0,d0.w)
  439. .key_up
  440.         move.b    #0,1(a0,d0.w)
  441.     movem.l  (sp)+,d0/a0
  442.     move.l  old_keyboard_int,-(sp)            ;call system interupt
  443.     rts
  444. its_not_the_system
  445. ;    move.b    #%01110111,$bfee01
  446. ;    clr.b    _iinkey                            ;cleak the old keyboard valu
  447. ;    move.b    $bfed01,d0                        ;is this a keyboard interupt
  448. ;    and.b    #$8,d0                            ;is it a keyboard interupt
  449. ;    beq.s    .not_keyboard    
  450. ;    move.b    $bfec01,d0                        ;load in the keyboard value
  451. ;    move.b    #$0,$bfec01
  452. ;    or.b    #$40,$bfee01                    ;yes so do somthing strange
  453.     cmp.b    #KF_10,d0                        ;is it an escape
  454.     bne.s    .not_escape
  455.         bset    #0,_scr_system                ;yes so switch to system
  456.         move.l  _GFXBase,a0
  457.         move.l  38(a0),d0
  458.         move.w    #1,_da_flag
  459.         move.l  d0,COP1LC
  460.         move.b    _iinkey,d0
  461. .not_escape    
  462. ;    move.b    d0,_iinkey                        ;save iinkey
  463.     lea        _key_on,a0
  464.     and.w    #$ff,d0                            ;now set the keyon value
  465.     btst    #0,d0
  466.     bne.s    .down
  467.         move.b    d0,(a0,d0.w)
  468.         bra.s    .done
  469. .down
  470.         clr.b    1(a0,d0.w)
  471. .done    
  472. ;    move.b    #$ff,$bfec01
  473. ;    andi.b    #$bf,$bfee01                    ;repole the stange one
  474. .not_keyboard
  475. ;    move.b    #%10001000,$bfee01
  476.     move.w   #$8,INTREQ
  477.     movem.l  (sp)+,d0/a0                    ;restore the registers
  478.     rte
  479.     even
  480. old_keyboard_int    dc.l    0
  481.  
  482.  
  483. LIB_OPEN    EQU        -408 
  484.  
  485.     xdef    _setup_libs
  486. _setup_libs    
  487.     movem.l a1/a6/d0,-(sp)
  488. ;open the dos base    
  489.     move.l  4,a6                ; exec base
  490.     lea         DOS_Name,a1             ; library to open
  491.     jsr         LIB_OPEN(a6)
  492.     move.l  d0,_DosBase
  493. ;open the gfxbase
  494.     move.l  4,a6                ; exec base
  495.     lea         GFX_Name,a1             ; library to open
  496.     jsr         LIB_OPEN(a6)
  497.     move.l  d0,_GFXBase
  498.     move.l    d0,a1
  499.     move.w    $ce(a1),d0            ;GfxBase->DisplayFlags
  500.     and.w    #4,d0
  501.     move.w    d0,_pal
  502.     IFD    OS_LEGAL
  503. ;make sure no requesters come up
  504.     move.l    4,a6                ;exec base
  505.     sub.l    a1,a1                ;set name to null for out task
  506.     jsr        -294(a6)
  507.     move.l    d0,a1                ;task structure    
  508.     move.l    #-1,184(a1)            ;set window ptr to -1
  509.     ENDC
  510.     movem.l    (sp)+,a1/a6/d0
  511.     rts
  512.  
  513.     xdef    _DosBase,_GFXBase
  514. _DosBase    dc.l    0
  515. _GFXBase    dc.l    0
  516. GFX_Name    dc.b    "graphics.library",0
  517.     EVEN
  518. DOS_Name    dc.b    "dos.library",0
  519.     EVEN
  520.  
  521. **************************************************************
  522.  
  523.     xdef    _swap_screens
  524. _swap_screens
  525.     movem.l d0/a0,-(sp)
  526.     move.l  _d_screen,a0
  527.     move.l  _w_screen,_d_screen
  528.     move.l  a0,_w_screen
  529.     eor.l   #4,_toggle
  530.     lea         _copper_list,a0
  531.     add.l   _toggle,a0
  532.     move.l    (a0),_showing
  533.     move.l  (a0),COP1LC
  534.     clr.w    _vbi_done
  535.     add.l    #1,_time
  536.     movem.l (sp)+,d0/a0
  537.     rts
  538.  
  539.  
  540.     xdef    _showing
  541.     xdef    _scr_system
  542.     xdef    _toggle
  543. _toggle     dc.l    0
  544. _showing    dc.l    0
  545. _scr_system    dc.l    0
  546. **************************************************************
  547.  
  548.     xdef    _wait_vbi
  549. _wait_vbi
  550.     
  551. .loop
  552.     tst.w   _vbi_done
  553.     beq.s   .loop
  554.     
  555.     rts
  556. **************************************************************
  557.     IFD    USE_MOUSE
  558. MSprite    equr    A0
  559.  
  560. Scratch equr    D0
  561. VStart  equr    D1
  562. HStart  equr    D2
  563. VStop   equr    D3
  564.  
  565.   xdef  _vbi_mouse
  566. _vbi_mouse:
  567.     move.w    JOY0DAT,D0
  568.     and.w    #$00ff,D0
  569.     move.w    _old_mousex,D1
  570.     move.w    D0,_old_mousex
  571.     sub.w    D1,D0
  572.     cmp.w    #127,D0
  573.     ble.s    .NO_X_SUB
  574.         sub.w    #256,D0
  575. .NO_X_SUB
  576.     cmp.w    #-127,D0
  577.     bge.s    .NO_X_ADD
  578.         add.w    #256,D0
  579. .NO_X_ADD    
  580.     add.w    _big_mousex,D0
  581.     bpl.s    .X_IS_PLUS
  582.         move.w      #0,D0
  583. .X_IS_PLUS    
  584.     cmp.w    #639,D0
  585.     ble.s    .X_IN_BOUNDS
  586.         move.w    #639,D0
  587. .X_IN_BOUNDS    
  588.     move.w    D0,_big_mousex
  589.     lsr.w    #1,D0
  590. * push the mouse x on to the stack for the sprite interupt    
  591.     move.w    D0,_mmousex         removed for now
  592.     add.w    #64,D0
  593.     move.w    D0,-(sp)
  594.     move.w    JOY0DAT,D0
  595.     move.w    #8,D1
  596.     lsr.w    D1,D0
  597.     move.w    _old_mousey,D1
  598.     move.w    D0,_old_mousey
  599.     sub.w    D1,D0
  600.     cmp.w    #127,D0
  601.     ble.s    .NO_Y_SUB
  602.         sub.w    #256,D0
  603. .NO_Y_SUB
  604.     cmp.w    #-127,D0
  605.     bge.s    .NO_Y_ADD
  606.         add.w    #256,D0
  607. .NO_Y_ADD
  608.     add.w    _big_mousey,D0
  609.     bpl.s    .Y_IS_PLUS
  610.         move.w    #0,D0
  611. .Y_IS_PLUS    
  612.     cmp.w    _mouse_limit,D0
  613.     ble        .Y_IN_BOUNDS
  614.         move.w    _mouse_limit,D0
  615. .Y_IN_BOUNDS
  616.     move.w    D0,_big_mousey
  617.     lsr.w    #1,D0
  618. * push the mousey on to the stack for the sprite    
  619.     move.w    D0,_mmousey    
  620.     move.w    D0,-(sp) 
  621. ;do the left and right buttons   
  622.     move.b    $bfe0ff,d0
  623.     and.w    #$40,D0
  624.     bne.s    .left_is_up
  625.         move.w    #1,d0
  626.         tst.w    _mleft_button
  627.         bne.s    .left_done
  628.         tst.w    _left_button
  629.         bne.s    .left_done
  630.             move.w    d0,_left_button                ;set right button to 1 (on)
  631.             move.l    _mmousex,_mousex
  632.             bra.s    .left_done
  633. .left_is_up
  634.         move.w    #0,d0
  635. .left_done
  636.     move.w    d0,_mleft_button                    ;reftect actual state
  637.  
  638.     move.w    #$0c00,$dff034
  639.     move.w    $dff016,D0
  640.     and.w    #$0400,D0
  641.     bne.s    .right_is_up
  642.         move.w    #1,d0
  643.         tst.w    _mright_button
  644.         bne.s    .right_done
  645.         tst.w    _right_button
  646.         bne.s    .right_done
  647.             move.w    d0,_right_button            ;set right button to 1 (on)
  648.             move.l    _mmousex,_mousex
  649.             bra.s    .right_done
  650. .right_is_up
  651.         move.w    #0,d0
  652. .right_done
  653.     move.w    d0,_mright_button                    ;reftect actual state
  654.     clr.w    -(sp)                                ;move the pointer
  655.     bsr.s    _move_pointer
  656.     add.l    #6,sp
  657.     rts    
  658.     
  659.     xdef        _setup_mouse
  660. _setup_mouse:
  661.     movem.l d0-d1,-(sp)
  662.     
  663.     move.w  JOY0DAT,D0
  664.     and.w   #$00ff,D0
  665.     move.w  D0,_old_mousex
  666.     move.w  JOY0DAT,D0
  667.     move.w  #8,D1
  668.     lsr.w   D1,D0
  669.     move.w  D0,_old_mousey
  670.     movem.l (sp)+,d0-d1
  671.     rts
  672.    
  673.     xdef    _move_pointer
  674. _move_pointer:
  675.     movem.l    Scratch-VStop/MSprite,-(sp)
  676.     move.w    4+4*5(sp),Scratch
  677.     move.w    6+4*5(sp),VStart
  678.     move.w    8+4*5(sp),HStart
  679. ; get the address of the sprite
  680.     lea        _pointer_data,MSprite        
  681.     move.b    3+18*4(MSprite),VStop
  682.     and.b    #$80,VStop
  683. ; calculate HSTART must add on the left of the screen
  684.     add.w    #64,HStart
  685. ;    add.w    #64+8,HStart
  686.     lsr.w    #1,HStart
  687.     bcc.s    .hstart_bit_is_0
  688.         bset    #0,VStop
  689. .hstart_bit_is_0
  690.     move.b    HStart,1(MSprite)
  691.     move.b    HStart,1+18*4(MSprite)
  692. ; must add on the top of screen border
  693. ;    add.w    #44,VStart
  694. ;    add.w    #46,VStart
  695.     add.w    #54,VStart
  696.     tst.w    _pal
  697.     bne.s    .ntsc
  698.         sub.w    #10,VStart
  699. .ntsc
  700.     btst    #8,VStart
  701.     beq.s    .vstart_bit_is_0
  702.         bset    #2,VStop
  703. .vstart_bit_is_0
  704.     move.b    VStart,0(MSprite)
  705.     move.b    VStart,18*4(MSprite)
  706. * calculate VSTOP by addin in the height and subtracting 1
  707.     add.w    #MSPRITE_HEIGHT,VStart
  708.     btst    #8,VStart
  709.     beq.s    .vstop_bit_is_0
  710.     bset    #1,VStop
  711. .vstop_bit_is_0        
  712.     move.b    VStart,2(MSprite)
  713.     move.b    VStart,2+18*4(MSprite)
  714. * move the stop bit in sprite word
  715.     move.b    VStop,3(MSprite)
  716.     move.b    VStop,3+18*4(MSprite)    
  717.     movem.l    (sp)+,Scratch-VStop/MSprite
  718.     rts
  719.     
  720. _old_mousex     dc.w    0
  721. _old_mousey     dc.w    0
  722. _big_mousex     dc.w    0
  723. _big_mousey     dc.w    0
  724. _mouse_limit    dc.w    399 
  725.     ENDC
  726.  
  727.     IFD        USE_SERIAL
  728. ************************ EQUATES ********************************
  729. *
  730. *
  731. ************************ REGISTER EQUATES ************************
  732. *                            A0    A1    A2    A3    A4    A5    A6    A7
  733. Address            equr    a0
  734. Serial            equr    a1
  735. *                            D0    D1    D2    D3    D4    D5    D6    D7
  736. Math            equr    d1        !
  737. Length            equr    d1        !
  738. Mode            equr    d2 
  739. ************************** setserial ****************************
  740. * set baud_rate of serial port
  741. *
  742. *
  743. *****************************************************************
  744.     xdef    _setup_serial
  745. _setup_serial
  746.     move.w    #$0801,INTENA
  747.     move.l    $64,old_level_1
  748.     move.l    $74,old_level_5
  749.     jsr        _set_serial
  750.     move.l    #_w_ser_buff,$64
  751.     move.l    #_r_ser_buff,$74
  752.     move.w    #$8801,INTENA
  753.     rts
  754. _reset_serial
  755.     move.w    #$0801,INTENA
  756.     move.l    old_level_1,d0
  757.     move.l    $64,old_level_1
  758.     move.l    d0,$64
  759.     move.l    old_level_5,d0
  760.     move.l    $74,old_level_5
  761.     move.l    d0,$74
  762.     move.w    #$8801,INTENA
  763.     rts
  764.  
  765.     xdef    _set_serial
  766. _set_serial
  767.     movem.l    Serial/Math,-(sp)
  768.     lea        _serial,Serial
  769.     clr.l    Scratch
  770.     move.w    SE_BAUD_RATE(Serial),Scratch
  771.     lsl.w    #3,Scratch
  772.     sub.w    SE_BAUD_RATE(Serial),Scratch
  773.     move.l    #3579098,Math
  774.     divu    SE_BAUD_RATE(Serial),Math
  775.     sub.w    #1,Math
  776.     move.w    Math,SERPER
  777.     move.w    #$8801,INTENA
  778.     move.w    #$0801,INTREQ
  779.     move.b    $bfd000,Math
  780.     and.b    #%00111111,Math
  781.     move.b    Math,$bfd000
  782.     movem.l    (a7)+,Serial/Math
  783.     rts
  784.  
  785.     xdef    _clear_serial
  786. _clear_serial
  787.     movem.l    a0,-(sp)
  788.     lea        _serial,a0
  789.     clr.w    SE_READ_POS(a0)
  790.     clr.w    SE_WRITE_POS(a0)
  791.     movem.l    (sp)+,a0
  792.     rts
  793.     
  794.     xdef    _r_ser_buff
  795. _r_ser_buff
  796.     movem.l    d0/a0,-(sp)
  797.     move.w    $dff01c,d0
  798.     and.w    $dff01e,d0
  799.     btst    #11,d0
  800.     beq.s    .not_mine
  801.     lea        _serial,a0
  802.     move.w    SE_WRITE_POS(a0),d0
  803.     move.b    SERDATR+1,SE_BUFFER(a0,d0.w)
  804.     add.w    #1,d0
  805.     cmp.w    #SE_BUFFER_LEN,d0
  806.     bne.s    .buffer_not_full
  807.         move.w    #0,d0
  808. .buffer_not_full
  809.     move.w    d0,SE_WRITE_POS(a0)
  810.     move.w    #$0800,INTREQ
  811.     movem.l    (sp)+,d0/a0
  812.     rte
  813. .not_mine
  814.     IFD    OS_LEGAL
  815.         movem.l  (sp)+,d0/a0
  816.         move.l  old_level_5,-(sp)
  817.         rts
  818.     ELSEIF
  819.     and.w    #$18,d0
  820.     move.w    d0,INTREQ
  821.     movem.l    (sp)+,d0/a0
  822.     ENDC
  823.     rte
  824.     xdef    _w_ser_buff
  825. _w_ser_buff
  826.     movem.l    d0/a0,-(sp)
  827.     move.w    INTREQR,d0
  828.     and.w    INTENAR,d0
  829.     beq.s    .no_call
  830.     or.b    d0,_hello
  831.     btst    #0,d0
  832.     beq.s    .not_mine
  833.     move.w    #$0001,INTENA
  834.     lea        _serial,a0
  835.     move.w    #0,SE_WRITE_READY(a0)
  836.     move.w    #$0001,INTREQ
  837.     move.w    #$8001,INTENA
  838.     and.w    #%110,d0
  839.     bne.s    .not_mine
  840.     movem.l    (sp)+,d0/a0
  841.     rte
  842. .not_mine
  843.     IFD    OS_LEGAL
  844.         movem.l  (sp)+,d0/a0
  845.         move.l  old_level_1,-(sp)
  846.         rts
  847.     ELSEIF
  848.     and.w    #$7,d0
  849.     move.w    d0,INTREQ
  850.     movem.l    (sp)+,d0/a0
  851.     ENDC
  852. .no_call
  853.     rte
  854.     
  855.     xdef    _ww_ser_buff
  856. _ww_ser_buff
  857.     movem.l    d0/a0,-(sp)
  858.     move.w    $dff01c,d0
  859.     and.w    $dff01e,d0
  860.     add.w    #1,_hello
  861.     btst    #0,d0
  862.     beq.s    .not_mine
  863.     lea        _serial,a0
  864.     move.w    #0,SE_WRITE_READY(a0)
  865.     move.w    #$1,INTREQ
  866.     movem.l    (sp)+,d0/a0
  867.     rte
  868. .not_mine
  869.     IFD    OS_LEGAL
  870.         movem.l  (sp)+,d0/a0
  871.         move.l  old_level_1,-(sp)
  872.         rts
  873.     ELSEIF
  874.     and.w    #$7,d0
  875.     move.w    d0,INTREQ
  876.     movem.l    (sp)+,d0/a0
  877.     ENDC
  878.     rte
  879. ************************** read_serial **************************
  880. * read serial port
  881. *
  882. *    buffer                    a0    (long)
  883. *    Length                    d0    (word)
  884. *    Mode                    d1    (word)
  885. *
  886. *****************************************************************
  887.     xdef    _read_serial
  888. _read_serial
  889.     movem.l    a0/a1/d1/d2,-(sp)
  890.     move.w    d0,Length                    
  891.     move.w    d1,Mode
  892.     lea        _serial,Serial
  893. read_next_char
  894.     tst.w    Mode
  895.     bra        dont_break_read
  896.     beq        dont_break_read
  897.         tst.w    _shift
  898.         beq        dont_break_read
  899.             cmp.w    _iinkey,Scratch
  900.             bne        dont_break_read
  901.             bra        abort_read
  902. dont_break_read
  903.     move.w    SE_READ_POS(Serial),Scratch
  904.     cmp.w    SE_WRITE_POS(Serial),Scratch
  905.     beq.s    read_next_char
  906.     move.b    SE_BUFFER(Serial,Scratch.w),(Address)
  907.     add.w    #1,Scratch
  908.     cmp.w    #SE_BUFFER_LEN,Scratch
  909.     bne.s    buffer_not_at_end
  910.         move.w    #0,Scratch
  911. buffer_not_at_end
  912.     move.w    Scratch,SE_READ_POS(Serial)
  913.     tst.w    Length
  914.     bne.s    read_till_length
  915.         tst.b    (Address)+
  916.         bne        read_next_char
  917.             move.b    #0,(Address)
  918.             bra.s    end_of_read
  919. read_till_length
  920.     add.l    #1,Address
  921.     sub.w    #1,Length
  922.     bne        read_next_char
  923. end_of_read
  924.     move.l    #0,Scratch
  925. abort_read
  926.     tst.w    Scratch
  927.     movem.l    (sp)+,a0/a1/d1/d2
  928.     rts
  929.  
  930. ************************** write_serial **************************
  931. * write to serial port
  932. *
  933. *    buffer                    a0    (long)    Address
  934. *    Length                    d0    (word)    Length
  935. *    Mode                    d1    (word)    Mode
  936. *
  937. *****************************************************************
  938.     xdef    _write_serial
  939. _write_serial
  940.     movem.l    a0/a1/d1/d2,-(sp)
  941.     move.w    d0,Length
  942.     move.w    d1,Mode
  943.     sub.w    #1,Length
  944.     lea        _serial,Serial
  945. write_buffer_not_empty
  946.     tst.w    Mode
  947.     bra        dont_break_write
  948.     beq            dont_break_write
  949.         tst.w    _shift
  950.         beq        dont_break_write
  951.         jsr        _keyboard
  952.         cmp.w    Mode,Scratch
  953.         bne        dont_break_write
  954.         bra        abort_write
  955. dont_break_write
  956.     tst.w    SE_WRITE_READY(Serial)
  957.     bne.s    write_buffer_not_empty
  958.     moveq    #0,Scratch
  959.     move.b    (Address)+,Scratch
  960.     or.w    #$0100,Scratch
  961.     move.w    #1,SE_WRITE_READY(Serial)
  962.     move.w    Scratch,SERDAT
  963.     dbra    Length,write_buffer_not_empty
  964.     move.l    #0,Scratch
  965. abort_write
  966.     movem.l    (sp)+,a0/a1/d1/d2
  967.     rts
  968.     ENDC
  969.     
  970.     IFD    OS_LEGAL
  971. **************************************************************************
  972. *             all oslegal dos stuff Sun Apr  1 11:42:37 1990
  973. **************************************************************************
  974.  
  975.     xdef    _Open
  976. _Open
  977.     movem.l    a0/d1-d2,-(sp)
  978.     moveq    #0,d0
  979.     move.l    3*4+4(sp),d1
  980.     move.l    3*4+8(sp),d2
  981.     move.l    _DosBase,a0
  982.     jsr        -30(a0)
  983.     movem.l    (sp)+,a0/d1-d2
  984.     rts
  985.  
  986.     xdef    _Close    
  987. _Close
  988.     movem.l    a0/d1,-(sp)
  989.     move.l    2*4+4(sp),d1
  990.     move.l    _DosBase,a0
  991.     jsr        -36(a0)    
  992.     movem.l    (sp)+,a0/d1
  993.     rts
  994.  
  995.     xdef    _Read
  996. _Read
  997.     movem.l    a0/d1-d3,-(sp)
  998.     moveq    #0,d0
  999.     move.l    4*4+4(sp),d1
  1000.     beq.s    .the_end
  1001.     move.l    4*4+8(sp),d2
  1002.     beq.s    .the_end
  1003.     move.l    4*4+12(sp),d3
  1004.     beq.s    .the_end
  1005.     move.l    _DosBase,a0
  1006.     jsr        -42(a0)
  1007. .the_end
  1008.     movem.l    (sp)+,a0/d1-d3
  1009.     rts
  1010.  
  1011.     xdef    _Write
  1012. _Write
  1013.     movem.l    a0/d1-d3,-(sp)
  1014.     moveq    #0,d0
  1015.     move.l    4*4+4(sp),d1
  1016.     beq.s    .the_end
  1017.     move.l    4*4+8(sp),d2
  1018.     beq.s    .the_end
  1019.     move.l    4*4+12(sp),d3
  1020.     beq.s    .the_end
  1021.     move.l    _DosBase,a0
  1022.     jsr        -48(a0)    
  1023. .the_end
  1024.     movem.l    (sp)+,a0/d1-d3
  1025.     rts
  1026.     
  1027.     xdef    _Seek
  1028. _Seek
  1029.     movem.l    a0/d1-d3,-(sp)
  1030.     moveq    #0,d0
  1031.     move.l    4*4+4(sp),d1
  1032.     beq.s    .the_end
  1033.     move.l    4*4+8(sp),d2
  1034.     move.l    4*4+12(sp),d3
  1035.     move.l    _DosBase,a0
  1036.     jsr        -66(a0)    
  1037. .the_end
  1038.     movem.l    (sp)+,a0/d1-d3
  1039.     rts
  1040.     ENDC
  1041. ***********************************************************
  1042. _pointer_data
  1043.     dcb.b    114,0
  1044.     dc.l    0
  1045. ;;;;
  1046.