Skip to content

Commit

Permalink
Move OS binaries to their own sector, improve boot process and sanity…
Browse files Browse the repository at this point in the history
… checks, bugfixes
  • Loading branch information
beckadamtheinventor committed Dec 3, 2021
1 parent 5463d53 commit 3099a74
Show file tree
Hide file tree
Showing 44 changed files with 1,385 additions and 543 deletions.
2 changes: 2 additions & 0 deletions bos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,7 @@ namespace bos
?fs_cluster_map := $3BE000
?fs_cluster_map.len := 7040
?fs_cmap_length := fs_cluster_map.len
?fs_root_dir_lba := $010000 shr 9
?fs_root_dir_address := start_of_user_archive + $010000
end namespace
2 changes: 1 addition & 1 deletion docs/syscalls.html
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
</td></tr>
</table></div><div id="fs_SanityCheck"><h1>fs_SanityCheck</h1> <h3>syscall Adress 020288</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>check the filesystem for errors. Attempts to fix if there are any. If that fails, it reformats the filesystem.</td><td></td><td></td><td></td><td>
<tr><td>Sanity check the filesystem and initialize it as needed</td><td></td><td></td><td></td><td>
</td></tr>
</table></div><div id="sys_SetupOnInterruptHandler"><h1>sys_SetupOnInterruptHandler</h1> <h3>syscall Adress 02028C</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
Expand Down
15 changes: 14 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ $(call NATIVEPATH,$(FSOBJ)/memedit.bin): $(call NATIVEPATH,$(FSSRC)/fs/bin/memed

$(call NATIVEPATH,$(FSSRC)/fs/bin/cedit/bosbin/CEDIT.bin): $(call NATIVEPATH,$(FSSRC)/fs/bin/cedit/src/main.c)
$(Q)make -f bos.makefile -C $(call NATIVEPATH,$(FSSRC)/fs/bin/cedit/)
convbin -i $(call NATIVEPATH,$(FSSRC)/fs/bin/cedit/bosbin/CEDIT.bin) -o $(call NATIVEPATH,$(FSOBJ)/CEDIT.zx7.bin) -j bin -k bin -c zx7

$(call NATIVEPATH,$(FSSRC)/fs/bin/msd/bosbin/MSD.bin): $(call NATIVEPATH,$(FSSRC)/fs/bin/msd/src/main.c)
$(Q)make -f makefile -C $(call NATIVEPATH,$(FSSRC)/fs/bin/msd/)
convbin -i $(call NATIVEPATH,$(FSSRC)/fs/bin/msd/bosbin/MSD.bin) -o $(call NATIVEPATH,$(FSOBJ)/MSD.zx7.bin) -j bin -k bin -c zx7

# filesystem var build rules
$(call NATIVEPATH,$(FSOBJ)/LIB.bin): $(call NATIVEPATH,$(FSSRC)/fs/var/LIB.asm)
fasmg $(call NATIVEPATH,$(FSSRC)/fs/var/LIB.asm) $(call NATIVEPATH,$(FSOBJ)/LIB.bin)
convbin -i $(call NATIVEPATH,$(FSOBJ)/LIB.bin) -o $(call NATIVEPATH,$(FSOBJ)/LIB.zx7.bin) -j bin -k bin -c zx7

$(call NATIVEPATH,$(FSOBJ)/PATH.bin): $(call NATIVEPATH,$(FSSRC)/fs/var/PATH.asm)
fasmg $(call NATIVEPATH,$(FSSRC)/fs/var/PATH.asm) $(call NATIVEPATH,$(FSOBJ)/PATH.bin)
convbin -i $(call NATIVEPATH,$(FSOBJ)/PATH.bin) -o $(call NATIVEPATH,$(FSOBJ)/PATH.zx7.bin) -j bin -k bin -c zx7

# Rule to build Filesytem and compress it
filesystem: $(call NATIVEPATH,$(FSSRC)/main.asm) $(call NATIVEPATH,$(FSSRC)/fs/lib/libload/bos_libload.asm) $(call NATIVEPATH,$(FSSRC)/fs/lib/fatdrvce/fatdrvce.asm) \
Expand All @@ -123,10 +133,13 @@ $(call NATIVEPATH,$(FSOBJ)/graphx.bin) $(call NATIVEPATH,$(FSOBJ)/keypadc.bin) $
$(call NATIVEPATH,$(FSSRC)/fs/bin/cedit/bosbin/CEDIT.bin) $(call NATIVEPATH,$(FSOBJ)/explorer.bin) $(call NATIVEPATH,$(FSOBJ)/memedit.bin) \
$(call NATIVEPATH,$(FSOBJ)/msddrvce.bin) $(call NATIVEPATH,$(FSSRC)/fs/bin/msd/bosbin/MSD.bin) $(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/config.asm) \
$(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/data.asm) $(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/display.asm) $(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/files.asm) \
$(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/libloader.asm) $(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/loadconfig.asm)
$(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/libloader.asm) $(call NATIVEPATH,$(FSSRC)/fs/bin/explorer/loadconfig.asm) $(call NATIVEPATH,$(FSOBJ)/PATH.bin) \
$(call NATIVEPATH,$(FSSRC)/fs/var/PATH.asm) $(call NATIVEPATH,$(FSOBJ)/LIB.bin) $(call NATIVEPATH,$(FSSRC)/fs/var/LIB.asm)
convbin -i $(call NATIVEPATH,$(FSSRC)/fs/etc/fontlibc/DrMono.dat) -o $(call NATIVEPATH,$(FSOBJ)/DrMono.zx7.dat) -j bin -k bin -c zx7
fasmg $(call NATIVEPATH,$(FSSRC)/main.asm) $(call NATIVEPATH,src/data/adrive/main.bin)
convbin -i $(call NATIVEPATH,src/data/adrive/main.bin) -o $(call NATIVEPATH,src/data/adrive/data.bin) -j bin -k bin -c zx7
convbin -i $(call NATIVEPATH,src/data/adrive/data.bin) -o $(call NATIVEPATH,bin/BOSOSpt2.8xv) -j bin -k 8xv -n BOSOSpt2
$(CP) $(call NATIVEPATH,src/data/adrive/data.bin) $(call NATIVEPATH,bin/BOSOSPT2.BIN)

# Rule to build noti-ez80 submodule required for standalone ROM image
$(call NATIVEPATH,noti-ez80/bin/NOTI.rom):
Expand Down
253 changes: 90 additions & 163 deletions src/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ boot_os:
inc a
call gfx_SetDraw

call fs_SanityCheck
call fs_InitClusterMap

ld hl,current_working_dir
ld (hl),'/'
inc hl
Expand Down Expand Up @@ -287,137 +284,11 @@ os_return:
call os_GetOSInfo
call gui_DrawConsoleWindow


call os_check_recovery_key
ld bc,str_BootConfigFile
push bc
call fs_OpenFile
pop bc
jq nc,.run_boot_cmd

; splash screen credit to LogicalJoe: https://github.com/LogicalJoe
.run_first_init:
ld de,BOS_B_compressed
ld hl,BOS_B
push de,hl
call util_Zx7Decompress
pop bc,bc

ld de,BOS_O_compressed
push de,hl
call util_Zx7Decompress
pop bc,bc

ld de,BOS_S_compressed
push de,hl
call util_Zx7Decompress
pop bc,bc

; ld hl,BOS_B
; ld bc, (97 shl 8) + 53
; call gfx_Sprite

ld hl,BOS_O
ld bc, (139 shl 8) + 99
call gfx_Sprite

; ld hl,BOS_S
; ld bc, (187 shl 8) + 145
; call gfx_Sprite


ld b,48 ; distance to move
.loop:
push bc

call ti.Delay10ms

pop hl ; I hate this code
push hl
ld l,h ; because b not c
ld h,0
ld bc,(97 shl 8) + 52
add hl,bc
push hl
pop bc
ld hl,BOS_B
call gfx_Sprite

pop bc ; I still hate this code
push bc
ld c,b
ld b,0
ld hl,(187 shl 8) + 146
sbc hl,bc
push hl
pop bc
ld hl,BOS_S
call gfx_Sprite

call gfx_BlitBuffer

pop bc ; delay if on first frame
ld a,b
cp a,48
jq nz,.notfirst

push bc
ld b,30
.Delay1:
call ti.Delay10ms
djnz .Delay1
pop bc

.notfirst:
call sys_AnyKey ; doesn't modify BC
jq nz,.skip_splash
djnz .loop

ld a,228
ld (lcd_text_fg),a
xor a,a
ld (lcd_text_bg),a

ld hl,140
ld a,86
call gfx_SetTextXY
ld hl,str_ecks
call gfx_PrintString

ld a,187
ld (lcd_x),a
ld a,134
ld (lcd_y),a
ld hl,str_perate
call gfx_PrintString
ld a,220
ld (lcd_x),a
ld a,181
ld (lcd_y),a
ld hl,str_ystem
call gfx_PrintString

call gfx_BlitBuffer

ld b,100
.Delay2:
call sys_AnyKey ; doesn't modify BC
jq nz,.skip_splash
call ti.Delay10ms
djnz .Delay2

.skip_splash:
ld a,255
ld (lcd_text_fg),a
ld hl,str_Loading
call gui_PrintLine
call fs_SanityCheck

call os_check_recovery_key
ld hl,str_HomeDir
ld e,1 shl fd_subdir
push de,hl
call fs_CreateDir
pop hl,bc
call unpack_updates

call os_check_recovery_key
call generate_boot_configs
Expand All @@ -431,7 +302,7 @@ os_return:
call os_check_recovery_key
ld de,str_CmdArguments
push de
ld hl,str_CmdExecutable
ld hl,str_CmdExecutable
.exec_file_hl:
push hl
call fs_OpenFile
Expand Down Expand Up @@ -468,44 +339,32 @@ os_recovery_menu:
call gui_DrawConsoleWindow
.keywait:
call sys_WaitKeyCycle
cp a,55
cp a,ti.skMode
jq z,.reset_fs
cp a,54
jq z,.turn_off
cp a,9
cp a,ti.skEnter
jq z,.attempt_recovery
cp a,56
cp a,ti.skDel
jq z,.uninstall
cp a,15
cp a,ti.skClear
jq z,boot_os
cp a,39
cp a,ti.skMatrix
jq z,.reinstalltios
jq .keywait

.reset_fs:
ld hl,string_press_enter_confirm
call gui_Print
call sys_WaitKeyCycle
cp a,9
jq nz,os_recovery_menu
call fs_Format
jq boot_os
; cp a,ti.sk6
; jq z,.validate
cp a,ti.sk2nd
jq nz,.keywait

.turn_off:
call sys_TurnOff
jq boot_os

.attempt_recovery:
call fs_SanityCheck
call fs_InitClusterMap.reinit
jq os_recovery_menu
.reset_fs:
call .confirm
call fs_Format
jq boot_os

.uninstall:
ld hl,string_press_enter_confirm
call gui_Print
call sys_WaitKeyCycle
cp a,9
jq nz,os_recovery_menu
call .confirm
ld hl,bos_UserMem
push hl ;return to usermem which immediately tells the calc to invalidate the OS and reboot
ld (hl),$CD
Expand All @@ -523,11 +382,7 @@ os_recovery_menu:
jq sys_EraseFlashSector ;erase first OS sector, bootcode will handle the rest

.reinstalltios:
ld hl,string_press_enter_confirm
call gui_Print
call sys_WaitKeyCycle
cp a,9
jq nz,os_recovery_menu
call .confirm
ld a,($0401FF)
inc a
jq nz,.reinstalltios_start
Expand All @@ -543,6 +398,77 @@ os_recovery_menu:
ldir
jp sys_FlashUnlock

.attempt_recovery:
call .confirm
call fs_SanityCheck
jq os_recovery_menu

; .validate:
; call .confirm
; ld hl,str_ValidatingOSFiles
; call gui_DrawConsoleWindow
; ld hl,safeRAM
; push hl
; .validate_loop:
; ld ix,fs_system_files
; push ix
; call fs_OpenFile
; ex (sp),hl
; call fs_HashFile
; pop bc
; lea hl,ix+32
; ld de,safeRAM
; ld b,32
; assert ~safeRAM and $FF
; ld c,e
; .digest_loop:
; ld a,(de)
; cp a,(hl)
; jq z,.match
; inc c
; .digest_match:
; djnz .digest_loop
; ld a,c
; or a,a
; call nz,.verification_fail

; lea ix,ix+64
; ld a,(ix)
; or a,a
; jq nz,.validate_loop
; pop bc
; jq .keywait

; .verification_fail:
; ld hl,str_VerificationFailed
; call gui_Print
; lea hl,ix
; call gui_PrintLine
; jq sys_WaitKeyCycle

.confirm:
ld hl,string_press_enter_confirm
call gui_Print
call sys_WaitKeyCycle
cp a,9
jq nz,os_recovery_menu
ret


unpack_updates:
db $3E ; smc'd into a nop once updates are unpacked
ret ; this will only be executed if updates are already unpacked
.extract:
call fs_ExtractOSBinaries
call fs_ExtractOSOptBinaries

call sys_FlashUnlock
xor a,a
ld de,unpack_updates
call sys_WriteFlashA
jq sys_FlashLock


;tios reinstaller
virtual at ti.userMem
Expand Down Expand Up @@ -578,3 +504,4 @@ data_reinstall_tios_program:
db data_reinstall_tios_program.data
.len:=$-.


Loading

0 comments on commit 3099a74

Please sign in to comment.