Skip to content

Commit effeb9e

Browse files
committed
Fixed kernel audio issue
1 parent 4aa38e4 commit effeb9e

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

common.def.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#define R_TXTI r10
3030
#define R_CLRI r25
3131

32+
;;; TODO: we might be able to save cycles by jumping to a special bit of code for the last tile on
33+
;;; each scanline and doing extra work between the `out`s
34+
3235
.macro TILE_ROW n,p0,p1,p2,p3,p4,p5
3336
_tilerow_\n:
3437
out VIDEO_PORT, \p0

tile_generator.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
TILE_W, TILE_H = 6, 8
77

8-
# TODO: DON'T KEEP FONT IN RAM, USE LPM TO LOAD IT
9-
108
# Note: also, only '_' actually uses a pixel on the far left in any of its rows; we might be able to
119
# cut down to 5-wide characters that always emit a background pixel on the far left
1210

@@ -49,7 +47,7 @@ def load_png(filepath):
4947
FILENAME = FILEPATH
5048

5149
OUTPUT = OUTPUT_DIR + FILENAME[0:-4] + ".s"
52-
50+
5351
PNG_W_PX, PNG_H_PX, pixels, metadata = load_png(FILEPATH)
5452
W, H = int(PNG_W_PX/TILE_W), int(PNG_H_PX/TILE_H) # width, height of our image, in tiles
5553

@@ -70,7 +68,7 @@ def load_png(filepath):
7068

7169
# for rowi in range(len(unique_rows)):
7270
# print("{}:\t{}".format(rowi, unique_rows[rowi]))
73-
71+
7472
with open(OUTPUT, 'w') as f:
7573
f.write(HEADER.format(FILEPATH))
7674

tiles.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "common.def.h"
2-
2+
33
.section .text
44

55
.global begin_code_tile_row
@@ -15,7 +15,7 @@ begin_code_tile_row:
1515
mul R_TILE_Y, r16
1616
add YL, r0
1717
adc YH, r1
18-
18+
1919
ldi XH, hi8(m96_palette)
2020

2121
;; ---------------------------------------- load first tile's colors

video.s

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
;;; ================================================================================
22
;;; Video Mode 96: text-only display with arbitrary color palettes
3-
;;;
3+
;;;
44
;;; Type: tile-based
5-
;;; Cycles/Pixel: ?? TODO
65
;;; Tile Size: 6x8
7-
;;; Resolution: ?? TODO
8-
;;;
6+
;;; Resolution: (216x224) 36x28
7+
;;;
98
;;; Each scanline must total 1820 cycles. There are 524 scanlines total.
10-
9+
1110
#include "common.def.h"
12-
11+
1312
.global vram ; just global for debugging
1413
.global m96_palette
15-
14+
1615
.section .bss
1716
vram: .space VRAM_SIZE
1817

@@ -33,7 +32,7 @@ sub_video_mode96:
3332
mov R_FONTL, r16
3433
ldi r16, hi8(m96_font)
3534
mov R_FONTH, r16
36-
35+
3736
;; pm converts from byte addresses to word addresses (divides by 2)
3837
ldi r16, lo8(pm(m96_rows))
3938
mov R_ROWSL, r16
@@ -58,8 +57,8 @@ render_scanline:
5857
;; `rcall` and `lds` both take 2 cycles, so should be 0x64
5958
lds r16, TCNT1L
6059
lds r17, TCNT1H
61-
rcall hsync_pulse ;156 cycles (154 inside hsync_pulse)
6260

61+
rcall hsync_pulse ;156 cycles (154 inside hsync_pulse) with AUDIO_OUT_HSYNC_CYCLES=135
6362
WAIT r16, HSYNC_USABLE_CYCLES - AUDIO_OUT_HSYNC_CYCLES
6463

6564
;; do our code tile setup
@@ -84,12 +83,12 @@ render_scanline:
8483
nop
8584
2:
8685
;; -------------------- continue to next line or end of frame, synced to 1820 cycle boundary
87-
WAIT r16, 55
88-
86+
WAIT r16, 41
87+
8988
;; if we've just drawn the last scanline, be done
9089
dec R_SCANLINE_COUNTER
9190
breq frame_end
92-
91+
9392
rjmp render_scanline
9493

9594
frame_end:
@@ -109,5 +108,5 @@ frame_end:
109108
;; clear any pending timer int
110109
ldi ZL,(1<<OCF1A)
111110
sts _SFR_MEM_ADDR(TIFR1),ZL
112-
111+
113112
ret ; returning from call to sub_video_mode96

videoMode.def.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
#define VMODE_FUNC sub_video_mode96
77

8-
#define HSYNC_USABLE_CYCLES 244
8+
// 258 is the maximum value of AUDIO_OUT_HSYNC_CYCLES, so less means cutting kernel functionality
9+
#define HSYNC_USABLE_CYCLES 258
910

1011
#define FONT_TILE_WIDTH 35 // size of a tile row in words
1112
#define TILE_HEIGHT 8

0 commit comments

Comments
 (0)