Following the successful review of my implementation of Bresenham's Line Algorithm, I've been asked to upload the full implementation of my project which creates a small animation of shapes moving around the screen and changing colours for a full review.
Note that this code hasn't been edited to incorporate the comments made in the last review and as such I don't expect the line algorithm to be reviewed again. (Because of this it still lacks comments and so will still be difficult to review).
Here's a screenshot of the working program, and yes, it looks terrible when a screenshot is taken partway through the drawing.
;=========================================================================================================
; MACROS
;=========================================================================================================
;=========================================================================================================
; BRESENHAM LINE ALGORITHM (lx1,ly1)-(lx2,ly2)
;=========================================================================================================
line macro lx1, ly1, lx2, ly2
local ldxsetup1, ldxsetup2, ldysetup1, ldysetup2
local lxisetup1, lxisetup2, lxisetupexit, lyisetup1, lyisetup2, lyisetupexit
local numsetup1, numsetup2, numsetupexit
local lloopstart, lloopif, lloopifexit, lloopend
pushall
mov ax, lx2
sub ax, lx1
cmp ax, 0
jge ldxsetup2
ldxsetup1:
mov bx, -1
mul bx
ldxsetup2:
mov ldx, ax
mov ax, ly2
sub ax, ly1
cmp ax, 0
jge ldysetup2
ldysetup1:
mov bx, -1
mul bx
ldysetup2:
mov ldy, ax
mov ax, lx1
mov lx, ax
mov ax, ly1
mov ly, ax
mov ax, lx2
cmp ax, lx1
jge lxisetup1
jmp lxisetup2
lxisetup1:
mov ax, 1
jmp lxisetupexit
lxisetup2:
mov ax, -1
lxisetupexit:
mov lxi1, ax
mov lxi2, ax
mov ax, ly2
cmp ax, ly1
jge lyisetup1
jmp lyisetup2
lyisetup1:
mov ax, 1
jmp lyisetupexit
lyisetup2:
mov ax, -1
lyisetupexit:
mov lyi1, ax
mov lyi2, ax
mov ax, ldx
mov bx, ldy
cmp ax, bx
jge numsetup1
jmp numsetup2
numsetup1:
mov ax, 0
mov lxi1, ax
mov lyi2, ax
mov ax, ldx
mov lden, ax
mov lnumpix, ax
shr ax, 1
mov lnum, ax
mov ax, ldy
mov lnumadd, ax
jmp numsetupexit
numsetup2:
mov ax, 0
mov lxi2, ax
mov lyi1, ax
mov ax, ldy
mov lden, ax
mov lnumpix, ax
shr ax, 1
mov lnum, ax
mov ax, ldx
mov lnumadd, ax
numsetupexit:
mov ax, lnum
mov dx, 0
lloopstart:
cmp dx, lnumpix
jg lloopend
plot lx, ly
add ax, lnumadd
cmp ax, lden
jge lloopif
jmp lloopifexit
lloopif:
sub ax, lden
mov bx, lx
add bx, lxi1
mov lx, bx
mov bx, ly
add bx, lyi1
mov ly, bx
lloopifexit:
mov bx, lx
add bx, lxi2
mov lx, bx
mov bx, ly
add bx, lyi2
mov ly, bx
inc dx
jmp lloopstart
lloopend:
popall
endm
;=========================================================================================================
;=========================================================================================================
; DRAW TRIANGLE BOTTOM LEFT POINT AT (tx,ty) OF HEIGHT th AND WIDTH tw
;=========================================================================================================
triangle macro tx, ty, tw, th
pushall
mov ax, tx
add ax, tw
mov tx2,ax
mov bx, tw
shr bx, 1
add bx, tx
mov tx3, bx
mov cx, ty
sub cx, th
mov ty3, cx
line tx, ty, tx2, ty
line tx2, ty, tx3, ty3
line tx3, ty3, tx, ty
popall
endm
;=========================================================================================================
;=========================================================================================================
; DRAW SHAPE
;=========================================================================================================
draw macro
pushall
mov ax, currentshape
cmp currentshape, 1
je draw1
jmp draw2
draw1:
mov ax, 0
add ax, currentx
mov val1, ax
mov ax, 50
add ax, currenty
mov val2, ax
mov ax, 50
mov val3, ax
mov ax, 43
mov val4, ax
triangle val1,val2,val3,val4
mov ax, 25
add ax, currentx
mov val1, ax
mov ax, 93
add ax, currenty
mov val2, ax
triangle val1,val2,val3,val4
mov ax, 50
add ax, currentx
mov val1, ax
mov ax, 50
add ax, currenty
mov val2, ax
triangle val1,val2,val3,val4
mov ax, 25
add ax, currentx
mov val1, ax
mov ax, 7
add ax, currenty
mov val2, ax
mov ax, -43
mov val4, ax
triangle val1,val2,val3,val4
mov ax, 0
add ax, currentx
mov val1, ax
mov ax, 50
add ax, currenty
mov val2, ax
mov ax, -43
mov val4, ax
triangle val1,val2,val3,val4
mov ax, 50
add ax, currentx
mov val1, ax
mov ax, 50
add ax, currenty
mov val2, ax
mov ax, -43
mov val4, ax
triangle val1,val2,val3,val4
jmp drawend
draw2:
mov ax, 50
add ax, currentx
mov val1, ax
mov ax, 0
add ax, currenty
mov val2, ax
mov ax, 68
add ax, currentx
mov val3, ax
mov ax, 3
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 79
add ax, currentx
mov val3, ax
mov ax, 9
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 88
add ax, currentx
mov val3, ax
mov ax, 18
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 94
add ax, currentx
mov val3, ax
mov ax, 26
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 98
add ax, currentx
mov val3, ax
mov ax, 38
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 100
add ax, currentx
mov val3, ax
mov ax, 50
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 98
add ax, currentx
mov val3, ax
mov ax, 62
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 94
add ax, currentx
mov val3, ax
mov ax, 74
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 88
add ax, currentx
mov val3, ax
mov ax, 82
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 79
add ax, currentx
mov val3, ax
mov ax, 91
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 68
add ax, currentx
mov val3, ax
mov ax, 97
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 50
add ax, currentx
mov val3, ax
mov ax, 100
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 32
add ax, currentx
mov val3, ax
mov ax, 97
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 21
add ax, currentx
mov val3, ax
mov ax, 91
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 12
add ax, currentx
mov val3, ax
mov ax, 82
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 6
add ax, currentx
mov val3, ax
mov ax, 74
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 2
add ax, currentx
mov val3, ax
mov ax, 62
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 0
add ax, currentx
mov val3, ax
mov ax, 50
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 2
add ax, currentx
mov val3, ax
mov ax, 38
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 6
add ax, currentx
mov val3, ax
mov ax, 26
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 12
add ax, currentx
mov val3, ax
mov ax, 18
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 21
add ax, currentx
mov val3, ax
mov ax, 9
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 32
add ax, currentx
mov val3, ax
mov ax, 3
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
mov ax, val3
mov val1, ax
mov ax, val4
mov val2, ax
mov ax, 50
add ax, currentx
mov val3, ax
mov ax, 0
add ax, currenty
mov val4, ax
line val1,val2,val3,val4
drawend:
popall
endm
;=========================================================================================================
;=========================================================================================================
; PLOT POINT (px,py)
;=========================================================================================================
plot macro px, py
pushall
mov ax, py
mov bx, 320
mul bx
add ax, px
mov di, ax
mov al, colour
mov es:[di],al
popall
endm
;=========================================================================================================
;=========================================================================================================
; CLEAR SCREEN
;=========================================================================================================
cls macro
pushall
mov ah, 07h
mov al, 00h
mov bh, 00h
mov cx, 00h
mov dx, 1827h
int 10h
popall
endm
;=========================================================================================================
;=========================================================================================================
; PUSH ALL DATA TO STACK
;=========================================================================================================
pushall macro
push ax
push bx
push cx
push dx
endm
;=========================================================================================================
;=========================================================================================================
; POP ALL DATA FROM STACK
;=========================================================================================================
popall macro
pop dx
pop cx
pop bx
pop ax
endm
;=========================================================================================================
;=========================================================================================================
;=========================================================================================================
; SETUP
;=========================================================================================================
.model small
.stack 256
;=========================================================================================================
;=========================================================================================================
; VARIABLES
;=========================================================================================================
.data
;draw line variables
ldx dw 0
ldy dw 0
lx dw 0
ly dw 0
lxi1 dw 0
lxi2 dw 0
lyi1 dw 0
lyi2 dw 0
lden dw 0
lnum dw 0
lnumadd dw 0
lnumpix dw 0
;draw triangle variables
tx2 dw 0
tx3 dw 0
ty3 dw 0
;main program variables
startaddr dw 0a000h
colour db 4
currentx dw 0
currenty dw 0
currentshape dw 0
changeshape dw 0
val1 dw 0
val2 dw 0
val3 dw 0
val4 dw 0
dir dw 0
;=========================================================================================================
;=========================================================================================================
; PROGRAM START
;=========================================================================================================
.code
start:
mov ax, @data
mov ds, ax
mov ah, 00h
mov al, 13h
int 10h
mov es, startaddr
;=========================================================================================================
;=========================================================================================================
; MAIN PROGRAM
;=========================================================================================================
mov ax, 10
mov currentx, ax
mov ax, 10
mov currenty, ax
mov ax, 2
mov currentshape, ax
mov ax, 0
mov changeshape, ax
mainloop:
mov ax, dir
cmp ax, 1
je dircheck1
cmp ax, 2
je dircheck2
cmp ax,3
je dircheck3
jmp dircheck4
dircheck1:
mov ax, 1
add currentx, ax
mov ax, currentx
cmp ax, 210
jle dircheckend
mov ax, 2
mov dir, ax
mov al, colour
inc al
mov colour, al
jmp dircheckend
dircheck2:
mov ax, 1
add currenty, ax
mov ax, currenty
cmp ax, 90
jle dircheckend
mov ax, 3
mov dir, ax
mov al, colour
inc al
mov colour, al
mov ax, 1
mov changeshape, ax
jmp dircheckend
dircheck3:
mov ax, -1
add currentx, ax
mov ax, currentx
cmp ax, 10
jge dircheckend
mov ax, 4
mov dir, ax
mov al, colour
inc al
mov colour, al
jmp dircheckend
dircheck4:
mov ax, -1
add currenty, ax
mov ax, currenty
cmp ax, 10
jge dircheckend
mov ax, 1
mov dir, ax
mov al, colour
inc al
mov colour, al
mov ax, 1
mov changeshape, ax
jmp dircheckend
dircheckend:
mov ax, changeshape
cmp ax, 1
jne shapechangeend
mov ax, 0
mov changeshape, ax
mov ax, currentshape
inc ax
mov currentshape, ax
cmp ax, 3
jne shapechangeend
mov ax, 1
mov currentshape, ax
shapechangeend:
cls
draw
mov ah, 01h
int 16h
jnz finish
jmp mainloop
;=========================================================================================================
;=========================================================================================================
; PROGRAM END
;=========================================================================================================
finish:
mov ah, 00h
mov al, 03h
int 10h
mov ah,04ch
mov al,00h
int 21h
end start
;=========================================================================================================