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

Subversion Repositories i650

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

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

powered by: WebSVN 2.1.0

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