Page 1 of 1
Printing to the screen
Posted: Sat Aug 02, 2008 11:16 pm
by chezzestix
In real mode I cant fit 0xb8000 in a register... how can I work around that? Up until now I have always hard coded the address but Im trying to automate the printing of strings which would make hard coding no longer an option.
Re: Printing to the screen
Posted: Sun Aug 03, 2008 12:14 am
by 01000101
you need to use a segment:offset pair to access 0xB8000.
You could put 0xB800 in 'es' and use 'bx' as the x/y offset register.
so, if you want to print a green 'L' in the upper left,
Code: Select all
mov ax, 0xB800 ; cant access 'es' directly
mov es, ax ; segment
mov bx, 0x0000 ; offset
mov ah, 0xA0 ; color
mov al, 'L' ; char
mov word [es:bx], ax ; write to vidmem
Re: Printing to the screen
Posted: Tue Aug 05, 2008 2:24 pm
by chezzestix
Okay and just to make sure I know whats going on here is the code correct for what this paragraph is perscribing?
Before enabling the A20 with any of the methods described below it better to test whether the A20 address line is already enabled by the BIOS. This can be achieved by comparing, at boot time in real mode, the bootsector identifier (0xAA55) located at address 0000:7DFE with the value 1 MiB higher which is at address FFFF:7E0E. When the two values are different it means that the A20 is already enabled...
Code: Select all
mov ax,0xFFFF
mov es,ax
mov ax,0xAA55
cmp ax,[es:0x7DFE]
jne skipA20 ;A20 is enabled
Re: Printing to the screen
Posted: Wed Aug 06, 2008 7:54 am
by bewing
Not quite. The 0xFFFF segment points 16 bytes BELOW the 1M mark. So you have to add 16 to your offset. So you need the 0x7E0E offset.
Code: Select all
xor ax, ax
mov ds, ax
dec ax ; set ax to 0xffff
mov es,ax
mov ax,0xAA55
cmp ax,[es:0x7E0E]
jne skipA20 ;A20 is enabled
; but maybe the two values just happened to be equal
not ax
mov [es:0x7E0E], ax
cmp ax, [ds:0x7DFE]
jne skipA20 ;A20 is enabled