Skip to content

Commit cb22351

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
Optimized and added autotest for gfx_SetDefaultPalette
1 parent a5a1c23 commit cb22351

File tree

4 files changed

+137
-3
lines changed

4 files changed

+137
-3
lines changed

src/graphx/graphx.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,11 @@ gfx_SetDefaultPalette:
337337
ld a,b
338338
rrca
339339
xor a,b
340-
and a,224
340+
and a,$E0
341341
xor a,b
342342
ld (de),a
343+
ld a,e ; E = B * 2, so we can remove one rla
343344
inc de
344-
ld a,b
345-
rla
346345
rla
347346
rla
348347
ld a,b

test/graphx/palette/autotest.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"transfer_files": [
3+
"bin/DEMO.8xp"
4+
],
5+
"target": {
6+
"name": "DEMO",
7+
"isASM": true
8+
},
9+
"sequence": [
10+
"action|launch",
11+
"delay|200",
12+
"hashWait|1",
13+
"key|enter",
14+
"delay|300",
15+
"hashWait|2"
16+
],
17+
"hashes": {
18+
"1": {
19+
"description": "All tests passed",
20+
"timeout": 5000,
21+
"start": "vram_start",
22+
"size": "vram_16_size",
23+
"expected_CRCs": [
24+
"38E2AD5A"
25+
]
26+
},
27+
"2": {
28+
"description": "Exit",
29+
"start": "vram_start",
30+
"size": "vram_16_size",
31+
"expected_CRCs": [
32+
"FFAF89BA",
33+
"101734A5",
34+
"9DA19F44",
35+
"A32840C8",
36+
"349F4775"
37+
]
38+
}
39+
}
40+
}

test/graphx/palette/makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ----------------------------
2+
# Makefile Options
3+
# ----------------------------
4+
5+
NAME = DEMO
6+
ICON = icon.png
7+
DESCRIPTION = "CE C Toolchain Demo"
8+
COMPRESSED = NO
9+
10+
CFLAGS = -Wall -Wextra -Wshadow -Oz
11+
CXXFLAGS = -Wall -Wextra -Wshadow -Oz
12+
13+
PREFER_OS_LIBC = NO
14+
15+
# ----------------------------
16+
17+
include $(shell cedev-config --makefile)

test/graphx/palette/src/main.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
#include <graphx.h>
6+
#include <ti/screen.h>
7+
#include <ti/getcsc.h>
8+
#include <sys/util.h>
9+
10+
#define PALETTE_SIZE (256 * sizeof(uint16_t))
11+
12+
const uint8_t palette_8bpp[PALETTE_SIZE] = {
13+
0x00, 0x00, 0x81, 0x00, 0x02, 0x01, 0x83, 0x01, 0x04, 0x02, 0x85, 0x02, 0x06, 0x03, 0x87, 0x03,
14+
0x08, 0x04, 0x89, 0x04, 0x0a, 0x05, 0x8b, 0x05, 0x0c, 0x06, 0x8d, 0x06, 0x0e, 0x07, 0x8f, 0x07,
15+
0x10, 0x08, 0x91, 0x08, 0x12, 0x09, 0x93, 0x09, 0x14, 0x0a, 0x95, 0x0a, 0x16, 0x0b, 0x97, 0x0b,
16+
0x18, 0x0c, 0x99, 0x0c, 0x1a, 0x0d, 0x9b, 0x0d, 0x1c, 0x0e, 0x9d, 0x0e, 0x1e, 0x0f, 0x9f, 0x0f,
17+
0x00, 0x90, 0x81, 0x90, 0x02, 0x91, 0x83, 0x91, 0x04, 0x92, 0x85, 0x92, 0x06, 0x93, 0x87, 0x93,
18+
0x08, 0x94, 0x89, 0x94, 0x0a, 0x95, 0x8b, 0x95, 0x0c, 0x96, 0x8d, 0x96, 0x0e, 0x97, 0x8f, 0x97,
19+
0x10, 0x98, 0x91, 0x98, 0x12, 0x99, 0x93, 0x99, 0x14, 0x9a, 0x95, 0x9a, 0x16, 0x9b, 0x97, 0x9b,
20+
0x18, 0x9c, 0x99, 0x9c, 0x1a, 0x9d, 0x9b, 0x9d, 0x1c, 0x9e, 0x9d, 0x9e, 0x1e, 0x9f, 0x9f, 0x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f7,
43+
0x70, 0xf8, 0xf1, 0xf8, 0x72, 0xf9, 0xf3, 0xf9, 0x74, 0xfa, 0xf5, 0xfa, 0x76, 0xfb, 0xf7, 0xfb,
44+
0x78, 0xfc, 0xf9, 0xfc, 0x7a, 0xfd, 0xfb, 0xfd, 0x7c, 0xfe, 0xfd, 0xfe, 0x7e, 0xff, 0xff, 0xff,
45+
};
46+
47+
const char* test(void) {
48+
if (memcmp(gfx_palette, palette_8bpp, PALETTE_SIZE) != 0) {
49+
return "gfx_Begin != palette_8bpp";
50+
}
51+
// wipe the previous palette
52+
memset(gfx_palette, 0xAA, PALETTE_SIZE);
53+
gfx_SetDefaultPalette(gfx_8bpp);
54+
if (memcmp(gfx_palette, palette_8bpp, PALETTE_SIZE) != 0) {
55+
return "gfx_SetDefaultPalette != palette_8bpp";
56+
}
57+
58+
return "All tests passed";
59+
}
60+
61+
int main(void) {
62+
// wipe the previous palette
63+
memset(gfx_palette, 0x55, PALETTE_SIZE);
64+
65+
gfx_Begin();
66+
67+
const char* result = test();
68+
69+
gfx_End();
70+
71+
os_ClrHome();
72+
73+
fputs(result, stdout);
74+
75+
while (!os_GetCSC());
76+
77+
return 0;
78+
}

0 commit comments

Comments
 (0)