diff --git a/services/graphics-server/src/blitstr2/codegen/config.json b/services/graphics-server/src/blitstr2/codegen/config.json index 72d338399..24a8d815c 100644 --- a/services/graphics-server/src/blitstr2/codegen/config.json +++ b/services/graphics-server/src/blitstr2/codegen/config.json @@ -21,7 +21,8 @@ "indexType": "txt-row-major", "glyphTrim": "CJK", "rustout": "../fonts/emoji.rs", - "loaderout": "../../../../../loader/src/fonts/emoji.rs" + "loaderout": "../../../../../loader/src/fonts/emoji.rs", + "small": true }, { "name": "zh", @@ -35,7 +36,8 @@ "indexType": "txt-row-major", "glyphTrim": "CJK", "rustout": "../fonts/zh.rs", - "loaderout": "../../../../../loader/src/fonts/zh.rs" + "loaderout": "../../../../../loader/src/fonts/zh.rs", + "small": false }, { "name": "ja", @@ -49,7 +51,8 @@ "indexType": "txt-row-major", "glyphTrim": "CJK", "rustout": "../fonts/ja.rs", - "loaderout": "../../../../../loader/src/fonts/ja.rs" + "loaderout": "../../../../../loader/src/fonts/ja.rs", + "small": false }, { "name": "kr", @@ -63,7 +66,8 @@ "indexType": "txt-row-major", "glyphTrim": "CJK", "rustout": "../fonts/kr.rs", - "loaderout": "../../../../../loader/src/fonts/kr.rs" + "loaderout": "../../../../../loader/src/fonts/kr.rs", + "small": false }, { "name": "Bold", @@ -77,7 +81,8 @@ "indexType": "json-grid-coord", "glyphTrim": "proportional", "rustout": "../fonts/bold.rs", - "loaderout": "../../../../../loader/src/fonts/bold.rs" + "loaderout": "../../../../../loader/src/fonts/bold.rs", + "small": true }, { "name": "Mono", @@ -91,7 +96,8 @@ "indexType": "json-grid-coord", "glyphTrim": "monospace", "rustout": "../fonts/mono.rs", - "loaderout": "../../../../../loader/src/fonts/mono.rs" + "loaderout": "../../../../../loader/src/fonts/mono.rs", + "small": true }, { "name": "Regular", @@ -105,7 +111,8 @@ "indexType": "json-grid-coord", "glyphTrim": "proportional", "rustout": "../fonts/regular.rs", - "loaderout": "../../../../../loader/src/fonts/regular.rs" + "loaderout": "../../../../../loader/src/fonts/regular.rs", + "small": false }, { "name": "Tall", @@ -119,7 +126,8 @@ "indexType": "json-grid-coord", "glyphTrim": "proportional", "rustout": "../fonts/tall.rs", - "loaderout": "../../../../../loader/src/fonts/tall.rs" + "loaderout": "../../../../../loader/src/fonts/tall.rs", + "small": true }, { "name": "Small", @@ -133,7 +141,8 @@ "indexType": "json-grid-coord", "glyphTrim": "proportional", "rustout": "../fonts/small.rs", - "loaderout": "../../../../../loader/src/fonts/small.rs" + "loaderout": "../../../../../loader/src/fonts/small.rs", + "small": false } ] -} +} \ No newline at end of file diff --git a/services/graphics-server/src/blitstr2/codegen/lib/config.go b/services/graphics-server/src/blitstr2/codegen/lib/config.go index ed40c4f26..8353a9486 100644 --- a/services/graphics-server/src/blitstr2/codegen/lib/config.go +++ b/services/graphics-server/src/blitstr2/codegen/lib/config.go @@ -32,6 +32,7 @@ type ConfigGlyphSet struct { GlyphTrim string RustOut string LoaderOut string + Small bool } // Holds data parsed from a json index file @@ -71,6 +72,7 @@ func (c Config) Fonts() []FontSpec { gs.codepointMap(), gs.RustOut, gs.GlyphTrim, gs.LoaderOut, + gs.Small, } list = append(list, fs) } diff --git a/services/graphics-server/src/blitstr2/codegen/lib/fontspec.go b/services/graphics-server/src/blitstr2/codegen/lib/fontspec.go index 88a6a65c3..85baa6228 100644 --- a/services/graphics-server/src/blitstr2/codegen/lib/fontspec.go +++ b/services/graphics-server/src/blitstr2/codegen/lib/fontspec.go @@ -16,6 +16,7 @@ type FontSpec struct { RustOut string // Where should the generated rust source code go? GlyphTrim string // How should bitmap glyphs be trimmed (proportional or CJK)? LoaderOut string // Path to the split of the glyph data into the loader, to reduce the RAM load + Small bool // Is this font part of the "small" configuration set } // Look up trim limits based on row & column in glyph grid diff --git a/services/graphics-server/src/blitstr2/codegen/lib/templates.go b/services/graphics-server/src/blitstr2/codegen/lib/templates.go index 099866644..7942be80b 100644 --- a/services/graphics-server/src/blitstr2/codegen/lib/templates.go +++ b/services/graphics-server/src/blitstr2/codegen/lib/templates.go @@ -35,8 +35,8 @@ func RenderLoaderFileTemplate(f FontSpec, gs GlyphSet) string { context := loaderFileTemplateContext{f, gs, fname} return renderTemplate(loaderFileTemplate, "loaderfile", context) } -func RenderFontmapTemplate(fd []FontMap) string { - context := fontmapTemplateContext{fd} +func RenderFontmapTemplate(fd []FontMap, small_fd []FontMap) string { + context := fontmapTemplateContext{fd, small_fd} return renderTemplate(fontmapTemplate, "fontmap", context) } func RenderLoadermodTemplate(fd []FontSummary) string { @@ -67,7 +67,8 @@ type loaderFileTemplateContext struct { // Holds data for rendering fontmapTemplate type fontmapTemplateContext struct { - FontDir []FontMap + FontDir []FontMap + SmallFontDir []FontMap } type loadermodTemplateContext struct { FontDir []FontSummary @@ -120,12 +121,12 @@ pub const MAX_HEIGHT: u8 = {{.Font.Size}}; pub const CODEPOINTS: [u32; {{.GS.CodepointsLen}}] = [ {{.GS.Codepoints}}]; -#[cfg(any(feature="precursor", feature="renode"))] +#[cfg(any(feature="precursor", feature="renode", feature="cramium-soc"))] pub(crate) static GLYPH_LOCATION: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0); pub(crate) const GLYPH_LEN: usize = {{.GS.GlyphsLen}}; pub(crate) fn glyphs() -> &'static [u32] { - #[cfg(any(feature="precursor", feature="renode"))] + #[cfg(any(feature="precursor", feature="renode", feature="cramium-soc"))] unsafe { let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); core::slice::from_raw_parts(data, GLYPH_LEN) @@ -177,5 +178,15 @@ const fontmapTemplate = `#![cfg_attr(rustfmt, rustfmt_skip)] // The order of these modules affects the link order in the loader, which is referred to in the graphics engine. // To make changes, see /services/graphics-server/src/blitstr2/codegen/main.go #![allow(dead_code)] -{{range $f := .FontDir}}pub const {{$f.Name}}: usize = 0x{{$f.Len}}; -{{end}}` +#[cfg(not(feature = "cramium-soc"))] +pub const FONT_BASE: usize = 0x2053_0000; +#[cfg(feature = "cramium-soc")] +pub const FONT_BASE: usize = 0x6001_0000; + +{{range $f := .FontDir}}#[cfg(not(feature = "cramium-soc"))] +pub const {{$f.Name}}: usize = 0x{{$f.Len}}; +{{end}} +{{range $fs := .SmallFontDir}}#[cfg(feature = "cramium-soc")] +pub const {{$fs.Name}}: usize = 0x{{$fs.Len}}; +{{end}} +` diff --git a/services/graphics-server/src/blitstr2/codegen/main.go b/services/graphics-server/src/blitstr2/codegen/main.go index c58750213..13daead85 100644 --- a/services/graphics-server/src/blitstr2/codegen/main.go +++ b/services/graphics-server/src/blitstr2/codegen/main.go @@ -14,9 +14,6 @@ import ( "strings" ) -// Location of the font base in the loader -const font_base = 0x2053_0000 - // Command line switch to confirm intent of writing output files const confirm = "--write" @@ -47,11 +44,9 @@ func codegen() { fsList := conf.Fonts() var fdir []FontSummary var offsets []FontMap + var small_offsets []FontMap var cur_address int = 0 - offsets = append(offsets, lib.FontMap{ - Name: "FONT_BASE", - Len: fmt.Sprintf("%x", font_base), - }) + var small_cur_address int = 0 for _, f := range fsList { // Find all the glyphs and pack them into a list of blit pattern objects pl := patternListFromSpriteSheet(f) @@ -75,18 +70,32 @@ func codegen() { Len: fmt.Sprintf("%x", cur_address), } offsets = append(offsets, offset) + if f.Small { + small_offsets = append(small_offsets, offset) + } length := lib.FontMap{ Name: strings.ToUpper(f.Name) + "_LEN", Len: fmt.Sprintf("%x", gs.GlyphsLen*4), } offsets = append(offsets, length) + if f.Small { + small_offsets = append(small_offsets, length) + } cur_address = cur_address + gs.GlyphsLen*4 + if f.Small { + small_cur_address = small_cur_address + gs.GlyphsLen*4 + } } total := lib.FontMap{ Name: "FONT_TOTAL_LEN", Len: fmt.Sprintf("%x", cur_address), } offsets = append(offsets, total) + small_total := lib.FontMap{ + Name: "FONT_TOTAL_LEN", + Len: fmt.Sprintf("%x", small_cur_address), + } + small_offsets = append(small_offsets, small_total) for _, fs := range fdir { fmt.Println(fs) } @@ -94,7 +103,7 @@ func codegen() { fmt.Println("Writing to", conf.GetLoaderMod()) ioutil.WriteFile(conf.GetLoaderMod(), []byte(loadermod), 0644) - fontmap := RenderFontmapTemplate(offsets) + fontmap := RenderFontmapTemplate(offsets, small_offsets) fmt.Println("Writing to", conf.GetFontMap()) ioutil.WriteFile(conf.GetFontMap(), []byte(fontmap), 0644) }