From d679b2b6bf3bb84dc7e6763d0397b9cd5441c9a5 Mon Sep 17 00:00:00 2001 From: iDunnoDev Date: Wed, 16 Nov 2022 00:43:03 +0000 Subject: [PATCH] Removed the endx and y local vars from the filled rect function Added checks for the filled rect function Added comments for the filled rect function --- stage4/.vscode/tasks.json | 6 +++ stage4/bootasm2.S | 97 +++++++++++++++++++++++++++++--------- stage4/bootasm2.o | Bin 4184 -> 4808 bytes stage4/bootblock2 | Bin 984 -> 1091 bytes stage4/bootblock2.o | Bin 3776 -> 4372 bytes stage4/xv6.img | 2 +- 6 files changed, 83 insertions(+), 22 deletions(-) diff --git a/stage4/.vscode/tasks.json b/stage4/.vscode/tasks.json index 51722d9..c567be5 100644 --- a/stage4/.vscode/tasks.json +++ b/stage4/.vscode/tasks.json @@ -8,6 +8,12 @@ "type": "shell", "command": "make qemu", "problemMatcher": [] + }, + { + "label": "Build and QEMU (debug)", + "type": "shell", + "command": "make qemu-gdb", + "problemMatcher": [] } ] } \ No newline at end of file diff --git a/stage4/bootasm2.S b/stage4/bootasm2.S index 1d187b0..6d15cf7 100644 --- a/stage4/bootasm2.S +++ b/stage4/bootasm2.S @@ -257,13 +257,10 @@ cons_plot_pixel_end: #define recty 6 #define rectx 4 -#define rectendx -2 -#define rectendy -4 - cons_draw_filled_rect: pushw %bp movw %sp, %bp - subw $4, %sp # Make room for our local variables in the stack + #subw $4, %sp # Make room for our local variables in the stack # Store existing register values to the stack so we can restore later pushw %ax @@ -273,15 +270,73 @@ cons_draw_filled_rect: pushw %si pushw %di -cons_filled_rect_setup: - movw rectwidth(%bp), %ax - add rectx(%bp), %ax - movw %ax, rectendx(%bp) - - movw rectheight(%bp), %bx - add recty(%bp), %bx - movw %bx, rectendy(%bp) +cons_filled_rect_check_x_dir: + movw rectwidth(%bp), %ax # Check if the user has entered a negative width value and swap the direction to a positive + cmpw $0, %ax + jge cons_filled_rect_check_y_dir + add %ax, rectx(%bp) + neg rectwidth(%bp) +cons_filled_rect_check_y_dir: + movw rectheight(%bp), %ax # Check if the user has entered a negative height value and swap the direction to a pos + cmpw $0, %ax + jge cons_filled_rect_check_x_zero + add %ax, recty(%bp) + neg rectheight(%bp) + +cons_filled_rect_check_x_zero: + movw rectx(%bp), %ax # Check if the x value is a negative value, set it to 0 and figure out the offset so we + movw $0, %bx # dont write to unwanted memory locations + cmpw %bx, %ax + jge cons_filled_rect_check_x_screenwidth + movw %bx, rectx(%bp) # Set to x 0 + sub %ax, %bx # get the distance from 0 to x + sub %bx, rectwidth(%bp) # take this away from the width + jmp cons_filled_rect_check_width_screenwidth + +cons_filled_rect_check_x_screenwidth: + movw (screen_width), %bx # Check if the x is outside of the view port, if so just end the call + cmpw %bx, %ax # since it will never draw anything + jg cons_filled_rect_loop_end + +cons_filled_rect_check_width_screenwidth: + add rectwidth(%bp), %ax + movw (screen_width), %bx # Check if the width ends up outside of the view port + cmpw %bx, %ax + jle cons_filled_rect_check_y_zero + sub %bx, %ax + sub %ax, rectwidth(%bp) # Remove the excess from the width value so we dont overflow memory + +cons_filled_rect_check_y_zero: + movw recty(%bp), %ax # Check if the y value is a negative value, set it to 0 and figure out the offset so we + movw $0, %bx # dont write to unwanted memory locations + cmpw %bx, %ax + jge cons_filled_rect_check_y_screenheight + movw %bx, recty(%bp) # Set to y 0 + sub %ax, %bx # get the distance from 0 to y + sub %bx, rectheight(%bp) # take this away from the height + jmp cons_filled_rect_check_height_screenheight + +cons_filled_rect_check_y_screenheight: + movw (screen_height), %bx # Check if the y is outside of the view port, if so just end the call + cmpw %bx, %ax # since it will never draw anything + jg cons_filled_rect_loop_end + +cons_filled_rect_check_height_screenheight: + add rectheight(%bp), %ax + movw (screen_height), %bx # Check if the width ends up outside of the view port + cmpw %bx, %ax + jle cons_filled_rect_setup + sub %bx, %ax + sub %ax, rectheight(%bp) # Remove the excess from the width value so we dont overflow memory + +cons_filled_rect_check_empty: + cmpw $0, rectwidth(%bp) # Check if the width or height is now zero, end the function if so + jle cons_filled_rect_loop_end + cmpw $0, rectheight(%bp) + jle cons_filled_rect_loop_end + +cons_filled_rect_setup: movw $0xA000, %bx # Set the start of the video memory location movw %bx, %es # Move that address into the "extra segment" es register @@ -290,21 +345,21 @@ cons_filled_rect_setup: mul %dx # does the (y * 320) part of our math add rectx(%bp), %ax # Add the value of x to register ax movw %ax, %si - lea %es:(%si), %bx # Move the value of ax into the si counter + lea %es:(%si), %bx # Load the memory address into the bx register - movw rectheight(%bp), %si + movw rectheight(%bp), %si # Set the counter to our height which should be the number of lines to draw to cons_filled_rect_loop_start: - movw rectcolor(%bp), %ax - movw %bx, %di - movw rectwidth(%bp), %cx - cld - rep stosb + movw rectcolor(%bp), %ax # Set the color byte for our rep + movw %bx, %di # move the memory location to the di counter + movw rectwidth(%bp), %cx # Set cx to our width so the rep knows when to end + cld # Clear the direction flag so our rep counter inc's + rep stosb # Run the stosb to copy bytes into the data segment til cx is 0 movw (screen_width), %cx - add %cx, %bx + add %cx, %bx # Add 320 to our current y value for the next line - dec %si + dec %si # Dex the height counter til we hit 0 jnz cons_filled_rect_loop_start diff --git a/stage4/bootasm2.o b/stage4/bootasm2.o index a7f25f373204afdd01ea59219b3dc319171a066b..6c43a6435027469cb00e4cd038b85d8f9db49974 100644 GIT binary patch delta 1694 zcmaKse`s4(6vxl|(YLqPHZR4vPFJ%o?b4=HLbtiCb0rip$SR|=-47$?DM@B}*EOT9 zX{uX-WUz(knA}>m?|ttkQ}vUZ&(_!0JHZ^=%()qAzzM(B3m0~5<}v{>)0q7mj&FQ)U8k6NAbS^% zyWRAhn<)l(h-YF*+^_MOEXE}LSPps%gJ!0wEa`F%T;EJBp zyDU9phgH zRqo!jWs@-)Iy(Fvf#u1M(AMQ|>*(_P{YLh`i7tOv+xTDN9*!@_v{PzWSBKY;H?O2< z&c^hZNYfJG8-(%OQkdfdBHbgq`A(4%*`0}T%RUaSqaI@T7u2sXT!Ee6V7LYOErxrL zYpm6=DF;VUf5_DH$X6M@z(WSUU=lx~;TFU5$Tt{v3IHXBTah0^k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>Bv#ZzWC5DvQQi&J0so=%zab z4?iN%psrf_$0byBz>!h95%S$}G4S*~hSgyocco za+TqNL&qJ{^&P*9hE9fOk$a4F{Q|O&(Z5FC&G7fghZ(+t>}BTvgFI5_cDyH=@35{7 zCh;~J9yMm(Y5AGcqna9hR>>-{cnYG)u?gi!JdsdiN=l8U6+BwcD9=YxSDCu``iOjw|X|>~=M*5|bNlW3pacQ{zXqG+TpyAEjji)E+NvC(_qBFtKoi6)7a(TJ8Xx!DuouyMa{z%Wc`our+k+<^n z7Zl61#ofmbHq!xj@BIn9y2tVHx8UpEg&l3sj@@ERH`)&}fLov^-QLZ=y8)hW2=>Kq F;lJk0)Lj4o delta 1003 zcmZ9Ke@IhN6vyv%qOu@t{}i$sX04nIwARHKh7SKQ7Ve+M z$aHt~heT9=NJ#{>ekhfMk{Ce}EgKRTN^!##qERN>Tjy=2k1p?AzMpf>J@>wQZq)X& zxX;Szjr}%TenNwgVmgEn2K)Ayd(c>p192MI7W{*{OZFB_(?DTx6?I!~#p&-kJQu2N4vuSynP^Fu)4|&1 zxjBUmYwVE;CS|0WSiIK|bIL^UK0*+)c>58nlj%pz?m$%g@2GZME*Ow)to;FBU@MioiH9g!t@?`jp1f`+NzP(9tR0#?4~7%ujDJ?JM1W zpi~)UwYB@9!1cx_-b z1sqZF0`Q=UwQ%T%DlXtq0F9~~)sXN`#dW~Z$i@bZz=JA24}4F>J-{QX178ImRmBH@ zr&N5Gt3&9!%JCc$o~jDG22QN81UK~IKlWxhHYUzv8aHmHdXq#ajRtzyXo_tywPD(0 zF5sXw17;hpp)bspS_ibOoVM%oY050&PHL1Yg%J3lz#hql+h~(isl6j0R6{*dKD{nU g#stu3*eDM!qKb}4TZLhepEx=r*|bpuLhVYuzj!AzTL1t6 diff --git a/stage4/xv6.img b/stage4/xv6.img index 6f9ef93..6ffd19d 100644 --- a/stage4/xv6.img +++ b/stage4/xv6.img @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0e72ff56ad3e3b45619ce85e77f8a521e4ab77e93fc1b0154d51ccc93efc416a +oid sha256:91937ee0ce0a78815628538f19ff3ee6cf003e740e7815fb11539871c39e068e size 5120000