Subversion Repositories pentevo

Rev

Rev 360 | Rev 513 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. `include "../include/tune.v"
  2.  
  3. // Pentevo project (c) NedoPC 2011
  4. //
  5. // address generation module for video data fetching
  6.  
  7. module video_addrgen(
  8.  
  9.         input  wire        clk, // 28 MHz clock
  10.  
  11.  
  12.         output reg  [20:0] video_addr, // DRAM arbiter signals
  13.         input  wire        video_next, //
  14.  
  15.  
  16.         input  wire        line_start, // some video sync signals
  17.         input  wire        int_start,  //
  18.         input  wire        vpix,       //
  19.  
  20.         input  wire        scr_page, // which screen to use
  21.  
  22.  
  23.         input  wire        mode_atm_n_pent, // decoded modes
  24.         input  wire        mode_zx,         //
  25.         input  wire        mode_p_16c,      //
  26.         input  wire        mode_p_hmclr,    //
  27.                                             //
  28.         input  wire        mode_a_hmclr,    //
  29.         input  wire        mode_a_16c,      //
  30.         input  wire        mode_a_text,     //
  31.  
  32.         output wire [ 2:0] typos // Y position in text mode symbols
  33. );
  34.  
  35.         wire mode_ag;
  36.  
  37.         assign mode_ag = mode_a_16c | mode_a_hmclr;
  38.  
  39.  
  40.  
  41.         wire line_init, frame_init;
  42.  
  43.         wire gnext,tnext,ldaddr;
  44.  
  45.         reg line_start_r;
  46.         reg frame_init_r;
  47.         reg line_init_r;
  48.  
  49.         always @(posedge clk)
  50.                 line_start_r <= line_start;
  51.  
  52.         assign line_init  = line_start_r & vpix;
  53.         assign frame_init = int_start;
  54.  
  55.         reg [13:0] gctr;
  56.  
  57.         reg [7:0] tyctr; // text Y counter
  58.         reg [6:0] txctr; // text X counter
  59.  
  60.  
  61.         always @(posedge clk)
  62.                 frame_init_r <= frame_init;
  63.  
  64.         always @(posedge clk)
  65.                 line_init_r <= line_init;
  66.  
  67.  
  68.         assign gnext = video_next | frame_init_r;
  69.         assign tnext = video_next | line_init_r;
  70.         assign ldaddr = mode_a_text ? tnext : gnext;
  71.  
  72.         // gfx counter
  73.         //
  74.         initial gctr <= 0;
  75.         //
  76.         always @(posedge clk)
  77.         if( frame_init )
  78.                 gctr <= 0;
  79.         else if( gnext )
  80.                 gctr <= gctr + 1;
  81.  
  82.  
  83.         // text counters
  84.         always @(posedge clk)
  85.         if( frame_init )
  86.                 tyctr <= 8'b0011_0111;
  87.         else if( line_init )
  88.                 tyctr <= tyctr + 1;
  89.  
  90.         always @(posedge clk)
  91.         if( line_init )
  92.                 txctr <= 7'b000_0000;
  93.         else if( tnext )
  94.                 txctr <= txctr + 1;
  95.  
  96.  
  97.         assign typos = tyctr[2:0];
  98.  
  99.  
  100. // zx mode:
  101. // [0] - attr or pix
  102. // [4:1] - horiz pos 0..15 (words)
  103. // [12:5] - vert pos
  104.  
  105.         wire [20:0] addr_zx;   // standard zx mode
  106.         wire [20:0] addr_phm;  // pentagon hardware multicolor
  107.         wire [20:0] addr_p16c; // pentagon 16c
  108.  
  109.         wire [20:0] addr_ag; // atm gfx: 16c (x320) or hard multicolor (x640) - same sequence!
  110.  
  111.         wire [20:0] addr_at; // atm text
  112.  
  113.         wire [11:0] addr_zx_pix;
  114.         wire [11:0] addr_zx_attr;
  115.         wire [11:0] addr_zx_p16c;
  116.  
  117.  
  118.         assign addr_zx_pix  = { gctr[12:11], gctr[7:5], gctr[10:8], gctr[4:1] };
  119.  
  120.         assign addr_zx_attr = { 3'b110, gctr[12:8], gctr[4:1] };
  121.  
  122.         assign addr_zx_p16c = { gctr[13:12], gctr[8:6], gctr[11:9], gctr[5:2] };
  123.  
  124.  
  125.         assign addr_zx =   { 6'b000001, scr_page, 2'b10, ( gctr[0] ? addr_zx_attr : addr_zx_pix ) };
  126.  
  127.         assign addr_phm =  { 6'b000001, scr_page, 1'b1, gctr[0], addr_zx_pix };
  128.  
  129.         assign addr_p16c = { 6'b000001, scr_page, ~gctr[0], gctr[1], addr_zx_p16c };
  130.  
  131.  
  132.         assign addr_ag = { 5'b00000, ~gctr[0], scr_page, 1'b1, gctr[1], gctr[13:2] };
  133.  
  134. //      assign addr_at = { 5'b00000, ~txctr[0], scr_page, 1'b1, (^txctr[1:0]), 2'b00, tyctr[7:3], txctr[6:2] };
  135.         assign addr_at = { 5'b00000, ~txctr[0], scr_page, 1'b1, txctr[1], 2'b00, tyctr[7:3], txctr[6:2] };
  136.  
  137.  
  138.         initial video_addr <= 0;
  139.         //
  140.         always @(posedge clk) if( ldaddr )
  141.         begin
  142.                 video_addr <=
  143.                         ( {21{mode_zx     }} & addr_zx  )  |
  144.                         ( {21{mode_p_16c  }} & addr_p16c)  |
  145.                         ( {21{mode_p_hmclr}} & addr_phm )  |
  146.                         ( {21{mode_ag     }} & addr_ag  )  |
  147.                         ( {21{mode_a_text }} & addr_at  )  ;
  148.  
  149.         end
  150.  
  151.  
  152. endmodule
  153.  
  154.