From 2828e7c2e19e44e48df926787eb4d06656ea7436 Mon Sep 17 00:00:00 2001 From: BeckATI on Win10 <40156145+beckadamtheinventor@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:07:58 -0600 Subject: [PATCH] Start migrating osrt libraries to syscall libraries --- bos.inc | 69 +++++--- build_bos_inc.py | 66 ++++--- src/compatibility/_Str.asm | 24 ++- src/data/adrive/src/fs/bin/if.asm | 165 +++++++++++++++++- src/data/adrive/src/fs/bin/include/bos.inc | 69 +++++--- .../adrive/src/fs/bin/include/defines.inc | 3 +- src/data/adrive/src/fs/bin/include/os.inc | 6 + src/data/adrive/src/fs/bin/memedit.asm | 46 ++++- src/data/adrive/src/fs/lib/include/bos.inc | 69 +++++--- .../adrive/src/fs/lib/include/defines.inc | 3 +- src/data/adrive/src/fs/lib/include/os.inc | 6 + src/data/adrive/src/main.asm | 5 + src/data/strings.asm | 11 ++ src/fs/WriteFile.asm | 3 +- src/include/bos.inc | 69 +++++--- src/include/defines.inc | 3 +- src/include/os.inc | 6 + src/installer8xp.asm | 60 +++++++ src/sys.inc | 1 + src/sys/ExecContinue.asm | 28 ++- src/sys/ExecSkipUntilEnd.asm | 61 +++++++ 21 files changed, 631 insertions(+), 142 deletions(-) create mode 100644 src/sys/ExecSkipUntilEnd.asm diff --git a/bos.inc b/bos.inc index 42b81ddd..303a32a5 100644 --- a/bos.inc +++ b/bos.inc @@ -1,4 +1,5 @@ + ;------------------------------------------------------------------------------- ; Executable formats ;------------------------------------------------------------------------------- @@ -67,6 +68,8 @@ macro flash_executable? header:1 else opcode lhs,rhs end match + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args end if @@ -93,48 +96,65 @@ end macro ;------------------------------------------------------------------------------- ; Syscall library macro ;------------------------------------------------------------------------------- -macro syscalllib? +macro syscalllib? sclname local exports - db "SCL",0 + local flashexecbase + element flashexecbase virtual exports.area:: end virtual - virtual at 0 - macro export? routine - virtual exports.area - if defined routine.ramroutine - db 2 - else - db 1 - end if - dw routine - db `routine, 0 - end virtual - end macro - macro export_named? routine, name + virtual as "h" + header.area:: + end virtual + virtual as "src" + symbols.area:: + end virtual + virtual at flashexecbase-5 + db "SCL",0 + macro export? routine, name, hname, hdef& virtual exports.area if defined routine.ramroutine db 2 else db 1 end if - dw routine + dw routine-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro - macro export_data? data, name + macro export_data? data, name, hname, hdef& virtual exports.area db 3 - dw data + dw data-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual end macro - macro export_ptr? routine, name + macro export_ptr? routine, name, hname, hdef& virtual exports.area db 8 dl routine db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro macro ram_routine? routine, ramloc routine.ramroutine: @@ -179,8 +199,8 @@ macro syscalllib? purge export? purge end?.syscalllib? end macro - iterate each, call,jp,jq,ld,syscall - macro each? args& + iterate opcode, call,jp,jq,ld,syscall + macro opcode? args& match lhs=,rhs, args match (val), lhs if val relativeto flashexecbase @@ -215,9 +235,11 @@ macro syscalllib? else opcode lhs end if + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args - end match + end if end macro end iterate end macro @@ -579,7 +601,8 @@ namespace bos ?reservedRAM := ti.ramCodeTop ?bos_UserMem := $D1A881 ?ram_fs_start := end_of_usermem-$10 -?end_of_usermem := open_device_table +?end_of_usermem := malloc_cache-$400 +?bos_basic_vars := malloc_cache-$400 ?open_device_table := malloc_cache-$380 ?open_device_table.len := $80 ?op_stack_bot := malloc_cache-$300 diff --git a/build_bos_inc.py b/build_bos_inc.py index 560b66ec..c735ce69 100644 --- a/build_bos_inc.py +++ b/build_bos_inc.py @@ -30,6 +30,7 @@ def build_bos_inc(): with open(path.join(path.dirname(__file__), "bos.inc"),"w") as f: f.write(""" + ;------------------------------------------------------------------------------- ; Executable formats ;------------------------------------------------------------------------------- @@ -98,6 +99,8 @@ def build_bos_inc(): else opcode lhs,rhs end match + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args end if @@ -124,48 +127,65 @@ def build_bos_inc(): ;------------------------------------------------------------------------------- ; Syscall library macro ;------------------------------------------------------------------------------- -macro syscalllib? +macro syscalllib? sclname local exports - db "SCL",0 + local flashexecbase + element flashexecbase virtual exports.area:: end virtual - virtual at 0 - macro export? routine - virtual exports.area - if defined routine.ramroutine - db 2 - else - db 1 - end if - dw routine - db `routine, 0 - end virtual - end macro - macro export_named? routine, name + virtual as "h" + header.area:: + end virtual + virtual as "src" + symbols.area:: + end virtual + virtual at flashexecbase-5 + db "SCL",0 + macro export? routine, name, hname, hdef& virtual exports.area if defined routine.ramroutine db 2 else db 1 end if - dw routine + dw routine-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro - macro export_data? data, name + macro export_data? data, name, hname, hdef& virtual exports.area db 3 - dw data + dw data-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual end macro - macro export_ptr? routine, name + macro export_ptr? routine, name, hname, hdef& virtual exports.area db 8 dl routine db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro macro ram_routine? routine, ramloc routine.ramroutine: @@ -210,8 +230,8 @@ def build_bos_inc(): purge export? purge end?.syscalllib? end macro - iterate each, call,jp,jq,ld,syscall - macro each? args& + iterate opcode, call,jp,jq,ld,syscall + macro opcode? args& match lhs=,rhs, args match (val), lhs if val relativeto flashexecbase @@ -246,9 +266,11 @@ def build_bos_inc(): else opcode lhs end if + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args - end match + end if end macro end iterate end macro diff --git a/src/compatibility/_Str.asm b/src/compatibility/_Str.asm index 85373a2b..0ba2c3c5 100644 --- a/src/compatibility/_Str.asm +++ b/src/compatibility/_Str.asm @@ -8,21 +8,34 @@ _StrCopy: inc de jr . - +; compare B bytes from data at HL and DE _StrCmpre: ld a,(de) - cp a,(hl) + sub a,(hl) ret nz inc hl inc de djnz . ret +; compare strings HL and DE +; stop at null terminator without comparing +_StrCmpre0: + ld a,(de) + sub a,(hl) + ret nz + or a,(hl) + ret z + inc de + inc hl + jr . + +; return length of string HL in BC _StrLength: push af,hl - xor a,a + xor a,a ; A = 0 ld c,a - mlt bc + mlt bc ; BC = ? * 0 --> 0 cpir scf sbc hl,hl @@ -30,6 +43,3 @@ _StrLength: ex (sp),hl pop bc,af ret - - - diff --git a/src/data/adrive/src/fs/bin/if.asm b/src/data/adrive/src/fs/bin/if.asm index 4e5d8edd..4d1c2868 100644 --- a/src/data/adrive/src/fs/bin/if.asm +++ b/src/data/adrive/src/fs/bin/if.asm @@ -2,8 +2,14 @@ jq if_main db "FEX",0 if_main: - ld hl,-9 + scf + sbc hl,hl + ld (hl),2 + ld hl,-6 call ti._frameset + xor a,a + ld (ix-5),a + ld (ix-6),a ld a,(ix+6) cp a,2 jq c,.info @@ -11,10 +17,157 @@ if_main: ld a,(hl) or a,a jq z,.info + inc hl + cp a,'!' + jr nz,.not_inverted + ld a,(hl) + inc hl + set 0,(ix-5) +.not_inverted: + call .readexpr + ld (ix-3),hl + ld (ix-4),a + ex hl,de + bit 1,(ix-5) + jr z,.non_negative_left + xor a,a + ld l,a + mlt hl + ld de,(ix-3) + ld c,(ix-4) + sbc hl,de + sbc a,c + ld (ix-3),hl + ld (ix-4),a +.non_negative_left: + ld a,(hl) + inc hl + cp a,'<' + jr z,.check_second_operator + inc (ix-6) + cp a,'>' + jr z,.check_second_operator + cp a,'=' + jq nz,.info + ld (ix-6),4 + jr .read_right +.check_second_operator: + ld a,(hl) + cp a,'=' + jr nz,.read_right + inc hl + set 1,(ix-6) +.read_right: + ld a,(hl) + inc hl + call .readexpr + bit 1,(ix-5) ; right side negative + jr z,.non_negative_right + ld c,a + ex hl,de + xor a,a + ld l,a + mlt hl + sbc hl,de + sbc a,c +.non_negative_right: + dec (ix-6) + jr c,.check_lt + jr z,.check_gt + dec (ix-6) + jr z,.check_lteq + dec (ix-6) + jr z,.check_gteq + ; or a,a ; carry flag probably will never be set here anyways + call .compare + jr z,.condition_true + jr .condition_false +; A < B if (B - A) > 0 +.check_lt: + scf + call .compare + jr nc,.condition_true + jr .condition_false +; A > B if (B - A) < 0 +.check_gt: + or a,a + call .compare + jr c,.condition_true + jr .condition_false +; A <= B if (B - A) >= 0 +.check_lteq: + or a,a + call .compare + jr nc,.condition_true + jr .condition_false +; A >= B if (B - A) <= 0 +.check_gteq: + scf + call .compare + jr c,.condition_true + ; jr .condition_false +.condition_false: + bit 0,(ix-5) + jq z,.condition_actually_false +.condition_true: + bit 0,(ix-5) + jq z,.exit_0 +.condition_actually_false: + call bos.sys_ExecSkipUntilEnd + jq .exit_0 - - +; .skipspace.next: + ; inc hl +; skip whitespace (advance) HL +; .skipspace: + ; ld a,(hl) + ; or a,a + ; ret z + ; cp a,' ' + ; jr z,.skipspace.next + ; cp a,$9 + ; ret nz + ; jr .skipspace.next + + +; subtract AUHL minus 32 bits from (ix-4) +; does not set/reset carry flag prior to subtraction +.compare: + ld de,(ix-3) + sbc hl,de + sbc a,(ix-4) + ret + +; read expression from HL, storing result in AUHL and character where parsing stopped in DE. +.readexpr: + cp a,'-' + jr nz,.not_negative + set 1,(ix-5) + ld a,(hl) + inc hl +.not_negative: + push hl + cp a,'$' + jr nz,.not_hex + call osrt.hexstr_to_int + jr .number +.not_hex: + sub a,'0' + jr c,.info + cp a,10 + jr nc,.not_base_10_number + call osrt.str_to_int + jr .number +.not_base_10_number: + sub a,'A'-'0' + jr c,.info + cp a,26 + jr nc,.info +.number: + pop bc + ret + .info: ld hl,.infostr call bos.gui_PrintLine @@ -26,5 +179,9 @@ if_main: pop ix ret .infostr: - + db "Usage:",$A + db "if expr[<>=]expr",$A + db "...",$A + db "end",$A + db "expr: [-][A-Z|[$]0-9A-F]",$A db 0 diff --git a/src/data/adrive/src/fs/bin/include/bos.inc b/src/data/adrive/src/fs/bin/include/bos.inc index 42b81ddd..303a32a5 100644 --- a/src/data/adrive/src/fs/bin/include/bos.inc +++ b/src/data/adrive/src/fs/bin/include/bos.inc @@ -1,4 +1,5 @@ + ;------------------------------------------------------------------------------- ; Executable formats ;------------------------------------------------------------------------------- @@ -67,6 +68,8 @@ macro flash_executable? header:1 else opcode lhs,rhs end match + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args end if @@ -93,48 +96,65 @@ end macro ;------------------------------------------------------------------------------- ; Syscall library macro ;------------------------------------------------------------------------------- -macro syscalllib? +macro syscalllib? sclname local exports - db "SCL",0 + local flashexecbase + element flashexecbase virtual exports.area:: end virtual - virtual at 0 - macro export? routine - virtual exports.area - if defined routine.ramroutine - db 2 - else - db 1 - end if - dw routine - db `routine, 0 - end virtual - end macro - macro export_named? routine, name + virtual as "h" + header.area:: + end virtual + virtual as "src" + symbols.area:: + end virtual + virtual at flashexecbase-5 + db "SCL",0 + macro export? routine, name, hname, hdef& virtual exports.area if defined routine.ramroutine db 2 else db 1 end if - dw routine + dw routine-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro - macro export_data? data, name + macro export_data? data, name, hname, hdef& virtual exports.area db 3 - dw data + dw data-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual end macro - macro export_ptr? routine, name + macro export_ptr? routine, name, hname, hdef& virtual exports.area db 8 dl routine db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro macro ram_routine? routine, ramloc routine.ramroutine: @@ -179,8 +199,8 @@ macro syscalllib? purge export? purge end?.syscalllib? end macro - iterate each, call,jp,jq,ld,syscall - macro each? args& + iterate opcode, call,jp,jq,ld,syscall + macro opcode? args& match lhs=,rhs, args match (val), lhs if val relativeto flashexecbase @@ -215,9 +235,11 @@ macro syscalllib? else opcode lhs end if + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args - end match + end if end macro end iterate end macro @@ -579,7 +601,8 @@ namespace bos ?reservedRAM := ti.ramCodeTop ?bos_UserMem := $D1A881 ?ram_fs_start := end_of_usermem-$10 -?end_of_usermem := open_device_table +?end_of_usermem := malloc_cache-$400 +?bos_basic_vars := malloc_cache-$400 ?open_device_table := malloc_cache-$380 ?open_device_table.len := $80 ?op_stack_bot := malloc_cache-$300 diff --git a/src/data/adrive/src/fs/bin/include/defines.inc b/src/data/adrive/src/fs/bin/include/defines.inc index 057269db..dd0bd7a1 100644 --- a/src/data/adrive/src/fs/bin/include/defines.inc +++ b/src/data/adrive/src/fs/bin/include/defines.inc @@ -89,7 +89,8 @@ ramCodeTop := ti.ramCodeTop reservedRAM := ti.ramCodeTop bos_UserMem := $D1A881 ram_fs_start := end_of_usermem-$10 -end_of_usermem := open_device_table +end_of_usermem := malloc_cache-$400 +bos_basic_vars := malloc_cache-$400 open_device_table := malloc_cache-$380 open_device_table.len := $80 op_stack_bot := malloc_cache-$300 diff --git a/src/data/adrive/src/fs/bin/include/os.inc b/src/data/adrive/src/fs/bin/include/os.inc index 0945e077..09803972 100644 --- a/src/data/adrive/src/fs/bin/include/os.inc +++ b/src/data/adrive/src/fs/bin/include/os.inc @@ -183,9 +183,15 @@ if defined INSTALLER8XP out0 ($24),a ret.l +<<<<<<< Updated upstream _unlock := .unlock _lock := .lock _sectorerase := .sectorerase +======= + _sectorerase := .sectorerase + _unlock := .unlock + _lock := .lock +>>>>>>> Stashed changes end if assume adl = 1 diff --git a/src/data/adrive/src/fs/bin/memedit.asm b/src/data/adrive/src/fs/bin/memedit.asm index 17b11800..2fe6b492 100644 --- a/src/data/adrive/src/fs/bin/memedit.asm +++ b/src/data/adrive/src/fs/bin/memedit.asm @@ -8,7 +8,7 @@ org ti.userMem jr mem_edit db "REX",0 mem_edit: - ld hl,-20 + ld hl,-21 call ti._frameset xor a,a ld (ix-12),a @@ -369,8 +369,10 @@ mem_edit_main: jq z,._write_file cp a,15 ;clear key jq z,.exit - cp a,53 ;yequ key + cp a,53 ;yequ / f1 key jq z,.setaddress + cp a,52 ;window / f2 key + jq z,.setaddressoffset cp a,10 ;"+" key jq z,.forwardfullpage cp a,11 ;"-" key @@ -458,16 +460,27 @@ edited_file:=$-1 ld (ix-7),a .dontloadcursor: jq .main_loop +.setaddressoffset: + call .getaddress + jq c,.main_loop + ld hl,(ix-6) + ld de,(ix-3) + add hl,de + jr ._setaddress .setaddress: call .getaddress jq c,.main_loop ld hl,(ix-6) +._setaddress: ld (ix-3),hl xor a,a jq .main_loop .getaddress: call .clearscreen - or a,a + xor a,a + ld (ix-21),a + inc a + ld (bos.curcol),a sbc hl,hl ld (ix-6),hl lea hl,ix-4 ;upper byte of address @@ -478,16 +491,12 @@ edited_file:=$-1 ret c .getaddrbyte: push hl - call bos.gfx_BlitBuffer - call bos.sys_WaitKeyCycle - call getnibble + call .getaddrbyte.waitkey jq nz,.exitaddrloop ld (ix-8),c ld a,c call _print4h - call bos.gfx_BlitBuffer - call bos.sys_WaitKeyCycle - call getnibble + call .getaddrbyte.waitkey jq nz,.exitaddrloop ld a,c ld l,a @@ -505,6 +514,25 @@ edited_file:=$-1 call bos.gfx_BlitBuffer or a,a ret +.getaddrbyte.waitkey: + ld a,(bos.curcol) + push af + xor a,a + ld (bos.curcol),a + call bos.gui_PrintChar + pop af + ld (bos.curcol),a + call bos.gfx_BlitBuffer + call bos.sys_WaitKeyCycle + cp a,ti.skSub ; subtract + jr z,.getaddrbyte.invert + cp a,ti.skChs ; negate + jr nz,.getaddrbyte.notsubtract +.getaddrbyte.invert: + set 0,(ix-21) + jr .getaddrbyte.waitkey +.getaddrbyte.notsubtract: + jq getnibble .lcd_ptr_from_cursor: ld c,a rra diff --git a/src/data/adrive/src/fs/lib/include/bos.inc b/src/data/adrive/src/fs/lib/include/bos.inc index 42b81ddd..303a32a5 100644 --- a/src/data/adrive/src/fs/lib/include/bos.inc +++ b/src/data/adrive/src/fs/lib/include/bos.inc @@ -1,4 +1,5 @@ + ;------------------------------------------------------------------------------- ; Executable formats ;------------------------------------------------------------------------------- @@ -67,6 +68,8 @@ macro flash_executable? header:1 else opcode lhs,rhs end match + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args end if @@ -93,48 +96,65 @@ end macro ;------------------------------------------------------------------------------- ; Syscall library macro ;------------------------------------------------------------------------------- -macro syscalllib? +macro syscalllib? sclname local exports - db "SCL",0 + local flashexecbase + element flashexecbase virtual exports.area:: end virtual - virtual at 0 - macro export? routine - virtual exports.area - if defined routine.ramroutine - db 2 - else - db 1 - end if - dw routine - db `routine, 0 - end virtual - end macro - macro export_named? routine, name + virtual as "h" + header.area:: + end virtual + virtual as "src" + symbols.area:: + end virtual + virtual at flashexecbase-5 + db "SCL",0 + macro export? routine, name, hname, hdef& virtual exports.area if defined routine.ramroutine db 2 else db 1 end if - dw routine + dw routine-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro - macro export_data? data, name + macro export_data? data, name, hname, hdef& virtual exports.area db 3 - dw data + dw data-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual end macro - macro export_ptr? routine, name + macro export_ptr? routine, name, hname, hdef& virtual exports.area db 8 dl routine db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro macro ram_routine? routine, ramloc routine.ramroutine: @@ -179,8 +199,8 @@ macro syscalllib? purge export? purge end?.syscalllib? end macro - iterate each, call,jp,jq,ld,syscall - macro each? args& + iterate opcode, call,jp,jq,ld,syscall + macro opcode? args& match lhs=,rhs, args match (val), lhs if val relativeto flashexecbase @@ -215,9 +235,11 @@ macro syscalllib? else opcode lhs end if + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args - end match + end if end macro end iterate end macro @@ -579,7 +601,8 @@ namespace bos ?reservedRAM := ti.ramCodeTop ?bos_UserMem := $D1A881 ?ram_fs_start := end_of_usermem-$10 -?end_of_usermem := open_device_table +?end_of_usermem := malloc_cache-$400 +?bos_basic_vars := malloc_cache-$400 ?open_device_table := malloc_cache-$380 ?open_device_table.len := $80 ?op_stack_bot := malloc_cache-$300 diff --git a/src/data/adrive/src/fs/lib/include/defines.inc b/src/data/adrive/src/fs/lib/include/defines.inc index 057269db..dd0bd7a1 100644 --- a/src/data/adrive/src/fs/lib/include/defines.inc +++ b/src/data/adrive/src/fs/lib/include/defines.inc @@ -89,7 +89,8 @@ ramCodeTop := ti.ramCodeTop reservedRAM := ti.ramCodeTop bos_UserMem := $D1A881 ram_fs_start := end_of_usermem-$10 -end_of_usermem := open_device_table +end_of_usermem := malloc_cache-$400 +bos_basic_vars := malloc_cache-$400 open_device_table := malloc_cache-$380 open_device_table.len := $80 op_stack_bot := malloc_cache-$300 diff --git a/src/data/adrive/src/fs/lib/include/os.inc b/src/data/adrive/src/fs/lib/include/os.inc index 0945e077..09803972 100644 --- a/src/data/adrive/src/fs/lib/include/os.inc +++ b/src/data/adrive/src/fs/lib/include/os.inc @@ -183,9 +183,15 @@ if defined INSTALLER8XP out0 ($24),a ret.l +<<<<<<< Updated upstream _unlock := .unlock _lock := .lock _sectorerase := .sectorerase +======= + _sectorerase := .sectorerase + _unlock := .unlock + _lock := .lock +>>>>>>> Stashed changes end if assume adl = 1 diff --git a/src/data/adrive/src/main.asm b/src/data/adrive/src/main.asm index 16be4d2b..390a9385 100644 --- a/src/data/adrive/src/main.asm +++ b/src/data/adrive/src/main.asm @@ -66,6 +66,7 @@ fs_dir bin_dir fs_entry memedit_exe, "hexed", "", f_system fs_entry memedit_exe, "hexedit", "", f_system fs_sfentry mf_exe, "mf", "", f_system+f_subfile + ; fs_sfentry if_exe, "if", "", f_system+f_subfile fs_sfentry info_exe, "info", "", f_system+f_subfile fs_sfentry jump_exe, "jump", "", f_system+f_subfile ; fs_sfentry json_exe, "json", "", f_system+f_subfile @@ -164,6 +165,10 @@ fs_file os_internal_subfiles include 'fs/bin/ls.asm' end fs_subfile + ; fs_subfile if_exe, bin_dir + ; include 'fs/bin/if.asm' + ; end fs_subfile + fs_subfile info_exe, bin_dir include 'fs/bin/info.asm' end fs_subfile diff --git a/src/data/strings.asm b/src/data/strings.asm index bfcc2e73..dd4a2e38 100644 --- a/src/data/strings.asm +++ b/src/data/strings.asm @@ -291,6 +291,17 @@ str_onbootconfig: db "explorer",$A .len:=$-. +; str_if: + ; db "if",0 +; str_end: + ; db "end",0 +; str_else: + ; db "else",0 +; str_repeat: + ; db "repeat",0 +; str_while: + ; db "while",0 + ; _sha256_state_init: ; dl 648807 ; db 106 diff --git a/src/fs/WriteFile.asm b/src/fs/WriteFile.asm index 9b66f71d..574d029b 100644 --- a/src/fs/WriteFile.asm +++ b/src/fs/WriteFile.asm @@ -44,7 +44,8 @@ fs_WriteFile: call sys_WriteFlashA ld hl,(ix+12) push hl - call fs_DeleteFileFD ; delete and free old file descriptor and data section +; note that this routine locks flash so we need to re-unlock it when we need to write to flash again. + call fs_DeleteFileFD ; delete and free old file descriptor and data section. ld hl,(ix-9) ex (sp),hl call fs_GetFDPtr ; get pointer to new file data section diff --git a/src/include/bos.inc b/src/include/bos.inc index 42b81ddd..303a32a5 100644 --- a/src/include/bos.inc +++ b/src/include/bos.inc @@ -1,4 +1,5 @@ + ;------------------------------------------------------------------------------- ; Executable formats ;------------------------------------------------------------------------------- @@ -67,6 +68,8 @@ macro flash_executable? header:1 else opcode lhs,rhs end match + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args end if @@ -93,48 +96,65 @@ end macro ;------------------------------------------------------------------------------- ; Syscall library macro ;------------------------------------------------------------------------------- -macro syscalllib? +macro syscalllib? sclname local exports - db "SCL",0 + local flashexecbase + element flashexecbase virtual exports.area:: end virtual - virtual at 0 - macro export? routine - virtual exports.area - if defined routine.ramroutine - db 2 - else - db 1 - end if - dw routine - db `routine, 0 - end virtual - end macro - macro export_named? routine, name + virtual as "h" + header.area:: + end virtual + virtual as "src" + symbols.area:: + end virtual + virtual at flashexecbase-5 + db "SCL",0 + macro export? routine, name, hname, hdef& virtual exports.area if defined routine.ramroutine db 2 else db 1 end if - dw routine + dw routine-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro - macro export_data? data, name + macro export_data? data, name, hname, hdef& virtual exports.area db 3 - dw data + dw data-flashexecbase db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual end macro - macro export_ptr? routine, name + macro export_ptr? routine, name, hname, hdef& virtual exports.area db 8 dl routine db name, 0 end virtual + virtual header.area + db hdef + db $A + end virtual + virtual symbols.area + db "public _", hname,$A + db '_',hname,' := syscall "',sclname,'/',name,'"',$A + end virtual end macro macro ram_routine? routine, ramloc routine.ramroutine: @@ -179,8 +199,8 @@ macro syscalllib? purge export? purge end?.syscalllib? end macro - iterate each, call,jp,jq,ld,syscall - macro each? args& + iterate opcode, call,jp,jq,ld,syscall + macro opcode? args& match lhs=,rhs, args match (val), lhs if val relativeto flashexecbase @@ -215,9 +235,11 @@ macro syscalllib? else opcode lhs end if + else if args relativeto flashexecbase + opcode args - flashexecbase else opcode args - end match + end if end macro end iterate end macro @@ -579,7 +601,8 @@ namespace bos ?reservedRAM := ti.ramCodeTop ?bos_UserMem := $D1A881 ?ram_fs_start := end_of_usermem-$10 -?end_of_usermem := open_device_table +?end_of_usermem := malloc_cache-$400 +?bos_basic_vars := malloc_cache-$400 ?open_device_table := malloc_cache-$380 ?open_device_table.len := $80 ?op_stack_bot := malloc_cache-$300 diff --git a/src/include/defines.inc b/src/include/defines.inc index 057269db..dd0bd7a1 100644 --- a/src/include/defines.inc +++ b/src/include/defines.inc @@ -89,7 +89,8 @@ ramCodeTop := ti.ramCodeTop reservedRAM := ti.ramCodeTop bos_UserMem := $D1A881 ram_fs_start := end_of_usermem-$10 -end_of_usermem := open_device_table +end_of_usermem := malloc_cache-$400 +bos_basic_vars := malloc_cache-$400 open_device_table := malloc_cache-$380 open_device_table.len := $80 op_stack_bot := malloc_cache-$300 diff --git a/src/include/os.inc b/src/include/os.inc index 0945e077..09803972 100644 --- a/src/include/os.inc +++ b/src/include/os.inc @@ -183,9 +183,15 @@ if defined INSTALLER8XP out0 ($24),a ret.l +<<<<<<< Updated upstream _unlock := .unlock _lock := .lock _sectorerase := .sectorerase +======= + _sectorerase := .sectorerase + _unlock := .unlock + _lock := .lock +>>>>>>> Stashed changes end if assume adl = 1 diff --git a/src/installer8xp.asm b/src/installer8xp.asm index 52b6ab5a..83e0c500 100644 --- a/src/installer8xp.asm +++ b/src/installer8xp.asm @@ -35,6 +35,7 @@ secondary_in_ram: call ti.LoadDEInd_s ld (os_second_binary),hl ld (os_second_binary.len),de +<<<<<<< Updated upstream ld hl,reinstaller_2_header + reinstaller_2_header.len-2 ld (hl),e inc hl @@ -42,10 +43,16 @@ secondary_in_ram: ld hl,backup_tios_query call _printline .waitkey: +======= + ld hl,backup_tios_querry + call _printline +waitkey: +>>>>>>> Stashed changes call ti.GetCSC cp a,ti.skLog jq z,do_installation cp a,ti.sk1 +<<<<<<< Updated upstream jr nz,.waitkey backup_tios: ld hl,($020104+1) @@ -80,6 +87,49 @@ do_installation: ; user flash end location is $3B0000, ; unless backing up TIOS in which case the end location is $300000 os_create $3B +======= + jr nz,waitkey +backup_tios: + ld hl,backingup_os_string + call _printline + + ; unlock flash + ld a,$d1 + ld mb,a + ld.sis sp,$987e + call.is _unlock and $ffff + + ; erase up until sector $3B + ld a,$30 +erase_upper_sectors_loop: + push af + call _sectorerase + pop af + inc a + cp a,$3B + jr c,erase_upper_sectors_loop + + ld de,$300000 ; write location + ld hl,$020000 + ld bc,$0B0000 ; OS size in sectors (ceil) + call $2E0 ; WriteFlash + + ld a,$d1 + ld mb,a + ld.sis sp,$987e + call.is _lock and $ffff + + jr do_installation +installation_fail: + ld hl,installation_failed_string + call _printline + jp ti.RunIndicOn +do_installation: + ld hl,installing_string + call _printline + os_create $30 ;erase all user flash sectors + jp $020108 ; boot OS +>>>>>>> Stashed changes fail_missing_secondary: ld hl,missing_secondary_str @@ -94,11 +144,16 @@ second_binary_appvar: db ti.AppVarObj,"BOSOSpt2" installing_string: db "Installing BOS...",0 +<<<<<<< Updated upstream backup_tios_query: +======= +backup_tios_querry: +>>>>>>> Stashed changes db "Back up TIOS? Y/N",0 missing_secondary_str: db "Missing AppVar BOSOSpt2",0 backingup_os_string: +<<<<<<< Updated upstream db "Backing up TIOS &",0 failed_to_backup_os_string: db "OS too large to backup",0 @@ -117,6 +172,11 @@ reinstaller_2_header: ; installation_failed_string: ; db "Need more ARC. Aborting.",0 +======= + db "Backing up TIOS...",0 +installation_failed_string: + db "Need more ARC. Aborting.",0 +>>>>>>> Stashed changes ; install_info_string: ; db "Please run a Garbage",0 ; db "Collect then re-run the",0 diff --git a/src/sys.inc b/src/sys.inc index 7c2d9681..d4f340a4 100644 --- a/src/sys.inc +++ b/src/sys.inc @@ -12,6 +12,7 @@ include 'sys/CheckMallocRAM.asm' include 'sys/SearchDeviceTable.asm' include 'sys/AppendDeviceTable.asm' include 'sys/EraseFlashSector.asm' +; include 'sys/ExecSkipUntilEnd.asm' include 'sys/ExecV.asm' include 'sys/Exec.asm' include 'sys/ExecData.asm' diff --git a/src/sys/ExecContinue.asm b/src/sys/ExecContinue.asm index 95357c78..73514b7b 100644 --- a/src/sys/ExecContinue.asm +++ b/src/sys/ExecContinue.asm @@ -15,8 +15,26 @@ sys_ExecContinue: jr z,.done ld a,(hl) cp a,'#' - jr z,.execute_program_string + jr z,.execute_program_string ; don't execute comments push hl + ld bc,(hl) + ex hl,de + db $21,"end" ; ld hl,"end" + or a,a + sbc hl,bc + jr nz,.not_end + inc de + inc de + inc de + ld a,(hl) + cp a,$A + jr z,.is_end + cp a,$9 + jr z,.is_end + cp a,' ' +.is_end: + jq nz,.done ; branch will only be taken if A is ' ', '\x09', or '\x0A' +.not_end: ld hl,(ix-3) call sys_Malloc.entryhl ex hl,de @@ -52,8 +70,8 @@ sys_ExecContinue: or a,a jr nz,.execute_program_string ;continue executing if an eol character was found before the null terminator .done: - xor a,a - ld (curcol),a + ; xor a,a + ; ld (curcol),a ld hl,(LastCommandResult) ld a,(LastCommandResult+3) ld e,a @@ -67,8 +85,10 @@ sys_ExecContinue: pop ix ret +;; eventually allow for forwarding command output, +;; would require me to redo how text printing works so it goes through +;; a device file of some kind. ; .forward_output: - ; ld hl,(ix-3) ; push hl ; call fs_WriteNewFile diff --git a/src/sys/ExecSkipUntilEnd.asm b/src/sys/ExecSkipUntilEnd.asm new file mode 100644 index 00000000..9d4bc7f5 --- /dev/null +++ b/src/sys/ExecSkipUntilEnd.asm @@ -0,0 +1,61 @@ +;@DOES Advance curPC until the corresponding "end" or "else" +;@INPUT void sys_ExecSkipUntilEnd(void); +sys_ExecSkipUntilEnd: + push iy + ld iy,1 + jr .entry +.loop: + call sys_ExecContinue.advance_to_next_line +.entry: + ld hl,(ti.curPC) + ld de,(ti.endPC) + or a,a + sbc hl,de + ret nc ; cur >= end + add hl,de + ; ld hl,(ti.curPC) + ld de,str_if + call _StrCmpre0 + jr z,.found_if + + ld hl,(ti.curPC) + ld de,str_end + call _StrCmpre0 + jr z,.found_end + + ld hl,(ti.curPC) + ld de,str_else + call _StrCmpre0 + jr z,.found_else + + ld hl,(ti.curPC) + ld de,str_repeat + call _StrCmpre0 + jr z,.found_repeat + + ld hl,(ti.curPC) + ld de,str_while + call _StrCmpre0 + jr z,.found_while + + jr .loop +.found_else: +.found_end: + dec iy + lea hl,iy + add hl,bc + or a,a + sbc hl,bc + jr z,.done + jr .loop +.found_if: +.found_repeat: +.found_while: + inc iy + jr .loop +.done: + pop iy + ret + + +