diff --git a/stage5/bootasm2.S b/stage5/bootasm2.S index d1c216d..0346d27 100644 --- a/stage5/bootasm2.S +++ b/stage5/bootasm2.S @@ -596,15 +596,15 @@ arr_add_point_setup: addw $2, %si # Otherwise move the array to the first data position arr_add_point_start: - cmpw $0x7f7f, (%si) # Check if the current - jne arr_add_point_move_addr - movw %cx, (%si) - movw %dx, 2(%si) + cmpw $0x7f7f, (%si) # Check if the current index has not been written to + jne arr_add_point_move_addr # If not move to the next for checking + movw %cx, (%si) # Add the X and Y values to the array at the current index + movw %dx, 2(%si) # and the next index jmp arr_add_point_end arr_add_point_move_addr: - addw $4, %si - cmpw $0x7fff, (%si) + addw $4, %si # Move the index to the next item + cmpw $0x7fff, (%si) # Check if we are at the end of the allocated array size jne arr_add_point_start arr_add_point_end: @@ -638,12 +638,12 @@ arr_dump: pushw %di arr_dump_setup: - movw dumpptr(%bp), %si - addw dumpstart(%bp), %si - movw dumplen(%bp), %cx + movw dumpptr(%bp), %si # Load the memory address of the array given + addw dumpstart(%bp), %si # Add any offset given by the user + movw dumplen(%bp), %cx # Set cx to the limit given for the 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_crlf add $2, %si @@ -705,7 +705,7 @@ arr_clear_loop_end: popw %bp 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 # Define parameter address positions in stack #define polygoncolor 10 @@ -715,8 +715,7 @@ arr_clear_loop_end: cons_draw_polygon: pushw %bp - movw %sp, %bp - #subw $20, %sp # Make room for our local variables in the stack + movw %sp, %bp # Store existing register values to the stack so we can restore later pushw %ax @@ -727,48 +726,48 @@ cons_draw_polygon: pushw %di 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 jne cons_polygon_loop_end # If not end the function addw $2, %si # Otherwise move the array to the first data position cons_draw_polygon_loop_next: - cmpw $0x7f7f, (%si) - je cons_polygon_loop_end - cmpw $0x7fff, (%si) + cmpw $0x7f7f, (%si) # Check if the current array item is not "empty" + je cons_polygon_loop_end # if so skip to the end of the function + cmpw $0x7fff, (%si) # also check if we've hit the end of the array je cons_polygon_loop_end 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 - cmpw $0x7f7f, 4(%si) - je cons_polygon_loop_map_end + cmpw $0x7f7f, 4(%si) # Check if the x1 and y1 values exist + je cons_polygon_loop_map_end # otherwise we jump to map end and use the first 2 array coords cmpw $0x7fff, 4(%si) 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 jmp cons_polygon_loop_draw_line cons_polygon_loop_map_end: - movw polygonarray(%bp), %di - movw 2(%di), %cx + movw polygonarray(%bp), %di # Set the Array address to di + movw 2(%di), %cx # Jump the first word and move the next 2 into x1 and y1 movw 4(%di), %dx 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 polygonoffy(%bp), %bx addw polygonoffy(%bp), %dx - pushw polygoncolor(%bp) + pushw polygoncolor(%bp) # Send the color, x and y values to the line function pushw %dx pushw %cx pushw %bx pushw %ax call cons_draw_line - addw $4, %si - jmp cons_draw_polygon_loop_next + addw $4, %si # Advance the array address by 1 coordinate set + jmp cons_draw_polygon_loop_next # Jump back upto the start cons_polygon_loop_end: # Return all the original values to each register before we return back @@ -805,9 +804,9 @@ setup_polygon_arrays: call arr_clear # Map points for the star polygon array - pushw $-6 - pushw $0 - pushw $polygon_array + pushw $-6 # y coordinate + pushw $0 # x coordinate + pushw $polygon_array # address of array call arr_add_point pushw $0 pushw $2 @@ -945,8 +944,8 @@ setup_polygon_arrays: # Draw the moon polygon pushw $7 # Color - pushw $30 # Y Offset - pushw $280 # X Offset + pushw $30 # Y Offset + pushw $280 # X Offset pushw $0x1050 # Address of the Array call cons_draw_polygon @@ -958,31 +957,31 @@ draw_stars: pushw $polygon_array call cons_draw_polygon - pushw $14 + pushw $13 pushw $20 pushw $80 pushw $polygon_array call cons_draw_polygon - pushw $14 + pushw $12 pushw $25 pushw $130 pushw $polygon_array call cons_draw_polygon - pushw $14 + pushw $11 pushw $10 pushw $250 pushw $polygon_array call cons_draw_polygon - pushw $14 + pushw $10 pushw $100 pushw $200 pushw $polygon_array call cons_draw_polygon - pushw $14 + pushw $9 pushw $60 pushw $50 pushw $polygon_array @@ -1052,22 +1051,22 @@ draw_flag_loop_end: call cons_draw_circle pushw $15 # Color - pushw $5 # radius - pushw $85 # y - pushw $80 # x + pushw $5 # radius + pushw $85 # y + pushw $80 # x call cons_draw_circle pushw $15 # Color - pushw $5 # radius - pushw $85 # y + pushw $5 # radius + pushw $85 # y pushw $100 # x call cons_draw_circle # Plot a line, we add the parameters to the stack in reverse order pushw $15 # Color - pushw $100 # y1 + pushw $100 # y1 pushw $75 # x1 - pushw $105 # y0 + pushw $105 # y0 pushw $90 # x0 call cons_draw_line @@ -1135,4 +1134,4 @@ screen_height: .word 200 polygon_array: # Create some memory space for our polygon points array - .fill 40 # Fill array with data to the size of the array \ No newline at end of file + .fill 200 # Fill array with data to the size of the array \ No newline at end of file diff --git a/stage5/bootasm2.o b/stage5/bootasm2.o index 674eaa4..7176aeb 100644 Binary files a/stage5/bootasm2.o and b/stage5/bootasm2.o differ diff --git a/stage5/bootblock2 b/stage5/bootblock2 index 88f99f4..1312f17 100644 Binary files a/stage5/bootblock2 and b/stage5/bootblock2 differ diff --git a/stage5/bootblock2.o b/stage5/bootblock2.o index f233798..8a1e1b9 100644 Binary files a/stage5/bootblock2.o and b/stage5/bootblock2.o differ diff --git a/stage5/xv6.img b/stage5/xv6.img index 621fd09..fe67061 100644 --- a/stage5/xv6.img +++ b/stage5/xv6.img @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:288eb982d8be8d0bae83fd38df2c56107fba15cf66fd1beb675960fa8ab77132 +oid sha256:a108667751cb7525a5bed280f5f36a5b873b513ecf2ddaa3758c560bcd0d3ade size 5120000