Pages

09 November 2012

Underc0der

!init
        #config scanner= 3
        #config weapon=  3
        #config armor=   4
        #config engine=  0
        #config heatsinks= 2
        #def    wpc
        #def    ang
        #def    turn            ;how much to turn
        #def    rh              ;relative heading
        #def    ts              ;target speed
        #def    o               ;pos/neg offset flag
        #def    off             ;firing offset
        out     11,     100     ;full throttle.
        out     22,     8       ;lay mine, trigger 8.
        out     17,     64      ;128 degree scan arc.
        mov     DX,     64
        mov     AX,     1
        mov     turn,   7
        int     3               ;keepshift on.
        out     22,     8       ;lay mine, trigger 8.
        jmp     !steer
!path
        cmp     @9,     250     ;Have we travelled 250 metres?
        jgr     !steer          ;if yes, steer.
        out     14,     turn    ;turn
        int     12              ;collisions?
        cmp     FX,     0
        jgr     !crash          ;if yes, respond to crash.
        jmp     !scan
 !crash
        int     13              ;reset collision count.
 !steer
        int     19              ;clear meters count.
        jmp     !checkpos       ;steer.
!scan
        out     11,     100
        in      7,      BX      ;scan
        cmp     BX,     1500    ;anyone in sight?
        jge     !nonefound      ;adjust scan arc to suit.
        jls     !arcmodf        ;modify arc & fire.
!nonefound
        cmp     DX,     64      ;Are we at maximum scan width already?
        je      !flip           ;if yes, flip turret.
        shl     DX,     1       ;else, double DX and
        out     17,     DX      ;set new scans to DX width.
        jmp     !path           ;path
 !flip
        out     12,     125     ;turn turret 125 degrees.
        jmp     !path           ;path
!arcmodf
        cmp     DX,     2       ;is scan angle 2 degrees?
        jle     !fire           ;if yes, fire. Else:
        shr     DX,     1       ;halve DX
        out     17,     DX      ;set scans to DX.
        cmp     @3,     0       ;is enemy in centre?
        jgr     !accright       ;if right, respond
        jls     !accleft        ;if left, respond.
        shr     DX,     1       
        out     17,     DX      ;quarter scan arc
        jmp     !fast           ;check if target is fast
 !accright
        out     12,     DX      ;turn radar right by scanarc.
        cmp     @3,     2       ;is it out by +2?
        jls     !fast           ;if less, fast
        out     12,     DX      ;turn radar right by 200% scanarc.
        jmp     !fast           ;check if target is fast
 !accleft
        mov     BX,     DX      ;set BX=scanarc
        neg     BX              ;and negate BX
        out     12,     BX      ;turn radar left by scanarc.
        cmp     @3,     -2      ;is it out by -2?
        jgr     !fast           ;if more, fast.
        out     12,     BX      ;turn radar left by 200% scanarc.
        jmp     !fast           ;check if target is fast
!fast
        cmp     @13,    768     ;is enemy moving very fast?
        jgr     !fire           ;if yes, fire
        jmp     !scan           ;else, scan.

!fire
        out     12,     @3      ;correct turret.
        in      2,      BX      ;check heat.
        cmp     BX,     200     ;too hot?
        jgr     !lock           ;if yes, lock. Else:
        cmp     @7,     0       ;Is target stationary?
        je      !statfire       ;if yes, fire at stationary target. Else:
        mov     ts,     @13     ;target speed
        mov     rh,     @6      ;relative heading
        cmp     ts,     0
        jge     !ps
        neg     ts
        add     rh,     128
        and     rh,     255
 !ps
        shr     ts,     6
        shl     ts,     7
        shr     rh,     1
        mov     off,    1028
        add     off,    ts
        add     off,    rh
        err     off
        jmp     !fireadj
 !statfire
        mov     AX,     1       ;
        int     4               ;Overburn= on.
        out     15,     0       ;fire
        out     15,     0       ;fire
        out     15,     0       ;fire
        out     15,     0       ;fire
        mov     AX,     0       ;
        int     4               ;Overburn = off.
        jmp     !lock           ;lock.
!lock
        out     14,     turn    ;turn
        in      7,      BX      ;scan
        out     12,     @3      ;adjust turret
        jmp     !scan           ;and scan.
!checkpos
        mov     wpc,    0
        int     2               ;get x and y co-ordinates.
        cmp     ex,     500
        jls     !wwall          ;west side
        jge     !ewall          ;east side
 !wwall
        cmp     fx,     500
        jle     !wwalln         ;northwest
        jgr     !wwalls         ;southwest
  !wwalln
        cmp     ex,     fx      ;closer to west or north wall?
        jle     !wnq            ;closer to west
        jgr     !nwq            ;closer to north
  !wwalls
        sub     fx,     1000
        neg     fx              ;distance rather than co-ord.
        cmp     ex,     fx      ;closer to west or south wall?
        jle     !wsq            ;closer to west
        jgr     !swq            ;closer to south
 !ewall
        cmp     fx,     500
        jle     !ewalln         ;northeast
        jgr     !ewalls         ;southeast
  !ewalln
        sub     ex,     1000
        neg     ex              ;distance rather than co-ord.
        cmp     ex,     fx      ;closer to east or north wall?
        jle     !enq            ;closer to east
        jgr     !neq            ;closer to north
  !ewalls
        cmp     ex,     fx      ;closer to east or south wall?
        jge     !esq            ;closer to east
        jls     !seq            ;closer to south
!wnq
        mov     ang,    112     ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!nwq
        mov     ang,    80      ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!wsq
        mov     ang,    16      ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!swq
        mov     ang,    48      ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!enq
        mov     ang,    144     ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!neq
        mov     ang,    176     ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!esq
        mov     ang,    240     ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!seq
        mov     ang,    208     ;desired heading
        sub     ang,    @1      ;difference
        out     14,     ang     ;turn to desired heading
        neg     turn
        jmp     !scan
!fireadj                        ;adjusted firing routine.
        out     12,     [off]
        out     15,     0       ;fire w/ new angle.
        out     15,     0       ;fire w/ new angle.
        cmp     @13,    500     ;enemy speed?
        jgr     !lock           ;
        out     15,     0       ;fire w/ new angle.
        out     15,     0
        jmp     !lock

0 comments: