Skip to content

Commit

Permalink
software written!
Browse files Browse the repository at this point in the history
  • Loading branch information
20Koen02 committed Feb 18, 2021
1 parent cbc1a04 commit d5e41f3
Show file tree
Hide file tree
Showing 31 changed files with 572 additions and 144 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea
.vscode
Software/build
.vscode
12 changes: 12 additions & 0 deletions Software/01_lcd_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all: lcd_test.rom

clean:
rm -f *.lst *.map *.o *.rom

%.o: src/%.s
ca65 -o $@ $<

%.rom: %.o ../kw6502.cfg
ld65 -C ../kw6502.cfg -o build/$@ $<

.PHONY: all clean
3 changes: 3 additions & 0 deletions Software/01_lcd_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LCD Test

This program puts "Hello, world!" on the LCD
Binary file not shown.
63 changes: 63 additions & 0 deletions Software/01_lcd_test/src/lcd.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
E = %10000000
RW = %01000000
RS = %00100000

init_lcd:
lda #%11111111 ; Set all pins on port B to output
sta via_ddrb
lda #%11100000 ; Set top 3 pins on port A to output
sta via_ddra

lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr lcd_instruction
lda #%00001110 ; Display on; cursor on; blink off
jsr lcd_instruction
lda #%00000110 ; Increment and shift cursor; don't shift display
jsr lcd_instruction
lda #$00000001 ; Clear display
jsr lcd_instruction
rts

_lcd_wait:
pha
lda #%00000000 ; Port B is input
sta via_ddrb
_lcdbusy:
lda #RW
sta via_a
lda #(RW | E)
sta via_a
lda via_b
and #%10000000
bne _lcdbusy

lda #RW
sta via_a
lda #%11111111 ; Port B is output
sta via_ddrb
pla
rts

lcd_instruction:
jsr _lcd_wait
sta via_b
lda #0 ; Clear RS/RW/E bits
sta via_a
lda #E ; Set E bit to send instruction
sta via_a
lda #0 ; Clear RS/RW/E bits
sta via_a
rts

write_lcd:
pha
jsr _lcd_wait
sta via_b
lda #RS ; Set RS; Clear RW/E bits
sta via_a
lda #(RS | E) ; Set E bit to send instruction
sta via_a
lda #RS ; Clear E bits
sta via_a
pla
rts
31 changes: 31 additions & 0 deletions Software/01_lcd_test/src/lcd_test.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.segment "CODE"
.include "main.s"

.segment "ACIA"
acia_data: .res 1 ; Read: Receiver Data Register - Write: Transmit Data Register
acia_status: .res 1 ; Read: Status Register - Write: Programmed Reset (Data is "Don't Care")
acia_command: .res 1 ; Command Register
acia_control: .res 1 ; Control Register

.segment "VIA"
via_b: .res 1 ; Register "B"
via_a: .res 1 ; Register "A"
via_ddrb: .res 1 ; Data Direction Register "B"
via_ddra: .res 1 ; Data Direction Register "A"
via_t1c_l: .res 1 ; Read: T1 Low-Order Counter - Write: T1 Low-Order Latches
via_t1c_h: .res 1 ; T1 High-Order Counter
via_t1l_l: .res 1 ; T1 Low-Order Latches
via_t1l_h: .res 1 ; T1 High-Order Latches
via_t2c_l: .res 1 ; Read: T2 Low-Order Counter - Write: T2 Low-Order Latches
via_t2c_h: .res 1 ; T2 High-Order Counter
via_sr: .res 1 ; Shift Register
via_acr: .res 1 ; Auxilary Control Register
via_pcr: .res 1 ; Peripheral Control Register
via_ifr: .res 1 ; Interrupt Flag Register
via_ier: .res 1 ; Interrupt Enable Register
via_a_noh: .res 1 ; Same as Register "A" (via_a) except no "Handshake"

.segment "VECTORS"
.word nmi
.word main
.word irq
25 changes: 25 additions & 0 deletions Software/01_lcd_test/src/main.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.include "lcd.s"

main:
; Initialize LCD
jsr init_lcd ; lcd.s

; Loop through 'message' and print the characters
ldx #0
print:
lda message,x ; Load character
beq exit ; If end of message go to exit
jsr write_lcd ; Print character
inx ; Increment Loop Idx
jmp print

exit:
jmp exit

message: .asciiz "Hello, world!"

nmi:
rti

irq:
rti
12 changes: 12 additions & 0 deletions Software/02_serial_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all: serial_test.rom

clean:
rm -f *.lst *.map *.o *.rom

%.o: src/%.s
ca65 -o $@ $<

%.rom: %.o ../kw6502.cfg
ld65 -C ../kw6502.cfg -o build/$@ $<

.PHONY: all clean
5 changes: 5 additions & 0 deletions Software/02_serial_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Serial Test

This program reads and writes to the serial monitor.
Every time you press a key on the serial monitor, a counter gets incremented and written to the serial monitor.
The counter gets reset to 0 after it passes 9
Binary file added Software/02_serial_test/build/serial_test.rom
Binary file not shown.
29 changes: 29 additions & 0 deletions Software/02_serial_test/src/main.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.include "serial.s"

main:
; Initialize Serial
jsr init_serial ; serial.s

; create read loop
ldx #0
read:
jsr read_serial ; read serial
cpx #$a ; compare x register with a

bcc continue_writing ; continue if x is less than a (so 0-9)

ldx #0 ; if not 0-9: reset x

continue_writing:
txa ; put x in a
ora #%00110000 ; set correct upper 4 bits to get the correct character codes (logical inclusive or)
jsr write_serial ; write a (modified index) to serial

inx
jmp read

nmi:
rti

irq:
rti
26 changes: 26 additions & 0 deletions Software/02_serial_test/src/serial.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

init_serial:
sta acia_status ; Programmed Reset (Data is "Don't Care")
lda #%00001011 ; No parity, no echo, no interrupt
sta acia_command
lda #%00011111 ; 1 stop bit, 8 data bits, 19200 baud
sta acia_control
rts

read_serial:
lda acia_status
and #%00001000
beq read_serial
lda acia_data
rts

write_serial:
pha
_wait_tx_empty:
lda acia_status
and #%00010000
beq _wait_tx_empty

pla
sta acia_data ; Send to ACIA
rts
31 changes: 31 additions & 0 deletions Software/02_serial_test/src/serial_test.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.segment "CODE"
.include "main.s"

.segment "ACIA"
acia_data: .res 1 ; Read: Receiver Data Register - Write: Transmit Data Register
acia_status: .res 1 ; Read: Status Register - Write: Programmed Reset (Data is "Don't Care")
acia_command: .res 1 ; Command Register
acia_control: .res 1 ; Control Register

.segment "VIA"
via_b: .res 1 ; Register "B"
via_a: .res 1 ; Register "A"
via_ddrb: .res 1 ; Data Direction Register "B"
via_ddra: .res 1 ; Data Direction Register "A"
via_t1c_l: .res 1 ; Read: T1 Low-Order Counter - Write: T1 Low-Order Latches
via_t1c_h: .res 1 ; T1 High-Order Counter
via_t1l_l: .res 1 ; T1 Low-Order Latches
via_t1l_h: .res 1 ; T1 High-Order Latches
via_t2c_l: .res 1 ; Read: T2 Low-Order Counter - Write: T2 Low-Order Latches
via_t2c_h: .res 1 ; T2 High-Order Counter
via_sr: .res 1 ; Shift Register
via_acr: .res 1 ; Auxilary Control Register
via_pcr: .res 1 ; Peripheral Control Register
via_ifr: .res 1 ; Interrupt Flag Register
via_ier: .res 1 ; Interrupt Enable Register
via_a_noh: .res 1 ; Same as Register "A" (via_a) except no "Handshake"

.segment "VECTORS"
.word nmi
.word main
.word irq
12 changes: 12 additions & 0 deletions Software/03_serial_and_lcd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all: serial_and_lcd.rom

clean:
rm -f *.lst *.map *.o *.rom

%.o: src/%.s
ca65 -o $@ $<

%.rom: %.o ../kw6502.cfg
ld65 -C ../kw6502.cfg -o build/$@ $<

.PHONY: all clean
3 changes: 3 additions & 0 deletions Software/03_serial_and_lcd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Serial and LCD

This program reads from the serial monitor and output it on both the lcd and serial monitor.
Binary file not shown.
63 changes: 63 additions & 0 deletions Software/03_serial_and_lcd/src/lcd.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
E = %10000000
RW = %01000000
RS = %00100000

init_lcd:
lda #%11111111 ; Set all pins on port B to output
sta via_ddrb
lda #%11100000 ; Set top 3 pins on port A to output
sta via_ddra

lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr lcd_instruction
lda #%00001110 ; Display on; cursor on; blink off
jsr lcd_instruction
lda #%00000110 ; Increment and shift cursor; don't shift display
jsr lcd_instruction
lda #$00000001 ; Clear display
jsr lcd_instruction
rts

_lcd_wait:
pha
lda #%00000000 ; Port B is input
sta via_ddrb
_lcdbusy:
lda #RW
sta via_a
lda #(RW | E)
sta via_a
lda via_b
and #%10000000
bne _lcdbusy

lda #RW
sta via_a
lda #%11111111 ; Port B is output
sta via_ddrb
pla
rts

lcd_instruction:
jsr _lcd_wait
sta via_b
lda #0 ; Clear RS/RW/E bits
sta via_a
lda #E ; Set E bit to send instruction
sta via_a
lda #0 ; Clear RS/RW/E bits
sta via_a
rts

write_lcd:
pha
jsr _lcd_wait
sta via_b
lda #RS ; Set RS; Clear RW/E bits
sta via_a
lda #(RS | E) ; Set E bit to send instruction
sta via_a
lda #RS ; Clear E bits
sta via_a
pla
rts
21 changes: 21 additions & 0 deletions Software/03_serial_and_lcd/src/main.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.include "lcd.s"
.include "serial.s"

main:
; Initialize LCD and Serial
jsr init_lcd ; lcd.s
jsr init_serial ; serial.s

read:
jsr read_serial ; Wait until data is received and store in a

jsr write_serial ; Send to ACIA
jsr write_lcd ; Send to LCD
jmp read


nmi:
rti

irq:
rti
26 changes: 26 additions & 0 deletions Software/03_serial_and_lcd/src/serial.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

init_serial:
sta acia_status ; Programmed Reset (Data is "Don't Care")
lda #%00001011 ; No parity, no echo, no interrupt
sta acia_command
lda #%00011111 ; 1 stop bit, 8 data bits, 19200 baud
sta acia_control
rts

read_serial:
lda acia_status
and #%00001000
beq read_serial
lda acia_data
rts

write_serial:
pha
_wait_tx_empty:
lda acia_status
and #%00010000
beq _wait_tx_empty

pla
sta acia_data ; Send to ACIA
rts
Loading

0 comments on commit d5e41f3

Please sign in to comment.