Skip to main content

[kernel]

# =============================================================================
# KERNEL (FRAMEWORK FILE) VERSION 2025-11-29
# =============================================================================
# You cannot modify this file. The kernel implements essential operations
# that the compiler depends upon. The funcs marked as "chombit" are
# implemented in a separate file called "kernel.casm". The funcs marked as
# "intrinsic" are generated directly by the compiler.

type string is byte[]

# -----------------------------------------------------------------------------
# If a class extends from class_id_base, then you can use class_id() with it.
class class_id_base
end class

# -----------------------------------------------------------------------------
# Array whose elements are 1 byte in size
class array_1
func resize(new_size: int)
chombit
end func

func copy_from(source: array_1)
chombit
end func
end class

# -----------------------------------------------------------------------------
# Array whose elements are 2 bytes in size
class array_2
func resize(new_size: int)
chombit
end func

func copy_from(source: array_2)
chombit
end func
end class

# -----------------------------------------------------------------------------
# Array whose elements are 3 bytes in size
class array_3
func resize(new_size: int)
chombit
end func

func copy_from(source: array_3)
chombit
end func
end class

# -----------------------------------------------------------------------------
# Array whose elements are 4 bytes in size
class array_4
func resize(new_size: int)
chombit
end func

func copy_from(source: array_4)
chombit
end func
end class

# -----------------------------------------------------------------------------
# Array whose elements are pointers
class array_p
func resize(new_size: int)
chombit
end func

func copy_from(source: array_p)
chombit
end func
end class

# -----------------------------------------------------------------------------
module math
func abs(x: int): int
intrinsic
end func

func sign(x: int): int
intrinsic
end func

func bit_and(x: int, y: int): int
intrinsic
end func

func bit_or(x: int, y: int): int
intrinsic
end func

func bit_xor(x: int, y: int): int
intrinsic
end func

func bit_not(x: int): int
intrinsic
end func

func shift_left(value: int, shift_amount: int): int
intrinsic
end func

func shift_right_signed(value: int, shift_amount: int): int
intrinsic
end func

func shift_right_unsigned(value: int, shift_amount: int): int
intrinsic
end func
end module

# -----------------------------------------------------------------------------
module kernel
# The text console uses 8 x 8 tiles, with room for 40 rows and 28 cols,
# however its tilemap grid has 64 rows x 32 cols = 2048 pairs.
# (There are 24 unused columns on the right and 4 unused rows on the bottom.)
inset console_grid: ^pair[size 2048] located at $10_0000 # ..$10_0fff

func trace_num(id: byte)
intrinsic
end func

func trace(message: string)
intrinsic
end func

func fail(message: string)
intrinsic
end func

func sleep()
intrinsic
end func

func memcpy(target: int, source: int, num_bytes: int)
chombit
end func

func memset_byte(target: int, value: byte, num_bytes: int)
chombit
end func

func memset_pair(target: int, value: pair, num_pairs: int)
chombit
end func

func collect_garbage()
chombit
end func
end module