improve AIX communication immunity, change ADSR/wave drawing, rename LCD master/slave...
authorb <rowerynaksiezycu@gmail.com>
Fri, 31 Jan 2025 00:47:40 +0000 (01:47 +0100)
committerb <rowerynaksiezycu@gmail.com>
Fri, 31 Jan 2025 00:47:40 +0000 (01:47 +0100)
aix.c
lcd.c
lcd.h

diff --git a/aix.c b/aix.c
index e2c9c5be002f699a29d3f3885521955fd33437b6..240b77c221a681ad798f82fe9277713b7e7015f0 100644 (file)
--- a/aix.c
+++ b/aix.c
@@ -127,7 +127,7 @@ void handle_aix (void)
                {
                        if( //frame is valid:
                                aix_check == 0 && // correct checksum
-                               aix_i != 0 && // frame not empty
+                               aix_i == 7 && // valid frame length
                                (((1<<aix_sel) & AIX_UNUSED)==0) && // not for an unused setting
                                aix_val <= AIX_DATA_MAX // value in range
                        ){
@@ -142,7 +142,6 @@ void handle_aix (void)
                                        else
                                                aix_data[aix_sel] = (aix_val + aix_data[aix_sel])>>1; // low pass approach
                                        
-                                       
                                        if((1<<aix_sel)&AIX_ADSR) // envelope to change
                                                update_adsr();
                                        else if((1<<aix_sel)&AIX_WAVE) //waveform to change
diff --git a/lcd.c b/lcd.c
index c47fa55b1b8071532eb8d5dce13d85ab6e514803..a7cf98ffd19f21e4bc4093136bbe14b5ee2227ca 100644 (file)
--- a/lcd.c
+++ b/lcd.c
@@ -74,9 +74,9 @@ inline void lcd_contrast (const uint16_t value)
        else if (x < LCD_Vop_MIN)
                x = LCD_Vop_MIN;
        
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_SetVop);
-       lcd_write(LCD_MASTER, LCD_DATA, x & LCD_Vop_LOWMASK);
-       lcd_write(LCD_MASTER, LCD_DATA, x >> LCD_Vop_HIGHSHIFT);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_SetVop);
+       lcd_write(LCD_RIGHT, LCD_DATA, x & LCD_Vop_LOWMASK);
+       lcd_write(LCD_RIGHT, LCD_DATA, x >> LCD_Vop_HIGHSHIFT);
 }
 
 inline void setup_lcd (void)
@@ -147,159 +147,159 @@ inline void init_lcd (void)
        LCD_RSTB=1;
        wait_ms(1 +1);
        
-       // Slave chip
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_ExtCommand1);
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_EnableSlave);
+       // "Slave" chip - left half
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_EnableSlave);
        
        // Disable auto read
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_ExtCommand2);
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_AutoReadControl);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x9F);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_ExtCommand2);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_AutoReadControl);
+       lcd_write(LCD_LEFT, LCD_DATA, 0x9F);
        
        // // Enable OTP Read
-       // lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_OtpWrRdControl);
-       // lcd_write(LCD_SLAVE, LCD_DATA, 0x00);
+       // lcd_write(LCD_LEFT, LCD_COMMAND, LCD_OtpWrRdControl);
+       // lcd_write(LCD_LEFT, LCD_DATA, 0x00);
        
        // wait_ms(10 +1);
        
        // // OTP Up-Load
-       // lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_OtpRead);
+       // lcd_write(LCD_LEFT, LCD_COMMAND, LCD_OtpRead);
        
        // wait_ms(20 +1);
        
        // // OTP Control Out
-       // lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_OtpControlWrite);
+       // lcd_write(LCD_LEFT, LCD_COMMAND, LCD_OtpControlWrite);
        
        // Sleep out
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_ExtCommand1);     
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_PowerSaveSleepOut);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_PowerSaveSleepOut);
        
        wait_ms(50 +1);
        
        // Power control
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_PowerControl);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x01); // VB OFF; VR ON, VF OFF
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_PowerControl);
+       lcd_write(LCD_LEFT, LCD_DATA, 0x01); // VB OFF; VR ON, VF OFF
        
        // Display Mode
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_DisplayMode);
-       lcd_write(LCD_SLAVE, LCD_DATA, LCD_MONO); // Monochrome Mode
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_DisplayMode);
+       lcd_write(LCD_LEFT, LCD_DATA, LCD_MONO); // Monochrome Mode
        
        // Display Format
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_DataFormatLsbTop);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_DataFormatLsbTop);
        
        // Display Control
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_DisplayControl);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x25); // Duty = 38
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_DisplayControl);
+       lcd_write(LCD_LEFT, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
+       lcd_write(LCD_LEFT, LCD_DATA, 0x25); // Duty = 38
+       lcd_write(LCD_LEFT, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
        
        // Data Scan Direction
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_DataScanDirection);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x06);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_DataScanDirection);
+       lcd_write(LCD_LEFT, LCD_DATA, 0x06);
        
        // Analog Circuit Set
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_ExtCommand2);
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_AnalogCircuitSet);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x00);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0x01); // Booster Efficiency = Level 1
-       lcd_write(LCD_SLAVE, LCD_DATA, LCD_BIAS); // Bias
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_ExtCommand2);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_AnalogCircuitSet);
+       lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+       lcd_write(LCD_LEFT, LCD_DATA, 0x01); // Booster Efficiency = Level 1
+       lcd_write(LCD_LEFT, LCD_DATA, LCD_BIAS); // Bias
        
        // Page Address Setting
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_ExtCommand1);
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_SetPageAddress);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0);
-       lcd_write(LCD_SLAVE, LCD_DATA, 4);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_SetPageAddress);
+       lcd_write(LCD_LEFT, LCD_DATA, 0);
+       lcd_write(LCD_LEFT, LCD_DATA, 4);
        
        // Column Address Setting
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_SetColumnAddress);
-       lcd_write(LCD_SLAVE, LCD_DATA, 0); 
-       lcd_write(LCD_SLAVE, LCD_DATA, HALFSCREEN_PIXELS-1);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_SetColumnAddress);
+       lcd_write(LCD_LEFT, LCD_DATA, 0);
+       lcd_write(LCD_LEFT, LCD_DATA, HALFSCREEN_PIXELS-1);
        
        // Display On
-       lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_DisplayOn);
+       lcd_write(LCD_LEFT, LCD_COMMAND, LCD_DisplayOn);
        
-       // Master chip
+       // "Master" chip - right half
        
        // Enable Master
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand1);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_EnableMaster);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_EnableMaster);
        
        // Disable auto read
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand2);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_AutoReadControl);
-       lcd_write(LCD_MASTER, LCD_DATA, 0x9F);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand2);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_AutoReadControl);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x9F);
        
        // // Enable OTP Read
-       // lcd_write(LCD_MASTER, LCD_COMMAND, LCD_OtpWrRdControl);
-       // lcd_write(LCD_MASTER, LCD_DATA, 0x00);
+       // lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_OtpWrRdControl);
+       // lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
        
        // wait_ms(10 +1);
        
        // // OTP Up-Load
-       // lcd_write(LCD_MASTER, LCD_COMMAND, LCD_OtpRead);
+       // lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_OtpRead);
        
        // wait_ms(20 +1);
        
        // // OTP Control Out
-       // lcd_write(LCD_MASTER, LCD_COMMAND, LCD_OtpControlWrite);
+       // lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_OtpControlWrite);
        
        // Sleep out
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand1);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_PowerSaveSleepOut);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_PowerSaveSleepOut);
        
        wait_ms(50 +1);
        
        // Power control
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_PowerControl);
-       lcd_write(LCD_MASTER, LCD_DATA, 0x0B); // VB ON; VR, VF ON
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_PowerControl);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x0B); // VB ON; VR, VF ON
        
        // Set Vop
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_SetVop);
-       lcd_write(LCD_MASTER, LCD_DATA, LCD_DEFAULT_Vop );//!
-       lcd_write(LCD_MASTER, LCD_DATA, LCD_DEFAULT_Vop_HIGH );//!
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_SetVop);
+       lcd_write(LCD_RIGHT, LCD_DATA, LCD_DEFAULT_Vop );//!
+       lcd_write(LCD_RIGHT, LCD_DATA, LCD_DEFAULT_Vop_HIGH );//!
        
        // Display Mode
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_DisplayMode);
-       lcd_write(LCD_MASTER, LCD_DATA, LCD_MONO); // Monochrome Mode
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_DisplayMode);
+       lcd_write(LCD_RIGHT, LCD_DATA, LCD_MONO); // Monochrome Mode
        
        // Display Format
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_DataFormatLsbTop);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_DataFormatLsbTop);
        
        // Display Control
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_DisplayControl);
-       lcd_write(LCD_MASTER, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
-       lcd_write(LCD_MASTER, LCD_DATA, 0x25); // Duty = 38
-       lcd_write(LCD_MASTER, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_DisplayControl);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x25); // Duty = 38
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x00); // CL Dividing Ratio -> Not Divide
        
        // Data Scan Direction
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_DataScanDirection);
-       lcd_write(LCD_MASTER, LCD_DATA, 0x06);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_DataScanDirection);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x06);
        
        // Analog Circuit Set
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand2);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_AnalogCircuitSet);
-       lcd_write(LCD_MASTER, LCD_DATA, 0x00);
-       lcd_write(LCD_MASTER, LCD_DATA, 0x01); // Booster Efficiency = Level
-       lcd_write(LCD_MASTER, LCD_DATA, LCD_BIAS); // Bias
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand2);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_AnalogCircuitSet);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0x01); // Booster Efficiency = Level
+       lcd_write(LCD_RIGHT, LCD_DATA, LCD_BIAS); // Bias
        
        // Page Address Setting
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand1);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_SetPageAddress);
-       lcd_write(LCD_MASTER, LCD_DATA, 0);
-       lcd_write(LCD_MASTER, LCD_DATA, 4);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_SetPageAddress);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0);
+       lcd_write(LCD_RIGHT, LCD_DATA, 4);
        
        // Column Address Setting
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_SetColumnAddress);
-       lcd_write(LCD_MASTER, LCD_DATA, 0);
-       lcd_write(LCD_MASTER, LCD_DATA, HALFSCREEN_PIXELS-1);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_SetColumnAddress);
+       lcd_write(LCD_RIGHT, LCD_DATA, 0);
+       lcd_write(LCD_RIGHT, LCD_DATA, HALFSCREEN_PIXELS-1);
        
        // Internal Power Supply
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand2);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_DrivingSelectInt);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand2);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_DrivingSelectInt);
        
        // Display On
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_ExtCommand1);
-       lcd_write(LCD_MASTER, LCD_COMMAND, LCD_DisplayOn);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_ExtCommand1);
+       lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_DisplayOn);
 }
 
 
@@ -331,7 +331,7 @@ void lcd_write ( // write single byte to LCD
        
        LCD_D__PM = 0x00; //data output
        
-       if (chip == LCD_SLAVE) //reverse bits for slave chip
+       if (chip == LCD_LEFT) //reverse bits for left chip
                d = reverse_bits(data);
        else
                d = data;
@@ -340,7 +340,7 @@ void lcd_write ( // write single byte to LCD
        
        LCD_D = d; //set data
        
-       if(chip == LCD_MASTER) //set chipselect
+       if(chip == LCD_RIGHT) //set chipselect
                LCD_CSB_MASTER=0;
        else
                LCD_CSB_SLAVE=0;
@@ -351,7 +351,7 @@ void lcd_write ( // write single byte to LCD
        
        LCD_WR = 1; //unset writeenable;
        
-       if(chip == LCD_MASTER) //unset chipselect
+       if(chip == LCD_RIGHT) //unset chipselect
                LCD_CSB_MASTER=1;
        else
                LCD_CSB_SLAVE=1;
@@ -414,14 +414,14 @@ void lcd_setup_drawing ( // setup drawing area and color depth
        if (x0 < HALFSCREEN_PIXELS)
        {
                x = (x1 > (HALFSCREEN_PIXELS-1)) ? HALFSCREEN_PIXELS-1 : x1;
-               lcd_set_mode(LCD_SLAVE, mode, x0, x, y0, y1);
-               lcd_write(LCD_SLAVE, LCD_COMMAND, LCD_WriteDataToDDRAM);
+               lcd_set_mode(LCD_LEFT, mode, x0, x, y0, y1);
+               lcd_write(LCD_LEFT, LCD_COMMAND, LCD_WriteDataToDDRAM);
        }
        if (x1 >= HALFSCREEN_PIXELS)
        {
                x = (x0 < HALFSCREEN_PIXELS) ? 0 : (x0-HALFSCREEN_PIXELS);
-               lcd_set_mode(LCD_MASTER, mode, x, x1-HALFSCREEN_PIXELS, y0, y1);
-               lcd_write(LCD_MASTER, LCD_COMMAND, LCD_WriteDataToDDRAM);
+               lcd_set_mode(LCD_RIGHT, mode, x, x1-HALFSCREEN_PIXELS, y0, y1);
+               lcd_write(LCD_RIGHT, LCD_COMMAND, LCD_WriteDataToDDRAM);
        }
 }
 
@@ -438,8 +438,8 @@ void lcd_clear_screen (const uint8_t mode)
        {
                for(j=0; j<=y; ++j)
                {
-                       lcd_write(LCD_SLAVE, LCD_DATA, 0x00);
-                       lcd_write(LCD_MASTER, LCD_DATA, 0x00);
+                       lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
                }
        }
 }
@@ -466,7 +466,7 @@ void lcd_subdraw_button (
        uint16_t line1, line2, line3, line4, margin_l, margin_r;
        uint16_t len, N;
        uint16_t i, i0, i1, i2, i3, j0, j1, j2, j3;
-       uint8_t  chip = LCD_SLAVE;
+       uint8_t  chip = LCD_LEFT;
        uint8_t  underline;
        
        underline = selected ? 0x3C : 00;
@@ -488,7 +488,7 @@ void lcd_subdraw_button (
        for(i=0; i<margin_l; ++i) // left margin
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
@@ -502,7 +502,7 @@ void lcd_subdraw_button (
                for (i=0, i0=-1; i<N; ++i)
                {
                        if (*x >= HALFSCREEN_PIXELS)
-                               chip = LCD_MASTER;
+                               chip = LCD_RIGHT;
                        if(!(i&0x7))
                        {
                                ++i0;
@@ -526,7 +526,7 @@ void lcd_subdraw_button (
                for (i=0, i0=-1, i1=line1-1; i<N; ++i)
                {
                        if (*x >= HALFSCREEN_PIXELS)
-                               chip = LCD_MASTER;
+                               chip = LCD_RIGHT;
                        if(!(i&0x7))
                        {
                                ++i0;
@@ -554,7 +554,7 @@ void lcd_subdraw_button (
                for (i=0, i0=-1, i1=line1-1, i2=line2-1; i<N; ++i)
                {
                        if (*x >= HALFSCREEN_PIXELS)
-                               chip = LCD_MASTER;
+                               chip = LCD_RIGHT;
                        if(!(i&0x7))
                        {
                                ++i0;
@@ -583,7 +583,7 @@ void lcd_subdraw_button (
                for (i=0, i0=-1, i1=line1-1, i2=line2-1, i3=line3-1; i<N; ++i)
                {
                        if (*x >= HALFSCREEN_PIXELS)
-                               chip = LCD_MASTER;
+                               chip = LCD_RIGHT;
                        if(!(i&0x7))
                        {
                                ++i0;
@@ -613,7 +613,7 @@ void lcd_subdraw_button (
        for(i=0; i<margin_r; ++i) // right margin
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
@@ -633,7 +633,7 @@ void lcd_subdraw_lowbutton8 (
        uint16_t line1, margin_l, margin_r;
        uint16_t len, N;
        uint16_t i, i0, j0, j3;
-       uint8_t  chip = LCD_SLAVE;
+       uint8_t  chip = LCD_LEFT;
        uint8_t  underline;
        
        underline = selected ? 0x3C : 00;
@@ -651,7 +651,7 @@ void lcd_subdraw_lowbutton8 (
        for(i=0; i<margin_l; ++i) // left margin
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
                ++(*x);
@@ -660,7 +660,7 @@ void lcd_subdraw_lowbutton8 (
        for (i=0, i0=-1; i<N; ++i) // single text line; 8 font
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                if(!(i&0x7))
                {
                        ++i0;
@@ -678,7 +678,7 @@ void lcd_subdraw_lowbutton8 (
        for(i=0; i<margin_r; ++i) // right margin
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
                ++(*x);
@@ -694,7 +694,7 @@ void lcd_subdraw_lowbutton16 (
        uint16_t line1, margin_l, margin_r;
        uint16_t len, N;
        uint16_t i, i0, j0, j3;
-       uint8_t  chip = LCD_SLAVE;
+       uint8_t  chip = LCD_LEFT;
        
        line1 = button_chars[type];
        margin_l = button_lmargin[type];
@@ -709,7 +709,7 @@ void lcd_subdraw_lowbutton16 (
        for(i=0; i<margin_l; ++i) // left margin
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
                ++(*x);
@@ -718,7 +718,7 @@ void lcd_subdraw_lowbutton16 (
        for (i=0, i0=-1; i<N; ++i) // single text line; 16px font
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                if(!(i&0x7))
                {
                        ++i0;
@@ -737,7 +737,7 @@ void lcd_subdraw_lowbutton16 (
        for(i=0; i<margin_r; ++i) // right margin
        {
                if (*x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                lcd_write(chip, LCD_DATA, 0x00);
                ++(*x);
@@ -746,10 +746,10 @@ void lcd_subdraw_lowbutton16 (
 
 void lcd_subdraw_divider (uint16_t * const x)
 {
-       uint8_t chip = LCD_SLAVE;
+       uint8_t chip = LCD_LEFT;
        
        if (*x >= HALFSCREEN_PIXELS)
-               chip = LCD_MASTER;
+               chip = LCD_RIGHT;
        
        lcd_write(chip, LCD_DATA, 0x55);
        lcd_write(chip, LCD_DATA, 0x55);
@@ -762,10 +762,10 @@ void lcd_subdraw_divider (uint16_t * const x)
 
 void lcd_subdraw_lowdivider (uint16_t * const x)
 {
-       uint8_t chip = LCD_SLAVE;
+       uint8_t chip = LCD_LEFT;
        
        if (*x >= HALFSCREEN_PIXELS)
-               chip = LCD_MASTER;
+               chip = LCD_RIGHT;
        
        lcd_write(chip, LCD_DATA, 0x55);
        lcd_write(chip, LCD_DATA, 0x55);
@@ -853,7 +853,7 @@ void lcd_select_button (
        uint16_t N;
        uint16_t margin_l, margin_r;
        uint16_t i;
-       uint8_t  chip = LCD_SLAVE;
+       uint8_t  chip = LCD_LEFT;
        uint8_t  underline;
        
        if ((id < -1) || (id > 5))
@@ -872,7 +872,7 @@ void lcd_select_button (
        for(i=0; i<margin_l; ++i) // left margin
        {
                if (x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                ++x;
        }
@@ -880,7 +880,7 @@ void lcd_select_button (
        for (i=0; i<N; ++i) // underline
        {
                if (x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, underline);
                ++x;
        }
@@ -888,7 +888,7 @@ void lcd_select_button (
        for(i=0; i<margin_r; ++i) // right margin
        {
                if (x >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
                ++x;
        }
@@ -897,7 +897,7 @@ void lcd_select_button (
 void lcd_draw_name_cursor (const uint8_t pos)
 {
        uint16_t x, i, j;
-       uint8_t chip = LCD_SLAVE;
+       uint8_t chip = LCD_LEFT;
        
        x = (pos<<3) + TITLE_6B_PIXELS + 1 +BUTTON_6X_LMARGIN;
        lcd_setup_drawing(LCD_MONO, x, x+7, 2, 2);
@@ -905,7 +905,7 @@ void lcd_draw_name_cursor (const uint8_t pos)
        for (i=x, j='^'<<3; i<x+8; ++i, j+=1)
        {
                if (i >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, font8[j]);
        }
 }
@@ -913,7 +913,7 @@ void lcd_draw_name_cursor (const uint8_t pos)
 void lcd_erase_name_cursor (const uint8_t pos)
 {
        uint16_t x, i;
-       uint8_t chip = LCD_SLAVE;
+       uint8_t chip = LCD_LEFT;
        
        x = (pos<<3) + TITLE_6B_PIXELS + 1 +BUTTON_6X_LMARGIN;
        lcd_setup_drawing(LCD_MONO, x, x+7, 2, 2);
@@ -921,7 +921,7 @@ void lcd_erase_name_cursor (const uint8_t pos)
        for (i=x; i<x+8; ++i)
        {
                if (i >= HALFSCREEN_PIXELS)
-                       chip = LCD_MASTER;
+                       chip = LCD_RIGHT;
                lcd_write(chip, LCD_DATA, 0x00);
        }
 }
@@ -1004,77 +1004,140 @@ void handle_lcd (void)
                lcd_setup_drawing(LCD_GRAY, draw_x, HALFSCREEN_PIXELS-1, 0, 9);
                while (draw_wave_active)
                {
-                       memset(col, 0, 10);
                        x = convert_wave((int8_t)draw_wave_data[draw_x]);
                        
-                       if (x < WAVE_LOWER_0)
+                       // Yes, I know this could be done with another loop. This is my choice.
+                       if (x < WAVE_LOWER_4)
                        {
-                               col[4] = WAVE_LOWER_START;
-                               if (x < WAVE_LOWER_1)
-                               {
-                                       col[5] = 0xff;
-                                       if (x < WAVE_LOWER_2)
-                                       {
-                                               col[6] = 0xff;
-                                               if (x < WAVE_LOWER_3)
-                                               {
-                                                       col[7] = 0xff;
-                                                       if (x < WAVE_LOWER_4)
-                                                       {
-                                                               col[8] = 0xff;
-                                                               col[9] = wave_lower[x-WAVE_LOWER_5];
-                                                       }
-                                                       else
-                                                               col[8] = wave_lower[x-WAVE_LOWER_4];
-                                               }
-                                               else
-                                                       col[7] = wave_lower[x-WAVE_LOWER_3];
-                                       }
-                                       else
-                                               col[6] = wave_lower[x-WAVE_LOWER_2];
-                               }
-                               else
-                                       col[5] = wave_lower[x-WAVE_LOWER_1];
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_LOWER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_lower[x-WAVE_LOWER_5]);
                        }
-                       else if (x >= WAVE_UPPER_0)
+                       else if (x < WAVE_LOWER_3)
                        {
-                               col[4] = WAVE_UPPER_START;
-                               if (x >= WAVE_UPPER_1)
-                               {
-                                       col[3] = 0xff;
-                                       if (x >= WAVE_UPPER_2)
-                                       {
-                                               col[2] = 0xff;
-                                               if (x >= WAVE_UPPER_3)
-                                               {
-                                                       col[1] = 0xff;
-                                                       col[0] = wave_upper[x-WAVE_UPPER_3];
-                                               }
-                                               else
-                                                       col[1] = wave_upper[x-WAVE_UPPER_2];
-                                       }
-                                       else
-                                               col[2] = wave_upper[x-WAVE_UPPER_1];
-                               }
-                               else
-                                       col[3] = wave_upper[x-WAVE_UPPER_0];
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_LOWER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_lower[x-WAVE_LOWER_4]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_LOWER_2)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_LOWER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_lower[x-WAVE_LOWER_3]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_LOWER_1)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_LOWER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_lower[x-WAVE_LOWER_2]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_LOWER_0)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_LOWER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_lower[x-WAVE_LOWER_1]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_UPPER_0)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_middle[x-WAVE_LOWER_0]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_UPPER_1)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_upper[x-WAVE_UPPER_0]);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_UPPER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_UPPER_2)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_upper[x-WAVE_UPPER_1]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_UPPER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                       }
+                       else if (x < WAVE_UPPER_3)
+                       {
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_upper[x-WAVE_UPPER_2]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_UPPER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
                        }
                        else
                        {
-                               col[4] = wave_middle[x-WAVE_LOWER_0];
+                               lcd_write(LCD_LEFT, LCD_DATA, wave_upper[x-WAVE_UPPER_3]);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0xff);
+                               lcd_write(LCD_LEFT, LCD_DATA, WAVE_UPPER_START);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
+                               lcd_write(LCD_LEFT, LCD_DATA, 0x00);
                        }
                        
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[0]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[1]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[2]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[3]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[4]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[5]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[6]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[7]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[8]);
-                       lcd_write(LCD_SLAVE, LCD_DATA, col[9]);
-                       
                        ++draw_x;
                        // finished
                        if (draw_x >= HALFSCREEN_PIXELS)
@@ -1083,9 +1146,9 @@ void handle_lcd (void)
                                draw_x = 0;
                                return;
                        }
-                       // // interrupt drawing to handle AIX communication
-                       // if (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_DATA))
-                               // return;
+                       // interrupt drawing to handle AIX communication
+                       if (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_DATA))
+                               return;
                }
                draw_x = 0;
        }
@@ -1095,75 +1158,138 @@ void handle_lcd (void)
                lcd_setup_drawing(LCD_GRAY, HALFSCREEN_PIXELS+draw_x, FULLSCREEN_PIXELS-1, 0, 9);
                while (draw_adsr_active)
                {
-                       memset(col, 0, 10);
                        x = draw_adsr_data[draw_x];
-                       
-                       if (x >= ADSR_UPPER_1)
+                       // Yes, I know this could be done with another loop. This is my choice.
+                       if (x < ADSR_UPPER_1)
                        {
-                               col[9] = 0xff;
-                               if (x >= ADSR_UPPER_2)
-                               {
-                                       col[8] = 0xff;
-                                       if (x >= ADSR_UPPER_3)
-                                       {
-                                               col[7] = 0xff;
-                                               if (x >= ADSR_UPPER_4)
-                                               {
-                                                       col[6] = 0xff;
-                                                       if (x >= ADSR_UPPER_5)
-                                                       {
-                                                               col[5] = 0xff;
-                                                               if (x >= ADSR_UPPER_6)
-                                                               {
-                                                                       col[4] = 0xff;
-                                                                       if (x >= ADSR_UPPER_7)
-                                                                       {
-                                                                               col[3] = 0xff;
-                                                                               if (x >= ADSR_UPPER_8)
-                                                                               {
-                                                                                       col[2] = 0xff;
-                                                                                       if (x >= ADSR_UPPER_9)
-                                                                                       {
-                                                                                               col[1] = 0xff;
-                                                                                               col[0] = wave_upper[x-ADSR_UPPER_9];
-                                                                                       }
-                                                                                       else
-                                                                                               col[1] = wave_upper[x-ADSR_UPPER_8];
-                                                                               }
-                                                                               else
-                                                                                       col[2] = wave_upper[x-ADSR_UPPER_7];
-                                                                       }
-                                                                       else
-                                                                               col[3] = wave_upper[x-ADSR_UPPER_6];
-                                                               }
-                                                               else
-                                                                       col[4] = wave_upper[x-ADSR_UPPER_5];
-                                                       }
-                                                       else
-                                                               col[5] = wave_upper[x-ADSR_UPPER_4];
-                                               }
-                                               else
-                                                       col[6] = wave_upper[x-ADSR_UPPER_3];
-                                       }
-                                       else
-                                               col[7] = wave_upper[x-ADSR_UPPER_2];
-                               }
-                               else
-                                       col[8] = wave_upper[x-ADSR_UPPER_1];
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_0]);
+                       }
+                       else if (x < ADSR_UPPER_2)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_1]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_3)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_2]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_4)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_3]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_5)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_4]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_6)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_5]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_7)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_6]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_8)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_7]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
+                       else if (x < ADSR_UPPER_9)
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0x00);
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_8]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
                        }
                        else
-                               col[9] = wave_upper[x-ADSR_UPPER_0];
-                       
-                       lcd_write(LCD_MASTER, LCD_DATA, col[0]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[1]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[2]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[3]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[4]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[5]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[6]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[7]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[8]);
-                       lcd_write(LCD_MASTER, LCD_DATA, col[9]);
+                       {
+                               lcd_write(LCD_RIGHT, LCD_DATA,  wave_upper[x-ADSR_UPPER_9]);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                               lcd_write(LCD_RIGHT, LCD_DATA, 0xff);
+                       }
                        
                        ++draw_x;
                        // finished
@@ -1173,9 +1299,9 @@ void handle_lcd (void)
                                draw_x = 0;
                                return;
                        }
-                       // // interrupt drawing to handle communication
-                       // if (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_DATA))
-                               // return;
+                       // interrupt drawing to handle communication
+                       if (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_DATA))
+                               return;
                }
                draw_x = 0;
        }
diff --git a/lcd.h b/lcd.h
index a01b84db5ca53b0ebc5dc87077a49fa7e287ce14..49ea8b81be8a9b068dd3c74d56512be23207759b 100644 (file)
--- a/lcd.h
+++ b/lcd.h
@@ -21,7 +21,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 +-------------+----+----+----+----+----+----+
 |             |    |    |    |    |    |    |
 +-------------+----+----+----+----+----+----+
-|     146     1 60 1 60 1 60 1 60 1 60 1 60 |    
+|     146     1 60 1 60 1 60 1 60 1 60 1 60 |
 
 |2|  7x8  |2| 
 +-+-------+-+
@@ -286,8 +286,8 @@ therefore:
 #define LCD_DEFAULT_Vop_LOW  (LCD_DEFAULT_Vop & LCD_Vop_LOWMASK)
 #define LCD_DEFAULT_Vop_HIGH (LCD_DEFAULT_Vop >> LCD_Vop_HIGHSHIFT)
 
-#define LCD_MASTER 0
-#define LCD_SLAVE 1
+#define LCD_RIGHT 0
+#define LCD_LEFT 1
 
 #define LCD_COMMAND 0
 #define LCD_DATA 1