6502-OS/main.s65

242 lines
5.1 KiB
Plaintext

.include "system/system.h65"
.include "string.h65"
.export home,homeloop
.import keypad_printer:absolute
.import spi_menu:absolute
.import ps2_keyboard_printer:absolute
.import ps2_keyboard_util:absolute
.code
;********************************************************************************
; 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
; DEBUG_LED_ON 2
@irq_io1:
lda IO1 + IO::IFR
and IO1 + IO::IER ; sometimes CB1/2 IFR set even though not enabled in IER
sta irq_via_ifr
bbr7 irq_via_ifr,@irq_io2 ; skip
bbs2 irq_via_ifr,@irq_kb_sr
bbs3 irq_via_ifr,@irq_kb_cb2
bbs4 irq_via_ifr,@irq_kb_cb1
bbs5 irq_via_ifr,@irq_kb_t2
bra @irq_unknown
@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
@irq_unknown:
; this SHOULD never be reached
Print "Unknown IRQ"
; force reset interrupt flags
lda #$ff
sta IO1 + IO::IFR
sta IO2 + IO::IFR
bra @irq_return
@irq_keypad:
jsr kp::read_irq
bra @irq_return
@irq_spi_p:
jsr spi_p::irq_read_byte
bra @irq_return
; jmp (spi_p::irq_handler)
; JsrIndirect (spi_p::irq_handler), @irq_return
@irq_kb_sr:
; Print "$3000"
JsrIndirect ($3000), @irq_return
@irq_kb_cb2:
JsrIndirect ($3020), @irq_return
@irq_kb_cb1:
JsrIndirect ($3040), @irq_return
@irq_kb_t2:
JsrIndirect ($3060), @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
DEBUG_LED_OFF 1
jsr kp::init
DEBUG_LED_ON 0
jsr spi_p::init
DEBUG_LED_ON 1
; SetCustomChar chars::CAT,0
; SetCustomChar chars::SMILEY,1
; SetCustomChar chars::SMILEY_XD,2
; DEBUG_LED_ON 2
; 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 keypad_printer
cmp #'B'
jeq spi_menu
cmp #'C'
jeq print_1
cmp #'D'
jeq print_2
cmp #'1'
; beq @debug0_on
beq @ps2_util
cmp #'2'
beq @ps2_printer
; beq @debug0_off
cmp #'4'
beq @debug1_on
cmp #'5'
beq @debug1_off
cmp #'7'
beq @debug2_on
cmp #'8'
beq @debug2_off
cmp #'9'
beq @print_rb
cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
beq home
wai
jmp @loop
@ps2_util:
jmp ps2_keyboard_util
@ps2_printer:
jmp ps2_keyboard_printer
@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
@debug2_off:
DEBUG_LED_OFF 2
jmp @loop
@debug2_on:
DEBUG_LED_ON 2
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 "0123456789=!?#+*"
.byte "ABCDEFGHIJKLMNOP"
.byte "QRSTUVWXYZöäüß-_"
.asciiz "{[(<>)]}$%&/,;.:"
message_menu:
.byte "A/2: KP/KB Print"
; .byte "<B> Temperatur"
.byte "1: KB Util "
.byte "B: SPI-Menu "
.asciiz "C/D: Text 1/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