-
Notifications
You must be signed in to change notification settings - Fork 3
/
dwwrite.asm
58 lines (52 loc) · 2.27 KB
/
dwwrite.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
*******************************************************
*
* DWWrite
* Send a packet to the DriveWire server.
* Serial data format: 1-8-N-1
* 4/12/2009 by Darren Atkinson
*
* Entry:
* X = starting address of data to send
* Y = number of bytes to send
*
* Exit:
* X = address of last byte sent + 1
* Y = 0
* All others preserved
*
*******************************************************
* 57600 (115200) bps using 6809 code and timimg
*******************************************************
DWWrite_hs
pshs dp,d,cc ; preserve registers
IFEQ NOINTMASK
orcc #IntMasks ; mask interrupts
ENDC
ldd #$04ff ; A = loop counter, B = $ff
tfr b,dp ; set direct page to $FFxx
setdp $ff
ldb <$ff23 ; read PIA 1-B control register
andb #$f7 ; clear sound enable bit
stb <$ff23 ; disable sound output
fcb $8c ; skip next instruction
txByte@ stb <BBOUT ; send stop bit
ldb ,x+ ; get a byte to transmit
nop
lslb ; left rotate the byte two positions..
rolb ; ..placing a zero (start bit) in bit 1
tx0020 stb <BBOUT ; send bit (start bit, d1, d3, d5)
rorb ; move next bit into position
exg a,a
nop
stb <BBOUT ; send bit (d0, d2, d4, d6)
rorb ; move next bit into position
leau ,u
deca ; decrement loop counter
bne tx0020 ; loop until 7th data bit has been sent
stb <BBOUT ; send bit 7
ldd #$0402 ; A = loop counter, B = MARK value
leay ,-y ; decrement byte counter
bne txByte@ ; loop if more to send
stb <BBOUT ; leave bit banger output at MARK
puls cc,d,dp,pc ; restore registers and return
setdp $00