Skip to content

Commit 963d1a8

Browse files
committed
get ramtest properly working in sim
1 parent e3f2229 commit 963d1a8

File tree

12 files changed

+304
-75
lines changed

12 files changed

+304
-75
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.map
44
*.swp
55
rom.bin
6+
librt.a

Makefile

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
CC65=cc65/bin
22
AS=$(CC65)/ca65
3-
ASFLAGS=--target sim65c02
3+
ASFLAGS=-l $@.lst
44

5-
rom.bin: main.o ramtest.o
5+
rom.bin: main.o ramtest.o librt.a
66
$(CC65)/ld65 --config eater.cfg -m rom.map -o $@ $^
77

8+
librt.a: reg.o via.o led.o lcd.o lfsr.o
9+
$(CC65)/ar65 r $@ $^
10+
11+
.PHONY: test
12+
test: rom.bin
13+
make -C test
14+
15+
.PHONY: program
16+
program: rom.bin
17+
minipro -p AT28C256 -w rom.bin
18+
819
.PHONY: hexdump
920
hexdump: rom.bin
1021
hexdump -C $<
@@ -15,4 +26,5 @@ cc65:
1526

1627
.PHONY: clean
1728
clean:
18-
rm -f rom.bin *.o
29+
rm -f rom.bin librt.a *.o
30+
make -C test clean

defs.inc

+18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
.PC02
22

3+
; main.s
4+
.globalzp r0, r1, r2, r3
5+
6+
; lfsr.s
37
.global srand
48
.global rand
59

10+
; via.s
11+
.global via_init
12+
13+
; lcd.s
614
.global lcd_init
715
.global lcd_home
16+
.global lcd_clear
817
.global lcd_puthex
18+
.global lcd_putc
19+
.global lcd_puts
20+
21+
; led.s
22+
.global led_on
23+
.global led_off
24+
.global led_blink
25+
.global led_code
926

27+
; ramtest.s
1028
.global ramtest
1129
.global ramtest_success

lcd.s

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
.include "defs.inc"
2-
3-
PORTB = $6000
4-
PORTA = $6001
5-
DDRB = $6002
6-
DDRA = $6003
7-
8-
E = %10000000
9-
RW = %01000000
10-
RS = %00100000
2+
.include "via.inc"
113

124
.proc lcd_wait
135
lda #%00000000 ; Set all pins on port B to input
@@ -48,7 +40,7 @@ loop:
4840
rts
4941
.endproc
5042

51-
.proc lcd_data
43+
.proc lcd_putc
5244
sta PORTB
5345

5446
jsr lcd_wait
@@ -81,21 +73,29 @@ skip:
8173
lsr
8274
lsr
8375
TO_ASCII
84-
jsr lcd_data
76+
jsr lcd_putc
8577
pla
8678
and #$f
8779
TO_ASCII
88-
jsr lcd_data
80+
jsr lcd_putc
8981
rts
9082
.endproc
9183

92-
.proc lcd_init
93-
lda #%11111111 ; Set all pins on port B to output
94-
sta DDRB
95-
96-
lda #%11100000 ; Set top 3 pins on port A to output
97-
sta DDRA
84+
.proc lcd_puts
85+
sty r0
86+
sta r0+1
87+
ldy #0
88+
loop:
89+
lda (r0),y
90+
beq done
91+
jsr lcd_putc
92+
iny
93+
jmp loop
94+
done:
95+
rts
96+
.endproc
9897

98+
.proc lcd_init
9999
lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
100100
jsr lcd_cmd
101101
lda #%00000001 ; Clear display
@@ -110,3 +110,8 @@ skip:
110110
lda #%00000010 ; Return home
111111
jmp lcd_cmd
112112
.endproc
113+
114+
.proc lcd_clear
115+
lda #%00000001 ; Clear display
116+
jmp lcd_cmd
117+
.endproc

led.s

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.include "defs.inc"
2+
.include "via.inc"
3+
4+
.proc led_on
5+
lda #LED
6+
sta PORTA
7+
rts
8+
.endproc
9+
10+
.proc led_off
11+
lda #0
12+
sta PORTA
13+
rts
14+
.endproc
15+
16+
.macro DELAY
17+
.local outer_loop
18+
.local inner_loop
19+
sty 0
20+
;lsl 0
21+
;lsl 0
22+
;lsl 0
23+
outer_loop:
24+
ldy #$ff
25+
inner_loop:
26+
dey
27+
bne inner_loop
28+
dec 0
29+
bne outer_loop
30+
.endmacro
31+
32+
.proc led_blink
33+
tay
34+
lda #LED
35+
sta PORTA
36+
DELAY
37+
lda #0
38+
sta PORTA
39+
rts
40+
.endproc
41+
42+
.proc led_code
43+
sec
44+
nextbit:
45+
ldy #$A0
46+
rol
47+
beq done
48+
bcc blink
49+
ldy #$50
50+
blink:
51+
tax
52+
tya
53+
jsr led_blink
54+
txa
55+
DELAY
56+
clc
57+
jmp nextbit
58+
done:
59+
rts
60+
.endproc

main.s

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
.include "defs.inc"
22

3+
RAMTEST_START = $01
4+
35
main:
6+
ldx #$ff
7+
txs
8+
9+
jsr via_init
10+
jsr led_on
11+
jsr lcd_init
12+
lda #>testing
13+
ldy #<testing
14+
jsr lcd_puts
15+
16+
lda #RAMTEST_START
417
jmp ramtest
518

619
ramtest_success:
7-
jmp ramtest_success
20+
jsr lcd_clear
21+
lda #>test_complete
22+
ldy #<test_complete
23+
jsr lcd_puts
24+
jsr led_off
25+
loop:
26+
jmp loop
27+
28+
.rodata
29+
testing:
30+
.asciiz "testing"
31+
test_complete:
32+
.asciiz "test complete"
833

934
.segment "VECTORS"
1035
nmi:

0 commit comments

Comments
 (0)