diff --git a/build.sh b/build.sh index 4469b0a..a73d3d4 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,3 @@ #!/bin/sh xa -W -C -v -O ASCII -S -c src/apple1serial.xa -l apple1serial.label -o apple1serial.bin -#xa -W -C -v -O ASCII -S -c src/serialmonitor.xa -l serialmonitor.label -o serialmonitor.bin diff --git a/firmware/main.c b/firmware/main.c index 312b1a9..7117533 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -21,21 +21,21 @@ #define DATA6 PD3 #define DATA7 PD4 -#define BUFFER_SIZE 8 +#define BUFFER_SIZE 100 typedef enum {NONE, READ, WRITE} mode_t; -mode_t mode = NONE; +volatile mode_t mode = NONE; -uint8_t data = 0x00; -uint8_t upper_part = 0x00; -uint8_t lower_part = 0x00; +volatile uint8_t data = 0x00; +volatile uint8_t upper_part = 0x00; +volatile uint8_t lower_part = 0x00; -uint8_t data_write_interrupt_count = 0; -uint8_t data_read_interrupt_count = 0; +volatile uint8_t data_write_interrupt_count = 0; +volatile uint8_t data_read_interrupt_count = 0; // receive buffer -uint8_t receive_buffer[BUFFER_SIZE]; -int8_t receive_index = -1; +volatile uint8_t receive_buffer[BUFFER_SIZE]; +volatile int8_t receive_index = -1; // Registers: PCMSK0, PCMSK1, PCMSK2 :registers that enable or disable pin-change interrupts // on individual pins diff --git a/src/apple1serial.xa b/src/apple1serial.xa index 56fdeb5..ac77107 100644 --- a/src/apple1serial.xa +++ b/src/apple1serial.xa @@ -1,4 +1,4 @@ - ;End address of dump block +;End address of dump block #define hex1_l $24 #define hex1_h $25 @@ -147,7 +147,10 @@ read beq read_ready lda serial_read ;Enable read mode, this can be done quick, without reset read_ready + txa ;Preserve X on stack + pha ldy #$00 + ldx #hex2_l read_byte lda serial_ready @@ -165,15 +168,14 @@ read_byte lda #last_command_read ;Set last command to READ sta last_command + + pla ;Restore X from stack + tax + jmp next_cmd ;Read is completed, proceed to next command read_next - txa ;Preserve X on stack - pha - ldx #hex2_l jsr increment_16bit ;Increment destination address - pla ;Restore X from stack - tax jmp read_byte ;------------------------------------------------------------------------- @@ -189,6 +191,9 @@ write ;and prevents from polluting the output while setting the write mode sta serial_write ;Enable write mode write_ready + txa ;Preserve X on stack + pha + ldx #hex2_l ldy #$00 write_byte @@ -207,15 +212,14 @@ write_byte lda #last_command_write ;Set last command to WRITE sta last_command + + pla ;Restore X from stack + tax + jmp next_cmd ;Write is completed, proceed to next command write_next - txa ;Preserve X on stack - pha - ldx #hex2_l jsr increment_16bit ;Increment destination address - pla ;Restore X from stack - tax jmp write_byte ;------------------------------------------------------------------------- @@ -247,11 +251,13 @@ reset_loop ; ~((2 + 2 + 3) * 255 + 2 + 3) * 255 = rts increment_16bit + txa inc $00,X bne increment_16bit_done inx inc $00,X increment_16bit_done + tax rts ;-------------------------------------------------------------------------