.model  small
        .stack  200h
        .data
px1     dw      0
py1     dw      0
px2     dw      0
py2     dw      0
px      dw      0
py      dw      0
pc      db      15
paddr   dw      0
tx      dw      ?
ty      dw      ?
tmp1    dw      0
tmp2    dw      0
tmp3    dw      0
mytitle db      'Fruity Bucket$'
table1  db      201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187,10,13,'$'
table2  db      186,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,186,10,13,'$'
table3  db      204,205,205,205,205,205,205,205,205,203,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,185,10,13,'$'
table4  db      186,032,032,032,032,032,032,032,032,186,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,186,10,13,'$'
table5  db      204,205,205,205,205,205,205,205,205,202,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,185,10,13,'$'
table6  db      200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188,'$'
table7  db      204,205,205,205,205,205,205,205,205,185,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,186,10,13,'$'
getmaxcolor     db      16
getmaxx dw      320
getmaxy dw      200
maxx    db      40
maxy    db      25
zero    db      33
tmpnum  db      ?
color   db      15
palette dw      0               ; 0-7
maxcolor        db     1               ; 1-32
x       db      ?
y       db      ?
counter dw      8
count   dw      0
speed   db      0
key     db      0
starttime       dw      0
endtime         dw      0
item1x   db      ?
item1y   db      ?
item1type       db      ?
ranweight       db      20
seed     db     100
score   dw      0
scoretitle      db      'SCORE$'
level   db      0
leveltitle      db      'LEVEL$'
itemtype1       dw      0
itemtype2       dw      0
itemtype3       dw      0
itemtype4       dw      0
itemtype5       dw      0
itemtype6       dw      0
itemtype7       dw      0
itemtype8       dw      0
itemtype9       dw      0
itemtype10      dw      0
maxitemtype     db      8
fruittitle      db      'FRUIT$'
wormtitle       db      'WORM$'
soundmode       db      ?
funcline        db      'Esc-Quit F1-Help F2-New F3-High Score$'
name1           db      '01:00:00$'
score1          dw      30000
name2           db      '00:30:00$'
score2          dw      10000
name3           db      '00:15:00$'
score3          dw      1000
name4           db      '00:05:00$'
score4          dw      100
name5           db      '00:00:30$'
score5          dw      10
highscoretitle  db      'H I G H  S C O R E$'
namescoretitle  db      'TIME        SCORE $'
linespace       db      '                             $'
shour           db      0
ehour           db      0
smin            db      0
emin            db      0
ssec            db      0
esec            db      0
colon           db      ':$'
helptitle       db      '             H E L P         $'
helpline1       db      ' FRUIT/WORM SCORE ',179,' LV  SCORE$'
helpline2       db      '             +1   ',179,'  1    10 $'
helpline3       db      '             +2   ',179,'  2    30 $'
helpline4       db      '             +3   ',179,'  3    90 $'
helpline5       db      '             +4   ',179,'  4   300 $'
helpline6       db      '             +5   ',179,'  5   800 $'
helpline7       db      '             -6   ',179,'  6  2000 $'
helpline8       db      '             -7   ',179,'  7  5000 $'
helpline9       db      '             -8   ',179,'  8  9999 $'
helpline10      db      '                  ',179,'  9 20000 $'
helpline11      db      '                  ',179,' 10 40000 $'
helpline12      db      '    E X T R A   S C O R E    $'
helpline13      db      ' Fail Fruit  : -Fruit score  $'
helpline14      db      ' Side Bucket : No Bonus      $'
helpline15      db      ' Center Bucket : +Level Bonus$'
helpline16      db      ' Move : Left - 4 , Right - 8 $'
endtitle        db      'MASM2.0, program by [email protected] version 0.48.1.26. (Sorry about a month Sunami.)         ',10,13,'$'
tablenum        db      '0123456789ABCDEF'
time            db      '00:00:00$'
ten             db      10
sec             db      0
palcolor        db      0
filename        db      0,'fruitbucpic',25 dup(?)
mydata          db      128*16 dup (100)
dataaddr        dw      0
pages   db      0
nextx   db      8
nexty   db      8
nextaddr        dw      64
palx    db      0
paly    db      0
block7  dw      7
block8  dw      8
delaytime       dw      1
swap    db      0

        .code
        mov     ax,@data
        mov     ds,ax
;========================================
main            proc
        call    fileinit

        call    vgamode                 ; mode 13 int 10 func 00
        call    graphinit               ; a000h screen memory
        call    initkeyboard            ; set keyboard rate
        call    draw_mytitle
        call    draw_table              ; draw table
        call    draw_itemtype           ; show how many block drop
        call    draw_score              ; show score

begining:
        xor     ah,ah
        int     16h                     ; readkey
        mov     [key],ah
        cmp     [key],3Ch               ; if key=F2 then funcf2 else continue3
        jne     begining

resetgame:                              ; loop when new game
        mov     [level],0               ; start level
        mov     [itemtype1],0           ; count no. piece drop each game
        mov     [itemtype2],0
        mov     [itemtype3],0
        mov     [itemtype4],0
        mov     [itemtype5],0
        mov     [itemtype6],0
        mov     [itemtype7],0
        mov     [itemtype8],0
        mov     [score],0               ; score

        call    draw_table              ; draw table
        mov     [ranweight],25          ; random(25)
        call    random
        mov     [item1x],ah             ; start block drop x=random(25)+12
        add     [item1x],12
        mov     [item1y],3              ; start block drop y=3
        mov     bl,[maxitemtype]
        mov     [ranweight],bl          ; random(max block type)
        call    random
        mov     [item1type],ah          ; start block type =random(max block type)+1
        add     [item1type],1           ; result = 1 to max block type
        call    draw_itemtype           ; show how many block drop
        mov     [x],25                  ; start bucket position x
        mov     [y],20                  ; start bucket position y
        mov     [count],0               ; initital delay loop
        mov     [key],0                 ; key function
        mov     [speed],50              ; start speed (can adjust for any pc)

        call    timeinit                ; keep start time (still be bug)

redraw_screen:                          ; loop when screen change

;====================== can remove this block if not show ==============
        call    draw_time               ; show timer
        push    dx                      ; keep dx 
        mov     dx,1800h                ; y=18h,x=0
        call    setcursor               ; set cursor position (dx)
        pop     dx                      ; restore dx
        xor     ax,ax                   ; clear ah before use byte to char
        mov     al,[x]                  ; show bucket position x
        call    bytetochar              ; show number(byte) to bcd at cursor position
        push    dx
        mov     dx,1805h                ; y=18h,x=0
        call    setcursor
        pop     dx
        xor     ax,ax
        mov     al,[y]                  ; show bucket position y
        call    bytetochar
        push    dx
        mov     dx,180Ah                ; y=18h,x=ah
        call    setcursor
        pop     dx
        xor     ax,ax
        mov     al,[item1x]             ; show block position x
        call    bytetochar
        push    dx
        mov     dx,180Fh                ; y=18h,x=fh
        call    setcursor
        pop     dx
        xor     ax,ax
        mov     al,[item1y]             ; show block position y
        call    bytetochar
;======================== end block ===============================

        mov     [pc],6                  ; set color(6)
        call    draw_cursor             ; draw background bucket
        mov     [pc],2                  ; set color(2)
        call    draw_cursor2            ; draw foregound bucket
        mov     bl,[item1type]          ; setcolor(itemtype)
        mov     [pc],bl                 ; this is demo use color instead block type
;        call    draw_item               ; show block drop
        mov     [pages],bl
        call    workpixelblock
        call    draw_score              ; show score

wait_for_key:                           ; loop when key change
        inc     [count]                 ; counter
        push    dx
        mov     dx,181fh                ; y=18h,x=1fh
        call    setcursor
        pop     dx
        mov     ax,[count]
        call    wordtochar              ; show number(word) to bcd at cursorposition
        mov     [ranweight],30          ; 
        call    random                  ; random(30) for change seed
        mov     ax,10                   ; calcurate speed
        xor     dx,dx                   ; set dx=0 for mul word
        xor     cx,cx                   ; clear ch
        mov     cl,10
        sub     cl,[level]
        mul     cx
        add     al,[speed]              ; speed=10*(10-lv)+speed
        cmp     [count],ax              ; if count>=speed then dropitem else continue0
        jae     dodropitem              ; can't use jae dropitem because jmp far error when compile
        jmp     continue0
dodropitem:
        jmp     dropitem                ; drop block
continue0:

        xor     ax,ax
        mov     ah,1                    ; not wait for keypress
        int     16h                     ; check for keypress
        jz      wait_for_key            ; if not key repeat wait key       
        xor     ah,ah
        int     16h                     ; readkey
        mov     [key],ah
        cmp     [key],1                 ; if key=esc then exit else continue1
        je      mainexit                ; can't use je exit; error when compile
        jmp     continue1
mainexit:
        jmp     exit
continue1:
        cmp     [key],3Bh               ; if key=F1 then funcf1 else continue2
        je      dofunc_f1               ; can't use je funcf1; error when compile
        jmp     continue2
dofunc_f1:
        jmp     func_f1
continue2:
        cmp     [key],3Ch               ; if key=F2 then funcf2 else continue3
        je      dofunc_f2               ; can't use je funcf2; error when compile
        jmp     continue3
dofunc_f2:
        jmp     func_f2
continue3:
        cmp     [key],3Dh               ; if key=F3 then funcf3 else continue4
        je      dofunc_f3               ; can't use je func3; error when compile
        jmp     continue4
dofunc_f3:
        jmp     func_f3
continue4:
        cmp     [key],4Bh               ; if key=left arrow then cursor_left 
	je	cursor_left
        cmp     [key],4Dh               ; if key=right arrow then cursor_right
	je	cursor_right
        cmp     [key],48h               ; if key=up arrow then cursor_up
	je	cursor_up
        cmp     [key],50h               ; if key=down arrow then cursor_down
	je	cursor_down

        jmp     wait_for_key            ; loop when key not in list

    cursor_left:
        cmp     [x],11                  ; if left is limit then wait_for_key else continue5
        jbe     dowait_for_key          ; can't use jbe wait_for_key; error when compile
        jmp     continue5
dowait_for_key:
        jmp     wait_for_key
continue5:
        call    clear_cursor            ; clear old bucket 
        dec     [x]                     ; x=x-1
        jmp     redraw_screen           ; loop draw screen
    cursor_right:
        cmp     [x],37                  ; if right is limit then wait_for_key else continue6
        jae     dowait_for_key1         ; can't use jae wait_for_key; error when compile
        jmp     continue6       
dowait_for_key1:
        jmp     wait_for_key
continue6:
	call	clear_cursor
        inc     [x]                     ; x=x+1
	jmp	redraw_screen
    cursor_up:
        cmp     [speed],200             ; if speed<200 then speed=speed+10
        ja      maxspeed
        add     [speed],10
maxspeed:
        mov     [key],0                 ; clear key
        jmp     redraw_screen
    cursor_down:
        cmp     [speed],9               ; if speed>9 then speed=speed-10
        jb      lowspeed
        sub     [speed],10
lowspeed:
        mov     [key],0
        jmp     redraw_screen
    func_f1:
        mov     ah,[x]                  ; keep bucket position x,y in ah,al
        mov     al,[y]
        push    ax
        call    draw_help               ; show help
        call    keypress                ; wait for keypress
        call    draw_table              ; draw table again
        call    draw_itemtype           ; draw itemtype again
        pop     ax                      ; restore bucket position x,y in ah,al
        mov     [y],al                  
        mov     [x],ah
        mov     [key],0                 ; clear key
        jmp     redraw_screen
    func_f2:
        call    compare_score           ; check new high score
        call    draw_highscore          ; show high score
        call    keypress                
        call    resetgame               ; reset game
        mov     [key],0                 ; clear key
    func_f3:
        mov     ah,[x]                  ; keep bucket position x,y in ah,al
        mov     al,[y]
        push    ax
        call    draw_highscore          ; show high score
        call    keypress                
        call    draw_table
        call    draw_itemtype
        pop     ax                      ; restore bucket position x,y in ah,al
        mov     [y],al
        mov     [x],ah
        mov     [key],0
        jmp     redraw_screen

dropitem:
        ;====== sound ===========
        in      al,97                   ; get port 97
        mov     [soundmode],al          ; keep soundmode
        or      al,3                    ; open sound
        out     97,al                   ; out port 97
        mov     al,182
        out     67,al                   ; initial frequency port 67

        mov     dx,14h                  ; cal division of frequency
        mov     ax,4f38h
        div     di
        out     66,al                   ; lower byte of frequency on port 66
        mov     al,ah
        out     66,al                   ; higher byte of frequency on port 66

        mov     cx,100                  ; delay loop 100 times
sounddelay:     loop    sounddelay
        mov     al,[soundmode]
        out     97,al
        ;=====  end sound =======

        mov     [count],0               ; clear count
        cmp     [item1y],5              ; case y<5 setcolor(2)
        jb      ctop 
        cmp     [item1y],19             ; case y<19 setcolor(6)
        jb      cmid
        mov     [pc],10                 ; else setcolor(10)
        mov     [pages],13
        jmp     draw_myitem
ctop:   mov     [pc],2
        mov     [pages],11
        jmp     draw_myitem
cmid:   mov     [pc],6
        mov     [pages],12
        jmp     draw_myitem             
draw_myitem:
        call    draw_item

        inc     [item1y]                ; y=y+1
        cmp     [item1y],21             ; if floor position then can't drop else drop
        jb      donotdropitem           ; error when compile
        jmp     continue7
donotdropitem:
        jmp     notdropitem
continue7:
        mov     al,[item1x]             ; check fruit in bucket
        mov     ah,al
        cmp     al,[x]                  ; center
        je      addscore2
        inc     al
        cmp     al,[x]                  ; right
        je      addscore1
        dec     ah
        cmp     ah,[x]                  ; left
        je      addscore1
        cmp     [item1type],5           ; check if worm not in bucket
        ja      addscore0
decscore:                               ; else not in bucket
        xor     bx,bx
        mov     bl,[item1type]
        cmp     bx,[score]              ; if score


Hosted by www.Geocities.ws

1