summary refs log tree commit diff
path: root/code/glumbo.a
blob: 72accf62fdb64245d5da4abbd2e7bd9f3fe5af9f (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
; GLUMBO - the 2d game thing

.macro store(reg, val, addr) \
    put @reg @val\
    str @reg @addr
.macro storer(reg, val, addr) \
    put @reg @val\
    srr @reg @addr

jmp start
get_coord:
    ld a tmp2              ; Y(0-4) -> a
    mov b width            ; width (5) -> b
    mul                    ; Y(0-4) * width (5)

    mov a grid_start       ; grid start address -> a
    swp c b                ; (offset from y) -> b
    add                    ; offsetY + gridStart
    swp c a                ; -> a
    ld b tmp1              ; X(0-4) -> b
    add                    ; loc + X

    str c tmp3             ; location -> tmp3
    ret

start:
    .label width 20
    .label height 10

    .label grid_start 512
    ; temp vars
    .label tmp1 0
    .label tmp2 1
    .label tmp3 2
    .label tmp4 3
    .label tmp5 4

    .label px 16
    .label py 17
    .label inp 256
    store a 2 px
    store a 2 py

    store a 0 tmp1 ; x
    store a 0 tmp2 ; y
    mov a 2
    mov b 1
    sys
    grid_loop:
        ;get coord
            jmr get_coord
        ;store tile
            ; storer a 46 c
        ;main loop stuff
        ; place tile
            ; get X % (width - 1) to check if on x edge
                store a 46 tmp4
                mov a width         ; width -> A
                mov b 1             ; 1 -> b
                sub                 ; c = width - 1
                swp c b             ; -> b
                ld a tmp1           ; x -> a
                mod                 ; c = x % (w - 1)
                mov a 0             ;
                crr c c a           ; c = c == 0?
                str c tmp5          ; c -> tmp5

            ; Y % (height - 1 )
                mov a height        ; height -> A
                mov b 1             ; 1 -> b
                sub                 ; c = height - 1
                swp c b             ; -> b
                ld a tmp2           ; x -> a
                mod                 ; c = x % (w - 1)
                mov a 0
                crr a c a           ; a = c == 0?

            ld b tmp5
            or
            cmp c 1

            jz do_the_store     ; edge ? continue : jmp do_the_store
            store a 35 tmp4     ; store 35 at tmp4
            do_the_store:
                ld b tmp3       ; location -> b
                ld a tmp4       ; tmp4 (character) -> a
                srr a b         ; store the tile
        ;;;;;;;;;;;;;;;;;;;;;;;;;
        mov a width             ; width -> a
        mov b 1                 ; 1 -> b
        sub                     ; c = width - 1
        ld a tmp1               ; X(0-4) -> a
        cmr a c                 ; X(0-4) == width
        jnz ifz                 ; go to ifz if X(0-4) == width (5)
        ifnz:                   ; X is not 0
            ld a tmp1           ; X -> a
            mov b 1             ; 1 -> b
            add                 ; X + 1
            str c tmp1          ; X = X + 1
            jmp continue_loop   ; continue
        ifz:                    ; X is 0
            store a 0 tmp1      ; set X to 1
            ld a tmp2           ; Y(0-4) -> a
            mov b 1             ; 1 -> b
            add                 ; c = Y + 1
            str c tmp2          ; Y = c
            jmp continue_loop   ; continue
        continue_loop:
            mov a height
            mov b 0
            sub
            ld a tmp2           ; get Y (0-4)
            cmr a c             ; Y == height+1 ?
            jz grid_loop        ; if not, continue
    ; escaped
    main_loop:
        jmr print
        ; get input
            mov a 0
            mov b 0
            mov c inp
            sys
            jmr parse_input
        jmp main_loop

parse_input:
    .macro case(addr, val, ln) \
        ld a @addr\
        cmp a @val\
        jnz @ln
    .macro break() jmp default

    case inp 119 case_w
    case inp 115 case_s
    case inp 97 case_a
    case inp 100 case_d

    case inp 99 case_c
    case inp 3 case_c
    break

    case_w:
        ld a py
        cmp a 0
        jnz default
        mov b 1
        sub
        str c py
        break
    
    case_s:
        ; width-1
            mov a width
            mov b 1
            sub

        ld a py
        cmr a c
        jnz default
        mov b 1
        add
        str c py
        break
    
    case_a:
        ld a px
        cmp a 0
        jnz default
        mov b 1
        sub
        str c px
        break
    
    case_d:
        ; width-1
            mov a width
            mov b 1
            sub

        ld a px
        cmr a c
        jnz default
        mov b 1
        add
        str c px
        break
    
    case_c:
        halt
        break

    default:
        ret

print:
    mov a 1
    mov b 1
    mov c [clear]
    sys
    store a 0 tmp1 ; x
    store a 0 tmp2 ; y
    print_loop:
        ;get coord
            jmr get_coord
        ; get tile
            ld a tmp3
            ldr b a
            str b 128
            store a 0 129

            ;TODO - make player tile be a @ or something
            ld a tmp1 ; x
            ld b px   ; player x
            crr c a b
            str c tmp4
            ld a tmp2 ; y
            ld b py   ; player y
            crr b a b
            ld a tmp4
            and
            cmp c 1
            jz print_normal
                store a 64 128
            print_normal:
                ; print
                mov a 1
                mov b 1
                mov c 128
                sys
                ; ld c 128
                ; dbg a
        ;loop
            mov a width
            mov b 1
            sub
            ld a tmp1              ; X(0-4) -> a
            cmr a c                ; X(0-4) == width
            jnz p_ifz              ; go to ifz if X(0-4) == width
            p_ifnz:                ; X is not 0
                ld a tmp1          ; X -> a
                mov b 1            ; 1 -> b
                add                ; X + 1
                str c tmp1         ; X = X + 1
                jmp continue_ploop ; continue
            p_ifz:                 ; X is 0
                store a 10 128
                store a 0 129
                mov a 1
                mov b 1
                mov c 128
                sys
                store a 0 tmp1     ; set X to 1
                ld a tmp2          ; Y(0-4) -> a
                mov b 1            ; 1 -> b
                add                ; c = Y + 1
                str c tmp2         ; Y = c
                jmp continue_ploop ; continue
            continue_ploop:
                mov a height
                mov b 0
                sub
                ld a tmp2          ; get Y (0-4)
                cmr a c            ; Y == width+1 ?
                jz print_loop      ; if not, continue
    ret
clear:
.hex 1b
.str "[2J"
.hex 1b
.str "[0;0H"
.hex 0