From 33ccdd91ebe23ad5354cf50d24b2e80d81e9b0ec Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Mon, 17 May 2021 17:28:13 -0700 Subject: [PATCH] Fix lastOffset calculations in Apple II hi-res visualizer The calculations were wrong for certain situations, generating answers that were useless or that caused a false-positive overflow error. This adds a couple of simple regression tests, modeled after layout of the Lode Runner sprite sheet (which worked fine before) and the Empire II EWS3 font (which failed). This also bumps up some of the arbitrary limits in the visualizer. (issue #94) --- CommonUtil/Font8x8.cs | 13 ++- SourceGen/RuntimeData/Apple/VisHiRes.cs | 21 +++-- .../Visualization/apple2-grid-test1 | Bin 0 -> 40 bytes .../Visualization/apple2-grid-test1.dis65 | 89 ++++++++++++++++++ .../Visualization/apple2-grid-test2 | Bin 0 -> 80 bytes .../Visualization/apple2-grid-test2.dis65 | 86 +++++++++++++++++ 6 files changed, 198 insertions(+), 11 deletions(-) create mode 100644 SourceGen/SGTestData/Visualization/apple2-grid-test1 create mode 100644 SourceGen/SGTestData/Visualization/apple2-grid-test1.dis65 create mode 100644 SourceGen/SGTestData/Visualization/apple2-grid-test2 create mode 100644 SourceGen/SGTestData/Visualization/apple2-grid-test2.dis65 diff --git a/CommonUtil/Font8x8.cs b/CommonUtil/Font8x8.cs index 8fbb78c..6da283f 100644 --- a/CommonUtil/Font8x8.cs +++ b/CommonUtil/Font8x8.cs @@ -23,6 +23,8 @@ namespace CommonUtil { /// so glyphs can be packed tightly. /// public static class Font8x8 { + private static List sBitData; + /// /// Returns an 8-byte array for the specified character. Each byte represents one /// row. The first byte holds the top row, and the most significant bit in each @@ -41,6 +43,11 @@ namespace CommonUtil { return sBitData[index]; } + /// + /// Maps a character value to an index into sFontData. + /// + /// Character to find. + /// Index of character's glyph, or index of REPLACEMENT CHARACTER. private static int MapChar(char ch) { if (ch == ' ') { return 1; @@ -53,8 +60,6 @@ namespace CommonUtil { } } - private static List sBitData; - /// /// Converts the easy-to-edit string data into easy-to-process bitmaps. /// @@ -170,7 +175,7 @@ namespace CommonUtil { "#.....#." + ".#####.." + "........", - // ' ' + // '7' "#######." + "......#." + ".....#.." + @@ -179,7 +184,7 @@ namespace CommonUtil { "..#....." + ".#......" + "........", - // ' ' + // '8' ".#####.." + "#.....#." + "#.....#." + diff --git a/SourceGen/RuntimeData/Apple/VisHiRes.cs b/SourceGen/RuntimeData/Apple/VisHiRes.cs index b7a4f56..341ce5c 100644 --- a/SourceGen/RuntimeData/Apple/VisHiRes.cs +++ b/SourceGen/RuntimeData/Apple/VisHiRes.cs @@ -64,9 +64,9 @@ namespace RuntimeData.Apple { new VisParamDescr("Height", P_HEIGHT, typeof(int), 1, 1024, 0, 1), new VisParamDescr("Column stride (bytes)", - P_COL_STRIDE, typeof(int), 0, 1024, 0, 0), + P_COL_STRIDE, typeof(int), 0, 4096, 0, 0), new VisParamDescr("Row stride (bytes)", - P_ROW_STRIDE, typeof(int), 0, 1024, 0, 0), + P_ROW_STRIDE, typeof(int), 0, 4096, 0, 0), new VisParamDescr("Color", P_IS_COLOR, typeof(bool), 0, 0, 0, true), new VisParamDescr("First col odd", @@ -88,13 +88,13 @@ namespace RuntimeData.Apple { new VisParamDescr("Cell height", P_ITEM_HEIGHT, typeof(int), 1, 192, 0, 1), new VisParamDescr("Column stride (bytes)", - P_COL_STRIDE, typeof(int), 0, 1024, 0, 0), + P_COL_STRIDE, typeof(int), 0, 4096, 0, 0), new VisParamDescr("Row stride (bytes)", - P_ROW_STRIDE, typeof(int), 0, 1024, 0, 0), + P_ROW_STRIDE, typeof(int), 0, 4096, 0, 0), new VisParamDescr("Cell stride (bytes)", P_CELL_STRIDE, typeof(int), 0, 4096, 0, 0), new VisParamDescr("Number of items", - P_COUNT, typeof(int), 1, 1024, 0, 64), + P_COUNT, typeof(int), 1, 4096, 0, 64), new VisParamDescr("Color", P_IS_COLOR, typeof(bool), 0, 0, 0, true), new VisParamDescr("First col odd", @@ -205,11 +205,14 @@ namespace RuntimeData.Apple { return null; } - int lastOffset = offset + rowStride * height - (colStride - 1) - 1; + int lastOffset = offset + rowStride * (height - 1) + + colStride * (byteWidth - 1); if (lastOffset >= mFileData.Length) { mAppRef.ReportError("Bitmap runs off end of file (last offset +" + lastOffset.ToString("x6") + ")"); return null; + //} else { + // mAppRef.DebugLog("last offset=+" + lastOffset.ToString("x6")); } VisBitmap8 vb = new VisBitmap8(byteWidth * 7, height); @@ -283,11 +286,15 @@ namespace RuntimeData.Apple { } int lastOffset = offset + (cellStride * (count - 1)) + - rowStride * itemHeight - (colStride - 1) - 1; + rowStride * (itemHeight - 1) + + colStride * (itemByteWidth - 1); if (lastOffset >= mFileData.Length) { mAppRef.ReportError("Bitmap runs off end of file (last offset +" + lastOffset.ToString("x6") + ")"); return null; + //} else { + // mAppRef.DebugLog("lastOffset=+" + lastOffset.ToString("x6") + + // ", len=" + mFileData.Length.ToString("x6")); } // Set the number of horizontal cells. For small counts we try to make it square, diff --git a/SourceGen/SGTestData/Visualization/apple2-grid-test1 b/SourceGen/SGTestData/Visualization/apple2-grid-test1 new file mode 100644 index 0000000000000000000000000000000000000000..89cb39ab9e01d9edd152f39ef858634709ea0afa GIT binary patch literal 40 pcmb