2022-05-19 23:15:40 +02:00
|
|
|
; fox32os kernel
|
|
|
|
|
2023-01-26 03:13:45 +01:00
|
|
|
const LOAD_ADDRESS: 0x03000000
|
|
|
|
|
2022-05-19 23:15:40 +02:00
|
|
|
const FOX32OS_VERSION_MAJOR: 0
|
|
|
|
const FOX32OS_VERSION_MINOR: 1
|
2022-10-28 07:49:55 +02:00
|
|
|
const FOX32OS_VERSION_PATCH: 1
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2022-06-25 01:14:06 +02:00
|
|
|
const SYSTEM_STACK: 0x01FFF800
|
2022-05-19 23:15:40 +02:00
|
|
|
const BACKGROUND_COLOR: 0xFF674764
|
|
|
|
const TEXT_COLOR: 0xFFFFFFFF
|
|
|
|
|
2022-05-22 01:55:56 +02:00
|
|
|
jmp entry
|
|
|
|
|
|
|
|
; system jump table
|
2022-10-28 07:49:55 +02:00
|
|
|
org.pad 0x00000010
|
|
|
|
jump_table:
|
2022-05-22 01:55:56 +02:00
|
|
|
data.32 get_os_version
|
|
|
|
|
|
|
|
; FXF jump table
|
2022-10-28 07:49:55 +02:00
|
|
|
org.pad 0x00000110
|
2022-05-22 01:55:56 +02:00
|
|
|
data.32 parse_fxf_binary
|
|
|
|
|
|
|
|
; task jump table
|
2022-10-28 07:49:55 +02:00
|
|
|
org.pad 0x00000210
|
2022-05-22 01:55:56 +02:00
|
|
|
data.32 new_task
|
|
|
|
data.32 yield_task
|
|
|
|
data.32 end_current_task
|
2022-06-25 02:40:52 +02:00
|
|
|
data.32 get_current_task_id
|
|
|
|
data.32 get_unused_task_id
|
2022-08-12 02:35:13 +02:00
|
|
|
data.32 is_task_id_used
|
2023-02-08 00:58:13 +01:00
|
|
|
data.32 save_state_and_yield_task
|
2022-05-22 01:55:56 +02:00
|
|
|
|
|
|
|
; memory jump table
|
2022-10-28 07:49:55 +02:00
|
|
|
org.pad 0x00000310
|
2022-05-22 01:55:56 +02:00
|
|
|
data.32 allocate_memory
|
2022-06-23 09:30:59 +02:00
|
|
|
data.32 free_memory
|
2022-05-22 01:55:56 +02:00
|
|
|
|
2022-10-06 01:15:36 +02:00
|
|
|
; window jump table
|
2022-10-28 07:49:55 +02:00
|
|
|
org.pad 0x00000410
|
2022-10-06 01:15:36 +02:00
|
|
|
data.32 new_window
|
|
|
|
data.32 destroy_window
|
|
|
|
data.32 new_window_event
|
|
|
|
data.32 get_next_window_event
|
|
|
|
data.32 draw_title_bar_to_window
|
|
|
|
data.32 move_window
|
|
|
|
data.32 fill_window
|
|
|
|
data.32 get_window_overlay_number
|
|
|
|
data.32 start_dragging_window
|
2023-01-22 22:47:55 +01:00
|
|
|
data.32 new_messagebox
|
2023-01-25 02:10:48 +01:00
|
|
|
data.32 get_active_window_struct
|
2022-10-06 01:15:36 +02:00
|
|
|
|
2022-10-15 01:39:40 +02:00
|
|
|
; VFS jump table
|
2022-10-28 07:49:55 +02:00
|
|
|
org.pad 0x00000510
|
2022-10-15 01:39:40 +02:00
|
|
|
data.32 open
|
|
|
|
data.32 seek
|
|
|
|
data.32 tell
|
|
|
|
data.32 read
|
|
|
|
data.32 write
|
|
|
|
|
2022-12-28 03:01:55 +01:00
|
|
|
; widget jump table
|
2023-01-21 09:17:10 +01:00
|
|
|
org.pad 0x00000610
|
2022-12-28 03:01:55 +01:00
|
|
|
data.32 draw_widgets_to_window
|
|
|
|
data.32 handle_widget_click
|
2022-10-28 07:49:55 +02:00
|
|
|
jump_table_end:
|
2022-10-15 01:53:41 +02:00
|
|
|
|
2022-05-19 23:15:40 +02:00
|
|
|
; initialization code
|
|
|
|
entry:
|
2022-06-25 01:14:06 +02:00
|
|
|
mov rsp, SYSTEM_STACK
|
|
|
|
|
2023-01-26 03:13:45 +01:00
|
|
|
; before doing anything, check if we are running on top of an existing instance of the kernel
|
|
|
|
; we can do this by comparing our load address to the known load address that the bootloader loads us to
|
|
|
|
; only the high 16 bits are checked
|
|
|
|
rcall 6
|
|
|
|
pop r0
|
|
|
|
mov.16 r0, 0
|
|
|
|
cmp r0, LOAD_ADDRESS
|
|
|
|
ifz jmp entry_ok
|
|
|
|
|
|
|
|
; if it appears that we're running on top of an existing kernel, then show a messagebox and exit
|
|
|
|
; call the messagebox routines of the existing kernel
|
|
|
|
mov r0, 0
|
|
|
|
mov r1, kernelception_error_str
|
|
|
|
mov r2, 0
|
|
|
|
mov r3, 64
|
|
|
|
mov r4, 64
|
|
|
|
mov r5, 184
|
|
|
|
call [0x00000C34] ; new_messagebox
|
|
|
|
call [0x00000A18] ; end_current_task
|
|
|
|
rjmp 0
|
|
|
|
|
|
|
|
entry_ok:
|
2022-05-19 23:15:40 +02:00
|
|
|
; clear the background
|
|
|
|
mov r0, BACKGROUND_COLOR
|
|
|
|
call fill_background
|
|
|
|
|
2022-06-23 09:30:59 +02:00
|
|
|
; initialize the memory allocator
|
|
|
|
call initialize_allocator
|
|
|
|
|
2022-12-29 21:02:03 +01:00
|
|
|
; draw the bottom bar
|
|
|
|
mov r0, bottom_bar_str_0
|
|
|
|
mov r1, 8
|
|
|
|
mov r2, 448
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r3, TEXT_COLOR
|
|
|
|
mov r4, 0x00000000
|
2022-12-29 21:02:03 +01:00
|
|
|
call draw_str_to_background
|
|
|
|
mov r0, bottom_bar_patterns
|
|
|
|
mov r1, 1
|
|
|
|
mov r2, 16
|
|
|
|
call set_tilemap
|
|
|
|
mov r1, 0
|
|
|
|
mov r2, 464
|
|
|
|
mov r31, 640
|
|
|
|
draw_bottom_bar_loop:
|
|
|
|
mov r4, r31
|
|
|
|
rem r4, 2
|
|
|
|
cmp r4, 0
|
|
|
|
ifz mov r0, 0
|
|
|
|
ifnz mov r0, 1
|
|
|
|
call draw_tile_to_background
|
|
|
|
inc r1
|
|
|
|
loop draw_bottom_bar_loop
|
|
|
|
mov r0, 10
|
|
|
|
mov r1, 464
|
|
|
|
mov r2, 20
|
|
|
|
mov r3, 16
|
|
|
|
mov r4, 0xFFFFFFFF
|
|
|
|
call draw_filled_rectangle_to_background
|
|
|
|
mov r0, bottom_bar_str_1
|
|
|
|
mov r1, 12
|
|
|
|
mov r2, 464
|
|
|
|
mov r3, 0xFF000000
|
|
|
|
mov r4, 0xFFFFFFFF
|
|
|
|
call draw_str_to_background
|
|
|
|
mov r0, bottom_bar_str_2
|
|
|
|
mov r1, 488
|
|
|
|
mov r2, 464
|
|
|
|
mov r3, 0xFF000000
|
|
|
|
mov r4, 0xFFFFFFFF
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r10, FOX32OS_VERSION_MAJOR
|
|
|
|
mov r11, FOX32OS_VERSION_MINOR
|
|
|
|
mov r12, FOX32OS_VERSION_PATCH
|
|
|
|
call draw_format_str_to_background
|
|
|
|
|
2022-10-28 07:49:55 +02:00
|
|
|
; copy the jump table to 0x00000810
|
|
|
|
mov r0, jump_table
|
|
|
|
mov r1, 0x00000810
|
|
|
|
mov r2, jump_table_end
|
|
|
|
sub r2, jump_table
|
|
|
|
call copy_memory_bytes
|
|
|
|
|
2022-10-06 01:15:36 +02:00
|
|
|
; check if a disk is inserted as disk 1
|
|
|
|
; if so, skip checking startup.cfg and just run disk 1
|
|
|
|
in r31, 0x80001001
|
|
|
|
cmp r31, 0
|
|
|
|
ifnz jmp boot_disk_1
|
2023-02-02 00:43:21 +01:00
|
|
|
try_startup:
|
2022-05-19 23:15:40 +02:00
|
|
|
; open startup.cfg
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r0, startup_cfg
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r1, 0
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r2, startup_cfg_struct
|
2022-05-19 23:15:40 +02:00
|
|
|
call ryfs_open
|
|
|
|
cmp r0, 0
|
2023-02-02 00:43:21 +01:00
|
|
|
ifz jmp startup_error
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2022-09-10 01:37:13 +02:00
|
|
|
; load a startup task
|
|
|
|
load_startup_task:
|
|
|
|
; load 11 bytes of startup.cfg into startup_file
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r0, 11
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r1, startup_cfg_struct
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r2, startup_file
|
|
|
|
call ryfs_read
|
|
|
|
|
|
|
|
; open the actual startup file
|
|
|
|
mov r0, startup_file
|
|
|
|
mov r1, 0
|
|
|
|
mov r2, startup_file_struct
|
|
|
|
call ryfs_open
|
|
|
|
cmp r0, 0
|
2022-06-22 04:38:45 +02:00
|
|
|
ifz jmp boot_disk_1
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2022-06-24 00:16:55 +02:00
|
|
|
; allocate memory for the startup file
|
|
|
|
mov r0, startup_file_struct
|
|
|
|
call ryfs_get_size
|
|
|
|
call allocate_memory
|
|
|
|
cmp r0, 0
|
|
|
|
ifz jmp memory_error
|
2022-09-10 01:37:13 +02:00
|
|
|
mov [startup_file_binary_ptr], r0
|
|
|
|
|
|
|
|
; allocate 64KiB for the startup file's stack
|
|
|
|
mov r0, 65536
|
|
|
|
call allocate_memory
|
|
|
|
cmp r0, 0
|
|
|
|
ifz jmp memory_error
|
|
|
|
mov [startup_file_stack_ptr], r0
|
2022-06-24 00:16:55 +02:00
|
|
|
|
|
|
|
; read the startup file into memory
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r0, startup_file_struct
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r1, [startup_file_binary_ptr]
|
2022-05-19 23:15:40 +02:00
|
|
|
call ryfs_read_whole_file
|
|
|
|
|
2022-05-22 01:55:56 +02:00
|
|
|
; relocate and execute it as a new task
|
2022-06-24 00:16:55 +02:00
|
|
|
mov r0, r1
|
2022-05-22 01:55:56 +02:00
|
|
|
call parse_fxf_binary
|
2022-06-24 00:16:55 +02:00
|
|
|
mov r3, r1
|
2022-05-22 01:55:56 +02:00
|
|
|
mov r1, r0
|
2022-09-10 01:37:13 +02:00
|
|
|
movz.8 r0, [next_task_id]
|
|
|
|
mov r2, [startup_file_stack_ptr]
|
|
|
|
add r2, 65536
|
2022-06-23 09:21:00 +02:00
|
|
|
sub r2, 4
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r4, [startup_file_stack_ptr]
|
2022-05-22 01:55:56 +02:00
|
|
|
call new_task
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2022-09-10 01:37:13 +02:00
|
|
|
; when the startup file yields for the first time, we'll end up back here
|
|
|
|
; now, check to see if startup.cfg has any other entries
|
|
|
|
; we do this by checking to see if the size of startup.cfg is less than or equal to 12 * next_task_id bytes
|
|
|
|
inc.8 [next_task_id]
|
|
|
|
mov r0, startup_cfg_struct
|
|
|
|
call ryfs_get_size
|
|
|
|
movz.8 r1, [next_task_id]
|
|
|
|
mul r1, 12
|
|
|
|
cmp r0, r1
|
|
|
|
iflteq jmp no_other_tasks
|
|
|
|
|
|
|
|
; seek forward one byte to skip the linefeed
|
|
|
|
mov r0, startup_cfg_struct
|
|
|
|
call ryfs_tell
|
|
|
|
inc r0
|
|
|
|
mov r1, startup_cfg_struct
|
|
|
|
call ryfs_seek
|
|
|
|
|
|
|
|
; load the next task
|
|
|
|
jmp load_startup_task
|
|
|
|
|
|
|
|
no_other_tasks:
|
2022-10-06 01:15:36 +02:00
|
|
|
; start the event manager task
|
|
|
|
call start_event_manager_task
|
|
|
|
|
2022-06-24 00:16:55 +02:00
|
|
|
; jump back to it without adding this "task" (not really a task) into the queue.
|
|
|
|
; end_current_task_no_mark_no_free is used specifically because it doesn't mark
|
|
|
|
; the current task (still set to 0) as unused, and it doesn't free the memory
|
|
|
|
; block.
|
|
|
|
; this does not return.
|
|
|
|
call end_current_task_no_mark_no_free
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2023-02-02 00:43:21 +01:00
|
|
|
; try loading the raw contents of disk 1 as an FXF binary
|
2022-06-22 04:38:45 +02:00
|
|
|
; if disk 1 is not inserted, then fail
|
|
|
|
boot_disk_1:
|
|
|
|
; check if a disk is inserted as disk 1
|
|
|
|
in r31, 0x80001001
|
|
|
|
cmp r31, 0
|
|
|
|
ifz jmp startup_error
|
|
|
|
|
|
|
|
; a disk is inserted, load it!!
|
2022-06-24 00:16:55 +02:00
|
|
|
|
|
|
|
; allocate memory for the startup file
|
|
|
|
; r31 contains disk size
|
|
|
|
mov r0, r31
|
|
|
|
call allocate_memory
|
|
|
|
cmp r0, 0
|
|
|
|
ifz jmp memory_error
|
|
|
|
|
2022-06-22 04:38:45 +02:00
|
|
|
div r31, 512
|
|
|
|
inc r31
|
|
|
|
|
2022-06-24 00:16:55 +02:00
|
|
|
mov r2, r0 ; destination pointer
|
|
|
|
mov r5, r0
|
2022-06-22 04:38:45 +02:00
|
|
|
mov r0, 0 ; sector counter
|
2022-06-24 00:16:55 +02:00
|
|
|
mov r3, 0x80003001 ; command to read a sector from disk 1 into memory
|
2022-06-22 04:38:45 +02:00
|
|
|
mov r4, 0x80002000 ; command to set the location of the buffer
|
|
|
|
boot_disk_1_loop:
|
|
|
|
out r4, r2 ; set the memory buffer location
|
|
|
|
out r3, r0 ; read the current sector into memory
|
|
|
|
inc r0 ; increment sector counter
|
|
|
|
add r2, 512 ; increment the destination pointer
|
|
|
|
loop boot_disk_1_loop
|
|
|
|
|
2022-06-24 00:16:55 +02:00
|
|
|
mov r1, r5
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r0, r5
|
|
|
|
call parse_fxf_binary
|
2023-02-02 00:43:21 +01:00
|
|
|
cmp r0, 0
|
|
|
|
ifz jmp disk_1_is_not_fxf
|
2022-09-10 01:37:13 +02:00
|
|
|
mov r3, r1
|
|
|
|
mov r1, r0
|
|
|
|
movz.8 r0, [next_task_id]
|
|
|
|
mov r2, rsp
|
|
|
|
sub r2, 4
|
|
|
|
mov r4, 0 ; don't attempt to free any stack block if the task ends
|
|
|
|
call new_task
|
2022-12-25 22:54:45 +01:00
|
|
|
jmp no_other_tasks
|
2022-06-22 04:38:45 +02:00
|
|
|
|
2023-02-02 00:43:21 +01:00
|
|
|
; disk 1 was found to not be a valid FXF binary
|
|
|
|
; free the memory allocated for it and instead just keep it mounted as a disk
|
|
|
|
disk_1_is_not_fxf:
|
|
|
|
mov r0, r5
|
|
|
|
call free_memory
|
|
|
|
jmp try_startup
|
|
|
|
|
2022-05-19 23:15:40 +02:00
|
|
|
startup_error:
|
2022-05-20 01:37:49 +02:00
|
|
|
mov r0, BACKGROUND_COLOR
|
|
|
|
call fill_background
|
|
|
|
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r0, startup_error_str
|
|
|
|
mov r1, 16
|
2022-05-20 01:37:49 +02:00
|
|
|
mov r2, 464
|
2022-05-19 23:15:40 +02:00
|
|
|
mov r3, TEXT_COLOR
|
|
|
|
mov r4, 0x00000000
|
2022-05-20 01:37:49 +02:00
|
|
|
mov r10, FOX32OS_VERSION_MAJOR
|
|
|
|
mov r11, FOX32OS_VERSION_MINOR
|
|
|
|
mov r12, FOX32OS_VERSION_PATCH
|
|
|
|
call draw_format_str_to_background
|
2022-05-19 23:15:40 +02:00
|
|
|
rjmp 0
|
|
|
|
|
2022-06-24 00:16:55 +02:00
|
|
|
memory_error:
|
|
|
|
mov r0, BACKGROUND_COLOR
|
|
|
|
call fill_background
|
|
|
|
|
|
|
|
mov r0, memory_error_str
|
|
|
|
mov r1, 16
|
|
|
|
mov r2, 464
|
|
|
|
mov r3, TEXT_COLOR
|
|
|
|
mov r4, 0x00000000
|
|
|
|
mov r10, FOX32OS_VERSION_MAJOR
|
|
|
|
mov r11, FOX32OS_VERSION_MINOR
|
|
|
|
mov r12, FOX32OS_VERSION_PATCH
|
|
|
|
call draw_format_str_to_background
|
|
|
|
rjmp 0
|
|
|
|
|
2022-05-22 01:55:56 +02:00
|
|
|
get_os_version:
|
|
|
|
mov r0, FOX32OS_VERSION_MAJOR
|
|
|
|
mov r1, FOX32OS_VERSION_MINOR
|
|
|
|
mov r2, FOX32OS_VERSION_PATCH
|
|
|
|
ret
|
|
|
|
|
2022-05-19 23:15:40 +02:00
|
|
|
#include "allocator.asm"
|
|
|
|
#include "fxf/fxf.asm"
|
2022-05-22 01:55:56 +02:00
|
|
|
#include "task.asm"
|
2022-12-28 03:01:55 +01:00
|
|
|
#include "widget/widget.asm"
|
2022-10-06 01:15:36 +02:00
|
|
|
#include "window/window.asm"
|
2022-10-15 01:39:40 +02:00
|
|
|
#include "vfs.asm"
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2023-02-02 00:08:22 +01:00
|
|
|
bottom_bar_str_0: data.strz "FOX"
|
|
|
|
bottom_bar_str_1: data.strz "32"
|
|
|
|
bottom_bar_str_2: data.strz " OS version %u.%u.%u "
|
|
|
|
startup_error_str: data.strz "fox32 - OS version %u.%u.%u - startup.cfg is invalid!"
|
|
|
|
memory_error_str: data.strz "fox32 - OS version %u.%u.%u - not enough memory to perform operation!"
|
|
|
|
kernelception_error_str: data.strz "Error: kernelception?"
|
2022-12-29 21:02:03 +01:00
|
|
|
bottom_bar_patterns:
|
|
|
|
; 1x16 tile
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
|
|
|
|
; 1x16 tile
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
|
|
|
data.32 0xFFFFFFFF
|
|
|
|
data.32 0xFF674764
|
2022-05-19 23:15:40 +02:00
|
|
|
|
2022-09-10 01:37:13 +02:00
|
|
|
next_task_id: data.8 0
|
|
|
|
startup_cfg: data.str "startup cfg"
|
|
|
|
startup_cfg_struct: data.32 0 data.32 0
|
|
|
|
startup_file: data.str " "
|
2022-05-19 23:15:40 +02:00
|
|
|
startup_file_struct: data.32 0 data.32 0
|
2022-09-10 01:37:13 +02:00
|
|
|
startup_file_binary_ptr: data.32 0
|
|
|
|
startup_file_stack_ptr: data.32 0
|
2022-05-19 23:15:40 +02:00
|
|
|
|
|
|
|
#include "../../fox32rom/fox32rom.def"
|
|
|
|
|
|
|
|
kernel_bottom:
|