You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
3.6 KiB
NASM
191 lines
3.6 KiB
NASM
6 years ago
|
[org 0x1000]
|
||
|
|
||
|
push 0a000h ;Video memory graphics segment
|
||
|
pop es
|
||
|
|
||
|
mov ax, 0012h ;320x200@8bpp
|
||
|
int 10h
|
||
|
|
||
|
|
||
|
push 0Eh ;Blue
|
||
|
push 10 ;cX
|
||
|
push 10 ;cY
|
||
|
push 10 ;Radius
|
||
|
call drawFilledCircle
|
||
|
|
||
|
push 02h ;Blue
|
||
|
push 40 ;cX
|
||
|
push 40 ;cY
|
||
|
push 30 ;Radius
|
||
|
call drawFilledCircle
|
||
|
|
||
|
push 06h ;Blue
|
||
|
push 140 ;cX
|
||
|
push 100 ;cY
|
||
|
push 70 ;Radius
|
||
|
call drawFilledCircle
|
||
|
|
||
|
main: ; Label for the start of the main program
|
||
|
|
||
|
mov ax,0x0000 ; Setup the Data Segment register
|
||
|
; Location of data is DS:Offset
|
||
|
mov ds,ax ; This can not be loaded directly it has to be in two steps.
|
||
|
; 'mov ds, 0x0000' will NOT work due to limitations on the CPU
|
||
|
|
||
|
mov si, HelloWorld ; Load the string into position for the procedure.
|
||
|
call PutStr ; Call/start the procedure
|
||
|
|
||
|
mov dx, 0C14h ;DH=12 row, DL=20 column
|
||
|
mov bh, 0 ;BH=0 display page
|
||
|
mov ah, 02h ;AH=02h set cursor position function
|
||
|
int 10h ;video BIOS interrupt
|
||
|
|
||
|
mov bx, 000Ch ;BH=0 display page, BL=12 red
|
||
|
mov ax, 0E42h ;AH=0Eh teletype function, AL=66 capital B
|
||
|
int 10h ;video BIOS interrupt
|
||
|
|
||
|
|
||
|
|
||
|
; Procedures
|
||
|
PutStr: ; Procedure label/start
|
||
|
; Set up the registers for the interrupt call
|
||
|
mov ah,0x0E ; The function to display a chacter (teletype)
|
||
|
mov bh,0x00 ; Page number
|
||
|
mov bl,0x0C ; Normal text attribute
|
||
|
|
||
|
.nextchar ; Internal label (needed to loop round for the next character)
|
||
|
lodsb ; I think of this as LOaD String Block
|
||
|
; (Not sure if thats the real meaning though)
|
||
|
; Loads [SI] into AL and increases SI by one
|
||
|
; Check for end of string '0'
|
||
|
or al,al ; Sets the zero flag if al = 0
|
||
|
; (OR outputs 0's where there is a zero bit in the register)
|
||
|
jz .return ; If the zero flag has been set go to the end of the procedure.
|
||
|
; Zero flag gets set when an instruction returns 0 as the answer.
|
||
|
int 0x10 ; Run the BIOS video interrupt
|
||
|
jmp .nextchar ; Loop back round tothe top
|
||
|
.return ; Label at the end to jump to when complete
|
||
|
ret ; Return to main program
|
||
|
|
||
|
|
||
|
;Color
|
||
|
;cX
|
||
|
;cY
|
||
|
;R
|
||
|
drawFilledCircle:
|
||
|
push bp
|
||
|
mov bp, sp
|
||
|
|
||
|
sub sp, 02h
|
||
|
|
||
|
mov cx, WORD [bp+04h] ;R
|
||
|
|
||
|
mov ax, cx
|
||
|
mul ax ;AX = R^2
|
||
|
mov WORD [bp-02h], ax ;[bp-02h] = R^2
|
||
|
|
||
|
|
||
|
|
||
|
mov ax, WORD [bp+06h]
|
||
|
sub ax, cx ;i = cY-R
|
||
|
mov bx, WORD [bp+08h]
|
||
|
sub bx, cx ;j = cX-R
|
||
|
|
||
|
shl cx, 1
|
||
|
mov dx, cx ;DX = Copy of 2R
|
||
|
|
||
|
.advance_v:
|
||
|
push cx
|
||
|
push bx
|
||
|
|
||
|
mov cx, dx
|
||
|
|
||
|
.advance_h:
|
||
|
;Save values
|
||
|
push bx
|
||
|
push ax
|
||
|
push dx
|
||
|
|
||
|
;Compute (i-y) and (j-x)
|
||
|
sub ax, WORD [bp+06h]
|
||
|
sub bx, WORD [bp+08h]
|
||
|
|
||
|
mul ax ;Compute (i-y)^2
|
||
|
|
||
|
push ax
|
||
|
mov ax, bx
|
||
|
mul ax
|
||
|
pop bx ;Compute (j-x)^2 in ax, (i-y)^2 is in bx now
|
||
|
|
||
|
add ax, bx ;(j-x)^2 + (i-y)^2
|
||
|
cmp ax, WORD [bp-02h] ;;(j-x)^2 + (i-y)^2 <= R^2
|
||
|
|
||
|
;Restore values before jump
|
||
|
pop dx
|
||
|
pop ax
|
||
|
pop bx
|
||
|
|
||
|
ja .continue ;Skip pixel if (j-x)^2 + (i-y)^2 > R^2
|
||
|
|
||
|
;Write pixel
|
||
|
push WORD [bp+0ah]
|
||
|
push bx
|
||
|
push ax
|
||
|
call writePx
|
||
|
|
||
|
|
||
|
.continue:
|
||
|
|
||
|
;Advance j
|
||
|
inc bx
|
||
|
loop .advance_h
|
||
|
|
||
|
;Advance i
|
||
|
inc ax
|
||
|
|
||
|
|
||
|
pop bx ;Restore j
|
||
|
pop cx ;Restore counter
|
||
|
|
||
|
loop .advance_v
|
||
|
|
||
|
add sp, 02h
|
||
|
|
||
|
|
||
|
pop bp
|
||
|
ret 08h
|
||
|
|
||
|
|
||
|
|
||
|
;Color
|
||
|
;X
|
||
|
;Y
|
||
|
writePx:
|
||
|
push bp
|
||
|
mov bp, sp
|
||
|
|
||
|
push ax
|
||
|
push bx
|
||
|
|
||
|
mov bx, WORD [bp+04h]
|
||
|
mov ax, bx
|
||
|
shl bx, 6
|
||
|
shl ax, 8
|
||
|
add bx, ax ;320 = 256 + 64
|
||
|
|
||
|
add bx, WORD [bp+06h]
|
||
|
mov ax, WORD [bp+08h]
|
||
|
|
||
|
;TODO: Clip
|
||
|
|
||
|
mov BYTE [es:bx], al
|
||
|
|
||
|
pop bx
|
||
|
pop ax
|
||
|
|
||
|
pop bp
|
||
|
ret 06h
|
||
|
|
||
|
|
||
|
HelloWorld db ' Not My Default Bootloader',0x0D,0x0A,0
|