Creating a Ball
Author Message
Creating a Ball

Hello everyone!  Well, I'm kinda stuck drawing a simple ball to the screen!
I'm trying to set it up using the following :

CHECK     DB     "00001110000000111110000011111110001111111110"
DB     "11111111111111111111111111111111101111111110"
DB     "001111111000001111100000001110000" ,NULL

Now, the problem is that when I'm inc the si and check for a Zero or a One,
it seems to always be a one
and prints a Square to the screen.  (Not a circle!)  Any help would be
greatly appreciated!

Obviously kinda new at this... I'm sure I made a simple mistake.  This was
the code I was writing :

;*****************************************************************
;***                                                           ***
;***  Here are some constants to make the code easier to read  ***
;***           Note: all the values are in hex!                ***
;***                                                           ***
;*****************************************************************

CR              EQU     0DH      ;ASCII carriage return
LF              EQU     0AH      ;ASCII line feed
BELL            EQU     07H      ;ASCII bell7
NULL            EQU     00H      ;All strings end with a NULL
TERMINATE       EQU     4CH      ;DOS Interupt 21H function (exit)
TAB             EQU     09H       ;TAB

OLDX     EQU    [DI]     ;Old X (CX) Co-ordinates
OLDY    EQU    [DI + 2]  ;Old Y (DX) Co-ordinates
NEWX       EQU    [DI + 4]  ;NEW X (CX) Co-ordinates
NEWY       EQU    [DI + 6]  ;NEW Y (DX) Co-ordinates

DOSSEG

.MODEL  small  ;
.STACK  512  ;Set the size of the stack segment

;*****************************************************************
;***                                                           ***
;***   This next section is some data we want to dump to the   ***
;***   screen.  The 1's means TO print, 0's mean NOT to print  ***
;***                                                           ***
;*****************************************************************

.DATA

CHECK DB "00001110000000111110000011111110001111111110"
DB "11111111111111111111111111111111101111111110"
DB "001111111000001111100000001110000" ,NULL

;*****************************************************************
;***                                                           ***
;***              Start the Main Body of Code                  ***
;***                                                           ***
;*****************************************************************

.CODE

ORG 100h

MAIN PROC NEAR

XOR Si,Si ;Clears the index

MOV DS,AX ;Transfer Address to Extra Segment Register

MOV AH,0Fh ;Set up for Getting the Graphics Mode
INT 10h  ;
PUSH AX  ;Save Orignial Graphics Mode (AX)
CALL SETGMODE ;Set Graphics Mode

MOV BL,8EH ; Set Ball Colour (The 8th bit sets XOR mode)

MOV CX,200 ;X Co-ordinate
MOV DX,200 ;Y Co-ordinate

mov oldx, cx ;Initialize and Save Old X Co-ordinate
mov oldy, dx ;Initialize and Save Old Y Co-ordinate
mov newx, cx ;Initialize New X Co-ordinate
mov newy, dx ;Initialize New Y Co-ordinate

call DRAWBALL ;Draw the Ball for the First Time
XOR Si,Si ;Clears the index

loop2: mov cx, oldx ;Get Old Co-ordinates for X (CX)
mov dx, oldy ;Get Old Co-ordinates for Y (DX)
CALL DRAWBALL ; erase the ball (XOR it again to clear it)
XOR Si,Si ;Clears the index

mov cx, newx ; get new coords
mov dx, newy
call DRAWBALL ;Draw the ball
XOR Si,Si ;Clears the index

cmp ax,0000 ;ax will be zero if we want to quit (set in KEYBCTRL)
jz quit

mov oldx,cx ;save registers into memory
mov oldy,dx ;save registers into memory

CALL KEYBCTRL ;get new x,y coords from the arrow keys

jmp loop2 ;end of loop

QUIT: POP AX
MOV AH,00H ;restore original graphics mode
INT 10h
MOV AX, 4C00h ;exit
INT 21h

MAIN ENDP

;********************************************

DRAWBALL PROC NEAR

PUSH AX
PUSH CX
mov AL,00h
cool:
CALL DRAWLINE
inc dx  ;
MOV CX,newx
inc AL
cmp AL,0BH ;Sets the Hieght of the Ball
jnz cool

POP CX
POP AX
RET

DRAWBALL ENDP

;********************************************

DRAWLINE PROC NEAR

PUSH AX
PUSH BX
PUSH CX
PUSH DX

MOV AH,0Ch ;Request Pixel Dot
MOV AL,BL ;Set up for Pixel Colour
MOV BL,00H ;Counter for the Length of the Line

LOOP1:
;MOV BH,[SI]
CMP si,00H
JNZ DOT
JZ  NODOT

DOT:
PUSH BX
MOV BH,00
INT 10H
POP  BX
INC Si

INC CX

INC BL
CMP BL,0BH
JNZ LOOP1
JZ  LINEDONE

NODOT:
INC Si
INC CX
INC BL
CMP BL,0BH
JNZ LOOP1
JZ LINEDONE

LINEDONE:
POP DX
POP CX
POP BX
POP AX
RET

DRAWLINE ENDP

;********************************************

SETGMODE PROC NEAR

MOV AH,00H ;Set VGA Graphics Mode
MOV AL,12H ;640 Cols x 480 Rows
INT 10H  ;

MOV AH,0BH ;Request Colour Palette
MOV BH,00H ;Set Page (0)
MOV BL,00H ;Background Colour (Black)
INT 10H  ;

RET

SETGMODE ENDP

;********************************************

KEYBCTRL PROC NEAR
MOV AH,10h
INT 16h  ;get keyboard input
cmp ah, 50h ;if down arrow
jz DOWN
cmp ah,4dh ;if right arrow
jz RIGHT
cmp ah, 4Bh ;if left arrow
jz Left
cmp ah, 48h ;if up arrow
jz UP
cmp ah,01 ; if esc key set ax to be zero for quit
mov ax, 0000
ret
jmp done
ret
ret
up: sub newy,10
ret
left: sub newx,10
ret
DONE:   RET
KEYBCTRL ENDP
END MAIN

Wed, 09 Jan 2002 03:00:00 GMT
Creating a Ball

Quote:
> CHECK     DB     "00001110000000111110000011111110001111111110"
>                    DB     "11111111111111111111111111111111101111111110"
>                    DB     "001111111000001111100000001110000" ,NULL

> Now, the problem is that when I'm inc the si and check for a Zero or a One,
> it seems to always be a one
> and prints a Square to the screen.  (Not a circle!)  Any help would be
> greatly appreciated!

> Obviously kinda new at this... I'm sure I made a simple mistake.  This was
> the code I was writing :

yes, it IS a simple mistakt.
instead of comparing with the VALUE 0, you should compare with the ascii
code of '0', which is not 0 but 48 (or 30h)

Fabian Giesen
ryg/teklords

Wed, 09 Jan 2002 03:00:00 GMT
Creating a Ball
I don't think this should make any difference, but you are zeroing si which
isn't necessarily (but should be in this case) the start of the CHECK array.
Shouldn't you be putting something like:

mov si, offset CHECK

also you have in your drawling procedure, this line:

cmp si, 00h

This is actually comparing the value _of_ si (not the value AT si) to zero,
so this will be not equal all of the time except the first time.

David

Thu, 10 Jan 2002 03:00:00 GMT
Creating a Ball
Now looking at this, and seeing Marcy is right, you could quite easily
compress this by storing it in binary, so your CHECK variable would be one
eighth the size.  This requires a little more code, but if you do it right,
it is possible to bring the overhead down to about 6 or 7 cycles per pixel,
which, in the scheme of things, isn't too bad, considering there is a number
of places in your code where this can be taken back, with interest

David

Thu, 10 Jan 2002 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages