-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.fxf | ||
*.rsf | ||
*.bin | ||
*.img | ||
demos/audio/audio.raw | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
; widget demo, with a window created from an external .rsf resource file | ||
|
||
; open and read resource.rsf into a buffer | ||
; exit if file not found | ||
call get_current_disk_id | ||
mov r1, r0 | ||
mov r0, window_rsf_filename | ||
mov r2, window_rsf_struct | ||
call open | ||
cmp r0, 0 | ||
ifz call end_current_task | ||
mov r0, window_rsf_struct | ||
call get_size | ||
push r0 | ||
call allocate_memory ; TODO: error handling? | ||
mov [window_rsf_buffer_ptr], r0 | ||
pop r0 | ||
mov r1, window_rsf_struct | ||
mov r2, [window_rsf_buffer_ptr] | ||
call read | ||
|
||
; extract the resource data from the .rsf | ||
mov r0, [window_rsf_buffer_ptr] | ||
call get_res_in_fxf | ||
mov r1, r0 | ||
|
||
; create the window | ||
mov r0, window_struct | ||
; r1 set above | ||
call new_window_from_resource | ||
|
||
; free the memory used by the .rsf as it is no longer needed | ||
mov r0, [window_rsf_buffer_ptr] | ||
call free_memory | ||
|
||
; fill the window with white | ||
mov r0, 0xFFFFFFFF | ||
mov r1, window_struct | ||
call fill_window | ||
|
||
; redraw the widgets after filling the window | ||
mov r0, window_struct | ||
call draw_widgets_to_window | ||
|
||
event_loop: | ||
mov r0, window_struct | ||
call get_next_window_event | ||
|
||
; did the user click somewhere in the window? | ||
cmp r0, EVENT_TYPE_MOUSE_CLICK | ||
ifz call mouse_click_event | ||
|
||
call yield_task | ||
rjmp event_loop | ||
|
||
mouse_click_event: | ||
push r0 | ||
|
||
; check if we are attempting to drag or close the window | ||
cmp r2, 16 | ||
iflteq jmp drag_or_close_window | ||
|
||
; check if we are clicking on a widget | ||
mov r0, window_struct | ||
call handle_widget_click | ||
|
||
pop r0 | ||
ret | ||
|
||
drag_or_close_window: | ||
cmp r1, 8 | ||
iflteq jmp close_window | ||
mov r0, window_struct | ||
call start_dragging_window | ||
pop r0 | ||
ret | ||
close_window: | ||
mov r0, window_struct | ||
call destroy_window | ||
call end_current_task | ||
|
||
window_struct: data.fill 0, 40 | ||
window_rsf_filename: data.strz "resource.rsf" | ||
window_rsf_struct: data.fill 0, 32 | ||
window_rsf_buffer_ptr: data.32 0 | ||
|
||
#include "../../../fox32rom/fox32rom.def" | ||
#include "../../../fox32os/fox32os.def" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
; RES binaries can be "enclosed" in an FXF binary in order to handle relocations | ||
; when a RES is enclosed in an FXF, it becomes a .rsf file instead of a standard .res file | ||
; this .rsf.asm file should be assembled into a .res.fxf, then renamed to .rsf | ||
|
||
const WIDGET_TYPE_LABEL: 0x00000002 | ||
|
||
; format: "RES"/"RSF" magic bytes, version, number of resource IDs | ||
; if "RES", no relocations; if "RSF", relocations applied | ||
data.str "RSF" data.8 0 data.8 3 | ||
|
||
; format: 3 character null-terminated ID, pointer to data, size | ||
data.strz "WIN" data.32 win data.32 40 | ||
data.strz "MNU" data.32 mnu data.32 32 ; REMEMBER TO CHANGE THIS SIZE!! | ||
data.strz "WID" data.32 wid data.32 32 ; REMEMBER TO CHANGE THIS SIZE!! | ||
|
||
; WIN resource layout (40 bytes): | ||
; data.fill 0, 32 - null-terminated window title | ||
; data.16 width - width of this window | ||
; data.16 height - height of this window, not including the title bar | ||
; data.16 x_pos - X coordinate of this window (top left corner of title bar) | ||
; data.16 y_pos - Y coordinate of this window (top left corner of title bar) | ||
win: | ||
data.str "RES demo" data.fill 0, 24 ; 32 byte window title | ||
data.16 128 ; width | ||
data.16 128 ; height | ||
data.16 64 ; x_pos | ||
data.16 64 ; y_pos | ||
|
||
mnu: | ||
data.8 1 ; number of menus | ||
data.32 menu_items_hello_list data.32 menu_items_hello_name ; pointer to menu list, pointer to menu name | ||
menu_items_hello_name: | ||
data.8 5 data.strz "Hello"; text length, text, null-terminator | ||
menu_items_hello_list: | ||
data.8 1 ; number of items | ||
data.8 14 ; menu width (usually longest item + 2) | ||
data.8 12 data.strz "Hello World!" ; text length, text, null-terminator | ||
|
||
wid: | ||
data.32 0 ; next_ptr | ||
data.32 0 ; id | ||
data.32 WIDGET_TYPE_LABEL ; type | ||
data.32 wid_text ; text_ptr | ||
data.32 0xFF000000 ; foreground_color | ||
data.32 0xFFFFFFFF ; background_color | ||
data.16 0 ; reserved | ||
data.16 0 ; reserved | ||
data.16 16 ; x_pos | ||
data.16 32 ; y_pos | ||
wid_text: data.strz "Hello World!" |