Sunday, August 26, 2018

64 column text on a 256x192 graphics screen -> 6502 Part 2

;* Copyright (c) 2015, 2016, 2018 James Diffendaffer

;**************************************************
; NAME: print_64
;**************************************************
;* Description:
;*  64 Column text display driver
;*  Routine does not print at pixel X,Y but
;*  prints at a character position.
;**************************************************
print_64:
	; register a contains character
	sec
	sbc		#' '				; printable character set data starts at space, ASCII 32
	tax							; save as character table offset

.if BytesPerLine = 32
	; point screen to base screen address + row
	lda		#>ScreenAdr
;	lda		#$80
	clc
	adc		row					; adding row to MSB = 256 * row
	sta		fscreen+1

	ldy		#0					; top line is always black (1st byte of the font)
								; start at zero offset from screen address
	
	; put the lowest bit in the carry so we know if it's left or right nibble
	lda		col					; 2 columns / byte
	lsr

	bcs		rightnibble
.endif

.if BytesPerLine = 40
.if Plus4
; col addition requires multiply by 8 due to the byte order of the screen and
; divide by 2 for two characters per byte, so col * 4
; any col over 64 requires 2 bytes added to screen address anyway, so make another table

	; calculate screen address based on row and column
	clc
	ldy		row					; put row offset in y
	lda		scrtableLSB,y		; get screen row address MSB from table
	ldy		col					; put col index in y
	adc		coltableLSB,y		; get LSB from column table
	sta		fscreen				; store LSB of screen address
	ldy		row					; put row offset in y
	lda		scrtableMSB,y		; get screen row address MSB from table
	ldy		col					; put col index in y
	adc		coltableMSB,y		; get MSB from column table
	sta		fscreen+1			; store MSB of screen address

	tya							; put column in a
	
	ldy		#0					; top line is always black (1st byte of the font)
								; start at zero offset from screen address

	lsr							; even or odd column?
	bcs		rightnibble
.else
	ldy		row					; put row offset in y

;	clc							; carry should be clear from asl
	lda		col
	lsr
	adc		scrtableLSB,y		; get LSB offset from table
	sta		fscreen				; store LSB
	lda		#0
	adc		scrtableMSB,y		; get MSB offset from table and add carry
	sta		fscreen+1			; store MSB

	ldy		#0					; top line is always black (1st byte of the font)
								; start at zero offset from screen address
	lda		col
	lsr
	bcs		rightnibble
.endif
.endif

	
;**************************************************
;* left nibble 
;**************************************************
leftnibble:
	lda		BGColor
	sta		(fscreen),y			; write to the screen

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*1		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol1,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol1,X				; EOR with the next byte of the font	
	sta		(fscreen),y

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*2		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol2,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol2,X				; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*3		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol3,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol3,X				; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*4		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol4,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol4,X				; EOR with the next byte of the font	
	sta		(fscreen),y

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*5		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol5,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol5,X				; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*6		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol6,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol6,X				; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
.if BytesPerLine = 32
	ldy		#BytesPerLine*7		; point to next screen byte
.endif
.if BytesPerLine = 40
	;clc
	lda		fscreen				; point to next screen byte
	adc		#BytesPerLine
	sta		fscreen				; LSB
	lda		#0
	adc		fscreen+1			; MSB
	sta		fscreen+1
.endif
.endif
	lda		(fscreen),y
;	eor		FCol7,X				; EOR with the next byte of the font
;	and		#%00001111
	eor		FCol7,X				; EOR with the next byte of the font	
	sta		(fscreen),y
	
	rts
	
	
;**************************************************
; right nibble
;**************************************************
rightnibble:
	lda		BGColor
	sta		(fscreen),y			; write to the screen

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*1		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol21,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol21,X			; EOR with the next byte of the font	
	sta		(fscreen),y

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*2		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol22,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol22,X			; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*3		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol23,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol23,X			; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*4		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol24,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol24,X			; EOR with the next byte of the font	
	sta		(fscreen),y

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*5		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol25,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol25,X			; EOR with the next byte of the font	
	sta		(fscreen),y
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*6		; point to next screen byte
.endif
	lda		(fscreen),y
;	eor		FCol26,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol26,X			; EOR with the next byte of the font	
	sta		(fscreen),y
	

.if Plus4 = 1
	iny							; point to next screen byte
.else
.if BytesPerLine = 32
	ldy		#BytesPerLine*7		; point to next screen byte
.endif
.if BytesPerLine = 40
	;clc
	lda		fscreen				; point to next screen byte
	adc		#BytesPerLine
	sta		fscreen				; LSB
	lda		#0
	adc		fscreen+1			; MSB
	sta		fscreen+1
.endif
.endif
	lda		(fscreen),y
;	eor		FCol27,X			; EOR with the next byte of the font
;	and		#%11110000
	eor		FCol27,X			; EOR with the next byte of the font	
	sta		(fscreen),y
	
	rts

;**************************************************
; write two characters at once
;**************************************************
print_642:
	; register a contains character
;	lda		(string),y
	sec
	sbc		#' '				; printable character set data starts at space, ASCII 32
	sta		firstchar			; save as character table offset

	iny
	lda		(string),y
	sec
	sbc		#' '
	sta		secondchar
	
.if BytesPerLine = 32
	; point screen to $8000 + row (base screen address + row)
	lda		#>ScreenAdr
;	lda		#$80
	clc
	adc		row					; adding row to MSB = 256 * row
	sta		fscreen+1

	ldy		#0					; top line is always black (1st byte of the font)
								; start at zero offset from screen address
	
	; add the column
	lda		col					; 2 columns / byte
	lsr
	sta		fscreen				; save it
.endif

.if BytesPerLine = 40
	lda		row
;	asl							; * 2 for word sized table (row max of 25 * 2)
	tax							; put offset in x

;	clc							; carry should be clear from asl
	lda		col
	lsr
	adc		scrtableLSB,X			; get LSB offset from table
	sta		fscreen				; store LSB
	lda		scrtableMSB,X		; get MSB offset from table
	adc		#0					; add carry
	sta		fscreen+1			; store MSB
.endif

twochar:
	lda		BGColor
	sta		(fscreen),y			; write to the screen

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*1		; point to next screen byte
.endif
	ldx		firstchar			; offset to 1st character
	lda		FCol1,X				; load the next byte of the 1st character
	ldx		secondchar			; offset to 2nd character
	eor		FCol21,X			; add the next byte of the 2nd character
	sta		(fscreen),y			; write it to the screen

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*2		; point to next screen byte
.endif
	lda		FCol22,X			; add the next byte of the 2nd character
	ldx		firstchar			; offset to 1st character
	eor		FCol2,X				; load the next byte of the 1st character
	sta		(fscreen),y			; write it to the screen
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*3		; point to next screen byte
.endif
	lda		FCol3,X				; load the next byte of the 1st character
	ldx		secondchar			; offset to 2nd character
	eor		FCol23,X			; add the next byte of the 2nd character
	sta		(fscreen),y			; write it to the screen
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*4		; point to next screen byte
.endif
	lda		FCol24,X			; add the next byte of the 2nd character
	ldx		firstchar			; offset to 1st character
	eor		FCol4,X				; load the next byte of the 1st character
	sta		(fscreen),y			; write it to the screen

.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*5		; point to next screen byte
.endif
	lda		FCol5,X				; load the next byte of the 1st character
	ldx		secondchar			; offset to 2nd character
	eor		FCol25,X			; add the next byte of the 2nd character
	sta		(fscreen),y			; write it to the screen
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
	ldy		#BytesPerLine*6		; point to next screen byte
.endif
	lda		FCol26,X			; add the next byte of the 2nd character
	ldx		firstchar			; offset to 1st character
	eor		FCol6,X				; load the next byte of the 1st character
	sta		(fscreen),y			; write it to the screen
	
.if Plus4 = 1
	iny							; point to next screen byte
.else
.if BytesPerLine = 32
	ldy		#BytesPerLine*7		; point to next screen byte
.endif
.if BytesPerLine = 40
	;clc
	lda		fscreen				; point to next screen byte
	adc		#BytesPerLine
	sta		fscreen				; LSB
	lda		#0
	adc		fscreen+1			; MSB
	sta		fscreen+1
.endif
.endif
	lda		FCol7,X				; load the next byte of the 1st character
	ldx		secondchar			; offset to 2nd character
	eor		FCol27,X			; add the next byte of the 2nd character
	sta		(fscreen),y			; write it to the screen
	
	rts

.if BytesPerLine = 40	
;**************************************************
; 80 column address lookup table
;**************************************************
.define scrval		ScreenAdr+BytesPerLine*8
.define coltable 	scrval*0, scrval*1, scrval*2, scrval*3, scrval*4, scrval*5, scrval*6, scrval*7, scrval*8, scrval*9, scrval*10, scrval*11, scrval*12, scrval*13, scrval*14, scrval*15, scrval*16, scrval*17, scrval*18, scrval*19, scrval*20, scrval*21, scrval*22, scrval*23, scrval*24	
scrtableLSB:
	.lobytes		coltable
scrtableMSB:
	.hibytes		coltable
.endif

;**************************************************
; HALF WIDTH 4x8 FONT
; Top row is always zero and not stored (336 bytes)
; characters are 4 bits wide and 7 bits high 
; (the top row is always blank)
; There are two characters stored in each group of
; 7 bytes.  Each byte has bits for one character in
; the high nibble and bits for another in the low nibble
; Font borrowed from Sinclair Spectrum code
;**************************************************
;.align 256
font:
;FCol0:
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;FCol20:
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
FCol1:
	.byte	$00, $20, $50, $20, $20, $50, $20, $20, $10, $40, $20, $00, $00, $00, $00, $10
	.byte	$20, $20, $20, $70, $50, $70, $10, $70, $20, $20, $00, $00, $00, $00, $00, $20
	.byte	$20, $30, $60, $30, $60, $70, $70, $30, $50, $70, $30, $50, $40, $50, $60, $20
	.byte	$60, $20, $60, $30, $70, $50, $50, $50, $50, $50, $70, $30, $40, $60, $20, $00
	.byte	$20, $00, $40, $00, $10, $00, $10, $00, $40, $20, $10, $40, $60, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $10, $20, $40, $50, $60
FCol21:
	.byte	$00, $02, $05, $02, $02, $05, $02, $02, $01, $04, $02, $00, $00, $00, $00, $01
	.byte	$02, $02, $02, $07, $05, $07, $01, $07, $02, $02, $00, $00, $00, $00, $00, $02
	.byte	$02, $03, $06, $03, $06, $07, $07, $03, $05, $07, $03, $05, $04, $05, $06, $02
	.byte	$06, $02, $06, $03, $07, $05, $05, $05, $05, $05, $07, $03, $04, $06, $02, $00
	.byte	$02, $00, $04, $00, $01, $00, $01, $00, $04, $02, $01, $04, $06, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $01, $02, $04, $05, $06
FCol2:
	.byte	$00, $20, $50, $70, $70, $10, $40, $20, $20, $20, $70, $00, $00, $00, $00, $10
	.byte	$50, $60, $50, $10, $50, $40, $20, $10, $50, $50, $00, $00, $10, $00, $40, $50
	.byte	$50, $50, $50, $40, $50, $40, $40, $40, $50, $20, $10, $50, $40, $70, $50, $50
	.byte	$50, $50, $50, $40, $20, $50, $50, $50, $50, $50, $10, $20, $40, $20, $50, $00
	.byte	$10, $00, $40, $00, $10, $00, $20, $00, $40, $00, $00, $40, $20, $00, $00, $00
	.byte	$00, $00, $00, $00, $20, $00, $00, $00, $00, $00, $00, $20, $20, $20, $a0, $90
FCol22:
	.byte	$00, $02, $05, $07, $07, $01, $04, $02, $02, $02, $07, $00, $00, $00, $00, $01
	.byte	$05, $06, $05, $01, $05, $04, $02, $01, $05, $05, $00, $00, $01, $00, $04, $05
	.byte	$05, $05, $05, $04, $05, $04, $04, $04, $05, $02, $01, $05, $04, $07, $05, $05
	.byte	$05, $05, $05, $04, $02, $05, $05, $05, $05, $05, $01, $02, $04, $02, $05, $00
	.byte	$01, $00, $04, $00, $01, $00, $02, $00, $04, $00, $00, $04, $02, $00, $00, $00
	.byte	$00, $00, $00, $00, $02, $00, $00, $00, $00, $00, $00, $02, $02, $02, $0a, $09
FCol3:
	.byte	$00, $20, $00, $20, $60, $20, $30, $00, $40, $10, $20, $20, $00, $00, $00, $20
	.byte	$50, $20, $10, $20, $50, $60, $60, $10, $20, $50, $20, $20, $20, $70, $20, $10
	.byte	$70, $50, $60, $40, $50, $60, $60, $40, $70, $20, $10, $60, $40, $50, $50, $50
	.byte	$50, $50, $50, $20, $20, $50, $50, $50, $20, $50, $20, $20, $20, $20, $00, $00
	.byte	$00, $30, $60, $30, $30, $20, $70, $30, $60, $60, $30, $50, $20, $50, $60, $20
	.byte	$60, $30, $50, $30, $70, $50, $50, $50, $50, $50, $70, $20, $20, $20, $00, $60
FCol23:
	.byte	$00, $02, $00, $02, $06, $02, $03, $00, $04, $01, $02, $02, $00, $00, $00, $02
	.byte	$05, $02, $01, $02, $05, $06, $06, $01, $02, $05, $02, $02, $02, $07, $02, $01
	.byte	$07, $05, $06, $04, $05, $06, $06, $04, $07, $02, $01, $06, $04, $05, $05, $05
	.byte	$05, $05, $05, $02, $02, $05, $05, $05, $02, $05, $02, $02, $02, $02, $00, $00
	.byte	$00, $03, $06, $03, $03, $02, $07, $03, $06, $06, $03, $05, $02, $05, $06, $02
	.byte	$06, $03, $05, $03, $07, $05, $05, $05, $05, $05, $07, $02, $02, $02, $00, $06
FCol4:
	.byte	$00, $20, $00, $20, $30, $20, $50, $00, $40, $10, $50, $70, $00, $70, $00, $20
	.byte	$50, $20, $20, $10, $70, $10, $50, $20, $50, $30, $00, $00, $40, $00, $10, $20
	.byte	$70, $70, $50, $40, $50, $40, $40, $50, $50, $20, $50, $50, $40, $50, $50, $50
	.byte	$60, $50, $60, $10, $20, $50, $50, $50, $20, $20, $20, $20, $20, $20, $00, $00
	.byte	$00, $50, $50, $40, $50, $50, $20, $50, $50, $20, $10, $60, $20, $70, $50, $50
	.byte	$50, $50, $60, $60, $20, $50, $50, $50, $20, $50, $30, $40, $20, $10, $00, $40
FCol24:
	.byte	$00, $02, $00, $02, $03, $02, $05, $00, $04, $01, $05, $07, $00, $07, $00, $02
	.byte	$05, $02, $02, $01, $07, $01, $05, $02, $05, $03, $00, $00, $04, $00, $01, $02
	.byte	$07, $07, $05, $04, $05, $04, $04, $05, $05, $02, $05, $05, $04, $05, $05, $05
	.byte	$06, $05, $06, $01, $02, $05, $05, $05, $02, $02, $02, $02, $02, $02, $00, $00
	.byte	$00, $05, $05, $04, $05, $05, $02, $05, $05, $02, $01, $06, $02, $07, $05, $05
	.byte	$05, $05, $06, $06, $02, $05, $05, $05, $02, $05, $03, $04, $02, $01, $00, $04
FCol5:
	.byte	$00, $00, $00, $70, $70, $40, $50, $00, $40, $10, $00, $20, $00, $00, $00, $40
	.byte	$50, $20, $40, $50, $10, $50, $50, $20, $50, $20, $00, $00, $20, $70, $20, $00
	.byte	$40, $50, $50, $40, $50, $40, $40, $50, $50, $20, $50, $50, $40, $50, $50, $50
	.byte	$40, $50, $50, $50, $20, $50, $20, $70, $50, $20, $40, $20, $10, $20, $00, $00
	.byte	$00, $50, $50, $40, $50, $60, $20, $50, $50, $20, $10, $50, $20, $50, $50, $50
	.byte	$50, $50, $40, $30, $20, $50, $20, $70, $20, $50, $60, $20, $20, $20, $00, $60
FCol25:
	.byte	$00, $00, $00, $07, $07, $04, $05, $00, $04, $01, $00, $02, $00, $00, $00, $04
	.byte	$05, $02, $04, $05, $01, $05, $05, $02, $05, $02, $00, $00, $02, $07, $02, $00
	.byte	$04, $05, $05, $04, $05, $04, $04, $05, $05, $02, $05, $05, $04, $05, $05, $05
	.byte	$04, $05, $05, $05, $02, $05, $02, $07, $05, $02, $04, $02, $01, $02, $00, $00
	.byte	$00, $05, $05, $04, $05, $06, $02, $05, $05, $02, $01, $05, $02, $05, $05, $05
	.byte	$05, $05, $04, $03, $02, $05, $02, $07, $02, $05, $06, $02, $02, $02, $00, $06
FCol6:
	.byte	$00, $20, $00, $20, $20, $50, $30, $00, $20, $20, $00, $00, $20, $00, $10, $40
	.byte	$20, $70, $70, $20, $10, $20, $20, $20, $20, $40, $20, $20, $10, $00, $40, $20
	.byte	$30, $50, $60, $30, $60, $70, $40, $30, $50, $70, $20, $50, $70, $50, $50, $20
	.byte	$40, $30, $50, $20, $20, $20, $20, $50, $50, $20, $70, $20, $10, $20, $00, $00
	.byte	$00, $30, $60, $30, $30, $30, $40, $30, $50, $70, $50, $50, $70, $50, $50, $20
	.byte	$60, $30, $40, $60, $10, $20, $20, $50, $50, $30, $70, $20, $20, $20, $00, $90
FCol26:
	.byte	$00, $02, $00, $02, $02, $05, $03, $00, $02, $02, $00, $00, $02, $00, $01, $04
	.byte	$02, $07, $07, $02, $01, $02, $02, $02, $02, $04, $02, $02, $01, $00, $04, $02
	.byte	$03, $05, $06, $03, $06, $07, $04, $03, $05, $07, $02, $05, $07, $05, $05, $02
	.byte	$04, $03, $05, $02, $02, $02, $02, $05, $05, $02, $07, $02, $01, $02, $00, $00
	.byte	$00, $03, $06, $03, $03, $03, $04, $03, $05, $07, $05, $05, $07, $05, $05, $02
	.byte	$06, $03, $04, $06, $01, $02, $02, $05, $05, $03, $07, $02, $02, $02, $00, $09
FCol7:
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $10, $40, $00, $00, $20, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $20, $00, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $30, $00, $60, $00, $F0
	.byte	$00, $00, $00, $00, $00, $00, $00, $66, $00, $00, $20, $00, $00, $00, $00, $00
	.byte	$40, $10, $00, $00, $00, $00, $00, $00, $00, $60, $00, $10, $00, $40, $00, $60
FCol27:
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $01, $04, $00, $00, $02, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $02, $00, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
	.byte	$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $03, $00, $06, $00, $0F
	.byte	$00, $00, $00, $00, $00, $00, $00, $06, $00, $00, $02, $00, $00, $00, $00, $00
	.byte	$04, $01, $00, $00, $00, $00, $00, $00, $00, $06, $00, $01, $00, $04, $00, $06



;	.bss	
String:	.res	256



.if Plus4
; Plus4 column offset.  I use Font Height but this must be fixed at 8 for the Plus4 screen layout
; format  column left nibble offset, column right nibble offset (both are the same), next...
; doubling info lets us replace lda col, lsr, tay  with ldy

coltableLSB:
	.byte	<FontHeight*0,<FontHeight*0, <FontHeight*1,<FontHeight*1, <FontHeight*2,<FontHeight*2, <FontHeight*3,<FontHeight*3
	.byte	<FontHeight*4,<FontHeight*4, <FontHeight*5,<FontHeight*5, <FontHeight*6,<FontHeight*6, <FontHeight*7,<FontHeight*7
	.byte	<FontHeight*8,<FontHeight*8, <FontHeight*9,<FontHeight*9, <FontHeight*10,<FontHeight*10, <FontHeight*11,<FontHeight*11
	.byte	<FontHeight*12,<FontHeight*12, <FontHeight*13,<FontHeight*13, <FontHeight*14,<FontHeight*14, <FontHeight*15,<FontHeight*15
	.byte	<FontHeight*16,<FontHeight*16, <FontHeight*17,<FontHeight*17, <FontHeight*18,<FontHeight*18, <FontHeight*19,<FontHeight*19
	.byte	<FontHeight*20,<FontHeight*20, <FontHeight*21,<FontHeight*21, <FontHeight*22,<FontHeight*22, <FontHeight*23,<FontHeight*23
	.byte	<FontHeight*24,<FontHeight*24, <FontHeight*25,<FontHeight*25, <FontHeight*26,<FontHeight*26, <FontHeight*27,<FontHeight*27
	.byte	<FontHeight*28,<FontHeight*28, <FontHeight*29,<FontHeight*29, <FontHeight*30,<FontHeight*30, <FontHeight*31,<FontHeight*31
	.byte	<FontHeight*32,<FontHeight*32, <FontHeight*33,<FontHeight*33, <FontHeight*34,<FontHeight*34, <FontHeight*35,<FontHeight*35
	.byte	<FontHeight*36,<FontHeight*36, <FontHeight*37,<FontHeight*37, <FontHeight*38,<FontHeight*38, <FontHeight*39,<FontHeight*39
coltableMSB:
	.byte	>FontHeight*0,>FontHeight*0, >FontHeight*1,>FontHeight*1, >FontHeight*2,>FontHeight*2, >FontHeight*3,>FontHeight*3
	.byte	>FontHeight*4,>FontHeight*4, >FontHeight*5,>FontHeight*5, >FontHeight*6,>FontHeight*6, >FontHeight*7,>FontHeight*7
	.byte	>FontHeight*8,>FontHeight*8, >FontHeight*9,>FontHeight*9, >FontHeight*10,>FontHeight*10, >FontHeight*11,>FontHeight*11
	.byte	>FontHeight*12,>FontHeight*12, >FontHeight*13,>FontHeight*13, >FontHeight*14,>FontHeight*14, >FontHeight*15,>FontHeight*15
	.byte	>FontHeight*16,>FontHeight*16, >FontHeight*17,>FontHeight*17, >FontHeight*18,>FontHeight*18, >FontHeight*19,>FontHeight*19
	.byte	>FontHeight*20,>FontHeight*20, >FontHeight*21,>FontHeight*21, >FontHeight*22,>FontHeight*22, >FontHeight*23,>FontHeight*23
	.byte	>FontHeight*24,>FontHeight*24, >FontHeight*25,>FontHeight*25, >FontHeight*26,>FontHeight*26, >FontHeight*27,>FontHeight*27
	.byte	>FontHeight*28,>FontHeight*28, >FontHeight*29,>FontHeight*29, >FontHeight*30,>FontHeight*30, >FontHeight*31,>FontHeight*31
	.byte	>FontHeight*32,>FontHeight*32, >FontHeight*33,>FontHeight*33, >FontHeight*34,>FontHeight*34, >FontHeight*35,>FontHeight*35
	.byte	>FontHeight*36,>FontHeight*36, >FontHeight*37,>FontHeight*37, >FontHeight*38,>FontHeight*38, >FontHeight*39,>FontHeight*39
.endif	




.CODE

.if AcornAtom = 1
.macro SETVDG	value
	lda		#value			; 6847 control - GM2 GM1 GM0 A/G 0 0 0 0
	sta		$B000
.endmacro
InitScreen:
;	lda		#$FF
	lda		#$00
	sta		BGColor			;set the background color
	;clear the screen before we show it
	jsr		cls
	;Acorn Atom
	SETVDG(%11110000)		; 6847 control - GM2 GM1 GM0 A/G 0 0 0 0   RG6 = 11110000
	
	rts
.endif


.if Plus4 = 1
InitScreen:
	;set hi-res graphics mode
	lda		#VMSet				; Load the video mode setting
	sta		TEDVMR				; set it 
	;set video RAM address
	lda		#VASet				; Load the video address setting
	sta		VBASEREG			; set the address of our hi-res screen

3072/255
; set up color RAM
	lda	#$33		;%00110011
	ldx	#$00		;clear X
@cloop:
	sta	$ColorRAM,x
	sta	$ColorRAM+$100,x
	sta	$ColorRAM+$200,x
	dex
	bne	@cloop		; loop until x hits zero again (256 times)

	ldx	#$
@cloop2:
	sta	$ColorRAM+$300,x
	dex
	bne	@cloop2

	rts
.endif
	




.if Atari = 1
; ******************************
; Atari 8 bit code
; ******************************

; ******************************
; CIO equates
; ******************************
ICHID =    $0340
ICDNO =    $0341
ICCOM =    $0342
ICSTA =    $0343
ICBAL =    $0344
ICBAH =    $0345
ICPTL =    $0346
ICPTH =    $0347
ICBLL =    $0348
ICBLH =    $0349
ICAX1 =    $034A
ICAX2 =    $034B
CIOV  =    $E456
; ******************************
; Other equates needed
; ******************************
;COLOR0 =   $02C4
;COLCRS =   $55
;ROWCRS =   $54
;ATACHR =   $02FB
;STORE1 =   $CC
;STOCOL =   $CD

COLOR0	=	$02C4			; OS COLOR REGISTERS
COLOR1	=	$02C5
COLOR2	=	$02C6
COLOR3	=	$02C7
COLOR4	=	$02C8

; ******************************
; Non Maskable Interrupt Enable register
; clear bit bits of the NMIEN register at $D40E to disable, set to enable
; DLI	- D7
; VBI	- D6
; RESET	- D5
; ******************************
NMIEN = $D40E	; non maskable interrupt enable

;
SDMCTL=$022F
;
SDLSTL=$0230
SDLSTH=$0231

DMACTL=$D400

;Mode 8 requires 40 * 192 bytes, or 7680 bytes.
;So a mode 8 screen will cross a 4K boundary, and my display list is a little more complex.
;To have contiguous screen RAM, I have to align the end of a 40 byte line with the end of the first 4K block.
;4K = 4096 bytes.  4096 / 40 = 102.4.   So 102 lines can fit in the 2nd 4K page, and 90 can fit in the first (192 lines - 102 = 90).  
;So find the 4K boundary I want to be top of RAM, subtract 4K, subtract 90 * 80 and that is the screen start address.
;Add 102 * 40 (4080) and that will give me the screen end address + 1.  4096 - 4080 = 16 unused bytes at the end of the screen.
	
InitScreen:	
	lda	#$00
	sta	BGColor				;set the background color

	;set up our display
	LDA	#$0D			; Set COLOR Light Grey
	STA	COLOR2			; Set background color
	LDA	#00				; clear A
	STA	COLOR1			; Set COLOR Black

	STA	SDMCTL			; TURN ANTIC OFF FOR A MOMENT ...
	LDA	#<HLIST			; WHILE WE STORE OUR NEW LIST'S ADDRESS
	STA	SDLSTL			; IN THE OS DISPLAY POINTER.
	LDA	#>HLIST			; NOW FOR THE HIGH BYTE.  /256
	STA	SDLSTH			; NOW ANTIC WILL KNOW OUR NEW ADDRESS
.if BytesPerLine = 32
	LDA	#$21			; NARROW PLAYFIELD 256
.elseif BytesPerLine = 40
	LDA	#$22			; NORMAL PLAYFIELD 320
.elseif BytesPerLine = 48
	LDA	#$23			; WIDE PLAYFIELD 384
.endif
	STA	SDMCTL			; ... SO WE'LL TURN ANTIC BACK ON NOW
	RTS

.data
;	.align  256,0

;	.res	194
	.res	76
;
;Atari Antic Display List
; Screen Mode 8, 256/320/384 pixels wide x 192 high, 1 bit per pixel
;
HLIST:
	.BYTE	$70,$70,$70		; 3 BLANK LINES

.if BytesPerLine = 32
	;first 4K screen block.  Only using 2K
	.BYTE	$0F+64			; Mode 8 + LSM, 256/320/384 pixels wide, 192 high, 1 bit per pixel, 7891 bytes
	.WORD	SCREEN			; Screen RAM address

	; 63 mode 8 instructions + above instruction = 64
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F					; Mode 8
	
;	;second 4K screen block, completely filled
	.BYTE	$0F+64			; Mode 8 + LSM, 256/320/384 pixels wide, 192 high, 1 bit per pixel, 7891 bytes
	.WORD	SCREEN+2048		; Screen RAM address

	; 127 mode 8 instructions + above = 128
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F					; Mode 8
.endif

.if BytesPerLine = 40
	;first 4K screen block
	.BYTE	$0F+64			; Mode 8 + LSM, 256/320/384 pixels wide, 192 high, 1 bit per pixel, 7891 bytes
	.WORD	SCREEN			; Screen RAM address
	; 89 mode 8 instructions + above
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F											; Mode 8

;	;second 4K screen block
	.BYTE	$0F+64			; Mode 8 + LSM, 320 pixels wide, 192 high, 1 bit per pixel, 7891 bytes
	.WORD	SCREEN+40*90	; Screen RAM address
; 101 mode 8 instructions + above
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F				; Mode 8
	.BYTE	$0F,$0F,$0F,$0F,$0F														; Mode 8
.endif
	
;	.BYTE	$42,$60,$9F,$02,$02	;copied from basic DL 8 dump
	
	.BYTE $41; JVB INSTRUCTION
	.WORD HLIST; TO JUMP BACK TO START OF LIST
.endif


EOF:
	 
.END

No comments:

Post a Comment