6502-OS/main.s65

191 lines
3.7 KiB
Plaintext
Raw Normal View History

2023-10-27 16:50:58 +02:00
.segment "CODE"
2023-10-26 19:51:20 +02:00
.include "system/system.h65"
2023-10-30 22:17:19 +01:00
.macro DEBUG_LED_OFF nr
lda IO1 + IO_RA
.if nr = 0
and #%11111110
.else
and #%11111101
.endif
sta IO1 + IO_RA
.endmacro
.macro DEBUG_LED_ON nr
lda IO1 + IO_RA
.if nr = 0
ora #%00000001
.else
ora #%00000010
.endif
sta IO1 + IO_RA
.endmacro
2023-10-28 03:48:27 +02:00
;********************************************************************************
; Modules
;********************************************************************************
; LCD
; .include "utility.asm6502"
LCD_IO = IO1
.include "lcd.s65"
; Keypad Reading
2023-10-30 22:17:19 +01:00
KP_IO = IO2
2023-10-28 03:48:27 +02:00
.include "keypad.s65"
2023-10-30 22:17:19 +01:00
; SPI
SPI_IO = IO1
.include "system/spi.s65"
2023-10-28 03:48:27 +02:00
; Printer
.include "printer.s65"
; Digital Humidity and Temerature Sensor
; .include "dht.s65"
2023-10-30 22:17:19 +01:00
2023-10-26 19:51:20 +02:00
;********************************************************************************
; Interrupts
;********************************************************************************
nmi:
2023-10-27 16:50:58 +02:00
lda #'%'
jsr _lcd_char
2023-10-26 19:51:20 +02:00
rti
irq:
2023-10-30 22:17:19 +01:00
; read IRFs, while bit 7 ist set handle interrupts
; Print str_irq
@irq_io1:
; todo use a reserved address instead of 0
lda IO1+IO_IFR
sta 0
bbr7 0,@irq_io2
bbs2 0,@irq_spi_p ; check SR
@irq_io2:
2023-10-26 19:51:20 +02:00
lda IO2+IO_IFR
sta 0
2023-10-30 22:17:19 +01:00
bbr7 0,@irq_return
bbs4 0,@irq_keypad ; check CB1
; this should never be reached
Print str_irq_unknown
; force reset interrupt flags
lda #$ff
sta IO1 + IO_IFR
sta IO2 + IO_IFR
bra @irq_return
@irq_keypad:
jsr kp_read_on_irq
bra irq
@irq_spi_p:
jsr spi_p_read
bra irq
@irq_dht:
2023-10-27 16:50:58 +02:00
lda IO1 + IO_T1CL ;T1L2 ; clear interrupt flag
2023-10-30 22:17:19 +01:00
bra irq
@irq_return:
2023-10-26 19:51:20 +02:00
rti
;********************************************************************************
; Reset sequence
;********************************************************************************
reset:
2023-10-30 22:17:19 +01:00
jsr spi_p_init
2023-10-26 19:51:20 +02:00
jsr lcd_init
2023-10-28 03:48:27 +02:00
jsr kp_init
2023-10-30 22:17:19 +01:00
lda #$ff
sta IO1 + IO_DDRA
DEBUG_LED_ON 0
DEBUG_LED_ON 1
2023-10-26 19:51:20 +02:00
2023-10-27 16:50:58 +02:00
; ; INIT DHT
; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2
; sta IER2
; lda #%00111111 ; set Timer 1 to interrupt when loaded
; and ACR2
; sta ACR2
; lda #%00000001 ; set PCR2 bit 0 CA1 pos edge interrupt
; ora PCR2
; sta PCR2
; stz DHT_STATUS
2023-10-26 19:51:20 +02:00
; enable interrupts
cli
.proc return_home
2023-10-28 03:48:27 +02:00
Print message_menu
2023-10-26 19:51:20 +02:00
.endproc
.proc home
2023-10-30 22:17:19 +01:00
.macro wait
wait:
stz 1
stz 2
.repeat 2
nop
.endrepeat
inc 1
bne wait
inc 2
bne wait
.endmacro
; jsr rb_keypad_read
lda KB_LAST
2023-10-26 19:51:20 +02:00
beq home
2023-10-30 22:17:19 +01:00
stz KB_LAST
; beq home
2023-10-26 19:51:20 +02:00
cmp #'A'
jeq printer
cmp #'B'
2023-10-27 16:50:58 +02:00
; jeq dht_request
2023-10-26 19:51:20 +02:00
cmp #'C'
2023-10-28 03:48:27 +02:00
jeq print_1
2023-10-26 19:51:20 +02:00
cmp #'D'
2023-10-28 03:48:27 +02:00
jeq print_2
2023-10-30 22:17:19 +01:00
cmp '4'
bra debug
2023-10-26 19:51:20 +02:00
cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
2023-10-30 22:17:19 +01:00
jeq return_home
2023-10-26 19:51:20 +02:00
2023-10-30 22:17:19 +01:00
jmp home
2023-10-28 03:48:27 +02:00
2023-10-30 22:17:19 +01:00
debug:
DEBUG_LED_OFF 0
2023-10-28 03:48:27 +02:00
jmp home
2023-10-30 22:17:19 +01:00
2023-10-26 19:51:20 +02:00
.endproc
print_1:
2023-10-28 03:48:27 +02:00
Print message_1
2023-10-26 19:51:20 +02:00
jmp home
print_2:
2023-10-28 03:48:27 +02:00
Print message_2
2023-10-26 19:51:20 +02:00
jmp home
2023-10-27 16:50:58 +02:00
.segment "RODATA"
2023-10-26 19:51:20 +02:00
message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz"
2023-10-30 22:17:19 +01:00
message_2:
.byte " Hallo "
.byte " Clara "
.byte " <3 "
.asciiz "================"
2023-10-28 03:48:27 +02:00
message_menu:
2023-10-26 19:51:20 +02:00
.byte "<A> Printer "
.byte "<B> Temperatur "
.byte "<C> Text 1 "
.asciiz "<D> Text 2 "
2023-10-30 22:17:19 +01:00
str_irq:
.asciiz "IRQ detected! "
str_irq_unknown:
.asciiz "Unknown IRQ src!"
2023-10-26 19:51:20 +02:00
2023-10-27 16:50:58 +02:00
.segment "CODE"
2023-10-26 19:51:20 +02:00
;********************************************************************************
; reset vector
;********************************************************************************
2023-10-27 16:50:58 +02:00
.segment "RESET_VECTOR"
2023-10-26 19:51:20 +02:00
.word nmi
.word reset
.word irq