text,length,is_long_context,metric_val,label_metric "#define DFMOCO_VERSION 1 #define DFMOCO_VERSION_STRING ""1.3.0"" /* DFMoco version 1.3.0 Multi-axis motion control. For use with the Arc motion control system in Dragonframe 4. Generates step and direction signals, which can be sent to stepper motor drivers. Control up to four axes with an Uno, Duemilanove or 101 board. Control up to eight axes with a Mega or Mega 2560. Version History Version 1.3.0 Arduino 101 support. Remove non-Arduino support (chipKit, Maple). Version 1.2.7 Direction setup time. Version 1.2.6 Add PINOUT_VERSION option to use older pinout. Version 1.2.5 Fix jogging with low pulse rate. Version 1.2.4 Fix pin assignments Version 1.2.3 New Position command Version 1.2.2 Jog and Inch commands Version 1.2.1 Moved step/direction pins for motions 5-8. Detects board type automatically. Version 1.2.0 Basic go-motion capabilities Version 1.1.2 Smooth transitions when changing direction Version 1.1.1 Save/restore motor position Version 1.1.0 Major rework Version 1.0.2 Moved pulses into interrupt handler Version 1.0.1 Added delay for pulse widths Version 1.0.0 Initial public release. Getting Started: 1. Install IDE (Integrated Development Environment): Go to https://www.arduino.cc/en/Main/Software and download the Arduino Software for your OS. 2. Run the IDE you installed. 3. Open this file in the IDE. 4. Go to the Tools menu of the IDE and choose the Board type you are using. 5. Verify/Compile the sketch. (Command-R on Mac, Control-R on Windows.) 6. After this finishes, Upload the code to the board. (Command-U on Mac, Control-U on Windows.) Pin configuration: channel 1 PIN 4 step PIN 5 direction channel 2 PIN 6 step PIN 7 direction channel 3 PIN 8 step PIN 9 direction channel 4 PIN 10 step PIN 11 direction channel 5 PIN 28 step PIN 29 direction channel 6 PIN 30 step PIN 31 direction channel 7 PIN 32 step PIN 33 direction channel 8 PIN 34 step PIN 35 direction */ // change this to 1 if you want original pinout for channels 5-8 #define PINOUT_VERSION 2 /* This is PINOUT_VERSION 1 channel 5 PIN 22 step PIN 23 direction channel 6 PIN 24 step PIN 25 direction channel 7 PIN 26 step PIN 27 direction channel 8 PIN 28 step PIN 29 direction */ // detect board type #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define BOARD_MEGA 1 #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega168__) #define BOARD_UNO 1 #elif defined(ARDUINO_ARCH_ARC32) // Intel Curie/101 #define BOARD_101 1 #include ""CurieTimerOne.h"" #else #error Cannot identify board #endif // USER: if you want a kill switch, uncomment out the next line by removing the // characters //#define KILL_SWITCH_INTERRUPT 0 #define SERIAL_DEVICE Serial #if defined(BOARD_101) #define PIN_ON(port, pin) { digitalWrite(pin, 1); } #define PIN_OFF(port, pin) { digitalWrite(pin, 0); } #else #define PIN_ON(port, pin) { port |= pin; } #define PIN_OFF(port, pin) { port &= ~pin; } #endif // Arduino Uno/Duemilanove -> 4 MOTORS MAX // Arduino Mega 2560 / Mega -> 8 MOTORS MAX #if defined(BOARD_UNO) || defined(BOARD_101) #define MOTOR_COUNT 4 #else #define MOTOR_COUNT 8 #endif #define TIME_CHUNK 50 #define SEND_POSITION_COUNT 20000 // update velocities 20 x second #define VELOCITY_UPDATE_RATE (50000 / TIME_CHUNK) #define VELOCITY_INC(maxrate) (max(1.0f, maxrate / 70.0f)) #define VELOCITY_CONVERSION_FACTOR 0.30517578125f /* 20 / 65.536f */ // setup step and direction pins #if defined(BOARD_101) #define MOTOR0_STEP_PORT 0 #define MOTOR0_STEP_PIN 4 #define MOTOR1_STEP_PORT 0 #define MOTOR1_STEP_PIN 6 #define MOTOR2_STEP_PORT 0 #define MOTOR2_STEP_PIN 8 #define MOTOR3_STEP_PORT 0 #define MOTOR3_STEP_PIN 10 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define MOTOR0_STEP_PORT PORTG #define MOTOR0_STEP_PIN B00100000 #define MOTOR1_STEP_PORT PORTH #define MOTOR1_STEP_PIN B00001000 #define MOTOR2_STEP_PORT PORTH #define MOTOR2_STEP_PIN B00100000 #define MOTOR3_STEP_PORT PORTB #define MOTOR3_STEP_PIN B00010000 #if ( PINOUT_VERSION == 2 ) #define MOTOR4_STEP_PORT PORTA #define MOTOR4_STEP_PIN B01000000 #define MOTOR5_STEP_PORT PORTC #define MOTOR5_STEP_PIN B10000000 #define MOTOR6_STEP_PORT PORTC #define MOTOR6_STEP_PIN B00100000 #define MOTOR7_STEP_PORT PORTC #define MOTOR7_STEP_PIN B00001000 #elif ( PINOUT_VERSION == 1 ) #define MOTOR4_STEP_PORT PORTA #define MOTOR4_STEP_PIN B00000001 #define MOTOR5_STEP_PORT PORTA #define MOTOR5_STEP_PIN B00000100 #define MOTOR6_STEP_PORT PORTA #define MOTOR6_STEP_PIN B00010000 #define MOTOR7_STEP_PORT PORTA #define MOTOR7_STEP_PIN B01000000 #endif #elif defined(BOARD_UNO) #define MOTOR0_STEP_PORT PORTD #define MOTOR0_STEP_PIN B00000100 #define MOTOR1_STEP_PORT PORTD #define MOTOR1_STEP_PIN B00001000 #define MOTOR2_STEP_PORT PORTD #define MOTOR2_STEP_PIN B00010000 #define MOTOR3_STEP_PORT PORTB #define MOTOR3_STEP_PIN B00010000 #endif /** * Serial output specialization */ #if defined(UBRRH) #define TX_UCSRA UCSRA #define TX_UDRE UDRE #define TX_UDR UDR #else #define TX_UCSRA UCSR0A #define TX_UDRE UDRE0 #define TX_UDR UDR0 #endif char txBuf[32]; char *txBufPtr; #define TX_MSG_BUF_SIZE 16 #define MSG_STATE_START 0 #define MSG_STATE_CMD 1 #define MSG_STATE_DATA 2 #define MSG_STATE_ERR 3 #define MSG_STATE_DONE 100 /* * Command codes from user */ #define USER_CMD_ARGS 40 #define CMD_NONE 0 #define CMD_HI 10 #define CMD_MS 30 #define CMD_NP 31 #define CMD_MM 40 // move motor #define CMD_PR 41 // pulse rate #define CMD_SM 42 // stop motor #define CMD_MP 43 // motor position #define CMD_ZM 44 // zero motor #define CMD_SA 50 // stop all (hard) #define CMD_BF 60 // blur frame #define CMD_GO 61 // go! #define CMD_JM 70 // jog motor #define CMD_IM 71 // inch motor #define MSG_HI 01 #define MSG_MM 02 #define MSG_MP 03 #define MSG_MS 04 #define MSG_PR 05 #define MSG_SM 06 #define MSG_SA 07 #define MSG_BF 10 #define MSG_GO 11 #define MSG_JM 12 #define MSG_IM 13 struct UserCmd { byte command; byte argCount; int32_t args[USER_CMD_ARGS]; } ; /* * Message state machine variables. */ byte lastUserData; int msgState; int msgNumberSign; UserCmd userCmd; struct txMsg { byte msg; byte motor; }; struct TxMsgBuffer { txMsg buffer[TX_MSG_BUF_SIZE]; byte head; byte tail; }; TxMsgBuffer txMsgBuffer; /* Motor data. */ uint16_t motorAccumulator0; uint16_t motorAccumulator1; uint16_t motorAccumulator2; uint16_t motorAccumulator3; #if MOTOR_COUNT > 4 uint16_t motorAccumulator4; uint16_t motorAccumulator5; uint16_t motorAccumulator6; uint16_t motorAccumulator7; #endif uint16_t* motorAccumulator[MOTOR_COUNT] = { &motorAccumulator0, &motorAccumulator1, &motorAccumulator2, &motorAccumulator3, #if MOTOR_COUNT > 4 &motorAccumulator4, &motorAccumulator5, &motorAccumulator6, &motorAccumulator7 #endif }; uint16_t motorMoveSteps0; uint16_t motorMoveSteps1; uint16_t motorMoveSteps2; uint16_t motorMoveSteps3; #if MOTOR_COUNT > 4 uint16_t motorMoveSteps4; uint16_t motorMoveSteps5; uint16_t motorMoveSteps6; uint16_t motorMoveSteps7; #endif uint16_t* motorMoveSteps[MOTOR_COUNT] = { &motorMoveSteps0, &motorMoveSteps1, &motorMoveSteps2, &motorMoveSteps3, #if MOTOR_COUNT > 4 &motorMoveSteps4, &motorMoveSteps5, &motorMoveSteps6, &motorMoveSteps7 #endif }; uint16_t motorMoveSpeed0; uint16_t motorMoveSpeed1; uint16_t motorMoveSpeed2; uint16_t motorMoveSpeed3; #if MOTOR_COUNT > 4 uint16_t motorMoveSpeed4; uint16_t motorMoveSpeed5; uint16_t motorMoveSpeed6; uint16_t motorMoveSpeed7; #endif uint16_t * motorMoveSpeed[MOTOR_COUNT] = { &motorMoveSpeed0, &motorMoveSpeed1, &motorMoveSpeed2, &motorMoveSpeed3, #if MOTOR_COUNT > 4 &motorMoveSpeed4, &motorMoveSpeed5, &motorMoveSpeed6, &motorMoveSpeed7 #endif }; volatile boolean nextMoveLoaded; unsigned int velocityUpdateCounter; byte sendPositionCounter; boolean hardStopRequested; byte sendPosition = 0; byte motorMoving = 0; byte toggleStep = 0; #define P2P_MOVE_COUNT 7 struct Motor { byte stepPin; byte dirPin; // pre-computed move float moveTime[P2P_MOVE_COUNT]; int32_t movePosition[P2P_MOVE_COUNT]; float moveVelocity[P2P_MOVE_COUNT]; float moveAcceleration[P2P_MOVE_COUNT]; float gomoMoveTime[P2P_MOVE_COUNT]; int32_t gomoMovePosition[P2P_MOVE_COUNT]; float gomoMoveVelocity[P2P_MOVE_COUNT]; float gomoMoveAcceleration[P2P_MOVE_COUNT]; int currentMove; float currentMoveTime; volatile boolean dir; int32_t position; int32_t destination; float maxVelocity; float maxAcceleration; uint16_t nextMotorMoveSteps; float nextMotorMoveSpeed; }; boolean goMoReady; int goMoDelayTime; Motor motors[MOTOR_COUNT]; #ifdef KILL_SWITCH_INTERRUPT void killSwitch() { hardStopRequested = true; } #endif /* * setup() gets called once, at the start of the program. */ void setup() { goMoReady = false; lastUserData = 0; msgState = MSG_STATE_START; velocityUpdateCounter = 0; sendPositionCounter = 10; nextMoveLoaded = false; hardStopRequested = false; for (int i = 0; i < 32; i++) txBuf[i] = 0; txBufPtr = txBuf; #ifdef KILL_SWITCH_INTERRUPT attachInterrupt(KILL_SWITCH_INTERRUPT, killSwitch, CHANGE); #endif // initialize motor structures for (int i = 0; i < MOTOR_COUNT; i++) { // setup motor pins - you can customize/modify these after loop // default sets step/dir pairs together, with first four motors at 4/5, 6/7, 8/9, 10/11 // then, for the Mega boards, it jumps to 28/29, 30/31, 32/33, 34/35 #if ( PINOUT_VERSION == 2 ) motors[i].stepPin = (i * 2) + ( (i < 4) ? 4 : 20 ); #elif ( PINOUT_VERSION == 1 ) motors[i].stepPin = (i * 2) + ( (i < 4) ? 4 : 14 ); #endif motors[i].dirPin = motors[i].stepPin + 1; motors[i].dir = true; // forward motors[i].position = 0L; motors[i].destination = 0L; motors[i].nextMotorMoveSteps = 0; motors[i].nextMotorMoveSpeed = 0; setPulsesPerSecond(i, 5000); } motors[0].stepPin = 2; motors[0].dirPin = 5; motors[1].stepPin = 3; motors[1].dirPin = 6; motors[2].stepPin = 4; motors[2].dirPin = 7; motors[3].stepPin = 12; motors[3].dirPin = 13; // set output pins for (int i = 0; i < MOTOR_COUNT; i++) { pinMode(motors[i].stepPin, OUTPUT); pinMode(motors[i].dirPin, OUTPUT); #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // disable PWM switch (motors[i].stepPin) { #if defined(TCCR3A) && defined(COM3B1) case 4: TCCR3A &= ~COM3B1; break; #endif #if defined(TCCR4A) && defined(COM4A1) case 6: TCCR4A &= ~COM4A1; break; #endif #if defined(TCCR4A) && defined(COM4C1) case 8: TCCR4A &= ~COM4C1; break; #endif #if defined(TCCR2A) && defined(COM2A1) case 10: TCCR2A &= ~COM2A1; break; #endif } #else switch (motors[i].stepPin) { #if defined(TCCR1A) && defined(COM1B1) case 10: TCCR1A &= ~COM1B1; break; #endif } #endif } // set initial direction for (int i = 0; i < MOTOR_COUNT; i++) { digitalWrite( motors[i].dirPin, motors[i].dir ? HIGH : LOW ); } // setup serial connection Serial.begin(57600); sendMessage(MSG_HI, 0); // SET UP interrupt timer #if defined(BOARD_UNO) || defined(BOARD_MEGA) TCCR1A = 0; TCCR1B = _BV(WGM13); ICR1 = (F_CPU / 4000000) * TIME_CHUNK; // goes twice as often as time chunk, but every other event turns off pins TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12)); TIMSK1 = _BV(TOIE1); TCCR1B |= _BV(CS10); #elif defined(BOARD_101) CurieTimerOne.start(25, &updateStepDirection); #endif } #if defined(BOARD_101) void updateStepDirection(void) { #else ISR(TIMER1_OVF_vect) { #endif toggleStep = !toggleStep; if (toggleStep) { // MOTOR 1 if (motorMoveSteps0) { uint16_t a = motorAccumulator0; motorAccumulator0 += motorMoveSpeed0; if (motorAccumulator0 < a) { motorMoveSteps0--; PIN_ON(MOTOR0_STEP_PORT, MOTOR0_STEP_PIN); } } // MOTOR 2 if (motorMoveSteps1) { uint16_t a = motorAccumulator1; motorAccumulator1 += motorMoveSpeed1; if (motorAccumulator1 < a) { motorMoveSteps1--; PIN_ON(MOTOR1_STEP_PORT, MOTOR1_STEP_PIN); } } // MOTOR 3 if (motorMoveSteps2) { uint16_t a = motorAccumulator2; motorAccumulator2 += motorMoveSpeed2; if (motorAccumulator2 < a) { motorMoveSteps2--; PIN_ON(MOTOR2_STEP_PORT, MOTOR2_STEP_PIN); } } // MOTOR 4 if (motorMoveSteps3) { uint16_t a = motorAccumulator3; motorAccumulator3 += motorMoveSpeed3; if (motorAccumulator3 < a) { motorMoveSteps3--; PIN_ON(MOTOR3_STEP_PORT, MOTOR3_STEP_PIN); } } #if MOTOR_COUNT > 4 // MOTOR 5 if (motorMoveSteps4) { uint16_t a = motorAccumulator4; motorAccumulator4 += motorMoveSpeed4; if (motorAccumulator4 < a) { motorMoveSteps4--; PIN_ON(MOTOR4_STEP_PORT, MOTOR4_STEP_PIN); } } // MOTOR 6 if (motorMoveSteps5) { uint16_t a = motorAccumulator5; motorAccumulator5 += motorMoveSpeed5; if (motorAccumulator5 < a) { motorMoveSteps5--; PIN_ON(MOTOR5_STEP_PORT, MOTOR5_STEP_PIN); } } // MOTOR 7 if (motorMoveSteps6) { uint16_t a = motorAccumulator6; motorAccumulator6 += motorMoveSpeed6; if (motorAccumulator6 < a) { motorMoveSteps6--; PIN_ON(MOTOR6_STEP_PORT, MOTOR6_STEP_PIN); } } // MOTOR 8 if (motorMoveSteps7) { uint16_t a = motorAccumulator7; motorAccumulator7 += motorMoveSpeed7; if (motorAccumulator7 < a) { motorMoveSteps7--; PIN_ON(MOTOR7_STEP_PORT, MOTOR7_STEP_PIN); } } #endif } else { velocityUpdateCounter++; if (velocityUpdateCounter == VELOCITY_UPDATE_RATE) { velocityUpdateCounter = 0; if (sendPositionCounter) { sendPositionCounter--; } for (int i = 0; i < MOTOR_COUNT; i++) { if (*motorMoveSpeed[i] && !motors[i].nextMotorMoveSpeed) { bitSet(sendPosition, i); } *motorMoveSteps[i] = motors[i].nextMotorMoveSteps; *motorMoveSpeed[i] = motors[i].nextMotorMoveSpeed; digitalWrite(motors[i].dirPin, motors[i].dir); *motorAccumulator[i] = 65535; } nextMoveLoaded = false; // ready for new move } PIN_OFF(MOTOR0_STEP_PORT, MOTOR0_STEP_PIN); PIN_OFF(MOTOR1_STEP_PORT, MOTOR1_STEP_PIN); PIN_OFF(MOTOR2_STEP_PORT, MOTOR2_STEP_PIN); PIN_OFF(MOTOR3_STEP_PORT, MOTOR3_STEP_PIN); #if MOTOR_COUNT > 4 PIN_OFF(MOTOR4_STEP_PORT, MOTOR4_STEP_PIN); PIN_OFF(MOTOR5_STEP_PORT, MOTOR5_STEP_PIN); PIN_OFF(MOTOR6_STEP_PORT, MOTOR6_STEP_PIN); PIN_OFF(MOTOR7_STEP_PORT, MOTOR7_STEP_PIN); #endif } } /* * For stepper-motor timing, every clock cycle counts. */ void loop() { int32_t *ramValues = (int32_t *)malloc(sizeof(int32_t) * MOTOR_COUNT); int32_t *ramNotValues = (int32_t *)malloc(sizeof(int32_t) * MOTOR_COUNT); for (int i = 0; i < MOTOR_COUNT; i++) { if (ramValues[i] == ~ramNotValues[i]) { motors[i].position = motors[i].destination = ramValues[i]; } } while (true) { if (!nextMoveLoaded) updateMotorVelocities(); processSerialCommand(); // check if we have serial output #if defined(BOARD_UNO) || defined(BOARD_MEGA) if (*txBufPtr) { if ((TX_UCSRA) & (1 << TX_UDRE)) { TX_UDR = *txBufPtr++; // we are done with this msg, get the next one if (!*txBufPtr) nextMessage(); } } #endif if (!sendPositionCounter) { sendPositionCounter = 20; byte i; for (i = 0; i < MOTOR_COUNT; i++) { if (bitRead(motorMoving, i) || bitRead(sendPosition, i)) { sendMessage(MSG_MP, i); ramValues[i] = motors[i].position; ramNotValues[i] = ~motors[i].position; } } sendPosition = 0; } } } /** * Update velocities. */ void updateMotorVelocities() { // process hard stop interrupt request if (hardStopRequested) { hardStopRequested = 0; hardStop(); } for (int m = 0; m < MOTOR_COUNT; m++) { Motor *motor = &motors[m]; motor->nextMotorMoveSteps = 0; motor->nextMotorMoveSpeed = 0; if (bitRead(motorMoving, m)) { int seg = motor->currentMove; if (motor->moveTime[seg] == 0) { bitClear(motorMoving, m); } else { float originalMoveTime = motor->currentMoveTime; int originalMove = motor->currentMove; motor->currentMoveTime += 0.05f; if (motor->currentMoveTime >= motor->moveTime[seg]) { motor->currentMoveTime -= motor->moveTime[seg]; motor->currentMove++; seg++; } float t = motor->currentMoveTime; int32_t xn = (int32_t)(motor->movePosition[seg] + motor->moveVelocity[seg] * t + motor->moveAcceleration[seg] * t * t); // accel was already multiplied * 0.5 int32_t dx = abs(xn - motor->position); if (!dx) // don't change direction flag unless we are actually stepping in new direction continue; boolean forward = xn > motor->position; if (forward != motor->dir) // direction setup time 1/20th second should be plenty { // revert everything except for dir flag motor->currentMoveTime = originalMoveTime; motor->currentMove = originalMove; } else { motor->nextMotorMoveSpeed = max(1, min(65535, dx * 65.6f)); motor->nextMotorMoveSteps = dx; motor->position = xn; } motor->dir = forward; } } } nextMoveLoaded = true; } /* * Set up the axis for pulses per second (approximate) */ void setPulsesPerSecond(int motorIndex, uint16_t pulsesPerSecond) { if (pulsesPerSecond > 20000) pulsesPerSecond = 20000; if (pulsesPerSecond < 100) pulsesPerSecond = 100; motors[motorIndex].maxVelocity = pulsesPerSecond; motors[motorIndex].maxAcceleration = pulsesPerSecond * 0.5f; } void setupMotorMove(int motorIndex, int32_t destination) { motors[motorIndex].destination = destination; if ( destination != motors[motorIndex].position ) { calculatePointToPoint(motorIndex, destination); bitSet(motorMoving, motorIndex); } } void hardStop() { // set the destination to the current location, so they won't move any more for (int i = 0; i < MOTOR_COUNT; i++) { stopMotor(i); } } void stopMotor(int motorIndex) { int32_t delta = (motors[motorIndex].destination - motors[motorIndex].position); if (!delta) return; Motor *motor = &motors[motorIndex]; int i; for (i = 0; i < P2P_MOVE_COUNT; i++) { motor->moveTime[i] = 0; motor->moveVelocity[i] = 0; motor->movePosition[i] = 0; } float v = VELOCITY_CONVERSION_FACTOR * motors[motorIndex].nextMotorMoveSpeed; float maxA = motor->maxAcceleration; float maxV = motor->maxVelocity; if (v > maxV) v = maxV; if (!motor->dir) v = -v; float t = fabs(v / maxA); motor->moveTime[0] = t; motor->movePosition[0] = motor->position; motor->moveVelocity[0] = v; motor->moveAcceleration[0] = (v > 0) ? -maxA : maxA; motor->moveTime[1] = 0; motor->movePosition[1] = (int32_t)(motor->movePosition[0] + motor->moveVelocity[0] * t + 0.5f * motor->moveAcceleration[0] * t * t); motor->moveVelocity[1] = 0; motor->moveAcceleration[1] = 0; motor->moveAcceleration[0] *= 0.5f; motor->destination = motor->movePosition[1]; motor->currentMoveTime = 0; motor->currentMove = 0; } boolean isValidMotor(int motorIndex) { return (motorIndex >=0 && motorIndex < MOTOR_COUNT); } void processGoPosition(int motorIndex, int32_t pos) { if (motors[motorIndex].position != pos) { setupMotorMove(motorIndex, pos); sendMessage(MSG_MM, motorIndex); } else { sendMessage(MSG_MP, motorIndex); } } /* Command format ASCII [command two bytes] Version ""hi"" -> ""hi 1"" zero motor ""zm 1"" -> ""z 1"" move motor ""mm 1 +1111111111 motor position? mp 1 MOTOR STATUS ""ms"" -> ""ms [busy motor count]"" SET PULSE PER SECOND pr 1 200 STOP MOTOR sm 1 STOP ALL sa */ /* * int processUserMessage(char data) * * Read user data (from virtual com port), processing one byte at a time. * Implemented with a state machine to reduce memory overhead. * * Returns command code for completed command. */ byte processUserMessage(char data) { byte cmd = CMD_NONE; switch (msgState) { case MSG_STATE_START: if (data != '\\r' && data != '\\n') { msgState = MSG_STATE_CMD; msgNumberSign = 1; userCmd.command = CMD_NONE; userCmd.argCount = 0; userCmd.args[0] = 0; } break; case MSG_STATE_CMD: if (lastUserData == 'h' && data == 'i') { userCmd.command = CMD_HI; msgState = MSG_STATE_DONE; } else if (lastUserData == 'm' && data == 's') { userCmd.command = CMD_MS; msgState = MSG_STATE_DONE; } else if (lastUserData == 's' && data == 'a') { userCmd.command = CMD_SA; msgState = MSG_STATE_DONE; } else if (lastUserData == 'm' && data == 'm') { userCmd.command = CMD_MM; msgState = MSG_STATE_DATA; } else if (lastUserData == 'n' && data == 'p') { userCmd.command = CMD_NP; msgState = MSG_STATE_DATA; } else if (lastUserData == 'm' && data == 'p') { userCmd.command = CMD_MP; msgState = MSG_STATE_DATA; } else if (lastUserData == 'z' && data == 'm') { userCmd.command = CMD_ZM; msgState = MSG_STATE_DATA; } else if (lastUserData == 's' && data == 'm') { userCmd.command = CMD_SM; msgState = MSG_STATE_DATA; } else if (lastUserData == 'p' && data == 'r') { userCmd.command = CMD_PR; msgState = MSG_STATE_DATA; } else if (lastUserData == 'b' && data == 'f') { userCmd.command = CMD_BF; msgState = MSG_STATE_DATA; } else if (lastUserData == 'g' && data == 'o') { userCmd.command = CMD_GO; msgState = MSG_STATE_DONE; } else if (lastUserData == 'j' && data == 'm') // jm [motor] [destination position] { userCmd.command = CMD_JM; msgState = MSG_STATE_DATA; } else if (lastUserData == 'i' && data == 'm') // im [motor] [destination position] { userCmd.command = CMD_IM; msgState = MSG_STATE_DATA; } else { // error msg? unknown command? msgState = MSG_STATE_START; } break; case MSG_STATE_DATA: if (((data >= '0' && data <= '9') || data == '-') && lastUserData == ' ') { userCmd.argCount++; if (userCmd.argCount >= USER_CMD_ARGS) { SERIAL_DEVICE.print(""error: too many args\\r\\n""); msgState = MSG_STATE_ERR; } else { userCmd.args[userCmd.argCount - 1] = 0; if (data == '-') { msgNumberSign = -1; } else { msgNumberSign = 1; userCmd.args[userCmd.argCount - 1] = (data - '0'); } } } else if (data >= '0' && data <= '9') { userCmd.args[userCmd.argCount - 1] = userCmd.args[userCmd.argCount - 1] * 10 + (data - '0'); } else if (data == ' ' || data == '\\r') { if (lastUserData >= '0' && lastUserData <= '9') { if (userCmd.argCount > 0) userCmd.args[userCmd.argCount - 1] *= msgNumberSign; } if (data == '\\r') { msgState = MSG_STATE_DONE; } } break; case MSG_STATE_ERR: userCmd.command = CMD_NONE; msgState = MSG_STATE_DONE; break; case MSG_STATE_DONE: // wait for newline, then reset if (data == '\\n' && lastUserData == '\\r') { cmd = userCmd.command; msgState = MSG_STATE_START; lastUserData = 0; } break; default: // unknown state -> revert to begin msgState = MSG_STATE_START; lastUserData = 0; } lastUserData = data; return cmd; } void processSerialCommand() { byte avail = SERIAL_DEVICE.available(); byte motor; int m; for (int i = 0; i < avail; i++) { int cmd = processUserMessage(SERIAL_DEVICE.read()); if (cmd != CMD_NONE) { boolean parseError = false; motor = userCmd.args[0] - 1; switch (cmd) { case CMD_HI: sendMessage(MSG_HI, 0); break; case CMD_ZM: parseError = (userCmd.argCount != 1 || !isValidMotor(motor)); if (!parseError) { motors[motor].position = 0; setupMotorMove(motor, 0); processGoPosition(motor, 0); bitSet(sendPosition, motor); } break; case CMD_MM: parseError = (userCmd.argCount != 2 || !isValidMotor(motor)); if (!parseError) { processGoPosition(motor, (int32_t)userCmd.args[1]); } break; case CMD_NP: parseError = (userCmd.argCount != 2 || !isValidMotor(motor)); if (!parseError) { motors[motor].position = userCmd.args[1]; sendMessage(MSG_MP, motor); } break; case CMD_MP: parseError = (userCmd.argCount != 1 || !isValidMotor(motor)); if (!parseError) { sendMessage(MSG_MP, motor); } break; case CMD_MS: parseError = (userCmd.argCount != 0); if (!parseError) { sendMessage(MSG_MS, 0); } break; case CMD_SM: parseError = (userCmd.argCount != 1 || !isValidMotor(motor)); if (!parseError) { stopMotor(motor); sendMessage(MSG_SM, motor); sendMessage(MSG_MP, motor); } break; case CMD_SA: parseError = (userCmd.argCount != 0); if (!parseError) { hardStop(); sendMessage(MSG_SA, 0); } break; case CMD_PR: parseError = (userCmd.argCount != 2 || !isValidMotor(motor)); if (!parseError) { setPulsesPerSecond(motor, (uint16_t)userCmd.args[1]); sendMessage(MSG_PR, motor); } break; case CMD_BF: parseError = motorMoving || userCmd.argCount < 5 || ((userCmd.argCount - 2) % 4) != 0; if (!parseError) { goMoDelayTime = 1000; int motorCount = (userCmd.argCount - 2) / 4; for (m = 0; m < MOTOR_COUNT; m++) { motors[m].gomoMoveTime[0] = 0.0f; } for (m = 0; m < motorCount; m++) { int offset = 2 + m * 4; motor = userCmd.args[offset] - 1; if (!isValidMotor(motor)) { parseError = true; break; } setupBlur(motor, userCmd.args[0], userCmd.args[1], userCmd.args[offset + 1], userCmd.args[offset + 2], userCmd.args[offset + 3]); } goMoReady = true; sendMessage(MSG_BF, 0); } break; case CMD_GO: parseError = motorMoving || (userCmd.argCount > 0) || !goMoReady; if (!parseError) { for (m = 0; m < MOTOR_COUNT; m++) { if (motors[m].gomoMoveTime[0] != 0) { int j; for (j = 0; j < P2P_MOVE_COUNT; j++) { motors[m].moveTime[j] = motors[m].gomoMoveTime[j]; motors[m].movePosition[j] = motors[m].gomoMovePosition[j]; motors[m].moveVelocity[j] = motors[m].gomoMoveVelocity[j]; motors[m].moveAcceleration[j] = motors[m].gomoMoveAcceleration[j]; } motors[m].destination = motors[m].gomoMovePosition[4]; // TODO change this! motors[m].currentMove = 0; bitSet(motorMoving, m); } } updateMotorVelocities(); noInterrupts(); velocityUpdateCounter = VELOCITY_UPDATE_RATE - 1; interrupts(); sendMessage(MSG_GO, 0); } break; case CMD_JM: parseError = (userCmd.argCount != 2 || !isValidMotor(motor)); if (!parseError) { int32_t destination = 0; if (jogMotor(motor, userCmd.args[1], &destination)) { if (!bitRead(motorMoving, motor) || destination != motors[motor].destination) { setupMotorMove(motor, destination); } } sendMessage(MSG_JM, motor); } break; case CMD_IM: parseError = (userCmd.argCount != 2 || !isValidMotor(motor)); if (!parseError) { inchMotor(motor, userCmd.args[1]); sendMessage(MSG_IM, motor); } break; default: parseError = true; break; } if (parseError) { SERIAL_DEVICE.print(""parse error\\r\\n""); } } } } /* * * Serial transmission. * */ void sendMessage(byte msg, byte motorIndex) { #if defined(BOARD_UNO) || defined(BOARD_MEGA) int i = (unsigned int)(txMsgBuffer.head + 1) % TX_MSG_BUF_SIZE; if (i != txMsgBuffer.tail) { txMsgBuffer.buffer[txMsgBuffer.head].msg = msg; txMsgBuffer.buffer[txMsgBuffer.head].motor = motorIndex; txMsgBuffer.head = i; if (!*txBufPtr) nextMessage(); } #else int i; switch (msg) { case MSG_HI: SERIAL_DEVICE.print(""hi ""); SERIAL_DEVICE.print(DFMOCO_VERSION); SERIAL_DEVICE.print("" ""); SERIAL_DEVICE.print(MOTOR_COUNT); SERIAL_DEVICE.print("" ""); SERIAL_DEVICE.print(DFMOCO_VERSION_STRING); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_MM: SERIAL_DEVICE.print(""mm ""); SERIAL_DEVICE.print(motorIndex + 1); SERIAL_DEVICE.print("" ""); SERIAL_DEVICE.print(motors[motorIndex].destination); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_MP: SERIAL_DEVICE.print(""mp ""); SERIAL_DEVICE.print(motorIndex + 1); SERIAL_DEVICE.print("" ""); SERIAL_DEVICE.print(motors[motorIndex].position); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_MS: SERIAL_DEVICE.print(""ms ""); for (i = 0; i < MOTOR_COUNT; i++) SERIAL_DEVICE.print(bitRead(motorMoving, i) ? '1' : '0'); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_PR: SERIAL_DEVICE.print(""pr ""); SERIAL_DEVICE.print(motorIndex + 1); SERIAL_DEVICE.print("" ""); SERIAL_DEVICE.print((uint16_t)motors[motorIndex].maxVelocity); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_SM: SERIAL_DEVICE.print(""sm ""); SERIAL_DEVICE.print(motorIndex + 1); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_SA: SERIAL_DEVICE.print(""sa\\r\\n""); break; case MSG_BF: SERIAL_DEVICE.print(""bf ""); SERIAL_DEVICE.print(goMoDelayTime); SERIAL_DEVICE.print(""\\r\\n""); case MSG_GO: SERIAL_DEVICE.print(""go\\r\\n""); break; case MSG_JM: SERIAL_DEVICE.print(""jm ""); SERIAL_DEVICE.print(motorIndex + 1); SERIAL_DEVICE.print(""\\r\\n""); break; case MSG_IM: SERIAL_DEVICE.print(""im ""); SERIAL_DEVICE.print(motorIndex + 1); SERIAL_DEVICE.print(""\\r\\n""); break; } #endif } #if defined(BOARD_UNO) || defined(BOARD_MEGA) void nextMessage() { char *bufPtr; int i; if ((TX_MSG_BUF_SIZE + txMsgBuffer.head - txMsgBuffer.tail) % TX_MSG_BUF_SIZE) { byte msg = txMsgBuffer.buffer[txMsgBuffer.tail].msg; byte motorIndex = txMsgBuffer.buffer[txMsgBuffer.tail].motor; txMsgBuffer.tail = (unsigned int)(txMsgBuffer.tail + 1) % TX_MSG_BUF_SIZE; switch (msg) { case MSG_HI: sprintf(txBuf, ""hi %d %d %s\\r\\n"", DFMOCO_VERSION, MOTOR_COUNT, DFMOCO_VERSION_STRING); break; case MSG_MM: sprintf(txBuf, ""mm %d %ld\\r\\n"", motorIndex + 1, motors[motorIndex].destination); break; case MSG_MP: sprintf(txBuf, ""mp %d %ld\\r\\n"", motorIndex + 1, motors[motorIndex].position); break; case MSG_MS: sprintf(txBuf, ""ms ""); bufPtr = txBuf + 3; for (i = 0; i < MOTOR_COUNT; i++) *bufPtr++ = bitRead(motorMoving, i) ? '1' : '0'; *bufPtr++ = '\\r'; *bufPtr++ = '\\n'; *bufPtr = 0; break; case MSG_PR: sprintf(txBuf, ""pr %d %u\\r\\n"", motorIndex + 1, (uint16_t)motors[motorIndex].maxVelocity); break; case MSG_SM: sprintf(txBuf, ""sm %d\\r\\n"", motorIndex + 1); break; case MSG_SA: sprintf(txBuf, ""sa\\r\\n""); break; case MSG_BF: sprintf(txBuf, ""bf %d\\r\\n"", goMoDelayTime); break; case MSG_GO: sprintf(txBuf, ""go\\r\\n""); break; case MSG_JM: sprintf(txBuf, ""jm %d\\r\\n"", motorIndex + 1); break; case MSG_IM: sprintf(txBuf, ""im %d\\r\\n"", motorIndex + 1); break; } txBufPtr = txBuf; } } #endif boolean jogMotor(int motorIndex, int32_t target, int32_t * destination) { Motor *motor = &motors[motorIndex]; // ideally send motor to distance where decel happens after 2 seconds float vi = (motor->dir ? 1 : -1) * VELOCITY_CONVERSION_FACTOR * motor->nextMotorMoveSpeed; int dir = (target > motor->position) ? 1 : -1; // if switching direction, just stop if (motor->nextMotorMoveSpeed && motor->dir * dir < 0) { stopMotor(motorIndex); return false; } if (target == motor->position) { return false; } float maxVelocity = motor->maxVelocity; float maxAcceleration = motor->maxAcceleration; // given current velocity vi // compute distance so that decel starts after 0.5 seconds // time to accel // time at maxvelocity // time to decel float accelTime = 0, atMaxVelocityTime = 0; if (fabs(vi) < maxVelocity) { accelTime = (maxVelocity - fabs(vi)) / maxAcceleration; if (accelTime < 0.5f) { atMaxVelocityTime = 0.5f - accelTime; } else { accelTime = 0.5f; } } else { atMaxVelocityTime = 0.5f; } float maxVelocityReached = fabs(vi) + maxAcceleration * accelTime; int32_t delta = fabs(vi) * accelTime + (0.5f * maxAcceleration * accelTime * accelTime); delta += atMaxVelocityTime * maxVelocityReached; delta += 0.5f * (maxVelocityReached * maxVelocityReached) / maxAcceleration; // = 0.5 * a * t^2 -> t = (v/a) int32_t dest = motor->position + dir * delta; // now clamp to target if ( (dir == 1 && dest > target) || (dir == -1 && dest < target) ) { dest = target; } *destination = dest; return true; } void inchMotor(int motorIndex, int32_t target) { Motor *motor = &motors[motorIndex]; // ideally send motor to distance where decel happens after 2 seconds // if switching direction, just stop int dir = (target > motor->destination) ? 1 : -1; if (motor->nextMotorMoveSpeed)// && motor->dir * dir < 0) { stopMotor(motorIndex); return; } int32_t dest = motor->destination + dir * 2; // now clamp to target if ( (dir == 1 && dest > target) || (dir == -1 && dest < target) ) { dest = target; } //setupMotorMove(motorIndex, dest); int i, moveCount; moveCount = 0; for (i = 0; i < P2P_MOVE_COUNT; i++) { motor->moveTime[i] = 0; motor->moveVelocity[i] = 0; motor->moveAcceleration[i] = 0; } motor->currentMoveTime = 0; motor->moveTime[0] = 0.01f; motor->movePosition[0] = motor->position; motor->movePosition[1] = motor->position + dir * 2; motor->currentMove = 0; motor->destination = dest; if ( dest != motor->position ) { bitSet(motorMoving, motorIndex); } } void calculatePointToPoint(int motorIndex, int32_t destination) { Motor *motor = &motors[motorIndex]; int i, moveCount; moveCount = 0; for (i = 0; i < P2P_MOVE_COUNT; i++) { motor->moveTime[i] = 0; motor->moveVelocity[i] = 0; motor->moveAcceleration[i] = 0; } motor->currentMoveTime = 0; motor->movePosition[0] = motor->position; float tmax = motor->maxVelocity / motor->maxAcceleration; float dmax = motor->maxVelocity * tmax; float dist = abs(destination - motor->position); int dir = destination > motor->position ? 1 : -1; if (motor->nextMotorMoveSpeed > 5) // we need to account for existing velocity { float vi = (motor->dir ? 1 : -1) * VELOCITY_CONVERSION_FACTOR * motor->nextMotorMoveSpeed; float ti = fabs(vi / motor->maxAcceleration); float di = 0.5f * motor->maxAcceleration * ti * ti; if (vi * dir < 0) // switching directions { motor->moveTime[moveCount] = ti; motor->moveAcceleration[moveCount] = dir * motor->maxAcceleration; motor->moveVelocity[moveCount] = vi; moveCount++; dist += di; } else if (dist < di) // must decelerate and switch directions { motor->moveTime[moveCount] = ti; motor->moveAcceleration[moveCount] = -dir * motor->maxAcceleration; motor->moveVelocity[moveCount] = vi; moveCount++; dist = (di - dist); dir = -dir; } else // further on in same direction { dist += di; motor->movePosition[0] -= dir * di; motor->currentMoveTime = ti; } } float t = tmax; if (dist <= dmax) { t = sqrt(dist / motor->maxAcceleration); } motor->moveTime[moveCount] = t; motor->moveAcceleration[moveCount] = dir * motor->maxAcceleration; if (dist > dmax) { moveCount++; dist -= dmax; float tconst = dist / motor->maxVelocity; motor->moveTime[moveCount] = tconst; motor->moveAcceleration[moveCount] = 0; } moveCount++; motor->moveTime[moveCount] = t; motor->moveAcceleration[moveCount] = dir * -motor->maxAcceleration; for (i = 1; i <= moveCount; i++) { float t = motor->moveTime[i - 1]; motor->movePosition[i] = (int32_t)(motor->movePosition[i - 1] + motor->moveVelocity[i - 1] * t + 0.5f * motor->moveAcceleration[i - 1] * t * t); motor->moveVelocity[i] = motor->moveVelocity[i - 1] + motor->moveAcceleration[i - 1] * t; } motor->movePosition[moveCount + 1] = destination; for (i = 0; i <= moveCount; i++) { motor->moveAcceleration[i] *= 0.5f; // pre-multiply here for later position calculation } motor->currentMove = 0; return; } void setupBlur(int motorIndex, int exposure, int blur, int32_t p0, int32_t p1, int32_t p2) { Motor *motor = &motors[motorIndex]; int i; float b = blur * 0.001f; float expTime = exposure * 0.001f; p0 = p1 + b * (p0 - p1); p2 = p1 + b * (p2 - p1); for (i = 0; i < P2P_MOVE_COUNT; i++) { motor->gomoMoveTime[i] = 0; motor->gomoMoveVelocity[i] = 0; motor->gomoMoveAcceleration[i] = 0; } motor->gomoMovePosition[1] = p0; motor->gomoMoveTime[1] = expTime * 0.5f; motor->gomoMoveVelocity[1] = (float)(p1 - p0) / (expTime * 0.5f); motor->gomoMovePosition[2] = p1; motor->gomoMoveTime[2] = expTime * 0.5f; motor->gomoMoveVelocity[2] = (float)(p2 - p1) / (expTime * 0.5f); // v = a*t -> a = v / t float accelTime = 1.0f; float a = motor->gomoMoveVelocity[1] / accelTime; float dp = 0.5f * a * accelTime * accelTime; float sp = p0 - dp; // starting position motor->gomoMovePosition[0] = sp; motor->gomoMoveTime[0] = accelTime; motor->gomoMoveAcceleration[0] = 0.5f * a; // pre-multiplied a = motor->gomoMoveVelocity[2] / accelTime; dp = 0.5f * a * accelTime * accelTime; float fp = p2 + dp; motor->gomoMovePosition[3] = p2; motor->gomoMoveTime[3] = accelTime; motor->gomoMoveVelocity[3] = motor->gomoMoveVelocity[2]; motor->gomoMoveAcceleration[3] = -0.5f * a; // pre-multiplied motor->gomoMovePosition[4] = fp; setupMotorMove(motorIndex, sp); } ",12464,False,1986.1059021434103,median "/* * Temperature and more sensor * * This device can measure: * - Temperature * - Humidity * - Air pressure (barometer). * * By looking at changes in air pressure it can predict the weather. * - unknown (it's still calculating) * - stable (expect more of the same) * - unstable (expect strong changes in weather) * - sunny (expect improving weather) * - cloudy (clouds and possibly rain) * - thunderstorm (strong shift to low pressure) * * You can use it indoor or outdoor. It does not have to be outside to be able to predict the weather. * * The main sensor used is the Bosch BME280. * * * SETTINGS */ // You can enable and disable the settings below by adding or removing double slashes ( // ) in front of a line. #define SECONDS_BETWEEN_SENDING 60 // Sleep time between reads for the BME sensor (in seconds). Keep this value at 60 if you have enabled the forecast feature, as the forecast algorithm needs a sample every minute. MAximum is 255 (because the value is stored as a byte, instead of the bigger 'int') #define HAS_TOUCH_SCREEN // Did you connect a touch screen? #define MY_REPEATER_FEATURE // Act as a repeater? The devices can pass along messages to each other to increase the range of your network. #define RF_NANO // RF-Nano. Check this box if you are using the RF-Nano Arduino, which has a built in radio. The Candle project uses the RF-Nano. /* END OF SETTINGS * * * */ // PINS #define TOUCH_SCREEN_RX_PIN 5 // The receive (RX) pin for the touchscreen. This connects to the transmit (TX) pin of the touchscreen. #define TOUCH_SCREEN_TX_PIN 6 // The receive (TX) pin for the touchscreen. This connects to the transmit (RX) pin of the touchscreen. // The BME280 uses I2C, so its SDA (data) pin should be connected to pin A4 on the Arduino, and the sensor's SCL (clock) pin should be connected to pin A5 on the Arduino. #ifdef RF_NANO // If you are using an RF-Nano, you have to switch CE and CS pins. #define MY_RF24_CS_PIN 9 // Used by the MySensors library. #define MY_RF24_CE_PIN 10 // Used by the MySensors library. #endif //#define DEBUG // Do you want to see extra debugging information in the serial output? //#define DEBUG_SCREEN // Do you want to see extra debugging information about the touch screen in the serial output? //#define MY_DEBUG // Enable MySensors debug output to the serial monitor, so you can check if the radio is working ok. // Enable and select the attached radio type #define MY_RADIO_RF24 // This is a common and simple radio used with MySensors. Downside is that it uses the same frequency space as WiFi. //#define MY_RADIO_NRF5_ESB // This is a new type of device that is arduino and radio all in one. Currently not suitable for beginners yet. //#define MY_RADIO_RFM69 // This is an open source radio on the 433mhz frequency. Great range and built-in encryption, but more expensive and little more difficult to connect. //#define MY_RADIO_RFM95 // This is a LoRaWan radio, which can have a range of 10km. // MySensors: Choose your desired radio power level. High power can cause issues on cheap Chinese NRF24 radio's. //#define MY_RF24_PA_LEVEL RF24_PA_MIN //#define MY_RF24_PA_LEVEL RF24_PA_LOW //#define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_RF24_PA_LEVEL RF24_PA_MAX // Mysensors security #define MY_ENCRYPTION_SIMPLE_PASSWD ""A2Ed8vCV"" // Be aware, the length of the password has an effect on memory use. //#define MY_SECURITY_SIMPLE_PASSWD ""A2Ed8vCV"" // Be aware, the length of the password has an effect on memory use. //#define MY_SIGNING_SOFT_RANDOMSEED_PIN A7 // Setting a pin to pickup random electromagnetic noise helps make encryption more secure. // Mysensors advanced settings #define MY_TRANSPORT_WAIT_READY_MS 10000 // Try connecting for 10 seconds. Otherwise just continue. //#define MY_RF24_CHANNEL 100 // In EU the default channel 76 overlaps with wifi, so you could try using channel 100. But you will have to set this up on every device, and also on the controller. #define MY_RF24_DATARATE RF24_1MBPS // The datarate influences range. 1MBPS is the most widely supported. 250KBPS will give you more range. //#define MY_NODE_ID 10 // Giving a node a manual ID can in rare cases fix connection issues. //#define MY_PARENT_NODE_ID 0 // Fixating the ID of the gatewaynode can in rare cases fix connection issues. //#define MY_PARENT_NODE_IS_STATIC // Used together with setting the parent node ID. Daking the controller ID static can in rare cases fix connection issues. #define MY_SPLASH_SCREEN_DISABLED // Saves a little memory. //define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE // Saves a little memory. // LIBRARIES #include // The MySensors library. Hurray! //#include ""Seeed_BME280.h"" // ""Grove - Barometer Sensor BME280"". A relatively new library (as of 2018), works well with cheap BME280 sensors from China. #include // The watchdog timer - if the device becomes unresponsive and doesn't periodically reset the timer, then it will automatically reset once the timer reaches 0. //BME280 bme280; // Create the BME sensor object // ADAfruit LIBRARIES #include #include #include #include #define BME_SCK 13 #define BME_MISO 12 #define BME_MOSI 11 #define BME_CS 10 //#define SEALEVELPRESSURE_HPA (1013.25) // Usefull if determining current height --> not really interestng in this static case... Adafruit_BME280 bme; // I2C //Adafruit_BME280 bme(BME_CS); // hardware SPI //Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI unsigned long delayTime; #ifdef HAS_TOUCH_SCREEN #include SoftwareSerial touch_screen_serial(TOUCH_SCREEN_RX_PIN,TOUCH_SCREEN_TX_PIN); // RX (receive) pin, TX (transmit) pin #define MAX_BASIC_COMMAND_LENGTH 16 // How many bytes are in the longest basic command? #define TOUCHSCREEN_WIDTH 240 // #define TOUCHSCREEN_HEIGHT 320 // #define SCREEN_PADDING 10 // Used to space things, e.g. the distance of content to the edge of the screen. #define ITEM_HEIGHT 80 // How many pixels tall a single item on the screen is. #define LABEL_HEIGHT 25 // How many pixels in height labels like 'temperature' are. boolean touched = false; // Was the touchscreen just touched? signed int touchX = 0; // Touch screen position X signed int touchY = 0; // Touch screen position Y // Basic commands for the touch screen. All commands for the TFT should start with 0x7E, but to save storage space this is taken care of in the basicCommand function. PROGMEM const byte play[] = {0x07, 0x11, ' ', 'P', 'L', 'A', 'Y', 0xEF,}; // Places the word ' play' on the screen. PROGMEM const byte on[] = {0x07, 0x11, ' ', 'O','N', ' ', ' ', 0xEF,}; // Places the word ' on ' on the screen. PROGMEM const byte off[] = {0x07, 0x11, ' ', 'O', 'F', 'F', ' ', 0xEF,}; // Places the word ' off ' on the screen. PROGMEM const byte w[] = {0x07, 0x11, 'w', 0x00, ' ', 0x00, 0x00, 0xEF,}; // Places the word 'w ' on the screen. PROGMEM const byte menu[] = {0x07, 0x11, 'M', 'E', 'N', 'U', ' ', 0xEF,}; // Places the word 'menu ' on the screen. PROGMEM const byte more[] = {0x07, 0x11, 'M', 'O', 'R', 'E', '>', 0xEF,}; // Places the word 'menu ' on the screen. PROGMEM const byte set_vertical[] = {0x03, 0x04, 0x00, 0xEF,}; // To set rotation of the screen to vertical. Try 0x01 or 0x03 instead of the 0x02. PROGMEM const byte fill_black[] = {0x04, 0x20, 0x00, 0x00, 0xEF,}; // Fill screen with one color //PROGMEM const byte fill_blue[] = {0x04, 0x20, 0x00, 0xFF, 0xEF,}; // Fill screen with one color PROGMEM const byte text_color_white[] = {0x04, 0x02, 0xFF, 0xFF, 0xEF,}; // white text color. fill screen with one color //PROGMEM const byte text_color_black[] = {0x04, 0x02, 0x00, 0x00, 0xEF,}; // Dark text color. fill screen with one color //PROGMEM const byte text_color_red[] = {0x04, 0x02, 0xF8, 0x00, 0xEF,}; // .. text color. fill screen with one color //PROGMEM const byte resetTFT[] = {0x02, 0x05, 0xEF,}; // Resets the TFT. But has no real effect. //PROGMEM const byte testTFT[] = {0x02, 0x00, 0xEF}; // Test the TFT, should respond with ""OK"". PROGMEM const byte backlight_on[] = {0x03, 0x06, 0xFF, 0xEF}; // Backlight intensity to half-full PROGMEM const byte backlight_off[] = {0x03, 0x06, 0x00, 0xEF}; // Backlight intensity to zero //PROGMEM const byte serialSpeedUp[] = {0x03, 0x40, 0x03, 0xEF,}; // Sets communication speed to 57600 (from 9600) //PROGMEM const byte serialSlowDown[] = {0x03, 0x40, 0x00, 0xEF,}; // Sets communication speed to 9600 again. Oddly enough, it seems it works fastest at this speed.. // Colors (OLD) #define BLACK 0 #define GREY111111 4226 #define GREY333333 12678 #define GREY666666 25388 #define GREYCCCCCC 52857 #define YELLOW 65504 #define LIGHT_YELLOW 65510 #define LIGHT_ORANGE 65126 #define RED 63488 #define GREEN 2016 #define WHITE 65535 // A list of strings stored in program memory in order to save ram. #define SCREEN_TEMPERATURE 0 #define SCREEN_HUMIDITY 1 #define SCREEN_FORECAST 2 #define SCREEN_STABLE 3 #define SCREEN_SUNNY 4 #define SCREEN_CLOUDY 5 #define SCREEN_UNSTABLE 6 #define SCREEN_THUNDERSTORM 7 #define SCREEN_UNKNOWN 8 typedef byte MessageID; // TODO Is this used? Not really. Simplifying the message table could save some storage space. struct MessageDef { MessageID ID; char Description[20]; }; const MessageDef MessageTable[] PROGMEM = { {SCREEN_TEMPERATURE,""Temperatuur""}, //""Temperature"" {SCREEN_HUMIDITY,""Luchtvochtigheid""}, // ""Humidity"" {SCREEN_FORECAST,""Barometer""}, {SCREEN_STABLE,""Stabiel""}, {SCREEN_SUNNY,""Zonnig""}, //""SUNNY"" {SCREEN_CLOUDY,""Bewolkt""}, {SCREEN_UNSTABLE,""Instabiel""}, {SCREEN_THUNDERSTORM,""Onweer""}, //""Thunderstorm"" {SCREEN_UNKNOWN,""Onbekend""}, }; const byte metadataArraySize = 8; // The size of the array to store the serial data we're decoding in. byte metaData[metadataArraySize]; // Holds metadata for a replayable signal. byte screen_brightness = 255; // When this is 0 the screen is turned off. #endif // End of has_touch_screen #define INTERVAL 1000 // When active, the internal clock runs every 1000 milliseconds, which is a second. float previous_temperature = 0; // Contains the latest temperature value. float temperature = 0; // Contains the latest temperature value. byte previous_humidity = 0; // Contains the latest humidity value. byte current_humidity = 0; // Contains the latest humidity value. unsigned int previous_pressure = 0; // Contains the previously detected air pressure value. unsigned int pressure = 0; // Contains the latest air pressure value. byte forecast = 5; // A number that represents a type of weather forecast // VARIABLES YOU PROBABLY SHOULDN'T CHANGE #define TEMP_CHILD_ID 0 // For MySensors. Within this node each sensortype should have its own ID number. #define HUM_CHILD_ID 1 #define BARO_CHILD_ID 2 #define FORECAST_CHILD_ID 3 #define SCREEN_BUTTON_CHILD_ID 4 //IM BEING VERY NAUGHT, AND REUSE THIS VARIABLE TO SAVE SPACE! #define RADIO_DELAY 100 // milliseconds betweeen radio signals during the presentation phase. DO NOT CHANGE // Forecast variables #define CONVERSION_FACTOR (1.0/10.0) // Used by forecast algorithm to convert from Pa to kPa, by dividing hPa by 10. #define STABLE 0 // ""Stable Weather Pattern"" #define SUNNY 1 // ""Slowly rising Good Weather"", ""Clear/Sunny "" #define CLOUDY 2 // ""Slowly falling L-Pressure "", ""Cloudy/Rain "" #define UNSTABLE 3 // ""Quickly rising H-Press"", ""Not Stable"" #define THUNDERSTORM 4 // ""Quickly falling L-Press"", ""Thunderstorm"" #define UNKNOWNN 5 // ""Unknown (More Time needed) byte lastForecast = 10; // Stores the previous forecast. Icons are only redrawn if necessary. const byte LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; byte minuteCount = 0; // The forecast algorithm keeps track of time bool firstRound = true; // The forecast algorithm needs to know if it is creating the first forecast. float pressureAvg; // Average value after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; // Used by the forecast algorithm. // MySensors variables MyMessage temperature_message(TEMP_CHILD_ID, V_TEMP); MyMessage humidity_message(HUM_CHILD_ID, V_HUM); MyMessage pressure_message(BARO_CHILD_ID, V_PRESSURE); MyMessage string_message(FORECAST_CHILD_ID, V_TEXT); MyMessage button_message(SCREEN_BUTTON_CHILD_ID, V_STATUS); // Allows the controller to turn the screen on and off. boolean connectedToNetwork = false; // Are we connected to the local MySensors network? Used to display the 'w' connection icon. boolean send_all_values = 1; // Sends the state of the toggle to the controller on startup or when requested by the controller. //boolean metric = true; // Should the device show metric or Fahrenheit? --> Just show fucking metric. No choises here. Removed Fahrenheit to save some space // Here comes some stuff that I hope places it as global varaible, so it doesnt take up space float lastPressureSamplesAverage; float change; byte string_length; char char_byte; /* // A function to measure how much ram is used. int freeRam () { extern int __heap_start, *__brkval; int v; return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); } // via https://playground.arduino.cc/Code/AvailableMemory */ // VOIDS I MOVED FROM END OF FILE HERE - START #ifdef HAS_TOUCH_SCREEN void displayNetworkStatus() // Show connection icon on the display { if( connectedToNetwork ){ //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: show W icon"")); //#endif setCur(TOUCHSCREEN_WIDTH - 30, SCREEN_PADDING ); fontSize(1); basicCommand(w); } else { //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: hide W icon"")); //#endif roundedRectangle(TOUCHSCREEN_WIDTH - 50,0, 50, LABEL_HEIGHT, 0, BLACK); } } void simpleHorizontal(unsigned int y, unsigned int color) // Draw a horizontal line on the screen. { #ifdef DEBUG_SCREEN Serial.println(F(""SIMPLEHORIZONTAL:"")); Serial.print(F(""y: "")); Serial.println(y); #endif byte command[12] = {0x7E, 0x0A, 0x23, 0,0, highByte(y), lowByte(y), 0,240, 255, 255, 0xEF,}; for( int i=0; i < sizeof(command); i++ ){ touch_screen_serial.write( command[i] ); //Serial.print(command[i],HEX); Serial.print(F("" "")); } waitForResponse(); } void roundedRectangle(int x, int y, int w, int h, int r, int c) // Draw a pixel on the screen. { #ifdef DEBUG_SCREEN Serial.println(F(""ROUNDEDRECTANGLE"")); Serial.print(F(""x:"")); Serial.println(x); // top-right x-position Serial.print(F(""y:"")); Serial.println(y); // top-left y-position Serial.print(F(""w:"")); Serial.println(w); // width Serial.print(F(""h:"")); Serial.println(h); // height Serial.print(F(""r:"")); Serial.println(r); // radius Serial.print(F(""c:"")); Serial.println(c); // color #endif byte command[16] = {0x7E, 0x0E, 0x2C, highByte(x), lowByte(x), highByte(y), lowByte(y), highByte(w), lowByte(w), highByte(h), lowByte(h) - 2, highByte(r), lowByte(r), highByte(c), lowByte(c), 0xEF,}; for( int i=0; i < sizeof(command); i++ ){ touch_screen_serial.write( command[i] ); //Serial.print(command[i],HEX); Serial.print(F("" "")); } waitForResponse(); } void circle(unsigned int x, unsigned int y, unsigned int r, unsigned int c) // Draw a pixel on the screen. { #ifdef DEBUG_SCREEN Serial.println(F(""CIRCLE"")); Serial.print(F(""x:"")); Serial.println(x); // top-right x-position Serial.print(F(""y:"")); Serial.println(y); // top-left y-position Serial.print(F(""r:"")); Serial.println(r); // radius Serial.print(F(""c:"")); Serial.println(c); // color #endif byte command[12] = {0x7E, 0x0A, 0x28, highByte(x), lowByte(x), highByte(y), lowByte(y), highByte(r), lowByte(r), highByte(c), lowByte(c), 0xEF}; for( int i=0; i < sizeof(command); i++ ){ touch_screen_serial.write( command[i] ); //Serial.print(command[i],HEX); Serial.print(F("" "")); } waitForResponse(); } // This function writes text to the screen. You can use the setCur function to place the cursor in the desired position first. void writeText(byte textID) { #ifdef DEBUG_SCREEN Serial.println(F(""WRITETEXT"")); #endif byte string_length = strlen_P(MessageTable[textID].Description); touch_screen_serial.write( 0x7E ); touch_screen_serial.write( string_length + 2); touch_screen_serial.write( 0x11 ); for( byte i=0; i < string_length; i++ ){ char char_byte = pgm_read_byte(MessageTable[textID].Description + i); //Serial.print(""-""); Serial.print(char_byte); touch_screen_serial.write( char_byte ); } touch_screen_serial.write( 0xEF ); waitForResponse(); } void writeString(char string_array[], byte string_length) { #ifdef DEBUG_SCREEN Serial.println(F(""WRITESTRING"")); #endif //byte string_length = strlen_P(MessageTable[textID].Description) + 2; touch_screen_serial.write( 0x7E ); touch_screen_serial.write( string_length + 2 ); touch_screen_serial.write( 0x11 ); for( byte i=0; i < string_length; i++ ){ char char_byte = string_array[i]; //Serial.print(""-""); Serial.print(char_byte); touch_screen_serial.write( char_byte ); } touch_screen_serial.write( 0xEF ); waitForResponse(); } //#ifdef DEBUG_SCREEN //void drawPix(int x, int y, int c) // Draw a pixel on the screen. //{ // Serial.println(F(""DRAWPIX:"")); // Serial.print(F(""x: "")); Serial.println(x); // Serial.print(F(""y: "")); Serial.println(y); // Serial.print(F(""c: "")); Serial.println(c); // byte command[10] = {0x7E, 0x08, 0x21, highByte(x), lowByte(x), highByte(y), lowByte(y), highByte(c), lowByte(c), 0xEF}; // for( int i=0; i < sizeof(command); i++ ){ // touch_screen_serial.write( command[i] ); // //Serial.print(command[i],HEX); Serial.print(F("" "")); // } // waitForResponse(); //} //#endif // This function places the text cursor anywhere on the screen. void setCur(int x, int y) { //#ifdef DEBUG_SCREEN // Serial.println(F(""SETCUR"")); // Serial.print(F(""x: "")); Serial.println(x); // Serial.print(F(""y: "")); Serial.println(y); //#endif byte command[8] = {0x7E, 0x06, 0x01, highByte(x), lowByte(x), highByte(y), lowByte(y), 0xEF}; for( int i=0; i < sizeof(command); i++ ){ touch_screen_serial.write( command[i] ); //Serial.print(command[i],HEX); Serial.print(F("" "")); } waitForResponse(); } // This function outputs a variable number to the screen. It can show negative and positive numbers. It cannot show floats. void displayNumber(int number) { //#ifdef DEBUG_SCREEN // Serial.print(F(""DISPLAYNUMBER ("")); Serial.println(number); // Serial.print(""Number:""); Serial.println(number); //#endif byte command[8] = {0x7E, 0x06, 0x13, 0x00, 0x0A, highByte(number), lowByte(number), 0xEF}; for( int i=0; i < sizeof(command); i++ ){ touch_screen_serial.write( command[i] ); //Serial.print(command[i],HEX); Serial.print(F("" "")); } waitForResponse(); } // This function outputs a variable number to the screen. It can show negative and positive numbers. It cannot show floats. void fontSize(byte font_size) { //#ifdef DEBUG_SCREEN // Serial.print(F(""TEXTSIZE ("")); Serial.println(font_size); //#endif byte command[5] = {0x7E, 0x03, 0x03, lowByte(font_size), 0xEF}; //byte command[5] = {0x7E, 0x03, 0x03, font_size, 0xEF,}; for( int i=0; i < sizeof(command); i++ ){ touch_screen_serial.write( command[i] ); //Serial.print(command[i],HEX); Serial.print(F("" "")); } waitForResponse(); } // This function reads the serial data (if available) from the screen. //void readResponse() //{ // volatile int availableSerialCount = touch_screen_serial.available(); // // if( availableSerialCount < 5 ){ // return; // } // //Serial.println(F(""READRESPONSE"")); // // boolean savingMessage = false; // When touch message, this starts recording data into an array for analysis. // //byte metaData[metadataArraySize]; // An array to store the received serial data // TODO: use the metadata array instead. It's just as long, and their uses don't overlap. // byte metaDataPosition = 0; // The metaData array is recycled: here is holds incoming serial data. // byte startMarker = 0x7E; // Any response from the screen will start with this. // byte endMarker = 0xEF; // Any response from the screen will end with this. // byte rc; // Hold the byte form the serial stream that we're examining. // // byte c = touch_screen_serial.peek(); // if( c != startMarker ){ // rc = touch_screen_serial.read(); // Serial.print(F(""throwing away left over touch_screen_serial byte:"")); Serial.println(rc); // return; // } // //#ifdef DEBUG_SCREEN // Serial.println(F(""GOT RESPONSE"")); //#endif // // while( touch_screen_serial.available() ){ // By not checking for this the entire buffer is always cleared. // rc = touch_screen_serial.read(); //#ifdef DEBUG_SCREEN // Serial.print(rc); Serial.print(F(""-"")); //#endif // if( savingMessage == true ){ // We are now in the part of the response that is the message we were looking for. // if(rc != endMarker){ // metaData[metaDataPosition] = rc; // metaDataPosition++; // if( metaDataPosition >= metadataArraySize ){ // metaDataPosition = metadataArraySize - 1; // } // } // else { // We've arrived at the end marker. // metaData[metaDataPosition] = '\\0'; // Terminate the string. // savingMessage = false; // metaDataPosition = 0; // if(metaData[metaDataPosition] == 0x06 && metaData[metaDataPosition + 1] == 0x07){ // touchX = touchToX( (metaData[metaDataPosition + 2] * 256) + metaData[metaDataPosition + 3] ); // touchY = touchToY( (metaData[metaDataPosition + 4] * 256) + metaData[metaDataPosition + 5] ); //#ifdef DEBUG_SCREEN // Serial.print(F(""touchX="")); Serial.println(touchX); // Serial.print(F(""touchY="")); Serial.println(touchY); //#endif // // if( screen_brightness == 0 ){ //#ifdef DEBUG_SCREEN // Serial.println(F(""Turning on backlight"")); //#endif // turnOnScreen(true); // } // else{ //#ifdef DEBUG_SCREEN // Serial.println(F(""Turning off backlight"")); //#endif // turnOnScreen(false); // //basicCommand(backlight_off); // //screen_brightness = 0; // To indicate that a touch event has just occured. // } // clearReceivedBuffer(); // } //#ifdef DEBUG_SCREEN // // OK message // else if( metaData[metaDataPosition] == 0x03 && metaData[metaDataPosition + 1] == 0x6F && metaData[metaDataPosition + 2] == 0x6B ){ // Serial.println(F(""-OK"")); // } // else{ // Unimplemented response form the touch screen. // Serial.println(F(""-X-"")); // metaDataPosition++; // if( metaDataPosition == metadataArraySize ){ return; } // } //#endif // } // } // if( rc == startMarker ){ // Once a valid startMarker is found, we start saving the message into the array. // savingMessage = true; //#ifdef DEBUG_SCREEN // Serial.print(F(""(startMarker) "")); //#endif // } // } //} // This function can send basic string command that don't have any variable parts in them. void basicCommand(const char* cmd) { //#ifdef DEBUG_SCREEN // Serial.println(F(""BASIC COMMAND"")); //#endif if( touch_screen_serial.available() ){ // If necessary, clear old messages from the serial buffer. clearReceivedBuffer(); } touch_screen_serial.write(0x7E); // Starting byte, is always the same. byte b = 0; while( b < MAX_BASIC_COMMAND_LENGTH ){ // How many bytes are the basic commands at most? touch_screen_serial.write( pgm_read_byte(&cmd[b]) ); //Serial.print( pgm_read_byte(&cmd[b]),HEX ); Serial.print(F("" "")); if( pgm_read_byte(&cmd[b]) == 0xEF ){ // This breaks out of the loop. //waitForResponse(b); b = MAX_BASIC_COMMAND_LENGTH; } b++; } waitForResponse(); } // This function can be activated after sending a command. It will wait until a response has arrived (or 100 milliseconds have passed), and then allow the Arduino to continue. //void waitForResponse(byte expectedBytes) // From the touch screen void waitForResponse() // From the touch screen { #ifdef DEBUG_SCREEN Serial.println(); Serial.println(F(""WAITING FOR RESPONSE FROM SCREEN"")); Serial.print(F(""-available now: "")); Serial.println( touch_screen_serial.available() ); #endif byte b = 0; while( touch_screen_serial.available() == 0 && b < 250){ b++; wait(1); } //#ifdef DEBUG_SCREEN // Serial.print(F(""wait time: "")); Serial.println(b); #endif if( touch_screen_serial.available() > 0 ){ wait(10); // Perhaps some more bytes will show up. while( touch_screen_serial.available() > 0 ){ // Throwing away the response. All we care about is touch messages, and they are handled in the readResponse function. byte x = touch_screen_serial.read(); //Serial.print(x); Serial.print(F(""-"")); } //Serial.println(); } // else if( b == 250 ){ // Serial.println(F(""Touch screen did not respond to command"")); // } } void turnOnScreen(boolean desired_state) { //#ifdef DEBUG_SCREEN // Serial.print(F(""Setting screen backlicht to: "")); Serial.println(desired_state); //#endif if( desired_state == true ){ //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: backlight_on"")); //#endif screen_brightness = 255; basicCommand(backlight_on); // Turn on the touch screen backlight. send(button_message.setSensor(SCREEN_BUTTON_CHILD_ID).set(1)); } else { //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: backlight_off"")); //#endif screen_brightness = 0; basicCommand(backlight_off); // Turn off the touch screen backlight send(button_message.setSensor(SCREEN_BUTTON_CHILD_ID).set(0)); } } int touchToX(int x) { return int constrain(((x - 80) / 3.7), 0, TOUCHSCREEN_WIDTH); } int touchToY(int y) { return int constrain(((y - RADIO_DELAY) / 2.8), 0, TOUCHSCREEN_HEIGHT); // RADIO_DELAY=100, to save space } void clearReceivedBuffer() { //Serial.print(F(""cleaning:"")); while( touch_screen_serial.available() ){ char x = touch_screen_serial.read(); Serial.print(x); } Serial.println(); } //#endif // End of touch screen check. void receive(const MyMessage &message) { // Serial.print(F(""INCOMING MESSAGE for child #"")); Serial.println(message.sensor); if (message.isAck()) { // Serial.println(F(""-Ack"")); connectedToNetwork = true; } #ifdef HAS_TOUCH_SCREEN else if( message.type==V_STATUS && message.sensor == SCREEN_BUTTON_CHILD_ID ){ boolean desired_state = message.getBool(); // Serial.print(F(""-Requested status: "")); Serial.println(desired_state); turnOnScreen(desired_state); // Set the touch screen brightness } #endif } // VOIDS I MOVED FROM END OF FILE HERE - END void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(F(""Weather station""), F(""1.0"")); wait(RADIO_DELAY); // Tell the MySensors gateway what kind of sensors this node has, and what their ID's on the node are, as defined in the code above. present(TEMP_CHILD_ID, S_TEMP, F(""Temperature"")); wait(RADIO_DELAY); present(HUM_CHILD_ID, S_HUM, F(""Humidity"")); wait(RADIO_DELAY); present(BARO_CHILD_ID, S_BARO, F(""Air pressure"")); wait(RADIO_DELAY); present(FORECAST_CHILD_ID, S_INFO, F(""Forecast"")); wait(RADIO_DELAY); #ifdef HAS_TOUCH_SCREEN present(SCREEN_BUTTON_CHILD_ID, S_BINARY, F(""Screen"")); wait(RADIO_DELAY); send_all_values = 1; #endif } #ifdef HAS_TOUCH_SCREEN void send_values(){ //#ifdef DEBUG // Serial.println(F(""Sending button states"")); //#endif send(button_message.setSensor(SCREEN_BUTTON_CHILD_ID).set(1)); wait(RADIO_DELAY); } #endif void setup() { Serial.begin(115200); // for serial debugging over USB. // Serial.println(F("""")); #ifdef HAS_TOUCH_SCREEN wait(2000); touch_screen_serial.begin(9600); wait(2000); //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: backlight_on"")); //#endif basicCommand(backlight_on); // Turn on the backlight (if it isn't already). //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: vertical"")); //#endif basicCommand(set_vertical); // Set the screen to vertical mode. //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: white text"")); //#endif basicCommand(text_color_white); // Set text color to white. //#ifdef DEBUG_SCREEN // Serial.println(F(""BC: fill black"")); //#endif basicCommand(fill_black); // Set the background color of the screen to black. fontSize(1); // Set the font size of the touch screen to its smallest size. setCur(SCREEN_PADDING,SCREEN_PADDING); writeText(SCREEN_TEMPERATURE); roundedRectangle(0,ITEM_HEIGHT, TOUCHSCREEN_WIDTH, ITEM_HEIGHT, 0, GREY111111); //simpleHorizontal(ITEM_HEIGHT, GREYCCCCCC); setCur(SCREEN_PADDING,SCREEN_PADDING + ITEM_HEIGHT); writeText(SCREEN_HUMIDITY); //simpleHorizontal(ITEM_HEIGHT * 2, GREYCCCCCC); setCur(SCREEN_PADDING,SCREEN_PADDING + (ITEM_HEIGHT * 2)); writeText(SCREEN_FORECAST); #endif // end of has_touch_screen if(isTransportReady()){ // If we are connected to the MySensors network. //Serial.println(F(""Connected to gateway!"")); connectedToNetwork = true; //metric = getControllerConfig().isMetric; // Ask if Celcius or Fahrenheit is prefered. ASUME METRIC! }else{ //Serial.println(F(""! NOT CONNECTED TO GATEWAY"")); } unsigned status; // default settings // (you can also pass in a Wire library object like &Wire2) status = bme.begin(); if (!status) { //Serial.println(""Could not find sensor, check stuff!""); //Serial.print(""SensorID was: 0x""); Serial.println(bme.sensorID(),16); // Serial.print("" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\\n""); // Serial.print("" ID of 0x56-0x58 represents a BMP 280,\\n""); // Serial.print("" ID of 0x60 represents a BME 280.\\n""); // Serial.print("" ID of 0x61 represents a BME 680.\\n""); while (1); } //else { //Serial.print(""Sensor working""); //} //if(!bme280.init()){ //Serial.println(F(""! Sensor error"")); //#ifdef HAS_TOUCH_SCREEN //writeString(""Sensor error"",12); //#endif //} wdt_enable(WDTO_2S); // Starts the watchdog timer. If it is not reset once every 2 seconds, then the entire device will automatically restart. } void loop() { // If a presentation is requested, we also send the values of the children. if( send_all_values ){ //#ifdef DEBUG // Serial.println(F(""RESENDING VALUES"")); //#endif send_all_values = 0; send_values(); } static unsigned long previousMillis = 0; // Used to keep track of time. static byte intervalCounter = 255; // How may intervals have passed. //#ifdef HAS_TOUCH_SCREEN // // Check if the screen is being touched. // readResponse(); //#endif // // MAIN LOOP // Runs every few seconds. By counting how often this loop has run (and resetting that counter back to zero after 250 loops), it becomes possible to schedule all kinds of things without using a lot of memory. // Maximum time that can be scheduled is 4s * 250 loops = 1000 seconds. So the maximum time between sending data can be 16 minutes. // if(millis() - previousMillis >= INTERVAL){ // Main loop, runs every second. previousMillis = millis(); // Store the current time as the previous measurement start time. if(intervalCounter >= SECONDS_BETWEEN_SENDING){ intervalCounter = 0; }else{ intervalCounter++; } //Serial.println(intervalCounter); wdt_reset(); // Reset the watchdog timer // Serial.print(""counter:"");Serial.print(intervalCounter); // Clock schedule switch (intervalCounter) { // // TEMPERATURE // case 0: // If we are in the first second of the clock //temperature = bme280.getTemperature(); temperature = bme.readTemperature(); previous_temperature = temperature; // Serial.print(F(""Sending temp: "")); Serial.println(temperature); connectedToNetwork = false; // If we receive an echo then this will be set back to true. send(temperature_message.set(temperature,1),1); // Ask for an echo from the controller // if(temperature != -127.00 && temperature != 85.00 && temperature != previous_temperature) { // Avoids working with measurement errors. FUCK measurements errors! // previous_temperature = temperature; //if(!metric){ // temperature = (temperature * 9.0)/5.0 + 32.0; //} // Serial.print(F(""Sending temp: "")); Serial.println(temperature); // connectedToNetwork = false; // If we receive an echo then this will be set back to true. // send(temperature_message.set(temperature,1),1); // Ask for an echo from the controller #ifdef HAS_TOUCH_SCREEN displayNetworkStatus(); // Clear the background for this part of the screen. roundedRectangle(0,LABEL_HEIGHT, TOUCHSCREEN_WIDTH, ITEM_HEIGHT - LABEL_HEIGHT, 0, BLACK); setCur(SCREEN_PADDING,SCREEN_PADDING + LABEL_HEIGHT); fontSize(4); char value_string[7]; // We create a character array to hold a 'string' representation of the temperature value. dtostrf(temperature, 0, 1, value_string); // Here the floating point value is turned into a 'string'. byte string_length = 4; if( abs(temperature) < 10 ){ string_length = 3; } if( abs(temperature) > 99 ){ string_length = 5; } if( temperature < 0 ){ string_length++; } // Accounting for the minus character writeString(value_string,string_length); fontSize(2); writeString(""C"",1); //if(metric){ // writeString(""C"",1); //} //else{ // writeString(""F"",1); //} #endif // } //break; // // HUMIDITY // case 1: //current_humidity = bme280.getHumidity(); // Serial.print(F(""Getting humidity"")); current_humidity = bme.readHumidity(); if( current_humidity != previous_humidity ){ previous_humidity = current_humidity; // Serial.print(F(""Sending humidity "")); Serial.println(current_humidity); send(humidity_message.set(current_humidity)); #ifdef HAS_TOUCH_SCREEN displayNetworkStatus(); // Show or remove the W icon in the top-right of the screen. // Clear the background for this part of the screen. roundedRectangle(0,ITEM_HEIGHT + LABEL_HEIGHT, TOUCHSCREEN_WIDTH, ITEM_HEIGHT - LABEL_HEIGHT, 0, GREY111111); setCur(SCREEN_PADDING,SCREEN_PADDING + ITEM_HEIGHT + LABEL_HEIGHT); fontSize(4); // Show humidity value on the screen displayNumber(current_humidity); fontSize(2); writeString(""%"",1); // Show quality opinion on the screen. fontSize(4); if (current_humidity > 0 && current_humidity < 30){ writeString("" Droog"",4); } else if (current_humidity < 65){ writeString("" Okok"",5); } else { writeString("" Nat"",6); } #endif } //break; // // PRESSURE // case 2: //pressure = round(bme280.getPressure() / 100); pressure = round(bme.readPressure() / RADIO_DELAY); // RADIO_DELAY=100 to save space // Serial.print(F(""Sending pressure "")); Serial.println(pressure); send(pressure_message.set((pressure),1)); forecast = sample(pressure/RADIO_DELAY); // RADIO_DELAY=100 to save space //forecast = random(5); // Show a random icon. This is used in exhibits, to make it a bit more interesting. if (pressure != previous_pressure || forecast != lastForecast) { previous_pressure = pressure; lastForecast = forecast; #ifdef HAS_TOUCH_SCREEN // Show pressure value on the screen // Clear the background for this part of the screen. roundedRectangle(0,(ITEM_HEIGHT * 2) + LABEL_HEIGHT, TOUCHSCREEN_WIDTH, (ITEM_HEIGHT * 2) - LABEL_HEIGHT, 0, BLACK); setCur(SCREEN_PADDING,SCREEN_PADDING + (ITEM_HEIGHT * 2) + LABEL_HEIGHT); fontSize(2); char pressure_value_string[6]; // We create a character array to hold a 'string' representation of the temperature value. memset(pressure_value_string,0,sizeof(pressure_value_string));// We fill the character array with zeros dtostrf(pressure, 0, 0, pressure_value_string); // Here the floating point value is turned into a 'string'. writeString(pressure_value_string,4); byte circle_size = 40; unsigned int cloud_color = WHITE; setCur(SCREEN_PADDING, SCREEN_PADDING + (ITEM_HEIGHT * 2) + (LABEL_HEIGHT * 2)); #endif // UNKNOWN if(forecast == 5){ // Serial.println(F(""UNKNOWN"")); send(string_message.set(F(""Unknown""))); // Sending the latest forecast to the controller. #ifdef HAS_TOUCH_SCREEN //fontSize(4); writeText(SCREEN_UNKNOWN); #endif } // STABLE WEATHER if(forecast == STABLE){ // Serial.println(F(""STABLE"")); send(string_message.set(F(""Stable""))); // Sending the latest forecast to the controller. cloud_color = WHITE; #ifdef HAS_TOUCH_SCREEN fontSize(4); writeText(SCREEN_STABLE); #endif } // UNSTABLE WEATHER else if(forecast == UNSTABLE){ // Serial.println(F(""UNSTABLE"")); send(string_message.set(F(""Unstable""))); #ifdef HAS_TOUCH_SCREEN fontSize(4); writeText(SCREEN_UNSTABLE); #endif } // SUNNY WEATHER else if(forecast == SUNNY){ // Serial.println(F(""SUNNY"")); send(string_message.set(F(""Sunny""))); //circle_size = 50; #ifdef HAS_TOUCH_SCREEN //circle(TOUCHSCREEN_WIDTH / 2, ITEM_HEIGHT * 3, circle_size, LIGHT_YELLOW); // x, y, radius, color circle(TOUCHSCREEN_WIDTH / 2, ITEM_HEIGHT * 3, circle_size, YELLOW); circle(TOUCHSCREEN_WIDTH / 2, ITEM_HEIGHT * 3, circle_size - 10, LIGHT_ORANGE); fontSize(1); writeText(SCREEN_SUNNY); #endif } // CLOUDY WEATHER OR THUNDERSTORM else if(forecast == CLOUDY || forecast == THUNDERSTORM){ if(forecast == THUNDERSTORM){ cloud_color = RED; } #ifdef HAS_TOUCH_SCREEN circle(TOUCHSCREEN_WIDTH / 2, ITEM_HEIGHT * 3, circle_size, cloud_color); // x, y, radius, color circle((TOUCHSCREEN_WIDTH / 2) - circle_size, ITEM_HEIGHT * 3 + 10, circle_size - 10, cloud_color); circle(int((TOUCHSCREEN_WIDTH / 2) + circle_size), ITEM_HEIGHT * 3 + 20, circle_size - 20, cloud_color); fontSize(1); #endif if(forecast == THUNDERSTORM){ // Serial.println(F(""THUNDERSTORM"")); send(string_message.set(F(""Thunderstorm""))); #ifdef HAS_TOUCH_SCREEN writeText(SCREEN_THUNDERSTORM); #endif } else { // Serial.println(F(""CLOUDY"")); send(string_message.set(F(""Cloudy""))); #ifdef HAS_TOUCH_SCREEN writeText(SCREEN_CLOUDY); #endif } } } break; } } } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (byte i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } // Forecast algorithm found here // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf // Pressure in hPa --> forecast done by calculating kPa/h byte sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) { // first time initial 3 hour dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) { // First time initial 3 hour dP_dt = change; // Note this is for t = 1 hour } else { dP_dt = change / 2; // Divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) { // First time initial 3 hour dP_dt = change / 1.5; // Note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // Divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) { // first time initial 3 hour dP_dt = change / 2; // Note this is for t = 2 hour } else { dP_dt = change / 3; // Divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) { // First time initial 3 hour dP_dt = change / 2.5; // Note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) { // first time initial 3 hour dP_dt = change / 3; // Note this is for t = 3 hour } else { dP_dt = change / 4; // Divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // Flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } byte forecast = UNKNOWNN; if (minuteCount < 35 && firstRound) { // If time is less than 35 min on the first 3 hour interval. forecast = UNKNOWNN; } else if (dP_dt < (-0.25)) { forecast = THUNDERSTORM; } else if (dP_dt > 0.25) { forecast = UNSTABLE; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = CLOUDY; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = SUNNY; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABLE; } else { forecast = UNKNOWNN; } // Useful for debugging //Serial.print(F(""BME280 - Forecast at minute "")); //Serial.print(minuteCount); //Serial.print(F("" dP/dt = "")); //Serial.print(dP_dt); //Serial.print(F(""kPa/h --> "")); //Serial.println(weather[forecast]); //Serial.println(freeRam()); return forecast; } //for (float i=0; i<=6 ; i=i+.4) { // Calculate sun rays end points //int resultX = sunPositionX + (int)round( sunSize * cos( i ) ); //int resultY = sunPositionY + (int)round( sunSize * sin( i ) ); //} /* * * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * */ ",12255,False,1903.2795947663928,median "/* ScrollingText.ino This will scroll text on the display. Enable U8g2 16 bit mode (see FAQ) for larger text! Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) Copyright (c) 2016, olikraus@gmail.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif #ifdef U8X8_HAVE_HW_I2C #include #endif /* U8glib Example Overview: Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards. U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only. This is a page buffer example. */ // Please UNCOMMENT one of the contructor lines below // U8g2 Contructor List (Picture Loop Page Buffer) // The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp // Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected //U8G2_NULL u8g2(U8G2_R0); // null device, a 8x8 pixel display which does nothing //U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition) //U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_128X64_ALT0_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping //U8G2_SSD1306_128X64_NONAME_1_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8G2_SSD1306_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8G2_SSD1306_128X64_ALT0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8G2_SH1106_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SH1106_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8G2_SH1106_128X64_WINSTAR_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but uses updated SH1106 init sequence //U8G2_SH1106_72X40_WISE_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1107_64X128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1107_128X128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1107_128X128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); //U8G2_SH1107_SEEED_96X96_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1108_160X160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1122_256X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8G2_SSD1306_64X48_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.66"" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered //U8G2_SSD1306_48X64_WINSTAR_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_64X32_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_64X32_1F_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_96X16_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.69"" OLED //U8G2_SSD1322_NHD_256X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1322_NHD_256X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1322_NHD_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1322_NHD_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1325_NHD_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1325_NHD_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1326_ER_256X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // experimental driver for ER-OLED018-1 //U8G2_SSD1327_SEEED_96X96_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8G2_SSD1327_SEEED_96X96_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8G2_SSD1327_EA_W128128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_EA_W128128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_EA_W128128_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1327_EA_W128128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1327_MIDAS_128X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_MIDAS_128X128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1329_128X96_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1329_128X96_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X32_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X32_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X64_ADAFRUIT_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X64_ADAFRUIT_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME0_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME2_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME2_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_LD7032_60X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 9, /* dc=*/ 10, /* reset=*/ 8); // SW SPI Nano Board //U8G2_LD7032_60X32_1_4W_SW_I2C u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE); // NOT TESTED! //U8G2_UC1701_EA_DOGS102_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1701_EA_DOGS102_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_PCD8544_84X48_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8G2_PCF8812_96X65_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8G2_PCF8812_96X65_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8G2_HX1230_96X68_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_HX1230_96X68_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_KS0108_128X64_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8G2_KS0108_ERM19264_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ 16, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8G2_ST7920_192X32_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ U8X8_PIN_NONE, /*dc=*/ 17, /*reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_192X32_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18 /* A4 */, /*cs=*/ U8X8_PIN_NONE, /*dc/rs=*/ 17 /* A3 */, /*reset=*/ 15 /* A1 */); // Remember to set R/W to 0 //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8); //U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_64128N_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_64128N_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM132_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8G2_ST7565_EA_DOGM132_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8G2_ST7565_ZOLEN_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ZOLEN_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_LM6059_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8G2_ST7565_LM6059_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8G2_ST7565_LX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_LX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ERC12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12832_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12832_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_JLX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_JLX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_PI_132X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8G2_ST7567_PI_132X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8G2_ST7567_JLX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_JLX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064I_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064I_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX172104_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX172104_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX256128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 9, /* data=*/ 8, /* cs=*/ 7, /* dc=*/ 6, /* reset=*/ 5); // MKR Zero, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 6, /* reset=*/ 5); // MKR Zero, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX240160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX240160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX25664_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, enable U8g2 16 bit mode for this display //U8G2_NT7534_TG12864R_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_NT7534_TG12864R_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7588_JLX12864_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ 5); //U8G2_ST7588_JLX12864_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ 5); //U8G2_IST3020_ERC19264_1_6800 u8g2(U8G2_R0, 44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 28, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect WR pin with GND //U8G2_IST3020_ERC19264_1_8080 u8g2(U8G2_R0, 44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 29, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect RD pin with 3.3V //U8G2_IST3020_ERC19264_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_LC7981_160X80_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_160X160_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_240X64_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_SED1520_122X32_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*dc=*/ A0, /*e1=*/ A3, /*e2=*/ A2, /* reset=*/ A4); // Set R/W to low! //U8G2_T6963_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_T6963_256X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_T6963_160X80_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_SED1330_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0 //U8G2_SED1330_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E //U8G2_RA8835_NHD_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0 //U8G2_RA8835_NHD_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E //U8G2_UC1601_128X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1601_128X32_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_UC1604_JLX19264_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1604_JLX19264_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1608_ERC24064_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup //U8G2_UC1608_ERC240120_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1608_240X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup //U8G2_UC1610_EA_DOGXL160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8G2_UC1610_EA_DOGXL160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8G2_UC1611_EA_DOGM240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board //U8G2_UC1611_EA_DOGM240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8G2_UC1611_EA_DOGXL240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board //U8G2_UC1611_EA_DOGXL240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8G2_UC1611_EW50850_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 16); // 240x160, Connect RD/WR1 pin with 3.3V, CS is aktive high //U8G2_UC1638_160X128_1_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ 2, /* dc=*/ 3, /* reset=*/ 4); // Not tested //U8G2_SSD1606_172X72_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display //U8G2_SSD1607_200X200_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT from embedded artists //U8G2_SSD1607_GD_200X200_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Good Display //U8G2_IL3820_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // WaveShare 2.9 inch eInk/ePaper Display, enable 16 bit mode for this display! //U8G2_IL3820_V2_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // ePaper Display, lesser flickering and faster speed, enable 16 bit mode for this display! // End of constructor list // This example shows a scrolling text. // If U8G2_16BIT is not set (default), then the pixel width of the text must be lesser than 128 // If U8G2_16BIT is set, then the pixel width an be up to 32000 u8g2_uint_t offset; // current offset for the scrolling text u8g2_uint_t width; // pixel width of the scrolling text (must be lesser than 128 unless U8G2_16BIT is defined const char *text = ""U8g2 ""; // scroll this text from right to left void setup(void) { /* U8g2 Project: SSD1306 Test Board */ //pinMode(10, OUTPUT); //pinMode(9, OUTPUT); //digitalWrite(10, 0); //digitalWrite(9, 0); /* U8g2 Project: T6963 Test Board */ //pinMode(18, OUTPUT); //digitalWrite(18, 1); /* U8g2 Project: KS0108 Test Board */ //pinMode(16, OUTPUT); //digitalWrite(16, 0); u8g2.begin(); u8g2.setFont(u8g2_font_inb30_mr); // set the target font to calculate the pixel width width = u8g2.getUTF8Width(text); // calculate the pixel width of the text u8g2.setFontMode(0); // enable transparent mode, which is faster } void loop(void) { u8g2_uint_t x; u8g2.firstPage(); do { // draw the scrolling text at current offset x = offset; u8g2.setFont(u8g2_font_inb30_mr); // set the target font do { // repeated drawing of the scrolling text... u8g2.drawUTF8(x, 30, text); // draw the scolling text x += width; // add the pixel width of the scrolling text } while( x < u8g2.getDisplayWidth() ); // draw again until the complete display is filled u8g2.setFont(u8g2_font_inb16_mr); // draw the current pixel width u8g2.setCursor(0, 58); u8g2.print(width); // this value must be lesser than 128 unless U8G2_16BIT is set } while ( u8g2.nextPage() ); offset-=1; // scroll by one pixel if ( (u8g2_uint_t)offset < (u8g2_uint_t)-width ) offset = 0; // start over again delay(10); // do some small delay } ",12475,True,3690.2125250966815,median "/** Super Mario Overworld / Main Theme per Arduino Code for Sketch (Arduino) tested on Arduino UNO R3 Made by Reyboz Blog [ http://blog.reyboz.it ] ** warm thanks to joseph karam, author of the transcripts of piano sheet music to two hands on the notes of the original composition of the nintendo entertainment system by koji kondo, who allowed us to reproduce faithfully to the song. [http://www.mariopiano.com] */ // [ http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation ] #include // Define speaker pins (PWM~) [REQUIRED] #define PIN_PLAYER_1 11 #define PIN_PLAYER_2 10 // Define ground pins for display [OPTIONAL] #define DISPLAY_1 13 #define DISPLAY_2 12 // Trimmer pins (Analog in) [OPTIONAL] #define PIN_VOLUME 0 // LED pins [OPTIONAL] #define LED_1 9 #define LED_2 8 #define LED_3 7 #define LED_4 6 #define LED_5 5 #define LED_6 4 #define LED_7 3 #define LED_8 2 Tone player_1; Tone player_2; int tempo; // this value is more high more off the notes between them. [optional] int tronca = 15; // truncates // you can set the speed limits [optional] int tempo_minimo = 78; // min tempo int tempo_massimo = 500; // max tempo // define the order of the pin in the display so that they are ordered according to the universal convention [optional] int pin_leds[8] = {LED_3, LED_4, LED_5, LED_6, LED_7, LED_2, LED_1, LED_8}; // Note facili da usare (Non modificare) #define SOL_d2 104 #define LA2 110 #define LA_d2 114 #define SI2 124 #define DO3 131 #define DO_d3 139 #define RE3 147 #define RE_d3 156 #define MI3 165 #define FA3 175 #define FA_d3 185 #define SOL3 196 #define SOL_d3 208 #define LA3 220 #define LA_d3 233 #define SI3 247 #define DO4 262 #define DO_d4 277 #define RE4 294 #define RE_d4 311 #define MI4 330 #define FA4 349 #define FA_d4 370 #define SOL4 392 #define SOL_d4 415 #define LA4 440 #define LA_d4 466 #define SI4 494 #define DO5 523 #define DO_d5 554 #define RE5 587 #define RE_d5 622 #define MI5 659 #define FA5 698 #define FA_d5 740 #define SOL5 784 #define SOL_d5 831 #define LA5 880 #define LA_d5 932 #define SI5 988 #define DO6 1046 #define DO_d6 1109 #define RE6 1175 #define RE_d6 1245 #define MI6 1319 #define FA6 1397 #define FA_d6 1480 #define SOL6 1568 #define SOL_d6 1661 #define LA6 1760 #define LA_d6 1865 // 4/3 (DON'T EDIT) #define TERZINA 1.333 // 4/3/2 (DON'T EDIT) #define TERZINA_2 0.666 // 1/3 (DON'T EDIT) #define TERZINA_3 0.333 // 1/4 (Non modificare) #define SEMICROMA 0.25 // DON'T EDIT SETUP void setup() { //Serial.begin(9600); pinMode(DISPLAY_1, OUTPUT); pinMode(DISPLAY_2, OUTPUT); pinMode(LED_1, OUTPUT); pinMode(LED_2, OUTPUT); pinMode(LED_3, OUTPUT); pinMode(LED_4, OUTPUT); pinMode(LED_5, OUTPUT); pinMode(LED_6, OUTPUT); pinMode(LED_7, OUTPUT); pinMode(LED_8, OUTPUT); player_1.begin(PIN_PLAYER_1); player_2.begin(PIN_PLAYER_2); } /* YOU CAN USE THESE FUNCTIONS: OVERWORLD(); UNDERWATER(); UNDERWORLD(); CASTLE(); FLAGPOLEFANFARE(); DAMAGEWARP(); COIN( number_of_coin ); POWERUP(); STARMAN(); DEATH(); */ void loop() { ONEUP(); pausa(8); OVERWORLD(); pausa(8); FLAGPOLEFANFARE(); pausa(8); DAMAGEWARP(); pausa(4); UNDERWORLD(); UNDERWORLD(); pausa(16); COIN(1); pausa(1); COIN(1); COIN(1); COIN(5); POWERUP(); pausa(2); STARMAN(); STARMAN(); pausa(8); UNDERWATER(); pausa(8); DEATH(); while (1); // Shut up! } void enableDisplay(int pin) { digitalWrite(pin, LOW); } void disableDisplay(int pin) { digitalWrite(pin, HIGH); } int inputTempo() { //global tempo_massimo, tempo_minimo; return (analogRead(PIN_VOLUME) / 1023.0) * (tempo_massimo - tempo_minimo) + tempo_minimo; } /* _____________________________________________________________ | Uhm... | | Ciò potrebbe annoiarti a morte! | |____________________________________________________________| Alcuni sanno che tutte le note hanno una frequenza e che essa si può prevedere tramite questa funzione matematica: frequenza(n) = 440 * 2^(n/12) [ http://it.wikipedia.org/wiki/Nota_musicale ] Guardatela bene. Questa formula ci rivela che tutte le note che noi usiamo sono in riferimento ad una e una sola frequenza: 440Hz. Ovvero il nostro 'LA' ('A' in americano). Fermandosi a ragionare ci si rente conto di una cosa strana: Qualcuno si è mai chiesto per quale motivo noi 'normali' chiamiamo le note DO, RE MI FA... iniziando dal DO, mentre quegli 'strani' degli Inglesi le chiamano A, B, C, D... inziando dalla A che sarebbe un LA? Ebbene siamo noi quegli strani. Perchè la notazione Inglese inizia appunto con la nota più importante, ovvero quella a 440Hz: 'A'. Ed è sconvolgente sapere che se noi siamo quelli 'strani', la 'colpa' è tutta di un monaco (pure Italiano). [ http://it.wikipedia.org/wiki/Paolo_Diacono ] Curioso? No? Bah... Detto ciò, c'è un motivo se siamo dovuti andare a cercare quella formula. Infatti per suonare io non faccio altro che passare una frequenza ad un nostro metodo 'suona(frequenza, tempo)'. Perciò all'interno di 'suona', avrei potuto creare un enorme 'switch case', controllando manualmente tutte le frequenze possibili immaginabili che mi arrivano in ingresso e associarle a quello che devo far visualizzare sul display. Questo però ci è sembrato un metodo di programmazione idiota, e quindi ci siamo presi una nottata del nostro tempo per esplicitare la nota dalla funzione della frequenza citata in alto, e abbiamo ottenuto un vero e proprio riconoscitore di note dinamico. Ed ecco il risultato: */ int getAmericanIndexOfLetterFromFrequency(int frequency) { double nota = 12 * (log(((double)frequency) / 440) / log(2)); //Serial.println(); //Serial.println(nota); while (nota >= 12) { nota = nota - 12; } while (nota < 0 ) { nota = nota + 12; } //Serial.println(nota); // Arrotondamento float virgola = nota - ((int) nota); if (virgola >= 0) { return (virgola < 0.5) ? nota : ++nota; } else { return (virgola < -0.5) ? nota : --nota; } } void setLetter(int index_letter) { // global pin_leds; boolean letter_table[12][8] = { {true, true, true, false, true, true, true, false}, // A {true, true, true, false, true, true, true, true}, // A_d {false, false, true, true, true, true, true, false}, // B {true, false, false, true, true, true, false, true}, // C_d {true, false, false, true, true, true, false, false}, // C {false, true, true, true, true, false, true, false}, // D {false, true, true, true, true, false, true, true}, // D_d {true, false, false, true, true, true, true, false}, // E {true, false, false, false, true, true, true, false}, // F {true, false, false, false, true, true, true, true}, // F_d {true, false, true, true, true, true, true, false}, // G {true, false, true, true, true, true, true, true} // G_d }; for (int i = 0; i < 8; i++) { digitalWrite(pin_leds[i], (letter_table[index_letter][i]) ? HIGH : LOW); } } void suona(int frequency, float fract) { setLetter(getAmericanIndexOfLetterFromFrequency(frequency)); player_2.play(frequency, inputTempo() * fract - tronca); enableDisplay(DISPLAY_1); while (player_2.isPlaying()); disableDisplay(DISPLAY_1); delay(tronca); } void suonaCoppia(int frequency, float fract) { int index_letter = getAmericanIndexOfLetterFromFrequency(frequency); int ms = inputTempo() * fract - tronca; player_1.play(frequency, ms); player_2.play(frequency, ms); while (player_1.isPlaying() || player_2.isPlaying()) { enableDisplay(DISPLAY_1); setLetter(index_letter); delay(4); disableDisplay(DISPLAY_1); delay(1); enableDisplay(DISPLAY_2); setLetter(index_letter); delay(4); disableDisplay(DISPLAY_2); } delay(tronca); } void suonaDoppio(int frequency_1, int frequency_2, float fract) { int index_letter_1 = getAmericanIndexOfLetterFromFrequency(frequency_1); int index_letter_2 = getAmericanIndexOfLetterFromFrequency(frequency_2); int ms = inputTempo() * fract - tronca; player_1.play(frequency_1, ms); player_2.play(frequency_2, ms); while (player_1.isPlaying() || player_2.isPlaying()) { enableDisplay(DISPLAY_1); setLetter(index_letter_1); delay(4); disableDisplay(DISPLAY_1); delay(1); enableDisplay(DISPLAY_2); setLetter(index_letter_2); delay(4); disableDisplay(DISPLAY_2); } delay(tronca); } void pausa(float fract) { delay(inputTempo() * fract); } void introduzione() { // Battuta 1 suonaDoppio(MI5, FA_d4, 1); suonaDoppio(MI5, FA_d4, 1); pausa(1); suonaDoppio(MI5, FA_d4, 1); // Battuta 2 pausa(1); suonaDoppio(DO5, FA_d4, 1); suonaDoppio(MI5, FA_d4, 1); pausa(1); // Battuta 3 suonaDoppio(SOL5, SOL4, 1); pausa(3); // Battuta 4 suonaDoppio(SOL4, SOL3, 1); pausa(3); } void OVERWORLDFoglio1Riga2() { // Battita 1 suonaDoppio(DO5, SOL3, 1); pausa(2); suonaDoppio(SOL4, MI3, 1); // Battuta 2 pausa(2); suonaDoppio(MI4, DO3, 1); pausa(1); // Battuta 3 pausa(1); suonaDoppio(LA4, FA3, 1); pausa(1); suonaDoppio(SI4, SOL3, 1); // Battuta 4 pausa(1); suonaDoppio(LA_d4, FA_d3, 1); suonaDoppio(LA4, FA3, 1); pausa(1); } void OVERWORLDFoglio1Riga3() { // Battuta 1 suonaDoppio(SOL4, MI3, TERZINA); suonaDoppio(MI5, DO4, TERZINA); suonaDoppio(SOL5, MI4, TERZINA); // Battuta 2 suonaDoppio(LA5, FA4, 1); pausa(1); suonaDoppio(FA5, RE4, 1); suonaDoppio(SOL5, MI4, 1); // Battuta 3 pausa(1); suonaDoppio(MI5, DO4, 1); pausa(1); suonaDoppio(DO5, LA3, 1); // Battuta 4 suonaDoppio(RE5, SI3, 1); suonaDoppio(SI4, SOL4, 1); pausa(2); } void OVERWORLDFoglio2Riga1Battuta1() { suona(DO3, 1); pausa(1); suonaDoppio(SOL5, MI5, 1); suonaDoppio(FA_d5, RE_d5, 1); } void OVERWORLDFoglio2Riga1() { // Battuta 1 OVERWORLDFoglio2Riga1Battuta1(); // Battuta 2 suonaDoppio(FA5, RE5, 1); suonaDoppio(RE_d5, SI4, 1); suona(DO4, 1); suonaDoppio(MI5, DO5, 1); // Battuta 3 suona(FA3, 1); suonaDoppio(SOL_d4, MI4, 1); suonaDoppio(LA4, FA4, 1); suonaDoppio(DO5, SOL4, 1); // Battuta 4 suona(DO4, 1); suonaDoppio(LA4, DO4, 1); suonaDoppio(DO5, MI4, 1); suonaDoppio(RE5, FA4, 1); } void OVERWORLDFoglio2Riga2() { // Battuta 1 OVERWORLDFoglio2Riga1Battuta1(); // Battuta 2 suonaDoppio(FA5, RE5, 1); suonaDoppio(RE_d5, SI4, 1); suona(SOL3, 1); suonaDoppio(MI5, DO4, 1); // Battuta 3 pausa(1); suonaDoppio(DO6, SOL5, 1); pausa(1); suonaDoppio(DO6, SOL5, 1); // Battuta 4 suonaDoppio(DO6, SOL5, 1); pausa(1); suona(SOL3, 1); pausa(1); } void OVERWORLDFoglio2Riga4() { // Battuta 1 suona(DO3, 1); pausa(1); suonaDoppio(RE_d5, SOL_d3, 1); pausa(1); // Battuta 2 pausa(1); suonaDoppio(RE5, LA_d3, 1); pausa(2); // Battuta 3 suonaDoppio(DO5, DO4, 1); pausa(2); suona(SOL3, 1); // Battuta 4 suona(SOL3, 1); pausa(1); suona(DO3, 1); pausa(1); } void OVERWORLDFoglio4Riga1Battuta1() { suonaDoppio(DO5, SOL_d4, 1); suonaDoppio(DO5, SOL_d4, 1); pausa(1); suonaDoppio(DO5, SOL_d4, 1); } void OVERWORLDFoglio4Riga1() { // Battuta 1 OVERWORLDFoglio4Riga1Battuta1(); // Battuta 2 pausa(1); suonaDoppio(DO5, SOL_d4, 1); suonaDoppio(RE5, LA_d4, 1); pausa(1); // Battuta 3 suonaDoppio(MI5, SOL4, 1); suonaDoppio(DO5, MI4, 1); pausa(1); suonaDoppio(LA4, MI4, 1); // Battuta 4 suonaDoppio(SOL4, DO4, 1); pausa(1); suona(SOL3, 1); // Non mettere SOL2 perchè la frequenza bassa manda a troie tutta la classe Tone pausa(1); } void OVERWORLDFoglio4Riga2() { // Battuta 1 OVERWORLDFoglio4Riga1Battuta1(); // Battuta 2 pausa(1); suonaDoppio(DO5, SOL_d4, 1); suonaDoppio(RE5, LA_d4, 1); suonaDoppio(MI5, SOL4, 1); // Battuta 3 suona(SOL3, 1); pausa(2); suona(DO3, 1); // Battuta 4 pausa(2); suona(SOL3, 1); // Non mettere SOL2, la frequenza è troppo bassa e manda a puttane tutta la classe Tone pausa(1); } void OVERWORLDFoglio6Riga1() { // Battuta 1 suonaDoppio(MI5, DO5, 1); suonaDoppio(DO5, LA4, 1); pausa(1); suonaDoppio(SOL4, MI4, 1); // Battuta 2 suona(SOL3, 1); pausa(1); suonaDoppio(SOL_d4, MI4, 1); pausa(1); // Battuta 3 suonaDoppio(LA4, FA4, 1); suonaDoppio(FA5, DO5, 1); suona(FA3, 1); suonaDoppio(FA5, DO5, 1); // Battuta 4 suonaDoppio(LA4, FA4, 1); suona(DO4, 1); suona(FA3, 1); pausa(1); } void OVERWORLDFoglio6Riga2() { // Battuta 1 suonaDoppio(SI4, SOL4, TERZINA); suonaDoppio(LA5, FA5, TERZINA); suonaDoppio(LA5, FA5, TERZINA); // Battuta 2 suonaDoppio(LA5, FA5, TERZINA); suonaDoppio(SOL5, MI5, TERZINA); suonaDoppio(FA5, RE5, TERZINA); // Battuta 3 suonaDoppio(MI5, DO5, 1); suonaDoppio(DO5, LA4, 1); suona(SOL3, 1); suonaDoppio(LA4, FA4, 1); // Battuta 4 suonaDoppio(SOL4, MI4, 1); suona(DO5, 1); suona(SOL4, 1); pausa(1); } void OVERWORLDFoglio6Riga4() { // Battuta 1 suonaDoppio(SI4, SOL4, 1); suonaDoppio(FA5, RE5, 1); pausa(1); suonaDoppio(FA5, RE5, 1); // Battuta 2 suonaDoppio(FA5, RE5, TERZINA); suonaDoppio(MI5, DO5, TERZINA); suonaDoppio(RE5, SI4, TERZINA); // Battuta 3 suonaDoppio(DO5, SOL4, 1); suona(MI4, 1); suona(SOL3, 1); suona(MI4, 1); // Battuta 4 suona(DO4, 1); pausa(3); } void OVERWORLDFoglio1() { // Riga 2 OVERWORLDFoglio1Riga2(); // Riga 3 OVERWORLDFoglio1Riga3(); // Riga 4 OVERWORLDFoglio1Riga2(); // Riga 5 OVERWORLDFoglio1Riga3(); } void OVERWORLDFoglio2() { // Riga 1 OVERWORLDFoglio2Riga1(); // Riga 2 OVERWORLDFoglio2Riga2(); // Riga 3 OVERWORLDFoglio2Riga1(); // Riga 4 OVERWORLDFoglio2Riga4(); } void OVERWORLDFoglio4() { // Riga 1 OVERWORLDFoglio4Riga1(); // Riga 2 OVERWORLDFoglio4Riga2(); // Riga 3 OVERWORLDFoglio4Riga1(); // Riga 4 introduzione(); } void OVERWORLDFoglio6() { // Riga 1 OVERWORLDFoglio6Riga1(); // Riga 2 OVERWORLDFoglio6Riga2(); // Riga 3 OVERWORLDFoglio6Riga1(); // Riga 4 OVERWORLDFoglio6Riga4(); } /* UNDERWORLD */ void UNDERWORLDFoglio1Riga1Battuta1() { suonaCoppia(DO4, 1); suonaCoppia(DO5, 1); suonaCoppia(LA3, 1); suonaCoppia(LA4, 1); } void UNDERWORLDFoglio1Riga1Battuta2() { suonaCoppia(LA_d3, 1); suonaCoppia(LA_d4, 1); pausa(2); } void UNDERWORLDFoglio1Riga1() { // Battuta 1 UNDERWORLDFoglio1Riga1Battuta1(); // Battuta 2 UNDERWORLDFoglio1Riga1Battuta2(); // Battuta 3 pausa(4); // Battuta 4 UNDERWORLDFoglio1Riga1Battuta1(); // Battuta 5 UNDERWORLDFoglio1Riga1Battuta2(); // Battuta 6 pausa(4); } void UNDERWORLDFoglio1Riga2Battuta1() { suonaCoppia(FA3, 1); suonaCoppia(FA4, 1); suonaCoppia(RE3, 1); suonaCoppia(RE4, 1); } void UNDERWORLDFoglio1Riga2Battuta2() { suonaCoppia(RE_d3, 1); suonaCoppia(RE_d4, 1); pausa(2); } void UNDERWORLDFoglio1Riga2() { // Battuta 1 UNDERWORLDFoglio1Riga2Battuta1(); // Battuta 2 UNDERWORLDFoglio1Riga2Battuta2(); // Battuta 3 pausa(4); // Battuta 4 UNDERWORLDFoglio1Riga2Battuta1(); // Battuta 5 UNDERWORLDFoglio1Riga2Battuta2(); // Battuta 6 pausa(2); suonaCoppia(RE_d4, TERZINA_2); suonaCoppia(RE4, TERZINA_2); suonaCoppia(DO_d4, TERZINA_2); } void UNDERWORLDFoglio1Riga3() { // Battuta 1 suonaCoppia(DO4, 2); suonaCoppia(RE_d4, 2); // Battuta 2 suonaCoppia(RE4, 2); suonaCoppia(SOL_d3, 2); // Battuta 3 suonaCoppia(SOL3, 2); suonaCoppia(DO_d4, 2); } void UNDERWORLDFoglio1Riga4() { // Battuta 1 suonaCoppia(DO4, TERZINA_2); suonaCoppia(FA_d4, TERZINA_2); suonaCoppia(FA4, TERZINA_2); suonaCoppia(MI4, TERZINA_2); suonaCoppia(LA_d4, TERZINA_2); suonaCoppia(LA4, TERZINA_2); // Battuta 2 suonaCoppia(SOL_d4, TERZINA); suonaCoppia(RE_d4, TERZINA); suonaCoppia(SI3, TERZINA); // Battuta 3 suonaCoppia(LA_d3, TERZINA); suonaCoppia(LA3, TERZINA); suonaCoppia(SOL_d3, TERZINA); } void UNDERWORLD() { // Riga 1 UNDERWORLDFoglio1Riga1(); // Riga 2 UNDERWORLDFoglio1Riga2(); // Riga 3 UNDERWORLDFoglio1Riga3(); // Riga 4 UNDERWORLDFoglio1Riga4(); // Riga 4 pausa(12); } void COIN(int n_coin) { for (int i = 0; i < n_coin; i++) { suonaCoppia(SI5, 0.5); } suonaCoppia(MI6, 1.5); } void STARMAN() { suonaDoppio(DO5, FA4, 1); suonaDoppio(DO5, FA4, 1); suonaDoppio(DO5, FA4, 1); suona(RE4, (float) 1 / 2); suonaDoppio(DO5, FA4, (float) 1 / 2); pausa((float) 1 / 2); suonaDoppio(DO5, FA4, 1); suona(RE4, (float) 1 / 2); suonaDoppio(DO5, FA4, (float) 1 / 2); suona(RE4, (float) 1 / 2); suonaDoppio(DO5, FA4, 1); suonaDoppio(SI4, MI4, 1); suonaDoppio(SI4, MI4, 1); suonaDoppio(SI4, MI4, 1); suona(DO4, (float) 1 / 2); suonaDoppio(SI4, MI4, (float) 1 / 2); pausa((float) 1 / 2); suonaDoppio(SI4, MI4, 1); suona(DO4, (float) 1 / 2); suonaDoppio(SI4, MI4, (float) 1 / 2); suona(DO4, (float) 1 / 2); suonaDoppio(SI4, MI4, 1); } void FLAGPOLEFANFARE() { int pretronca = tronca; tronca = 0; float freqPartenza = SOL3; float freqFinale = FA_d5; float tempo = 0.0851; float passoFreq = (freqFinale - freqPartenza) / 47; float freq = freqPartenza; while (freq <= freqFinale) { suona(freq, tempo); freq += passoFreq; } tronca = pretronca; suonaCoppia(SOL5, 0.25); pausa(5.75); suona(SOL3, TERZINA_2); suonaDoppio(DO4, MI3, TERZINA_2); suonaDoppio(MI4, SOL3, TERZINA_2); suonaDoppio(SOL4, DO3, TERZINA_2); suonaDoppio(DO5, MI3, TERZINA_2); suonaDoppio(MI5, SOL3, TERZINA_2); suonaDoppio(SOL5, MI3, 2); suonaDoppio(MI5, DO3, 2); suona(SOL_d3, TERZINA_2); suonaDoppio(DO4, RE_d3, TERZINA_2); suonaDoppio(RE_d4, SOL_d3, TERZINA_2); suonaDoppio(SOL_d4, DO3, TERZINA_2); suonaDoppio(DO5, MI3, TERZINA_2); suonaDoppio(RE_d5, SOL_d3, TERZINA_2); suonaDoppio(SOL_d5, RE_d3, 2); suonaDoppio(RE_d5, DO3, 2); suona(LA_d3, TERZINA_2); suonaDoppio(RE4, LA_d3, TERZINA_2); suonaDoppio(FA4, FA3, TERZINA_2); suonaDoppio(LA_d4, RE3, TERZINA_2); suonaDoppio(RE5, FA3, TERZINA_2); suonaDoppio(FA5, LA_d3, TERZINA_2); suonaDoppio(LA_d5, RE4, 2); suonaDoppio(LA_d5, LA_d3, TERZINA_2); suonaDoppio(LA_d5, LA_d3, TERZINA_2); suonaDoppio(LA_d5, LA_d3, TERZINA_2); suonaDoppio(DO6, DO4, 4); } void POWERUP() { suonaCoppia(SOL4, 0.2); suonaCoppia(SI4, 0.2); suonaCoppia(RE5, 0.2); suonaCoppia(SOL5, 0.2); suonaCoppia(SI5, 0.2); suonaCoppia(SOL_d4, 0.2); suonaCoppia(DO5, 0.2); suonaCoppia(RE_d5, 0.2); suonaCoppia(SOL_d5, 0.2); suonaCoppia(DO6, 0.2); suonaCoppia(LA_d4, 0.2); suonaCoppia(RE5, 0.2); suonaCoppia(FA5, 0.2); suonaCoppia(LA_d5, 0.2); suonaCoppia(RE6, 0.2); pausa(1); } void ITEMBLOCK() { suonaDoppio(SOL4, SOL3, 0.5); suonaDoppio(SOL_d4, SOL_d3, 0.5); suonaDoppio(LA4, LA3, 0.5); suonaDoppio(LA_d4, LA_d3, 0.5); suonaDoppio(SI4, SI3, 0.5); pausa(1.0); } void DAMAGEWARP() { for (int i = 0; i < 3; i++) { suonaCoppia(LA4, TERZINA_3); suonaCoppia(MI4, TERZINA_3); suonaCoppia(LA3, TERZINA_3); pausa(1); } pausa(2); } void ONEUP() { suonaCoppia(MI5, 1); suonaCoppia(SOL5, 1); suonaCoppia(MI6, 1); suonaCoppia(DO6, 1); suonaCoppia(RE6, 1); suonaCoppia(SOL6, 1); pausa(2); } void RESCUEFANFARE() { int pretronca = tronca; tronca = 0; for (int i = 0; i < 2; i++) { suonaDoppio(DO5, MI3, TERZINA_2); suonaDoppio(SOL4, MI3, TERZINA_2); suonaDoppio(MI4, MI3, TERZINA_2); } tronca = pretronca; suonaDoppio(DO5, MI3, 1); suonaDoppio(DO5, MI3, 0.5); suonaDoppio(DO5, MI3, 0.5); for (int i = 0; i < 3; i++) { suonaDoppio(DO5, MI3, TERZINA_2); } tronca = 0; for (int i = 0; i < 2; i++) { suonaDoppio(DO_d5, FA3, TERZINA_2); suonaDoppio(SOL_d4, FA3, TERZINA_2); suonaDoppio(FA4, FA3, TERZINA_2); } tronca = pretronca; suonaDoppio(DO_d5, FA3, 1); suonaDoppio(DO_d5, FA3, 0.5); suonaDoppio(DO_d5, FA3, 0.5); for (int i = 0; i < 3; i++) { suonaDoppio(DO_d5, FA3, TERZINA_2); } tronca = 0; for (int i = 0; i < 2; i++) { suonaDoppio(RE_d5, SOL4, TERZINA_2); suonaDoppio(LA_d4, RE_d4, TERZINA_2); suonaDoppio(SOL4, LA_d3, TERZINA_2); } tronca = pretronca; suonaDoppio(RE_d5, SOL4, 1); suonaDoppio(RE_d5, SOL4, 0.5); suonaDoppio(RE_d5, SOL4, 0.5); for (int i = 0; i < 3; i++) { suonaDoppio(FA5, LA4, TERZINA_2); } suonaDoppio(SOL5, SI4, 4); } void DEATH() { suonaCoppia(DO5, (float) 1 / 4); suonaCoppia(DO_d5, (float) 1 / 4); suonaCoppia(RE5, 0.5); pausa(3); suonaDoppio(SI4, SOL4, 1); suonaDoppio(FA5, RE5, 1); pausa(1); suonaDoppio(FA5, RE5, 1); suonaDoppio(FA5, RE5, TERZINA); suonaDoppio(MI5, DO5, TERZINA); suonaDoppio(RE5, SI4, TERZINA); suonaDoppio(DO5, SOL4, 1); suona(MI4, 1); suona(SOL3, 1); suona(MI4, 1); suonaDoppio(DO4, DO3, 1); pausa(3); } void GAMEOVER() { suonaDoppio(DO5, MI4, 1); pausa(2); suonaDoppio(SOL4, DO4, 1); pausa(2); suonaDoppio(MI4, SOL3, 2); suonaDoppio(LA4, FA4, TERZINA); suonaDoppio(SI4, FA4, TERZINA); suonaDoppio(LA4, FA4, TERZINA); suonaDoppio(SOL_d4, FA4, 2); suonaDoppio(LA_d4, FA4, 2); suonaDoppio(SOL_d4, FA4, 2); suonaDoppio(SOL4, MI4, 1); suonaDoppio(SOL4, RE4, 1); suonaDoppio(SOL4, MI4, 8); } void CASTLEBattuta1() { suonaDoppio(RE5, LA_d4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(DO_d4, LA4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(DO4, SOL_d4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(DO_d4, LA4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(RE5, LA_d4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(RE_d4, SI4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(RE4, LA_d4, SEMICROMA); suona(SOL4, SEMICROMA); suonaDoppio(DO_d4, LA4, SEMICROMA); suona(SOL4, SEMICROMA); } void CASTLEBattuta3() { suonaDoppio(DO_d5, LA4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(DO4, SOL_d4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(DO_d4, LA4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(RE4, LA_d4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(DO_d5, LA4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(RE4, LA_d4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(DO_d4, LA_d4, SEMICROMA); suona(FA_d4, SEMICROMA); suonaDoppio(DO4, SOL_d4, SEMICROMA); suona(FA_d4, SEMICROMA); } void CASTLEBattuta5() { suonaDoppio(FA5, DO_d5, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(FA_d5, RE5, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(FA5, DO_d5, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(MI5, DO4, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(FA5, DO_d5, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(MI5, DO5, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(RE_d5, SI4, SEMICROMA); suona(LA_d4, SEMICROMA); suonaDoppio(MI5, DO5, SEMICROMA); suona(LA_d4, SEMICROMA); } void CASTLE() { int pretronca = tronca; tronca = 0; for (int i = 0; i < 2; i++) { CASTLEBattuta1(); CASTLEBattuta1(); CASTLEBattuta3(); CASTLEBattuta3(); CASTLEBattuta5(); CASTLEBattuta5(); } tronca = pretronca; } void UNDERWATER() { int pretronca = tronca; tronca = 0; suonaDoppio(RE4, RE4, 1); suonaDoppio(MI4, DO_d4, 1); suonaDoppio(FA_d4, DO4, 1); suonaDoppio(SOL4, SI3, 1); suonaDoppio(LA4, DO4, 1); suonaDoppio(LA_d4, DO_d4, 1); suonaDoppio(SI4, RE4, 0.5); suonaDoppio(SI4, RE4, 0.5); suonaDoppio(SI4, RE4, 1); suonaDoppio(SI4, SOL3, 1); suonaDoppio(SI4, SOL3, 2); suona(SOL4, 1); // Riga 2 suonaDoppio(MI5, DO3, 1); suonaDoppio(MI5, SOL3, 1); suonaDoppio(MI5, DO4, 1); suonaDoppio(RE_d5, SI2, 1); suonaDoppio(RE_d5, SOL3, 1); suonaDoppio(RE_d5, SI3, 1); suonaDoppio(MI5, DO3, 1); suonaDoppio(MI5, SOL3, 1); suonaDoppio(MI5, DO4, 1); suona(MI4, 0.5); suonaDoppio(SOL4, MI4, 0.5); suonaDoppio(LA4, SOL3, 0.5); suonaDoppio(SI4, SOL3, 0.5); suonaDoppio(DO5, DO4, 0.5); suonaDoppio(RE5, DO4, 0.5); // Riga 3 suonaDoppio(MI5, DO3, 1); suonaDoppio(MI5, SOL3, 1); suonaDoppio(MI5, DO4, 1); suonaDoppio(RE_d5, SI2, 1); suonaDoppio(RE_d5, SOL3, 1); suonaDoppio(FA5, SI3, 1); suonaDoppio(MI5, DO3, 1); suonaDoppio(MI5, SOL3, 1); suonaDoppio(MI5, DO4, 1); suona(MI3, 1); suona(SOL3, 1); suona(DO4, 0.5); suona(SOL4, 0.5); // Riga 4 suonaDoppio(RE5, RE3, 1); suonaDoppio(RE5, SOL3, 1); suonaDoppio(RE5, SI3, 1); suonaDoppio(DO_d5, DO_d3, 1); suonaDoppio(DO_d5, FA_d3, 1); suonaDoppio(DO_d5, LA_d3, 1); suonaDoppio(RE5, RE3, 1); suonaDoppio(RE5, SOL3, 1); suonaDoppio(RE5, SI3, 1); suona(SI2, 0.5); suonaDoppio(SOL4, SI2, 0.5); suonaDoppio(LA4, SOL3, 0.5); suonaDoppio(SI4, SOL3, 0.5); suonaDoppio(DO5, SI3, 0.5); suonaDoppio(DO_d5, SI3, 0.5); // Foglio 2 // Riga 1 suonaDoppio(RE5, RE3, 1); suonaDoppio(RE5, SOL3, 1); suonaDoppio(RE5, SI3, 1); suonaDoppio(SOL4, SI2, 1); suonaDoppio(SOL4, SOL3, 1); suonaDoppio(FA5, SI3, 1); suonaDoppio(MI5, DO3, 1); suonaDoppio(MI5, SOL3, 1); suonaDoppio(MI5, SOL4, 1); suona(DO3, 1); // Non posso fare SOL2: Arduino esplode suona(SOL3, 1); suona(DO4, 0.5); suonaDoppio(SOL4, DO4, 0.5); // Riga 2 suonaDoppio(SOL5, DO3, 1); suonaDoppio(SOL5, SOL3, 1); suonaDoppio(SOL5, MI4, 1); suonaDoppio(SOL5, SI2, 1); suonaDoppio(SOL5, SOL3, 1); suonaDoppio(SOL5, RE4, 1); suonaDoppio(SOL5, SI2, 1); // CON LA_d2 Esplode! suonaDoppio(SOL5, SOL3, 1); suonaDoppio(SOL5, DO_d4, 1); suonaDoppio(SOL5, DO_d3, 1); suonaDoppio(LA5, SOL3, 1); suona(MI4, 0.5); suonaDoppio(SOL5, MI4, 0.5); // Riga 3 suonaDoppio(FA5, RE3, 1); suonaDoppio(FA5, LA3, 1); suonaDoppio(FA5, RE4, 1); suonaDoppio(FA5, DO_d3, 1); suonaDoppio(FA5, LA3, 1); suonaDoppio(FA5, DO_d4, 1); suonaDoppio(FA5, DO3, 1); suonaDoppio(FA5, LA3, 1); suonaDoppio(FA5, RE4, 1); suonaDoppio(FA5, SI2, 1); suonaDoppio(SOL5, SOL3, 1); suona(RE4, 0.5); suonaDoppio(FA5, RE4, 0.5); // Riga 4 suonaDoppio(MI5, DO3, 1); // COn DO2 esplode! suonaDoppio(MI5, SOL3, 1); suonaDoppio(MI5, MI4, 1); suonaDoppio(LA4, SOL3, 1); // Con SOL2 esplode! suonaDoppio(SI4, SOL3, 1); suonaDoppio(FA5, SOL3, 1); suonaDoppio(MI5, MI3, 0.5); suonaDoppio(MI5, MI3, 0.5); suonaDoppio(MI5, MI3, 1.5); suonaDoppio(SI4, SI2, 0.5); suonaDoppio(DO5, DO3, 3); tronca = pretronca; } void OVERWORLD() { introduzione(); OVERWORLDFoglio1(); // Foglio 2 OVERWORLDFoglio2(); // Foglio 3 OVERWORLDFoglio2(); // Foglio 4 OVERWORLDFoglio4(); // Foglio 5 OVERWORLDFoglio1(); // Foglio 6 OVERWORLDFoglio6(); // Foglio 7 //OVERWORLDFoglio6(); // Foglio 8 //OVERWORLDFoglio4(); // Foglio 9 //OVERWORLDFoglio6(); } ",12204,True,2826.9909533491827,median "INCLUDE ""charmap.asm"" INCLUDE ""constants/text_constants.asm"" TEXT_1 EQU $20 TEXT_2 EQU TEXT_1 + 1 TEXT_3 EQU TEXT_2 + 1 TEXT_4 EQU TEXT_3 + 1 TEXT_5 EQU TEXT_4 + 1 TEXT_6 EQU TEXT_5 + 1 TEXT_7 EQU TEXT_6 + 1 TEXT_8 EQU TEXT_7 + 1 TEXT_9 EQU TEXT_8 + 1 TEXT_10 EQU TEXT_9 + 1 TEXT_11 EQU TEXT_10 + 1 POKEDEX_TEXT EQU TEXT_11 + 1 MOVE_NAMES EQU POKEDEX_TEXT + 1 INCLUDE ""macros.asm"" INCLUDE ""hram.asm"" SECTION ""Text 1"", ROMX, BANK[TEXT_1] _CardKeySuccessText1:: text ""Bingo!@@"" _CardKeySuccessText2:: text """" line ""The CARD KEY"" cont ""opened the door!"" done _CardKeyFailText:: text ""Darn! It needs a"" line ""CARD KEY!"" done _TrainerNameText:: TX_RAM wcd6d text "": @@"" _NoNibbleText:: text ""Not even a nibble!"" prompt _NothingHereText:: text ""Looks like there's"" line ""nothing here."" prompt _ItsABiteText:: text ""Oh!"" line ""It's a bite!"" prompt _ExclamationText:: text ""!"" done _GroundRoseText:: text ""Ground rose up"" line ""somewhere!"" done _BoulderText:: text ""This requires"" line ""STRENGTH to move!"" done _MartSignText:: text ""All your item"" line ""needs fulfilled!"" cont ""#MON MART"" done _PokeCenterSignText:: text ""Heal Your #MON!"" line ""#MON CENTER"" done _FoundItemText:: text "" found"" line ""@"" TX_RAM wcf4b text ""!@@"" _NoMoreRoomForItemText:: text ""No more room for"" line ""items!"" done _OaksAideHiText:: text ""Hi! Remember me?"" line ""I'm PROF.OAK's"" cont ""AIDE!"" para ""If you caught @"" TX_NUM hOaksAideRequirement, 1, 3 text """" line ""kinds of #MON,"" cont ""I'm supposed to"" cont ""give you an"" cont ""@"" TX_RAM wOaksAideRewardItemName text ""!"" para ""So, ! Have"" line ""you caught at"" cont ""least @"" TX_NUM hOaksAideRequirement, 1, 3 text "" kinds of"" cont ""#MON?"" done _OaksAideUhOhText:: text ""Let's see..."" line ""Uh-oh! You have"" cont ""caught only @"" TX_NUM hOaksAideNumMonsOwned, 1, 3 text """" cont ""kinds of #MON!"" para ""You need @"" TX_NUM hOaksAideRequirement, 1, 3 text "" kinds"" line ""if you want the"" cont ""@"" TX_RAM wOaksAideRewardItemName text ""."" done _OaksAideComeBackText:: text ""Oh. I see."" para ""When you get @"" TX_NUM hOaksAideRequirement, 1, 3 text """" line ""kinds, come back"" cont ""for @"" TX_RAM wOaksAideRewardItemName text ""."" done _OaksAideHereYouGoText:: text ""Great! You have"" line ""caught @"" TX_NUM hOaksAideNumMonsOwned, 1, 3 text "" kinds "" cont ""of #MON!"" cont ""Congratulations!"" para ""Here you go!"" prompt _OaksAideGotItemText:: text "" got the"" line ""@"" TX_RAM wOaksAideRewardItemName text ""!@@"" _OaksAideNoRoomText:: text ""Oh! I see you"" line ""don't have any"" cont ""room for the"" cont ""@"" TX_RAM wOaksAideRewardItemName text ""."" done INCLUDE ""text/maps/viridian_forest.asm"" INCLUDE ""text/maps/mt_moon_1f.asm"" INCLUDE ""text/maps/mt_moon_b1f.asm"" INCLUDE ""text/maps/mt_moon_b2f.asm"" INCLUDE ""text/maps/ss_anne_1.asm"" INCLUDE ""text/maps/ss_anne_2.asm"" INCLUDE ""text/maps/ss_anne_3.asm"" INCLUDE ""text/maps/ss_anne_5.asm"" INCLUDE ""text/maps/ss_anne_6.asm"" INCLUDE ""text/maps/ss_anne_7.asm"" INCLUDE ""text/maps/ss_anne_8.asm"" INCLUDE ""text/maps/ss_anne_9.asm"" INCLUDE ""text/maps/ss_anne_10.asm"" INCLUDE ""text/maps/victory_road_3f.asm"" INCLUDE ""text/maps/rocket_hideout_b1f.asm"" INCLUDE ""text/maps/rocket_hideout_b2f.asm"" INCLUDE ""text/maps/rocket_hideout_b3f.asm"" INCLUDE ""text/maps/rocket_hideout_b4f.asm"" INCLUDE ""text/maps/rocket_hideout_elevator.asm"" INCLUDE ""text/maps/silph_co_2f.asm"" INCLUDE ""text/maps/silph_co_3f.asm"" INCLUDE ""text/maps/silph_co_4f.asm"" INCLUDE ""text/maps/silph_co_5f_1.asm"" SECTION ""Text 2"", ROMX, BANK[TEXT_2] INCLUDE ""text/maps/silph_co_5f_2.asm"" INCLUDE ""text/maps/silph_co_6f.asm"" INCLUDE ""text/maps/silph_co_7f.asm"" INCLUDE ""text/maps/silph_co_8f.asm"" INCLUDE ""text/maps/silph_co_9f.asm"" INCLUDE ""text/maps/silph_co_10f.asm"" INCLUDE ""text/maps/silph_co_11f.asm"" INCLUDE ""text/maps/mansion_2f.asm"" INCLUDE ""text/maps/mansion_3f.asm"" INCLUDE ""text/maps/mansion_b1f.asm"" INCLUDE ""text/maps/safari_zone_east.asm"" INCLUDE ""text/maps/safari_zone_north.asm"" INCLUDE ""text/maps/safari_zone_west.asm"" INCLUDE ""text/maps/safari_zone_center.asm"" INCLUDE ""text/maps/safari_zone_rest_house_1.asm"" INCLUDE ""text/maps/safari_zone_secret_house.asm"" INCLUDE ""text/maps/safari_zone_rest_house_2.asm"" INCLUDE ""text/maps/safari_zone_rest_house_3.asm"" INCLUDE ""text/maps/safari_zone_rest_house_4.asm"" INCLUDE ""text/maps/unknown_dungeon_b1f.asm"" INCLUDE ""text/maps/victory_road_1f.asm"" INCLUDE ""text/maps/lance.asm"" INCLUDE ""text/maps/hall_of_fame.asm"" INCLUDE ""text/maps/champion.asm"" INCLUDE ""text/maps/lorelei.asm"" INCLUDE ""text/maps/bruno.asm"" INCLUDE ""text/maps/agatha.asm"" INCLUDE ""text/maps/rock_tunnel_b2f_1.asm"" SECTION ""Text 3"", ROMX, BANK[TEXT_3] INCLUDE ""text/maps/rock_tunnel_b2f_2.asm"" INCLUDE ""text/maps/seafoam_islands_b4f.asm"" INCLUDE ""text/maps/move_deleter.asm"" INCLUDE ""text/maps/move_reminder.asm"" _AIBattleWithdrawText:: TX_RAM wTrainerName text "" with-"" line ""drew @"" TX_RAM wEnemyMonNick text ""!"" prompt _AIBattleUseItemText:: TX_RAM wTrainerName text """" line ""used @"" TX_RAM wcd6d text """" cont ""on @"" TX_RAM wEnemyMonNick text ""!"" prompt _TradeWentToText:: TX_RAM wcf4b text "" went"" line ""to @"" TX_RAM wGrassRate text ""."" done _TradeForText:: text ""For 's"" line ""@"" TX_RAM wcf4b text "","" done _TradeSendsText:: TX_RAM wGrassRate text "" sends"" line ""@"" TX_RAM wcd6d text ""."" done _TradeWavesFarewellText:: TX_RAM wGrassRate text "" waves"" line ""farewell as"" done _TradeTransferredText:: TX_RAM wcd6d text "" is"" line ""transferred."" done _TradeTakeCareText:: text ""Take good care of"" line ""@"" TX_RAM wcd6d text ""."" done _TradeWillTradeText:: TX_RAM wGrassRate text "" will"" line ""trade @"" TX_RAM wcd6d text """" done _TradeforText:: text ""for 's"" line ""@"" TX_RAM wcf4b text ""."" done _PlaySlotMachineText:: text ""A slot machine!"" line ""Want to play?"" done _OutOfCoinsSlotMachineText:: text ""Darn!"" line ""Ran out of coins!"" done _BetHowManySlotMachineText:: text ""Bet how many"" line ""coins?"" done _StartSlotMachineText:: text ""Start!"" done _NotEnoughCoinsSlotMachineText:: text ""Not enough"" line ""coins!"" prompt _OneMoreGoSlotMachineText:: text ""One more "" line ""go?"" done _LinedUpText:: text "" lined up!"" line ""Scored @"" TX_RAM wcf4b text "" coins!"" done _NotThisTimeText:: text ""Not this time!"" prompt _YeahText:: text ""Yeah!@@"" _DexSeenOwnedText:: text ""#DEX Seen:@"" TX_NUM wDexRatingNumMonsSeen, 1, 3 text """" line "" Owned:@"" TX_NUM wDexRatingNumMonsOwned, 1, 3 db ""@"" _DexRatingText:: text ""#DEX Rating"", $6d done _GymStatueText1:: TX_RAM wGymCityName text """" line ""#MON GYM"" cont ""LEADER: @"" TX_RAM wGymLeaderName text """" para ""WINNING TRAINERS:"" line """" done _GymStatueText2:: TX_RAM wGymCityName text """" line ""#MON GYM"" cont ""LEADER: @"" TX_RAM wGymLeaderName text """" para ""WINNING TRAINERS:"" line """" cont """" done _ViridianCityPokecenterGuyText:: text ""#MON CENTERs"" line ""heal your tired,"" cont ""hurt or fainted"" cont ""#MON!"" done _PewterCityPokecenterGuyText:: text ""Yawn!"" para ""When JIGGLYPUFF"" line ""sings, #MON"" cont ""get drowsy..."" para ""...Me too..."" line ""Snore..."" done _CeruleanPokecenterGuyText:: text ""BILL has lots of"" line ""#MON!"" para ""He collects rare"" line ""ones too!"" done _LavenderPokecenterGuyText:: text ""CUBONEs wear"" line ""skulls, right?"" para ""People will pay a"" line ""lot for one!"" done _MtMoonPokecenterBenchGuyText:: text ""If you have too"" line ""many #MON, you"" cont ""should store them"" cont ""via PC!"" done _RockTunnelPokecenterGuyText:: text ""I heard that"" line ""GHOSTs haunt"" cont ""LAVENDER TOWN!"" done _UnusedBenchGuyText1:: text ""I wish I could"" line ""catch #MON."" done _UnusedBenchGuyText2:: text ""I'm tired from"" line ""all the fun..."" done _UnusedBenchGuyText3:: text ""SILPH's manager"" line ""is hiding in the"" cont ""SAFARI ZONE."" done _VermilionPokecenterGuyText:: text ""It is true that a"" line ""higher level"" cont ""#MON will be"" cont ""more powerful..."" para ""But, all #MON"" line ""will have weak"" cont ""points against"" cont ""specific types."" para ""So, there is no"" line ""universally"" cont ""strong #MON."" done _CeladonCityPokecenterGuyText:: text ""If I had a BIKE,"" line ""I would go to"" cont ""CYCLING ROAD!"" done _FuchsiaCityPokecenterGuyText:: text ""If you're studying "" line ""#MON, visit"" cont ""the SAFARI ZONE."" para ""It has all sorts"" line ""of rare #MON."" done _CinnabarPokecenterGuyText:: text ""#MON can still"" line ""learn techniques"" cont ""after canceling"" cont ""evolution."" para ""Evolution can wait"" line ""until new moves"" cont ""have been learned."" done _SaffronCityPokecenterGuyText1:: text ""It would be great"" line ""if the ELITE FOUR"" cont ""came and stomped"" cont ""TEAM ROCKET!"" done _SaffronCityPokecenterGuyText2:: text ""TEAM ROCKET took"" line ""off! We can go"" cont ""out safely again!"" cont ""That's great!"" done _CeladonCityHotelText:: text ""My sis brought me"" line ""on this vacation!"" done _BookcaseText:: text ""Crammed full of"" line ""#MON books!"" done _NewBicycleText:: text ""A shiny new"" line ""BICYCLE!"" done _PushStartText:: text ""Push START to"" line ""open the MENU!"" done _SaveOptionText:: text ""The SAVE option is"" line ""on the MENU"" cont ""screen."" done _StrengthsAndWeaknessesText:: text ""All #MON types"" line ""have strong and"" cont ""weak points"" cont ""against others."" done _TimesUpText:: text ""PA: Ding-dong!"" para ""Time's up!"" prompt _GameOverText:: text ""PA: Your SAFARI"" line ""GAME is over!"" done _CinnabarGymQuizIntroText:: text ""#MON Quiz!"" para ""Get it right and"" line ""the door opens to"" cont ""the next room!"" para ""Get it wrong and"" line ""face a trainer!"" para ""If you want to"" line ""conserve your"" cont ""#MON for the"" cont ""GYM LEADER..."" para ""Then get it right!"" line ""Here we go!"" prompt _CinnabarQuizQuestionsText1:: text ""CATERPIE evolves"" line ""into BUTTERFREE?"" done _CinnabarQuizQuestionsText2:: text ""There are 9"" line ""certified #MON"" cont ""LEAGUE BADGEs?"" done _CinnabarQuizQuestionsText3:: text ""POLIWAG evolves 3"" line ""times?"" done _CinnabarQuizQuestionsText4:: text ""Are thunder moves"" line ""effective against"" cont ""ground element-"" cont ""type #MON?"" done _CinnabarQuizQuestionsText5:: text ""#MON of the"" line ""same kind and"" cont ""level are not"" cont ""identical?"" done _CinnabarQuizQuestionsText6:: text ""TM28 contains"" line ""TOMBSTONER?"" done _CinnabarGymQuizCorrectText:: text ""You're absolutely"" line ""correct!"" para ""Go on through!@@"" _CinnabarGymQuizIncorrectText:: text ""Sorry! Bad call!"" prompt _MagazinesText:: text ""#MON magazines!"" para ""#MON notebooks!"" para ""#MON graphs!"" done _BillsHouseMonitorText:: text ""TELEPORTER is"" line ""displayed on the"" cont ""PC monitor."" done _BillsHouseInitiatedText:: text "" initiated"" line ""TELEPORTER's Cell"" cont ""Separator!@@"" _BillsHousePokemonListText1:: text ""BILL's favorite"" line ""#MON list!"" prompt _BillsHousePokemonListText2:: text ""Which #MON do"" line ""you want to see?"" done _OakLabEmailText:: text ""There's an e-mail"" line ""message here!"" para ""..."" para ""Calling all"" line ""#MON trainers!"" para ""The elite trainers"" line ""of #MON LEAGUE"" cont ""are ready to take"" cont ""on all comers!"" para ""Bring your best"" line ""#MON and see"" cont ""how you rate as a"" cont ""trainer!"" para ""#MON LEAGUE HQ"" line ""INDIGO PLATEAU"" para ""PS: PROF.OAK,"" line ""please visit us!"" cont ""..."" done _GameCornerCoinCaseText:: text ""A COIN CASE is"" line ""required!"" done _GameCornerNoCoinsText:: text ""You don't have"" line ""any coins!"" done _GameCornerOutOfOrderText:: text ""OUT OF ORDER"" line ""This is broken."" done _GameCornerOutToLunchText:: text ""OUT TO LUNCH"" line ""This is reserved."" done _GameCornerSomeonesKeysText:: text ""Someone's keys!"" line ""They'll be back."" done _JustAMomentText:: text ""Just a moment."" done TMNotebookText:: text ""It's a pamphlet"" line ""on TMs."" para ""..."" para ""There are 50 TMs"" line ""in all."" para ""There are also 5"" line ""HMs that can be"" cont ""used repeatedly."" para ""SILPH CO.@@"" _TurnPageText:: text ""Turn the page?"" done _ViridianSchoolNotebookText5:: text ""GIRL: Hey! Don't"" line ""look at my notes!@@"" _ViridianSchoolNotebookText1:: text ""Looked at the"" line ""notebook!"" para ""First page..."" para ""# BALLs are"" line ""used to catch"" cont ""#MON."" para ""Up to 6 #MON"" line ""can be carried."" para ""People who raise"" line ""and make #MON"" cont ""fight are called"" cont ""#MON trainers."" prompt _ViridianSchoolNotebookText2:: text ""Second page..."" para ""A healthy #MON"" line ""may be hard to"" cont ""catch, so weaken"" cont ""it first!"" para ""Poison, burns and"" line ""other damage are"" cont ""effective!"" prompt _ViridianSchoolNotebookText3:: text ""Third page..."" para ""#MON trainers"" line ""seek others to"" cont ""engage in #MON"" cont ""fights."" para ""Battles are"" line ""constantly fought"" cont ""at #MON GYMs."" prompt _ViridianSchoolNotebookText4:: text ""Fourth page..."" para ""The goal for"" line ""#MON trainers"" cont ""is to beat the "" cont ""top 8 #MON"" cont ""GYM LEADERs."" para ""Do so to earn the"" line ""right to face..."" para ""The ELITE FOUR of"" line ""#MON LEAGUE!"" prompt _EnemiesOnEverySideText:: text ""Enemies on every"" line ""side!"" done _WhatGoesAroundComesAroundText:: text ""What goes around"" line ""comes around!"" done _FightingDojoText:: text ""FIGHTING DOJO"" done _IndigoPlateauHQText:: text ""INDIGO PLATEAU"" line ""#MON LEAGUE HQ"" done _RedBedroomSNESText:: text "" is"" line ""playing the SNES!"" cont ""...Okay!"" cont ""It's time to go!"" done _Route15UpstairsBinocularsText:: text ""Looked into the"" line ""binoculars..."" para ""A large, shining"" line ""bird is flying"" cont ""toward the sea."" done _AerodactylFossilText:: text ""AERODACTYL Fossil"" line ""A primitive and"" cont ""rare #MON."" done _KabutopsFossilText:: text ""KABUTOPS Fossil"" line ""A primitive and"" cont ""rare #MON."" done _LinkCableHelpText1:: text ""TRAINER TIPS"" para ""Using a Game Link"" line ""Cable"" prompt _LinkCableHelpText2:: text ""Which heading do"" line ""you want to read?"" done _LinkCableInfoText1:: text ""When you have"" line ""linked your GAME"" cont ""BOY with another"" cont ""GAME BOY, talk to"" cont ""the attendant on"" cont ""the right in any"" cont ""#MON CENTER."" prompt _LinkCableInfoText2:: text ""COLOSSEUM lets"" line ""you play against"" cont ""a friend."" prompt _LinkCableInfoText3:: text ""TRADE CENTER is"" line ""used for trading"" cont ""#MON."" prompt _ViridianSchoolBlackboardText1:: text ""The blackboard"" line ""describes #MON"" cont ""STATUS changes"" cont ""during battles."" prompt _ViridianSchoolBlackboardText2:: text ""Which heading do"" line ""you want to read?"" done _ViridianBlackboardSleepText:: text ""A #MON can't"" line ""attack if it's"" cont ""asleep!"" para ""#MON will stay"" line ""asleep even after"" cont ""battles."" para ""Use AWAKENING to"" line ""wake them up!"" prompt _ViridianBlackboardPoisonText:: text ""When poisoned, a"" line ""#MON's health"" cont ""steadily drops."" para ""Poison lingers"" line ""after battles."" para ""Use an ANTIDOTE"" line ""to cure poison!"" prompt _ViridianBlackboardPrlzText:: text ""Paralysis could"" line ""make #MON"" cont ""unable to attack!"" para ""It also reduces"" line ""the SPEED stat!"" para ""Paralysis remains"" line ""after battles."" para ""Use PARLYZ HEAL"" line ""for treatment!"" prompt _ViridianBlackboardBurnText:: text ""When burned, a"" line ""#MON's health"" cont ""steadily drops."" para ""It also reduces"" line ""the ATTACK stat!"" para ""A burn remains"" line ""after battles."" para ""Use BURN HEAL to"" line ""cure a burn!"" prompt _ViridianBlackboardFrozenText:: text ""If frozen, a"" line ""#MON becomes"" cont ""totally immobile!"" para ""#MON will stay"" line ""frozen even after"" cont ""battles."" para ""Use ICE HEAL to"" line ""thaw out #MON!"" prompt _VermilionGymTrashText:: text ""Nope, there's"" line ""only trash here."" done _VermilionGymTrashSuccessText1:: text ""Hey! There's a"" line ""switch under the"" cont ""trash!"" cont ""Turn it on!"" para ""The 1st electric"" line ""lock opened!@@"" _VermilionGymTrashSuccessText2:: text ""Hey! There's"" line ""another switch"" cont ""under the trash!"" cont ""Turn it on!"" prompt _VermilionGymTrashSuccessText3:: text ""The 2nd electric"" line ""lock opened!"" para ""The motorized door"" line ""opened!@@"" _VermilionGymTrashFailText:: text ""Nope! There's"" line ""only trash here."" cont ""Hey! The electric"" cont ""locks were reset!@@"" _FoundHiddenItemText:: text "" found"" line ""@"" TX_RAM wcd6d text ""!@@"" _HiddenItemBagFullText:: text ""But, has"" line ""no more room for"" cont ""other items!"" done _FoundHiddenCoinsText:: text "" found"" line ""@"" TX_BCD hCoins, 2 | LEADING_ZEROES | LEFT_ALIGN text "" coins!@@"" _FoundHiddenCoins2Text:: text "" found"" line ""@"" TX_BCD hCoins, 2 | LEADING_ZEROES | LEFT_ALIGN text "" coins!@@"" _DroppedHiddenCoinsText:: text """" para ""Oops! Dropped"" line ""some coins!"" done _IndigoPlateauStatuesText1:: text ""INDIGO PLATEAU"" prompt _IndigoPlateauStatuesText2:: text ""The ultimate goal"" line ""of trainers!"" cont ""#MON LEAGUE HQ"" done _IndigoPlateauStatuesText3:: text ""The highest"" line ""#MON authority"" cont ""#MON LEAGUE HQ"" done _PokemonBooksText:: text ""Crammed full of"" line ""#MON books!"" done _DiglettSculptureText:: text ""It's a sculpture"" line ""of DIGLETT."" done _ElevatorText:: text ""This is an"" line ""elevator."" done _TownMapText:: text ""A TOWN MAP.@@"" _PokemonStuffText:: text ""Wow! Tons of"" line ""#MON stuff!"" done _OutOfSafariBallsText:: text ""PA: Ding-dong!"" para ""You are out of"" line ""SAFARI BALLs!"" prompt _WildRanText:: text ""Wild @"" TX_RAM wEnemyMonNick text """" line ""ran!"" prompt _EnemyRanText:: text ""Enemy @"" TX_RAM wEnemyMonNick text """" line ""ran!"" prompt _HurtByPoisonText:: text ""'s"" line ""hurt by poison!"" prompt _HurtByBurnText:: text ""'s"" line ""hurt by the burn!"" prompt _HurtByLeechSeedText:: text ""LEECH SEED saps"" line ""!"" prompt _EnemyMonFaintedText:: text ""Enemy @"" TX_RAM wEnemyMonNick text """" line ""fainted!"" prompt _MoneyForWinningText:: text "" got ¥@"" TX_BCD wAmountMoneyWon, 3 | LEADING_ZEROES | LEFT_ALIGN text """" line ""for winning!"" prompt _TrainerDefeatedText:: text "" defeated"" line ""@"" TX_RAM wTrainerName text ""!"" prompt _PlayerMonFaintedText:: TX_RAM wBattleMonNick text """" line ""fainted!"" prompt _UseNextMonText:: text ""Use next #MON?"" done _Rival1WinText:: text "": Yeah! Am"" line ""I great or what?"" prompt _PlayerBlackedOutText2:: text "" is out of"" line ""useable #MON!"" para "" blacked"" line ""out!"" prompt _LinkBattleLostText:: text "" lost to"" line ""@"" TX_RAM wTrainerName text ""!"" prompt _TrainerAboutToUseText:: TX_RAM wTrainerName text "" is"" line ""about to use"" cont""@"" TX_RAM wEnemyMonNick text ""!"" para ""Will "" line ""change #MON?"" done _TrainerSentOutText:: TX_RAM wTrainerName text "" sent"" line ""out @"" TX_RAM wEnemyMonNick text ""!"" done _NoWillText:: text ""There's no will"" line ""to fight!"" prompt _CantEscapeText:: text ""Can't escape!"" prompt _NoRunningText:: text ""No! There's no"" line ""running from a"" cont ""trainer battle!"" prompt _GotAwayText:: text ""Got away safely!"" prompt _ItemsCantBeUsedHereText:: text ""Items can't be"" line ""used here."" prompt _AlreadyOutText:: TX_RAM wBattleMonNick text "" is"" line ""already out!"" prompt _MoveNoPPText:: text ""No PP left for"" line ""this move!"" prompt _MoveDisabledText:: text ""The move is"" line ""disabled!"" prompt _NoMovesLeftText:: TX_RAM wBattleMonNick text "" has no"" line ""moves left!"" done _MultiHitText:: text ""Hit the enemy"" line ""@"" TX_NUM wPlayerNumHits,1,1 text "" times!"" prompt _ScaredText:: TX_RAM wBattleMonNick text "" is too"" line ""scared to move!"" prompt _GetOutText:: text ""GHOST: Get out..."" line ""Get out..."" prompt _FastAsleepText:: text """" line ""is fast asleep!"" prompt _WokeUpText:: text """" line ""woke up!"" prompt _IsFrozenText:: text """" line ""is frozen solid!"" prompt _FullyParalyzedText:: text ""'s"" line ""fully paralyzed!"" prompt _FlinchedText:: text """" line ""flinched!"" prompt _MustRechargeText:: text """" line ""must recharge!"" prompt _DisabledNoMoreText:: text ""'s"" line ""disabled no more!"" prompt _IsConfusedText:: text """" line ""is confused!"" prompt _HurtItselfText:: text ""It hurt itself in"" line ""its confusion!"" prompt _ConfusedNoMoreText:: text ""'s"" line ""confused no more!"" prompt _SavingEnergyText:: text """" line ""is saving energy!"" prompt _UnleashedEnergyText:: text """" line ""unleashed energy!"" prompt _ThrashingAboutText:: text ""'s"" line ""thrashing about!"" done _AttackContinuesText:: text ""'s"" line ""attack continues!"" done _CantMoveText:: text """" line ""can't move!"" prompt _MoveIsDisabledText:: text ""'s"" line ""@"" TX_RAM wcd6d text "" is"" cont ""disabled!"" prompt _MonName1Text:: text ""@@"" _Used1Text:: text """" line ""used @@"" _Used2Text:: text """" line ""used @@"" _InsteadText:: text ""instead,"" cont ""@@"" _CF4BText:: TX_RAM wcf4b text ""@"" _ExclamationPoint1Text:: text ""!"" done _ExclamationPoint2Text:: text ""!"" done _ExclamationPoint3Text:: text ""!"" done _ExclamationPoint4Text:: text ""!"" done _ExclamationPoint5Text:: text ""!"" done _AttackMissedText:: text ""'s"" line ""attack missed!"" prompt _KeptGoingAndCrashedText:: text """" line ""kept going and"" cont ""crashed!"" prompt _UnaffectedText:: text ""'s"" line ""unaffected!"" prompt _DoesntAffectMonText:: text ""It doesn't affect"" line ""!"" prompt _CriticalHitText:: text ""Critical hit!"" prompt _OHKOText:: text ""One-hit KO!"" prompt _LoafingAroundText:: TX_RAM wBattleMonNick text "" is"" line ""loafing around."" prompt _BeganToNapText:: TX_RAM wBattleMonNick text "" began"" line ""to nap!"" prompt _WontObeyText:: TX_RAM wBattleMonNick text "" won't"" line ""obey!"" prompt _TurnedAwayText:: TX_RAM wBattleMonNick text "" turned"" line ""away!"" prompt _IgnoredOrdersText:: TX_RAM wBattleMonNick text """" line ""ignored orders!"" prompt _SubstituteTookDamageText:: text ""The SUBSTITUTE"" line ""took damage for"" cont ""!"" prompt _SubstituteBrokeText:: text ""'s"" line ""SUBSTITUTE broke!"" prompt _BuildingRageText:: text ""'s"" line ""RAGE is building!"" prompt _MirrorMoveFailedText:: text ""The MIRROR MOVE"" next ""failed!"" prompt _HitXTimesText:: text ""Hit @"" TX_NUM wEnemyNumHits, 1, 1 text "" times!"" prompt _GainedText:: TX_RAM wcd6d text "" gained"" line ""@@"" _WithExpAllText:: text ""with EXP.ALL,"" cont ""@@"" _BoostedText:: text ""a boosted"" cont ""@@"" _ExpPointsText:: TX_NUM wExpAmountGained, 2, 4 text "" EXP. Points!"" prompt _GrewLevelText:: TX_RAM wcd6d text "" grew"" line ""to level @"" TX_NUM wCurEnemyLVL, 1, 3 text ""!@@"" _WildMonAppearedText:: text ""Wild @"" TX_RAM wEnemyMonNick text """" line ""appeared!"" prompt _HookedMonAttackedText:: text ""The hooked"" line ""@"" TX_RAM wEnemyMonNick text """" cont ""attacked!"" prompt _EnemyAppearedText:: TX_RAM wEnemyMonNick text """" line ""appeared!"" prompt _TrainerWantsToFightText:: TX_RAM wTrainerName text "" wants"" line ""to fight!"" prompt _UnveiledGhostText:: text ""SILPH SCOPE"" line ""unveiled the"" cont ""GHOST's identity!"" prompt _GhostCantBeIDdText:: text ""Darn! The GHOST"" line ""can't be ID'd!"" prompt _GoText:: text ""Go! @@"" _DoItText:: text ""Do it! @@"" _GetmText:: text ""Get'm! @@"" _EnemysWeakText:: text ""The enemy's weak!"" line ""Get'm! @@"" _PlayerMon1Text:: TX_RAM wBattleMonNick text ""!"" done _PlayerMon2Text:: TX_RAM wBattleMonNick text "" @@"" _EnoughText:: text ""enough!@@"" _OKExclamationText:: text ""OK!@@"" _GoodText:: text ""good!@@"" _ComeBackText:: text """" line ""Come back!"" done _SuperEffectiveText:: text ""It's super"" line ""effective!"" prompt _NotVeryEffectiveText:: text ""It's not very"" line ""effective..."" prompt _SafariZoneEatingText:: text ""Wild @"" TX_RAM wEnemyMonNick db $0 line ""is eating!"" prompt _SafariZoneAngryText:: text ""Wild @"" TX_RAM wEnemyMonNick db $0 line ""is angry!"" prompt ; money related _PickUpPayDayMoneyText:: text "" picked up"" line ""¥@"" TX_BCD wTotalPayDayMoney, 3 | LEADING_ZEROES | LEFT_ALIGN text ""!"" prompt _ClearSaveDataText:: text ""Clear all saved"" line ""data?"" done _WhichFloorText:: text ""Which floor do"" line ""you want? "" done _PartyMenuNormalText:: text ""Choose a #MON."" done _PartyMenuItemUseText:: text ""Use item on which"" line ""#MON?"" done _PartyMenuBattleText:: text ""Bring out which"" line ""#MON?"" done _PartyMenuUseTMText:: text ""Use TM on which"" line ""#MON?"" done _PartyMenuSwapMonText:: text ""Move #MON"" line ""where?"" done _PotionText:: TX_RAM wcd6d text """" line ""recovered by @"" TX_NUM wHPBarHPDifference, 2, 3 text ""!"" done _AntidoteText:: TX_RAM wcd6d text "" was"" line ""cured of poison!"" done _ParlyzHealText:: TX_RAM wcd6d text ""'s"" line ""rid of paralysis!"" done _BurnHealText:: TX_RAM wcd6d text ""'s"" line ""burn was healed!"" done _IceHealText:: TX_RAM wcd6d text "" was"" line ""defrosted!"" done _AwakeningText:: TX_RAM wcd6d text """" line ""woke up!"" done _FullHealText:: TX_RAM wcd6d text ""'s"" line ""health returned!"" done _ReviveText:: TX_RAM wcd6d text """" line ""is revitalized!"" done _RareCandyText:: TX_RAM wcd6d text "" grew"" line ""to level @"" TX_NUM wCurEnemyLVL, 1, 3 text ""!@@"" _TurnedOnPC1Text:: text "" turned on"" line ""the PC."" prompt _AccessedBillsPCText:: text ""Accessed BILL's"" line ""PC."" para ""Accessed #MON"" line ""Storage System."" prompt _AccessedSomeonesPCText:: text ""Accessed someone's"" line ""PC."" para ""Accessed #MON"" line ""Storage System."" prompt _AccessedMyPCText:: text ""Accessed my PC."" para ""Accessed Item"" line ""Storage System."" prompt _TurnedOnPC2Text:: text "" turned on"" line ""the PC."" prompt _WhatDoYouWantText:: text ""What do you want"" line ""to do?"" done _WhatToDepositText:: text ""What do you want"" line ""to deposit?"" done _DepositHowManyText:: text ""How many?"" done _ItemWasStoredText:: TX_RAM wcd6d text "" was"" line ""stored via PC."" prompt _NothingToDepositText:: text ""You have nothing"" line ""to deposit."" prompt _NoRoomToStoreText:: text ""No room left to"" line ""store items."" prompt _WhatToWithdrawText:: text ""What do you want"" line ""to withdraw?"" done _WithdrawHowManyText:: text ""How many?"" done _WithdrewItemText:: text ""Withdrew"" line ""@"" TX_RAM wcd6d text ""."" prompt _NothingStoredText:: text ""There is nothing"" line ""stored."" prompt _CantCarryMoreText:: text ""You can't carry"" line ""any more items."" prompt _WhatToTossText:: text ""What do you want"" line ""to toss away?"" done _TossHowManyText:: text ""How many?"" done _AccessedHoFPCText:: text ""Accessed #MON"" line ""LEAGUE's site."" para ""Accessed the HALL"" line ""OF FAME List."" prompt _SwitchOnText:: text ""Switch on!"" prompt _WhatText:: text ""What?"" done _DepositWhichMonText:: text ""Deposit which"" line ""#MON?"" done _MonWasStoredText:: TX_RAM wcf4b text "" was"" line ""stored in Box @"" TX_RAM wBoxNumString text ""."" prompt _CantDepositLastMonText:: text ""You can't deposit"" line ""the last #MON!"" prompt _BoxFullText:: text ""Oops! This Box is"" line ""full of #MON."" prompt _MonIsTakenOutText:: TX_RAM wcf4b text "" is"" line ""taken out."" cont ""Got @"" TX_RAM wcf4b text ""."" prompt _NoMonText:: text ""What? There are"" line ""no #MON here!"" prompt _CantTakeMonText:: text ""You can't take"" line ""any more #MON."" para ""Deposit #MON"" line ""first."" prompt _ReleaseWhichMonText:: text ""Release which"" line ""#MON?"" done _OnceReleasedText:: text ""Once released,"" line ""@"" TX_RAM wcf4b text "" is"" cont ""gone forever. OK?"" done _MonWasReleasedText:: TX_RAM wcf4b text "" was"" line ""released outside."" cont ""Bye @"" _CF4BExclamationText:: TX_RAM wcf4b text ""!"" prompt _RequireCoinCaseText:: text ""A COIN CASE is"" line ""required!@@"" _ExchangeCoinsForPrizesText:: text ""We exchange your"" line ""coins for prizes."" prompt _WhichPrizeText:: text ""Which prize do"" line ""you want?"" done _HereYouGoText:: text ""Here you go!@@"" _SoYouWantPrizeText:: text ""So, you want"" line ""@"" TX_RAM wcd6d text ""?"" done _SorryNeedMoreCoinsText:: text ""Sorry, you need"" line ""more coins.@@"" _OopsYouDontHaveEnoughRoomText:: text ""Oops! You don't"" line ""have enough room.@@"" _OhFineThenText:: text ""Oh, fine then.@@"" _GetDexRatedText:: text ""Want to get your"" line ""#DEX rated?"" done _ClosedOaksPCText:: text ""Closed link to"" line ""PROF.OAK's PC.@@"" _AccessedOaksPCText:: text ""Accessed PROF."" line ""OAK's PC."" para ""Accessed #DEX"" line ""Rating System."" prompt _WhereWouldYouLikeText:: text ""Where would you"" line ""like to go?"" done _PleaseWaitText:: text ""OK, please wait"" line ""just a moment."" done _LinkCanceledText:: text ""The link was"" line ""canceled."" done INCLUDE ""text/oakspeech.asm"" _DoYouWantToNicknameText:: text ""Do you want to"" line ""give a nickname"" cont ""to @"" TX_RAM wcd6d text ""?"" done _YourNameIsText:: text ""Right! So your"" line ""name is !"" prompt _HisNameIsText:: text ""That's right! I"" line ""remember now! His"" cont ""name is !"" prompt _WillBeTradedText:: TX_RAM wNameOfPlayerMonToBeTraded text "" and"" line ""@"" TX_RAM wcd6d text "" will"" cont ""be traded."" done _Char00Text:: TX_NUM hSpriteIndexOrTextID,1,2 text "" ERROR."" done _Char55Text:: text $4B,""@@"" INCLUDE ""text/maps/digletts_cave_route_2_entrance.asm"" INCLUDE ""text/maps/viridian_forest_exit.asm"" INCLUDE ""text/maps/route_2_house.asm"" INCLUDE ""text/maps/route_2_gate.asm"" INCLUDE ""text/maps/viridian_forest_entrance.asm"" INCLUDE ""text/maps/mt_moon_pokecenter.asm"" INCLUDE ""text/maps/saffron_gates.asm"" INCLUDE ""text/maps/daycare_1.asm"" SECTION ""Text 4"", ROMX, BANK[TEXT_4] INCLUDE ""text/maps/daycare_2.asm"" INCLUDE ""text/maps/underground_path_route_6_entrance.asm"" INCLUDE ""text/maps/underground_path_route_7_entrance.asm"" INCLUDE ""text/maps/underground_path_route_7_entrance_unused.asm"" INCLUDE ""text/maps/underground_path_route_8_entrance.asm"" INCLUDE ""text/maps/rock_tunnel_pokecenter.asm"" INCLUDE ""text/maps/rock_tunnel_b1f.asm"" INCLUDE ""text/maps/power_plant.asm"" INCLUDE ""text/maps/route_11_gate.asm"" INCLUDE ""text/maps/route_11_gate_upstairs.asm"" INCLUDE ""text/maps/digletts_cave_route_11_entrance.asm"" INCLUDE ""text/maps/route_12_gate.asm"" INCLUDE ""text/maps/route_12_gate_upstairs.asm"" INCLUDE ""text/maps/route_12_house.asm"" INCLUDE ""text/maps/route_15_gate.asm"" INCLUDE ""text/maps/route_15_gate_upstairs.asm"" INCLUDE ""text/maps/route_16_gate.asm"" INCLUDE ""text/maps/route_16_gate_upstairs.asm"" INCLUDE ""text/maps/route_16_house.asm"" INCLUDE ""text/maps/route_18_gate.asm"" INCLUDE ""text/maps/route_18_gate_upstairs.asm"" INCLUDE ""text/maps/pokemon_league_gate.asm"" INCLUDE ""text/maps/victory_road_2f.asm"" INCLUDE ""text/maps/bills_house.asm"" INCLUDE ""text/maps/route_1.asm"" INCLUDE ""text/maps/route_2.asm"" INCLUDE ""text/maps/route_3.asm"" INCLUDE ""text/maps/route_4.asm"" INCLUDE ""text/maps/route_5.asm"" INCLUDE ""text/maps/route_6.asm"" INCLUDE ""text/maps/route_7.asm"" INCLUDE ""text/maps/route_8.asm"" INCLUDE ""text/maps/route_9.asm"" INCLUDE ""text/maps/route_10.asm"" INCLUDE ""text/maps/route_11_1.asm"" SECTION ""Text 5"", ROMX, BANK[TEXT_5] INCLUDE ""text/maps/route_11_2.asm"" INCLUDE ""text/maps/route_12.asm"" INCLUDE ""text/maps/route_13.asm"" INCLUDE ""text/maps/route_14.asm"" INCLUDE ""text/maps/route_15.asm"" INCLUDE ""text/maps/route_16.asm"" INCLUDE ""text/maps/route_17.asm"" INCLUDE ""text/maps/route_18.asm"" INCLUDE ""text/maps/route_19.asm"" INCLUDE ""text/maps/route_20.asm"" INCLUDE ""text/maps/route_21.asm"" INCLUDE ""text/maps/route_22.asm"" INCLUDE ""text/maps/route_23.asm"" INCLUDE ""text/maps/route_24_1.asm"" SECTION ""Text 6"", ROMX, BANK[TEXT_6] INCLUDE ""text/maps/route_24_2.asm"" INCLUDE ""text/maps/route_25.asm"" _FileDataDestroyedText:: text ""The file data is"" line ""destroyed!"" prompt _WouldYouLikeToSaveText:: text ""Would you like to"" line ""SAVE the game?"" done _GameSavedText:: text "" saved"" line ""the game!"" done _OlderFileWillBeErasedText:: text ""The older file"" line ""will be erased to"" cont ""save. Okay?"" done _WhenYouChangeBoxText:: text ""When you change a"" line ""#MON BOX, data"" cont ""will be saved."" para ""Is that okay?"" done _ChooseABoxText:: text ""Choose a"" line "" BOX.@@"" _EvolvedText:: TX_RAM wcf4b text "" evolved"" done _IntoText:: text """" line ""into @"" TX_RAM wcd6d text ""!"" done _StoppedEvolvingText:: text ""Huh? @"" TX_RAM wcf4b text """" line ""stopped evolving!"" prompt _IsEvolvingText:: text ""What? @"" TX_RAM wcf4b text """" line ""is evolving!"" done _FellAsleepText:: text """" line ""fell asleep!"" prompt _AlreadyAsleepText:: text ""'s"" line ""already asleep!"" prompt _PoisonedText:: text """" line ""was poisoned!"" prompt _BadlyPoisonedText:: text ""'s"" line ""badly poisoned!"" prompt _BurnedText:: text """" line ""was burned!"" prompt _FrozenText:: text """" line ""was frozen solid!"" prompt _FireDefrostedText:: text """" line ""was defrosted!"" prompt _MonsStatsRoseText:: text ""'s"" line ""@"" TX_RAM wcf4b text ""@@"" _GreatlyRoseText:: text $4c, ""greatly@@"" _RoseText:: text "" rose!"" prompt _MonsStatsFellText:: text ""'s"" line ""@"" TX_RAM wcf4b text ""@@"" _GreatlyFellText:: text $4c, ""greatly@@"" _FellText:: text "" fell!"" prompt _RanFromBattleText:: text """" line ""ran from battle!"" prompt _RanAwayScaredText:: text """" line ""ran away scared!"" prompt _WasBlownAwayText:: text """" line ""was blown away!"" prompt _ChargeMoveEffectText:: text ""@@"" _MadeWhirlwindText:: text """" line ""made a whirlwind!"" prompt _TookInSunlightText:: text """" line ""took in sunlight!"" prompt _LoweredItsHeadText:: text """" line ""lowered its head!"" prompt _SkyAttackGlowingText:: text """" line ""is glowing!"" prompt _FutureSightText:: text """" line ""foresaw an attack!"" prompt _FlewUpHighText:: text """" line ""flew up high!"" prompt _DugAHoleText:: text """" line ""dug a hole!"" prompt _BecameConfusedText:: text """" line ""became confused!"" prompt _MimicLearnedMoveText:: text """" line ""learned"" cont ""@"" TX_RAM wcd6d text ""!"" prompt _MoveWasDisabledText:: text ""'s"" line ""@"" TX_RAM wcd6d text "" was"" cont ""disabled!"" prompt _NothingHappenedText:: text ""Nothing happened!"" prompt _NoEffectText:: text ""No effect!"" prompt _ButItFailedText:: text ""But, it failed! "" prompt _DidntAffectText:: text ""It didn't affect"" line ""!"" prompt _IsUnaffectedText:: text """" line ""is unaffected!"" prompt _ParalyzedMayNotAttackText:: text ""'s"" line ""paralyzed! It may"" cont ""not attack!"" prompt _SubstituteText:: text ""It created a"" line ""SUBSTITUTE!"" prompt _HasSubstituteText:: text """" line ""has a SUBSTITUTE!"" prompt _TooWeakSubstituteText:: text ""Too weak to make"" line ""a SUBSTITUTE!"" prompt _CoinsScatteredText:: text ""Coins scattered"" line ""everywhere!"" prompt _GettingPumpedText:: text $5a, ""'s"" line ""getting pumped!"" prompt _WasSeededText:: text """" line ""was seeded!"" prompt _EvadedAttackText:: text """" line ""evaded attack!"" prompt _AlreadySeededText:: text ""'s"" line ""already seeded!"" prompt _HitWithRecoilText:: text ""'s"" line ""hit with recoil!"" prompt _ConvertedTypeText:: text ""Converted type to"" line ""'s!"" prompt _StatusChangesEliminatedText:: text ""All STATUS changes"" line ""are eliminated!"" prompt _StartedSleepingEffect:: text """" line ""started sleeping!"" done _FellAsleepBecameHealthyText:: text """" line ""fell asleep and"" cont ""became healthy!"" done _RegainedHealthText:: text """" line ""regained health!"" prompt _TransformedText:: text """" line ""transformed into"" cont ""@"" TX_RAM wcd6d text ""!"" prompt _LightScreenProtectedText:: text ""'s"" line ""protected against"" cont ""special attacks!"" prompt _ReflectGainedArmorText:: text ""'s"" line ""protected against"" cont ""physical attacks!"" prompt _ShroudedInMistText:: text ""'s"" line ""shrouded in mist!"" prompt _SuckedHealthText:: text ""Sucked health from"" line ""!"" prompt _DreamWasEatenText:: text ""'s"" line ""dream was eaten!"" prompt _TradeCenterText1:: text ""!"" done _ColosseumText1:: text ""!"" done INCLUDE ""text/maps/reds_house_1f.asm"" INCLUDE ""text/maps/blues_house.asm"" INCLUDE ""text/maps/oaks_lab.asm"" INCLUDE ""text/maps/viridian_pokecenter.asm"" INCLUDE ""text/maps/viridian_mart.asm"" INCLUDE ""text/maps/school.asm"" INCLUDE ""text/maps/viridian_house.asm"" INCLUDE ""text/maps/viridian_gym.asm"" INCLUDE ""text/maps/museum_1f.asm"" INCLUDE ""text/maps/museum_2f.asm"" INCLUDE ""text/maps/pewter_gym_1.asm"" SECTION ""Text 7"", ROMX, BANK[TEXT_7] INCLUDE ""text/maps/pewter_gym_2.asm"" INCLUDE ""text/maps/pewter_house_1.asm"" INCLUDE ""text/maps/pewter_mart.asm"" INCLUDE ""text/maps/pewter_house_2.asm"" INCLUDE ""text/maps/pewter_pokecenter.asm"" INCLUDE ""text/maps/cerulean_trashed_house.asm"" INCLUDE ""text/maps/cerulean_trade_house.asm"" INCLUDE ""text/maps/cerulean_pokecenter.asm"" INCLUDE ""text/maps/cerulean_gym.asm"" INCLUDE ""text/maps/bike_shop.asm"" INCLUDE ""text/maps/cerulean_mart.asm"" INCLUDE ""text/maps/cerulean_badge_house.asm"" INCLUDE ""text/maps/lavender_pokecenter.asm"" INCLUDE ""text/maps/pokemon_tower_1f.asm"" INCLUDE ""text/maps/pokemon_tower_2f.asm"" INCLUDE ""text/maps/pokemon_tower_3f.asm"" INCLUDE ""text/maps/pokemon_tower_4f.asm"" INCLUDE ""text/maps/pokemon_tower_5f.asm"" INCLUDE ""text/maps/pokemon_tower_6f.asm"" INCLUDE ""text/maps/pokemon_tower_7f.asm"" INCLUDE ""text/maps/fujis_house.asm"" INCLUDE ""text/maps/lavender_mart.asm"" INCLUDE ""text/maps/lavender_house.asm"" INCLUDE ""text/maps/name_rater.asm"" INCLUDE ""text/maps/vermilion_pokecenter.asm"" INCLUDE ""text/maps/fan_club.asm"" INCLUDE ""text/maps/vermilion_mart.asm"" INCLUDE ""text/maps/vermilion_gym_1.asm"" SECTION ""Text 8"", ROMX, BANK[TEXT_8] INCLUDE ""text/maps/vermilion_gym_2.asm"" INCLUDE ""text/maps/vermilion_house.asm"" INCLUDE ""text/maps/vermilion_dock.asm"" INCLUDE ""text/maps/vermilion_fishing_house.asm"" INCLUDE ""text/maps/celadon_dept_store_1f.asm"" INCLUDE ""text/maps/celadon_dept_store_2f.asm"" INCLUDE ""text/maps/celadon_dept_store_3f.asm"" INCLUDE ""text/maps/celadon_dept_store_4f.asm"" INCLUDE ""text/maps/celadon_dept_store_roof.asm"" INCLUDE ""text/maps/celadon_mansion_1f.asm"" INCLUDE ""text/maps/celadon_mansion_2f.asm"" INCLUDE ""text/maps/celadon_mansion_3f.asm"" INCLUDE ""text/maps/celadon_mansion_4f_outside.asm"" INCLUDE ""text/maps/celadon_mansion_4f_inside.asm"" INCLUDE ""text/maps/celadon_pokecenter.asm"" INCLUDE ""text/maps/celadon_gym.asm"" INCLUDE ""text/maps/celadon_game_corner.asm"" INCLUDE ""text/maps/celadon_dept_store_5f.asm"" INCLUDE ""text/maps/celadon_prize_room.asm"" INCLUDE ""text/maps/celadon_diner.asm"" INCLUDE ""text/maps/celadon_house.asm"" INCLUDE ""text/maps/celadon_hotel.asm"" INCLUDE ""text/maps/fuchsia_mart.asm"" INCLUDE ""text/maps/fuchsia_house.asm"" INCLUDE ""text/maps/fuchsia_pokecenter.asm"" INCLUDE ""text/maps/wardens_house.asm"" INCLUDE ""text/maps/safari_zone_entrance.asm"" INCLUDE ""text/maps/fuchsia_gym_1.asm"" SECTION ""Text 9"", ROMX, BANK[TEXT_9] INCLUDE ""text/maps/fuchsia_gym_2.asm"" INCLUDE ""text/maps/fuchsia_meeting_room.asm"" INCLUDE ""text/maps/fuchsia_fishing_house.asm"" INCLUDE ""text/maps/mansion_1f.asm"" INCLUDE ""text/maps/cinnabar_gym.asm"" INCLUDE ""text/maps/cinnabar_lab.asm"" INCLUDE ""text/maps/cinnabar_lab_trade_room.asm"" INCLUDE ""text/maps/cinnabar_lab_metronome_room.asm"" INCLUDE ""text/maps/cinnabar_lab_fossil_room.asm"" INCLUDE ""text/maps/cinnabar_pokecenter.asm"" INCLUDE ""text/maps/cinnabar_mart.asm"" INCLUDE ""text/maps/indigo_plateau_lobby.asm"" INCLUDE ""text/maps/copycats_house_1f.asm"" INCLUDE ""text/maps/copycats_house_2f.asm"" INCLUDE ""text/maps/fighting_dojo.asm"" INCLUDE ""text/maps/saffron_gym.asm"" INCLUDE ""text/maps/saffron_house.asm"" INCLUDE ""text/maps/saffron_mart.asm"" INCLUDE ""text/maps/silph_co_1f.asm"" INCLUDE ""text/maps/saffron_pokecenter.asm"" INCLUDE ""text/maps/mr_psychics_house.asm"" _PokemartGreetingText:: text ""Welcome! How may"" next ""I help you?"" done _PokemonFaintedText:: TX_RAM wcd6d text """" line ""fainted!"" done _PlayerBlackedOutText:: text "" is out of"" line ""useable #MON!"" para "" blacked"" line ""out!"" prompt _RepelWoreOffText:: text ""REPEL's effect"" line ""wore off."" done _PokemartBuyingGreetingText:: text ""Take your time."" done _PokemartTellBuyPriceText:: TX_RAM wcf4b text ""?"" line ""That will be"" cont ""¥@"" TX_BCD hMoney, 3 | LEADING_ZEROES | LEFT_ALIGN text "". OK?"" done _PokemartBoughtItemText:: text ""Here you are!"" line ""Thank you!"" prompt _PokemartNotEnoughMoneyText:: text ""You don't have"" line ""enough money."" prompt _PokemartItemBagFullText:: text ""You can't carry"" line ""any more items."" prompt _PokemonSellingGreetingText:: text ""What would you"" line ""like to sell?"" done _PokemartTellSellPriceText:: text ""I can pay you"" line ""¥@"" TX_BCD hMoney, 3 | LEADING_ZEROES | LEFT_ALIGN text "" for that."" done _PokemartItemBagEmptyText:: text ""You don't have"" line ""anything to sell."" prompt _PokemartUnsellableItemText:: text ""I can't put a"" line ""price on that."" prompt _PokemartThankYouText:: text ""Thank you!"" done _PokemartAnythingElseText:: text ""Is there anything"" line ""else I can do?"" done _LearnedMove1Text:: TX_RAM wLearnMoveMonName text "" learned"" line ""@"" TX_RAM wcf4b text ""!@@"" _WhichMoveToForgetText:: text ""Which move should"" next ""be forgotten?"" done _AbandonLearningText:: text ""Abandon learning"" line ""@"" TX_RAM wcf4b text ""?"" done _DidNotLearnText:: TX_RAM wLearnMoveMonName text """" line ""did not learn"" cont ""@"" TX_RAM wcf4b text ""!"" prompt _TryingToLearnText:: TX_RAM wLearnMoveMonName text "" is"" line ""trying to learn"" cont ""@"" TX_RAM wcf4b text ""!"" para ""But, @"" TX_RAM wLearnMoveMonName text """" line ""can't learn more"" cont ""than 4 moves!"" para ""Delete an older"" line ""move to make room"" cont ""for @"" TX_RAM wcf4b text ""?"" done _OneTwoAndText:: text ""1, 2 and...@@"" _PoofText:: text "" Poof!@@"" _ForgotAndText:: text """" para ""@"" TX_RAM wLearnMoveMonName text "" forgot"" line ""@"" TX_RAM wcd6d text ""!"" para ""And..."" prompt _HMCantDeleteText:: text ""HM techniques"" line ""can't be deleted!"" prompt _PokemonCenterWelcomeText:: text ""Welcome to our"" line ""#MON CENTER!"" para ""We heal your"" line ""#MON back to"" cont ""perfect health!"" prompt _ShallWeHealYourPokemonText:: text ""Shall we heal your"" line ""#MON?"" done _NeedYourPokemonText:: text ""OK. We'll need"" line ""your #MON."" done _PokemonFightingFitText:: text ""Thank you!"" line ""Your #MON are"" cont ""fighting fit!"" prompt _PokemonCenterFarewellText:: text ""We hope to see"" line ""you again!"" done _CableClubNPCAreaReservedFor2FriendsLinkedByCableText:: text ""This area is"" line ""reserved for 2"" cont ""friends who are"" cont ""linked by cable."" done _CableClubNPCWelcomeText:: text ""Welcome to the"" line ""Cable Club!"" done _CableClubNPCPleaseApplyHereHaveToSaveText:: text ""Please apply here."" para ""Before opening"" line ""the link, we have"" cont ""to save the game."" done _CableClubNPCPleaseWaitText:: text ""Please wait.@@"" _CableClubNPCLinkClosedBecauseOfInactivityText:: text ""The link has been"" line ""closed because of"" cont ""inactivity."" para ""Please contact"" line ""your friend and"" cont ""come again!"" done SECTION ""Text 10"", ROMX, BANK[TEXT_10] _CableClubNPCPleaseComeAgainText:: text ""Please come again!"" done _CableClubNPCMakingPreparationsText:: text ""We're making"" line ""preparations."" cont ""Please wait."" done _UsedStrengthText:: TX_RAM wcd6d text "" used"" line ""STRENGTH.@@"" _CanMoveBouldersText:: TX_RAM wcd6d text "" can"" line ""move boulders."" prompt _CurrentTooFastText:: text ""The current is"" line ""much too fast!"" prompt _CyclingIsFunText:: text ""Cycling is fun!"" line ""Forget SURFing!"" prompt _FlashLightsAreaText:: text ""A blinding FLASH"" line ""lights the area!"" prompt _WarpToLastPokemonCenterText:: text ""Warp to the last"" line ""#MON CENTER."" done _CannotUseTeleportNowText:: TX_RAM wcd6d text "" can't"" line ""use TELEPORT now."" prompt _CannotFlyHereText:: TX_RAM wcd6d text "" can't"" line ""FLY here."" prompt _NotHealthyEnoughText:: text ""Not healthy"" line ""enough."" prompt _NewBadgeRequiredText:: text ""No! A new BADGE"" line ""is required."" prompt _CannotUseItemsHereText:: text ""You can't use items"" line ""here."" prompt _CannotGetOffHereText:: text ""You can't get off"" line ""here."" prompt _GotMonText:: text "" got"" line ""@"" TX_RAM wcd6d text ""!@@"" _SetToBoxText:: text ""There's no more"" line ""room for #MON!"" cont ""@"" TX_RAM wBoxMonNicks text "" was"" cont ""sent to #MON"" cont ""BOX @"" TX_RAM wcf4b text "" on PC!"" done _BoxIsFullText:: text ""There's no more"" line ""room for #MON!"" para ""The #MON BOX"" line ""is full and can't"" cont ""accept any more!"" para ""Change the BOX at"" line ""a #MON CENTER!"" done INCLUDE ""text/maps/pallet_town.asm"" INCLUDE ""text/maps/viridian_city.asm"" INCLUDE ""text/maps/pewter_city.asm"" INCLUDE ""text/maps/cerulean_city.asm"" INCLUDE ""text/maps/lavender_town.asm"" INCLUDE ""text/maps/vermilion_city.asm"" INCLUDE ""text/maps/celadon_city.asm"" INCLUDE ""text/maps/fuchsia_city.asm"" INCLUDE ""text/maps/cinnabar_island.asm"" INCLUDE ""text/maps/saffron_city.asm"" _ItemUseBallText00:: text ""It dodged the"" line ""thrown BALL!"" para ""This #MON"" line ""can't be caught!"" prompt _ItemUseBallText01:: text ""You missed the"" line ""#MON!"" prompt _ItemUseBallText02:: text ""Darn! The #MON"" line ""broke free!"" prompt _ItemUseBallText03:: text ""Aww! It appeared"" line ""to be caught! "" prompt _ItemUseBallText04:: text ""Shoot! It was so"" line ""close too!"" prompt _ItemUseBallText05:: text ""All right!"" line ""@"" TX_RAM wEnemyMonNick text "" was"" cont ""caught!@@"" _ItemUseBallText07:: TX_RAM wBoxMonNicks text "" was"" line ""transferred to"" cont ""BILL's PC!"" prompt _ItemUseBallText08:: TX_RAM wBoxMonNicks text "" was"" line ""transferred to"" cont ""someone's PC!"" prompt _ItemUseBallText06:: text ""New #DEX data"" line ""will be added for"" cont ""@"" TX_RAM wEnemyMonNick text ""!@@"" _SurfingGotOnText:: text "" got on"" line ""@"" TX_RAM wcd6d text ""!"" prompt _SurfingNoPlaceToGetOffText:: text ""There's no place"" line ""to get off!"" prompt _VitaminStatRoseText:: TX_RAM wcd6d text ""'s"" line ""@"" TX_RAM wcf4b text "" rose."" prompt _VitaminNoEffectText:: text ""It won't have any"" line ""effect."" prompt _ThrewBaitText:: text "" threw"" line ""some BAIT."" done _ThrewRockText:: text "" threw a"" line ""ROCK."" done _PlayedFluteNoEffectText:: text ""Played the #"" line ""FLUTE."" para ""Now, that's a"" line ""catchy tune!"" prompt _FluteWokeUpText:: text ""All sleeping"" line ""#MON woke up."" prompt _PlayedFluteHadEffectText:: text "" played the"" line ""# FLUTE.@@"" _CoinCaseNumCoinsText:: text ""Coins"" line ""@"" TX_BCD wPlayerCoins, 2 | LEADING_ZEROES | LEFT_ALIGN text "" "" prompt _ItemfinderFoundItemText:: text ""Yes! ITEMFINDER"" line ""indicates there's"" cont ""an item nearby."" prompt _ItemfinderFoundNothingText:: text ""Nope! ITEMFINDER"" line ""isn't responding."" prompt _RaisePPWhichTechniqueText:: text ""Raise PP of which"" line ""technique?"" done _RestorePPWhichTechniqueText:: text ""Restore PP of"" line ""which technique?"" done _PPMaxedOutText:: TX_RAM wcf4b text ""'s PP"" line ""is maxed out."" prompt _PPIncreasedText:: TX_RAM wcf4b text ""'s PP"" line ""increased."" prompt _PPRestoredText:: text ""PP was restored."" prompt _BootedUpTMText:: text ""Booted up a TM!"" prompt _BootedUpHMText:: text ""Booted up an HM!"" prompt _TeachMachineMoveText:: text ""It contained"" line ""@"" TX_RAM wcf4b text ""!"" para ""Teach @"" TX_RAM wcf4b text """" line ""to a #MON?"" done _MonCannotLearnMachineMoveText:: TX_RAM wcd6d text "" is not"" line ""compatible with"" cont ""@"" TX_RAM wcf4b text ""."" para ""It can't learn"" line ""@"" TX_RAM wcf4b text ""."" prompt _ItemUseNotTimeText:: text ""OAK: !"" line ""This isn't the"" cont ""time to use that! "" prompt _ItemUseNotYoursToUseText:: text ""This isn't yours"" line ""to use!"" prompt _ItemUseNoEffectText:: text ""It won't have any"" line ""effect."" prompt _ThrowBallAtTrainerMonText1:: text ""The trainer"" line ""blocked the BALL!"" prompt _ThrowBallAtTrainerMonText2:: text ""Don't be a thief!"" prompt _NoCyclingAllowedHereText:: text ""No cycling"" next ""allowed here."" prompt _NoSurfingHereText:: text ""No SURFing on"" line ""@"" TX_RAM wcd6d text "" here!"" prompt _BoxFullCannotThrowBallText:: text ""The #MON BOX"" line ""is full! Can't"" cont ""use that item!"" prompt SECTION ""Text 11"", ROMX, BANK[TEXT_11] _ItemUseText001:: text "" used@@"" _ItemUseText002:: TX_RAM wcf4b text ""!"" done _GotOnBicycleText1:: text "" got on the@@"" _GotOnBicycleText2:: TX_RAM wcf4b text ""!"" prompt _GotOffBicycleText1:: text "" got off@@"" _GotOffBicycleText2:: text ""the @"" TX_RAM wcf4b text ""."" prompt _ThrewAwayItemText:: text ""Threw away"" line ""@"" TX_RAM wcd6d text ""."" prompt _IsItOKToTossItemText:: text ""Is it OK to toss"" line ""@"" TX_RAM wcf4b text ""?"" prompt _TooImportantToTossText:: text ""That's too impor-"" line ""tant to toss!"" prompt _AlreadyKnowsText:: TX_RAM wcd6d text "" knows"" line ""@"" TX_RAM wcf4b text ""!"" prompt _ConnectCableText:: text ""Okay, connect the"" line ""cable like so!"" prompt _TradedForText:: text "" traded"" line ""@"" TX_RAM wInGameTradeGiveMonName text "" for"" cont ""@"" TX_RAM wInGameTradeReceiveMonName text ""!@@"" _WannaTrade1Text:: text ""I'm looking for"" line ""@"" TX_RAM wInGameTradeGiveMonName text ""! Wanna"" para ""trade one for"" line ""@"" TX_RAM wInGameTradeReceiveMonName text ""? "" done _NoTrade1Text:: text ""Awww!"" line ""Oh well..."" done _WrongMon1Text:: text ""What? That's not"" line ""@"" TX_RAM wInGameTradeGiveMonName text ""!"" para ""If you get one,"" line ""come back here!"" done _Thanks1Text:: text ""Hey thanks!"" done _AfterTrade1Text:: text ""Isn't my old"" line ""@"" TX_RAM wInGameTradeReceiveMonName text "" great?"" done _WannaTrade2Text:: text ""Hello there! Do"" line ""you want to trade"" para ""your @"" TX_RAM wInGameTradeGiveMonName text """" line ""for @"" TX_RAM wInGameTradeReceiveMonName text ""?"" done _NoTrade2Text:: text ""Well, if you"" line ""don't want to..."" done _WrongMon2Text:: text ""Hmmm? This isn't"" line ""@"" TX_RAM wInGameTradeGiveMonName text ""."" para ""Think of me when"" line ""you get one."" done _Thanks2Text:: text ""Thanks!"" done _AfterTrade2Text:: text ""The @"" TX_RAM wInGameTradeGiveMonName text "" you"" line ""traded to me"" para ""went and evolved!"" done _WannaTrade3Text:: text ""Hi! Do you have"" line ""@"" TX_RAM wInGameTradeGiveMonName text ""?"" para ""Want to trade it"" line ""for @"" TX_RAM wInGameTradeReceiveMonName text ""?"" done _NoTrade3Text:: text ""That's too bad."" done _WrongMon3Text:: text ""...This is no"" line ""@"" TX_RAM wInGameTradeGiveMonName text ""."" para ""If you get one,"" line ""trade it with me!"" done _Thanks3Text:: text ""Thanks pal!"" done _AfterTrade3Text:: text ""How is my old"" line ""@"" TX_RAM wInGameTradeReceiveMonName text ""?"" para ""My @"" TX_RAM wInGameTradeGiveMonName text "" is"" line ""doing great!"" done _NothingToCutText:: text ""There isn't"" line ""anything to CUT!"" prompt _UsedCutText:: TX_RAM wcd6d text "" hacked"" line ""away with CUT!"" prompt SECTION ""Pokedex Text"", ROMX, BANK[POKEDEX_TEXT] IF DEF(_BLUE) INCLUDE ""text/pokedex_blue.asm"" ELSE INCLUDE ""text/pokedex_redgreen.asm"" ENDC SECTION ""Move Names"", ROMX, BANK[MOVE_NAMES] INCLUDE ""text/move_names.asm"" INCLUDE ""text/item_descriptions.asm"" ",16170,True,3641.3162231596325,median "bits 32 %define WRK ebp ; // alias for unit workspace %define VAL esi ; // alias for unit values (transformed/untransformed) %define COM ebx ; // alias for instrument opcodes %include ""4klang.inc"" ;// conditional defines %ifdef GO4K_USE_VCO_SHAPE %define INCLUDE_WAVESHAPER %endif %ifdef GO4K_USE_DST %define INCLUDE_WAVESHAPER %endif %ifdef GO4K_USE_VCO_MOD_PM %define PHASE_RENORMALIZE %endif %ifdef GO4K_USE_VCO_PHASE_OFFSET %define PHASE_RENORMALIZE %endif %ifdef GO4K_USE_ENVELOPE_RECORDINGS %define GO4K_USE_BUFFER_RECORDINGS %endif %ifdef GO4K_USE_NOTE_RECORDINGS %define GO4K_USE_BUFFER_RECORDINGS %endif ; //======================================================================================== ; // .bss section ; //======================================================================================== %ifdef USE_SECTIONS section .g4kbss1 bss align=1 %else section .bss %endif ; // the one and only synth object %if MAX_VOICES > 1 go4k_voiceindex resd 16 %endif go4k_transformed_values resd 16 go4k_synth_wrk resb go4k_synth.size global _go4k_delay_buffer_ofs _go4k_delay_buffer_ofs resd 1 global _go4k_delay_buffer _go4k_delay_buffer resd 16*16*go4kDLL_wrk.size %ifdef AUTHORING global __4klang_current_tick __4klang_current_tick resd 0 %endif %ifdef GO4K_USE_ENVELOPE_RECORDINGS global __4klang_envelope_buffer __4klang_envelope_buffer resd ((MAX_SAMPLES)/8) ; // samples every 256 samples and stores 16*2 = 32 values %endif %ifdef GO4K_USE_NOTE_RECORDINGS global __4klang_note_buffer __4klang_note_buffer resd ((MAX_SAMPLES)/8) ; // samples every 256 samples and stores 16*2 = 32 values %endif ; //======================================================================================== ; // .g4kdat section (initialized data for go4k) ; //======================================================================================== %ifdef USE_SECTIONS section .g4kdat1 data align=1 %else section .data %endif ; // some synth constants go4k_synth_commands dd 0 dd _go4kENV_func@0 dd _go4kVCO_func@0 dd _go4kVCF_func@0 dd _go4kDST_func@0 dd _go4kDLL_func@0 dd _go4kFOP_func@0 dd _go4kFST_func@0 dd _go4kPAN_func@0 dd _go4kOUT_func@0 dd _go4kACC_func@0 dd _go4kFLD_func@0 %ifdef GO4K_USE_FSTG dd _go4kFSTG_func@0 %endif %ifdef USE_SECTIONS section .g4kdat2 data align=1 %else section .data %endif %ifdef GO4K_USE_16BIT_OUTPUT c_32767 dd 32767.0 %endif c_i128 dd 0.0078125 c_RandDiv dd 65536*32768 c_0_5 dd 0.5 %ifdef GO4K_USE_VCO_GATE c_16 dd 16.0 %endif %ifdef GO4K_USE_DLL_CHORUS DLL_DEPTH dd 1024.0 %endif %ifdef GO4K_USE_DLL_DC_FILTER c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) %else %ifdef GO4K_USE_VCO_GATE c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) %endif %endif global _RandSeed _RandSeed dd 1 c_24 dd 24 c_i12 dd 0x3DAAAAAA FREQ_NORMALIZE dd 0.000092696138 ; // 220.0/(2^(69/12)) / 44100.0 global _LFO_NORMALIZE _LFO_NORMALIZE dd DEF_LFO_NORMALIZE %ifdef GO4K_USE_GROOVE_PATTERN go4k_groove_pattern dw 0011100111001110b %endif ; //======================================================================================== ; // .crtemui section (emulates crt functions) ; //======================================================================================== %ifdef USE_SECTIONS section .crtemui code align=1 %else section .text %endif export_func FloatRandomNumber@0 push eax imul eax,dword [_RandSeed],16007 mov dword [_RandSeed], eax fild dword [_RandSeed] fidiv dword [c_RandDiv] pop eax ret ; //======================================================================================== ; // .g4kcod* sections (code for go4k) ; //======================================================================================== %ifdef INCLUDE_WAVESHAPER %ifdef USE_SECTIONS section .g4kcod2 code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Waveshaper function ; //---------------------------------------------------------------------------------------- ; // Input : st0 : shaping coeff ; // st1 : input ; // Output: st0 : result ; //---------------------------------------------------------------------------------------- go4kWaveshaper: %ifdef GO4K_USE_WAVESHAPER_CLIP fxch fld1 ; // 1 val fucomi st1 ; // 1 val jbe short go4kWaveshaper_clip fchs ; // -1 val fucomi st1 ; // -1 val fcmovb st0, st1 ; // val -1 (if val > -1) go4kWaveshaper_clip: fstp st1 ; // newval fxch %endif fsub dword [c_0_5] fadd st0 fst dword [esp-4] ; // amnt in fadd st0 ; // 2*amnt in fld1 ; // 1 2*amnt in fsub dword [esp-4] ; // 1-amnt 2*amnt in fdivp st1, st0 ; // k in fld st1 ; // sin k in fabs ; // a(in) k in fmul st1 ; // k*a(in) k in fld1 faddp st1, st0 ; // 1+k*a(in) k in fxch st1 ; // k 1+k*a(in) in fld1 faddp st1, st0 ; // 1+k 1+k*a(in) in fmulp st2 ; // 1+k*a(in) (1+k)*in fdivp st1, st0 ; // out ret %endif %ifdef USE_SECTIONS section .g4kcod3 code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // unit values preparation/transform ; //---------------------------------------------------------------------------------------- go4kTransformValues: push ecx xor ecx, ecx xor eax, eax mov edx, go4k_transformed_values go4kTransformValues_loop: lodsb push eax fild dword [esp] fmul dword [c_i128] fstp dword [edx+ecx*4] pop eax inc ecx cmp ecx, dword [esp+8] jl go4kTransformValues_loop pop ecx ret 4 %ifdef USE_SECTIONS section .g4kcod4 code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Envelope param mapping ; //---------------------------------------------------------------------------------------- go4kENVMap: fld dword [edx+eax*4] %ifdef GO4K_USE_ENV_MOD_ADR fadd dword [WRK+go4kENV_wrk.am+eax*4] %endif fimul dword [c_24] fchs ; //---------------------------------------------------------------------------------------- ; // Power function (2^x) ; //---------------------------------------------------------------------------------------- ; // Input : st0 : base ; // st1 : exponent ; // Output: st0 : result ; //---------------------------------------------------------------------------------------- export_func Power@0 ; // base exp fld1 fadd st0 fyl2x ; // log2_base fld1 ; // 1 log2_base fld st1 ; // log2_base 1 log2_base fprem ; // (frac)log2_base 1 log2_base f2xm1 ; // 2 ^ '' - 1 1 log2_base faddp st1, st0 ; // 2 ^ '' (int)log2_base fscale fstp st1 ret %ifdef USE_SECTIONS section .g4kcoda code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // ENV Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kENV_func@0 push 5 call go4kTransformValues %ifdef GO4K_USE_ENV_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kENV_func_do fldz ret %endif go4kENV_func_do: mov eax, dword [ecx-8] ; // is the instrument in release mode (note off)? test eax, eax je go4kENV_func_process mov dword [WRK+go4kENV_wrk.state], ENV_STATE_RELEASE go4kENV_func_process: mov eax, dword [WRK+go4kENV_wrk.state] fld dword [WRK+go4kENV_wrk.level] ; // val - ; // check for sustain state cmp al, ENV_STATE_SUSTAIN je short go4kENV_func_leave2 go4kENV_func_attac: cmp al, ENV_STATE_ATTAC jne short go4kENV_func_decay call go4kENVMap ; // newval faddp st1, st0 ; // check for end of attac fld1 ; // 1 newval fucomi st1 ; // 1 newval fcmovnb st0, st1 ; // newval 1 (if newval < 1) jbe short go4kENV_func_statechange go4kENV_func_decay: cmp al, ENV_STATE_DECAY jne short go4kENV_func_release call go4kENVMap ; // newval fsubp st1, st0 ; // check for end of decay fld dword [edx+go4kENV_val.sustain] ; // sustain newval fucomi st1 ; // sustain newval fcmovb st0, st1 ; // newval sustain (if newval > sustain) jnc short go4kENV_func_statechange go4kENV_func_release: ; // release state? cmp al, ENV_STATE_RELEASE jne short go4kENV_func_leave call go4kENVMap ; // newval fsubp st1, st0 ; // check for end of release fldz ; // 0 newval fucomi st1 ; // 0 newval fcmovb st0, st1 ; // newval 0 (if newval > 0) jc short go4kENV_func_leave go4kENV_func_statechange: ; // newval inc dword [WRK+go4kENV_wrk.state] go4kENV_func_leave: ; // newval bla fstp st1 ; // store new env value fst dword [WRK+go4kENV_wrk.level] go4kENV_func_leave2: ; // mul by gain %ifdef GO4K_USE_ENV_MOD_GM fld dword [edx+go4kENV_val.gain] fadd dword [WRK+go4kENV_wrk.gm] fmulp st1, st0 %else fmul dword [edx+go4kENV_val.gain] %endif ret ; //---------------------------------------------------------------------------------------- ; // VCO Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- %ifdef USE_SECTIONS section .g4kcodp code align=1 %else section .text %endif go4kVCO_pulse: fucomi st1 ; // c p fld1 jnc short go4kVCO_func_pulse_up ; // +1 c p fchs ; // -1 c p go4kVCO_func_pulse_up: fstp st1 ; // +-1 p fstp st1 ; // +-1 ret %ifdef USE_SECTIONS section .g4kcodt code align=1 %else section .text %endif go4kVCO_trisaw: fucomi st1 ; // c p jnc short go4kVCO_func_trisaw_up fld1 ; // 1 c p fsubr st2, st0 ; // 1 c 1-p fsubrp st1, st0 ; // 1-c 1-p go4kVCO_func_trisaw_up: fdivp st1, st0 ; // tp'/tc fadd st0 ; // 2*'' fld1 ; // 1 2*'' fsubp st1, st0 ; // 2*''-1 ret %ifdef USE_SECTIONS section .g4kcods code align=1 %else section .text %endif go4kVCO_sine: fucomi st1 ; // c p jnc short go4kVCO_func_sine_do fstp st1 fsub st0, st0 ; // 0 ret go4kVCO_func_sine_do fdivp st1, st0 ; // p/c fldpi ; // pi p fadd st0 ; // 2*pi p fmulp st1, st0 ; // 2*pi*p fsin ; // sin(2*pi*p) ret %ifdef GO4K_USE_VCO_GATE %ifdef USE_SECTIONS section .g4kcodq code align=1 %else section .text %endif go4kVCO_gate: fxch ; // p c fstp st1 ; // p fmul dword [c_16] ; // p' push eax push eax fistp dword [esp] ; // - fld1 ; // 1 pop eax and al, 0xf bt word [VAL-5],ax jc go4kVCO_gate_bit fsub st0, st0 ; // 0 go4kVCO_gate_bit: fld dword [WRK+go4kVCO_wrk.cm] ; // f x fsub st1 ; // f-x x fmul dword [c_dc_const] ; // c(f-x) x faddp st1, st0 ; // x' fst dword [WRK+go4kVCO_wrk.cm] pop eax ret %endif %ifdef USE_SECTIONS section .g4kcodb code align=1 %else section .text %endif export_func go4kVCO_func@0 %ifdef GO4K_USE_VCO_PHASE_OFFSET %ifdef GO4K_USE_VCO_SHAPE %ifdef GO4K_USE_VCO_GATE push 8 %else push 7 %endif %else %ifdef GO4K_USE_VCO_GATE push 7 %else push 6 %endif %endif %else %ifdef GO4K_USE_VCO_SHAPE %ifdef GO4K_USE_VCO_GATE push 7 %else push 6 %endif %else %ifdef GO4K_USE_VCO_GATE push 6 %else push 5 %endif %endif %endif call go4kTransformValues %ifdef GO4K_USE_VCO_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kVCO_func_do %ifdef GO4K_USE_VCO_STEREO movzx eax, byte [VAL-1] ; // get flags and check for stereo test al, byte VCO_STEREO jz short go4kVCO_func_nostereoout fldz go4kVCO_func_nostereoout: %endif fldz ret go4kVCO_func_do: %endif movzx eax, byte [VAL-1] ; // get flags %ifdef GO4K_USE_VCO_STEREO test al, byte VCO_STEREO jz short go4kVCO_func_nopswap fld dword [WRK+go4kVCO_wrk.phase] ;// swap left/right phase values for first stereo run fld dword [WRK+go4kVCO_wrk.phase2] fstp dword [WRK+go4kVCO_wrk.phase] fstp dword [WRK+go4kVCO_wrk.phase2] go4kVCO_func_nopswap: %endif go4kVCO_func_process: fld dword [edx+go4kVCO_val.transpose] fsub dword [c_0_5] %ifdef GO4K_USE_VCO_MOD_TM fadd dword [WRK+go4kVCO_wrk.tm] %endif fdiv dword [c_i128] fld dword [edx+go4kVCO_val.detune] fsub dword [c_0_5] fadd st0 %ifdef GO4K_USE_VCO_STEREO test al, byte VCO_STEREO jz short go4kVCO_func_nodswap fchs ;// negate detune for stereo go4kVCO_func_nodswap: %endif faddp st1 %ifdef GO4K_USE_VCO_MOD_DM fadd dword [WRK+go4kVCO_wrk.dm] %endif ; // st0 now contains the transpose+detune offset test al, byte LFO jnz go4kVCO_func_skipnote fiadd dword [ecx-4] ; // st0 is note, st1 is t+d offset go4kVCO_func_skipnote: fmul dword [c_i12] call _Power@0 test al, byte LFO jz short go4kVCO_func_normalize_note fmul dword [_LFO_NORMALIZE] ; // st0 is now frequency for lfo jmp short go4kVCO_func_normalized go4kVCO_func_normalize_note: fmul dword [FREQ_NORMALIZE] ; // st0 is now frequency go4kVCO_func_normalized: fadd dword [WRK+go4kVCO_wrk.phase] %ifdef GO4K_USE_VCO_MOD_FM fadd dword [WRK+go4kVCO_wrk.fm] %endif fld1 fadd st1, st0 fxch fprem fstp st1 fst dword [WRK+go4kVCO_wrk.phase] %ifdef GO4K_USE_VCO_MOD_PM fadd dword [WRK+go4kVCO_wrk.pm] %endif %ifdef GO4K_USE_VCO_PHASE_OFFSET fadd dword [edx+go4kVCO_val.phaseofs] %endif %ifdef PHASE_RENORMALIZE fld1 fadd st1, st0 fxch fprem fstp st1 ; // p %endif fld dword [edx+go4kVCO_val.color] ; // c p %ifdef GO4K_USE_VCO_MOD_CM fadd dword [WRK+go4kVCO_wrk.cm] ; // c p %endif go4kVCO_func_sine: test al, byte SINE jz short go4kVCO_func_trisaw call go4kVCO_sine go4kVCO_func_trisaw: test al, byte TRISAW jz short go4kVCO_func_pulse call go4kVCO_trisaw go4kVCO_func_pulse: test al, byte PULSE %ifdef GO4K_USE_VCO_GATE jz short go4kVCO_func_gate %else jz short go4kVCO_func_noise %endif call go4kVCO_pulse %ifdef GO4K_USE_VCO_GATE go4kVCO_func_gate: test al, byte GATE jz short go4kVCO_func_noise call go4kVCO_gate %endif go4kVCO_func_noise: test al, byte NOISE jz short go4kVCO_func_end call _FloatRandomNumber@0 fstp st1 fstp st1 go4kVCO_func_end: %ifdef GO4K_USE_VCO_SHAPE fld dword [edx+go4kVCO_val.shape] %ifdef GO4K_USE_VCO_MOD_SM fadd dword [WRK+go4kVCO_wrk.sm] %endif call go4kWaveshaper %endif fld dword [edx+go4kVCO_val.gain] %ifdef GO4K_USE_VCO_MOD_GM fadd dword [WRK+go4kVCO_wrk.gm] %endif fmulp st1, st0 %ifdef GO4K_USE_VCO_STEREO test al, byte VCO_STEREO jz short go4kVCO_func_stereodone sub al, byte VCO_STEREO fld dword [WRK+go4kVCO_wrk.phase] ;// swap left/right phase values again for second stereo run fld dword [WRK+go4kVCO_wrk.phase2] fstp dword [WRK+go4kVCO_wrk.phase] fstp dword [WRK+go4kVCO_wrk.phase2] jmp go4kVCO_func_process go4kVCO_func_stereodone: %endif ret %ifdef USE_SECTIONS section .g4kcodc code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // VCF Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kVCF_func@0 push 3 call go4kTransformValues %ifdef GO4K_USE_VCF_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kVCF_func_do ret go4kVCF_func_do: %endif movzx eax, byte [VAL-1] ; // get type flag fld dword [edx+go4kVCF_val.res] ; // r in %ifdef GO4K_USE_VCF_MOD_RM fadd dword [WRK+go4kVCF_wrk.rm] %endif fstp dword [esp-8] fld dword [edx+go4kVCF_val.freq] ; // f in %ifdef GO4K_USE_VCF_MOD_FM fadd dword [WRK+go4kVCF_wrk.fm] %endif fmul st0, st0 ; // square the input so we never get negative and also have a smoother behaviour in the lower frequencies fstp dword [esp-4] ; // in %ifdef GO4K_USE_VCF_STEREO test al, byte STEREO jz short go4kVCF_func_process add WRK, go4kVCF_wrk.low2 go4kVCF_func_stereoloop: ; // switch channels fxch st1 ; // inr inl %endif go4kVCF_func_process: fld dword [esp-8] fld dword [esp-4] fmul dword [WRK+go4kVCF_wrk.band] ; // f*b r in fadd dword [WRK+go4kVCF_wrk.low] ; // l' r in fst dword [WRK+go4kVCF_wrk.low] ; // l' r in fsubp st2, st0 ; // r in-l' fmul dword [WRK+go4kVCF_wrk.band] ; // r*b in-l' fsubp st1, st0 ; // h' fst dword [WRK+go4kVCF_wrk.high] ; // h' fmul dword [esp-4] ; // h'*f fadd dword [WRK+go4kVCF_wrk.band] ; // b' fstp dword [WRK+go4kVCF_wrk.band] fldz go4kVCF_func_low: test al, byte LOWPASS jz short go4kVCF_func_high fadd dword [WRK+go4kVCF_wrk.low] go4kVCF_func_high: %ifdef GO4K_USE_VCF_HIGH test al, byte HIGHPASS jz short go4kVCF_func_band fadd dword [WRK+go4kVCF_wrk.high] %endif go4kVCF_func_band: %ifdef GO4K_USE_VCF_BAND test al, byte BANDPASS jz short go4kVCF_func_peak fadd dword [WRK+go4kVCF_wrk.band] %endif go4kVCF_func_peak: %ifdef GO4K_USE_VCF_PEAK test al, byte PEAK jz short go4kVCF_func_processdone fadd dword [WRK+go4kVCF_wrk.low] fsub dword [WRK+go4kVCF_wrk.high] %endif go4kVCF_func_processdone: %ifdef GO4K_USE_VCF_STEREO test al, byte STEREO ; // outr inl jz short go4kVCF_func_end sub al, byte STEREO sub WRK, go4kVCF_wrk.low2 jmp go4kVCF_func_stereoloop %endif go4kVCF_func_end: ; // value - - - - ret %ifdef USE_SECTIONS section .g4kcodd code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // DST Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kDST_func@0 %ifdef GO4K_USE_DST %ifdef GO4K_USE_DST_SH %ifdef GO4K_USE_DST_STEREO push 3 %else push 2 %endif %else %ifdef GO4K_USE_DST_STEREO push 2 %else push 1 %endif %endif call go4kTransformValues %ifdef GO4K_USE_DST_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kDST_func_do ret go4kDST_func_do: %endif movzx eax, byte [VAL-1] ; // get type flag %ifdef GO4K_USE_DST_SH fld dword [edx+go4kDST_val.snhfreq] ; // snh in %ifdef GO4K_USE_DST_MOD_SH fadd dword [WRK+go4kDST_wrk.sm] ; // snh' in %endif fmul st0, st0 ; // square the input so we never get negative and also have a smoother behaviour in the lower frequencies fchs fadd dword [WRK+go4kDST_wrk.snhphase]; // snh' in fst dword [WRK+go4kDST_wrk.snhphase] fldz ; // 0 snh' in fucomip st1 ; // 0 snh' in jc short go4kDST_func_hold fld1 ; // 1 snh' in faddp st1, st0 ; // 1+snh' in fstp dword [WRK+go4kDST_wrk.snhphase]; // in %endif ; // calc pregain and postgain %ifdef GO4K_USE_DST_STEREO test al, byte STEREO ; // outr inl jz short go4kDST_func_mono fxch st1 ; // inr inl fld dword [edx+go4kDST_val.drive] ; // drive inr inl %ifdef GO4K_USE_DST_MOD_DM fadd dword [WRK+go4kDST_wrk.dm] %endif call go4kWaveshaper ; // outr inl %ifdef GO4K_USE_DST_SH fst dword [WRK+go4kDST_wrk.out2] ; // outr inl %endif fxch st1 ; // inl outr go4kDST_func_mono: %endif fld dword [edx+go4kDST_val.drive] ; // drive in %ifdef GO4K_USE_DST_MOD_DM fadd dword [WRK+go4kDST_wrk.dm] %endif call go4kWaveshaper ; // out %ifdef GO4K_USE_DST_SH fst dword [WRK+go4kDST_wrk.out] ; // out' %endif ret ; // out' %ifdef GO4K_USE_DST_SH go4kDST_func_hold: fstp st0 ; // in fstp st0 %ifdef GO4K_USE_DST_STEREO test al, byte STEREO ; // outr inl jz short go4kDST_func_monohold fld dword [WRK+go4kDST_wrk.out2] ; // out2 go4kDST_func_monohold: %endif fld dword [WRK+go4kDST_wrk.out] ; // out ret %endif %endif %ifdef USE_SECTIONS section .g4kcodf code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // DLL Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kDLL_func@0 %ifdef GO4K_USE_DLL %ifdef GO4K_USE_DLL_CHORUS %ifdef GO4K_USE_DLL_DAMP push 8 %else push 7 %endif %else %ifdef GO4K_USE_DLL_DAMP push 6 %else push 5 %endif %endif call go4kTransformValues pushad movzx ebx, byte [VAL-(go4kDLL_val.size-go4kDLL_val.delay)/4] ;// delay length index %ifdef GO4K_USE_DLL_NOTE_SYNC test ebx, ebx jne go4kDLL_func_process fld1 fild dword [ecx-4] ; // load note freq fmul dword [c_i12] call _Power@0 fmul dword [FREQ_NORMALIZE] ; // normalize fdivp st1, st0 ; // invert to get numer of samples fistp word [_go4k_delay_times+ebx*2] ; store current comb size %endif go4kDLL_func_process: mov ecx, eax ;// ecx is delay counter %ifdef GO4K_USE_DLL_MOD mov edi, WRK ;// edi is modulation workspace %endif mov WRK, dword [_go4k_delay_buffer_ofs] ;// ebp is current delay fld st0 ;// in in %ifdef GO4K_USE_DLL_MOD_IM fld dword [edx+go4kDLL_val.dry] ;// dry in in fadd dword [edi+go4kDLL_wrk2.im] ;// dry' in in fmulp st1, st0 ;// out in %else fmul dword [edx+go4kDLL_val.dry] ;// out in %endif fxch ;// in out %ifdef GO4K_USE_DLL_MOD_PM fld dword [edx+go4kDLL_val.pregain] ;// pg in out fadd dword [edi+go4kDLL_wrk2.pm] ;// pg' in out fmul st0, st0 ;// pg'' in out fmulp st1, st0 ;// in' out %else fmul dword [edx+go4kDLL_val.pregain] ;// in' out fmul dword [edx+go4kDLL_val.pregain] ;// in' out %endif %ifdef GO4K_USE_DLL_CHORUS ;// update saw lfo for chorus/flanger fld dword [edx+go4kDLL_val.freq] ;// f in' out %ifdef GO4K_USE_DLL_MOD_SM fadd dword [edi+go4kDLL_wrk2.sm] ;// f' in' out %endif fmul st0, st0 fmul st0, st0 fdiv dword [DLL_DEPTH] fadd dword [WRK+go4kDLL_wrk.phase] ;// p' in' out ;// clamp phase to 0,1 (only in editor, since delay can be active quite long) %ifdef GO4K_USE_DLL_CHORUS_CLAMP fld1 ;// 1 p' in' out fadd st1, st0 ;// 1 1+p' in' out fxch ;// 1+p' 1 in' out fprem ;// p'' 1 in' out fstp st1 ;// p'' in' out %endif fst dword [WRK+go4kDLL_wrk.phase] ;// get current sine value fldpi ; // pi p in' out fadd st0 ; // 2*pi p in' out fmulp st1, st0 ; // 2*pi*p in' out fsin ; // sin in' out fld1 ; // 1 sin in' out faddp st1, st0 ; // 1+sin in' out ;// mul with depth and convert to samples fld dword [edx+go4kDLL_val.depth] ; // d 1+sin in' out %ifdef GO4K_USE_DLL_MOD_AM fadd dword [edi+go4kDLL_wrk2.am] ; // d' 1+sin in' out %endif fmul st0, st0 fmul st0, st0 fmul dword [DLL_DEPTH] fmulp st1, st0 fistp dword [esp-4] ; // in' out %endif go4kDLL_func_loop: movzx esi, word [_go4k_delay_times+ebx*2] ; fetch comb size mov eax, dword [WRK+go4kDLL_wrk.index] ;// eax is current comb index %ifdef GO4K_USE_DLL_CHORUS ;// add lfo offset and wrap buffer add eax, dword [esp-4] cmp eax, esi jl short go4kDLL_func_buffer_nowrap1 sub eax, esi go4kDLL_func_buffer_nowrap1: %endif fld dword [WRK+eax*4+go4kDLL_wrk.buffer];// cout in' out %ifdef GO4K_USE_DLL_CHORUS mov eax, dword [WRK+go4kDLL_wrk.index] %endif ;// add comb output to current output fadd st2, st0 ;// cout in' out' %ifdef GO4K_USE_DLL_DAMP fld1 ;// 1 cout in' out' fsub dword [edx+go4kDLL_val.damp] ;// 1-damp cout in' out' %ifdef GO4K_USE_DLL_MOD_DM fsub dword [edi+go4kDLL_wrk2.dm] ;// 1-damp' cout in' out' %endif fmulp st1, st0 ;// cout*d2 in' out' fld dword [edx+go4kDLL_val.damp] ;// d1 cout*d2 in' out' %ifdef GO4K_USE_DLL_MOD_DM fadd dword [edi+go4kDLL_wrk2.dm] ;// d1' cout*d2 in' out' %endif fmul dword [WRK+go4kDLL_wrk.store] ;// store*d1 cout*d2 in' out' faddp st1, st0 ;// store' in' out' fst dword [WRK+go4kDLL_wrk.store] ;// store' in' out' %endif %ifdef GO4K_USE_DLL_MOD_FM fld dword [edx+go4kDLL_val.feedback] ;// fb cout in' out' fadd dword [edi+go4kDLL_wrk2.fm] ;// fb' cout in' out' fmulp st1, st0 ;// cout*fb' in' out' %else fmul dword [edx+go4kDLL_val.feedback] ;// cout*fb in' out' %endif %ifdef GO4K_USE_DLL_DC_FILTER fadd st0, st1 ;// store in' out' fstp dword [WRK+eax*4+go4kDLL_wrk.buffer];// in' out' %else fsub st0, st1 ;// store in' out' fstp dword [WRK+eax*4+go4kDLL_wrk.buffer];// in' out' fneg %endif ;// wrap comb buffer pos inc eax cmp eax, esi jl short go4kDLL_func_buffer_nowrap2 %ifdef GO4K_USE_DLL_CHORUS sub eax, esi %else xor eax, eax %endif go4kDLL_func_buffer_nowrap2: mov dword [WRK+go4kDLL_wrk.index], eax ;// increment buffer pointer to next buffer inc ebx ;// go to next delay length index add WRK, go4kDLL_wrk.size ;// go to next delay mov dword [_go4k_delay_buffer_ofs], WRK ;// store next delay offset loopne go4kDLL_func_loop fstp st0 ;// out' ;// process a dc filter to prevent heavy offsets in reverb ;// we're using the dc filter variables from the next delay line here, but doesnt hurt anyway %ifdef GO4K_USE_DLL_DC_FILTER ; y(n) = x(n) - x(n-1) + R * y(n-1) fld dword [WRK+go4kDLL_wrk.dcout] ;// dco out' fmul dword [c_dc_const] ;// dcc*dco out' fsub dword [WRK+go4kDLL_wrk.dcin] ;// dcc*dco-dci out' fxch ;// out' dcc*dco-dci fst dword [WRK+go4kDLL_wrk.dcin] ;// out' dcc*dco-dci faddp st1 ;// out' %ifdef GO4K_USE_UNDENORMALIZE fadd dword [c_0_5] ;// add and sub small offset to prevent denormalization fsub dword [c_0_5] %endif fst dword [WRK+go4kDLL_wrk.dcout] %endif popad ret %endif %ifdef USE_SECTIONS section .g4kcodg code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FOP Tick (various fp stack based operations) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFOP_func@0 push 1 call go4kTransformValues go4kFOP_func_pop: dec eax jnz go4kFOP_func_addp fstp st0 ret go4kFOP_func_addp: dec eax jnz go4kFOP_func_mulp faddp st1, st0 ret go4kFOP_func_mulp: dec eax jnz go4kFOP_func_push fmulp st1, st0 ret go4kFOP_func_push: dec eax jnz go4kFOP_func_xch fld st0 ret go4kFOP_func_xch: dec eax jnz go4kFOP_func_add fxch ret go4kFOP_func_add: dec eax jnz go4kFOP_func_mul fadd st1 ret go4kFOP_func_mul: dec eax jnz go4kFOP_func_addp2 fmul st1 ret go4kFOP_func_addp2: dec eax jnz go4kFOP_func_loadnote faddp st2, st0 faddp st2, st0 ret go4kFOP_func_loadnote: dec eax jnz go4kFOP_func_mulp2 fild dword [ecx-4] fmul dword [c_i128] ret go4kFOP_func_mulp2: fmulp st2, st0 fmulp st2, st0 ret %ifdef USE_SECTIONS section .g4kcodh code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FST Tick (stores a value somewhere in the local workspace) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFST_func@0 push 1 call go4kTransformValues fld dword [edx+go4kFST_val.amount] fsub dword [c_0_5] fadd st0 fmul st1 lodsw and eax, 0x00003fff ; // eax is destination slot test word [VAL-2], FST_ADD jz go4kFST_func_set fadd dword [ecx+eax*4] go4kFST_func_set: fstp dword [ecx+eax*4] test word [VAL-2], FST_POP jz go4kFST_func_done fstp st0 go4kFST_func_done: ret %ifdef USE_SECTIONS section .g4kcodm code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FLD Tick (load a value on stack, optionally add a modulation signal beforehand) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : signal-signal*pan , signal*pan ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFLD_func@0 ;// in main env %ifdef GO4K_USE_FLD push 1 call go4kTransformValues fld dword [edx+go4kFLD_val.value] ;// value in fsub dword [c_0_5] fadd st0 %ifdef GO4K_USE_FLD_MOD_VM fadd dword [WRK+go4kFLD_wrk.vm] ;// value' in %endif %endif ret %ifdef GO4K_USE_FSTG %ifdef USE_SECTIONS section .g4kcodi code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FSTG Tick (stores a value anywhere in the synth (and in each voice)) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFSTG_func@0 push 1 call go4kTransformValues %ifdef GO4K_USE_FSTG_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kFSTG_func_do lodsw jmp go4kFSTG_func_testpop go4kFSTG_func_do: %endif fld dword [edx+go4kFST_val.amount] fsub dword [c_0_5] fadd st0 fmul st1 lodsw and eax, 0x00003fff ; // eax is destination slot test word [VAL-2], FST_ADD jz go4kFSTG_func_set fadd dword [go4k_synth_wrk+eax*4] go4kFSTG_func_set: %if MAX_VOICES > 1 fst dword [go4k_synth_wrk+eax*4] fstp dword [go4k_synth_wrk+eax*4+go4k_instrument.size] %else fstp dword [go4k_synth_wrk+eax*4] %endif go4kFSTG_func_testpop: test word [VAL-2], FST_POP jz go4kFSTG_func_done fstp st0 go4kFSTG_func_done: ret %endif %ifdef USE_SECTIONS section .g4kcodj code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // PAN Tick (multiplies signal with main envelope and converts to stereo) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : signal-signal*pan , signal*pan ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kPAN_func@0 ;// in main env %ifdef GO4K_USE_PAN push 1 call go4kTransformValues fld dword [edx+go4kPAN_val.panning] ;// pan in %ifdef GO4K_USE_PAN_MOD fadd dword [WRK+go4kPAN_wrk.pm] ;// pan in %endif fmul st1 ;// r in fsub st1, st0 ;// r l fxch ;// l r %else fmul dword [c_0_5] fld st0 %endif ret %ifdef USE_SECTIONS section .g4kcodk code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // OUT Tick ( stores stereo signal pair in temp buffers of the instrument) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kOUT_func@0 ;// l r %ifdef GO4K_USE_GLOBAL_DLL push 2 call go4kTransformValues pushad lea edi, [ecx+MAX_UNITS*MAX_UNIT_SLOTS*4] fld st1 ;// r l r fld st1 ;// l r l r fld dword [edx+go4kOUT_val.auxsend] ;// as l r l r %ifdef GO4K_USE_OUT_MOD_AM fadd dword [WRK+go4kOUT_wrk.am] ;// am l r l r %endif fmulp st1, st0 ;// l' r l r fstp dword [edi] ;// r l r scasd fld dword [edx+go4kOUT_val.auxsend] ;// as r l r %ifdef GO4K_USE_OUT_MOD_AM fadd dword [WRK+go4kOUT_wrk.am] ;// am r l r %endif fmulp st1, st0 ;// r' l r fstp dword [edi] ;// l r scasd fld dword [edx+go4kOUT_val.gain] ;// g l r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm l r %endif fmulp st1, st0 ;// l' r fstp dword [edi] ;// r scasd fld dword [edx+go4kOUT_val.gain] ;// g r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm r %endif fmulp st1, st0 ;// r' fstp dword [edi] ;// - scasd popad %else push 1 call go4kTransformValues fld dword [edx+go4kOUT_val.gain] ;// g l r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm l r %endif fmulp st1, st0 ;// l' r fstp dword [ecx+MAX_UNITS*MAX_UNIT_SLOTS*4+0] ;// r fld dword [edx+go4kOUT_val.gain] ;// g r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm r %endif fmulp st1, st0 ;// r' fstp dword [ecx+MAX_UNITS*MAX_UNIT_SLOTS*4+4] ;// - %endif ret %ifdef USE_SECTIONS section .g4kcodl code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // ACC Tick (stereo signal accumulation for synth commands only -> dont use in instrument commands) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kACC_func@0 push 1 call go4kTransformValues pushad mov edi, go4k_synth_wrk add edi, go4k_instrument.size sub edi, eax ; // eax already contains the accumulation offset from the go4kTransformValues call mov cl, MAX_INSTRUMENTS*MAX_VOICES fldz ;// 0 fldz ;// 0 0 go4kACC_func_loop: fadd dword [edi-8] ;// l 0 fxch ;// 0 l fadd dword [edi-4] ;// r l fxch ;// l r add edi, go4k_instrument.size dec cl jnz go4kACC_func_loop popad ret %ifdef USE_SECTIONS section .g4kcodw code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Update Instrument (allocate voices, set voice to release) ; //---------------------------------------------------------------------------------------- ; // IN : ; // IN : ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- go4kUpdateInstrument: ; // get new note mov eax, dword [esp+4+4] ; // eax = current tick shr eax, PATTERN_SIZE_SHIFT ; // eax = current pattern imul edx, ecx, dword MAX_PATTERNS ; // edx = instrument pattern list index movzx edx, byte [edx+eax+go4k_pattern_lists] ; // edx = pattern index mov eax, dword [esp+4+4] ; // eax = current tick shl edx, PATTERN_SIZE_SHIFT and eax, PATTERN_SIZE-1 movzx edx, byte [edx+eax+go4k_patterns] ; // edx = requested note in new patterntick ; // apply note changes cmp dl, HLD ; // anything but hold causes action je short go4kUpdateInstrument_done inc dword [edi] ; // set release flag if needed %if MAX_VOICES > 1 inc dword [edi+go4k_instrument.size] ; // set release flag if needed %endif cmp dl, HLD ; // check for new note jl short go4kUpdateInstrument_done %if MAX_VOICES > 1 pushad xchg eax, dword [go4k_voiceindex + ecx*4] test eax, eax je go4kUpdateInstrument_newNote add edi, go4k_instrument.size go4kUpdateInstrument_newNote: xor al,1 xchg dword [go4k_voiceindex + ecx*4], eax %endif pushad xor eax, eax mov ecx, (8+MAX_UNITS*MAX_UNIT_SLOTS*4)/4 ; // clear only relase, note and workspace rep stosd popad mov dword [edi+4], edx ; // set requested note as current note %if MAX_VOICES > 1 popad %endif jmp short go4kUpdateInstrument_done go4kUpdateInstrument_done: ret %ifdef USE_SECTIONS section .g4kcodx code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Render Voices ; //---------------------------------------------------------------------------------------- ; // IN : ; // IN : ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- go4kRenderVoices: push ecx ; // save current instrument counter %if MAX_VOICES > 1 push COM ; // save current instrument command index push VAL ; // save current instrument values index %endif call go4k_VM_process ; // call synth vm for instrument voices mov eax, dword [ecx+go4kENV_wrk.state] cmp al, byte ENV_STATE_OFF jne go4kRenderVoices_next xor eax, eax mov dword [ecx-4], eax ; // kill note if voice is done go4kRenderVoices_next: %if MAX_VOICES > 1 pop VAL ; // restore instrument value index pop COM ; // restore instrument command index %endif %ifdef GO4K_USE_BUFFER_RECORDINGS mov eax, dword [esp+16] ; // get current tick shr eax, 8 ; // every 256th sample = ~ 172 hz shl eax, 5 ; // for 16 instruments a 2 voices add eax, dword [esp] add eax, dword [esp] ; // + 2*currentinstrument+0 %ifdef GO4K_USE_ENVELOPE_RECORDINGS mov edx, dword [ecx+go4kENV_wrk.level] mov dword [__4klang_envelope_buffer+eax*4], edx %endif %ifdef GO4K_USE_NOTE_RECORDINGS mov edx, dword [ecx-4] mov dword [__4klang_note_buffer+eax*4], edx %endif %endif %if MAX_VOICES > 1 call go4k_VM_process ; // call synth vm for instrument voices mov eax, dword [ecx+go4kENV_wrk.state] cmp al, byte ENV_STATE_OFF jne go4k_render_instrument_next2 xor eax, eax mov dword [ecx-4], eax ; // kill note if voice is done go4k_render_instrument_next2: %ifdef GO4K_USE_BUFFER_RECORDINGS mov eax, dword [esp+16] ; // get current tick shr eax, 8 ; // every 256th sample = ~ 172 hz shl eax, 5 ; // for 16 instruments a 2 voices add eax, dword [esp] add eax, dword [esp] ; // + 2*currentinstrument+0 %ifdef GO4K_USE_ENVELOPE_RECORDINGS mov edx, dword [ecx+go4kENV_wrk.level] mov dword [__4klang_envelope_buffer+eax*4+4], edx %endif %ifdef GO4K_USE_NOTE_RECORDINGS mov edx, dword [ecx-4] mov dword [__4klang_note_buffer+eax*4+4], edx %endif %endif %endif pop ecx ; // restore instrument counter ret %ifdef USE_SECTIONS section .g4kcody code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // the entry point for the synth ; //---------------------------------------------------------------------------------------- %ifdef USE_SECTIONS export_func _4klang_render@4 %else export_func _4klang_render %endif pushad xor ecx, ecx %ifdef GO4K_USE_BUFFER_RECORDINGS push ecx %endif ; loop all ticks go4k_render_tickloop: push ecx xor ecx, ecx ; loop all samples per tick go4k_render_sampleloop: push ecx xor ecx, ecx mov ebx, go4k_synth_instructions ; // ebx = instrument command index mov VAL, go4k_synth_parameter_values; // VAL = instrument values index mov edi, _go4k_delay_buffer ; // get offset of first delay buffer mov dword [_go4k_delay_buffer_ofs], edi ; // store offset in delaybuffer offset variable mov edi, go4k_synth_wrk ; // edi = first instrument ; loop all instruments go4k_render_instrumentloop: mov eax, dword [esp] ; // eax = current tick sample and eax, eax jnz go4k_render_instrument_process ; // tick change? (first sample in current tick) call go4kUpdateInstrument ; // update instrument state ; process instrument go4k_render_instrument_process: call go4kRenderVoices inc ecx cmp cl, byte MAX_INSTRUMENTS jl go4k_render_instrumentloop mov dword [edi+4], ecx ; // move a value != 0 into note slot, so processing will be done call go4k_VM_process ; // call synth vm for synth go4k_render_output_sample: %ifdef GO4K_USE_BUFFER_RECORDINGS inc dword [esp+8] xchg esi, dword [esp+48] ; // edx = destbuffer %else xchg esi, dword [esp+44] ; // edx = destbuffer %endif %ifdef GO4K_CLIP_OUTPUT fld dword [edi-8] fld1 ; // 1 val fucomi st1 ; // 1 val jbe short go4k_render_clip1 fchs ; // -1 val fucomi st1 ; // -1 val fcmovb st0, st1 ; // val -1 (if val > -1) go4k_render_clip1: fstp st1 ; // newval %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted left sample lodsw %else fstp dword [esi] ; // store left sample lodsd %endif fld dword [edi-4] fld1 ; // 1 val fucomi st1 ; // 1 val jbe short go4k_render_clip2 fchs ; // -1 val fucomi st1 ; // -1 val fcmovb st0, st1 ; // val -1 (if val > -1) go4k_render_clip2: fstp st1 ; // newval %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted right sample lodsw %else fstp dword [esi] ; // store right sample lodsd %endif %else fld dword [edi-8] %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted left sample lodsw %else fstp dword [esi] ; // store left sample lodsd %endif fld dword [edi-4] %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted right sample lodsw %else fstp dword [esi] ; // store right sample lodsd %endif %endif %ifdef GO4K_USE_BUFFER_RECORDINGS xchg esi, dword [esp+48] %else xchg esi, dword [esp+44] %endif pop ecx inc ecx %ifdef GO4K_USE_GROOVE_PATTERN mov ebx, dword SAMPLES_PER_TICK mov eax, dword [esp] and eax, 0x0f bt dword [go4k_groove_pattern],eax jnc go4k_render_nogroove sub ebx, dword 3000 go4k_render_nogroove: cmp ecx, ebx %else cmp ecx, dword SAMPLES_PER_TICK %endif jl go4k_render_sampleloop pop ecx inc ecx %ifdef AUTHORING mov dword[__4klang_current_tick], ecx %endif cmp ecx, dword MAX_TICKS jl go4k_render_tickloop %ifdef GO4K_USE_BUFFER_RECORDINGS pop ecx %endif popad ret 4 %ifdef USE_SECTIONS section .g4kcodz code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // the magic behind it :) ; //---------------------------------------------------------------------------------------- ; // IN : edi = instrument pointer ; // IN : esi = instrumet values ; // IN : ebx = instrument instructions ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- go4k_VM_process: lea WRK, [edi+8] ; // get current workspace pointer mov ecx, WRK ; // ecx = workspace start go4k_VM_process_loop: movzx eax, byte [ebx] ; // get command byte inc ebx test eax, eax je go4k_VM_process_done ; // command byte = 0? so done call dword [eax*4+go4k_synth_commands] add WRK, MAX_UNIT_SLOTS*4 ; // go to next workspace slot jmp short go4k_VM_process_loop go4k_VM_process_done: add edi, go4k_instrument.size ; // go to next instrument voice ret",16297,True,3578.969174958891,median ";-------------------------------------------------------- ; File Created by SDCC : free open source ANSI-C Compiler ; Version 4.1.4 #12246 (Mac OS X x86_64) ;-------------------------------------------------------- .module background_1_map .optsdcc -mgbz80 ;-------------------------------------------------------- ; Public variables in this module ;-------------------------------------------------------- .globl _background_1_map .globl ___bank_background_1_map ;-------------------------------------------------------- ; special function registers ;-------------------------------------------------------- ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- .area _DATA ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- .area _INITIALIZED ;-------------------------------------------------------- ; absolute external ram data ;-------------------------------------------------------- .area _DABS (ABS) ;-------------------------------------------------------- ; global & static initialisations ;-------------------------------------------------------- .area _HOME .area _GSINIT .area _GSFINAL .area _GSINIT ;-------------------------------------------------------- ; Home ;-------------------------------------------------------- .area _HOME .area _HOME ;-------------------------------------------------------- ; code ;-------------------------------------------------------- .area _CODE_255 .area _CODE_255 ___bank_background_1_map = 0x00ff _background_1_map: .db #0x31 ; 49 '1' .db #0x32 ; 50 '2' .db #0x33 ; 51 '3' .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x33 ; 51 '3' .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x33 ; 51 '3' .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x33 ; 51 '3' .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x37 ; 55 '7' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x3a ; 58 .db #0x3b ; 59 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x37 ; 55 '7' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x41 ; 65 'A' .db #0x42 ; 66 'B' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x45 ; 69 'E' .db #0x46 ; 70 'F' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x45 ; 69 'E' .db #0x46 ; 70 'F' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x45 ; 69 'E' .db #0x46 ; 70 'F' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x45 ; 69 'E' .db #0x46 ; 70 'F' .db #0x47 ; 71 'G' .db #0x38 ; 56 '8' .db #0x48 ; 72 'H' .db #0x49 ; 73 'I' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4b ; 75 'K' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4b ; 75 'K' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4b ; 75 'K' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4b ; 75 'K' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x37 ; 55 '7' .db #0x4c ; 76 'L' .db #0x4d ; 77 'M' .db #0x4e ; 78 'N' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x00 ; 0 .db #0x51 ; 81 'Q' .db #0x00 ; 0 .db #0x00 ; 0 .db #0x00 ; 0 .db #0x00 ; 0 .db #0x4c ; 76 'L' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x37 ; 55 '7' .db #0x37 ; 55 '7' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x38 ; 56 '8' .db #0x40 ; 64 .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x53 ; 83 'S' .db #0x54 ; 84 'T' .db #0x54 ; 84 'T' .db #0x54 ; 84 'T' .db #0x54 ; 84 'T' .db #0x55 ; 85 'U' .db #0x4c ; 76 'L' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x47 ; 71 'G' .db #0x47 ; 71 'G' .db #0x37 ; 55 '7' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x56 ; 86 'V' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x57 ; 87 'W' .db #0x58 ; 88 'X' .db #0x58 ; 88 'X' .db #0x58 ; 88 'X' .db #0x58 ; 88 'X' .db #0x59 ; 89 'Y' .db #0x4c ; 76 'L' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x37 ; 55 '7' .db #0x37 ; 55 '7' .db #0x47 ; 71 'G' .db #0x5a ; 90 'Z' .db #0x5b ; 91 .db #0x5b ; 91 .db #0x5b ; 91 .db #0x5a ; 90 'Z' .db #0x5b ; 91 .db #0x5a ; 90 'Z' .db #0x5b ; 91 .db #0x5a ; 90 'Z' .db #0x5b ; 91 .db #0x5a ; 90 'Z' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x5c ; 92 .db #0x5d ; 93 .db #0x5e ; 94 .db #0x5f ; 95 .db #0x5d ; 93 .db #0x60 ; 96 .db #0x4c ; 76 'L' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x37 ; 55 '7' .db #0x61 ; 97 'a' .db #0x62 ; 98 'b' .db #0x62 ; 98 'b' .db #0x63 ; 99 'c' .db #0x64 ; 100 'd' .db #0x62 ; 98 'b' .db #0x61 ; 97 'a' .db #0x62 ; 98 'b' .db #0x61 ; 97 'a' .db #0x62 ; 98 'b' .db #0x61 ; 97 'a' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x65 ; 101 'e' .db #0x66 ; 102 'f' .db #0x67 ; 103 'g' .db #0x68 ; 104 'h' .db #0x65 ; 101 'e' .db #0x66 ; 102 'f' .db #0x4c ; 76 'L' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x40 ; 64 .db #0x5b ; 91 .db #0x5b ; 91 .db #0x5a ; 90 'Z' .db #0x69 ; 105 'i' .db #0x6a ; 106 'j' .db #0x5a ; 90 'Z' .db #0x5b ; 91 .db #0x5b ; 91 .db #0x5a ; 90 'Z' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x4c ; 76 'L' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x56 ; 86 'V' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x40 ; 64 .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4c ; 76 'L' .db #0x4b ; 75 'K' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x40 ; 64 .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x6d ; 109 'm' .db #0x6e ; 110 'n' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x56 ; 86 'V' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x45 ; 69 'E' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x6f ; 111 'o' .db #0x70 ; 112 'p' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x4b ; 75 'K' .db #0x4a ; 74 'J' .db #0x39 ; 57 '9' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4b ; 75 'K' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x71 ; 113 'q' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x73 ; 115 's' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x56 ; 86 'V' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x74 ; 116 't' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x75 ; 117 'u' .db #0x4c ; 76 'L' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x4c ; 76 'L' .db #0x74 ; 116 't' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x4c ; 76 'L' .db #0x4c ; 76 'L' .db #0x4b ; 75 'K' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x4c ; 76 'L' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x39 ; 57 '9' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x76 ; 118 'v' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x38 ; 56 '8' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x56 ; 86 'V' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x4c ; 76 'L' .db #0x77 ; 119 'w' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x78 ; 120 'x' .db #0x39 ; 57 '9' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x79 ; 121 'y' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x72 ; 114 'r' .db #0x7a ; 122 'z' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x4c ; 76 'L' .db #0x4b ; 75 'K' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x40 ; 64 .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x56 ; 86 'V' .db #0x46 ; 70 'F' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x43 ; 67 'C' .db #0x44 ; 68 'D' .db #0x4a ; 74 'J' .db #0x38 ; 56 '8' .db #0x40 ; 64 .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x40 ; 64 .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x39 ; 57 '9' .db #0x38 ; 56 '8' .db #0x4c ; 76 'L' .db #0x4b ; 75 'K' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x4f ; 79 'O' .db #0x50 ; 80 'P' .db #0x6b ; 107 'k' .db #0x34 ; 52 '4' .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x3e ; 62 .db #0x52 ; 82 'R' .db #0x6c ; 108 'l' .db #0x3d ; 61 .db #0x33 ; 51 '3' .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x7b ; 123 .db #0x34 ; 52 '4' .db #0x35 ; 53 '5' .db #0x36 ; 54 '6' .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .db #0x3c ; 60 .db #0x3d ; 61 .db #0x3e ; 62 .db #0x3f ; 63 .area _INITIALIZER .area _CABS (ABS) ",16183,True,6153.255638977126,median ";============================================================== ; WLA-DX banking setup ;============================================================== .memorymap defaultslot 0 slotsize $8000 slot 0 $0000 .endme .rombankmap bankstotal 1 banksize $8000 banks 1 .endro ;============================================================== ; SDSC tag and SMS rom header ;============================================================== .sdsctag 1.10,""Hello World!"",""SMS programming tutorial program (bugfixed)"",""Maxim"" .bank 0 slot 0 .org $0000 ;============================================================== ; Boot section ;============================================================== di ; disable interrupts im 1 ; Interrupt mode 1 jp main ; jump to main program .org $0066 ;============================================================== ; Pause button handler ;============================================================== ; Do nothing retn ;============================================================== ; Main program ;============================================================== main: ld sp, $dff0 ;============================================================== ; Set up VDP registers ;============================================================== ld hl,VdpData ld b,VdpDataEnd-VdpData ld c,$bf otir ;============================================================== ; Clear VRAM ;============================================================== ; 1. Set VRAM write address to 0 by outputting $4000 ORed with $0000 ld a,$00 out ($bf),a ld a,$40 out ($bf),a ; 2. Output 16KB of zeroes ld bc, $4000 ; Counter for 16KB of VRAM ld a,$00 ; Value to write ClearVRAMLoop: out ($be),a ; Output to VRAM address, which is auto-incremented after each write dec c jp nz,ClearVRAMLoop dec b jp nz,ClearVRAMLoop ;============================================================== ; Load palette ;============================================================== ; 1. Set VRAM write address to CRAM (palette) address 0 (for palette index 0) ; by outputting $c000 ORed with $0000 ld a,$00 out ($bf),a ld a,$c0 out ($bf),a ; 2. Output colour data ld hl,PaletteData ld b,(PaletteDataEnd-PaletteData) ld c,$be otir ;============================================================== ; Load tiles (font) ;============================================================== ; 1. Set VRAM write address to tile index 0 ; by outputting $4000 ORed with $0000 ld a,$00 out ($bf),a ld a,$40 out ($bf),a ; 2. Output tile data ld hl,FontData ; Location of tile data ld bc,FontDataEnd-FontData ; Counter for number of bytes to write WriteTilesLoop: ; Output data byte then three zeroes, because our tile data is 1 bit ; and must be increased to 4 bit ld a,(hl) ; Get data byte out ($be),a ld a,$00 out ($be),a out ($be),a out ($be),a inc hl ; Add one to hl so it points to the next data byte dec c jp nz,WriteTilesLoop dec b jp nz,WriteTilesLoop ;============================================================== ; Write text to name table ;============================================================== ; 1. Set VRAM write address to name table index 0 ; by outputting $4000 ORed with $3800+0 ld a,$00 out ($bf),a ld a,$38|$40 out ($bf),a ; 2. Loop through text data, converting from ASCII ans writing tile indices ; to name table. Stop when a zero byte is found. ld hl,Message WriteTextLoop: ld a,(hl) ; Get data byte cp $00 ; Is it zero? jp z,EndWriteTextLoop ; If so, exit loop sub $20 ; In ASCII, space=$20 and the rest follow on. We want space=$00 so we subtract $20. out ($be),a ld a,$00 out ($be),a inc hl ; Point to next letter jp WriteTextLoop EndWriteTextLoop: ; Turn screen on ld a,%11000100 ; |||| |`- Zoomed sprites -> 16x16 pixels ; |||| `-- Doubled sprites -> 2 tiles per sprite, 8x16 ; |||`---- 30 row/240 line mode ; ||`----- 28 row/224 line mode ; |`------ VBlank interrupts ; `------- Enable display out ($bf),a ld a,$81 out ($bf),a ; Infinite loop to stop program Loop: jp Loop ;============================================================== ; Data ;============================================================== Message: .db ""Hello world!"",0 PaletteData: .db $00,$3f ; Black, White PaletteDataEnd: ; VDP initialisation data VdpData: .db $04,$80,$84,$81,$ff,$82,$ff,$85,$ff,$86,$ff,$87,$00,$88,$00,$89,$ff,$8a VdpDataEnd: FontData: ; This font data was provided by Mike G and is reproduced here in its entirety: ;------------------------------------------ ; In loving memory of Acorn Computers Ltd. ; Mike G proudly presents the: ; ; BBC Micro Character Set! ; ======================== ; ; This source was created automatically ; from character data stored in the BBC ; Microcomputer operating system ROM. ; ; The BBC set is a nice, clear font which ; (unlike the classic Namco/Sega font) ; includes lower-case letters as well as ; upper-case. ; ; Being a British micro, there's even a ; Pound Sterling currency symbol, which ; should come in handy when I begin to ; write financial apps on the SMS. (Just ; kidding!) ; ; Hopefully by using binary representation ; it will be obvious how the character ; data is stored. ; ;------------------------------------------ ; Character 0x20 (space) .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x21 ! .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x22 "" .DB %01101100 ; Hex 6Ch .DB %01101100 ; Hex 6Ch .DB %01101100 ; Hex 6Ch .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x23 # .DB %00110110 ; Hex 36h .DB %00110110 ; Hex 36h .DB %01111111 ; Hex 7Fh .DB %00110110 ; Hex 36h .DB %01111111 ; Hex 7Fh .DB %00110110 ; Hex 36h .DB %00110110 ; Hex 36h .DB %00000000 ; Hex 00h ; Character 0x24 $ .DB %00001100 ; Hex 0Ch .DB %00111111 ; Hex 3Fh .DB %01101000 ; Hex 68h .DB %00111110 ; Hex 3Eh .DB %00001011 ; Hex 0Bh .DB %01111110 ; Hex 7Eh .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x25 % .DB %01100000 ; Hex 60h .DB %01100110 ; Hex 66h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %01100110 ; Hex 66h .DB %00000110 ; Hex 06h .DB %00000000 ; Hex 00h ; Character 0x26 & .DB %00111000 ; Hex 38h .DB %01101100 ; Hex 6Ch .DB %01101100 ; Hex 6Ch .DB %00111000 ; Hex 38h .DB %01101101 ; Hex 6Dh .DB %01100110 ; Hex 66h .DB %00111011 ; Hex 3Bh .DB %00000000 ; Hex 00h ; Character 0x27 ' .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x28 ( .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00011000 ; Hex 18h .DB %00001100 ; Hex 0Ch .DB %00000000 ; Hex 00h ; Character 0x29 ) .DB %00110000 ; Hex 30h .DB %00011000 ; Hex 18h .DB %00001100 ; Hex 0Ch .DB %00001100 ; Hex 0Ch .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %00000000 ; Hex 00h ; Character 0x2A * .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %01111110 ; Hex 7Eh .DB %00111100 ; Hex 3Ch .DB %01111110 ; Hex 7Eh .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x2B + .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %01111110 ; Hex 7Eh .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x2C , .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h ; Character 0x2D - .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x2E . .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x2F / .DB %00000000 ; Hex 00h .DB %00000110 ; Hex 06h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %01100000 ; Hex 60h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x30 0 .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01101110 ; Hex 6Eh .DB %01111110 ; Hex 7Eh .DB %01110110 ; Hex 76h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x31 1 .DB %00011000 ; Hex 18h .DB %00111000 ; Hex 38h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x32 2 .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %00000110 ; Hex 06h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x33 3 .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %00000110 ; Hex 06h .DB %00011100 ; Hex 1Ch .DB %00000110 ; Hex 06h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x34 4 .DB %00001100 ; Hex 0Ch .DB %00011100 ; Hex 1Ch .DB %00111100 ; Hex 3Ch .DB %01101100 ; Hex 6Ch .DB %01111110 ; Hex 7Eh .DB %00001100 ; Hex 0Ch .DB %00001100 ; Hex 0Ch .DB %00000000 ; Hex 00h ; Character 0x35 5 .DB %01111110 ; Hex 7Eh .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %00000110 ; Hex 06h .DB %00000110 ; Hex 06h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x36 6 .DB %00011100 ; Hex 1Ch .DB %00110000 ; Hex 30h .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x37 7 .DB %01111110 ; Hex 7Eh .DB %00000110 ; Hex 06h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00000000 ; Hex 00h ; Character 0x38 8 .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x39 9 .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000110 ; Hex 06h .DB %00001100 ; Hex 0Ch .DB %00111000 ; Hex 38h .DB %00000000 ; Hex 00h ; Character 0x3A : .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x3B ; .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h ; Character 0x3C < .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %01100000 ; Hex 60h .DB %00110000 ; Hex 30h .DB %00011000 ; Hex 18h .DB %00001100 ; Hex 0Ch .DB %00000000 ; Hex 00h ; Character 0x3D = .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x3E > .DB %00110000 ; Hex 30h .DB %00011000 ; Hex 18h .DB %00001100 ; Hex 0Ch .DB %00000110 ; Hex 06h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %00000000 ; Hex 00h ; Character 0x3F ? .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x40 @ .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01101110 ; Hex 6Eh .DB %01101010 ; Hex 6Ah .DB %01101110 ; Hex 6Eh .DB %01100000 ; Hex 60h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x41 A .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111110 ; Hex 7Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x42 B .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111100 ; Hex 7Ch .DB %00000000 ; Hex 00h ; Character 0x43 C .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x44 D .DB %01111000 ; Hex 78h .DB %01101100 ; Hex 6Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01101100 ; Hex 6Ch .DB %01111000 ; Hex 78h .DB %00000000 ; Hex 00h ; Character 0x45 E .DB %01111110 ; Hex 7Eh .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x46 F .DB %01111110 ; Hex 7Eh .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %00000000 ; Hex 00h ; Character 0x47 G .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100000 ; Hex 60h .DB %01101110 ; Hex 6Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x48 H .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111110 ; Hex 7Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x49 I .DB %01111110 ; Hex 7Eh .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x4A J .DB %00111110 ; Hex 3Eh .DB %00001100 ; Hex 0Ch .DB %00001100 ; Hex 0Ch .DB %00001100 ; Hex 0Ch .DB %00001100 ; Hex 0Ch .DB %01101100 ; Hex 6Ch .DB %00111000 ; Hex 38h .DB %00000000 ; Hex 00h ; Character 0x4B K .DB %01100110 ; Hex 66h .DB %01101100 ; Hex 6Ch .DB %01111000 ; Hex 78h .DB %01110000 ; Hex 70h .DB %01111000 ; Hex 78h .DB %01101100 ; Hex 6Ch .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x4C L .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x4D M .DB %01100011 ; Hex 63h .DB %01110111 ; Hex 77h .DB %01111111 ; Hex 7Fh .DB %01101011 ; Hex 6Bh .DB %01101011 ; Hex 6Bh .DB %01100011 ; Hex 63h .DB %01100011 ; Hex 63h .DB %00000000 ; Hex 00h ; Character 0x4E N .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01110110 ; Hex 76h .DB %01111110 ; Hex 7Eh .DB %01101110 ; Hex 6Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x4F O .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x50 P .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111100 ; Hex 7Ch .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %00000000 ; Hex 00h ; Character 0x51 Q .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01101010 ; Hex 6Ah .DB %01101100 ; Hex 6Ch .DB %00110110 ; Hex 36h .DB %00000000 ; Hex 00h ; Character 0x52 R .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111100 ; Hex 7Ch .DB %01101100 ; Hex 6Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x53 S .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100000 ; Hex 60h .DB %00111100 ; Hex 3Ch .DB %00000110 ; Hex 06h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x54 T .DB %01111110 ; Hex 7Eh .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x55 U .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x56 V .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x57 W .DB %01100011 ; Hex 63h .DB %01100011 ; Hex 63h .DB %01101011 ; Hex 6Bh .DB %01101011 ; Hex 6Bh .DB %01111111 ; Hex 7Fh .DB %01110111 ; Hex 77h .DB %01100011 ; Hex 63h .DB %00000000 ; Hex 00h ; Character 0x58 X .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00011000 ; Hex 18h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x59 Y .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x5A Z .DB %01111110 ; Hex 7Eh .DB %00000110 ; Hex 06h .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %01100000 ; Hex 60h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x5B [ .DB %01111100 ; Hex 7Ch .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %00000000 ; Hex 00h ; Character 0x5C \\ .DB %00000000 ; Hex 00h .DB %01100000 ; Hex 60h .DB %00110000 ; Hex 30h .DB %00011000 ; Hex 18h .DB %00001100 ; Hex 0Ch .DB %00000110 ; Hex 06h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x5D ] .DB %00111110 ; Hex 3Eh .DB %00000110 ; Hex 06h .DB %00000110 ; Hex 06h .DB %00000110 ; Hex 06h .DB %00000110 ; Hex 06h .DB %00000110 ; Hex 06h .DB %00111110 ; Hex 3Eh .DB %00000000 ; Hex 00h ; Character 0x5E ^ .DB %00011000 ; Hex 18h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01000010 ; Hex 42h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x5F (underscore) .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %11111111 ; Hex FFh ; Character 0x60 (Pound Sterling) .DB %00011100 ; Hex 1Ch .DB %00110110 ; Hex 36h .DB %00110000 ; Hex 30h .DB %01111100 ; Hex 7Ch .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x61 a .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111100 ; Hex 3Ch .DB %00000110 ; Hex 06h .DB %00111110 ; Hex 3Eh .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000000 ; Hex 00h ; Character 0x62 b .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111100 ; Hex 7Ch .DB %00000000 ; Hex 00h ; Character 0x63 c .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100000 ; Hex 60h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x64 d .DB %00000110 ; Hex 06h .DB %00000110 ; Hex 06h .DB %00111110 ; Hex 3Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000000 ; Hex 00h ; Character 0x65 e .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01111110 ; Hex 7Eh .DB %01100000 ; Hex 60h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x66 f .DB %00011100 ; Hex 1Ch .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %01111100 ; Hex 7Ch .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00000000 ; Hex 00h ; Character 0x67 g .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111110 ; Hex 3Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000110 ; Hex 06h .DB %00111100 ; Hex 3Ch ; Character 0x68 h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x69 i .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00111000 ; Hex 38h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x6A j .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00111000 ; Hex 38h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %01110000 ; Hex 70h ; Character 0x6B k .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100110 ; Hex 66h .DB %01101100 ; Hex 6Ch .DB %01111000 ; Hex 78h .DB %01101100 ; Hex 6Ch .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x6C l .DB %00111000 ; Hex 38h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x6D m .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00110110 ; Hex 36h .DB %01111111 ; Hex 7Fh .DB %01101011 ; Hex 6Bh .DB %01101011 ; Hex 6Bh .DB %01100011 ; Hex 63h .DB %00000000 ; Hex 00h ; Character 0x6E n .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x6F o .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00000000 ; Hex 00h ; Character 0x70 p .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01111100 ; Hex 7Ch .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01111100 ; Hex 7Ch .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h ; Character 0x71 q .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111110 ; Hex 3Eh .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000110 ; Hex 06h .DB %00000111 ; Hex 07h ; Character 0x72 r .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01101100 ; Hex 6Ch .DB %01110110 ; Hex 76h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %01100000 ; Hex 60h .DB %00000000 ; Hex 00h ; Character 0x73 s .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00111110 ; Hex 3Eh .DB %01100000 ; Hex 60h .DB %00111100 ; Hex 3Ch .DB %00000110 ; Hex 06h .DB %01111100 ; Hex 7Ch .DB %00000000 ; Hex 00h ; Character 0x74 t .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %01111100 ; Hex 7Ch .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00110000 ; Hex 30h .DB %00011100 ; Hex 1Ch .DB %00000000 ; Hex 00h ; Character 0x75 u .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000000 ; Hex 00h ; Character 0x76 v .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x77 w .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01100011 ; Hex 63h .DB %01101011 ; Hex 6Bh .DB %01101011 ; Hex 6Bh .DB %01111111 ; Hex 7Fh .DB %00110110 ; Hex 36h .DB %00000000 ; Hex 00h ; Character 0x78 x .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01100110 ; Hex 66h .DB %00111100 ; Hex 3Ch .DB %00011000 ; Hex 18h .DB %00111100 ; Hex 3Ch .DB %01100110 ; Hex 66h .DB %00000000 ; Hex 00h ; Character 0x79 y .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %01100110 ; Hex 66h .DB %00111110 ; Hex 3Eh .DB %00000110 ; Hex 06h .DB %00111100 ; Hex 3Ch ; Character 0x7A z .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %01111110 ; Hex 7Eh .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %01111110 ; Hex 7Eh .DB %00000000 ; Hex 00h ; Character 0x7B { .DB %00001100 ; Hex 0Ch .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %01110000 ; Hex 70h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00001100 ; Hex 0Ch .DB %00000000 ; Hex 00h ; Character 0x7C (OR symbol) .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00000000 ; Hex 00h ; Character 0x7D } .DB %00110000 ; Hex 30h .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00001110 ; Hex 0Eh .DB %00011000 ; Hex 18h .DB %00011000 ; Hex 18h .DB %00110000 ; Hex 30h .DB %00000000 ; Hex 00h ; Character 0x7E ~ .DB %00110001 ; Hex 31h .DB %01101011 ; Hex 6Bh .DB %01000110 ; Hex 46h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h .DB %00000000 ; Hex 00h ; Character 0x7F (block) .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh .DB %11111111 ; Hex FFh ;------------------------------------------ ; ; That's all folks! Now that Acorn is no ; longer with us (RIP), it should be safe ; to use this font in any homebrew ; projects. ; ; Anyone is welcome to distribute and use ; this source file for whatever purpose ; they wish. ; ; ; Best wishes, ; ; Mike G. (mike@mikeg2.freeserve.co.uk) ; ; 4th March 2001 ; ; SMS Power! - www.smspower.org ; SMSReader - www.smspower.org/smsreader/ ; ; My Home Page: www.mikeg2.freeserve.co.uk ; ;------------------------------------------ ; End of Mike G's font. FontDataEnd: ",16168,True,5249.960885207654,median "/* Clock.ino Demonstrates a clock-like display with a very huge font. Also shows usage of u8x8_u8toa(). Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) Copyright (c) 2016, olikraus@gmail.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif #ifdef U8X8_HAVE_HW_I2C #include #endif /* U8glib Example Overview: Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards. U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only. This is a page buffer example. */ // Please UNCOMMENT one of the contructor lines below // U8g2 Contructor List (Picture Loop Page Buffer) // The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp // Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected //U8G2_NULL u8g2(U8G2_R0); // null device, a 8x8 pixel display which does nothing //U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition) //U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_128X64_ALT0_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping //U8G2_SSD1306_128X64_NONAME_1_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8G2_SSD1306_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8G2_SSD1306_128X64_ALT0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8G2_SH1106_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SH1106_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8G2_SH1106_128X64_WINSTAR_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but uses updated SH1106 init sequence //U8G2_SH1106_72X40_WISE_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1107_64X128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1107_128X128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1107_128X128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); //U8G2_SH1107_SEEED_96X96_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1108_160X160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1122_256X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8G2_SSD1306_64X48_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.66"" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered //U8G2_SSD1306_48X64_WINSTAR_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_64X32_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_64X32_1F_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_96X16_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.69"" OLED //U8G2_SSD1322_NHD_256X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1322_NHD_256X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1322_NHD_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1322_NHD_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1325_NHD_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1325_NHD_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1326_ER_256X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // experimental driver for ER-OLED018-1 //U8G2_SSD1327_SEEED_96X96_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8G2_SSD1327_SEEED_96X96_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8G2_SSD1327_EA_W128128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_EA_W128128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_EA_W128128_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1327_EA_W128128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1327_MIDAS_128X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_MIDAS_128X128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1329_128X96_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1329_128X96_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X32_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X32_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X64_ADAFRUIT_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X64_ADAFRUIT_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME0_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME2_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME2_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_LD7032_60X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 9, /* dc=*/ 10, /* reset=*/ 8); // SW SPI Nano Board //U8G2_LD7032_60X32_1_4W_SW_I2C u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE); // NOT TESTED! //U8G2_UC1701_EA_DOGS102_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1701_EA_DOGS102_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_PCD8544_84X48_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8G2_PCF8812_96X65_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8G2_PCF8812_96X65_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8G2_HX1230_96X68_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_HX1230_96X68_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_KS0108_128X64_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8G2_KS0108_ERM19264_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ 16, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8G2_ST7920_192X32_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ U8X8_PIN_NONE, /*dc=*/ 17, /*reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_192X32_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18 /* A4 */, /*cs=*/ U8X8_PIN_NONE, /*dc/rs=*/ 17 /* A3 */, /*reset=*/ 15 /* A1 */); // Remember to set R/W to 0 //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8); //U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_64128N_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_64128N_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM132_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8G2_ST7565_EA_DOGM132_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8G2_ST7565_ZOLEN_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ZOLEN_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_LM6059_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8G2_ST7565_LM6059_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8G2_ST7565_LX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_LX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ERC12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12832_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12832_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_JLX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_JLX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_PI_132X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8G2_ST7567_PI_132X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8G2_ST7567_JLX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_JLX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064I_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_ENH_DG128064I_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX172104_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX172104_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX256128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 9, /* data=*/ 8, /* cs=*/ 7, /* dc=*/ 6, /* reset=*/ 5); // MKR Zero, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 6, /* reset=*/ 5); // MKR Zero, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX256160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Uno, Enable U8g2 16 bit mode for this display //U8G2_ST75256_JLX240160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX240160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST75256_JLX25664_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, enable U8g2 16 bit mode for this display //U8G2_NT7534_TG12864R_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_NT7534_TG12864R_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7588_JLX12864_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ 5); //U8G2_ST7588_JLX12864_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ 5); //U8G2_IST3020_ERC19264_1_6800 u8g2(U8G2_R0, 44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 28, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect WR pin with GND //U8G2_IST3020_ERC19264_1_8080 u8g2(U8G2_R0, 44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 29, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect RD pin with 3.3V //U8G2_IST3020_ERC19264_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_LC7981_160X80_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_160X160_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_240X64_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_SED1520_122X32_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*dc=*/ A0, /*e1=*/ A3, /*e2=*/ A2, /* reset=*/ A4); // Set R/W to low! //U8G2_T6963_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_T6963_256X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_T6963_160X80_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_SED1330_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0 //U8G2_SED1330_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E //U8G2_RA8835_NHD_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0 //U8G2_RA8835_NHD_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E //U8G2_UC1601_128X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1601_128X32_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_UC1604_JLX19264_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1604_JLX19264_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1608_ERC24064_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup //U8G2_UC1608_ERC240120_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1608_240X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup //U8G2_UC1610_EA_DOGXL160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8G2_UC1610_EA_DOGXL160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8G2_UC1611_EA_DOGM240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board //U8G2_UC1611_EA_DOGM240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8G2_UC1611_EA_DOGXL240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board //U8G2_UC1611_EA_DOGXL240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8G2_UC1611_EW50850_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 16); // 240x160, Connect RD/WR1 pin with 3.3V, CS is aktive high //U8G2_UC1638_160X128_1_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ 2, /* dc=*/ 3, /* reset=*/ 4); // Not tested //U8G2_SSD1606_172X72_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display //U8G2_SSD1607_200X200_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT from embedded artists //U8G2_SSD1607_GD_200X200_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Good Display //U8G2_IL3820_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // WaveShare 2.9 inch eInk/ePaper Display, enable 16 bit mode for this display! //U8G2_IL3820_V2_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // ePaper Display, lesser flickering and faster speed, enable 16 bit mode for this display! // End of constructor list void setup(void) { /* U8g2 Project: SSD1306 Test Board */ //pinMode(10, OUTPUT); //pinMode(9, OUTPUT); //digitalWrite(10, 0); //digitalWrite(9, 0); /* U8g2 Project: T6963 Test Board */ //pinMode(18, OUTPUT); //digitalWrite(18, 1); /* U8g2 Project: KS0108 Test Board */ //pinMode(16, OUTPUT); //digitalWrite(16, 0); /* U8g2 Project: LC7981 Test Board, connect RW to GND */ //pinMode(17, OUTPUT); //digitalWrite(17, 0); /* U8g2 Project: Pax Instruments Shield: Enable Backlight */ //pinMode(6, OUTPUT); //digitalWrite(6, 0); u8g2.begin(); } uint8_t m = 24; void loop(void) { char m_str[3]; strcpy(m_str, u8x8_u8toa(m, 2)); /* convert m to a string with two digits */ u8g2.firstPage(); do { u8g2.setFont(u8g2_font_logisoso62_tn); u8g2.drawStr(0,63,""9""); u8g2.drawStr(33,63,"":""); u8g2.drawStr(50,63,m_str); } while ( u8g2.nextPage() ); delay(1000); m++; if ( m == 60 ) m = 0; } ",12198,True,3748.8378088938707,median "bits 32 %define WRK ebp ; // alias for unit workspace %define VAL esi ; // alias for unit values (transformed/untransformed) %define COM ebx ; // alias for instrument opcodes %include ""4klang.inc"" ;// conditional defines %ifdef GO4K_USE_VCO_SHAPE %define INCLUDE_WAVESHAPER %endif %ifdef GO4K_USE_DST %define INCLUDE_WAVESHAPER %endif %ifdef GO4K_USE_VCO_MOD_PM %define PHASE_RENORMALIZE %endif %ifdef GO4K_USE_VCO_PHASE_OFFSET %define PHASE_RENORMALIZE %endif %ifdef GO4K_USE_ENVELOPE_RECORDINGS %define GO4K_USE_BUFFER_RECORDINGS %endif %ifdef GO4K_USE_NOTE_RECORDINGS %define GO4K_USE_BUFFER_RECORDINGS %endif ; //======================================================================================== ; // .bss section ; //======================================================================================== %ifdef USE_SECTIONS section .g4kbss1 bss align=1 %else section .bss %endif ; // the one and only synth object %if MAX_VOICES > 1 go4k_voiceindex resd 16 %endif go4k_transformed_values resd 16 go4k_synth_wrk resb go4k_synth.size global _go4k_delay_buffer_ofs _go4k_delay_buffer_ofs resd 1 global _go4k_delay_buffer _go4k_delay_buffer resd 16*16*go4kDLL_wrk.size %ifdef AUTHORING global __4klang_current_tick __4klang_current_tick resd 0 %endif %ifdef GO4K_USE_ENVELOPE_RECORDINGS global __4klang_envelope_buffer __4klang_envelope_buffer resd ((MAX_SAMPLES)/8) ; // samples every 256 samples and stores 16*2 = 32 values %endif %ifdef GO4K_USE_NOTE_RECORDINGS global __4klang_note_buffer __4klang_note_buffer resd ((MAX_SAMPLES)/8) ; // samples every 256 samples and stores 16*2 = 32 values %endif ; //======================================================================================== ; // .g4kdat section (initialized data for go4k) ; //======================================================================================== %ifdef USE_SECTIONS section .g4kdat1 data align=1 %else section .data %endif ; // some synth constants go4k_synth_commands dd 0 dd _go4kENV_func@0 dd _go4kVCO_func@0 dd _go4kVCF_func@0 dd _go4kDST_func@0 dd _go4kDLL_func@0 dd _go4kFOP_func@0 dd _go4kFST_func@0 dd _go4kPAN_func@0 dd _go4kOUT_func@0 dd _go4kACC_func@0 dd _go4kFLD_func@0 %ifdef GO4K_USE_FSTG dd _go4kFSTG_func@0 %endif %ifdef USE_SECTIONS section .g4kdat2 data align=1 %else section .data %endif %ifdef GO4K_USE_16BIT_OUTPUT c_32767 dd 32767.0 %endif c_i128 dd 0.0078125 c_RandDiv dd 65536*32768 c_0_5 dd 0.5 %ifdef GO4K_USE_VCO_GATE c_16 dd 16.0 %endif %ifdef GO4K_USE_DLL_CHORUS DLL_DEPTH dd 1024.0 %endif %ifdef GO4K_USE_DLL_DC_FILTER c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) %else %ifdef GO4K_USE_VCO_GATE c_dc_const dd 0.99609375 ; R = 1 - (pi*2 * frequency /samplerate) %endif %endif global _RandSeed _RandSeed dd 1 c_24 dd 24 c_i12 dd 0x3DAAAAAA FREQ_NORMALIZE dd 0.000092696138 ; // 220.0/(2^(69/12)) / 44100.0 global _LFO_NORMALIZE _LFO_NORMALIZE dd DEF_LFO_NORMALIZE %ifdef GO4K_USE_GROOVE_PATTERN go4k_groove_pattern dw 0011100111001110b %endif ; //======================================================================================== ; // .crtemui section (emulates crt functions) ; //======================================================================================== %ifdef USE_SECTIONS section .crtemui code align=1 %else section .text %endif export_func FloatRandomNumber@0 push eax imul eax,dword [_RandSeed],16007 mov dword [_RandSeed], eax fild dword [_RandSeed] fidiv dword [c_RandDiv] pop eax ret ; //======================================================================================== ; // .g4kcod* sections (code for go4k) ; //======================================================================================== %ifdef INCLUDE_WAVESHAPER %ifdef USE_SECTIONS section .g4kcod2 code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Waveshaper function ; //---------------------------------------------------------------------------------------- ; // Input : st0 : shaping coeff ; // st1 : input ; // Output: st0 : result ; //---------------------------------------------------------------------------------------- go4kWaveshaper: %ifdef GO4K_USE_WAVESHAPER_CLIP fxch fld1 ; // 1 val fucomi st1 ; // 1 val jbe short go4kWaveshaper_clip fchs ; // -1 val fucomi st1 ; // -1 val fcmovb st0, st1 ; // val -1 (if val > -1) go4kWaveshaper_clip: fstp st1 ; // newval fxch %endif fsub dword [c_0_5] fadd st0 fst dword [esp-4] ; // amnt in fadd st0 ; // 2*amnt in fld1 ; // 1 2*amnt in fsub dword [esp-4] ; // 1-amnt 2*amnt in fdivp st1, st0 ; // k in fld st1 ; // sin k in fabs ; // a(in) k in fmul st1 ; // k*a(in) k in fld1 faddp st1, st0 ; // 1+k*a(in) k in fxch st1 ; // k 1+k*a(in) in fld1 faddp st1, st0 ; // 1+k 1+k*a(in) in fmulp st2 ; // 1+k*a(in) (1+k)*in fdivp st1, st0 ; // out ret %endif %ifdef USE_SECTIONS section .g4kcod3 code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // unit values preparation/transform ; //---------------------------------------------------------------------------------------- go4kTransformValues: push ecx xor ecx, ecx xor eax, eax mov edx, go4k_transformed_values go4kTransformValues_loop: lodsb push eax fild dword [esp] fmul dword [c_i128] fstp dword [edx+ecx*4] pop eax inc ecx cmp ecx, dword [esp+8] jl go4kTransformValues_loop pop ecx ret 4 %ifdef USE_SECTIONS section .g4kcod4 code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Envelope param mapping ; //---------------------------------------------------------------------------------------- go4kENVMap: fld dword [edx+eax*4] %ifdef GO4K_USE_ENV_MOD_ADR fadd dword [WRK+go4kENV_wrk.am+eax*4] %endif fimul dword [c_24] fchs ; //---------------------------------------------------------------------------------------- ; // Power function (2^x) ; //---------------------------------------------------------------------------------------- ; // Input : st0 : base ; // st1 : exponent ; // Output: st0 : result ; //---------------------------------------------------------------------------------------- export_func Power@0 ; // base exp fld1 fadd st0 fyl2x ; // log2_base fld1 ; // 1 log2_base fld st1 ; // log2_base 1 log2_base fprem ; // (frac)log2_base 1 log2_base f2xm1 ; // 2 ^ '' - 1 1 log2_base faddp st1, st0 ; // 2 ^ '' (int)log2_base fscale fstp st1 ret %ifdef USE_SECTIONS section .g4kcoda code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // ENV Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kENV_func@0 push 5 call go4kTransformValues %ifdef GO4K_USE_ENV_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kENV_func_do fldz ret %endif go4kENV_func_do: mov eax, dword [ecx-8] ; // is the instrument in release mode (note off)? test eax, eax je go4kENV_func_process mov dword [WRK+go4kENV_wrk.state], ENV_STATE_RELEASE go4kENV_func_process: mov eax, dword [WRK+go4kENV_wrk.state] fld dword [WRK+go4kENV_wrk.level] ; // val - ; // check for sustain state cmp al, ENV_STATE_SUSTAIN je short go4kENV_func_leave2 go4kENV_func_attac: cmp al, ENV_STATE_ATTAC jne short go4kENV_func_decay call go4kENVMap ; // newval faddp st1, st0 ; // check for end of attac fld1 ; // 1 newval fucomi st1 ; // 1 newval fcmovnb st0, st1 ; // newval 1 (if newval < 1) jbe short go4kENV_func_statechange go4kENV_func_decay: cmp al, ENV_STATE_DECAY jne short go4kENV_func_release call go4kENVMap ; // newval fsubp st1, st0 ; // check for end of decay fld dword [edx+go4kENV_val.sustain] ; // sustain newval fucomi st1 ; // sustain newval fcmovb st0, st1 ; // newval sustain (if newval > sustain) jnc short go4kENV_func_statechange go4kENV_func_release: ; // release state? cmp al, ENV_STATE_RELEASE jne short go4kENV_func_leave call go4kENVMap ; // newval fsubp st1, st0 ; // check for end of release fldz ; // 0 newval fucomi st1 ; // 0 newval fcmovb st0, st1 ; // newval 0 (if newval > 0) jc short go4kENV_func_leave go4kENV_func_statechange: ; // newval inc dword [WRK+go4kENV_wrk.state] go4kENV_func_leave: ; // newval bla fstp st1 ; // store new env value fst dword [WRK+go4kENV_wrk.level] go4kENV_func_leave2: ; // mul by gain %ifdef GO4K_USE_ENV_MOD_GM fld dword [edx+go4kENV_val.gain] fadd dword [WRK+go4kENV_wrk.gm] fmulp st1, st0 %else fmul dword [edx+go4kENV_val.gain] %endif ret ; //---------------------------------------------------------------------------------------- ; // VCO Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- %ifdef USE_SECTIONS section .g4kcodp code align=1 %else section .text %endif go4kVCO_pulse: fucomi st1 ; // c p fld1 jnc short go4kVCO_func_pulse_up ; // +1 c p fchs ; // -1 c p go4kVCO_func_pulse_up: fstp st1 ; // +-1 p fstp st1 ; // +-1 ret %ifdef USE_SECTIONS section .g4kcodt code align=1 %else section .text %endif go4kVCO_trisaw: fucomi st1 ; // c p jnc short go4kVCO_func_trisaw_up fld1 ; // 1 c p fsubr st2, st0 ; // 1 c 1-p fsubrp st1, st0 ; // 1-c 1-p go4kVCO_func_trisaw_up: fdivp st1, st0 ; // tp'/tc fadd st0 ; // 2*'' fld1 ; // 1 2*'' fsubp st1, st0 ; // 2*''-1 ret %ifdef USE_SECTIONS section .g4kcods code align=1 %else section .text %endif go4kVCO_sine: fucomi st1 ; // c p jnc short go4kVCO_func_sine_do fstp st1 fsub st0, st0 ; // 0 ret go4kVCO_func_sine_do fdivp st1, st0 ; // p/c fldpi ; // pi p fadd st0 ; // 2*pi p fmulp st1, st0 ; // 2*pi*p fsin ; // sin(2*pi*p) ret %ifdef GO4K_USE_VCO_GATE %ifdef USE_SECTIONS section .g4kcodq code align=1 %else section .text %endif go4kVCO_gate: fxch ; // p c fstp st1 ; // p fmul dword [c_16] ; // p' push eax push eax fistp dword [esp] ; // - fld1 ; // 1 pop eax and al, 0xf bt word [VAL-5],ax jc go4kVCO_gate_bit fsub st0, st0 ; // 0 go4kVCO_gate_bit: fld dword [WRK+go4kVCO_wrk.cm] ; // f x fsub st1 ; // f-x x fmul dword [c_dc_const] ; // c(f-x) x faddp st1, st0 ; // x' fst dword [WRK+go4kVCO_wrk.cm] pop eax ret %endif %ifdef USE_SECTIONS section .g4kcodb code align=1 %else section .text %endif export_func go4kVCO_func@0 %ifdef GO4K_USE_VCO_PHASE_OFFSET %ifdef GO4K_USE_VCO_SHAPE %ifdef GO4K_USE_VCO_GATE push 8 %else push 7 %endif %else %ifdef GO4K_USE_VCO_GATE push 7 %else push 6 %endif %endif %else %ifdef GO4K_USE_VCO_SHAPE %ifdef GO4K_USE_VCO_GATE push 7 %else push 6 %endif %else %ifdef GO4K_USE_VCO_GATE push 6 %else push 5 %endif %endif %endif call go4kTransformValues %ifdef GO4K_USE_VCO_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kVCO_func_do %ifdef GO4K_USE_VCO_STEREO movzx eax, byte [VAL-1] ; // get flags and check for stereo test al, byte VCO_STEREO jz short go4kVCO_func_nostereoout fldz go4kVCO_func_nostereoout: %endif fldz ret go4kVCO_func_do: %endif movzx eax, byte [VAL-1] ; // get flags %ifdef GO4K_USE_VCO_STEREO test al, byte VCO_STEREO jz short go4kVCO_func_nopswap fld dword [WRK+go4kVCO_wrk.phase] ;// swap left/right phase values for first stereo run fld dword [WRK+go4kVCO_wrk.phase2] fstp dword [WRK+go4kVCO_wrk.phase] fstp dword [WRK+go4kVCO_wrk.phase2] go4kVCO_func_nopswap: %endif go4kVCO_func_process: fld dword [edx+go4kVCO_val.transpose] fsub dword [c_0_5] %ifdef GO4K_USE_VCO_MOD_TM fadd dword [WRK+go4kVCO_wrk.tm] %endif fdiv dword [c_i128] fld dword [edx+go4kVCO_val.detune] fsub dword [c_0_5] fadd st0 %ifdef GO4K_USE_VCO_STEREO test al, byte VCO_STEREO jz short go4kVCO_func_nodswap fchs ;// negate detune for stereo go4kVCO_func_nodswap: %endif faddp st1 %ifdef GO4K_USE_VCO_MOD_DM fadd dword [WRK+go4kVCO_wrk.dm] %endif ; // st0 now contains the transpose+detune offset test al, byte LFO jnz go4kVCO_func_skipnote fiadd dword [ecx-4] ; // st0 is note, st1 is t+d offset go4kVCO_func_skipnote: fmul dword [c_i12] call _Power@0 test al, byte LFO jz short go4kVCO_func_normalize_note fmul dword [_LFO_NORMALIZE] ; // st0 is now frequency for lfo jmp short go4kVCO_func_normalized go4kVCO_func_normalize_note: fmul dword [FREQ_NORMALIZE] ; // st0 is now frequency go4kVCO_func_normalized: fadd dword [WRK+go4kVCO_wrk.phase] %ifdef GO4K_USE_VCO_MOD_FM fadd dword [WRK+go4kVCO_wrk.fm] %endif fld1 fadd st1, st0 fxch fprem fstp st1 fst dword [WRK+go4kVCO_wrk.phase] %ifdef GO4K_USE_VCO_MOD_PM fadd dword [WRK+go4kVCO_wrk.pm] %endif %ifdef GO4K_USE_VCO_PHASE_OFFSET fadd dword [edx+go4kVCO_val.phaseofs] %endif %ifdef PHASE_RENORMALIZE fld1 fadd st1, st0 fxch fprem fstp st1 ; // p %endif fld dword [edx+go4kVCO_val.color] ; // c p %ifdef GO4K_USE_VCO_MOD_CM fadd dword [WRK+go4kVCO_wrk.cm] ; // c p %endif go4kVCO_func_sine: test al, byte SINE jz short go4kVCO_func_trisaw call go4kVCO_sine go4kVCO_func_trisaw: test al, byte TRISAW jz short go4kVCO_func_pulse call go4kVCO_trisaw go4kVCO_func_pulse: test al, byte PULSE %ifdef GO4K_USE_VCO_GATE jz short go4kVCO_func_gate %else jz short go4kVCO_func_noise %endif call go4kVCO_pulse %ifdef GO4K_USE_VCO_GATE go4kVCO_func_gate: test al, byte GATE jz short go4kVCO_func_noise call go4kVCO_gate %endif go4kVCO_func_noise: test al, byte NOISE jz short go4kVCO_func_end call _FloatRandomNumber@0 fstp st1 fstp st1 go4kVCO_func_end: %ifdef GO4K_USE_VCO_SHAPE fld dword [edx+go4kVCO_val.shape] %ifdef GO4K_USE_VCO_MOD_SM fadd dword [WRK+go4kVCO_wrk.sm] %endif call go4kWaveshaper %endif fld dword [edx+go4kVCO_val.gain] %ifdef GO4K_USE_VCO_MOD_GM fadd dword [WRK+go4kVCO_wrk.gm] %endif fmulp st1, st0 %ifdef GO4K_USE_VCO_STEREO test al, byte VCO_STEREO jz short go4kVCO_func_stereodone sub al, byte VCO_STEREO fld dword [WRK+go4kVCO_wrk.phase] ;// swap left/right phase values again for second stereo run fld dword [WRK+go4kVCO_wrk.phase2] fstp dword [WRK+go4kVCO_wrk.phase] fstp dword [WRK+go4kVCO_wrk.phase2] jmp go4kVCO_func_process go4kVCO_func_stereodone: %endif ret %ifdef USE_SECTIONS section .g4kcodc code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // VCF Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kVCF_func@0 push 3 call go4kTransformValues %ifdef GO4K_USE_VCF_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kVCF_func_do ret go4kVCF_func_do: %endif movzx eax, byte [VAL-1] ; // get type flag fld dword [edx+go4kVCF_val.res] ; // r in %ifdef GO4K_USE_VCF_MOD_RM fadd dword [WRK+go4kVCF_wrk.rm] %endif fstp dword [esp-8] fld dword [edx+go4kVCF_val.freq] ; // f in %ifdef GO4K_USE_VCF_MOD_FM fadd dword [WRK+go4kVCF_wrk.fm] %endif fmul st0, st0 ; // square the input so we never get negative and also have a smoother behaviour in the lower frequencies fstp dword [esp-4] ; // in %ifdef GO4K_USE_VCF_STEREO test al, byte STEREO jz short go4kVCF_func_process add WRK, go4kVCF_wrk.low2 go4kVCF_func_stereoloop: ; // switch channels fxch st1 ; // inr inl %endif go4kVCF_func_process: fld dword [esp-8] fld dword [esp-4] fmul dword [WRK+go4kVCF_wrk.band] ; // f*b r in fadd dword [WRK+go4kVCF_wrk.low] ; // l' r in fst dword [WRK+go4kVCF_wrk.low] ; // l' r in fsubp st2, st0 ; // r in-l' fmul dword [WRK+go4kVCF_wrk.band] ; // r*b in-l' fsubp st1, st0 ; // h' fst dword [WRK+go4kVCF_wrk.high] ; // h' fmul dword [esp-4] ; // h'*f fadd dword [WRK+go4kVCF_wrk.band] ; // b' fstp dword [WRK+go4kVCF_wrk.band] fldz go4kVCF_func_low: test al, byte LOWPASS jz short go4kVCF_func_high fadd dword [WRK+go4kVCF_wrk.low] go4kVCF_func_high: %ifdef GO4K_USE_VCF_HIGH test al, byte HIGHPASS jz short go4kVCF_func_band fadd dword [WRK+go4kVCF_wrk.high] %endif go4kVCF_func_band: %ifdef GO4K_USE_VCF_BAND test al, byte BANDPASS jz short go4kVCF_func_peak fadd dword [WRK+go4kVCF_wrk.band] %endif go4kVCF_func_peak: %ifdef GO4K_USE_VCF_PEAK test al, byte PEAK jz short go4kVCF_func_processdone fadd dword [WRK+go4kVCF_wrk.low] fsub dword [WRK+go4kVCF_wrk.high] %endif go4kVCF_func_processdone: %ifdef GO4K_USE_VCF_STEREO test al, byte STEREO ; // outr inl jz short go4kVCF_func_end sub al, byte STEREO sub WRK, go4kVCF_wrk.low2 jmp go4kVCF_func_stereoloop %endif go4kVCF_func_end: ; // value - - - - ret %ifdef USE_SECTIONS section .g4kcodd code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // DST Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kDST_func@0 %ifdef GO4K_USE_DST %ifdef GO4K_USE_DST_SH %ifdef GO4K_USE_DST_STEREO push 3 %else push 2 %endif %else %ifdef GO4K_USE_DST_STEREO push 2 %else push 1 %endif %endif call go4kTransformValues %ifdef GO4K_USE_DST_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kDST_func_do ret go4kDST_func_do: %endif movzx eax, byte [VAL-1] ; // get type flag %ifdef GO4K_USE_DST_SH fld dword [edx+go4kDST_val.snhfreq] ; // snh in %ifdef GO4K_USE_DST_MOD_SH fadd dword [WRK+go4kDST_wrk.sm] ; // snh' in %endif fmul st0, st0 ; // square the input so we never get negative and also have a smoother behaviour in the lower frequencies fchs fadd dword [WRK+go4kDST_wrk.snhphase]; // snh' in fst dword [WRK+go4kDST_wrk.snhphase] fldz ; // 0 snh' in fucomip st1 ; // 0 snh' in jc short go4kDST_func_hold fld1 ; // 1 snh' in faddp st1, st0 ; // 1+snh' in fstp dword [WRK+go4kDST_wrk.snhphase]; // in %endif ; // calc pregain and postgain %ifdef GO4K_USE_DST_STEREO test al, byte STEREO ; // outr inl jz short go4kDST_func_mono fxch st1 ; // inr inl fld dword [edx+go4kDST_val.drive] ; // drive inr inl %ifdef GO4K_USE_DST_MOD_DM fadd dword [WRK+go4kDST_wrk.dm] %endif call go4kWaveshaper ; // outr inl %ifdef GO4K_USE_DST_SH fst dword [WRK+go4kDST_wrk.out2] ; // outr inl %endif fxch st1 ; // inl outr go4kDST_func_mono: %endif fld dword [edx+go4kDST_val.drive] ; // drive in %ifdef GO4K_USE_DST_MOD_DM fadd dword [WRK+go4kDST_wrk.dm] %endif call go4kWaveshaper ; // out %ifdef GO4K_USE_DST_SH fst dword [WRK+go4kDST_wrk.out] ; // out' %endif ret ; // out' %ifdef GO4K_USE_DST_SH go4kDST_func_hold: fstp st0 ; // in fstp st0 %ifdef GO4K_USE_DST_STEREO test al, byte STEREO ; // outr inl jz short go4kDST_func_monohold fld dword [WRK+go4kDST_wrk.out2] ; // out2 go4kDST_func_monohold: %endif fld dword [WRK+go4kDST_wrk.out] ; // out ret %endif %endif %ifdef USE_SECTIONS section .g4kcodf code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // DLL Tick ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kDLL_func@0 %ifdef GO4K_USE_DLL %ifdef GO4K_USE_DLL_CHORUS %ifdef GO4K_USE_DLL_DAMP push 8 %else push 7 %endif %else %ifdef GO4K_USE_DLL_DAMP push 6 %else push 5 %endif %endif call go4kTransformValues pushad movzx ebx, byte [VAL-(go4kDLL_val.size-go4kDLL_val.delay)/4] ;// delay length index %ifdef GO4K_USE_DLL_NOTE_SYNC test ebx, ebx jne go4kDLL_func_process fld1 fild dword [ecx-4] ; // load note freq fmul dword [c_i12] call _Power@0 fmul dword [FREQ_NORMALIZE] ; // normalize fdivp st1, st0 ; // invert to get numer of samples fistp word [_go4k_delay_times+ebx*2] ; store current comb size %endif go4kDLL_func_process: mov ecx, eax ;// ecx is delay counter %ifdef GO4K_USE_DLL_MOD mov edi, WRK ;// edi is modulation workspace %endif mov WRK, dword [_go4k_delay_buffer_ofs] ;// ebp is current delay fld st0 ;// in in %ifdef GO4K_USE_DLL_MOD_IM fld dword [edx+go4kDLL_val.dry] ;// dry in in fadd dword [edi+go4kDLL_wrk2.im] ;// dry' in in fmulp st1, st0 ;// out in %else fmul dword [edx+go4kDLL_val.dry] ;// out in %endif fxch ;// in out %ifdef GO4K_USE_DLL_MOD_PM fld dword [edx+go4kDLL_val.pregain] ;// pg in out fadd dword [edi+go4kDLL_wrk2.pm] ;// pg' in out fmul st0, st0 ;// pg'' in out fmulp st1, st0 ;// in' out %else fmul dword [edx+go4kDLL_val.pregain] ;// in' out fmul dword [edx+go4kDLL_val.pregain] ;// in' out %endif %ifdef GO4K_USE_DLL_CHORUS ;// update saw lfo for chorus/flanger fld dword [edx+go4kDLL_val.freq] ;// f in' out %ifdef GO4K_USE_DLL_MOD_SM fadd dword [edi+go4kDLL_wrk2.sm] ;// f' in' out %endif fmul st0, st0 fmul st0, st0 fdiv dword [DLL_DEPTH] fadd dword [WRK+go4kDLL_wrk.phase] ;// p' in' out ;// clamp phase to 0,1 (only in editor, since delay can be active quite long) %ifdef GO4K_USE_DLL_CHORUS_CLAMP fld1 ;// 1 p' in' out fadd st1, st0 ;// 1 1+p' in' out fxch ;// 1+p' 1 in' out fprem ;// p'' 1 in' out fstp st1 ;// p'' in' out %endif fst dword [WRK+go4kDLL_wrk.phase] ;// get current sine value fldpi ; // pi p in' out fadd st0 ; // 2*pi p in' out fmulp st1, st0 ; // 2*pi*p in' out fsin ; // sin in' out fld1 ; // 1 sin in' out faddp st1, st0 ; // 1+sin in' out ;// mul with depth and convert to samples fld dword [edx+go4kDLL_val.depth] ; // d 1+sin in' out %ifdef GO4K_USE_DLL_MOD_AM fadd dword [edi+go4kDLL_wrk2.am] ; // d' 1+sin in' out %endif fmul st0, st0 fmul st0, st0 fmul dword [DLL_DEPTH] fmulp st1, st0 fistp dword [esp-4] ; // in' out %endif go4kDLL_func_loop: movzx esi, word [_go4k_delay_times+ebx*2] ; fetch comb size mov eax, dword [WRK+go4kDLL_wrk.index] ;// eax is current comb index %ifdef GO4K_USE_DLL_CHORUS ;// add lfo offset and wrap buffer add eax, dword [esp-4] cmp eax, esi jl short go4kDLL_func_buffer_nowrap1 sub eax, esi go4kDLL_func_buffer_nowrap1: %endif fld dword [WRK+eax*4+go4kDLL_wrk.buffer];// cout in' out %ifdef GO4K_USE_DLL_CHORUS mov eax, dword [WRK+go4kDLL_wrk.index] %endif ;// add comb output to current output fadd st2, st0 ;// cout in' out' %ifdef GO4K_USE_DLL_DAMP fld1 ;// 1 cout in' out' fsub dword [edx+go4kDLL_val.damp] ;// 1-damp cout in' out' %ifdef GO4K_USE_DLL_MOD_DM fsub dword [edi+go4kDLL_wrk2.dm] ;// 1-damp' cout in' out' %endif fmulp st1, st0 ;// cout*d2 in' out' fld dword [edx+go4kDLL_val.damp] ;// d1 cout*d2 in' out' %ifdef GO4K_USE_DLL_MOD_DM fadd dword [edi+go4kDLL_wrk2.dm] ;// d1' cout*d2 in' out' %endif fmul dword [WRK+go4kDLL_wrk.store] ;// store*d1 cout*d2 in' out' faddp st1, st0 ;// store' in' out' fst dword [WRK+go4kDLL_wrk.store] ;// store' in' out' %endif %ifdef GO4K_USE_DLL_MOD_FM fld dword [edx+go4kDLL_val.feedback] ;// fb cout in' out' fadd dword [edi+go4kDLL_wrk2.fm] ;// fb' cout in' out' fmulp st1, st0 ;// cout*fb' in' out' %else fmul dword [edx+go4kDLL_val.feedback] ;// cout*fb in' out' %endif %ifdef GO4K_USE_DLL_DC_FILTER fadd st0, st1 ;// store in' out' fstp dword [WRK+eax*4+go4kDLL_wrk.buffer];// in' out' %else fsub st0, st1 ;// store in' out' fstp dword [WRK+eax*4+go4kDLL_wrk.buffer];// in' out' fneg %endif ;// wrap comb buffer pos inc eax cmp eax, esi jl short go4kDLL_func_buffer_nowrap2 %ifdef GO4K_USE_DLL_CHORUS sub eax, esi %else xor eax, eax %endif go4kDLL_func_buffer_nowrap2: mov dword [WRK+go4kDLL_wrk.index], eax ;// increment buffer pointer to next buffer inc ebx ;// go to next delay length index add WRK, go4kDLL_wrk.size ;// go to next delay mov dword [_go4k_delay_buffer_ofs], WRK ;// store next delay offset loopne go4kDLL_func_loop fstp st0 ;// out' ;// process a dc filter to prevent heavy offsets in reverb ;// we're using the dc filter variables from the next delay line here, but doesnt hurt anyway %ifdef GO4K_USE_DLL_DC_FILTER ; y(n) = x(n) - x(n-1) + R * y(n-1) fld dword [WRK+go4kDLL_wrk.dcout] ;// dco out' fmul dword [c_dc_const] ;// dcc*dco out' fsub dword [WRK+go4kDLL_wrk.dcin] ;// dcc*dco-dci out' fxch ;// out' dcc*dco-dci fst dword [WRK+go4kDLL_wrk.dcin] ;// out' dcc*dco-dci faddp st1 ;// out' %ifdef GO4K_USE_UNDENORMALIZE fadd dword [c_0_5] ;// add and sub small offset to prevent denormalization fsub dword [c_0_5] %endif fst dword [WRK+go4kDLL_wrk.dcout] %endif popad ret %endif %ifdef USE_SECTIONS section .g4kcodg code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FOP Tick (various fp stack based operations) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFOP_func@0 push 1 call go4kTransformValues go4kFOP_func_pop: dec eax jnz go4kFOP_func_addp fstp st0 ret go4kFOP_func_addp: dec eax jnz go4kFOP_func_mulp faddp st1, st0 ret go4kFOP_func_mulp: dec eax jnz go4kFOP_func_push fmulp st1, st0 ret go4kFOP_func_push: dec eax jnz go4kFOP_func_xch fld st0 ret go4kFOP_func_xch: dec eax jnz go4kFOP_func_add fxch ret go4kFOP_func_add: dec eax jnz go4kFOP_func_mul fadd st1 ret go4kFOP_func_mul: dec eax jnz go4kFOP_func_addp2 fmul st1 ret go4kFOP_func_addp2: dec eax jnz go4kFOP_func_loadnote faddp st2, st0 faddp st2, st0 ret go4kFOP_func_loadnote: dec eax jnz go4kFOP_func_mulp2 fild dword [ecx-4] fmul dword [c_i128] ret go4kFOP_func_mulp2: fmulp st2, st0 fmulp st2, st0 ret %ifdef USE_SECTIONS section .g4kcodh code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FST Tick (stores a value somewhere in the local workspace) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFST_func@0 push 1 call go4kTransformValues fld dword [edx+go4kFST_val.amount] fsub dword [c_0_5] fadd st0 fmul st1 lodsw and eax, 0x00003fff ; // eax is destination slot test word [VAL-2], FST_ADD jz go4kFST_func_set fadd dword [ecx+eax*4] go4kFST_func_set: fstp dword [ecx+eax*4] test word [VAL-2], FST_POP jz go4kFST_func_done fstp st0 go4kFST_func_done: ret %ifdef USE_SECTIONS section .g4kcodm code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FLD Tick (load a value on stack, optionally add a modulation signal beforehand) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : signal-signal*pan , signal*pan ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFLD_func@0 ;// in main env %ifdef GO4K_USE_FLD push 1 call go4kTransformValues fld dword [edx+go4kFLD_val.value] ;// value in fsub dword [c_0_5] fadd st0 %ifdef GO4K_USE_FLD_MOD_VM fadd dword [WRK+go4kFLD_wrk.vm] ;// value' in %endif %endif ret %ifdef GO4K_USE_FSTG %ifdef USE_SECTIONS section .g4kcodi code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // FSTG Tick (stores a value anywhere in the synth (and in each voice)) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kFSTG_func@0 push 1 call go4kTransformValues %ifdef GO4K_USE_FSTG_CHECK ; check if current note still active mov eax, dword [ecx-4] test eax, eax jne go4kFSTG_func_do lodsw jmp go4kFSTG_func_testpop go4kFSTG_func_do: %endif fld dword [edx+go4kFST_val.amount] fsub dword [c_0_5] fadd st0 fmul st1 lodsw and eax, 0x00003fff ; // eax is destination slot test word [VAL-2], FST_ADD jz go4kFSTG_func_set fadd dword [go4k_synth_wrk+eax*4] go4kFSTG_func_set: %if MAX_VOICES > 1 fst dword [go4k_synth_wrk+eax*4] fstp dword [go4k_synth_wrk+eax*4+go4k_instrument.size] %else fstp dword [go4k_synth_wrk+eax*4] %endif go4kFSTG_func_testpop: test word [VAL-2], FST_POP jz go4kFSTG_func_done fstp st0 go4kFSTG_func_done: ret %endif %ifdef USE_SECTIONS section .g4kcodj code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // PAN Tick (multiplies signal with main envelope and converts to stereo) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : signal-signal*pan , signal*pan ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kPAN_func@0 ;// in main env %ifdef GO4K_USE_PAN push 1 call go4kTransformValues fld dword [edx+go4kPAN_val.panning] ;// pan in %ifdef GO4K_USE_PAN_MOD fadd dword [WRK+go4kPAN_wrk.pm] ;// pan in %endif fmul st1 ;// r in fsub st1, st0 ;// r l fxch ;// l r %else fmul dword [c_0_5] fld st0 %endif ret %ifdef USE_SECTIONS section .g4kcodk code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // OUT Tick ( stores stereo signal pair in temp buffers of the instrument) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- export_func go4kOUT_func@0 ;// l r %ifdef GO4K_USE_GLOBAL_DLL push 2 call go4kTransformValues pushad lea edi, [ecx+MAX_UNITS*MAX_UNIT_SLOTS*4] fld st1 ;// r l r fld st1 ;// l r l r fld dword [edx+go4kOUT_val.auxsend] ;// as l r l r %ifdef GO4K_USE_OUT_MOD_AM fadd dword [WRK+go4kOUT_wrk.am] ;// am l r l r %endif fmulp st1, st0 ;// l' r l r fstp dword [edi] ;// r l r scasd fld dword [edx+go4kOUT_val.auxsend] ;// as r l r %ifdef GO4K_USE_OUT_MOD_AM fadd dword [WRK+go4kOUT_wrk.am] ;// am r l r %endif fmulp st1, st0 ;// r' l r fstp dword [edi] ;// l r scasd fld dword [edx+go4kOUT_val.gain] ;// g l r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm l r %endif fmulp st1, st0 ;// l' r fstp dword [edi] ;// r scasd fld dword [edx+go4kOUT_val.gain] ;// g r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm r %endif fmulp st1, st0 ;// r' fstp dword [edi] ;// - scasd popad %else push 1 call go4kTransformValues fld dword [edx+go4kOUT_val.gain] ;// g l r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm l r %endif fmulp st1, st0 ;// l' r fstp dword [ecx+MAX_UNITS*MAX_UNIT_SLOTS*4+0] ;// r fld dword [edx+go4kOUT_val.gain] ;// g r %ifdef GO4K_USE_OUT_MOD_GM fadd dword [WRK+go4kOUT_wrk.gm] ;// gm r %endif fmulp st1, st0 ;// r' fstp dword [ecx+MAX_UNITS*MAX_UNIT_SLOTS*4+4] ;// - %endif ret %ifdef USE_SECTIONS section .g4kcodl code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // ACC Tick (stereo signal accumulation for synth commands only -> dont use in instrument commands) ; //---------------------------------------------------------------------------------------- ; // IN : WRK = unit workspace ; // IN : VAL = unit values ; // IN : ecx = global workspace ; // OUT : ; // DIRTY : eax ; //---------------------------------------------------------------------------------------- export_func go4kACC_func@0 push 1 call go4kTransformValues pushad mov edi, go4k_synth_wrk add edi, go4k_instrument.size sub edi, eax ; // eax already contains the accumulation offset from the go4kTransformValues call mov cl, MAX_INSTRUMENTS*MAX_VOICES fldz ;// 0 fldz ;// 0 0 go4kACC_func_loop: fadd dword [edi-8] ;// l 0 fxch ;// 0 l fadd dword [edi-4] ;// r l fxch ;// l r add edi, go4k_instrument.size dec cl jnz go4kACC_func_loop popad ret %ifdef USE_SECTIONS section .g4kcodw code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Update Instrument (allocate voices, set voice to release) ; //---------------------------------------------------------------------------------------- ; // IN : ; // IN : ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- go4kUpdateInstrument: ; // get new note mov eax, dword [esp+4+4] ; // eax = current tick shr eax, PATTERN_SIZE_SHIFT ; // eax = current pattern imul edx, ecx, dword MAX_PATTERNS ; // edx = instrument pattern list index movzx edx, byte [edx+eax+go4k_pattern_lists] ; // edx = pattern index mov eax, dword [esp+4+4] ; // eax = current tick shl edx, PATTERN_SIZE_SHIFT and eax, PATTERN_SIZE-1 movzx edx, byte [edx+eax+go4k_patterns] ; // edx = requested note in new patterntick ; // apply note changes cmp dl, HLD ; // anything but hold causes action je short go4kUpdateInstrument_done inc dword [edi] ; // set release flag if needed %if MAX_VOICES > 1 inc dword [edi+go4k_instrument.size] ; // set release flag if needed %endif cmp dl, HLD ; // check for new note jl short go4kUpdateInstrument_done %if MAX_VOICES > 1 pushad xchg eax, dword [go4k_voiceindex + ecx*4] test eax, eax je go4kUpdateInstrument_newNote add edi, go4k_instrument.size go4kUpdateInstrument_newNote: xor al,1 xchg dword [go4k_voiceindex + ecx*4], eax %endif pushad xor eax, eax mov ecx, (8+MAX_UNITS*MAX_UNIT_SLOTS*4)/4 ; // clear only relase, note and workspace rep stosd popad mov dword [edi+4], edx ; // set requested note as current note %if MAX_VOICES > 1 popad %endif jmp short go4kUpdateInstrument_done go4kUpdateInstrument_done: ret %ifdef USE_SECTIONS section .g4kcodx code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // Render Voices ; //---------------------------------------------------------------------------------------- ; // IN : ; // IN : ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- go4kRenderVoices: push ecx ; // save current instrument counter %if MAX_VOICES > 1 push COM ; // save current instrument command index push VAL ; // save current instrument values index %endif call go4k_VM_process ; // call synth vm for instrument voices mov eax, dword [ecx+go4kENV_wrk.state] cmp al, byte ENV_STATE_OFF jne go4kRenderVoices_next xor eax, eax mov dword [ecx-4], eax ; // kill note if voice is done go4kRenderVoices_next: %if MAX_VOICES > 1 pop VAL ; // restore instrument value index pop COM ; // restore instrument command index %endif %ifdef GO4K_USE_BUFFER_RECORDINGS mov eax, dword [esp+16] ; // get current tick shr eax, 8 ; // every 256th sample = ~ 172 hz shl eax, 5 ; // for 16 instruments a 2 voices add eax, dword [esp] add eax, dword [esp] ; // + 2*currentinstrument+0 %ifdef GO4K_USE_ENVELOPE_RECORDINGS mov edx, dword [ecx+go4kENV_wrk.level] mov dword [__4klang_envelope_buffer+eax*4], edx %endif %ifdef GO4K_USE_NOTE_RECORDINGS mov edx, dword [ecx-4] mov dword [__4klang_note_buffer+eax*4], edx %endif %endif %if MAX_VOICES > 1 call go4k_VM_process ; // call synth vm for instrument voices mov eax, dword [ecx+go4kENV_wrk.state] cmp al, byte ENV_STATE_OFF jne go4k_render_instrument_next2 xor eax, eax mov dword [ecx-4], eax ; // kill note if voice is done go4k_render_instrument_next2: %ifdef GO4K_USE_BUFFER_RECORDINGS mov eax, dword [esp+16] ; // get current tick shr eax, 8 ; // every 256th sample = ~ 172 hz shl eax, 5 ; // for 16 instruments a 2 voices add eax, dword [esp] add eax, dword [esp] ; // + 2*currentinstrument+0 %ifdef GO4K_USE_ENVELOPE_RECORDINGS mov edx, dword [ecx+go4kENV_wrk.level] mov dword [__4klang_envelope_buffer+eax*4+4], edx %endif %ifdef GO4K_USE_NOTE_RECORDINGS mov edx, dword [ecx-4] mov dword [__4klang_note_buffer+eax*4+4], edx %endif %endif %endif pop ecx ; // restore instrument counter ret %ifdef USE_SECTIONS section .g4kcody code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // the entry point for the synth ; //---------------------------------------------------------------------------------------- %ifdef USE_SECTIONS export_func _4klang_render@4 %else export_func _4klang_render %endif pushad xor ecx, ecx %ifdef GO4K_USE_BUFFER_RECORDINGS push ecx %endif ; loop all ticks go4k_render_tickloop: push ecx xor ecx, ecx ; loop all samples per tick go4k_render_sampleloop: push ecx xor ecx, ecx mov ebx, go4k_synth_instructions ; // ebx = instrument command index mov VAL, go4k_synth_parameter_values; // VAL = instrument values index mov edi, _go4k_delay_buffer ; // get offset of first delay buffer mov dword [_go4k_delay_buffer_ofs], edi ; // store offset in delaybuffer offset variable mov edi, go4k_synth_wrk ; // edi = first instrument ; loop all instruments go4k_render_instrumentloop: mov eax, dword [esp] ; // eax = current tick sample and eax, eax jnz go4k_render_instrument_process ; // tick change? (first sample in current tick) call go4kUpdateInstrument ; // update instrument state ; process instrument go4k_render_instrument_process: call go4kRenderVoices inc ecx cmp cl, byte MAX_INSTRUMENTS jl go4k_render_instrumentloop mov dword [edi+4], ecx ; // move a value != 0 into note slot, so processing will be done call go4k_VM_process ; // call synth vm for synth go4k_render_output_sample: %ifdef GO4K_USE_BUFFER_RECORDINGS inc dword [esp+8] xchg esi, dword [esp+48] ; // edx = destbuffer %else xchg esi, dword [esp+44] ; // edx = destbuffer %endif %ifdef GO4K_CLIP_OUTPUT fld dword [edi-8] fld1 ; // 1 val fucomi st1 ; // 1 val jbe short go4k_render_clip1 fchs ; // -1 val fucomi st1 ; // -1 val fcmovb st0, st1 ; // val -1 (if val > -1) go4k_render_clip1: fstp st1 ; // newval %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted left sample lodsw %else fstp dword [esi] ; // store left sample lodsd %endif fld dword [edi-4] fld1 ; // 1 val fucomi st1 ; // 1 val jbe short go4k_render_clip2 fchs ; // -1 val fucomi st1 ; // -1 val fcmovb st0, st1 ; // val -1 (if val > -1) go4k_render_clip2: fstp st1 ; // newval %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted right sample lodsw %else fstp dword [esi] ; // store right sample lodsd %endif %else fld dword [edi-8] %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted left sample lodsw %else fstp dword [esi] ; // store left sample lodsd %endif fld dword [edi-4] %ifdef GO4K_USE_16BIT_OUTPUT push eax fmul dword [c_32767] fistp dword [esp] pop eax mov word [esi],ax ; // store integer converted right sample lodsw %else fstp dword [esi] ; // store right sample lodsd %endif %endif %ifdef GO4K_USE_BUFFER_RECORDINGS xchg esi, dword [esp+48] %else xchg esi, dword [esp+44] %endif pop ecx inc ecx %ifdef GO4K_USE_GROOVE_PATTERN mov ebx, dword SAMPLES_PER_TICK mov eax, dword [esp] and eax, 0x0f bt dword [go4k_groove_pattern],eax jnc go4k_render_nogroove sub ebx, dword 3000 go4k_render_nogroove: cmp ecx, ebx %else cmp ecx, dword SAMPLES_PER_TICK %endif jl go4k_render_sampleloop pop ecx inc ecx %ifdef AUTHORING mov dword[__4klang_current_tick], ecx %endif cmp ecx, dword MAX_TICKS jl go4k_render_tickloop %ifdef GO4K_USE_BUFFER_RECORDINGS pop ecx %endif popad ret 4 %ifdef USE_SECTIONS section .g4kcodz code align=1 %else section .text %endif ; //---------------------------------------------------------------------------------------- ; // the magic behind it :) ; //---------------------------------------------------------------------------------------- ; // IN : edi = instrument pointer ; // IN : esi = instrumet values ; // IN : ebx = instrument instructions ; // OUT : ; // DIRTY : ; //---------------------------------------------------------------------------------------- go4k_VM_process: lea WRK, [edi+8] ; // get current workspace pointer mov ecx, WRK ; // ecx = workspace start go4k_VM_process_loop: movzx eax, byte [ebx] ; // get command byte inc ebx test eax, eax je go4k_VM_process_done ; // command byte = 0? so done call dword [eax*4+go4k_synth_commands] add WRK, MAX_UNIT_SLOTS*4 ; // go to next workspace slot jmp short go4k_VM_process_loop go4k_VM_process_done: add edi, go4k_instrument.size ; // go to next instrument voice ret ",16298,True,3579.2170408061634,median "pragma Warnings (Off); pragma Ada_95; with System; with System.Parameters; with System.Secondary_Stack; package ada_main is gnat_argc : Integer; gnat_argv : System.Address; gnat_envp : System.Address; pragma Import (C, gnat_argc); pragma Import (C, gnat_argv); pragma Import (C, gnat_envp); gnat_exit_status : Integer; pragma Import (C, gnat_exit_status); GNAT_Version : constant String := ""GNAT Version: Community 2020 (20200429-93)"" & ASCII.NUL; pragma Export (C, GNAT_Version, ""__gnat_version""); Ada_Main_Program_Name : constant String := ""_ada_planificador_ciclico"" & ASCII.NUL; pragma Export (C, Ada_Main_Program_Name, ""__gnat_ada_main_program_name""); procedure adainit; pragma Export (C, adainit, ""adainit""); procedure adafinal; pragma Export (C, adafinal, ""adafinal""); function main (argc : Integer; argv : System.Address; envp : System.Address) return Integer; pragma Export (C, main, ""main""); type Version_32 is mod 2 ** 32; u00001 : constant Version_32 := 16#8b6ec1eb#; pragma Export (C, u00001, ""planificador_ciclicoB""); u00002 : constant Version_32 := 16#67c8d842#; pragma Export (C, u00002, ""system__standard_libraryB""); u00003 : constant Version_32 := 16#5741b5a5#; pragma Export (C, u00003, ""system__standard_libraryS""); u00004 : constant Version_32 := 16#76789da1#; pragma Export (C, u00004, ""adaS""); u00005 : constant Version_32 := 16#57c21ad4#; pragma Export (C, u00005, ""ada__calendarB""); u00006 : constant Version_32 := 16#31350a81#; pragma Export (C, u00006, ""ada__calendarS""); u00007 : constant Version_32 := 16#f34ff985#; pragma Export (C, u00007, ""ada__exceptionsB""); u00008 : constant Version_32 := 16#cfbb5cc5#; pragma Export (C, u00008, ""ada__exceptionsS""); u00009 : constant Version_32 := 16#35e1815f#; pragma Export (C, u00009, ""ada__exceptions__last_chance_handlerB""); u00010 : constant Version_32 := 16#cfec26ee#; pragma Export (C, u00010, ""ada__exceptions__last_chance_handlerS""); u00011 : constant Version_32 := 16#32a08138#; pragma Export (C, u00011, ""systemS""); u00012 : constant Version_32 := 16#ae860117#; pragma Export (C, u00012, ""system__soft_linksB""); u00013 : constant Version_32 := 16#4d9536d3#; pragma Export (C, u00013, ""system__soft_linksS""); u00014 : constant Version_32 := 16#59d61025#; pragma Export (C, u00014, ""system__secondary_stackB""); u00015 : constant Version_32 := 16#c30bb6bc#; pragma Export (C, u00015, ""system__secondary_stackS""); u00016 : constant Version_32 := 16#896564a3#; pragma Export (C, u00016, ""system__parametersB""); u00017 : constant Version_32 := 16#75f245f3#; pragma Export (C, u00017, ""system__parametersS""); u00018 : constant Version_32 := 16#ced09590#; pragma Export (C, u00018, ""system__storage_elementsB""); u00019 : constant Version_32 := 16#1f63cb3c#; pragma Export (C, u00019, ""system__storage_elementsS""); u00020 : constant Version_32 := 16#ce3e0e21#; pragma Export (C, u00020, ""system__soft_links__initializeB""); u00021 : constant Version_32 := 16#5697fc2b#; pragma Export (C, u00021, ""system__soft_links__initializeS""); u00022 : constant Version_32 := 16#41837d1e#; pragma Export (C, u00022, ""system__stack_checkingB""); u00023 : constant Version_32 := 16#bc1fead0#; pragma Export (C, u00023, ""system__stack_checkingS""); u00024 : constant Version_32 := 16#34742901#; pragma Export (C, u00024, ""system__exception_tableB""); u00025 : constant Version_32 := 16#0dc9c2c8#; pragma Export (C, u00025, ""system__exception_tableS""); u00026 : constant Version_32 := 16#ce4af020#; pragma Export (C, u00026, ""system__exceptionsB""); u00027 : constant Version_32 := 16#5ac3ecce#; pragma Export (C, u00027, ""system__exceptionsS""); u00028 : constant Version_32 := 16#69416224#; pragma Export (C, u00028, ""system__exceptions__machineB""); u00029 : constant Version_32 := 16#5c74e542#; pragma Export (C, u00029, ""system__exceptions__machineS""); u00030 : constant Version_32 := 16#aa0563fc#; pragma Export (C, u00030, ""system__exceptions_debugB""); u00031 : constant Version_32 := 16#2eed524e#; pragma Export (C, u00031, ""system__exceptions_debugS""); u00032 : constant Version_32 := 16#6c2f8802#; pragma Export (C, u00032, ""system__img_intB""); u00033 : constant Version_32 := 16#307b61fa#; pragma Export (C, u00033, ""system__img_intS""); u00034 : constant Version_32 := 16#39df8c17#; pragma Export (C, u00034, ""system__tracebackB""); u00035 : constant Version_32 := 16#6c825ffc#; pragma Export (C, u00035, ""system__tracebackS""); u00036 : constant Version_32 := 16#9ed49525#; pragma Export (C, u00036, ""system__traceback_entriesB""); u00037 : constant Version_32 := 16#32fb7748#; pragma Export (C, u00037, ""system__traceback_entriesS""); u00038 : constant Version_32 := 16#3f39e75e#; pragma Export (C, u00038, ""system__traceback__symbolicB""); u00039 : constant Version_32 := 16#46491211#; pragma Export (C, u00039, ""system__traceback__symbolicS""); u00040 : constant Version_32 := 16#179d7d28#; pragma Export (C, u00040, ""ada__containersS""); u00041 : constant Version_32 := 16#701f9d88#; pragma Export (C, u00041, ""ada__exceptions__tracebackB""); u00042 : constant Version_32 := 16#ae2d2db5#; pragma Export (C, u00042, ""ada__exceptions__tracebackS""); u00043 : constant Version_32 := 16#e865e681#; pragma Export (C, u00043, ""system__bounded_stringsB""); u00044 : constant Version_32 := 16#455da021#; pragma Export (C, u00044, ""system__bounded_stringsS""); u00045 : constant Version_32 := 16#7b499e82#; pragma Export (C, u00045, ""system__crtlS""); u00046 : constant Version_32 := 16#641e2245#; pragma Export (C, u00046, ""system__dwarf_linesB""); u00047 : constant Version_32 := 16#40ce1ea3#; pragma Export (C, u00047, ""system__dwarf_linesS""); u00048 : constant Version_32 := 16#5b4659fa#; pragma Export (C, u00048, ""ada__charactersS""); u00049 : constant Version_32 := 16#8f637df8#; pragma Export (C, u00049, ""ada__characters__handlingB""); u00050 : constant Version_32 := 16#3b3f6154#; pragma Export (C, u00050, ""ada__characters__handlingS""); u00051 : constant Version_32 := 16#4b7bb96a#; pragma Export (C, u00051, ""ada__characters__latin_1S""); u00052 : constant Version_32 := 16#e6d4fa36#; pragma Export (C, u00052, ""ada__stringsS""); u00053 : constant Version_32 := 16#96df1a3f#; pragma Export (C, u00053, ""ada__strings__mapsB""); u00054 : constant Version_32 := 16#1e526bec#; pragma Export (C, u00054, ""ada__strings__mapsS""); u00055 : constant Version_32 := 16#465aa89c#; pragma Export (C, u00055, ""system__bit_opsB""); u00056 : constant Version_32 := 16#0765e3a3#; pragma Export (C, u00056, ""system__bit_opsS""); u00057 : constant Version_32 := 16#6c6ff32a#; pragma Export (C, u00057, ""system__unsigned_typesS""); u00058 : constant Version_32 := 16#92f05f13#; pragma Export (C, u00058, ""ada__strings__maps__constantsS""); u00059 : constant Version_32 := 16#5ab55268#; pragma Export (C, u00059, ""interfacesS""); u00060 : constant Version_32 := 16#a0d3d22b#; pragma Export (C, u00060, ""system__address_imageB""); u00061 : constant Version_32 := 16#934c1c02#; pragma Export (C, u00061, ""system__address_imageS""); u00062 : constant Version_32 := 16#8631cc2e#; pragma Export (C, u00062, ""system__img_unsB""); u00063 : constant Version_32 := 16#f39bcfdd#; pragma Export (C, u00063, ""system__img_unsS""); u00064 : constant Version_32 := 16#20ec7aa3#; pragma Export (C, u00064, ""system__ioB""); u00065 : constant Version_32 := 16#ace27677#; pragma Export (C, u00065, ""system__ioS""); u00066 : constant Version_32 := 16#3080f2ca#; pragma Export (C, u00066, ""system__mmapB""); u00067 : constant Version_32 := 16#9ad4d587#; pragma Export (C, u00067, ""system__mmapS""); u00068 : constant Version_32 := 16#92d882c5#; pragma Export (C, u00068, ""ada__io_exceptionsS""); u00069 : constant Version_32 := 16#a8ba7b3b#; pragma Export (C, u00069, ""system__mmap__os_interfaceB""); u00070 : constant Version_32 := 16#8f4541b8#; pragma Export (C, u00070, ""system__mmap__os_interfaceS""); u00071 : constant Version_32 := 16#657efc5a#; pragma Export (C, u00071, ""system__os_libB""); u00072 : constant Version_32 := 16#d872da39#; pragma Export (C, u00072, ""system__os_libS""); u00073 : constant Version_32 := 16#ec4d5631#; pragma Export (C, u00073, ""system__case_utilB""); u00074 : constant Version_32 := 16#0d75376c#; pragma Export (C, u00074, ""system__case_utilS""); u00075 : constant Version_32 := 16#2a8e89ad#; pragma Export (C, u00075, ""system__stringsB""); u00076 : constant Version_32 := 16#52b6adad#; pragma Export (C, u00076, ""system__stringsS""); u00077 : constant Version_32 := 16#e49bce3e#; pragma Export (C, u00077, ""interfaces__cB""); u00078 : constant Version_32 := 16#dbc36ce0#; pragma Export (C, u00078, ""interfaces__cS""); u00079 : constant Version_32 := 16#c83ab8ef#; pragma Export (C, u00079, ""system__object_readerB""); u00080 : constant Version_32 := 16#f6d45c39#; pragma Export (C, u00080, ""system__object_readerS""); u00081 : constant Version_32 := 16#914b0305#; pragma Export (C, u00081, ""system__val_lliB""); u00082 : constant Version_32 := 16#5ece13c8#; pragma Export (C, u00082, ""system__val_lliS""); u00083 : constant Version_32 := 16#d2ae2792#; pragma Export (C, u00083, ""system__val_lluB""); u00084 : constant Version_32 := 16#01a17ec8#; pragma Export (C, u00084, ""system__val_lluS""); u00085 : constant Version_32 := 16#269742a9#; pragma Export (C, u00085, ""system__val_utilB""); u00086 : constant Version_32 := 16#9e0037c6#; pragma Export (C, u00086, ""system__val_utilS""); u00087 : constant Version_32 := 16#b578159b#; pragma Export (C, u00087, ""system__exception_tracesB""); u00088 : constant Version_32 := 16#167fa1a2#; pragma Export (C, u00088, ""system__exception_tracesS""); u00089 : constant Version_32 := 16#e1282880#; pragma Export (C, u00089, ""system__win32S""); u00090 : constant Version_32 := 16#8c33a517#; pragma Export (C, u00090, ""system__wch_conB""); u00091 : constant Version_32 := 16#29dda3ea#; pragma Export (C, u00091, ""system__wch_conS""); u00092 : constant Version_32 := 16#9721e840#; pragma Export (C, u00092, ""system__wch_stwB""); u00093 : constant Version_32 := 16#04cc8feb#; pragma Export (C, u00093, ""system__wch_stwS""); u00094 : constant Version_32 := 16#a831679c#; pragma Export (C, u00094, ""system__wch_cnvB""); u00095 : constant Version_32 := 16#266a1919#; pragma Export (C, u00095, ""system__wch_cnvS""); u00096 : constant Version_32 := 16#ece6fdb6#; pragma Export (C, u00096, ""system__wch_jisB""); u00097 : constant Version_32 := 16#a61a0038#; pragma Export (C, u00097, ""system__wch_jisS""); u00098 : constant Version_32 := 16#24ec69e6#; pragma Export (C, u00098, ""system__os_primitivesB""); u00099 : constant Version_32 := 16#355de4ce#; pragma Export (C, u00099, ""system__os_primitivesS""); u00100 : constant Version_32 := 16#05c60a38#; pragma Export (C, u00100, ""system__task_lockB""); u00101 : constant Version_32 := 16#532ab656#; pragma Export (C, u00101, ""system__task_lockS""); u00102 : constant Version_32 := 16#b8c476a4#; pragma Export (C, u00102, ""system__win32__extS""); u00103 : constant Version_32 := 16#ffaa9e94#; pragma Export (C, u00103, ""ada__calendar__delaysB""); u00104 : constant Version_32 := 16#d86d2f1d#; pragma Export (C, u00104, ""ada__calendar__delaysS""); u00105 : constant Version_32 := 16#f4e097a7#; pragma Export (C, u00105, ""ada__text_ioB""); u00106 : constant Version_32 := 16#03e83e15#; pragma Export (C, u00106, ""ada__text_ioS""); u00107 : constant Version_32 := 16#10558b11#; pragma Export (C, u00107, ""ada__streamsB""); u00108 : constant Version_32 := 16#67e31212#; pragma Export (C, u00108, ""ada__streamsS""); u00109 : constant Version_32 := 16#f9576a72#; pragma Export (C, u00109, ""ada__tagsB""); u00110 : constant Version_32 := 16#b6661f55#; pragma Export (C, u00110, ""ada__tagsS""); u00111 : constant Version_32 := 16#796f31f1#; pragma Export (C, u00111, ""system__htableB""); u00112 : constant Version_32 := 16#b66232d2#; pragma Export (C, u00112, ""system__htableS""); u00113 : constant Version_32 := 16#089f5cd0#; pragma Export (C, u00113, ""system__string_hashB""); u00114 : constant Version_32 := 16#143c59ac#; pragma Export (C, u00114, ""system__string_hashS""); u00115 : constant Version_32 := 16#73d2d764#; pragma Export (C, u00115, ""interfaces__c_streamsB""); u00116 : constant Version_32 := 16#b1330297#; pragma Export (C, u00116, ""interfaces__c_streamsS""); u00117 : constant Version_32 := 16#ec9c64c3#; pragma Export (C, u00117, ""system__file_ioB""); u00118 : constant Version_32 := 16#95d1605d#; pragma Export (C, u00118, ""system__file_ioS""); u00119 : constant Version_32 := 16#86c56e5a#; pragma Export (C, u00119, ""ada__finalizationS""); u00120 : constant Version_32 := 16#95817ed8#; pragma Export (C, u00120, ""system__finalization_rootB""); u00121 : constant Version_32 := 16#7d52f2a8#; pragma Export (C, u00121, ""system__finalization_rootS""); u00122 : constant Version_32 := 16#cf3f1b90#; pragma Export (C, u00122, ""system__file_control_blockS""); u00123 : constant Version_32 := 16#fd83e873#; pragma Export (C, u00123, ""system__concat_2B""); u00124 : constant Version_32 := 16#300056e8#; pragma Export (C, u00124, ""system__concat_2S""); u00125 : constant Version_32 := 16#932a4690#; pragma Export (C, u00125, ""system__concat_4B""); u00126 : constant Version_32 := 16#4cc4aa18#; pragma Export (C, u00126, ""system__concat_4S""); u00127 : constant Version_32 := 16#2b70b149#; pragma Export (C, u00127, ""system__concat_3B""); u00128 : constant Version_32 := 16#39d0dd9d#; pragma Export (C, u00128, ""system__concat_3S""); u00129 : constant Version_32 := 16#276453b7#; pragma Export (C, u00129, ""system__img_lldB""); u00130 : constant Version_32 := 16#c1828851#; pragma Export (C, u00130, ""system__img_lldS""); u00131 : constant Version_32 := 16#bd3715ff#; pragma Export (C, u00131, ""system__img_decB""); u00132 : constant Version_32 := 16#9c8d88e3#; pragma Export (C, u00132, ""system__img_decS""); u00133 : constant Version_32 := 16#9dca6636#; pragma Export (C, u00133, ""system__img_lliB""); u00134 : constant Version_32 := 16#23efd4e9#; pragma Export (C, u00134, ""system__img_lliS""); u00135 : constant Version_32 := 16#eca5ecae#; pragma Export (C, u00135, ""system__memoryB""); u00136 : constant Version_32 := 16#6bdde70c#; pragma Export (C, u00136, ""system__memoryS""); -- BEGIN ELABORATION ORDER -- ada%s -- ada.characters%s -- ada.characters.latin_1%s -- interfaces%s -- system%s -- system.img_int%s -- system.img_int%b -- system.img_dec%s -- system.img_dec%b -- system.img_lli%s -- system.img_lli%b -- system.img_lld%s -- system.img_lld%b -- system.io%s -- system.io%b -- system.parameters%s -- system.parameters%b -- system.crtl%s -- interfaces.c_streams%s -- interfaces.c_streams%b -- system.storage_elements%s -- system.storage_elements%b -- system.stack_checking%s -- system.stack_checking%b -- system.string_hash%s -- system.string_hash%b -- system.htable%s -- system.htable%b -- system.strings%s -- system.strings%b -- system.traceback_entries%s -- system.traceback_entries%b -- system.unsigned_types%s -- system.img_uns%s -- system.img_uns%b -- system.wch_con%s -- system.wch_con%b -- system.wch_jis%s -- system.wch_jis%b -- system.wch_cnv%s -- system.wch_cnv%b -- system.concat_2%s -- system.concat_2%b -- system.concat_3%s -- system.concat_3%b -- system.concat_4%s -- system.concat_4%b -- system.traceback%s -- system.traceback%b -- ada.characters.handling%s -- system.case_util%s -- system.os_lib%s -- system.secondary_stack%s -- system.standard_library%s -- ada.exceptions%s -- system.exceptions_debug%s -- system.exceptions_debug%b -- system.soft_links%s -- system.val_lli%s -- system.val_llu%s -- system.val_util%s -- system.val_util%b -- system.wch_stw%s -- system.wch_stw%b -- ada.exceptions.last_chance_handler%s -- ada.exceptions.last_chance_handler%b -- ada.exceptions.traceback%s -- ada.exceptions.traceback%b -- system.address_image%s -- system.address_image%b -- system.bit_ops%s -- system.bit_ops%b -- system.bounded_strings%s -- system.bounded_strings%b -- system.case_util%b -- system.exception_table%s -- system.exception_table%b -- ada.containers%s -- ada.io_exceptions%s -- ada.strings%s -- ada.strings.maps%s -- ada.strings.maps%b -- ada.strings.maps.constants%s -- interfaces.c%s -- interfaces.c%b -- system.exceptions%s -- system.exceptions%b -- system.exceptions.machine%s -- system.exceptions.machine%b -- system.win32%s -- ada.characters.handling%b -- system.exception_traces%s -- system.exception_traces%b -- system.memory%s -- system.memory%b -- system.mmap%s -- system.mmap.os_interface%s -- system.mmap.os_interface%b -- system.mmap%b -- system.object_reader%s -- system.object_reader%b -- system.dwarf_lines%s -- system.dwarf_lines%b -- system.os_lib%b -- system.secondary_stack%b -- system.soft_links.initialize%s -- system.soft_links.initialize%b -- system.soft_links%b -- system.standard_library%b -- system.traceback.symbolic%s -- system.traceback.symbolic%b -- ada.exceptions%b -- system.val_lli%b -- system.val_llu%b -- ada.tags%s -- ada.tags%b -- ada.streams%s -- ada.streams%b -- system.file_control_block%s -- system.finalization_root%s -- system.finalization_root%b -- ada.finalization%s -- system.file_io%s -- system.file_io%b -- system.task_lock%s -- system.task_lock%b -- system.win32.ext%s -- system.os_primitives%s -- system.os_primitives%b -- ada.calendar%s -- ada.calendar%b -- ada.calendar.delays%s -- ada.calendar.delays%b -- ada.text_io%s -- ada.text_io%b -- planificador_ciclico%b -- END ELABORATION ORDER end ada_main; ",7980,True,2531.518413638277,median "colbak .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 colpf0 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 colpf1 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 colpf2 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 1C 1C 1C 1C 1C 1C 1C 1C .he 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C .he 1C 1C 1C 1C 1C 1C 1C 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 colpf3 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 80 80 80 80 80 80 80 80 .he 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 .he 80 80 80 80 80 80 80 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposp0 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposp1 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposp2 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposp3 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposm0 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposm1 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposm2 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 hposm3 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 colpm0 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 .he 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 colpm1 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 .he 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 colpm2 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 .he 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 colpm3 .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E .he 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E missiles .ds $100 player0 .ds $100 player1 .ds $100 player2 .ds $100 player3 .ds $100 charset0 .he 00 00 00 00 00 00 00 00 02 09 25 25 95 95 95 55 .he A0 58 56 55 55 55 55 55 00 00 00 00 80 40 6A 66 .he 00 00 00 00 02 2A 95 95 00 00 0A A9 55 59 59 55 .he 00 00 AA 56 55 55 65 65 00 00 00 80 60 58 98 56 .he 02 02 02 02 09 09 09 09 55 56 56 59 55 55 55 55 .he 55 55 55 55 55 55 55 55 56 55 55 55 55 55 55 55 .he 55 69 55 95 65 55 55 55 95 55 69 55 55 55 55 59 .he 55 55 55 65 65 55 55 55 96 95 55 56 55 95 55 55 .he 00 00 80 40 68 6A 6A 62 00 00 00 00 00 00 80 80 .he 09 09 09 25 25 15 95 55 55 55 55 55 55 55 55 6A .he 55 55 55 55 55 55 55 95 55 55 55 5A 6F BF BF BF .he 55 56 55 55 95 95 95 95 55 95 55 55 55 55 55 55 .he 65 55 55 55 55 55 55 55 55 55 55 55 55 55 95 95 .he A0 60 60 5A 55 55 56 56 A0 28 2A 0A A2 A8 FA FF .he 00 00 00 A0 A8 2A 02 80 02 0A 0A 02 00 00 00 00 .he 55 95 96 A8 00 00 00 00 A0 A0 80 00 00 00 00 00 .he 29 02 02 02 02 00 00 00 BF FE FE FA F8 A0 00 00 .he 95 55 55 55 95 29 02 00 55 55 55 55 55 55 AA 00 .he 55 55 55 55 56 68 80 00 65 69 62 80 00 00 00 00 .he 5B 63 82 00 00 00 00 00 FF FE FE A8 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .he 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ",16354,True,3958.968985670571,median "/* Версия 2.5 использует библиотеки Adafruit_NeoPixel и IRLremote вместо FastLED и IRremote Библиотеки идут в архиве с проектом! https://alexgyver.ru/colormusic/ Крутейшая свето-цветомузыка на Arduino и адресной светодиодной ленте WS2812b. Данная версия поддерживает около 410 светодиодов! Версия для ИК пульта KEYES Управление: - Однократное нажатие кнопки: смена режима - Удержание кнопки: калибровка нижнего порога шума Режимы работы (переключаются кнопкой): - VU meter (столбик громкости): от зелёного к красному - VU meter (столбик громкости): плавно бегущая радуга - Светомузыка по частотам: 5 полос симметрично - Светомузыка по частотам: 3 полосы - Светомузыка по частотам: 1 полоса - Стробоскоп - Подсветка - Бегущие частоты - Анализатор спектра Особенности: - Плавная анимация (можно настроить) - Автонастройка по громкости (можно настроить) - Фильтр нижнего шума (можно настроить) - Автокалибровка шума при запуске (можно настроить) - Поддержка стерео и моно звука (можно настроить) - В режиме частот лента не гаснет полностью (EMPTY_BRIGHT) - Все настройки сохраняются в памяти и не сбрасываются при перезагрузке - Сохранение настроек происходит при выключении кнопкой звёздочка (*) - А также через 30 секунд после последнего нажатия на любую кнопку ИК пульта НАСТРОЙКА НИЖНЕГО ПОРОГА ШУМА (строки 65-71) - Включаем систему - Ставим музыку на паузу - Удерживаем кнопку 1 секунду ИЛИ жмём кнопку 0 на пульте Значения шумов будут записаны в память и САМИ загружаться при последующем запуске! Всё! Пульт: - Цифры (1 - 9) активируют режимы - Цифра 0: калибровка шума - Звёздочка (*): включить/выключить систему - Кнопка ОК: переключение между локальными и глобальными настройками) - Решётка (#): смена подрежима - Глобальные настройки (горит светодиод на плате): + Стрелки ← →: общая яркость горящих светодиодов + Стрелки ↑ ↓: яркость ""не горящих"" светодиодов - Локальные настройки (у каждого режима свои): 1 - Шкала громкости (градиент) Стрелки ← →: плавность анимации 2 - Шкала громкости (радуга) Стрелки ← →: плавность анимации Стрелки ↑ ↓: скорость радуги 3 - Цветомузыка (5 полос) Стрелки ← →: плавность анимации Стрелки ↑ ↓: чувствительность 4 - Цветомузыка (3 полосы) Стрелки ← →: плавность анимации Стрелки ↑ ↓: чувствительность 5 - Цветомузыка (1 полоса) Стрелки ← →: плавность анимации Стрелки ↑ ↓: чувствительность Подрежимы #: 3 частоты / низкие / средние / высокие 6 - Стробоскоп Стрелки ← →: плавность вспышек Стрелки ↑ ↓: частота вспышек 7 - Цветная подсветка Подрежимы #: Постоянный: стрелки ← →: цвет, стрелки ↑ ↓: насыщенность Плавная смена: стрелки ← →: скорость, стрелки ↑ ↓: насыщенность Бегущая радуга: стрелки ← →: скорость, стрелки ↑ ↓: шаг радуги 8 - “Бегущие частоты” Стрелки ← →: скорость Стрелки ↑ ↓: чувствительность Подрежимы #: 3 частоты / низкие / средние / высокие 9 - Анализатор спектра Стрелки ← →: шаг цвета Стрелки ↑ ↓: цвет ************************************************** Разработано: AlexGyver Страница проекта: http://alexgyver.ru/colormusic/ GitHub: https://github.com/AlexGyver/ColorMusic */ // --------------------------- НАСТРОЙКИ --------------------------- #define KEEP_SETTINGS 1 // хранить ВСЕ настройки в памяти #define RESET_SETTINGS 0 // сброс настроек в памяти. // поставить 1. Прошиться. Поставить обратно 0. Прошиться. Всё. // лента #define NUM_LEDS 310 // количество светодиодов byte BRIGHTNESS = 200; // яркость (0 - 255) // пины #define SOUND_R A2 // аналоговый пин вход аудио, правый канал #define SOUND_L A1 // аналоговый пин вход аудио, левый канал #define SOUND_R_FREQ A3 // аналоговый пин вход аудио для режима с частотами (через кондер) #define BTN_PIN 3 // кнопка переключения режимов (PIN --- КНОПКА --- GND) #define LED_PIN 12 // пин DI светодиодной ленты #define POT_GND A0 // пин земля для потенциометра #define IR_PIN 2 // ИК приёмник // настройки радуги float RAINBOW_STEP = 5.5; // шаг изменения цвета радуги // отрисовка #define MODE 0 // режим при запуске #define MAIN_LOOP 5 // период основного цикла отрисовки (по умолчанию 5) // сигнал #define MONO 1 // 1 - только один канал (ПРАВЫЙ!!!!! SOUND_R!!!!!), 0 - два канала #define EXP 1.4 // степень усиления сигнала (для более ""резкой"" работы) (по умолчанию 1.4) #define POTENT 1 // 1 - используем потенциометр, 0 - используется внутренний источник опорного напряжения 1.1 В byte EMPTY_BRIGHT = 30; // яркость ""не горящих"" светодиодов (0 - 255) #define EMPTY_COLOR HUE_PURPLE // цвет ""не горящих"" светодиодов. Будет чёрный, если яркость 0 // нижний порог шумов byte LOW_PASS = 100; // нижний порог шумов режим VU, ручная настройка byte SPEKTR_LOW_PASS = 40; // нижний порог шумов режим спектра, ручная настройка #define AUTO_LOW_PASS 0 // разрешить настройку нижнего порога шумов при запуске (по умолч. 0) #define EEPROM_LOW_PASS 1 // порог шумов хранится в энергонезависимой памяти (по умолч. 1) #define LOW_PASS_ADD 13 // ""добавочная"" величина к нижнему порогу, для надёжности (режим VU) #define LOW_PASS_FREQ_ADD 3 // ""добавочная"" величина к нижнему порогу, для надёжности (режим частот) // шкала громкости float SMOOTH = 0.5; // коэффициент плавности анимации VU (по умолчанию 0.5) #define MAX_COEF 1.8 // коэффициент громкости (максимальное равно срднему * этот коэф) (по умолчанию 1.8) // режим цветомузыки float SMOOTH_FREQ = 0.8; // коэффициент плавности анимации частот (по умолчанию 0.8) float MAX_COEF_FREQ = 1.2; // коэффициент порога для ""вспышки"" цветомузыки (по умолчанию 1.5) #define SMOOTH_STEP 20 // шаг уменьшения яркости в режиме цветомузыки (чем больше, тем быстрее гаснет) #define LOW_COLOR HUE_RED // цвет низких частот #define MID_COLOR HUE_GREEN // цвет средних #define HIGH_COLOR HUE_YELLOW // цвет высоких // режим стробоскопа int STROBE_PERIOD = 100; // период вспышек, миллисекунды #define STROBE_DUTY 20 // скважность вспышек (1 - 99) - отношение времени вспышки ко времени темноты #define STROBE_COLOR HUE_YELLOW // цвет стробоскопа #define STROBE_SAT 0 // насыщенность. Если 0 - цвет будет БЕЛЫЙ при любом цвете (0 - 255) byte STROBE_SMOOTH = 100; // скорость нарастания/угасания вспышки (0 - 255) // режим подсветки byte LIGHT_COLOR = 0; // начальный цвет подсветки byte LIGHT_SAT = 200; // начальная насыщенность подсветки byte COLOR_SPEED = 100; int RAINBOW_PERIOD = 3; float RAINBOW_STEP_2 = 5.5; // режим бегущих частот byte RUNNING_SPEED = 60; // режим анализатора спектра byte HUE_START = 0; byte HUE_STEP = 5; #define LIGHT_SMOOTH 2 /* Цвета для HSV HUE_RED HUE_ORANGE HUE_YELLOW HUE_GREEN HUE_AQUA HUE_BLUE HUE_PURPLE HUE_PINK */ // --------------------------- НАСТРОЙКИ --------------------------- // ----- КНОПКИ ПУЛЬТА ----- #define BUTT_UP 0xE51CA6AD #define BUTT_DOWN 0xD22353AD #define BUTT_LEFT 0x517068AD #define BUTT_RIGHT 0xAC2A56AD #define BUTT_OK 0x1B92DDAD #define BUTT_1 0x68E456AD #define BUTT_2 0xF08A26AD #define BUTT_3 0x151CD6AD #define BUTT_4 0x18319BAD #define BUTT_5 0xF39EEBAD #define BUTT_6 0x4AABDFAD #define BUTT_7 0xE25410AD #define BUTT_8 0x297C76AD #define BUTT_9 0x14CE54AD #define BUTT_0 0xC089F6AD #define BUTT_STAR 0xAF3F1BAD #define BUTT_HASH 0x38379AD // ----- КНОПКИ ПУЛЬТА ----- // ------------------------------ ДЛЯ РАЗРАБОТЧИКОВ -------------------------------- #define MODE_AMOUNT 9 // количество режимов // цвета HSV #define HUE_RED 0 #define HUE_ORANGE 12 #define HUE_YELLOW 44 #define HUE_GREEN 85 #define HUE_AQUA 128 #define HUE_BLUE 171 #define HUE_PURPLE 213 #define HUE_PINK 244 #define STRIPE NUM_LEDS / 5 float freq_to_stripe = NUM_LEDS / 40; // /2 так как симметрия, и /20 так как 20 частот #define FHT_N 64 // ширина спектра х2 #define LOG_OUT 1 #include // преобразование Хартли #include #include ""Adafruit_NeoPixel.h"" Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); #include ""GyverButton.h"" GButton butt1(BTN_PIN); #include ""IRLremote.h"" CHashIR IRLremote; uint32_t IRdata; byte Rlenght, Llenght; float RsoundLevel, RsoundLevel_f; float LsoundLevel, LsoundLevel_f; float averageLevel = 50; int maxLevel = 100; byte MAX_CH = NUM_LEDS / 2; int hue; unsigned long main_timer, hue_timer, strobe_timer, running_timer, color_timer, rainbow_timer, eeprom_timer; float averK = 0.006; byte count; float index = (float)(HUE_GREEN - HUE_RED) / MAX_CH; // коэффициент перевода для палитры зеленый-красный float index2 = (float)255 / MAX_CH; // коэффициент перевода для радуги boolean lowFlag; byte low_pass; int RcurrentLevel, LcurrentLevel; int colorMusic[3]; float colorMusic_f[3], colorMusic_aver[3]; boolean colorMusicFlash[3], strobeUp_flag, strobeDwn_flag; byte this_mode = MODE; int thisBright[3], strobe_bright = 0; unsigned int light_time = STROBE_PERIOD * STROBE_DUTY / 100; volatile boolean ir_flag; boolean settings_mode, ONstate = true; int8_t freq_strobe_mode, light_mode; int freq_max; float freq_max_f, rainbow_steps; int freq_f[32]; int this_color; boolean running_flag[3], eeprom_flag; #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) // ------------------------------ ДЛЯ РАЗРАБОТЧИКОВ -------------------------------- void setup() { Serial.begin(9600); strip.begin(); strip.setBrightness(BRIGHTNESS); pinMode(13, OUTPUT); digitalWrite(13, LOW); pinMode(POT_GND, OUTPUT); digitalWrite(POT_GND, LOW); butt1.setTimeout(900); IRLremote.begin(IR_PIN); // для увеличения точности уменьшаем опорное напряжение, // выставив EXTERNAL и подключив Aref к выходу 3.3V на плате через делитель // GND ---[10-20 кОм] --- REF --- [10 кОм] --- 3V3 // в данной схеме GND берётся из А0 для удобства подключения if (POTENT) analogReference(EXTERNAL); else analogReference(INTERNAL); // жуткая магия, меняем частоту оцифровки до 18 кГц // команды на ебучем ассемблере, даже не спрашивайте, как это работает sbi(ADCSRA, ADPS2); cbi(ADCSRA, ADPS1); sbi(ADCSRA, ADPS0); if (RESET_SETTINGS) EEPROM.write(100, 0); // сброс флага настроек if (AUTO_LOW_PASS && !EEPROM_LOW_PASS) { // если разрешена автонастройка нижнего порога шумов autoLowPass(); } if (EEPROM_LOW_PASS) { // восстановить значения шумов из памяти LOW_PASS = EEPROM.readInt(70); SPEKTR_LOW_PASS = EEPROM.readInt(72); } // в 100 ячейке хранится число 100. Если нет - значит это первый запуск системы if (KEEP_SETTINGS) { if (EEPROM.read(100) != 100) { //Serial.println(F(""First start"")); EEPROM.write(100, 100); updateEEPROM(); } else { readEEPROM(); } } } void loop() { buttonTick(); // опрос и обработка кнопки remoteTick(); // опрос ИК пульта mainLoop(); // главный цикл обработки и отрисовки eepromTick(); // проверка не пора ли сохранить настройки } void mainLoop() { // главный цикл отрисовки if (ONstate) { if (millis() - main_timer > MAIN_LOOP) { // сбрасываем значения RsoundLevel = 0; LsoundLevel = 0; // перваые два режима - громкость (VU meter) if (this_mode == 0 || this_mode == 1) { for (byte i = 0; i < 100; i ++) { // делаем 100 измерений RcurrentLevel = analogRead(SOUND_R); // с правого if (!MONO) LcurrentLevel = analogRead(SOUND_L); // и левого каналов if (RsoundLevel < RcurrentLevel) RsoundLevel = RcurrentLevel; // ищем максимальное if (!MONO) if (LsoundLevel < LcurrentLevel) LsoundLevel = LcurrentLevel; // ищем максимальное } // фильтруем по нижнему порогу шумов RsoundLevel = map(RsoundLevel, LOW_PASS, 1023, 0, 500); if (!MONO)LsoundLevel = map(LsoundLevel, LOW_PASS, 1023, 0, 500); // ограничиваем диапазон RsoundLevel = constrain(RsoundLevel, 0, 500); if (!MONO)LsoundLevel = constrain(LsoundLevel, 0, 500); // возводим в степень (для большей чёткости работы) RsoundLevel = pow(RsoundLevel, EXP); if (!MONO)LsoundLevel = pow(LsoundLevel, EXP); // фильтр RsoundLevel_f = RsoundLevel * SMOOTH + RsoundLevel_f * (1 - SMOOTH); if (!MONO)LsoundLevel_f = LsoundLevel * SMOOTH + LsoundLevel_f * (1 - SMOOTH); if (MONO) LsoundLevel_f = RsoundLevel_f; // если моно, то левый = правому // заливаем ""подложку"", если яркость достаточная if (EMPTY_BRIGHT > 5) { for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, EMPTY_COLOR, 255, EMPTY_BRIGHT); } // если значение выше порога - начинаем самое интересное if (RsoundLevel_f > 15 && LsoundLevel_f > 15) { // расчёт общей средней громкости с обоих каналов, фильтрация. // Фильтр очень медленный, сделано специально для автогромкости averageLevel = (float)(RsoundLevel_f + LsoundLevel_f) / 2 * averK + averageLevel * (1 - averK); // принимаем максимальную громкость шкалы как среднюю, умноженную на некоторый коэффициент MAX_COEF maxLevel = (float)averageLevel * MAX_COEF; // преобразуем сигнал в длину ленты (где MAX_CH это половина количества светодиодов) Rlenght = map(RsoundLevel_f, 0, maxLevel, 0, MAX_CH); Llenght = map(LsoundLevel_f, 0, maxLevel, 0, MAX_CH); // ограничиваем до макс. числа светодиодов Rlenght = constrain(Rlenght, 0, MAX_CH); Llenght = constrain(Llenght, 0, MAX_CH); animation(); // отрисовать } } // 3-5 режим - цветомузыка if (this_mode == 2 || this_mode == 3 || this_mode == 4 || this_mode == 7 || this_mode == 8) { analyzeAudio(); colorMusic[0] = 0; colorMusic[1] = 0; colorMusic[2] = 0; for (int i = 0 ; i < 32 ; i++) { if (fht_log_out[i] < SPEKTR_LOW_PASS) fht_log_out[i] = 0; } // низкие частоты, выборка со 2 по 5 тон (0 и 1 зашумленные!) for (byte i = 2; i < 6; i++) { if (fht_log_out[i] > colorMusic[0]) colorMusic[0] = fht_log_out[i]; } // средние частоты, выборка с 6 по 10 тон for (byte i = 6; i < 11; i++) { if (fht_log_out[i] > colorMusic[1]) colorMusic[1] = fht_log_out[i]; } // высокие частоты, выборка с 11 по 31 тон for (byte i = 11; i < 32; i++) { if (fht_log_out[i] > colorMusic[2]) colorMusic[2] = fht_log_out[i]; } freq_max = 0; for (byte i = 0; i < 30; i++) { if (fht_log_out[i + 2] > freq_max) freq_max = fht_log_out[i + 2]; if (freq_max < 5) freq_max = 5; if (freq_f[i] < fht_log_out[i + 2]) freq_f[i] = fht_log_out[i + 2]; if (freq_f[i] > 0) freq_f[i] -= LIGHT_SMOOTH; else freq_f[i] = 0; } freq_max_f = freq_max * averK + freq_max_f * (1 - averK); for (byte i = 0; i < 3; i++) { colorMusic_aver[i] = colorMusic[i] * averK + colorMusic_aver[i] * (1 - averK); // общая фильтрация colorMusic_f[i] = colorMusic[i] * SMOOTH_FREQ + colorMusic_f[i] * (1 - SMOOTH_FREQ); // локальная if (colorMusic_f[i] > ((float)colorMusic_aver[i] * MAX_COEF_FREQ)) { thisBright[i] = 255; colorMusicFlash[i] = true; running_flag[i] = true; } else colorMusicFlash[i] = false; if (thisBright[i] >= 0) thisBright[i] -= SMOOTH_STEP; if (thisBright[i] < EMPTY_BRIGHT) { thisBright[i] = EMPTY_BRIGHT; running_flag[i] = false; } } animation(); } if (this_mode == 5) { if ((long)millis() - strobe_timer > STROBE_PERIOD) { strobe_timer = millis(); strobeUp_flag = true; strobeDwn_flag = false; } if ((long)millis() - strobe_timer > light_time) { strobeDwn_flag = true; } if (strobeUp_flag) { // если настало время пыхнуть if (strobe_bright < 255) // если яркость не максимальная strobe_bright += STROBE_SMOOTH; // увелчить if (strobe_bright > 255) { // если пробили макс. яркость strobe_bright = 255; // оставить максимум strobeUp_flag = false; // флаг опустить } } if (strobeDwn_flag) { // гаснем if (strobe_bright > 0) // если яркость не минимальная strobe_bright -= STROBE_SMOOTH; // уменьшить if (strobe_bright < 0) { // если пробили мин. яркость strobeDwn_flag = false; strobe_bright = 0; // оставить 0 } } animation(); } if (this_mode == 6) animation(); if (!IRLremote.receiving()) // если на ИК приёмник не приходит сигнал (без этого НЕ РАБОТАЕТ!) strip.show(); // отправить значения на ленту if (this_mode != 7) // 7 режиму не нужна очистка!!! strip.clear(); // очистить массив пикселей main_timer = millis(); // сбросить таймер } } } void animation() { // согласно режиму switch (this_mode) { case 0: count = 0; for (int i = (MAX_CH - 1); i > ((MAX_CH - 1) - Rlenght); i--) { setPixelHSV(i, HUE_GREEN - count * index, 255, 255); count++; } count = 0; for (int i = (MAX_CH); i < (MAX_CH + Llenght); i++ ) { setPixelHSV(i, HUE_GREEN - count * index, 255, 255); count++; } if (EMPTY_BRIGHT > 0) { for (int i = ((MAX_CH - 1) - Rlenght); i > 0; i--) setPixelHSV(i, EMPTY_COLOR, 255, EMPTY_BRIGHT); for (int i = MAX_CH + Llenght; i < NUM_LEDS; i++) setPixelHSV(i, EMPTY_COLOR, 255, EMPTY_BRIGHT); } break; case 1: if (millis() - rainbow_timer > 35) { rainbow_timer = millis(); hue = floor((float)hue + RAINBOW_STEP); if (hue > 255) hue = 0; } count = 0; for (int i = (MAX_CH - 1); i > ((MAX_CH - 1) - Rlenght); i--) { setPixelHSV(i, (count * index) / 2 - hue, 255, 255); count++; } count = 0; for (int i = (MAX_CH); i < (MAX_CH + Llenght); i++ ) { setPixelHSV(i, (count * index) / 2 - hue, 255, 255); count++; } if (EMPTY_BRIGHT > 0) { for (int i = ((MAX_CH - 1) - Rlenght); i > 0; i--) setPixelHSV(i, EMPTY_COLOR, 255, EMPTY_BRIGHT); for (int i = MAX_CH + Llenght; i < NUM_LEDS; i++) setPixelHSV(i, EMPTY_COLOR, 255, EMPTY_BRIGHT); } break; case 2: for (int i = 0; i < NUM_LEDS; i++) { if (i < STRIPE) setPixelHSV(i, HIGH_COLOR, 255, thisBright[2]); else if (i < STRIPE * 2) setPixelHSV(i, MID_COLOR, 255, thisBright[1]); else if (i < STRIPE * 3) setPixelHSV(i, LOW_COLOR, 255, thisBright[0]); else if (i < STRIPE * 4) setPixelHSV(i, MID_COLOR, 255, thisBright[1]); else if (i < STRIPE * 5) setPixelHSV(i, HIGH_COLOR, 255, thisBright[2]); } break; case 3: for (int i = 0; i < NUM_LEDS; i++) { if (i < NUM_LEDS / 3) setPixelHSV(i, HIGH_COLOR, 255, thisBright[2]); else if (i < NUM_LEDS * 2 / 3) setPixelHSV(i, MID_COLOR, 255, thisBright[1]); else if (i < NUM_LEDS) setPixelHSV(i, LOW_COLOR, 255, thisBright[0]); } break; case 4: switch (freq_strobe_mode) { case 0: if (colorMusicFlash[2]) HIGHS(); else if (colorMusicFlash[1]) MIDS(); else if (colorMusicFlash[0]) LOWS(); else SILENCE(); break; case 1: if (colorMusicFlash[2]) HIGHS(); else SILENCE(); break; case 2: if (colorMusicFlash[1]) MIDS(); else SILENCE(); break; case 3: if (colorMusicFlash[0]) LOWS(); else SILENCE(); break; } break; case 5: if (strobe_bright > 0) { setPixelHSV(0, STROBE_COLOR, STROBE_SAT, strobe_bright); uint32_t new_color = strip.getPixelColor(0); for (int i = 1; i < NUM_LEDS; i++) strip.setPixelColor(i, new_color); } else { setPixelHSV(0, EMPTY_COLOR, 255, EMPTY_BRIGHT); uint32_t new_color = strip.getPixelColor(0); for (int i = 1; i < NUM_LEDS; i++) strip.setPixelColor(i, new_color); } break; case 6: switch (light_mode) { case 0: for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, LIGHT_COLOR, LIGHT_SAT, 255); break; case 1: if (millis() - color_timer > COLOR_SPEED) { color_timer = millis(); if (++this_color > 255) this_color = 0; } for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, this_color, LIGHT_SAT, 255); break; case 2: if (millis() - rainbow_timer > 35) { rainbow_timer = millis(); this_color += RAINBOW_PERIOD; if (this_color > 255) this_color = 0; if (this_color < 0) this_color = 255; } rainbow_steps = this_color; for (int i = 0; i < NUM_LEDS; i++) { setPixelHSV(i, (int)floor(rainbow_steps), 255, 255); rainbow_steps += RAINBOW_STEP_2; if (rainbow_steps > 255) rainbow_steps = 0; if (rainbow_steps < 0) rainbow_steps = 255; } break; } break; case 7: switch (freq_strobe_mode) { case 0: if (running_flag[2]) setPixelHSV(NUM_LEDS / 2, HIGH_COLOR, 255, thisBright[2]); else if (running_flag[1]) setPixelHSV(NUM_LEDS / 2, MID_COLOR, 255, thisBright[1]); else if (running_flag[0]) setPixelHSV(NUM_LEDS / 2, LOW_COLOR, 255, thisBright[0]); else setPixelHSV(NUM_LEDS / 2, EMPTY_COLOR, 255, EMPTY_BRIGHT); break; case 1: if (running_flag[2]) setPixelHSV(NUM_LEDS / 2, HIGH_COLOR, 255, thisBright[2]); else setPixelHSV(NUM_LEDS / 2, EMPTY_COLOR, 255, EMPTY_BRIGHT); break; case 2: if (running_flag[1]) setPixelHSV(NUM_LEDS / 2, MID_COLOR, 255, thisBright[1]); else setPixelHSV(NUM_LEDS / 2, EMPTY_COLOR, 255, EMPTY_BRIGHT); break; case 3: if (running_flag[0]) setPixelHSV(NUM_LEDS / 2, LOW_COLOR, 255, thisBright[0]); else setPixelHSV(NUM_LEDS / 2, EMPTY_COLOR, 255, EMPTY_BRIGHT); break; } strip.setPixelColor((NUM_LEDS / 2) - 1, strip.getPixelColor(NUM_LEDS / 2)); if (millis() - running_timer > RUNNING_SPEED) { running_timer = millis(); for (byte i = 0; i < NUM_LEDS / 2 - 1; i++) { strip.setPixelColor(i, strip.getPixelColor(i + 1)); strip.setPixelColor(NUM_LEDS - i - 1, strip.getPixelColor(i)); } } break; case 8: byte HUEindex = HUE_START; for (byte i = 0; i < NUM_LEDS / 2; i++) { byte this_bright = map(freq_f[(int)floor((NUM_LEDS / 2 - i) / freq_to_stripe)], 0, freq_max_f, 0, 255); this_bright = constrain(this_bright, 0, 255); setPixelHSV(i, HUEindex, 255, this_bright); setPixelHSV(NUM_LEDS - i - 1, HUEindex, 255, this_bright); HUEindex += HUE_STEP; if (HUEindex > 255) HUEindex = 0; } break; } } void HIGHS() { for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, HIGH_COLOR, 255, thisBright[2]); } void MIDS() { for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, MID_COLOR, 255, thisBright[1]); } void LOWS() { for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, LOW_COLOR, 255, thisBright[0]); } void SILENCE() { for (int i = 0; i < NUM_LEDS; i++) setPixelHSV(i, EMPTY_COLOR, 255, EMPTY_BRIGHT); } // вспомогательная функция, изменяет величину value на шаг incr в пределах minimum.. maximum int smartIncr(int value, int incr_step, int mininmum, int maximum) { int val_buf = value + incr_step; val_buf = constrain(val_buf, mininmum, maximum); //Serial.println(val_buf); return val_buf; } float smartIncrFloat(float value, float incr_step, float mininmum, float maximum) { float val_buf = value + incr_step; val_buf = constrain(val_buf, mininmum, maximum); //Serial.println(val_buf); return val_buf; } void remoteTick() { if (IRLremote.available()) { auto data = IRLremote.read(); IRdata = data.command; ir_flag = true; } if (ir_flag) { // если данные пришли eeprom_timer = millis(); eeprom_flag = true; switch (IRdata) { // режимы case BUTT_1: this_mode = 0; break; case BUTT_2: this_mode = 1; break; case BUTT_3: this_mode = 2; break; case BUTT_4: this_mode = 3; break; case BUTT_5: this_mode = 4; break; case BUTT_6: this_mode = 5; break; case BUTT_7: this_mode = 6; break; case BUTT_8: this_mode = 7; break; case BUTT_9: this_mode = 8; break; case BUTT_0: fullLowPass(); break; case BUTT_STAR: ONstate = !ONstate; strip.clear(); strip.show(); updateEEPROM(); break; case BUTT_HASH: switch (this_mode) { case 4: case 7: if (++freq_strobe_mode > 3) freq_strobe_mode = 0; break; case 6: if (++light_mode > 2) light_mode = 0; break; } break; case BUTT_OK: settings_mode = !settings_mode; digitalWrite(13, settings_mode); break; case BUTT_UP: if (settings_mode) { // ВВЕРХ общие настройки EMPTY_BRIGHT = smartIncr(EMPTY_BRIGHT, 5, 0, 255); } else { switch (this_mode) { case 0: break; case 1: RAINBOW_STEP = smartIncrFloat(RAINBOW_STEP, 0.5, 0.5, 20); break; case 2: case 3: case 4: MAX_COEF_FREQ = smartIncrFloat(MAX_COEF_FREQ, 0.1, 0, 5); break; case 5: STROBE_PERIOD = smartIncr(STROBE_PERIOD, 20, 1, 1000); break; case 6: switch (light_mode) { case 0: LIGHT_SAT = smartIncr(LIGHT_SAT, 20, 0, 255); break; case 1: LIGHT_SAT = smartIncr(LIGHT_SAT, 20, 0, 255); break; case 2: RAINBOW_STEP_2 = smartIncrFloat(RAINBOW_STEP_2, 0.5, 0.5, 10); break; } break; case 7: MAX_COEF_FREQ = smartIncrFloat(MAX_COEF_FREQ, 0.1, 0.0, 10); break; case 8: HUE_START = smartIncr(HUE_START, 10, 0, 255); break; } } break; case BUTT_DOWN: if (settings_mode) { // ВНИЗ общие настройки EMPTY_BRIGHT = smartIncr(EMPTY_BRIGHT, -5, 0, 255); } else { switch (this_mode) { case 0: break; case 1: RAINBOW_STEP = smartIncrFloat(RAINBOW_STEP, -0.5, 0.5, 20); break; case 2: case 3: case 4: MAX_COEF_FREQ = smartIncrFloat(MAX_COEF_FREQ, -0.1, 0, 5); break; case 5: STROBE_PERIOD = smartIncr(STROBE_PERIOD, -20, 1, 1000); break; case 6: switch (light_mode) { case 0: LIGHT_SAT = smartIncr(LIGHT_SAT, -20, 0, 255); break; case 1: LIGHT_SAT = smartIncr(LIGHT_SAT, -20, 0, 255); break; case 2: RAINBOW_STEP_2 = smartIncrFloat(RAINBOW_STEP_2, -0.5, 0.5, 10); break; } break; case 7: MAX_COEF_FREQ = smartIncrFloat(MAX_COEF_FREQ, -0.1, 0.0, 10); break; case 8: HUE_START = smartIncr(HUE_START, -10, 0, 255); break; } } break; case BUTT_LEFT: if (settings_mode) { // ВЛЕВО общие настройки BRIGHTNESS = smartIncr(BRIGHTNESS, -20, 0, 255); strip.setBrightness(BRIGHTNESS); } else { switch (this_mode) { case 0: case 1: SMOOTH = smartIncrFloat(SMOOTH, -0.05, 0.05, 1); break; case 2: case 3: case 4: SMOOTH_FREQ = smartIncrFloat(SMOOTH_FREQ, -0.05, 0.05, 1); break; case 5: STROBE_SMOOTH = smartIncr(STROBE_SMOOTH, -20, 0, 255); break; case 6: switch (light_mode) { case 0: LIGHT_COLOR = smartIncr(LIGHT_COLOR, -10, 0, 255); break; case 1: COLOR_SPEED = smartIncr(COLOR_SPEED, -10, 0, 255); break; case 2: RAINBOW_PERIOD = smartIncr(RAINBOW_PERIOD, -1, -20, 20); break; } break; case 7: RUNNING_SPEED = smartIncr(RUNNING_SPEED, -10, 1, 255); break; case 8: HUE_STEP = smartIncr(HUE_STEP, -1, 1, 255); break; } } break; case BUTT_RIGHT: if (settings_mode) { // ВПРАВО общие настройки BRIGHTNESS = smartIncr(BRIGHTNESS, 20, 0, 255); strip.setBrightness(BRIGHTNESS); } else { switch (this_mode) { case 0: case 1: SMOOTH = smartIncrFloat(SMOOTH, 0.05, 0.05, 1); break; case 2: case 3: case 4: SMOOTH_FREQ = smartIncrFloat(SMOOTH_FREQ, 0.05, 0.05, 1); break; case 5: STROBE_SMOOTH = smartIncr(STROBE_SMOOTH, 20, 0, 255); break; case 6: switch (light_mode) { case 0: LIGHT_COLOR = smartIncr(LIGHT_COLOR, 10, 0, 255); break; case 1: COLOR_SPEED = smartIncr(COLOR_SPEED, 10, 0, 255); break; case 2: RAINBOW_PERIOD = smartIncr(RAINBOW_PERIOD, 1, -20, 20); break; } break; case 7: RUNNING_SPEED = smartIncr(RUNNING_SPEED, 10, 1, 255); break; case 8: HUE_STEP = smartIncr(HUE_STEP, 1, 1, 255); break; } } break; default: eeprom_flag = false; // если не распознали кнопку, не обновляем настройки! break; } ir_flag = false; } } void autoLowPass() { // для режима VU delay(10); // ждём инициализации АЦП int thisMax = 0; // максимум int thisLevel; for (byte i = 0; i < 200; i++) { thisLevel = analogRead(SOUND_R); // делаем 200 измерений if (thisLevel > thisMax) // ищем максимумы thisMax = thisLevel; // запоминаем delay(4); // ждём 4мс } LOW_PASS = thisMax + LOW_PASS_ADD; // нижний порог как максимум тишины + некая величина // для режима спектра thisMax = 0; for (byte i = 0; i < 100; i++) { // делаем 100 измерений analyzeAudio(); // разбить в спектр for (byte j = 2; j < 32; j++) { // первые 2 канала - хлам thisLevel = fht_log_out[j]; if (thisLevel > thisMax) // ищем максимумы thisMax = thisLevel; // запоминаем } delay(4); // ждём 4мс } SPEKTR_LOW_PASS = thisMax + LOW_PASS_FREQ_ADD; // нижний порог как максимум тишины if (EEPROM_LOW_PASS && !AUTO_LOW_PASS) { EEPROM.updateInt(70, LOW_PASS); EEPROM.updateInt(72, SPEKTR_LOW_PASS); } } void analyzeAudio() { for (int i = 0 ; i < FHT_N ; i++) { int sample = analogRead(SOUND_R_FREQ); fht_input[i] = sample; // put real data into bins } fht_window(); // window the data for better frequency response fht_reorder(); // reorder the data before doing the fht fht_run(); // process the data in the fht fht_mag_log(); // take the output of the fht } void buttonTick() { butt1.tick(); // обязательная функция отработки. Должна постоянно опрашиваться if (butt1.isSingle()) // если единичное нажатие if (++this_mode >= MODE_AMOUNT) this_mode = 0; // изменить режим if (butt1.isHolded()) { // кнопка удержана fullLowPass(); } } void fullLowPass() { digitalWrite(13, HIGH); // включить светодиод 13 пин strip.setBrightness(0); // погасить ленту strip.clear(); // очистить массив пикселей strip.show(); // отправить значения на ленту delay(500); // подождать чутка autoLowPass(); // измерить шумы delay(500); // подождать strip.setBrightness(BRIGHTNESS); // вернуть яркость digitalWrite(13, LOW); // выключить светодиод } void updateEEPROM() { EEPROM.updateByte(1, this_mode); EEPROM.updateByte(2, freq_strobe_mode); EEPROM.updateByte(3, light_mode); EEPROM.updateInt(4, RAINBOW_STEP); EEPROM.updateFloat(8, MAX_COEF_FREQ); EEPROM.updateInt(12, STROBE_PERIOD); EEPROM.updateInt(16, LIGHT_SAT); EEPROM.updateFloat(20, RAINBOW_STEP_2); EEPROM.updateInt(24, HUE_START); EEPROM.updateFloat(28, SMOOTH); EEPROM.updateFloat(32, SMOOTH_FREQ); EEPROM.updateInt(36, STROBE_SMOOTH); EEPROM.updateInt(40, LIGHT_COLOR); EEPROM.updateInt(44, COLOR_SPEED); EEPROM.updateInt(48, RAINBOW_PERIOD); EEPROM.updateInt(52, RUNNING_SPEED); EEPROM.updateInt(56, HUE_STEP); EEPROM.updateInt(60, EMPTY_BRIGHT); } void readEEPROM() { this_mode = EEPROM.readByte(1); freq_strobe_mode = EEPROM.readByte(2); light_mode = EEPROM.readByte(3); RAINBOW_STEP = EEPROM.readInt(4); MAX_COEF_FREQ = EEPROM.readFloat(8); STROBE_PERIOD = EEPROM.readInt(12); LIGHT_SAT = EEPROM.readInt(16); RAINBOW_STEP_2 = EEPROM.readFloat(20); HUE_START = EEPROM.readInt(24); SMOOTH = EEPROM.readFloat(28); SMOOTH_FREQ = EEPROM.readFloat(32); STROBE_SMOOTH = EEPROM.readInt(36); LIGHT_COLOR = EEPROM.readInt(40); COLOR_SPEED = EEPROM.readInt(44); RAINBOW_PERIOD = EEPROM.readInt(48); RUNNING_SPEED = EEPROM.readInt(52); HUE_STEP = EEPROM.readInt(56); EMPTY_BRIGHT = EEPROM.readInt(60); } void eepromTick() { if (eeprom_flag) if (millis() - eeprom_timer > 30000) { // 30 секунд после последнего нажатия с пульта eeprom_flag = false; eeprom_timer = millis(); updateEEPROM(); } } /* void setPixelHSV(uint16_t pix, uint8_t h, uint8_t s, uint8_t v) { float r, g, b; float H = (float)h / 255; float S = (float)s / 255; float V = (float)v / 255; int i = int(H * 6); float f = H * 6 - i; float p = V * (1 - S); float q = V * (1 - f * S); float t = V * (1 - (1 - f) * S); switch (i % 6) { case 0: r = V, g = t, b = p; break; case 1: r = q, g = V, b = p; break; case 2: r = p, g = V, b = t; break; case 3: r = p, g = q, b = V; break; case 4: r = t, g = p, b = V; break; case 5: r = V, g = p, b = q; break; } r *= 255; g *= 255; b *= 255; strip.setPixelColor(pix, r, g, b); } */ void setPixelHSV(uint16_t pix, uint8_t hue, uint8_t sat, uint8_t val) { byte h = ((24 * hue / 17) / 60) % 6; byte vmin = (long)val - val * sat / 255; byte a = (long)val * sat / 255 * (hue * 24 / 17 % 60) / 60; byte vinc = vmin + a; byte vdec = val - a; byte r, g, b; switch (h) { case 0: r = val; g = vinc; b = vmin; break; case 1: r = vdec; g = val; b = vmin; break; case 2: r = vmin; g = val; b = vinc; break; case 3: r = vmin; g = vdec; b = val; break; case 4: r = vinc; g = vmin; b = val; break; case 5: r = val; g = vmin; b = vdec; break; } strip.setPixelColor(pix, r, g, b); } ",12368,False,2015.384707677359,median "/* * Target: Lolin D1 Mini */ #include ""Arduino.h"" #include #include #include #include #include #include #include #include #include // #include #include #define VERSION ""v2021.09.26"" #include ""config.h"" #define CURRENT_LIMIT_BOOT 13 #define CURRENT_LIMIT_MIN 6 #define CURRENT_LIMIT_ONE 20 #define CURRENT_LIMIT_THREE 16 #define PP_CURRENT_LIMIT 20 #define THREE_PHASE_RELAY D8 #define THREE_PHASE_OFF 0 #define THREE_PHASE_ON 1 // Unused D5 // Unused A0 #define PUSH_BUTTON D6 #define PUSH_BUTTON_LED D7 #define RXPin D4 // Serial Receive pin #define TXPin D3 // Serial Transmit pin //RS485 control #define SERIAL_COMMUNICATION_CONTROL_PIN D0 // Transmission set pin #define RS485_TX_PIN_VALUE HIGH #define RS485_RX_PIN_VALUE LOW U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/*reset=*/ U8X8_PIN_NONE, /* clock=*/ D1, /* data=*/ D2); SoftwareSerial RS485Serial(RXPin, TXPin); // RX, TX ESP8266WebServer server(80); ModbusIP mb; const byte evse_slave_id = 0x01; const byte sdm_slave_id = 0x02; int byteSend; float sdm_voltage, sdm_current, sdm_power, sdm_energy, sdm_frequency, sdm_import_energy, sdm_export_energy, sdm_import_power, sdm_export_power; unsigned long sdm_updated = 0, evse_updated = 0; // 4: constant led, 8: on ventilation, 16: clear RCD error // 16384: disable EVSE, 8192: disable EVSE after charge // Register 2005 #define EVSE_CONFIG (4 | 8 | 16) #define EVSE_CONFIG_DISABLE_CHARGING 16384 bool evse_charging = false, evse_vehicle_present = false, evse_charging_enabled = true; unsigned int evse_config[10], evse_fw, evse_amp, evse_vehicle_state, evse_state, evse_status, evse_set_current = 0, evse_reg_charging = 0, evse_config_reg; int request_evse_set_current = -1; bool request_evse_stop_charging = false, request_evse_start_charging = false; #define MODE_MANUAL_THREE 3 #define MODE_MANUAL 1 #define MODE_AUTO 2 int evse_mode = MODE_AUTO; int request_evse_mode = -1; int request_phases = -1; unsigned long chargeStart = 0, chargeDuration = 0; float chargeEnergy = 0, chargeEnergyStart = 0; #define STATE_INIT 1 #define STATE_READY 2 #define STATE_CHARGING 3 #define STATE_ERROR 4 unsigned int state = STATE_INIT; #define PHASE_UNKNOWN 0 #define PHASE_ONE 1 #define PHASE_THREE 3 unsigned int phase_state = PHASE_UNKNOWN; String state_error, last_error; // WiFiManager wifiManager; ESP8266WiFiMulti wifiMulti; #define CRC_SEED 0xFFFF //initialization for CRC16 #define CRC_GP 0xA001 //generating polynomial // #define MODBUS_DEBUG 1 void modbus_crc_single(unsigned char b, unsigned int* CRC) { int carry, i ; CRC[0] ^= b & 0xFF; for (i = 0; i < 8; i++) { carry = CRC[0] & 0x0001; CRC[0] >>= 1; if (carry) CRC[0] ^= CRC_GP; } } void modbus_crc(unsigned char *b, int len, unsigned int *CRC) { *CRC = CRC_SEED; for (int i = 0; i < len; i++) { modbus_crc_single(b[i], CRC); } } /* 01 The slave address (always 01) 03 Function code (03 is for read holding registers function), 16 for write multiple registers 04 The number of data bytes to follow (2 registers x 2 bytes each = 4) 00 20 The contents of register 1000 (32A) 00 20 The contents of register 1001 (32A) FA 21 CRC-16 Modbus (cyclic redundancy check) */ void byte2float(byte *data, float *res) { ((byte *)res)[0] = data[3]; ((byte *)res)[1] = data[2]; ((byte *)res)[2] = data[1]; ((byte *)res)[3] = data[0]; } void float2byte(float f, byte *data) { data[3] = ((byte *)&f)[0]; data[2] = ((byte *)&f)[1]; data[1] = ((byte *)&f)[2]; data[0] = ((byte *)&f)[3]; } // #define MODBUS_DEBUG 1 // read holding registers: modbus_send_command(0x01, 3, 1000, 10, 0); // read input registers : modbus_send_command(0x01, 4, 1000, 10, 0); // write multiple holding registers : modbus_send_command(0x01, 16, 1000, 10, int16); int modbus_send_command(byte slave_id, byte function_code, int address, int count, byte *payload, int payload_length, byte *reply, int reply_length) { unsigned char data[10]; unsigned int CRC; byte crc_offset = 6; int err = 0; data[0] = slave_id; data[1] = function_code; // read data[2] = address >> 8; data[3] = address & 0xff; data[4] = count >> 8; data[5] = count & 0xff; for (int i = 0; i < payload_length; i += 1) { data[6 + i] = payload[i]; crc_offset += 1; } modbus_crc(data, crc_offset, &CRC); data[crc_offset + 1] = CRC >> 8; data[crc_offset] = CRC & 0xff; #ifdef MODBUS_DEBUG Serial.print(""TX ""); for (int i = 0; i < (crc_offset + 2); i++) { Serial.print(data[i], HEX); Serial.print("" ""); } Serial.println("".""); #endif // flush input queue while (RS485Serial.available()) { RS485Serial.read(); } digitalWrite(SERIAL_COMMUNICATION_CONTROL_PIN, RS485_TX_PIN_VALUE); delay(1); RS485Serial.write(data, crc_offset + 2); RS485Serial.flush(); digitalWrite(SERIAL_COMMUNICATION_CONTROL_PIN, RS485_RX_PIN_VALUE); delay(1); // read return value byte buf[4]; unsigned int rx_crc = CRC_SEED; //delay(10); int rx_count = RS485Serial.readBytes(buf, 3); if (rx_count != 3) { err = 6; return err; } int rx_slave = buf[0]; int rx_function = buf[1]; int rx_len = buf[2]; modbus_crc_single(buf[0], &rx_crc); modbus_crc_single(buf[1], &rx_crc); modbus_crc_single(buf[2], &rx_crc); #ifdef MODBUS_DEBUG Serial.print(""RX ""); Serial.print(rx_slave); Serial.print("" F""); Serial.print(rx_function); Serial.print("" L""); Serial.print(rx_len); Serial.print("": ""); #endif if (rx_slave != slave_id) { err = 3; } if (rx_function != function_code) { err = 4; } for (int i = 0; i < rx_len; i += 1) { rx_count = RS485Serial.readBytes(buf, 1); if (rx_count == 1) { #ifdef MODBUS_DEBUG Serial.print(buf[0], HEX); Serial.print("" ""); #endif modbus_crc_single(buf[0], &rx_crc); if (i < reply_length) { reply[i] = buf[0]; } } else { #ifdef MODBUS_DEBUG Serial.print(""TO""); #endif err = 2; break; } } rx_count = RS485Serial.readBytes(buf, 2); if ((buf[0] != (rx_crc & 0xff)) || (buf[1] != (rx_crc >> 8))) { Serial.print(""CRCerr ""); Serial.print(buf[0], HEX); Serial.print("" ""); Serial.print(buf[1], HEX); Serial.print("" vs. ""); Serial.print(rx_crc, HEX); Serial.print("" ""); err = 1; } #ifdef MODBUS_DEBUG Serial.println("".""); #endif return err; } int modbus_handle_error(const char *fun, int address, int error) { if (error) { Serial.print(""Modbus Error ""); Serial.print(fun); Serial.print("" ""); Serial.print(address); Serial.print("" ""); Serial.println(error); } return error; } int modbus_read_input_float(byte slave_id, int address, float *res) { byte buf[4], tries = 0; int err = 0; while (tries < 3) { err = modbus_send_command(slave_id, 4, address, 2, NULL, 0, buf, 4); if (!err) break; tries++; } if (err) return modbus_handle_error(""modbus_read_input_float"", address, err); byte2float(buf, res); return 0; } int modbus_read_holding_int(byte slave_id, int address, unsigned int *res) { byte buf[4], tries = 0; int err = 0; while (tries < 3) { err = modbus_send_command(slave_id, 3, address, 2, NULL, 0, buf, 4); if (!err) break; tries++; } if (err) return modbus_handle_error(""modbus_read_holding_int"", address, err); *res = ((unsigned int)buf[0] << 8) + buf[1]; return 0; } int modbus_read_holding_multi_int(byte slave_id, int address, unsigned int count, unsigned int *res) { byte buf[40], tries = 0; int err = 0; while (tries < 3) { err = modbus_send_command(slave_id, 3, address, count, NULL, 0, buf, 40); if (!err) break; tries++; } if (err) return modbus_handle_error(""modbus_read_holding_multi_int"", address, err); for (unsigned int i = 0; i < count; i++) { res[i] = ((unsigned int)buf[0 + 2 * i] << 8) + buf[1 + 2 * i]; } return 0; } int modbus_read_holding_uint32(byte slave_id, int address, uint32_t *res) { byte buf[4]; int err = modbus_send_command(slave_id, 3, address, 2, NULL, 0, buf, 4); if (err) return modbus_handle_error(""modbus_read_holding_uint32"", address, err); *res = ((uint32_t)buf[0] << 24) + ((uint32_t)buf[1] << 16) + ((uint32_t)buf[2] << 8) + buf[3]; return 0; } int modbus_read_float(byte slave_id, int address, float *res) { byte buf[4]; int err = modbus_send_command(slave_id, 3, address, 2, NULL, 0, buf, 4); if (err) return modbus_handle_error(""modbus_read_float"", address, err); byte2float(buf, res); return 0; } int modbus_write_float(byte slave_id, int address, float value) { byte buf[5]; buf[0] = 4; float2byte(value, buf + 1); int err = modbus_send_command(slave_id, 16, address, 2, buf, 5, NULL, 0); if (err) return modbus_handle_error(""modbus_write_float"", address, err); return 0; } int modbus_write_int(byte slave_id, int address, unsigned int value) { byte buf[3], tries = 0; int err; buf[0] = 2; buf[1] = value >> 8; buf[2] = value & 0xff; while (tries < 3) { err = modbus_send_command(slave_id, 16, address, 2, buf, 3, NULL, 0); if (!err) break; tries++; } if (err) return modbus_handle_error(""modbus_write_int"", address, err); return 0; } #define REG_MODEL 5000 #define REG_SERIAL 5001 #define REG_FW 5007 #define REG_MODE 5009 #define REG_START_STOP 5010 #define REG_AC_L1P 5011 #define REG_AC_L2P 5012 #define REG_AC_L3P 5013 #define REG_AC_P 5014 #define REG_STATUS 5015 #define REG_SET_CURRENT 5016 #define REG_MAX_CURRENT 5017 #define REG_CURRENT 5018 #define REG_CHARGING_TIME 5019 #define REG_ENERGY_FORWARD 5021 uint16_t cbWrite(TRegister* reg, uint16_t val) { if ((state == STATE_INIT) || (state == STATE_ERROR)) { return val; } if (reg->value == val) { return val; } Serial.print(""Write. Reg RAW#: ""); Serial.print(reg->address.address); Serial.print("" Old: ""); Serial.print(reg->value); Serial.print("" New: ""); Serial.println(val); switch (reg->address.address) { case REG_MODE: Serial.println(""REG_MODE not implemented""); break; case REG_START_STOP: if (val == 1) { if (!evse_charging) request_evse_start_charging = true; } else { if (evse_charging) request_evse_stop_charging = true; } break; case REG_SET_CURRENT: Serial.print(""REG_SET_CURRENT to""); Serial.println(val); request_evse_set_current = val; break; } return val; } bool cbConn(IPAddress ip) { /* Serial.print(""Modbus connection: ""); Serial.println(ip); */ return true; } uint16_t cbEVSE(TRegister* reg, uint16_t val) { Serial.println(""cbEVSE callback GET""); unsigned int r = 0; int err = modbus_read_holding_int(evse_slave_id, reg->address.address, &r); if (err) { Serial.print(""ERROR ""); Serial.println(err); } return r; } uint16_t cbEVSESet(TRegister* reg, uint16_t val) { Serial.println(""cbEVSE callback SET""); int err = modbus_write_int(evse_slave_id, reg->address.address, val); if (err) { Serial.print(""ERROR ""); Serial.println(err); } return val; } void init_modbus() { // see https://github.com/victronenergy/dbus-modbus-client/blob/master/ev_charger.py, models mb.addHreg(REG_MODEL, 0xc024); for (int i = 0; i < 6; i++) { mb.addHreg(REG_SERIAL + i, 65); } mb.addHreg(REG_FW, 1); mb.addHreg(REG_FW + 1, 0); mb.addHreg(REG_MODE, 1); // 0 MANUAL or 1 for auto mb.onSetHreg(REG_MODE, cbWrite, 1); mb.addHreg(REG_START_STOP, 0); // or 1 for start mb.onSetHreg(REG_START_STOP, cbWrite, 1); mb.addHreg(REG_AC_L1P, 1); mb.addHreg(REG_AC_L2P, 1); mb.addHreg(REG_AC_L3P, 1); mb.addHreg(REG_AC_P, 1); mb.addHreg(REG_SET_CURRENT, 1); mb.onSetHreg(REG_SET_CURRENT, cbWrite, 1); mb.addHreg(REG_MAX_CURRENT, 1); mb.onSetHreg(REG_MAX_CURRENT, cbWrite, 1); mb.addHreg(REG_CURRENT, 10); mb.addHreg(REG_CHARGING_TIME, 0); mb.addHreg(REG_CHARGING_TIME + 1, 0); mb.addHreg(REG_ENERGY_FORWARD, 100); // Passthrough for debugging of EVSE for (int i = 1000; i < 1010; i++) { mb.onGetHreg(i, cbEVSE); mb.onSetHreg(i, cbEVSESet, 1); } for (int i = 2000; i < 2020; i++) { mb.onGetHreg(i, cbEVSE); mb.onSetHreg(i, cbEVSESet, 1); } updateModbus(); mb.onConnect(cbConn); mb.server(); } void updateModbus() { // https://github.com/victronenergy/dbus-modbus-client/blob/master/ev_charger.py unsigned int p = sdm_power; mb.Hreg(REG_MODE, 1); mb.Hreg(REG_AC_L1P, p); if (phase_state == PHASE_ONE) { mb.Hreg(REG_AC_L2P, 0); mb.Hreg(REG_AC_L3P, 0); mb.Hreg(REG_AC_P, p); } else { mb.Hreg(REG_AC_L2P, p); mb.Hreg(REG_AC_L3P, p); mb.Hreg(REG_AC_P, 3 * p); } /* DISCONNECTED = 0 CONNECTED = 1 CHARGING = 2 CHARGED = 3 WAIT_SUN = 4 WAIT_RFID = 5 WAIT_START = 6 LOW_SOC = 7 GND_ERROR = 8 WELD_CON = 9 CP_SHORTED = 10 */ int mb_status = 0; if (evse_charging) { mb_status = 2; } else if (evse_vehicle_present) { mb_status = 1; } mb.Hreg(REG_STATUS, mb_status); mb.Hreg(REG_SET_CURRENT, evse_set_current); mb.Hreg(REG_MAX_CURRENT, PP_CURRENT_LIMIT); mb.Hreg(REG_CURRENT, evse_amp * 10); mb.Hreg(REG_CHARGING_TIME, chargeDuration); mb.Hreg(REG_ENERGY_FORWARD, (int)(chargeEnergy*100)); } DynamicJsonDocument doc(1024); void getJson() { doc[""meter""][""updated""] = sdm_updated; doc[""meter""][""voltage""] = sdm_voltage; doc[""meter""][""current""] = sdm_current; doc[""meter""][""power""] = sdm_power; doc[""meter""][""energy""] = sdm_energy; doc[""meter""][""frequency""] = sdm_frequency; doc[""meter""][""energy_import""] = sdm_import_energy; doc[""meter""][""energy_export""] = sdm_export_energy; doc[""meter""][""power_import""] = sdm_import_power; doc[""meter""][""power_export""] = sdm_export_power; doc[""meter""][""updated""] = sdm_updated; doc[""evse""][""config_reg""] = evse_config_reg; doc[""evse""][""charging_reg""] = evse_reg_charging; doc[""evse""][""charging_enabled""] = evse_charging_enabled; doc[""evse""][""charging""] = evse_charging; doc[""evse""][""vehicle_present""] = evse_vehicle_present; doc[""evse""][""state""] = evse_state; doc[""evse""][""vehicle_state""] = evse_vehicle_state; doc[""evse""][""status""] = evse_status; doc[""evse""][""set_current""] = evse_set_current; doc[""evse""][""announced_current""] = evse_amp; doc[""evse""][""firmware""] = evse_fw; doc[""evse""][""phases""] = phase_state; doc[""evse""][""mode""] = evse_mode; doc[""evse""][""updated""] = evse_updated; doc[""charge""][""duration""] = chargeDuration; doc[""charge""][""energy""] = chargeEnergy; doc[""state""] = state; doc[""state_error""] = state_error; doc[""last_error""] = last_error; doc[""uptime""] = millis(); doc[""version""] = VERSION; WiFiClient client = server.client(); client.println(""HTTP/1.0 200 OK""); client.println(""Content-Type: application/json""); client.println(""Access-Control-Allow-Origin: *""); client.println(""Connection: close""); client.println(); // server.sendHeader(""Content-Type"", ""application/json""); // client.println(""Content-Type: application/json""); serializeJson(doc, client); client.stop(); } void getIndex() { server.send(200, F(""text/html""), F(""Welcome to the Trixing EVSE Web Server"")); } void post_charging() { Serial.print(""Post Change Charging State: ""); if (server.hasArg(""value"")) { int val = server.arg(""value"").toInt(); if (val == 1) { Serial.println(""Start""); request_evse_start_charging = true; server.send(200, ""text/plain"", ""OK""); return; } else if (val == 2) { Serial.println(""Stop""); request_evse_stop_charging = true; server.send(200, ""text/plain"", ""OK""); return; } } Serial.println(""Error""); server.send(400, ""text/plain"", ""ERR value:(1=start, 2=stop)""); } void post_current() { Serial.print(""Post Set Current: ""); if (server.hasArg(""value"")) { int val = server.arg(""value"").toInt(); if ((val >= CURRENT_LIMIT_MIN) && (val <= PP_CURRENT_LIMIT)) { Serial.println(val); request_evse_set_current = val; server.send(200, ""text/plain"", ""OK""); return; } } Serial.println(""Error""); server.send(400, ""text/plain"", ""ERR value:current""); } void post_mode() { Serial.print(""Post Mode: ""); if (server.hasArg(""value"")) { int val = server.arg(""value"").toInt(); if (val == 1) { Serial.println(val); request_evse_mode = val; server.send(200, ""text/plain"", ""OK""); return; } } Serial.println(""Error""); server.send(400, ""text/plain"", ""ERR value:1""); } void post_phases() { Serial.print(""Post Three Phase: ""); if (server.hasArg(""value"")) { int val = server.arg(""value"").toInt(); if ((val == 3) || (val == 1)) { Serial.print(val); request_phases = val; server.send(200, ""text/plain"", ""OK""); return; } } Serial.println(""Error""); server.send(400, ""text/plain"", ""ERR value:3""); } String getContentType(String filename) { // convert the file extension to the MIME type if (filename.endsWith("".html"")) return ""text/html""; else if (filename.endsWith("".css"")) return ""text/css""; else if (filename.endsWith("".js"")) return ""application/javascript""; else if (filename.endsWith("".ico"")) return ""image/x-icon""; return ""text/plain""; } void handleNotFound() { String path = server.uri(); if (path.endsWith(""/"")) path += ""index.html""; Serial.print(""Request: ""); Serial.print(path); if (SPIFFS.exists(path)) { String contentType = getContentType(path); File file = SPIFFS.open(path, ""r""); // Open it size_t sent = server.streamFile(file, contentType); // And send it to the client file.close(); // Then close the file again Serial.println("" OK""); return; } Serial.println("" 404""); String message = ""File Not Found\\n\\n""; message += ""URI: ""; message += server.uri(); message += ""\\nMethod: ""; message += (server.method() == HTTP_GET) ? ""GET"" : ""POST""; message += ""\\nArguments: ""; message += server.args(); message += ""\\n""; for (uint8_t i = 0; i < server.args(); i++) { message += "" "" + server.argName(i) + "": "" + server.arg(i) + ""\\n""; } server.send(404, ""text/plain"", message); } void start_webserver() { server.on(F(""/j""), HTTP_GET, getJson); // 0 to disable charging for an hour or until reboot server.on(F(""/charging""), HTTP_POST, post_charging); server.on(F(""/current""), HTTP_POST, post_current); server.on(F(""/mode""), HTTP_POST, post_mode); server.on(F(""/phases""), HTTP_POST, post_phases); server.on(""/update"", HTTP_POST, []() { server.sendHeader(""Connection"", ""close""); server.send(200, ""text/plain"", (Update.hasError()) ? ""FAIL"" : ""OK""); ESP.restart(); }, []() { HTTPUpload& upload = server.upload(); if (upload.status == UPLOAD_FILE_START) { Serial.setDebugOutput(true); WiFiUDP::stopAll(); Serial.printf(""Update: %s\\n"", upload.filename.c_str()); uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; if (!Update.begin(maxSketchSpace)) { //start with max available size Update.printError(Serial); } } else if (upload.status == UPLOAD_FILE_WRITE) { if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { Update.printError(Serial); } } else if (upload.status == UPLOAD_FILE_END) { if (Update.end(true)) { //true to set the size to the current progress Serial.printf(""Update Success: %u\\nRebooting...\\n"", upload.totalSize); } else { Update.printError(Serial); } Serial.setDebugOutput(false); } yield(); }); // Set not found response server.onNotFound(handleNotFound); // Start server server.close(); server.begin(); } int swap_line(const char *new_line, char *old_line, U8X8 u8x8) { int i, chg = 0; char b[2] = {0, 0}; //unsigned long t = millis(), t2; bool eol = false; for (i = 0; i < 8; i++) { if (!eol && (new_line[i] == 0)) eol = true; if (eol) { if (old_line[i] != 0) { u8x8.drawString(i * 2, 1, "" ""); old_line[i] = 0; chg++; } } else { if (new_line[i] != old_line[i]) { b[0] = new_line[i]; old_line[i] = new_line[i]; u8x8.drawString(i * 2, 1, b); chg++; } } } //t2 = millis(); if (chg > 0) { Serial.println(new_line); /* Serial.print(new_line); Serial.print("" ""); Serial.print(chg); Serial.print(""x ""); Serial.print(t2 - t); Serial.println("" ms""); */ } return chg; } char line_out_0[9]; char ubuf[32]; volatile unsigned long button_trigger = 0; ICACHE_RAM_ATTR void push_button() { int btn = digitalRead(PUSH_BUTTON); Serial.print(millis()); Serial.print("" ""); Serial.println(btn); if (btn == 0) { button_trigger = millis(); return; } unsigned long duration = millis() - button_trigger; Serial.print(""PUSH BUTTON: ""); Serial.println(duration); if (duration < 10) { // ignore } else if (duration < 1000) { request_evse_mode = 1; } else { Serial.println("" press too long""); } } /* void configModeCallback (WiFiManager *myWiFiManager) { Serial.println(""Entered config mode""); Serial.println(WiFi.softAPIP()); Serial.println(myWiFiManager->getConfigPortalSSID()); sprintf(ubuf, ""WifiConf""); swap_line(ubuf, line_out_0, u8x8); } */ void update_display(const char *text) { sprintf(ubuf, ""%s"", text); swap_line(ubuf, line_out_0, u8x8); } void setupOTA() { ArduinoOTA.onStart([]() { String type; if (ArduinoOTA.getCommand() == U_FLASH) { type = ""sketch""; } else { // U_FS type = ""filesystem""; } // NOTE: if updating FS this would be the place to unmount FS using FS.end() Serial.println(""Start updating "" + type); }); ArduinoOTA.onEnd([]() { Serial.println(""\\nEnd""); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { Serial.printf(""Progress: %u%%\\r"", (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) { Serial.printf(""Error[%u]: "", error); if (error == OTA_AUTH_ERROR) { Serial.println(""Auth Failed""); } else if (error == OTA_BEGIN_ERROR) { Serial.println(""Begin Failed""); } else if (error == OTA_CONNECT_ERROR) { Serial.println(""Connect Failed""); } else if (error == OTA_RECEIVE_ERROR) { Serial.println(""Receive Failed""); } else if (error == OTA_END_ERROR) { Serial.println(""End Failed""); } }); #ifdef OTA_PASSWORD ArduinoOTA.setPassword(OTA_PASSWORD); #endif ArduinoOTA.begin(); } void setup() { Serial.begin(115200); Serial.println(""""); Serial.println(""Trixing EVSE Wifi""); Serial.print(""Version "" VERSION); Serial.println(""""); pinMode(PUSH_BUTTON, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(PUSH_BUTTON), push_button, CHANGE); pinMode(PUSH_BUTTON_LED, OUTPUT); digitalWrite(PUSH_BUTTON_LED, 0); pinMode(THREE_PHASE_RELAY, OUTPUT); digitalWrite(THREE_PHASE_RELAY, 0); pinMode(SERIAL_COMMUNICATION_CONTROL_PIN, OUTPUT); digitalWrite(SERIAL_COMMUNICATION_CONTROL_PIN, RS485_RX_PIN_VALUE); RS485Serial.begin(9600); // set the data rate RS485Serial.setTimeout(100); u8x8.setBusClock(800000); u8x8.begin(); u8x8.setFont(u8x8_font_profont29_2x3_r); update_display(""TrixEVSE""); wifiMulti.addAP(ssid, password); wifiMulti.addAP(ssid_backup, password_backup); WiFi.persistent(false); WiFi.hostname(""trixing-evse""); WiFi.mode(WIFI_STA); WiFi.setPhyMode(WIFI_PHY_MODE_11N); WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.setAutoReconnect(true); WiFi.config(staticIP, gateway, subnet, dnsIP, dnsIPA); WiFi.begin(ssid, password); /* // wifiManager.setConfigPortalTimeout(180); wifiManager.setConnectTimeout(5000); wifiManager.setConfigPortalBlocking(false); wifiManager.setAPCallback(configModeCallback); wifiManager.autoConnect(""TrixEVSE""); */ sprintf(ubuf, ""Trix EVSE""); swap_line(ubuf, line_out_0, u8x8); Serial.print("" - Mount SPIFFS""); SPIFFS.begin(); Serial.print("" - IP address: ""); Serial.println(WiFi.localIP()); Serial.println("" - setup http server""); start_webserver(); if (MDNS.begin(""trixing-evse"")) { Serial.println("" - MDNS responder started""); } Serial.println("" - setup modbus/tcp server""); init_modbus(); Serial.println("" - setup OTA""); #ifdef OTA_PASSWORD Serial.println("" - OTA password "" OTA_PASSWORD); #endif setupOTA(); /* from pymodbus.client.sync import ModbusTcpClient client = ModbusTcpClient('192.168.178.112') reg = client.read_holding_registers(100) print('%x' % reg.getRegister(0)) client.write_register(100, 0x1234) */ Serial.println("" - setup end""); } int evse_stop_charging() { // stop modbus_write_int(evse_slave_id, 1004, 1); delay(100); // disable to prevent re-enabling modbus_write_int(evse_slave_id, 2005, EVSE_CONFIG | EVSE_CONFIG_DISABLE_CHARGING); return 0; } int evse_start_charging() { // clear inhibit charging bit modbus_write_int(evse_slave_id, 2005, EVSE_CONFIG); delay(100); // start charging modbus_write_int(evse_slave_id, 1004, 0); return 0; } unsigned int sdm_meter_code, sdm_sw_version; uint32_t sdm_serial; int sdmInit() { int err = modbus_read_holding_uint32(sdm_slave_id, 0xFC00, &sdm_serial) || modbus_read_holding_int(sdm_slave_id, 0xFC02, &sdm_meter_code) || modbus_read_holding_int(sdm_slave_id, 0xFC03, &sdm_sw_version); if (err) { Serial.print(""sdm_init failed ""); Serial.println(err); } else { Serial.print(""sdm_init success: meter_code ""); Serial.print(sdm_meter_code); Serial.print("", serial ""); Serial.print(sdm_serial); Serial.print("", version ""); Serial.println(sdm_sw_version); } return err; } int evseInit() { int err = modbus_read_holding_multi_int(evse_slave_id, 2000, 10, evse_config); err += 10 * modbus_read_holding_int(evse_slave_id, 1000, &evse_set_current); err += 100 * modbus_read_holding_int(evse_slave_id, 1005, &evse_fw); err += 1000 * modbus_read_holding_int(evse_slave_id, 1002, &evse_vehicle_state); if (err) { Serial.print(""evse_init failed ""); Serial.println(err); return err; } Serial.print(""evse_init firmware ""); Serial.println(evse_fw); // Disable PP detection, fixed limit if (evse_config[7] != PP_CURRENT_LIMIT) { err = modbus_write_int(evse_slave_id, 2007, PP_CURRENT_LIMIT); if (err) return err; } if (evse_config[5] != EVSE_CONFIG) { err = modbus_write_int(evse_slave_id, 2005, EVSE_CONFIG); if (err) return err; } // default amps after boot if (evse_config[0] != CURRENT_LIMIT_BOOT) { err = modbus_write_int(evse_slave_id, 2000, CURRENT_LIMIT_BOOT); if (err) return err; } return 0; } void evse_configure_set_current() { if (request_evse_set_current <= 0) return; if (request_evse_set_current == (int)evse_set_current) { request_evse_set_current = -1; return; } // write current limit if (request_evse_set_current < CURRENT_LIMIT_MIN) { request_evse_set_current = -1; return; } if (request_evse_set_current > PP_CURRENT_LIMIT) { request_evse_set_current = -1; return; } if ( ((phase_state == PHASE_ONE) && (request_evse_set_current <= CURRENT_LIMIT_ONE)) || ((phase_state == PHASE_THREE) && (request_evse_set_current <= CURRENT_LIMIT_THREE)) ) { int err = modbus_write_int(evse_slave_id, 1000, request_evse_set_current); if (err) return; evse_set_current = request_evse_set_current; request_evse_set_current = -1; } else { request_evse_set_current = -1; } } const char *vehicle_states[] = { // 1002 ""none"", // 0 ""ready"", // 1 ""EV is present"", // 2 ""charging"", // 3 ""charging with ventilation"", // 4 ""failure"" }; const char *evse_states[] = { // 1006 ""none"", ""steady 12V"", // 1 ""PWM is being generated"", // 2 ""OFF, steady 12V"" }; bool evse_relay_on, evse_diode_check_fail, evse_vent_req_fail, evse_wait_pilot_rel, evse_rcd_check_err; void decodeEvseStatus(unsigned int status) { evse_relay_on = (status & 1); evse_diode_check_fail = (status & 2); evse_vent_req_fail = (status & 4); evse_wait_pilot_rel = (status & 8); evse_rcd_check_err = (status & 16); } void evse_toggle_three_phases(unsigned int newstate) { int tries = 10, err; unsigned int hw_state; if (newstate == phase_state) { // nothing to do return; } evse_stop_charging(); while (tries) { err = modbus_read_holding_int(evse_slave_id, 1007, &hw_state); if (err) { tries--; delay(20); continue; } if (!(hw_state & 0x01)) { break;// wait until relay is off } tries--; delay(500); // 2. } if (!tries) { // FAILED, do not touch relay!! Serial.println(""Three phase failed: charge stop""); return; } // Write new current config, default to boot config. err = modbus_write_int(evse_slave_id, 1000, CURRENT_LIMIT_BOOT); if (err) { Serial.println(""Three phase failed: current config""); return; } evse_set_current = CURRENT_LIMIT_BOOT; request_evse_set_current = -1; // PHASE L2 & L3 RELAY ON or OFF if (newstate == PHASE_THREE) { digitalWrite(THREE_PHASE_RELAY, THREE_PHASE_ON); phase_state = PHASE_THREE; } else { digitalWrite(THREE_PHASE_RELAY, THREE_PHASE_OFF); phase_state = PHASE_ONE; } // short delay to avoid too fast trigger of relay delay(500); // enable charging possibility again evse_start_charging(); } int update_modbus_cnt = 0; int updateModbusData() { int reterr = 0; bool extended_update = ((update_modbus_cnt % 10) == 0); update_modbus_cnt++; int err = modbus_read_input_float(sdm_slave_id, 0x0006, &sdm_current) || modbus_read_input_float(sdm_slave_id, 0x000C, &sdm_power) || modbus_read_input_float(sdm_slave_id, 0x0156, &sdm_energy); if (extended_update) { err = err || modbus_read_input_float(sdm_slave_id, 0x0000, &sdm_voltage) || modbus_read_input_float(sdm_slave_id, 0x0046, &sdm_frequency) || modbus_read_input_float(sdm_slave_id, 0x0048, &sdm_import_energy) || modbus_read_input_float(sdm_slave_id, 0x004a, &sdm_export_energy) || modbus_read_input_float(sdm_slave_id, 0x0058, &sdm_import_power) || modbus_read_input_float(sdm_slave_id, 0x005c, &sdm_export_power) ; } if (err) { Serial.print(""update_modbus_data sdm failed ""); Serial.println(err); reterr = 1; } else { sdm_updated = millis(); } err = modbus_read_holding_int(evse_slave_id, 1001, &evse_amp) || modbus_read_holding_int(evse_slave_id, 1002, &evse_vehicle_state) || modbus_read_holding_int(evse_slave_id, 1004, &evse_reg_charging) || modbus_read_holding_int(evse_slave_id, 1006, &evse_state) || modbus_read_holding_int(evse_slave_id, 1007, &evse_status) || modbus_read_holding_int(evse_slave_id, 2005, &evse_config_reg); if (err) { Serial.print(""update_modbus_data evse failed ""); Serial.println(err); reterr = 2; } else { evse_updated = millis(); } decodeEvseStatus(evse_status); evse_vehicle_present = (evse_vehicle_state >= 2); /* Serial.print(evse_relay_on); Serial.print("" ""); Serial.print(evse_state); Serial.print("" "");meter Serial.print(evse_vehicle_state); Serial.print("" ""); Serial.print(sdm_power); Serial.println(); */ evse_charging = (evse_relay_on || (evse_vehicle_state == 3) || (evse_vehicle_state == 4) || (sdm_power > 5.0)); evse_charging_enabled = !(evse_config_reg & EVSE_CONFIG_DISABLE_CHARGING) && !(evse_reg_charging & 1); if (request_evse_stop_charging) { evse_stop_charging(); evse_charging_enabled = false; request_evse_stop_charging = false; } if (request_evse_start_charging) { evse_start_charging(); evse_charging_enabled = true; request_evse_start_charging = false; } if (!evse_charging && (phase_state == PHASE_UNKNOWN)) { // After boot we know that the relay is off, hence once the charging // stops, we know it is configured to one phase. Serial.println(""Phase-state ONE""); phase_state = PHASE_ONE; } if (!evse_charging) { evse_amp = 0; } evse_configure_set_current(); return reterr; } unsigned long lastInitRetry = 0; unsigned long lastModbusUpdate = 0; unsigned long lastStateError = 0; unsigned long modeTimeout = 0; unsigned int last_state = 99; unsigned long blink_last = 0; char blink_pattern[10] = ""1""; int blink_idx; void blink_mode(const char *pattern) { strncpy(blink_pattern, pattern, 10); } void blink_manager() { unsigned long now = millis(); if ((now - blink_last) < 200) { return; } blink_idx++; if (blink_pattern[blink_idx] == 0) { blink_idx = 0; } if (blink_pattern[blink_idx] == '1') { digitalWrite(PUSH_BUTTON_LED, 1); } else { digitalWrite(PUSH_BUTTON_LED, 0); } blink_last = now; } bool wifi_manager_portal_active = true; void loop() { unsigned long now = millis(); switch (state) { case STATE_INIT: if ((now - lastInitRetry) > 5000) { lastInitRetry = now; if (sdmInit()) { state_error = ""SDM Init failed""; state = STATE_ERROR; lastStateError = now; break; } if (evseInit()) { state_error = ""EVSE Init failed""; state = STATE_ERROR; lastStateError = now; break; } state_error = """"; updateModbusData(); } else { break; } Serial.println(""Ready?""); request_evse_mode = -1; state = STATE_READY; // Intentionally no break to fall through to charging check. case STATE_READY: if (evse_charging) { state = STATE_CHARGING; chargeStart = now; chargeDuration = 0; chargeEnergyStart = sdm_energy; chargeEnergy = 0; break; } if (request_evse_mode != -1) { modeTimeout = now + 2 * 60000; // 2 minutes if (!evse_charging_enabled) { request_evse_start_charging = true; } else if (evse_mode == MODE_AUTO) { evse_mode = MODE_MANUAL; request_evse_set_current = CURRENT_LIMIT_ONE; } else if (evse_mode == MODE_MANUAL) { evse_mode = MODE_MANUAL_THREE; request_evse_set_current = CURRENT_LIMIT_THREE; } else { evse_mode = MODE_AUTO; // 1 phase has a higher limit anyways than 3-phase // request_evse_set_current = CURRENT_LIMIT_BOOT; request_phases = PHASE_ONE; // digitalWrite(THREE_PHASE_RELAY, THREE_PHASE_OFF); // phase_state = PHASE_ONE; } } if ((now > modeTimeout) && (evse_mode != MODE_AUTO)) { evse_mode = MODE_AUTO; // We are not charging, so this is safe to do. request_evse_set_current = CURRENT_LIMIT_BOOT; request_phases = PHASE_ONE; } request_evse_mode = -1; break; case STATE_CHARGING: if (request_evse_mode != -1) { evse_stop_charging(); } request_evse_mode = -1; if (!evse_charging) { // sane default after charging. state = STATE_READY; phase_state = PHASE_ONE; evse_mode = MODE_AUTO; // Do not reset current, if we go from 3 to 1 phase, the limit will be smaller anyways. // request_evse_set_current = CURRENT_LIMIT_BOOT; break; } if (chargeEnergyStart == 0) { chargeEnergyStart = sdm_energy; } chargeDuration = now - chargeStart; chargeEnergy = sdm_energy - chargeEnergyStart; if (phase_state == PHASE_THREE) { chargeEnergy *= 3; // We detected we are in the charging state, we consume power, that // means the relay is hold on by the ""back-current"" from the charging // phase. Turn this off that in case of power interruption, we want // to fall back to PHASE_ONE state. (see above) if (evse_charging && (sdm_power > 5.0)) { digitalWrite(THREE_PHASE_RELAY, THREE_PHASE_OFF); // not setting phase_state to ONE until after charging is done (see above) } } break; case STATE_ERROR: if ((now - lastStateError) > 30000) { state = STATE_INIT; } request_evse_mode = -1; break; default: // should never happen(tm) state = STATE_ERROR; lastStateError = now; break; } if (((evse_mode == MODE_MANUAL_THREE) && (phase_state != PHASE_THREE)) || (request_phases == PHASE_THREE)) { evse_toggle_three_phases(PHASE_THREE); } else if (((evse_mode == MODE_MANUAL) && (phase_state != PHASE_ONE)) || (request_phases == PHASE_ONE)) { evse_toggle_three_phases(PHASE_ONE); } request_phases = -1; char tmp[10], tmp2[10]; unsigned long s = (now % 15000) / 5000; int phase_multiplier = 1; if (phase_state == PHASE_THREE) { phase_multiplier = 3; } switch (state) { case STATE_INIT: update_display(""Init""); break; case STATE_READY: if (evse_vehicle_present) { sprintf(tmp, ""Veh""); } else { sprintf(tmp, ""Rdy""); } if (!evse_charging_enabled) { sprintf(tmp2, ""%s DIS"", tmp); } else if (s == 0) { switch (evse_mode) { case MODE_AUTO: sprintf(tmp2, ""%s AUTO"", tmp); blink_mode(""1""); break; case MODE_MANUAL: sprintf(tmp2, ""%s 1-PH"", tmp); blink_mode(""11110000""); break; case MODE_MANUAL_THREE: sprintf(tmp2, ""%s 3-PH"", tmp); blink_mode(""101010000""); break; } } else { if (phase_state == PHASE_ONE) { sprintf(tmp2, ""%s %dA"", tmp, evse_set_current); } else if (phase_state == PHASE_THREE) { sprintf(tmp2, ""%s 3x%d"", tmp, evse_set_current); } else { sprintf(tmp2, ""%s ?P?"", tmp); } } update_display(tmp2); break; case STATE_CHARGING: switch (evse_mode) { case MODE_AUTO: sprintf(tmp2, ""Chg %.0fkW"", phase_multiplier * sdm_power / 1000); blink_mode(""1""); break; case MODE_MANUAL: sprintf(tmp2, ""1ph %.0fkW"", phase_multiplier * sdm_power / 1000); blink_mode(""11110000""); break; case MODE_MANUAL_THREE: sprintf(tmp2, ""3ph %.0fkW"", phase_multiplier * sdm_power / 1000); blink_mode(""101010000""); break; } if (s == 1) { sprintf(tmp2, ""%.2fkWH"", phase_multiplier * chargeEnergy); } else if (s == 2) { unsigned long duration = (now - chargeStart) / 1000; if (duration < 300) { sprintf(tmp2, ""%ld sec"", duration); } else if (duration < 3600) { sprintf(tmp2, ""%ldm%lds"", duration / 60, duration % 60); } else { unsigned long m = (duration % 3600) / 60; sprintf(tmp2, ""%ldh%ldm"", duration / 3600, m); } } update_display(tmp2); break; case STATE_ERROR: update_display(state_error.c_str()); blink_mode(""10""); // fast blink break; } if ((now - lastModbusUpdate) > 1000) { //Serial.print("".""); if ((state != STATE_INIT) && (state != STATE_ERROR)) { updateModbusData(); } updateModbus(); // update external (server modbus) lastModbusUpdate = now; } blink_manager(); server.handleClient(); mb.task(); /* if (WiFi.status() == WL_CONNECTED) { if (wifi_manager_portal_active) { Serial.println(""Wifi Connected, disable portal""); wifiManager.stopWebPortal(); start_webserver(); wifi_manager_portal_active = false; } } else { // TODO add a timeout before starting the web portal. if (!wifi_manager_portal_active) { Serial.println(""Wifi Disconnected, enable portal""); wifiManager.startWebPortal(); wifi_manager_portal_active = true; } } wifiManager.process(); */ ArduinoOTA.handle(); MDNS.update(); wifiMulti.run(); yield(); } ",12303,False,1992.2387854704273,median "org 0x7e00 jmp 0x0000:start %define blackColor 0 %define blueColor 1 %define darkGreenColor 2 %define blue 3 %define redColor 4 %define lightGrayColor 7 %define greenColor 10 %define yellowColor 14 %define whiteColor 15 %macro setText 4 mov ah, 02h ; Setando o cursor mov bh, 0 ; Pagina 0 mov dh, %1 ; Linha mov dl, %2 ; Coluna int 10h mov bx, %4 mov si, %3 call printf_color %endmacro %macro simplePrintf 2 mov bx, %2 mov si, %1 call printf_color %endmacro start: call initVideo call login system: call initVideo setText 15, 16, title, greenColor call draw_logo call delay call menu jmp $ get_password: xor cl,cl ;zera variavel cl (sera usada como contador) loop_get_password: mov ah,0 int 16h cmp al,08h ;backspace teclado? je key_backspace_password cmp al,0dh ;enter teclado? je key_enter_password cmp cl,0fh ;15 valores ja teclados? je loop_get_password ;só aceita backspace ou enter mov byte [di],al inc di mov al,'*' mov ah,0eh int 10h inc cl jmp loop_get_password key_backspace_password: cmp cl,0 je loop_get_password ;n faz sentido apagar string vazia dec di ;volta dl pra o caractere anterior mov byte [di],0 ;zera o valor daquela posicao dec cl ;diminui o contador em 1 mov ah,0eh mov al,08h ;imprime backspace(volta o cursor) int 10h mov al,' ' int 10h mov al,08h int 10h jmp loop_get_password key_enter_password: mov al,0 mov byte[di],al mov ah,0eh mov al,0dh int 10h mov al,0ah int 10h ret login: getspassword: simplePrintf stringusuario, whiteColor mov di, stringname call get_input simplePrintf string_senha, whiteColor mov di,password call get_password jmp comp_pass comp_pass: simplePrintf String_senha2, whiteColor mov di, stringpassword call get_password mov si, stringpassword mov di, password call strcmp cmp al,1 jne wrong jmp system wrong: simplePrintf stringwrongpassword, whiteColor call endl jmp comp_pass %macro drawer 1 mov ah, 0ch mov al, %1 mov bh, 0 %endmacro %macro drawSquare 4 mov cx, %1 .draw_rows: mov dx, %2 int 10h mov dx, %4 int 10h inc cx cmp cx, %3 je .end_column jmp .draw_rows .end_column: mov dx, %2 .draw_columns: mov cx, %1 int 10h mov cx, %3 int 10h inc dx cmp dx, %4 jne .draw_columns %endmacro %macro drawCursor 4 mov cx, %1 .draw_seg: mov dx, %3-1 int 10h mov dx, %3 int 10h inc cx cmp cx, %4 je .end_column jmp .draw_seg .end_column: mov dx, %2 .draw_columns: mov cx, %4-2 int 10h mov cx, %4-1 int 10h inc dx cmp dx, %3 jne .draw_columns %endmacro %macro startTimer 1 mov al, %1+48 mov bx, whiteColor mov ah, 0eh ; modo de imprmir na tela int 10h ; imprime o que tá em al mov ah, 03h mov ch, 0 mov cl, 0 mov dh, 0 mov dl, 1 int 1aH .loop: mov ah, 02h ; int 1aH cmp dh, %1h je good_job add dh, 48 mov [time], dh setText 12, 29, time, yellowColor jmp .loop %endmacro cursorApp: drawer blackColor call cursor_app1 drawer darkGreenColor ret getchar: mov ah, 00h int 16h ret initVideo: mov ah, 00h mov al, 13h int 10h ret printf_color: loop_print_string: lodsb cmp al,0 je end_print_string mov ah,0eh int 10h jmp loop_print_string end_print_string: ret menu: call initVideo call draw_logo_background ; Desenha a borda call draw_border ; Escreve nome de cada APP call draw_box_app ; Desenha os retangulos setText 1, 16, title, darkGreenColor setText 6, 4, app1, darkGreenColor setText 6, 27, app2, darkGreenColor setText 13, 4, app3, darkGreenColor setText 13, 26, app4, darkGreenColor setText 20, 4, app5, darkGreenColor setText 20, 27, app6, darkGreenColor call first_cursor ; Inicia a aplicação delay: mov ah, 86h mov cx, 30 mov dx, 500 int 15h ret fast_delay: mov ah, 86h mov dx, 3000 int 15h ret endline: mov ah, 02h ; setar o cursor mov bh, 0 ; pagina mov dl, 1 inc dh int 10h jmp teclado delete_endline: cmp dh, 2 ;Linha inicial je teclado mov al, ' ' mov ah, 09h ; codigo para printar caractere apenas onde esta o cursor mov bh, 0 ; seta a pagina mov bl, whiteColor ; seta a cor do caractere, nesse caso, branco int 10h mov ah, 02h ; setar o cursor mov bh, 0 ; pagina dec dh mov dl, 100 int 10h jmp teclado backspace: cmp dl, 1 je delete_endline mov al, ' ' mov cx, 1 mov ah, 09h ; codigo para printar caractere apenas onde esta o cursor mov bh, 0 ; seta a pagina mov bl, whiteColor ; seta a cor do caractere, nesse caso, branco int 10h mov ah, 02h ; setar o cursor dec dl ; coluna -- mov bh, 0 ; pagina int 10h jmp teclado teclado: mov ah, 0 ; prepara o ah para a chamada do teclado int 16h ; interrupcao para ler o caractere e armazena-lo em al cmp al, 8 je backspace cmp al, 27 je menu cmp dl, 100 je endline mov ah, 02h ; setar o cursor mov bh, 0 ; pagina inc dl int 10h mov ah, 09h ; codigo para printar caractere apenas onde esta o cursor mov bh, 0 ; seta a pagina int 10h jmp teclado draw_logo: mov si, lacoste mov dx, 0 ; Y mov bx, si add si, 2 .for1: cmp dl, byte[bx+1] je .endfor1 mov cx, 0 ; X .for2: cmp cl, byte[bx] je .endfor2 lodsb push dx push cx mov ah, 0ch add dx, 70 add cx, 140 int 10h pop cx pop dx inc cx jmp .for2 .endfor2: inc dx jmp .for1 .endfor1: ret %macro position 2 push dx push cx mov ah, 0ch add dx, %1 add cx, %2 int 10h pop cx pop dx %endmacro lacoste_positions: position 20, 10 position 20, 150 position 20, 280 position 50, 80 position 50, 230 position 80, 10 position 80, 150 position 80, 280 position 110, 80 position 110, 230 position 140, 10 position 140, 150 position 140, 280 position 170, 80 position 170, 230 ret draw_logo_background: mov si, lacoste mov dx, 0 ; Y mov bx, si add si, 2 .for1: cmp dl, byte[bx+1] je .endfor1 mov cx, 0 ; X .for2: cmp cl, byte[bx] je .endfor2 lodsb call lacoste_positions inc cx jmp .for2 .endfor2: inc dx jmp .for1 .endfor1: ret %macro blackBackgroundApp 4 mov ah, 0ch mov al, blackColor mov bh, 0 mov cx, %1 mov dx, %2 .draw_seg: int 10h inc cx cmp cx, %3 je .jump_row jne .draw_seg .back_column: mov cx, %1 jmp .draw_seg .jump_row: inc dx cmp dx, %4 jne .back_column mov al, blue ; Voltando a cor original %endmacro box_app1: drawSquare 20, 145, 100, 180 blackBackgroundApp 21, 146, 100, 180 box_app2: drawSquare 200, 35, 280, 70 blackBackgroundApp 201, 36, 280, 70 box_app3: drawSquare 200, 90, 280, 125 blackBackgroundApp 201, 91, 280, 125 box_app4: drawSquare 200, 145, 280, 180 blackBackgroundApp 201, 146, 280, 180 box_app5: drawSquare 20, 35, 100, 70 blackBackgroundApp 21, 36, 100, 70 box_app6: drawSquare 20, 90, 100, 125 blackBackgroundApp 21, 91, 100, 125 ret draw_box_app: drawer blue call box_app1 ret draw_border: drawer whiteColor mov cx, 0 .draw_seg: mov dx, 0 int 10h mov dx, 199 int 10h inc cx cmp cx, 319 je .end_column jmp .draw_seg .end_column: mov dx, 0 .draw_columns: mov cx, 0 int 10h mov cx, 319 int 10h inc dx cmp dx, 199 jne .draw_columns ret draw_white_border: mov ah, 0ch mov al, whiteColor mov bh, 0 mov cx, 0 .draw_seg: mov dx, 0 int 10h mov dx, 198 int 10h inc cx cmp cx, 319 je .end_column jmp .draw_seg .end_column: mov dx, 0 .draw_columns: mov cx, 0 int 10h mov cx, 319 int 10h inc dx cmp dx, 198 jne .draw_columns ret cursor_app1: drawCursor 85, 54, 67, 98 cursor_app2: drawCursor 85, 109, 122, 98 cursor_app3: drawCursor 85, 164, 177, 98 cursor_app4: drawCursor 265, 54, 67, 278 cursor_app5: drawCursor 265, 109, 122, 278 cursor_app6: drawCursor 265, 164, 177, 278 ret bad_input: setText 15, 20, error, whiteColor call delay jmp menu good_job: setText 20, 4, work, whiteColor call delay jmp menu loading_app: call initVideo call draw_logo call loading_limit call loading ret background_white: ; Set background white mov ah, 0ch mov al, whiteColor mov bh, 0 mov cx, 0 mov dx, 0 .draw_seg: int 10h inc cx cmp cx, 320 je .jump_row jne .draw_seg .back_column: mov cx, 0 jmp .draw_seg .jump_row: inc dx cmp dx, 200 jne .back_column ret first_cursor: call cursorApp drawCursor 85, 54, 67, 98 call getchar cmp al, 13 je init_browser cmp al, 'w' je third_cursor cmp al, 'a' je fourth_cursor cmp al, 's' je second_cursor cmp al, 'd' je fourth_cursor jmp first_cursor ret init_browser: call loading_app call initVideo call background_white call draw_dino setText 11, 13, offline, whiteColor setText 14, 3, text_fun1, whiteColor setText 15, 3, text_fun2, whiteColor setText 18, 12, try, whiteColor call draw_esc_button exitBrowser: call getchar cmp al, 27 je menu jmp exitBrowser second_cursor: call cursorApp drawCursor 85, 109, 122, 98 call getchar cmp al, 13 je initPhotos cmp al, 'w' je first_cursor cmp al, 'a' je fifth_cursor cmp al, 's' je third_cursor cmp al, 'd' je fifth_cursor jmp second_cursor ret %macro loadPhotos 1 call video call %1 call hold %endmacro initPhotos: call loading_app loadPhotos japan loadPhotos france loadPhotos england loadPhotos brasil loadPhotos italy loadPhotos russia loadPhotos germany ret third_cursor: call cursorApp drawCursor 85, 164, 177, 98 call getchar cmp al, 13 je prompt_command cmp al, 'w' je second_cursor cmp al, 'a' je sixth_cursor cmp al, 's' je first_cursor cmp al, 'd' je sixth_cursor jmp third_cursor ret %macro setprint 2 simplePrintf stringtab, blackColor simplePrintf %1, %2 ;string a ser printada call endl %endmacro %macro funcao 2 mov si,stringinput mov di, %1 call strcmp cmp al,1 je %2 %endmacro prompt_command: xor ax,ax mov ds,ax call video mov bx, whiteColor xor dx,dx mov dl,'0' mov dh,'4' system_loop: call print_user mov bx, yellowColor mov di, stringinput call get_input funcao ls, command_ls funcao dan, command_dan funcao lk, command_lk funcao prds, command_prds funcao touch, command_touch funcao rm, command_rm funcao ping, command_ping funcao cd, command_cd funcao sudo, command_sudo funcao uname, command_uname funcao secret, command_secret funcao hello, command_hello funcao clear, command_clear funcao df, command_df funcao exit, command_exit jmp invalid invalid: simplePrintf stringnocommand, whiteColor simplePrintf stringinput, whiteColor simplePrintf stringfound, whiteColor jmp system_loop jmp $ print_user: simplePrintf stringTCK, whiteColor simplePrintf stringname, whiteColor simplePrintf stringpc, whiteColor ret endl: mov ax,0x0e0a int 10h mov al,0x0d int 10h ret clean: mov dx, 0 mov bh, 0 mov ah, 0x2 int 0x10 mov cx, 4000 ; print 2000 chars mov bh, 0 mov bl, 10 mov al, 0x20 ; blank char mov ah, 0x9 int 0x10 mov dx, 0 ; Set cursor to top left-most corner of screen mov bh, 0 mov ah, 0x2 int 0x10 ret strcmp:;di é a constante strcmp_loop: mov al,byte [di] inc di mov ah,byte [si] inc si cmp al,0 je eq cmp ah,al jne dif jmp strcmp_loop eq: mov al,1 jmp strcmp_end dif: xor al,al strcmp_end: ret get_input: xor cl,cl ;zera variavel cl (sera usada como contador) loop_get_input: mov ah,0 int 16h cmp al,08h ;backspace teclado? je key_backspace_input cmp al,0dh ;enter teclado? je key_enter_input cmp cl,28h ;40 valores ja teclados? je loop_get_input ;só aceita backspace ou enter mov ah,0eh int 10h mov byte [di],al inc di inc cl jmp loop_get_input key_backspace_input: cmp cl,0 je loop_get_input ; n faz sentido apagar string vazia dec di ; volta dl pra o caractere anterior mov byte [di],0 ; zera o valor daquela posicao dec cl ; diminui o contador em 1 mov ah,0eh mov al,08h ; imprime backspace(volta o cursor) int 10h mov al,' ' int 10h mov al,08h int 10h jmp loop_get_input key_enter_input: mov al,0 mov byte[di],al mov ah,0eh mov al,0dh int 10h mov al,0ah int 10h ret ; ------ Commands ------- command_ls: simplePrintf stringcommandlist, whiteColor setprint touch, whiteColor setprint rm, whiteColor setprint ping, whiteColor setprint cd, whiteColor setprint sudo, whiteColor setprint uname, whiteColor setprint hello, whiteColor setprint df, whiteColor setprint clear, whiteColor setprint exit, whiteColor setprint stringsecret2, lightGrayColor jmp system_loop command_dan: simplePrintf stringdan, whiteColor jmp system_loop command_lk: simplePrintf stringlk, whiteColor jmp system_loop command_prds: simplePrintf stringprds, whiteColor jmp system_loop command_touch: simplePrintf stringtouch, whiteColor jmp system_loop command_rm: simplePrintf stringrm, whiteColor jmp system_loop command_ping: simplePrintf stringping, whiteColor jmp system_loop command_cd: simplePrintf stringcd, whiteColor jmp system_loop command_sudo: simplePrintf stringsudo, whiteColor jmp system_loop command_uname: simplePrintf stringuname, greenColor simplePrintf stringuname2, greenColor simplePrintf stringuname3, greenColor simplePrintf stringuname4, greenColor simplePrintf stringuname5, greenColor jmp system_loop command_secret: setprint stringsecreta32, whiteColor setprint dan, greenColor setprint lk, greenColor setprint prds, greenColor jmp system_loop command_hello: setprint helloword, whiteColor jmp system_loop command_clear: call clean jmp system_loop command_df: simplePrintf sdf, whiteColor jmp system_loop command_exit jmp menu ; ---------------//------------ fourth_cursor: call cursorApp drawCursor 265, 54, 67, 278 call getchar cmp al, 13 je notes_app cmp al, 'w' je sixth_cursor cmp al, 'a' je first_cursor cmp al, 's' je fifth_cursor cmp al, 'd' je first_cursor jmp fourth_cursor ret notes_app: call loading_app ; Init Video mov ah, 0 mov al, 2h int 10h ; Set background Color mov ah, 0Bh mov bh, 0 mov bl, 1 int 10h setText 1, 1, ESC, whiteColor setText 1, 33, bloco_de_notas, whiteColor mov ah, 02h ; Setando o cursor mov dh, 2 ; Linha mov dl, 1 ; Coluna int 10h jmp teclado fifth_cursor: call cursorApp drawCursor 265, 109, 122, 278 call getchar cmp al, 13 je time_app cmp al, 'w' je fourth_cursor cmp al, 'a' je second_cursor cmp al, 's' je sixth_cursor cmp al, 'd' je second_cursor jmp fifth_cursor ret await_3: startTimer 3 await_5: startTimer 5 await_9: startTimer 9 time_app: call loading_app call initVideo call draw_border setText 1, 14, time_to_rest, whiteColor setText 5, 4, instruction_time, whiteColor setText 9, 27, timer, whiteColor setText 9, 4, time_3, whiteColor setText 12, 4, time_5, whiteColor setText 15, 4, time_9, whiteColor setText 22, 11, obs, whiteColor call draw_esc_button mov ah, 02h ; Setando o cursor mov bh, 0 ; Pagina 0 mov dh, 15 ; Linha mov dl, 29 ; Coluna int 10h call getchar cmp al, '1' je await_3 cmp al, '2' je await_5 cmp al, '3' je await_9 cmp al, 27 je menu call bad_input jmp time_app sixth_cursor: call cursorApp drawCursor 265, 164, 177, 278 call getchar cmp al, 13 je about_app cmp al, 'w' je fifth_cursor cmp al, 'a' je third_cursor cmp al, 's' je fourth_cursor cmp al, 'd' je third_cursor jmp sixth_cursor ret about_app: call initVideo setText 1, 10, spec, blue setText 4, 3, nomePc, blue setText 7, 3, organizacao, blue setText 10, 3, edicao, blue setText 13, 3, compilacao, blue setText 16, 3, processador, blue setText 19, 3, ram, blue setText 22, 3, sistema, blue setText 10, 22, spcs, blue setText 7, 22, org_sp, blue setText 13, 22, JDaniel, blue setText 16, 22, Pedro, blue setText 19, 22, LK, blue setText 22, 22, tchucoOS, blue setText 4, 22, stringname, blue call draw_white_border call draw_esc_button call getchar cmp al, 27 je menu jmp about_app draw_dino: mov si, dino mov dx, 0 mov bx, si add si, 2 .for1: cmp dl, byte[bx+1] je .endfor1 mov cx, 0 .for2: cmp cl, byte[bx] je .endfor2 lodsb push dx ; Draw pixel push cx mov ah, 0ch add dx, 50 add cx, 130 int 10h pop cx pop dx inc cx jmp .for2 .endfor2: inc dx jmp .for1 .endfor1: ret draw_esc_button: mov si, esc_button mov dx, 0 ; Y mov bx, si add si, 2 .for1: cmp dl, byte[bx+1] je .endfor1 mov cx, 0 ; X .for2: cmp cl, byte[bx] je .endfor2 lodsb push dx push cx mov ah, 0ch add dx, 2 add cx, 2 int 10h pop cx pop dx inc cx jmp .for2 .endfor2: inc dx jmp .for1 .endfor1: ret data: ; SO interface title db 'TchucoOS', 0 app1 db 'Browser', 0 app2 db 'Notes', 0 app3 db 'Photos', 0 app4 db 'RestTime', 0 app5 db 'Terminal', 0 app6 db 'About', 0 ; Browser APP offline db ""Sem internet"", 0 text_fun1 db ""Retire os cabos de rede e roteador"", 0 text_fun2 db ""Desconecte de sua rede Wi-Fi"", 0 try db ""Tente novamente"", 0 ; Time to Rest APP time_to_rest db 'Time to Rest', 0 instruction_time db 'Quantos minutos deseja descansar?', 0 obs db 'Minutos = Segundos', 0 work db 'Acabou o descanso, bom trabalho!', 0 error db 'Digite 1, 2 ou 3', 0 timer db 'Timer', 0 time db 8,0 choice db 8, 0 time_3 db '1. 3 minuto', 0 time_5 db '2. 5 minutos', 0 time_9 db '3. 9 minutos', 0 ; About spec db 'Especificacoes do SO', 0 org_sp db 'ThucosSA',0 nomePc db 'Nome do PC ', 0 organizacao db 'Organizacao', 0 edicao db 'Edicao', 0 spcs db 'Edicao da realeza',0 compilacao db 'Compilacao do SO', 0 processador db 'Processador', 0 ram db 'RAM instalada', 0 sistema db 'Tipo de sistema', 0 tchucoOS db 'TchucoOS', 0 JDaniel db 'Jose Daniel', 0 LK db 'Lucas Emmanuel-LK', 0 Pedro db 'Pedro Rogrigues', 0 ; Notes app bloco_de_notas db 'Bloco de notas', 0 ESC db 'ESC', 0 ; Login stringusuario db 'Username:', 0 string_senha db 'Create Password:',0 String_senha2 db 'Confirm password:',0 stringwrongpassword db 'Incorrect Password.',0 stringpassword times 16 db 0 password times 16 db 0 ; Command prompt stringTCK db 'ThucOS@',0 stringpc db '-PC: ',0 stringaskname db 'User name:',0 stringnocommand db 'No command ',39,0 stringfound db 39,' found.',10,13,0 stringcommandlist db 'Command List:',10,13,0 stringsecreta32 db 'Secret Commands:',13,0 stringsecret2 db 'Secret para comandos incrivelmente secretos',10,13,0 stringtab db ' ',0 stringdan db ' Daniel ta ouvindo um pagodinho',10,13,0 stringlk db ' Lk considera Eduardo o melhor professor',10,13,0 stringprds db ' Eu Amo Bitcoin e provavelmente neste momento to dando uma cagada', 10,13,0 stringtouch db ' lista de calouras mais lindas.c',10,13,0 stringrm db ' Voce perdeu as calouras',10,13,0 stringping db ' Nao esta conectado a internet :(',10,13,0 stringcd db ' Voce trocou para ciencia da computacao',10,13,0 stringsudo db ' Voce acaba de baixar um virus parabens',10,13,0 stringuname db ' Sistema: thucOS muito melhor que qualquer linux :D',10,13,0 stringuname2 db ' Ram: Lk disse que a ram era segredo',10,13,0 stringuname3 db ' Processador: Pedro vendeu pra comprar Bitcoin',10,13,0 stringuname4 db ' Memoria livre: daniel Gastou a memoria toda baixando pagode',10,13,0 stringuname5 db ' Quem usa ThucOS faz uma grande favor ao meio ambiente :)',10,13,0 helloword db ' Hello world pq aqui a gente programa very good ',13,0 sdf db ' 8mb livre amigao bora comprar um hd novo',13,10 ;commands ls db 'ls',0 dan db 'dan',0 prds db 'prds',0 lk db 'lk',0 touch db 'touch',0 rm db 'rm',0 ping db 'ping',0 cd db 'cd',0 sudo db 'sudo',0 uname db 'uname',0 secret db 'secret',0 hello db 'hello',0 clear db 'clear',0 df db 'df',0 exit db 'exit',0 stringname times 16 db 0 stringinput times 40 db 0 lacoste db 35, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 8, 2, 2, 0, 2, 2, 2, 2, 8, 8, 0, 0, 0, 0, 2, 2, 0, 2, 0, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 6, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 0, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 8, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 dino db 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 7, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 7, 15, 15, 15, 15, 15, 15, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 8, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 15, 7, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 15, 15, 15, 7, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 15, 15, 15, 15, 15, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 15, 15, 15, 15, 15, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 15, 15, 15, 15, 0, 0, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 esc_button db 15, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 15, 15, 15, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 15, 12, 4, 4, 15, 15, 15, 4, 15, 15, 15, 4, 0, 0, 4, 15, 15, 15, 4, 15, 12, 4, 4, 15, 4, 4, 4, 0, 0, 4, 15, 4, 4, 4, 15, 15, 15, 4, 15, 4, 4, 4, 0, 0, 4, 15, 4, 4, 4, 4, 4, 15, 4, 15, 4, 4, 4, 0, 0, 12, 15, 15, 15, 4, 15, 15, 15, 4, 15, 15, 15, 12, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; ------- Código inspirado por ----------- hold: call getchar cmp al, 27 je menu cmp al, ' ' jne hold ret video: mov ah, 0 ; Set video mode mov al, 12h int 10h ret %macro setColor 1 mov ah, 0ch mov bh, 0 mov al, %1 ; cor int 10h %endmacro %macro setBackground 1 mov ah, 0xb mov bh, 0 mov bl, %1 int 10h %endmacro %macro filled_circle 3 push cx push dx mov ax, -%1 push ax .loop_circle: pop ax cmp ax, %1 je .done inc ax push ax mov bx, -%1 push bx jmp .loop_circle2 .loop_circle2: pop bx cmp bx, %1 je .loop_circle inc bx push bx jmp .check .check: pop bx pop ax push ax push bx mov cx, ax mov dx, bx mul ax xchg ax, bx mul ax add ax, bx cmp ax, %2 jg .loop_circle2 pop bx pop ax pop dx pop cx push cx push dx push ax push bx add cx, ax add dx, bx setColor %3 jmp .loop_circle2 .done: pop dx pop cx %endmacro japan: mov dx, 0 .jp_white: cmp dx, 480 jg .jp_red mov cx, 0 .jp_loop_white: setColor whiteColor inc cx cmp cx, 640 jl .jp_loop_white inc dx jmp .jp_white .jp_red: mov cx, 320 mov dx, 240 filled_circle 125, 15625, redColor .jp_end: ret france: setBackground redColor mov dx, 0 .fr_blue: cmp dx, 480 jg .fr_next mov cx, 0 ; inicio da linha .fr_loop_blue: setColor blueColor inc cx cmp cx, 214 jl .fr_loop_blue inc dx jmp .fr_blue .fr_next: mov dx, 0 .fr_white: cmp dx, 480 jg .fr_end mov cx, 214 .fr_loop_white: setColor whiteColor inc cx cmp cx, 427 jl .fr_loop_white inc dx jmp .fr_white .fr_end: ret italy: setBackground redColor mov dx, 0 .it_green: cmp dx, 480 jg .it_next mov cx, 0 ; inicio da linha .it_loop_green: setColor darkGreenColor inc cx cmp cx, 214 jl .it_loop_green inc dx jmp .it_green .it_next: mov dx, 0 .it_white: cmp dx, 480 jg .it_end mov cx, 214 .it_loop_white: setColor whiteColor inc cx cmp cx, 427 jl .it_loop_white inc dx jmp .it_white .it_end: ret germany: mov dx, 160 .gr_red: cmp dx, 320 jg .gr_yellow mov cx, 0 .gr_loop_red: setColor redColor inc cx cmp cx, 640 jl .gr_loop_red inc dx jmp .gr_red .gr_yellow: cmp dx, 480 jg .gr_end mov cx, 0 .gr_loop_yellow: setColor yellowColor inc cx cmp cx, 640 jl .gr_loop_yellow inc dx jmp .gr_yellow .gr_end: ret russia: setBackground redColor mov dx, 0 .rs_white: cmp dx, 160 jg .rs_blue mov cx, 0 .rs_loop_white: setColor whiteColor inc cx cmp cx, 640 jl .rs_loop_white inc dx jmp .rs_white .rs_blue: cmp dx, 320 jg .rs_end mov cx, 0 .rs_loop_blue: setColor blueColor inc cx cmp cx, 640 jl .rs_loop_blue inc dx jmp .rs_blue .rs_end: ret england: mov dx, 0 .en_white: cmp dx, 480 jg .en_next mov cx, 0 .en_loop_white: setColor whiteColor inc cx cmp cx, 640 jl .en_loop_white inc dx jmp .en_white .en_next: mov dx, 0 .en_red_vertical: cmp dx, 480 jg .en_next1 mov cx, 280 .en_loop_red1: setColor redColor inc cx cmp cx, 360 jl .en_loop_red1 inc dx jmp .en_red_vertical .en_next1: mov dx, 200 .en_red_horizontal: cmp dx, 280 jg .en_end mov cx, 0 .en_loop_red2: setColor redColor inc cx cmp cx, 640 jl .en_loop_red2 inc dx jmp .en_red_horizontal .en_end: ret brasil: setBackground darkGreenColor mov dx, 0 push cx push ax mov dx, 80 mov cx, 320 ; Salva o inicio da linha amarela mov ax, 322 ; Salva o final da linha amarela .br_yellow: cmp dx, 240 jg .br_yellowBottom push cx .br_loopLine: push ax setColor yellowColor pop ax inc cx cmp cx, ax jl .br_loopLine inc dx add ax, 2 pop cx sub cx, 2 jmp .br_yellow .br_yellowBottom: cmp dx, 400 jg .br_next push cx .br_loopLine1: push ax setColor yellowColor pop ax inc cx cmp cx, ax jl .br_loopLine1 inc dx sub ax, 2 pop cx add cx, 2 jmp .br_yellowBottom .br_next: pop ax pop cx mov cx, 320 mov dx, 240 call filled_circle 110, 12100, blueColor mov dx, 235 mov cx, 225 .br_white: cmp dx, 245 jg .br_end push cx .loopLine4: setColor whiteColor inc cx cmp cx, 420 jl .loopLine4 inc dx pop cx jmp .br_white .br_end: ret ; ------- Lucas Cavalcanti Calabria ; ------- Maria Eduarda Barros Mota ; ------- José Maycon Lima Cunegundes ; ------ Código inspirador por ------ loading: mov cx, 50 loop_loading: call loading_unit inc cx push cx xor cx, cx call fast_delay pop cx cmp cx, 250 jne loop_loading mov ah, 86h; INT 15h / AH = 86h mov cx, 1 xor dx, dx ;CX:DX = interval in microseconds mov dx, 5 int 15h ret loading_unit_off: mov ax,0x0c00 ;Write graphics pixel, preto mov bh,0x00 mov dx, 160 loop_loading_unit_off: int 10h inc dx cmp dx, 170 jne loop_loading_unit_off ret loading_limit: mov ax,0x0c0f ;Write graphics pixel,white mov bh,0x00 mov dx, 160 loop_loading_limit: mov cx, 49 int 10h mov cx, 250 int 10h inc dx cmp dx, 170 jne loop_loading_limit ret loading_unit: mov ax,0x0c02 ;Write graphics pixel, verde mov bh,0x00 mov dx, 160 loop_loading_unit: int 10h inc dx cmp dx, 170 jne loop_loading_unit ret ; ------- Mikahel Leal Dias ; ------- Igor Eduardo Mascarenhas ; ------- André Luiz Figueirôa de Barros",16265,True,3594.1138341838378,median "; /* aes_asm.asm ; * ; * Copyright (C) 2006-2016 wolfSSL Inc. ; * ; * This file is part of wolfssl. (formerly known as CyaSSL) ; * ; * wolfSSL is free software; you can redistribute it and/or modify ; * it under the term of the GNU General Public License as published by ; * the Free Software Foundation/either version 2 of the License, or ; * (at your option) any later version. ; * ; * wolfSSL is distributed in the hope that it will be useful, ; * but WITHOUT ANY WARRANTY; without even the implied warranty of ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; * GNU General Public License for more details. ; * ; * You should have received a copy of the GNU General Public License ; * along with this program; if not, write to the Free Software ; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA ; */ ; ; ; /* See Intel Advanced Encryption Standard (AES) Instructions Set White Paper ; * by Israel, Intel Mobility Group Development Center, Israel Shay Gueron ; */ ; ; /* This file is in intel asm syntax, see .s for at&t syntax */ ; ; /* ; AES_CBC_encrypt[const ,unsigned char*in ; unsigned ,char*out ; unsigned ,char ivec+16 ; unsigned ,long length ; const ,unsigned char*KS ; int nr] ; */ _text SEGMENT AES_CBC_encrypt PROC ;# parameter 1: rdi ;# parameter 2: rsi ;# parameter 3: rdx ;# parameter 4: rcx ;# parameter 5: r8 ;# parameter 6: r9d ; save rdi and rsi to rax and r11, restore before ret mov rax,rdi mov r11,rsi ; convert to what we had for att&t convention mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 mov r8,[rsp+40] mov r9d,[rsp+48] mov r10,rcx shr rcx,4 shl r10,60 je NO_PARTS add rcx,1 NO_PARTS: sub rsi,16 movdqa xmm1,[rdx] LOOP_1: pxor xmm1,[rdi] pxor xmm1,[r8] add rsi,16 add rdi,16 cmp r9d,12 aesenc xmm1,16[r8] aesenc xmm1,32[r8] aesenc xmm1,48[r8] aesenc xmm1,64[r8] aesenc xmm1,80[r8] aesenc xmm1,96[r8] aesenc xmm1,112[r8] aesenc xmm1,128[r8] aesenc xmm1,144[r8] movdqa xmm2,160[r8] jb LAST cmp r9d,14 aesenc xmm1,160[r8] aesenc xmm1,176[r8] movdqa xmm2,192[r8] jb LAST aesenc xmm1,192[r8] aesenc xmm1,208[r8] movdqa xmm2,224[r8] LAST: dec rcx aesenclast xmm1,xmm2 movdqu [rsi],xmm1 jne LOOP_1 ; restore non volatile rdi,rsi mov rdi,rax mov rsi,r11 ret AES_CBC_encrypt ENDP ; void AES_CBC_decrypt_by4(const unsigned char* in, ; unsigned char* out, ; unsigned char ivec[16], ; unsigned long length, ; const unsigned char* KS, ; int nr) AES_CBC_decrypt_by4 PROC ; parameter 1: rdi ; parameter 2: rsi ; parameter 3: rdx ; parameter 4: rcx ; parameter 5: r8 ; parameter 6: r9d ; save rdi and rsi to rax and r11, restore before ret mov rax, rdi mov r11, rsi ; convert to what we had for att&t convention mov rdi, rcx mov rsi, rdx mov rdx, r8 mov rcx,r9 mov r8, [rsp+40] mov r9d, [rsp+48] ; on microsoft xmm6-xmm15 are non volatile, ; let's save on stack and restore at end sub rsp, 8+8*16 ; 8 = align stack , 8 xmm6-12,15 16 bytes each movdqa [rsp+0], xmm6 movdqa [rsp+16], xmm7 movdqa [rsp+32], xmm8 movdqa [rsp+48], xmm9 movdqa [rsp+64], xmm10 movdqa [rsp+80], xmm11 movdqa [rsp+96], xmm12 movdqa [rsp+112], xmm15 ; back to our original code, more or less mov r10, rcx shr rcx, 4 shl r10, 60 je DNO_PARTS_4 add rcx, 1 DNO_PARTS_4: mov r10, rcx shl r10, 62 shr r10, 62 shr rcx, 2 movdqu xmm5, [rdx] je DREMAINDER_4 sub rsi, 64 DLOOP_4: movdqu xmm1, [rdi] movdqu xmm2, 16[rdi] movdqu xmm3, 32[rdi] movdqu xmm4, 48[rdi] movdqa xmm6, xmm1 movdqa xmm7, xmm2 movdqa xmm8, xmm3 movdqa xmm15, xmm4 movdqa xmm9, [r8] movdqa xmm10, 16[r8] movdqa xmm11, 32[r8] movdqa xmm12, 48[r8] pxor xmm1, xmm9 pxor xmm2, xmm9 pxor xmm3, xmm9 pxor xmm4, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm1, xmm12 aesdec xmm2, xmm12 aesdec xmm3, xmm12 aesdec xmm4, xmm12 movdqa xmm9, 64[r8] movdqa xmm10, 80[r8] movdqa xmm11, 96[r8] movdqa xmm12, 112[r8] aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm1, xmm12 aesdec xmm2, xmm12 aesdec xmm3, xmm12 aesdec xmm4, xmm12 movdqa xmm9, 128[r8] movdqa xmm10, 144[r8] movdqa xmm11, 160[r8] cmp r9d, 12 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 jb DLAST_4 movdqa xmm9, 160[r8] movdqa xmm10, 176[r8] movdqa xmm11, 192[r8] cmp r9d, 14 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 jb DLAST_4 movdqa xmm9, 192[r8] movdqa xmm10, 208[r8] movdqa xmm11, 224[r8] aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 DLAST_4: add rdi, 64 add rsi, 64 dec rcx aesdeclast xmm1, xmm11 aesdeclast xmm2, xmm11 aesdeclast xmm3, xmm11 aesdeclast xmm4, xmm11 pxor xmm1, xmm5 pxor xmm2, xmm6 pxor xmm3, xmm7 pxor xmm4, xmm8 movdqu [rsi], xmm1 movdqu 16[rsi], xmm2 movdqu 32[rsi], xmm3 movdqu 48[rsi], xmm4 movdqa xmm5, xmm15 jne DLOOP_4 add rsi, 64 DREMAINDER_4: cmp r10, 0 je DEND_4 DLOOP_4_2: movdqu xmm1, [rdi] movdqa xmm15, xmm1 add rdi, 16 pxor xmm1, [r8] movdqu xmm2, 160[r8] cmp r9d, 12 aesdec xmm1, 16[r8] aesdec xmm1, 32[r8] aesdec xmm1, 48[r8] aesdec xmm1, 64[r8] aesdec xmm1, 80[r8] aesdec xmm1, 96[r8] aesdec xmm1, 112[r8] aesdec xmm1, 128[r8] aesdec xmm1, 144[r8] jb DLAST_4_2 movdqu xmm2, 192[r8] cmp r9d, 14 aesdec xmm1, 160[r8] aesdec xmm1, 176[r8] jb DLAST_4_2 movdqu xmm2, 224[r8] aesdec xmm1, 192[r8] aesdec xmm1, 208[r8] DLAST_4_2: aesdeclast xmm1, xmm2 pxor xmm1, xmm5 movdqa xmm5, xmm15 movdqu [rsi], xmm1 add rsi, 16 dec r10 jne DLOOP_4_2 DEND_4: ; restore non volatile rdi,rsi mov rdi, rax mov rsi, r11 ; restore non volatile xmms from stack movdqa xmm6, [rsp+0] movdqa xmm7, [rsp+16] movdqa xmm8, [rsp+32] movdqa xmm9, [rsp+48] movdqa xmm10, [rsp+64] movdqa xmm11, [rsp+80] movdqa xmm12, [rsp+96] movdqa xmm15, [rsp+112] add rsp, 8+8*16 ; 8 = align stack , 8 xmm6-12,15 16 bytes each ret AES_CBC_decrypt_by4 ENDP ; void AES_CBC_decrypt_by6(const unsigned char *in, ; unsigned char *out, ; unsigned char ivec[16], ; unsigned long length, ; const unsigned char *KS, ; int nr) AES_CBC_decrypt_by6 PROC ; parameter 1: rdi - in ; parameter 2: rsi - out ; parameter 3: rdx - ivec ; parameter 4: rcx - length ; parameter 5: r8 - KS ; parameter 6: r9d - nr ; save rdi and rsi to rax and r11, restore before ret mov rax, rdi mov r11, rsi ; convert to what we had for att&t convention mov rdi, rcx mov rsi, rdx mov rdx, r8 mov rcx, r9 mov r8, [rsp+40] mov r9d, [rsp+48] ; on microsoft xmm6-xmm15 are non volatile, ; let's save on stack and restore at end sub rsp, 8+9*16 ; 8 = align stack , 9 xmm6-14 16 bytes each movdqa [rsp+0], xmm6 movdqa [rsp+16], xmm7 movdqa [rsp+32], xmm8 movdqa [rsp+48], xmm9 movdqa [rsp+64], xmm10 movdqa [rsp+80], xmm11 movdqa [rsp+96], xmm12 movdqa [rsp+112], xmm13 movdqa [rsp+128], xmm14 ; back to our original code, more or less mov r10, rcx shr rcx, 4 shl r10, 60 je DNO_PARTS_6 add rcx, 1 DNO_PARTS_6: mov r12, rax mov r13, rdx mov r14, rbx mov rdx, 0 mov rax, rcx mov rbx, 6 div rbx mov rcx, rax mov r10, rdx mov rax, r12 mov rdx, r13 mov rbx, r14 cmp rcx, 0 movdqu xmm7, [rdx] je DREMAINDER_6 sub rsi, 96 DLOOP_6: movdqu xmm1, [rdi] movdqu xmm2, 16[rdi] movdqu xmm3, 32[rdi] movdqu xmm4, 48[rdi] movdqu xmm5, 64[rdi] movdqu xmm6, 80[rdi] movdqa xmm8, [r8] movdqa xmm9, 16[r8] movdqa xmm10, 32[r8] movdqa xmm11, 48[r8] pxor xmm1, xmm8 pxor xmm2, xmm8 pxor xmm3, xmm8 pxor xmm4, xmm8 pxor xmm5, xmm8 pxor xmm6, xmm8 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm5, xmm9 aesdec xmm6, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm5, xmm10 aesdec xmm6, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 movdqa xmm8, 64[r8] movdqa xmm9, 80[r8] movdqa xmm10, 96[r8] movdqa xmm11, 112[r8] aesdec xmm1, xmm8 aesdec xmm2, xmm8 aesdec xmm3, xmm8 aesdec xmm4, xmm8 aesdec xmm5, xmm8 aesdec xmm6, xmm8 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm5, xmm9 aesdec xmm6, xmm9 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm5, xmm10 aesdec xmm6, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 movdqa xmm8, 128[r8] movdqa xmm9, 144[r8] movdqa xmm10, 160[r8] cmp r9d, 12 aesdec xmm1, xmm8 aesdec xmm2, xmm8 aesdec xmm3, xmm8 aesdec xmm4, xmm8 aesdec xmm5, xmm8 aesdec xmm6, xmm8 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm5, xmm9 aesdec xmm6, xmm9 jb DLAST_6 movdqa xmm8, 160[r8] movdqa xmm9, 176[r8] movdqa xmm10, 192[r8] cmp r9d, 14 aesdec xmm1, xmm8 aesdec xmm2, xmm8 aesdec xmm3, xmm8 aesdec xmm4, xmm8 aesdec xmm5, xmm8 aesdec xmm6, xmm8 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm5, xmm9 aesdec xmm6, xmm9 jb DLAST_6 movdqa xmm8, 192[r8] movdqa xmm9, 208[r8] movdqa xmm10, 224[r8] aesdec xmm1, xmm8 aesdec xmm2, xmm8 aesdec xmm3, xmm8 aesdec xmm4, xmm8 aesdec xmm5, xmm8 aesdec xmm6, xmm8 aesdec xmm1, xmm9 aesdec xmm2, xmm9 aesdec xmm3, xmm9 aesdec xmm4, xmm9 aesdec xmm5, xmm9 aesdec xmm6, xmm9 DLAST_6: add rsi, 96 aesdeclast xmm1, xmm10 aesdeclast xmm2, xmm10 aesdeclast xmm3, xmm10 aesdeclast xmm4, xmm10 aesdeclast xmm5, xmm10 aesdeclast xmm6, xmm10 movdqu xmm8, [rdi] movdqu xmm9, 16[rdi] movdqu xmm10, 32[rdi] movdqu xmm11, 48[rdi] movdqu xmm12, 64[rdi] movdqu xmm13, 80[rdi] pxor xmm1, xmm7 pxor xmm2, xmm8 pxor xmm3, xmm9 pxor xmm4, xmm10 pxor xmm5, xmm11 pxor xmm6, xmm12 movdqu xmm7, xmm13 movdqu [rsi], xmm1 movdqu 16[rsi], xmm2 movdqu 32[rsi], xmm3 movdqu 48[rsi], xmm4 movdqu 64[rsi], xmm5 movdqu 80[rsi], xmm6 add rdi, 96 dec rcx jne DLOOP_6 add rsi, 96 DREMAINDER_6: cmp r10, 0 je DEND_6 DLOOP_6_2: movdqu xmm1, [rdi] movdqa xmm10, xmm1 add rdi, 16 pxor xmm1, [r8] movdqu xmm2, 160[r8] cmp r9d, 12 aesdec xmm1, 16[r8] aesdec xmm1, 32[r8] aesdec xmm1, 48[r8] aesdec xmm1, 64[r8] aesdec xmm1, 80[r8] aesdec xmm1, 96[r8] aesdec xmm1, 112[r8] aesdec xmm1, 128[r8] aesdec xmm1, 144[r8] jb DLAST_6_2 movdqu xmm2, 192[r8] cmp r9d, 14 aesdec xmm1, 160[r8] aesdec xmm1, 176[r8] jb DLAST_6_2 movdqu xmm2, 224[r8] aesdec xmm1, 192[r8] aesdec xmm1, 208[r8] DLAST_6_2: aesdeclast xmm1, xmm2 pxor xmm1, xmm7 movdqa xmm7, xmm10 movdqu [rsi], xmm1 add rsi, 16 dec r10 jne DLOOP_6_2 DEND_6: ; restore non volatile rdi,rsi mov rdi, rax mov rsi, r11 ; restore non volatile xmms from stack movdqa xmm6, [rsp+0] movdqa xmm7, [rsp+16] movdqa xmm8, [rsp+32] movdqa xmm9, [rsp+48] movdqa xmm10, [rsp+64] movdqa xmm11, [rsp+80] movdqa xmm12, [rsp+96] movdqa xmm13, [rsp+112] movdqa xmm14, [rsp+128] add rsp, 8+9*16 ; 8 = align stack , 9 xmm6-14 16 bytes each ret AES_CBC_decrypt_by6 ENDP ; void AES_CBC_decrypt_by8(const unsigned char *in, ; unsigned char *out, ; unsigned char ivec[16], ; unsigned long length, ; const unsigned char *KS, ; int nr) AES_CBC_decrypt_by8 PROC ; parameter 1: rdi - in ; parameter 2: rsi - out ; parameter 3: rdx - ivec ; parameter 4: rcx - length ; parameter 5: r8 - KS ; parameter 6: r9d - nr ; save rdi and rsi to rax and r11, restore before ret mov rax, rdi mov r11, rsi ; convert to what we had for att&t convention mov rdi, rcx mov rsi, rdx mov rdx, r8 mov rcx,r9 mov r8, [rsp+40] mov r9d, [rsp+48] ; on microsoft xmm6-xmm15 are non volatile, ; let's save on stack and restore at end sub rsp, 8+8*16 ; 8 = align stack , 8 xmm6-13 16 bytes each movdqa [rsp+0], xmm6 movdqa [rsp+16], xmm7 movdqa [rsp+32], xmm8 movdqa [rsp+48], xmm9 movdqa [rsp+64], xmm10 movdqa [rsp+80], xmm11 movdqa [rsp+96], xmm12 movdqa [rsp+112], xmm13 ; back to our original code, more or less mov r10, rcx shr rcx, 4 shl r10, 60 je DNO_PARTS_8 add rcx, 1 DNO_PARTS_8: mov r10, rcx shl r10, 61 shr r10, 61 shr rcx, 3 movdqu xmm9, [rdx] je DREMAINDER_8 sub rsi, 128 DLOOP_8: movdqu xmm1, [rdi] movdqu xmm2, 16[rdi] movdqu xmm3, 32[rdi] movdqu xmm4, 48[rdi] movdqu xmm5, 64[rdi] movdqu xmm6, 80[rdi] movdqu xmm7, 96[rdi] movdqu xmm8, 112[rdi] movdqa xmm10, [r8] movdqa xmm11, 16[r8] movdqa xmm12, 32[r8] movdqa xmm13, 48[r8] pxor xmm1, xmm10 pxor xmm2, xmm10 pxor xmm3, xmm10 pxor xmm4, xmm10 pxor xmm5, xmm10 pxor xmm6, xmm10 pxor xmm7, xmm10 pxor xmm8, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 aesdec xmm7, xmm11 aesdec xmm8, xmm11 aesdec xmm1, xmm12 aesdec xmm2, xmm12 aesdec xmm3, xmm12 aesdec xmm4, xmm12 aesdec xmm5, xmm12 aesdec xmm6, xmm12 aesdec xmm7, xmm12 aesdec xmm8, xmm12 aesdec xmm1, xmm13 aesdec xmm2, xmm13 aesdec xmm3, xmm13 aesdec xmm4, xmm13 aesdec xmm5, xmm13 aesdec xmm6, xmm13 aesdec xmm7, xmm13 aesdec xmm8, xmm13 movdqa xmm10, 64[r8] movdqa xmm11, 80[r8] movdqa xmm12, 96[r8] movdqa xmm13, 112[r8] aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm5, xmm10 aesdec xmm6, xmm10 aesdec xmm7, xmm10 aesdec xmm8, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 aesdec xmm7, xmm11 aesdec xmm8, xmm11 aesdec xmm1, xmm12 aesdec xmm2, xmm12 aesdec xmm3, xmm12 aesdec xmm4, xmm12 aesdec xmm5, xmm12 aesdec xmm6, xmm12 aesdec xmm7, xmm12 aesdec xmm8, xmm12 aesdec xmm1, xmm13 aesdec xmm2, xmm13 aesdec xmm3, xmm13 aesdec xmm4, xmm13 aesdec xmm5, xmm13 aesdec xmm6, xmm13 aesdec xmm7, xmm13 aesdec xmm8, xmm13 movdqa xmm10, 128[r8] movdqa xmm11, 144[r8] movdqa xmm12, 160[r8] cmp r9d, 12 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm5, xmm10 aesdec xmm6, xmm10 aesdec xmm7, xmm10 aesdec xmm8, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 aesdec xmm7, xmm11 aesdec xmm8, xmm11 jb DLAST_8 movdqa xmm10, 160[r8] movdqa xmm11, 176[r8] movdqa xmm12, 192[r8] cmp r9d, 14 aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm5, xmm10 aesdec xmm6, xmm10 aesdec xmm7, xmm10 aesdec xmm8, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 aesdec xmm7, xmm11 aesdec xmm8, xmm11 jb DLAST_8 movdqa xmm10, 192[r8] movdqa xmm11, 208[r8] movdqa xmm12, 224[r8] aesdec xmm1, xmm10 aesdec xmm2, xmm10 aesdec xmm3, xmm10 aesdec xmm4, xmm10 aesdec xmm5, xmm10 aesdec xmm6, xmm10 aesdec xmm7, xmm10 aesdec xmm8, xmm10 aesdec xmm1, xmm11 aesdec xmm2, xmm11 aesdec xmm3, xmm11 aesdec xmm4, xmm11 aesdec xmm5, xmm11 aesdec xmm6, xmm11 aesdec xmm7, xmm11 aesdec xmm8, xmm11 DLAST_8: add rsi, 128 aesdeclast xmm1, xmm12 aesdeclast xmm2, xmm12 aesdeclast xmm3, xmm12 aesdeclast xmm4, xmm12 aesdeclast xmm5, xmm12 aesdeclast xmm6, xmm12 aesdeclast xmm7, xmm12 aesdeclast xmm8, xmm12 movdqu xmm10, [rdi] movdqu xmm11, 16[rdi] movdqu xmm12, 32[rdi] movdqu xmm13, 48[rdi] pxor xmm1, xmm9 pxor xmm2, xmm10 pxor xmm3, xmm11 pxor xmm4, xmm12 pxor xmm5, xmm13 movdqu xmm10, 64[rdi] movdqu xmm11, 80[rdi] movdqu xmm12, 96[rdi] movdqu xmm9, 112[rdi] pxor xmm6, xmm10 pxor xmm7, xmm11 pxor xmm8, xmm12 movdqu [rsi], xmm1 movdqu 16[rsi], xmm2 movdqu 32[rsi], xmm3 movdqu 48[rsi], xmm4 movdqu 64[rsi], xmm5 movdqu 80[rsi], xmm6 movdqu 96[rsi], xmm7 movdqu 112[rsi], xmm8 add rdi, 128 dec rcx jne DLOOP_8 add rsi, 128 DREMAINDER_8: cmp r10, 0 je DEND_8 DLOOP_8_2: movdqu xmm1, [rdi] movdqa xmm10, xmm1 add rdi, 16 pxor xmm1, [r8] movdqu xmm2, 160[r8] cmp r9d, 12 aesdec xmm1, 16[r8] aesdec xmm1, 32[r8] aesdec xmm1, 48[r8] aesdec xmm1, 64[r8] aesdec xmm1, 80[r8] aesdec xmm1, 96[r8] aesdec xmm1, 112[r8] aesdec xmm1, 128[r8] aesdec xmm1, 144[r8] jb DLAST_8_2 movdqu xmm2, 192[r8] cmp r9d, 14 aesdec xmm1, 160[r8] aesdec xmm1, 176[r8] jb DLAST_8_2 movdqu xmm2, 224[r8] aesdec xmm1, 192[r8] aesdec xmm1, 208[r8] DLAST_8_2: aesdeclast xmm1, xmm2 pxor xmm1, xmm9 movdqa xmm9, xmm10 movdqu [rsi], xmm1 add rsi, 16 dec r10 jne DLOOP_8_2 DEND_8: ; restore non volatile rdi,rsi mov rdi, rax mov rsi, r11 ; restore non volatile xmms from stack movdqa xmm6, [rsp+0] movdqa xmm7, [rsp+16] movdqa xmm8, [rsp+32] movdqa xmm9, [rsp+48] movdqa xmm10, [rsp+64] movdqa xmm11, [rsp+80] movdqa xmm12, [rsp+96] movdqa xmm13, [rsp+112] add rsp, 8+8*16 ; 8 = align stack , 8 xmm6-13 16 bytes each ret AES_CBC_decrypt_by8 ENDP ; /* ; AES_ECB_encrypt[const ,unsigned char*in ; unsigned ,char*out ; unsigned ,long length ; const ,unsigned char*KS ; int nr] ; */ ; . globl AES_ECB_encrypt AES_ECB_encrypt PROC ;# parameter 1: rdi ;# parameter 2: rsi ;# parameter 3: rdx ;# parameter 4: rcx ;# parameter 5: r8d ; save rdi and rsi to rax and r11, restore before ret mov rax,rdi mov r11,rsi ; convert to what we had for att&t convention mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 mov r8d,[rsp+40] ; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end sub rsp,8+4*16 ; 8 = align stack , 4 xmm9-12, 16 bytes each movdqa [rsp+0], xmm9 movdqa [rsp+16], xmm10 movdqa [rsp+32], xmm11 movdqa [rsp+48], xmm12 mov r10,rdx shr rdx,4 shl r10,60 je EECB_NO_PARTS_4 add rdx,1 EECB_NO_PARTS_4: mov r10,rdx shl r10,62 shr r10,62 shr rdx,2 je EECB_REMAINDER_4 sub rsi,64 EECB_LOOP_4: movdqu xmm1,[rdi] movdqu xmm2,16[rdi] movdqu xmm3,32[rdi] movdqu xmm4,48[rdi] movdqa xmm9,[rcx] movdqa xmm10,16[rcx] movdqa xmm11,32[rcx] movdqa xmm12,48[rcx] pxor xmm1,xmm9 pxor xmm2,xmm9 pxor xmm3,xmm9 pxor xmm4,xmm9 aesenc xmm1,xmm10 aesenc xmm2,xmm10 aesenc xmm3,xmm10 aesenc xmm4,xmm10 aesenc xmm1,xmm11 aesenc xmm2,xmm11 aesenc xmm3,xmm11 aesenc xmm4,xmm11 aesenc xmm1,xmm12 aesenc xmm2,xmm12 aesenc xmm3,xmm12 aesenc xmm4,xmm12 movdqa xmm9,64[rcx] movdqa xmm10,80[rcx] movdqa xmm11,96[rcx] movdqa xmm12,112[rcx] aesenc xmm1,xmm9 aesenc xmm2,xmm9 aesenc xmm3,xmm9 aesenc xmm4,xmm9 aesenc xmm1,xmm10 aesenc xmm2,xmm10 aesenc xmm3,xmm10 aesenc xmm4,xmm10 aesenc xmm1,xmm11 aesenc xmm2,xmm11 aesenc xmm3,xmm11 aesenc xmm4,xmm11 aesenc xmm1,xmm12 aesenc xmm2,xmm12 aesenc xmm3,xmm12 aesenc xmm4,xmm12 movdqa xmm9,128[rcx] movdqa xmm10,144[rcx] movdqa xmm11,160[rcx] cmp r8d,12 aesenc xmm1,xmm9 aesenc xmm2,xmm9 aesenc xmm3,xmm9 aesenc xmm4,xmm9 aesenc xmm1,xmm10 aesenc xmm2,xmm10 aesenc xmm3,xmm10 aesenc xmm4,xmm10 jb EECB_LAST_4 movdqa xmm9,160[rcx] movdqa xmm10,176[rcx] movdqa xmm11,192[rcx] cmp r8d,14 aesenc xmm1,xmm9 aesenc xmm2,xmm9 aesenc xmm3,xmm9 aesenc xmm4,xmm9 aesenc xmm1,xmm10 aesenc xmm2,xmm10 aesenc xmm3,xmm10 aesenc xmm4,xmm10 jb EECB_LAST_4 movdqa xmm9,192[rcx] movdqa xmm10,208[rcx] movdqa xmm11,224[rcx] aesenc xmm1,xmm9 aesenc xmm2,xmm9 aesenc xmm3,xmm9 aesenc xmm4,xmm9 aesenc xmm1,xmm10 aesenc xmm2,xmm10 aesenc xmm3,xmm10 aesenc xmm4,xmm10 EECB_LAST_4: add rdi,64 add rsi,64 dec rdx aesenclast xmm1,xmm11 aesenclast xmm2,xmm11 aesenclast xmm3,xmm11 aesenclast xmm4,xmm11 movdqu [rsi],xmm1 movdqu 16[rsi],xmm2 movdqu 32[rsi],xmm3 movdqu 48[rsi],xmm4 jne EECB_LOOP_4 add rsi,64 EECB_REMAINDER_4: cmp r10,0 je EECB_END_4 EECB_LOOP_4_2: movdqu xmm1,[rdi] add rdi,16 pxor xmm1,[rcx] movdqu xmm2,160[rcx] aesenc xmm1,16[rcx] aesenc xmm1,32[rcx] aesenc xmm1,48[rcx] aesenc xmm1,64[rcx] aesenc xmm1,80[rcx] aesenc xmm1,96[rcx] aesenc xmm1,112[rcx] aesenc xmm1,128[rcx] aesenc xmm1,144[rcx] cmp r8d,12 jb EECB_LAST_4_2 movdqu xmm2,192[rcx] aesenc xmm1,160[rcx] aesenc xmm1,176[rcx] cmp r8d,14 jb EECB_LAST_4_2 movdqu xmm2,224[rcx] aesenc xmm1,192[rcx] aesenc xmm1,208[rcx] EECB_LAST_4_2: aesenclast xmm1,xmm2 movdqu [rsi],xmm1 add rsi,16 dec r10 jne EECB_LOOP_4_2 EECB_END_4: ; restore non volatile rdi,rsi mov rdi,rax mov rsi,r11 ; restore non volatile xmms from stack movdqa xmm9, [rsp+0] movdqa xmm10, [rsp+16] movdqa xmm11, [rsp+32] movdqa xmm12, [rsp+48] add rsp,8+4*16 ; 8 = align stack , 4 xmm9-12 16 bytes each ret AES_ECB_encrypt ENDP ; /* ; AES_ECB_decrypt[const ,unsigned char*in ; unsigned ,char*out ; unsigned ,long length ; const ,unsigned char*KS ; int nr] ; */ ; . globl AES_ECB_decrypt AES_ECB_decrypt PROC ;# parameter 1: rdi ;# parameter 2: rsi ;# parameter 3: rdx ;# parameter 4: rcx ;# parameter 5: r8d ; save rdi and rsi to rax and r11, restore before ret mov rax,rdi mov r11,rsi ; convert to what we had for att&t convention mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 mov r8d,[rsp+40] ; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end sub rsp,8+4*16 ; 8 = align stack , 4 xmm9-12, 16 bytes each movdqa [rsp+0], xmm9 movdqa [rsp+16], xmm10 movdqa [rsp+32], xmm11 movdqa [rsp+48], xmm12 mov r10,rdx shr rdx,4 shl r10,60 je DECB_NO_PARTS_4 add rdx,1 DECB_NO_PARTS_4: mov r10,rdx shl r10,62 shr r10,62 shr rdx,2 je DECB_REMAINDER_4 sub rsi,64 DECB_LOOP_4: movdqu xmm1,[rdi] movdqu xmm2,16[rdi] movdqu xmm3,32[rdi] movdqu xmm4,48[rdi] movdqa xmm9,[rcx] movdqa xmm10,16[rcx] movdqa xmm11,32[rcx] movdqa xmm12,48[rcx] pxor xmm1,xmm9 pxor xmm2,xmm9 pxor xmm3,xmm9 pxor xmm4,xmm9 aesdec xmm1,xmm10 aesdec xmm2,xmm10 aesdec xmm3,xmm10 aesdec xmm4,xmm10 aesdec xmm1,xmm11 aesdec xmm2,xmm11 aesdec xmm3,xmm11 aesdec xmm4,xmm11 aesdec xmm1,xmm12 aesdec xmm2,xmm12 aesdec xmm3,xmm12 aesdec xmm4,xmm12 movdqa xmm9,64[rcx] movdqa xmm10,80[rcx] movdqa xmm11,96[rcx] movdqa xmm12,112[rcx] aesdec xmm1,xmm9 aesdec xmm2,xmm9 aesdec xmm3,xmm9 aesdec xmm4,xmm9 aesdec xmm1,xmm10 aesdec xmm2,xmm10 aesdec xmm3,xmm10 aesdec xmm4,xmm10 aesdec xmm1,xmm11 aesdec xmm2,xmm11 aesdec xmm3,xmm11 aesdec xmm4,xmm11 aesdec xmm1,xmm12 aesdec xmm2,xmm12 aesdec xmm3,xmm12 aesdec xmm4,xmm12 movdqa xmm9,128[rcx] movdqa xmm10,144[rcx] movdqa xmm11,160[rcx] cmp r8d,12 aesdec xmm1,xmm9 aesdec xmm2,xmm9 aesdec xmm3,xmm9 aesdec xmm4,xmm9 aesdec xmm1,xmm10 aesdec xmm2,xmm10 aesdec xmm3,xmm10 aesdec xmm4,xmm10 jb DECB_LAST_4 movdqa xmm9,160[rcx] movdqa xmm10,176[rcx] movdqa xmm11,192[rcx] cmp r8d,14 aesdec xmm1,xmm9 aesdec xmm2,xmm9 aesdec xmm3,xmm9 aesdec xmm4,xmm9 aesdec xmm1,xmm10 aesdec xmm2,xmm10 aesdec xmm3,xmm10 aesdec xmm4,xmm10 jb DECB_LAST_4 movdqa xmm9,192[rcx] movdqa xmm10,208[rcx] movdqa xmm11,224[rcx] aesdec xmm1,xmm9 aesdec xmm2,xmm9 aesdec xmm3,xmm9 aesdec xmm4,xmm9 aesdec xmm1,xmm10 aesdec xmm2,xmm10 aesdec xmm3,xmm10 aesdec xmm4,xmm10 DECB_LAST_4: add rdi,64 add rsi,64 dec rdx aesdeclast xmm1,xmm11 aesdeclast xmm2,xmm11 aesdeclast xmm3,xmm11 aesdeclast xmm4,xmm11 movdqu [rsi],xmm1 movdqu 16[rsi],xmm2 movdqu 32[rsi],xmm3 movdqu 48[rsi],xmm4 jne DECB_LOOP_4 add rsi,64 DECB_REMAINDER_4: cmp r10,0 je DECB_END_4 DECB_LOOP_4_2: movdqu xmm1,[rdi] add rdi,16 pxor xmm1,[rcx] movdqu xmm2,160[rcx] cmp r8d,12 aesdec xmm1,16[rcx] aesdec xmm1,32[rcx] aesdec xmm1,48[rcx] aesdec xmm1,64[rcx] aesdec xmm1,80[rcx] aesdec xmm1,96[rcx] aesdec xmm1,112[rcx] aesdec xmm1,128[rcx] aesdec xmm1,144[rcx] jb DECB_LAST_4_2 cmp r8d,14 movdqu xmm2,192[rcx] aesdec xmm1,160[rcx] aesdec xmm1,176[rcx] jb DECB_LAST_4_2 movdqu xmm2,224[rcx] aesdec xmm1,192[rcx] aesdec xmm1,208[rcx] DECB_LAST_4_2: aesdeclast xmm1,xmm2 movdqu [rsi],xmm1 add rsi,16 dec r10 jne DECB_LOOP_4_2 DECB_END_4: ; restore non volatile rdi,rsi mov rdi,rax mov rsi,r11 ; restore non volatile xmms from stack movdqa xmm9, [rsp+0] movdqa xmm10, [rsp+16] movdqa xmm11, [rsp+32] movdqa xmm12, [rsp+48] add rsp,8+4*16 ; 8 = align stack , 4 xmm9-12 16 bytes each ret AES_ECB_decrypt ENDP ; /* ; void ,AES_128_Key_Expansion[const unsigned char*userkey ; unsigned char*key_schedule]/ ; */ ; . align 16,0x90 ; . globl AES_128_Key_Expansion AES_128_Key_Expansion PROC ;# parameter 1: rdi ;# parameter 2: rsi ; save rdi and rsi to rax and r11, restore before ret mov rax,rdi mov r11,rsi ; convert to what we had for att&t convention mov rdi,rcx mov rsi,rdx mov dword ptr 240[rsi],10 movdqu xmm1,[rdi] movdqa [rsi],xmm1 ASSISTS: aeskeygenassist xmm2,xmm1,1 call PREPARE_ROUNDKEY_128 movdqa 16[rsi],xmm1 aeskeygenassist xmm2,xmm1,2 call PREPARE_ROUNDKEY_128 movdqa 32[rsi],xmm1 aeskeygenassist xmm2,xmm1,4 call PREPARE_ROUNDKEY_128 movdqa 48[rsi],xmm1 aeskeygenassist xmm2,xmm1,8 call PREPARE_ROUNDKEY_128 movdqa 64[rsi],xmm1 aeskeygenassist xmm2,xmm1,16 call PREPARE_ROUNDKEY_128 movdqa 80[rsi],xmm1 aeskeygenassist xmm2,xmm1,32 call PREPARE_ROUNDKEY_128 movdqa 96[rsi],xmm1 aeskeygenassist xmm2,xmm1,64 call PREPARE_ROUNDKEY_128 movdqa 112[rsi],xmm1 aeskeygenassist xmm2,xmm1,80h call PREPARE_ROUNDKEY_128 movdqa 128[rsi],xmm1 aeskeygenassist xmm2,xmm1,1bh call PREPARE_ROUNDKEY_128 movdqa 144[rsi],xmm1 aeskeygenassist xmm2,xmm1,36h call PREPARE_ROUNDKEY_128 movdqa 160[rsi],xmm1 ; restore non volatile rdi,rsi mov rdi,rax mov rsi,r11 ret PREPARE_ROUNDKEY_128: pshufd xmm2,xmm2,255 movdqa xmm3,xmm1 pslldq xmm3,4 pxor xmm1,xmm3 pslldq xmm3,4 pxor xmm1,xmm3 pslldq xmm3,4 pxor xmm1,xmm3 pxor xmm1,xmm2 ret AES_128_Key_Expansion ENDP ; /* ; void ,AES_192_Key_Expansion[const unsigned char*userkey ; unsigned char*key] ; */ ; . globl AES_192_Key_Expansion AES_192_Key_Expansion PROC ;# parameter 1: rdi ;# parameter 2: rsi ; save rdi and rsi to rax and r11, restore before ret mov rax,rdi mov r11,rsi ; convert to what we had for att&t convention mov rdi,rcx mov rsi,rdx ; on microsoft xmm6-xmm15 are non volaitle, let's save on stack and restore at end sub rsp,8+1*16 ; 8 = align stack , 1 xmm6, 16 bytes each movdqa [rsp+0], xmm6 movdqu xmm1,[rdi] movq xmm3,qword ptr 16[rdi] movdqa [rsi],xmm1 movdqa xmm5,xmm3 aeskeygenassist xmm2,xmm3,1h call PREPARE_ROUNDKEY_192 shufpd xmm5,xmm1,0 movdqa 16[rsi],xmm5 movdqa xmm6,xmm1 shufpd xmm6,xmm3,1 movdqa 32[rsi],xmm6 aeskeygenassist xmm2,xmm3,2h call PREPARE_ROUNDKEY_192 movdqa 48[rsi],xmm1 movdqa xmm5,xmm3 aeskeygenassist xmm2,xmm3,4h call PREPARE_ROUNDKEY_192 shufpd xmm5,xmm1,0 movdqa 64[rsi],xmm5 movdqa xmm6,xmm1 shufpd xmm6,xmm3,1 movdqa 80[rsi],xmm6 aeskeygenassist xmm2,xmm3,8h call PREPARE_ROUNDKEY_192 movdqa 96[rsi],xmm1 movdqa xmm5,xmm3 aeskeygenassist xmm2,xmm3,10h call PREPARE_ROUNDKEY_192 shufpd xmm5,xmm1,0 movdqa 112[rsi],xmm5 movdqa xmm6,xmm1 shufpd xmm6,xmm3,1 movdqa 128[rsi],xmm6 aeskeygenassist xmm2,xmm3,20h call PREPARE_ROUNDKEY_192 movdqa 144[rsi],xmm1 movdqa xmm5,xmm3 aeskeygenassist xmm2,xmm3,40h call PREPARE_ROUNDKEY_192 shufpd xmm5,xmm1,0 movdqa 160[rsi],xmm5 movdqa xmm6,xmm1 shufpd xmm6,xmm3,1 movdqa 176[rsi],xmm6 aeskeygenassist xmm2,xmm3,80h call PREPARE_ROUNDKEY_192 movdqa 192[rsi],xmm1 movdqa 208[rsi],xmm3 ; restore non volatile rdi,rsi mov rdi,rax mov rsi,r11 ; restore non volatile xmms from stack movdqa xmm6, [rsp+0] add rsp,8+1*16 ; 8 = align stack , 1 xmm6 16 bytes each ret PREPARE_ROUNDKEY_192: pshufd xmm2,xmm2,55h movdqu xmm4,xmm1 pslldq xmm4,4 pxor xmm1,xmm4 pslldq xmm4,4 pxor xmm1,xmm4 pslldq xmm4,4 pxor xmm1,xmm4 pxor xmm1,xmm2 pshufd xmm2,xmm1,0ffh movdqu xmm4,xmm3 pslldq xmm4,4 pxor xmm3,xmm4 pxor xmm3,xmm2 ret AES_192_Key_Expansion ENDP ; /* ; void ,AES_256_Key_Expansion[const unsigned char*userkey ; unsigned char*key] ; */ ; . globl AES_256_Key_Expansion AES_256_Key_Expansion PROC ;# parameter 1: rdi ;# parameter 2: rsi ; save rdi and rsi to rax and r11, restore before ret mov rax,rdi mov r11,rsi ; convert to what we had for att&t convention mov rdi,rcx mov rsi,rdx movdqu xmm1,[rdi] movdqu xmm3,16[rdi] movdqa [rsi],xmm1 movdqa 16[rsi],xmm3 aeskeygenassist xmm2,xmm3,1h call MAKE_RK256_a movdqa 32[rsi],xmm1 aeskeygenassist xmm2,xmm1,0h call MAKE_RK256_b movdqa 48[rsi],xmm3 aeskeygenassist xmm2,xmm3,2h call MAKE_RK256_a movdqa 64[rsi],xmm1 aeskeygenassist xmm2,xmm1,0h call MAKE_RK256_b movdqa 80[rsi],xmm3 aeskeygenassist xmm2,xmm3,4h call MAKE_RK256_a movdqa 96[rsi],xmm1 aeskeygenassist xmm2,xmm1,0h call MAKE_RK256_b movdqa 112[rsi],xmm3 aeskeygenassist xmm2,xmm3,8h call MAKE_RK256_a movdqa 128[rsi],xmm1 aeskeygenassist xmm2,xmm1,0h call MAKE_RK256_b movdqa 144[rsi],xmm3 aeskeygenassist xmm2,xmm3,10h call MAKE_RK256_a movdqa 160[rsi],xmm1 aeskeygenassist xmm2,xmm1,0h call MAKE_RK256_b movdqa 176[rsi],xmm3 aeskeygenassist xmm2,xmm3,20h call MAKE_RK256_a movdqa 192[rsi],xmm1 aeskeygenassist xmm2,xmm1,0h call MAKE_RK256_b movdqa 208[rsi],xmm3 aeskeygenassist xmm2,xmm3,40h call MAKE_RK256_a movdqa 224[rsi],xmm1 ; restore non volatile rdi,rsi mov rdi,rax mov rsi,r11 ret AES_256_Key_Expansion ENDP MAKE_RK256_a: pshufd xmm2,xmm2,0ffh movdqa xmm4,xmm1 pslldq xmm4,4 pxor xmm1,xmm4 pslldq xmm4,4 pxor xmm1,xmm4 pslldq xmm4,4 pxor xmm1,xmm4 pxor xmm1,xmm2 ret MAKE_RK256_b: pshufd xmm2,xmm2,0aah movdqa xmm4,xmm3 pslldq xmm4,4 pxor xmm3,xmm4 pslldq xmm4,4 pxor xmm3,xmm4 pslldq xmm4,4 pxor xmm3,xmm4 pxor xmm3,xmm2 ret END ",16131,True,3966.9818920020707,median "; ; 2048 2600 ; ========= ; ; A port of the 2048 game to the Atari 2600 ; ; © 2014 Carlos Duarte do Nascimento (chesterbr) ; ; ; Latest version, contributors and general info: ; http://github.com/chesterbr/2048-2060 ; ; Building ; --------- ; ; You can build with DASM (http://dasm-dillon.sourceforge.net/), e.g.: ; ; dasm 2048.asm -o2048.bin -f3 ; ; However, you'll likely want to run graphics_gen.rb before. I've included ; my build script (build.sh), under the express condition that you don't ; mock my lame bash abilities :-P ; Cell Tables ; ----------- ; ; The game store each player's tiles in a ""cell table"", which can contain one ; of these values: ; ; 0 = empty cell ; 1 = ""2"" tile ; 2 = ""4"" tile ; 3 = ""8"" tile ; 4 = ""16"" tile ; ... ; n = ""2ⁿ"" tile (or, if you prefer: log₂k = ""k"" tile) ; ... ; 11 = ""2048"" tile ; 12 = ""4096"" tile ; 13 = ""8192"" tile ; (could go on, but try drawing a5-digit 8x10 tiles :-P ) ; 128 ($FF) = sentinel tile (see below) ; ; In theory, we'd use 16 positions in memory for a 4x4 grid. Navigating ; left/right on the grid would mean subtracting/adding one position, and ; moving up/down would be done by asubtracting 4 positions (that ; is, ""cell table y offset"" would be 4) ; ; However, we'd need to do complicated boundaries checking, so instead I ; surround the grid with ""sentinel"" or ""wall"" tiles. That would theoretically ; need 20 extra cells (bytes) to store the grid: ; ; first cell -> SSSSSS S = sentinel, . = data (a tile or empty cell) ; 7th cell -> S....S ; 13rd cell -> S....S ; 19th cell -> S....S ; 25th cell -> S....S ; SSSSSS <- last (36th) cell ; ; But we can save some space by removing th left-side sentinels, since the ; memory position before those will be a sentinel anyway (the previous line's ; right-side sentinel). ; ; We can also cut the first and last sentinel (no movement can reach those), ; ending with with this layout in memory (notice how you still hit a ; sentinel if you try to leave the board in any direction): ; ; first cell -> SSSSS S = sentinel, . = data (a tile or empty cell) ; 6th cell -> ....S ; 11th cell -> ....S ; 16th cell -> ....S ; 21st cell -> ....S ; SSSS <- last (29th) cell ; ; Only change from usual 4x4 is the cell table vertical y offset is now 5 (we ; add/subtract 5 to go down/up). The first data cell is still the first cell ; plus vertical y offset ; ; ; Grid Drawing ; ------------ ; ; The grid itself will be drawn using the TIA playfield, and the tiles ; with player graphics. The Atari only allows two of those graphics per ; scanline (although they can be repeated up to 3 times by the hardware), ; and we have four tiles per row, meaning we have to trick it[2] by: ; ; - Load the graphic for tiles A and B: ""A"" and ""B"" ; - Ask TIA to repeat each player graphic: ""A A"" and ""B B"" ; - Overlap their horizontal positions: ""A B A B"" ; - Load grpahic for tiles C and D when the ""A B C D"" ; TV beam is right halfway, that is, here: --------^ ; ; First three staeps can be done just once when we start drawing the grid ; (TIA remembers the position), but the fourth must be repeated for every ; scanline. Timing is crucial on third and fourth steps, but that's Atari ; programming for you! ; ; To translate the cell table into a visual grid, we have to calculate, for ; each data cell, where the bitmap for its value (tile or empty space) is ; stored. We use the scanlines between each row of cells to do this calculation, ; meaning we need 8 RAM positions (4 cells per row x 2 bytes per address). ; ; We use the full address instead of a memory page offset to take advantage ; of the ""indirect indexed"" 6502 addressing mode [1], but we load the ; graphics table at a ""page aligned"" location (i.e., a ""$xx00"" address), ; so we only need to update the least significant byte on the positions above. ; ; ; Shifting ; -------- ; ; The original 2048 sets a ""vector"" strucutre that points two variables with ; the direction in which the tiles will shift (e.g., vector.x = -1, vector.y ; = 0 means we'll move left). It also processes them from the opposite side ; (e.g., start from leftmost if it's a right shift), making the first one ; stop before the edge, the second stop before the first, etc. ; ; It also marks each merged tile as so (removing the marks between shifts), ; so it can block multiple merges (i.e., the row "" 4 4 8 16"" does not go ; straight to ""32"" with a left, but first becomes ""8 8 16"", then ""16 16"", then ; ""32"". Similarly, ""2 2 2 2"" would first become ""4 4"", then ""8"". Finally, ; it stores the previous position for each tile, and lets the awesomeness ; of CSS move them all at once with ease. ; ; We'll translate this idea by having a single-byte ""vector"" which can be ; -1/+1 for left/right, and -5/+5 for up/down (each row is 4 bytes plus a ; sentinel tile, see above). Each tile will be pushed (by adding the vector ; value) until the next cell is non-empty and does not match its value. ; ; The vector signal also tells us where to start to ensure they all get to ; the end: negative (left/up) start processing from the first cell and ; positive (right/down) start from the last. ; ; Merged tiles are marked by setting bit 7 on their values, which will be ; easy to check in upcoming pushed blocks without needing extra memory. ; We'll only miss the animations, but we can't have everything. ; ; ; Timings ; ------- ; ; Since the shift routine can have unpredictable timing (and I wanted some ; freedom to move routines between overscan and vertical blank), I decided ; to use RIOT timers instead of the traditional scanline count. It is not ; the usual route for games (as they tend to squeeze every scanline of ; processing), but for this project it worked fine. ; ; [1] http://skilldrick.github.io/easy6502/ ; [2] http://www.slideshare.net/chesterbr/atari-2600programming PROCESSOR 6502 INCLUDE ""vcs.h"" ORG $F800 ; It's a 2K cart, meaning it has 2048 bytes! #mindblow ;;;;;;;;;;;;;;;;; ;; DATA TABLES ;; ;;;;;;;;;;;;;;;;; ; Tile and digit graphics go in the beginning of the cart to keep page-aligned ; (that is, the address' MSB never changes and we only calculate the LSB) ;;;;;;;;;;;;;; ;; GRAPHICS ;; ;;;;;;;;;;;;;; ; Tiles are 8 x 11 to partially compensate for ; Atari's pixel ratio (approx. 1.66:1) ; ; Actually, the value-colored kernel can't really ; update the rightmost pixel on the first tile, so ; if you want to roll your own tiles... ; ; ┌─── ...don't set THIS bit ; ↓; Tiles: .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %11111111 .BYTE %10000001 .BYTE %10000001 .BYTE %10011111 .BYTE %10011111 .BYTE %10000001 .BYTE %10000001 .BYTE %11111001 .BYTE %10000001 .BYTE %10000001 .BYTE %11111111 .BYTE %11111111 .BYTE %11111001 .BYTE %11111001 .BYTE %11111001 .BYTE %11111001 .BYTE %10000001 .BYTE %10000001 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %11111111 .BYTE %11111111 .BYTE %11000011 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %11000011 .BYTE %11000011 .BYTE %10011001 .BYTE %10011001 .BYTE %11000011 .BYTE %11111111 .BYTE %11111111 .BYTE %11010001 .BYTE %11010101 .BYTE %11010101 .BYTE %11010101 .BYTE %11010001 .BYTE %11010111 .BYTE %11010111 .BYTE %11010111 .BYTE %11010111 .BYTE %11111111 .BYTE %11111111 .BYTE %11001001 .BYTE %11101011 .BYTE %11101011 .BYTE %11101011 .BYTE %11001001 .BYTE %11101101 .BYTE %11101101 .BYTE %11101101 .BYTE %11001001 .BYTE %11111111 .BYTE %11111111 .BYTE %10001101 .BYTE %10101101 .BYTE %10101101 .BYTE %10101101 .BYTE %10001101 .BYTE %10110001 .BYTE %10110101 .BYTE %10110101 .BYTE %10110101 .BYTE %11111111 .BYTE %00010001 .BYTE %01110101 .BYTE %00010001 .BYTE %11010101 .BYTE %00010001 .BYTE %11111111 .BYTE %11111101 .BYTE %11111101 .BYTE %11111101 .BYTE %11111101 .BYTE %11111101 .BYTE %00010001 .BYTE %11010101 .BYTE %00010001 .BYTE %01110111 .BYTE %00010111 .BYTE %11111111 .BYTE %11110001 .BYTE %11110111 .BYTE %11110001 .BYTE %11111101 .BYTE %11110001 .BYTE %11010001 .BYTE %11010111 .BYTE %11010001 .BYTE %11011101 .BYTE %11010001 .BYTE %11111111 .BYTE %11110001 .BYTE %11111101 .BYTE %11110001 .BYTE %11110111 .BYTE %11110001 .BYTE %00011101 .BYTE %01111101 .BYTE %00010001 .BYTE %11010101 .BYTE %00010101 .BYTE %11111111 .BYTE %11010001 .BYTE %11010101 .BYTE %11010101 .BYTE %11010101 .BYTE %11010001 .BYTE %11010001 .BYTE %11010101 .BYTE %00010001 .BYTE %01010101 .BYTE %01010001 .BYTE %11111111 .BYTE %00010001 .BYTE %01110101 .BYTE %00010101 .BYTE %11010101 .BYTE %00010001 .BYTE %11010001 .BYTE %11010101 .BYTE %00010001 .BYTE %01010111 .BYTE %00010111 .BYTE %11111111 .BYTE %11010001 .BYTE %11010101 .BYTE %00010101 .BYTE %01010101 .BYTE %01010001 .BYTE %11010001 .BYTE %11010111 .BYTE %00010001 .BYTE %01011101 .BYTE %00010001 .BYTE %11111111 .BYTE %10001011 .BYTE %10101011 .BYTE %10001011 .BYTE %10101011 .BYTE %10001011 TitleScreenTiles: .BYTE %11111111 .BYTE %11000011 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %11000011 .BYTE %11111111 .BYTE %11111111 .BYTE %11000011 .BYTE %10011001 .BYTE %10011001 .BYTE %10011001 .BYTE %10000001 .BYTE %10000011 .BYTE %10011111 .BYTE %10011001 .BYTE %11000011 .BYTE %11111111 .BYTE %01101010 .BYTE %01001010 .BYTE %01101100 .BYTE %01001010 .BYTE %01101110 .BYTE %00000000 .BYTE %11010101 .BYTE %10010101 .BYTE %10011101 .BYTE %10010101 .BYTE %11010101 .BYTE %11101010 .BYTE %10101010 .BYTE %11001100 .BYTE %10101010 .BYTE %11101110 .BYTE %00000000 .BYTE %10110010 .BYTE %00010010 .BYTE %10110010 .BYTE %00100010 .BYTE %10110111 Digits: .BYTE %01111110 .BYTE %01100110 .BYTE %01100110 .BYTE %01100110 .BYTE %01111110 .BYTE %01111110 .BYTE %00011000 .BYTE %00011000 .BYTE %01111000 .BYTE %00011000 .BYTE %01111110 .BYTE %01100000 .BYTE %01111110 .BYTE %00000110 .BYTE %01111110 .BYTE %01111110 .BYTE %00000110 .BYTE %00011110 .BYTE %00000110 .BYTE %01111110 .BYTE %00000110 .BYTE %00000110 .BYTE %01111110 .BYTE %01100110 .BYTE %01100110 .BYTE %01111110 .BYTE %00000110 .BYTE %01111110 .BYTE %01100000 .BYTE %01111110 .BYTE %01111110 .BYTE %01100110 .BYTE %01111110 .BYTE %01100000 .BYTE %01111110 .BYTE %00000110 .BYTE %00000110 .BYTE %00000110 .BYTE %00000110 .BYTE %01111110 .BYTE %01111110 .BYTE %01100110 .BYTE %01111110 .BYTE %01100110 .BYTE %01111110 .BYTE %01111110 .BYTE %00000110 .BYTE %01111110 .BYTE %01100110 .BYTE %01111110 ; Score values of each tile, in BCD TileValuesBCD: .byte $00,$04 .byte $00,$08 .byte $00,$16 .byte $00,$32 .byte $00,$64 .byte $01,$28 .byte $02,$56 .byte $05,$12 .byte $10,$24 .byte $20,$48 .byte $40,$96 .byte $81,$92 ; Values that change if we are on PAL mode (TV TYPE switch ""B•W"" position) ; Order: NTSC, PAL. (thanks @SvOlli) VBlankTime64T: .byte 44,74 OverscanTime64T: .byte 35,65 ;;;;;;;;;;;;;;; ;; CONSTANTS ;; ;;;;;;;;;;;;;;; ; Special cell values (see header) CellEmpty = 0 Cell2 = 1 Cell4 = 2 Cell2048 = 11 CellSentinel = 127 ; Can't use bit 7 (will be wiped) MergedMask = %10000000 ; Bit 7 is set to flag tiles as merged ClearMergedMask = %01111111 ; We need to reset to get to original values ; The original 2048 puts 2s with 90% probability and 4s with 10%. Our random ; number range between 0-255, so we'll put a 4 if it is above 256 * 0.9 ≅ 230 ThresholdForTile4 = 230 ; Values of GameState (it's a state machine!) TitleScreen = 0 ; => AddingRandomTitle AddingRandomTile = 1 ; => WaitingJoyRelease WaitingJoyRelease = 2 ; => WaitingJoyPress WaitingJoyPress = 3 ; => Shifting Shifting = 4 ; => ShowingMerged OR WaitingJoyRelease ShowingMerged = 5 ; => AddingRandomTile OR GameOverFX GameOverFX = 6 ; => GameOver GameOver = 7 ; => TitleScreen ; Values of GameMode OnePlayerGame = 0 TwoPlayerGame = 1 ; Some relative positions on the cell table ; Notice how we go to last data cell: Top-Left + 3 rows down + 3 columns right ; (FYI: add another row down and you'd have the last sentinel) FirstDataCellOffset = 5 LastDataCellOffset = FirstDataCellOffset + (CellTableYOffset * 3) + 3 LastCellOffset = LastDataCellOffset + CellTableYOffset CellTableYOffset = 5 ; How much we +/- to move up/down a line on the table ; Position of sentinels that might be picked as random tiles (for being the ; ones on the right ""wall"", see drawing on header), relative to the ; first data cell offset. ; We'll replace them with the last three, allowing our random nibble to ; effectively map a random data cell Wall1 = 4 Wall2 = 9 Wall3 = 14 Wall1Repl = 16 Wall2Repl = 17 Wall3Repl = 18 ScoreColor = $28 ; Colors were chosen to get equal or equally nice InactiveScoreColor = $04 ; on both PAL and NTSC, avoiding adjust branches GridColor = $04 BackgroundColor = $00 TileHeight = 11 ; Tiles have 11 scanlines (and are in graphics.asm) GridBottomHeight = 5 ; Doesn't count the ones we use calculating P1's score GridPF0 = $00 ; Grid sides are always clear, minus last bit GridPF1 = $01 GridPF2Tile = %10011001 ; Grid has ""holes"" for numbers GridPF2Space = %11111111 ; but is solid between the tiles PlayerTwoCopiesWide = $02 ; P0 and P1 drawing tiles: 0 1 0 1 PlayerThreeCopies = $03 ; P0 and P1 drawing score: 010101 VerticalDelay = $01 ; Delays writing of GRP0/GRP1 for 6-digit score AnimationFrames = 11 ; Time limit for merged tile / new tile animations JoyUp = %11100000 ; Masks to test SWCHA for joystick movement JoyDown = %11010000 ; (we'll shift P1's bits into P0s on his turn, so JoyLeft = %10110000 ; it's ok to use P0 values) JoyRight = %01110000 JoyMask = %11110000 ColSwitchMask = %00001000 ; Mask to test SWCHB for TV TYPE switch SelectResetMask = %00000011 ; Mask to test SWCHB for GAME SELECT/RESET switches GameSelect = %00000001 ; Value for GAME SELECT pressed (after mask) GameReset = %00000010 ; Value for GAME RESET pressed (after mask) ; Amount to add to move to a direciton in the cell grid, in two's complement RightShiftVector = $01 ; 1 LeftShiftVector = $FF ; -1 DownShiftVector = $05 ; 5 UpShiftVector = $FB ; -5 TurnIndicatorFrames = 60 ; Special display for this # of frames if turn switches MergeNoise = 4 ; Value of TurnNoise (AUDC0) if a merge happened ShiftNoise = 1 ; Value of TurnNoise (AUDC0) if no merge happened ;;;;;;;;; ;; RAM ;; ;;;;;;;;; ; Some positions are shared between different coroutines ; (think of them as local variables) CellTable = $80 ; 29 ($1D) bytes (16 cells + 13 sentinels) CellCursor = $9D ; Table offset of the ""current"" cell on grid setup ; Frame count based RNG, used to add tiles and title screen rainbow RandomNumber = $9E ; Counter to display ""animated"" tiles (merged / new) AnimationCounter = $9F ; Added to the tile address to produce the merge animation AnimationDelta = $A0 ; 6-digit score is stored in BCD (each nibble = 1 digit => 3 bytes) ScoreBCD = $A1 GameMode = $A4 ; One or Two players DidMerge = $A5 ; Nonzero if a merge happened on the last move ; $A6-$A7 have different uses in various kernel routines: TempVar1 = $A6 ; General use variable TempVar2 = $A7 ; General use variable LineCounter = $A6 ; Counts lines while drawing the score TempDigitBmp = $A7 ; Stores intermediate part of 6-digit score DidShift = $A6 ; True if a shift happened GameState = $A8; ; Tile shift routine variables ShiftVector = $A9 ; What to add to get to ""next"" tile in current direction TilesLoopDirection = $AA ; +1 for left/up, -1 for right/down OffsetBeingPushed = $AB ; Position in cell table of the tile being pushed ShiftEndOffset = $AC ; Position in which we'll stop processing CurrentValue = $AD ; Value of that tile ; Address of the graphic for for each digit (6x2 bytes) ; or tile (4x2 bytes) currently being drawn DigitBmpPtr = $B0 ; 6 bytes TileBmpPtr = $B0 ; 4 bytes (2 wasted) ; Colors of each tile on the current row (4 bytes) RowTileColor = $BC ; Store each player score separatedly and copy ; from/to ScoreBCD as needed to display, add, etc. ; Note: P1 score will store (and show) the high-score in single-player games P0ScoreBCD = $C0 ; 3 bytes P1ScoreBCD = $C3 ; 3 bytes ScoreBeingDrawn = $C6 ; 0 for P0 or 1 for P1 CurrentPlayer = $C7 ; 0 for P0 or 1 for P1 LastSWCHB = $C8 ; Avoid multiple detection of console switches TurnIndicatorCounter = $C9 ; Controls the time spent changing player turn GameOverEffectCounter = $CA ; Controls the time spent on game over effect CurrentBGColor = $CB ; Ensures invisible score keeps invisible during ; game over ""explosion"" DidMerge2048 = $CC ; 0 if no 2048 was reached; 11 (Cell2048) if we did Party2048Counter = $CD ; 2048 effects counter (and ensures they play only once) ;;;;;;;;;;;;;;; ;; BOOTSTRAP ;; ;;;;;;;;;;;;;;; Initialize: ; Cleanup routine from macro.h (by Andrew Davie/DASM) sei cld ldx #0 txa tay CleanStack: dex txs pha bne CleanStack ;;;;;;;;;;;;;;; ;; TIA SETUP ;; ;;;;;;;;;;;;;;; lda #%00000001 ; Playfield (grid) in mirror (symmetrical) mode sta CTRLPF ;;;;;;;;;;;;;;;;;;; ;; PROGRAM SETUP ;; ;;;;;;;;;;;;;;;;;;; ; Pre-fill the graphic pointers' MSBs, so we only have to ; figure out the LSBs for each tile or digit lda #>Tiles ; MSB of tiles/digits page ldx #11 ; 12-byte table (6 digits), zero-based FillMsbLoop: sta TileBmpPtr,x dex ; Skip to the next MSB dex bpl FillMsbLoop ; Initialize the cell table with sentinels, then fill ; the interior with empty cells ldx #LastCellOffset lda #CellSentinel InitCellTableLoop1: sta CellTable,x dex bpl InitCellTableLoop1 ;;;;;;;;;;;;;;;;;; ;; TITLE SCREEN ;; ;;;;;;;;;;;;;;;;;; ShowTitleScreen: lda #TitleScreen sta GameState lda #BackgroundColor ; Hide the grid separator sta COLUPF ldx #LastDataCellOffset ; Print using tiles TitleScreenLoop: lda TitleTiles-FirstDataCellOffset,x sta CellTable,x dex cpx #FirstDataCellOffset-1 bne TitleScreenLoop jmp StartFrame TitleTiles: .byte 1, 14, 2, 3, CellSentinel .byte 1, 15, 14, 14, CellSentinel .byte 0, 0, 0, 0, CellSentinel .byte 0, 0, 16, 17, CellSentinel ;;;;;;;;;;;;;; ;; NEW GAME ;; ;;;;;;;;;;;;;; StartNewGame: lda GridColor sta COLUPF ; Show the grid separator ldx #LastDataCellOffset ; Last non-sentinel cell offset lda #CellEmpty InitCellTableLoop2Outer: ldy #4 ; We'll clean 4 cells at a time InitCellTableLoop2Inner: sta CellTable,x dex dey bne InitCellTableLoop2Inner dex ; skip 1 cell (side sentinel) cpx #FirstDataCellOffset bcs InitCellTableLoop2Outer ; and continue until we pass the top-left cell ; Reset score lda #0 ldx #5 ; Reset both scores if on two-player game ldy GameMode cpy #TwoPlayerGame beq LoopResetScore ldx #2 ; Only reset P0 if single-player (P1=record) LoopResetScore: sta P0ScoreBCD,x dex bpl LoopResetScore ; Reset other variables sta CurrentPlayer sta CurrentBGColor sta DidMerge2048 sta Party2048Counter ; Start the game with a random tile lda #AddingRandomTile sta GameState ;;;;;;;;;;;;;;;;; ;; FRAME START ;; ;;;;;;;;;;;;;;;;; StartFrame: lda #%00000010 ; VSYNC sta VSYNC REPEAT 3 sta WSYNC REPEND lda #0 sta VSYNC sta WSYNC ldx #$00 lda #ColSwitchMask ; VBLANK start bit SWCHB bne NoVBlankPALAdjust ; ""Color"" => NTSC; ""B•W"" = PAL inx ; (this ajust will appear a few times in the code) NoVBlankPALAdjust: lda VBlankTime64T,x sta TIM64T ; Use a RIOT timer (with the proper value) instead lda #0 ; of counting scanlines (since we only care about sta VBLANK ; the overall time) ;;;;;;;;;;;;;;;;;;;;; ;; NEW RANDOM TILE ;; ;;;;;;;;;;;;;;;;;;;;; lda GameState cmp #AddingRandomTile bne EndRandomTile ; No need for a random tile now ; Pick a random cell from a number from 0..15, mapping those that would ; hit sentinels on the right side (""walls"") to the ones not covered by the range lda RandomNumber and #$0F cmp #Wall1 bne NoWall1 lda #Wall1Repl NoWall1: cmp #Wall2 bne NoWall2 lda #Wall2Repl NoWall2: cmp #Wall3 bne CheckIfCellIsEmpty lda #Wall3Repl CheckIfCellIsEmpty: tax ; Cell offset now in X lda CellTable+FirstDataCellOffset,x cmp #CellEmpty bne EndRandomTile ; Tile not empty, let's try again next frame PickTileType: ldy RandomNumber cpy #ThresholdForTile4 bcc PickTile2 lda #Cell4 ; >= threshold, A will be a ""4"" tile jmp AddTileToCell PickTile2: lda #Cell2 ; < threshold, A will be a ""2"" tile AddTileToCell: sta CellTable+FirstDataCellOffset,x lda #WaitingJoyRelease ; Tile added, player can play as soon as they sta GameState ; release the joystick EndRandomTile: inc RandomNumber ; Feed the random number generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SELECT, RESET AND P0 FIRE BUTTON ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ldx GameMode ; Remember if we were on one or two player mode lda SWCHB ; We only want the switch presses once and #SelectResetMask ; (in particular GAME SELECT) cmp LastSWCHB beq NoSwitchChange sta LastSWCHB ; Store so we know if it's a repeat next time cmp #GameSelect ; GAME SELECT flips single/multiplayer... bne NoSelect lda GameMode eor #1 sta GameMode jmp StartNewGame ; ...and restarts with no further game mode change NoSelect: cmp #GameReset ; GAME RESET restarts the game at any time beq Restart NoSwitchChange: lda INPT4 bpl ButtonPressed ; P0 Fire button pressed? ldx #1 ; P1 fire button always starts two-player game lda INPT5 ; P1 fire button pressed? bmi NoRestart ButtonPressed: lda GameState cmp #TitleScreen beq Restart ; Start game if title screen cmp #GameOver ; or game over bne NoRestart Restart: stx GameMode jmp StartNewGame NoRestart: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; POST-SHIFT ACTION (MERGE ANIMATION, SCORE UPDATE, GAME OVER) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; lda GameState cmp #ShowingMerged bne ResetAnimationCounter ; No animation: just keep the counter ready lda AnimationCounter ; Steadly decrease the shift tone, lsr ; giving it a ""wall hit"" feeling lsr sta AUDV0 dec AnimationCounter ; Decrease counter until animation ends bne DoneCounterManagement ; Finished animation: update score and add new tile lda #AddingRandomTile ; Animation done, let's add a tile... sta GameState ; and count points for merged cells... ldx FirstDataCellOffset ; (SEE NOTE 1) lda #0 sta DidMerge ; and set this flag if there were any sta DidMerge2048 ; and this to flag if any was a 2048 CountScoreLoop: lda CellTable,x cmp #MergedMask bmi ClearMergedBit ; Not merged, just clear the bit sta DidMerge ; Flag that we had (at least one) merge and #ClearMergedMask ; and get the value without the merge bit cmp #Cell2048 bne CountScore sta DidMerge2048 ; If we merged a 2048, flag it CountScore: asl tay ; Now Y = offset of tile values table sed ; We'll work in BCD lda CurrentPlayer bne AddScoreToP1 AddScoreToP0: clc lda TileValuesBCD-3,y adc P0ScoreBCD+2 sta P0ScoreBCD+2 ; score ""low byte"" += table LSB lda TileValuesBCD-4,y adc P0ScoreBCD+1 sta P0ScoreBCD+1 ; score ""middle byte"" += table MSB + carry lda #0 adc P0ScoreBCD sta P0ScoreBCD ; score ""high byte"" += carry jmp DoneAddingScore AddScoreToP1: clc lda TileValuesBCD-3,y adc P1ScoreBCD+2 sta P1ScoreBCD+2 ; score ""low byte"" += table LSB lda TileValuesBCD-4,y adc P1ScoreBCD+1 sta P1ScoreBCD+1 ; score ""middle byte"" += table MSB + carry lda #0 adc P1ScoreBCD sta P1ScoreBCD ; score ""high byte"" += carry DoneAddingScore: cld lda CellTable,x ; Restore original value ClearMergedBit: and #ClearMergedMask ; Clear bit and store sta CellTable,x inx cpx #LastDataCellOffset+1 bne CountScoreLoop ; Go to the next, up to the last tile ; Change the turn to the other player, if appropriate lda GameMode cmp #TwoPlayerGame bne DoneCounterManagement ; Single player always keeps their turn lda DidMerge bne DoneCounterManagement ; Did merge, player keeps his turn lda CurrentPlayer eor #1 ; Flip player (0<->1) sta CurrentPlayer lda #TurnIndicatorFrames ; Show it's his turn sta TurnIndicatorCounter ResetAnimationCounter: lda #AnimationFrames ; Keep this counter initialized sta AnimationCounter ; for the next animation DoneCounterManagement: ; Reached first 2048? Let's party! lda DidMerge2048 beq NoParty ; No 2048 lda Party2048Counter bne NoParty ; Already had a party inc Party2048Counter ; Let's party! NoParty: ;;;;;;;;;;;;;;;;;;;;;;;;; ;; GAME OVER DETECTION ;; ;;;;;;;;;;;;;;;;;;;;;;;;; lda GameState cmp #WaitingJoyRelease bne EndGameOverDetection ldx #FirstDataCellOffset FindAMoveLoop: lda CellTable,x ; A = current cell value cmp #CellEmpty beq FoundAMove ; Empty cell => can move inx cmp #CellSentinel beq FindAMoveLoopEnd ; Sentinel, check next cell cmp CellTable,x ; X = offset of cell to the right beq FoundAMove ; Cell matches right neighbour => can merge inx inx inx inx ; X = offset of cell to the bottom (1+4=5) cmp CellTable,x beq FoundAMove ; Cell matches bottom neighbour => can merge dex dex dex dex ; X = offset of next cell (1+4-4=1) FindAMoveLoopEnd: cpx #LastDataCellOffset+1 bne FindAMoveLoop ; Iterate all tiles ; If we get here, no move was found => game over lda #GameOverFX ; Start the game over effects... sta GameState lda #127 ; with a centered... sta AUDF0 lda #8 ; explosion-ish... sta AUDC0 lda #15 ; loud sound sta AUDV0 ldx #0 stx GameOverEffectCounter ; For two-player mode, find the winner and make it current (=highlighted) ; For one-player mode, just update the high score (P1 Score) ldy GameMode FindHigherScoreLoop: ; Iterate over score byte until we can lda P0ScoreBCD,x ; define whether P0 or P1 is higher cmp P1ScoreBCD,x beq ContinueFindHigherScore ; Can't tell from this byte, keep looping bcc P1Higher P0Higher: lda #0 cpy #TwoPlayerGame beq SetTurnToWinner ; Two-player game: P0 wins, make it current. ldx P0ScoreBCD ; One-player game: we have a new record, stx P1ScoreBCD ; copy it to the P1 (high score) ldx P0ScoreBCD+1 stx P1ScoreBCD+1 ldx P0ScoreBCD+2 stx P1ScoreBCD+2 jmp EndGameOverDetection P1Higher: cpy #OnePlayerGame beq EndGameOverEffects ; One-player game: no new record, we're done lda #1 ; Two-Player game: P1 wins, make it current. jmp SetTurnToWinner ContinueFindHigherScore: inx cpx #3 bne FindHigherScoreLoop BothAreLosers: lda #99 ; In a tie, no one will be bright SetTurnToWinner: sta CurrentPlayer FoundAMove: EndGameOverDetection: ;;;;;;;;;;;;;;;;;;;;;;; ;; GAME OVER EFFECTS ;; ;;;;;;;;;;;;;;;;;;;;;;; lda GameState cmp #GameOverFX bne EndGameOverEffects lda RandomNumber ; Flash the background sta COLUBK sta CurrentBGColor inc GameOverEffectCounter ; Keep on for ~2.3s (+/-0.2 for PAL/NTSC diff) bpl EndGameOverEffects lda #BackgroundColor ; Now game is *really* over, cut the effects sta COLUBK sta CurrentBGColor lda #0 sta AUDV0 lda #GameOver sta GameState EndGameOverEffects: ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 2048 ""PARTY"" EFFECTS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;; lda Party2048Counter beq DonePartyCheck ; No party yet bmi DonePartyCheck ; Party is over lda #04 ; Party! sta AUDC1 lda Party2048Counter sta AUDF1 sta COLUPF lda #10 sta AUDV1 inc Party2048Counter bpl DonePartyCheck lda #0 ; End of party sta AUDV1 lda GridColor sta COLUPF DonePartyCheck: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; OTHER FRAME CONFIGURATION ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; lda #0 ; First score to show is P0's sta ScoreBeingDrawn ; (P1 will come after the grid) ;;;;;;;;;;;;;;;;;;;;;;;;; ;; REMAINDER OF VBLANK ;; ;;;;;;;;;;;;;;;;;;;;;;;;; WaitForVBlankEndLoop: lda INTIM ; Wait until the timer signals the actual end bne WaitForVBlankEndLoop ; of the VBLANK period sta WSYNC ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOP SPACE ABOVE SCORE ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ldx #36 SpaceAboveLoop: sta WSYNC dex bne SpaceAboveLoop sta WSYNC ;;;;;;;;;;;;;;;;; ;; SCORE SETUP ;; ;;;;;;;;;;;;;;;;; ScoreSetup: ; Score setup scanline 1: ; general configuration lda GameState cmp #TitleScreen bne YesScore ; No score on title screen NoScore: ldx #13 ScoreSpaceLoop: sta WSYNC dex bne ScoreSpaceLoop jmp ScoreCleanup YesScore: lda #0 ; No players until we start sta GRP0 sta GRP1 lda ScoreBeingDrawn ; Copy the proper score to display bne ReadScoreP1 ReadScoreP0: lda P0ScoreBCD ldx P0ScoreBCD+1 ldy P0ScoreBCD+2 jmp WriteScore ReadScoreP1: lda P1ScoreBCD ldx P1ScoreBCD+1 ldy P1ScoreBCD+2 WriteScore: sta ScoreBCD stx ScoreBCD+1 sty ScoreBCD+2 sta WSYNC ; Score setup scanlines 2-3: ; player graphics triplicated and positioned like this: P0 P1 P0 P1 P0 P1 ; also, set their colors lda #PlayerThreeCopies ; (2) sta NUSIZ0 ; (3) sta NUSIZ1 ; (3) lda #VerticalDelay ; (2) ; Needed for precise timing of GRP0/GRP1 sta VDELP0 ; (3) sta VDELP1 ; (3) REPEAT 10 ; (20=10x2) ; Delay to position right nop REPEND sta RESP0 ; (3) ; Position P0 sta RESP1 ; (3) ; Position P1 sta WSYNC lda #$E0 ; Fine-tune player positions to center on screen sta HMP0 lda #$F0 sta HMP1 sta WSYNC sta HMOVE ; (3) ldx #ScoreColor ; Animate score for a few seconds when the lda TurnIndicatorCounter ; turn changes beq NoTurnAnimation adc #ScoreColor tax dec TurnIndicatorCounter NoTurnAnimation: lda ScoreBeingDrawn ; If score drawn belongs to the current player, cmp CurrentPlayer ; it is always shown as active beq SetScoreColor lda GameState ; If game is over, always show both scores cmp #GameOver ; (because P1 is the high score) beq ShowAsInactive ldx CurrentBGColor ; Get rid of score if not current and on single lda GameMode ; player game (in which P0 is always current), cmp #OnePlayerGame ; otherwise show as inactive beq SetScoreColor ShowAsInactive: ldx #InactiveScoreColor SetScoreColor: stx COLUP0 stx COLUP1 ; Score setup scanlines 4-5 ; set the graphic pointers for each score digit ldy #2 ; (2) ; Score byte counter (source) ldx #10 ; (2) ; Graphic pointer counter (target) clc ; (2) ScorePtrLoop: lda ScoreBCD,y ; (4) and #$0F ; (2) ; Lower nibble sta TempVar1 ; (3) asl ; (2) ; A = digit x 2 asl ; (2) ; A = digit x 4 adc TempVar1 ; (3) ; 4.digit + digit = 5.digit adc # tile values cpx #FirstDataCellOffset+19 bpl FixedColors ; Title 4th row => fixed values cpx #FirstDataCellOffset+12 bpl ColorsFromValues ; Title 3rd row => tile values (=0) ColorsFromRainbow: ; Title 1st/2nd row => rainbow lda RandomNumber sta RowTileColor adc #10 adc CellCursor sta RowTileColor+1 adc #10 adc CellCursor sta RowTileColor+2 adc #10 adc CellCursor sta RowTileColor+3 sta WSYNC jmp DoneWithColors FixedColors: sta WSYNC lda #BackgroundColor sta RowTileColor sta RowTileColor+1 lda #ScoreColor sta RowTileColor+2 sta RowTileColor+3 ldx #3 PositionChesterTilesLoop: nop dex bne PositionChesterTilesLoop sta RESP0 jmp DoneWithColors ColorsFromValues: ldy #3 SetColorLoop: dex lda CellTable,x ; A = current cell value. asl asl asl asl beq StoreColor adc #8 ; If not empty, add some luminance StoreColor: sta RowTileColor,y ; Y = current color table offset dey bpl SetColorLoop DoneWithColors: sta WSYNC ; Last separator scanline: ; change playfield (after the beam draws the last separator one) ; and initialize counter ldx RowTileColor+3 ; (3) ; Will be used on grid row txs ; (2) ; to save a cycle ldy #9 ; (2) ; Wait till beam is past the board LastSeparatorLineLoop: dey ; (2) bne LastSeparatorLineLoop ; (2*) (3 except last) ldy #TileHeight-1 ; (2) ; Initialize tile scanline counter ; (goes downwards and is zero-based) lda #GridPF2Tile ; (2) ; Change to the ""tile"" playfield sta PF2 ; (3) ; no STA wsync (will do it in the grid row loop) ;;;;;;;;;;;;;; ;; GRID ROW ;; ;;;;;;;;;;;;;; RowScanline: ldx RowTileColor+2 ; (3) lda RowTileColor ; (3) sta COLUP0 ; (3) sta WSYNC ; (3) lda RowTileColor+1 ; (3) sta COLUP1 ; (3) lda (TileBmpPtr+6),y ; (5) sta TempVar1 ; (3) nop ; (2) nop ; (2) lda (TileBmpPtr),y ; (5) sta GRP0 ; (3) lda (TileBmpPtr+2),y ; (5) sta GRP1 ; (3) lda (TileBmpPtr+4),y ; (5) sta GRP0 ; (3) lda TempVar1 ; (3) stx COLUP0 ; (3) sta GRP1 ; (3) tsx ; (2) stx COLUP1 ; (3) dey ; (2) bpl RowScanline ; (2*) sta WSYNC ; Go to the next row of tiles (or finish grid) lda #0 ; Disable player (tile) graphics sta GRP0 sta GRP1 lda #GridPF2Space ; and return to the ""separator"" playfield sta PF2 inc CellCursor ; Advance cursor (past the side sentinel) ldx CellCursor ; and get its value lda CellTable,x cmp #CellSentinel ; If it's a sentinel, move on beq FinishGrid sta WSYNC ; otherwise just skip the setup and prepare sta WSYNC ; another batch of tiles to display sta WSYNC jmp GridRowPreparation FinishGrid: ldx #GridBottomHeight ; We'll draw a part of the last separator here; DrawBottomSeparatorLoop: ; the remainder will be drawn during P1 score sta WSYNC ; calculation dex bne DrawBottomSeparatorLoop inc ScoreBeingDrawn ; Display score for P1 (even if invisible) jmp ScoreSetup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; BOTTOM SPACE BELOW GRID ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FrameBottomSpace: ldx #36 SpaceBelowGridLoop: sta WSYNC dex bne SpaceBelowGridLoop ;;;;;;;;;;;;;; ;; OVERSCAN ;; ;;;;;;;;;;;;;; lda #%01000010 ; Disable output sta VBLANK ldx #$00 lda #ColSwitchMask bit SWCHB bne NoOverscanPALAdjust inx NoOverscanPALAdjust: lda OverscanTime64T,x ; Use a timer adjusted to the color system's TV sta TIM64T ; timings to end Overscan, same as VBLANK ;;;;;;;;;;;;;;;;;;;; ;; INPUT CHECKING ;; ;;;;;;;;;;;;;;;;;;;; ; Joystick lda SWCHA ldx CurrentPlayer beq VerifyGameStateForJoyCheck asl ; If it's P1's turn, put their bits where P0s asl ; would be asl asl VerifyGameStateForJoyCheck: and #JoyMask ; Only player 0 bits ldx GameState ; We only care for states in which we are waiting cpx #WaitingJoyRelease ; for a joystick press or release beq CheckJoyRelease cpx #WaitingJoyPress bne EndJoyCheck ; If the joystick is in one of these directions, trigger the shift by ; setting the ShiftVector and changing mode CheckJoyUp: cmp #JoyUp bne CheckJoyDown lda #UpShiftVector jmp TriggerShift CheckJoyDown: cmp #JoyDown bne CheckJoyLeft lda #DownShiftVector jmp TriggerShift CheckJoyLeft: cmp #JoyLeft bne CheckJoyRight lda #LeftShiftVector jmp TriggerShift CheckJoyRight: cmp #JoyRight bne EndJoyCheck lda #RightShiftVector TriggerShift: sta ShiftVector ; We'll need the direction vector on the shift lda #Shifting sta GameState jmp EndJoyCheck CheckJoyRelease: cmp #JoyMask bne EndJoyCheck lda #WaitingJoyPress ; Joystick released, can accept shifts again sta GameState EndJoyCheck: ;;;;;;;;;;;;;;;;; ;; SHIFT BOARD ;; ;;;;;;;;;;;;;;;;; lda GameState cmp #Shifting beq StartShift ; Have to do this instead of bne EndShift jmp EndShift ; because the routine is > 128 bytes! ; Outer loop will traverse the entire cell map in the *opposite* order of the ; movement, that is, from the beginning for right/up and from end for left/down, ; so they stack and merge as expected. Let's setup these parameters StartShift: lda #0 ; So far, no merges happened sta DidMerge SetDirection: lda ShiftVector bmi NegativeVector PositiveVector: ldx #LastDataCellOffset ; Start from the last cell ldy #FirstDataCellOffset-1 ; Stop when we pass the first one lda #$FF ; Go backwards (-1) jmp SetShiftParams NegativeVector: ldx #FirstDataCellOffset ; Start from the first cell ldy #LastDataCellOffset+1 ; Stop when we pass the last one lda #$01 ; Go forward (+1) SetShiftParams: sty ShiftEndOffset sta TilesLoopDirection lda #WaitingJoyRelease ; We won't animate or add tiles unless some sta GameState ; movement happens ; Notice that X will keep the offset of the cell being processed (main loop), ; and will advance until we have no more processable tile positions. ; ; Whenever we have a ""good"" tile on X (not empty or sentinel), we'll start ; pushing it on the vector direciton (inner/""push"" loop), until we can't ; push anyomre. CheckIfXIsPushable: lda CellTable,x cmp #CellSentinel beq AdvanceToNext ; Skip empty cells cmp #CellEmpty beq AdvanceToNext ; Skip sentinels stx OffsetBeingPushed jmp StartPush ; This one is good, start pushing it AdvanceToNext: txa ; Move X to the next candidate offset clc adc TilesLoopDirection tax cpx ShiftEndOffset beq TurnNoiseSetup ; Processed all tiles, shift is done! jmp CheckIfXIsPushable ; Check the new candidate TurnNoiseSetup: lda GameState cmp #WaitingJoyRelease beq EndShift ; No shift => no noise ldx #ShiftNoise lda DidMerge beq StartNoise ; Shift with no merge => shift noise ldx #MergeNoise ; Shift & merge => merge noise StartNoise: stx AUDC0 lda #90 sta AUDF0 jmp EndShift ; Inner loop will push the tile currenlty picked by the outer loop towards ; the desired direction, until hitting an unmergeable tile StartPush: lda CellTable,x sta CurrentValue ; Keep the current tile's value stx OffsetBeingPushed ; Initialize inner loop counter PushCurrentTile: ; Inner loop begins here clc lda OffsetBeingPushed adc ShiftVector tay lda CellTable,y ; A <= value of next cell in the vector direction cmp #CellEmpty bne NotEmpty ; We won't move if the next cell is not empty MoveCurrentToNext: lda #ShowingMerged ; If we move at least once, we can show merged sta GameState ; animations (if any) lda CurrentValue sta CellTable,y ; Set next cell to current value lda #CellEmpty ldy OffsetBeingPushed sta CellTable,y ; Clear current cell clc lda OffsetBeingPushed adc ShiftVector sta OffsetBeingPushed ; - make next the one being pushed jmp PushCurrentTile ; Keep pushing NotEmpty: cmp #MergedMask bcs AdvanceToNext ; Can't merge if next cell has already been merged cmp CurrentValue bne AdvanceToNext ; Only merge if value matches Merge: inc CurrentValue ; Multiply by 2 in log (that is, add 1 to exponent) lda #MergedMask ora CurrentValue ; Add the ""merged"" bit (so it doesn't match others) sta CurrentValue sta DidMerge ; Signal the merge jmp MoveCurrentToNext ; Move the multiplied cell to the target position EndShift: ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; REMAINDER OF OVERSCAN ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; WaitForOverscanEndLoop: lda INTIM ; Wait until the timer signals the actual end bne WaitForOverscanEndLoop ; of the overscan period sta WSYNC jmp StartFrame ORG $FFFA .WORD Initialize .WORD Initialize .WORD Initialize END ; NOTE 1: ; ; As pointed out by http://github.com/david-schmidt in Issue #8 ; (https://github.com/chesterbr/2048-2600/issues/8), this line should read: ; ; ldx #FirstDataCellOffset ; ; The way it is it will instead read the contents of CXM1FB, a collision ; latch whose active bits will be always 0, and I it seems I got lucky that: ; ; a) The inactive ones are also 0 (although this is not documented), making the ; score count start from the wall instead of the first data cell. ; b) Walls don't score points. ; ; which makes the score count work depsite of the bug. I will not fix it ; to avoid generating a deviant binary from the one that is already on the ; wild (including physical carts from GDG) ; ; The MIT License (MIT) ; Copyright (c) 2014 Carlos Duarte do Nascimento (Chester) ; ; Original 2048 game Copyright (c) 2014 Gabriele Cirulli ; Permission is hereby granted, free of charge, to any person obtaining a copy ; of this software and associated documentation files (the ""Software""), to deal ; in the Software without restriction, including without limitation the rights ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ; copies of the Software, and to permit persons to whom the Software is ; furnished to do so, subject to the following conditions: ; The above copyright notice and this permission notice shall be included in all ; copies or substantial portions of the Software. ; THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ; SOFTWARE. ",16306,True,2515.1529078940257,median ";this file for FamiTone2 library generated by FamiStudio silver_surfer_c_stephen_ruddy_music_data: db 1 dw @instruments dw @samples-3 dw @song0ch0,@song0ch1,@song0ch2,@song0ch3,@song0ch4 db <(@tempo_env6), >(@tempo_env6), 0, 0 @instruments: dw @env59,@env38,@env34,@env31 dw @env50,@env43,@env34,@env31 dw @env39,@env38,@env34,@env31 dw @env44,@env38,@env34,@env31 dw @env20,@env47,@env34,@env31 dw @env13,@env41,@env34,@env31 dw @env36,@env42,@env34,@env31 dw @env30,@env38,@env34,@env31 dw @env11,@env40,@env34,@env31 dw @env14,@env32,@env37,@env31 dw @env14,@env1,@env15,@env31 dw @env14,@env1,@env34,@env31 dw @env14,@env1,@env35,@env31 dw @env14,@env1,@env6,@env31 dw @env54,@env26,@env34,@env10 dw @env54,@env25,@env6,@env49 dw @env52,@env25,@env6,@env49 dw @env17,@env1,@env35,@env61 dw @env5,@env1,@env34,@env31 dw @env29,@env1,@env35,@env28 dw @env55,@env12,@env6,@env31 dw @env58,@env1,@env37,@env31 dw @env14,@env4,@env34,@env31 dw @env8,@env1,@env35,@env31 dw @env7,@env1,@env34,@env23 dw @env7,@env19,@env34,@env31 dw @env7,@env1,@env37,@env23 dw @env7,@env1,@env35,@env23 dw @env55,@env1,@env34,@env31 dw @env53,@env1,@env35,@env51 dw @env46,@env1,@env6,@env3 dw @env56,@env27,@env34,@env31 dw @env60,@env57,@env34,@env31 @samples: @env0: db $c0,$cc,$c3,$cf,$c7,$d3,$cc,$d8,$c7,$cc,$cf,$d3,$00,$00 @env1: db $c0,$7f,$00,$00 @env2: db $c0,$02,$c4,$02,$c9,$02,$c4,$c4,$c4,$00,$00 @env3: db $00,$c0,$08,$c0,$bf,$be,$bd,$be,$bf,$c0,$c1,$c2,$c3,$c2,$c1,$00,$03 @env4: db $c0,$03,$b4,$00,$02 @env5: db $04,$c5,$00,$01,$c4,$03,$c3,$03,$c2,$00,$08 @env6: db $c3,$7f,$00,$00 @env7: db $00,$c2,$c4,$c5,$c6,$c4,$00,$05 @env8: db $00,$c1,$c2,$c3,$c4,$00,$04 @env9: db $c0,$c0,$cc,$cc,$c4,$c4,$d0,$d0,$c7,$c7,$d3,$d3,$00,$00 @env10: db $00,$c0,$c0,$c1,$00,$03 @env11: db $00,$c7,$c5,$c5,$c4,$c4,$c3,$c3,$c2,$c2,$c1,$c1,$c0,$00,$0c @env12: db $c0,$c0,$cc,$00,$02 @env13: db $00,$c5,$c4,$03,$c3,$04,$c2,$00,$06 @env14: db $04,$cf,$7f,$00,$01 @env15: db $c0,$c0,$c1,$c1,$c0,$c0,$00,$00 @env16: db $c0,$02,$c5,$02,$c8,$02,$c5,$c5,$c5,$00,$00 @env17: db $00,$c8,$c7,$c6,$c5,$c4,$c3,$c2,$c1,$03,$c2,$c4,$c3,$c2,$c1,$c1,$c2,$c4,$c3,$c2,$c1,$c1,$c2,$c6,$c5,$c4,$c3,$c2,$c1,$c4,$c3,$c2,$c1,$02,$c3,$c2,$c1,$02,$c2,$c4,$c3,$c2,$c1,$c1,$c4,$00,$01 @env18: db $c0,$cc,$c4,$d0,$c7,$d3,$cc,$d8,$c7,$cc,$cf,$d3,$00,$00 @env19: db $c0,$c0,$b4,$b4,$c0,$c0,$00,$00 @env20: db $0b,$c7,$c3,$10,$c2,$05,$c1,$05,$c0,$00,$08,$c1,$c2,$00,$0c @env21: db $c0,$c0,$cc,$cc,$c4,$c4,$d0,$d0,$c7,$c7,$d3,$d3,$cb,$cb,$d7,$d7,$00,$00 @env22: db $c0,$c0,$cc,$cc,$c4,$c4,$d0,$d0,$c6,$c6,$d2,$d2,$c9,$c9,$d5,$d5,$00,$00 @env23: db $00,$c0,$09,$c0,$be,$bc,$be,$c0,$c2,$c4,$c2,$00,$03 @env24: db $c0,$02,$c4,$02,$c7,$02,$c4,$c4,$c4,$00,$00 @env25: db $c0,$d3,$c0,$00,$02 @env26: db $c0,$cc,$c0,$00,$02 @env27: db $c0,$be,$ba,$b6,$b4,$b2,$00,$05 @env28: db $00,$b5,$c4,$d3,$e2,$f1,$ff,$00,$01 @env29: db $04,$c3,$7f,$00,$01 @env30: db $00,$c4,$03,$c3,$03,$c2,$00,$05 @env31: db $00,$c0,$7f,$00,$01 @env32: db $c0,$bf,$be,$bd,$bc,$bb,$ba,$b9,$b8,$b7,$b6,$b5,$00,$00 @env33: db $c0,$02,$c5,$02,$c9,$02,$c5,$c5,$c5,$00,$00 @env34: db $7f,$00,$00 @env35: db $c2,$7f,$00,$00 @env36: db $00,$c5,$c4,$02,$c3,$03,$c2,$04,$c1,$00,$08 @env37: db $c1,$7f,$00,$00 @env38: db $c0,$c2,$00,$01 @env39: db $00,$c3,$c3,$c2,$c1,$c0,$00,$05 @env40: db $c0,$c3,$00,$01 @env41: db $c0,$c6,$00,$01 @env42: db $c0,$c4,$00,$01 @env43: db $c0,$c5,$00,$01 @env44: db $00,$c4,$02,$c3,$02,$c2,$02,$c1,$00,$07 @env45: db $c0,$c0,$cc,$cc,$c4,$c4,$cf,$cf,$c7,$c7,$d3,$d3,$cc,$cc,$d8,$d8,$c7,$c7,$cc,$cc,$cf,$cf,$d3,$d3,$00,$00 @env46: db $04,$c5,$00,$01,$c3,$c1,$00,$05 @env47: db $c0,$c4,$02,$c5,$03,$c6,$04,$c7,$00,$07 @env48: db $c0,$02,$c5,$02,$c7,$02,$c5,$c5,$c5,$00,$00 @env49: db $00,$c0,$c1,$00,$02 @env50: db $00,$c5,$c3,$c2,$c1,$c0,$00,$05 @env51: db $00,$c0,$03,$c0,$bf,$be,$bd,$be,$bf,$c0,$c1,$c2,$c3,$c2,$c1,$00,$03 @env52: db $00,$c4,$c3,$c4,$c4,$c2,$c1,$00,$06 @env53: db $04,$c4,$00,$01,$c2,$c1,$00,$05 @env54: db $04,$c4,$7f,$00,$01 @env55: db $00,$c5,$c5,$c4,$c4,$00,$01 @env56: db $00,$cf,$05,$c0,$00,$03 @env57: db $c0,$bf,$00,$01 @env58: db $00,$c5,$c5,$c4,$02,$c3,$00,$05 @env59: db $00,$c5,$c4,$c4,$c3,$02,$c2,$02,$c1,$00,$08 @env60: db $00,$cf,$cf,$c0,$00,$03 @env61: db $00,$bf,$c0,$00,$02 @env62: db $00,$c0,$bf,$be,$02,$bf,$c1,$c2,$02,$c1,$00,$01 @tempo_env6: db $01,$05,$80 @song0ch0: @ref0: db $72,$96,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89 @ref1: db $33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89,$33,$89,$2e,$89 @song0ch0loop: @ref2: db $fb,<(@tempo_env6),>(@tempo_env6),$7f,$64,<(@env18),>(@env18),$a4,$25,$c5,$64,<(@env0),>(@env0),$62,$27,$b1,$f9,$91,$64,<(@env18),>(@env18),$2a,$ad @ref3: db $62,$2c,$f7,$b1,$f9,$91 @ref4: db $67,$25,$c5,$64,<(@env0),>(@env0),$62,$27,$b1,$f9,$91,$64,<(@env18),>(@env18),$2a,$ad db $ff,$05 dw @ref3 db $ff,$08 dw @ref4 db $ff,$05 dw @ref3 @ref5: db $67,$2c,$95 @ref6: db $74,$64,<(@env45),>(@env45),$96,$28,$f7,$c5 @ref7: db $64,<(@env22),>(@env22),$28,$f7,$c5 @ref8: db $7f,$64,<(@env1),>(@env1),$66,$9c,$24,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$1d,$9d,$00,$81,$1b,$91,$00,$81,$1a,$91,$00,$81,$1b,$91,$00,$81 @ref9: db $24,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$1d,$9d,$00,$81,$1f,$91,$00,$81,$22,$91,$00,$81,$24,$91,$00,$81 @ref10: db $24,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$18,$85,$00,$81,$1d,$9d,$00,$81,$1b,$91,$00,$81,$1a,$91,$00,$81,$1b,$91,$00,$81 db $ff,$2c dw @ref9 db $ff,$2c dw @ref10 db $ff,$2c dw @ref9 db $ff,$2c dw @ref10 db $ff,$2c dw @ref9 db $ff,$2c dw @ref10 db $ff,$2c dw @ref9 db $ff,$2c dw @ref10 db $ff,$2c dw @ref9 db $ff,$2c dw @ref10 db $ff,$2c dw @ref9 @ref11: db $64,<(@env16),>(@env16),$aa,$2b,$dd,$64,<(@env2),>(@env2),$2c,$dd @ref12: db $64,<(@env33),>(@env33),$29,$dd,$64,<(@env48),>(@env48),$2b,$ad,$64,<(@env24),>(@env24),$2b,$ad @ref13: db $64,<(@env16),>(@env16),$62,$2b,$dd,$64,<(@env2),>(@env2),$2c,$dd db $ff,$06 dw @ref12 db $ff,$04 dw @ref13 db $ff,$06 dw @ref12 db $ff,$04 dw @ref13 db $ff,$06 dw @ref12 @ref14: db $73,$64,<(@env1),>(@env1),$66,$98,$30,$ad,$62,$61,$fd,$30,$48,$f7,$95 @ref15: db $f7,$c7 @ref16: db $7f,$a2,$57,$dd,$57,$dd @ref17: db $57,$dd,$57,$dd @ref18: db $57,$dd,$57,$dd @ref19: db $57,$dd,$57,$dd @ref20: db $9e,$23,$95,$17,$95,$23,$95,$17,$95,$23,$95,$17,$95,$23,$95,$17,$95 @ref21: db $21,$95,$a0,$17,$89,$21,$89,$17,$89,$17,$89,$21,$89,$17,$89,$17,$89,$21,$89,$17,$89,$17,$89,$21,$89,$17,$89,$17,$89,$21,$89 db $ff,$10 dw @ref20 db $ff,$1e dw @ref21 db $ff,$10 dw @ref20 db $ff,$1e dw @ref21 db $ff,$10 dw @ref20 db $ff,$1e dw @ref21 @ref22: db $64,<(@env9),>(@env9),$b8,$24,$f7,$c5 @ref23: db $64,<(@env21),>(@env21),$22,$f7,$c5 @ref24: db $64,<(@env9),>(@env9),$24,$f7,$c5 db $ff,$03 dw @ref23 @ref25: db $64,<(@env9),>(@env9),$21,$f7,$c5 @ref26: db $64,<(@env21),>(@env21),$1f,$f7,$c5 db $ff,$03 dw @ref25 db $ff,$03 dw @ref26 @ref27: db $64,<(@env1),>(@env1),$66,$a8,$17,$85,$19,$85,$1b,$85,$1e,$85,$23,$85,$25,$85,$27,$85,$2a,$85,$2f,$85,$31,$85,$33,$85,$36,$85,$33,$85,$31,$85,$2f,$85,$2a,$85,$27,$85,$25,$85,$23,$85,$1e,$85,$1b,$85,$19,$85,$17,$85,$12,$85 @ref28: db $19,$85,$1b,$85,$1d,$85,$20,$85,$25,$85,$27,$85,$29,$85,$2c,$85,$31,$85,$33,$85,$35,$85,$38,$85,$35,$85,$33,$85,$31,$85,$2c,$85,$29,$85,$27,$85,$25,$85,$20,$85,$1d,$85,$1b,$85,$19,$85,$14,$85 @ref29: db $17,$85,$19,$85,$1b,$85,$1e,$85,$23,$85,$25,$85,$27,$85,$2a,$85,$2f,$85,$31,$85,$33,$85,$36,$85,$33,$85,$31,$85,$2f,$85,$2a,$85,$27,$85,$25,$85,$23,$85,$1e,$85,$1b,$85,$19,$85,$17,$85,$12,$85 db $ff,$30 dw @ref28 db $ff,$30 dw @ref29 db $ff,$30 dw @ref29 @ref30: db $17,$85,$1b,$85,$1d,$85,$20,$85,$23,$85,$27,$85,$29,$85,$2c,$85,$2f,$85,$33,$85,$35,$85,$38,$85,$35,$85,$33,$85,$2f,$85,$2c,$85,$29,$85,$27,$85,$23,$85,$20,$85,$1d,$85,$1b,$85,$17,$85,$14,$85 db $ff,$30 dw @ref30 db $ff,$20 dw @ref0 db $ff,$1c dw @ref1 db $fd dw @song0ch0loop @song0ch1: @ref31: db $7f,$a6,$61,$fe,$2f,$44,$f7,$c5 @ref32: db $f7,$af @song0ch1loop: @ref33: db $74,$98,$30,$31,$9b,$61,$0f,$31,$2c,$91,$72,$61,$0f,$31,$2c,$91,$74,$32,$33,$9b,$61,$13,$33,$2c,$91,$72,$61,$13,$33,$2c,$91,$74,$34,$35,$36,$89,$63,<(@env62),>(@env62),$9d,$63,<(@env31),>(@env31),$65,$81 @ref34: db $37,$38,$8d,$63,<(@env62),>(@env62),$f7,$8b,$63,<(@env31),>(@env31),$65,$81,$61,$0c,$38,$32,$91,$72,$61,$0c,$38,$32,$91 @ref35: db $74,$9a,$3c,$3d,$9b,$61,$0f,$3d,$34,$91,$72,$61,$0f,$3d,$34,$91,$74,$3e,$3f,$9b,$61,$16,$3f,$32,$91,$72,$61,$16,$3f,$32,$91,$74,$40,$41,$42,$89,$63,<(@env62),>(@env62),$9d,$63,<(@env31),>(@env31),$65,$81 @ref36: db $43,$44,$8d,$63,<(@env62),>(@env62),$f7,$8b,$63,<(@env31),>(@env31),$65,$81,$61,$0d,$44,$39,$91,$72,$61,$0d,$44,$39,$91 @ref37: db $74,$98,$43,$44,$9b,$61,$0f,$44,$38,$91,$72,$61,$0f,$44,$38,$91,$74,$45,$46,$9b,$61,$14,$46,$36,$91,$72,$61,$14,$46,$36,$91,$74,$47,$48,$49,$87,$63,<(@env62),>(@env62),$9f,$63,<(@env31),>(@env31),$65,$81 @ref38: db $4a,$4b,$8d,$63,<(@env62),>(@env62),$f7,$8b,$63,<(@env31),>(@env31),$65,$81,$61,$0c,$4b,$3d,$91,$72,$61,$0c,$4b,$3d,$91 @ref39: db $00,$95 @ref40: db $74,$46,$47,$97,$63,<(@env62),>(@env62),$f7,$81,$63,<(@env31),>(@env31),$65,$81,$61,$0c,$47,$3b,$91,$72,$61,$0c,$47,$3b,$91 @ref41: db $74,$48,$49,$8d,$63,<(@env62),>(@env62),$f7,$89,$63,<(@env31),>(@env31),$65,$81,$61,$0b,$49,$3c,$93,$72,$61,$0c,$49,$3c,$91 @ref42: db $7f,$ae,$2e,$85,$35,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$33,$85,$37,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$39,$85,$2e,$81,$35,$85,$39,$81,$3c,$85,$35,$81,$35,$85,$3c,$81 @ref43: db $2e,$85,$35,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$33,$85,$37,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$39,$85,$2e,$81,$35,$85,$39,$81,$3c,$85,$35,$81,$35,$85,$3c,$81 @ref44: db $7f,$2e,$85,$35,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$33,$85,$37,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$33,$85,$2e,$81,$37,$85,$33,$81,$2e,$85,$37,$81,$39,$85,$2e,$81,$35,$85,$39,$81,$3c,$85,$35,$81,$35,$85,$3c,$81 db $ff,$40 dw @ref43 @ref45: db $70,$00,$95,$ac,$30,$83,$71,$85,$35,$89,$37,$89,$32,$72,$89,$33,$89,$35,$87,$73,$81,$2e,$89,$33,$89,$30,$83,$74,$85,$35,$89,$37,$89,$32,$75,$89,$33,$89,$35,$87,$76,$81 @ref46: db $70,$00,$95,$3c,$83,$71,$85,$41,$89,$43,$89,$3e,$72,$89,$3f,$89,$41,$87,$73,$81,$3a,$89,$3f,$89,$3c,$83,$74,$85,$41,$89,$43,$89,$3e,$75,$89,$3f,$89,$41,$87,$76,$81 @ref47: db $7f,$b0,$3e,$89,$3e,$89,$3e,$89,$3e,$9d,$00,$81,$3e,$89,$3f,$89,$41,$91,$00,$81,$3e,$89,$3f,$91,$00,$81,$3c,$89,$3e,$91,$00,$81 @ref48: db $3a,$89,$3a,$89,$3a,$89,$3c,$89,$37,$89,$3c,$89,$3e,$89,$3f,$89,$43,$a9,$00,$81,$41,$a9,$00,$81 @ref49: db $b2,$3e,$89,$3e,$89,$3e,$89,$3e,$9d,$00,$81,$3e,$89,$3f,$89,$41,$91,$00,$81,$3e,$89,$3f,$91,$00,$81,$3c,$89,$3e,$91,$00,$81 db $ff,$18 dw @ref48 @ref50: db $b6,$43,$c1,$00,$81,$41,$89,$3f,$89,$3e,$c1,$00,$81,$3f,$89,$41,$89 @ref51: db $3e,$c1,$00,$81,$3f,$89,$41,$89,$3c,$62,$3d,$81,$3e,$8b,$00,$81,$3d,$62,$3c,$62,$3b,$8d,$00,$81,$3a,$62,$39,$62,$38,$62,$37,$8b,$00,$81,$38,$62,$39,$62,$3a,$62,$3b,$62,$3c,$62,$3d,$62,$3e,$85,$00,$81 @ref52: db $3f,$c1,$00,$81,$3e,$89,$3c,$89,$3e,$c1,$00,$81,$3c,$89,$37,$89 @ref53: db $3a,$d9,$00,$81,$3c,$a9,$00,$81,$3e,$a9,$00,$81 @ref54: db $b4,$2b,$c1,$00,$81,$29,$89,$27,$89,$26,$c1,$00,$81,$27,$89,$29,$89 @ref55: db $26,$c1,$00,$81,$27,$89,$29,$89,$24,$62,$25,$81,$26,$8b,$00,$81,$25,$62,$24,$62,$23,$8d,$00,$81,$22,$62,$21,$62,$20,$62,$1f,$8b,$00,$81,$20,$62,$21,$62,$22,$62,$23,$62,$24,$62,$25,$62,$26,$85,$00,$81 @ref56: db $27,$c1,$00,$81,$26,$89,$24,$89,$26,$c1,$00,$81,$24,$89,$1f,$89 @ref57: db $22,$d9,$00,$81,$24,$a9,$00,$81,$26,$a9,$00,$81 @ref58: db $b0,$37,$c1,$00,$81,$35,$89,$33,$89,$32,$c1,$00,$81,$33,$89,$35,$89 @ref59: db $32,$c1,$00,$81,$33,$89,$35,$89,$30,$62,$31,$81,$32,$8b,$00,$81,$31,$62,$30,$62,$2f,$8d,$00,$81,$2e,$62,$2d,$62,$2c,$62,$2b,$8b,$00,$81,$2c,$62,$2d,$62,$2e,$62,$2f,$62,$30,$62,$31,$62,$32,$85,$00,$81 @ref60: db $33,$c1,$00,$81,$32,$89,$30,$89,$32,$c1,$00,$81,$30,$89,$2b,$89 @ref61: db $2e,$d9,$00,$81,$30,$a9,$00,$81,$32,$a9,$00,$81 @ref62: db $73,$68,$00,$98,$37,$dd,$62,$61,$fe,$37,$60,$dd @ref63: db $f7,$c5,$00 @ref64: db $7f,$a2,$60,$dd,$60,$dd @ref65: db $60,$dd,$60,$dd @ref66: db $60,$f7,$c5 @ref67: db $60,$dd,$60,$dd @ref68: db $9e,$28,$95,$1c,$95,$28,$95,$1c,$95,$28,$95,$1c,$95,$28,$95,$1c,$95 @ref69: db $26,$95,$a0,$1c,$89,$26,$89,$1c,$89,$1c,$89,$26,$89,$1c,$89,$1c,$89,$26,$89,$1c,$89,$1c,$89,$26,$89,$1c,$89,$1c,$89,$26,$89 db $ff,$10 dw @ref68 db $ff,$1e dw @ref69 @ref70: db $9e,$2a,$95,$1e,$95,$2a,$95,$1e,$95,$2a,$95,$1e,$95,$2a,$95,$1e,$95 @ref71: db $28,$95,$a0,$1e,$89,$28,$89,$1e,$89,$1e,$89,$28,$89,$1e,$89,$1e,$89,$28,$89,$1e,$89,$1e,$89,$28,$89,$1e,$89,$1e,$89,$28,$89 db $ff,$10 dw @ref70 db $ff,$1e dw @ref71 @ref72: db $bc,$30,$89,$2d,$2b,$81,$f9,$81,$00,$2e,$30,$81,$f9,$81,$00,$33,$34,$81,$f9,$81,$00,$37,$89,$34,$31,$30,$f9,$81,$00,$33,$34,$81,$f9,$81,$00,$37,$83,$f9,$81,$00,$3a,$3c,$87,$39,$37,$81,$f9,$81,$00,$34,$83,$f9,$81,$00,$35,$89,$32,$83,$f9,$81,$00,$34,$83,$f9,$81,$00,$31,$30,$87,$2d,$2b,$81,$f9,$81,$00 @ref73: db $2e,$95,$31,$32,$81,$f9,$81,$00,$30,$a1,$32,$a1,$34,$a1,$35,$95,$38,$39,$8d,$f9,$81,$00 @ref74: db $36,$33,$62,$30,$f9,$81,$00,$2d,$2b,$81,$f9,$81,$00,$2e,$30,$81,$f9,$81,$00,$33,$34,$81,$f9,$81,$00,$37,$89,$34,$31,$30,$f9,$81,$00,$33,$34,$81,$f9,$81,$00,$37,$83,$f9,$81,$00,$3a,$3c,$87,$39,$37,$81,$f9,$81,$00,$34,$83,$f9,$81,$00,$35,$89,$32,$83,$f9,$81,$00,$34,$83,$f9,$81,$00,$31,$30,$87,$2d,$2b,$81,$f9,$81,$00 db $ff,$16 dw @ref73 @ref75: db $74,$98,$39,$36,$33,$31,$97,$61,$0f,$31,$2c,$91,$72,$61,$0f,$31,$2c,$91,$74,$31,$32,$9b,$61,$0e,$32,$2d,$91,$72,$61,$0e,$32,$2d,$91,$74,$32,$34,$9b,$61,$0f,$34,$2e,$8d @ref76: db $83,$72,$61,$0f,$34,$2e,$91,$74,$34,$36,$9b,$61,$0e,$36,$30,$91,$72,$61,$0e,$36,$30,$91,$74,$36,$37,$9b,$61,$10,$37,$31,$8d,$37,$39,$9b,$61,$0e,$39,$33,$8d @ref77: db $7f,$ba,$38,$95,$36,$34,$8d,$f9,$81,$00,$32,$31,$8d,$f9,$81,$00,$33,$35,$36,$91,$34,$95,$32,$31,$8d,$f9,$81,$00,$2f,$2d,$8d,$f9,$81,$00,$2f,$31,$8d,$f9,$81,$00 @ref78: db $32,$95,$30,$2f,$93,$2d,$2b,$8d,$f9,$81,$00,$2d,$2f,$31,$33,$34,$8d,$32,$31,$93,$2f,$2d,$8d,$f9,$81,$00,$2f,$31,$33,$35,$36,$89,$f9,$81,$34,$32,$8f,$f9,$81 @ref79: db $34,$36,$d7,$f9,$81,$38,$3a,$3b,$d5,$f9,$81 @ref80: db $3d,$a9,$f9,$81,$3b,$39,$38,$a5,$f9,$81,$36,$a9,$f9,$81,$35,$a9,$f9,$81 @ref81: db $36,$a9,$f9,$81,$34,$33,$a7,$f9,$81,$35,$37,$39,$3b,$a3,$f9,$81,$3d,$3f,$a7,$f9,$62,$3e @ref82: db $3d,$d9,$f9,$81,$3f,$41,$d7,$f9,$81 @ref83: db $74,$98,$36,$9d,$61,$0e,$36,$30,$91,$72,$61,$0e,$36,$30,$91,$74,$35,$9d,$61,$0e,$35,$2f,$91,$72,$61,$0e,$35,$2f,$91,$74,$31,$9d,$61,$0e,$31,$2d,$8d @ref84: db $33,$dd,$35,$ad,$36,$ad @ref85: db $38,$dd,$3a,$3c,$3e,$40,$41,$d5 @ref86: db $81,$43,$44,$87,$42,$41,$87,$3f,$89,$3d,$3b,$87,$3a,$89,$38,$89,$36,$35,$87,$33,$89,$31,$2f,$87,$2e,$89,$2c,$89,$2a,$29,$87,$27,$89,$25,$23,$87,$22,$89,$20,$87 db $ff,$03 dw @ref31 @ref87: db $f7,$af db $fd dw @song0ch1loop @song0ch2: @ref88: db $f7,$c7 @ref89: db $f7,$c0,$2e,$89,$2e,$89,$2e,$95 @song0ch2loop: @ref90: db $be,$25,$89,$96,$19,$b9,$be,$25,$89,$96,$1b,$89,$00,$ad,$be,$25,$89,$96,$1e,$a1 @ref91: db $be,$25,$89,$96,$20,$89,$1e,$89,$20,$89,$be,$25,$89,$96,$1e,$89,$c0,$2e,$81,$96,$20,$a9,$be,$25,$89,$96,$1e,$89,$c0,$2e,$81,$96,$20,$85,$c0,$2e,$81,$96,$20,$85,$c0,$2e,$81,$96,$20,$91 db $ff,$0e dw @ref90 db $ff,$20 dw @ref91 db $ff,$0e dw @ref90 db $ff,$20 dw @ref91 @ref92: db $be,$25,$89,$96,$20,$89 @ref93: db $be,$25,$89,$96,$1c,$89,$1a,$1b,$1c,$91,$c0,$2f,$81,$96,$23,$91,$1a,$1b,$1c,$91,$be,$25,$89,$96,$1c,$89,$1b,$1c,$87,$be,$25,$89,$96,$1c,$89,$1b,$1c,$87,$be,$25,$89,$96,$1b,$89 @ref94: db $be,$25,$89,$96,$19,$89,$17,$18,$19,$91,$c0,$2c,$81,$96,$20,$91,$17,$18,$19,$91,$be,$25,$89,$96,$19,$89,$18,$19,$87,$be,$25,$89,$96,$19,$89,$18,$19,$87,$be,$25,$89,$96,$1b,$89 @ref95: db $be,$25,$89,$96,$18,$85,$00,$81,$18,$91,$00,$81,$c0,$2e,$81,$96,$24,$85,$18,$85,$00,$81,$18,$89,$be,$25,$89,$96,$1d,$91,$00,$81,$be,$25,$89,$96,$1b,$89,$c0,$2e,$81,$96,$1a,$91,$1b,$89,$c0,$2e,$81,$96,$1b,$85 @ref96: db $be,$25,$89,$96,$18,$85,$00,$81,$18,$91,$00,$81,$c0,$2e,$81,$96,$24,$85,$18,$85,$00,$81,$18,$89,$be,$25,$89,$96,$1d,$91,$00,$81,$be,$25,$89,$96,$1b,$89,$c0,$2e,$81,$96,$22,$85,$c0,$2e,$81,$96,$22,$85,$c0,$2e,$81,$96,$24,$85,$c0,$2e,$81,$96,$24,$85 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 db $ff,$28 dw @ref95 db $ff,$2e dw @ref96 @ref97: db $be,$25,$f7,$c5 @ref98: db $f7,$c7 @ref99: db $25,$89,$00,$a1,$c0,$2e,$a1,$be,$25,$a1,$25,$95,$c0,$2e,$a1,$2e,$89 @ref100: db $be,$25,$ad,$c0,$2e,$a1,$be,$25,$a1,$25,$95,$c0,$2e,$89,$2e,$89,$2e,$89,$2e,$89 @ref101: db $be,$25,$ad,$c0,$2e,$a1,$be,$25,$a1,$25,$95,$c0,$2e,$a1,$2e,$89 db $ff,$10 dw @ref100 db $ff,$0c dw @ref101 db $ff,$10 dw @ref100 db $ff,$0c dw @ref101 db $ff,$10 dw @ref100 db $ff,$0c dw @ref101 db $ff,$10 dw @ref100 @ref102: db $be,$25,$89,$96,$18,$a1,$c0,$2e,$81,$96,$18,$9d,$be,$25,$89,$96,$18,$95,$be,$25,$89,$96,$18,$89,$c0,$2e,$81,$96,$22,$85,$24,$89,$1f,$89,$c0,$2e,$81,$96,$1f,$85 @ref103: db $be,$25,$89,$96,$18,$a1,$c0,$2e,$81,$96,$18,$9d,$be,$25,$89,$96,$18,$95,$be,$25,$89,$96,$18,$89,$c0,$2e,$81,$96,$24,$85,$c0,$2e,$81,$96,$24,$85,$c0,$2e,$81,$96,$24,$85,$c0,$2e,$81,$96,$24,$85 db $ff,$1c dw @ref102 db $ff,$20 dw @ref103 @ref104: db $be,$25,$89,$96,$15,$a1,$c0,$2e,$81,$96,$15,$9d,$be,$25,$89,$96,$15,$95,$be,$25,$89,$96,$15,$89,$c0,$2e,$81,$96,$1f,$85,$21,$89,$1c,$89,$c0,$2e,$81,$96,$1c,$85 @ref105: db $be,$25,$89,$96,$15,$a1,$c0,$2e,$81,$96,$15,$9d,$be,$25,$89,$96,$15,$95,$be,$25,$89,$96,$15,$89,$c0,$2e,$81,$96,$21,$85,$c0,$2e,$81,$96,$21,$85,$c0,$2e,$81,$96,$21,$85,$c0,$2e,$81,$96,$21,$85 db $ff,$1c dw @ref104 db $ff,$20 dw @ref105 @ref106: db $be,$25,$89,$96,$1e,$a1,$c0,$2e,$81,$96,$1e,$9d,$be,$25,$89,$96,$1e,$95,$be,$25,$89,$96,$1e,$89,$c0,$2e,$81,$96,$28,$85,$2a,$89,$25,$89,$c0,$2e,$81,$96,$25,$85 @ref107: db $be,$25,$89,$96,$1e,$a1,$c0,$2e,$81,$96,$1e,$9d,$be,$25,$89,$96,$1e,$95,$be,$25,$89,$96,$1e,$89,$c0,$2e,$81,$96,$2a,$85,$c0,$2e,$81,$96,$2a,$85,$c0,$2e,$81,$96,$2a,$85,$c0,$2e,$81,$96,$2a,$85 db $ff,$1c dw @ref106 db $ff,$20 dw @ref107 db $ff,$1c dw @ref106 db $ff,$20 dw @ref107 @ref108: db $be,$25,$89,$96,$1d,$a1,$c0,$2e,$81,$96,$1d,$9d,$be,$25,$89,$96,$1d,$95,$be,$25,$89,$96,$1d,$89,$c0,$2e,$81,$96,$27,$85,$29,$89,$24,$89,$c0,$2e,$81,$96,$24,$85 @ref109: db $be,$25,$89,$96,$1d,$a1,$c0,$2e,$81,$96,$1d,$9d,$be,$25,$89,$96,$1d,$95,$be,$25,$89,$96,$1d,$89,$c0,$2e,$81,$96,$29,$85,$c0,$2e,$81,$96,$29,$85,$c0,$2e,$81,$96,$29,$85,$c0,$2e,$81,$96,$29,$85 @ref110: db $be,$25,$89,$96,$1b,$89,$00,$f7,$ad db $ff,$07 dw @ref89 db $fd dw @song0ch2loop @song0ch3: @ref111: db $73,$92,$2c,$ab,$72,$99,$71,$99,$00,$db @ref112: db $71,$94,$23,$89,$24,$83,$72,$85,$25,$89,$26,$73,$89,$27,$87,$74,$81,$28,$89,$29,$83,$75,$85,$2a,$89,$2b,$89,$2c,$87,$77,$81,$7f,$90,$26,$89,$26,$89,$26,$95 @song0ch3loop: @ref113: db $88,$25,$c1,$f9,$81,$25,$c1,$f9,$81,$25,$a9,$f9,$81 @ref114: db $25,$95,$84,$2b,$89,$2b,$89,$82,$27,$89,$84,$2b,$89,$90,$26,$95,$84,$2b,$89,$2b,$89,$82,$27,$89,$84,$2b,$89,$90,$26,$89,$26,$89,$26,$95 db $ff,$0c dw @ref113 db $ff,$1a dw @ref114 db $ff,$0c dw @ref113 db $ff,$1a dw @ref114 @ref115: db $8a,$27,$95 @ref116: db $8c,$29,$95,$8e,$2b,$95,$90,$26,$95,$8e,$2b,$95,$8c,$29,$a1,$29,$a1,$29,$95 @ref117: db $29,$95,$8e,$2b,$95,$90,$26,$95,$8e,$2b,$95,$8c,$29,$a1,$29,$a1,$29,$95 @ref118: db $7f,$80,$27,$95,$86,$2b,$95,$90,$26,$95,$86,$2b,$89,$82,$27,$89,$86,$2b,$89,$84,$2b,$89,$82,$27,$89,$84,$2b,$89,$90,$26,$95,$84,$2b,$89,$90,$26,$89 @ref119: db $80,$27,$95,$86,$2b,$95,$90,$26,$95,$86,$2b,$89,$82,$27,$89,$86,$2b,$89,$84,$2b,$89,$82,$27,$89,$84,$2b,$89,$90,$26,$89,$26,$89,$26,$89,$26,$89 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 @ref120: db $75,$96,$27,$74,$22,$9b,$73,$9f,$72,$9f,$71,$9f,$00,$bd @ref121: db $f7,$8b,$71,$22,$83,$23,$72,$83,$24,$83,$73,$25,$83,$26,$81,$74,$81,$27,$83,$28,$75,$83,$29,$83,$76,$2a,$83,$2b,$81,$77,$81 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$18 dw @ref118 db $ff,$1a dw @ref119 db $ff,$06 dw @ref111 db $ff,$1e dw @ref112 db $fd dw @song0ch3loop @song0ch4: @ref122: db $f7,$c7 @ref123: db $f7,$af @song0ch4loop: @ref124: db $f7,$c7 @ref125: db $f7,$c7 @ref126: db $f7,$c7 @ref127: db $f7,$c7 @ref128: db $f7,$c7 @ref129: db $f7,$c7 @ref130: db $97 @ref131: db $f7,$c7 @ref132: db $f7,$c7 @ref133: db $f7,$c7 @ref134: db $f7,$c7 @ref135: db $f7,$c7 @ref136: db $f7,$c7 @ref137: db $f7,$c7 @ref138: db $f7,$c7 @ref139: db $f7,$c7 @ref140: db $f7,$c7 @ref141: db $f7,$c7 @ref142: db $f7,$c7 @ref143: db $f7,$c7 @ref144: db $f7,$c7 @ref145: db $f7,$c7 @ref146: db $f7,$c7 @ref147: db $f7,$c7 @ref148: db $f7,$c7 @ref149: db $f7,$c7 @ref150: db $f7,$c7 @ref151: db $f7,$c7 @ref152: db $f7,$c7 @ref153: db $f7,$c7 @ref154: db $f7,$c7 @ref155: db $f7,$c7 @ref156: db $f7,$c7 @ref157: db $f7,$c7 @ref158: db $f7,$c7 @ref159: db $f7,$c7 @ref160: db $f7,$c7 @ref161: db $f7,$c7 @ref162: db $f7,$c7 @ref163: db $f7,$c7 @ref164: db $f7,$c7 @ref165: db $f7,$c7 @ref166: db $f7,$c7 @ref167: db $f7,$c7 @ref168: db $f7,$c7 @ref169: db $f7,$c7 @ref170: db $f7,$c7 @ref171: db $f7,$c7 @ref172: db $f7,$c7 @ref173: db $f7,$c7 @ref174: db $f7,$c7 @ref175: db $f7,$c7 @ref176: db $f7,$c7 @ref177: db $f7,$c7 @ref178: db $f7,$c7 @ref179: db $f7,$c7 @ref180: db $f7,$c7 @ref181: db $f7,$c7 @ref182: db $f7,$c7 @ref183: db $f7,$c7 @ref184: db $f7,$c7 @ref185: db $f7,$c7 @ref186: db $f7,$af db $fd dw @song0ch4loop ",16149,True,4012.064984660348,median "/**************************************************************************************************************************** ConfigOnSwitchFS_MQTT_Ptr.ino For ESP8266 / ESP32 boards ESP_WiFiManager is a library for the ESP8266/ESP32 platform (https://github.com/esp8266/Arduino) to enable easy configuration and reconfiguration of WiFi credentials using a Captive Portal. Inspired by: http://www.esp8266.com/viewtopic.php?f=29&t=2520 https://github.com/chriscook8/esp-arduino-apboot https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortalAdvanced/ Modified from Tzapu https://github.com/tzapu/WiFiManager and from Ken Taylor https://github.com/kentaylor Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager Licensed under MIT license Version: 1.5.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 07/10/2019 Initial coding 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32 1.0.2 K Hoang 19/12/2019 Fix bug thatkeeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL. 1.0.3 K Hoang 05/01/2020 Option not displaying AvailablePages in Info page. Enhance README.md. Modify examples 1.0.4 K Hoang 07/01/2020 Add RFC952 setHostname feature. 1.0.5 K Hoang 15/01/2020 Add configurable DNS feature. Thanks to @Amorphous of https://community.blynk.cc 1.0.6 K Hoang 03/02/2020 Add support for ArduinoJson version 6.0.0+ ( tested with v6.14.1 ) 1.0.7 K Hoang 13/04/2020 Reduce start time, fix SPIFFS bug in examples, update README.md 1.0.8 K Hoang 10/06/2020 Fix STAstaticIP issue. Restructure code. Add LittleFS support for ESP8266 core 2.7.1+ 1.0.9 K Hoang 29/07/2020 Fix ESP32 STAstaticIP bug. Permit changing from DHCP <-> static IP using Config Portal. Add, enhance examples (fix MDNS for ESP32) 1.0.10 K Hoang 08/08/2020 Add more features to Config Portal. Use random WiFi AP channel to avoid conflict. 1.0.11 K Hoang 17/08/2020 Add CORS feature. Fix bug in softAP, autoConnect, resetSettings. 1.1.0 K Hoang 28/08/2020 Add MultiWiFi feature to autoconnect to best WiFi at runtime 1.1.1 K Hoang 30/08/2020 Add setCORSHeader function to allow flexible CORS. Fix typo and minor improvement. 1.1.2 K Hoang 17/08/2020 Fix bug. Add example. 1.2.0 K Hoang 09/10/2020 Restore cpp code besides Impl.h code to use if linker error. Fix bug. 1.3.0 K Hoang 04/12/2020 Add LittleFS support to ESP32 using LITTLEFS Library 1.4.1 K Hoang 22/12/2020 Fix staticIP not saved. Add functions. Add complex examples. Sync with ESPAsync_WiFiManager 1.4.2 K Hoang 14/01/2021 Fix examples' bug not using saved WiFi Credentials after losing all WiFi connections. 1.4.3 K Hoang 23/01/2021 Fix examples' bug not saving Static IP in certain cases. 1.5.0 K Hoang 12/02/2021 Add support to new ESP32-S2 1.5.1 K Hoang 26/03/2021 Fix compiler error if setting Compiler Warnings to All. Retest with esp32 core v1.0.6 *****************************************************************************************************************************/ /**************************************************************************************************************************** This example will open a configuration portal when no WiFi configuration has been previously entered or when a button is pushed. It is the easiest scenario for configuration but requires a pin and a button on the ESP8266/ESP32 device. The Flash button is convenient for this on NodeMCU devices. Also in this example a password is required to connect to the configuration portal network. This is inconvenient but means that only those who know the password or those already connected to the target WiFi network can access the configuration portal and the WiFi network credentials will be sent from the browser over an encrypted connection and can not be read by observers. The Credentials, being input via Config Portal, will then be saved into LittleFS / SPIFFS file, and be used to connect to Adafruit MQTT Server at ""io.adafruit.com"" and publish a Temperature Topic Based on original sketch posted by user ""wackoo"" on https://forum.arduino.cc/index.php?topic=692108 *****************************************************************************************************************************/ #if !( defined(ESP8266) || defined(ESP32) ) #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif #define ESP_WIFIMANAGER_VERSION_MIN_TARGET ""ESP_WiFiManager v1.5.1"" // Use from 0 to 4. Higher number, more debugging messages and memory usage. #define _WIFIMGR_LOGLEVEL_ 3 #include // for button #include // for button #include // Now support ArduinoJson 6.0.0+ ( tested with v6.15.2 to v6.16.1 ) #include // get it from https://arduinojson.org/ or install via Arduino library manager //For ESP32, To use ESP32 Dev Module, QIO, Flash 4MB/80MHz, Upload 921600 //Ported to ESP32 #ifdef ESP32 #include #include #include // From v1.1.0 #include WiFiMulti wifiMulti; // LittleFS has higher priority than SPIFFS #define USE_LITTLEFS true #define USE_SPIFFS false #if USE_LITTLEFS // Use LittleFS #include ""FS.h"" // The library will be depreciated after being merged to future major Arduino esp32 core release 2.x // At that time, just remove this library inclusion #include // https://github.com/lorol/LITTLEFS FS* filesystem = &LITTLEFS; #define FileFS LITTLEFS #define FS_Name ""LittleFS"" #elif USE_SPIFFS #include FS* filesystem = &SPIFFS; #define FileFS SPIFFS #define FS_Name ""SPIFFS"" #else // Use FFat #include FS* filesystem = &FFat; #define FileFS FFat #define FS_Name ""FFat"" #endif ////// #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) #define LED_BUILTIN 2 #define LED_ON HIGH #define LED_OFF LOW #else #include //https://github.com/esp8266/Arduino //needed for library #include #include // From v1.1.0 #include ESP8266WiFiMulti wifiMulti; #define USE_LITTLEFS true #if USE_LITTLEFS #include FS* filesystem = &LittleFS; #define FileFS LittleFS #define FS_Name ""LittleFS"" #else FS* filesystem = &SPIFFS; #define FileFS SPIFFS #define FS_Name ""SPIFFS"" #endif ////// #define ESP_getChipId() (ESP.getChipId()) #define LED_ON LOW #define LED_OFF HIGH #endif #include ""Adafruit_MQTT.h"" //https://github.com/adafruit/Adafruit_MQTT_Library #include ""Adafruit_MQTT_Client.h"" //https://github.com/adafruit/Adafruit_MQTT_Library #if ESP32 //See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED #define PIN_LED 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED #define PIN_D0 0 // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32 #define PIN_D1 1 // Pin D1 mapped to pin GPIO1/TX0 of ESP32 #define PIN_D2 2 // Pin D2 mapped to pin GPIO2/ADC12/TOUCH2 of ESP32 #define PIN_D3 3 // Pin D3 mapped to pin GPIO3/RX0 of ESP32 #define PIN_D4 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 #define PIN_D5 5 // Pin D5 mapped to pin GPIO5/SPISS/VSPI_SS of ESP32 #define PIN_D6 6 // Pin D6 mapped to pin GPIO6/FLASH_SCK of ESP32 #define PIN_D7 7 // Pin D7 mapped to pin GPIO7/FLASH_D0 of ESP32 #define PIN_D8 8 // Pin D8 mapped to pin GPIO8/FLASH_D1 of ESP32 #define PIN_D9 9 // Pin D9 mapped to pin GPIO9/FLASH_D2 of ESP32 #define PIN_D10 10 // Pin D10 mapped to pin GPIO10/FLASH_D3 of ESP32 #define PIN_D11 11 // Pin D11 mapped to pin GPIO11/FLASH_CMD of ESP32 #define PIN_D12 12 // Pin D12 mapped to pin GPIO12/HSPI_MISO/ADC15/TOUCH5/TDI of ESP32 #define PIN_D13 13 // Pin D13 mapped to pin GPIO13/HSPI_MOSI/ADC14/TOUCH4/TCK of ESP32 #define PIN_D14 14 // Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 #define PIN_D15 15 // Pin D15 mapped to pin GPIO15/HSPI_SS/ADC13/TOUCH3/TDO of ESP32 #define PIN_D16 16 // Pin D16 mapped to pin GPIO16/TX2 of ESP32 #define PIN_D17 17 // Pin D17 mapped to pin GPIO17/RX2 of ESP32 #define PIN_D18 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 #define PIN_D19 19 // Pin D19 mapped to pin GPIO19/VSPI_MISO of ESP32 #define PIN_D21 21 // Pin D21 mapped to pin GPIO21/SDA of ESP32 #define PIN_D22 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32 #define PIN_D23 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32 #define PIN_D24 24 // Pin D24 mapped to pin GPIO24 of ESP32 #define PIN_D25 25 // Pin D25 mapped to pin GPIO25/ADC18/DAC1 of ESP32 #define PIN_D26 26 // Pin D26 mapped to pin GPIO26/ADC19/DAC2 of ESP32 #define PIN_D27 27 // Pin D27 mapped to pin GPIO27/ADC17/TOUCH7 of ESP32 #define PIN_D32 32 // Pin D32 mapped to pin GPIO32/ADC4/TOUCH9 of ESP32 #define PIN_D33 33 // Pin D33 mapped to pin GPIO33/ADC5/TOUCH8 of ESP32 #define PIN_D34 34 // Pin D34 mapped to pin GPIO34/ADC6 of ESP32 //Only GPIO pin < 34 can be used as output. Pins >= 34 can be only inputs //See .../cores/esp32/esp32-hal-gpio.h/c //#define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg) //#define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg) //#define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1) //#define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1) //#define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1) //#define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1) #define PIN_D35 35 // Pin D35 mapped to pin GPIO35/ADC7 of ESP32 #define PIN_D36 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 #define PIN_D39 39 // Pin D39 mapped to pin GPIO39/ADC3/SVN of ESP32 #define PIN_RX0 3 // Pin RX0 mapped to pin GPIO3/RX0 of ESP32 #define PIN_TX0 1 // Pin TX0 mapped to pin GPIO1/TX0 of ESP32 #define PIN_SCL 22 // Pin SCL mapped to pin GPIO22/SCL of ESP32 #define PIN_SDA 21 // Pin SDA mapped to pin GPIO21/SDA of ESP32 #else //PIN_D0 can't be used for PWM/I2C #define PIN_D0 16 // Pin D0 mapped to pin GPIO16/USER/WAKE of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON #define PIN_D1 5 // Pin D1 mapped to pin GPIO5 of ESP8266 #define PIN_D2 4 // Pin D2 mapped to pin GPIO4 of ESP8266 #define PIN_D3 0 // Pin D3 mapped to pin GPIO0/FLASH of ESP8266 #define PIN_D4 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266 #define PIN_LED 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED #define PIN_D5 14 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266 #define PIN_D6 12 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266 #define PIN_D7 13 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266 #define PIN_D8 15 // Pin D8 mapped to pin GPIO15/TXD2/HCS of ESP8266 //Don't use pins GPIO6 to GPIO11 as already connected to flash, etc. Use them can crash the program //GPIO9(D11/SD2) and GPIO11 can be used only if flash in DIO mode ( not the default QIO mode) #define PIN_D11 9 // Pin D11/SD2 mapped to pin GPIO9/SDD2 of ESP8266 #define PIN_D12 10 // Pin D12/SD3 mapped to pin GPIO10/SDD3 of ESP8266 #define PIN_SD2 9 // Pin SD2 mapped to pin GPIO9/SDD2 of ESP8266 #define PIN_SD3 10 // Pin SD3 mapped to pin GPIO10/SDD3 of ESP8266 #define PIN_D9 3 // Pin D9 /RX mapped to pin GPIO3/RXD0 of ESP8266 #define PIN_D10 1 // Pin D10/TX mapped to pin GPIO1/TXD0 of ESP8266 #define PIN_RX 3 // Pin RX mapped to pin GPIO3/RXD0 of ESP8266 #define PIN_TX 1 // Pin RX mapped to pin GPIO1/TXD0 of ESP8266 #define LED_PIN 16 // Pin D0 mapped to pin GPIO16 of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON #endif //ESP32 #if ESP32 const int BUTTON_PIN = PIN_D27; const int RED_LED = PIN_D26; const int BLUE_LED = PIN_D25; #else const int BUTTON_PIN = PIN_D1; const int RED_LED = PIN_D2; const int BLUE_LED = PIN_D5; #endif //ESP32 uint32_t timer = millis(); const char* CONFIG_FILE = ""/ConfigMQTT.json""; // Indicates whether ESP has WiFi credentials saved from previous session bool initialConfig = true; //default false // Default configuration values for Adafruit IO MQTT // This actually works #define AIO_SERVER ""io.adafruit.com"" #define AIO_SERVERPORT ""1883"" //1883, or 8883 for SSL #define AIO_USERNAME ""private"" //Adafruit IO #define AIO_KEY ""private"" // Labels for custom parameters in WiFi manager #define AIO_SERVER_Label ""AIO_SERVER_Label"" #define AIO_SERVERPORT_Label ""AIO_SERVERPORT_Label"" #define AIO_USERNAME_Label ""AIO_USERNAME_Label"" #define AIO_KEY_Label ""AIO_KEY_Label"" // Just dummy topics. To be updated later when got valid data from FS or Config Portal String MQTT_Pub_Topic = ""private/feeds/Temperature""; // Variables to save custom parameters to... // I would like to use these instead of #defines // Variables to save custom parameters to... // I would like to use these instead of #defines #define custom_AIO_SERVER_LEN 20 #define custom_AIO_PORT_LEN 5 #define custom_AIO_USERNAME_LEN 20 #define custom_AIO_KEY_LEN 40 char custom_AIO_SERVER[custom_AIO_SERVER_LEN]; char custom_AIO_SERVERPORT[custom_AIO_PORT_LEN]; char custom_AIO_USERNAME[custom_AIO_USERNAME_LEN]; char custom_AIO_KEY[custom_AIO_KEY_LEN]; // Function Prototypes void MQTT_connect(); bool readConfigFile(); bool writeConfigFile(); // For Config Portal // SSID and PW for Config Portal String ssid = ""ESP_"" + String(ESP_getChipId(), HEX); const char* password = ""your_password""; // SSID and PW for your Router String Router_SSID; String Router_Pass; // From v1.1.0 // You only need to format the filesystem once //#define FORMAT_FILESYSTEM true #define FORMAT_FILESYSTEM false #define MIN_AP_PASSWORD_SIZE 8 #define SSID_MAX_LEN 32 //From v1.0.10, WPA2 passwords can be up to 63 characters long. #define PASS_MAX_LEN 64 typedef struct { char wifi_ssid[SSID_MAX_LEN]; char wifi_pw [PASS_MAX_LEN]; } WiFi_Credentials; typedef struct { String wifi_ssid; String wifi_pw; } WiFi_Credentials_String; #define NUM_WIFI_CREDENTIALS 2 typedef struct { WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; } WM_Config; WM_Config WM_config; #define CONFIG_FILENAME F(""/wifi_cred.dat"") ////// // Indicates whether ESP has WiFi credentials saved from previous session //bool initialConfig = false; // Use false if you don't like to display Available Pages in Information Page of Config Portal // Comment out or use true to display Available Pages in Information Page of Config Portal // Must be placed before #include #define USE_AVAILABLE_PAGES false // From v1.0.10 to permit disable/enable StaticIP configuration in Config Portal from sketch. Valid only if DHCP is used. // You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa // You have to explicitly specify false to disable the feature. //#define USE_STATIC_IP_CONFIG_IN_CP false // Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal. // See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23) #define USE_ESP_WIFIMANAGER_NTP false // Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare // See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21) #define USE_CLOUDFLARE_NTP false // New in v1.0.11 #define USING_CORS_FEATURE true ////// // Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network #if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP) // Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #define USE_DHCP_IP true #else // You can select DHCP or Static IP here //#define USE_DHCP_IP true #define USE_DHCP_IP false #endif // Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network #if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP) // Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #define USE_DHCP_IP true #else // You can select DHCP or Static IP here //#define USE_DHCP_IP true #define USE_DHCP_IP false #endif #if ( USE_DHCP_IP ) // Use DHCP #warning Using DHCP IP IPAddress stationIP = IPAddress(0, 0, 0, 0); IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress netMask = IPAddress(255, 255, 255, 0); #else // Use static IP #warning Using static IP #ifdef ESP32 IPAddress stationIP = IPAddress(192, 168, 2, 232); #else IPAddress stationIP = IPAddress(192, 168, 2, 186); #endif IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress netMask = IPAddress(255, 255, 255, 0); #endif #define USE_CONFIGURABLE_DNS true IPAddress dns1IP = gatewayIP; IPAddress dns2IP = IPAddress(8, 8, 8, 8); // New in v1.4.0 IPAddress APStaticIP = IPAddress(192, 168, 100, 1); IPAddress APStaticGW = IPAddress(192, 168, 100, 1); IPAddress APStaticSN = IPAddress(255, 255, 255, 0); #include //https://github.com/khoih-prog/ESP_WiFiManager //Button config OneButton btn = OneButton( BUTTON_PIN, // Input pin for the button true, // Button is active LOW true // Enable internal pull-up resistor ); // Create an ESP32 WiFiClient class to connect to the MQTT server WiFiClient *client = NULL; Adafruit_MQTT_Client *mqtt = NULL; Adafruit_MQTT_Publish *Temperature = NULL; /////////////////////////////////////////// // New in v1.4.0 /****************************************** * // Defined in ESPAsync_WiFiManager.h typedef struct { IPAddress _ap_static_ip; IPAddress _ap_static_gw; IPAddress _ap_static_sn; } WiFi_AP_IPConfig; typedef struct { IPAddress _sta_static_ip; IPAddress _sta_static_gw; IPAddress _sta_static_sn; #if USE_CONFIGURABLE_DNS IPAddress _sta_static_dns1; IPAddress _sta_static_dns2; #endif } WiFi_STA_IPConfig; ******************************************/ WiFi_AP_IPConfig WM_AP_IPconfig; WiFi_STA_IPConfig WM_STA_IPconfig; void initAPIPConfigStruct(WiFi_AP_IPConfig &in_WM_AP_IPconfig) { in_WM_AP_IPconfig._ap_static_ip = APStaticIP; in_WM_AP_IPconfig._ap_static_gw = APStaticGW; in_WM_AP_IPconfig._ap_static_sn = APStaticSN; } void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig) { in_WM_STA_IPconfig._sta_static_ip = stationIP; in_WM_STA_IPconfig._sta_static_gw = gatewayIP; in_WM_STA_IPconfig._sta_static_sn = netMask; #if USE_CONFIGURABLE_DNS in_WM_STA_IPconfig._sta_static_dns1 = dns1IP; in_WM_STA_IPconfig._sta_static_dns2 = dns2IP; #endif } void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig) { LOGERROR3(F(""stationIP =""), in_WM_STA_IPconfig._sta_static_ip, "", gatewayIP ="", in_WM_STA_IPconfig._sta_static_gw); LOGERROR1(F(""netMask =""), in_WM_STA_IPconfig._sta_static_sn); #if USE_CONFIGURABLE_DNS LOGERROR3(F(""dns1IP =""), in_WM_STA_IPconfig._sta_static_dns1, "", dns2IP ="", in_WM_STA_IPconfig._sta_static_dns2); #endif } void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig) { #if USE_CONFIGURABLE_DNS // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2); #else // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn); #endif } /////////////////////////////////////////// uint8_t connectMultiWiFi() { #if ESP32 // For ESP32, this better be 0 to shorten the connect time. // For ESP32-S2, must be > 500 #if ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_PROS2 || ARDUINO_MICROS2 ) #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 500L #else // For ESP32 core v1.0.6, must be >= 500 #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 800L #endif #else // For ESP8266, this better be 2200 to enable connect the 1st time #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L #endif #define WIFI_MULTI_CONNECT_WAITING_MS 100L uint8_t status; LOGERROR(F(""ConnectMultiWiFi with :"")); if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Flash-stored Router_SSID = ""), Router_SSID, F("", Router_Pass = ""), Router_Pass ); } for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Additional SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); } } LOGERROR(F(""Connecting MultiWifi..."")); WiFi.mode(WIFI_STA); #if !USE_DHCP_IP // New in v1.4.0 configWiFi(WM_STA_IPconfig); ////// #endif int i = 0; status = wifiMulti.run(); delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) { status = wifiMulti.run(); if ( status == WL_CONNECTED ) break; else delay(WIFI_MULTI_CONNECT_WAITING_MS); } if ( status == WL_CONNECTED ) { LOGERROR1(F(""WiFi connected after time: ""), i); LOGERROR3(F(""SSID:""), WiFi.SSID(), F("",RSSI=""), WiFi.RSSI()); LOGERROR3(F(""Channel:""), WiFi.channel(), F("",IP address:""), WiFi.localIP() ); } else LOGERROR(F(""WiFi not connected"")); return status; } void toggleLED() { //toggle state digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } void heartBeatPrint() { static int num = 1; if (WiFi.status() == WL_CONNECTED) Serial.print(F(""W"")); // W means connected to WiFi else Serial.print(F(""N"")); // N means not connected to WiFi if (num == 40) { Serial.println(); num = 1; } else if (num++ % 5 == 0) { Serial.print(F("" "")); } } void publishMQTT() { float some_number = 25.0 + (float) ( millis() % 100 ) / 100; // For debug only //Serial.print(F(""Published Temp = "")); //Serial.println(some_number); MQTT_connect(); if (Temperature->publish(some_number)) { //Serial.println(F(""Failed to send value to Temperature feed!"")); Serial.print(F(""T"")); // T means publishing OK } else { //Serial.println(F(""Value to Temperature feed sucessfully sent!"")); Serial.print(F(""F"")); // F means publishing failure } } void check_WiFi() { if ( (WiFi.status() != WL_CONNECTED) ) { Serial.println(F(""\\nWiFi lost. Call connectMultiWiFi in loop"")); connectMultiWiFi(); } } void check_status() { static ulong checkstatus_timeout = 0; static ulong LEDstatus_timeout = 0; static ulong checkwifi_timeout = 0; static ulong mqtt_publish_timeout = 0; ulong current_millis = millis(); #define WIFICHECK_INTERVAL 1000L #define LED_INTERVAL 2000L #define HEARTBEAT_INTERVAL 10000L #define PUBLISH_INTERVAL 60000L // Check WiFi every WIFICHECK_INTERVAL (1) seconds. if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) { check_WiFi(); checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; } if ((current_millis > LEDstatus_timeout) || (LEDstatus_timeout == 0)) { // Toggle LED at LED_INTERVAL = 2s toggleLED(); LEDstatus_timeout = current_millis + LED_INTERVAL; } // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) { heartBeatPrint(); checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; } // Check every PUBLISH_INTERVAL (60) seconds. if ((current_millis > mqtt_publish_timeout) || (mqtt_publish_timeout == 0)) { if (WiFi.status() == WL_CONNECTED) { publishMQTT(); } mqtt_publish_timeout = current_millis + PUBLISH_INTERVAL; } } bool loadConfigData() { File file = FileFS.open(CONFIG_FILENAME, ""r""); LOGERROR(F(""LoadWiFiCfgFile "")); memset(&WM_config, 0, sizeof(WM_config)); // New in v1.4.0 memset(&WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig)); ////// if (file) { file.readBytes((char *) &WM_config, sizeof(WM_config)); // New in v1.4.0 file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); ////// file.close(); LOGERROR(F(""OK"")); // New in v1.4.0 displayIPConfigStruct(WM_STA_IPconfig); ////// return true; } else { LOGERROR(F(""failed"")); return false; } } void saveConfigData() { File file = FileFS.open(CONFIG_FILENAME, ""w""); LOGERROR(F(""SaveWiFiCfgFile "")); if (file) { file.write((uint8_t*) &WM_config, sizeof(WM_config)); displayIPConfigStruct(WM_STA_IPconfig); // New in v1.4.0 file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); ////// file.close(); LOGERROR(F(""OK"")); } else { LOGERROR(F(""failed"")); } } void deleteOldInstances() { // Delete previous instances if (mqtt) { delete mqtt; mqtt = NULL; Serial.println(F(""Deleting old MQTT object"")); } if (Temperature) { delete Temperature; Temperature = NULL; Serial.println(F(""Deleting old Temperature object"")); } } void createNewInstances() { if (!client) { client = new WiFiClient; Serial.print(F(""\\nCreating new WiFi client object : "")); Serial.println(client? F(""OK"") : F(""failed"")); } // Create new instances from new data if (!mqtt) { // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. mqtt = new Adafruit_MQTT_Client(client, custom_AIO_SERVER, atoi(custom_AIO_SERVERPORT), custom_AIO_USERNAME, custom_AIO_KEY); Serial.print(F(""Creating new MQTT object : "")); if (mqtt) { Serial.println(F(""OK"")); Serial.println(String(""AIO_SERVER = "") + custom_AIO_SERVER + "", AIO_SERVERPORT = "" + custom_AIO_SERVERPORT); Serial.println(String(""AIO_USERNAME = "") + custom_AIO_USERNAME + "", AIO_KEY = "" + custom_AIO_KEY); } else Serial.println(F(""Failed"")); } if (!Temperature) { Serial.print(F(""Creating new MQTT_Pub_Topic, Temperature = "")); Serial.println(MQTT_Pub_Topic); Temperature = new Adafruit_MQTT_Publish(mqtt, MQTT_Pub_Topic.c_str()); Serial.print(F(""Creating new Temperature object : "")); if (Temperature) { Serial.println(F(""OK"")); Serial.println(String(""Temperature MQTT_Pub_Topic = "") + MQTT_Pub_Topic); } else Serial.println(F(""Failed"")); } } //event handler functions for button static void handleClick() { Serial.println(F(""Button clicked!"")); wifi_manager(); } static void handleDoubleClick() { Serial.println(F(""Button double clicked!"")); } static void handleLongPressStop() { Serial.println(F(""Button pressed for long time and then released!"")); newConfigData(); } void wifi_manager() { Serial.println(F(""\\nConfig Portal requested."")); digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode. //Local intialization. Once its business is done, there is no need to keep it around ESP_WiFiManager ESP_wifiManager(""ConfigOnSwitchFS-MQTT""); //Check if there is stored WiFi router/password credentials. //If not found, device will remain in configuration mode until switched off via webserver. Serial.print(F(""Opening Configuration Portal. "")); Router_SSID = ESP_wifiManager.WiFi_SSID(); Router_Pass = ESP_wifiManager.WiFi_Pass(); // From v1.1.1, Don't permit NULL password if ( !initialConfig && (Router_SSID != """") && (Router_Pass != """") ) { //If valid AP credential and not DRD, set timeout 120s. ESP_wifiManager.setConfigPortalTimeout(120); Serial.println(F(""Got stored Credentials. Timeout 120s"")); } else { ESP_wifiManager.setConfigPortalTimeout(0); Serial.print(F(""No timeout : "")); if (initialConfig) { Serial.println(F(""DRD or No stored Credentials.."")); } else { Serial.println(F(""No stored Credentials."")); } } //Local intialization. Once its business is done, there is no need to keep it around // Extra parameters to be configured // After connecting, parameter.getValue() will get you the configured value // Format: