mirror of
https://github.com/flowenol/apple1serial.git
synced 2024-09-27 04:54:42 +00:00
read buffer & last operation
This commit is contained in:
parent
7de77dd557
commit
f05389366d
@ -2,7 +2,7 @@
|
|||||||
GAL20V8
|
GAL20V8
|
||||||
EQN2JED - Boolean Equations to JEDEC file assembler (Version V101)
|
EQN2JED - Boolean Equations to JEDEC file assembler (Version V101)
|
||||||
Copyright (c) National Semiconductor Corporation 1990-1993
|
Copyright (c) National Semiconductor Corporation 1990-1993
|
||||||
Assembled from "e:/APPLE1~1/ADDRES~1.EQN". Date: 5-24-120
|
Assembled from "c:/APPLE1~1/ADDRES~1.EQN". Date: 6-7-120
|
||||||
*
|
*
|
||||||
NOTE PINS RW:2 A0:3 A1:4 A2:5 A3:6 A4:7 A5:8 A6:9 A7:10 A8:11*
|
NOTE PINS RW:2 A0:3 A1:4 A2:5 A3:6 A4:7 A5:8 A6:9 A7:10 A8:11*
|
||||||
NOTE PINS GND:12 A9:14 A10:15 A11:16 SR:17 RD:18 WD:19 ROM:20*
|
NOTE PINS GND:12 A9:14 A10:15 A11:16 SR:17 RD:18 WD:19 ROM:20*
|
||||||
@ -19,7 +19,7 @@ L0640
|
|||||||
L0960
|
L0960
|
||||||
1011011010011011101110111010101001101011*
|
1011011010011011101110111010101001101011*
|
||||||
L1280
|
L1280
|
||||||
0111101010011011101110111010101001101011*
|
0111101010111011101110111010101001101011*
|
||||||
L1600
|
L1600
|
||||||
0111101010111011101110111010101010101011*
|
0111101010111011101110111010101010101011*
|
||||||
L2560
|
L2560
|
||||||
@ -30,5 +30,5 @@ L2640
|
|||||||
0000000010000000111100001000000010000000100000000000000000000000*
|
0000000010000000111100001000000010000000100000000000000000000000*
|
||||||
L2704
|
L2704
|
||||||
10*
|
10*
|
||||||
C1FC0*
|
C1FC4*
|
||||||
0000
|
0000
|
||||||
|
@ -7,7 +7,7 @@ R=23 VCC=24
|
|||||||
equations
|
equations
|
||||||
|
|
||||||
SR = /A0 * /A1 * /A2 * /A3 * /A4 * /A5 * /A6 * /A7 * /A8 * /A9 * /A10 * /A11 * /R * RW
|
SR = /A0 * /A1 * /A2 * /A3 * /A4 * /A5 * /A6 * /A7 * /A8 * /A9 * /A10 * /A11 * /R * RW
|
||||||
RD = /A0 * /A1 * /A2 * /A3 * /A4 * /A5 * /A6 * A7 * /A8 * /A9 * /A10 * /A11 * /R * RW * PHI
|
RD = /A0 * /A1 * /A2 * /A3 * /A4 * /A5 * /A6 * A7 * /A8 * /A9 * /A10 * /A11 * /R * RW
|
||||||
WD = A0 * /A1 * /A2 * /A3 * /A4 * /A5 * /A6 * A7 * /A8 * /A9 * /A10 * /A11 * /R * /RW * PHI
|
WD = A0 * /A1 * /A2 * /A3 * /A4 * /A5 * /A6 * A7 * /A8 * /A9 * /A10 * /A11 * /R * /RW * PHI
|
||||||
/ROM = A8 * /R * RW
|
/ROM = A8 * /R * RW
|
||||||
+ A9 * /R * RW
|
+ A9 * /R * RW
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#define DATA6 PD3
|
#define DATA6 PD3
|
||||||
#define DATA7 PD4
|
#define DATA7 PD4
|
||||||
|
|
||||||
|
#define BUFFER_SIZE 8
|
||||||
|
|
||||||
typedef enum {NONE, READ, WRITE} mode_t;
|
typedef enum {NONE, READ, WRITE} mode_t;
|
||||||
mode_t mode = NONE;
|
mode_t mode = NONE;
|
||||||
|
|
||||||
@ -31,6 +33,10 @@ uint8_t lower_part = 0x00;
|
|||||||
uint8_t data_write_interrupt_count = 0;
|
uint8_t data_write_interrupt_count = 0;
|
||||||
uint8_t data_read_interrupt_count = 0;
|
uint8_t data_read_interrupt_count = 0;
|
||||||
|
|
||||||
|
// receive buffer
|
||||||
|
uint8_t receive_buffer[BUFFER_SIZE];
|
||||||
|
int8_t receive_index = -1;
|
||||||
|
|
||||||
// Registers: PCMSK0, PCMSK1, PCMSK2 :registers that enable or disable pin-change interrupts
|
// Registers: PCMSK0, PCMSK1, PCMSK2 :registers that enable or disable pin-change interrupts
|
||||||
// on individual pins
|
// on individual pins
|
||||||
|
|
||||||
@ -46,6 +52,14 @@ inline void not_ready() {
|
|||||||
PORTD &= ~(_BV(STATUS));
|
PORTD &= ~(_BV(STATUS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void put_data() {
|
||||||
|
upper_part = (PORTD & 0xe3) | ((0xe0 & receive_buffer[0])>>3);
|
||||||
|
lower_part = (PORTB & 0xc1) | ((0x1f & receive_buffer[0])<<1);
|
||||||
|
|
||||||
|
PORTD = upper_part;
|
||||||
|
PORTB = lower_part;
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
// set input on DATA_READ_LINE
|
// set input on DATA_READ_LINE
|
||||||
@ -94,9 +108,28 @@ ISR(PCINT0_vect) {
|
|||||||
// set output on data pins
|
// set output on data pins
|
||||||
DDRD |= _BV(DATA5) | _BV(DATA6) | _BV(DATA7);
|
DDRD |= _BV(DATA5) | _BV(DATA6) | _BV(DATA7);
|
||||||
DDRB |= _BV(DATA0) | _BV(DATA1) | _BV(DATA2) | _BV(DATA3) | _BV(DATA4);
|
DDRB |= _BV(DATA0) | _BV(DATA1) | _BV(DATA2) | _BV(DATA3) | _BV(DATA4);
|
||||||
}
|
|
||||||
|
receive_index = -1;
|
||||||
not_ready();
|
not_ready();
|
||||||
data_read_interrupt_count = 1;
|
data_read_interrupt_count = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receive_index > -1) {
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 1; i <= receive_index; i++) {
|
||||||
|
receive_buffer[i - 1] = receive_buffer[i];
|
||||||
|
}
|
||||||
|
receive_index--;
|
||||||
|
|
||||||
|
if (receive_index == -1) {
|
||||||
|
not_ready();
|
||||||
|
} else {
|
||||||
|
// put next byte from receive buffer
|
||||||
|
put_data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data_read_interrupt_count = 1;
|
||||||
} else {
|
} else {
|
||||||
data_read_interrupt_count = 0;
|
data_read_interrupt_count = 0;
|
||||||
}
|
}
|
||||||
@ -149,11 +182,14 @@ ISR(USART_RX_vect)
|
|||||||
if (mode == READ) {
|
if (mode == READ) {
|
||||||
data = UDR0;
|
data = UDR0;
|
||||||
|
|
||||||
upper_part = (PORTD & 0xe3) | ((0xe0 & data)>>3);
|
if (receive_index >= BUFFER_SIZE - 1) {
|
||||||
lower_part = (PORTB & 0xc1) | ((0x1f & data)<<1);
|
receive_index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
PORTD = upper_part;
|
receive_buffer[++receive_index] = data;
|
||||||
PORTB = lower_part;
|
|
||||||
|
// always put first byte from receive buffer
|
||||||
|
put_data();
|
||||||
|
|
||||||
ready();
|
ready();
|
||||||
}
|
}
|
||||||
@ -174,4 +210,3 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
return 0; /* never reached */
|
return 0; /* never reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
;End address of dump block
|
;End address of dump block
|
||||||
#define hex1_l $50
|
#define hex1_l $24
|
||||||
#define hex1_h $51
|
#define hex1_h $25
|
||||||
|
|
||||||
;Begin address of dump block
|
;Begin address of dump block
|
||||||
#define hex2_l $52
|
#define hex2_l $26
|
||||||
#define hex2_h $53
|
#define hex2_h $27
|
||||||
|
|
||||||
|
#define last_command $28
|
||||||
|
#define last_command_none $00
|
||||||
|
#define last_command_read $01
|
||||||
|
#define last_command_write $02
|
||||||
|
|
||||||
;Input buffer
|
;Input buffer
|
||||||
#define input $0200
|
#define input $0200
|
||||||
@ -44,6 +49,8 @@ apple_serial
|
|||||||
jsr echo
|
jsr echo
|
||||||
lda #CR ;And drop the cursor one line
|
lda #CR ;And drop the cursor one line
|
||||||
jsr echo
|
jsr echo
|
||||||
|
lda #$00 ;Set last command type to NONE
|
||||||
|
sta last_command
|
||||||
ldy #$FF ;Reset the input buffer index
|
ldy #$FF ;Reset the input buffer index
|
||||||
|
|
||||||
next_char
|
next_char
|
||||||
@ -133,28 +140,16 @@ separator
|
|||||||
sta hex1_h
|
sta hex1_h
|
||||||
jmp next_chr
|
jmp next_chr
|
||||||
|
|
||||||
reset
|
|
||||||
txa
|
|
||||||
pha
|
|
||||||
lda serial_reset
|
|
||||||
ldx #$00
|
|
||||||
ldy #$00
|
|
||||||
reset_loop ; ((2 + 2 + 3) * 255 + 2 + 3) * 255 =
|
|
||||||
nop ; 2 cycles
|
|
||||||
iny ; 2 cycles
|
|
||||||
bne reset_loop ; 3 cycles
|
|
||||||
inx ; 2 cycles
|
|
||||||
bne reset_loop ; 3 cycles
|
|
||||||
pla
|
|
||||||
tax
|
|
||||||
rts
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------
|
;-------------------------------------------------------------------------
|
||||||
; Read procedure
|
; Read procedure
|
||||||
;-------------------------------------------------------------------------
|
;-------------------------------------------------------------------------
|
||||||
|
|
||||||
read
|
read
|
||||||
|
lda last_command
|
||||||
|
cmp #last_command_read
|
||||||
|
beq read_ready
|
||||||
lda serial_read ;Enable read mode, this can be done quick, without reset
|
lda serial_read ;Enable read mode, this can be done quick, without reset
|
||||||
|
read_ready
|
||||||
ldy #$00
|
ldy #$00
|
||||||
|
|
||||||
read_byte
|
read_byte
|
||||||
@ -171,6 +166,8 @@ read_byte
|
|||||||
cmp hex1_h ;Compare upper destination address half with upper end address half
|
cmp hex1_h ;Compare upper destination address half with upper end address half
|
||||||
bne read_next ;If not equal then proceed to read next byte
|
bne read_next ;If not equal then proceed to read next byte
|
||||||
|
|
||||||
|
lda last_command_read ;Set last command to READ
|
||||||
|
sta last_command
|
||||||
jmp next_cmd ;Read is completed, proceed to next command
|
jmp next_cmd ;Read is completed, proceed to next command
|
||||||
|
|
||||||
read_next
|
read_next
|
||||||
@ -187,10 +184,14 @@ read_next
|
|||||||
;-------------------------------------------------------------------------
|
;-------------------------------------------------------------------------
|
||||||
|
|
||||||
write
|
write
|
||||||
|
lda last_command
|
||||||
|
cmp #last_command_write
|
||||||
|
beq write_ready
|
||||||
jsr reset ;Reset serial and give some time to stabilize
|
jsr reset ;Reset serial and give some time to stabilize
|
||||||
;This is required due to inability to guess what is the current device mode
|
;This is required due to inability to guess what is the current device mode
|
||||||
;and prevents from polluting the output while setting the write mode
|
;and prevents from polluting the output while setting the write mode
|
||||||
sta serial_write ;Enable write mode
|
sta serial_write ;Enable write mode
|
||||||
|
write_ready
|
||||||
ldy #$00
|
ldy #$00
|
||||||
|
|
||||||
write_byte
|
write_byte
|
||||||
@ -207,6 +208,8 @@ write_byte
|
|||||||
cmp hex1_h ;Compare upper source address half with upper end address half
|
cmp hex1_h ;Compare upper source address half with upper end address half
|
||||||
bne write_next ;If not equal then proceed to write next byte
|
bne write_next ;If not equal then proceed to write next byte
|
||||||
|
|
||||||
|
lda last_command_write ;Set last command to WRITE
|
||||||
|
sta last_command
|
||||||
jmp next_cmd ;Write is completed, proceed to next command
|
jmp next_cmd ;Write is completed, proceed to next command
|
||||||
|
|
||||||
write_next
|
write_next
|
||||||
@ -222,6 +225,30 @@ write_next
|
|||||||
; tool routines
|
; tool routines
|
||||||
;-------------------------------------------------------------------------
|
;-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
reset
|
||||||
|
txa ;Preserve X on stack
|
||||||
|
pha
|
||||||
|
|
||||||
|
tya ;Preserve Y on stack
|
||||||
|
pha
|
||||||
|
|
||||||
|
lda serial_reset ;Reset
|
||||||
|
ldx #$00
|
||||||
|
ldy #$00
|
||||||
|
reset_loop ; ~((2 + 2 + 3) * 255 + 2 + 3) * 255 =
|
||||||
|
nop ; 2 cycles
|
||||||
|
iny ; 2 cycles
|
||||||
|
bne reset_loop ; 3 cycles
|
||||||
|
inx ; 2 cycles
|
||||||
|
bne reset_loop ; 3 cycles
|
||||||
|
|
||||||
|
pla ;Restore Y from stack
|
||||||
|
tay
|
||||||
|
|
||||||
|
pla ;Restore X from stack
|
||||||
|
tax
|
||||||
|
rts
|
||||||
|
|
||||||
increment_16bit
|
increment_16bit
|
||||||
inc $00,X
|
inc $00,X
|
||||||
bne increment_16bit_done
|
bne increment_16bit_done
|
||||||
|
29
src/tests.xa
29
src/tests.xa
@ -5,12 +5,12 @@
|
|||||||
#define serial_read $C080
|
#define serial_read $C080
|
||||||
#define serial_write $C081
|
#define serial_write $C081
|
||||||
|
|
||||||
* = $C200
|
* = $C300
|
||||||
.dsb (*-end_of_apple1serial), 0
|
.dsb (*-end_of_apple1serial), 0
|
||||||
|
|
||||||
; teletype on apple-1
|
; teletype on apple-1
|
||||||
* = $C200
|
* = $C300
|
||||||
teletype_apple1 = $C200
|
teletype_apple1 = $C300
|
||||||
lda serial_read
|
lda serial_read
|
||||||
wait
|
wait
|
||||||
lda serial_ready
|
lda serial_ready
|
||||||
@ -20,16 +20,12 @@ wait
|
|||||||
jmp wait
|
jmp wait
|
||||||
end_of_teletype_apple1
|
end_of_teletype_apple1
|
||||||
|
|
||||||
; AD 80 C0 AD 00 C0 F0 FB
|
|
||||||
; AD 80 C0 20 EF FF 4C 03
|
|
||||||
; 00
|
|
||||||
|
|
||||||
; teletype on remote
|
; teletype on remote
|
||||||
* = $C300
|
* = $C400
|
||||||
.dsb (*-end_of_teletype_apple1), 0
|
.dsb (*-end_of_teletype_apple1), 0
|
||||||
|
|
||||||
* = $C300
|
* = $C400
|
||||||
teletype_remote = $C300
|
teletype_remote = $C400
|
||||||
lda #$FF
|
lda #$FF
|
||||||
sta serial_write
|
sta serial_write
|
||||||
get_key
|
get_key
|
||||||
@ -42,16 +38,12 @@ get_key
|
|||||||
jmp get_key
|
jmp get_key
|
||||||
end_of_teletype_remote
|
end_of_teletype_remote
|
||||||
|
|
||||||
; A9 FF 8D 81 C0 AD 11 D0
|
|
||||||
; 10 FB AD 10 D0 38 E9 A0
|
|
||||||
; 8D 81 C0 4C 85 02
|
|
||||||
|
|
||||||
; 0-255 repeating counter over TXD
|
; 0-255 repeating counter over TXD
|
||||||
* = $C400
|
* = $C500
|
||||||
.dsb (*-end_of_teletype_remote), 0
|
.dsb (*-end_of_teletype_remote), 0
|
||||||
|
|
||||||
* = $C400
|
* = $C500
|
||||||
counter_remote = $C400
|
counter_remote = $C500
|
||||||
ldy #$00
|
ldy #$00
|
||||||
sta serial_write
|
sta serial_write
|
||||||
check_ready
|
check_ready
|
||||||
@ -62,6 +54,3 @@ check_ready
|
|||||||
iny
|
iny
|
||||||
jmp check_ready
|
jmp check_ready
|
||||||
|
|
||||||
; A0 00 8D 81 C0 AD 00 C0
|
|
||||||
; F0 FB 98 8D 81 C0 C8 4C
|
|
||||||
; 85 02
|
|
||||||
|
Loading…
Reference in New Issue
Block a user