2003-04-15 20:47:29 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2003-04-15
|
|
|
|
;
|
|
|
|
; Common functions of the serial drivers
|
|
|
|
;
|
|
|
|
|
2013-06-01 09:03:14 +00:00
|
|
|
.import return0, ser_libref
|
2003-04-15 20:47:29 +00:00
|
|
|
.importzp ptr1
|
2013-05-09 11:56:54 +00:00
|
|
|
.interruptor ser_irq, 29 ; Export as high priority IRQ handler
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
.include "ser-kernel.inc"
|
|
|
|
.include "ser-error.inc"
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; Variables
|
|
|
|
|
|
|
|
|
|
|
|
.bss
|
2013-05-09 11:56:54 +00:00
|
|
|
_ser_drv: .res 2 ; Pointer to driver
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
; Jump table for the driver functions.
|
|
|
|
.data
|
|
|
|
ser_vectors:
|
2013-05-09 11:56:54 +00:00
|
|
|
ser_install: jmp return0
|
|
|
|
ser_uninstall: jmp return0
|
2003-08-22 11:23:48 +00:00
|
|
|
ser_open: jmp return0
|
|
|
|
ser_close: jmp return0
|
2003-04-18 16:29:51 +00:00
|
|
|
ser_get: jmp return0
|
|
|
|
ser_put: jmp return0
|
|
|
|
ser_status: jmp return0
|
2003-04-20 22:49:32 +00:00
|
|
|
ser_ioctl: jmp return0
|
2013-05-09 11:56:54 +00:00
|
|
|
ser_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
; Driver header signature
|
|
|
|
.rodata
|
2003-12-13 11:02:07 +00:00
|
|
|
ser_sig: .byte $73, $65, $72, SER_API_VERSION ; "ser", version
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
|
2006-03-31 20:07:43 +00:00
|
|
|
.code
|
2003-04-15 20:47:29 +00:00
|
|
|
;----------------------------------------------------------------------------
|
2021-05-16 20:57:28 +00:00
|
|
|
; unsigned char __fastcall__ ser_install (const void* driver);
|
2003-04-15 20:47:29 +00:00
|
|
|
; /* Install the driver once it is loaded */
|
|
|
|
|
|
|
|
|
|
|
|
_ser_install:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta _ser_drv
|
|
|
|
sta ptr1
|
|
|
|
stx _ser_drv+1
|
|
|
|
stx ptr1+1
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
; Check the driver signature
|
|
|
|
|
2003-12-13 11:02:07 +00:00
|
|
|
ldy #.sizeof(ser_sig)-1
|
2003-04-15 20:47:29 +00:00
|
|
|
@L0: lda (ptr1),y
|
|
|
|
cmp ser_sig,y
|
|
|
|
bne inv_drv
|
|
|
|
dey
|
|
|
|
bpl @L0
|
|
|
|
|
2013-06-01 09:03:14 +00:00
|
|
|
; Set the library reference
|
|
|
|
|
|
|
|
ldy #SER_HDR::LIBREF
|
|
|
|
lda #<ser_libref
|
|
|
|
sta (ptr1),y
|
|
|
|
iny
|
|
|
|
lda #>ser_libref
|
|
|
|
sta (ptr1),y
|
|
|
|
|
2003-04-15 20:47:29 +00:00
|
|
|
; Copy the jump vectors
|
|
|
|
|
2003-12-03 19:57:27 +00:00
|
|
|
ldy #SER_HDR::JUMPTAB
|
2003-04-15 20:47:29 +00:00
|
|
|
ldx #0
|
|
|
|
@L1: inx ; Skip the JMP opcode
|
|
|
|
jsr copy ; Copy one byte
|
|
|
|
jsr copy ; Copy one byte
|
2003-12-13 11:02:07 +00:00
|
|
|
cpy #(SER_HDR::JUMPTAB + .sizeof(SER_HDR::JUMPTAB))
|
2003-04-15 20:47:29 +00:00
|
|
|
bne @L1
|
|
|
|
|
2003-12-14 17:39:22 +00:00
|
|
|
jsr ser_install ; Call driver install routine
|
|
|
|
|
2003-12-14 18:57:08 +00:00
|
|
|
ldy ser_irq+2 ; Check high byte of IRQ vector
|
2003-12-14 17:39:22 +00:00
|
|
|
beq @L2 ; Jump if vector invalid
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #$4C ; Jump opcode
|
|
|
|
sty ser_irq ; Activate IRQ routine
|
2003-12-14 17:39:22 +00:00
|
|
|
@L2: rts
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
; Driver signature invalid
|
|
|
|
|
|
|
|
inv_drv:
|
|
|
|
lda #SER_ERR_INV_DRIVER
|
|
|
|
ldx #0
|
|
|
|
rts
|
|
|
|
|
|
|
|
; Copy one byte from the jump vectors
|
|
|
|
|
|
|
|
copy: lda (ptr1),y
|
|
|
|
sta ser_vectors,x
|
|
|
|
iny
|
|
|
|
inx
|
|
|
|
rts
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2012-03-04 13:08:54 +00:00
|
|
|
; unsigned char ser_uninstall (void);
|
2003-04-15 20:47:29 +00:00
|
|
|
; /* Uninstall the currently loaded driver and return an error code.
|
2014-06-30 09:10:35 +00:00
|
|
|
; ** Note: This call does not free allocated memory.
|
|
|
|
; */
|
2003-04-15 20:47:29 +00:00
|
|
|
|
|
|
|
_ser_uninstall:
|
|
|
|
jsr ser_uninstall ; Call driver routine
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$60 ; RTS opcode
|
|
|
|
sta ser_irq ; Disable IRQ entry point
|
2003-12-14 17:39:22 +00:00
|
|
|
|
2006-06-04 10:01:33 +00:00
|
|
|
_ser_clear_ptr: ; External entry point
|
2003-04-15 20:47:29 +00:00
|
|
|
lda #0
|
|
|
|
sta _ser_drv
|
|
|
|
sta _ser_drv+1 ; Clear the driver pointer
|
|
|
|
|
|
|
|
tax
|
|
|
|
rts ; Return zero
|