Skip to content

Commit

Permalink
more so words
Browse files Browse the repository at this point in the history
  • Loading branch information
phreda4 committed Jul 15, 2021
1 parent bbabbb8 commit 8fdb00d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto
*.r3 text eol=crlf linguist-language=forth
*.fnt text eol=crlf linguist-language=forth
*.rft text eol=crlf linguist-language=forth
*.ric text eol=crlf linguist-language=forth
24 changes: 16 additions & 8 deletions main.r3
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@
^r3/lib/str.r3

|--------------------------------------
:type | str cnt --
stdout rot rot 0 0 WriteFile drop ;
:ms | ms --
Sleep ;

:cls | color --
gr_buffer >a sizebuffer ( 1? over a!+ 1 - ) 2drop ;

#buffer * 256

:input
'buffer
( key 13 <>? swap c!+ ) drop
0 swap c! ;

:test
|$ffffff SDL_screen 28 + @ d! ;

:tt
100 ( 1? 1 -
50 ms
key? . ) drop ;

:main
windows
"1;1H" .[ | home
"2J" .[ | cls
"r3init" 6 type
cr
input
cr
sdl2
"r3sdl" 640 480 SDLinit

Expand Down
9 changes: 9 additions & 0 deletions r3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,19 @@ register int ip=boot;
memset64((uint64_t*)*(NOS-1),*NOS,TOS);
NOS-=2;TOS=*NOS;NOS--;goto next;

#if defined(LINUX) || defined(RPI)
case LOADLIB: // "" -- hmo
TOS=(int64_t)dlopen((char*)TOS,RTLD_NOW));goto next; //RTLD_LAZY 1 RTLD_NOW 2
case GETPROCA: // hmo "" -- ad
TOS=(int64_t)dlsym((void*)*NOS,(char*)TOS);NOS--;goto next;
#else // WINDOWS
case LOADLIB: // "" -- hmo
TOS=(int64_t)LoadLibraryA((char*)TOS);goto next;
case GETPROCA: // hmo "" -- ad
TOS=(int64_t)GetProcAddress((HMODULE)*NOS,(char*)TOS);NOS--;goto next;
#endif


case SYSCALL0: // adr -- rs
TOS=((int64_t (__stdcall *)())TOS)();goto next;
case SYSCALL1: // a0 adr -- rs
Expand Down
Binary file modified r3.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions r3.layout
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ CursorRow=1047
TopLine=1023
LeftChar=1
[Editor_0]
CursorCol=23
CursorRow=1051
TopLine=1032
CursorCol=1
CursorRow=1038
TopLine=1023
LeftChar=1
[Editor_2]
CursorCol=5
Expand Down
59 changes: 43 additions & 16 deletions r3/win/core.r3
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#sys-WriteFile
#sys-GetConsoleMode
#sys-SetConsoleMode
#sys-WriteConsole
#sys-FlushConsoleInputBuffer
#sys-Sleep
#sys-WaitForSingleObject sys2
Expand All @@ -25,22 +24,16 @@
#sys-HeapFree
#sys-HeapReAlloc

##process-heap

##stdin
##stdout
##stderr

::AllocConsole sys-allocconsole sys0 ;
::AllocConsole sys-allocconsole sys0 drop ;
::ExitProcess sys-ExitProcess sys1 ;
::GetStdHandle sys-GetStdHandle sys1 ;
::ReadFile sys-ReadFile sys5 ;
::WriteFile sys-WriteFile sys5 ;
::GetConsoleMode sys-GetConsoleMode sys2 ;
::SetConsoleMode sys-SetConsoleMode sys2 ;
::WriteConsole sys-WriteConsole sys5 ;
::FlushConsoleInputBuffer sys-FlushConsoleInputBuffer sys1 ;
::Sleep sys-Sleep sys1 ;
::Sleep sys-Sleep sys1 drop ;
::WaitForSingleObject sys-WaitForSingleObject sys2 ;
::GetLastError sys-GetLastError sys0 ;
::CreateFileA sys-CreateFileA sys7 ;
Expand All @@ -53,11 +46,16 @@
::GetFileSize sys-GetFileSize sys2 ;

::GetProcessHeap sys-GetProcessHeap sys0 ;
::HeapAlloc 'sys-HeapAlloc sys3 ;
::HeapFree 'sys-HeapFree sys3 ;
::HeapReAlloc 'sys-HeapReAlloc sys4 ;
::HeapAlloc 'sys-HeapAlloc sys3 drop ;
::HeapFree 'sys-HeapFree sys3 drop ;
::HeapReAlloc 'sys-HeapReAlloc sys4 drop ;

#console-mode
#process-heap

##stdin
##stdout
##stderr

::windows
"KERNEL32.DLL" loadlib
Expand All @@ -68,7 +66,6 @@
dup "WriteFile" getproc 'sys-WriteFile !
dup "GetConsoleMode" getproc 'sys-GetConsoleMode !
dup "SetConsoleMode" getproc 'sys-SetConsoleMode !
| dup "WriteConsoleA" getproc 'sys-WriteConsole !
dup "FlushConsoleInputBuffer" getproc 'sys-FlushConsoleInputBuffer !
dup "Sleep" getproc 'sys-Sleep !
dup "WaitForSingleObject" getproc 'sys-WaitForSingleObject !
Expand All @@ -81,24 +78,54 @@
dup "SetFilePointer" getproc 'sys-SetFilePointer !
dup "SetEndOfFile" getproc 'sys-SetEndOfFile !
dup "GetFileSize" getproc 'sys-GetFileSize !

dup "GetProcessHeap" getproc 'sys-GetProcessHeap !
dup "HeapAlloc" getproc 'sys-HeapAlloc !
dup "HeapFree" getproc 'sys-HeapFree !
dup "HeapReAlloc" getproc 'sys-HeapReAlloc !

drop
AllocConsole drop
AllocConsole
-10 GetStdHandle 'stdin ! | STD_INPUT_HANDLE
-11 GetStdHandle 'stdout ! | STD_OUTPUT_HANDLE
-12 GetStdHandle 'stderr ! | STD_ERROR_HANDLE
stdin 'console-mode GetConsoleMode drop
stdin console-mode $1a neg and SetConsoleMode drop
stdout 'console-mode GetConsoleMode drop
stdout console-mode $4 or SetConsoleMode drop

GetProcessHeap 'process-heap !
;

#kb 0

::key | -- key
stdin 'kb 1 0 0 ReadFile drop kb ;

::key? | -- f
stdin 0 WaitForSingleObject ;


::ms | ms --
Sleep ;

::allocate |( n -- a ior )
process-heap 0 rot HeapAlloc ;

::free |( a -- ior )
process-heap 0 rot HeapFree ;

::resize |( a n -- a ior )
process-heap rot rot 0 rot HeapReAlloc ;

::type | str cnt --
stdout rot rot 0 0 WriteFile drop ;

#crb ( 10 13 0 0 )
#esc[ ( $1b $5b 0 0 0 0 0 0 0 0 0 0 )

::cr 'crb 2 type ;

::.[ 'esc[ 2 + swap
( c@+ 1? rot c!+ swap ) 2drop
'esc[ swap over - type ;

46 changes: 36 additions & 10 deletions r3/win/sdl2.r3
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#sys-SDL_RenderCopy
#sys-SDL_RenderPresent

::SDL_Init sys-SDL_Init sys1 ;
::SDL_Quit sys-SDL_Quit sys0 ;
::SDL_Init sys-SDL_Init sys1 drop ;
::SDL_Quit sys-SDL_Quit sys0 drop ;
::SDL_GetNumVideoDisplays sys-SDL_GetNumVideoDisplays sys0 ;
::SDL_CreateWindow sys-SDL_CreateWindow sys6 ;
::SDL_GetWindowSurface sys-SDL_GetWindowSurface sys1 ;
::SDL_ShowCursor sys-SDL_ShowCursor sys1 ;
::SDL_UpdateWindowSurface sys-SDL_UpdateWindowSurface sys1 ;
::SDL_DestroyWindow sys-SDL_DestroyWindow sys1 ;
::SDL_ShowCursor sys-SDL_ShowCursor sys1 drop ;
::SDL_UpdateWindowSurface sys-SDL_UpdateWindowSurface sys1 drop ;
::SDL_DestroyWindow sys-SDL_DestroyWindow sys1 drop ;
::SDL_CreateRenderer sys-SDL_CreateRenderer sys3 ;
::SDL_CreateTexture sys-SDL_CreateTexture sys5 ;
::SDL_DestroyTexture sys-SDL_DestroyTexture sys1 ;
Expand All @@ -32,6 +32,26 @@
::SDL_RenderCopy sys-SDL_RenderCopy sys4 ;
::SDL_RenderPresent sys-SDL_RenderPresent sys1 ;

#sys-SDL_Delay
::SDL_Delay | dl --
sys-SDL_Delay sys1 drop ;

#sys-SDL_PollEvent
::SDL_PollEvent | &evt -- ok
sys-SDL_PollEvent sys1 ;

#sys-SDL_GetTicks
::SDL_GetTicks | -- msec
sys-SDL_GetTicks sys0 ;

#sys-SDL_StartTextInput
::SDL_StartTextInput
sys-SDL_StartTextInput sys0 drop ;

#sys-SDL_StopTextInput
::SDL_StopTextInput
sys-SDL_StopTextInput sys0 drop ;

::sdl2
"SDL2.DLL" loadlib
dup "SDL_Init" getproc 'sys-SDL_Init !
Expand All @@ -49,8 +69,14 @@
dup "SDL_UpdateTexture" getproc 'sys-SDL_UpdateTexture !
dup "SDL_RenderCopy" getproc 'sys-SDL_RenderCopy !
dup "SDL_RenderPresent" getproc 'sys-SDL_RenderPresent !

"SDL_Delay" getproc 'sys-SDL_Delay !
"SDL_PollEvent" getproc 'sys-SDL_PollEvent !
"SDL_GetTicks" getproc 'sys-SDL_GetTicks !
drop
;

##SDLevent * 56

##SDL_windows
##SDL_screen
Expand Down Expand Up @@ -83,19 +109,19 @@
::SDLinit | "titulo" w h --
2dup * 'sizebuffer !
'screenh ! 'screenw !
$3231 SDL_init drop
$3231 SDL_init
$1FFF0000 $1FFF0000 screenw screenh 0 SDL_CreateWindow dup 'SDL_windows !
SDL_GetWindowSurface dup 'SDL_screen !
24 + d@+ 'pitch !
4 + @ 'gr_buffer !

0 SDL_ShowCursor drop | disable cursor
0 SDL_ShowCursor | disable cursor
;

::SDLquit
SDL_windows SDL_DestroyWindow drop
SDL_Quit drop ;
SDL_windows SDL_DestroyWindow
SDL_Quit ;

::SDLupdate
SDL_windows SDL_UpdateWindowSurface drop ;
SDL_windows SDL_UpdateWindowSurface ;

0 comments on commit 8fdb00d

Please sign in to comment.