File: counter.wl

package info (click to toggle)
wadc 2.1%2Bgit3aac3015-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,312 kB
  • ctags: 643
  • sloc: java: 2,771; ansic: 1,526; xml: 125; makefile: 33; sh: 13
file content (161 lines) | stat: -rw-r--r-- 4,050 bytes parent folder | download | duplicates (3)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * counter.wl - part of WadC
 * Copyright © 2016 Jonathan Dowland <jon@dow.land>
 *
 * Distributed under the terms of the GNU GPL Version 2
 * See file LICENSE.txt
 *
 * an 8-bit binary ripple counter
 * implementation based on Fraggle's by-hand version
 * https://www.doomworld.com/idgames/levels/doom2/Ports/a-c/counter
 */

#"control.h"
#"basic.h"
#"boom.h"

main {
    -- control lines for scrolling
    linetype(253, $scroll_north_ish) step(256,-64)
    linetype(253, $scroll_east_ish)  step(64,256)
    linetype(253, $scroll_south_ish) step(-256,64)
    linetype(253, $scroll_west_ish)  step(-64,-256)
    leftsector(0,0,0)
    linetype(0,0)

    countertextures

    move(512)
    !main
    counters(8)
}

/*
 * some custom textures for the counter display
 * (etc)
 */
countertextures {
    -- custom texture for binary display
    texture("RIPPLE", 64, 128)
    addpatch("COMP03_1", 0, 0)
    addpatch("COMP03_2", 0, 64)
    addpatch("WINUM0",   0, 116)
    addpatch("WINUM1",  32, 116)

    -- redefine switch textures
    texture("SW1STRTN", 64, 128)
    addpatch("RW24_2", 0, 0)
    addpatch("SW1S0", 16, 72)
    texture("SW2STRTN", 64, 128)
    addpatch("RW24_2", 0, 0)
    addpatch("SW1S1", 16, 72)
}

counters(x) {
    -- ripple counters themselves
    -- from most signifiant bit to least
    set("carry", 0)
    fori(1, x,
      set("current", newtag)
      set(cat("show",i), counter(get("current"), get("carry")))
      set("carry", get("current"))
      movestep(0,256)
    ) 

    -- viewing space
    ^main
    movestep(192,-64)
    unpegged
    sectortype(0, 0)
    straight(256)

    right(mul(x,256))
    !digits

    linetype(gendoor(trigger_sr,
      speed_turbo,
      door_open_delay_close,
      0,
      door_delay_1s), get("current"))
    mid("SW1STRTN")
    straight(64)
    mid("BRICK7")
    linetype(0,0)

    right(256) 
    right(mul(x,256)) straight(64)
    rightsector(0,128,160)

    ^digits
    move(-64) rotleft
    fori(1, x,
      digit(get(cat("show",i))) movestep(0,-64)
    )

    placeitem(-64, 0, turnaround player1start)
}

/*
 * a big 1/0 digit display
 */
digit(tag) {
  !digit
    top("RIPPLE") bot("RIPPLE")
    straight(2) xoff(32) yoff(96) right(32) xoff(0) yoff(0) right(2) right(32) rotright rightsector(48,80,144)
    move(2)
    sectortype(0,tag)
    straight(2) yoff(96) right(32) yoff(0) right(2) right(32) rotright rightsector(48,80,144)
    sectortype(0,0)
    move(2)
    box(80,80,144,2,32)
  ^digit
}

/*
 * counter - a binary ripple register
 * 	tag - the sector tag value for activating/incrementing this register
 * 	carry - the sector tag value of the next counter register to carry into 
 * 	returns: a tag value to use for displaying the register value
 */
counter(tag, carry) {
    -- XXX: these directions are a bit misleading because of the WadC/Doom
    -- disagreement on the X axis direction
    set("counter", newtag)
    sectortype(0, $scroll_east_ish)  trapezium(get("counter"),83)  guard(tag,carry) movestep(0,192) rotleft
    sectortype(0, $scroll_north_ish) trapezium(0,0)                                 movestep(0,192) rotleft
    sectortype(0, $scroll_west_ish)  trapezium(get("counter"),84)  guard(tag,0)     movestep(0,192) rotleft
    sectortype(0, $scroll_south_ish) trapezium(0,0)                                 movestep(0,192) rotleft
    placeitem(96,32,rotright player1start)

    get("counter")
}

/*
 * recv is the receiver of the value (counter display)
 */
trapezium(recv,type) {
    step(80,80)
    step(0,32)
    { eq(recv,0) ? 0 : linetype(type, recv) } step(-80,80) linetype(0,0)
    impassable step(0,-192) impassable
    rightsector(16,80,120)
}

/*
 * door used to gate the counters
 */
guard(tag,carry) {
  !guard
    movestep(72,100)
    left(8)
    { eq(0,carry) ? 0 : linetype(gendoor(
          trigger_wr,
          speed_turbo,
          door_open_delay_close,
          0,
          door_delay_1s), carry) } left(64) linetype(0,0)
    left(8)
    left(64)
    sectortype(0,tag) innerleftsector(16,16,0) sectortype(0,0)
  ^guard
}