diff --git a/asm.jrt b/asm.jrt index 5bd500f..21f8f51 100755 --- a/asm.jrt +++ b/asm.jrt @@ -290,9 +290,14 @@ var ignoreimm : >grp2* ( ext -- ) 0xd0 swap-args oparg-imm? oparg-val @ 1 = and not if ( 1, d0/d1 ) - oparg-reg? oparg-val @ 0x11 = and + oparg-reg? oparg-val @ 0x11 = and if 2 + ( CL, d2/d3 ) else swap-args 2drop return then - then swap-args 'extregmem 1 ignoreimm ! *? 0 ignoreimm ! if 2ret then ; + then swap-args + oparg-wreg? if 1 + ' >extreg* else + oparg-breg? if ' >extbreg* else + oparg-mem? if byteptr? not if 1 + then :| >mem 2ret |; else + 2drop then then then + 1 ignoreimm ! *? 0 ignoreimm ! if 2ret then ; 2 :op XCHG arg2 oparg-reg? oparg-val @ 0x00 = and arg1 oparg-wreg? and diff --git a/boot.jor b/boot.jor index 682cd79..71f07ee 100755 --- a/boot.jor +++ b/boot.jor @@ -49,13 +49,13 @@ key const sp then ; : interpreter begin word dup b@ while compileword repeat drop ; -: loadfp ( -- ) +: loadfp ( fp -- fp ) infile @ >r - fdeactivate infile ! + infile ! interpreter - infile @ factivate + infile @ r open loadfp close t t' w>t ; : @>t t& @t w>t ; -: :t DEF [ t& $DOCOLON @t lit ] w>t ; +: :t DEF [ t& $DOCOLON lit ] w>t ; :CP $DODEFERRED INC BX INC BX MOV BX @[ BX] JMP @[ BX] +: DEFERRED DEF [ t& $DODEFERRED lit ] w>t '>t ; + :ASM LIT_ LODSW PUSH AX @@ -228,19 +230,6 @@ L: fail-digit 0 <: PUSH CX NEXT -:ASM emit - MOV AH 2 # - POP DX - INT 0x21 # - NEXT - -:ASM key - MOV AH 8 # - INT 0x21 # - XOR AH AH - PUSH AX - NEXT - :ASM terminate MOV AH 0x4c # MOV AL 0 # ( todo: pop ) @@ -268,6 +257,97 @@ L: fail-digit 0 <: PUSH AX NEXT +L: TRUE 0xffff w>t +L: FALSE 0 w>t +L: RETTRUE + PUSH TRUE + NEXT +L: RETFALSE + PUSH FALSE + NEXT + +:ASM not + POP AX + CMP AX FALSE + JZ RETTRUE + JMP RETFALSE + +:ASM = + POP AX + POP BX + CMP AX BX + JZ RETTRUE + JMP RETFALSE + +:ASM < + POP AX + POP BX + CMP AX BX + JL RETTRUE + JMP RETFALSE + +:ASM > + POP AX + POP BX + CMP AX BX + JG RETTRUE + JMP RETFALSE + +:ASM and + POP AX + POP BX + CMP AX FALSE + JZ RETFALSE + CMP BX FALSE + JZ RETFALSE + JMP RETTRUE + +:ASM or + POP AX + POP BX + OR AX BX + JZ RETFALSE + JMP RETTRUE + +:t != '>t = '>t not '>t return +:t <= '>t > '>t not '>t return +:t >= '>t < '>t not '>t return + +:ASM & + POP AX + POP BX + AND AX BX + PUSH AX + NEXT + +:ASM | + POP AX + POP BX + OR AX BX + PUSH AX + NEXT + +:ASM ^ + POP AX + POP BX + XOR AX BX + PUSH AX + NEXT + +:ASM << ( val count ) + POP CX + POP AX + SHL AX CL + PUSH AX + NEXT + +:ASM >> + POP CX + POP AX + SHR AX CL + PUSH AX + NEXT + :ASM @ POP BX MOV AX @[ BX] @@ -281,6 +361,13 @@ L: fail-digit 0 <: PUSH AX NEXT +:ASM ub@ + POP BX + MOV AL @[ BX] + XOR AH AH + PUSH AX + NEXT + :ASM @far POP ES POP BX MOV AX @[ ES: BX] @@ -354,6 +441,81 @@ L: fail-digit 0 <: :t segalloc '>t lastseg '>t @ '>t LIT_ 4096 w>t '>t + '>t dup '>t lastseg '>t ! '>t return +2 CONST cell +:t allot '>t here '>t + '>t here! '>t return +:t , '>t here '>t ! '>t cell '>t allot '>t return +:t b, '>t here '>t b! '>t LIT_ 1 w>t '>t allot '>t return + +:ASM overwrite + MOV AH 0x3c # + XOR CX CX ( non-system, non-hidden ) + POP DX ( filename ptr ) + INT 0x21 # + PUSH AX + NEXT + +:ASM open + MOV AH 0x3d # + MOV AL 2 # ( read/write access, allow child inheritance ) + POP DX ( filename ptr ) + INT 0x21 # + PUSH AX + NEXT + +:ASM close + MOV AH 0x3e # + POP BX + INT 0x21 # + NEXT + +0 VAR, fcount +:ASM fread + MOV AH 0x3f # + POP BX ( fp ) + POP DX ( buffer ) + POP CX ( length ) + INT 0x21 # + MOV t& fcount @+ AX ( save number of bytes read ) + NEXT + +:ASM fwrite + MOV AH 0x40 # + POP BX ( fp ) + POP DX ( buffer ) + POP CX ( length ) + INT 0x21 # + MOV t& fcount @+ AX ( save number of bytes written ) + NEXT + +-1 CONST EOF +0 VAR, fbuffer +:t fgetc '>t LIT_ 1 w>t '>t fbuffer '>t t fread + '>t fbuffer '>t ub@ + '>t fcount '>t @ '>t not '>t BZ_ target @ 3 cells + w>t + '>t drop '>t EOF '>t return +:t fputc '>t swap '>t fbuffer '>t b! + '>t LIT_ 1 w>t '>t fbuffer '>t t fwrite '>t return + +:ASM console-emit + MOV AH 2 # + POP DX + INT 0x21 # + NEXT +DEFERRED emit console-emit + +:ASM console-key + MOV AH 8 # + INT 0x21 # + XOR AH AH + PUSH AX + NEXT + +0 VAR, infile ( 0 is a predefined file handle meaning stdin ) +:t in-key '>t infile '>t @ '>t dup '>t BZ_ target @ 4 cells + w>t + '>t drop '>t console-key '>t return + '>t fgetc '>t return +DEFERRED key in-key + ( test program ) ARRAY hex65 key 6 >t key 5 >t 0 >t L: test-word t' hex65 w>t t' number w>t t' drop w>t t' emit w>t t' terminate w>t @@ -373,5 +535,5 @@ target @ t& &here !t dbg" Program assembled, saving tinyjort.com" s" tinyjort.com" overwrite -0x100 target @ :noname for i tseg b@far fputc next ; execute +0x100 target @ :noname for i tseg b@far over fputc next ; execute close