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

Subversion Repositories i650

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

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

powered by: WebSVN 2.1.0

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