FreeBasic Bare Bones: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
m Bot: Replace deprecated source tag with syntaxhighlight |
mNo edit summary |
||
Line 20:
In FreeBasic, a pointer is defined by adding the Ptr keyword.
<syntaxhighlight lang="
Dim mypointer As Byte Ptr
</syntaxhighlight>
This one holds the location of a byte of memory.
<syntaxhighlight lang="
Dim mypointer As Long Ptr
</syntaxhighlight>
Line 31:
You can not use pointers straight away. Consider sending a letter with no address on it will not do any good. So we must first put an address in there. That leads to the question: how do we get an address. Some things have fixed addresses, like the video card.
You can also ask variables for their addresses.
<syntaxhighlight lang="
Dim variable as Byte
Dim pointer as Byte Ptr
Line 37:
</syntaxhighlight>
The @ returns the address of the variable that follows it.
<syntaxhighlight lang="
Dim pointer as Byte Ptr
Dim address as Long
Line 44:
</syntaxhighlight>
Here CPtr (Convert to Pointer) is used to create pointers. You give it a type (Byte Ptr) and the address. You can also change pointers:
<syntaxhighlight lang="
Dim pointer1 as Byte Ptr
Dim pointer2 as Long Ptr
Line 52:
You can access pointers with an index:
<syntaxhighlight lang="
Dim value as Long
Dim pointer as Long Pointer
Line 61:
Strings are useful, but tedious. A string is stored as a series of bytes in consecutive addresses. You can build a pointer to a string as well:
<syntaxhighlight lang="
Dim s as String
Dim pointer as String Ptr
Line 67:
</syntaxhighlight>
But since we do not have the Runtime, we have to use something that does not use it.
<syntaxhighlight lang="
Const s = "Text"
Dim pointer as Byte Ptr
Line 81:
Basic uses an borrowed trick to tell us the end of the string. After the last character, there will always be a 0. So if we read a string in order, we can tell when it has ended.
<syntaxhighlight lang="
Sub PrintString(src As Byte Ptr, x As Long, y As Long)
Line 177:
=== link.ld ===
<syntaxhighlight lang="text">
OUTPUT_FORMAT("elf32-i386")
ENTRY (loader)
Line 210:
}
}
</syntaxhighlight>
=== Build instructions ===
<syntaxhighlight lang="bash">
i586-elf-ld -T link.ld -o kernel.bin kernel.o
</syntaxhighlight>
<tt>kernel.bin</tt> can then be loaded by [[GRUB]]
|