; Default DCPU OS
; by Markus Persson


set PC, start

#include macros.asm
#include mem.asm
#include display.asm
#include keyboard.asm
			
:str_empty	dat 0
:str_tmp	dat 0, 0
:str_1		dat "    **** DCPU BASIC 1.0 ****    ", 0
:str_2		dat "  Copyright 2012 Mojang, Earth  ", 0
:str_3		dat "       64K RAM   40K FREE       ", 0
:str_rdy	dat "Ready.", 0

:start
			

:reloop
			setbg(0x9)
			clear(0x1)


			println(str_empty, 0x91)
			println(str_1, 0x91)
			println(str_2, 0x91)
			println(str_3, 0x91)
			println(str_empty, 0x91)
			println(str_rdy, 0x91)
			set a, [screen_p]
			add a, 0x8000
			set [a], 0x919b

:mainloop
			nextkey(a)
			ifn a,0
				jsr handlekey
			jmp mainloop

:handlekey
			ife a,8
				jmp backspace
			ife a,10
				jmp return
			ifg 0x1f,a
				ret
				
			set [str_tmp], a
			print(str_tmp, 0x91)
			set a, [screen_p]
			add a, 0x8000
			set [a], 0x919b
			ret

:backspace
			set a, [screen_p]
			ife a, 0
				ret
			add a, 0x8000
			set [a], 0x9120
			sub [screen_p], 1
			set a, [screen_p]
			add a, 0x8000
			set [a], 0x919b
			ret

:return
			set a, [screen_p]
			add a, 0x8000
			set [a], 0x9120
			
			println(str_empty, 0x91)

			set a, [screen_p]
			add a, 0x8000
			set [a], 0x919b
			ret
			