SET PC, initialstate ; string definitions (currently using C-style strings) :version dat "0x42c v.0.1 128K MEM READY", 0 :input dat "> ", 0 ; commands :reddit dat "reddit", 0 :date dat "date", 0 :clean dat "clean", 0 :vers dat "version", 0 :echo dat "echo", 0 ; outputs :redditoutput dat "Reddit, the frontpage of the internet.", 0 :dateoutput dat "00:00:00 UTC on 1 January 1970", 0 :unrecognized dat "Unrecognized command '", 0 :unrecognizedEnd dat "'.", 0 :initialstate set [0x1335], 0x8000 ; vidmem set [0x1337], 0x1338 ; input buffer :main set a, version jsr printnl ; printnl(version) :inputready set a, input jsr print ; printnl(input) set pc, kbloop :kbloop ife [0x9000], 0 ; if there's no input... set pc, kbloop ife [0x9000], 0xA ; enter jsr enteredcommand ife [0x9000], 0x8 ; backspace jsr backspace set a, [0x9000] jsr printchar ; printchar([0x9000]) set a, [0x1337] ; 0x1337 is the pointer to my buffer string set b, [0x9000] jsr strcat ; strcat([0x1337], [0x9000]) add [0x1337], 1 set [0x9000], 0 set pc, kbloop :backspace sub [0x1335], 1 ; video pointer sub [0x1337], 1 ; delete last char set a, [0x1337] set [a], 0 set a, 0 jsr printchar ; printchar(0) sub [0x1335], 1 set [0x9000], 0 set pc, kbloop :reset set [0x1337], 0x1338 ; reset pointer set [0x1338], 0 ; reset string set [0x9000], 0 ; reset keyboard set [0x1336], 0 ; reset command recognized set pc, pop :enteredcommand set a, echo set b, 0x1338 jsr startswith ; startswith(echo, 0x1338) ife y, 1 set pc, echof set a, reddit set b, 0x1338 jsr strcmp ; strcmp(reddit, 0x1338) ife y, 1 set pc, redditf set a, date set b, 0x1338 jsr strcmp ; strcmp(date, 0x1338) ife y, 1 set pc, datef set a, clean set b, 0x1338 jsr strcmp ; strcmp(date, 0x1338) ife y, 1 set pc, cleanf set a, vers set b, 0x1338 jsr strcmp ; strcmp(vers, 0x1338) ife y, 1 set pc, versionf ifn a, 1 set pc, unrecognizedf :enterdone jsr reset set pc, inputready :echof jsr newline set a, echo jsr strlen add a, 1 ; +1 to strlen, for the space set b, 0x1338 add b, a ; start at `strlen' set a, b ; string pointer jsr printnl set a, 1 set pc, enterdone :cleanf jsr clearScreen set [0x1335], 0x8000 set a, 1 set pc, enterdone :clearScreen set i, sp set sp, 0x8200 :clearScreen_loop set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 set push, 0 ifg 0x8000, sp set pc, clearScreen_done set pc, clearScreen_loop :clearScreen_done set sp, i set pc, pop :versionf jsr newline jsr reset set a, 1 ; return 1 set pc, main :unrecognizedf jsr newline set a, unrecognized jsr print set a, 0x1338 jsr print set a, unrecognizedEnd jsr printnl set a, 1 ; return 1 set pc, enterdone :redditf set x, 1337 jsr printnl set a, redditoutput jsr printnl set a, 1 ; return 1 set pc, enterdone :datef jsr printnl set a, dateoutput jsr printnl set a, 1 ; return 1 set pc, enterdone ;; STANDARD FUNCTIONS OVER HER :startswith set y, 0 ife [a], 0 set pc, startswith_end_success ife [a], [b] jsr checkzero ifn [a], [b] set pc, pop ife y, 1 set pc, pop add a, 1 add b, 1 set pc, startswith :startswith_end_success set y, 1 set pc, pop :strlen set y, 0 :strlen_begin ife [a], 0 set pc, strlen_end add y, 1 add a, 1 set pc, strlen_begin :strlen_end set a, y set pc, pop :strcmp set y, 0 ife [a], [b] jsr checkzero ife y, 1 set pc, pop ifn [a], [b] set pc, pop add a, 1 add b, 1 set pc, strcmp :checkzero ife [a], 0 set y, 1 set pc, pop :strcat set [a], b add a, 1 add b, 1 set [a], 0 set pc, pop :printnl ; shortcut jsr print jsr newline set pc, pop :print set i, a :doprint ifg [0x1335], 0x81ff ; end of vidmem set [0x1335], 0x8000 ife [i], 0 set pc, pop set a, [i] jsr printchar add i, 1 set pc, doprint :printchar set b, [0x1335] bor a, 0xf100 ; color :D set [b], a add [0x1335], 1 set pc, pop :newline set i, [0x1335] mod i, 32 ; width set z, 32 sub z, i add [0x1335], z set pc, pop :end set pc, end