Interreupt handling

This commit is contained in:
Paul Warren 2020-08-02 22:46:31 +10:00
parent 83204c0882
commit 57b380829d
1 changed files with 187 additions and 0 deletions

187
interrupt.s Normal file
View File

@ -0,0 +1,187 @@
PORTB = $6000
PORTA = $6001
DDRB = $6002
DDRA = $6003
value = $0200 ; 2 bytes
mod10 = $0202 ; 2 bytes
message = $0204 ; 6 bytes
counter = $020a ; 2 bytes
E = %10000000
RW = %01000000
RS = %00100000
.org $8000
reset:
ldx #$ff
txs
cli
lda #%11111111 ; Set all pins on port B to output
sta DDRB
lda #%11100000 ; Set top 3 pins on port A to output
sta DDRA
lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr send_inst
lda #%00001110 ; Display on; cursor on; blink off
jsr send_inst
lda #%00000001 ; Reset display
jsr send_inst
lda #%00000110 ; Increment and shift cursor; don't shift display
jsr send_inst
loop:
lda#%00000010 ; home the cursor
jsr send_inst
lda #0
sta message
;; initialize value to the conversion number
sei
lda counter
sta value
lda counter + 1
sta value + 1
cli
divide:
;; initialse remainder to zero
lda #0
sta mod10
sta mod10 + 1
clc
ldx #16
divloop:
;; rotate the quotient
rol value
rol value + 1
rol mod10
rol mod10 + 1
;; a,y = dividend = divisor
sec
lda mod10
sbc #10
tay ; save low byte in Y
lda mod10 + 1
sbc #0
bcc ignore_result ; branch if dividend < divosr
sty mod10
sta mod10 + 1
ignore_result:
dex
bne divloop
rol value ; shift in last bit of quotient
rol value + 1
lda mod10
clc
adc #"0"
jsr push_char
;; if value != 0 continue dividing
lda value
ora value + 1
bne divide
ldx #0
print:
lda message,x
beq loop
jsr send_data
inx
jmp print
;; add character in A to start of message
push_char:
pha ; Push first char on stack
ldy #0
char_loop:
lda message,y ; get char on string and put in X
tax
pla
sta message,y ; pull char off stack and add it to the string
iny
txa
pha ; put char from string and put it back
bne char_loop
pla
sta message,y ; Pull null off stack stuff on end of string
rts
lcd_wait:
pha
lda #%00000000 ; PORT B to INPUT
sta DDRB
lcd_busy:
lda #RW
sta PORTA
lda #(RW | E)
sta PORTA
lda PORTB
and #%10000000
bne lcd_busy
lda #RW
sta PORTA
lda #%11111111 ; PORT B to output
sta DDRB
pla
rts
send_inst:
jsr lcd_wait
sta PORTB
lda #0 ; Clear RS/RW/E bits
sta PORTA
lda #E ; Set E bit to send instruction
sta PORTA
lda #0 ; Clear RS/RW/E bits
sta PORTA
rts
send_data:
jsr lcd_wait
sta PORTB
lda #RS ; Set RS; Clear RW/E bits
sta PORTA
lda #(RS | E) ; Set E bit to send instruction
sta PORTA
lda #RS ; Clear E bits
sta PORTA
rts
nmi:
irq:
inc counter
bne exit_irq
inc counter + 1
exit_irq:
rti
.org $fffa
.word nmi
.word reset
.word irq
.word $0000