2 For z80, a read from a pointer overwrote register a that was in use for a local variable.
7 // Based on code by "Under4Mhz" licensed under GPL 2.0 or later
10 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
11 static volatile uint8_t VDPControlPort
;
12 static volatile uint8_t VDPDataPortOut
;
14 #define BYTE_HI(x) ((x)>>8)
15 #define VDU_ADDRESS_SET_MASK 0x4000
19 #define vdu_next_set_fast(value) VDPDataPortOut = value
20 #define vdu_address_set_unsafe(address) { VDPControlPort=address; VDPControlPort=BYTE_HI((address) | VDU_ADDRESS_SET_MASK ); }
22 #define for8( var, size ) for ( unsigned char var = 0; var < size; var++ )
38 GameTile tiles
[MAX_TILES
];
43 GameTileState gameTiles
= { .size
= 2, .tiles
= { { 1, 2, { 2, 3 } }, { 6, 2, { 7, 8 } } } };
50 void GameTileCallback() {
54 GameTile
*gameTile
= gameTiles
.tiles
;
56 for8( id
, gameTiles
.size
) {
58 vdu_address_set_unsafe( gameTile
->address
);
60 u8
*ptr
= gameTile
->tile
;
61 u8 size
; size
= gameTile
->size
;
63 vdu_next_set_fast( *ptr
++ ); // Pointer read here overwrote size, which was allocated to register a.
67 p (ptr
- gameTile
->tile
);
78 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory