Skip to content

Instantly share code, notes, and snippets.

@mnaberez
Created January 12, 2013 19:46
Show Gist options
  • Save mnaberez/4520170 to your computer and use it in GitHub Desktop.
Save mnaberez/4520170 to your computer and use it in GitHub Desktop.
P500 IEEE-488 read/write routines commented (based on the disassembly from http://www.von-bassewitz.de/uz/oldcomputers/p500/rom500.s.html)
;READ
; Output secondary address on IEEE-488 bus
tksa: jsr txbyte
tkatn: lda #$3D
and tpi1_pa
; Output A on IEEE-488, switch data to input
setlns: sta tpi1_pa
lda #%11000011 ;PA7 NRFD Output
;PA6 NDAC Output
;PA5 EOI Input
;PA4 DAV Input
;PA3 ATN Input
;PA2 REN Input
;PA1 TE Output
;PA0 DC Output
sta tpi1_ddra
lda #$00
sta cia2_ddra ;Data lines all inputs
beq secatn
; Read char from IEEE-488 bus into A
acptr: lda tpi1_pa
and #%10111101 ;Set PA1 (TE) = 0 (Talk enable off)
;Set PA6 (NDAC) = 0
ora #$10000001 ;Set PA7 (NRFD) = 1
;Set PA0 (DC) = 1 (Direction = Receive)
sta tpi1_pa
LF31B: jsr timeron
bcc LF321
LF320: sec
LF321: lda tpi1_pa
and #%00010000 ;Mask off all but PA4 (DAV)
beq LF346 ;DAV = 0? Branch to LF346
lda cia2_icr
and #$02
beq LF321
lda timout
bmi LF31B
bcc LF320 ;Timeout related
lda #$02
jsr udst ;Status related
lda tpi1_pa
and #%00111101
sta tpi1_pa ;Set PA1 (TE) = 0
;Set PA6 (NDAC) = 0
;Set PA7 (NRFD) = 0
lda #$0D
rts
LF346: lda tpi1_pa
and #%01111111
sta tpi1_pa ;PA7 (NRFD) = 0
and #%00100000 ;Mask off all but PA5 (EOI)
bne LF357
lda #$40
jsr udst ;ORA with status byte
LF357: lda cia2_pra ;Read data byte from IEEE lines
eor #$FF ;Invert it
pha
lda tpi1_pa
ora #%01000000 ;PA6 (NDAC) = 1
sta tpi1_pa
LF365: lda tpi1_pa
and #%00010000 ;Mask off all but PA4 (DAV)
beq LF365 ;Wait until DAV = 1
lda tpi1_pa
and #%10111111 ;PA6 (NDAC) = 0
sta tpi1_pa
pla
rts
;WRITE
;Output listen on IEEE-488 bus
listn: ora #$20
LF23D: pha
lda #%00111011 ;PA7 NRFD Input
;PA6 NDAC Input
;PA5 EOI Output
;PA4 DAV Output
;PA3 ATN Output
;PA2 REN Input
;PA1 TE Output
;PA0 DC Output
sta tpi1_ddra
lda #$FF
sta cia2_pra
sta cia2_ddra ;Data lines all outputs
lda #$FE
sta tpi1_pa ;Set EOI=1, DAV=1, ATN=1, TE=1, DC=0
; Output A on IEEE-488 without EOF flag
txbyte: eor #$FF ;Invert the byte
sta cia2_pra ;Put it on IEEE data lines
lda tpi1_pa
ora #%00010010
sta tpi1_pa ;Set PA1 (TE) = 1 (Talk enable on)
;Set PA4 (DAV) = 1
bit tpi1_pa
bvc txbyt1 ;Is PA6 (NDAC) = 1? goto txbyt1
bpl txbyt1 ;Is PA7 (NRFD) = 0? goto txbyt1
lda #$80
jsr udst ;ORA with status byte
bne txbyt4
txbyt1: lda tpi1_pa
bpl txbyt1 ;Wait for NRFD to go to 1
and #%11101111
sta tpi1_pa ;PA4 (DAV) := 0
txbyt2: jsr timeron
bcc txbyt4
txbyt3: sec
txbyt4: bit tpi1_pa
bvs txbyt4 ;Wait for PA6 (NDAC) to go to 0
lda cia2_icr
and #$02
beq txbyt4
lda timout
bmi txbyt2
bcc txbyt3
lda #$01
jsr udst ;ORA with status byte
txbyt4: lda tpi1_pa
ora #$00010000
sta tpi1_pa ;Set PA1 (DAV) = 1
txbyt4: lda #$FF
sta cia2_pra ;Release IEEE data lines
rts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment