lots of fixes

This commit is contained in:
matthias@rpi 2023-10-28 03:48:27 +02:00
parent a63bd562d1
commit 4dbdbaf55d
7 changed files with 99 additions and 96 deletions

View File

@ -1,4 +0,0 @@
.build/test.o: test.s65 system/system.h65 system/io_W65C22.h65 utility.h65 /usr/share/cc65/asminc/longbranch.mac
test.s65 system/system.h65 system/io_W65C22.h65 utility.h65 /usr/share/cc65/asminc/longbranch.mac:

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
**.bin **.bin
**.o **.o
.build .build
.dependencies

View File

@ -19,21 +19,22 @@ LDFLAGS = -C linker.conf
$(BUILD_DIR): $(BUILD_DIR):
mkdir $@ mkdir $@
.PHONY: default test clean
default: $(ROM) default: $(ROM)
test: ../test.bin
$(ROM): $(BUILD_DIR)/main.o $(ROM): $(BUILD_DIR)/main.o
$(LD) $(LDFLAGS) $< -o $@ $(LD) $(LDFLAGS) $< -o $@
$(BUILD_DIR)/%.o: %.s65 $(BUILD_DIR)
$(ASM) $(ASMFLAGS) $(ASMDEPFLAGS) $< -o $@
.PHONY = test
test: ../test.bin
../test.bin: $(BUILD_DIR)/test.o ../test.bin: $(BUILD_DIR)/test.o
# $(VASM) -dotdir -opt-branch -wdc02 -chklabels test.asm6502 # $(VASM) -dotdir -opt-branch -wdc02 -chklabels test.asm6502
# $(ASM) $(ASMFLAGS) test.asm6502 -o test.o
$(LD) $(LDFLAGS) $(BUILD_DIR)/test.o -o ../test.bin $(LD) $(LDFLAGS) $(BUILD_DIR)/test.o -o ../test.bin
$(BUILD_DIR)/%.o: %.s65 | $(BUILD_DIR)
$(ASM) $(ASMFLAGS) $(ASMDEPFLAGS) $< -o $@
clean: clean:
rm -r $(BUILD_DIR) rm -r $(BUILD_DIR)
rm $(ROM) rm $(ROM)

View File

@ -1,6 +1,21 @@
.segment "CODE" .segment "CODE"
.include "system/system.h65" .include "system/system.h65"
;********************************************************************************
; Modules
;********************************************************************************
; LCD
; .include "utility.asm6502"
LCD_IO = IO1
.include "lcd.s65"
; Keypad Reading
KP_IO = IO1
.include "keypad.s65"
; Printer
.include "printer.s65"
; Digital Humidity and Temerature Sensor
; .include "dht.s65"
;******************************************************************************** ;********************************************************************************
; Interrupts ; Interrupts
;******************************************************************************** ;********************************************************************************
@ -45,15 +60,15 @@ reset:
lda #%11111111 lda #%11111111
sta IO1 + IO_RANH sta IO1 + IO_RANH
.endmacro .endmacro
SET_DEBUG_LED_OFF ; SET_DEBUG_LED_OFF
jsr lcd_init jsr lcd_init
SET_DEBUG_LED_ON ; .repeat 1000
.repeat 1000 ; nop
nop ; .endrepeat
.endrepeat ; SET_DEBUG_LED_ON
SET_DEBUG_LED_OFF jsr kp_init
; jsr kp_init ; SET_DEBUG_LED_OFF
; ; INIT DHT ; ; INIT DHT
; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2 ; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2
@ -70,18 +85,20 @@ reset:
cli cli
.proc return_home .proc return_home
ldx #$00 Print message_menu
@return_home: ; @return_home:
lda menu,x ; lda menu,x
beq @return_home_done ; beq @return_home_done
sta TO_PRINT,x ; sta TO_PRINT,x
inx ; jsr _lcd_char
bra @return_home ; inx
@return_home_done: ; bra @return_home
jsr lcd_print_clear ; @return_home_done:
; jsr lcd_print_clear
.endproc .endproc
.proc home .proc home
; SET_DEBUG_LED_ON
jsr kb_read jsr kb_read
beq home beq home
cmp #'A' cmp #'A'
@ -89,40 +106,37 @@ reset:
cmp #'B' cmp #'B'
; jeq dht_request ; jeq dht_request
cmp #'C' cmp #'C'
beq print_1 jeq print_1
cmp #'D' cmp #'D'
beq print_2 jeq print_2
cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home) cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
beq return_home beq return_home
bra home ; .repeat 500
; nop
; .endrepeat
; SET_DEBUG_LED_OFF
; .repeat 500
; nop
; .endrepeat
jmp home
.endproc .endproc
print_1: print_1:
ldx #$00 Print message_1
@print_1:
lda message_1,x
sta TO_PRINT,x
inx
bne @print_1
jsr lcd_print_clear
jmp home jmp home
print_2: print_2:
ldx #$00 Print message_2
@print_2:
lda message_2,x
sta TO_PRINT,x
inx
bne @print_2
jsr lcd_print_clear
jmp home jmp home
.segment "RODATA" .segment "RODATA"
message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz"
message_2: .asciiz " Danke fuer eure Aufmerksamkeit ;) " message_2: .asciiz " Danke fuer eure Aufmerksamkeit ;) "
menu: message_menu:
.byte "<A> Printer " .byte "<A> Printer "
.byte "<B> Temperatur " .byte "<B> Temperatur "
.byte "<C> Text 1 " .byte "<C> Text 1 "
@ -130,20 +144,6 @@ menu:
.segment "CODE" .segment "CODE"
;******************************************************************************** ;********************************************************************************
; Modules
;********************************************************************************
; LCD
; .include "utility.asm6502"
LCD_IO = IO1
.include "lcd.s65"
; Keypad Reading
KP_IO = IO1
.include "keypad.s65"
; Printer
.include "printer.s65"
; Digital Humidity and Temerature Sensor
; .include "dht.s65"
;********************************************************************************
; reset vector ; reset vector
;******************************************************************************** ;********************************************************************************
.segment "RESET_VECTOR" .segment "RESET_VECTOR"

View File

@ -1,9 +1,10 @@
;******************************************************************************** ;********************************************************************************
; @module 4x4 Keypad ; @module keypad4x4
; @type driver ; @type driver
; @device 4x4 Matrix Keypad ; @device 4x4 Matrix Keypad
; @details ; @details
; Keypad must be connected to a VIA ; The LCD must be connected to a W65C22N Interface Chip:
; - IO.RB0-7 ->
; @requires KP_IO: Base Address of IO Chip ; @requires KP_IO: Base Address of IO Chip
; @depends IO-W65C22N ; @depends IO-W65C22N
;******************************************************************************** ;********************************************************************************
@ -18,8 +19,8 @@ INCLUDE_KEYPAD = 1
; Keypad Buffer from $202 to $2ff ; Keypad Buffer from $202 to $2ff
;******************************************************************************** ;********************************************************************************
KB_VAR = $00 KB_VAR = $00
KB_WRITE = $200 KB_WRITE = $200 ; write pointer, relative to KB_WRITE
KB_READ = $201 KB_READ = $201 ; read ponter, relative to KB_START
KB_START = $202 KB_START = $202
KB_LENGTH = $fd KB_LENGTH = $fd

View File

@ -3,14 +3,14 @@
; @type driver ; @type driver
; @device ELECTRONIC ASSEMBLY - W164B-NLW ; @device ELECTRONIC ASSEMBLY - W164B-NLW
; @details ; @details
; Assumes it is connected to a W65C22N Interface Chip: ; The LCD must be connected to a W65C22N Interface Chip:
; - IO.RB0-7 -> LCD.D0-7 data lines ; - IO.RB0-7 -> LCD.D0-7 data lines
; - IO.RA5 -> LCD.RS register select ; - IO.RA5 -> LCD.RS register select
; - IO.RA6 -> LCD.R/W read/write ; - IO.RA6 -> LCD.R/W read/write
; - IO.RA7 -> LCD.E enable ; - IO.RA7 -> LCD.E enable
; ;
; @requires LCD_IO: Base Address of IO Chip ; @requires LCD_IO: Base Address of IO Chip
; @optparam LCD_MEM: Address to a block of memory 1B. Default = $300 ; @optparam LCD_MEM: Memory address for a runtime variable. Default = $300
; @depends IO-W65C22N ; @depends IO-W65C22N
;******************************************************************************** ;********************************************************************************
@ -37,14 +37,14 @@ LCD_RW = %01000000
LCD_RS = %00100000 LCD_RS = %00100000
; .local LCD_E,LCD_RW,LCD_RS ; .local LCD_E,LCD_RW,LCD_RS
; LCD Instructions ; LCD Instructions (see datasheet for more)
LCD_CMD_CLEAR = %00000001 ; clear display LCD_CMD_CLEAR = %00000001 ; clear display
LCD_CMD_ENTRY_MODE = %00000110 ; auto-shift cursor LCD_CMD_ENTRY_MODE = %00000110 ; auto-shift cursor
LCD_CMD_DISPLAY_ON = %00001111 ; everything on, with blinking cursor LCD_CMD_DISPLAY_ON = %00001111 ; everything on, with blinking cursor
LCD_CMD_FUNCTION_SET = %00111000 ; 8-bit, 4 lines, 5x7 font LCD_CMD_FUNCTION_SET = %00111000 ; 8-bit, 4 lines, 5x7 font
LCD_CMD_SET_ADDRESS = %10000000 ; or with the address LCD_CMD_SET_ADDRESS = %10000000 ; or with the address
; LCD Constants ; LCD Constants
LCD_LINE1 = $00 ; line 1 LCD_LINE1 = $00
LCD_LINE2 = $40 LCD_LINE2 = $40
LCD_LINE3 = $10 LCD_LINE3 = $10
LCD_LINE4 = $50 LCD_LINE4 = $50
@ -61,9 +61,9 @@ LCD_CLEAR = %00000000
lda #$ff ; RB 0-7 output lda #$ff ; RB 0-7 output
sta LCD_IO+IO_DDRB sta LCD_IO+IO_DDRB
UT_update_with_mask LCD_IO + IO_DDRA, (LCD_RS | LCD_RW | LCD_E), (LCD_RS | LCD_RW | LCD_E) ; UT_update_with_mask LCD_IO + IO_DDRA, (LCD_RS | LCD_RW | LCD_E), (LCD_RS | LCD_RW | LCD_E)
; lda #(LCD_RS | LCD_RW | LCD_E) ; RA 5-7 output lda #(LCD_RS | LCD_RW | LCD_E) ; RA 5-7 output
; sta LCD_IO+IO_DDRA sta LCD_IO+IO_DDRA
; init lcd ; init lcd
lda #LCD_CMD_FUNCTION_SET lda #LCD_CMD_FUNCTION_SET
@ -82,39 +82,44 @@ LCD_CLEAR = %00000000
;******************************************************************************** ;********************************************************************************
; PRINTING TO LCD ; PRINTING TO LCD
;******************************************************************************** ;********************************************************************************
_lcd_clear: ; clear lcd
;********************************************************************************
; @function Clear the display
; @see lcd_print
;********************************************************************************
.proc lcd_clear
stz LCD_CHARCOUNT stz LCD_CHARCOUNT
lda #LCD_CLEAR lda #LCD_CLEAR
jsr _lcd_cmd jsr _lcd_cmd
lda #(LCD_CMD_SET_ADDRESS | LCD_LINE1) lda #(LCD_CMD_SET_ADDRESS | LCD_LINE1)
jsr _lcd_cmd jsr _lcd_cmd
rts rts
.endproc
;********************************************************************************
; @function Clear the display and print a null-terminated string
; @see lcd_print
;********************************************************************************
lcd_print_clear: ; clear lcd and print word located at message
stz LCD_CHARCOUNT
lda #LCD_CLEAR
jsr _lcd_cmd
lda #(LCD_CMD_SET_ADDRESS | LCD_LINE1)
jsr _lcd_cmd
;******************************************************************************** ;********************************************************************************
; @function Print a null-terminated string ; @function Print a null-terminated string
; @param ARG0-1 Address of the string to print ; @param ARG0-1 Address of the string to print
;******************************************************************************** ;********************************************************************************
lcd_print: .proc lcd_print
ldx #$00 ldy #$00
_lcd_print_loop: @lcd_print_loop:
lda (ARG0,x) lda ARG0,y
beq _lcd_print_end beq @lcd_print_end
jsr _lcd_char jsr _lcd_char
inx iny
bra _lcd_print_loop bra @lcd_print_loop
_lcd_print_end: @lcd_print_end:
rts rts
.endproc
.macro Print message
jsr lcd_clear
lda #.LOBYTE(message)
sta ARG0
lda #.HIBYTE(message)
sta ARG1
jsr lcd_print
.endmacro
;******************************************************************************** ;********************************************************************************
; LCD Commands ; LCD Commands
@ -138,7 +143,7 @@ _lcd_wait_nbusy:
sta LCD_IO + IO_DDRB sta LCD_IO + IO_DDRB
rts rts
_lcd_cmd: ; send cmd in acc .proc _lcd_cmd ; send cmd in acc
pha pha
jsr _lcd_wait_nbusy jsr _lcd_wait_nbusy
pla pla
@ -152,6 +157,7 @@ _lcd_cmd: ; send cmd in acc
lda #LCD_CLEAR lda #LCD_CLEAR
sta LCD_IO + IO_RA sta LCD_IO + IO_RA
rts rts
.endproc
_lcd_char: _lcd_char:
pha pha
@ -173,7 +179,7 @@ _lcd_char:
;******************************************************************************** ;********************************************************************************
; Set the LCD DD-RAM Address so that text linebreaks after 16 chars ; Set the LCD DD-RAM Address so that text linebreaks after 16 chars
;******************************************************************************** ;********************************************************************************
_lcd_set_address: .proc _lcd_set_address
; check if checks are necessary ; check if checks are necessary
lda LCD_CHARCOUNT lda LCD_CHARCOUNT
beq @lcd_line1 beq @lcd_line1
@ -209,3 +215,4 @@ _lcd_set_address:
lda #(LCD_CMD_SET_ADDRESS | LCD_LINE4) lda #(LCD_CMD_SET_ADDRESS | LCD_LINE4)
jsr _lcd_cmd jsr _lcd_cmd
rts rts
.endproc

View File

@ -13,14 +13,11 @@ INCLUDE_SYSTEM = 1
; 20-ff - free ; 20-ff - free
; 0100 - 01FF Stack ; 0100 - 01FF Stack
; 0200,0201 keybuffer write/read pointer ; 0200,0201 keybuffer write/read pointer
; 0202 - 02ff keybuffer ; 0202-02ff keybuffer
; 0300 lcd character counter ; 0300 lcd character counter
; 0301 - 0341 message to print
; 0400, 0401, 0402 dht status, dht bit, dht_bit_rot ; 0400, 0401, 0402 dht status, dht bit, dht_bit_rot
; 0403 value offset ; 0403 value offset
; 0405 - 04a0 rh high/low, temp high/low, checksum ; 0405-04a0 rh high/low, temp high/low, checksum
TO_PRINT = $300
; ARGUMENTS ; ARGUMENTS
; a,x,y can also be used ; a,x,y can also be used