6502-OS/main.s65

245 lines
5.0 KiB
Plaintext
Raw Permalink Normal View History

2023-12-08 22:56:35 +01:00
.include "system/system.h65"
2023-12-16 02:41:19 +01:00
.export home,homeloop
2023-12-08 22:56:35 +01:00
.import printer:absolute
.import spi_menu:absolute
2023-11-11 12:13:47 +01:00
.code
2023-10-26 19:51:20 +02:00
2023-10-30 22:17:19 +01:00
.macro DEBUG_LED_OFF nr
2023-12-08 00:02:22 +01:00
pha
2023-11-01 13:13:23 +01:00
lda IO1 + IO::RA
2023-10-30 22:17:19 +01:00
.if nr = 0
and #%11111110
.else
and #%11111101
.endif
2023-11-01 13:13:23 +01:00
sta IO1 + IO::RA
2023-12-08 00:02:22 +01:00
pla
2023-10-30 22:17:19 +01:00
.endmacro
.macro DEBUG_LED_ON nr
2023-12-08 00:02:22 +01:00
pha
2023-11-01 13:13:23 +01:00
lda IO1 + IO::RA
2023-10-30 22:17:19 +01:00
.if nr = 0
ora #%00000001
.else
ora #%00000010
.endif
2023-11-01 13:13:23 +01:00
sta IO1 + IO::RA
2023-12-08 00:02:22 +01:00
pla
2023-10-30 22:17:19 +01:00
.endmacro
2023-10-28 03:48:27 +02:00
;********************************************************************************
; Modules
;********************************************************************************
; LCD
; .include "utility.asm6502"
2023-12-08 22:56:35 +01:00
; LCD_IO = IO1
.include "system/lcd.h65"
2023-12-16 02:41:19 +01:00
.include "chars.h65"
2023-10-28 03:48:27 +02:00
; Keypad Reading
2023-12-08 22:56:35 +01:00
; KP_IO = IO2
.include "system/keypad.h65"
2023-10-30 22:17:19 +01:00
; SPI
2023-12-08 22:56:35 +01:00
.include "system/spi.h65"
2023-10-28 03:48:27 +02:00
; Printer
2023-12-08 22:56:35 +01:00
; .include "programs/printer.s65"
2023-12-16 02:41:19 +01:00
.include "programs/print_slow.h65"
2023-12-08 22:56:35 +01:00
; .include "programs/spi-menu.s65"
2023-10-28 03:48:27 +02:00
; 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
;********************************************************************************
2023-11-13 19:14:18 +01:00
.zeropage
2023-12-21 17:27:54 +01:00
irq_via_ifr: .res 1
2023-11-11 12:13:47 +01:00
.code
2023-10-26 19:51:20 +02:00
nmi:
2023-10-27 16:50:58 +02:00
lda #'%'
2023-12-08 22:56:35 +01:00
jsr lcd::print_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
2023-12-21 17:27:54 +01:00
@irq_io1:
lda IO1 + IO::IFR
sta irq_via_ifr
2023-12-22 02:17:53 +01:00
bbr7 irq_via_ifr,@irq_io2 ; skip
2023-12-21 17:27:54 +01:00
bbs2 irq_via_ifr,@irq_kb1 ; shit reg -> first 8 bits
bbs5 irq_via_ifr,@irq_kb2 ; timer -> last 3 bits
2023-11-13 19:14:18 +01:00
@irq_io2:
2023-12-21 17:27:54 +01:00
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
2023-12-20 12:27:54 +01:00
; this SHOULD never be reached
2023-12-08 22:56:35 +01:00
jsr lcd::clear
2023-12-21 17:27:54 +01:00
Print "Unknown IRQ"
2023-10-30 22:17:19 +01:00
; force reset interrupt flags
lda #$ff
2023-11-01 13:13:23 +01:00
sta IO1 + IO::IFR
sta IO2 + IO::IFR
2023-12-22 02:17:53 +01:00
rti
; bra @irq_return
2023-10-30 22:17:19 +01:00
@irq_keypad:
2023-12-08 22:56:35 +01:00
jsr kp::read_irq
2023-11-01 13:13:23 +01:00
bra @irq_return
2023-10-30 22:17:19 +01:00
@irq_spi_p:
2023-12-08 00:02:22 +01:00
jsr spi_p::read
2023-11-01 13:13:23 +01:00
bra @irq_return
2023-12-20 12:27:54 +01:00
@irq_kb1:
2023-12-22 12:10:54 +01:00
; PrintNC "<30>"
2023-12-20 12:27:54 +01:00
jsr $3000
bra @irq_return
@irq_kb2:
2023-12-22 12:10:54 +01:00
; PrintNC "<31>"
2023-12-20 12:27:54 +01:00
jsr $3100
bra @irq_return
2023-11-13 19:14:18 +01:00
; @irq_dht:
; lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag
; bra @irq_return
2023-10-30 22:17:19 +01:00
@irq_return:
2023-10-26 19:51:20 +02:00
rti
;********************************************************************************
; Reset sequence
;********************************************************************************
reset:
2023-12-08 22:56:35 +01:00
jsr lcd::init
2023-10-26 19:51:20 +02:00
2023-12-08 00:02:22 +01:00
; TODO debug stuff
stz IO2 + IO::DDRB
2023-10-30 22:17:19 +01:00
lda #$ff
2023-11-01 13:13:23 +01:00
sta IO1 + IO::DDRA
DEBUG_LED_OFF 0
DEBUG_LED_OFF 1
2023-10-26 19:51:20 +02:00
2023-11-13 19:14:18 +01:00
2023-12-08 22:56:35 +01:00
jsr kp::init
2023-11-13 19:14:18 +01:00
2023-12-16 02:41:19 +01:00
SetCustomChar chars::CAT,0
SetCustomChar chars::SMILEY,1
SetCustomChar chars::SMILEY_XD,2
2023-11-13 19:14:18 +01: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
2023-12-08 00:02:22 +01:00
bra home
2023-10-26 19:51:20 +02:00
.proc home
2023-12-08 00:02:22 +01:00
Print message_menu
; jsr rb_keypad_read
2023-12-20 12:27:54 +01:00
stz kp::_DEBUG_VAL
2023-12-16 02:41:19 +01:00
bra homeloop
.endproc
.proc homeloop
2023-12-08 00:02:22 +01:00
@loop:
2023-12-08 22:56:35 +01:00
lda kp::_DEBUG_VAL
2023-12-08 00:02:22 +01:00
beq @loop
; TODO debug
sta 0
2023-12-08 22:56:35 +01:00
stz kp::_DEBUG_VAL
2023-12-08 00:02:22 +01:00
lda 0
2023-10-30 22:17:19 +01:00
; beq home
2023-10-26 19:51:20 +02:00
cmp #'A'
jeq printer
cmp #'B'
2023-12-08 22:56:35 +01:00
jeq spi_menu
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-12-08 00:02:22 +01:00
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:
2023-11-13 19:14:18 +01:00
DEBUG_LED_OFF 0
2023-12-08 00:02:22 +01:00
jmp @loop
@debug0_on:
2023-11-13 19:14:18 +01:00
DEBUG_LED_ON 0
2023-12-08 00:02:22 +01:00
jmp @loop
@debug1_off:
2023-11-13 19:14:18 +01:00
DEBUG_LED_OFF 1
2023-12-08 00:02:22 +01:00
jmp @loop
@debug1_on:
2023-11-13 19:14:18 +01:00
DEBUG_LED_ON 1
2023-12-08 00:02:22 +01:00
jmp @loop
@print_rb:
2023-12-08 22:56:35 +01:00
jsr lcd::clear
2023-12-08 00:02:22 +01:00
Print str_io2
lda IO2 + IO::RB
2023-12-08 22:56:35 +01:00
jsr lcd::print_char
2023-12-08 00:02:22 +01:00
lda #'''
2023-12-08 22:56:35 +01:00
jsr lcd::print_char
2023-12-08 00:02:22 +01:00
jmp @loop
2023-10-26 19:51:20 +02:00
.endproc
2023-11-09 12:10:00 +01:00
2023-10-26 19:51:20 +02:00
print_1:
2023-12-08 22:56:35 +01:00
jsr lcd::clear
2023-11-09 12:10:00 +01:00
PrintSlow message_1,10
2023-10-26 19:51:20 +02:00
jmp home
print_2:
2023-12-08 22:56:35 +01:00
jsr lcd::clear
2023-11-09 12:10:00 +01:00
PrintSlow message_2,10
2023-10-26 19:51:20 +02:00
jmp home
2023-11-11 12:13:47 +01:00
.rodata
2023-11-13 19:14:18 +01:00
message_1:
.byte " Powered by "
.byte "......6502......"
.byte " **** "
.asciiz "www.quintern.xyz"
2023-10-30 22:17:19 +01:00
message_2:
2023-11-11 12:13:47 +01:00
.byte " Hello "
.byte " there "
2023-10-30 22:17:19 +01:00
.byte " <3 "
.asciiz "================"
2023-10-28 03:48:27 +02:00
message_menu:
2023-10-26 19:51:20 +02:00
.byte "<A> Printer "
2023-11-09 12:10:00 +01:00
; .byte "<B> Temperatur "
2023-12-08 00:02:22 +01:00
.byte "<B> SPI-Menu "
2023-10-26 19:51:20 +02:00
.byte "<C> Text 1 "
.asciiz "<D> Text 2 "
2023-12-08 00:02:22 +01:00
str_spi_begin:
.asciiz "---BEGIN SPI---"
str_spi_start:
.asciiz "---START SPI---"
str_io2:
.asciiz "IO2::RB='"
2023-10-26 19:51:20 +02:00
;********************************************************************************
; reset vector
;********************************************************************************
2023-10-27 16:50:58 +02:00
.segment "RESET_VECTOR"
2023-12-27 20:38:57 +01:00
.assert * = $fffa,error,"Reset vector not at $8ffa"
2023-10-26 19:51:20 +02:00
.word nmi
.word reset
.word irq