@@ -123,43 +123,63 @@ void update_nz(uint8_t value) {
123123 neg_flag = (value & 0b010000000 ) != 0 ;
124124}
125125
126- uint8_t zero_page (uint8_t addr ) {
127- return read_byte (addr );
126+ inline uint8_t zero_page (uint8_t addr ) {
127+ return read_byte (( uint16_t ) addr );
128128}
129129
130- uint8_t zero_page_x (uint8_t addr ) {
131- return read_byte (( addr + x ) & 0xff ); // TODO: check if wrapping is necessary
130+ inline uint8_t zero_page_x_addr (uint8_t addr ) {
131+ return addr + x ;
132132}
133133
134- uint8_t zero_page_y (uint8_t addr ) {
135- return read_byte (addr + y );
134+ inline uint8_t zero_page_x (uint8_t addr ) {
135+ return read_byte (( uint16_t ) zero_page_x_addr ( addr ) );
136136}
137137
138- uint8_t absolute (uint16_t addr ) {
138+ inline uint8_t zero_page_y_addr (uint8_t addr ) {
139+ return addr + y ;
140+ }
141+
142+ inline uint8_t zero_page_y (uint8_t addr ) {
143+ return read_byte ((uint16_t )zero_page_y_addr (addr ));
144+ }
145+
146+ inline uint8_t absolute (uint16_t addr ) {
139147 return read_byte (addr );
140148}
141149
142- uint8_t absolute_x (uint16_t addr ) {
143- return read_byte (addr + x );
150+ inline uint16_t absolute_x_addr (uint16_t addr ) {
151+ return addr + x ;
152+ }
153+
154+ inline uint8_t absolute_x (uint16_t addr ) {
155+ return read_byte (absolute_x_addr (addr ));
144156}
145157
146- uint8_t absolute_y (uint16_t addr ) {
158+ inline uint8_t absolute_y (uint16_t addr ) {
147159 return read_byte (addr + y );
148160}
149161
150- uint16_t indirect_x_addr (uint8_t addr ) {
151- return read_word (addr + x );
162+ inline uint16_t indirect_x_addr (uint8_t addr ) {
163+ uint8_t addr1 = addr + x ;
164+ uint8_t addr2 = addr1 + 1 ; // zero page wrap around
165+ uint16_t low_byte = (uint16_t )read_byte (addr1 );
166+ uint16_t high_byte = (uint16_t )(((uint16_t )read_byte (addr2 )) << 8 );
167+ return high_byte | low_byte ;
168+ return read_word (addr1 );
152169}
153170
154- uint16_t indirect_y_addr (uint8_t addr ) {
155- return read_word (addr ) + y ;
171+ inline uint16_t indirect_y_addr (uint8_t addr ) {
172+ uint8_t addr2 = addr + 1 ; // zero page wrap around
173+ uint16_t low_byte = (uint16_t )read_byte (addr );
174+ uint16_t high_byte = (uint16_t )(((uint16_t )read_byte (addr2 )) << 8 );
175+ return (high_byte | low_byte ) + (uint16_t )y ;
156176}
157177
158- uint8_t indirect_x_val (uint8_t addr ) {
178+ inline uint8_t indirect_x_val (uint8_t addr ) {
159179 return read_byte (indirect_x_addr (addr ));
160180}
161181
162- uint8_t indirect_y_val (uint8_t addr ) {
182+ inline uint8_t indirect_y_val (uint8_t addr ) {
163183 return read_byte (indirect_y_addr (addr ));
164184}
165185
0 commit comments