Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Remove menu magic numbers #47

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions driver/bk1080.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include "driver/system.h"
#include "misc.h"

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

static const uint16_t BK1080_RegisterTable[] = {
0x0008, 0x1080, 0x0201, 0x0000,
0x40C0, 0x0A1F, 0x002E, 0x02FF,
Expand Down
7 changes: 4 additions & 3 deletions driver/st7565.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "driver/spi.h"
#include "driver/st7565.h"
#include "driver/system.h"
#include "misc.h"

uint8_t gStatusLine[128];
uint8_t gFrameBuffer[7][128];
Expand Down Expand Up @@ -59,10 +60,10 @@ void ST7565_BlitFullScreen(void)
SPI_ToggleMasterMode(&SPI0->CR, false);
ST7565_WriteByte(0x40);

for (Line = 0; Line < 7; Line++) {
for (Line = 0; Line < ARRAY_SIZE(gFrameBuffer); Line++) {
ST7565_SelectColumnAndLine(4U, Line + 1U);
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);
for (Column = 0; Column < 128; Column++) {
for (Column = 0; Column < ARRAY_SIZE(gFrameBuffer[0]); Column++) {
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {
}
SPI0->WDR = gFrameBuffer[Line][Column];
Expand All @@ -83,7 +84,7 @@ void ST7565_BlitStatusLine(void)
ST7565_SelectColumnAndLine(4, 0);
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_A0);

for (i = 0; i < 0x80; i++) {
for (i = 0; i < ARRAY_SIZE(gStatusLine); i++) {
while ((SPI0->FIFOST & SPI_FIFOST_TFF_MASK) != SPI_FIFOST_TFF_BITS_NOT_FULL) {
}
SPI0->WDR = gStatusLine[i];
Expand Down
3 changes: 3 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <stdbool.h>
#include <stdint.h>


#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

#define IS_MR_CHANNEL(x) ((x) >= MR_CHANNEL_FIRST && (x) <= MR_CHANNEL_LAST)
#define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
#define IS_NOAA_CHANNEL(x) ((x) >= NOAA_CHANNEL_FIRST && (x) <= NOAA_CHANNEL_LAST)
Expand Down
27 changes: 20 additions & 7 deletions ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ uint8_t gMenuCursor;
int8_t gMenuScrollDirection;
uint32_t gSubMenuSelection;

//Pixel where we split the screen: left is menu selection, right is menu item content
#define SPLIT (50)

void UI_DisplayMenu(void)
{
char String[16];
Expand All @@ -186,29 +189,39 @@ void UI_DisplayMenu(void)

memset(gFrameBuffer, 0, sizeof(gFrameBuffer));

/* Print the 3 visible menu items */
for (i = 0; i < 3; i++) {
if (gMenuCursor || i) {
if ((gMenuListCount - 1) != gMenuCursor || (i != 2)) {
UI_PrintString(MenuList[gMenuCursor + i - 1], 0, 127, i * 2, 8, false);
UI_PrintString(MenuList[gMenuCursor + i - 1], 0, SPLIT - 2, i * 2, 8, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a bug fix 😄

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with "bug fix" ? The original uses 127. From Ghidra:

            if (((cursor | i) != 0) && ((gMenuListCount - 1 != cursor || (i != 2)))) {
                    GUI_PrintString("SQL" + ((cursor + i) - 1 & 0xff) * 7,0,0x7f,(i << 0x19) >> 0x18,8,0);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean a bug by QS, then I have the "fixes" branch for that. Fixes is rebased on v2.01.31 which is rebased on main.
I have fixed a few bugs in "fixes" that QS firmware (e.g. the 8.33kHz step for airband was not working correctly).

I'll test the "48" here and commit to fixes after the test.

}
}
}
for (i = 0; i < 48; i++) {

/* Invert for the select item */
for (i = 0; i < SPLIT - 2; i++) {
gFrameBuffer[2][i] ^= 0xFF;
gFrameBuffer[3][i] ^= 0xFF;
}
for (i = 0; i < 7; i++) {
gFrameBuffer[i][48] = 0xFF;
gFrameBuffer[i][49] = 0xFF;

/* Create a vertical line line, 2 pixels wide */
for (i = 0; i < ARRAY_SIZE(gFrameBuffer); i++) {
gFrameBuffer[i][SPLIT - 2] = 0xFF;
gFrameBuffer[i][SPLIT - 1] = 0xFF;
}

/* Print the number of the current menu item, 2 digits 1 pixel from split */
NUMBER_ToDigits(gMenuCursor + 1, String);
UI_DisplaySmallDigits(2, String + 6, 33, 6);
UI_DisplaySmallDigits(2, String + 6, SPLIT - (2 * 8) - 1, 6);

/* Display submenu arrow */
if (gIsInSubMenu) {
memcpy(gFrameBuffer[0] + 50, BITMAP_CurrentIndicator, sizeof(BITMAP_CurrentIndicator));
memcpy(gFrameBuffer[0] + SPLIT, BITMAP_CurrentIndicator, sizeof(BITMAP_CurrentIndicator));
}

memset(String, 0, sizeof(String));

/* Get menu item content as string */
switch (gMenuCursor) {
case MENU_SQL:
case MENU_MIC:
Expand Down