Added comments to the source code for stage 1

Changed the parameters for the function to load into registers
Changed all the data types to words instead of int in case ints are not allowed
This commit is contained in:
iDunnoDev
2022-11-05 11:21:06 +00:00
committed by iDunnoDev
parent 9efe950b7b
commit d7f3c20324
5 changed files with 112 additions and 75 deletions

View File

@ -38,6 +38,8 @@ cons_writeline:
call cons_write_crlf
ret
# Added Write Hex and Int functions to help with debugging
HexChars: .ascii "0123456789ABCDEF"
cons_write_hex:
@ -84,72 +86,78 @@ getdigit:
IntBuffer: .string " "
cons_draw_line:
movw $0, err
movw x1, %cx
movw y1, %dx
sub x0, %cx
movw $0, err # Make sure that err starts at 0
movw %ax, (x0) # Move the initial vars from the registers to static memory
movb %cl, (y0)
movw %bx, (x1)
movb %ch, (y1)
movb %dl, (color)
movw x1, %cx # Load x1 and y1 into the registers
movw y1, %dx
sub x0, %cx # Remove x/y0 from x/y1 to get the delta values
sub y0, %dx
movw %cx, (deltax)
movw %cx, (deltax) # Store the delta values
movw %dx, (deltay)
cons_line_check_x:
movw x0, %cx
movw $1, (sx)
cmp x1, %cx
movw x0, %cx # Load x0 into register cx so we can manipulate this value to plot each pixel
movw $1, (sx) # Preload x slope with 1
cmp x1, %cx # Check if x1 is less than x0 and we can move to y
jl cons_line_check_y
negw sx
negw sx # if x1 is greater than we need to flip the slope and the x delta values
negw deltax
cons_line_check_y:
movw y0, %dx
movw $1, (sy)
cmpw y1, %dx
movw y0, %dx # Load y0 into register dx so we can manipulate this value to plot each pixel
movw $1, (sy) # Preload y slope with 1
cmpw y1, %dx # Check if y1 is less than y0 and we can start our plotting
jl cons_line_prep_loop
negw sy
negw sy # if y1 is greater than we need to flip the slope y and delta y values
negw deltay
cons_line_prep_loop:
movw deltax, %ax
movw deltax, %ax # Calculate the err variable by subtracting delta y from delta x
sub deltay, %ax
movw %ax, (err)
movw %ax, (err)
cons_line_loop_start:
xor %ax, %ax
xor %ax, %ax # Clear ax and bx for use with the draw function
xor %bx, %bx
movb $0x0c, %ah
movb $0, %bh
movb (color), %al
int $0x10
movb $0x0c, %ah # Set the function byte to plot the pixel
movb $0, %bh # Set the video page number
movb (color), %al # Set the color of the pixel
int $0x10 # Call the int
cmpw x1, %cx
cmpw x1, %cx # Check if x0 and x1 are equal, if not then we are still plotting
jne cons_line_loop_next_point
cmpw y1, %dx
cmpw y1, %dx # Check if y0 and y1 are equal, if not then we are still plotting
jne cons_line_loop_next_point
jmp cons_line_loop_end
jmp cons_line_loop_end # if both x's and y's are equal then we can end the function
cons_line_loop_next_point:
movw err, %ax
add %ax, %ax
movw err, %ax # Load err into ax so that we can multiply it
add %ax, %ax # e2 is 2 * err, so we can just add err to itself
cons_line_loop_move_y_point:
movw deltay, %bx
negw %bx
cmpw %bx, %ax
negw %bx # We need negative deltay to compare
cmpw %bx, %ax # Check if we need to apply the slope value to y
jle cons_line_loop_move_x_point
negw %bx
subw %bx, err
addw sx, %cx
negw %bx # Change deltay back to normal
subw %bx, err # Remove the deltay from the err check
addw sx, %cx # Add the slope value to the current y value
cons_line_loop_move_x_point:
movw deltax, %bx
cmpw %bx, %ax
cmpw %bx, %ax # Check if we need to apply the x slope value
jge cons_line_loop_start
addw %bx, err
addw sy, %dx
jmp cons_line_loop_start
addw %bx, err # Add the deltax to the err value
addw sy, %dx # Add the slope value to the current x value
jmp cons_line_loop_start # Go back to the start of the loop
cons_line_loop_end:
ret
ret # Finish the loop and return to the call address
real_start:
movw $boot_message, %si # Display our boot message
@ -162,46 +170,75 @@ draw_start:
int $0x10
xor %ax, %ax
movw $50, x0
movw $50, y0
movw $160, x1
movw $55, y1
movb $12, color
movw $50, %ax # Plot a line, ax = x0, bx = x1, cl = y0, ch = y1, dl = color
movb $50, %cl # the X values require a full register but the y's only require a byte since the max value is 200
movw $160, %bx
movb $55, %ch
movb $12, %dl # The Color also only requires a byte
call cons_draw_line
movw $150, x0
movw $150, y0
movw $50, x1
movw $50, y1
movb $10, color
# Draw the rest of the lines
movw $160, %ax
movb $55, %cl
movw $90, %bx
movb $150, %ch
movb $11, %dl
call cons_draw_line
movw $150, x0
movw $150, y0
movw $160, x1
movw $55, y1
movb $11, color
movw $90, %ax
movb $150, %cl
movw $50, %bx
movb $50, %ch
movb $14, %dl
call cons_draw_line
movw $10, x0
movw $10, y0
movw $310, x1
movw $190, y1
movb $9, color
movw $10, %ax
movb $10, %cl
movw $310, %bx
movb $10, %ch
movb $9, %dl
call cons_draw_line
movw $310, x0
movw $190, y0
movw $10, x1
movw $95, y1
movb $8, color
movw $310, %ax
movb $10, %cl
movw $310, %bx
movb $190, %ch
movb $10, %dl
call cons_draw_line
movw $10, x0
movw $95, y0
movw $10, x1
movw $10, y1
movb $7, color
movw $310, %ax
movb $190, %cl
movw $10, %bx
movb $190, %ch
movb $13, %dl
call cons_draw_line
movw $10, %ax
movb $190, %cl
movw $10, %bx
movb $10, %ch
movb $15, %dl
call cons_draw_line
movw $75, %ax
movb $150, %cl
movw $250, %bx
movb $110, %ch
movb $1, %dl
call cons_draw_line
movw $210, %ax
movb $30, %cl
movw $300, %bx
movb $150, %ch
movb $6, %dl
call cons_draw_line
movw $180, %ax
movb $180, %cl
movw $170, %bx
movb $20, %ch
movb $3, %dl
call cons_draw_line
endless_loop: # Loop forever more
@ -211,14 +248,14 @@ endless_loop: # Loop forever more
boot_message:
.string "Boot Loader Stage 2 loaded"
x0: .int 0
y0: .int 0
x1: .int 0
y1: .int 0
deltax: .int 0
deltay: .int 0
sx: .int 0
sy: .int 0
err: .int 0
e2: .int 0
x0: .word 0
y0: .word 0
x1: .word 0
y1: .word 0
deltax: .word 0
deltay: .word 0
sx: .word 0
sy: .word 0
err: .word 0
e2: .word 0
color: .byte 0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.