OpenCores
URL https://opencores.org/ocsvn/i650/i650/trunk

Subversion Repositories i650

[/] [i650/] [trunk/] [rtl/] [operator_ctl.v] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 eightycc
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// IBM 650 Reconstruction in Verilog (i650)
4
// 
5
// This file is part of the IBM 650 Reconstruction in Verilog (i650) project
6
// http:////www.opencores.org/project,i650
7
//
8
// Description: Operator console and external control interface.
9
// 
10
// Additional Comments: See US 2959351, Fig. 75, 76, 76 and 77. Also implements
11
//  a simple command-based control interface.
12
//
13
// Copyright (c) 2015 Robert Abeles
14
//
15
// This source file is free software; you can redistribute it
16
// and/or modify it under the terms of the GNU Lesser General
17
// Public License as published by the Free Software Foundation;
18
// either version 2.1 of the License, or (at your option) any
19
// later version.
20
//
21
// This source is distributed in the hope that it will be
22
// useful, but WITHOUT ANY WARRANTY; without even the implied
23
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
24
// PURPOSE.  See the GNU Lesser General Public License for more
25
// details.
26
//
27
// You should have received a copy of the GNU Lesser General
28
// Public License along with this source; if not, download it
29
// from http://www.opencores.org/lgpl.shtml
30
//////////////////////////////////////////////////////////////////////////////////
31
`include "defines.v"
32
 
33
module operator_ctl (
34 11 eightycc
      input rst, clk,
35 7 eightycc
      input ap, dp,
36 16 eightycc
      input dx, d0, d1, d2, d3, d4, d5, d6, d9, d10,
37
      input wu, wl, hp,
38 7 eightycc
      input [0:3] early_idx, ontime_idx,
39
 
40 15 eightycc
      input [0:6] cmd_digit_in, io_buffer_in, gs_in, acc_ontime, dist_ontime,
41
                  prog_ontime,
42 7 eightycc
      input [0:5] command,
43 22 eightycc
      input restart_reset,
44 7 eightycc
 
45 11 eightycc
      output reg[0:6] data_out, addr_out, console_out,
46 15 eightycc
      output [0:6] display_digit,
47 21 eightycc
      output reg console_to_addr, acc_ri_console,
48 7 eightycc
      output reg[0:14] gs_ram_addr,
49 10 eightycc
      output reg read_gs, write_gs,
50 7 eightycc
      output reg pgm_start, pgm_stop, err_reset, err_sense_reset,
51
      output run_control, half_or_pgm_stop, ri_storage, ro_storage,
52
             storage_control,
53 16 eightycc
      output reg man_pgm_reset, man_acc_reset, hard_reset,
54
      output set_8000, reset_8000,
55 7 eightycc
 
56
      output reg[0:6] cmd_digit_out,
57 22 eightycc
      output reg busy, digit_ready, restart_reset_busy,
58 7 eightycc
      output reg punch_card, read_card, card_digit_ready
59
   );
60
 
61
   //-----------------------------------------------------------------------------
62 12 eightycc
   // Operator console switch settings and their control signals.
63 7 eightycc
   //-----------------------------------------------------------------------------
64
   reg pgm_sw_stop, pgm_sw_run,
65
       half_cycle_sw_run, half_cycle_sw_half,
66
       ctl_sw_addr_stop, ctl_sw_run, ctl_sw_manual,
67
       disp_sw_lacc, disp_sw_uacc, disp_sw_dist, disp_sw_pgm,
68
       disp_sw_ri, disp_sw_ro,
69
       ovflw_sw_stop, ovflw_sw_sense, err_sw_stop, err_sw_sense;
70
   reg [0:6] storage_entry_sw [0:15];
71
   reg [0:6] addr_sel_sw [0:3];
72
   assign run_control = disp_sw_lacc | disp_sw_uacc | disp_sw_dist | disp_sw_pgm;
73
   assign half_or_pgm_stop = half_cycle_sw_half | pgm_stop;
74
   assign ri_storage = disp_sw_ri;
75
   assign ro_storage = disp_sw_ro;
76
   assign storage_control = run_control | disp_sw_ro;
77 15 eightycc
   assign display_digit = (disp_sw_lacc | disp_sw_uacc)? acc_ontime
78
                        : (disp_sw_dist | disp_sw_ri | disp_sw_ro)? dist_ontime
79
                        : disp_sw_pgm? prog_ontime
80
                        : `biq_blank;
81 16 eightycc
   assign set_8000 = man_pgm_reset & (ctl_sw_addr_stop | ctl_sw_run);
82
   assign reset_8000 = man_pgm_reset & ctl_sw_manual;
83 7 eightycc
 
84 12 eightycc
   //-----------------------------------------------------------------------------
85
   // Calculate the RAM address of the general storage word at address gs_addr_.
86
   //-----------------------------------------------------------------------------
87 7 eightycc
   reg [0:6] gs_addr_th, gs_addr_h, gs_addr_t, gs_addr_u;
88 9 eightycc
   wire [0:14] gs_band_addr;
89 10 eightycc
   wire [0:9] gs_word_offset;
90 9 eightycc
   ram_band_addr rba(gs_addr_th, gs_addr_h, gs_addr_t, gs_band_addr);
91 7 eightycc
   ram_word_offset rwo(gs_addr_t, gs_addr_u, gs_word_offset);
92
   wire [0:14] gs_word_addr = gs_band_addr + gs_word_offset;
93
 
94 12 eightycc
   //-----------------------------------------------------------------------------
95
   // Operator console state machine
96
   //-----------------------------------------------------------------------------
97
   reg do_power_on_reset, do_reset_console, do_err_reset, do_err_sense_reset,
98
       do_pgm_reset, do_acc_reset, do_hard_reset, do_clear_drum;
99
   reg [0:5] state;
100
 
101 7 eightycc
   `define state_idle                  6'd0
102
 
103
   `define state_reset_console_1       6'd1
104
   `define state_reset_console_2       6'd2
105
   `define state_pgm_reset_1           6'd3
106
   `define state_pgm_reset_2           6'd4
107
   `define state_acc_reset_1           6'd5
108
   `define state_acc_reset_2           6'd6
109
   `define state_err_reset_1           6'd7
110
   `define state_err_reset_2           6'd8
111
   `define state_err_sense_reset_1     6'd9
112
   `define state_err_sense_reset_2     6'd10
113 11 eightycc
   `define state_hard_reset_1          6'd11
114 7 eightycc
 
115 11 eightycc
   `define state_storage_entry_sw_1    6'd12
116
   `define state_storage_entry_sw_2    6'd13
117
   `define state_addr_sel_sw_1         6'd14
118
   `define state_addr_sel_sw_2         6'd15
119 7 eightycc
 
120 11 eightycc
   `define state_xfer_key_1            6'd16
121
   `define state_xfer_key_2            6'd17
122
   `define state_pgm_start_key_1       6'd18
123
   `define state_pgm_start_key_2       6'd19
124
   `define state_pgm_stop_key_1        6'd20
125
   `define state_pgm_stop_key_2        6'd21
126 7 eightycc
 
127 11 eightycc
   `define state_read_gs_1             6'd30
128
   `define state_read_gs_2             6'd31
129
   `define state_read_gs_3             6'd32
130
   `define state_read_gs_4             6'd33
131
   `define state_read_gs_5             6'd34
132 12 eightycc
   `define state_read_gs_6             6'd35
133 13 eightycc
   `define state_write_gs_1            6'd36
134
   `define state_write_gs_2            6'd37
135
   `define state_write_gs_3            6'd38
136
   `define state_write_gs_4            6'd39
137
   `define state_write_gs_5            6'd40
138 16 eightycc
   `define state_read_acc_1            6'd41
139
   `define state_read_acc_2            6'd42
140
   `define state_read_acc_3            6'd43
141
   `define state_read_dist_1           6'd44
142
   `define state_read_dist_2           6'd45
143
   `define state_read_dist_3           6'd46
144
   `define state_read_prog_1           6'd47
145
   `define state_read_prog_2           6'd48
146
   `define state_read_prog_3           6'd49
147 21 eightycc
   `define state_write_acc_1           6'd50
148
   `define state_write_acc_2           6'd51
149
   `define state_write_acc_3           6'd52
150
   `define state_clear_drum_1          6'd53
151
   `define state_clear_drum_2          6'd54
152
   `define state_clear_drum_3          6'd55
153
   `define state_load_gs_1             6'd56
154
   `define state_load_gs_2             6'd57
155
   `define state_dump_gs_1             6'd58
156
   `define state_dump_gs_2             6'd59
157
   `define state_dump_gs_3             6'd60
158
   `define state_dump_gs_4             6'd61
159 7 eightycc
 
160 20 eightycc
   always @(posedge clk)
161 7 eightycc
      if (rst) begin
162
         console_to_addr  <= 0;
163
         pgm_start        <= 0;
164
         pgm_stop         <= 0;
165
         err_reset        <= 0;
166
         err_sense_reset  <= 0;
167
         man_pgm_reset    <= 0;
168
         man_acc_reset    <= 0;
169 11 eightycc
         hard_reset       <= 0;
170 7 eightycc
 
171
         // reset console switches
172
         pgm_sw_stop      <= 0;
173
         pgm_sw_run       <= 1;
174 11 eightycc
         half_cycle_sw_run <= 1;
175
         half_cycle_sw_half <= 0;
176 7 eightycc
         ctl_sw_addr_stop <= 0;
177
         ctl_sw_run       <= 1;
178
         ctl_sw_manual    <= 0;
179
         disp_sw_lacc     <= 0;
180
         disp_sw_uacc     <= 0;
181
         disp_sw_dist     <= 1;
182 22 eightycc
         disp_sw_pgm      <= 0;
183 7 eightycc
         disp_sw_ri       <= 0;
184
         disp_sw_ro       <= 0;
185
         ovflw_sw_stop    <= 1;
186
         ovflw_sw_sense   <= 0;
187
         err_sw_stop      <= 1;
188
         err_sw_sense     <= 0;
189
 
190
         state         <= `state_idle;
191
         busy          <= 1;
192
         digit_ready   <= 0;
193
         cmd_digit_out <= `biq_blank;
194 22 eightycc
         restart_reset_busy <= 0;
195 7 eightycc
 
196
         do_power_on_reset  <= 1;
197
         do_reset_console   <= 0;
198
         do_err_reset       <= 0;
199
         do_err_sense_reset <= 0;
200
         do_pgm_reset       <= 0;
201
         do_acc_reset       <= 0;
202 11 eightycc
         do_hard_reset      <= 0;
203
         do_clear_drum      <= 0;
204 7 eightycc
 
205
         gs_ram_addr        <= 15'd0;
206 9 eightycc
         read_gs            <= 0;
207 10 eightycc
         write_gs           <= 0;
208 21 eightycc
         acc_ri_console     <= 0;
209 11 eightycc
         console_out        <= `biq_blank;
210
      end else if (dp) begin
211 7 eightycc
         case (state)
212
            `state_idle: begin
213
               case (command)
214
                  `cmd_none: begin
215 22 eightycc
                     if (restart_reset) begin
216
                        do_pgm_reset       <= 1;
217
                        do_acc_reset       <= 1;
218
                        do_err_reset       <= 1;
219
                        restart_reset_busy <= 1;
220
                     end else if (do_power_on_reset) begin
221 7 eightycc
                        do_power_on_reset  <= 0;
222
                        do_reset_console   <= 1;
223
                        do_pgm_reset       <= 1;
224
                        do_acc_reset       <= 1;
225
                        do_err_reset       <= 1;
226
                        do_err_sense_reset <= 1;
227 11 eightycc
                        do_hard_reset      <= 1;
228
                        do_clear_drum      <= 1;
229
                     end else if (do_hard_reset) begin
230 22 eightycc
                        do_hard_reset      <= 0;
231
                        hard_reset         <= 1;
232 11 eightycc
                        state <= `state_hard_reset_1;
233 7 eightycc
                     end else if (do_reset_console) begin
234
                        do_reset_console   <= 0;
235
                        state <= `state_reset_console_1;
236
                     end else if (do_pgm_reset) begin
237
                        do_pgm_reset       <= 0;
238
                        state <= `state_pgm_reset_1;
239
                     end else if (do_acc_reset) begin
240
                        do_acc_reset       <= 0;
241
                        man_acc_reset      <= 1;
242
                        state <= `state_acc_reset_1;
243
                     end else if (do_err_reset) begin
244
                        do_err_reset       <= 0;
245
                        err_reset          <= 1;
246
                        state <= `state_err_reset_1;
247
                     end else if (do_err_sense_reset) begin
248
                        do_err_sense_reset <= 0;
249 22 eightycc
                        err_sense_reset    <= 1;
250 7 eightycc
                        state <= `state_err_sense_reset_1;
251 21 eightycc
                     end else if (do_clear_drum) begin
252 22 eightycc
                        do_clear_drum      <= 0;
253 21 eightycc
                        state <= `state_clear_drum_1;
254 7 eightycc
                     end else begin
255
                        busy <= 0;
256
                        digit_ready <= 0;
257 22 eightycc
                        restart_reset_busy <= 0;
258 7 eightycc
                     end
259
                  end
260
 
261
                  `cmd_pgm_sw_stop: begin
262
                     busy <= 1;
263
                     pgm_sw_stop <= 1;
264
                     pgm_sw_run  <= 0;
265
                  end
266
 
267
                  `cmd_pgm_sw_run: begin
268
                     busy <= 1;
269
                     pgm_sw_stop <= 0;
270
                     pgm_sw_run  <= 1;
271
                  end
272
 
273
                  `cmd_half_cycle_sw_run: begin
274
                     busy <= 1;
275
                     half_cycle_sw_run  <= 1;
276
                     half_cycle_sw_half <= 0;
277
                  end
278
 
279
                  `cmd_half_cycle_sw_half: begin
280
                     busy <= 1;
281
                     half_cycle_sw_run  <= 0;
282
                     half_cycle_sw_half <= 1;
283
                  end
284
 
285
                  `cmd_ctl_sw_addr_stop: begin
286
                     busy <= 1;
287
                     ctl_sw_addr_stop <= 1;
288
                     ctl_sw_run       <= 0;
289
                     ctl_sw_manual    <= 0;
290
                  end
291
 
292
                  `cmd_ctl_sw_run: begin
293
                     busy <= 1;
294
                     ctl_sw_addr_stop <= 0;
295
                     ctl_sw_run       <= 1;
296
                     ctl_sw_manual    <= 0;
297
                  end
298
 
299
                  `cmd_ctl_sw_manual: begin
300
                     busy <= 1;
301
                     ctl_sw_addr_stop <= 0;
302
                     ctl_sw_run       <= 0;
303
                     ctl_sw_manual    <= 1;
304
                  end
305
 
306
                  `cmd_disp_sw_lacc: begin
307
                     busy <= 1;
308
                     disp_sw_lacc <= 1;
309
                     disp_sw_uacc <= 0;
310
                     disp_sw_dist <= 0;
311 22 eightycc
                     disp_sw_pgm  <= 0;
312 7 eightycc
                     disp_sw_ri   <= 0;
313
                     disp_sw_ro   <= 0;
314
                  end
315
 
316
                  `cmd_disp_sw_uacc: begin
317
                     busy <= 1;
318
                     disp_sw_lacc <= 0;
319
                     disp_sw_uacc <= 1;
320
                     disp_sw_dist <= 0;
321
                     disp_sw_pgm <= 0;
322
                     disp_sw_ri   <= 0;
323
                     disp_sw_ro   <= 0;
324
                  end
325
 
326
                  `cmd_disp_sw_dist: begin
327
                     busy <= 1;
328
                     disp_sw_lacc <= 0;
329
                     disp_sw_uacc <= 0;
330
                     disp_sw_dist <= 1;
331
                     disp_sw_pgm <= 0;
332
                     disp_sw_ri   <= 0;
333
                     disp_sw_ro   <= 0;
334
                  end
335
 
336
                  `cmd_disp_sw_prog: begin
337
                     busy <= 1;
338
                     disp_sw_lacc <= 0;
339
                     disp_sw_uacc <= 0;
340
                     disp_sw_dist <= 0;
341
                     disp_sw_pgm <= 1;
342
                     disp_sw_ri   <= 0;
343
                     disp_sw_ro   <= 0;
344
                  end
345
 
346
                  `cmd_disp_sw_ri: begin
347
                     busy <= 1;
348
                     disp_sw_lacc <= 0;
349
                     disp_sw_uacc <= 0;
350
                     disp_sw_dist <= 0;
351
                     disp_sw_pgm <= 0;
352
                     disp_sw_ri   <= 1;
353
                     disp_sw_ro   <= 0;
354
                  end
355
 
356
                  `cmd_disp_sw_ro: begin
357
                     busy <= 1;
358
                     disp_sw_lacc <= 0;
359
                     disp_sw_uacc <= 0;
360
                     disp_sw_dist <= 0;
361
                     disp_sw_pgm <= 0;
362
                     disp_sw_ri   <= 0;
363
                     disp_sw_ro   <= 1;
364
                  end
365
 
366
                  `cmd_ovflw_sw_stop: begin
367
                     busy <= 1;
368
                     ovflw_sw_stop  <= 1;
369
                     ovflw_sw_sense <= 0;
370
                  end
371
 
372
                  `cmd_ovflw_sw_sense: begin
373
                     busy <= 1;
374
                     ovflw_sw_stop  <= 0;
375
                     ovflw_sw_sense <= 1;
376
                  end
377
 
378
                  `cmd_err_sw_stop: begin
379
                     busy <= 1;
380
                     err_sw_stop  <= 1;
381
                     err_sw_sense <= 0;
382
                  end
383
 
384
                  `cmd_err_sw_sense: begin
385
                     busy <= 1;
386
                     err_sw_stop  <= 0;
387
                     err_sw_sense <= 1;
388
                  end
389
 
390
                  `cmd_storage_entry_sw: begin
391
                     busy <= 1;
392
                     state <= `state_storage_entry_sw_1;
393
                  end
394
 
395
                  `cmd_addr_sel_sw: begin
396
                     busy <= 1;
397
                     state <= `state_addr_sel_sw_1;
398
                  end
399
 
400
                  `cmd_xfer_key: begin
401
                     if (ctl_sw_manual) begin
402
                        busy <= 1;
403
                        state <= `state_xfer_key_1;
404
                     end
405
                  end
406
 
407
                  `cmd_pgm_start_key: begin
408
                     busy <= 1;
409
                     state <= `state_pgm_start_key_1;
410
                  end
411
 
412
                  `cmd_pgm_stop_key: begin
413
                     busy <= 1;
414
                     pgm_stop <= 1;
415
                     state <= `state_pgm_stop_key_1;
416
                  end
417
 
418
                  `cmd_pgm_reset_key: begin
419 11 eightycc
                     busy <= 1;
420 7 eightycc
                     do_pgm_reset <= 1;
421
                     do_err_reset <= 1;
422
                  end
423
 
424
                  `cmd_comp_reset_key: begin
425 11 eightycc
                     busy <= 1;
426 7 eightycc
                     do_pgm_reset <= 1;
427
                     do_acc_reset <= 1;
428
                     do_err_reset <= 1;
429
                  end
430
 
431
                  `cmd_acc_reset_key: begin
432 11 eightycc
                     busy <= 1;
433 7 eightycc
                     do_acc_reset <= 1;
434
                     do_err_reset <= 1;
435
                  end
436
 
437
                  `cmd_err_reset_key: begin
438 11 eightycc
                     busy <= 1;
439 7 eightycc
                     do_err_reset <= 1;
440
                  end
441
 
442
                  `cmd_err_sense_reset_key: begin
443 11 eightycc
                     busy <= 1;
444 7 eightycc
                     do_err_sense_reset <= 1;
445
                  end
446
 
447
                  //--------------------------------------------------------------
448
                  // Read from general storage:
449
                  //    --> 4 digits address, little-endian
450
                  //    <-- 1 digit sign, 10 digits, little-endian
451
                  // 0 : Ignore if CPU not stopped
452
                  //     Accept low-order address digit
453
                  // 1 : Accept remaining address digits
454
                  // 2 : Calculate word origin in gs RAM
455
                  //     Validate address
456
                  //     console_read_gs <= 1;
457
                  // 3 : Send gs-early digit to out
458
                  //     digit_ready <= 1;
459
                  // 4 : digit_ready <= 0;
460
                  //--------------------------------------------------------------
461
                  `cmd_read_gs: begin
462
                     if (ctl_sw_manual) begin
463
                        busy <= 1;
464
                        state <= `state_read_gs_1;
465
                     end
466
                  end
467 10 eightycc
 
468 13 eightycc
                  // Write word to general storage:
469
                  //    --> 4 digits address, little-endian
470
                  //    <-- dx digit, sign digit, d1-d10
471
                  // 0: Ignore if not in manual
472
                  // 1: Readin low-order addr digit
473
                  // 2: Readin remaining addr digits
474
                  // 3: Synchronize with d10
475
                  //    digit_ready <- 1
476
                  // 4: Readin first digit
477
                  // 5: Write digit
478
                  //    Readin next digit
479
                  // 6: Cleanup
480 9 eightycc
                  `cmd_write_gs: begin
481 13 eightycc
                     if (ctl_sw_manual) begin
482
                        busy <= 1;
483
                        state <= `state_write_gs_1;
484
                     end
485 10 eightycc
                  end
486
 
487 9 eightycc
                  `cmd_read_acc: begin
488 16 eightycc
                     busy <= 1;
489
                     state <= `state_read_acc_1;
490 10 eightycc
                  end
491
 
492 9 eightycc
                  `cmd_read_dist: begin
493 16 eightycc
                     busy <= 1;
494
                     state <= `state_read_dist_1;
495 10 eightycc
                  end
496
 
497 9 eightycc
                  `cmd_read_prog: begin
498 16 eightycc
                     busy <= 1;
499
                     state <= `state_read_prog_1;
500 10 eightycc
                  end
501
 
502 21 eightycc
                  `cmd_write_acc: begin
503
                     busy <= 1;
504
                     state <= `state_write_acc_1;
505
                  end
506
 
507 10 eightycc
                  // 0 : Ignore if not in manual
508
                  //     Clear gs_ram_addr
509
                  // 1 : Synchronize with d10
510
                  //     Turn on console_write_gs
511
                  // 2 : Put a digit:
512
                  //     dx: blank
513
                  //     d0: minus
514
                  //     d1-d10: zero
515
                  //     gs_ram_addr++
516 9 eightycc
                  `cmd_clear_gs: begin
517 11 eightycc
                     if (ctl_sw_manual) begin
518
                        busy <= 1;
519
                        do_clear_drum <= 1;
520
                     end
521 10 eightycc
                  end
522
 
523 9 eightycc
                  `cmd_load_gs: begin
524 13 eightycc
                     if (ctl_sw_manual) begin
525
                        busy <= 1;
526
                        state <= `state_load_gs_1;
527
                        digit_ready <= 1;
528
                     end
529 10 eightycc
                  end
530
 
531 9 eightycc
                  `cmd_dump_gs: begin
532 15 eightycc
                     if (ctl_sw_manual) begin
533
                        busy <= 1;
534
                        state <= `state_dump_gs_1;
535
                     end
536 10 eightycc
                  end
537
 
538 9 eightycc
                  `cmd_power_on_reset: begin
539 13 eightycc
                     busy <= 1;
540
                     do_power_on_reset <= 1;
541 10 eightycc
                  end
542
 
543 9 eightycc
                  `cmd_reset_console: begin
544 13 eightycc
                     busy <= 1;
545
                     do_reset_console <= 1;
546 10 eightycc
                  end
547 7 eightycc
 
548 11 eightycc
                  `cmd_hard_reset: begin
549
                     busy <= 1;
550
                     do_hard_reset <= 1;
551
                  end
552
 
553 7 eightycc
               endcase;
554
            end
555
 
556
            // Reset console            
557
            `state_reset_console_1: begin
558
               if (d10) state <= `state_reset_console_2;
559
            end
560
 
561
            `state_reset_console_2: begin
562 11 eightycc
               storage_entry_sw[ontime_idx] <= dx? `biq_blank
563
                                             : d0? `biq_plus : `biq_0;
564 7 eightycc
               addr_sel_sw[ontime_idx[2:3]] <= `biq_0;
565
               if (d10) state <= `state_idle;
566
            end
567
 
568
            // Program reset key press
569
            `state_pgm_reset_1: begin
570
               if (wu & d10) begin
571
                  man_pgm_reset <= 1;
572
                  state <= `state_pgm_reset_2;
573
               end
574
            end
575
 
576
            `state_pgm_reset_2: begin
577
               if (wu & d10) begin
578
                  man_pgm_reset <= 0;
579
                  state <= `state_idle;
580
               end
581
            end
582
 
583
            // Accumulator reset key press
584
            `state_acc_reset_1: begin
585
               if (wu & d10) begin
586
                  man_acc_reset <= 1;
587
                  state <= `state_acc_reset_2;
588
               end
589
            end
590
 
591
            `state_acc_reset_2: begin
592
               if (wu & d10) begin
593
                  man_acc_reset <= 0;
594
                  state <= `state_idle;
595
               end
596
            end
597
 
598
            // Error reset key press
599
            `state_err_reset_1: begin
600
               if (wu & d10) begin
601
                  err_reset <= 1;
602
                  state <= `state_err_reset_2;
603
               end
604
            end
605
 
606
            `state_err_reset_2: begin
607
               if (wu & d10) begin
608
                  err_reset <= 0;
609
                  state <= `state_idle;
610
               end
611
            end
612
 
613
            // Error sense reset key press
614
            `state_err_sense_reset_1: begin
615
               if (wu & d10) begin
616
                  err_sense_reset <= 1;
617
                  state <= `state_err_sense_reset_2;
618
               end
619
            end
620
 
621
            `state_err_sense_reset_2: begin
622
               if (wu & d10) begin
623
                  err_sense_reset <= 0;
624
                  state <= `state_idle;
625
               end
626
            end
627
 
628 11 eightycc
            // Hard reset
629
            `state_hard_reset_1: begin
630
               hard_reset <= 0;
631
               state <= `state_idle;
632
            end
633
 
634 7 eightycc
            // Set storage entry switches
635
            `state_storage_entry_sw_1: begin
636
               if (d0) begin
637
                  state <= `state_storage_entry_sw_2;
638
                  digit_ready <= 1;
639
                  storage_entry_sw[ontime_idx] <= cmd_digit_in;
640
               end
641
            end
642
 
643
            `state_storage_entry_sw_2: begin
644
               storage_entry_sw[ontime_idx] <= cmd_digit_in;
645
               if (d10) begin
646
                  state <= `state_idle;
647
                  digit_ready <= 0;
648
               end
649
            end
650
 
651
            // Set address selection switches
652
            `state_addr_sel_sw_1: begin
653
               if (dx) begin
654
                  state <= `state_addr_sel_sw_2;
655
                  digit_ready <= 1;
656
                  addr_sel_sw[ontime_idx[2:3]] <= cmd_digit_in;
657
               end
658
            end
659
 
660
            `state_addr_sel_sw_2: begin
661
               addr_sel_sw[ontime_idx[2:3]] <= cmd_digit_in;
662
               if (d2) begin
663
                  state <= `state_idle;
664
                  digit_ready <= 0;
665
               end
666
            end
667
 
668
            // Transfer key press
669
            `state_xfer_key_1: begin
670
               if (d10) begin
671
                  console_to_addr <= 1;
672
                  state <= `state_xfer_key_2;
673
               end
674
            end
675
 
676
            `state_xfer_key_2: begin
677
               if (d10) begin
678
                  console_to_addr <= 0;
679
                  state <= `state_idle;
680
               end
681
            end
682
 
683
            // Start key press
684
            `state_pgm_start_key_1: begin
685
               if (wu & d10) begin
686
                  pgm_start <= 1;
687
                  state <= `state_pgm_start_key_2;
688
               end
689
            end
690
 
691
            `state_pgm_start_key_2: begin
692
               if (wu & d10) begin
693
                  pgm_start <= 0;
694
                  state <= `state_idle;
695
               end
696
            end
697
 
698
            // Stop key press
699
            `state_pgm_stop_key_1: begin
700
               if (hp) state <= `state_pgm_stop_key_2;
701
            end
702
 
703
            `state_pgm_stop_key_2: begin
704
               if (hp) begin
705
                  pgm_stop <= 0;
706
                  state <= `state_idle;
707
               end
708
            end
709
 
710
            // Read word from general storage
711
            //    --> 4 digits address, little-endian
712
            //    <-- 1 digit sign, 10 digits, little-endian
713
            // 0 : Ignore if CPU not stopped
714 12 eightycc
            // 1 : Accept first address digit
715
            // 2 : Accept remaining address digits
716 7 eightycc
            // 2 : Calculate word origin in gs RAM
717
            //     Validate address
718
            //     console_read_gs <= 1;
719
            // 3 : Send gs-early digit to out
720
            //     digit_ready <= 1;
721
            // 4 : digit_ready <= 0;
722
            `state_read_gs_1: begin
723
               if (dx) begin
724
                  state <= `state_read_gs_2;
725
                  digit_ready <= 1;
726
                  gs_addr_u <= cmd_digit_in;
727
               end
728
            end
729
 
730
            `state_read_gs_2: begin
731
               if (d0) gs_addr_t <= cmd_digit_in;
732
               else if (d1) gs_addr_h <= cmd_digit_in;
733
               else if (d2) begin
734
                  gs_addr_th <= cmd_digit_in;
735
                  state <= `state_read_gs_3;
736
                  digit_ready <= 0;
737
               end
738
            end
739
 
740
            `state_read_gs_3: begin
741 12 eightycc
               if (d10) begin
742
                  gs_ram_addr <= gs_word_addr;
743
                  read_gs <= 1;
744
                  state <= `state_read_gs_4;
745
               end
746 7 eightycc
            end
747
 
748 10 eightycc
            `state_read_gs_4: begin
749
               state <= `state_read_gs_5;
750 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
751 10 eightycc
            end
752 12 eightycc
 
753
            `state_read_gs_5: begin
754
               digit_ready <= 1;
755
               cmd_digit_out <= gs_in;
756 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
757 12 eightycc
               if (dx) begin
758
                  state <= `state_read_gs_6;
759
                  read_gs <= 0;
760
               end
761
            end
762
 
763
            `state_read_gs_6: begin
764
               digit_ready <= 0;
765
               state <= `state_idle;
766
            end
767 11 eightycc
 
768 13 eightycc
            // Write word to general storage:
769
            //    --> 4 digits address, little-endian
770
            //    <-- dx digit, sign digit, d1-d10
771
            // 0: Ignore if not in manual
772
            // 1: Readin low-order addr digit
773
            // 2: Readin remaining addr digits
774
            // 3: Synchronize with d10
775
            //    digit_ready <- 1
776
            // 4: Readin and write digit
777
            // 5: Write digit
778
            //    Readin next digit
779
            // 6: Cleanup
780
 
781
            `state_write_gs_1: begin
782
               if (dx) begin
783
                  state <= `state_write_gs_2;
784
                  digit_ready <= 1;
785
                  gs_addr_u <= cmd_digit_in;
786
               end
787
            end
788
 
789
            `state_write_gs_2: begin
790
               if (d0) gs_addr_t <= cmd_digit_in;
791
               else if (d1) gs_addr_h <= cmd_digit_in;
792
               else if (d2) begin
793
                  gs_addr_th <= cmd_digit_in;
794
                  state <= `state_write_gs_3;
795
                  digit_ready <= 0;
796
               end
797
            end
798
 
799
            `state_write_gs_3: begin
800
               if (d10) begin
801
                  gs_ram_addr <= gs_word_addr;
802
                  digit_ready <= 1;
803
                  state <= `state_write_gs_4;
804
               end
805
            end
806
 
807
            `state_write_gs_4: begin
808
               write_gs <= 1;
809
               console_out <= cmd_digit_in;
810 16 eightycc
               if (write_gs)
811
                  gs_ram_addr <= (gs_ram_addr + 1) % 32768;
812 13 eightycc
               if (d10) begin
813
                  digit_ready <= 0;
814
                  state <= `state_write_gs_5;
815
               end
816
            end
817
 
818
            `state_write_gs_5: begin
819
               write_gs <= 0;
820
               state <= `state_idle;
821
            end
822
 
823 16 eightycc
            `state_read_acc_1: begin
824
               if (wl & d10) begin
825
                  state <= `state_read_acc_2;
826
               end
827
            end
828
 
829
            `state_read_acc_2: begin
830
               digit_ready <= 1;
831
               cmd_digit_out <= acc_ontime;
832
               if (wu & d10) begin
833
                  state <= `state_read_acc_3;
834
               end
835
            end
836
 
837
            `state_read_acc_3: begin
838
               digit_ready <= 0;
839
               state <= `state_idle;
840
            end
841
 
842
            `state_read_dist_1: begin
843
               if (d10) begin
844
                  state <= `state_read_dist_2;
845
               end
846
            end
847
 
848
            `state_read_dist_2: begin
849
               digit_ready <= 1;
850
               cmd_digit_out <= dist_ontime;
851
               if (d10) begin
852
                  state <= `state_read_dist_3;
853
               end
854
            end
855
 
856
            `state_read_dist_3: begin
857
               digit_ready <= 0;
858
               state <= `state_idle;
859
            end
860
 
861
            `state_read_prog_1: begin
862
               if (d10) begin
863
                  state <= `state_read_prog_2;
864
               end
865
            end
866
 
867
            `state_read_prog_2: begin
868
               digit_ready <= 1;
869
               cmd_digit_out <= prog_ontime;
870
               if (d10) begin
871
                  state <= `state_read_prog_3;
872
               end
873
            end
874
 
875
            `state_read_prog_3: begin
876
               digit_ready <= 0;
877
               state <= `state_idle;
878
            end
879
 
880 21 eightycc
            `state_write_acc_1: begin
881 22 eightycc
               if (wl & dx) begin
882 21 eightycc
                  console_out <= cmd_digit_in;
883
                  acc_ri_console <= 1;
884
                  digit_ready <= 1;
885
                  state <= `state_write_acc_2;
886
               end
887
            end
888
 
889
            `state_write_acc_2: begin
890
               console_out <= cmd_digit_in;
891
               if (wu & d10) begin
892
                  digit_ready <= 0;
893
                  state <= `state_write_acc_3;
894
               end
895
            end
896
 
897
            `state_write_acc_3: begin
898
               acc_ri_console <= 0;
899
               state <= `state_idle;
900
            end
901
 
902 11 eightycc
            // 0 : Ignore if not in manual
903 15 eightycc
            // 1 : Synchronize with dx
904
            //     Put first dx digit
905 11 eightycc
            // 2 : Put a digit:
906
            //     dx: blank
907
            //     d0: minus
908
            //     d1-d10: zero
909
            `state_clear_drum_1: begin
910 15 eightycc
               if (dx) begin
911 13 eightycc
                  console_out <= `biq_blank;
912
                  gs_ram_addr <= 15'd0;
913
                  write_gs <= 1;
914 11 eightycc
                  state <= `state_clear_drum_2;
915
               end
916
            end
917 10 eightycc
 
918 11 eightycc
            `state_clear_drum_2: begin
919
               console_out <= dx? `biq_blank
920
                            : d0? `biq_minus
921
                            : `biq_0;
922 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
923 11 eightycc
               if (gs_ram_addr == 15'd23999) begin
924
                  write_gs <= 0;
925
                  state <= `state_idle;
926
               end
927
            end
928
 
929 13 eightycc
            `state_load_gs_1: begin
930
               gs_ram_addr <= 15'd0;
931
               write_gs <= 1;
932
               console_out <= cmd_digit_in;
933
               state <= `state_load_gs_2;
934
            end
935
 
936
            `state_load_gs_2: begin
937 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
938 13 eightycc
               console_out <= cmd_digit_in;
939 15 eightycc
               if (gs_ram_addr == 15'd23999) begin
940 13 eightycc
                  write_gs <= 0;
941
                  digit_ready <= 0;
942
                  state <= `state_idle;
943
               end
944
            end
945
 
946 15 eightycc
            `state_dump_gs_1: begin
947
               gs_ram_addr <= 15'd0;
948
               read_gs <= 1;
949
               state <= `state_dump_gs_2;
950
            end
951
 
952
            `state_dump_gs_2: begin
953
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
954
               state <= `state_dump_gs_3;
955
            end
956
 
957
            `state_dump_gs_3: begin
958
               digit_ready <= 1;
959
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
960
               cmd_digit_out <= gs_in;
961
               if (gs_ram_addr == 15'd23999) begin
962
                  state <= `state_dump_gs_4;
963
               end
964
            end
965
 
966
            `state_dump_gs_4: begin
967
               digit_ready <= 0;
968
               read_gs <= 0;
969
               state <= `state_idle;
970
            end
971
 
972 7 eightycc
         endcase;
973 20 eightycc
      end;
974 7 eightycc
 
975 20 eightycc
   always @(posedge ap)
976 11 eightycc
      if (hard_reset) begin
977 7 eightycc
         data_out <= `biq_blank;
978
         addr_out <= `biq_blank;
979
      end else begin
980
         data_out <= d10? `biq_blank : storage_entry_sw[early_idx];
981
         addr_out <= (d3 | d4 | d5 | d6)? addr_sel_sw[early_idx[2:3]] : `biq_blank;
982 20 eightycc
      end;
983 7 eightycc
 
984 20 eightycc
   always @(posedge ap)
985 11 eightycc
      if (hard_reset) begin
986 7 eightycc
         punch_card       <= 0;
987
         read_card        <= 0;
988
         card_digit_ready <= 0;
989 20 eightycc
      end;
990 7 eightycc
 
991
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.