TempleOS Notes
William's notes on TempleOS.
These are my personal notes as I explore the world of TempleOS, not anything polished. Feel free to read but don't expect it to be correct.
April 24, 2016
Easy Project
underline hacking
Underlined text in TempleOS, combined with the default font can be a bit heavy handed.
I dont like it when the underline pixels connect to the letters.
There are a few options. Shifting up the each character of the font is problematic.
A half solution explored here -- reduce the number of pixels which are part of the underline.
So where to look? Start with F("underline"); Look around in some code.
My eyes lit up when I saw a hex code that looks something like this, while poking around code having to do with underlines.
0xFF0000000000000000
Why? - B/c it hints at a solid line, when converted into binary and wrapped into an 8 by 8 block.
0xFF is 1111 1111. To make it a dotted line, you would do something like this: 0101 0101 = 0x55.
I used 0x55 over 0xAA because it was easier for me to recall that 5 is 101 than A is 1010, but this is arbitrary. Use AA if you want.
After making an edit recompilation is neccessary, atleast I think, or maybe an Adam Include.
Location to Edit: /Adam/Gr/GrAsm.CPP.Z
Change this code:
//************************************
_GR_ROP_EQU_U8_NO_CLIPPING::
//Puts foreground char shape onto gr.dc2.
//ch.u8[1] is color as a whole byte
//ch ATTRf_UNDERLINE attr flag is used.
PUSH RBP
MOV RBP,RSP
MOVZX RAX,U8 SF_ARG1[RBP]
MOV RDX,U64 [&text.font]
MOV RAX,U64 [RDX+RAX*8] //RAX is 8x8 char font data, 64-bits
BT U64 SF_ARG1[RBP],ATTRf_UNDERLINE
JNC @@05
MOV RBX,0xFF00000000000000
OR RAX,RBX
@@05: TEST RAX,RAX
JZ I32 @@10
To this code:
//************************************
_GR_ROP_EQU_U8_NO_CLIPPING::
//Puts foreground char shape onto gr.dc2.
//ch.u8[1] is color as a whole byte
//ch ATTRf_UNDERLINE attr flag is used.
PUSH RBP
MOV RBP,RSP
MOVZX RAX,U8 SF_ARG1[RBP]
MOV RDX,U64 [&text.font]
MOV RAX,U64 [RDX+RAX*8] //RAX is 8x8 char font data, 64-bits
BT U64 SF_ARG1[RBP],ATTRf_UNDERLINE
JNC @@05
MOV RBX,0x5500000000000000
OR RAX,RBX
@@05: TEST RAX,RAX
JZ I32 @@10
Todo :
A. research how to make the underlines draw in a different color than the rest of the characters
B. research how to make the underlines animate. EG. flip between 0x5500... and 0xAA00...
(this is not just for cuteness -- it improves legibility of characters to have underlines from bleeding into characters.)
April 23, 2016
Foulproof Pointer Contrast after messing with color defintions.
If you change the mappings of colors, it is possible that the algorithm used to shift the colors of pointer might fail to retain contrast.
This happened to me, and my cursor failed to be visible unless I was holding down the left or right mouse button.
The culprit seems to be that there is some intelligent color shifting going on that assumes that the defined colors are infact uniquely defined.
Search for DrawInputPtr(CDC *dc) to update that code.
The function is in Adam/WinA
ROP_XOR is probably the inverse color(s?) in the graphics buffer below the mouse.
Here is my theory on how it works:
I think addition of LTPURPLE, LTCYAN, or BLACK is used to shift the color.
The expectation is that black is defined as 0, and that shifting the ROP_XOR by 0 should leave ROP_XOR,
which should be high contrast -- which is what we would want for the most common case -- that is, not having the left
or right mouse button depressed.
If we assume that the color variable can be 16 values, then adding beyond the number 15 would rewrap? IE, these operations should be happening mod 16.
So I think that if you define black to be another color, like 8, then it would actually get you back to where you started -- having an invisible mouse.
If you have messed up color defintions, do not rely on them to provide contrast. Just hardcode the amount of desired shifting.
This theory could be wrong in part or whole. Also, code as written is not tested, will confirm it later.
Before:
U0 DrawInputPtr(CDC *dc)
{
I64 x,y;
PUSHFD
CLI
x=ip.pos.x;
y=ip.pos.y;
POPFD
if (ip.show && ip.dev!=IP_NULL) {
if (!Bt(&sys_run_level,RLf_VGA)) //if text mode
gr.text_base[ip.pos_text.x+ip.pos_text.y*TEXT_COLS]^=0x7F00;
else {
if (gr.fp_draw_input_ptr) {
if (ip.lb)
dc->color=ROP_XOR+LTPURPLE^TRANSPARENT;
else if (ip.rb)
dc->color=ROP_XOR+LTCYAN^TRANSPARENT;
else
dc->color=ROP_XOR+BLACK^TRANSPARENT;
if (winmgr.grab_scroll && gr.fp_draw_grab_input_ptr)
(*gr.fp_draw_grab_input_ptr)(dc,x,y,winmgr.grab_scroll_closed);
else
(*gr.fp_draw_input_ptr)(dc,x,y);
}
}
}
}
After:
U0 DrawInputPtr(CDC *dc)
{
I64 x,y;
PUSHFD
CLI
x=ip.pos.x;
y=ip.pos.y;
POPFD
if (ip.show && ip.dev!=IP_NULL) {
if (!Bt(&sys_run_level,RLf_VGA)) //if text mode
gr.text_base[ip.pos_text.x+ip.pos_text.y*TEXT_COLS]^=0x7F00;
else {
if (gr.fp_draw_input_ptr) {
if (ip.lb)
dc->color=ROP_XOR+13^TRANSPARENT;
else if (ip.rb)
dc->color=ROP_XOR+11^TRANSPARENT;
else
dc->color=ROP_XOR+0^TRANSPARENT;
if (winmgr.grab_scroll && gr.fp_draw_grab_input_ptr)
(*gr.fp_draw_grab_input_ptr)(dc,x,y,winmgr.grab_scroll_closed);
else
(*gr.fp_draw_input_ptr)(dc,x,y);
}
}
}
}
April 23, 2016
FontEd is great. 8*8 bitmap fonts are great.
I am very interested in modifying Temple's font.
FontEd is great, you can see changes live.
The saving of fonts is a bit confusing at first. I copy some instructions from the comments here:
After making a font...
You can save it as a binary file with:
FileWrite("filename.BIN.Z",text.font,256*FONT_HEIGHT);
You can load it with:
U64 *my_font=FileRead("filename.BIN.Z");
text.aux_font=my_font;
CTRL-ALT-f will toggle main font and aux_font.
If you want to change the system font permanently,
save to a file with this font editor program
and cut and paste the code into ::/Kernel/Font8x8.CPP.
You will need to recompile Kernel by calling MakeOSDrvBootInstall().
See ::/Demo/ExtendedChars.CPP, ::/Demo/Games/CharDemo.CPP,
::/Demo/Graphics/CharAnimation.CPP and ::/Demo/ScreenCodes.CPP.
I will have more to post about fonts. I am currently trying to make a thin font. About halfway there.
The goal of the font is to have light look and calming effect. I am customizing the UI of Temple to better suit my preferences.