HELP Input pull-up AVR working in simulator, not working IRL [Again my Attiny13a

Given that I accomplished shrinking size of my project and with huge help here and on arduino stack exchange, basically rewrited to atmel studio, my "fire cat" displays all(but 1 led, this was problem before idk, sometimes works sometimes not, not that big of a problem) leds, problem now is I have a button connected on Attiny13a PB3, in theory and simulator everything works, but then IRL it doesnt, like it cant even read the f*in pin

#include <stdbool.h>
    #include <string.h>
    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <util/atomic.h>
    
    #define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))
    #define bit_is_clear(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit)))
    
    #define INPUT 0x0f
    #define LOW   0x00
    #define HIGH  0x01
    
    // Configure Timer 0 to count milliseconds, assuming F_CPU = 8 MHz.
    static void init_timer() {
    	OCR0A  = 125 - 1;     // period = 125*64 = 8000 CPU cycles
    	TCCR0A = _BV(WGM01);  // CTC, TOP = OCR0A
    	TCCR0B = _BV(CS00)    // clock @ F_CPU/64
    	| _BV(CS01);   // ditto
    	TIMSK0 = _BV(TOIE0);  // enable timer overflow interrupt
    }
    
    volatile uint16_t millis_counter;
    
    // Count a millisecond on each timer overflow.
    ISR(TIM0_OVF_vect) {
    	++millis_counter;
    }
    
    // Read the milliseconds counter avoiding race conditions.
    static uint16_t millis() {
    	uint16_t millis_counter_copy;
    	ATOMIC_BLOCK(ATOMIC_FORCEON) {
    		millis_counter_copy = millis_counter;
    	}
    	return millis_counter_copy;
    }
    
    static void setup() {
    	
    	PORTB |= _BV(PB3);
    	DDRB &= ~_BV(PB3);
    	PORTB |= _BV(PB3);  // pullup on PB3
    	init_timer();
    	sei();
    }
    
    // Set a pin as either INPUT, LOW or HIGH.
    static void set_pin(uint8_t pin_mask, uint8_t state) {
    	if (state == INPUT) {
    		DDRB &= ~pin_mask;     // INPUT
    		PORTB &= ~pin_mask;    // no pullup
    		} else {
    		if (state)
    		PORTB |= pin_mask;   // HIGH
    		else
    		PORTB &= ~pin_mask;  // LOW
    		DDRB |= pin_mask;      // OUTPUT
    	}
    }
    
    static void charlie(uint8_t a[])
    {
    	set_pin(_BV(PB0), a[0]);
    	set_pin(_BV(PB1), a[1]);
    	set_pin(_BV(PB2), a[2]);
    	set_pin(_BV(PB4), a[3]);
    }
    
    static uint16_t oldTime = 0;
    static bool holdButt = false;
    static uint16_t holdTime = 0;
    static uint16_t shortPressATime = 0;
    static bool kozichOn = true;
    
    void loop() {
    
    	static uint8_t koz1[4] = {INPUT,LOW,HIGH,INPUT};
    
    	static uint8_t koz2[4] = {INPUT,HIGH,LOW,INPUT};/*
    	memcpy(koz2, koz1, sizeof(koz1[0])*4);
    	koz2[1] = HIGH;
    	koz2[2] = LOW;
    */
    	static uint8_t koz3[4] = {LOW,HIGH,INPUT,INPUT};
    	static uint8_t koz4[4] = {HIGH,LOW,INPUT,INPUT};;/*
    	memcpy(koz4, koz3, sizeof(koz3[0])*4);
    	koz4[0] = HIGH;
    	koz4[1] = LOW;
    */
    	static uint8_t koz5[4] = {LOW, INPUT,INPUT,HIGH};
    	static uint8_t koz6[4] = {HIGH, INPUT,INPUT,LOW};/*
    	memcpy(koz6, koz5, sizeof(koz5[0])*4);
    	koz4[0] = HIGH;
    	koz4[3] = LOW;
    */
    	static uint8_t cap[4] = {INPUT, HIGH,INPUT,LOW};
    
    	static uint8_t oko1[4] = {LOW, INPUT,HIGH,INPUT};
    	static uint8_t oko2[4] = {HIGH, INPUT,LOW,INPUT};/*
    	memcpy(oko2, oko1, sizeof(oko1[0])*4);
    	oko2[0] = HIGH;
    	oko2[2] = LOW;
    */
    	
    	
    	
    	uint16_t Ctime = millis();
    	uint16_t diffT = Ctime - oldTime;
    	oldTime = Ctime;
    
    	
    
    	if (bit_is_clear(PINB, PB3))
    	{
    		holdButt = true;
    		holdTime = holdTime + diffT;
    	}
    	else if (holdButt && bit_is_set(PINB, PB3)){
    		holdButt = false;
    		if(holdTime > 1000){
    			kozichOn = !kozichOn;
    		}
    		else
    		{
    			shortPressATime = 5000;
    		}
    		holdTime = 0;
    	}
    
    	if(shortPressATime > 0)
    	{
    		shortPressATime = shortPressATime - diffT;
    		if(shortPressATime & 0x100){
    			charlie(oko1);
    			charlie(oko2);
    		}
    	}
    	else{		
    		charlie(oko1);
    		charlie(oko2);
    	}
    	if(kozichOn){
    		charlie(koz1);
    		charlie(koz2);
    		charlie(koz3);
    		charlie(koz4);
    		charlie(koz5);
    		charlie(koz6);
    		charlie(cap);
    	}
    	DDRB &= ~(_BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB4));
    }
    
    int main(void) {
    	setup();
    	for (;;)
    	loop();
    }

Now You are out on really thin ice. That higly optimized code is only readable by experts, not by "normal" programmers. I wish You good luck, hoping the expert guys still have steam left for Your project. Brr, what a code…..

Good luck with your experiments, you seem to prefer the hard way :wink:

I wonder why you don't use a slightly bigger Arduino, that does not require such code optimization and obfuscation, at least until the program logic is working with standard Arduino libraries and conventions. Then you have the choice of optimizing on/for that controller first, step by step, and for presenting both the expressive and the optimized code for easier comparison and study.

I acutally made it, IDK what i changed but now it works, i couldnt get a timer to work, but at the end Iam happy it ended, I was first using arduino and then was optimizing(with help there and on exchange) at some point charlieplexing broke and some angel on stack exchange basically rewritten it for me so after a day of messing with it I was able to have half memory usage than with arduino ide and still working. Also I first deisgned the board with components in mind and didnt think of actually size of the microchip. And it was cheap.

Congratulations! You landed "mission impossible".

honzapat:
I acutally made it, IDK what i changed but now it works

That is a bad news. You did not learn what caused the bug. It can come back to bite you again and again. And it may be more subtle next time, showing up only after you deploy your the project or something like that.

Pull-up not working is most likely a poor contact. Are you using a breadboard for this?

honzapat:
#define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))
#define bit_is_clear(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit)))

There's also the built-in bitRead() macro, along with a bunch of other bit manipulation macros. Does the same as those two.

Assuming you compile with the Arduino IDE, that main() function isn't doing anything... Or did you abandon the IDE?