def invert(): label("forth.core.INVERT") adda(-add_cost_of_next(cost_of_invert) / 2) # 1 ld(data_stack_page, Y) ld([data_stack_pointer], X) ld([Y, X]) xora(0xFF) # 5 st([Y, Xpp]) ld([Y, X]) xora(0xFF) st([Y, X]) # 9 NEXT(cost_of_invert)
def increment(): "Add one to the top of the stack (n -- n)" label("forth.core.1+") adda(-add_cost_of_next(cost_of_increment) / 2) # 1 ld(data_stack_page, Y) ld([data_stack_pointer], X) ld([Y, X]) adda(1) # 5 bne(lo(".done")) # 6 st([Y, Xpp]) # 7 ld([Y, X]) # 8 adda(1) st([Y, X]) NEXT(cost_of_increment__two_words_written) label(".done") NEXT(cost_of_increment__one_word_written)
def emit_entry_page(vticks, vreturn): """Emit the data for NEXT and some other core routines The first page does not have the 'restart-or-quit' trampoline at 0x00 So we can't put any Forth word in here. """ while pc() & 255 < 255: nop() assert _next.INTERPRETER_ENTER_PAGE == pc() >> 8 label("FORTH_ENTER") C("You are now entering... Forth") adda(_next.INBOUND_TICK_CORRECTION) # --- Page boundary --- align(0x100, 0x100) st([vticks]) _next.next1(vticks) _next.next1_reenter(vticks) _next.next2(vticks) _next.exit(vticks, vreturn) _docol_exit.do_docol_rom() _docol_exit.do_docol_ram()
def do_restore_mode(): label("forth.DO-RESTORE-MODE") adda(-add_cost_of_reenter(cost_of_do_restore_mode) / 2) ld(return_stack_page, Y) ld([return_stack_pointer], X) ld([return_stack_pointer]) adda(1) st([return_stack_pointer]) ld([Y, X]) st([mode]) ld(0, Y) ld(W, X) st(lo("forth.core.EXIT"), [Y, Xpp]) st(hi("forth.core.EXIT"), [Y, Xpp]) # 12 REENTER(cost_of_do_restore_mode)