-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.tcl
145 lines (116 loc) · 3.5 KB
/
render.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# horizontal constants
set H_DISPLAY 640 ; # horizontal display width
set H_BACK 48 ; # horizontal left border (back porch)
set H_FRONT 16 ; # horizontal right border (front porch)
set H_SYNC 96 ; # horizontal sync width
# vertical constants
set V_DISPLAY 480 ; # vertical display height
set V_TOP 33 ; # vertical top border
set V_BOTTOM 10 ; # vertical bottom border
set V_SYNC 2 ; # vertical sync # lines
# derived constants
set H_SYNC_START [expr { $H_DISPLAY + $H_FRONT }]
set H_SYNC_END [expr { $H_DISPLAY + $H_FRONT + $H_SYNC - 1 }]
set H_MAX_SIZE [expr { $H_DISPLAY + $H_BACK + $H_FRONT + $H_SYNC }]
set H_MAX [expr { $H_MAX_SIZE - 1 }]
set V_SYNC_START [expr { $V_DISPLAY + $V_BOTTOM }]
set V_SYNC_END [expr { $V_DISPLAY + $V_BOTTOM + $V_SYNC - 1 }]
set V_MAX_SIZE [expr { $V_DISPLAY + $V_TOP + $V_BOTTOM + $V_SYNC }]
set V_MAX [expr { $V_MAX_SIZE - 1 }]
proc isPosClock { line } {
if { [ string index $line 0 ] == "1" } { return 1 }
return 0
}
proc isNegClock { line } {
return [ expr ! [ isPosClock $line ] ]
}
proc isHSyncUp { line } {
if { [ string index $line 2 ] == "1" } { return 1 }
return 0
}
proc isHSyncDown { line } {
return [ expr ! [ isHSyncUp $line ] ]
}
proc isVSyncUp { line } {
if { [ string index $line 4 ] == "1" } { return 1 }
return 0
}
proc isVSyncDown { line } {
return [ expr ! [ isVSyncUp $line ] ]
}
proc color { line } {
return [string range $line 6 12]
}
# Canvas
set theCanvas [ canvas .can -width $H_MAX_SIZE -height $V_MAX_SIZE -background "#ff0000" ]
# Image
set theImage [ image create photo -width $H_MAX_SIZE -height $V_MAX_SIZE -palette 256/256/256 ]
# Canvas image item
set theImageId [ .can create image 0 0 -anchor nw -image $theImage ]
pack .can
wm title . "VGA Renderer - Pattern from file"
wm geometry . "${H_MAX_SIZE}x${V_MAX_SIZE}"
#set infile [open "simulate_hexa.log" r]
set infile stdin
set offset 0
update
$theCanvas create rect \
[ expr { $H_BACK - 2 } ] \
[ expr { $V_TOP -2 } ] \
[ expr { $H_BACK + $H_DISPLAY } ] \
[ expr { $V_DISPLAY + $V_TOP } ] \
-fill "" -width 2 -outline green
while 1 {
puts "searching for next vsync..."
while { [gets $infile line] >= 0 && [ isVSyncDown $line ] } { incr offset }
puts "line : $line"
puts "offset : $offset"
update
puts "skipping vsync up to vertical front porch"
while { [gets $infile line] >= 0 && [ isVSyncUp $line ] } { incr offset }
puts "line : $line"
puts "offset : $offset"
update
puts "drawing..."
set x 0
set y 0
set mode "hsyncDown"
set skip 0
# read until first vsync
while { [gets $infile line] >= 0 && [ isVSyncDown $line ] } {
incr offset
# only negclock, skip posclock
if { [ isPosClock $line ] } { continue }
if { $skip == 3 } {
set skip 0
} else {
incr skip
continue
}
switch $mode {
"hsyncDown" {
if { [ isHSyncUp $line ] } {
set mode "hsyncUp"
}
incr x
}
"hsyncUp" {
if { [ isHSyncDown $line ] } {
set mode "hsyncDown"
update
set x 0
incr y
for {set idx 0 } { $idx < $H_MAX_SIZE } {incr idx } {
$theImage put "#ffffff" -to $idx $y [expr {$idx + 3}] [expr {$y + 3}]
}
}
}
}
$theImage put [ color $line ] -to $x $y [expr {$x + 1}] [expr {$y + 1}]
}
puts "end frame : $offset"
if { $line == "" } {
break
}
}
puts "end file : $offset"