woz64/devices/video.asm

305 lines
9.1 KiB
NASM
Raw Normal View History

2019-11-06 04:31:17 +00:00
#importonce
2020-01-12 08:10:01 +00:00
#import "../libs/math.asm"
#import "../libs/memory.asm"
2020-01-19 06:48:59 +00:00
#import "../core/module.asm"
2020-01-13 07:33:13 +00:00
#import "../core/pseudo.asm"
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// MACROS //////////////////////////////////////////
// ========================================================
2020-01-20 07:32:37 +00:00
* = * "Device: Video"
2019-12-28 01:00:13 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoClearChunks -
2020-01-13 00:52:10 +00:00
// Fast clear screen mem chunks.
//
// Parameters:
// baseAddress = Pointer to screen orcolor map Address
// clearByte = Byte to use to clear screen
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoClearChunks(baseAddress, clearByte) {
2019-12-28 01:00:13 +00:00
lda #clearByte
ldx #0
!loop:
sta baseAddress, x
sta baseAddress + $100, x
sta baseAddress + $200, x
sta baseAddress + $300, x
inx
2020-01-20 07:32:37 +00:00
bne !loop-
2019-12-28 01:00:13 +00:00
}
2020-03-09 05:57:30 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoClear -
2020-01-13 00:52:10 +00:00
// Fast clear screen characters mem.
//
// Parameters:
// clearByte = Byte to use to clear screen
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoClear(clearByte) {
VideoClearChunks(Video.VIDEO_ADDR, clearByte)
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoClear -
2020-01-13 00:52:10 +00:00
// Fast clear screen Color Ram.
//
// Parameters:
// clearByte = Byte to use to clear screen
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoClearColorRam(clearByte) {
VideoClearChunks(Video.COLOR_ADDR, clearByte)
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoSetBorderColor -
// Set Video border color.
2020-01-13 00:52:10 +00:00
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoSetBorderColor(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d020
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoSetBackgroundColor -
// Set Video Backfground color.
2020-01-13 00:52:10 +00:00
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoSetBackgroundColor(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d021
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoSetMultiColor1 -
// Set Video Muticolor 1.
2020-01-13 00:52:10 +00:00
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoSetMultiColor1(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d022
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoSetMultiColor2 -
// Set Video Muticolor 2.
2020-01-13 00:52:10 +00:00
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoSetMultiColor2(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d023
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// VideoSetMultiColorMode -
// Set Video Muticolor 2.
2020-01-13 00:52:10 +00:00
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Multicolor_Bitmap_Mode
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
.macro VideoSetMultiColorMode() {
2019-12-28 01:00:13 +00:00
lda $d016
ora #16
sta $d016
2019-11-06 04:31:17 +00:00
}
2020-01-20 07:32:37 +00:00
.filenamespace Video
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// CONSTANTS ///////////////////////////////////////
// ========================================================
2019-11-06 04:31:17 +00:00
2019-12-28 01:00:13 +00:00
.label VIDEO_ADDR = $0400
.label COLOR_ADDR = $D800
.label COLUMN_NUM = 40
.label ROWS_NUM = 25
.label CR = $8e
.label BS = $95
2019-11-21 06:18:23 +00:00
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// METHODS /////////////////////////////////////////
// ========================================================
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// init -
// Module Init.
// --------------------------------------------------------
2019-11-06 04:31:17 +00:00
init: {
2019-11-23 02:50:25 +00:00
lda #$00
2020-01-20 07:32:37 +00:00
sta MemMap.VIDEO.CursorCol
sta MemMap.VIDEO.CursorRow
2020-01-21 02:09:18 +00:00
lda #%00000000
sta MemMap.VIDEO.StatusBitsA
2019-11-23 02:50:25 +00:00
rts
2019-11-18 03:28:54 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// toDebug -
// Print debug info.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
toDebug: {
2020-01-13 00:52:10 +00:00
ModuleToDebug(module_type, module_name, version)
2020-01-12 08:10:01 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// scrollUp -
// Scroll the entire screen UP - 1 line
// --------------------------------------------------------
2019-11-18 03:28:54 +00:00
scrollUp: {
2019-11-23 02:50:25 +00:00
pha
2020-01-12 08:10:01 +00:00
MemoryClone(VIDEO_ADDR+40, VIDEO_ADDR+(COLUMN_NUM*(ROWS_NUM)), VIDEO_ADDR)
2019-11-23 02:50:25 +00:00
// clear last line
2019-12-28 01:00:13 +00:00
lda #32
ldx #40
2019-11-23 02:50:25 +00:00
!:
sta VIDEO_ADDR+(COLUMN_NUM*(ROWS_NUM-1)), x
dex
2019-12-28 01:00:13 +00:00
bpl !- // x == -1
2020-01-20 07:32:37 +00:00
dec MemMap.VIDEO.CursorRow
2019-11-23 02:50:25 +00:00
pla
rts
2019-11-18 03:28:54 +00:00
}
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// sendChar -
// Send a single char to the screen. Auto handle line feed,
// end of screen scrolling and Backspace.
//
// Parameters:
2020-01-20 07:32:37 +00:00
// A = Character to Print VIDEO ASCII
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
sendChar: {
2019-12-28 01:00:13 +00:00
sei
2020-01-13 07:33:13 +00:00
phx
2019-11-21 06:18:23 +00:00
cmp #CR
2020-01-20 07:32:37 +00:00
bne !+
2019-11-18 03:28:54 +00:00
jsr screenNewLine
2019-11-06 04:31:17 +00:00
iny
2019-11-21 06:18:23 +00:00
jmp exit
2019-11-23 02:50:25 +00:00
!:
2019-11-21 06:18:23 +00:00
cmp #BS
2020-01-20 07:32:37 +00:00
bne !+
ldx MemMap.VIDEO.CursorCol
2019-11-21 06:18:23 +00:00
cmp #0
beq exit
2020-01-20 07:32:37 +00:00
dec MemMap.VIDEO.CursorCol
2019-11-23 02:50:25 +00:00
!:
2019-11-06 04:31:17 +00:00
// Store Base Video Address 16 bit
2019-11-18 03:28:54 +00:00
ldx #<VIDEO_ADDR // Low byte
2020-01-20 07:32:37 +00:00
stx MemMap.VIDEO.TempVideoPointer
2019-11-18 03:28:54 +00:00
ldx #>VIDEO_ADDR // High byte
2020-01-20 07:32:37 +00:00
stx MemMap.VIDEO.TempVideoPointer+1
2019-11-06 04:31:17 +00:00
// Temp Save Y
2020-01-13 07:33:13 +00:00
phy
2019-11-06 04:31:17 +00:00
// CursorRow * 40
2020-01-20 07:32:37 +00:00
ldy MemMap.VIDEO.CursorRow
2019-11-18 03:28:54 +00:00
sty MemMap.MATH.factor1
ldy #COLUMN_NUM
sty MemMap.MATH.factor2
jsr Math.multiply
2019-11-06 04:31:17 +00:00
// Add mul result to TempVideoPointer
pha
2020-01-25 17:27:50 +00:00
clc
2019-11-18 03:28:54 +00:00
lda MemMap.MATH.result
2020-01-20 07:32:37 +00:00
adc MemMap.VIDEO.TempVideoPointer+1
sta MemMap.VIDEO.TempVideoPointer+1
2019-11-18 03:28:54 +00:00
lda MemMap.MATH.result+1
2020-01-20 07:32:37 +00:00
adc MemMap.VIDEO.TempVideoPointer
sta MemMap.VIDEO.TempVideoPointer
2019-11-18 03:28:54 +00:00
2020-01-20 07:32:37 +00:00
ldy MemMap.VIDEO.CursorCol
2019-11-18 03:28:54 +00:00
cpy #COLUMN_NUM // Is this > col num?
2020-01-20 07:32:37 +00:00
bcc noEndOfLine
jsr screenNewLine // Yes? Add new line first
2019-11-18 03:28:54 +00:00
2020-01-21 02:09:18 +00:00
bitTest(%00000001, MemMap.VIDEO.StatusBitsA)
2019-11-18 03:28:54 +00:00
bne noScrollTriggered
2019-11-21 06:18:23 +00:00
// Compensate Scroll
2019-11-18 03:28:54 +00:00
sec
2020-01-20 07:32:37 +00:00
lda MemMap.VIDEO.TempVideoPointer
sbc #40
2020-01-20 07:32:37 +00:00
sta MemMap.VIDEO.TempVideoPointer
2019-11-18 03:28:54 +00:00
bcs !+
2020-01-20 07:32:37 +00:00
dec MemMap.VIDEO.TempVideoPointer+1
2019-11-23 02:50:25 +00:00
!:
2019-11-18 03:28:54 +00:00
2020-01-12 08:10:01 +00:00
noScrollTriggered:
noEndOfLine:
2019-11-06 04:31:17 +00:00
pla
2019-11-21 06:18:23 +00:00
// This is a backspace
2019-12-28 01:00:13 +00:00
cmp #BS
bne !+
lda #' '
2020-01-20 07:32:37 +00:00
sta (MemMap.VIDEO.TempVideoPointer), y
2020-01-19 07:11:56 +00:00
ply
2019-12-28 01:00:13 +00:00
jmp exit
2019-11-23 02:50:25 +00:00
!:
2019-11-18 03:28:54 +00:00
// insert into screen
2020-01-20 07:32:37 +00:00
sta (MemMap.VIDEO.TempVideoPointer), y
2020-01-13 07:33:13 +00:00
ply
2019-11-06 04:31:17 +00:00
iny
2020-01-20 07:32:37 +00:00
inc MemMap.VIDEO.CursorCol
2019-11-06 04:31:17 +00:00
2019-11-23 02:50:25 +00:00
exit:
2020-01-13 07:33:13 +00:00
plx
2019-12-28 01:00:13 +00:00
cli
2019-11-06 04:31:17 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// screenNewLine -
// Insert a New Line to screen - auto handle screen bottom
// linit scroll.
// --------------------------------------------------------
2019-11-06 04:31:17 +00:00
screenNewLine: {
2019-11-23 02:50:25 +00:00
pha
lda #0
2020-01-20 07:32:37 +00:00
sta MemMap.VIDEO.CursorCol
2019-11-23 02:50:25 +00:00
lda #ROWS_NUM-1
2020-01-20 07:32:37 +00:00
cmp MemMap.VIDEO.CursorRow // Are we at the screen bottom?
2019-11-23 02:50:25 +00:00
bne noScrollUp
2020-01-20 07:32:37 +00:00
jsr Video.scrollUp
2020-01-21 02:09:18 +00:00
bitSet(%00000001, MemMap.VIDEO.StatusBitsA)
2019-11-23 02:50:25 +00:00
jmp done
noScrollUp:
2020-01-21 02:09:18 +00:00
bitClear(%00000001, MemMap.VIDEO.StatusBitsA)
2019-11-23 02:50:25 +00:00
done:
2020-01-20 07:32:37 +00:00
inc MemMap.VIDEO.CursorRow
2019-11-23 02:50:25 +00:00
pla
rts
2019-11-06 04:31:17 +00:00
}
2020-01-20 07:32:37 +00:00
* = * "Device: Video Data"
module_type: .byte Module.TYPES.DEVICE
2020-01-19 07:14:02 +00:00
version: .byte 1, 0, 1
2020-01-12 08:10:01 +00:00
module_name:
2020-01-20 07:32:37 +00:00
.text "video"
2020-01-12 08:10:01 +00:00
.byte 0
2019-11-23 02:50:25 +00:00
2020-01-20 07:38:20 +00:00
#import "../hardware/mem_map.asm"