davazp / eulex

A straightforward standalone Forth implementation for x86.
http://davazp.net/2012/12/08/eulex-forth-implementation.html
GNU General Public License v3.0
127 stars 18 forks source link

Some questions to get it going / Keyboard Layout #2

Open mczero80 opened 6 years ago

mczero80 commented 6 years ago

Hi,

first thank you for this wonderful forth variant! I really like it.

I have some questions, and I must admit, that I am a forth beginner.

I would like to modify keyboard.fs for my german keyboard, but I am really unsure how. Some important characters like @ or \ are only reachable with ALT-key on a german keyboard. keyboard.fs unfortunately seems only to map a unshifted and a shifted keymap, at least thats how I understand the code for now. Perhaps you could help me a bit what to modify?

And the second question is perhaps a bit ridiculous, I don't know how to start the editor that you build! I don't find a word to execute for it.

Third and last question (I hope), how to use the in-built assembler. Does it follow a particular forth assembler standard? I would be very interested, how I could take a value from the stack, and do some assembler things like MOVing, and how to put a value from assembler back on the forth stack.

Thank you very much in advance!

davazp commented 6 years ago

Hi @mczero80

first thank you for this wonderful forth variant! I really like it.

Thanks!

I'll answer your questions in separate messages.

davazp commented 6 years ago

I would like to modify keyboard.fs for my german keyboard, but I am really unsure how.

There are a few different ways of doing that. Probably one of the easiest ways is to rename TBLSC in the code below (and the shift version) to be US specific, and define a deferred word so the rest of the code works without any change.

CREATE TBLSC-US
( )
( ) 0 c, ESC c,
( )       | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | =     BACK c,
( ) TAB c,  | q | w | e | r | t | y | u | i | o | p | [ | ]    RET c,
( ) CTRL c,  | a | s | d | f | g | h | j | k | l | ; | ' | `
( ) SHIFT c,  | \ | z | x | c | v | b | n | m | , | . | /    SHIFT c,
( ) PRSCR c, ALT c,     ______SPACE______ c,       CAPSLOCK c,
( )
( ) TBLSC-SPECIAL
( )
TBLSC-US END.

For example, you could switch keymaps with something like

DEFER TBLSC

: US ['] TBLSC-US ['] TBLSC-US-SHIFT ;

: setxkmap ( tblsc-addr tblsc-shift-addr )
  IS TBLSC-SHIFT
  IS TBLSC ;

\ And call it like
US setxkmap
davazp commented 6 years ago

And the second question is perhaps a bit ridiculous, I don't know how to start the editor that you build! I don't find a word to execute for it.

It's definitely ridicuous from my side :-D I should have documented it better. Don't worry, I also struggle to remember.

Try typing this in a freshly booted eulex:

eulex \ will switch to the eulex vocabulary, the main one, where most of the internal code lives

\ The editor.fs is a block-editor. Blocks are not like text files, they are fixed length. Look at blocks.fs for an idea about what they are, or google a bit for it.  Eulex provides 2 backends for blocks,  memory and floppy.  This command will switch to the memory implementation.
use-memory  

\ This will open the editor for the block 0.
0 edit

\ Here you can type some emacs-like keybindings. You can save with `C-x C-s`, navigate and exit with `C-x C-c`.  If you later open the same block, you should see the same content.
davazp commented 6 years ago

Third and last question (I hope), how to use the in-built assembler. Does it follow a particular forth assembler standard?

Not really super standard, but I think it is mostly conventional. The thing about the assembler is, it is not in use in the project. No other code is using that assembler. It was an attempt for me to bootstrap the whole project, I wanted to get rid of forth.S (the basic Forth core written in Assembly).

That being said, here is a snippet that you can try. Note, you can execute assembler.fs into gforth as well! (after all the idea was to bootstrap this).

But you can also run this in Eulex. Copy the following snippet to eulexrc.fs (or you could type it into the REPL):

eulex
require @assembler.fs
\ Enable the vocabulary
also assembler

\ Assembly is compiled into the dictionary.. give it a name
create target  

\ compile some code
nop
5 # %eax mov
ret

\ Disassemble!
target disassemble-memory

\ Or Look at the binary code
target 10 dump

It supports most of the addressing modes and such, but it is not very well tested. So be preapred to touch assembler.fs itself if you want to work on it. If you would like to know the register conventions and such, have a look to forth.s itself.

Let me know if you have any other questions!

mczero80 commented 6 years ago

Thank you very much! I will take a look into it tomorrow. So far, eulex is really promising to play around with forth as a standalone system.

I found some really cool forth benchmarks, and would like to try them. So far, only one word seems to be missing for benchmarking, "TIMER-RESET" . Perhaps I am able to implement it somehow. And then I thought about some graphic modes, like 320x200x256 VGA mode- therefor I need some assembler to play around.

davazp commented 6 years ago

That sounds great! The compiler is quite naive unfortunately, but any improvement is welcome!

I would have liked to define a IR for the compilation instead, as I did in this other project https://github.com/ams-hackers/gbforth . You may be interested in that one as well.

It has some technical docs: https://ams-hackers.github.io/gbforth/

mczero80 commented 6 years ago

Just searched google for IR, you mean intermediate representation? I am no compiler expert, but I guess it is a form of abstraction for portability or speedup. It is not that big problem if eulex is not very fast. I just like the idea "How far can we go with a minimum forth system, can we build a complete operating system with it and what can it look like?".

I came across gbforth recently, and I must say that I have a gameboy myself and that it sounds interesting, but I don't know for what its good really? Could I write a small game like tetris with it, while avoiding Z80 assembler? Perhaps it is just because the gameboy has no keyboard, which irritates me in this case. But apart from my understanding problem, they are all really great projects, and worth a look!

davazp commented 6 years ago

Yes, intermediate representation. It allows you to easily transform that representation before the code is emitted, so you can implement some optimizations.

I came across gbforth recently, and I must say that I have a gameboy myself and that it sounds interesting, but I don't know for what its good really? Yeah, it is not extremely useful πŸ˜„ but it is nice to explore some old hardware and Forth. Also, it can be good as a source of inspiration if you want to implement something into Eulex :-)

Anyway, let me know how it goes!

mczero80 commented 6 years ago

Sure, I will give feedback, perhaps even upload a pull request to github when I have something interesting, that is useful too! :)

Ahh one more question, I am sorry. Could I boot eulex from grub? I know, it is dangerous to use it on a real machine, but that is no problem here.

davazp commented 6 years ago

Sure. It should boot. I haven' tried on real hardware for a while... it would be wise to try. Hopefully there is no big issues!

mczero80 commented 6 years ago

Hi, still haven't tested it on bare metal. Your proposed changes for keyboard.fs work as intended. But I had no luck implementing keyboard chars, that are reached while holding ALT. Perhaps there could be something implemented like CREATE TBLSC-ALT Or better, localized CREATE TBLSC-US-ALT and CREATE TBLSC-US-CTRL ? From there on, it would be easy to implement different international layouts. Apart from special chars like the german ΓΆ,ΓΌ,Γ€ - but those are not that important. What do you think?

davazp commented 6 years ago

So each modifier alt ctrl and shift will switch to a different table.. what about when multiple modifiers are active? is there any character that can be typed like that? If there are they are probably just a few so and few combinations of modifiers as well. So it sounds reasonable.

For special characters like ΓΆ,ΓΌ,Γ€, they are mostly typed with multiple keys right? It's is a separated problem but I like how emacs does it with input methods.

So, it sounds good to me! πŸ‘

mczero80 commented 6 years ago

As far as I know, there are no chars that are in a ALT-CTRL table. Only ALT, CTRL and SHIFT as separate tables. ΓΆ, ΓΌ and Γ€ are reachable without a modifier, but there are uppercase chars from it: Γ„,Γ– and Ü while holding SHIFT. I tried inserting Γ€, ΓΆ and ΓΌ, but both gave me a compile error (I guess missing words for them)

Really important are chars like \ of course. And they need a ALT table for german keyboards. I guess other countries need a ALT table as well...

mczero80 commented 6 years ago

Btw I will take a look into emacs keys, so far I have only used nano and vim :D