Load disk 1's contents as an FXF binary if startup.cfg is invalid

This commit is contained in:
Ry 2022-06-21 19:38:45 -07:00
parent 30f8ec6d81
commit 2dbe318538

View File

@ -9,6 +9,8 @@ const FOX32OS_VERSION_PATCH: 0
const BACKGROUND_COLOR: 0xFF674764 const BACKGROUND_COLOR: 0xFF674764
const TEXT_COLOR: 0xFFFFFFFF const TEXT_COLOR: 0xFFFFFFFF
const STARTUP_TASK_LOAD_ADDRESS: 0x03000000
jmp entry jmp entry
jump_table: jump_table:
@ -53,7 +55,7 @@ draw_startup_text:
mov r2, startup_file_struct mov r2, startup_file_struct
call ryfs_open call ryfs_open
cmp r0, 0 cmp r0, 0
ifz jmp startup_error ifz jmp boot_disk_1
; load the first 11 bytes of startup.cfg, overwriting the "startup cfg" string ; load the first 11 bytes of startup.cfg, overwriting the "startup cfg" string
mov r0, 11 mov r0, 11
@ -67,15 +69,16 @@ draw_startup_text:
mov r2, startup_file_struct mov r2, startup_file_struct
call ryfs_open call ryfs_open
cmp r0, 0 cmp r0, 0
ifz jmp startup_error ifz jmp boot_disk_1
; read the startup file into memory starting at 0x03000000 ; read the startup file into memory starting at STARTUP_TASK_LOAD_ADDRESS
mov r0, startup_file_struct mov r0, startup_file_struct
mov r1, 0x03000000 mov r1, STARTUP_TASK_LOAD_ADDRESS
call ryfs_read_whole_file call ryfs_read_whole_file
; relocate and execute it as a new task ; relocate and execute it as a new task
mov r0, 0x03000000 run_startup_task:
mov r0, STARTUP_TASK_LOAD_ADDRESS
call parse_fxf_binary call parse_fxf_binary
mov r1, r0 mov r1, r0
mov r0, 0 mov r0, 0
@ -88,6 +91,31 @@ draw_startup_text:
; this does not return ; this does not return
call end_current_task_no_mark call end_current_task_no_mark
; if startup.cfg is invalid, try loading the raw contents of disk 1 as an FXF binary
; 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!!
div r31, 512
inc r31
mov r0, 0 ; sector counter
mov r2, STARTUP_TASK_LOAD_ADDRESS ; destination pointer
mov r3, 0x80003001 ; command to read a sector from disk 01 into memory
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
jmp run_startup_task
startup_error: startup_error:
mov r0, BACKGROUND_COLOR mov r0, BACKGROUND_COLOR
call fill_background call fill_background