RAM_SIZE = 65536 # in bytes max_pixels = 4*RAM_SIZE print("Expecting use of Nuclaer Tech VGA uPD7220 Graphics Card.") print(round(RAM_SIZE/1024,2),"K VRAM, up to ",max_pixels," pixels.") while True: min_y_size = 410 vs_lines = 4 vbp_lines = 18 vfp_lines = 10 max_porch_size = 63 pixel_time = 1/float(input("Pixel Clock (Mhz) > ")) signal_time = 2/float(input("Signal Clock (Mhz) > ")) frame_time = 16683 # 60 Hz max_line_time = frame_time/min_y_size xres = int(input("Horizontal Resolution > ")) yres = int(input("Vertical Resolution > ")) err = False if xres/8!=xres//8: print("Error: Horizontal resolution must be a multiple of 8.") nval = xres//8 print("Nearest values are ",8*nval," and ",8*(1+nval)) err = True if xres*yres>max_pixels: print("Error: Resolution too high; not enough VRAM to store.") print("Try decreasing resolution. Current usage is ",xres*yres," of ",max_pixels," pixels.") err = True extra_vblank = max(0,min_y_size-yres-vs_lines-vbp_lines-vfp_lines) if(extra_vblank>max_porch_size*2): print("Error: vertical resolution MUST be ",min_y_size-vs_lines-2*max_porch_size," pixels or more.") print("Increase vertical resolution.") err = True if(extra_vblank==0): # constrained by vertical line count, keep default vertical values line_time = frame_time/(vs_lines+vbp_lines+vfp_lines+yres) hpixel_time = xres*pixel_time if(hpixel_time+5.2>line_time): print("Error: not enough time for each line to meet 60Hz.") print("Try decreasing resolution or increasng pixel clock frequency.") err = True hsync = round(3.268/signal_time) hbp = round(1.6346/signal_time) extra_line_time = line_time - hpixel_time - signal_time*(hsync+hbp) hfp = round((.545+extra_line_time)/signal_time) else: # need to increase vfp to make valid signal vfp_lines+=extra_vblank line_time = frame_time/(vs_lines+vbp_lines+vfp_lines+yres) hpixel_time = xres*pixel_time if(hpixel_time+5.2>line_time): print("Error: not enough time for each line to meet 60Hz.") print("Try decreasing resolution or increasng pixel clock frequency.") err = True hsync = round(3.268/signal_time) hbp = round(1.6346/signal_time) extra_line_time = line_time - hpixel_time - signal_time*(hsync+hbp) hfp = round((.545+extra_line_time)/signal_time) if vfp_lines>max_porch_size: vbp_lines+=vfp_lines-max_porch_size vfp_lines = max_porch_size if vbp_lines>max_porch_size: vbp_lines = max_porch_size # now recalculate hfp line_time = frame_time/(vs_lines+vbp_lines+vfp_lines+yres) extra_line_time = line_time - hpixel_time - signal_time*(hsync+hbp) hfp = round((.545+extra_line_time)/signal_time) if hfp>max_porch_size: hbp+=hfp-max_porch_size hfp = max_porch_size if hbp<5: hfp-=5-hbp hbp = 5 if hfp<6 and not err: print("Error: could not make horizontal back porch and horizontal front porch big enough!") print("Try decrasing the horizontal resolution or increasing either clock speed.") err = True if hbp>max_porch_size: print("Error: unable to make video signal meet hardware constraints.") print("A higher resolution or lower signal clock speed may be required.") err = True if(not err): print("Horzontal Front Porch: ",hfp) print("Horzontal Sync: ",hsync) print("Horzontal Back Porch: ",hbp) print() print("Vertical Front Porch: ",vfp_lines) print("Vertical Sync: ",vs_lines) print("Vertical Back Porch: ",vbp_lines) line_time = (hfp+hsync+hbp)*signal_time + xres*pixel_time vert_time = line_time*(vs_lines+vfp_lines+vbp_lines+yres) print() print("Expected exact frequency: ",round(1000000/vert_time,2),"Hz") print("Image pixel count: ",xres*yres," of maximum ",max_pixels) print("Words per line: ",xres//4) """ # legacy: if(yres*(xres*pixel_time + .545+3.268+1.6346)+signal_time*vs_lines>frame_time): print("Error: not possible.") else: print("Generating timings for "+str(xres)+'x'+str(yres)+' @ 60 Hz') hextra = (25.422-xres*pixel_time) hfp = round((.636+hextra)/signal_time) print("Horzontal Front Porch: ",hfp) print("Horzontal Sync: ",hsync) print("Horzontal Back Porch: ",hbp) print("Generating timings for "+str(xres)+'x'+str(yres)+' @ 70 Hz') hextra = (21.79-xres*pixel_time) hfp = round((.545+hextra)/signal_time) hsync = round(3.268/signal_time) hbp = round(1.6346/signal_time) print("Horzontal Front Porch: ",hfp) print("Horzontal Sync: ",hsync) print("Horzontal Back Porch: ",hbp) """