From: cuz Date: Fri, 15 Aug 2003 21:17:36 +0000 (+0000) Subject: Working on the serial driver X-Git-Tag: V2.12.0~1407 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5efa39491a4d32ee5f5ab8cd80938aaea208060e;p=cc65 Working on the serial driver git-svn-id: svn://svn.cc65.org/cc65/trunk@2329 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/.cvsignore b/libsrc/.cvsignore index 0b9fd880a..66bfccb41 100644 --- a/libsrc/.cvsignore +++ b/libsrc/.cvsignore @@ -1,4 +1,5 @@ *.emd *.joy *.lib +*.ser *.tgi diff --git a/libsrc/Makefile b/libsrc/Makefile index 01f1d4da6..625767ea7 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -129,6 +129,7 @@ c64lib: mv c64/crt0.o c64.o cp c64/*.emd . cp c64/*.joy . + cp c64/*.ser . cp c64/c64-320-200-2.tgi c64-hi.tgi #----------------------------------------------------------------------------- diff --git a/libsrc/c64/Makefile b/libsrc/c64/Makefile index 246f4773e..07bf76618 100644 --- a/libsrc/c64/Makefile +++ b/libsrc/c64/Makefile @@ -21,6 +21,9 @@ %.joy: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ +%.ser: %.o ../runtime/zeropage.o + @$(LD) -t module -o $@ $^ + %.tgi: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ @@ -55,6 +58,8 @@ EMDS = c64-georam.emd c64-ram.emd c64-ramcart.emd c64-reu.emd c64-vdc.emd JOYS = c64-stdjoy.joy +SERS = c64-swlink.ser + TGIS = c64-320-200-2.tgi #-------------------------------------------------------------------------- @@ -62,14 +67,14 @@ TGIS = c64-320-200-2.tgi .PHONY: all clean zap -all: $(OBJS) $(EMDS) $(JOYS) $(TGIS) +all: $(OBJS) $(EMDS) $(JOYS) $(SERS) $(TGIS) ../runtime/zeropage.o: $(MAKE) -C $(dir $@) $(notdir $@) clean: - @rm -f $(OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(TGIS:.tgi=.o) + @rm -f $(OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(SERS:.ser=.o) $(TGIS:.tgi=.o) zap: clean - @rm -f $(EMDS) $(JOYS) $(TGIS) + @rm -f $(EMDS) $(JOYS) $(SERS) $(TGIS) diff --git a/libsrc/c64/c64-swlink.s b/libsrc/c64/c64-swlink.s index 3fc4055e6..ca83d3cd0 100644 --- a/libsrc/c64/c64-swlink.s +++ b/libsrc/c64/c64-swlink.s @@ -65,10 +65,8 @@ ACIA_CLOCK = ACIA+7 ; Turbo232 external baud-rate generator ; .bss -DropCnt: .res 4 ; Number of bytes lost from rx buffer full Stopped: .res 1 ; Flow-stopped flag RtsOff: .res 1 ; -Errors: .res 1 ; Number of bytes received in error, low byte RecvHead: .res 1 ; Head of receive buffer RecvTail: .res 1 ; Tail of receive buffer RecvFreeCnt: .res 1 ; Number of bytes in receive buffer @@ -95,15 +93,15 @@ BaudTable: ; bit7 = 1 means setting is invalid .byte $FF ; SER_BAUD_75 .byte $FF ; SER_BAUD_110 .byte $FF ; SER_BAUD_134_5 - .byte $FF ; SER_BAUD_150 + .byte $02 ; SER_BAUD_150 .byte $05 ; SER_BAUD_300 .byte $06 ; SER_BAUD_600 .byte $07 ; SER_BAUD_1200 .byte $FF ; SER_BAUD_1800 .byte $08 ; SER_BAUD_2400 - .byte $FF ; SER_BAUD_3600 + .byte $09 ; SER_BAUD_3600 .byte $0A ; SER_BAUD_4800 - .byte $FF ; SER_BAUD_7200 + .byte $0B ; SER_BAUD_7200 .byte $0C ; SER_BAUD_9600 .byte $0E ; SER_BAUD_19200 .byte $0F ; SER_BAUD_38400 @@ -128,11 +126,6 @@ ParityTable: .byte $A0 ; SER_PAR_MARK .byte $E0 ; SER_PAR_SPACE -HandshakeTable: ; bit7 = 1 means that setting is invalid - .byte $FF ; SER_HS_NONE - .byte $00 ; SER_HS_HW - .byte $FF ; SER_HS_SW - ; Delay times: 32 byte-receive times in milliseconds, or 100 max. ; Formula = 320,000 / baud. Invalid values do contain $FF. PauseTimes: @@ -167,18 +160,22 @@ PauseTimes: INSTALL: +; Deactivate DTR and disable 6551 interrupts + + lda #%00001010 + sta ACIA_CMD + ; Initialize buffers & control -@L4: lda #0 - sta RecvHead - sta SendHead - sta RecvTail - sta SendTail - sta Errors - sta Stopped - lda #255 - sta RecvFreeCnt - sta SendFreeCnt +@L4: ldx #0 + stx RecvHead + stx SendHead + stx RecvTail + stx SendTail + stx Stopped + dex ; X = 255 + stx RecvFreeCnt + stx SendFreeCnt ; Set up nmi's @@ -188,27 +185,13 @@ INSTALL: sty NmiSave+1 lda #NmiHandler - sta NMIVec +SetNMI: sta NMIVec sty NMIVec+1 -; Set default to 2400-8N1, enable interrupts - - lda ACIA_DATA - lda ACIA_STATUS - lda #$18 - sta ACIA_CTRL - - lda #$01 - sta RtsOff - ora #$08 - sta ACIA_CMD - lda #$06 - sta BaudCode - ; Done, return an error code - lda #SER_ERR_OK - tax + lda #SER_ERR_INIT_FAILED + rts -.rodata +; Baud rate not available -BaudTable: - .byte $ff,$ff,$ff,$05,$06,$07,$08,$0a,$0c,$0e,$0f,$10,$20,$30,$ff,$ff - ;in: 0 1 2 3 4 5 6 7 8 9 a b c d e f - ;baud50 110 134 3 6 12 24 48 96 19 38 57 115 230 exp exp - ;out masks: $0F=Baud, val$FF=err - ; $30=t232ExtBaud: $00=none, $10=57.6, $20=115.2, $30=230.4 -.code +InvBaud: + lda #SER_ERR_BAUD_UNAVAIL + rts ;---------------------------------------------------------------------------- ; GET: Will fetch a character from the receive buffer and store it into the @@ -394,7 +293,7 @@ GET: ; Check for bytes to send ldx SendFreeCnt - cpx #$ff + inx ; X == $FF? beq @L1 lda #$00 jsr TryToSend @@ -404,8 +303,8 @@ GET: @L1: lda RecvFreeCnt ; (25) cmp #$ff bne @L2 - lda #SER_ERR_NO_DATA - ldx #0 + lda #SER_ERR_NO_DATA rts ; Check for flow stopped & enough free: release flow control @@ -432,7 +331,7 @@ GET: rts ;---------------------------------------------------------------------------- -; PUT: Output character in A. +; PUT: Output character in A. ; Must return an error code in a/x. ; @@ -441,7 +340,7 @@ PUT: ; Try to send ldx SendFreeCnt - cpx #$ff + inx ; X = $ff? beq @L2 pha lda #$00 @@ -487,7 +386,7 @@ PAUSE: ; Stop rx interrupts lda RtsOff - ora #$02 + ora #%00000010 ; Disable interrupts sta ACIA_CMD lda #SER_ERR_INV_IOCTL + rts + ;---------------------------------------------------------------------------- ; ; NMI handler @@ -548,46 +455,31 @@ STATUS: NmiHandler: pha - lda ACIA_STATUS ;(4) ;status ;check for byte received - and #$08 ;(2) - beq @L9 ;(2*) + lda ACIA_STATUS ;(4) ;status ;check for byte received + and #$08 ;(2) + beq @L9 ;(2*) cld txa pha tya pha - lda ACIA_STATUS ;(4) opt ;status ;check for receive errors - and #$07 ;(2) opt - beq @L1 ;(3*)opt - inc Errors ;(5^)opt -@L1: lda ACIA_DATA ;(4) ;data ;get byte and put into receive buffer - ldy RecvTail ;(4) - ldx RecvFreeCnt ;(4) - beq @L3 ;(2*) - sta RecvBuf,y ;(5) - inc RecvTail ;(6) - dec RecvFreeCnt ;(6) - cpx #33 ;(2) ;check for buffer space low - bcc @L2 ;(2*) - jmp NMIEXIT ;(3) +@L1: lda ACIA_DATA ;(4) data ;get byte and put into receive buffer + ldy RecvTail ;(4) + ldx RecvFreeCnt ;(4) + beq @L3 ;(2*) Jump if no space in receive buffer + sta RecvBuf,y ;(5) + inc RecvTail ;(6) + dec RecvFreeCnt ;(6) + cpx #33 ;(2) check for buffer space low + bcc @L2 ;(2*) + jmp NMIEXIT ;(3) ; Assert flow control -@L2: lda RtsOff ;(3) ;assert flow control if buffer space too low - sta ACIA_CMD ;(4) ;command - sta Stopped ;(3) - jmp NMIEXIT ;(3) - -; Drop this char - -@L3: inc DropCnt+0 ; not time-critical - bne @L4 - inc DropCnt+1 - bne @L4 - inc DropCnt+2 - bne @L4 - inc DropCnt+3 -@L4: jmp NMIEXIT +@L2: lda RtsOff ;(3) assert flow control if buffer space too low + sta ACIA_CMD ;(4) command + sta Stopped ;(3) +@L3: jmp NMIEXIT ;(3) @L9: pla jmp NmiContinue