From dasw9801@sparky.cs.nyu.edu Wed Dec  4 16:44 EST 1996
Return-Path: <dasw9801@sparky.cs.nyu.edu>
Received: from sparky.cs.nyu.edu by jinai.cs.nyu.edu (5.0/1.20)
	id AA23635; Wed, 4 Dec 96 16:44:13 EST
Received: from localhost by sparky.cs.nyu.edu (SMI-8.6/1.20)
	id QAA27049; Wed, 4 Dec 1996 16:38:09 -0500
Date: Wed, 4 Dec 1996 16:38:09 -0500 (EST)
From: "Susheel M. Daswani" <dasw9801@sparky.cs.nyu.edu>
To: yap@jinai.cs.nyu.edu
Subject: HELP
Message-Id: <Pine.GSO.3.92.961204163530.26890A-100000@sparky.cs.nyu.edu>
Mime-Version: 1.0
X-Lines: 498
Status: RO
Content-Type: TEXT/PLAIN; charset="US-ASCII"
Content-Length: 10645


Prof. Yap,

I have attached my frogger game at the end of this mail.  I mentioned in
class that it is running kind of slow -- please compile it on your
computer and check it out to see if you know why it is going so slow on my
computer.  Not really slow, but pretty slow.  I would really appreciate
the help.  If you can't find the problem, would this speed be acceptable
(seeing that we don't know what the problem is??)  Thanks.  --  Susheel

-----------------------------------------------------------------------

TITLE Frogger: Frogger game
.MODEL small


DRAW_VERT_LINE   MACRO   Begin,End,Row,COLOR ;actually draws a horiz line
        LOCAL L1
;draws a line in row X from column Begin to column End
        PUSH cx
        PUSH dx
        PUSH bx
        PUSH ax
        MOV ah,12       ;draw pixel
        MOV al,COLOR    ;any color specified
        MOV cx,Begin    ;column Begin
        MOV dx,Row        ;row X
L1:     INT 10h
        MOV ah,12
        INC cx        ;next column
        CMP cx,END    ;beyond column END
        JL L1
        POP ax
        POP bx
        POP dx
        POP cx
        ENDM



DRAW_CAR       MACRO   Row,Column
        LOCAL L1
;draw a car at Row, Column
;the car will span 15 spaces down.  Giving different columns will
;simulate motion.  Uses DRAW_VERT_LINE macro
        PUSH cx
        PUSH ax
        PUSH dx
        PUSH bx         ;save regs
;put column in bx,row in dx, and use draw macro to make car, which is just a
;rectangle
        MOV bx,Column
        ADD bx,30       ;where to stop drawing
        MOV cx,15
        MOV dx,Row       ;rows

        L1:
            DRAW_VERT_LINE Column,bx,dx,4       ;red
            INC dx
            LOOP L1

        POP bx
        POP dx
        POP ax
        POP cx
        ENDM



DRAW_TRUCK       MACRO   Row,Column
        LOCAL L1,CADDY,BACK_TO
;draw a truck spaced at Row, Column
;the truck will span 20 spaces down.  Giving different columns will
;simulate motion.  Uses DRAW_VERT_LINE macro
        PUSH cx
        PUSH ax
        PUSH dx
        PUSH bx         ;save regs
;through the rows (20) and inner loop draws in appropriate columns
        MOV bx,Column
        ADD bx,45       ;where to stop drawing caddy of truck
        MOV cx,20        ;first draw 5 short lines, then 10 longer, then 5 short
        MOV dx,Row       ;rows

        L1:
        ;if 5 < cx < 15
            CMP cx,4
            JL CADDY
            CMP cx,17  ;if cx is in between  5 and 15 then
            JG CADDY
        ;then
            PUSH bx
            ADD bx,15

            DRAW_VERT_LINE Column,bx,dx,100       ;red

            POP bx

            JMP BACK_TO

        CADDY:

            DRAW_VERT_LINE Column,bx,dx,100       ;red

        BACK_TO:
            INC dx
            LOOP L1

        POP bx
        POP dx
        POP ax
        POP cx
        ENDM



.STACK 200h
.DATA
;this array has beginning of the car positions on track 1 and 3
  CAR_POS       DW      0,80,160,240,40,120,200,280
;this array has truck position for track 2
  TRUCK_POS     DW      20,130,240
;snake array of where snakes are
  SNAKE_POS     DW      10,90,170,250,30,110,190,270
;alligator array has alligators positions
  ALLIGATOR_POS DW      0,110,220
;TITLE and instructions

  TITLE1         DB      "                                  FROGGER",13,10,"$"
  MSG           DB      " This is kind of a frogger game.  You can go in the water with no problem",13,10,"$"
  MSG1          DB      " and the road, but don't touch the green alligator mouth, magenta snake, ",13,10,"$"
  MSG2          DB      " red car or white truck.  you can go up, left, or right.  GOOD LUCK. -- SMD",13,10,"$"
  CTRLLF        DB      13,10,"$"
.CODE



BACKGROUND PROC
;set background as the following:
;                       NORTH POND GOAL  -- 15 rows (0-14)
;                            STREET      -- 76 rows (15-90)
;                           REST AREA    -- 19 rows (91-109)
;                           SOUTH POND   -- 75 rows (110-174)
;                       SOUTH POND COAST -- 15 rows (175-199)
;                                         ----------
;                                          200 rows

;save registers
        PUSH ax
        PUSH dx
        PUSH bx
        PUSH cx
;draw North Pond
  MOV cx,15
  MOV dx,0    ;starts at row 0

  NORTH_POND:

        DRAW_VERT_LINE 0,320,dx,6   ;full line, row dx, brown
        INC dx
        LOOP NORTH_POND

  ;for the street, shall put white lines to  distinguish lanes
  MOV cx,76
  MOV dx,15     ;starts at row 15

  STREET:

        CMP dx,15
        JE DRAW_WHITE
        CMP dx,40
        JE DRAW_WHITE
        CMP dx,65
        JE DRAW_WHITE
        CMP dx,90
        JE DRAW_WHITE
;else
        DRAW_VERT_LINE 0,320,dx,8   ;full line,row dx,gray
        JMP BACKTO

  DRAW_WHITE:

        DRAW_VERT_LINE 0,320,dx,15  ;full line, row dx,intense white

  BACKTO:

        INC dx

        LOOP STREET


  MOV cx,20
  MOV dx,91    ;starts at row 90

  REST_AREA:

        DRAW_VERT_LINE 0,320,dx,10  ;full line, row dx, light greeen
        INC dx
        LOOP REST_AREA

  MOV cx,75
  MOV dx,110    ;starts at row 110

  SOUTH_POND:

        DRAW_VERT_LINE 0,320,dx,1   ;full line, row dx, blue
        INC dx
        LOOP SOUTH_POND

  MOV cx,15
  MOV dx,185

  SOUTH_POND_COAST:

        DRAW_VERT_LINE 0,320,dx,6   ;full line, row dx,brown
        INC dx
        LOOP SOUTH_POND_COAST

;restore registers
        POP cx
        POP bx
        POP dx
        POP ax
        RET

BACKGROUND ENDP



CARS_TRUCKS PROC
;draw cars and trucks moving around.  makes extensive use of draw_car and
;draw_truck macro
        PUSH ax
        PUSH bx
        PUSH cx
        PUSH dx ;save regs

;display cars and trucks
        DRAW_CAR 20,CAR_POS
        DRAW_CAR 20,CAR_POS+2
        DRAW_CAR 20,CAR_POS+4
        DRAW_CAR 20,CAR_POS+6
        DRAW_CAR 70,CAR_POS+8
        DRAW_CAR 70,CAR_POS+10
        DRAW_CAR 70,CAR_POS+12
        DRAW_CAR 70,CAR_POS+14
        DRAW_TRUCK 42,TRUCK_POS
        DRAW_TRUCK 42,TRUCK_POS+2
        DRAW_TRUCK 42,TRUCK_POS+4

;restore regs
        POP dx
        POP cx
        POP bx
        POP ax

        RET

CARS_TRUCKS ENDP



DRAW_SNAKE     MACRO   Row,Column
        LOCAL L1
;this macro works conceptually the same as draw cars and draw trucks macros
;snake is just a long line of two strips of magenta.

;save regs
        PUSH ax
        PUSH bx
        PUSH cx
        PUSH dx
;setup registers
        MOV bx,Column
        ADD bx,40       ;snake is 40 long
        MOV cx,2        ;only 2 lines needed
        MOV dx,Row

        L1:
                DRAW_VERT_LINE Column,bx,dx,5   ;magenta
                INC dx
                LOOP L1

;restore regs
        POP dx
        POP cx
        POP bx
        POP ax
        ENDM



DRAW_ALLIGATOR     MACRO   Row,Column
        LOCAL L1,MOUTH,BODY,TAIL,SWITCH,ORIG
;this macro works conceptually the same as draw cars and draw trucks macros
;snake is just a long line of two strips of magenta.

;save regs
        PUSH ax
        PUSH bx
        PUSH cx
        PUSH dx
;setup registers
        MOV bx,Column
        ADD bx,45       ;alligator body is 40 long
        MOV cx,20       ;only 20 lines needed
        MOV dx,Row

        L1:
        ;if cx < 6 or > 14
        CMP cx,13
        JG TAIL
        CMP cx,6
        JL TAIL
        ;then draw body

        ORIG:
                DRAW_VERT_LINE Column,bx,dx,2   ;green
                JMP BODY

        TAIL:
                PUSH Column
                PUSH bx
                ADD Column,25
                ADD bx,25

                DRAW_VERT_LINE Column,bx,dx,2

                POP bx
                POP Column

        BODY:
                INC dx
                LOOP L1
;restore regs
        POP dx
        POP cx
        POP bx
        POP ax
        ENDM



SNAKES_ALLIGATORS PROC
;draws snakes and alligators in appropriate waterway.  uses Draw_snake and
;draw alligator
        PUSH ax
        PUSH bx
        PUSH cx
        PUSH dx ;save regs
;display snakes and alligators

        DRAW_SNAKE   122,SNAKE_POS
        DRAW_SNAKE   122,SNAKE_POS+2
        DRAW_SNAKE   122,SNAKE_POS+4
        DRAW_SNAKE   122,SNAKE_POS+6
        DRAW_SNAKE   168,SNAKE_POS+8
        DRAW_SNAKE   168,SNAKE_POS+10
        DRAW_SNAKE   168,SNAKE_POS+12
        DRAW_SNAKE   168,SNAKE_POS+14
        DRAW_ALLIGATOR 137,ALLIGATOR_POS
        DRAW_ALLIGATOR 137,ALLIGATOR_POS+2
        DRAW_ALLIGATOR 137,ALLIGATOR_POS+4

;restore regs
        POP dx
        POP cx
        POP bx
        POP ax
        RET
SNAKES_ALLIGATORS ENDP



MAIN PROC
;intialize ds
  MOV ax,@data
  MOV ds,ax
;dispaly initial prompt
  MOV ah,9
  LEA dx,CTRLLF
  MOV cx,10

  LOOP1:
        INT 21h
        LOOP LOOP1

  LEA dx,TITLE1
  INT 21h
  LEA dx,MSG
  INT 21h
  LEA dx,MSG1
  INT 21h
  LEA dx,MSG2
  INT 21h
  LEA dx,CTRLLF
  MOV cx,10

  LOOP2:
        INT 21h
        LOOP LOOP2
;wait for keyboard
  MOV ah,0
  INT 16h
;set mode to 13, 320 * 200, 256 colors
  MOV ah,0
  MOV al,13h
  INT 10h
;save carpos's
  MOV cx,8
  MOV bx,0
  SAVE_VARS:
    PUSH CAR_POS+bx
    PUSH SNAKE_POS+bx
    LOOP SAVE_VARS

    PUSH TRUCK_POS
    PUSH TRUCK_POS+2
    PUSH TRUCK_POS+4
    PUSH ALLIGATOR_POS
    PUSH ALLIGATOR_POS+2
    PUSH ALLIGATOR_POS+4

;need to setup background and obstacles
  MOV cx,25

  GAME:

    CALL BACKGROUND
    CALL CARS_TRUCKS
    CALL SNAKES_ALLIGATORS

    PUSH cx
    PUSH bx
    MOV cx,4
    MOV bx,8

    INCREMENT1:
        ADD CAR_POS+bx,4       ;increment car and truck positions
        ADD SNAKE_POS+bx,8      ;increment snake position
        ADD bx,2                ;track 3 moves at 4
        LOOP INCREMENT1

    ADD TRUCK_POS,2
    ADD TRUCK_POS+2,2           ;trucks moves slow at 2
    ADD TRUCK_POS+4,2
    ADD ALLIGATOR_POS,3
    ADD ALLIGATOR_POS+2,3       ;alligator moves pretty slow
    ADD ALLIGATOR_POS+4,3

    MOV cx,4
    MOV bx,0
    INCREMENT:                  ;increment car and truck positions
        ADD CAR_POS+bx,6        ;track 1 moves fastest at 6
        ADD SNAKE_POS+bx,10      ;move snakes
        ADD bx,2
        LOOP INCREMENT

     POP bx
     POP cx

  LOOP GAME

;restore alligatorpos and truckpos
  POP ALLIGATOR_POS+4
  POP ALLIGATOR_POS+2
  POP ALLIGATOR_POS
  POP TRUCK_POS+4
  POP TRUCK_POS+2
  POP TRUCK_POS

;restore carpos's
  MOV cx,8
  MOV bx,0
  RESTORE_VARS:
    POP SNAKE_POS+bx
    POP CAR_POS+bx
    LOOP RESTORE_VARS

DRAW_TRUCK 42,0

  MOV ah,0
  INT 16h
  MOV al,3
  INT 10h

;set to text mode
  MOV ax,3      ;select mode 3,text mode
  INT 10h

;dos exit
  MOV ah,76
  INT 21h
MAIN ENDP
        END MAIN




