base:rs232silversurfer.s
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:rs232silversurfer.s [2015-04-17 04:33] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== silver surfer polling mode driver for cc65 ====== | ||
+ | < | ||
+ | ; | ||
+ | ; silver surfer polling mode driver for cc65 | ||
+ | ; - work from here to create a full featured driver with interupts. | ||
+ | ; gpz fixed 20020828: fatal bug fixed in _ss232_params | ||
+ | ; | ||
+ | .include " | ||
+ | |||
+ | .export _ss232_init | ||
+ | .export _ss232_done | ||
+ | .export _ss232_params | ||
+ | .export _ss232_put | ||
+ | .export _ss232_get | ||
+ | |||
+ | .importzp ptr1, ptr2 | ||
+ | .import | ||
+ | |||
+ | ; | ||
+ | ; Error codes. Beware: The codes must match the codes in the C header file | ||
+ | |||
+ | ErrNotInitialized | ||
+ | ErrBaudTooFast | ||
+ | ErrBaudNotAvail | ||
+ | ErrNoData | ||
+ | ErrOverflow | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_init (char hacked); | ||
+ | ;/* Initialize the serial port, install the interrupt handler. The parameter | ||
+ | ; * has no effect for now and should be set to 0. | ||
+ | ; */ | ||
+ | ; | ||
+ | |||
+ | .code | ||
+ | |||
+ | _ss232_init: | ||
+ | ; enable ssurfer-port | ||
+ | lda $de01 | ||
+ | ora #$01 | ||
+ | sta $de01 | ||
+ | |||
+ | ; disable nmi's from ssurfer | ||
+ | lda #%00000000 | ||
+ | sta fifo_ier | ||
+ | |||
+ | ; activate dtr | ||
+ | lda #%00000001 | ||
+ | sta fifo_mcr | ||
+ | |||
+ | lda #$00 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_done (void); | ||
+ | ;/* Close the port, deinstall the interrupt hander. You MUST call this function | ||
+ | ; * before terminating the program, otherwise the machine may crash later. If | ||
+ | ; * in doubt, install an exit handler using atexit(). The function will do | ||
+ | ; * nothing, if it was already called. | ||
+ | ; */ | ||
+ | ; | ||
+ | |||
+ | _ss232_done: | ||
+ | ; disable nmi's from ssurfer | ||
+ | lda #%00000000 | ||
+ | sta fifo_ier | ||
+ | |||
+ | ; deactivate dtr | ||
+ | sta fifo_mcr | ||
+ | |||
+ | ; disable ssurfer-port | ||
+ | lda $de01 | ||
+ | and #$fe | ||
+ | sta $de01 | ||
+ | |||
+ | lda #$00 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity); | ||
+ | ;/* Set the port parameters. Use a combination of the #defined values above. */ | ||
+ | ; | ||
+ | |||
+ | .data | ||
+ | |||
+ | _ss232_baudrates: | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | .bss | ||
+ | |||
+ | _ss232_tmp1: | ||
+ | .res 1 | ||
+ | |||
+ | .code | ||
+ | |||
+ | _ss232_params: | ||
+ | |||
+ | sta _ss232_tmp1 ; save parity | ||
+ | |||
+ | ; reset fifo | ||
+ | lda #%10000111 | ||
+ | sta fifo_fcr | ||
+ | |||
+ | ; that delay thing really needed ?! | ||
+ | ; (original datasheet mentions a delay here) | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | |||
+ | ; set dlab | ||
+ | lda #%10000011 ; we assmume 8n1 | ||
+ | sta fifo_lcr | ||
+ | |||
+ | jsr popa | ||
+ | | ||
+ | |||
+ | ; set baudrate | ||
+ | clc | ||
+ | lsr a | ||
+ | lsr a | ||
+ | lsr a | ||
+ | lsr a | ||
+ | asl a | ||
+ | tax | ||
+ | lda _ss232_baudrates, | ||
+ | sta fifo_dll | ||
+ | lda _ss232_baudrates+1, | ||
+ | sta fifo_dlm | ||
+ | |||
+ | | ||
+ | and #$0f | ||
+ | ora _ss232_tmp1 ; parity | ||
+ | |||
+ | ; reset dlab | ||
+ | sta fifo_lcr | ||
+ | |||
+ | lda #$00 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ; check if byte available, returns AKKU=0 if none | ||
+ | |||
+ | ss_getlsr: | ||
+ | lda fifo_lsr | ||
+ | and #$01 | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_get (char* b); | ||
+ | ;/* Get a character from the serial port. If no characters are available, the | ||
+ | ; * function will return RS_ERR_NO_DATA, | ||
+ | ; */ | ||
+ | ; | ||
+ | ; get byte (non blocking, returns byte in A or CARRY=1 - error) | ||
+ | |||
+ | _ss232_get: | ||
+ | sta ptr1 | ||
+ | stx ptr1+1 | ||
+ | |||
+ | jsr ss_getlsr | ||
+ | ; bne sk32 ; yes | ||
+ | bne sk33 ; yes | ||
+ | |||
+ | ; activate rts | ||
+ | lda #%00000011 | ||
+ | sta fifo_mcr | ||
+ | sk32: | ||
+ | |||
+ | ; deactivate rts | ||
+ | ; lda #%00000001 | ||
+ | ; sta fifo_mcr | ||
+ | |||
+ | jsr ss_getlsr | ||
+ | bne sk33 ; yes | ||
+ | |||
+ | ; deactivate rts | ||
+ | lda #%00000001 | ||
+ | sta fifo_mcr | ||
+ | |||
+ | lda # | ||
+ | ldx #0 | ||
+ | rts | ||
+ | sk33: | ||
+ | ; deactivate rts | ||
+ | lda #%00000001 | ||
+ | sta fifo_mcr | ||
+ | |||
+ | ; get byte | ||
+ | ldy #$00 | ||
+ | lda fifo_rxd | ||
+ | sta (ptr1),y | ||
+ | |||
+ | lda #0 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_put (char b); | ||
+ | ;/* Send a character via the serial port. There is a transmit buffer, but | ||
+ | ; * transmitting is not done via interrupt. The function returns | ||
+ | ; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer. | ||
+ | ; */ | ||
+ | ; | ||
+ | |||
+ | _ss232_put: | ||
+ | tax | ||
+ | ; transmit buf ready? | ||
+ | lda fifo_lsr | ||
+ | and #%00100000 | ||
+ | bne @sk1 | ||
+ | @sk2: | ||
+ | lda # | ||
+ | ldx #$00 | ||
+ | rts | ||
+ | @sk1: | ||
+ | ; reciever ready? | ||
+ | lda fifo_msr | ||
+ | and #%00010000 | ||
+ | beq @sk2 | ||
+ | |||
+ | stx fifo_txd | ||
+ | |||
+ | lda #$00 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_pause (void); | ||
+ | ;/* Assert flow control and disable interrupts. */ | ||
+ | ; | ||
+ | |||
+ | _ss232_pause: | ||
+ | ; activate rts | ||
+ | lda #%00000011 | ||
+ | sta fifo_mcr | ||
+ | |||
+ | lda #$00 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_unpause (void); | ||
+ | ;/* Re-enable interrupts and release flow control */ | ||
+ | ; | ||
+ | |||
+ | _ss232_unpause: | ||
+ | ; deactivate rts | ||
+ | lda #%00000001 | ||
+ | sta fifo_mcr | ||
+ | |||
+ | lda #$00 ; ok | ||
+ | tax | ||
+ | rts | ||
+ | |||
+ | ; | ||
+ | ;unsigned char __fastcall__ rs232_status (unsigned char* status, | ||
+ | ; | ||
+ | ;/* Return the serial port status. */ | ||
+ | ; | ||
+ | |||
+ | _ss232_status: | ||
+ | sta ptr2 | ||
+ | stx | ||
+ | jsr popax | ||
+ | sta ptr1 | ||
+ | stx | ||
+ | |||
+ | ldy #$00 | ||
+ | |||
+ | ; Get status | ||
+ | lda | ||
+ | and # | ||
+ | sta | ||
+ | lda | ||
+ | lsr a | ||
+ | and # | ||
+ | ora | ||
+ | sta | ||
+ | lda | ||
+ | and # | ||
+ | ora | ||
+ | sta | ||
+ | |||
+ | ; Get errors | ||
+ | lda # | ||
+ | sta | ||
+ | |||
+ | lda # | ||
+ | tax | ||
+ | rts | ||
+ | </ |
base/rs232silversurfer.s.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1