





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






int 16h @Cls @Setcsrpos,0, .exit main endp
;************************************************* ;Function: drawscreen ;Description: ; This function clears the backbuffer, draws ; the remaining blocks to the backbuffer, ; draws the ball to the backbuffer, draws the ; the paddle to the backbuffer, and then ; finally draws the backbuffer to the screen ;Input: ; None ;Output: ; None ;Return: ; None ;************************************************* drawscreen proc c uses ax bx cx dx invoke clearbuffer,addr backbuff
;draw remaining blocks invoke writebuffer,0,0,addr blockbuff,2000,0FFh, addr backbuff
;draw ball invoke writebuffer,ballx,bally,addr paddlebar, 1, ballcolor, addr backbuff
;draw paddle invoke writebuffer,xpos,ypos,addr paddlebar,paddlelen,0Fh, addr backbuff
;swap buffer call swapbuffer
ret drawscreen endp
checkybrick proc c uses bx cx dx
mov dx, 0 mov ax, VIDCOL mov bx, bally mul bx add ax, ballx shl ax, 1 lea bx, blockbuff add bx, ax mov ax, [bx] cmp ah, 00h jz checkunderpaddle invoke writebuffer, ballx, bally, addr paddlebar, 1, 00h, addr blockbuff inc score mov ax, TRUE jmp continue checkunderpaddle: mov ax, bally inc ax cmp ax, ypos jnz setfalse mov dx, 0 mov ax, VIDCOL mov bx, bally inc bx mul bx add ax, ballx shl ax, 1 lea bx, backbuff add bx, ax mov ax, [bx] cmp ah, 00h jz checkleftpaddle mov ax, TRUE jmp continue checkleftpaddle: mov dx, 0 mov ax, VIDCOL mov bx, bally inc bx mul bx add ax, ballx inc ax shl ax, 1 lea bx, backbuff add bx, ax mov ax, [bx] cmp ah, 00h jz checkrightpaddle mov ax, TRUE jmp continue checkrightpaddle: mov dx, 0 mov ax, VIDCOL mov bx, bally inc bx mul bx
add ax, ballx dec ax shl ax, 1 lea bx, backbuff add bx, ax mov ax, [bx] cmp ah, 00h jz setfalse mov ax, TRUE jmp continue setfalse: mov ax, FALSE continue: ret checkybrick endp
updateball proc c uses ax bx cx dx
cmp moveball, 350 jnz continue mov moveball, 0 updatex: mov ax, ballx add ax, ballvelx mov ballx, ax cmp ax, VIDCOL jb updatey mov ax, - mov bx, ballvelx mov dx, 0 imul bx mov ballvelx, ax updatey: mov ax, bally add ax, ballvely mov bally, ax cmp ax, VIDROW jb adjustygreater mov ax, - mov bx, ballvely mov dx, 0 imul bx mov ballvely, ax adjustygreater: cmp bally, 24 jng adjustylower mov bally, STARTY mov ballx, STARTX mov ballvely, STARTVELY mov ballvelx, STARTVELX jmp continue adjustylower: cmp bally, 0 jge checkycoll mov bally, 0 checkycoll: call checkybrick cmp ax, FALSE jz adjustxgreater mov ax, - mov bx, ballvely mov dx, 0 imul bx mov ballvely, ax jmp continue adjustxgreater: cmp ballx, 79 jng adjustxlower mov ballx, 79 jmp continue adjustxlower: cmp ballx, 0 jge continue mov ballx, 0 continue: inc moveball ret updateball endp
;************************************************* ;Function: clearbuffer ;Description: ; This function sets the contents of a buffer ; to all 0's ;Input: ; buff - address of buffer to clear ;Output: ; buff - cleared buffer ;Return: ; None ;************************************************* clearbuffer proc c uses ax bx cx dx, buff:word mov di, buff ;move address of buffer into di mov cx, 2000 ;mov length of buffer into cx again: mov WORD PTR [di], WORD PTR 0000h;move 00 into location pointed to by di add di, 2 ;increment buffer pointer
mov ypos, 23 ;set ypos to minimum row postiion (max position on screen) noadjust: popf ;restore the flags ret keyread endp
;************************************************* ;Function: writebuffer ;Description: ; This function writes a series of characters ; of arbitrary length and color to a specified ; buffer of length and width no larger than the ; the size of the screen 80x ;Input: ; x - column position to write to ; y - row position to write to ; s - address to character array to write to ; buffer ; a - color attributes to write to buffer ;Output: ; buff - address of buffer to write to ;Return: ; None ;************************************************* writebuffer proc c uses ax bx cx dx, x:word, y:word, s:word, l:word, a:byte, buff:word pushf ;save flags mov si, s ;move address into si mov cx, l ;move length to cx again: mov di, buff ;move address of buffer into di mov ax, VIDCOL ;move buffer width into ax mul y ;multiply ax by row position add ax, x ;add column position to ax shl ax, 1 ;multiply ax by 2 to get offset add di, ax ;add offset to buff address in di cmp a, 0FFh ;comare attribute to 0FFh jnz assigncolor ;if a!=0FFh then jump to label assigncolor mov ax, [si] ;move character in source into ax add si, 2 ;increment source pointer jmp continue ;jump to lable continue assigncolor: mov al, [si] ;move character from source into al mov ah, a ;move attributes into ah inc si ;increment source pointer continue: mov [di], ax ;mov ah,al pair into desitination buffer inc x ;increment column position dec cx ;decrement cx, number of characters left jnz again ;if cx==0, we are done, jump to label again done: popf ;restore flags ret ;return flow of control to caller writebuffer endp
;************************************************* ;Function: blockbuffinit ;Description: ; This function initializes the blocks that ; that will be displayed to the screen ; that are left on the screen ;Input: ; STARTBRICKX (GLOBAL CONST) - starting column ; position of the bricks ; STARTBRICKY (GLOBAL CONST) - starting row ; position of the bricks ; ENDBRICKX (GLOBAL CONST) - the ending column ; position of the bricks ; ENDBRICKY (GLOBAL CONST) - the ending row ; position of the bricks ;Output: ; None ;Return: ; None ;************************************************* blockbuffinit proc c uses ax bx cx dx local lx:word, ly:word, k:byte
pushf ;save flags mov ax, 00DBh mov ly, STARTBRICKY mov lx, STARTBRICKX mov k, 6 col: invoke writebuffer, lx,ly,addr paddlebar,1,k,addr blockbuff inc k mov al, k mov ah, 0 mov bx, 16 mov dx, 0 div bx add dx, 3 mov k, dl
inc lx cmp lx, ENDBRICKX jle col row:
inc ly mov lx, STARTBRICKX cmp ly, ENDBRICKY jbe col
mov ax, ENDBRICKX sub ax, STARTBRICKX mov bx, ENDBRICKY sub bx, STARTBRICKY mul bx mov blockcount, ax popf ;restore flags ret blockbuffinit endp
;************************************************* ;Function: checkblockcount ;Description: ; This function counts the number of blocks ; that are left on the screen ;Input: ; blockcount (GLOBAL) - the number of blocks ; left on the screen ;Output: ; blockcount (GLOBAL) - the number of blocks ; left on the screen ;Return: ; None ;************************************************* checkblockcount proc c uses ax bx cx dx pushf ;save flags mov blockcount, 0 ;clear blockcount variable lea di, blockbuff ;load address of blockbuff mov cx, 2000 ;move 2000 into cx, the size of blockbuff again: cmp cx, 0 ;compare cx to 0 jz done ;if cx==0, then we are done checking mov ax, [di] ;move character pointed to by di into ax add di, 2 ;increment di by 2 bytes dec cx ;decrement cx, number of buffer spaces to check cmp ah, 00h ;compare ah, to color black jz again ;if ah==0 then check next block inc blockcount ;if ah!=0 then found a block, increment blockcount jmp again ;jump to label again, start process again done: popf ;restore flags ret ;return flow of control to caller checkblockcount endp
;************************************************* ;Function: putchar ;Description: ; This function displays a character to the ; string, at an arbitrary postion, with any ; color attributes ;Input: ; x - column position to begin writing ; character to ; y - row position to begin writing character ; to ; k - character to write to screen ; a - color attributes of string ;Output: ; None ;Return: ; None ;************************************************* putchar proc c uses ax di es, x:word, y:word, k:byte, a:byte pushf ;store flags mov di, vidseg ;move video segment into di mov es, di ;move di into es (video segment) mov ax, vidcol ;move ax, the number of video columns mul y ;multiply ax by the number row location add ax, x ;add the column offset shl ax, 1 ;multiply by 2 to get correct byte to write to mov di, ax ;move segment offset into di mov al, k ;move display character to al mov ah, a ;move display character attribute into ah (color, etc) mov es:[di], ax ;write character to vid memory es:di popf ;restore flags ret ;return flow of control to caller putchar endp
;************************************************* ;Function: displaystring ;Description: ; This function displays a string of arbitrary ; length to the screen. It will do thia at any ; position with any color. This function ; understands CR, LF and will skip to the next ; line (beginning at x position) when encountered ;Input: ; x - column position to begin writing string to ; y - row position to begin writing string to ; s - address of string to write out to screen ; l - length of string to write out to screen ; a - color attributes of string