diff --git a/6502/finalize.ft b/6502/finalize.ft index 26ba9d9..5a0f08b 100644 --- a/6502/finalize.ft +++ b/6502/finalize.ft @@ -1,13 +1,14 @@ \ Final file that goes last in the process. \ This sets Target's LATEST and DP properly. +\ TODO: This file is (I think) identical across all the systems now? host definitions -\ This needs to be the last lines in the target compilation. -host latest var_latest tcode! -host data-space @ var_dp_ptr tcode! -S" entry-point " type entry-point hex. cr -S" entry-point @ " type entry-point tcode@ hex. cr +config data-indirect? @ [IF] prepare-data-initializers [THEN] + +\ This needs to be the last lines in the target compilation. +host latest latest0 tcode! +host data-space @ dp0 tcode! \ At this point the assembler's output region should be complete. \ Dump the binary! diff --git a/6502/kernel.ft b/6502/kernel.ft index 70f5b96..ab04a41 100644 --- a/6502/kernel.ft +++ b/6502/kernel.ft @@ -408,22 +408,26 @@ end-code-bare \ Variables and core states ================================================== -label var_latest 0 asm,16 -label var_base 0 asm,16 -label var_state 0 asm,16 -label var_handler 0 asm,16 +label dp0 0 asm,16 +label latest0 0 asm,16 + +TVARIABLE var_dp +TVARIABLE var_latest +TVARIABLE var_base +TVARIABLE var_state +TVARIABLE var_handler + +data-space @ CONSTANT var_last_parse 2 tcells tdata-allot +data-space @ CONSTANT var_source 2 tcells tdata-allot +TVARIABLE var_in_ptr +TVARIABLE var_source_id + +data-space @ CONSTANT input-buf 128 tdata-allot -label var_last_parse 0 asm,16 0 asm,16 -label var_source 0 asm,16 0 asm,16 -label var_in_ptr 0 asm,16 -label var_source_id 0 asm,16 -label input-buf 128 tcode-allot \ The dictionary pointer is in the zero page for speed. code DP herel lit, end-code -label var_dp_ptr 0 asm,16 - code , ( x -- ) 0 zp,x lda, 0 # ldy, @@ -928,9 +932,9 @@ label main \ TODO: Adjust the memory banks at this point, if we're going to. \ Set the initial DP into the ZP slot. - var_dp_ptr $ lda, + dp0 $ lda, herel zp sta, - var_dp_ptr 1+ $ lda, + dp0 1+ $ lda, hereh zp sta, \ The hardware stack starts configured - set up the data stack by setting X. diff --git a/6502/model-target.ft b/6502/model-target.ft index e4120fc..0b5fde4 100644 --- a/6502/model-target.ft +++ b/6502/model-target.ft @@ -13,10 +13,10 @@ target : ,CF ( codeword-addr -- ) compile, ; \ In STC this is empty, so this word is a no-op. target : ,DOCOL ( -- ) ; -host colocated-names? [IF] - target : ,PFA ( -- ) ; -host [ELSE] +host config data-indirect? @ [IF] target : ,PFA ( -- ) here cell+ , ; +host [ELSE] + target : ,PFA ( -- ) ; host [THEN] target : ,xt-slot ( -- ) ,pfa ; @@ -52,6 +52,8 @@ target : EXIT [ host $60 tliteral target ] c, ; IMMEDIATE target : ALIGNED ; host acts: ; target : ALIGN ; host acts: ; + + target : NAME>STRING ( nt -- c-addr u ) cell+ dup char+ swap c@ [ host mask_len tliteral target ] and ; @@ -59,18 +61,18 @@ target : NAME>STRING ( nt -- c-addr u ) \ (DOES>), there's no good place to put it with splitting this file into 3. target : >CFA ( nt -- xt ) name>string + aligned - [ host config mix-code-and-name? @ 0= [IF] target ] @ [ host [THEN] target ] ; + [ host config names-indirect? @ [IF] target ] @ [ host [THEN] target ] ; -host config mix-code-and-name? @ [IF] -target : /NAME-FIELD ( -- u ) 0 ; -host [ELSE] +host config names-indirect? @ [IF] target : /NAME-FIELD ( -- u ) 1 cells ; +host [ELSE] +target : /NAME-FIELD ( -- u ) 0 ; host [THEN] -host config mix-code-and-data? @ [IF] -target : >BODY ( xt -- addr ) 3 + ; -host [ELSE] +host config data-indirect? @ [IF] target : >BODY ( xt -- addr ) 3 + @ ; +host [ELSE] +target : >BODY ( xt -- addr ) 3 + ; host [THEN] diff --git a/6502/model.ft b/6502/model.ft index 721804f..bf97ff0 100644 --- a/6502/model.ft +++ b/6502/model.ft @@ -94,28 +94,29 @@ $0000 $ jmp, \ return addresses work on the 6502. \ So pop it from the return stack, add 1, and push it onto the data stack. \ Then the RTS at the end will return to the thread. -colocated-names? [IF] +config data-indirect? @ [IF] : pfa->tos, ( -- ) dex, dex, pla, \ lo -> A clc, 1 # adc, \ A+1 -> A - 0 zp,x sta, \ -> TOS_lo + wl zp sta, \ -> W_lo pla, \ hi -> A 0 # adc, - 1 zp,x sta, ; + wh zp sta, \ -> W_hi + + \ Now the address is ready in W, and there's space on the stack already. + wl (zp)>tos, ; [ELSE] +: pfa->tos, ( -- ) dex, dex, pla, \ lo -> A clc, 1 # adc, \ A+1 -> A - wl zp sta, \ -> W_lo + 0 zp,x sta, \ -> TOS_lo pla, \ hi -> A 0 # adc, - wh zp sta, \ -> W_hi - - \ Now the address is ready in W, and there's space on the stack already. - wl (zp)>tos, + 1 zp,x sta, ; [THEN] label DOVAR diff --git a/6502/preamble.ft b/6502/preamble.ft index 4d2ceec..024378b 100644 --- a/6502/preamble.ft +++ b/6502/preamble.ft @@ -17,3 +17,27 @@ interactive-forth! 1 config alignment ! config little-endian? ON + + +\ Target spaces ============================================================== +REQUIRE ../host/spaces.ft + +$0801 CONSTANT origin +$0810 CONSTANT machine-code-entry +here 2 allot align THERE-PTR CONSTANT prg-header + +\ Add a new tiny space for the "origin" pointer in the .prg file. +\ It's a 2-byte little-endian offset value, which is the same format as a +\ target cell. +$0 prg-header org! +$0 prg-header space>offset ! +origin $0 prg-header + +: spaces::single ( -- ) + single-space! + origin code-space ORG! + + \ There's a 2-byte PRG header first. + $2 code-space space>offset ! ; + +' spaces::single IS default-spaces! diff --git a/6502/system.ft b/6502/system.ft index c443ac3..02329af 100644 --- a/6502/system.ft +++ b/6502/system.ft @@ -1,3 +1,5 @@ +?default-spaces + host definitions REQUIRE assembler.ft host definitions REQUIRE registers.ft host definitions REQUIRE asm-helpers.ft diff --git a/Makefile b/Makefile index 9ca3373..edd1e84 100644 --- a/Makefile +++ b/Makefile @@ -160,10 +160,15 @@ test-arm-copying: forth-arm-copying-tests.bin test.disk FORCE # Commodore 64 =============================================================== forth-c64.prg: host/*.ft 6502/*.ft shared/*.ft - $(FORTH) 6502/main.ft + $(FORTH) 6502/preamble.ft -e "' spaces::single IS default-spaces!" \ + 6502/system.ft -e 'host :noname S" $@" ; IS tcforth-output' \ + 6502/finalize.ft -e 'bye' forth-c64-test.prg: host/*.ft 6502/*.ft shared/*.ft - $(FORTH) 6502/main-test.ft + $(FORTH) 6502/preamble.ft -e "' spaces::single IS default-spaces!" \ + 6502/system.ft -e 'host :noname S" $@" ; IS tcforth-output' \ + 6502/test-tail.ft \ + 6502/finalize.ft -e 'bye' c64: forth-c64.prg @@ -171,7 +176,7 @@ run-c64: forth-c64.prg $(VICE_C64) $(VICE_C64_FLAGS) forth-c64.prg test-c64: forth-c64-test.prg FORCE - $(VICE_C64) $(VICE_C64_FLAGS) -warp forth-c64-test.prg + $(VICE_C64) $(VICE_C64_FLAGS) -warp $< # Top level ================================================================== test: test-dcpu16 test-dcpu16-separate test-dcpu16-copying \