Skip to content

Commit 33370c3

Browse files
committedAug 23, 2024
Output characters using a loop
1 parent bb447d5 commit 33370c3

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed
 

‎asm/Makefile

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

22
ASM_FLAGS=
33

4+
.PHONY: all clean
5+
46
all: rocket.rom \
57
jumping_X_and_O.rom \
68
Fishie.rom \
79
random_number_test.rom \
810
delay_timer_test.rom \
9-
show_bcd.rom
11+
show_bcd.rom \
12+
counter.rom
1013

1114
rocket.rom: rocket.asm chip8.asm
1215
customasm -o $@ $(ASM_FLAGS) $<
@@ -29,6 +32,8 @@ delay_timer_test.rom: delay_timer_test.asm chip8.asm
2932
show_bcd.rom: show_bcd.asm chip8.asm
3033
customasm -o $@ $(ASM_FLAGS) $<
3134

32-
.phony: clean
35+
counter.rom: counter.asm chip8.asm
36+
customasm -o $@ $(ASM_FLAGS) $<
37+
3338
clean:
34-
rm *.rom
39+
rm -vf *.rom

‎asm/count.asm ‎asm/counter.asm

+20-32
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,28 @@ count_sm:
6565
; V5 ... the value we want to output
6666
;
6767
write:
68-
LD I, ascii_c ; Draw the label "COUNT = "
69-
DRW V3, V4, 5
70-
ADD V3, 6
71-
LD I, ascii_o
72-
DRW V3, V4, 5
73-
ADD V3, 6
74-
LD I, ascii_u
75-
DRW V3, V4, 5
76-
ADD V3, 6
77-
LD I, ascii_n
78-
DRW V3, V4, 5
79-
ADD V3, 6
80-
LD I, ascii_t
81-
DRW V3, V4, 5
82-
ADD V3, 6
83-
LD I, ascii_eq
84-
DRW V3, V4, 5
85-
ADD V3, 6
86-
LD I, .work ; Now draw the digit
87-
LD B, V5
88-
LD V2, [I]
89-
LD F, V0
68+
LD V0, 6 ; 6 characters
69+
LD V1, 5 ; address increment
70+
LD I, ascii_c - 5 ; initial address, offset by 5
71+
.begin:
72+
ADD I, V1 ; Load character address.
73+
DRW V3, V4, 5 ; Draw character.
74+
ADD V3, 6 ; Increment x-coordinate.
75+
ADD V0, -1 ; Decrement counter.
76+
SE V0, 0 ; If characters remain,
77+
JP .begin ; return to draw next character.
78+
LD I, digits
79+
LD B, V5 ; Load
80+
LD V2, [I] ; Load decimals into V0-V2
81+
LD F, V0 ; Digit 1
9082
DRW V3, V4, 5
9183
ADD V3, 5
92-
LD F, V1
84+
LD F, V1 ; Digit 2
9385
DRW V3, V4, 5
9486
ADD V3, 5
95-
LD F, V2
87+
LD F, V2 ; Digit 3
9688
DRW V3, V4, 5
9789
RET
98-
.work:
99-
#res 3
10090

10191
;
10292
; Alphabetic characters
@@ -107,38 +97,36 @@ ascii_c:
10797
#d8 0b10000000
10898
#d8 0b10000000
10999
#d8 0b11111000
110-
111100
ascii_o:
112101
#d8 0b11111000
113102
#d8 0b10001000
114103
#d8 0b10001000
115104
#d8 0b10001000
116105
#d8 0b11111000
117-
118106
ascii_u:
119107
#d8 0b10001000
120108
#d8 0b10001000
121109
#d8 0b10001000
122110
#d8 0b10001000
123111
#d8 0b11111000
124-
125112
ascii_n:
126113
#d8 0b10001000
127114
#d8 0b11001000
128115
#d8 0b10101000
129116
#d8 0b10011000
130117
#d8 0b10001000
131-
132118
ascii_t:
133119
#d8 0b11111000
134120
#d8 0b00100000
135121
#d8 0b00100000
136122
#d8 0b00100000
137123
#d8 0b00100000
138-
139124
ascii_eq:
140125
#d8 0b00000000
141126
#d8 0b11111000
142127
#d8 0b00000000
143128
#d8 0b11111000
144-
#d8 0b00000000
129+
#d8 0b00000000
130+
digits:
131+
#res 3
132+

0 commit comments

Comments
 (0)
Failed to load comments.