diff --git a/Makefile b/Makefile index ad4886f..a30dec5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ RYFS := $(CURDIR)/meta/ryfs/ryfs.py FOX32ASM := ../fox32asm/target/release/fox32asm +OKAMERON := $(CURDIR)/meta/okameron/okameron.lua GFX2INC := ../tools/gfx2inc/target/release/gfx2inc IMAGE_SIZE := 16777216 @@ -15,7 +16,6 @@ base_image/kernel.fxf: kernel/main.asm $(wildcard kernel/*.asm kernel/*/*.asm) $(FOX32ASM) $< $@ base_image/sh.fxf: applications/sh/main.asm $(wildcard applications/sh/*.asm applications/sh/*/*.asm) - echo $(wildcard applications/sh/**/*.asm) $(FOX32ASM) $< $@ base_image/barclock.fxf: applications/barclock/main.asm @@ -30,6 +30,11 @@ base_image/serial.fxf: applications/serial/main.asm $(wildcard applications/term base_image/foxpaint.fxf: applications/foxpaint/main.asm $(FOX32ASM) $< $@ +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 $@ + rm applications/okmpaint/okmpaint.asm + base_image/bg.fxf: applications/bg/main.asm $(FOX32ASM) $< $@ @@ -59,6 +64,7 @@ FILES = \ base_image/terminal.fxf \ base_image/serial.fxf \ base_image/foxpaint.fxf \ + base_image/okmpaint.fxf \ base_image/bg.fxf \ base_image/bg.raw \ base_image/launcher.fxf diff --git a/applications/okmpaint/OkmPaint.okm b/applications/okmpaint/OkmPaint.okm new file mode 100644 index 0000000..9db8cab --- /dev/null +++ b/applications/okmpaint/OkmPaint.okm @@ -0,0 +1,128 @@ +MODULE OkmPaint; + EXTERN PROCEDURE new_window, destroy_window, draw_str_to_overlay, get_window_overlay_number, + draw_widgets_to_window, draw_filled_rectangle_to_overlay, GetNextWindowEvent, DrawPixel, + save_state_and_yield_task, start_dragging_window, handle_widget_click, fill_window, + menu_update_event, menu_bar_click_event, close_menu: INT; + EXTERN eventArgs: ARRAY 8 OF INT; + EXTERN menuItemsRoot: POINTER TO CHAR; + EXTERN EVENT_TYPE_MOUSE_CLICK, + EVENT_TYPE_MOUSE_RELEASE, + EVENT_TYPE_BUTTON_CLICK, + EVENT_TYPE_MENU_BAR_CLICK, + EVENT_TYPE_MENU_UPDATE, + EVENT_TYPE_MENU_CLICK, + EVENT_TYPE_MENU_ACK, + WIDGET_TYPE_BUTTON: INT; + + TYPE Fox32OSButtonWidget = RECORD + next, id, type, text, fgColor, bgColor, width: INT; + x, y: SHORT; + END; + + VAR running: CHAR; + drawing: CHAR; + size: CHAR; + color: INT; + canvasWindow: ARRAY 36 OF CHAR; + + PROCEDURE Main(); + BEGIN + running := 1; + drawing := 0; + size := 2; + color := 0FFFFFFFFH; + + new_window(PTROF(canvasWindow), "OkmPaint canvas", 256, 256, 128, 128, PTROF(menuItemsRoot), 0); + + WHILE running DO + GetNextWindowEvent(PTROF(canvasWindow)); + + (* mouse click event *) + IF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_CLICK) THEN + IF (eventArgs[1] <| 8) & (eventArgs[2] <| 16) THEN + (* clicked the window's close box *) + destroy_window(PTROF(canvasWindow)); + running := 0; + ELSIF eventArgs[2] <| 16 THEN + (* clicked the window's title bar *) + start_dragging_window(PTROF(canvasWindow)); + ELSE + drawing := 1; + END; + + (* mouse release event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_RELEASE) THEN + drawing := 0; + + (* menu bar click event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_BAR_CLICK) THEN + menu_bar_click_event(PTROF(menuItemsRoot)); + + (* menu update event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_UPDATE) THEN + menu_update_event(); + + (* menu click event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_CLICK) THEN + MenuClickEvent(eventArgs[2], eventArgs[3]); + + (* menu ack event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_ACK) THEN + close_menu(PTROF(menuItemsRoot)); + END; + + IF drawing THEN + DrawPixel(); + END; + + save_state_and_yield_task(); + END; + END; + + PROCEDURE MenuClickEvent(rootIndex, itemIndex: INT;); + BEGIN + IF rootIndex = 0 THEN + (* Canvas menu *) + IF itemIndex = 0 THEN + (* Clear to Black *) + fill_window(0FF000000H, PTROF(canvasWindow)); + ELSIF itemIndex = 1 THEN + (* Clear to White *) + fill_window(0FFFFFFFFH, PTROF(canvasWindow)); + END; + ELSIF rootIndex = 1 THEN + (* Brush menu *) + IF itemIndex = 0 THEN + (* 2x2 *) + size := 2; + ELSIF itemIndex = 1 THEN + (* 4x4 *) + size := 4; + ELSIF itemIndex = 2 THEN + (* 8x8 *) + size := 8; + ELSIF itemIndex = 3 THEN + (* 16x16 *) + size := 16; + END; + ELSIF rootIndex = 2 THEN + (* Color menu *) + IF itemIndex = 0 THEN + (* Black *) + color := 0FF000000H; + ELSIF itemIndex = 1 THEN + (* White *) + color := 0FFFFFFFFH; + ELSIF itemIndex = 2 THEN + (* Red *) + color := 0FF0000FFH; + ELSIF itemIndex = 3 THEN + (* Green *) + color := 0FF00FF00H; + ELSIF itemIndex = 3 THEN + (* Blue *) + color := 0FFFF0000H; + END; + END; + END; +END. diff --git a/applications/okmpaint/start.asm b/applications/okmpaint/start.asm new file mode 100644 index 0000000..ae05889 --- /dev/null +++ b/applications/okmpaint/start.asm @@ -0,0 +1,74 @@ + call Main + call end_current_task + +DrawPixel: + mov r0, canvasWindow + call get_window_overlay_number + mov r2, r0 + mov r5, r0 + call get_mouse_position + call make_coordinates_relative_to_overlay + movz.8 r2, [size] + movz.8 r3, [size] + mov r4, [color] + call draw_filled_rectangle_to_overlay + ret + +GetNextWindowEvent: + push r8 + call get_next_window_event + mov r8, eventArgs + mov [r8], r0 + add r8, 4 + mov [r8], r1 + add r8, 4 + mov [r8], r2 + add r8, 4 + mov [r8], r3 + add r8, 4 + mov [r8], r4 + add r8, 4 + mov [r8], r5 + add r8, 4 + mov [r8], r6 + add r8, 4 + mov [r8], r7 + pop r8 + ret + +eventArgs: data.fill 0, 32 + +menuItemsRoot: + data.8 3 ; number of menus + data.32 menu_items_canvas_list data.32 menu_items_canvas_name ; pointer to menu list, pointer to menu name + data.32 menu_items_brush_list data.32 menu_items_brush_name ; pointer to menu list, pointer to menu name + data.32 menu_items_color_list data.32 menu_items_color_name ; pointer to menu list, pointer to menu name +menu_items_canvas_name: + data.8 6 data.strz "Canvas" ; text length, text, null-terminator +menu_items_brush_name: + data.8 5 data.strz "Brush" ; text length, text, null-terminator +menu_items_color_name: + data.8 5 data.strz "Color" ; text length, text, null-terminator +menu_items_canvas_list: + data.8 2 ; number of items + data.8 16 ; menu width (usually longest item + 2) + data.8 14 data.strz "Clear to Black" ; text length, text, null-terminator + data.8 14 data.strz "Clear to White" ; text length, text, null-terminator +menu_items_brush_list: + data.8 4 ; number of items + data.8 7 ; menu width (usually longest item + 2) + data.8 3 data.strz "2x2" ; text length, text, null-terminator + data.8 3 data.strz "4x4" ; text length, text, null-terminator + data.8 3 data.strz "8x8" ; text length, text, null-terminator + data.8 5 data.strz "16x16" ; text length, text, null-terminator +menu_items_color_list: + data.8 5 ; number of items + data.8 7 ; menu width (usually longest item + 2) + data.8 5 data.strz "Black" ; text length, text, null-terminator + data.8 5 data.strz "White" ; text length, text, null-terminator + data.8 3 data.strz "Red" ; text length, text, null-terminator + data.8 5 data.strz "Green" ; text length, text, null-terminator + data.8 4 data.strz "Blue" ; text length, text, null-terminator + + #include "../../../fox32rom/fox32rom.def" + #include "../../fox32os.def"