mirror of
				https://gitlab.com/sortix/sortix.git
				synced 2023-02-13 20:55:38 -05:00 
			
		
		
		
	Hello is now a hello world sample ANSI text editor.
This commit is contained in:
		
							parent
							
								
									4db550c13b
								
							
						
					
					
						commit
						9ee93082c5
					
				
					 6 changed files with 41 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -38,8 +38,8 @@ hello: hello.o
 | 
			
		|||
	$(LD) $(LDFLAGS) hello.o -o hello.tmp $(LIBC)
 | 
			
		||||
	objcopy -O binary hello.tmp hello
 | 
			
		||||
 | 
			
		||||
hello.o: hello.c
 | 
			
		||||
	$(CC) $(CPPFLAGS) $(CFLAGS) -O2 -c hello.c -o hello.o
 | 
			
		||||
hello.o: hello.cpp
 | 
			
		||||
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -O2 -c hello.cpp -o hello.o
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f hello.tmp hello.o hello
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +0,0 @@
 | 
			
		|||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(int argc, char* argv[])
 | 
			
		||||
{
 | 
			
		||||
	printf("\e[m\e[0J");
 | 
			
		||||
	printf("OH MY GOD! Sortix can load programs!\n");
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										34
									
								
								hello/hello.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								hello/hello.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
#include <stdio.h>
 | 
			
		||||
#include <libmaxsi/sortix-keyboard.h>
 | 
			
		||||
 | 
			
		||||
int main(int argc, char* argv[])
 | 
			
		||||
{
 | 
			
		||||
	printf("\e[m\e[0J");
 | 
			
		||||
	printf("Hello World: Welcome to Sortix! This is a program running in user-space.\n"
 | 
			
		||||
	       "This program is a probably the worst text editor ever made.\n"
 | 
			
		||||
	       "You are currently using the buggy USA keyboard layout.\n"
 | 
			
		||||
	       "This terminal is controlled using ANSI Escape Sequences:\n"
 | 
			
		||||
	       " - Type \e[32mESC [ 2 J\e[m to clear the screen\n"
 | 
			
		||||
	       );
 | 
			
		||||
 | 
			
		||||
	while (true)
 | 
			
		||||
	{
 | 
			
		||||
		unsigned method = System::Keyboard::POLL;
 | 
			
		||||
		uint32_t codepoint = System::Keyboard::ReceieveKeystroke(method);
 | 
			
		||||
 | 
			
		||||
		if ( codepoint == 0 ) { continue; }
 | 
			
		||||
		if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
 | 
			
		||||
		if ( codepoint == Maxsi::Keyboard::UP ) { printf("\e[A"); continue; }
 | 
			
		||||
		if ( codepoint == Maxsi::Keyboard::DOWN ) { printf("\e[B"); continue; }
 | 
			
		||||
		if ( codepoint == Maxsi::Keyboard::RIGHT ) { printf("\e[C"); continue; }
 | 
			
		||||
		if ( codepoint == Maxsi::Keyboard::LEFT ) { printf("\e[D"); continue; }
 | 
			
		||||
		if ( codepoint == Maxsi::Keyboard::ESC ) { printf("\e"); continue; }
 | 
			
		||||
		if ( codepoint >= 0x80 ) { continue; }
 | 
			
		||||
 | 
			
		||||
		char msg[2]; msg[0] = codepoint; msg[1] = '\0';
 | 
			
		||||
		printf(msg);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -29,10 +29,10 @@
 | 
			
		|||
#ifdef	__cplusplus
 | 
			
		||||
	#define __BEGIN_DECLS	extern "C" {
 | 
			
		||||
	#define __END_DECLS		}
 | 
			
		||||
	#define restrict
 | 
			
		||||
#else
 | 
			
		||||
	#define __BEGIN_DECLS
 | 
			
		||||
	#define __END_DECLS
 | 
			
		||||
	#define restrict
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define __POSIX_NO_OBSOLETE
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ namespace Sortix
 | 
			
		|||
				// Check that we can use this kind of RAM.
 | 
			
		||||
				if ( MMap->type != 1 ) { continue; }
 | 
			
		||||
 | 
			
		||||
				Log::PrintF("RAM at 0x%64x\t of length 0x%64zx\n", MMap->addr, MMap->len);
 | 
			
		||||
				//Log::PrintF("RAM at 0x%64x\t of length 0x%64zx\n", MMap->addr, MMap->len);
 | 
			
		||||
 | 
			
		||||
				// The kernels code may split this memory area into multiple pieces.
 | 
			
		||||
				struct { uintptr_t Base; size_t Length; } Entries[2]; nat Num = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -150,7 +150,7 @@ namespace Sortix
 | 
			
		|||
			Fragmentize();
 | 
			
		||||
 | 
			
		||||
#ifndef PLATFORM_SERIAL
 | 
			
		||||
			Log::PrintF("%zu pages are available for paging (%zu MiB RAM)\n", PagesTotal, PagesTotal >> 8 /* * 0x1000 / 1024 / 1024*/);
 | 
			
		||||
			//Log::PrintF("%zu pages are available for paging (%zu MiB RAM)\n", PagesTotal, PagesTotal >> 8 /* * 0x1000 / 1024 / 1024*/);
 | 
			
		||||
#endif
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -235,6 +235,7 @@ namespace Sortix
 | 
			
		|||
 | 
			
		||||
		void Init()
 | 
			
		||||
		{
 | 
			
		||||
#if 0
 | 
			
		||||
			Log::Print("PCI Devices: ");
 | 
			
		||||
 | 
			
		||||
			for ( nat Bus = 0; Bus < 256; Bus++ )
 | 
			
		||||
| 
						 | 
				
			
			@ -264,6 +265,7 @@ namespace Sortix
 | 
			
		|||
			}
 | 
			
		||||
 | 
			
		||||
			Log::Print("\b\b\n");
 | 
			
		||||
#endif
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		uint32_t ReadLong(uint8_t Bus, uint8_t Slot, uint8_t Function, uint8_t Offset)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue