Skip to content

Commit

Permalink
ted: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed May 4, 2024
1 parent 8314c31 commit fc274d3
Show file tree
Hide file tree
Showing 5 changed files with 655 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ base_image/serial.fxf: applications/serial/main.asm $(wildcard applications/term
base_image/foxpaint.fxf: applications/foxpaint/main.asm
$(FOX32ASM) $< $@

base_image/ted.fxf: applications/ted/TEd.okm $(wildcard applications/ted/*.okm)
lua $(OKAMERON) -arch=fox32 -startup=applications/ted/start.asm $< \
applications/ted/OS.okm \
> applications/ted/ted.asm
$(FOX32ASM) applications/ted/ted.asm $@
rm applications/ted/ted.asm

base_image/okmpaint.fxf: applications/okmpaint/OkmPaint.okm $(wildcard applications/okmpaint/*.okm)
lua $(OKAMERON) -arch=fox32 -startup=applications/okmpaint/start.asm $< > applications/okmpaint/okmpaint.asm
$(FOX32ASM) applications/okmpaint/okmpaint.asm $@
Expand Down Expand Up @@ -95,7 +102,8 @@ FILES = \
base_image/okmpaint.fxf \
base_image/bg.fxf \
base_image/bg.raw \
base_image/launcher.fxf
base_image/launcher.fxf \
base_image/ted.fxf

ROM_FILES = \
base_image/startup.bat \
Expand All @@ -107,7 +115,8 @@ ROM_FILES = \
base_image/fetcher.fxf \
base_image/serial.fxf \
base_image/bg.fxf \
base_image/launcher.fxf
base_image/launcher.fxf \
base_image/ted.fxf

fox32os.img: $(BOOTLOADER) $(FILES)
$(RYFS) -s $(IMAGE_SIZE) -l fox32os -b $(BOOTLOADER) create $@.tmp
Expand Down
97 changes: 97 additions & 0 deletions applications/ted/OS.okm
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
(* FIXME: this module should probably be moved somewhere global so all applications can use it *)

MODULE OS;
CONST FILE_STRUCT_SIZE = 32;
FILL_TERM = 0F0H;
MOVE_CURSOR = 0F1H;
SET_COLOR = 0F2H;
FILL_LINE = 0F3H;
REDRAW_LINE = 0FEH;
REDRAW = 0FFH;

EXTERN PROCEDURE end_current_task, open, create, read, write, get_size, get_current_disk_id,
allocate_memory, free_memory, string_length, copy_memory_bytes, copy_string: INT;

EXTERN PROCEDURE brk: INT;

EXTERN eventArgs: ARRAY 8 OF INT;

EXTERN terminalStreamPtr: POINTER TO CHAR;
EXTERN arg0Ptr: POINTER TO CHAR;
EXTERN arg1Ptr: POINTER TO CHAR;
EXTERN arg2Ptr: POINTER TO CHAR;
EXTERN arg3Ptr: POINTER TO CHAR;

(* FIXME: this copies memory past the end of the old block *)
(* that is probably fine, as any allocated memory is assumed to contain garbage anyways *)
PROCEDURE Reallocate(oldBlock, newSize: PTR;): PTR;
VAR newBlock: PTR;
BEGIN
IF oldBlock = 0 THEN
newBlock := allocate_memory(newSize);
ELSE
newBlock := allocate_memory(newSize);
copy_memory_bytes(oldBlock, newBlock, newSize);
free_memory(oldBlock);
END;
RETURN(newBlock);
END;

PROCEDURE MoveMemory(source, destination: POINTER TO CHAR; size: INT;);
VAR tempBlock: POINTER TO CHAR;
BEGIN
IF size = 0 THEN RETURN(); END;
tempBlock := allocate_memory(size);
copy_memory_bytes(source, tempBlock, size);
copy_memory_bytes(tempBlock, destination, size);
free_memory(tempBlock);
END;

PROCEDURE Print(string: POINTER TO CHAR;);
BEGIN
write(string_length(string), terminalStreamPtr, string);
END;

PROCEDURE PrintChar(c: CHAR;);
VAR buffer: CHAR;
BEGIN
buffer := c;
write(1, terminalStreamPtr, PTROF(buffer));
END;

PROCEDURE PrintChars(string: POINTER TO CHAR; length: INT;);
VAR buffer: CHAR;
BEGIN
WHILE length DO
buffer := string^;
write(1, terminalStreamPtr, PTROF(buffer));
string := string + 1;
length := length - 1;
END;
END;

PROCEDURE PrintInt(i: INT; radix: CHAR;);
VAR string: ARRAY 11 OF CHAR;
temp: INT;
offset: CHAR;
BEGIN
offset := 0;
IF i = 0 THEN
PrintChar(48);
RETURN();
ELSE WHILE i DO
temp := i UMOD radix;
i := i /| radix;
IF temp <| 10 THEN
string[offset] := temp + 48; (* '0' *)
ELSE
string[offset] := temp + 65 - 10;
END;
offset := offset + 1;
END; END;
WHILE offset DO
PrintChar(string[offset - 1]);
offset := offset - 1;
END;
END;
END.
Loading

0 comments on commit fc274d3

Please sign in to comment.