###############################################################################################
# VGAdriver2 関数
# 対応LCD　KCG075VG2BP（7.5型 VGA透過カラーSTN液晶パネル：京セラ）
#　対応CPU　RP2350(Rasberry Pi Pico2/W)
#
#　関数
# 1)横カラーバー描画				VGAdriver2.color_h_bar()
# 2)縦カラーバー描画				VGAdriver2.color_v_bar()
# 3)全体を指定色で描画			VGAdriver2.fill_screen(color)　　						
# 4)ドットを描画					VGAdriver2.draw_pix(x:int,y:int,col:int)				
# 5)水平実線を描画				VGAdriver2.draw_Hline(x1:int,x2:int,y:int,col:int)
# 6)水平破線を描画				VGAdriver2.draw_dashed_Hline(x1:int,x2:int,y:int,col:int)
# 7)垂直実線を描画				VGAdriver2.draw_Vline(x:int,y1:int,y2:int,col:int)
# 8)垂直破線を描画				VGAdriver2.draw_dashed_Vline(x:int,y1:int,y2:int,col:int)
# 9)斜実線を描画					VGAdriver2.draw_line(x1:int,y1:int,x2:int,y2:int,col:int)
# 10)斜破線を描画					VGAdriver2.draw_dashed_line(x1:int,y1:int,x2:int,y2:int,col:int)
# 11)四角（線）を描画				VGAdriver2.draw_rect(x1:int,y1:int,x2:int,y2:int,col:int)
# 12)四角（面）を描画				VGAdriver2.fill_rect(x1:int,y1:int,x2:int,y2:int,col:int)
# 13)円（線）を描画					VGAdriver2.draw_circle(x:int,y:int,r:int,color:int)
# 14)円（面）を描画					VGAdriver2.fill_disk(x:int,y:int,r:int,color:int)
# 15)5dot幅フォントを描画			VGAdriver2.draw_font12(x:int,y:int,col:int,moji)
# 16)12dotフォントを描画			VGAdriver2.draw_font12(x:int,y:int,col:int,moji)
# 17)18dotフォントを描画			VGAdriver2.draw_font18(x:int,y:int,col:int,moji)
# 18)24dotフォントを描画			VGAdriver2.draw_font24(x:int,y:int,col:int,moji)
# 19)ピンボール					VGAdriver2.pin_ball():
#　20)LCDのコントラスト(Vcont)設定	VGAdriver2.Vcont(contrast:int)  0:min(1.65V),50:typ(1.95V),100:max(2.25V)
#
#  パラメータ
#	color(色)			：BLACK,BLUE,GREEN,CYAN,RED,MAGENTA,YELLOW,WHITEのどれかを入力する
#	x,x1,x2(横軸ｘ座標)	:0 =< x,x1,x2 < 640 を入力する LCDのｘ座標は左が０で　一番右が６３９です
#	y,y1,y2(縦軸ｙ座標)	:0 =< y,y1,y2 < 480 を入力する　LCDのｙ座標は上が０で　一番下が４７９です
#	r(半径)				:0 =< r < 640 を入力する
#	moji(文字列)			:文字列を入力する
#						問題解決	フォントデータ：タプルはフラッシュに保存すること
# 						凍結モジュール、凍結バイトコード　を利用する
#######################################################################################################

#========== Raspberry Pi PICO LCD接続 ==================
# 
# Raspberry Pi PICO LCD接続ハードウエア情報
#	GP2  (4ピン):VSYNC
#	GP3  (5ピン):Vcont(1.95V)
#	GP4  (6ピン):HSYNC
#	GP5  (7ピン):CLK
#	GP6  (9ピン):D0
#	GP7 (10ピン):D1
#	GP8 (11ピン):D2
#	GP9 (12ピン):D3
#	GP10(14ピン):D4
#	GP11(15ピン):D5
#	GP12(16ピン):D6
#	GP13(17ピン):D7

#
#　LCD駆動情報
#	VSYNC:75Hz
#	HSYNC:75Hz*482ライン＝36.15kHz(27.66uSec)
#	CLK:36.15KHz*(240+36)=10MHz(100nSec)

############# ここからプログラム #########################
#------------ 液晶駆動信号生成プログラム ------------------------
from machine import Pin,PWM
from rp2 import PIO, StateMachine, asm_pio
from micropython import const
from array import array
from uctypes import addressof
from gc import mem_free,collect

# VGAパラメータ for 640x480 using 3ビット／ピクセル
H_res=const(640)             # Horizontal resolution in pixels
V_res=const(480)             # Vertical resolution in pixels

# --- ステートマシン０（sm0）は　HSYNC信号生成に使用 ---
@asm_pio(set_init=PIO.OUT_LOW, autopull=True, pull_thresh=32)
def paral_Hsync():
    pull(block)                  	# Pull from FIFO to OSR (only once)
    wrap_target()
    mov(x, osr)               		# Copy value from OSR to x scratch register
    label("activeporch")
    jmp(x_dec,"activeporch")  		# Remain high in active mode and front porch
    set(pins, 1) [1]    			# High for hsync pulse (32 cycles)
    set(pins, 0)     				# low for back porch (32 cycles)
    irq(0)               			# Set IRQ to signal end of line (47 cycles)
    wrap()     
paral_write_Hsync = StateMachine(0, paral_Hsync,freq=10_000_000, set_base=Pin(4))

# --- ステートマシン１（sm１）は　VSYNC信号生成に使用 ---
@asm_pio(sideset_init=(PIO.OUT_LOW,) * 1, autopull=True, pull_thresh=32)
def paral_Vsync():
    pull(block)             		# Pull from FIFO to OSR (only once)
    wrap_target()
    # 　１ライン目		ダミー？　
    wait(1,irq,0)					# Wait for hsync to go high and Set pin low
    irq(1)                       	# Signal that we're in active mode
    # 2ライン目	VSYNCパルス生成
    wait(1,irq,0)	.side(1)				# Wait for hsync to go high - SIDESET REPLACEMENT
    irq(1)                          # Signal that we're in active mode
    # 3ライン目
    wait(1,irq,0)	.side(0)		# Wait for hsync to go high - SIDESET REPLACEMENT
    irq(1)                          # Signal that we're in active mode
    # 4ライン～４８２ライン
    mov(x, osr)                     # Copy value from OSR to x scratch register     
    label("active")
    wait(1,irq,0)
    irq(1)                          # Signal that we're in active mode
    jmp(x_dec,"active")             # Remain in active mode, decrementing counter
    wrap() 
paral_write_Vsync = StateMachine(1, paral_Vsync,freq=125_000_000, sideset_base=Pin(2))

# --- ステートマシン２（sm２）は　RGB信号データ出力,クロック生成に使用 ---
@asm_pio(out_init=(PIO.OUT_HIGH,) * 8, out_shiftdir=PIO.SHIFT_LEFT, sideset_init=(PIO.OUT_LOW,) * 1, autopull=True,pull_thresh=32)
def paral_RGB():					# irq1が１となったら　２４０バイト出力する。                 
    wait(1,irq,1)              		# Wait for vsync active mode
    set(y,7)
    label("colorout_y")
    set(x,29)
    label("colorout_x")
    out(pins,8)	.side(1)	[1]		# RGBデーター出力　クロック１
    nop()	[3]
    nop()		.side(0)			# RGBデーター出力　クロック0
    nop()	[3]
    jmp(x_dec,"colorout_x")       	# 29+1=30　RGBデーター出力
    jmp(y_dec,"colorout_y")         #　（７+1=８）＊３０＝２４０　RGBデーター出力
    irq(0x40,1)						#irq(1)をクリア
paral_write_RGB = StateMachine(2, paral_RGB,freq=110_000_000, out_base=Pin(6),sideset_base=Pin(5))

# --- DMAの設定 ---
@micropython.viper
def configure_DMAs(nword:int, H_buffer_line_add:ptr32):		#RP2350
    # --- DMA チャネル０，１共通設定項目 ---
    IRQ_QUIET = 0  									# Do not generate an interrupt
    RING_SEL = 0   									# No wrapping
    RING_SIZE = 0  									# No wrapping
    HIGH_PRIORITY = 1
    INCR_WRITE = 0  								# Non increment while writing
    # --- DMA channel 1 設定 ---
    TREQ_SEL = 2    								#  num of rhe RGB statemachine -> at the pace of the PIO
    INCR_READ = 1   								# 1 increment while reading
    DATA_SIZE = 2   								# 32 bit transfer
    CHAIN_TO = 0    								# DMAチャネル０へチェインする
    EN = 1          								# Channel is enabled by the configure DMA chan0
    DMA_control_word = ((IRQ_QUIET << 23) | (TREQ_SEL << 17) | (CHAIN_TO  << 13) | (RING_SEL << 12) |
                        (RING_SIZE << 8) | (INCR_WRITE << 6) | (INCR_READ << 4) | (DATA_SIZE << 2) |
                        (HIGH_PRIORITY << 1) | (EN << 0))
    ptr32(0x50000040)[0] = 0                        # DMA Channel 1 Read Address pointer <- not important because reset by DMA0 "configure" channel
    ptr32(0x50000044)[0] = uint(0x50200018)         # DMA Channel 1 Write Address pointer -> PIO TX FIFO 2 (sm2) adress
    ptr32(0x50000048)[0] = nword       				# DMA Channel 1 Transfer Count <- length of the Data array buffer
    ptr32(0x50000060)[0] = DMA_control_word         # DMA Channel 1 Control and Status (using alias to not start immediatly - will be started by DMA chanel 0)

    # --- DMA channel 0 設定 ---
    TREQ_SEL = 0x3f 								# Max speed, however synchronization is achieved via the PIO irq 1
    INCR_READ = 0   								# No increment while reading
    CHAIN_TO = 1    								# DMAチャネル１へチェインする
    EN = 1          								# Start channel upon setting the trigger register
    DMA_control_word = ((IRQ_QUIET << 23) | (TREQ_SEL << 17) | (CHAIN_TO  << 13) | (RING_SEL << 12) |
                        (RING_SIZE << 8) | (INCR_WRITE << 6) | (INCR_READ << 4) | (DATA_SIZE << 2) |
                        (HIGH_PRIORITY << 1) | (EN << 0))
    ptr32(0x50000000)[0] = uint(H_buffer_line_add)	# DMA Channel 0 Read Address pointer <- data array to reconfigure DMA1
    ptr32(0x50000004)[0] = uint(0x5000007c)         # DMA Channel 0 Write Address pointer -> DMA1 read_adress alias register 3 (CH1_AL3_READ_ADDR_TRIG ) - trigger the DMA1 start
    ptr32(0x50000008)[0] = 1               			# DMA Channel 0 Transfer Count <- Just one data (long) array to transfer continuously
    ptr32(0x50000010)[0] = DMA_control_word         # DMA Channel 0 Control and Status (using alias to not start immediatly - will be started by DMA trigger register)

# --- ステートマシン０，１，２の動作を開始する ---
@micropython.viper
def startsync():
    paral_write_Hsync.put(270)       				# H Visible areas 27.66uSecに合わせる
    paral_write_Vsync.put(478)  					# V Visible area 479+1+2=482
    ptr32(0x50000450)[0] |= 0b00001  				#　RP2350 triggers DMA chan0
    ptr32(0x50200000)[0] |= 0b111    				# Enable PIO0 SM 0, 1, and 2

# --- ステートマシン０，１，２の動作を停止する ---
@micropython.viper
def stopsync():
    ptr32(0x50000444)[0] |= 0b000011         # Aborts DMA chan0 and 1
    ptr32(0x50200000)[0] &= 0b111111111000   # Disable PIO0 SM 0, 1 and2
    
#　--- LCDのコントラスト：Vcont電圧（１．９５Vtyp）をPWMで生成する ---
@micropython.viper
def Vcont(contrast:int):					#0%min(1.65V)-50%typ(1.95V)-100%max(2.25V)
    pwm0 = PWM(Pin(3), freq=200_000)
    x= 120*contrast + 32768					#50%typ(1.95V)の時　x=120*50+32768=38768
    pwm0.duty_u16(x)      					# チャンネルAのデューティ比を設定(0-65535 の範囲)

# --- ビデオバッファ（Data array buffer）の設定 ---
collect()
print("フリーメモリ=",mem_free())
H_buffer_line = array('L')								# 数値データー配列（32ビット）
for k in range(28920):									# Creating an array with all the 32b words set to zero(60word*482=28920)
    H_buffer_line.append(0)
H_buffer_line_add=array('L',[addressof(H_buffer_line)])	# We need an array containing the adress of the buffer for the DMA chan0 to read the values
collect()

 # --- DMAと各ステートマシンの開始 ---
nword = 28920											#60ワード*482ライン=28920ワード
Vcont(50)												#Vcont電圧　１．９５Vtyp (50%)
configure_DMAs(len(H_buffer_line),H_buffer_line_add)	#DMA設定
startsync()												#video描画　スタート


#------------------------　main.py で使用可能な関数--------------------------------------------------------- 
# --- 1)横カラーバー描画		VGAdriver2.color_h_bar() ---									
@micropython.viper
def color_h_bar():
    Data=ptr32(H_buffer_line)
    for i in range(0,3600,3):						#RED(4)
        Data[i]   = uint(0x92492492)
        Data[i+1] = uint(0x49249249)
        Data[i+2] = uint(0x24924924)
    for i in range(3600,7200,3):					#GREEN(2)
        Data[i]   = uint(0x49249249)
        Data[i+1] = uint(0x24924924)
        Data[i+2] = uint(0x92492492)
    for i in range(7200,10800,3):					#BLUE(1)
        Data[i]   = uint(0x24924924)
        Data[i+1] = uint(0x92492492)
        Data[i+2] = uint(0x49249249)
    for i in range(10800,14400):    				#BLACK(0)
        Data[i]   = uint(0x0)
    for i in range(14400,18000,3):					#YELLOW(6)
        Data[i]   = uint(0xdb6db6db)
        Data[i+1] = uint(0x6db6db6d)
        Data[i+2] = uint(0xb6db6db6)
#     for i in range(18000,21600,3):					#MAGENTA(5)
#         Data[i]   = uint(0xb6db6db6)
#         Data[i+1] = uint(0xdb6db6db)
#         Data[i+2] = uint(0x6db6db6d)
#     for i in range(21600,25200,3):					#CYAN(3)
#         Data[i]   = uint(0x6db6db6d)
#         Data[i+1] = uint(0xb6db6db6)
#         Data[i+2] = uint(0xdb6db6db)
    for i in range(25200,28800):					#WHITE(7)
        Data[i]   = uint(0xffffffff)


# --- 2)縦カラーバー描画		VGAdriver2.color_v_bar() ---
@micropython.viper
def color_v_bar():
    Data=ptr32(H_buffer_line)
    for j in range(0,28920,60):
        for i in range(0,9,3):					#RED(4)
            Data[i+j]   = uint(0x92492492)
            Data[i+j+1] = uint(0x49249249)
            Data[i+j+2] = uint(0x24924924)
        for i in range(9,18,3):					#GREEN(2)
            Data[i+j]   = uint(0x49249249)
            Data[i+j+1] = uint(0x24924924)
            Data[i+j+2] = uint(0x92492492)
        for i in range(18,27,3):				#BLUE(1)
            Data[i+j]   = uint(0x24924924)
            Data[i+j+1] = uint(0x92492492)
            Data[i+j+2] = uint(0x49249249)
        for i in range(27,36):    				#BLACK(0)
            Data[i+j]   = uint(0x0)
        for i in range(36,42,3):				#YELLOW(6)
            Data[i+j]   = uint(0xdb6db6db)
            Data[i+j+1] = uint(0x6db6db6d)
            Data[i+j+2] = uint(0xb6db6db6)
        for i in range(42,48,3):				#MAGENTA(5)
            Data[i+j]   = uint(0xb6db6db6)
            Data[i+j+1] = uint(0xdb6db6db)
            Data[i+j+2] = uint(0x6db6db6d)
        for i in range(48,54,3):				#CYAN(3)
            Data[i+j]   = uint(0x6db6db6d)
            Data[i+j+1] = uint(0xb6db6db6)
            Data[i+j+2] = uint(0xdb6db6db)    
        for i in range(54,60):					#WHITE(7)
            Data[i+j]   = uint(0xffffffff)
            
# --- 3)全体を指定色で描画	VGAdriver2.fill_screen(color)　---　
@micropython.viper
def fill_screen(col:int):
    Data=ptr32(H_buffer_line)
    
    if(col == 0):						#BLACK(0)
        color_data0 = uint(0x0)
        color_data1 = uint(0x0)
        color_data2 = uint(0x0)
    elif(col == 1):						#BLUE(1)
        color_data0 = uint(0x24924924)
        color_data1 = uint(0x92492492)
        color_data2 = uint(0x49249249)
    elif(col == 2):						#GREEN(2)
        color_data0 = uint(0x49249249)
        color_data1 = uint(0x24924924)
        color_data2 = uint(0x92492492)  
    elif(col == 3):						#CYAN(3)
        color_data0 = uint(0x6db6db6d)
        color_data1 = uint(0xb6db6db6)
        color_data2 = uint(0xdb6db6db)
    elif(col == 4):						#RED(4)
        color_data0 = uint(0x92492492)
        color_data1 = uint(0x49249249)
        color_data2 = uint(0x24924924)
    elif(col == 5):						#MAGENTA(5)
        color_data0 = uint(0xb6db6db6)
        color_data1 = uint(0xdb6db6db)
        color_data2 = uint(0x6db6db6d)
    elif(col == 6):						#YELLOW(6)
        color_data0 = uint(0xdb6db6db)
        color_data1 = uint(0x6db6db6d)
        color_data2 = uint(0xb6db6db6)
    elif(col == 7):						#WHITE(7)
        color_data0 = uint(0xffffffff)
        color_data1 = uint(0xffffffff)
        color_data2 = uint(0xffffffff)
        
    for i in range(0,28920,3):			#640画素*3色＊４８２ライン／３２bit=28920words
        Data[i]   = color_data0
        Data[i+1] = color_data1
        Data[i+2] = color_data2

# --- 4)ドットを描画			VGAdriver2.draw_pix(x:int,y:int,col:int) ---
@micropython.viper
def draw_pix(x:int,y:int,col:int):
    Data=ptr32(H_buffer_line)
    # x,yを既定の範囲に補正する
    if(x < 0):		x = 0
    if(x > 639):	x = 639
    if(y < 0):		y = 0
    if(y > 479):	y = 479
    
    mask = uint(0xe0000000)
    x_syou  = x >> 5						# x/32の商
    x_amari = x % 32						# x/32の余り
    if(x_amari < 10):						# x_amari = 0-9
        mask = ~(mask >> 3*x_amari)
        col_data = col << 29 - 3*x_amari
        Data[60*y + 3*x_syou] = Data[60*y + 3*x_syou] & mask | col_data 
    elif(x_amari == 10):					# x_amari = 10
        mask = uint(0xfffffffc)
        col_data = col >> 1
        Data[60*y + 3*x_syou] = Data[60*y + 3*x_syou] & mask | col_data
        mask = uint(0x7fffffff)
        col_data = col << 31
        Data[60*y + 3*x_syou + 1] = Data[60*y + 3*x_syou + 1] & mask | col_data
    elif(x_amari < 21):						# x_amari = 11-20
        mask = ~(mask >> 3*(x_amari-11)+1)
        col_data = col << 28 - 3*(x_amari-11)
        Data[60*y + 3*x_syou + 1] = Data[60*y + 3*x_syou + 1] & mask | col_data
    elif(x_amari == 21):					# x_amari = 21
        mask = uint(0xfffffffe)
        col_data = col >> 2
        Data[60*y + 3*x_syou + 1] = Data[60*y + 3*x_syou + 1] & mask | col_data
        mask = uint(0x3fffffff)
        col_data = col << 30
        Data[60*y + 3*x_syou + 2] = Data[60*y + 3*x_syou + 2] & mask | col_data
    else:									# x_amari = 22-31
        mask = ~(mask >> 3*(x_amari-22)+2)
        col_data = col << 27 - 3*(x_amari-22)
        Data[60*y + 3*x_syou + 2] = Data[60*y + 3*x_syou + 2] & mask | col_data
        
# --- 5)水平実線を描画		VGAdriver2.draw_Hline(x1:int,x2:int,y:int,col:int) ---    
@micropython.viper
def draw_Hline(x1:int,x2:int,y:int,col:int):
    Data=ptr32(H_buffer_line)
    if(x1 < 0):		x1 = 0
    if(x1 > 639):	x1 = 639
    if(x2 < 0):		x2 = 0
    if(x2 > 639):	x2 = 639
    if(y < 0):		y = 0
    if(y > 479):	y = 479
    if(x1 > x2):	x1,x2 = x2,x1	#x1とx2を入れ替え
    
    if(x2-x1 < 64):					# 64画素以下の描画
        for i in range(x1,x2+1):
           draw_pix(i,y,col)
    else:							# 64画素以上の描画
        x1_syou  = x1 >> 5						# x1/32の商
        x2_syou  = x2 >> 5						# x1/32の商
        #--- 最初の32画素以下の描画 ---
        for i in range(x1,(x1_syou+1)*32):
           draw_pix(i,y,col)
        #--- 中間の描画（直接書き込む：高速) (x1_syou+1)*32からx2_syou*32-1まで---
        if(col == 0):						#BLACK(0)
            color_data0 = uint(0x0)
            color_data1 = uint(0x0)
            color_data2 = uint(0x0)
        elif(col == 1):						#BLUE(1)
            color_data0 = uint(0x24924924)
            color_data1 = uint(0x92492492)
            color_data2 = uint(0x49249249)
        elif(col == 2):						#GREEN(2)
            color_data0 = uint(0x49249249)
            color_data1 = uint(0x24924924)
            color_data2 = uint(0x92492492)  
        elif(col == 3):						#CYAN(3)
            color_data0 = uint(0x6db6db6d)
            color_data1 = uint(0xb6db6db6)
            color_data2 = uint(0xdb6db6db)
        elif(col == 4):						#RED(4)
            color_data0 = uint(0x92492492)
            color_data1 = uint(0x49249249)
            color_data2 = uint(0x24924924)
        elif(col == 5):						#MAGENTA(5)
            color_data0 = uint(0xb6db6db6)
            color_data1 = uint(0xdb6db6db)
            color_data2 = uint(0x6db6db6d)
        elif(col == 6):						#YELLOW(6)
            color_data0 = uint(0xdb6db6db)
            color_data1 = uint(0x6db6db6d)
            color_data2 = uint(0xb6db6db6)
        elif(col == 7):						#WHITE(7)
            color_data0 = uint(0xffffffff)
            color_data1 = uint(0xffffffff)
            color_data2 = uint(0xffffffff)
        for i in range(3*(x1_syou+1)+60*y,3*x2_syou -1+60*y,3):	#
            Data[i]   = color_data0
            Data[i+1] = color_data1
            Data[i+2] = color_data2  
        #--- 最後３２画素以下の描画 ---
        for i in range(x2_syou*32,x2+1):
           draw_pix(i,y,col)
           
# --- 6)水平破線を描画		VGAdriver2.draw_dashed_Hline(x1:int,x2:int,y:int,col:int) --- 
@micropython.viper
def draw_dashed_Hline(x1:int,x2:int,y:int,col:int):
    Data=ptr32(H_buffer_line)
    if(x1 < 0):		x1 = 0
    if(x1 > 639):	x1 = 639
    if(x2 < 0):		x2 = 0
    if(x2 > 639):	x2 = 639
    if(y < 0):		y = 0
    if(y > 479):	y = 479
    if(x1 > x2):	x1,x2 = x2,x1	#x1とx2を入れ替え
    
    for i in range(x1,x2+1):
        if(i % 2 == 0):	draw_pix(i,y,col)
        
# --- 7)垂直実線を描画		VGAdriver2.draw_Vline(x:int,y1:int,y2:int,col:int) ---      
@micropython.viper
def draw_Vline(x:int,y1:int,y2:int,col:int):
    Data=ptr32(H_buffer_line)
    if(x < 0):		x = 0
    if(x > 639):	x = 639
    if(y1 < 0):		y1 = 0
    if(y1 > 479):	y1 = 479
    if(y2 < 0):		y2 = 0
    if(y2 > 479):	y2 = 479
    if(y1 > y2):	y1,y2 = y2,y1	#y1とy2を入れ替え
    
    for i in range(y1,y2+1):
       draw_pix(x,i,col)

# --- 8)垂直破線を描画		VGAdriver2.draw_dashed_Vline(x:int,y1:int,y2:int,col:int) ---
@micropython.viper
def draw_dashed_Vline(x:int,y1:int,y2:int,col:int):
    Data=ptr32(H_buffer_line)
    if(x < 0):		x = 0
    if(x > 639):	x = 639
    if(y1 < 0):		y1 = 0
    if(y1 > 479):	y1 = 479
    if(y2 < 0):		y2 = 0
    if(y2 > 479):	y2 = 479
    if(y1 > y2):	y1,y2 = y2,y1	#y1とy2を入れ替え
    
    for i in range(y1,y2+1):
       if(i % 2 == 0):	draw_pix(x,i,col)

# --- 9)斜実線を描画			VGAdriver2.draw_line(x1:int,y1:int,x2:int,y2:int,col:int) ---
@micropython.viper
def draw_line(x1:int,y1:int,x2:int,y2:int,col:int):		#斜線を引く
    Data=ptr32(H_buffer_line)
    if(x1 < 0):		x1 = 0
    if(x1 > 639):	x1 = 639
    if(x2 < 0):		x2 = 0
    if(x2 > 639):	x2 = 639
    if(y1 < 0):		y1 = 0
    if(y1 > 479):	y1 = 479
    if(y2 < 0):		y2 = 0
    if(y2 > 479):	y2 = 479
    if(x1 > x2):
        x1,x2 = x2,x1	#x1とx2を入れ替え
        y1,y2 = y2,y1	#y1とy2を入れ替え
    
    for i in range(x1,x2):
        temp1 = ((y2-y1) * i + (y1*x2-y2*x1))//(x2-x1)
        draw_pix(i,temp1,col)
 
# --- 10)斜破線を描画			VGAdriver2.draw_dashed_line(x1:int,y1:int,x2:int,y2:int,col:int) ---
@micropython.viper
def draw_dashed_line(x1:int,y1:int,x2:int,y2:int,col:int):		#斜線を引く
    Data=ptr32(H_buffer_line)
    if(x1 < 0):		x1 = 0
    if(x1 > 639):	x1 = 639
    if(x2 < 0):		x2 = 0
    if(x2 > 639):	x2 = 639
    if(y1 < 0):		y1 = 0
    if(y1 > 479):	y1 = 479
    if(y2 < 0):		y2 = 0
    if(y2 > 479):	y2 = 479
    if(x1 > x2):
        x1,x2 = x2,x1	#x1とx2を入れ替え
        y1,y2 = y2,y1	#y1とy2を入れ替え
    
    for i in range(x1,x2):
        temp1 = ((y2-y1) * i + (y1*x2-y2*x1))//(x2-x1)
        if(i % 2 == 0):	draw_pix(i,temp1,col)

# --- 11)四角（線）を描画		VGAdriver2.draw_rect(x1:int,y1:int,x2:int,y2:int,col:int) ---
@micropython.viper
def draw_rect(x1:int,y1:int,x2:int,y2:int,col:int):
    draw_Hline(x1,x2,y1,col)
    draw_Hline(x1,x2,y2,col)
    draw_Vline(x1,y1,y2,col)
    draw_Vline(x2,y1,y2,col)
    
# --- 12)四角（面）を描画		VGAdriver2.fill_rect(x1:int,y1:int,x2:int,y2:int,col:int) ---
@micropython.viper
def fill_rect(x1:int,y1:int,x2:int,y2:int,col:int):
    if(y1 < 0):		y1 = 0
    if(y1 > 479):	y1 = 479
    if(y2 < 0):		y2 = 0
    if(y2 > 479):	y2 = 479
    if(y1 > y2):	y1,y2 = y2,y1	#y1とy2を入れ替え

    for i in range(y1,y2):
        draw_Hline(x1,x2,i,col)

# --- 13)円（線）を描画			VGAdriver2.draw_circle(x:int,y:int,r:int,color:int) ---
@micropython.viper
def draw_circle(x:int, y:int, r:int , color:int):
    if (x < 0 or y < 0 or x >= int(H_res) or y >= int(V_res)):
        return
    # Bresenham algorithm
    x_pos = 0-r
    y_pos = 0
    err = 2 - 2 * r
    while 1:
        draw_pix(x-x_pos, y+y_pos,color)
        draw_pix(x-x_pos, y-y_pos,color)
        draw_pix(x+x_pos, y+y_pos,color)
        draw_pix(x+x_pos, y-y_pos,color)
        e2 = err
        if (e2 <= y_pos):
            y_pos += 1
            err += y_pos * 2 + 1
            if((0-x_pos) == y_pos and e2 <= x_pos):
                e2 = 0
        if (e2 > x_pos):
            x_pos += 1
            err += x_pos * 2 + 1
        if x_pos > 0:
            break

# --- 14)円（面）を描画			VGAdriver2.fill_disk(x:int,y:int,r:int,color:int) ---
@micropython.viper
def fill_disk(x:int, y:int, r:int , color:int):
    if (x < 0 or y < 0 or x >= int(H_res) or y >= int(V_res)):
        return
    # Bresenham algorithm
    x_pos = 0-r
    y_pos = 0
    err = 2 - 2 * r
    while 1:
        draw_Hline(x-x_pos,x+x_pos,y+y_pos,color)
        draw_Hline(x-x_pos,x+x_pos,y-y_pos,color)
        e2 = err
        if (e2 <= y_pos):
            y_pos += 1
            err += y_pos * 2 + 1
            if((0-x_pos) == y_pos and e2 <= x_pos):
                e2 = 0
        if (e2 > x_pos):
            x_pos += 1
            err += x_pos * 2 + 1
        if x_pos > 0:
            break

# --- 15)12dotフォントを描画	VGAdriver2.draw_font12(x:int,y:int,col:int,moji) ---
def draw_font12(x:int,y:int,col:int, moji):
#*****************************  12dot FONTデータ	 ******************************
    font12 = (
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),#20h(SP)
    (0x00000020,0x00200020,0x00200020,0x00200020,0x00000000,0x00200000),#21h(!)
    (0x00000048,0x00240012,0x00000000,0x00000000,0x00000000,0x00000000),#22h(")
    (0x00000090,0x00900090,0x03fc0090,0x009003fc,0x00900090,0x00900000),#23h(#)
    (0x00000020,0x00f80124,0x002400f8,0x01200120,0x012400f8,0x00200000),#24h($)
    (0x0000008c,0x00920052,0x0052002c,0x01a00250,0x02500248,0x01880000),#25h(%)
    (0x00000070,0x00880088,0x00480130,0x01480084,0x00840144,0x02380000),#26h(&)
    (0x00200010,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),#27h(')
    (0x02000100,0x00800080,0x00400040,0x00400040,0x00800080,0x01000200),#28h[(]
    (0x00020004,0x00080008,0x00100010,0x00100010,0x00080008,0x00040002),#29h[)]
    (0x00000020,0x012400a8,0x007000a8,0x01240020,0x00000000,0x00000000),#2ah(*)
    (0x00000000,0x00200020,0x00200020,0x03fe0020,0x00200020,0x00200000),#2bh(+)
    (0x00000000,0x00000000,0x00000000,0x00000000,0x0000000c,0x000c0006),#2ch(,)
    (0x00000000,0x00000000,0x00000000,0x03fe0000,0x00000000,0x00000000),#2dh(-)
    (0x00000000,0x00000000,0x00000000,0x00000000,0x0000000c,0x000c0000),#2eh(.)
    (0x00000400,0x02000100,0x00800040,0x00200010,0x00080004,0x00020001),#2fh[/]
        
    (0x00000070,0x00880104,0x01040104,0x01040104,0x01040088,0x00700000),#30h(0)
    (0x00000020,0x00300028,0x00240020,0x00200020,0x00200020,0x00200000),#31h(1)
    (0x00000070,0x00880104,0x01000080,0x00400020,0x00100008,0x01fc0000),#32h(2)
    (0x000001fc,0x00800040,0x00200070,0x00800100,0x01040088,0x00700000),#33h(3)
    (0x00000060,0x00500050,0x00480048,0x00440044,0x01fe0040,0x00400000),#34h(4)
    (0x000001fc,0x00040004,0x0074008c,0x01000100,0x01000084,0x00780000),#35h(5)
    (0x000000f0,0x00080004,0x0074008c,0x01040104,0x01040088,0x00700000),#36h(6)
    (0x000001fc,0x01000080,0x00800040,0x00400020,0x00200010,0x00100000),#37h(7)
    (0x00000070,0x00880104,0x00880070,0x00880104,0x01040088,0x00700000),#38h(8)
    (0x00000070,0x00880104,0x01040104,0x01880170,0x01000080,0x00780000),#39h(9)
    (0x00000000,0x00000000,0x00300030,0x00000000,0x00300030,0x00000000),#3ah(:)
    (0x00000000,0x00000000,0x00300030,0x00000000,0x00300030,0x00180000),#3bh(;)
    (0x00000000,0x030000c0,0x0030000c,0x0003000c,0x003000c0,0x03000000),#3ch(<)
    (0x00000000,0x00000000,0x000003fe,0x00000000,0x03fe0000,0x00000000),#3dh(=)
    (0x00000000,0x00060018,0x00600180,0x06000180,0x00600018,0x00060000),#3eh(>)
    (0x00000070,0x00880104,0x01000080,0x00400020,0x00200000,0x00200000),#3fh(?)
        
    (0x000000f0,0x010c0264,0x02920292,0x02920292,0x01e4000c,0x00700000),#40h(@)
    (0x00000020,0x00200050,0x00500088,0x008801fc,0x01040202,0x02020000),#41h(A)
    (0x000000fc,0x01040104,0x010400fc,0x01040204,0x02040104,0x00fc0000),#42h(B)
    (0x000001f0,0x02080004,0x00040004,0x00040004,0x00040208,0x01f00000),#43h(C)
    (0x0000007c,0x01840104,0x02040204,0x02040204,0x01040184,0x00fc0000),#44h(D)
    (0x000001fc,0x00040004,0x000400fc,0x00040004,0x00040004,0x01fc0000),#45h(E)
    (0x000001fc,0x00040004,0x000400fc,0x00040004,0x00040004,0x00040000),#46h(F)
    (0x000001f0,0x02080004,0x000403c4,0x02040204,0x02040308,0x00f00000),#47h(G)
    (0x00000204,0x02040204,0x020403fc,0x02040204,0x02040204,0x02040000),#48h(H)
    (0x00000020,0x00200020,0x00200020,0x00200020,0x00200020,0x00200000),#49h(I)
    (0x00000080,0x00800080,0x00800080,0x00820082,0x00820044,0x00380000),#4ah(J)
    (0x00000104,0x00840044,0x00240014,0x002c0044,0x00840104,0x02040000),#4bh(K)
    (0x00000004,0x00040004,0x00040004,0x00040004,0x00040004,0x01fc0000),#4ch(L)
    (0x00000202,0x0306028a,0x02520222,0x02220202,0x02020202,0x02020000),#4dh(M)
    (0x00000104,0x010c0114,0x01140124,0x01240144,0x01440184,0x01040000),#4eh(N)
    (0x000000f0,0x01080204,0x02040204,0x02040204,0x02040108,0x00f00000),#4fh(O)
        
    (0x0000007c,0x00840104,0x01040084,0x007c0004,0x00040004,0x00040000),#50h(P)
    (0x000000f0,0x01080204,0x02040204,0x02040244,0x02840108,0x02f00000),#51h(Q)
    (0x0000007c,0x00840104,0x01040084,0x007c0084,0x00840104,0x01040000),#52h(R)
    (0x000000f0,0x01080204,0x000800f0,0x01000200,0x02040108,0x00f00000),#53h(S)
    (0x000003fe,0x00200020,0x00200020,0x00200020,0x00200020,0x00200000),#54h(T)
    (0x00000104,0x01040104,0x01040104,0x01040104,0x01040088,0x00700000),#55h(U)
    (0x00000104,0x01040104,0x00880088,0x00880050,0x00500020,0x00200000),#56h(V)
    (0x00000222,0x02220222,0x02220154,0x01540154,0x00880088,0x00880000),#57h(W)
    (0x00000104,0x01040088,0x00500020,0x00200050,0x00880104,0x01040000),#58h(X)
    (0x00000104,0x01040088,0x00880050,0x00500020,0x00200020,0x00200000),#59h(Y)
    (0x000001fc,0x01000080,0x00400020,0x00100008,0x00040004,0x01fc0000),#5ah(Z)
    (0x03800080,0x00800080,0x00800080,0x00800080,0x00800080,0x00800380),#5bh([)
    (0x00000104,0x01040088,0x005001fc,0x00200020,0x01fc0020,0x00200000),#5ch(\) 
    (0x000e0008,0x00080008,0x00080008,0x00080008,0x00080008,0x0008000e),#5dh(])
    (0x00200050,0x00880000,0x00000000,0x00000000,0x00000000,0x00000000),#5eh(^)
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000fff),#5fh(_)
        
    (0x00100020,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),#60h()
    (0x00000000,0x00000000,0x00f00100,0x01e00118,0x01080188,0x01700000),#61h(a)
    (0x00000008,0x00080008,0x00680098,0x01080108,0x01080098,0x00680000),#62h(b)
    (0x00000000,0x00000000,0x00e00110,0x00080008,0x00080110,0x00e00000),#63h(c)
    (0x00000100,0x01000100,0x01600190,0x01080108,0x01080190,0x01600000),#64h(d)
    (0x00000000,0x00000000,0x00600090,0x010801f8,0x00080110,0x00e00000),#65h(e)
    (0x000001c0,0x00200020,0x002001f8,0x00200020,0x00200020,0x00200000),#66h(f)
    (0x00000000,0x00000160,0x01900108,0x01080190,0x01600100,0x00800070),#67h(g)
    (0x00000008,0x00080008,0x00680098,0x01080108,0x01080108,0x01080000),#68h(h)
    (0x00000020,0x00200000,0x00000020,0x00200020,0x00200020,0x00200000),#69h(i)
    (0x00000040,0x00400000,0x00000040,0x00400040,0x00400040,0x00200018),#6ah(j)
    (0x00000008,0x00080008,0x00880048,0x00280018,0x00280048,0x00880000),#6bh(k)
    (0x00000020,0x00200020,0x00200020,0x00200020,0x00200020,0x00200000),#6ch(l)
    (0x00000000,0x00000000,0x019a0266,0x02220222,0x02220222,0x02220000),#6dh(m)
    (0x00000000,0x00000000,0x00e80118,0x01080108,0x01080108,0x01080000),#6eh(n)
    (0x00000000,0x00000000,0x00700088,0x01040104,0x01040088,0x00700000),#6fh(o)
        
    (0x00000000,0x00000068,0x00980108,0x01080108,0x00980068,0x00080008),#70h(p)
    (0x00000000,0x00000160,0x01900108,0x01080108,0x01900160,0x01000100),#71h(q)
    (0x00000000,0x00000000,0x00680098,0x00080008,0x00080008,0x00080000),#72h[r]
    (0x00000000,0x00000000,0x00f00108,0x000800f0,0x01000108,0x00f00000),#73h(s)
    (0x00000010,0x00100010,0x00fc0010,0x00100010,0x00100090,0x00e00000),#74h(t)
    (0x00000000,0x00000000,0x01080108,0x01080108,0x01080188,0x01700000),#75h(u)
    (0x00000000,0x00000000,0x01040104,0x00880088,0x00500050,0x00200000),#76h(v)
    (0x00000000,0x00000000,0x02220222,0x02220154,0x015400a8,0x00a80000),#77h(w)
    (0x00000000,0x00000000,0x01040088,0x00500020,0x00500088,0x01040000),#78h(x)
    (0x00000000,0x00000000,0x01080108,0x01100090,0x00a00040,0x00400020),#79h(y)
    (0x00000000,0x00000000,0x01f80080,0x00400020,0x00100008,0x01f80000),#7ah(z)
    (0x00000100,0x00800080,0x00800080,0x00600080,0x00800080,0x00800100),#7bh({)
    (0x00200020,0x00200020,0x00200020,0x00200020,0x00200020,0x00200020),#7ch(|)
    (0x00000004,0x00080008,0x00080008,0x00300008,0x00080008,0x00080004),#7dh(})
    (0x00000000,0x00000000,0x00001c70,0x038e0000,0x00000000,0x00000000),#7eh(~)
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),#7fh(DL)
    )
        
    #------- draw_font12(x:int,y:int,col:int, moji)の　プログラムはここから --------
    # x,yを既定の範囲に補正する
    if(x < 0):		x = 0
    if(x > 639):	x = 639
    if(y < 0):		y = 0
    if(y > 479):	y = 479
         
    y_copy = y
    x_copy = x 
    for character in moji:												#最初の文字から文字列の最後までを繰り返す
        for j in range(6):												#各文字の6ワードを順に読みだす
            font_data1 = font12[ord(character)-0x20][j] >> 16			#bit32-16
            font_data2 = font12[ord(character)-0x20][j] & 0x0000ffff	#bit15-0
            #-------- 上位１６ビット処理 --------
            mask = 0b0000000000000001									#16bit  
            for k in range(12):											#8bit分(bit31-16)　font12に１があるかチェックする
                if font_data1 & mask != 0:								#1の時、ドットを描画する
                    draw_pix(x_copy,y_copy,col)
                mask = mask << 1
                x_copy = x_copy + 1
                    
            #-------- 下位１６ビット処理 --------
            y_copy = y_copy + 1
            x_copy = x_copy - 12
            mask = 0b0000000000000001								#16bit 
            for k in range(12):										#8bit分(bit15-0)　font12に１があるかチェックする
                if font_data2 & mask != 0:							#1の時、ドットを描画する
                    draw_pix(x_copy,y_copy,col)
                mask = mask << 1
                x_copy = x_copy + 1
            #--------- 次のfontデーターの座標再設定 -----------    
            y_copy = y_copy + 1
            x_copy = x_copy - 12
            
        #-----------------次のキャラクタの座標の再設定 --------------------
        y_copy = y
        x_copy = x_copy + 12
    del font12

# --- 16)18dotフォントを描画	VGAdriver2.draw_font18(x:int,y:int,col:int,moji) ---
def draw_font18(x:int,y:int,col:int, moji):
#*****************************  18dot FONTデータ(bit32-18,bit15-2) ********************
    font18 = (							
    # 0          1          2          3          4          5          6          7          8
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),   #0x20 sp
    (0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc0000000,0x0000c000,0xc0000000,0x00000000),   #0x21 !
    (0x33003300,0x66008800,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),   #0x22 '"'
    (0x19801980,0x19801980,0xffc0ffc0,0x33003300,0x3300ffc0,0xffc06600,0x66006600,0x66000000,0x00000000),   #0x23 #
    (0x0c003f00,0x7f80edc0,0xccc0cc00,0x6c003f00,0x0d800cc0,0xccc0edc0,0x7f803f00,0x0c000000,0x00000000),   #0x24 $
    (0x38067c0e,0x6c1c6c38,0x6c707ce0,0x39c00380,0x07780e7c,0x1c6c386c,0x706ce07c,0xc0380000,0x00000000),   #0x25 %
    (0x18003c00,0x6e006600,0x66006c00,0x38003800,0x6cc0cec0,0xc7c0c380,0xe7c07ef0,0x3c700000,0x00000000),   #0x26 &
    (0x30003000,0x60008000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),   #0x27 "'"
    (0x30007000,0x6000e000,0xc000c000,0xc000c000,0xc000c000,0xc000e000,0x60007000,0x30000000,0x00000000),	#0x28 (
    (0xc000e000,0x60007000,0x30003000,0x30003000,0x30003000,0x30007000,0x6000e000,0xc0000000,0x00000000),	#0x29)
    (0x0000c30c,0xe31c7338,0x3b701fe0,0x0fc00780,0x07800fc0,0x1fe03b70,0x7338e31c,0xc30c0000,0x00000000),   #0x2a *
    (0x00000000,0x00000000,0x00001800,0x18001800,0xff00ff00,0x18001800,0x18000000,0x00000000,0x00000000),	#0x2b +
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00003000,0x30006000,0x80000000,0x00000000),	#0x2c ,
    (0x00000000,0x00000000,0x00000000,0x00000000,0xff00ff00,0x00000000,0x00000000,0x00000000,0x00000000),	#0x2d -
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x0000c000,0xc0000000,0x00000000),	#0x2e .
    (0x03800300,0x07000600,0x0e000c00,0x1c001800,0x38003000,0x70006000,0xe000c000,0xc0000000,0x00000000),	#0x2f /
    # 0          1          2          3          4          5          6          7          8		
    (0x3e007f00,0xe380c180,0xc180c180,0xc180c180,0xc180c180,0xc180c180,0xe3807f00,0x3e000000,0x00000000),   #0x30 0	
    (0x10003000,0x7000f000,0x30003000,0x30003000,0x30003000,0x30003000,0x30003000,0x30000000,0x00000000),   #0x31 1	
    (0x3c007e00,0xe700c300,0x03000700,0x06000c00,0x18003000,0x7000e000,0xc000ff00,0xff000000,0x00000000),   #0x32 2	
    (0x7c00fe00,0xc7000300,0x03000700,0x3e003c00,0x0e000700,0x03000300,0xc700fe00,0x7c000000,0x00000000),   #0x33 3	
    (0x07000f00,0x0f001b00,0x1b003300,0x33006300,0x6300c300,0xffc0ffc0,0x03000300,0x03000000,0x00000000),   #0x34 4	
    (0xff00ff00,0xc000c000,0xc000dc00,0xfe00f700,0x03000300,0xc300c300,0x67007e00,0x3c000000,0x00000000),   #0x35 5	
    (0x1c003e00,0x7700e300,0xc000c000,0xdc00fe00,0xe700c300,0xc300c300,0xe6007e00,0x3c000000,0x00000000),   #0x36 6	
    (0xff00ff00,0x03000700,0x06000e00,0x0c001c00,0x18003800,0x30007000,0x60006000,0x60000000,0x00000000),   #0x37 7	
    (0x3e007f00,0xe380c180,0xc180e380,0x7f003e00,0x6300c180,0xc180c180,0xe3807f00,0x3e000000,0x00000000),   #0x38 8
    (0x3c007e00,0x6700c300,0xc300c300,0x67007f00,0x3b000300,0x0300c300,0xe7007e00,0x3c000000,0x00000000),   #0x39 9	
    (0x00000000,0x0000c000,0xc0000000,0x00000000,0x00000000,0x0000c000,0xc0000000,0x00000000,0x00000000),   #0x3a :	
    (0x00000000,0x0000c000,0xc0000000,0x00000000,0x00000000,0x0000c000,0xc0004000,0x80000000,0x00000000),   #0x3b ;	
    (0x01c00380,0x07000e00,0x1c003800,0x7000e000,0x70003800,0x1c000e00,0x07000380,0x01c00000,0x00000000),   #0x3c <	
    (0x00000000,0x00000000,0x00000000,0xff80ff80,0x00000000,0x0000ff80,0xff800000,0x00000000,0x00000000),   #0x3d =	
    (0xe0007000,0x38001c00,0x0e000700,0x038001c0,0x03800700,0x0e001c00,0x38007000,0xe0000000,0x00000000),   #0x3e >	
    (0x3c007e00,0xe700c300,0xc3000300,0x06000c00,0x18001800,0x18000000,0x00001800,0x18000000,0x00000000),   #0x3f ?
    # 0          1          2          3          4          5          6          7          8
    (0x1f803fc0,0x7060e730,0xcfb0ddb0,0xd8b0d8b0,0xd9b0dd30,0xcfe0e6c0,0x70003fc0,0x1f800000,0x00000000),   #0x40 @	
    (0x0e000e00,0x0e001f00,0x1f001b80,0x3b803180,0x31807fc0,0x7fc060c0,0xe0e0c060,0xc0600000,0x00000000),   #0x41 A	
    (0xfe00ff00,0xc380c180,0xc180c300,0xfe00ff00,0xc180c0c0,0xc0c0c0c0,0xc1c0ff80,0xff000000,0x00000000),   #0x42 B	
    (0x1e003f00,0x7380e1c0,0xc0c0c000,0xc000c000,0xc000c000,0xc0c0e1c0,0x73803f00,0x1e000000,0x00000000),   #0x43 C	
    (0xfe00ff00,0xc380c1c0,0xc0c0c0c0,0xc0c0c0c0,0xc0c0c0c0,0xc0c0c1c0,0xc380ff00,0xfe000000,0x00000000),   #0x44 D	
    (0xffc0ffc0,0xc000c000,0xc000c000,0xff80ff80,0xc000c000,0xc000c000,0xc000ffc0,0xffc00000,0x00000000),   #0x45 E	
    (0xff80ff80,0xc000c000,0xc000c000,0xff00ff00,0xc000c000,0xc000c000,0xc000c000,0xc0000000,0x00000000),   #0x46 F	
    (0x1e003f00,0x7380e1c0,0xc0c0c0c0,0xc000c000,0xc7c0c7c0,0xc0c0e1c0,0x73c03fc0,0x1ec00000,0x00000000),   #0x47 G	
    (0xc0c0c0c0,0xc0c0c0c0,0xc0c0c0c0,0xffc0ffc0,0xc0c0c0c0,0xc0c0c0c0,0xc0c0c0c0,0xc0c00000,0x00000000),   #0x48 H	
    (0xf000f000,0x60006000,0x60006000,0x60006000,0x60006000,0x60006000,0x6000f000,0xf0000000,0x00000000),   #0x49 I	
    (0x01800180,0x01800180,0x01800180,0x01800180,0x0180c180,0xc180c180,0xe3807f00,0x3e000000,0x00000000),   #0x4a J	
    (0xc0e0c1c0,0xc380c700,0xce00dc00,0xf800f000,0xf800dc00,0xce00c700,0xc380c1c0,0xc0e00000,0x00000000),   #0x4b K	
    (0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000ff80,0xff800000,0x00000000),   #0x4c L	
    (0xe038e038,0xf078f078,0xf8f8d8d8,0xddd8cd98,0xcf98c718,0xc718c218,0xc218c018,0xc0180000,0x00000000),   #0x4d M	
    (0xc0c0e0c0,0xf0c0f0c0,0xd8c0d8c0,0xccc0ccc0,0xccc0c6c0,0xc6c0c3c0,0xc3c0c1c0,0xc0c00000,0x00000000),   #0x4e N	
    (0x1f803fc0,0x70e0e070,0xc030c030,0xc030c030,0xc030c030,0xc030e070,0x70e03fc0,0x1f800000,0x00000000),   #0x4f O
    # 0          1          2          3          4          5          6          7          8        
    (0xfe00ff00,0xc380c180,0xc180c380,0xff00de00,0xc000c000,0xc000c000,0xc000c000,0xc0000000,0x00000000),   #0x50 P	
    (0x1f803fc0,0x70e0e070,0xc030c030,0xc030c030,0xc330c330,0xe1f0e0e0,0x71f03fb8,0x1f180000,0x00000000),   #0x51 Q	
    (0xfe00ff00,0xc380c1c0,0xc0c0c0c0,0xc1c0ff80,0xff00dc00,0xce00c700,0xc380c1c0,0xc0e00000,0x00000000),   #0x52 R	
    (0x3e007f00,0xe300c000,0xc000e000,0x7c003f00,0x07800180,0x0180c180,0xe3807f00,0x3e000000,0x00000000),   #0x53 S	
    (0xffc0ffc0,0x0c000c00,0x0c000c00,0x0c000c00,0x0c000c00,0x0c000c00,0x0c000c00,0x0c000000,0x00000000),   #0x54 T	
    (0xc060c060,0xc060c060,0xc060c060,0xc060c060,0xc060c060,0xc060e0e0,0x71c03f80,0x1f000000,0x00000000),   #0x55 U	
    (0xc060c060,0xc060e0e0,0x60c060c0,0x71c03180,0x31803b80,0x1b001b00,0x1f000e00,0x0e000000,0x00000000),   #0x56 V	
    (0xc30cc30c,0xc30cc30c,0xe79c6798,0x67986798,0x7ff83cf0,0x3cf03cf0,0x3cf01860,0x18600000,0x00000000),   #0x57 W	
    (0xe0e060c0,0x71803180,0x3b801b00,0x1b000e00,0x1b001b00,0x3b803180,0x718060c0,0xe0e00000,0x00000000),   #0x58 X	
    (0xc0c0c0c0,0xe1c06180,0x73803300,0x3f001e00,0x1e000c00,0x0c000c00,0x0c000c00,0x0c000000,0x00000000),   #0x59 Y	
    (0xff80ff80,0x03000700,0x06000e00,0x0c001c00,0x18003800,0x30007000,0x6000ff80,0xff800000,0x00000000),   #0x5a Z	
    (0xf800f800,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000f800,0xf8000000,0x00000000),   #0x5b [	
    (0xe0706060,0x70e030c0,0x39c01980,0x1f807fe0,0x7fe00600,0x7fe07fe0,0x06000600,0x06000000,0x00000000),   #0x5c	
    (0xf800f800,0x18001800,0x18001800,0x18001800,0x18001800,0x18001800,0x1800f800,0xf8000000,0x00000000),   #0x5d ]
    (0x08001c00,0x36006300,0xc1800000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),   #0x5e ^	
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x0000ffc0,0xffc00000,0x00000000),   #0x5f _
    # 0          1          2          3          4          5          6          7          8     
    (0x30003000,0x40004000,0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),   #0x60 	
    (0x00000000,0x00000000,0x00007e00,0x7f000300,0x7f00ff00,0xe300c300,0xe380ffc0,0x7ec00000,0x00000000),   #0x61 a
    (0xc000c000,0xc000c000,0xc000fe00,0xff00c380,0xc180c180,0xc180c180,0xc380ff00,0xfe000000,0x00000000),   #0x62 b
    (0x00000000,0x00000000,0x00003e00,0x7f00e300,0xc000c000,0xc000c000,0xe3007f00,0x3e000000,0x00000000),   #0x63 c	
    (0x03000300,0x03000300,0x03003f00,0x7f00e300,0xc300c300,0xc300c300,0xe3007f00,0x3f000000,0x00000000),   #0x64 d	
    (0x00000000,0x00000000,0x00003c00,0x7e00e700,0xc300ff00,0xff00c000,0xe3007f00,0x3e000000,0x00000000),   #0x65 e	
    (0x07000f00,0x1c001800,0x18001800,0xff00ff00,0x18001800,0x18001800,0x18001800,0x18000000,0x00000000),   #0x66 f	
    (0x00000000,0x00000000,0x00003c00,0x7e00e700,0xc300c300,0xc300e700,0x7f003b00,0x0300c700,0xfe007c00),   #0x67 g	
    (0xc000c000,0xc000c000,0xc000fc00,0xfe00c700,0xc300c300,0xc300c300,0xc300c300,0xc3000000,0x00000000),   #0x68 h	
    (0x0000c000,0xc0000000,0x0000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc0000000,0x00000000),   #0x69 i	
    (0x00001800,0x18000000,0x00001800,0x18001800,0x18001800,0x18001800,0x18001800,0x18003800,0xf000e000),   #0x6a j	
    (0xc000c000,0xc000c000,0xc000c380,0xc700ce00,0xdc00f800,0xfc00ee00,0xc700c380,0xc1c00000,0x00000000),   #0x6b k	
    (0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000f000,0xf0000000,0x00000000),   #0x6c l	
    (0x00000000,0x00000000,0x0000cc60,0xdef0fff0,0xf7b0e730,0xc630c630,0xc630c630,0xc6300000,0x00000000),   #0x6d m
    (0x00000000,0x00000000,0x0000ce00,0xdf00ff00,0xf300e300,0xc300c300,0xc300c300,0xc3000000,0x00000000),   #0x6e n
    (0x00000000,0x00000000,0x00003c00,0x7e00e700,0xc300c300,0xc300c300,0xe7007e00,0x3c000000,0x00000000),   #0x6f o
    # 0          1          2          3          4          5          6          7          8
    (0x00000000,0x00000000,0x0000fc00,0xfe00c700,0xc300c300,0xc700fe00,0xfc00c000,0xc000c000,0xc000c000),   #0x70 p	
    (0x00000000,0x00000000,0x00003f00,0x7f00e300,0xc300c300,0xc300e300,0x7f003f00,0x03000300,0x03000300),   #0x71 q	
    (0x00000000,0x00000000,0x0000c600,0xce00d800,0xf000e000,0xc000c000,0xc000c000,0xc0000000,0x00000000),   #0x72 r	
    (0x00000000,0x00000000,0x00007e00,0xff00c300,0xe0007e00,0x3f000300,0xc700ff00,0x7e000000,0x00000000),   #0x73 s	
    (0x00000000,0x30003000,0x3000fe00,0xfe003000,0x30003000,0x30003000,0x38003e00,0x1e000000,0x00000000),   #0x74 t	
    (0x00000000,0x00000000,0x0000c300,0xc300c300,0xc300c300,0xc300c300,0xe7007e00,0x3c000000,0x00000000),   #0x75 u	
    (0x00000000,0x00000000,0x0000c180,0xc180e380,0x63007700,0x36003e00,0x1c001c00,0x08000000,0x00000000),   #0x76 v	
    (0x00000000,0x00000000,0x0000c980,0xc980dd80,0xdd80ff80,0xff807700,0x77006300,0x63000000,0x00000000),   #0x77 w	
    (0x00000000,0x00000000,0x0000c0c0,0xe1c07380,0x3f001e00,0x1e003f00,0x7380e1c0,0xc0c00000,0x00000000),   #0x78 x	
    (0x00000000,0x00000000,0x0000c300,0xc300c300,0xc300e700,0xff007b00,0x03000300,0x03000700,0x7f007e00),   #0x79 y	
    (0x00000000,0x00000000,0x0000ff00,0xff000300,0x06001c00,0x38006000,0xc000ff00,0xff000000,0x00000000),   #0x7a z
    (0x0c001800,0x30003000,0x30003000,0x7000e000,0x70003000,0x30003000,0x30001800,0x0c000000,0x00000000),   #0x7b {
    (0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc0000000,0x00000000),   #0x7c |	
    (0xc0006000,0x30003000,0x30003000,0x38001c00,0x38003000,0x30003000,0x30006000,0xc0000000,0x00000000),   #0x7d)}
    (0x00000000,0x00000000,0x00000000,0x00001810,0x7e70e7e0,0x81800000,0x00000000,0x00000000,0x00000000),   #0x7e ~  
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),   #0x7f DL
    )
    #------- draw_font18(x:int,y:int,col:int, moji)の　プログラムはここから --------
    # x,yを既定の範囲に補正する
    if(x < 0):		x = 0
    if(x > 639):	x = 639
    if(y < 0):		y = 0
    if(y > 479):	y = 479
     
    y_copy = y
    x_copy = x 
    for character in moji:											#最初の文字から文字列の最後までを繰り返す  
        for j in range(9):											#各文字の9ワードを順に読みだす
            font_data1 = font18[ord(character)-0x20][j] >> 16			#bit32-16
            font_data2 = font18[ord(character)-0x20][j] & 0x0000ffff	#bit15-0
            #-------- 上位１６ビット処理 --------
            mask = 0b1000000000000000								#16bit  
            for k in range(16):										#14bit分(bit31-18)　font18に１があるかチェックする
                if font_data1 & mask != 0:							#1の時、ドットを描画する
                    draw_pix(x_copy,y_copy,col)
                mask = mask >> 1
                x_copy = x_copy + 1    
            #-------- 下位１６ビット処理 --------
            y_copy = y_copy + 1
            x_copy = x_copy - 17
            mask = 0b10000000000000000								#16bit 
            for k in range(16):										#14bit分(bit15-2)　font18に１があるかチェックする
                if font_data2 & mask != 0:							#1の時、ドットを描画する
                    draw_pix(x_copy,y_copy,col)
                mask = mask >> 1
                x_copy = x_copy + 1
            #--------- 次のfontデーターの座標再設定 -----------    
            y_copy = y_copy + 1
            x_copy = x_copy - 15
        #-----------------次のキャラクタの座標の再設定 --------------------
        y_copy = y
        x_copy = x_copy + 16
    del font18

# --- 17)24dotフォントを描画	VGAdriver2.draw_font24(x:int,y:int,col:int,moji) ---
def draw_font24(x:int,y:int,col:int, moji):
#*****************************  24dot FONTデータ(bit32-16,bit15-0) ********************
    font24 = (
#	  0			 1			2		   3		  4			 5			6		   7		  8			 9			10		   11
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),  # sp:20h
    (0x0f800f80,0x0f800f80,0x0f800f80,0x0f800f80,0x07000700,0x07000700,0x07000000,0x00000000,0x07000f00,0x0f800700,0x00000000,0x00000000),	# ! :21h
    (0x38e038e0,0x38e030c0,0x20800000,0x00000000,0x00000000,0x000000000,0x0000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),  # " :22h
    (0x1c701c70,0x1c701c70,0x1cfefffe,0xfffeff70,0x1c701c70,0x1c701c70,0x1cfefffe,0xfffeff70,0x1c701c70,0x1c701c70,0x00000000,0x00000000),	# # :23h   
    (0x03800380,0x0fe03ff8,0x7ff87398,0x63806380,0x73803ff0,0x1ffc038e,0x0386c386,0xf39efffe,0x3ff80fe0,0x03800380,0x00000000,0x00000000),	# $ :24h    
    (0x7c0efe0e,0xc61cc638,0xc638fe70,0x7ce000e0,0x01c001c0,0x03800700,0x077c0efe,0x1cc61cc6,0x38c638fe,0x707ce000,0x00000000,0x00000000),	# % :25h  
    (0x07000f80,0x1dc03860,0x30603060,0x386019c0,0x1f801e00,0x7c006e00,0xc700c382,0xc1cee0fe,0xf0fc7ff8,0x1fde070e,0x00000000,0x00000000),	# & :26h   
    (0x07000700,0x07000600,0x04000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# ':27h
    
    (0x06000c00,0x18003000,0x30006000,0x6000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc0006000,0x60003000,0x30001800,0x0c000600),	# ( :28h
    (0xc0006000,0x30001800,0x18000c00,0x0c000600,0x06000600,0x06000600,0x06000600,0x06000600,0x06000c00,0x0c001800,0x18003000,0x6000c000),	# ) :29h
    (0x00000000,0x07000700,0x07004710,0xe738f778,0x3fe00f80,0x0f803fe0,0xf778e738,0x47100700,0x07000700,0x00000000,0x00000000,0x00000000),	# * :2Ah
    (0x00000000,0x00000700,0x07000700,0x07000700,0x0700fff8,0xfff80700,0x07000700,0x07000700,0x07000000,0x00000000,0x00000000,0x00000000),	# + :2Bh
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xe000e000,0xe0006000,0xc000c000,0x00000000,0x00000000),	# , :2Ch
    (0x00000000,0x00000000,0x00000000,0x00000000,0xfff8fff8,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# - :2Dh
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# . :2Eh
    (0x00180010,0x00300060,0x004000c0,0x00800180,0x01000300,0x02000600,0x0c000800,0x18001000,0x00000000,0x00000000,0x00000000,0x00000000),	# / :2Fh

#	  0			 1			2		   3		  4			 5			6		   7		  8			 9			10		   11
    (0x0f801fc0,0x38e07070,0xe038e038,0xe078e0f8,0xe1b8e338,0xe638ec38,0xf838f038,0xe038e038,0x707038e0,0x1fc00f80,0x00000000,0x00000000),	# 0 :30h 
    (0x0c001c00,0x3c007c00,0xfc001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x00000000,0x00000000),	# 1 :31h
    (0x1f003f80,0x7bc071e0,0xe0e0e0e0,0x00e001c0,0x01c00380,0x07000f00,0x1e003c00,0x7800f000,0xe000fff0,0xfff0fff0,0x00000000,0x00000000),	# 2 :32h
    (0x1f003fc0,0x79c060e0,0xe0e0c0e0,0x00e001e0,0x0fc00f80,0x07e001e0,0x00f00070,0xe070e070,0xf0e07be0,0x3fc01f80,0x00000000,0x00000000),	# 3 :33h
    (0x01c003c0,0x07c007c0,0x0fc00dc0,0x1dc039c0,0x39c071c0,0x71c0e1c0,0xfff8fff8,0xfff801c0,0x01c001c0,0x01c001c0,0x00000000,0x00000000),	# 4 :34h
    (0x7fe07fe0,0x7fe07000,0x70007000,0x77007fc0,0x7de078e0,0x70f00070,0x00700070,0xe070e0e0,0x70e079c0,0x3f801f00,0x00000000,0x00000000),	# 5 :35h
    (0x0f001f80,0x39c070e0,0x6060e000,0xe000ef80,0xffc0f1c0,0xe0e0e0e0,0xe0e0e0e0,0xe0e0e0e0,0x70e079c0,0x3fc03f00,0x00000000,0x00000000),	# 6 :36h
    (0xfff0fff0,0xffe000e0,0x00e001c0,0x01c001c0,0x01800380,0x03800380,0x07000700,0x07000e00,0x0e000e00,0x1c001c00,0x00000000,0x00000000),	# 7 :37h
    (0x1f803fc0,0x79e070e0,0x60606060,0x70e070e0,0x3fc01f80,0x3fc070e0,0xe070e070,0xe070e070,0xf0f079e0,0x3fc01f80,0x00000000,0x00000000),	# 8 :38h
    (0x1e003f80,0x7fc071c0,0xe0e0e0e0,0xe0e0e0e0,0xe0e0e1e0,0x7fe07fe0,0x3ee000e0,0x00e0e0e0,0xe1c073c0,0x7f803e00,0x00000000,0x00000000),	# 9 :39h
    (0x00000000,0x0000e000,0xe000e000,0x00000000,0x00000000,0x00000000,0x00000000,0xe000e000,0x00000000,0x00000000,0x00000000,0x00000000),	# : :3Ah
    (0x00000000,0x0000e000,0xe000e000,0x00000000,0x00000000,0x00000000,0x00000000,0xe000e000,0xe0006000,0xc000c000,0x00000000,0x00000000),	# ; :3Bh
    (0x00380070,0x00e001c0,0x03800700,0x0e001c00,0x38007000,0xe0007000,0x38001c00,0x0e000700,0x038001c0,0x00e00070,0x00000000,0x00000000),	# < :3Ch
    (0x00000000,0x00000000,0x0000fff8,0xfff8fff8,0x00000000,0x00000000,0xfff8fff8,0xfff80000,0x00000000,0x00000000,0x00000000,0x00000000),	# = :3Dh
    (0xe0007000,0x38001c00,0x0e000700,0x038001c0,0x00e00070,0x00380070,0x00e001c0,0x03800700,0x0e001c00,0x38007000,0x00000000,0x00000000),	# > :3Eh
    (0x1f803fc0,0x79e070e0,0xe0e0e0e0,0x00e001e0,0x03c00780,0x07000e00,0x0e000e00,0x00000000,0x00000e00,0x0e000e00,0x00000000,0x00000000),	# ? :3Fh

#	  0			 1			2		   3		  4			 5			6		   7		  8			 9			10		   11
    (0x000003c0,0x0e38180c,0x300663ba,0x47f28e33,0x8c339c33,0x9c739c63,0x9c62dce4,0x4ffc4738,0x60003008,0x1c7807e0,0x00000000,0x00000000),	# @ :40h 
    (0x03800380,0x038007c0,0x07c007c0,0x0ee00ee0,0x1c701c70,0x18303838,0x3ff83ff8,0x783c701c,0x701cf01e,0xe00ee00e,0x00000000,0x00000000),	# A :41h
    (0xffe0fff0,0xfff8e03c,0xe01ce01c,0xe01ce03c,0xfff8fff0,0xfff8e01c,0xe00ee00e,0xe00ee00e,0xe01efffc,0xfff8ffe0,0x00000000,0x00000000),	# B :42h
    (0x07e00ff8,0x1ffc381e,0x700e700e,0xe00ee000,0xe000e000,0xe000e000,0xe00ee00e,0xf00e700e,0x781e3ffc,0x1ff807e0,0x00000000,0x00000000),	# C :43h
    (0xffc0ffe0,0xfff0e038,0xe01ce00c,0xe00ee006,0xe006e006,0xe006e006,0xe006e006,0xe00ee01c,0xe03cfff8,0xfff0ffe0,0x00000000,0x00000000),	# D :44h
    (0xfff8fff8,0xfff8e000,0xe000e000,0xe000e000,0xfff0fff0,0xfff0e000,0xe000e000,0xe000e000,0xe000fffc,0xfffcfffc,0x00000000,0x00000000),	# E :45h
    (0xfff8fff8,0xfff8e000,0xe000e000,0xe000e000,0xffe0ffe0,0xffe0e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0x00000000,0x00000000),	# F :46h    
    (0x03e00ff8,0x1ffc3c1e,0x780e7006,0xf006e000,0xe000e000,0xe03ee03e,0xe006f006,0x70067806,0x3c0e1ffe,0x0ff607e6,0x00000000,0x00000000),	# G :47h
    (0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xfffefffe,0xfffee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0x00000000,0x00000000),	# H :48h
    (0x07c007c0,0x07c00380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x038007c0,0x07c007c0,0x00000000,0x00000000),	# I :49h
    (0x00380038,0x00380038,0x00380038,0x00380038,0x00380038,0x00380038,0xe038e038,0xe038f038,0x78787ff0,0x3fe01fc0,0x00000000,0x00000000),	# J :4Ah
    (0xe01ce038,0xe038e070,0xe0e0e1c0,0xe380e700,0xee00ff00,0xfb80f380,0xe1c0e0e0,0xe0e0e070,0xe038e038,0xe01ce00e,0x00000000,0x00000000),	# K :4Bh
    (0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000fff8,0xfff8fff8,0x00000000,0x00000000),	# L :4Ch
    (0xe00ee00e,0xe00ef01e,0xf01ef01e,0xf83ef83e,0xf83efc7e,0xfc7efc7e,0xeeeeeeee,0xeeeee7ce,0xe7cee7ce,0xe38ee38e,0x00000000,0x00000000),	# M :4Dh
    (0xe00ef00e,0xf80ef80e,0xfc0efc0e,0xfc0ee60e,0xe70ee30e,0xe18ee18e,0xe0cee0ee,0xe06ee07e,0xe03ee03e,0xe01ee00e,0x00000000,0x00000000),	# N :4Eh    
    (0x07e01ff0,0x3e78783c,0x701ce00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00e701c,0x783c3e78,0x1ff007e0,0x00000000,0x00000000),	# O :4Fh

#	  0			 1			2		   3		  4			 5			6		   7		  8			 9			10		   11
    (0xffe0fff8,0xfffce01e,0xe00ee00e,0xe00ee00e,0xe00ee03e,0xfffcfff8,0xffe0e000,0xe000e000,0xe000e000,0xe000e000,0x00000000,0x00000000),	# P :50h 
    (0x07e01ff0,0x3e78783c,0x701ce00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee1ce,0xe0ee707c,0x783c3e7c,0x1ffe07ee,0x00000000,0x00000000),	# Q :51h    
    (0xffe0fff8,0xfffce01c,0xe00ee00e,0xe00ee00e,0xe01cfff8,0xfff0ffe0,0xe0f0e070,0xe038e038,0xe01ce01c,0xe00ee00e,0x00000000,0x00000000),	# R :52h
    (0x0fc03ff0,0x7cf87038,0xe01ce01c,0xf0007800,0x3f000fc0,0x03f000f8,0x003ce01e,0xe01ee01c,0x703c7c78,0x3ff80fe0,0x00000000,0x00000000),	# S :53h
    (0xfffefffe,0xfffe0380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x00000000,0x00000000),	# T :54h
    (0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ee00e,0xe00ef01e,0x783c7ffc,0x3ff80fe0,0x00000000,0x00000000),	# U :55h
    (0xe007700e,0x700e700e,0x381c381c,0x381c1c38,0x1c381c38,0x0e700e70,0x0e7007e0,0x07e007e0,0x03c003c0,0x01800180,0x00000000,0x00000000),	# V :56h
    (0xe187e187,0xe187e3c7,0x73ce73ce,0x77ee766e,0x766e366c,0x3e7c3e7c,0x3e7c3c3c,0x3c3c3c3c,0x1c381c38,0x18181818,0x00000000,0x00000000),	# W :57h
    (0xe007700e,0x281c381c,0x1c380e70,0x0e7007e0,0x03c003c0,0x03c003c0,0x07e00e70,0x0e701c38,0x381c381c,0x700ee007,0x00000000,0x00000000),	# X :58h
    (0xe00e701c,0x701c3838,0x38381c70,0x1c700ee0,0x0ee007c0,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x00000000,0x00000000),	# Y :59h
    (0x7ffc7ffc,0x7ffc001c,0x00380070,0x00e001c0,0x01c00380,0x07000e00,0x0e001c00,0x38007000,0xe000fffc,0xfffcfffc,0x00000000,0x00000000),	# Z :5Ah
    (0xfe00fe00,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xc000c000,0xfe00fe00,0x00000000,0x00000000),  # [ :5Bh
    (0xe0076006,0x781c781c,0x1c380c30,0x0e7007e0,0x3ffc3ffc,0x01800180,0x3ffc3ffc,0x01800180,0x01800180,0x01800180,0x00000000,0x00000000),	# ￥ :5Ch
    (0xfe00fe00,0x06000600,0x06000600,0x06000600,0x06000600,0x06000600,0x06000600,0x06000600,0x06000600,0xfe00fe00,0x00000000,0x00000000),	# ] :5Dh
    (0x0e001f00,0x3f8071c0,0xe0e00000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# ^ :5Eh
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xff80ff80,0x00000000,0x00000000),	# _ :5Fh

#	  0			 1			2		   3		  4			 5			6		   7		  8			 9			10		   11
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# ' :60h 
    (0x00000000,0x00000000,0x00000000,0x00001f80,0x3fc079e0,0x706000e0,0x07e03fe0,0x7860e060,0xe0e0e1e0,0x7fe03e70,0x00000000,0x00000000),	# a :61h
    (0xe000e000,0xe000e000,0xe000e000,0xe000ef80,0xffc0f9e0,0xf060e070,0xe070e070,0xe070e070,0xf0e0f9e0,0xffc0ef80,0x00000000,0x00000000),	# b :62h
    (0x00000000,0x00000000,0x00000000,0x00000f80,0x1fc039e0,0x70e07070,0xe000e000,0xe000e070,0x707078e0,0x3fe01f80,0x00000000,0x00000000),	# c :63h
    (0x00700070,0x00700070,0x00700070,0x00701f70,0x3ff071f0,0x70f0e070,0xe070e070,0xe070e070,0x70f079f0,0x3ff00f70,0x00000000,0x00000000),	# d :64h
    (0x00000000,0x00000000,0x00000000,0x0f003fc0,0x79e070e0,0xe070fff0,0xfff0e000,0xe000e070,0x707078e0,0x1fe00f80,0x00000000,0x00000000),	# e :65h
    (0x07c00fe0,0x1e601c00,0x1c001c00,0x1c00ffc0,0xffc01c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001c00,0x00000000,0x00000000),	# f :66h
    (0x00000000,0x00000000,0x00000000,0x00001f78,0x1ff879c0,0x70c070c0,0x71c03bc0,0x3f806e00,0x60007fc0,0x3fe060f0,0xe070e070,0x7fe03fc0),	# g :67h
    (0xe000e000,0xe000e000,0xe000e000,0xe000e7c0,0xefe0fcf0,0xf870f070,0xe070e070,0xe070e070,0xe070e070,0xe070e070,0x00000000,0x00000000),	# h :68h
    (0x00000000,0x0000e000,0xe000e000,0x00000000,0x0000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0x00000000,0x00000000),	# i :69h
    (0x03800380,0x03800000,0x00000000,0x00000380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0x03800380,0xc380e780,0x7f003e00),	# j :6Ah
    (0xe000e000,0xe000e000,0xe000e000,0xe000e0e0,0xe1e0e380,0xe700ee00,0xff00fb00,0xf380e1c0,0xe1c0e0e0,0xe060e070,0x00000000,0x00000000),	# k :6Bh
    (0x00000000,0x0000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0xf000f000,0x00000000,0x00000000),	# l :6Ch   
    (0x00000000,0x00000000,0x00000000,0x0000ec60,0xfef8f7dc,0xe38ee38e,0xe38ee38e,0xe38ee38e,0xe38ee38e,0xe38ee38e,0x00000000,0x00000000),	# m :6Dh    
    (0x00000000,0x00000000,0x00000000,0x0000e780,0xefe0fce0,0xf070f070,0xe070e070,0xe070e070,0xe070e070,0xe070e070,0x00000000,0x00000000),	# n :6Eh    
    (0x00000000,0x00000000,0x00000000,0x00001f80,0x3fc079e0,0xf0f0e070,0xe070e070,0xe070e070,0xf0f079e0,0x3fc01f80,0x00000000,0x00000000),	# o :6Fh

#	  0			 1			2		   3		  4			 5			6		   7		  8			 9			10		   11
    (0x00000000,0x00000000,0x00000000,0x0000ef80,0xffc0f9e0,0xf0f0e070,0xe070e070,0xe070e070,0xf070f8e0,0xffc0ef80,0xe000e000,0xe000e000),	# p :70h 
    (0x00000000,0x00000000,0x00000000,0x00001f70,0x3ff071f0,0x60f0e070,0xe070e070,0xe070e070,0x70f079f0,0x3ff01f70,0x00700070,0x00700070),	# q :71h
    (0x00000000,0x00000000,0x00000000,0x0000e780,0xef80ff80,0xf800f000,0xe000e000,0xe000e000,0xe000e000,0xe000e000,0x00000000,0x00000000),	# r :72h
    (0x00000000,0x00000000,0x00000000,0x00001f00,0x3f8071c0,0xe0c0f000,0x7c003f80,0x07c001e0,0xe0e0f0e0,0x7fc03f80,0x00000000,0x00000000),	# s :73h
    (0x00000000,0x1c001c00,0x1c001c00,0x1c00ff80,0xff801c00,0x1c001c00,0x1c001c00,0x1c001c00,0x1c001e60,0x0fe007c0,0x00000000,0x00000000),	# t :74h
    (0x00000000,0x00000000,0x00000000,0x0000e070,0xe070e070,0xe070e070,0xe070e070,0xe070e0f0,0xe0f073f0,0x7f703e70,0x00000000,0x00000000),	# u :75h
    (0x00000000,0x00000000,0x00000000,0x0000e038,0x60307070,0x70703060,0x38e018c0,0x1dc01dc0,0x0d800f80,0x07000700,0x00000000,0x00000000),	# v :76h
    (0x00000000,0x00000000,0x00000000,0x0000e187,0xe18773ce,0x73ce73ce,0x33cc366c,0x3e7c1e78,0x1e781e78,0x0c300c30,0x00000000,0x00000000),	# w :77h
    (0x00000000,0x00000000,0x00000000,0x0000e070,0x70e039c0,0x39c01f80,0x0f000600,0x0f001f80,0x39c039c0,0x70e0f070,0x00000000,0x00000000),	# x :78h
    (0x00000000,0x00000000,0x00000000,0x0000e038,0x60307070,0x30703060,0x38e018c0,0x1cc01dc0,0x0d800f80,0x07800700,0x07006e00,0x3e003c00),	# y :79h
    (0x00000000,0x00000000,0x00000000,0x0000ffe0,0xffe000e0,0x01c00380,0x07000e00,0x1c003800,0x7000e000,0xffe0ffe0,0x00000000,0x00000000),	# z :7Ah
    (0x00e000e0,0x01c001c0,0x01c001c0,0x01c001c0,0x03800700,0x07000380,0x01c001c0,0x01c001c0,0x01c001c0,0x00e000e0,0x00000000,0x00000000),	# { :7Bh
    (0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0,0x01c001c0),	# | :7Ch

    (0x07000700,0x03800380,0x03800380,0x03800380,0x038000e0,0x00e00380,0x03800380,0x03800380,0x03800380,0x07000700,0x00000000,0x00000000),	# } :7Dh
    
    (0x00000000,0x00000000,0x00000000,0x1c063e0e,0x7f3ee3f8,0xc1f080e0,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# ~  :7Eh
    (0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000),	# DL  :7Fh
    )
    #------- draw_font24(x:int,y:int,col:int, moji)の　プログラムはここから --------
    # x,yを既定の範囲に補正する
    if(x < 0):		x = 0
    if(x > 639):	x = 639
    if(y < 0):		y = 0
    if(y > 479):	y = 479
     
    y_copy = y
    x_copy = x 
    for character in moji:												#最初の文字から文字列の最後までを繰り返す  
        for j in range(12):												#各文字の9ワードを順に読みだす
            font_data1 = font24[ord(character)-0x20][j] >> 16			#bit32-16
            font_data2 = font24[ord(character)-0x20][j] & 0x0000ffff	#bit15-0
            #-------- 上位１６ビット処理 --------
            mask = 0b1000000000000000									#16bit  
            for k in range(16):											#16bit分(bit31-16)　font24に１があるかチェックする
                if font_data1 & mask != 0:								#1の時、ドットを描画する
                    draw_pix(x_copy,y_copy,col)
                mask = mask >> 1
                x_copy = x_copy + 1    
            #-------- 下位１６ビット処理 --------
            y_copy = y_copy + 1
            x_copy = x_copy - 17
            mask = 0b10000000000000000									#16bit 
            for k in range(16):											#16bit分(bit15-0)　font24に１があるかチェックする
                if font_data2 & mask != 0:								#1の時、ドットを描画する
                    draw_pix(x_copy,y_copy,col)
                mask = mask >> 1
                x_copy = x_copy + 1
            #--------- 次のfontデーターの座標再設定 -----------    
            y_copy = y_copy + 1
            x_copy = x_copy - 15
        #-----------------次のキャラクタの座標の再設定 --------------------
        y_copy = y
        x_copy = x_copy + 16
    del font24

# --- 18)ピンボール			VGAdriver2.pin_ball() ---
@micropython.viper
def pin_ball():
    fill_screen(7)			#白
    
    mode_x = 1				#x-
    mode_y = 1				#y-
    col = 1
    x = 20
    y = 20
    
    while(col < 26):
        if(x > 620):
            mode_x = 0		#x-
            col = col + 1
        if(x < 20):
            mode_x = 1		#x+
            col = col + 1
        if(y > 460):
            mode_y = 0		#y-
            col = col + 1
        if(y < 20):
            mode_y = 1		#y+
            col = col + 1
             
        if(mode_x == 0):	 x = x - 1		#x-
        if(mode_x == 1):	 x = x + 1		#x+
        if(mode_y == 0):	 y = y - 1		#y-
        if(mode_y == 1):	 y = y + 1		#y+
        fill_disk(x,y,20,col & 0b111)

        

    


 