.include "atari.inc"
.include "../common/errno.inc"
+ .include "../common/rs232.inc"
.rodata
; using 8 bit word size. So only 8 bit is currently tested.
;
-; shouldn't this come from a "rs232.inc" ??
-ErrNotInitialized = $01
-ErrNoData = $04
-
.proc _rs232_params
sta tmp2
lda rshand
cmp #$ff
bne work ; work only if initialized
- lda #ErrNotInitialized
+ lda #RS_ERR_NOT_INITIALIZED
bne done
work: lda rshand
ldx #0
ldy rshand
cpy #$ff
bne work ; work only if initialized
- lda #ErrNotInitialized
+ lda #RS_ERR_NOT_INITIALIZED
bne nierr
work: sta ptr1
beq nix_da ; no input waiting...
; input is available: get it!
-
+
lda #GETCHR ; get raw bytes
sta ICCOM,x ; in command code
lda #0
sta (ptr1,x) ; return received byte
txa
rts
-
+
nierr: ldx #0
rts
-nix_da: lda #ErrNoData
+nix_da: lda #RS_ERR_NO_DATA
ldx #0
rts
ldy rshand
cpy #$ff
bne work ; work only if initialized
- lda #ErrNotInitialized
+ lda #RS_ERR_NOT_INITIALIZED
bne nierr
work: pha
.importzp ptr1, ptr2, tmp1, tmp2
.import popa, popax
.export _rs232_init, _rs232_params, _rs232_done, _rs232_get
- .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
+ .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
.include "c128.inc"
+ .include "../common/rs232.inc"
NmiExit = $ff33 ;exit address for nmi
RegControl = 3 ; Control register
RegClock = 7 ; Turbo232 external baud-rate generator
-; Error codes. Beware: The codes must match the codes in the C header file
-ErrNotInitialized = $01
-ErrBaudTooFast = $02
-ErrBaudNotAvail = $03
-ErrNoData = $04
-ErrOverflow = $05
.code
lda #$06
sta BaudCode
-;** return
- lda #$ff
- sta Initialized
- lda #$00
- tax
+; Done
+
+ ldx #$ff
+ stx Initialized
+ inx ; X = 0
+ txa ; A = 0
rts
;----------------------------------------------------------------------------
;
_rs232_params:
- jsr CheckInitialized ;** check initialized
- bcc @L1
- rts
+ bit Initialized
+ bmi @L1
+ jmp NotInitialized ; Return an error code
; Save new parity
beq @L3
cpx #4
bcs @L3
-@L2: lda #ErrBaudTooFast
- bne @L9
+@L2: lda #RS_ERR_BAUD_TOO_FAST
+ bne @L9
; Set baud/parameters
lda HackBauds,x
@L4: cmp #$ff
bne @L5
- lda #ErrBaudNotAvail
+ lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9
@L5: tax
and #$30
beq @L6
bit Turbo232
- bmi @L6
- lda #ErrBaudNotAvail
- bne @L9
+ bmi @L6
+ lda #RS_ERR_BAUD_NOT_AVAIL
+ bne @L9
@L6: lda tmp1
and #$0f
beq @L7
lsr
lsr
- lsr
+ lsr
lsr
eor #%00000011
sta ACIA+RegClock
@L9: lda #$00
sta Initialized
- tax
+ tax
rts
;----------------------------------------------------------------------------
;
_rs232_get:
- jsr CheckInitialized ; Check if initialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Check for bytes to send
@L1: sta ptr1
stx ptr1+1 ; Store pointer to received char
- ldx SendFreeCnt
+ ldx SendFreeCnt
cpx #$ff
beq @L2
lda #$00
@L2: lda RecvFreeCnt
cmp #$ff
bne @L3
- lda #ErrNoData
+ lda #RS_ERR_NO_DATA
ldx #0
rts
@L3: ldx Stopped
beq @L4
cmp #63
- bcc @L4
+ bcc @L4
lda #$00
sta Stopped
lda RtsOff
@L4: ldx RecvHead
lda RecvBuf,x
inc RecvHead
- inc RecvFreeCnt
+ inc RecvFreeCnt
ldx #$00
sta (ptr1,x)
txa ; Return code = 0
rts
+;----------------------------------------------------------------------------
+;
+; RS232 module not initialized
+
+NotInitialized:
+ lda #<RS_ERR_NOT_INITIALIZED
+ ldx #>RS_ERR_NOT_INITIALIZED
+ rts
+
;----------------------------------------------------------------------------
;
; unsigned char __fastcall__ rs232_put (char B);
;
_rs232_put:
- jsr CheckInitialized ; Check initialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Try to send
pha
lda #$00
jsr TryToSend
- pla
+ pla
; Put byte into send buffer & send
@L2: ldx SendFreeCnt
bne @L3
- lda #ErrOverflow
- ldx #$00
+ lda #RS_ERR_OVERFLOW
+ ldx #$00
rts
@L3: ldx SendTail
;
_rs232_pause:
-; Check initialized
- jsr CheckInitialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Assert flow control
; Delay for flow stop to be received
- ldx BaudCode
+ ldx BaudCode
lda PauseTimes,x
jsr DelayMs
;
_rs232_unpause:
-; Check initialized
- jsr CheckInitialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Re-enable rx interrupts & release flow control
@L1: lda #$00
sta Stopped
lda RtsOff
- ora #%00001000
+ ora #%00001000
sta ACIA+RegCommand
; Poll for stalled char & exit
;
_rs232_status:
- sta ptr2
- stx ptr2+1
- jsr popax
- sta ptr1
- stx ptr1+1
- jsr CheckInitialized
- bcs @L9
+ sta ptr2
+ stx ptr2+1
+ jsr popax
+ sta ptr1
+ stx ptr1+1
+ bit Initialized
+ bmi @L1
+ jmp NotInitialized
; Get status
- lda ACIA+RegStatus
+@L1: lda ACIA+RegStatus
ldy #0
sta (ptr1),y
jsr PollReceive ; bug-recovery hack
; Because of the C128 banking, the NMI handler must go into the non banked
; memory, since the ROM NMI entry point will switch to a configuration where
; only the lowest 16K of RAM are visible. We will place the NMI handler into
-; it's own segment and map this segment into the lower 16K in the linker
+; it's own segment and map this segment into the lower 16K in the linker
; config.
-
+
.segment "NMI"
NmiHandler:
lda #CC65_MMU_CFG ;(2)
- sta MMU_CR ;(4)
+ sta MMU_CR ;(4)
lda ACIA+RegStatus ;(4) ;status ;check for byte received
and #$08 ;(2)
beq @L9 ;(2*)
@L4: jmp NmiExit
@L9: jmp NmiContinue
-
-.code
-;----------------------------------------------------------------------------
-;
-; CheckInitialized - internal check if initialized
-; Set carry and an error code if not initialized, clear carry and do not
-; change any registers if initialized.
-;
-
-CheckInitialized:
- bit Initialized
- bmi @L1
- lda #ErrNotInitialized
- ldx #0
- sec
- rts
-
-@L1: clc
- rts
+.code
;----------------------------------------------------------------------------
; Try to send a byte. Internal routine. A = TryHard
.export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
.include "c64.inc"
+ .include "../common/rs232.inc"
NmiExit = $febc ;exit address for nmi
RegControl = 3 ; Control register
RegClock = 7 ; Turbo232 external baud-rate generator
-; Error codes. Beware: The codes must match the codes in the C header file
-ErrNotInitialized = $01
-ErrBaudTooFast = $02
-ErrBaudNotAvail = $03
-ErrNoData = $04
-ErrOverflow = $05
.code
lda #$06
sta BaudCode
-;** return
- lda #$ff
- sta Initialized
- lda #$00
- tax
+; Done
+
+ ldx #$ff
+ stx Initialized
+ inx ; X = 0
+ txa ; A = 0
rts
;----------------------------------------------------------------------------
;
_rs232_params:
- jsr CheckInitialized ;** check initialized
- bcc @L1
- rts
+ bit Initialized
+ bmi @L1
+ jmp NotInitialized ; Return an error code
; Save new parity
beq @L3
cpx #4
bcs @L3
-@L2: lda #ErrBaudTooFast
+@L2: lda #RS_ERR_BAUD_TOO_FAST
bne @L9
; Set baud/parameters
lda HackBauds,x
@L4: cmp #$ff
bne @L5
- lda #ErrBaudNotAvail
+ lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9
@L5: tax
beq @L6
bit Turbo232
bmi @L6
- lda #ErrBaudNotAvail
+ lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9
@L6: lda tmp1
;
_rs232_get:
- jsr CheckInitialized ; Check if initialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Check for bytes to send
-@L1: sta ptr1
+ sta ptr1
stx ptr1+1 ; Store pointer to received char
ldx SendFreeCnt
cpx #$ff
@L2: lda RecvFreeCnt
cmp #$ff
bne @L3
- lda #ErrNoData
+ lda #RS_ERR_NO_DATA
ldx #0
rts
txa ; Return code = 0
rts
+;----------------------------------------------------------------------------
+;
+; RS232 module not initialized
+
+NotInitialized:
+ lda #<RS_ERR_NOT_INITIALIZED
+ ldx #>RS_ERR_NOT_INITIALIZED
+ rts
+
;----------------------------------------------------------------------------
;
; unsigned char __fastcall__ rs232_put (char B);
;
_rs232_put:
- jsr CheckInitialized ; Check initialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Try to send
-@L1: ldx SendFreeCnt
+ ldx SendFreeCnt
cpx #$ff
beq @L2
pha
@L2: ldx SendFreeCnt
bne @L3
- lda #ErrOverflow
+ lda #RS_ERR_OVERFLOW
ldx #$00
rts
;
_rs232_pause:
-; Check initialized
- jsr CheckInitialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Assert flow control
-@L1: lda RtsOff
+ lda RtsOff
sta Stopped
sta ACIA+RegCommand
;
_rs232_unpause:
-; Check initialized
- jsr CheckInitialized
- bcc @L1
- rts
+ bit Initialized
+ bpl NotInitialized ; Jump if not initialized
; Re-enable rx interrupts & release flow control
stx ptr2+1
jsr popax
sta ptr1
- stx ptr1+1
- jsr CheckInitialized
- bcs @L9
+ stx ptr1+1
+ bit Initialized
+ bmi @L1
+ jmp NotInitialized
; Get status
- lda ACIA+RegStatus
+@L1: lda ACIA+RegStatus
ldy #0
sta (ptr1),y
jsr PollReceive ; bug-recovery hack
; Drop this char
-@L3: inc DropCnt+0 ;not time-critical
+@L3: inc DropCnt+0 ; not time-critical
bne @L4
inc DropCnt+1
bne @L4
@L4: jmp NmiExit
@L9: pla
- jmp NmiContinue
-
-;----------------------------------------------------------------------------
-;
-; CheckInitialized - internal check if initialized
-; Set carry and an error code if not initialized, clear carry and do not
-; change any registers if initialized.
-;
-
-CheckInitialized:
- bit Initialized
- bmi @L1
- lda #ErrNotInitialized
- ldx #0
- sec
- rts
-
-@L1: clc
- rts
+ jmp NmiContinue
;----------------------------------------------------------------------------
; Try to send a byte. Internal routine. A = TryHard
--- /dev/null
+;
+; rs232.inc
+;
+; (C) Copyright 2002 Ullrich von Bassewitz (uz@cc65.org)
+;
+
+; Assembler include file that makes the constants and structures from rs232.h
+; available for asm code.
+
+
+
+; Error codes returned by all functions
+RS_ERR_OK = $00 ; Not an error - relax
+RS_ERR_NOT_INITIALIZED = $01 ; Module not initialized
+RS_ERR_BAUD_TOO_FAST = $02 ; Cannot handle baud rate
+RS_ERR_BAUD_NOT_AVAIL = $03 ; Baud rate not available
+RS_ERR_NO_DATA = $04 ; Nothing to read
+RS_ERR_OVERFLOW = $05 ; No room in send buffer
+
+
+