woz64/devices/video.asm

301 lines
8.4 KiB
NASM
Raw Permalink 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
2023-07-03 04:10:00 +00:00
lda #COLUMN_NUM
sta MemMap.MATH.factor2
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: {
2023-07-03 04:10:00 +00:00
sei
phx
cmp #CR
bne notCR
jsr screenNewLine
iny
jmp exit
notCR:
cmp #BS
bne notBS
ldx MemMap.VIDEO.CursorCol
beq exit
dec MemMap.VIDEO.CursorCol
jmp storeBaseVideoAddress
notBS:
// Store Base Video Address 16 bit
storeBaseVideoAddress:
ldx #<VIDEO_ADDR // Low byte
stx MemMap.VIDEO.TempVideoPointer
ldx #>VIDEO_ADDR // High byte
stx MemMap.VIDEO.TempVideoPointer+1
// CursorRow * 40
ldy MemMap.VIDEO.CursorRow
sty MemMap.MATH.factor1
jsr Math.multiply
// Add mul result to TempVideoPointer
pha
clc
lda MemMap.MATH.result
adc MemMap.VIDEO.TempVideoPointer+1
sta MemMap.VIDEO.TempVideoPointer+1
lda MemMap.MATH.result+1
adc MemMap.VIDEO.TempVideoPointer
sta MemMap.VIDEO.TempVideoPointer
ldy MemMap.VIDEO.CursorCol
cpy #COLUMN_NUM // Is this > col num?
bcc noEndOfLine
jsr screenNewLine // Yes? Add new line first
lda MemMap.VIDEO.StatusBitsA
and #%00000001
beq noScrollTriggered
// Compensate Scroll
sec
lda MemMap.VIDEO.TempVideoPointer
sbc #40
sta MemMap.VIDEO.TempVideoPointer
bcs noScrollTriggered
dec MemMap.VIDEO.TempVideoPointer+1
noScrollTriggered:
noEndOfLine:
pla
cmp #BS
bne notBackspace
lda #' '
sta (MemMap.VIDEO.TempVideoPointer), y
jmp exit
notBackspace:
sta (MemMap.VIDEO.TempVideoPointer), y
iny
inc MemMap.VIDEO.CursorCol
exit:
plx
cli
rts
2019-11-06 04:31:17 +00:00
}
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"