Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3579.c
blobb1ee758579045a9d35579236890e8cd8e833510b
1 /* bug-3579.c
2 Codegen for sm83 could generate an "ex de, hl" (a Z80 instruction not supported on SM83) when passing a struct as function argument while register hl holds another variable.
3 This would then result in an error message from the assembler.
4 */
6 #include <testfwk.h>
8 // Based on code by "Under4Mhz" licensed under GPL 2.0 or later
9 #pragma disable_warning 85
11 #include <stdint.h>
12 #include <stdbool.h>
14 typedef struct {
16 uint8_t type;
17 uint8_t state;
18 uint8_t left;
19 uint8_t width;
20 uint8_t ingress;
21 uint8_t scale;
23 } SpriteData;
25 uint8_t vdu_patch_crop_impl( uint8_t id, int8_t col, int8_t row,
26 int8_t width, int8_t offset, const uint8_t *counts, const uint8_t *colours,
27 int8_t cols, int8_t rows, uint16_t tile_offset, bool zoom ) {
29 ASSERT( tile_offset == 8);
31 return 0;
34 typedef uint8_t ImageBaseType;
36 typedef struct {
38 const ImageBaseType * const * const * const sprites;
39 uint8_t bank;
41 } SpriteItem;
43 const ImageBaseType * const I1 = {0};
44 const ImageBaseType * const * const I0 = &I1;
45 SpriteItem SI = {&I0, 0};
47 const SpriteItem * wolf_sheets[1] = {&SI};
49 uint8_t sprite_state_show( uint8_t id, SpriteData *sprite, uint8_t y, uint8_t tile ) {
51 static bool zoom = false;
53 // Only allow zoom on first sprite, if it's full size enemy
54 if ( id == 0 ) {
55 zoom = sprite->type > 1 && sprite->scale == 5;
56 if ( zoom ) sprite->scale--;
57 } else {
58 if ( zoom ) goto finish;
61 const SpriteItem * sprite_data = wolf_sheets[0];
63 const ImageBaseType * const * const scale_sprite_data = sprite_data[0].sprites[0];
65 id = vdu_patch_crop_impl( id, sprite->left, 0, sprite->width, 0, scale_sprite_data[0], 0,0,0, tile, zoom );
67 finish:
69 return id;
72 void
73 testBug (void) {
74 SpriteData sprite = { 1,2,3,4,5,6};
75 sprite_state_show( 0, &sprite, 7, 8 );