From 4d5dd089f65a2e5d61c0a1c9645a2a55bb6849a7 Mon Sep 17 00:00:00 2001 From: iDunnoDev Date: Wed, 23 Nov 2022 15:54:32 +0000 Subject: [PATCH] Added comments to stage 5 --- stage5/bootasm2.S | 89 ++++++++++++++++++++++---------------------- stage5/bootasm2.o | Bin 6912 -> 7072 bytes stage5/bootblock2 | Bin 1850 -> 2010 bytes stage5/bootblock2.o | Bin 6304 -> 6464 bytes stage5/xv6.img | 2 +- 5 files changed, 45 insertions(+), 46 deletions(-) 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 674eaa46ab11b32d2a799ce80c8f8f7b870e4207..7176aebef09d95e3949f4d6cfd0246143b000183 100644 GIT binary patch delta 285 zcmZoLTVOsxf$_&i#Vf2Pyjdby0U1KR z$v6S#-2a=!xmlCVm2q-`ga9#^F?4f2I}a11;pQ4nH%8W%j0}v7le4*1C%@*>X1c{c zS%O=AvIDmWsH$kXXl4`7Z>rvJNvSat?NI05F| U|C`0R`75g{<75SPDIAyu0PZ9r00000 delta 65 zcmcb`zl(3fK~@vKERn2$458^S*#2elWl3fEm7VKw2+63Gh45Sspi?Ozs8mSjc~1BmnUZx(kJ zSH>?e=gr?NuB?=d6JXB$zge7{J=xqDCpWMQ5P?+~Z%tmxuE2DQfAVp5CC1Rruh@B* z7!5an=X7IaddWE1j=OR50q!L%inpdSfPnx5Bf~jXp!1OUvzQqe?rd%qn9l|@O;uc( z$$(?Bm$({J0LSDaAXUmSd6u{uYbOT-L*(S6;>wJVCchL{XOiQYEF=L`#536nNI3{j UPLfcQ5EW-&D1_JqCK;h@0GI7h#{d8T delta 250 zcmX?Lw7_tJ0@DkziAqYWR_qK6RvSIfu$u5?iDU(22u**%_AiSsOERO00mS+F7s%nt z_yy*?0dZ0?PJlW0ft<~rZ0?Mc4LC#?ttPv2C@}5fo1D&}#2B)8#l-EEM-x&n$7?Q0t}1{=U9O@Bk^Z3Gced}Ru!Dj1~lxbxH8iO_Q|ir)tEN0 zPZp9;W4g*d*-Ao<^(D}~5tCCTlo=f-cS@);)pAeX1eD#tJ^2=pS|Bi)Nm5OsRE&Y4 L5MmRUWQ4K-8qPwR 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