6502-OS/main.s65

242 lines
5.1 KiB
Plaintext
Raw Normal View History

2023-12-08 22:56:35 +01:00
.include "system/system.h65"
2023-12-31 01:59:06 +01:00
.include "string.h65"
2023-12-16 02:41:19 +01:00
.export home,homeloop
2024-01-07 00:39:51 +01:00
.import keypad_printer:absolute
2023-12-08 22:56:35 +01:00
.import spi_menu:absolute
2024-08-08 20:15:28 +02:00
.import ps2_keyboard_printer:absolute
.import ps2_keyboard_util:absolute
2023-12-08 22:56:35 +01:00
2023-11-11 12:13:47 +01:00
.code
2023-10-26 19:51:20 +02:00
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-31 01:59:06 +01:00
; DEBUG_LED_ON 2
2023-12-21 17:27:54 +01:00
@irq_io1:
lda IO1 + IO::IFR
2024-01-02 23:37:07 +01:00
and IO1 + IO::IER ; sometimes CB1/2 IFR set even though not enabled in IER
2023-12-21 17:27:54 +01:00
sta irq_via_ifr
2024-01-02 23:37:07 +01:00
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
2023-12-31 01:59:06 +01:00
bra @irq_unknown
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-27 16:56:14 +01:00
2023-12-31 01:59:06 +01:00
@irq_unknown:
2023-12-20 12:27:54 +01:00
; this SHOULD never be reached
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-27 16:56:14 +01:00
bra @irq_return
2023-10-30 22:17:19 +01:00
@irq_keypad:
2023-12-27 16:56:14 +01:00
jsr kp::read_irq
2023-11-01 13:13:23 +01:00
bra @irq_return
2023-12-27 16:56:14 +01:00
@irq_spi_p:
2023-12-31 01:59:06 +01:00
jsr spi_p::irq_read_byte
bra @irq_return
; jmp (spi_p::irq_handler)
; JsrIndirect (spi_p::irq_handler), @irq_return
2024-01-02 23:37:07 +01:00
@irq_kb_sr:
2023-12-31 01:59:06 +01:00
; Print "$3000"
2024-01-02 23:37:07 +01:00
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
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-12-31 01:59:06 +01:00
DEBUG_LED_OFF 1
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-31 01:59:06 +01:00
DEBUG_LED_ON 0
2023-12-16 02:41:19 +01:00
2023-12-31 01:59:06 +01:00
jsr spi_p::init
DEBUG_LED_ON 1
; SetCustomChar chars::CAT,0
; SetCustomChar chars::SMILEY,1
; SetCustomChar chars::SMILEY_XD,2
2023-11-13 19:14:18 +01:00
2023-12-31 01:59:06 +01:00
; DEBUG_LED_ON 2
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'
2024-01-07 00:39:51 +01:00
jeq keypad_printer
2023-10-26 19:51:20 +02:00
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'
2024-08-08 20:15:28 +02:00
; beq @debug0_on
beq @ps2_util
2023-12-08 00:02:22 +01:00
cmp #'2'
2024-08-08 20:15:28 +02:00
beq @ps2_printer
; beq @debug0_off
2023-12-08 00:02:22 +01:00
cmp #'4'
beq @debug1_on
cmp #'5'
beq @debug1_off
cmp #'7'
2023-12-31 01:59:06 +01:00
beq @debug2_on
cmp #'8'
beq @debug2_off
cmp #'9'
2023-12-08 00:02:22 +01:00
beq @print_rb
cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
beq home
2023-12-31 01:59:06 +01:00
wai
2023-12-08 00:02:22 +01:00
jmp @loop
2024-08-08 20:15:28 +02:00
@ps2_util:
jmp ps2_keyboard_util
@ps2_printer:
jmp ps2_keyboard_printer
2023-12-08 00:02:22 +01:00
@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
2023-12-31 01:59:06 +01:00
@debug2_off:
DEBUG_LED_OFF 2
jmp @loop
@debug2_on:
DEBUG_LED_ON 2
jmp @loop
2023-12-08 00:02:22 +01:00
@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-12-31 01:59:06 +01:00
.byte "0123456789=!?#+*"
.byte "ABCDEFGHIJKLMNOP"
2024-08-08 20:15:28 +02:00
.byte "QRSTUVWXYZöäüß-_"
2023-12-31 01:59:06 +01:00
.asciiz "{[(<>)]}$%&/,;.:"
2023-10-28 03:48:27 +02:00
message_menu:
2024-08-08 20:15:28 +02:00
.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---"
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