6502-OS/main.s65

224 lines
4.4 KiB
Plaintext
Raw Normal View History

2023-11-11 12:13:47 +01:00
.include "system/system.s65"
.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"
LCD_IO = IO1
2023-11-09 12:10:00 +01:00
.include "system/lcd.s65"
2023-10-28 03:48:27 +02:00
; Keypad Reading
2023-10-30 22:17:19 +01:00
KP_IO = IO2
2023-11-09 12:10:00 +01:00
.include "system/keypad.s65"
2023-10-30 22:17:19 +01:00
; SPI
2023-11-09 12:10:00 +01:00
SPI_IO = IO2
2023-10-30 22:17:19 +01:00
.include "system/spi.s65"
2023-10-28 03:48:27 +02:00
; Printer
2023-11-09 12:10:00 +01:00
.include "programs/printer.s65"
.include "programs/print_slow.s65"
2023-12-08 00:02:22 +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
IRQ_VAR: .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-11-01 13:13:23 +01:00
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
2023-11-13 19:14:18 +01:00
; @irq_io1:
; lda SPI_IO+IO::IFR
; sta IRQ_VAR
; bbr7 IRQ_VAR,@irq_io2
@irq_io2:
lda IO2+IO::IFR
2023-11-09 12:10:00 +01:00
sta IRQ_VAR
2023-11-13 19:14:18 +01:00
bbr7 IRQ_VAR,@irq_return
2023-11-09 12:10:00 +01:00
bbs2 IRQ_VAR,@irq_spi_p ; check SR
2023-12-08 00:02:22 +01:00
bbs1 IRQ_VAR,@irq_keypad ; check CA1
2023-10-30 22:17:19 +01:00
; this should never be reached
2023-11-09 12:10:00 +01:00
jsr lcd_clear
2023-10-30 22:17:19 +01:00
Print str_irq_unknown
; force reset interrupt flags
lda #$ff
2023-11-01 13:13:23 +01:00
sta IO1 + IO::IFR
sta IO2 + IO::IFR
2023-10-30 22:17:19 +01:00
bra @irq_return
@irq_keypad:
jsr kp_read_on_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-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:
jsr lcd_init
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 00:02:22 +01:00
jsr kp_init
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
@loop:
lda _KP_DEBUG_VAL
beq @loop
; TODO debug
sta 0
stz _KP_DEBUG_VAL
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 00:02:22 +01:00
jeq spi_menu::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:
jsr lcd_clear
Print str_io2
lda IO2 + IO::RB
jsr lcd_char
lda #'''
jsr lcd_char
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-11-09 12:10:00 +01:00
jsr lcd_clear
PrintSlow message_1,10
2023-10-26 19:51:20 +02:00
jmp home
print_2:
2023-11-09 12:10:00 +01:00
jsr lcd_clear
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---"
2023-10-30 22:17:19 +01:00
str_irq:
.asciiz "IRQ detected! "
str_irq_unknown:
.asciiz "Unknown IRQ src!"
2023-12-08 00:02:22 +01:00
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-10-26 19:51:20 +02:00
.word nmi
.word reset
.word irq