| 1 | #include <stdint.h> |
| 2 | #include "pt2_tables.h" |
| 3 | #include "pt2_textout.h" |
| 4 | #include "pt2_structs.h" |
| 5 | #include "pt2_config.h" |
| 6 | #include "pt2_visuals.h" |
| 7 | |
| 8 | #define MIDDLE_ROW 7 |
| 9 | #define VISIBLE_ROWS 15 |
| 10 | |
| 11 | static const char emptyDottedEffect[4] = { 0x02, 0x02, 0x02, 0x00 }; |
| 12 | static const char emptyDottedSample[3] = { 0x02, 0x02, 0x00 }; |
| 13 | |
| 14 | static int32_t periodToNote(int32_t period) // 0 = no note, 1 = illegal note, 2..37 = note |
| 15 | { |
| 16 | if (period == 0) |
| 17 | return 0; |
| 18 | |
| 19 | int32_t beg = 0; |
| 20 | int32_t end = 36 - 1; |
| 21 | |
| 22 | // do binary search |
| 23 | while (beg <= end) |
| 24 | { |
| 25 | const int32_t mid = (beg + end) >> 1; |
| 26 | |
| 27 | int32_t tableVal = periodTable[mid]; |
| 28 | if (period == tableVal) |
| 29 | return 2+mid; |
| 30 | |
| 31 | if (period < tableVal) |
| 32 | beg = mid+1; |
| 33 | else |
| 34 | end = mid-1; |
| 35 | } |
| 36 | |
| 37 | return 1; // illegal note |
| 38 | } |
| 39 | |
| 40 | static void drawPatternNormal(void) |
| 41 | { |
| 42 | const char **noteNames; |
| 43 | if (config.accidental) |
| 44 | noteNames = (const char **)noteNames2; |
| 45 | else |
| 46 | noteNames = (const char **)noteNames1; |
| 47 | |
| 48 | note_t *patt = song->patterns[song->currPattern]; |
| 49 | int32_t row = song->currRow - MIDDLE_ROW; |
| 50 | int32_t y = 140; |
| 51 | |
| 52 | for (int32_t i = 0; i < VISIBLE_ROWS; i++, y += 7, row++) |
| 53 | { |
| 54 | if (row < 0 || row >= MOD_ROWS) |
| 55 | { |
| 56 | // clear empty rows outside of pattern data |
| 57 | fillRect(8, y, FONT_CHAR_W*2, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 58 | fillRect(32+(0*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 59 | fillRect(32+(1*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 60 | fillRect(32+(2*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 61 | fillRect(32+(3*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | if (i == MIDDLE_ROW) // middle row has twice as tall glyphs |
| 66 | { |
| 67 | y++; |
| 68 | printTwoDecimalsBigBg(8, y, row, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 69 | |
| 70 | note_t *note = patt + (row << 2); |
| 71 | int32_t x = 32; |
| 72 | for (int32_t j = 0; j < PAULA_VOICES; j++, note++) |
| 73 | { |
| 74 | textOutBigBg(x, y, noteNames[periodToNote(note->period)], video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 75 | x += 8*3; |
| 76 | |
| 77 | char smpChar = (config.blankZeroFlag && !(note->sample & 0xF0)) ? ' ' : hexTable[note->sample >> 4]; |
| 78 | charOutBigBg(x, y, smpChar, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 79 | x += 8; |
| 80 | |
| 81 | printOneHexBigBg(x, y, note->sample & 0x0F, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 82 | x += 8; |
| 83 | |
| 84 | printOneHexBigBg(x, y, note->command, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 85 | x += 8; |
| 86 | |
| 87 | printTwoHexBigBg(x, y, note->param, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 88 | x += (8*2)+8; |
| 89 | } |
| 90 | y += 6; |
| 91 | } |
| 92 | else // non-middle rows |
| 93 | { |
| 94 | printTwoDecimalsBg(8, y, row, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 95 | |
| 96 | note_t *note = patt + (row << 2); |
| 97 | int32_t x = 32; |
| 98 | for (int32_t j = 0; j < PAULA_VOICES; j++, note++) |
| 99 | { |
| 100 | textOutBg(x, y, noteNames[periodToNote(note->period)], video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 101 | x += 8*3; |
| 102 | |
| 103 | char smpChar = (config.blankZeroFlag && !(note->sample & 0xF0)) ? ' ' : hexTable[note->sample >> 4]; |
| 104 | charOutBg(x, y, smpChar, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 105 | x += 8; |
| 106 | |
| 107 | printOneHexBg(x , y, note->sample & 0x0F, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 108 | x += 8; |
| 109 | |
| 110 | printOneHexBg(x, y, note->command, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 111 | x += 8; |
| 112 | |
| 113 | printTwoHexBg(x, y, note->param, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 114 | x += (8*2)+8; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static void drawPatternDotted(void) |
| 122 | { |
| 123 | const char **noteNames; |
| 124 | if (config.accidental) |
| 125 | noteNames = (const char **)noteNames4; |
| 126 | else |
| 127 | noteNames = (const char **)noteNames3; |
| 128 | |
| 129 | note_t *patt = song->patterns[song->currPattern]; |
| 130 | int32_t row = song->currRow - MIDDLE_ROW; |
| 131 | int32_t y = 140; |
| 132 | |
| 133 | for (int32_t i = 0; i < VISIBLE_ROWS; i++, y += 7, row++) |
| 134 | { |
| 135 | if (row < 0 || row >= MOD_ROWS) |
| 136 | { |
| 137 | // clear empty rows outside of pattern data |
| 138 | fillRect(8, y, FONT_CHAR_W*2, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 139 | fillRect(32+(0*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 140 | fillRect(32+(1*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 141 | fillRect(32+(2*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 142 | fillRect(32+(3*72), y, FONT_CHAR_W*8, FONT_CHAR_H, video.palette[PAL_BACKGRD]); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | if (i == MIDDLE_ROW) // middle row has twice as tall glyphs |
| 147 | { |
| 148 | y++; |
| 149 | printTwoDecimalsBigBg(8, y, row, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 150 | |
| 151 | note_t *note = patt + (row << 2); |
| 152 | int32_t x = 32; |
| 153 | for (int32_t j = 0; j < PAULA_VOICES; j++, note++) |
| 154 | { |
| 155 | textOutBigBg(x, y, noteNames[periodToNote(note->period)], video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 156 | x += 8*3; |
| 157 | |
| 158 | if (note->sample == 0) |
| 159 | { |
| 160 | textOutBigBg(x, y, emptyDottedSample, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 161 | x += 8*2; |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | char smpChar = (note->sample & 0xF0) ? hexTable[note->sample >> 4] : 0x02; |
| 166 | charOutBigBg(x, y, smpChar, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 167 | x += 8; |
| 168 | printOneHexBigBg(x, y, note->sample & 0x0F, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 169 | x += 8; |
| 170 | } |
| 171 | |
| 172 | if (note->command == 0 && note->param == 0) |
| 173 | { |
| 174 | textOutBigBg(x, y, emptyDottedEffect, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 175 | x += (8*3)+8; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | printOneHexBigBg(x, y, note->command, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 180 | x += 8; |
| 181 | printTwoHexBigBg(x, y, note->param, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]); |
| 182 | x += (8*2)+8; |
| 183 | } |
| 184 | } |
| 185 | y += 6; |
| 186 | } |
| 187 | else // non-middle rows |
| 188 | { |
| 189 | printTwoDecimalsBg(8, y, row, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 190 | |
| 191 | // pattern data |
| 192 | note_t *note = patt + (row << 2); |
| 193 | int32_t x = 32; |
| 194 | for (int32_t j = 0; j < PAULA_VOICES; j++, note++) |
| 195 | { |
| 196 | textOutBg(x, y, noteNames[periodToNote(note->period)], video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 197 | x += 8*3; |
| 198 | |
| 199 | if (note->sample == 0) |
| 200 | { |
| 201 | textOutBg(x, y, emptyDottedSample, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 202 | x += 8*2; |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | char smpChar = (note->sample & 0xF0) ? hexTable[note->sample >> 4] : 0x02; |
| 207 | charOutBg(x, y, smpChar, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 208 | x += 8; |
| 209 | printOneHexBg(x, y, note->sample & 0x0F, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 210 | x += 8; |
| 211 | } |
| 212 | |
| 213 | if (note->command == 0 && note->param == 0) |
| 214 | { |
| 215 | textOutBg(x, y, emptyDottedEffect, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 216 | x += (8*3)+8; |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | printOneHexBg(x, y, note->command, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 221 | x += 8; |
| 222 | printTwoHexBg(x, y, note->param, video.palette[PAL_PATTXT], video.palette[PAL_BACKGRD]); |
| 223 | x += (8*2)+8; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void redrawPattern(void) |
| 232 | { |
| 233 | if (config.pattDots) |
| 234 | drawPatternDotted(); |
| 235 | else |
| 236 | drawPatternNormal(); |
| 237 | } |