-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathw65c265sxb.asm
131 lines (108 loc) · 4.96 KB
/
w65c265sxb.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
;==============================================================================
; __ ____ ____ ____ ____ __ ____ ______ ______
; \ \ / / /_| ___| / ___|___ \ / /_| ___/ ___\ \/ / __ )
; \ \ /\ / / '_ \___ \| | __) | '_ \___ \___ \\ /| _ \
; \ V V /| (_) |__) | |___ / __/| (_) |__) |__) / \| |_) |
; \_/\_/ \___/____/ \____|_____|\___/____/____/_/\_\____/
;
; Application Startup Code for the W65C265SXB Development Board
;------------------------------------------------------------------------------
; Copyright (C)2015 HandCoded Software Ltd.
; All rights reserved.
;
; This work is made available under the terms of the Creative Commons
; Attribution-NonCommercial-ShareAlike 4.0 International license. Open the
; following URL to see the details.
;
; http://creativecommons.org/licenses/by-nc-sa/4.0/
;
;==============================================================================
; Notes:
;
;------------------------------------------------------------------------------
pw 132
inclist on
chip 65816
include "w65c816.inc"
include "w65c265.inc"
include "w65c265sxb.inc"
;==============================================================================
; Configuration
;------------------------------------------------------------------------------
BAUD_RATE equ 19200 ; ACIA baud rate
BRG_VALUE equ OSC_FREQ/(16*BAUD_RATE)-1
if BRG_VALUE&$ffff0000
messg "BRG_VALUE does not fit in 16-bits"
endif
;==============================================================================
; Power On Reset
;------------------------------------------------------------------------------
code
extern Start
longi off
longa off
RESET:
sei ; Disable interrupts
native ; Switch to native mode
long_i
ldx #$01ff ; Reset the stack
txs
stz UIER
lda #$c0 ; Ensure A15/AMS are output
sta PDD4
stz PD4 ; And select bank 0
lda #%00010000 ; Set UART0 to use timer 3
trb TCR
lda #<BRG_VALUE ; And set baud rate
sta T3CL
lda #>BRG_VALUE
sta T3CH
lda #1<<3 ; Enable timer 3
tsb TER
lda #%00100101 ; Set UART0 for 8-N-1
sta ACSR0
jmp Start ; Jump to the application start
;==============================================================================
; UART Interface
;------------------------------------------------------------------------------
; Wait until the last transmission has been completed then send the character
; in A.
public UartTx
UartTx:
pha ; Save the character
php ; Save register sizes
short_a ; Make A 8-bits
pha
lda #1<<1
TxWait: bit UIFR ; Has last transmit finished?
beq TxWait ; No.
pla
sta ARTD0 ; Transmit the character
plp ; Restore register sizes
pla ; And callers A
rts ; Done
; Fetch the next character from the receive buffer waiting for some to arrive
; if the buffer is empty.
public UartRx
UartRx:
php ; Save register sizes
short_a ; Make A 8-bits
lda #1<<0
RxWait: bit UIFR ; Any data in RX buffer?
beq RxWait ; No
lda ARTD0 ; Yes, read it
plp ; Restore register sizes
rts ; Done
; Check if the receive buffer contains any data and return C=1 if there is
; some.
public UartRxTest
UartRxTest:
pha ; Save callers A
php
short_a
lda UIFR ; Read the status register
plp
ror a ; Shift UART0R bit into carry
pla ; Restore A
rts ; Done
end