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

Subversion Repositories i650

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

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

powered by: WebSVN 2.1.0

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