6502-OS/main.s65
2023-12-23 14:19:15 +01:00

246 lines
5.0 KiB
Plaintext

.include "system/system.h65"
.export home,homeloop
.import printer:absolute
.import spi_menu:absolute
.code
.macro DEBUG_LED_OFF nr
pha
lda IO1 + IO::RA
.if nr = 0
and #%11111110
.else
and #%11111101
.endif
sta IO1 + IO::RA
pla
.endmacro
.macro DEBUG_LED_ON nr
pha
lda IO1 + IO::RA
.if nr = 0
ora #%00000001
.else
ora #%00000010
.endif
sta IO1 + IO::RA
pla
.endmacro
;********************************************************************************
; Modules
;********************************************************************************
; LCD
; .include "utility.asm6502"
; LCD_IO = IO1
.include "system/lcd.h65"
.include "chars.h65"
; Keypad Reading
; KP_IO = IO2
.include "system/keypad.h65"
; SPI
.include "system/spi.h65"
; Printer
; .include "programs/printer.s65"
.include "programs/print_slow.h65"
; .include "programs/spi-menu.s65"
; Digital Humidity and Temerature Sensor
; .include "dht.s65"
;********************************************************************************
; Interrupts
;********************************************************************************
.zeropage
irq_via_ifr: .res 1
.code
nmi:
lda #'%'
jsr lcd::print_char
rti
irq:
; read IRFs, while bit 7 ist set handle interrupts
@irq_io1:
lda IO1 + IO::IFR
sta irq_via_ifr
bbr7 irq_via_ifr,@irq_io2 ; skip
bbs2 irq_via_ifr,@irq_kb1 ; shit reg -> first 8 bits
bbs5 irq_via_ifr,@irq_kb2 ; timer -> last 3 bits
@irq_io2:
lda IO2 + IO::IFR
sta irq_via_ifr
bbr7 irq_via_ifr,@irq_return ; skip
bbs2 irq_via_ifr,@irq_spi_p ; check SR
bbs1 irq_via_ifr,@irq_keypad ; check CA1
; this SHOULD never be reached
jsr lcd::clear
Print "Unknown IRQ"
; force reset interrupt flags
lda #$ff
sta IO1 + IO::IFR
sta IO2 + IO::IFR
rti
; bra @irq_return
@irq_keypad:
lda #<@irq_return
pha
lda #>@irq_return
pha
jmp (spi_p::irq_handler)
@irq_spi_p:
jsr spi_p::read
bra @irq_return
@irq_kb1:
; PrintNC "<30>"
jsr $3000
bra @irq_return
@irq_kb2:
; PrintNC "<31>"
jsr $3100
bra @irq_return
; @irq_dht:
; lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag
; bra @irq_return
@irq_return:
rti
;********************************************************************************
; Reset sequence
;********************************************************************************
reset:
jsr lcd::init
; TODO debug stuff
stz IO2 + IO::DDRB
lda #$ff
sta IO1 + IO::DDRA
DEBUG_LED_OFF 0
DEBUG_LED_OFF 1
jsr kp::init
SetCustomChar chars::CAT,0
SetCustomChar chars::SMILEY,1
SetCustomChar chars::SMILEY_XD,2
; ; 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
; enable interrupts
cli
bra home
.proc home
Print message_menu
; jsr rb_keypad_read
stz kp::_DEBUG_VAL
bra homeloop
.endproc
.proc homeloop
@loop:
lda kp::_DEBUG_VAL
beq @loop
; TODO debug
sta 0
stz kp::_DEBUG_VAL
lda 0
; beq home
cmp #'A'
jeq printer
cmp #'B'
jeq spi_menu
cmp #'C'
jeq print_1
cmp #'D'
jeq print_2
cmp #'1'
beq @debug0_on
cmp #'2'
beq @debug0_off
cmp #'4'
beq @debug1_on
cmp #'5'
beq @debug1_off
cmp #'7'
beq @print_rb
cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
beq home
jmp @loop
@debug0_off:
DEBUG_LED_OFF 0
jmp @loop
@debug0_on:
DEBUG_LED_ON 0
jmp @loop
@debug1_off:
DEBUG_LED_OFF 1
jmp @loop
@debug1_on:
DEBUG_LED_ON 1
jmp @loop
@print_rb:
jsr lcd::clear
Print str_io2
lda IO2 + IO::RB
jsr lcd::print_char
lda #'''
jsr lcd::print_char
jmp @loop
.endproc
print_1:
jsr lcd::clear
PrintSlow message_1,10
jmp home
print_2:
jsr lcd::clear
PrintSlow message_2,10
jmp home
.rodata
message_1:
.byte " Powered by "
.byte "......6502......"
.byte " **** "
.asciiz "www.quintern.xyz"
message_2:
.byte " Hello "
.byte " there "
.byte " <3 "
.asciiz "================"
message_menu:
.byte "<A> Printer "
; .byte "<B> Temperatur "
.byte "<B> SPI-Menu "
.byte "<C> Text 1 "
.asciiz "<D> Text 2 "
str_spi_begin:
.asciiz "---BEGIN SPI---"
str_spi_start:
.asciiz "---START SPI---"
str_io2:
.asciiz "IO2::RB='"
;********************************************************************************
; reset vector
;********************************************************************************
.segment "RESET_VECTOR"
.word nmi
.word reset
.word irq