;      ___           ___                       ___           ___     
;     /  /\         /  /\          ___        /  /\         /  /\    
;    /  /  \       /  / /_        /  /\      /  /  \       /  /  \   
;   /  / /\ \     /  / / /\      /  / /     /  / /\ \     /  / /\ \  
;  /  / /~/ /    /  / / / /_    /  / /     /  / /~/ /    /  / /  \ \ 
; /__/ / / /___ /__/ / / / /\  /  /  \    /__/ / / /___ /__/ / \__\ \
; \  \ \/     / \  \ \/ / / / /__/ /\ \   \  \ \/     / \  \ \ /  / /
;  \  \  /~~~~   \  \  / / /  \__\/  \ \   \  \  /~~~~   \  \ \  / / 
;   \  \ \        \  \ \/ /        \  \ \   \  \ \        \  \ \/ /  
;    \  \ \        \  \  /          \__\/    \  \ \        \  \  /
;     \__\/         \__\/                     \__\/         \__\/    
;
; RetroForth, Release 6
; Visit http://retro.tunes.org for updates
;
; Created by Tom Novelli
; Developed into its present state by Charles Childers
;--------------------------------------------------------------------
; This is primarily a wrapper for the other files. It loads the
; macros, sets up memory + stacks, and initializes the Forth
; system. It includes the following files automatically:
;  * macros
;  * forth.asm + forth-ic.asm + forth.f
;  * drivers.asm + drivers.f
;  * user.asm + user.f
; If you're porting RF, you should only need to edit the startup
; code and drivers. The rest should work "out of the box".
;--------------------------------------------------------------------

%include "macros"

extern vga_init
extern vga_setmode
extern vga_setlinearaddressing
extern vga_getgraphmem
global main

SECTION .text
main:
	mov eax, 07dh              ;sys mprotect (pinched from IsForth :-)
	mov ebx, 08048000h
	mov ecx, 00100000h
	mov edx, 7
	int 080h                   ;make the entire program space rwx
	lea esi, [esp-0x200]	;Initialize data stack

        call vga_init
        push word 5
        call vga_setmode
        add esp, 4*2
        call vga_setlinearaddressing
        call vga_getgraphmem
        mov dword [frame], eax

MAIN:   upsh startup            ;Load startup code (startup.f)
        upsh startup.1 - startup
        call eval
        call user_init
	call interpret
;---------------------------------------------------------------------
%include "forth-ic.asm"
%include "drivers.asm"
%include "user.asm"
%include "forth.asm"
;---------------------------------------------------------------------
section .data
startup: incbin "forth.f"
         incbin "drivers.f"
         incbin "user.f"
         db 'red color ! " Retro" type'
         db 'blue color ! " Forth" type'
         db 'black color ! " 6.20" type cr'
.1
END
