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

Subversion Repositories i650

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

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

powered by: WebSVN 2.1.0

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