Added comments to stage 5
This commit is contained in:
@ -596,15 +596,15 @@ arr_add_point_setup:
|
|||||||
addw $2, %si # Otherwise move the array to the first data position
|
addw $2, %si # Otherwise move the array to the first data position
|
||||||
|
|
||||||
arr_add_point_start:
|
arr_add_point_start:
|
||||||
cmpw $0x7f7f, (%si) # Check if the current
|
cmpw $0x7f7f, (%si) # Check if the current index has not been written to
|
||||||
jne arr_add_point_move_addr
|
jne arr_add_point_move_addr # If not move to the next for checking
|
||||||
movw %cx, (%si)
|
movw %cx, (%si) # Add the X and Y values to the array at the current index
|
||||||
movw %dx, 2(%si)
|
movw %dx, 2(%si) # and the next index
|
||||||
jmp arr_add_point_end
|
jmp arr_add_point_end
|
||||||
|
|
||||||
arr_add_point_move_addr:
|
arr_add_point_move_addr:
|
||||||
addw $4, %si
|
addw $4, %si # Move the index to the next item
|
||||||
cmpw $0x7fff, (%si)
|
cmpw $0x7fff, (%si) # Check if we are at the end of the allocated array size
|
||||||
jne arr_add_point_start
|
jne arr_add_point_start
|
||||||
|
|
||||||
arr_add_point_end:
|
arr_add_point_end:
|
||||||
@ -638,12 +638,12 @@ arr_dump:
|
|||||||
pushw %di
|
pushw %di
|
||||||
|
|
||||||
arr_dump_setup:
|
arr_dump_setup:
|
||||||
movw dumpptr(%bp), %si
|
movw dumpptr(%bp), %si # Load the memory address of the array given
|
||||||
addw dumpstart(%bp), %si
|
addw dumpstart(%bp), %si # Add any offset given by the user
|
||||||
movw dumplen(%bp), %cx
|
movw dumplen(%bp), %cx # Set cx to the limit given for the loop
|
||||||
|
|
||||||
arr_dump_loop:
|
arr_dump_loop:
|
||||||
movw (%si), %bx
|
movw (%si), %bx # This just prints the word at the given point then loops
|
||||||
call cons_write_hex
|
call cons_write_hex
|
||||||
call cons_write_crlf
|
call cons_write_crlf
|
||||||
add $2, %si
|
add $2, %si
|
||||||
@ -705,7 +705,7 @@ arr_clear_loop_end:
|
|||||||
popw %bp
|
popw %bp
|
||||||
ret $4
|
ret $4
|
||||||
|
|
||||||
# Draw Polygon function DrawPolygon(ptr polygonarray (2), short polygoncolor(4)...)
|
# Draw Polygon function DrawPolygon(ptr polygonarray (4), int polygonoffy (6), int polygonoffx (8), short polygoncolor (10))
|
||||||
# Accepts the address for the array and a color for the lines
|
# Accepts the address for the array and a color for the lines
|
||||||
# Define parameter address positions in stack
|
# Define parameter address positions in stack
|
||||||
#define polygoncolor 10
|
#define polygoncolor 10
|
||||||
@ -715,8 +715,7 @@ arr_clear_loop_end:
|
|||||||
|
|
||||||
cons_draw_polygon:
|
cons_draw_polygon:
|
||||||
pushw %bp
|
pushw %bp
|
||||||
movw %sp, %bp
|
movw %sp, %bp
|
||||||
#subw $20, %sp # Make room for our local variables in the stack
|
|
||||||
|
|
||||||
# Store existing register values to the stack so we can restore later
|
# Store existing register values to the stack so we can restore later
|
||||||
pushw %ax
|
pushw %ax
|
||||||
@ -727,48 +726,48 @@ cons_draw_polygon:
|
|||||||
pushw %di
|
pushw %di
|
||||||
|
|
||||||
cons_draw_polygon_setup:
|
cons_draw_polygon_setup:
|
||||||
movw polygonarray(%bp), %si
|
movw polygonarray(%bp), %si # Load the arrays memory address into si
|
||||||
cmpw $0x7fff, (%si) # Check if the user has pointed to an initialized array
|
cmpw $0x7fff, (%si) # Check if the user has pointed to an initialized array
|
||||||
jne cons_polygon_loop_end # If not end the function
|
jne cons_polygon_loop_end # If not end the function
|
||||||
addw $2, %si # Otherwise move the array to the first data position
|
addw $2, %si # Otherwise move the array to the first data position
|
||||||
|
|
||||||
cons_draw_polygon_loop_next:
|
cons_draw_polygon_loop_next:
|
||||||
cmpw $0x7f7f, (%si)
|
cmpw $0x7f7f, (%si) # Check if the current array item is not "empty"
|
||||||
je cons_polygon_loop_end
|
je cons_polygon_loop_end # if so skip to the end of the function
|
||||||
cmpw $0x7fff, (%si)
|
cmpw $0x7fff, (%si) # also check if we've hit the end of the array
|
||||||
je cons_polygon_loop_end
|
je cons_polygon_loop_end
|
||||||
|
|
||||||
cons_polygon_loop_map_xy0:
|
cons_polygon_loop_map_xy0:
|
||||||
movw (%si), %ax # Move x0 and y0 into ax and bx
|
movw (%si), %ax # Move x0 and y0 into ax and bx
|
||||||
movw 2(%si), %bx
|
movw 2(%si), %bx
|
||||||
cmpw $0x7f7f, 4(%si)
|
cmpw $0x7f7f, 4(%si) # Check if the x1 and y1 values exist
|
||||||
je cons_polygon_loop_map_end
|
je cons_polygon_loop_map_end # otherwise we jump to map end and use the first 2 array coords
|
||||||
cmpw $0x7fff, 4(%si)
|
cmpw $0x7fff, 4(%si)
|
||||||
je cons_polygon_loop_map_end
|
je cons_polygon_loop_map_end
|
||||||
movw 4(%si), %cx
|
movw 4(%si), %cx # If not set x1 and y1 values
|
||||||
movw 6(%si), %dx
|
movw 6(%si), %dx
|
||||||
jmp cons_polygon_loop_draw_line
|
jmp cons_polygon_loop_draw_line
|
||||||
|
|
||||||
cons_polygon_loop_map_end:
|
cons_polygon_loop_map_end:
|
||||||
movw polygonarray(%bp), %di
|
movw polygonarray(%bp), %di # Set the Array address to di
|
||||||
movw 2(%di), %cx
|
movw 2(%di), %cx # Jump the first word and move the next 2 into x1 and y1
|
||||||
movw 4(%di), %dx
|
movw 4(%di), %dx
|
||||||
|
|
||||||
cons_polygon_loop_draw_line:
|
cons_polygon_loop_draw_line:
|
||||||
addw polygonoffx(%bp), %ax
|
addw polygonoffx(%bp), %ax # Add the x and y offsets to each coordinate
|
||||||
addw polygonoffx(%bp), %cx
|
addw polygonoffx(%bp), %cx
|
||||||
addw polygonoffy(%bp), %bx
|
addw polygonoffy(%bp), %bx
|
||||||
addw polygonoffy(%bp), %dx
|
addw polygonoffy(%bp), %dx
|
||||||
|
|
||||||
pushw polygoncolor(%bp)
|
pushw polygoncolor(%bp) # Send the color, x and y values to the line function
|
||||||
pushw %dx
|
pushw %dx
|
||||||
pushw %cx
|
pushw %cx
|
||||||
pushw %bx
|
pushw %bx
|
||||||
pushw %ax
|
pushw %ax
|
||||||
call cons_draw_line
|
call cons_draw_line
|
||||||
|
|
||||||
addw $4, %si
|
addw $4, %si # Advance the array address by 1 coordinate set
|
||||||
jmp cons_draw_polygon_loop_next
|
jmp cons_draw_polygon_loop_next # Jump back upto the start
|
||||||
|
|
||||||
cons_polygon_loop_end:
|
cons_polygon_loop_end:
|
||||||
# Return all the original values to each register before we return back
|
# Return all the original values to each register before we return back
|
||||||
@ -805,9 +804,9 @@ setup_polygon_arrays:
|
|||||||
call arr_clear
|
call arr_clear
|
||||||
|
|
||||||
# Map points for the star polygon array
|
# Map points for the star polygon array
|
||||||
pushw $-6
|
pushw $-6 # y coordinate
|
||||||
pushw $0
|
pushw $0 # x coordinate
|
||||||
pushw $polygon_array
|
pushw $polygon_array # address of array
|
||||||
call arr_add_point
|
call arr_add_point
|
||||||
pushw $0
|
pushw $0
|
||||||
pushw $2
|
pushw $2
|
||||||
@ -945,8 +944,8 @@ setup_polygon_arrays:
|
|||||||
|
|
||||||
# Draw the moon polygon
|
# Draw the moon polygon
|
||||||
pushw $7 # Color
|
pushw $7 # Color
|
||||||
pushw $30 # Y Offset
|
pushw $30 # Y Offset
|
||||||
pushw $280 # X Offset
|
pushw $280 # X Offset
|
||||||
pushw $0x1050 # Address of the Array
|
pushw $0x1050 # Address of the Array
|
||||||
call cons_draw_polygon
|
call cons_draw_polygon
|
||||||
|
|
||||||
@ -958,31 +957,31 @@ draw_stars:
|
|||||||
pushw $polygon_array
|
pushw $polygon_array
|
||||||
call cons_draw_polygon
|
call cons_draw_polygon
|
||||||
|
|
||||||
pushw $14
|
pushw $13
|
||||||
pushw $20
|
pushw $20
|
||||||
pushw $80
|
pushw $80
|
||||||
pushw $polygon_array
|
pushw $polygon_array
|
||||||
call cons_draw_polygon
|
call cons_draw_polygon
|
||||||
|
|
||||||
pushw $14
|
pushw $12
|
||||||
pushw $25
|
pushw $25
|
||||||
pushw $130
|
pushw $130
|
||||||
pushw $polygon_array
|
pushw $polygon_array
|
||||||
call cons_draw_polygon
|
call cons_draw_polygon
|
||||||
|
|
||||||
pushw $14
|
pushw $11
|
||||||
pushw $10
|
pushw $10
|
||||||
pushw $250
|
pushw $250
|
||||||
pushw $polygon_array
|
pushw $polygon_array
|
||||||
call cons_draw_polygon
|
call cons_draw_polygon
|
||||||
|
|
||||||
pushw $14
|
pushw $10
|
||||||
pushw $100
|
pushw $100
|
||||||
pushw $200
|
pushw $200
|
||||||
pushw $polygon_array
|
pushw $polygon_array
|
||||||
call cons_draw_polygon
|
call cons_draw_polygon
|
||||||
|
|
||||||
pushw $14
|
pushw $9
|
||||||
pushw $60
|
pushw $60
|
||||||
pushw $50
|
pushw $50
|
||||||
pushw $polygon_array
|
pushw $polygon_array
|
||||||
@ -1052,22 +1051,22 @@ draw_flag_loop_end:
|
|||||||
call cons_draw_circle
|
call cons_draw_circle
|
||||||
|
|
||||||
pushw $15 # Color
|
pushw $15 # Color
|
||||||
pushw $5 # radius
|
pushw $5 # radius
|
||||||
pushw $85 # y
|
pushw $85 # y
|
||||||
pushw $80 # x
|
pushw $80 # x
|
||||||
call cons_draw_circle
|
call cons_draw_circle
|
||||||
|
|
||||||
pushw $15 # Color
|
pushw $15 # Color
|
||||||
pushw $5 # radius
|
pushw $5 # radius
|
||||||
pushw $85 # y
|
pushw $85 # y
|
||||||
pushw $100 # x
|
pushw $100 # x
|
||||||
call cons_draw_circle
|
call cons_draw_circle
|
||||||
|
|
||||||
# Plot a line, we add the parameters to the stack in reverse order
|
# Plot a line, we add the parameters to the stack in reverse order
|
||||||
pushw $15 # Color
|
pushw $15 # Color
|
||||||
pushw $100 # y1
|
pushw $100 # y1
|
||||||
pushw $75 # x1
|
pushw $75 # x1
|
||||||
pushw $105 # y0
|
pushw $105 # y0
|
||||||
pushw $90 # x0
|
pushw $90 # x0
|
||||||
call cons_draw_line
|
call cons_draw_line
|
||||||
|
|
||||||
@ -1135,4 +1134,4 @@ screen_height:
|
|||||||
.word 200
|
.word 200
|
||||||
|
|
||||||
polygon_array: # Create some memory space for our polygon points array
|
polygon_array: # Create some memory space for our polygon points array
|
||||||
.fill 40 # Fill array with data to the size of the array
|
.fill 200 # Fill array with data to the size of the array
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
stage5/xv6.img
(Stored with Git LFS)
BIN
stage5/xv6.img
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user