.global _start
_start:
	la	s1, logodata
	la	s2, logodataend
	sub	s2, s2, s1
	srli	s2, s2, 2

1:	lw	s3, 0(s1)
	addi	s1, s1, 4

	# Set color: \e[38;2;{};{};{}m
	srli	a0, s3, 8
	call	set_color

	# Print character
	li	a0, 0xff
	and	a0, a0, s3
	ecall

	addi	s2, s2, -1
	bne	s2, zero, 1b

	# End of program
	.long	0

set_color:
	addi	sp, sp, -16
	sd	s0, 0(sp)
	sd	ra, 8(sp)
	mv	s0, a0

	li	a0, 0x1b # \e
	ecall
	li	a0, '['
	ecall
	li	a0, '3'
	ecall
	li	a0, '8'
	ecall
	li	a0, ';'
	ecall
	li	a0, '2'
	ecall
	li	a0, ';'
	ecall

	srli	a0, s0, 16
	li	a1, 0xff
	and	a0, a0, a1
	call	print_byte_dec

	li	a0, ';'
	ecall

	srli	a0, s0, 8
	li	a1, 0xff
	and	a0, a0, a1
	call	print_byte_dec

	li	a0, ';'
	ecall

	li	a0, 0xff
	and	a0, a0, s0
	call	print_byte_dec

	li	a0, 'm'
	ecall

	ld	ra, 8(sp)
	ld	s0, 0(sp)
	addi	sp, sp, 16
	ret

# fastcall sort of function, uses only
print_byte_dec:
	mv	a2, a0

	li	a0, '0' # hundreds
	li	a1, 100
1:	blt	a2, a1, 2f
	addi	a0, a0, 1
	sub	a2, a2, a1
	j	1b
2:	ecall

	li	a0, '0' # tens
	li	a1, 10
1:	blt	a2, a1, 2f
	addi	a0, a0, 1
	sub	a2, a2, a1
	j	1b
2:	ecall

	addi	a0, a2, '0'
	ecall
	ret

logodata:
#include "logo.s"
logodataend:
