Cls:
	stz CursorX 
	stz CursorY
	rts
Locate:
		stx CursorX 
		sty CursorY
	rts
NewLine:
	stz CursorX	
	inc CursorY
	rts
  
PrintChar:
	clc
	sbc #31
	sta z_As
	PushAll
	lda z_H
	pha
	lda z_L
	pha

		lda CursorY 	
		.ifdef ScrWid256	;256x192
			clc
			adc #2
		.endif
		sta z_H
		lda #0
		
		clc
		ror z_H
		ror 
		ror z_H
		ror 
		ror z_H
		ror 
		adc CursorX 	
		sta z_L
		
		
PrintCharRetry:
		jsr WaitVblank
		lda z_L
		sta $2116		;MemL -Video port address [VMADDL/VMADDH]                            
		lda z_H
		sta $2117		;MemH
		
		stz $2119	;h -Video port data [VMDATAL/VMDATAH]                             
		lda z_As
		sta $2118	;l
	
		lda $4212 			;HVBJOY - Status 
			; xy00000a		- x=vblank state y=hblank state a=joypad ready
		and #%10000000
		beq PrintCharRetry		;Wait until we get nonzero - this means we're in VBLANK
	
	inc CursorX
	lda CursorX
	cmp #32
	bne PrintChar_NotNextLine
	jsr NewLine
	
PrintChar_NotNextLine:
	
		
	pla
	sta z_L
	pla
	sta z_H	
	PullAll
	
	rts
	
			
load_font:

	lda #$00
	sta $2116		;MemL
	lda #$10
	sta $2117		;MemH
	

	lda #BitmapFont&255
	sta z_L
	lda #BitmapFont/256
	sta z_H
	ldx #3
	ldy #0
fontchar_loop:
	lda (z_HL),y
	sta $2119
	sta $2118			;Write data to data-port
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	iny
	lda (z_HL),y
	sta $2119
	sta $2118
	
	
	lda #0	
	jsr blankblock
	iny
	bne fontchar_loop
	inc z_HL+1
	dex
	bne fontchar_loop
	rts
blankblock:
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	sta $2119
	sta $2118
	rts