forked from mist64/msbasic
-
Notifications
You must be signed in to change notification settings - Fork 24
/
bios.s
133 lines (114 loc) · 3.04 KB
/
bios.s
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
132
.setcpu "65C02"
.debuginfo
.zeropage
.org ZP_START0
READ_PTR: .res 1
WRITE_PTR: .res 1
.segment "INPUT_BUFFER"
INPUT_BUFFER: .res $100
.segment "BIOS"
ACIA_DATA = $5000
ACIA_STATUS = $5001
ACIA_CMD = $5002
ACIA_CTRL = $5003
PORTA = $6001
DDRA = $6003
LOAD:
rts
SAVE:
rts
; Input a character from the serial interface.
; On return, carry flag indicates whether a key was pressed
; If a key was pressed, the key value will be in the A register
;
; Modifies: flags, A
MONRDKEY:
CHRIN:
phx
jsr BUFFER_SIZE
beq @no_keypressed
jsr READ_BUFFER
jsr CHROUT ; echo
pha
jsr BUFFER_SIZE
cmp #$B0
bcs @mostly_full
lda #$fe
and PORTA
sta PORTA
@mostly_full:
pla
plx
sec
rts
@no_keypressed:
plx
clc
rts
; Output a character (from the A register) to the serial interface.
;
; Modifies: flags
MONCOUT:
CHROUT:
pha
sta ACIA_DATA
lda #$FF
@txdelay: dec
bne @txdelay
pla
rts
; Initialize the circular input buffer
; Modifies: flags, A
INIT_BUFFER:
lda READ_PTR
sta WRITE_PTR
lda #$01
sta DDRA
lda #$fe
and PORTA
sta PORTA
rts
; Write a character (from the A register) to the circular input buffer
; Modifies: flags, X
WRITE_BUFFER:
ldx WRITE_PTR
sta INPUT_BUFFER,x
inc WRITE_PTR
rts
; Read a character from the circular input buffer and put it in the A register
; Modifies: flags, A, X
READ_BUFFER:
ldx READ_PTR
lda INPUT_BUFFER,x
inc READ_PTR
rts
; Return (in A) the number of unread bytes in the circular input buffer
; Modifies: flags, A
BUFFER_SIZE:
lda WRITE_PTR
sec
sbc READ_PTR
rts
; Interrupt request handler
IRQ_HANDLER:
pha
phx
lda ACIA_STATUS
; For now, assume the only source of interrupts is incoming data
lda ACIA_DATA
jsr WRITE_BUFFER
jsr BUFFER_SIZE
cmp #$F0
bcc @not_full
lda #$01
ora PORTA
sta PORTA
@not_full:
plx
pla
rti
.include "wozmon.s"
.segment "RESETVEC"
.word $0F00 ; NMI vector
.word RESET ; RESET vector
.word IRQ_HANDLER ; IRQ vector