From 7c5943956bbc6c64e2aec7f40946ddc798bc7da3 Mon Sep 17 00:00:00 2001 From: Charles Mangin Date: Mon, 10 Apr 2017 12:16:47 -0400 Subject: [PATCH] added Merlin source for main routines Merlin32 compatible source for readbyte, sendbyte, and bufferedio routines --- GP2IO-KFEST/GP2IO-KFEST.ino | 145 ++++++++++++++++++++++++++---------- _FileInformation.txt | 3 + bufferedio | Bin 0 -> 125 bytes bufferedio.s | 70 +++++++++++++++++ bufferedio_Output.txt | 75 +++++++++++++++++++ readbyte | Bin 0 -> 40 bytes readbyte.s | 28 +++++++ readbyte_Output.txt | 33 ++++++++ sendbyte | 2 + sendbyte.s | 28 +++++++ sendbyte_Output.txt | 32 ++++++++ 11 files changed, 378 insertions(+), 38 deletions(-) create mode 100644 _FileInformation.txt create mode 100644 bufferedio create mode 100644 bufferedio.s create mode 100644 bufferedio_Output.txt create mode 100644 readbyte create mode 100644 readbyte.s create mode 100644 readbyte_Output.txt create mode 100644 sendbyte create mode 100644 sendbyte.s create mode 100644 sendbyte_Output.txt diff --git a/GP2IO-KFEST/GP2IO-KFEST.ino b/GP2IO-KFEST/GP2IO-KFEST.ino index 4cb5351..86f5ea3 100644 --- a/GP2IO-KFEST/GP2IO-KFEST.ino +++ b/GP2IO-KFEST/GP2IO-KFEST.ino @@ -26,6 +26,16 @@ CLRAN3 = $C05F ;Set annunciator-3 output to 1 +..xx xx.. 3C +.x.. ..x. 42 +x.x. .x.x a5 +x.x. .x.x a5 +x... ...x 81 +x.x. .x.x a5 +.x.x x.x. 5a +..xx xx.. 3c + + */ // I2C @@ -89,10 +99,10 @@ byte bufferLength[1]; B10101110, B01101010, B10101110 - };*/ + }; byte I2CBuffer[8] = { - B01111010, /* bit 7--0 */ + B01111010, B10111000, B00000000, B10111000, @@ -100,8 +110,27 @@ byte I2CBuffer[8] = { B10101110, B01101010, B10101110 +};*/ + +byte I2CBuffer[8] = { + B01010101, /* bit 7--0 */ + B10101010, + B01010101, + B10101010, + B01010101, + B10101010, + B01010101, + B10101010 }; + + + + /* + * + * + * + * 1 --- 6 | 7 | 2 @@ -126,9 +155,9 @@ byte ESPByte; const int LED_PIN = 11; -int RGB_RED = 9; -int RGB_GREEN = 10; -int RGB_BLUE = 4; +int RGB_RED = 10; +int RGB_GREEN = 4; +int RGB_BLUE = 9; int ANN0_PIN = 5; int ANN1_PIN = 6; @@ -159,30 +188,6 @@ int functionArray[] = //DEBUG is active until the AVR is reset or input timeout is reached. void setup() { - //LED MATRIX / 7 segment display - - if (!i2c_init()) { - Serial.println("I2C error. SDA or SCL are low"); - } - if (!i2c_start(i2c_addr) ) { - Serial.println("I2C device not found"); - } - - i2c_write(0x21); // turn on oscillator - i2c_stop(); - - // set blinkrate 0 - i2c_start(i2c_addr); - i2c_write(HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (0 << 1)); - i2c_stop(); - - // set brightness to 15/15 - i2c_start(i2c_addr); - i2c_write(HT16K33_CMD_BRIGHTNESS | 15); - i2c_stop(); - - writeI2C(); // "Good"/"ok" - pinMode(ANN2_PIN, INPUT); // annunciator 2 pinMode(ANN3_PIN, INPUT); // annunciator 3 @@ -207,15 +212,64 @@ void setup() { digitalWrite(LED_PIN, LOW); + /* + pinMode(14, OUTPUT); + digitalWrite(14, HIGH); + pinMode(15, OUTPUT); + digitalWrite(15, HIGH); + pinMode(16, OUTPUT); + digitalWrite(16, HIGH); + pinMode(17, OUTPUT); + digitalWrite(17, HIGH); + pinMode(18, OUTPUT); + digitalWrite(18, HIGH); + pinMode(19, OUTPUT); + digitalWrite(19, HIGH); + pinMode(20, OUTPUT); + digitalWrite(20, HIGH); + pinMode(21, OUTPUT); + digitalWrite(21, HIGH); + */ + Serial.begin(baud); // to ESP, other serial devices - HWSERIAL.begin(baud); + // HWSERIAL.begin(baud); enablePinInterrupt(ANN2_PIN); // Apple ready to receive attachInterrupt(0, APPLERTS, RISING); // ANNUNCIATOR 0, Apple sending byte attachInterrupt(1, RECEIVINGBITS, CHANGE); // ANNUNCIATOR 1, Apple sending bits - setRGBOneShot(0, 0, 200); // blue = ready + setRGBOneShot(200, 200, 200); // blue = ready + + + //LED MATRIX / 7 segment display + + if (!i2c_init()) { + Serial.println("I2C error. SDA or SCL are low"); + } + if (!i2c_start(i2c_addr) ) { + Serial.println("I2C device not found"); + } + + i2c_write(0x21); // turn on oscillator + i2c_stop(); + + // set blinkrate 0 + i2c_start(i2c_addr); + i2c_write(HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (0 << 1)); + i2c_stop(); + + // set brightness to 15/15 + i2c_start(i2c_addr); + i2c_write(HT16K33_CMD_BRIGHTNESS | 15); + i2c_stop(); + + writeI2C(); // "Good"/"ok" + ClearI2C(); + + + + } void loop() @@ -247,6 +301,8 @@ void loop() } + + } //loop void IOMODERESET(long resetTime, String reason) { @@ -260,7 +316,7 @@ void IOMODERESET(long resetTime, String reason) { Serial.print("MODE RESET "); Serial.println(reason); // Serial.println(TIMESINCELASTBYTE); - setRGBOneShot(0, 0, 200); + setRGBOneShot(200, 200, 200); digitalWrite(PB0_PIN, LOW); // RTS off digitalWrite(PB1_PIN, LOW); // Bits out @@ -270,6 +326,7 @@ void IOMODERESET(long resetTime, String reason) { // Serial.write(HWSERIALBuffer, 256); } + } @@ -370,7 +427,7 @@ void sendByte (byte byteToSend, bool oneShot) { void APPLERTS() { - // signal to start receiving bits from Apple II + // signal to start receiving bits from Apple II" bitCount = 0; changeCount = 0; returnByte = B00000000; @@ -453,6 +510,9 @@ void RECEIVINGBITS() void PROCESSBYTE(byte receivedByte) { + + + // char longstring[80] = "AT+CIPSTART=\"TCP\",\"www.option8llc.com\",80\n\r"; // int rd, wr; String connectString; @@ -665,16 +725,18 @@ void PROCESSBYTE(byte receivedByte) { case 4: // read and buffer 8 bytes to I2C buffer for matrix/7segment display if (functionLength == -1) { // first byte == message length functionLength = receivedByte; - Serial.print("I2C "); - Serial.println(functionLength); + Serial.print("L"); + Serial.println(functionLength); } else { I2CBuffer[functionLength - 1] = receivedByte; - Serial.println(receivedByte); + // Serial.print("I2C Buffer "); + // Serial.print(functionLength); + // Serial.println(I2CBuffer[functionLength - 1]); functionLength --; if (functionLength == 0) { writeI2C(); - Serial.print("I2C DONE"); + // Serial.print("I2C DONE"); } } @@ -800,7 +862,7 @@ void drawPixel(int16_t x, int16_t y, uint16_t color) { // if ((x < 0) || (x >= 8)) return; // wrap around the x - x += 7; // 0,0 => 7,0 // 7,0 => 14,0 // 1,0 => 8,0 + x += 7; // 0,0 => 7,0 // 7,0 => 14,0 // 1,0 => 8,0se x %= 8; // 7,0 => 7,0 // 14,0 => 6,0 // 8,0 => 0,0 if (color) { @@ -824,14 +886,21 @@ void writeI2C(void) { i2c_write(0x00); // start address $00 for (uint8_t i = 0; i < 8; i++) { + // Serial.print("I2C write "); + // Serial.println(I2CBuffer[i]); + // rotate the byte right by 1. "carry" bit gets rolled around I2CBuffer[i] = ((I2CBuffer[i] & 0x01) ? 0x80 : 0x00) | (I2CBuffer[i] >> 1); // seriously? ROR. i2c_write(I2CBuffer[i]); // write the bits to turn on/off pixels i2c_write(0xff); // control/bitmask? + + + } i2c_stop(); + // Serial.println("I2C WROTE"); } void ClearI2C(void) { diff --git a/_FileInformation.txt b/_FileInformation.txt new file mode 100644 index 0000000..cabccb8 --- /dev/null +++ b/_FileInformation.txt @@ -0,0 +1,3 @@ +sendbyte=Type(00),AuxType(0000),VersionCreate(70),MinVersion(BE),Access(E3),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000) +readbyte=Type(00),AuxType(0000),VersionCreate(70),MinVersion(BE),Access(E3),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000) +bufferedio=Type(00),AuxType(0000),VersionCreate(70),MinVersion(BE),Access(E3),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000) diff --git a/bufferedio b/bufferedio new file mode 100644 index 0000000000000000000000000000000000000000..bb8fccf9643e9a50505aa01151397a8629cd96eb GIT binary patch literal 125 zcmY%J=2+RFz`(qe14yjYP+0Lt!Hb!*LE-J+V;oC4F1%If`#aChyA7>5W{#rSD+qgBaQX literal 0 HcmV?d00001 diff --git a/readbyte.s b/readbyte.s new file mode 100644 index 0000000..9414cee --- /dev/null +++ b/readbyte.s @@ -0,0 +1,28 @@ + ORG $34A +ANN2HI EQU $C05D +ANN2LO EQU $C05C +BUTT1 EQU $C062 +BYTETRCVD EQU $EF +BUTT1HILO EQU $EE + + +READBYTE LDX #$09 ; reading 8 bits requires 9 transitions. + LDA #$00 ; clear the accumulator + STA BYTETRCVD ; $EF is staging for received byte, set 0 + STA BUTT1HILO ; $EE is staging for each bit, set 0 +CTS STA ANN2HI ; set ANN2 HIGH, indicate to AVR "Clear to Send" +LOOPSTART LDY #$FF ; start wait loop +LOOPCOUNT INY ; Increment Y - rolls over to 0 on first run (loopcount) + LDA BUTT1 ; check PB1 status hi/low + AND #$80 ; clear 0-6 bits (just need bit 7, all others float) + CMP BUTT1HILO ; compare Accumulator 7 bit with $EE, previous PB2 value + BNE BITCHANGE ; if PB2 has changed state, store in $EE (bitchange) + BEQ LOOPCOUNT ; bit hasn't changed yet, return to (loopcount) +BITCHANGE STA BUTT1HILO ; (bitchange) + CPY #$44 ; if the loop count is more than 68, bit is one. Bit is set in Carry + ROL BYTETRCVD ; rotate the new bit into $EF, our result byte. + DEX ; decrement X, our bit count + BNE LOOPSTART ; if bit count is not yet full, loop back to (loopcount) +CTSOFF STA ANN2LO ; if bit count is full, set ANN2 LOW, CTS off + LDA BYTETRCVD ; puts received byte into Accumulator + RTS ; return with byte in Accumulator diff --git a/readbyte_Output.txt b/readbyte_Output.txt new file mode 100644 index 0000000..d47591a --- /dev/null +++ b/readbyte_Output.txt @@ -0,0 +1,33 @@ +------+----------------------+-------------+----+---------+------+-----------------------+------------------------------------------------------------------- + Line | # File Line | Line Type | MX | Reloc | Size | Address Object Code | Source Code +------+----------------------+-------------+----+---------+------+-----------------------+------------------------------------------------------------------- + 1 | 1 readbyte.s 1 | Directive | 11 | | 0 | 00/8000 | ORG $34A + 2 | 1 readbyte.s 2 | Equivalence | 11 | | 0 | 00/034A | ANN2HI EQU $C05D + 3 | 1 readbyte.s 3 | Equivalence | 11 | | 0 | 00/034A | ANN2LO EQU $C05C + 4 | 1 readbyte.s 4 | Equivalence | 11 | | 0 | 00/034A | BUTT1 EQU $C062 + 5 | 1 readbyte.s 5 | Equivalence | 11 | | 0 | 00/034A | BYTETRCVD EQU $EF + 6 | 1 readbyte.s 6 | Equivalence | 11 | | 0 | 00/034A | BUTT1HILO EQU $EE + 7 | 1 readbyte.s 7 | Empty | 11 | | 0 | 00/034A | + 8 | 1 readbyte.s 8 | Empty | 11 | | 0 | 00/034A | + 9 | 1 readbyte.s 9 | Code | 11 | | 2 | 00/034A : A2 09 | READBYTE LDX #$09 ; reading 8 bits requires 9 transitions. + 10 | 1 readbyte.s 10 | Code | 11 | | 2 | 00/034C : A9 00 | LDA #$00 ; clear the accumulator + 11 | 1 readbyte.s 11 | Code | 11 | | 2 | 00/034E : 85 EF | STA {$EF} ; $EF is staging for received byte, set 0 + 12 | 1 readbyte.s 12 | Code | 11 | | 2 | 00/0350 : 85 EE | STA {$EE} ; $EE is staging for each bit, set 0 + 13 | 1 readbyte.s 13 | Code | 11 | | 3 | 00/0352 : 8D 5D C0 | CTS STA {$C05D} ; set ANN2 HIGH, indicate to AVR "Clear to Send" + 14 | 1 readbyte.s 14 | Code | 11 | | 2 | 00/0355 : A0 FF | LOOPSTART LDY #$FF ; start wait loop + 15 | 1 readbyte.s 15 | Code | 11 | | 1 | 00/0357 : C8 | LOOPCOUNT INY ; Increment Y - rolls over to 0 on first run (loopcount) + 16 | 1 readbyte.s 16 | Code | 11 | | 3 | 00/0358 : AD 62 C0 | LDA {$C062} ; check PB1 status hi/low + 17 | 1 readbyte.s 17 | Code | 11 | | 2 | 00/035B : 29 80 | AND #$80 ; clear 0-6 bits (just need bit 7, all others float) + 18 | 1 readbyte.s 18 | Code | 11 | | 2 | 00/035D : C5 EE | CMP {$EE} ; compare Accumulator 7 bit with $EE, previous PB2 value + 19 | 1 readbyte.s 19 | Code | 11 | | 2 | 00/035F : D0 02 | BNE BITCHANGE ; if PB2 has changed state, store in $EE (bitchange) + 20 | 1 readbyte.s 20 | Code | 11 | | 2 | 00/0361 : F0 F4 | BEQ LOOPCOUNT ; bit hasn't changed yet, return to (loopcount) + 21 | 1 readbyte.s 21 | Code | 11 | | 2 | 00/0363 : 85 EE | BITCHANGE STA {$EE} ; (bitchange) + 22 | 1 readbyte.s 22 | Code | 11 | | 2 | 00/0365 : C0 44 | CPY #$44 ; if the loop count is more than 68, bit is one. Bit is set in Carry + 23 | 1 readbyte.s 23 | Code | 11 | | 2 | 00/0367 : 26 EF | ROL {$EF} ; rotate the new bit into $EF, our result byte. + 24 | 1 readbyte.s 24 | Code | 11 | | 1 | 00/0369 : CA | DEX ; decrement X, our bit count + 25 | 1 readbyte.s 25 | Code | 11 | | 2 | 00/036A : D0 E9 | BNE LOOPSTART ; if bit count is not yet full, loop back to (loopcount) + 26 | 1 readbyte.s 26 | Code | 11 | | 3 | 00/036C : 8D 5C C0 | CTSOFF STA {$C05C} ; if bit count is full, set ANN2 LOW, CTS off + 27 | 1 readbyte.s 27 | Code | 11 | | 2 | 00/036F : A5 EF | LDA {$EF} ; puts received byte into Accumulator + 28 | 1 readbyte.s 28 | Code | 11 | | 1 | 00/0371 : 60 | RTS ; return with byte in Accumulator + 29 | 1 readbyte.s 29 | Empty | 11 | | 0 | 00/0372 | +------+----------------------+-------------+----+---------+------+-----------------------+------------------------------------------------------------------- diff --git a/sendbyte b/sendbyte new file mode 100644 index 0000000..eeef8cd --- /dev/null +++ b/sendbyte @@ -0,0 +1,2 @@ +Y&L +[ZX` \ No newline at end of file diff --git a/sendbyte.s b/sendbyte.s new file mode 100644 index 0000000..1906c2c --- /dev/null +++ b/sendbyte.s @@ -0,0 +1,28 @@ + ORG $0300 +ANN0HI EQU $C059 +ANN0LO EQU $C058 +ANN1HI EQU $C05B +ANN1LO EQU $C05A +BYTETOSEND EQU $EF + +SENDBYTE LDY #$08 ; load 8 for a full byte, loop counter + STA BYTETOSEND ; put byte in zero page for safe keeping +RTS STA ANN0HI ; annunciator 0 high, RTS +SENDBIT ROL BYTETOSEND ; rotate byte left, high/MSB out to carry (sendbit) + BCC SHORTLOOP ; "branch on carry clear" - if carry/bit = 0, goto #311 (short loop) +LONGLOOP LDX #$14 ; if carry/bit = 1, load X with 20 (long loop) + JMP SETANN1 ; jump over SHORTLOOP +SHORTLOOP LDX #$0A ; if carry/bit = 0, load X with 10 (short loop) +SETANN1 STA ANN1HI ; set annunciator 1 HIGH +COUNTDOWN DEX ; decrement, countdown to setting ANN1 low (COUNTDOWN) + BNE COUNTDOWN ; if X > 0, keep counting (goto COUNTDOWN) + STA ANN1LO ; if done, set ANN1 LOW, countdown to getting next bit + LDX #$05 ; reset counter for short "reset" transition. This lets the GP2IO stage the bit before the next interrupt +COUNTDOWN2 DEX ; count down again (COUNTDOWN2) + BNE COUNTDOWN2 ; if X > 0, keep counting (goto COUNTDOWN2) + DEY ; decrement y, countdown bits sent + BNE SENDBIT ; if y > 0, next bit (SENDBIT) +RTSOFF STA ANN0LO ; annunciator 0 low, sending RTS OFF + RTS ; return + + \ No newline at end of file diff --git a/sendbyte_Output.txt b/sendbyte_Output.txt new file mode 100644 index 0000000..2f2756d --- /dev/null +++ b/sendbyte_Output.txt @@ -0,0 +1,32 @@ +------+----------------------+-------------+----+---------+------+-----------------------+------------------------------------------------------------------- + Line | # File Line | Line Type | MX | Reloc | Size | Address Object Code | Source Code +------+----------------------+-------------+----+---------+------+-----------------------+------------------------------------------------------------------- + 1 | 1 sendbyte.s 1 | Directive | 11 | | 0 | 00/8000 | ORG $0300 + 2 | 1 sendbyte.s 2 | Equivalence | 11 | | 0 | 00/0300 | ANN0HI EQU $C059 + 3 | 1 sendbyte.s 3 | Equivalence | 11 | | 0 | 00/0300 | ANN0LO EQU $C058 + 4 | 1 sendbyte.s 4 | Equivalence | 11 | | 0 | 00/0300 | ANN1HI EQU $C05B + 5 | 1 sendbyte.s 5 | Equivalence | 11 | | 0 | 00/0300 | ANN1LO EQU $C05A + 6 | 1 sendbyte.s 6 | Equivalence | 11 | | 0 | 00/0300 | BYTETOSEND EQU $EF + 7 | 1 sendbyte.s 7 | Empty | 11 | | 0 | 00/0300 | + 8 | 1 sendbyte.s 8 | Code | 11 | | 2 | 00/0300 : A0 08 | SENDBYTE LDY #$08 ; load 8 for a full byte, loop counter + 9 | 1 sendbyte.s 9 | Code | 11 | | 2 | 00/0302 : 85 EF | STA {$EF} ; put byte in zero page for safe keeping + 10 | 1 sendbyte.s 10 | Code | 11 | | 3 | 00/0304 : 8D 59 C0 | RTS STA {$C059} ; annunciator 0 high, RTS + 11 | 1 sendbyte.s 11 | Code | 11 | | 2 | 00/0307 : 26 EF | SENDBIT ROL {$EF} ; rotate byte left, high/MSB out to carry (sendbit) + 12 | 1 sendbyte.s 12 | Code | 11 | | 2 | 00/0309 : 90 05 | BCC SHORTLOOP ; "branch on carry clear" - if carry/bit = 0, goto #311 (short loop) + 13 | 1 sendbyte.s 13 | Code | 11 | | 2 | 00/030B : A2 14 | LONGLOOP LDX #$14 ; if carry/bit = 1, load X with 20 (long loop) + 14 | 1 sendbyte.s 14 | Code | 11 | | 3 | 00/030D : 4C 12 03 | JMP SETANN1 ; jump over SHORTLOOP + 15 | 1 sendbyte.s 15 | Code | 11 | | 2 | 00/0310 : A2 0A | SHORTLOOP LDX #$0A ; if carry/bit = 0, load X with 10 (short loop) + 16 | 1 sendbyte.s 16 | Code | 11 | | 3 | 00/0312 : 8D 5B C0 | SETANN1 STA {$C05B} ; set annunciator 1 HIGH + 17 | 1 sendbyte.s 17 | Code | 11 | | 1 | 00/0315 : CA | COUNTDOWN DEX ; decrement, countdown to setting ANN1 low (COUNTDOWN) + 18 | 1 sendbyte.s 18 | Code | 11 | | 2 | 00/0316 : D0 FD | BNE COUNTDOWN ; if X > 0, keep counting (goto COUNTDOWN) + 19 | 1 sendbyte.s 19 | Code | 11 | | 3 | 00/0318 : 8D 5A C0 | STA {$C05A} ; if done, set ANN1 LOW, countdown to getting next bit + 20 | 1 sendbyte.s 20 | Code | 11 | | 2 | 00/031B : A2 05 | LDX #$05 ; reset counter for short "reset" transition. This lets the GP2IO stage the bit before the next interrupt + 21 | 1 sendbyte.s 21 | Code | 11 | | 1 | 00/031D : CA | COUNTDOWN2 DEX ; count down again (COUNTDOWN2) + 22 | 1 sendbyte.s 22 | Code | 11 | | 2 | 00/031E : D0 FD | BNE COUNTDOWN2 ; if X > 0, keep counting (goto COUNTDOWN2) + 23 | 1 sendbyte.s 23 | Code | 11 | | 1 | 00/0320 : 88 | DEY ; decrement y, countdown bits sent + 24 | 1 sendbyte.s 24 | Code | 11 | | 2 | 00/0321 : D0 E4 | BNE SENDBIT ; if y > 0, next bit (SENDBIT) + 25 | 1 sendbyte.s 25 | Code | 11 | | 3 | 00/0323 : 8D 58 C0 | RTSOFF STA {$C058} ; annunciator 0 low, sending RTS OFF + 26 | 1 sendbyte.s 26 | Code | 11 | | 1 | 00/0326 : 60 | RTS ; return + 27 | 1 sendbyte.s 27 | Empty | 11 | | 0 | 00/0327 | + 28 | 1 sendbyte.s 28 | Empty | 11 | | 0 | 00/0327 | +------+----------------------+-------------+----+---------+------+-----------------------+-------------------------------------------------------------------